mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-19 16:29:39 +00:00
add a hash code to the equals method
This commit is contained in:
1 parent
605466e011
commit
17d8c99e8b
6 files changed
+56
No files matched your search
@@ -4,6 +4,8 @@ import net.minecraft.entity.Entity;
|
||||
import net.minecraft.util.Vec3;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* 3D Vector helper class for lightning calculations.
|
||||
* Adapted from Botania's Vector3 by ChickenBones.
|
||||
@@ -181,4 +183,9 @@ public class Vec3d {
|
||||
Vec3d v = (Vec3d) o;
|
||||
return x == v.x && y == v.y && z == v.z;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(x, y, z);
|
||||
}
|
||||
}
|
||||
@@ -6,6 +6,7 @@ import net.minecraft.nbt.NBTTagCompound;
|
||||
import org.lwjgl.input.Keyboard;
|
||||
import org.lwjgl.input.Mouse;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public class KeyPreset {
|
||||
@@ -189,6 +190,11 @@ public class KeyPreset {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash( currentState);
|
||||
}
|
||||
|
||||
public static class KeyState {
|
||||
public int keyCode = -1;
|
||||
public boolean hasCtrl, hasAlt, hasShift;
|
||||
@@ -232,6 +238,11 @@ public class KeyPreset {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(keyCode, hasCtrl, hasAlt, hasShift);
|
||||
}
|
||||
|
||||
public NBTTagCompound writeToNbt() {
|
||||
NBTTagCompound compound = new NBTTagCompound();
|
||||
compound.setInteger("keyCode", keyCode);
|
||||
|
||||
@@ -15,6 +15,8 @@ import noppes.npcs.api.IPos;
|
||||
import noppes.npcs.api.ITileEntity;
|
||||
import noppes.npcs.api.IWorld;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public class ScriptBlock implements IBlock {
|
||||
protected IWorld world;
|
||||
protected Block block;
|
||||
@@ -224,4 +226,9 @@ public class ScriptBlock implements IBlock {
|
||||
((ScriptBlock) obj).getWorld() == this.getWorld() &&
|
||||
((ScriptBlock) obj).getPos().equals(this.getPos());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(getWorld(), block, getPos());
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,8 @@ import net.minecraft.util.Vec3i;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import noppes.npcs.api.IPos;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public class ScriptBlockPos implements IPos {
|
||||
public BlockPos blockPos;
|
||||
|
||||
@@ -169,4 +171,9 @@ public class ScriptBlockPos implements IPos {
|
||||
public boolean equals(Object object) {
|
||||
return object instanceof IPos && ((IPos) object).toLong() == this.toLong();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hashCode(blockPos);
|
||||
}
|
||||
}
|
||||
@@ -35,6 +35,7 @@ import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
|
||||
public class ScriptEntity<T extends Entity> implements IEntity {
|
||||
@@ -964,6 +965,11 @@ public class ScriptEntity<T extends Entity> implements IEntity {
|
||||
return object instanceof IEntity && ((IEntity<?>) object).getMCEntity().equals(this.entity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(entity, tempData);
|
||||
}
|
||||
|
||||
public void updateEntity() {
|
||||
IWorld world = NpcAPI.Instance().getIWorld(entity.worldObj);
|
||||
entity.dimension = world.getDimensionID();
|
||||
|
||||
@@ -36,6 +36,7 @@ import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
|
||||
public class ScriptItemStack implements IItemStack {
|
||||
@@ -355,6 +356,7 @@ public class ScriptItemStack implements IItemStack {
|
||||
* @return Returns whether this item is a book
|
||||
* @since 1.7.10d
|
||||
*/
|
||||
@Override
|
||||
public boolean isWrittenBook() {
|
||||
return item.getItem() == Items.written_book || item.getItem() == Items.writable_book;
|
||||
}
|
||||
@@ -363,6 +365,7 @@ public class ScriptItemStack implements IItemStack {
|
||||
* @return Returns the books title
|
||||
* @since 1.7.10d
|
||||
*/
|
||||
@Override
|
||||
public String getBookTitle() {
|
||||
return item.getTagCompound().getString("title");
|
||||
}
|
||||
@@ -371,6 +374,7 @@ public class ScriptItemStack implements IItemStack {
|
||||
* @return Returns the books author
|
||||
* @since 1.7.10d
|
||||
*/
|
||||
@Override
|
||||
public String getBookAuthor() {
|
||||
return item.getTagCompound().getString("author");
|
||||
}
|
||||
@@ -379,6 +383,7 @@ public class ScriptItemStack implements IItemStack {
|
||||
* @return If the item is a book, returns a string array with book pages
|
||||
* @since 1.7.10d
|
||||
*/
|
||||
@Override
|
||||
public String[] getBookText() {
|
||||
if (!isWrittenBook())
|
||||
return null;
|
||||
@@ -399,6 +404,7 @@ public class ScriptItemStack implements IItemStack {
|
||||
/**
|
||||
* @return Returns whether or not this item is a block
|
||||
*/
|
||||
@Override
|
||||
public boolean isBlock() {
|
||||
Block block = Block.getBlockFromItem(item.getItem());
|
||||
if (block == null || block == Blocks.air)
|
||||
@@ -415,6 +421,7 @@ public class ScriptItemStack implements IItemStack {
|
||||
return -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public INbt getNbt() {
|
||||
NBTTagCompound compound = this.item.getTagCompound();
|
||||
if (compound == null) {
|
||||
@@ -424,18 +431,21 @@ public class ScriptItemStack implements IItemStack {
|
||||
return NpcAPI.Instance().getINbt(compound);
|
||||
}
|
||||
|
||||
@Override
|
||||
public INbt getItemNbt() {
|
||||
NBTTagCompound compound = new NBTTagCompound();
|
||||
this.item.writeToNBT(compound);
|
||||
return NpcAPI.Instance().getINbt(compound);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBTTagCompound getMCNbt() {
|
||||
NBTTagCompound compound = new NBTTagCompound();
|
||||
this.item.writeToNBT(compound);
|
||||
return compound;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setMCNbt(NBTTagCompound compound) {
|
||||
}
|
||||
|
||||
@@ -444,18 +454,26 @@ public class ScriptItemStack implements IItemStack {
|
||||
*
|
||||
* @return Minecraft ItemStack
|
||||
*/
|
||||
@Override
|
||||
public ItemStack getMCItemStack() {
|
||||
return item;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int itemHash() {
|
||||
return item.hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object object) {
|
||||
return object instanceof ScriptItemStack && ((ScriptItemStack) object).getMCItemStack().equals(this.getMCItemStack());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hashCode(item);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean compare(IItemStack item, boolean ignoreNBT) {
|
||||
return NoppesUtilPlayer.compareItems(getMCItemStack(), item.getMCItemStack(), false, ignoreNBT);
|
||||
|
||||
Reference in new issue
Block a user