Java Code Examples for net.minecraft.item.ItemStack#isItemEqual()

The following examples show how to use net.minecraft.item.ItemStack#isItemEqual() . 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: PLItems.java    From Production-Line with MIT License 6 votes vote down vote up
@Override
public int getBurnTime(ItemStack fuel) {
    if (fuel.isItemEqual(sawdust)) {
        return 50;
    }
    if (fuel.isItemEqual(smallCompressedWaterHyacinth)) {
        return 400;
    }
    if (fuel.getItem().equals(
            Item.getItemFromBlock(PLBlocks.waterHyacinth))) {
        return 100;
    }
    if (fuel.isItemEqual(PLBlocks.compressedWaterHyacinth)) {
        return 800;
    }
    if (fuel.isItemEqual(PLBlocks.dehydratedWaterHyacinthblock)) {
        return 1000;
    }
    return 0;
}
 
Example 2
Source File: Utils.java    From NEI-Integration with MIT License 6 votes vote down vote up
public static List<ItemStack> getItemVariations(ItemStack base) {
    List<ItemStack> variations = new ArrayList<ItemStack>();
    base.getItem().getSubItems(base.getItem(), null, variations);
    Iterator<ItemStack> itr = variations.iterator();
    ItemStack stack;
    while (itr.hasNext()) {
        stack = itr.next();
        if (!base.isItemEqual(stack) || !stack.hasTagCompound()) {
            itr.remove();
        }
    }
    if (variations.isEmpty()) {
        return Collections.singletonList(base);
    }
    return variations;
}
 
Example 3
Source File: ContainerPneumaticBase.java    From PneumaticCraft with GNU General Public License v3.0 5 votes vote down vote up
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 4
Source File: TileChemicalReactor.java    From AdvancedRocketry with MIT License 5 votes vote down vote up
public void consumeItemsSpecial(IRecipe recipe) {
	List<List<ItemStack>> ingredients = recipe.getIngredients();

	for(int ingredientNum = 0;ingredientNum < ingredients.size(); ingredientNum++) {

		List<ItemStack> ingredient = ingredients.get(ingredientNum);

		ingredientCheck:
		for(IInventory hatch : itemInPorts) {
			for(int i = 0; i < hatch.getSizeInventory(); i++) {
				ItemStack stackInSlot = hatch.getStackInSlot(i);
				for (ItemStack stack : ingredient) {
					if(stackInSlot != null && stackInSlot.getCount() >= stack.getCount() && stackInSlot.isItemEqual(stack)) {
						ItemStack stack2 = hatch.decrStackSize(i, stack.getCount());
						
						if(stack2.getItem() instanceof ItemArmor)
						{
							stack2.addEnchantment(AdvancedRocketryAPI.enchantmentSpaceProtection, 1);
							List<ItemStack> list = new LinkedList<ItemStack>();
							list.add(stack2);
							setOutputs(list);
						}
						
						hatch.markDirty();
						world.notifyBlockUpdate(pos, world.getBlockState(((TileEntity)hatch).getPos()),  world.getBlockState(((TileEntity)hatch).getPos()), 6);
						break ingredientCheck;
					}
				}
			}
		}
	}
}
 
