Java Code Examples for net.minecraft.item.ItemStack.isEmpty()

The following are Jave code examples for showing how to use isEmpty() of the net.minecraft.item.ItemStack class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: pnc-repressurized   File: SemiBlockRequester.java   View Source Code Vote up 6 votes
@Override
public int amountRequested(ItemStack stack) {
    int totalRequestingAmount = getTotalRequestedAmount(stack);
    if (totalRequestingAmount > 0) {
        IItemHandler inv = IOHelper.getInventoryForTE(getTileEntity());
        int count = 0;
        if (inv != null) {
            for (int i = 0; i < inv.getSlots(); i++) {
                ItemStack s = inv.getStackInSlot(i);
                if (!s.isEmpty() && isItemEqual(s, stack)) {
                    count += s.getCount();
                }
            }
            count += getIncomingItems(stack);
            return Math.max(0, Math.min(stack.getCount(), totalRequestingAmount - count));
        }
    }
    return 0;
}
 
Example 2
Project: pnc-repressurized   File: TileEntityProgrammer.java   View Source Code Vote up 6 votes
@Override
public void handleGUIButtonPress(int buttonID, EntityPlayer player) {
    switch (buttonID) {
        case 0:
            if (++redstoneMode > 1) redstoneMode = 0;
            break;
        case 1:
            ItemStack stack = inventory.getStackInSlot(PROGRAM_SLOT);
            NBTTagCompound tag = stack.isEmpty() ? null : stack.getTagCompound();
            if (tag != null)
                readProgWidgetsFromNBT(tag);
            else
                progWidgets.clear();
            break;
        case 2:
            tryProgramDrone(player);
            break;
        case 9:
            undo();
            break;
        case 10:
            redo();
            break;
    }
    sendDescriptionPacket();
}
 
Example 3
Project: Industrial-Foregoing   File: BlackHoleUnitTile.java   View Source Code Vote up 6 votes
@Nonnull
@Override
public ItemStack extractItem(int slot, int amount, boolean simulate) {
    if (amount == 0) return ItemStack.EMPTY;
    ItemStack existing = tile.getItemStack().copy();
    if (existing.isEmpty()) return ItemStack.EMPTY;
    if (tile.getAmount() <= amount) {
        int newAmount = tile.getAmount();
        if (!simulate) {
            tile.setAmount(0);
            outItems.setStackInSlot(0, ItemStack.EMPTY);
        }
        return ItemHandlerHelper.copyStackWithSize(existing, newAmount);
    } else {
        if (!simulate) {
            tile.setAmount(tile.amount - amount);
        }
        return ItemHandlerHelper.copyStackWithSize(existing, amount);
    }
}
 
Example 4
Project: Metalworks   File: Util.java   View Source Code Vote up 6 votes
@SideOnly(Side.CLIENT)
public static void renderItemInWorld(ItemStack stack){
    if(!stack.isEmpty()){
        Minecraft mc = Minecraft.getMinecraft();
        RenderItem renderer = mc.getRenderItem();
        TextureManager manager = mc.getTextureManager();

        IBakedModel model = renderer.getItemModelWithOverrides(stack, null, null);

        manager.bindTexture(TextureMap.LOCATION_BLOCKS_TEXTURE);
        manager.getTexture(TextureMap.LOCATION_BLOCKS_TEXTURE).setBlurMipmap(false, false);
        GlStateManager.enableRescaleNormal();
        GlStateManager.enableBlend();
        GlStateManager.pushMatrix();
        model = ForgeHooksClient.handleCameraTransforms(model, ItemCameraTransforms.TransformType.FIXED, false);
        renderer.renderItem(stack, model);
        GlStateManager.cullFace(GlStateManager.CullFace.BACK);
        GlStateManager.popMatrix();
        GlStateManager.disableRescaleNormal();
        GlStateManager.disableBlend();
        manager.bindTexture(TextureMap.LOCATION_BLOCKS_TEXTURE);
        manager.getTexture(TextureMap.LOCATION_BLOCKS_TEXTURE).restoreLastBlurMipmap();
    }
}
 
