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

The following examples show how to use net.minecraft.item.ItemStack#areItemStacksEqual() . 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: ModHandler.java    From GregTech with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Removes a Smelting Recipe
 */
public static boolean removeFurnaceSmelting(ItemStack input) {
    if (input.isEmpty()) {
        GTLog.logger.error("Cannot remove furnace recipe with empty input.");
        GTLog.logger.error("Stacktrace:", new IllegalArgumentException());
        RecipeMap.setFoundInvalidRecipe(true);
        return false;
    }
    for (ItemStack stack : FurnaceRecipes.instance().getSmeltingList().keySet()) {
        if (ItemStack.areItemStacksEqual(input, stack)) {
            FurnaceRecipes.instance().getSmeltingList().remove(stack);
            return true;
        }
    }
    return false;
}
 
Example 2
Source File: MetaTileEntity.java    From GregTech with GNU Lesser General Public License v3.0 6 votes vote down vote up
public boolean fillInternalTankFromFluidContainer(IItemHandlerModifiable importItems, IItemHandlerModifiable exportItems, int inputSlot, int outputSlot) {
    ItemStack inputContainerStack = importItems.extractItem(inputSlot, 1, true);
    FluidActionResult result = FluidUtil.tryEmptyContainer(inputContainerStack, importFluids, Integer.MAX_VALUE, null, false);
    if (result.isSuccess()) {
        ItemStack remainingItem = result.getResult();
        if (ItemStack.areItemStacksEqual(inputContainerStack, remainingItem))
            return false; //do not fill if item stacks match
        if (!remainingItem.isEmpty() && !exportItems.insertItem(outputSlot, remainingItem, true).isEmpty())
            return false; //do not fill if can't put remaining item
        FluidUtil.tryEmptyContainer(inputContainerStack, importFluids, Integer.MAX_VALUE, null, true);
        importItems.extractItem(inputSlot, 1, false);
        exportItems.insertItem(outputSlot, remainingItem, false);
        return true;
    }
    return false;
}
 
Example 3
Source File: MetaItem.java    From GregTech with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public EnumActionResult onItemUse(EntityPlayer player, World world, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
    ItemStack stack = player.getHeldItem(hand);
    ItemStack originalStack = stack.copy();
    for (IItemBehaviour behaviour : getBehaviours(stack)) {
        ActionResult<ItemStack> behaviourResult = behaviour.onItemUse(player, world, pos, hand, facing, hitX, hitY, hitZ);
        stack = behaviourResult.getResult();
        if (behaviourResult.getType() != EnumActionResult.PASS) {
            if (!ItemStack.areItemStacksEqual(originalStack, stack))
                player.setHeldItem(hand, stack);
            return behaviourResult.getType();
        } else if (stack.isEmpty()) {
            player.setHeldItem(hand, ItemStack.EMPTY);
            return EnumActionResult.PASS;
        }
    }
    return EnumActionResult.PASS;
}
 
Example 4
Source File: ContainerAutoChisel.java    From Chisel-2 with GNU General Public License v2.0 6 votes vote down vote up
@Override
public ItemStack slotClick(int slotId, int p_75144_2_, int p_75144_3_, EntityPlayer player) {
	if (slotId >= 0 && slotId < this.inventorySlots.size()) {
		Slot slot = (Slot) this.inventorySlots.get(slotId);
		ItemStack stack = slot.getStack();
		ItemStack ret = super.slotClick(slotId, p_75144_2_, p_75144_3_, player);

		if (!player.worldObj.isRemote && slot.slotNumber == TileEntityAutoChisel.BASE && !ItemStack.areItemStacksEqual(stack, slot.getStack())) {
			int chiseled = stack == null ? 0 : slot.getStack() == null ? stack.stackSize : stack.stackSize - slot.getStack().stackSize;
			PacketHandler.INSTANCE.sendToDimension(new MessageAutoChisel(autoChisel, chiseled, false, false), player.worldObj.provider.dimensionId);
		}

		return ret;
	}
	return super.slotClick(slotId, p_75144_2_, p_75144_3_, player);
}
 
