Search in sources :

Example 1 with InventoryPlayer

use of net.minecraft.entity.player.InventoryPlayer in project BluePower by Qmunity.

the class ProjectTableOverlayHandler method findInventoryQuantities.

@SuppressWarnings("unchecked")
private void findInventoryQuantities(GuiContainer gui, List<DistributedIngred> ingredStacks) {
    for (// work out how much we have to go round
    Slot slot : // work out how much we have to go round
    (List<Slot>) gui.inventorySlots.inventorySlots) {
        if (slot.getHasStack() && (slot.inventory instanceof TileProjectTable || slot.inventory instanceof InventoryPlayer)) {
            ItemStack pstack = slot.getStack();
            DistributedIngred istack = findIngred(ingredStacks, pstack);
            if (istack != null)
                istack.invAmount += pstack.stackSize;
        }
    }
}
Also used : InventoryPlayer(net.minecraft.entity.player.InventoryPlayer) TileProjectTable(com.bluepowermod.tile.tier1.TileProjectTable) Slot(net.minecraft.inventory.Slot) ArrayList(java.util.ArrayList) List(java.util.List) LinkedList(java.util.LinkedList) ItemStack(net.minecraft.item.ItemStack) DistributedIngred(codechicken.nei.recipe.DefaultOverlayHandler.DistributedIngred)

Example 2 with InventoryPlayer

use of net.minecraft.entity.player.InventoryPlayer in project BluePower by Qmunity.

the class ProjectTableOverlayHandler method moveIngredients.

@SuppressWarnings("unchecked")
private void moveIngredients(GuiContainer gui, List<IngredientDistribution> assignedIngredients, int quantity) {
    for (IngredientDistribution distrib : assignedIngredients) {
        ItemStack pstack = distrib.permutation;
        int transferCap = quantity * pstack.stackSize;
        int transferred = 0;
        int destSlotIndex = 0;
        Slot dest = distrib.slots[0];
        int slotTransferred = 0;
        int slotTransferCap = pstack.getMaxStackSize();
        for (Slot slot : (List<Slot>) gui.inventorySlots.inventorySlots) {
            if (!slot.getHasStack() || !(slot.inventory instanceof TileProjectTable) && !(slot.inventory instanceof InventoryPlayer))
                continue;
            ItemStack stack = slot.getStack();
            if (!InventoryUtils.canStack(stack, pstack))
                continue;
            FastTransferManager.clickSlot(gui, slot.slotNumber);
            int amount = Math.min(transferCap - transferred, stack.stackSize);
            for (int c = 0; c < amount; c++) {
                FastTransferManager.clickSlot(gui, dest.slotNumber, 1);
                transferred++;
                slotTransferred++;
                if (slotTransferred >= slotTransferCap) {
                    destSlotIndex++;
                    if (destSlotIndex == distrib.slots.length) {
                        dest = null;
                        break;
                    }
                    dest = distrib.slots[destSlotIndex];
                    slotTransferred = 0;
                }
            }
            FastTransferManager.clickSlot(gui, slot.slotNumber);
            if (transferred >= transferCap || dest == null)
                break;
        }
    }
}
Also used : IngredientDistribution(codechicken.nei.recipe.DefaultOverlayHandler.IngredientDistribution) InventoryPlayer(net.minecraft.entity.player.InventoryPlayer) TileProjectTable(com.bluepowermod.tile.tier1.TileProjectTable) Slot(net.minecraft.inventory.Slot) ArrayList(java.util.ArrayList) List(java.util.List) LinkedList(java.util.LinkedList) ItemStack(net.minecraft.item.ItemStack)

Example 3 with InventoryPlayer

use of net.minecraft.entity.player.InventoryPlayer in project BluePower by Qmunity.

the class ContainerGhosts method slotClickPhantom.

/**
     * This method is copied from the BuildCraft code, which can be found here: https://github.com/BuildCraft/BuildCraft
     * @author CovertJaguar <http://www.railcraft.info>
     */
