package com.elytradev.teckle.common.container;

import com.elytradev.teckle.common.tile.TileBeamQuarry;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.IContainerListener;
import net.minecraft.inventory.Slot;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import net.minecraftforge.items.SlotItemHandler;

public class ContainerBeamQuarry extends Container {
    public final TileBeamQuarry beamQuarry;
    public final EntityPlayer player;

    public int power;

    public ContainerBeamQuarry(TileBeamQuarry tile, EntityPlayer player) {
        this.beamQuarry = tile;
        this.player = player;

        for (int i = 0; i < 2; ++i) {
            for (int j = 0; j < 3; ++j) {
                this.addSlotToContainer(new SlotItemHandler(tile.junkTypes, j + i * 3, 116 + j * 18, 20 + i * 18));
            }
        }

        for (int i = 0; i < 4; ++i) {
            for (int j = 0; j < 3; ++j) {
                this.addSlotToContainer(new SlotItemHandler(tile.junkSupply.getHandler(), j + i * 3, 116 + j * 18, 74 + i * 18));
            }
        }

        for (int i = 0; i < 5; ++i) {
            for (int j = 0; j < 5; ++j) {
                this.addSlotToContainer(new SlotItemHandler(tile.bufferData.getHandler(), j + i * 5, 8 + j * 18, 56 + i * 18));
            }
        }

        bindPlayerInventory(player.inventory);
    }

    protected void bindPlayerInventory(InventoryPlayer inventoryplayer) {
        for (int i = 0; i < 3; i++) {
            for (int j = 0; j < 9; j++) {
                addSlotToContainer(new Slot(inventoryplayer, j + i * 9 + 9, 8 + j * 18, 150 + i * 18));
            }
        }

        for (int i = 0; i < 9; i++) {
            addSlotToContainer(new Slot(inventoryplayer, i, 8 + i * 18, 208));
        }
    }

    @SideOnly(Side.CLIENT)
    @Override
    public void updateProgressBar(int id, int data) {
        if (id == 0)
            this.beamQuarry.energyStorage.setEnergyStored(data);
        super.updateProgressBar(id, data);
    }

    @Override
    public void detectAndSendChanges() {
        super.detectAndSendChanges();

        if (power != beamQuarry.energyStorage.getEnergyStored()) {
            listeners.forEach(iContainerListener -> iContainerListener.sendWindowProperty(ContainerBeamQuarry.this, 0, power));
        }
        this.power = beamQuarry.energyStorage.getEnergyStored();
    }

    @Override
    public boolean canInteractWith(EntityPlayer player) {
        return beamQuarry.isUsableByPlayer(player);
    }
}

@@ -328,16 +328,53 @@
 y.Slot;%0A
+import net.minecraft.item.ItemStack;%0A
 import n
@@ -2701,11 +2701,1010 @@
 );%0A    %7D
+%0A%0A    @Override%0A    public ItemStack transferStackInSlot(EntityPlayer playerIn, int index) %7B%0A        ItemStack itemstack = ItemStack.EMPTY;%0A        Slot slot = this.inventorySlots.get(index);%0A%0A        if (slot != null && slot.getHasStack()) %7B%0A            ItemStack itemstack1 = slot.getStack();%0A            itemstack = itemstack1.copy();%0A%0A            if (index %3C 43) %7B%0A                if (!this.mergeItemStack(itemstack1, 43, 79, true)) %7B%0A                    return ItemStack.EMPTY;%0A                %7D%0A            %7D else if (!this.mergeItemStack(itemstack1, 0, 43, true)) %7B%0A                return ItemStack.EMPTY;%0A            %7D%0A%0A            if (itemstack1.isEmpty()) %7B%0A                slot.putStack(ItemStack.EMPTY);%0A            %7D else %7B%0A                slot.onSlotChanged();%0A            %7D%0A%0A            if (itemstack1.getCount() == itemstack.getCount()) %7B%0A                return ItemStack.EMPTY;%0A            %7D%0A%0A            slot.onTake(playerIn, itemstack1);%0A        %7D%0A%0A        return itemstack;%0A    %7D
 %0A%7D%0A

Fix crash with shift click in bang quiver