Example 5
Source File: RecipeSteroidSyringe.java    From Wizardry with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public boolean matches(@Nonnull InventoryCrafting inv, @Nonnull World worldIn) {
	boolean foundSyringe = false;
	boolean foundMana = false;
	boolean foundNacre = false;
	boolean foundLava = false;
	boolean foundDevilDust = false;

	ItemStack mana = FluidUtil.getFilledBucket(new FluidStack(ModFluids.MANA.getActual(), 1));
	ItemStack nacre = FluidUtil.getFilledBucket(new FluidStack(ModFluids.NACRE.getActual(), 1));

	for (int i = 0; i < inv.getSizeInventory(); i++) {
		ItemStack stack = inv.getStackInSlot(i);
		if (stack.getItem() == ModItems.SYRINGE && stack.getItemDamage() == 0) foundSyringe = true;
		if (ItemStack.areItemStacksEqual(mana, stack)) foundMana = true;
		if (ItemStack.areItemStacksEqual(nacre, stack)) foundNacre = true;
		if (stack.getItem() == Items.LAVA_BUCKET) foundLava = true;
		if (stack.getItem() == ModItems.DEVIL_DUST) foundDevilDust = true;
	}
	return foundSyringe && foundMana && foundDevilDust && foundLava && foundNacre;
}
 
Example 6
Source File: RecipeManaSyringe.java    From Wizardry with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public boolean matches(@Nonnull InventoryCrafting inv, @Nonnull World worldIn) {
	boolean foundSyringe = false;
	boolean foundMana = false;

	ItemStack bucket = FluidUtil.getFilledBucket(new FluidStack(ModFluids.MANA.getActual(), 1));

	for (int i = 0; i < inv.getSizeInventory(); i++) {
		ItemStack stack = inv.getStackInSlot(i);
		if (stack.getItem() == ModItems.SYRINGE && stack.getItemDamage() == 0) {
			foundSyringe = true;
		} else if (stack.getItem() == ModItems.ORB && ManaManager.isManaFull(stack)) {
			foundMana = true;
		} else if (ItemStack.areItemStacksEqual(bucket, stack))
			foundMana = true;
	}
	return foundSyringe && foundMana;
}
 
Example 7
Source File: HaloInfusionItemRegistry.java    From Wizardry with GNU Lesser General Public License v3.0 5 votes vote down vote up
public static boolean isHaloInfusionItem(ItemStack stack) {
	if (stack.isEmpty()) return false;
	for (HaloInfusionItem item : items) {
		if (ItemStack.areItemStacksEqual(stack, item.getStack())) return true;
	}
	return false;
}
 
Example 8
Source File: StatementParameterItemStack.java    From Framez with GNU General Public License v3.0 5 votes vote down vote up
@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 9
Source File: GuiEnchantment.java    From Et-Futurum with The Unlicense 5 votes vote down vote up
public void func_147068_g() {
	ItemStack var1 = inventorySlots.getSlot(0).getStack();

	if (!ItemStack.areItemStacksEqual(var1, field_147077_B)) {
		field_147077_B = var1;

		do
			field_147082_x += field_147074_F.nextInt(4) - field_147074_F.nextInt(4);
		while (field_147071_v <= field_147082_x + 1.0F && field_147071_v >= field_147082_x - 1.0F);
	}

	++field_147073_u;
	field_147069_w = field_147071_v;
	field_147076_A = field_147080_z;
	boolean var2 = false;

	for (int var3 = 0; var3 < 3; ++var3)
		if (field_147075_G.enchantLevels[var3] != 0)
			var2 = true;

	if (var2)
		field_147080_z += 0.2F;
	else
		field_147080_z -= 0.2F;

	field_147080_z = MathHelper.clamp_float(field_147080_z, 0.0F, 1.0F);
	float var5 = (field_147082_x - field_147071_v) * 0.4F;
	float var4 = 0.2F;
	var5 = MathHelper.clamp_float(var5, -var4, var4);
	field_147081_y += (var5 - field_147081_y) * 0.9F;
	field_147071_v += field_147081_y;
}
 
