Java Code Examples for net.minecraft.item.ItemStack#areItemStackTagsEqual()
The following examples show how to use
net.minecraft.item.ItemStack#areItemStackTagsEqual() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TileEntityFluidCrafter.java From ExtraCells1 with MIT License | 6 votes |
public void removeItems(ItemStack stack) { for (int i = 0; i < bufferInventory.slots.size(); i++) { ItemStack item = bufferInventory.getStackInSlot(i) != null ? bufferInventory.getStackInSlot(i).copy() : null; if (item != null && item.isItemEqual(stack) && ItemStack.areItemStackTagsEqual(stack, item)) { if (item.stackSize > stack.stackSize) { item.stackSize -= stack.stackSize; bufferInventory.slots.set(i, item); } else if (item.stackSize == stack.stackSize) { bufferInventory.slots.set(i, null); } } } }
Example 2
Source File: TileEntityAutoChisel.java From Chisel-2 with GNU General Public License v2.0 | 6 votes |
private boolean canChisel(ItemStack toMerge) { // if the output slot is empty we can merge without checking if (inventory[OUTPUT] == null) { return true; } // need to check NBT as well as item if (!toMerge.isItemEqual(inventory[OUTPUT]) || !ItemStack.areItemStackTagsEqual(toMerge, inventory[OUTPUT])) { return false; } // we only care about metadata if the item has subtypes if (toMerge.getHasSubtypes() && toMerge.getItemDamage() != inventory[OUTPUT].getItemDamage()) { return false; } return ((IChiselItem) inventory[CHISEL].getItem()).canChisel(worldObj, inventory[CHISEL], General.getVariation(getTarget())); }
Example 3
Source File: SlotItemHandlerCraftResult.java From enderutilities with GNU Lesser General Public License v3.0 | 5 votes |
public ItemStack onTake(EntityPlayer player, ItemStack stack) { this.onCrafting(stack); net.minecraftforge.common.ForgeHooks.setCraftingPlayer(player); NonNullList<ItemStack> remainingItems = CraftingManager.getRemainingItems(this.craftMatrix, player.getEntityWorld()); net.minecraftforge.common.ForgeHooks.setCraftingPlayer(null); for (int i = 0; i < remainingItems.size(); i++) { ItemStack stackInSlot = this.craftMatrix.getStackInSlot(i); ItemStack remainingItemsInSlot = remainingItems.get(i); if (stackInSlot.isEmpty() == false) { this.craftMatrix.decrStackSize(i, 1); stackInSlot = this.craftMatrix.getStackInSlot(i); } if (remainingItemsInSlot.isEmpty() == false) { if (stackInSlot.isEmpty()) { this.craftMatrix.setInventorySlotContents(i, remainingItemsInSlot); } else if (ItemStack.areItemsEqual(stackInSlot, remainingItemsInSlot) && ItemStack.areItemStackTagsEqual(stackInSlot, remainingItemsInSlot)) { remainingItemsInSlot.grow(stackInSlot.getCount()); this.craftMatrix.setInventorySlotContents(i, remainingItemsInSlot); } else if (this.player.inventory.addItemStackToInventory(remainingItemsInSlot) == false) { this.player.dropItem(remainingItemsInSlot, false); } } } return stack; }
Example 4
Source File: ECContainer.java From ExtraCells1 with MIT License | 5 votes |
public boolean canStacksMerge(ItemStack stack1, ItemStack stack2) { if (stack1 == null || stack2 == null) return false; if (!stack1.isItemEqual(stack2)) return false; if (!ItemStack.areItemStackTagsEqual(stack1, stack2)) return false; return true; }
Example 5
Source File: StatementParameterItemStack.java From Framez with GNU General Public License v3.0 | 5 votes |
@Override public boolean equals(Object object) { if (object instanceof StatementParameterItemStack) { StatementParameterItemStack param = (StatementParameterItemStack) object; return ItemStack.areItemStacksEqual(stack, param.stack) && ItemStack.areItemStackTagsEqual(stack, param.stack); } else { return false; } }
Example 6
Source File: SemiBlockHeatFrame.java From PneumaticCraft with GNU General Public License v3.0 | 5 votes |
private boolean tryCoolSlot(IInventory inv, int slot){ ItemStack stack = inv.getStackInSlot(slot); if(stack != null) { for(Pair<Object, ItemStack> recipe : PneumaticRecipeRegistry.getInstance().heatFrameCoolingRecipes) { if(PneumaticRecipeRegistry.isItemEqual(recipe.getKey(), stack)) { int amount = PneumaticRecipeRegistry.getItemAmount(recipe.getKey()); if(stack.stackSize >= amount) { ItemStack containerItem = stack.getItem().getContainerItem(stack); boolean canStoreContainerItem = false; boolean canStoreOutput = false; for(int i = 0; i < inv.getSizeInventory(); i++) { ItemStack s = inv.getStackInSlot(i); if(s == null) { if(canStoreOutput) { canStoreContainerItem = true; } else { canStoreOutput = true; } } else { if(s.isItemEqual(recipe.getRight()) && ItemStack.areItemStackTagsEqual(s, recipe.getRight()) && s.getMaxStackSize() >= s.stackSize + recipe.getRight().stackSize) { canStoreOutput = true; } if(containerItem != null && s.isItemEqual(containerItem) && ItemStack.areItemStackTagsEqual(s, containerItem) && s.getMaxStackSize() >= s.stackSize + containerItem.stackSize) { canStoreContainerItem = true; } } } if(canStoreOutput && (containerItem == null || canStoreContainerItem)) { inv.decrStackSize(slot, amount); IOHelper.insert(getTileEntity(), recipe.getValue().copy(), false); if(containerItem != null) IOHelper.insert(getTileEntity(), containerItem.copy(), false); return true; } } } } } return false; }
Example 7
Source File: ContainerPneumaticBase.java From PneumaticCraft with GNU General Public License v3.0 | 5 votes |
public boolean canStacksMerge(ItemStack stack1, ItemStack stack2){ if(stack1 == null || stack2 == null) return false; if(!stack1.isItemEqual(stack2)) return false; if(!ItemStack.areItemStackTagsEqual(stack1, stack2)) return false; return true; }
Example 8
Source File: SimpleItemFilter.java From GregTech with GNU Lesser General Public License v3.0 | 5 votes |
private static boolean areItemsEqual(boolean ignoreDamage, boolean ignoreNBTData, ItemStack filterStack, ItemStack itemStack) { if (ignoreDamage) { if (!filterStack.isItemEqualIgnoreDurability(itemStack)) { return false; } } else if (!filterStack.isItemEqual(itemStack)) { return false; } return ignoreNBTData || ItemStack.areItemStackTagsEqual(filterStack, itemStack); }
Example 9
Source File: InventoryUtils.java From CodeChickenLib with GNU Lesser General Public License v2.1 | 5 votes |
public static boolean canStack(ItemStack stack1, ItemStack stack2) { return stack1 == null || stack2 == null || (stack1.getItem() == stack2.getItem() && (!stack2.getHasSubtypes() || stack2.getItemDamage() == stack1.getItemDamage()) && ItemStack.areItemStackTagsEqual(stack2, stack1)) && stack1.isStackable(); }
Example 10
Source File: MetaTileEntityCokeOven.java From GregTech with GNU Lesser General Public License v3.0 | 4 votes |
private static boolean areItemStacksEqual(ItemStack stackA, ItemStack stackB) { return (stackA.isEmpty() && stackB.isEmpty()) || (ItemStack.areItemsEqual(stackA, stackB) && ItemStack.areItemStackTagsEqual(stackA, stackB)); }
Example 11
Source File: CorporeaHelper.java From ForbiddenMagic with Do What The F*ck You Want To Public License | 4 votes |
/** * Gets if two stacks match. */ public static boolean stacksMatch(ItemStack stack1, ItemStack stack2, boolean checkNBT) { return stack1 != null && stack2 != null && stack1.isItemEqual(stack2) && (!checkNBT || ItemStack.areItemStackTagsEqual(stack1, stack2)); }
Example 12
Source File: InventoryUtils.java From CodeChickenLib with GNU Lesser General Public License v2.1 | 4 votes |
public static boolean canStack(@Nonnull ItemStack stack1, @Nonnull ItemStack stack2) { return stack1.isEmpty() || stack2.isEmpty() || (stack1.getItem() == stack2.getItem() && (stack2.getDamage() == stack1.getDamage()) && ItemStack.areItemStackTagsEqual(stack2, stack1)) && stack1.isStackable(); }
Example 13
Source File: EntityUtils.java From litematica with GNU Lesser General Public License v3.0 | 4 votes |
public static boolean areStacksEqualIgnoreDurability(ItemStack stack1, ItemStack stack2) { return ItemStack.areItemsEqualIgnoreDurability(stack1, stack2) && ItemStack.areItemStackTagsEqual(stack1, stack2); }
Example 14
Source File: GuiScreenHook.java From SkyblockAddons with MIT License | 4 votes |
public static void renderBackpack(ItemStack stack, int x, int y, ReturnValue<?> returnValue) { SkyblockAddons main = SkyblockAddons.getInstance(); if (stack.getItem().equals(Items.skull) && main.getConfigValues().isEnabled(Feature.SHOW_BACKPACK_PREVIEW)) { if (main.getConfigValues().isEnabled(Feature.SHOW_BACKPACK_HOLDING_SHIFT) && !GuiScreen.isShiftKeyDown()) { return; } Container playerContainer = Minecraft.getMinecraft().thePlayer.openContainer; if (playerContainer instanceof ContainerChest) { // Avoid showing backpack preview in auction stuff. IInventory chestInventory = ((ContainerChest) playerContainer).getLowerChestInventory(); if (chestInventory.hasCustomName()) { String chestName = chestInventory.getDisplayName().getUnformattedText(); if (chestName.contains("Auction") || "Your Bids".equals(chestName)) { // Show preview for backpacks in player inventory if enabled. if (!main.getConfigValues().isEnabled(Feature.BACKPACK_PREVIEW_AH)) { return; } /* If the backpack is in the auction house window, ignore it. Empty backpacks can't be listed in the auction. */ for (int i = 0; i < chestInventory.getSizeInventory(); i++) { if (ItemStack.areItemStackTagsEqual(chestInventory.getStackInSlot(i), stack)) { return; } } } } } Backpack backpack = BackpackManager.getFromItem(stack); if (backpack != null) { backpack.setX(x); backpack.setY(y); if (isFreezeKeyDown() && System.currentTimeMillis() - lastBackpackFreezeKey > 500) { lastBackpackFreezeKey = System.currentTimeMillis(); GuiContainerHook.setFreezeBackpack(!GuiContainerHook.isFreezeBackpack()); main.getUtils().setBackpackToPreview(backpack); } if (!GuiContainerHook.isFreezeBackpack()) { main.getUtils().setBackpackToPreview(backpack); } main.getPlayerListener().onItemTooltip(new ItemTooltipEvent(stack, null, null, false)); returnValue.cancel(); } } if (GuiContainerHook.isFreezeBackpack()) { returnValue.cancel(); } }
Example 15
Source File: TileEntitySeedStorage.java From AgriCraft with MIT License | 4 votes |
@Override public boolean addStackToInventory(ItemStack stack) { // Fetch the seed. final AgriSeed seed = AgriApi.getSeedRegistry().valueOf(stack).filter(s -> s.getStat().isAnalyzed()).orElse(null); if (seed == null || this.getWorld().isRemote) { return false; } // Set the locked seed if no locked seed is present. if (this.lockedSeed == null) { this.lockedSeed = seed; this.setSlotContents(0, stack); return true; } // Determine if the seed matches this chest's type. if (this.lockedSeed.getPlant() == seed.getPlant()) { for (Map.Entry<Integer, SeedStorageSlot> entry : this.slots.entrySet()) { if (entry.getValue() != null) { if (ItemStack.areItemStackTagsEqual(lockedSeed.toStack(), stack)) { ItemStack newStack = stack.copy(); newStack.setCount(newStack.getCount() + entry.getValue().count); this.setSlotContents(entry.getKey(), newStack); return true; } } } // If no slot to combine with was found, add to a new slot. int slotId = getFirstFreeSlot(); if (slotId >= 0) { this.setSlotContents(slotId, stack); return true; } } // The seed could not be added to the storage unit. return false; }
Example 16
Source File: InventoryPlayerTFC.java From TFC2 with GNU General Public License v3.0 | 4 votes |
public static boolean stackEqualExact(ItemStack stack1, ItemStack stack2) { return stack1.getItem() == stack2.getItem() && (!stack1.getHasSubtypes() || stack1.getMetadata() == stack2.getMetadata()) && (ItemStack.areItemStackTagsEqual(stack1, stack2) || (stack1.getItem() instanceof IFood && stack2.getItem() instanceof IFood && Food.areEqual(stack1, stack2))); }
Example 17
Source File: SlotUtil.java From GregTech with GNU Lesser General Public License v3.0 | 4 votes |
public static boolean areItemsEqual(ItemStack itemStack1, ItemStack itemStack2) { return !ItemStack.areItemsEqual(itemStack1, itemStack2) || !ItemStack.areItemStackTagsEqual(itemStack1, itemStack2); }
Example 18
Source File: ItemStackKey.java From GregTech with GNU Lesser General Public License v3.0 | 4 votes |
public boolean isItemStackEqual(ItemStack itemStack) { return ItemStack.areItemsEqual(this.itemStack, itemStack) && ItemStack.areItemStackTagsEqual(this.itemStack, itemStack); }
Example 19
Source File: ItemUtils.java From CodeChickenLib with GNU Lesser General Public License v2.1 | 2 votes |
/** * @param stack1 The {@link ItemStack} being compared. * @param stack2 The {@link ItemStack} to compare to. * @return whether the two items are the same in terms of damage and itemID. */ public static boolean areStacksSameType(@Nonnull ItemStack stack1, @Nonnull ItemStack stack2) { return !stack1.isEmpty() && !stack2.isEmpty() && (stack1.getItem() == stack2.getItem() && (stack2.getDamage() == stack1.getDamage()) && ItemStack.areItemStackTagsEqual(stack2, stack1)); }