private ItemStack slotClickPhantom(Slot slot, int mouseButton, int modifier, EntityPlayer player) {
    ItemStack stack = null;
    if (mouseButton == 2) {
        if (((IPhantomSlot) slot).canAdjust()) {
            slot.putStack(null);
        }
    } else if (mouseButton == 0 || mouseButton == 1) {
        InventoryPlayer playerInv = player.inventory;
        slot.onSlotChanged();
        ItemStack stackSlot = slot.getStack();
        ItemStack stackHeld = playerInv.getItemStack();
        if (stackSlot != null) {
            stack = stackSlot.copy();
        }
        if (stackSlot == null) {
            if (stackHeld != null && slot.isItemValid(stackHeld)) {
                fillPhantomSlot(slot, stackHeld, mouseButton, modifier);
            }
        } else if (stackHeld == null) {
            adjustPhantomSlot(slot, mouseButton, modifier);
            slot.onPickupFromSlot(player, playerInv.getItemStack());
        } else if (slot.isItemValid(stackHeld)) {
            if (canStacksMerge(stackSlot, stackHeld)) {
                adjustPhantomSlot(slot, mouseButton, modifier);
            } else {
                fillPhantomSlot(slot, stackHeld, mouseButton, modifier);
            }
        }
    }
    return stack;
}
Also used : InventoryPlayer(net.minecraft.entity.player.InventoryPlayer) IPhantomSlot(com.bluepowermod.container.slot.IPhantomSlot) ItemStack(net.minecraft.item.ItemStack)

Example 4 with InventoryPlayer

use of net.minecraft.entity.player.InventoryPlayer in project VoodooCraft by Mod-DevCafeTeam.

the class TileDeathGlyph method readPlayerInventory.

/**
     * Reads the player's inventory from this tile entity and saves it to the player given
     */
public void readPlayerInventory(EntityPlayer player) {
    InventoryPlayer playerInv = player.inventory;
    List<ItemStack> excessStacks = new ArrayList<>();
    excessStacks.addAll(setInvStackList(playerInv.mainInventory, readStacksFromNBT(playerInventory, "main")));
    excessStacks.addAll(setInvStackList(playerInv.armorInventory, readStacksFromNBT(playerInventory, "armour")));
    excessStacks.addAll(setInvStackList(playerInv.offHandInventory, readStacksFromNBT(playerInventory, "offhand")));
    //Try add the rest of the items which couldn't be placed
    for (ItemStack stack : excessStacks) if (playerInv.addItemStackToInventory(stack))
        //Drop item if can't fit in inventory
        player.dropItem(stack, true);
}
Also used : InventoryPlayer(net.minecraft.entity.player.InventoryPlayer) ArrayList(java.util.ArrayList) ItemStack(net.minecraft.item.ItemStack)

Example 5 with InventoryPlayer

use of net.minecraft.entity.player.InventoryPlayer in project ConvenientAdditions by Necr0.

the class SlotFake method slotClick.

@Override
public ItemStack slotClick(Container container, int button, ClickType mode, EntityPlayer player) {
    InventoryPlayer inventoryplayer = player.inventory;
    ItemStack held = inventoryplayer.getItemStack().copy();
    if (!held.isEmpty())
        held.setCount(1);
    if (mode == ClickType.THROW) {
        this.putStack(ItemStack.EMPTY);
    } else if (mode == ClickType.SWAP) {
        return ItemStack.EMPTY;
    } else if ((mode == ClickType.PICKUP || mode == ClickType.PICKUP_ALL) && (button == 0 || button == 1)) {
        if (!held.isEmpty()) {
            putStack(held);
        } else {
            putStack(ItemStack.EMPTY);
        }
    } else if ((mode == ClickType.QUICK_MOVE) && (button == 0 || button == 1)) {
        this.putStack(ItemStack.EMPTY);
    }
    container.detectAndSendChanges();
    return ItemStack.EMPTY;
}
Also used : InventoryPlayer(net.minecraft.entity.player.InventoryPlayer) ItemStack(net.minecraft.item.ItemStack)

Aggregations

InventoryPlayer (net.minecraft.entity.player.InventoryPlayer)81 ItemStack (net.minecraft.item.ItemStack)56 Slot (net.minecraft.inventory.Slot)15 EntityPlayer (net.minecraft.entity.player.EntityPlayer)14 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)8 Item (net.minecraft.item.Item)6 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)6 ArrayList (java.util.ArrayList)5 Nonnull (javax.annotation.Nonnull)4 IFuzzySlot (logisticspipes.interfaces.IFuzzySlot)4 Button (com.minecolonies.blockout.controls.Button)3 EntityItem (net.minecraft.entity.item.EntityItem)3 AxisAlignedBB (net.minecraft.util.math.AxisAlignedBB)3 IPhantomSlot (buildcraft.lib.gui.slot.IPhantomSlot)2 TileProjectTable (com.bluepowermod.tile.tier1.TileProjectTable)2 ItemIcon (com.minecolonies.blockout.controls.ItemIcon)2 Label (com.minecolonies.blockout.controls.Label)2 BuildingBuilderResource (com.minecolonies.coremod.colony.buildings.utils.BuildingBuilderResource)2 GameProfile (com.mojang.authlib.GameProfile)2 LinkedList (java.util.LinkedList)2