Example 10
Source File: ECPrivatePatternInventory.java    From ExtraCells1 with MIT License 5 votes vote down vote up
public boolean doesRecipeExist(ICraftingPatternMAC pattern)
{
	InventoryCrafting inv = new InventoryCrafting(new ContainerWorkbench(new InventoryPlayer(null), gridTE.getWorld(), 0, 0, 0)
	{
		public void onCraftMatrixChanged(IInventory par1IInventory)
		{
		}
	}, 3, 3);
	for (int i = 0; i < pattern.getCraftingMatrix().length; i++)
	{
		inv.setInventorySlotContents(i, pattern.getCraftingMatrix()[i]);
	}
	ItemStack thing = CraftingManager.getInstance().findMatchingRecipe(inv, gridTE.getWorld());
	return ItemStack.areItemStacksEqual(thing, pattern.getOutput());
}
 
Example 11
Source File: ItemDropChecker.java    From SkyblockAddons with MIT License 5 votes vote down vote up
/**
 * Checks if the player has confirmed that they want to drop the given item stack.
 * The player confirms that they want to drop the item when they try to drop it the number of
 * times specified in {@code numberOfActions}
 *
 * @param item the item stack the player is attempting to drop
 * @param numberOfActions the number of times the player has to drop the item to confirm
 * @return {@code true} if the player has dropped the item enough
 */
public boolean dropConfirmed(ItemStack item, int numberOfActions) {
    logger.entry(item, numberOfActions);

    if (item == null) {
        logger.throwing(new NullPointerException("Item cannot be null!"));
    }
    else if (numberOfActions < 2) {
        logger.throwing(new IllegalArgumentException("At least two attempts are required."));
    }

    // If there's no drop confirmation active, set up a new one.
    if (itemOfLastDropAttempt == null) {
        itemOfLastDropAttempt = item;
        timeOfLastDropAttempt = Minecraft.getSystemTime();
        attemptsRequiredToConfirm = numberOfActions - 1;
        onDropConfirmationFail();
        return logger.exit(false);
    }
    else {
        long DROP_CONFIRMATION_TIMEOUT = 3000L;

        // Reset the current drop confirmation on time out or if the item being dropped changes.
        if (Minecraft.getSystemTime() - timeOfLastDropAttempt > DROP_CONFIRMATION_TIMEOUT ||
                !ItemStack.areItemStacksEqual(item, itemOfLastDropAttempt)) {
            resetDropConfirmation();
            return dropConfirmed(item, numberOfActions);
        }
        else {
            if (attemptsRequiredToConfirm >= 1) {
                onDropConfirmationFail();
                return logger.exit(false);
            }
            else {
                resetDropConfirmation();
                return logger.exit(true);
            }
        }
    }
}
 
Example 12
Source File: HaloInfusionItemRegistry.java    From Wizardry with GNU Lesser General Public License v3.0 5 votes vote down vote up
public static HaloInfusionItem getInfusionItemFromStack(ItemStack stack) {
	if (stack.isEmpty()) return EMPTY;
	for (HaloInfusionItem item : items) {
		if (ItemStack.areItemStacksEqual(stack, item.getStack())) return item;
	}
	return EMPTY;
}
 
Example 13
Source File: GTHelperStack.java    From GT-Classic with GNU Lesser General Public License v3.0 5 votes vote down vote up
/** removing smelting recipes code by Muramasa **/
public static void removeSmelting(ItemStack resultStack) {
	ItemStack recipeResult;
	Map<ItemStack, ItemStack> recipes = FurnaceRecipes.instance().getSmeltingList();
	Iterator<ItemStack> iterator = recipes.keySet().iterator();
	while (iterator.hasNext()) {
		ItemStack tmpRecipe = iterator.next();
		recipeResult = recipes.get(tmpRecipe);
		if (ItemStack.areItemStacksEqual(resultStack, recipeResult)) {
			iterator.remove();
		}
	}
}
 