Example 5
Project: morefurnaces   File: TileEntityIronFurnace.java   View Source Code Vote up 6 votes
/**
 * Returns true if the furnace can smelt an item, i.e. has a source item, destination stack isn't full, etc.
 */
private boolean canSmelt(int id)
{
    int inputIndex = type.getFirstInputSlot(id);
    int outputIndex = type.getFirstOutputSlot(id);

    ItemStack input = itemHandler.getStackInSlot(inputIndex);
    ItemStack output = itemHandler.getStackInSlot(outputIndex);

    if (input.isEmpty())
    {
        return false;
    } else
    {
        ItemStack res = FurnaceRecipes.instance().getSmeltingResult(input);
        if (res.isEmpty())
            return false;
        if (output.isEmpty())
            return true;
        if (!output.isItemEqual(res))
            return false;
        int result = output.getCount() + res.getCount();
        return result <= itemHandler.getSlotLimit(outputIndex) && result <= res.getMaxStackSize();
    }
}
 
Example 6
Project: harshencastle   File: HarshenUtils.java   View Source Code Vote up 6 votes
public static ArrayList<Block> getBlocksFromString(String blockName)
{
	ArrayList<Block> blocks = new ArrayList<>();
	if(!HarshenUtils.toArray(Blocks.AIR, null).contains(Block.getBlockFromName(blockName)))
		blocks.add(Block.getBlockFromName(blockName));
	for(ItemStack oreStack : OreDictionary.getOres(blockName))
		if(oreStack.getItem() instanceof ItemBlock)
			blocks.add(((ItemBlock)oreStack.getItem()).getBlock());
	ArrayList<Block> finalBlocks = new ArrayList<>();
	for(Block b : blocks)
	{
		NonNullList<ItemStack> items = NonNullList.create();
		b.getSubBlocks(CreativeTabs.SEARCH, items);
		for(ItemStack stack : items)
			if(!stack.isEmpty())
				finalBlocks.add(Block.getBlockFromItem(stack.getItem()));
			else
				finalBlocks.add(b);
	}
	return finalBlocks;
}
 
Example 7
Project: Loot-Slash-Conquer   File: CustomLootTable.java   View Source Code Vote up 5 votes
@Override
public void fillInventory(IInventory inventory, Random rand, LootContext context)
{
	TileEntityChest chest = (TileEntityChest) inventory;
    CustomLootContext.Builder context$builder = new CustomLootContext.Builder((WorldServer) chest.getWorld());
    context$builder.withChestPos(chest.getPos());
    CustomLootContext customContext = context$builder.build();
	
    List<ItemStack> list = this.generateLootForPools(rand, customContext);
    List<Integer> list1 = this.getEmptySlotsRandomized(inventory, rand);
    this.shuffleItems(list, list1.size(), rand);

    for (ItemStack itemstack : list)
    {
        if (list1.isEmpty())
        {
        	LootSlashConquer.LOGGER.warn("Tried to over-fill a container");
            return;
        }
        
        if (itemstack.isEmpty())
        {
            inventory.setInventorySlotContents(((Integer)list1.remove(list1.size() - 1)).intValue(), ItemStack.EMPTY);
        }
        else
        {
            inventory.setInventorySlotContents(((Integer)list1.remove(list1.size() - 1)).intValue(), itemstack);
        }
    }
}
 
