use of com.builtbroken.mc.prefab.items.ItemStackWrapper in project Engine by VoltzEngine-Project.
the class ItemStackWrapperTest method testHashCodeNotEquals.
public void testHashCodeNotEquals() {
//Check for item compare
ItemStackWrapper a = new ItemStackWrapper(new ItemStack(Items.apple));
ItemStackWrapper b = new ItemStackWrapper(new ItemStack(Items.stone_axe));
assertFalse("Hash codes should not equal", a.hashCode() == b.hashCode());
a = new ItemStackWrapper(new ItemStack(Items.apple));
b = new ItemStackWrapper(new ItemStack(Items.apple));
assertTrue("Hash codes should equal", a.hashCode() == b.hashCode());
//Check for stack compare when turned off, which is default
a = new ItemStackWrapper(new ItemStack(Items.apple, 2));
b = new ItemStackWrapper(new ItemStack(Items.apple, 1));
assertTrue("Hash codes should equal as stack size is not compared", a.hashCode() == b.hashCode());
//Check for stack compare when turned on
a = new ItemStackWrapper(new ItemStack(Items.apple, 2)).setStackCompare(true);
b = new ItemStackWrapper(new ItemStack(Items.apple, 1)).setStackCompare(true);
assertFalse("Hash codes should not equal", a.hashCode() == b.hashCode());
//Check for meta compare
a = new ItemStackWrapper(new ItemStack(Items.apple, 1, 0)).setMetaCompare(true);
b = new ItemStackWrapper(new ItemStack(Items.apple, 1, 1)).setMetaCompare(true);
assertFalse("Hash codes should not equal", a.hashCode() == b.hashCode());
}
use of com.builtbroken.mc.prefab.items.ItemStackWrapper in project Engine by VoltzEngine-Project.
the class ItemStackWrapperTest method testHashCodeEquals.
public void testHashCodeEquals() {
ItemStackWrapper a = new ItemStackWrapper(new ItemStack(Items.apple));
ItemStackWrapper b = new ItemStackWrapper(new ItemStack(Items.apple));
assertTrue("Wrappers failed to equal each other", a.equals(b));
assertTrue("Hash codes don't equal", a.hashCode() == b.hashCode());
a = new ItemStackWrapper(new ItemStack(Items.coal));
b = new ItemStackWrapper(new ItemStack(Items.coal, 10));
assertTrue("Wrappers failed to equal each other", a.equals(b));
assertTrue("Hash codes don't equal", a.hashCode() == b.hashCode());
}
use of com.builtbroken.mc.prefab.items.ItemStackWrapper in project Engine by VoltzEngine-Project.
the class ItemStackWrapperTest method testCheckNBTCompare.
public void testCheckNBTCompare() {
ItemStackWrapper a = new ItemStackWrapper(new ItemStack(Items.apple));
a.nbt_compare = true;
ItemStackWrapper b = new ItemStackWrapper(new ItemStack(Items.apple));
b.nbt_compare = true;
assertTrue("Failed Null equals Null NBT", a.equals(b));
//Compare Not null to Null
a.itemStack.setTagCompound(new NBTTagCompound());
assertTrue("Failed Not Null equals Null NBT", a.equals(b));
//Compare Empty NBT
a.itemStack.setTagCompound(new NBTTagCompound());
b.itemStack.setTagCompound(new NBTTagCompound());
assertTrue("Failed Empty NBT", a.equals(b));
//Compare Null to Not Null
a.itemStack.setTagCompound(null);
assertTrue("Failed Null equals Not Null NBT", a.equals(b));
//Compare same NBT with data
a.itemStack.setTagCompound(new NBTTagCompound());
a.itemStack.getTagCompound().setBoolean("a", true);
b.itemStack.setTagCompound(new NBTTagCompound());
b.itemStack.getTagCompound().setBoolean("a", true);
assertTrue("Failed same NBT compare", a.equals(b));
//Compare NBT with different data
a.itemStack.setTagCompound(new NBTTagCompound());
a.itemStack.getTagCompound().setBoolean("a", true);
b.itemStack.setTagCompound(new NBTTagCompound());
b.itemStack.getTagCompound().setBoolean("b", true);
assertFalse("Failed same NBT compare", a.equals(b));
}
use of com.builtbroken.mc.prefab.items.ItemStackWrapper in project Engine by VoltzEngine-Project.
the class ItemStackWrapperTest method testCompareBlock.
//Check if Wrapper equals block
public void testCompareBlock() {
Block block = Blocks.diamond_block;
ItemStack itemStack = new ItemStack(Blocks.diamond_block);
ItemStackWrapper wrapper = new ItemStackWrapper(itemStack);
wrapper.meta_compare = false;
wrapper.nbt_compare = false;
assertEquals("MC compare check for items equal", Item.getItemFromBlock(block), itemStack.getItem());
assertTrue("Compare failed for block equals", wrapper.equals(block));
}
use of com.builtbroken.mc.prefab.items.ItemStackWrapper in project Engine by VoltzEngine-Project.
the class ItemStackWrapperTest method testForNotEquals.
//Check if Wrapper equals stack
public void testForNotEquals() {
ItemStack itemStack = new ItemStack(Blocks.diamond_block);
ItemStackWrapper wrapper = new ItemStackWrapper(itemStack);
//Random blocks to compare to for the hell of it
for (int i = 0; i < 10; i++) {
Block block = Block.getBlockById(MathUtility.rand.nextInt(255));
if (block != null && Item.getItemFromBlock(block) != null && block != Blocks.diamond_block) {
ItemStack stack = new ItemStack(block);
assertFalse("Should be false as the blocks are not the same", stack.isItemEqual(itemStack));
assertFalse("Should be false as the blocks are not the same", wrapper.equals(stack));
}
}
}
Aggregations