Example 14
Source File: MemorizedRecipeWidget.java    From GregTech with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void detectAndSendChanges() {
    super.detectAndSendChanges();
    MemorizedRecipe recipe = recipeMemory.getRecipeAtIndex(recipeIndex);
    ItemStack resultStack = recipe == null ? ItemStack.EMPTY : recipe.getRecipeResult();
    if (!ItemStack.areItemStacksEqual(resultStack, slotReference.getStack())) {
        slotReference.putStack(resultStack);
        uiAccess.sendSlotUpdate(this);
    }
    boolean recipeLocked = recipe != null && recipe.isRecipeLocked();
    if (this.recipeLocked != recipeLocked) {
        this.recipeLocked = recipeLocked;
        writeUpdateInfo(1, buf -> buf.writeBoolean(recipeLocked));
    }
}
 
Example 15
Source File: CachedRecipeData.java    From GregTech with GNU Lesser General Public License v3.0 5 votes vote down vote up
private boolean getIngredientEquivalent(int slot) {
    ItemStack currentStack = inventory.getStackInSlot(slot);
    if (currentStack.isEmpty()) {
        return true; //stack is empty, nothing to return
    }
    ItemStackKey currentStackKey = new ItemStackKey(currentStack);
    if (simulateExtractItem(currentStackKey)) {
        //we can extract ingredient equal to the one in the crafting grid,
        //so just return it without searching equivalent
        return true;
    }
    //iterate stored items to find equivalent
    for (ItemStackKey itemStackKey : itemSourceList.getStoredItems()) {
        ItemStack itemStack = itemStackKey.getItemStack();
        //update item in slot, and check that recipe matches and output item is equal to the expected one
        inventory.setInventorySlotContents(slot, itemStack);
        if (recipe.matches(inventory, itemSourceList.getWorld()) &&
            ItemStack.areItemStacksEqual(expectedOutput, recipe.getCraftingResult(inventory))) {
            //ingredient matched, attempt to extract it and return if successful
            if (simulateExtractItem(itemStackKey)) {
                return true;
            }
        }
    }
    //nothing matched, so return null
    return false;
}
 
Example 16
Source File: MetaItem.java    From GregTech with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public boolean shouldCauseReequipAnimation(ItemStack oldStack, ItemStack newStack, boolean slotChanged) {
    //if item is equal, and old item has electric item capability, remove charge tags to stop reequip animation when charge is altered
    if(ItemStack.areItemsEqual(oldStack, newStack) && oldStack.hasCapability(GregtechCapabilities.CAPABILITY_ELECTRIC_ITEM, null) &&
        oldStack.hasTagCompound() && newStack.hasTagCompound()) {
        oldStack = oldStack.copy();
        newStack = newStack.copy();
        oldStack.getTagCompound().removeTag("Charge");
        newStack.getTagCompound().removeTag("Charge");
    }
    return !ItemStack.areItemStacksEqual(oldStack, newStack);
}
 
Example 17
Source File: ContainerEnderUtilities.java    From enderutilities with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void detectAndSendChanges()
{
    if (this.isClient == false)
    {
        for (int slot = 0; slot < this.inventorySlots.size(); slot++)
        {
            ItemStack currentStack = this.inventorySlots.get(slot).getStack();
            ItemStack prevStack = this.inventoryItemStacks.get(slot);

            if (ItemStack.areItemStacksEqual(prevStack, currentStack) == false)
            {
                prevStack = currentStack.isEmpty() ? ItemStack.EMPTY : currentStack.copy();
                this.inventoryItemStacks.set(slot, prevStack);

                for (int i = 0; i < this.listeners.size(); i++)
                {
                    IContainerListener listener = this.listeners.get(i);

                    if (listener instanceof EntityPlayerMP)
                    {
                        PacketHandler.INSTANCE.sendTo(new MessageSyncSlot(this.windowId, slot, prevStack), (EntityPlayerMP) listener);
                    }
                }
            }
        }
    }
}
 