Example 8
Project: PurificatiMagicae   File: GuiTranslationDesk.java   View Source Code Vote up 5 votes
public void updateStatus()
{
    TileEntity te = world.getTileEntity(pos);
    if (te != null && te instanceof TileTranslationDesk)
    {
        TileTranslationDesk ttd = (TileTranslationDesk) te;
        ItemStack stack = ttd.handler.getStackInSlot(0);
        if (panel.translating)
        {
            status = Status.TRANSLATING;
            return;
        }
        entryName = null;
        if (!stack.isEmpty())
        {
            for (Pair<IfEntry, IRSTranslatePapyrus> p : PurMag.INSTANCE.getIfRegistry().getAllResearchableSteps(IRSTranslatePapyrus.class, Minecraft.getMinecraft().player))
            {
                if (p.getRight().isSuitable(stack))
                {
                    this.entryName = p.getLeft().getId();
                    this.stack = stack;
                    status = Status.CAN_TRANSLATE;
                    return;
                }
            }
            status = Status.CANT_TRANSLATE;
            return;
        }
    }
    status = Status.NO_PAPYRUS;
}
 
Example 9
Project: GardenStuff   File: TileBloomeryFurnace.java   View Source Code Vote up 5 votes
@Override
public boolean isEmpty () {
    for (ItemStack stack : furnaceItemStacks) {
        if (!stack.isEmpty())
            return false;
    }

    return true;
}
 
Example 10
Project: Mods   File: ItemFromData.java   View Source Code Vote up 5 votes
public static WeaponData getData(ItemStack stack) {
	WeaponData value = BLANK_DATA;
	if(!stack.isEmpty() && stack.hasCapability(TF2weapons.WEAPONS_DATA_CAP, null)) {
		value=stack.getCapability(TF2weapons.WEAPONS_DATA_CAP, null).inst;
		if (value == BLANK_DATA && stack.hasTagCompound() && MapList.nameToData.containsKey(stack.getTagCompound().getString("Type")))
			value = stack.getCapability(TF2weapons.WEAPONS_DATA_CAP, null).inst = MapList.nameToData.get(stack.getTagCompound().getString("Type"));
	}
	return value;	
}
 
Example 11
Project: pnc-repressurized   File: TileEntityOmnidirectionalHopper.java   View Source Code Vote up 5 votes
protected boolean doImport(int maxItems) {
    boolean success = false;

    // Suck from input inventory
    IItemHandler handler = IOHelper.getInventoryForTE(IOHelper.getNeighbor(this, inputDir));
    if (handler != null) {
        for (int i = 0; i < maxItems; i++) {
            LocatedItemStack extracted = IOHelper.extractOneItem(handler, true);
            if (!extracted.stack.isEmpty()) {
                ItemStack excess = ItemHandlerHelper.insertItem(inventory, extracted.stack, false);
                if (excess.isEmpty()) {
                    handler.extractItem(extracted.slot, 1, false);
                    success = true;
                } else {
                    break;
                }
            } else {
                break;
            }
        }
    }

    // Suck in item entities
    for (EntityItem entity : getNeighborItems(this, inputDir)) {
        if (!entity.isDead) {
            ItemStack remainder = IOHelper.insert(this, entity.getItem(), null, false);
            if (remainder.isEmpty()) {
                entity.setDead();
                success = true;
            }
        }
    }

    return success;
}
 
Example 12
Project: Mods   File: RecipeToScrap.java   View Source Code Vote up 5 votes
@Override
public boolean matches(InventoryCrafting inv, World worldIn) {
	ArrayList<ItemStack> stacks = new ArrayList<>();

	for (int x = 0; x < inv.getSizeInventory(); x++) {
		ItemStack stack = inv.getStackInSlot(x);
		if (!stack.isEmpty())
			if (stacks.size() < 2 && stack.getItem() instanceof ItemFromData && ItemFromData.getData(stack).getInt(PropertyType.COST) >= 6)
				stacks.add(stack);
			else
				return false;
	}
	// System.out.println("matches "+(australium&&stack2!=null));
	return stacks.size() == 2;
}
 
