Java Code Examples for net.minecraft.item.Item.equals()

The following are Jave code examples for showing how to use equals() of the net.minecraft.item.Item class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: ModularMachinery   File: ItemUtils.java   Source Code and License Vote up 6 votes
public static boolean stackEqualsNonNBT(@Nonnull ItemStack stack, @Nonnull  ItemStack other) {
    if (stack.isEmpty() && other.isEmpty())
        return true;
    if (stack.isEmpty() || other.isEmpty())
        return false;
    Item sItem = stack.getItem();
    Item oItem = other.getItem();
    if (sItem.getHasSubtypes() || oItem.getHasSubtypes()) {
        return sItem.equals(other.getItem()) &&
                (stack.getItemDamage() == other.getItemDamage() ||
                        stack.getItemDamage() == OreDictionary.WILDCARD_VALUE ||
                        other.getItemDamage() == OreDictionary.WILDCARD_VALUE);
    } else {
        return sItem.equals(other.getItem());
    }
}
 
Example 2
Project: Industrial-Foregoing   File: BlockUtils.java   Source Code and License Vote up 5 votes
public static boolean isBlockOreDict(World world, BlockPos pos, String ore) {
    IBlockState state = world.getBlockState(pos);
    Item item = Item.getItemFromBlock(state.getBlock());
    if (!item.equals(Items.AIR)) {
        ItemStack stack = new ItemStack(item);
        int id = OreDictionary.getOreID(ore);
        for (int i : OreDictionary.getOreIDs(stack)) {
            if (i == id) return true;
        }
    }
    return false;
}
 
Example 3
Project: craftsman   File: FstPlayer.java   Source Code and License Vote up 5 votes
public void runIfAirOrBlockHeld(Runnable blockHeld, Runnable airHeld) {
    Item heldItem = player.getHeldItemMainhand().getItem();
    
    if(heldItem.equals(Items.AIR)) {
        info("You don't hold a block. The command will do the cleaning.");
        airHeld.run();
    } else if(!(heldItem instanceof ItemBlock)) {
        info("Hold a block");
    } else {
        blockHeld.run();
    }
}
 
Example 4
Project: craftsman   File: FstPlayer.java   Source Code and License Vote up 5 votes
public void runIfAirOrStairsHeld(Runnable runnable) {
    Item heldItem = player.getHeldItemMainhand().getItem();
    Block heldBlock = Block.getBlockFromItem(heldItem);
    
    if(heldItem.equals(Items.AIR)) {
        info("You don't hold stairs. The command will do the cleaning.");
    } else if(!(heldBlock instanceof BlockStairs)) {
        info("Hold stairs");
        return;
    }        
    
    runnable.run();
}
 
Example 5
Project: bit-client   File: ItemUtil.java   Source Code and License Vote up 5 votes
public static int player_itemSlotHotbar(Item compare) {
    for (int i = 0; i < 9; i++) {
        if (Wrapper.player_inventoryItems() != null) {
            try {
                Item item = getItemFromStack(Wrapper.player_inventoryItems()[i]);
                if (item != null && item.equals(compare))
                    return i;
            } catch (Exception e) {
                continue;
            }
        }
    }
    return -1;
}
 
Example 6
Project: bit-client   File: ItemUtil.java   Source Code and License Vote up 5 votes
public static int player_itemSlot(Item compare) {
    for (int i = 0; i < Wrapper.player_inventoryItems().length; i++) {
        if (Wrapper.player_inventoryItems() != null) {
            try {
                Item item = getItemFromStack(Wrapper.player_inventoryItems()[i]);
                if (item != null && item.equals(compare))
                    return i;
            } catch (Exception e) {
                continue;
            }
        }
    }
    return -1;
}
 
Example 7
Project: bit-client   File: ItemUtil.java   Source Code and License Vote up 5 votes
public static int player_itemSlot_noHotbar(Item compare) {
    for (int i = 9; i < Wrapper.player_inventoryItems().length; i++) {
        if (Wrapper.player_inventoryItems() != null) {
            try {
                Item item = getItemFromStack(Wrapper.player_inventoryItems()[i]);
                if (item != null && item.equals(compare))
                    return i;
            } catch (Exception e) {
                continue;
            }
        }
    }
    return -1;
}