Example 18
Source File: ItemHandyBag.java    From enderutilities with GNU Lesser General Public License v3.0 4 votes vote down vote up
private void updateItems(ItemStack bagStack, World world, Entity entity, int bagSlot)
{
    if (entity instanceof EntityPlayer)
    {
        EntityPlayer player = (EntityPlayer) entity;
        InventoryItemModular bagInv = getInventoryForBag(bagStack, player);

        if (bagInv != null && player.inventory.getStackInSlot(bagSlot) == bagStack)
        {
            int moduleSlot = bagInv.getSelectedModuleIndex();

            if (moduleSlot >= 0)
            {
                ItemStack cardStack = bagInv.getModuleInventory().getStackInSlot(moduleSlot);

                if (cardStack.isEmpty() == false)
                {
                    // Try to find an empty slot in the player's inventory, for temporarily moving the updated item to
                    int tmpSlot = InventoryUtils.getFirstEmptySlot(new PlayerMainInvWrapperNoSync(player.inventory));
                    long[] masks = new long[] { 0x1FFFFFFL, 0x1FFF8000000L, 0x7FFE0000000000L };
                    long mask = NBTUtils.getLong(cardStack, "HandyBag", "UpdateMask");
                    int numSections = bagStack.getMetadata() == 1 ? 3 : 1;
                    int invSize = bagInv.getSlots();

                    // If there were no empty slots, then we use the bag's slot instead... risky!
                    if (tmpSlot == -1)
                    {
                        tmpSlot = bagSlot;
                    }

                    ItemStack stackInTmpSlot = player.inventory.getStackInSlot(tmpSlot);
                    boolean isCurrentItem = tmpSlot == player.inventory.currentItem;

                    for (int section = 0; section < numSections; section++)
                    {
                        if ((mask & masks[section]) != 0)
                        {
                            SlotRange range = getSlotRangeForSection(section);

                            for (int slot = range.first; slot < range.lastExc && slot < invSize; slot++)
                            {
                                if ((mask & (1L << slot)) != 0)
                                {
                                    ItemStack stackTmp = bagInv.getStackInSlot(slot);

                                    if (stackTmp.isEmpty() == false)
                                    {
                                        ItemStack stackOrig = stackTmp.copy();
                                        // Temporarily move the item-being-updated into the temporary slot in the player's inventory
                                        player.inventory.setInventorySlotContents(tmpSlot, stackTmp);

                                        try
                                        {
                                            stackTmp.updateAnimation(world, entity, tmpSlot, isCurrentItem);
                                        }
                                        catch (Throwable t)
                                        {
                                            EnderUtilities.logger.warn("Exception while updating items inside a Handy Bag!", t);
                                        }

                                        // The stack changed while being updated, write it back to the bag's inventory
                                        if (ItemStack.areItemStacksEqual(stackTmp, stackOrig) == false)
                                        {
                                            bagInv.setStackInSlot(slot, stackTmp.isEmpty() ? ItemStack.EMPTY : stackTmp);
                                        }
                                    }
                                }
                            }
                        }
                    }

                    // Restore the Handy Bag into the original slot it was in
                    player.inventory.setInventorySlotContents(tmpSlot, stackInTmpSlot);
                }
            }
        }
    }
}
 
Example 19
Source File: ItemEnderUtilities.java    From enderutilities with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public boolean shouldCauseReequipAnimation(ItemStack oldStack, ItemStack newStack, boolean slotChanged)
{
    return slotChanged || ItemStack.areItemStacksEqual(oldStack, newStack) == false;
}
 
Example 20
Source File: ModuleEffectExtract.java    From Wizardry with GNU Lesser General Public License v3.0 3 votes vote down vote up
private static boolean shouldContinue(Entity caster, EntityLivingBase target, ItemStack stack) {
	if (!(caster instanceof EntityLivingBase)) return true;

	ItemStack held = ((EntityLivingBase) caster).getHeldItemMainhand();

	return !target.getUniqueID().equals(caster.getUniqueID()) || !ItemStack.areItemStacksEqual(held, stack);
}