Java Code Examples for net.minecraft.item.ItemStack#EMPTY

The following examples show how to use net.minecraft.item.ItemStack#EMPTY . 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: GTContainerTranslocatorFluid.java    From GT-Classic with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Nullable
@Override
public ItemStack slotClick(int slotId, int dragType, ClickType clickTypeIn, EntityPlayer player) {
	if (slotId == 0) {
		ItemStack stack = player.inventory.getItemStack();
		if (stack.isEmpty()) {
			this.block.setStackInSlot(0, ItemStack.EMPTY);
			this.block.filter = null;
			return ItemStack.EMPTY;
		}
		if (FluidUtil.getFluidContained(stack) != null) {
			FluidStack fluidStack = FluidUtil.getFluidContained(stack);
			FluidStack newStack = new FluidStack(fluidStack.getFluid(), 1000);
			this.block.setStackInSlot(0, ItemDisplayIcon.createWithFluidStack(newStack));
			this.block.filter = newStack;
		}
		return ItemStack.EMPTY;
	}
	return super.slotClick(slotId, dragType, clickTypeIn, player);
}
 
Example 2
Source File: TileSpaceLaser.java    From AdvancedRocketry with MIT License 6 votes vote down vote up
public TileSpaceLaser() { 
	super();
	glassPanel = ItemStack.EMPTY;
	//invBuffer = new ItemStack[INVSIZE];
	radius = 0;
	xCenter = 0;
	yCenter = 0;
	numSteps = 0;
	prevDir = null;

	tickSinceLastOperation = 0;
	laserX = 0;
	laserZ = 0;
	inv= new MultiInventory(this.itemOutPorts);
	
	if(Configuration.laserDrillPlanet)
		laserSat = new SatelliteLaser(inv);
	else
		laserSat = new SatelliteLaserNoDrill(inv);
	
	isRunning = false;
	finished = false;
	mode = MODE.SINGLE;
}
 
Example 3
Source File: TileAnvil.java    From TFC2 with GNU General Public License v3.0 6 votes vote down vote up
@Override
public ItemStack decrStackSize(int index, int count) 
{
	if(inventory.get(index) != ItemStack.EMPTY)
	{
		if(inventory.get(index).getMaxStackSize() <= count)
		{
			ItemStack itemstack = inventory.get(index);
			inventory.set(index, ItemStack.EMPTY);
			TFC.proxy.sendToAllNear(getWorld(), getPos(), 200, this.getUpdatePacket());
			return itemstack;
		}
		ItemStack itemstack1 = inventory.get(index).splitStack(count);
		if(inventory.get(index).getMaxStackSize() == 0)
			inventory.set(index, ItemStack.EMPTY);
		return itemstack1;
	}
	else
		return ItemStack.EMPTY;
}
 
Example 4
Source File: ShapedRecipe.java    From customstuff4 with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Gets recipe input without the chars for the shape.
 */
Object[] getRecipeInput()
{
    Object[] result = new Object[getRecipeWidth() * getRecipeHeight()];

    for (int row = 0; row < shape.length; row++)
    {
        for (int col = 0; col < shape[0].length(); col++)
        {
            RecipeInput input = items.get(shape[row].charAt(col));

            int index = col + row * shape[0].length();

            if (input != null)
            {
                result[index] = input.isOreClass() ? OreDictionary.getOres(input.getOreClass().getOreName()) : input.getStack().getItemStack();
            } else
            {
                result[index] = ItemStack.EMPTY;
            }
        }
    }

    return result;
}
 
Example 5
Source File: ContainerPotionCreator.java    From NotEnoughItems with MIT License 6 votes vote down vote up
@Override
public ItemStack slotClick(ContainerExtended container, EntityPlayer player, int button, ClickType clickType) {
    ItemStack held = player.inventory.getItemStack();
    if (button == 0 && clickType == ClickType.QUICK_MOVE) {
        NEIClientUtils.cheatItem(getStack(), button, -1);
    } else if (button == 1) {
        putStack(ItemStack.EMPTY);
    } else if (!held.isEmpty()) {
        if (isItemValid(held)) {
            putStack(ItemUtils.copyStack(held, 1));
            player.inventory.setItemStack(ItemStack.EMPTY);
        }
    } else if (getHasStack()) {
        player.inventory.setItemStack(getStack());
    }

    return ItemStack.EMPTY;
}
 
Example 6
Source File: GenericInventory.java    From OpenModsLib with MIT License 5 votes vote down vote up
@Override
@Nonnull
public ItemStack getStackInSlot(int index) {
	if (index >= 0 && index < this.inventoryContents.size())
		return this.inventoryContents.get(index);
	else
		return ItemStack.EMPTY;
}
 
