ScriptItemStack, ScriptEntity, ScriptBlock, & ScriptBlockPos:

-Implemented equals() functions for comparing objects of these types
This commit is contained in:
Luis C.M committed 2023-06-03 00:34:07 -05:00
1 parent 826a90bd6d
commit 29fb8d1dcf
5 files changed
+19 -6

No files matched your search

@@ -19,7 +19,6 @@ import noppes.npcs.util.LRUHashMap;
import java.util.Map;
public class ScriptBlock implements IBlock {
private static final Map<String, IBlock> blockCache = new LRUHashMap(400);
protected IWorld world;
protected Block block;
protected BlockPos pos;
@@ -147,10 +146,6 @@ public class ScriptBlock implements IBlock {
return this.block;
}
public static void clearCache() {
blockCache.clear();
}
public boolean hasTileEntity() {
return this.tile != null;
}
@@ -226,4 +221,10 @@ public class ScriptBlock implements IBlock {
public String toString() {
return this.getName() + " @" + this.getPos() + (world == null ? "" : " in DIM" + world.getDimensionID());
}
public boolean equals(Object obj) {
return obj instanceof IBlock && ((ScriptBlock)obj).getName().equals(this.getName()) &&
((ScriptBlock)obj).getWorld() == this.getWorld() &&
((ScriptBlock)obj).getPos().equals(this.getPos());
}
}
@@ -154,4 +154,8 @@ public class ScriptBlockPos implements IPos {
public String toString() {
return "(" + this.getX() + ", " + this.getY() + ", " + this.getZ() + ")";
}
public boolean equals(Object object) {
return object instanceof IPos && ((IPos) object).toLong() == this.toLong();
}
}
@@ -895,4 +895,8 @@ public class ScriptEntity<T extends Entity> implements IEntity {
public IWorld getWorld() {
return NpcAPI.Instance().getIWorld(entity.worldObj);
}
public boolean equals(Object object) {
return object instanceof IEntity && ((IEntity<?>)object).getMCEntity().equals(this.entity);
}
}
@@ -409,4 +409,8 @@ public class ScriptItemStack implements IItemStack {
public int itemHash() {
return item.hashCode();
}
public boolean equals(Object object) {
return object instanceof ScriptItemStack && ((ScriptItemStack) object).getMCItemStack().equals(this.getMCItemStack());
}
}