Search in sources :

Example 1 with IEItemStackHandler

use of blusunrize.immersiveengineering.common.util.inventory.IEItemStackHandler in project ImmersiveEngineering by BluSunrize.

the class ContainerRevolver method onContainerClosed.

@Override
public void onContainerClosed(EntityPlayer par1EntityPlayer) {
    super.onContainerClosed(par1EntityPlayer);
    for (int hand = 0; hand < (this.secondHand != null ? 2 : 1); hand++) {
        IItemHandler secondRevolverInventory = secondRevolver.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null);
        IItemHandler inv = this.secondHand == null ? this.inv : (hand == 0) == (player.getPrimaryHand() == EnumHandSide.RIGHT) ? secondRevolverInventory : this.inv;
        if (inv instanceof IEItemStackHandler)
            ((IEItemStackHandler) inv).setInventoryForUpdate(null);
    }
}
Also used : IItemHandler(net.minecraftforge.items.IItemHandler) IEItemStackHandler(blusunrize.immersiveengineering.common.util.inventory.IEItemStackHandler)

Example 2 with IEItemStackHandler

use of blusunrize.immersiveengineering.common.util.inventory.IEItemStackHandler in project ImmersiveEngineering by BluSunrize.

the class ContainerModWorkbench method rebindSlots.

public void rebindSlots() {
    // Don't rebind if the tool didn't change
    if (FMLCommonHandler.instance().getEffectiveSide() == Side.CLIENT)
        for (Slot slot : inventorySlots) if (slot instanceof IESlot.Upgrades)
            if (ItemStack.areItemsEqual(((IESlot.Upgrades) slot).upgradeableTool, inv.getStackInSlot(0)))
                return;
    this.inventorySlots.clear();
    this.inventoryItemStacks.clear();
    this.addSlotToContainer(new IESlot.ModWorkbench(this, this.inv, 0, 24, 22, 1));
    slotCount = 1;
    ItemStack tool = this.getSlot(0).getStack();
    if (tool.getItem() instanceof IUpgradeableTool) {
        IItemHandler handler = tool.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null);
        if (handler instanceof IEItemStackHandler)
            ((IEItemStackHandler) handler).setTile(tile);
        Slot[] slots = ((IUpgradeableTool) tool.getItem()).getWorkbenchSlots(this, tool);
        if (slots != null)
            for (Slot s : slots) {
                this.addSlotToContainer(s);
                slotCount++;
            }
        if (tool.hasCapability(CapabilityShader.SHADER_CAPABILITY, null)) {
            ShaderWrapper wrapper = tool.getCapability(CapabilityShader.SHADER_CAPABILITY, null);
            if (wrapper != null) {
                this.shaderInv = new InventoryShader(this, wrapper);
                this.addSlotToContainer(new IESlot.Shader(this, shaderInv, 0, 130, 32, tool));
                slotCount++;
                this.shaderInv.shader = wrapper.getShaderItem();
            }
        }
    } else if (!(tool.getItem() instanceof IConfigurableTool)) {
        boolean blueprint = false;
        if (tool.getItem() instanceof ItemEngineersBlueprint) {
            // Init the output inventory
            blueprint = true;
            BlueprintCraftingRecipe[] recipes = ((ItemEngineersBlueprint) tool.getItem()).getRecipes(tool);
            inventoryBPoutput = new InventoryBlueprint(this, recipes);
            // Add output slots
            for (int i = 0; i < recipes.length; i++) {
                int y = 21 + (i < 9 ? i / 3 : (-(i - 6) / 3)) * 18;
                this.addSlotToContainer(new IESlot.BlueprintOutput(this, inventoryBPoutput, this.inv, i, 118 + (i % 3 * 18), y, recipes[i]));
                slotCount++;
            }
        }
        // Add input slots, these are always here if no tool is in
        for (int i = 0; i < 6; i++) {
            if (blueprint)
                this.addSlotToContainer(new IESlot.BlueprintInput(this, this.inv, this.inventoryBPoutput, i + 1, i % 2 == 0 ? 74 : 92, 21 + (i / 2) * 18));
            else
                this.addSlotToContainer(new Slot(this.inv, i + 1, i % 2 == 0 ? 74 : 92, 21 + (i / 2) * 18));
            slotCount++;
        }
    }
    bindPlayerInv(inventoryPlayer);
    ImmersiveEngineering.proxy.reInitGui();
}
Also used : IItemHandler(net.minecraftforge.items.IItemHandler) IEItemStackHandler(blusunrize.immersiveengineering.common.util.inventory.IEItemStackHandler) ItemEngineersBlueprint(blusunrize.immersiveengineering.common.items.ItemEngineersBlueprint) ShaderWrapper(blusunrize.immersiveengineering.api.shader.CapabilityShader.ShaderWrapper) Slot(net.minecraft.inventory.Slot) IUpgradeableTool(blusunrize.immersiveengineering.api.tool.IUpgradeableTool) IConfigurableTool(blusunrize.immersiveengineering.api.tool.IConfigurableTool) ItemStack(net.minecraft.item.ItemStack)