Example 5
Source File: PLEvent.java    From Production-Line with MIT License 5 votes vote down vote up
@SubscribeEvent
public void onEntityThrowableImpact(EntityThrowableImpactEvent event) {
    Optional<ItemStack> optItemStack = event.entityThrownItem.getThrowItem();
    if (!optItemStack.isPresent()) {
        return;
    }
    ItemStack stack = optItemStack.get();
    if (stack.getItem().equals(PLItems.packagedSalt)) {
        for (int i = 0; i < 8; ++i) {
            float fmod = (float) (1.2 - (Math.random() * 2.4));
            float f1mod = (float) (0.5 - (Math.random() * 1.0));
            float f2mod = (float) (1.2 - (Math.random() * 2.4));

            event.entityThrownItem.world.spawnParticle(EnumParticleTypes.ITEM_CRACK,
                    event.entityThrownItem.posX + fmod, event.entityThrownItem.posY + f1mod,
                    event.entityThrownItem.posZ + f2mod, 0.1D, 0.1D, 0.1D, Item.getIdFromItem(PLItems.salt));

            if (!event.entityThrownItem.world.isRemote) {
                EntityItem entityItem = new EntityItem(event.entityThrownItem.world,
                        event.entityThrownItem.posX + fmod, event.entityThrownItem.posY + f1mod,
                        event.entityThrownItem.posZ + f2mod, new ItemStack(PLItems.salt));
                event.entityThrownItem.world.spawnEntity(entityItem);
            }
        }
        this.onImpact(event.entityThrownItem, event.movingObjectPosition, new PotionEffect(PLPotion.salty, 0, 3));
    } else if (stack.isItemEqual(IC2Items.getItem("Uran238"))) {
        this.onImpact(event.entityThrownItem, event.movingObjectPosition, new PotionEffect(IC2Potion.radiation, 200, 0));
    } else {
        this.onImpact(event.entityThrownItem, event.movingObjectPosition, null);
    }
}
 
Example 6
Source File: ContainerManager.java    From CraftingKeys with MIT License 5 votes vote down vote up
/**
 * Calculates the next fitting or free inventory slot.
 *
 * @param stackToMove The ItemType and sized Stack to move
 * @return A super cool inventory slot index! Or -1, if you are to dumb
 * to keep your bloody inventory sorted! WHY U NO USE INV TWEAKS?!
 */
private int calcInventoryDestination(ItemStack stackToMove) {

    // First run: Try to find a nice stack to put items on additionally
    for (int i = getInventoryStartIndex(); i < container.inventorySlots.size(); i++) {

        ItemStack potentialGoalStack = getItemStack(i);

        if (potentialGoalStack != null && stackToMove != null) {
            if (potentialGoalStack.isItemEqual(stackToMove)) {
                if (potentialGoalStack.getCount() + stackToMove.getCount() <= stackToMove.getMaxStackSize()) {
                    return i;
                }
            }
        }
    }

    // Second run: Find a free slot
    for (int i = getInventoryStartIndex(); i < container.inventorySlots.size(); i++) {
        if (getItemStack(i) == null) {
            return i;
        }
    }

    // Third run: No slot found. Drop this shit!
    return -1;

}
 
Example 7
Source File: ContainerBase.java    From Signals with GNU General Public License v3.0 5 votes vote down vote up
public boolean canStacksMerge(ItemStack stack1, ItemStack stack2){

        if(stack1.isEmpty() || stack2.isEmpty()) return false;
        if(!stack1.isItemEqual(stack2)) return false;
        if(!ItemStack.areItemStackTagsEqual(stack1, stack2)) return false;
        return true;

    }
 
Example 8
Source File: IStructure.java    From Wizardry with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Deprecated
static ItemStack findItemInventoryFromItem(EntityPlayer player, ItemStack toFind) {
	ItemStack stack = ItemStack.EMPTY;
	for (ItemStack invStack : player.inventory.mainInventory)
		if (!invStack.isEmpty()
				&& invStack.isItemEqual(toFind)) {
			stack = invStack;
			break;
		}
	return stack;
}
 
Example 9
Source File: ItemHelper.java    From customstuff4 with GNU General Public License v3.0 5 votes vote down vote up
public static boolean isSameStackForFuel(ItemStack fuel, ItemStack stack)
{
    boolean itemEqual = stack.getMetadata() == OreDictionary.WILDCARD_VALUE
                        ? fuel.isItemEqualIgnoreDurability(stack)
                        : fuel.isItemEqual(stack);

    boolean nbtEqual = !stack.hasTagCompound() || ItemStack.areItemStackTagsEqual(stack, fuel);

    return itemEqual && nbtEqual;
}
 