Example 13
Project: ExPetrum   File: PlayerInventoryHelper.java   View Source Code Vote up 5 votes
@SuppressWarnings("SuspiciousNameCombination")
   public static Map<Pair<Integer, Integer>, Boolean> getSlotData(EntityPlayer player)
{
	HashMap<Pair<Integer, Integer>, Boolean> ret = Maps.newHashMap();
	for (int i = 9; i < 36; ++i)
	{
		ItemStack is = player.inventory.getStackInSlot(i);
		if (!is.isEmpty())
		{
			int x = (i - 9) % 9;
			int y = (i - 9) / 9;
			ret.put(Pair.of(x, y), true);
			if (getVolume(is) != defaultVolume)
			{
				Pair<Byte, Byte> volume = getVolume(is);
				for (byte b = 0; b < volume.getLeft(); ++b)
				{
					for (byte b1 = 0; b1 < volume.getRight(); ++b1)
					{
						ret.put(Pair.of(x + b, y + b1), true);
					}
				}
			}
		}
	}
	
	return ret;
}
 
Example 14
Project: MeeCreeps   File: InsertCartridgeFactory.java   View Source Code Vote up 5 votes
/**
 * Returns an Item that is the result of this recipe
 */
@Override
@Nonnull
public ItemStack getCraftingResult(@Nonnull InventoryCrafting var1) {
    ItemStack newOutput = this.output.copy();

    ItemStack cartridge = ItemStack.EMPTY;
    ItemStack portalgun = ItemStack.EMPTY;

    for (int i = 0; i < var1.getSizeInventory(); ++i) {
        ItemStack stack = var1.getStackInSlot(i);

        if (!stack.isEmpty()) {
            if (stack.getItem() instanceof CartridgeItem) {
                cartridge = stack;
            } else if (stack.getItem() instanceof EmptyPortalGunItem) {
                portalgun = stack;
            }
        }
    }

    if (portalgun.hasTagCompound()) {
        newOutput.setTagCompound(portalgun.getTagCompound().copy());
    }
    if (!cartridge.isEmpty()) {
        int charge = CartridgeItem.getCharge(cartridge);
        PortalGunItem.setCharge(newOutput, charge);
    }

    return newOutput;
}
 
Example 15
Project: Loot-Slash-Conquer   File: CustomLootTable.java   View Source Code Vote up 4 votes
/**
 * shuffles items by changing their order and splitting stacks
 */
private void shuffleItems(List<ItemStack> stacks, int p_186463_2_, Random rand)
{
    List<ItemStack> list = Lists.<ItemStack>newArrayList();
    Iterator<ItemStack> iterator = stacks.iterator();

    while (iterator.hasNext())
    {
        ItemStack itemstack = iterator.next();

        if (itemstack.isEmpty())
        {
            iterator.remove();
        }
        else if (itemstack.getCount() > 1)
        {
            list.add(itemstack);
            iterator.remove();
        }
    }

    p_186463_2_ = p_186463_2_ - stacks.size();

    while (p_186463_2_ > 0 && !list.isEmpty())
    {
        ItemStack itemstack2 = list.remove(MathHelper.getInt(rand, 0, list.size() - 1));
        int i = MathHelper.getInt(rand, 1, itemstack2.getCount() / 2);
        ItemStack itemstack1 = itemstack2.splitStack(i);

        if (itemstack2.getCount() > 1 && rand.nextBoolean())
        {
            list.add(itemstack2);
        }
        else
        {
            stacks.add(itemstack2);
        }

        if (itemstack1.getCount() > 1 && rand.nextBoolean())
        {
            list.add(itemstack1);
        }
        else
        {
            stacks.add(itemstack1);
        }
    }

    stacks.addAll(list);
    Collections.shuffle(stacks, rand);
}
 
Example 16
Project: Mods   File: ContainerTF2Workbench.java   View Source Code Vote up 4 votes
/**
 * Take a stack from the specified inventory slot.
 */