Example 7
Source File: FWInventory.java    From NOVA-Core with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public ItemStack decrStackSize(int slot, int amount) {
	ItemStack stack = getStackInSlot(slot);
	ItemStack ret = stack.copy();
	ret.setCount(Math.min(ret.getCount(), amount));
	stack.setCount(stack.getCount() - ret.getCount());
	if (stack.getCount() <= 0) {
		setInventorySlotContents(slot, null);
		return ItemStack.EMPTY;
	}
	markDirty();
	return ret;
}
 
Example 8
Source File: OptimiserRecipes.java    From EmergingTechnology with MIT License 5 votes vote down vote up
public static ItemStack getOutputByItemStack(ItemStack itemStack) {
    ItemStack stack = RecipeBuilder.getOutputForItemStackFromRecipes(itemStack, getRecipes());

    if (stack == null) {
        return ItemStack.EMPTY;
    }

    return stack.copy();
}
 
Example 9
Source File: TileEntityBarrel.java    From enderutilities with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
protected void readItemsFromNBT(NBTTagCompound nbt)
{
    this.itemHandlerUpgrades.deserializeNBT(nbt);

    super.readItemsFromNBT(nbt);

    this.hasStructureUpgrade = this.itemHandlerUpgrades.getStackInSlot(1).isEmpty() == false;
    this.hasVoidUpgrade = this.itemHandlerUpgrades.getStackInSlot(3).isEmpty() == false;
    ItemStack stack = this.itemHandlerLockable.getStackInSlot(0);
    this.cachedStack = stack.isEmpty() ? ItemStack.EMPTY : stack.copy();
}
 
Example 10
Source File: ContainerUpgrades.java    From BetterChests with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public ItemStack slotClick(int slotId, int dragType, ClickType clickTypeIn, EntityPlayer player) {
	if (clickTypeIn == ClickType.CLONE) {
		Slot slot = getSlot(slotId);
		if (slot.inventory == inventory) {
			ItemStack stack = slot.getStack();
			if (stack.getItem() instanceof IUpgrade && ((IUpgrade) stack.getItem()).canBeDisabled(stack)) {
				inventory.getUpgradePart().setUpgradeDisabled(slot.getStack(), !inventory.getUpgradePart().isUpgradeDisabled(slot.getStack()));
			}
			return ItemStack.EMPTY;
		}
	}
	return super.slotClick(slotId, dragType, clickTypeIn, player);
}
 
Example 11
Source File: InventoryUtils.java    From enderutilities with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Tries to insert the given ItemStack stack to the target inventory, inside the given slot range.
 * The return value is a stack of the remaining items that couldn't be inserted.
 * If all items were successfully inserted, then null is returned.
 */
public static ItemStack tryInsertItemStackToInventoryWithinSlotRange(IItemHandler inv, @Nonnull ItemStack stackIn, SlotRange slotRange)
{
    final int lastSlot = Math.min(slotRange.lastInc, inv.getSlots() - 1);

    // First try to add to existing stacks
    for (int slot = slotRange.first; slot <= lastSlot; slot++)
    {
        if (inv.getStackInSlot(slot).isEmpty() == false)
        {
            stackIn = inv.insertItem(slot, stackIn, false);

            if (stackIn.isEmpty())
            {
                return ItemStack.EMPTY;
            }
        }
    }

    // Second round, try to add to any slot
    for (int slot = slotRange.first; slot <= lastSlot; slot++)
    {
        stackIn = inv.insertItem(slot, stackIn, false);

        if (stackIn.isEmpty())
        {
            return ItemStack.EMPTY;
        }
    }

    return stackIn;
}
 
Example 12
Source File: TileAnvil.java    From TFC2 with GNU General Public License v3.0 5 votes vote down vote up
@Override
public ItemStack removeStackFromSlot(int index) 
{
	if(index < getSizeInventory())
	{
		ItemStack out = inventory.get(index);
		inventory.set(index, ItemStack.EMPTY);
		TFC.proxy.sendToAllNear(getWorld(), getPos(), 200, this.getUpdatePacket());
		return out;
	}
	return ItemStack.EMPTY;
}
 
Example 13
Source File: ContainerTFOven.java    From TofuCraftReload with MIT License 5 votes vote down vote up
/**
 * Called when a player shift-clicks on a slot. You must override this or you will crash when someone does that.
 */
