Search in sources :

Example 1 with Slot

use of net.minecraft.inventory.Slot in project BetterStorage by copygirl.

the class ItemBackpack method onArmorTick.

@Override
public void onArmorTick(World world, EntityPlayer player, ItemStack itemStack) {
    // Replace the armor slot with a custom one, so the player
    // can't unequip the backpack when there's items inside.
    int index = 5 + armorType;
    Slot slotBefore = player.inventoryContainer.getSlot(index);
    if (slotBefore instanceof SlotArmorBackpack)
        return;
    int slotIndex = player.inventory.getSizeInventory() - getChestSlotOffset(player) - armorType;
    SlotArmorBackpack slot = new SlotArmorBackpack(player.inventory, slotIndex, 8, 8 + armorType * 18);
    slot.slotNumber = index;
    player.inventoryContainer.inventorySlots.set(index, slot);
}
Also used : SlotArmorBackpack(net.mcft.copy.betterstorage.container.SlotArmorBackpack) S2FPacketSetSlot(net.minecraft.network.play.server.S2FPacketSetSlot) EquipmentSlot(net.mcft.copy.betterstorage.misc.EquipmentSlot) Slot(net.minecraft.inventory.Slot)

Example 2 with Slot

use of net.minecraft.inventory.Slot in project BetterStorage by copygirl.

the class ContainerBetterStorage method transferStackInSlot.

@Override
public ItemStack transferStackInSlot(EntityPlayer player, int slotId) {
    ItemStack stack = null;
    Slot slot = (Slot) inventorySlots.get(slotId);
    // If slot isn't empty and item can be stacked.
    if ((slot != null) && slot.getHasStack()) {
        ItemStack slotStack = slot.getStack();
        stack = slotStack.copy();
        if (!mergeItemStack(slotStack, transferStart(slotId), transferEnd(slotId), transferDirection(slotId)))
            return null;
        if (slotStack.stackSize != 0)
            slot.onSlotChanged();
        else
            slot.putStack(null);
    }
    return stack;
}
Also used : Slot(net.minecraft.inventory.Slot) ItemStack(net.minecraft.item.ItemStack)

Example 3 with Slot

use of net.minecraft.inventory.Slot in project compactsolars by cpw.

the class ContainerCompactSolar method transferStackInSlot.

@Override
public ItemStack transferStackInSlot(EntityPlayer par1EntityPlayer, int i) {
    ItemStack itemstack = null;
    Slot slot = (Slot) inventorySlots.get(i);
    if (slot != null && slot.getHasStack()) {
        ItemStack itemstack1 = slot.getStack();
        itemstack = itemstack1.copy();
        if (i == 0) {
            if (!mergeItemStack(itemstack1, 1, 37, true)) {
                return null;
            }
        } else if (i >= 1 && i < 28) {
            if (!mergeItemStack(itemstack1, 28, 37, false)) {
                return null;
            }
        } else if (i >= 28 && i < 37) {
            if (!mergeItemStack(itemstack1, 1, 27, false)) {
                return null;
            }
        } else if (!mergeItemStack(itemstack1, 1, 37, false)) {
            return null;
        }
        if (itemstack1.stackSize == 0) {
            slot.putStack(null);
        } else {
            slot.onSlotChanged();
        }
        if (itemstack1.stackSize != itemstack.stackSize) {
            slot.onPickupFromSlot(par1EntityPlayer, itemstack1);
        } else {
            return null;
        }
    }
    return itemstack;
}
Also used : Slot(net.minecraft.inventory.Slot) ItemStack(net.minecraft.item.ItemStack)

Example 4 with Slot

use of net.minecraft.inventory.Slot 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 5 with Slot

use of net.minecraft.inventory.Slot in project BluePower by Qmunity.

the class ProjectTableOverlayHandler method assignIngredSlots.

private Slot[][] assignIngredSlots(GuiContainer gui, List<PositionedStack> ingredients, List<IngredientDistribution> assignedIngredients) {
    // setup the slot map
    Slot[][] recipeSlots = mapIngredSlots(gui, ingredients);
    HashMap<Slot, Integer> distribution = new HashMap<Slot, Integer>();
    for (Slot[] recipeSlot : recipeSlots) for (Slot slot : recipeSlot) if (!distribution.containsKey(slot))
        distribution.put(slot, -1);
    HashSet<Slot> avaliableSlots = new HashSet<Slot>(distribution.keySet());
    HashSet<Integer> remainingIngreds = new HashSet<Integer>();
    ArrayList<LinkedList<Slot>> assignedSlots = new ArrayList<LinkedList<Slot>>();
    for (int i = 0; i < ingredients.size(); i++) {
        remainingIngreds.add(i);
        assignedSlots.add(new LinkedList<Slot>());
    }
    while (avaliableSlots.size() > 0 && remainingIngreds.size() > 0) {
        for (Iterator<Integer> iterator = remainingIngreds.iterator(); iterator.hasNext(); ) {
            int i = iterator.next();
            boolean assigned = false;
            DistributedIngred istack = assignedIngredients.get(i).distrib;
            for (Slot slot : recipeSlots[i]) {
                if (avaliableSlots.contains(slot)) {
                    avaliableSlots.remove(slot);
                    if (slot.getHasStack())
                        continue;
                    istack.numSlots++;
                    assignedSlots.get(i).add(slot);
                    assigned = true;
                    break;
                }
            }
            if (!assigned || istack.numSlots * istack.stack.getMaxStackSize() >= istack.invAmount)
                iterator.remove();
        }
    }
    for (int i = 0; i < ingredients.size(); i++) assignedIngredients.get(i).slots = assignedSlots.get(i).toArray(new Slot[0]);
    return recipeSlots;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) Slot(net.minecraft.inventory.Slot) DistributedIngred(codechicken.nei.recipe.DefaultOverlayHandler.DistributedIngred) HashSet(java.util.HashSet)

Aggregations

Slot (net.minecraft.inventory.Slot)199 ItemStack (net.minecraft.item.ItemStack)163 ArrayList (java.util.ArrayList)9 IFuzzySlot (logisticspipes.interfaces.IFuzzySlot)9 InventoryPlayer (net.minecraft.entity.player.InventoryPlayer)9 SlotRemoveOnly (powercrystals.minefactoryreloaded.gui.slot.SlotRemoveOnly)7 List (java.util.List)6 ItemFocusCharge (am2.items.ItemFocusCharge)4 IESlot (blusunrize.immersiveengineering.common.gui.IESlot)4 LinkedList (java.util.LinkedList)4 SlotFake (powercrystals.minefactoryreloaded.gui.slot.SlotFake)4 ISpellFocus (am2.items.ISpellFocus)3 IConfigurableTool (blusunrize.immersiveengineering.api.tool.IConfigurableTool)3 ItemEngineersBlueprint (blusunrize.immersiveengineering.common.items.ItemEngineersBlueprint)3 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)3 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)3 ItemSpellBase (am2.api.spell.ItemSpellBase)2 ItemFocusMana (am2.items.ItemFocusMana)2 BlueprintCraftingRecipe (blusunrize.immersiveengineering.api.crafting.BlueprintCraftingRecipe)2 ToolConfigBoolean (blusunrize.immersiveengineering.api.tool.IConfigurableTool.ToolConfig.ToolConfigBoolean)2