@Override
public ItemStack transferStackInSlot(EntityPlayer playerIn, int index) {
	ItemStack itemstack = ItemStack.EMPTY;
	Slot slot = this.inventorySlots.get(index);

	if (slot != null && slot.getHasStack()) {
		ItemStack itemstack1 = slot.getStack();

		if (itemstack1.getItem() == TF2weapons.itemTF2 && itemstack1.getMetadata() == 9)
			itemstack1 = ItemFromData.getRandomWeapon(playerIn.getRNG(), ItemFromData.VISIBLE_WEAPON);
		else if (itemstack1.getItem() == TF2weapons.itemTF2 && itemstack1.getMetadata() == 10)
			itemstack1 = ItemFromData.getRandomWeaponOfClass("cosmetic", playerIn.getRNG(), false);

		itemstack = itemstack1.copy();

		if (index == 0) {
			if (!this.mergeItemStack(itemstack1, 10, 46, true))
				return ItemStack.EMPTY;

			slot.onSlotChange(itemstack1, itemstack);
		} else if (index >= 10 && index < 37) {
			if (!this.mergeItemStack(itemstack1, 37, 46, false))
				return ItemStack.EMPTY;
		} else if (index >= 37 && index < 46) {
			if (!this.mergeItemStack(itemstack1, 10, 37, false))
				return ItemStack.EMPTY;
		} else if (!this.mergeItemStack(itemstack1, 10, 46, false))
			return ItemStack.EMPTY;

		if (itemstack1.isEmpty())
			slot.putStack(ItemStack.EMPTY);
		else
			slot.onSlotChanged();

		if (itemstack1.getCount() ==itemstack.getCount())
			return ItemStack.EMPTY;

		slot.onTake(playerIn, itemstack1);
	}

	return itemstack;
}
 
Example 17
Project: GardenStuff   File: ContainerBloomeryFurnace.java   View Source Code Vote up 4 votes
@Override
@Nonnull
public ItemStack transferStackInSlot (EntityPlayer player, int slotIndex) {
    @Nonnull ItemStack itemStack = ItemStack.EMPTY;
    Slot slot = inventorySlots.get(slotIndex);

    // Assume inventory and hotbar slot IDs are contiguous
    int inventoryStart = playerSlots.get(0).slotNumber;
    int hotbarStart = hotbarSlots.get(0).slotNumber;
    int hotbarEnd = hotbarSlots.get(hotbarSlots.size() - 1).slotNumber + 1;

    if (slot != null && slot.getHasStack()) {
        @Nonnull ItemStack slotStack = slot.getStack();
        itemStack = slotStack.copy();

        // Try merge output into inventory and signal change
        if (slotIndex == outputSlot.slotNumber) {
            if (!mergeItemStack(slotStack, inventoryStart, hotbarEnd, true))
                return ItemStack.EMPTY;

            slot.onSlotChange(slotStack, itemStack);
        }

        // Try merge stacks within inventory and hotbar spaces
        else if (slotIndex >= inventoryStart && slotIndex < hotbarEnd) {
            boolean merged = false;
            if (TileBloomeryFurnace.isItemFuel(slotStack))
                merged = mergeItemStack(slotStack, fuelSlot.slotNumber, fuelSlot.slotNumber + 1, false);
            else if (TileBloomeryFurnace.isItemPrimaryInput(slotStack))
                merged = mergeItemStack(slotStack, primarySlot.slotNumber, primarySlot.slotNumber + 1, false);
            else if (TileBloomeryFurnace.isItemSecondaryInput(slotStack))
                merged = mergeItemStack(slotStack, secondarySlot.slotNumber, secondarySlot.slotNumber + 1, false);

            if (!merged) {
                if (slotIndex >= inventoryStart && slotIndex < hotbarStart) {
                    if (!mergeItemStack(slotStack, hotbarStart, hotbarEnd, false))
                        return ItemStack.EMPTY;
                } else if (slotIndex >= hotbarStart && slotIndex < hotbarEnd && !this.mergeItemStack(slotStack, inventoryStart, hotbarStart, false))
                    return ItemStack.EMPTY;
            }
        }

        // Try merge stack into inventory
        else if (!mergeItemStack(slotStack, inventoryStart, hotbarEnd, false))
            return ItemStack.EMPTY;

        if (slotStack.isEmpty())
            slot.putStack(ItemStack.EMPTY);
        else
            slot.onSlotChanged();

        if (slotStack.getCount() == itemStack.getCount())
            return ItemStack.EMPTY;

        slot.onTake(player, slotStack);
    }

    return itemStack;
}
 