@Override
public ItemStack transferStackInSlot(EntityPlayer player, int slotIndex) {
    ItemStack itemstack = ItemStack.EMPTY;
    Slot slot = inventorySlots.get(slotIndex);

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

        switch (slotIndex) {
            case 0:
                if (!this.mergeItemStack(itemstack1, 1, 37, true))
                    return ItemStack.EMPTY;
            default:
                if (!this.mergeItemStack(itemstack1, 0, 0, false)) {
                    return ItemStack.EMPTY;
                }

                slot.onSlotChange(itemstack1, itemstack);
        }


        if (itemstack1.getCount() == 0)
            slot.putStack(ItemStack.EMPTY);
        else
            slot.onSlotChanged();
        if (itemstack1.getCount() == itemstack.getCount())
            return ItemStack.EMPTY;

        slot.onTake(player, itemstack1);
    }
    return itemstack;
}
 
Example 14
Source File: LightRecipes.java    From EmergingTechnology with MIT License 4 votes vote down vote up
public static boolean isValidInput(ItemStack itemStack) {
    return getOutputByItemStack(itemStack) != ItemStack.EMPTY;
}
 
Example 15
Source File: ItemHandyBag.java    From enderutilities with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * Tries to first fill the matching stacks in the player's inventory,
 * and then depending on the bag's mode, tries to add the remaining items
 * to the bag's inventory.
 * @param event
 * @return true if all items were handled and further processing of the event should not occur
 */
public static boolean onEntityItemPickupEvent(EntityItemPickupEvent event)
{
    EntityItem entityItem = event.getItem();
    ItemStack stack = entityItem.getItem();
    EntityPlayer player = event.getEntityPlayer();

    if (player.getEntityWorld().isRemote || entityItem.isDead || stack.isEmpty())
    {
        return true;
    }

    ItemStack origStack = ItemStack.EMPTY;
    final int origStackSize = stack.getCount();
    int stackSizeLast = origStackSize;
    boolean ret = false;

    IItemHandler playerInv = player.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null);
    // Not all the items could fit into existing stacks in the player's inventory, move them directly to the bag
    List<Integer> slots = InventoryUtils.getSlotNumbersOfMatchingItems(playerInv, EnderUtilitiesItems.HANDY_BAG);

    for (int slot : slots)
    {
        ItemStack bagStack = playerInv.getStackInSlot(slot);

        // Bag is not locked
        if (bagStack.isEmpty() == false && bagStack.getItem() == EnderUtilitiesItems.HANDY_BAG && ItemHandyBag.bagIsOpenable(bagStack))
        {
            // Delayed the stack copying until we know if there is a valid bag,
            // so check if the stack was copied already or not.
            if (origStack == ItemStack.EMPTY)
            {
                origStack = stack.copy();
            }

            stack = handleItems(stack, bagStack, player);

            if (stack.isEmpty() || stack.getCount() != stackSizeLast)
            {
                if (stack.isEmpty())
                {
                    entityItem.setDead();
                    event.setCanceled(true);
                    ret = true;
                    break;
                }

                ItemStack pickedUpStack = origStack.copy();
                pickedUpStack.setCount(stackSizeLast - stack.getCount());

                FMLCommonHandler.instance().firePlayerItemPickupEvent(player, entityItem, pickedUpStack);
                player.onItemPickup(entityItem, origStackSize);
            }

            stackSizeLast = stack.getCount();
        }
    }

    // Not everything was handled, update the stack
    if (entityItem.isDead == false && stack.getCount() != origStackSize)
    {
        entityItem.setItem(stack);
    }

    // At least some items were picked up
    if (entityItem.isSilent() == false && (entityItem.isDead || stack.getCount() != origStackSize))
    {
        player.getEntityWorld().playSound(null, player.getPosition(), SoundEvents.ENTITY_ITEM_PICKUP, SoundCategory.MASTER,
                0.2F, ((itemRand.nextFloat() - itemRand.nextFloat()) * 0.7F + 1.0F) * 2.0F);
    }

    return ret;
}
 
Example 16
Source File: ItemPickupManager.java    From enderutilities with GNU Lesser General Public License v3.0 4 votes vote down vote up
public ItemStack tryTransportItems(EntityPlayer player, ItemStack manager, ItemStack itemsIn)
{
    if (itemsIn.isEmpty())
    {
        return itemsIn;
    }

    IItemHandler inv = UtilItemModular.getBoundInventory(manager, player, 30);

    if (inv == null)
    {
        return itemsIn;
    }

    //return InventoryUtils.tryInsertItemStackToInventory(inv, itemsIn);
    ItemStack stackToSend = itemsIn.copy();

    int cost = ENDER_CHARGE_COST_PER_SENT_ITEM;

    // Not enough Ender Charge to send all the items
    if (UtilItemModular.useEnderCharge(manager, cost * itemsIn.getCount(), true) == false)
    {
        int available = UtilItemModular.getAvailableEnderCharge(manager);

        if (available < cost)
        {
            return itemsIn;
        }

        stackToSend.setCount(Math.min(itemsIn.getCount(), available / cost));
    }

    int numTransported = stackToSend.getCount();
    ItemStack itemsRemaining = InventoryUtils.tryInsertItemStackToInventory(inv, stackToSend);

    if (itemsRemaining.isEmpty() == false)
    {
        numTransported -= itemsRemaining.getCount();
    }

    itemsIn.shrink(numTransported);

    // Get the final charge amount
    UtilItemModular.useEnderCharge(manager, numTransported * cost, false);

    if (itemsIn.isEmpty())
    {
        return ItemStack.EMPTY;
    }

    return itemsIn;
}
 
