Search in sources :

Example 16 with ItemStackWrapper

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());
}
Also used : ItemStackWrapper(com.builtbroken.mc.prefab.items.ItemStackWrapper) ItemStack(net.minecraft.item.ItemStack)

Example 17 with ItemStackWrapper

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());
}
Also used : ItemStackWrapper(com.builtbroken.mc.prefab.items.ItemStackWrapper) ItemStack(net.minecraft.item.ItemStack)

Example 18 with ItemStackWrapper

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));
}
Also used : NBTTagCompound(net.minecraft.nbt.NBTTagCompound) ItemStackWrapper(com.builtbroken.mc.prefab.items.ItemStackWrapper) ItemStack(net.minecraft.item.ItemStack)

Example 19 with ItemStackWrapper

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));
}
Also used : Block(net.minecraft.block.Block) ItemStack(net.minecraft.item.ItemStack) ItemStackWrapper(com.builtbroken.mc.prefab.items.ItemStackWrapper)

Example 20 with ItemStackWrapper

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));
        }
    }
}
Also used : Block(net.minecraft.block.Block) ItemStack(net.minecraft.item.ItemStack) ItemStackWrapper(com.builtbroken.mc.prefab.items.ItemStackWrapper)

Aggregations

ItemStackWrapper (com.builtbroken.mc.prefab.items.ItemStackWrapper)21 ItemStack (net.minecraft.item.ItemStack)17 IExplosiveHandler (com.builtbroken.mc.api.explosive.IExplosiveHandler)3 HashMap (java.util.HashMap)2 Block (net.minecraft.block.Block)2 Item (net.minecraft.item.Item)2 ITexturedExplosiveHandler (com.builtbroken.mc.api.explosive.ITexturedExplosiveHandler)1 IItemHasMass (com.builtbroken.mc.api.items.IItemHasMass)1 IExplosiveContainerItem (com.builtbroken.mc.api.items.explosives.IExplosiveContainerItem)1 ExplosiveHandlerGeneric (com.builtbroken.mc.prefab.explosive.ExplosiveHandlerGeneric)1 AbstractTest (com.builtbroken.mc.testing.junit.AbstractTest)1 ArrayList (java.util.ArrayList)1 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)1 IIcon (net.minecraft.util.IIcon)1 Test (org.junit.Test)1