Example 10
Source File: SimpleItemFilter.java    From GregTech with GNU Lesser General Public License v3.0 5 votes vote down vote up
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 11
Source File: SemiBlockHeatFrame.java    From PneumaticCraft with GNU General Public License v3.0 5 votes vote down vote up
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 12
Source File: MultiblockReactorSimulator.java    From reactor_simulator with MIT License 5 votes vote down vote up
/**
 * Attempt to distribute a stack of ingots to a given access port, sensitive to the amount and type of ingots already in it.
 * @param port The port to which we're distributing ingots.
 * @param itemsToDistribute The stack of ingots to distribute. Will be modified during the operation and may be returned with stack size 0.
 * @param distributeToInputs Should we try to send ingots to input ports?
 * @return The number of waste items distributed, i.e. the differential in stack size for wasteToDistribute.
 */
private int tryDistributeItems(TileEntityReactorAccessPort port, ItemStack itemsToDistribute, boolean distributeToInputs) {
  ItemStack existingStack = port.getStackInSlot(TileEntityReactorAccessPort.SLOT_OUTLET);
  int initialWasteAmount = itemsToDistribute.stackSize;
  if (!port.isInlet() || (distributeToInputs || attachedAccessPorts.size() < 2)) {
    // Dump waste preferentially to outlets, unless we only have one access port
    if (existingStack == null) {
      if (itemsToDistribute.stackSize > port.getInventoryStackLimit()) {
        ItemStack newStack = itemsToDistribute.splitStack(port.getInventoryStackLimit());
        port.setInventorySlotContents(TileEntityReactorAccessPort.SLOT_OUTLET, newStack);
      } else {
        port.setInventorySlotContents(TileEntityReactorAccessPort.SLOT_OUTLET, itemsToDistribute.copy());
        itemsToDistribute.stackSize = 0;
      }
    } else if (existingStack.isItemEqual(itemsToDistribute)) {
      if (existingStack.stackSize + itemsToDistribute.stackSize <= existingStack.getMaxStackSize()) {
        existingStack.stackSize += itemsToDistribute.stackSize;
        itemsToDistribute.stackSize = 0;
      } else {
        int amt = existingStack.getMaxStackSize() - existingStack.stackSize;
        itemsToDistribute.stackSize -= existingStack.getMaxStackSize() - existingStack.stackSize;
        existingStack.stackSize += amt;
      }
    }

    port.onItemsReceived();
  }

  return initialWasteAmount - itemsToDistribute.stackSize;
}
 
Example 13
Source File: TileEntityTFOven.java    From TofuCraftReload with MIT License 5 votes vote down vote up
@Override
public boolean canWork() {
    if (energy >= POWER) { //If energy is suitable
        if (((ItemStack) this.inventory.get(0)).isEmpty()) {
            return false;
        } else {
            ItemStack itemstack = FurnaceRecipes.instance().getSmeltingResult(this.inventory.get(0));

            if (itemstack.isEmpty()) {
                return false;
            } else {
                ItemStack itemstack1 = this.inventory.get(1);

                if (itemstack1.isEmpty()) {
                    return true;
                } else if (!itemstack1.isItemEqual(itemstack)) {
                    return false;
                } else if (itemstack1.getCount() + itemstack.getCount() <= this.getInventoryStackLimit() && itemstack1.getCount() + itemstack.getCount() <= itemstack1.getMaxStackSize())  // Forge fix: make furnace respect stack sizes in furnace recipes
                {
                    return true;
                } else {
                    return itemstack1.getCount() + itemstack.getCount() <= itemstack.getMaxStackSize(); // Forge fix: make furnace respect stack sizes in furnace recipes
                }
            }
        }
    }
    return false;
}
 