Example 17
Source File: ContainerTFC.java    From TFC2 with GNU General Public License v3.0 4 votes vote down vote up
@Override
/**
 * Handles slot click.
 *  
 * @param mode 0 = basic click, 1 = shift click, 2 = hotbar, 3 = pick block, 4 = drop, 5 = ?, 6 = double click
 */
public ItemStack slotClick(int slotID, int dragType, ClickType clickTypeIn, EntityPlayer p)
{
	if (slotID >= 0 && slotID < this.inventorySlots.size())
	{
		Slot sourceSlot = (Slot) this.inventorySlots.get(slotID);
		ItemStack slotStack = sourceSlot.getStack();

		//This section is for merging foods with differing expirations.
		if(clickTypeIn == ClickType.SWAP && slotStack != null && p.inventory.getItemStack() != null)
		{
			ItemStack itemstack4 = p.inventory.getItemStack();
			if (slotStack.getItem() == itemstack4.getItem() && slotStack.getMetadata() == itemstack4.getMetadata() && ContainerTFC.areCompoundsEqual(slotStack, itemstack4))
			{
				if(slotStack.getItem() instanceof IFood && itemstack4.getItem() instanceof IFood)
				{
					long ex1 = Food.getDecayTimer(slotStack);
					long ex2 = Food.getDecayTimer(itemstack4);
					if(ex2 < ex1)
						Food.setDecayTimer(slotStack, ex2);
				}

				//int l1 = clickedButton == 0 ? itemstack4.getMaxStackSize() : 1;
				int l1 = itemstack4.getMaxStackSize();

				if (l1 > sourceSlot.getItemStackLimit(itemstack4) - slotStack.getMaxStackSize())
				{
					l1 = sourceSlot.getItemStackLimit(itemstack4) - slotStack.getMaxStackSize();
				}

				if (l1 > itemstack4.getMaxStackSize() - slotStack.getMaxStackSize())
				{
					l1 = itemstack4.getMaxStackSize() - slotStack.getMaxStackSize();
				}

				itemstack4.splitStack(l1);

				if (itemstack4.getMaxStackSize() == 0)
				{
					p.inventory.setItemStack(ItemStack.EMPTY);
				}

				slotStack.grow(l1);
				return ItemStack.EMPTY;
			}
			else if (itemstack4.getMaxStackSize() <= sourceSlot.getItemStackLimit(itemstack4))
			{
				sourceSlot.putStack(itemstack4);
				p.inventory.setItemStack(slotStack);
			}
		}

		// Hotbar press to remove from crafting output
		if (clickTypeIn == ClickType.QUICK_MOVE && slotID == 0 && slotStack != null)
		{
			//Removed During Port
			//CraftingHandler.preCraft(p, slotStack, craftMatrix);
		}
		// S and D hotkeys for trimming/combining food
		/*else if (mode == 7 && slotID >= 9 && slotID < 45)
		{
			if (sourceSlot.canTakeStack(p))
			{
				Slot destSlot = (Slot) this.inventorySlots.get(clickedButton);
				destSlot.putStack(slotStack);
				sourceSlot.putStack(null);
				return null;
			}
		}*/
	}

	ItemStack is = super.slotClick(slotID, dragType, clickTypeIn, p);
	//saveContents(is);
	return is;
}
 
Example 18
Source File: SatelliteBase.java    From AdvancedRocketry with MIT License 4 votes vote down vote up
public SatelliteBase() {
	satelliteProperties = new SatelliteProperties();
	satelliteProperties.setSatelliteType(SatelliteRegistry.getKey(this.getClass()));
	isDead = false;
	satellite = ItemStack.EMPTY;
}
 
Example 19
Source File: DummyRecipe.java    From Survivalist with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public ItemStack getCraftingResult(CraftingInventory inv)
{
    return ItemStack.EMPTY;
}
 
Example 20
Source File: GTItemLightHelmet.java    From GT-Classic with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public ItemStack getRepairItem() {
	return ItemStack.EMPTY;
}