Example 18
Project: pnc-repressurized   File: ItemPneumaticArmor.java   View Source Code Vote up 4 votes
public static void setEntityFilter(ItemStack helmetStack, String filter) {
    if (!helmetStack.isEmpty()) {
        NBTUtil.setString(helmetStack, "entityFilter", filter);
    }
}
 
Example 19
Project: pnc-repressurized   File: TileEntityBase.java   View Source Code Vote up 4 votes
@Override
public boolean test(Integer integer, ItemStack itemStack) {
    return itemStack.isEmpty()
            || applicableUpgrades.contains(itemStack.getItem())
            || applicableCustomUpgrades.contains(makeUpgradeKey(itemStack));
}
 
Example 20
Project: Mods   File: ContainerWearables.java   View Source Code Vote up 4 votes
/**
 * Take a stack from the specified inventory slot.
 */
@Override
@Nullable
public ItemStack transferStackInSlot(EntityPlayer playerIn, int index) {
	ItemStack itemstack = ItemStack.EMPTY;
	Slot slot = this.inventorySlots.get(index);

	if (slot != null && slot.getHasStack()) {
		ItemStack itemstack1 = slot.getStack();
		itemstack = itemstack1.copy();
		EntityEquipmentSlot entityequipmentslot = EntityLiving.getSlotForItemStack(itemstack);

		if (index >= 0 && index < 4) {
			if (!this.mergeItemStack(itemstack1, 8, 44, false))
				return ItemStack.EMPTY;
		} else if (index >= 4 && index < 7) {
			if (!this.mergeItemStack(itemstack1, 8, 44, false))
				return ItemStack.EMPTY;
		} else if (entityequipmentslot.getSlotType() == EntityEquipmentSlot.Type.ARMOR
				&& !this.inventorySlots.get(4 - entityequipmentslot.getIndex()).getHasStack()) {
			int i = 4 - entityequipmentslot.getIndex();

			if (!this.mergeItemStack(itemstack1, i, i + 1, false))
				return ItemStack.EMPTY;
		} else if (entityequipmentslot == EntityEquipmentSlot.OFFHAND
				&& !this.inventorySlots.get(44).getHasStack()) {
			if (!this.mergeItemStack(itemstack1, 44, 45, false))
				return ItemStack.EMPTY;
		} else if (itemstack1.getItem() instanceof ItemAmmoBelt
				&& !this.inventorySlots.get(7).getHasStack()) {
			if (!this.mergeItemStack(itemstack1, 7, 8, false))
				return ItemStack.EMPTY;
		} else if (itemstack1.getItem() instanceof ItemWearable && index >= 8) {
			if (!this.mergeItemStack(itemstack1, 4, 7, false))
				return ItemStack.EMPTY;
		} else if (itemstack1.getItem() instanceof ItemAmmo && ammoBelt && index < 44) {
			if (!this.mergeItemStack(itemstack1, 45, 54, false))
				return ItemStack.EMPTY;
		} else if (index >= 8 && index < 35) {
			if (!this.mergeItemStack(itemstack1, 35, 44, false))
				return ItemStack.EMPTY;
		} else if (index >= 35 && index < 44) {
			if (!this.mergeItemStack(itemstack1, 8, 35, false))
				return ItemStack.EMPTY;
		} else if (!this.mergeItemStack(itemstack1, 8, 44, false))
			return ItemStack.EMPTY;

		if (itemstack1.isEmpty())
			slot.putStack(ItemStack.EMPTY);
		else
			slot.onSlotChanged();

		if (itemstack1.getCount() ==itemstack.getCount())
			return ItemStack.EMPTY;

		slot.onTake(playerIn, itemstack1);
	}

	return itemstack;
}