Example 14
Source File: TileEntityTFCrasher.java    From TofuCraftReload with MIT License 5 votes vote down vote up
@Override
public boolean canWork() {
    if (energy >= POWER) { //If energy is suitable
        if (((ItemStack) this.inventory.get(0)).isEmpty()) {
            return false;
        } else {
            ItemStack itemstack = CrasherRecipes.getResult(this.inventory.get(0));

            if (itemstack.isEmpty()) {
                return false;
            } else {
                ItemStack itemstack1 = this.inventory.get(1);

                if (itemstack1.isEmpty()) {
                    return true;
                } else if (!itemstack1.isItemEqual(itemstack)) {
                    return false;
                } else if (itemstack1.getCount() + itemstack.getCount() <= this.getInventoryStackLimit() && itemstack1.getCount() + itemstack.getCount() <= itemstack1.getMaxStackSize())  // Forge fix: make furnace respect stack sizes in furnace recipes
                {
                    return true;
                } else {
                    return itemstack1.getCount() + itemstack.getCount() <= itemstack.getMaxStackSize(); // Forge fix: make furnace respect stack sizes in furnace recipes
                }
            }
        }
    }
    return false;
}
 
Example 15
Source File: AssemblyProgram.java    From PneumaticCraft with GNU General Public License v3.0 4 votes vote down vote up
public static boolean isValidInput(AssemblyRecipe recipe, ItemStack input){
    return input != null && (input.isItemEqual(recipe.getInput()) || PneumaticCraftUtils.isSameOreDictStack(input, recipe.getInput())) && input.stackSize == recipe.getInput().stackSize;
}
 
Example 16
Source File: ItemVanillaDrill.java    From Electro-Magic-Tools with GNU General Public License v3.0 4 votes vote down vote up
@Override
public boolean getIsRepairable(ItemStack stack1, ItemStack stack2) {
    return stack2.isItemEqual(repairMaterial) ? true : super.getIsRepairable(stack1, stack2);
}
 
Example 17
Source File: ItemMorphAxe.java    From ForbiddenMagic with Do What The F*ck You Want To Public License 4 votes vote down vote up
public boolean getIsRepairable(ItemStack stack, ItemStack stack2) {
    return stack2.isItemEqual(new ItemStack(ForbiddenItems.deadlyShards, 1, 1)) ? true : super.getIsRepairable(stack, stack2);
}
 
Example 18
Source File: ItemMorphPickaxe.java    From ForbiddenMagic with Do What The F*ck You Want To Public License 4 votes vote down vote up
@Override
public boolean getIsRepairable(ItemStack stack, ItemStack stack2) {
    return stack2.isItemEqual(new ItemStack(ForbiddenItems.deadlyShards, 1, 1)) ? true : super.getIsRepairable(stack, stack2);
}
 
Example 19
Source File: SemiBlockLogistics.java    From PneumaticCraft with GNU General Public License v3.0 4 votes vote down vote up
protected boolean isItemEqual(ItemStack s1, ItemStack s2){
    return s1.isItemEqual(s2);
}
 
Example 20
Source File: RecipePetals.java    From ForbiddenMagic with Do What The F*ck You Want To Public License 4 votes vote down vote up
public boolean matches(IInventory inv) {
	List<Object> inputsMissing = new ArrayList(inputs);

	for(int i = 0; i < inv.getSizeInventory(); i++) {
		ItemStack stack = inv.getStackInSlot(i);
		if(stack == null)
			break;

		int stackIndex = -1, oredictIndex = -1;

		for(int j = 0; j < inputsMissing.size(); j++) {
			Object input = inputsMissing.get(j);
			if(input instanceof String) {
				List<ItemStack> validStacks = OreDictionary.getOres((String) input);
				boolean found = false;
				for(ItemStack ostack : validStacks) {
					ItemStack cstack = ostack.copy();
					if(cstack.getItemDamage() == Short.MAX_VALUE)
						cstack.setItemDamage(stack.getItemDamage());

					if(stack.isItemEqual(cstack)) {
						oredictIndex = j;
						found = true;
						break;
					}
				}


				if(found)
					break;
			} else if(input instanceof ItemStack && simpleAreStacksEqual((ItemStack) input, stack)) {
				stackIndex = j;
				break;
			}
		}

		if(stackIndex != -1)
			inputsMissing.remove(stackIndex);
		else if(oredictIndex != -1)
			inputsMissing.remove(oredictIndex);
		else return false;
	}

	return inputsMissing.isEmpty();
}