Example 3 with IEItemStackHandler

use of blusunrize.immersiveengineering.common.util.inventory.IEItemStackHandler in project ImmersiveEngineering by BluSunrize.

the class ContainerRevolver method addSlots.

@Override
int addSlots() {
    if (this.equipmentSlot == EntityEquipmentSlot.MAINHAND || this.equipmentSlot == EntityEquipmentSlot.OFFHAND) {
        int bullets0 = ((IBulletContainer) (heldItem).getItem()).getBulletCount(heldItem);
        this.secondHand = this.equipmentSlot == EntityEquipmentSlot.MAINHAND ? EntityEquipmentSlot.OFFHAND : EntityEquipmentSlot.MAINHAND;
        this.secondRevolver = this.player.getItemStackFromSlot(this.secondHand);
        if (!secondRevolver.isEmpty() && secondRevolver.getItem() instanceof IBulletContainer) {
            int bullets1 = ((IBulletContainer) secondRevolver.getItem()).getBulletCount(secondRevolver);
            this.offset = ((bullets0 >= 18 ? 150 : bullets0 > 8 ? 136 : 74) + (bullets1 >= 18 ? 150 : bullets1 > 8 ? 136 : 74) + 4 - 176) / 2;
        } else {
            this.secondRevolver = ItemStack.EMPTY;
            this.secondHand = null;
            this.offset = ((bullets0 >= 18 ? 150 : bullets0 > 8 ? 136 : 74) - 176) / 2;
        }
    }
    int total = 0;
    int off = (offset < 0 ? -offset : 0);
    for (int hand = 0; hand < (this.secondHand != null ? 2 : 1); hand++) {
        int i = 0;
        ItemStack held = this.secondHand == null ? heldItem : (hand == 0) == (player.getPrimaryHand() == EnumHandSide.RIGHT) ? secondRevolver : heldItem;
        IItemHandler secondRevolverInventory = secondRevolver.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null);
        IItemHandler inv = this.secondHand == null ? this.inv : (hand == 0) == (player.getPrimaryHand() == EnumHandSide.RIGHT) ? secondRevolverInventory : this.inv;
        int revolverSlots = ((IBulletContainer) (held).getItem()).getBulletCount(held);
        if (inv instanceof IEItemStackHandler)
            ((IEItemStackHandler) inv).setInventoryForUpdate(this.inventoryPlayer);
        this.addSlotToContainer(new IESlot.Bullet(inv, i++, off + 29, 3, 1));
        int slots = revolverSlots >= 18 ? 2 : revolverSlots > 8 ? 1 : 0;
        for (int[] slot : slotPositions[slots]) this.addSlotToContainer(new IESlot.Bullet(inv, i++, off + slot[0], slot[1], 1));
        this.addSlotToContainer(new IESlot.Bullet(inv, i++, off + 48, 49, 1));
        this.addSlotToContainer(new IESlot.Bullet(inv, i++, off + 29, 57, 1));
        this.addSlotToContainer(new IESlot.Bullet(inv, i++, off + 10, 49, 1));
        this.addSlotToContainer(new IESlot.Bullet(inv, i++, off + 2, 30, 1));
        this.addSlotToContainer(new IESlot.Bullet(inv, i++, off + 10, 11, 1));
        off += (revolverSlots >= 18 ? 150 : revolverSlots > 8 ? 136 : 74) + 4;
        total += i;
    }
    this.bindPlayerInventory(this.inventoryPlayer);
    return total;
}
Also used : IBulletContainer(blusunrize.immersiveengineering.common.items.IEItemInterfaces.IBulletContainer) IItemHandler(net.minecraftforge.items.IItemHandler) IEItemStackHandler(blusunrize.immersiveengineering.common.util.inventory.IEItemStackHandler) ItemStack(net.minecraft.item.ItemStack)

Aggregations

IEItemStackHandler (blusunrize.immersiveengineering.common.util.inventory.IEItemStackHandler)3 IItemHandler (net.minecraftforge.items.IItemHandler)3 ItemStack (net.minecraft.item.ItemStack)2 ShaderWrapper (blusunrize.immersiveengineering.api.shader.CapabilityShader.ShaderWrapper)1 IConfigurableTool (blusunrize.immersiveengineering.api.tool.IConfigurableTool)1 IUpgradeableTool (blusunrize.immersiveengineering.api.tool.IUpgradeableTool)1 IBulletContainer (blusunrize.immersiveengineering.common.items.IEItemInterfaces.IBulletContainer)1 ItemEngineersBlueprint (blusunrize.immersiveengineering.common.items.ItemEngineersBlueprint)1 Slot (net.minecraft.inventory.Slot)1