aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/gtPlusPlus/core/container/ContainerVolumetricFlaskSetter.java
blob: 1a517e6761b5a0c64b9cb8d5fd6312bc3611394e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
package gtPlusPlus.core.container;

import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.ICrafting;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;

import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import gtPlusPlus.api.objects.Logger;
import gtPlusPlus.core.block.ModBlocks;
import gtPlusPlus.core.inventories.InventoryVolumetricFlaskSetter;
import gtPlusPlus.core.slots.SlotNoInput;
import gtPlusPlus.core.slots.SlotVolumetricFlask;
import gtPlusPlus.core.tileentities.general.TileEntityVolumetricFlaskSetter;
import gtPlusPlus.core.util.Utils;

public class ContainerVolumetricFlaskSetter extends Container {

    public TileEntityVolumetricFlaskSetter mTileEntity;
    public final InventoryVolumetricFlaskSetter inventoryChest;

    public int mCustomValue;
    private int oCustomValue;
    private int mTimer;

    private final World worldObj;
    private final int posX;
    private final int posY;
    private final int posZ;

    public static final int SLOT_OUTPUT = 8;

    public static int StorageSlotNumber = 8; // Number of slots in storage area
    public static int InventorySlotNumber = 36; // Inventory Slots (Inventory
    // and Hotbar)
    public static int FullSlotNumber = InventorySlotNumber + StorageSlotNumber; // All
    // slots

    public ContainerVolumetricFlaskSetter(final InventoryPlayer inventory, final TileEntityVolumetricFlaskSetter te) {
        this.mTileEntity = te;
        this.inventoryChest = te.getInventory();

        int var6;
        int var7;
        this.worldObj = te.getWorldObj();
        this.posX = te.xCoord;
        this.posY = te.yCoord;
        this.posZ = te.zCoord;
        // mCustomValue = te.getCustomValue();

        int o = 0;

        // Storage Side
        /*
         * for (var6 = 0; var6 < 3; var6++) { for (var7 = 0; var7 < 5; var7++) { this.addSlotToContainer(new
         * SlotIntegratedCircuit(o, this.inventoryChest, o, 44 + (var7 * 18), 15 + (var6 * 18))); o++; } }
         */

        int xStart = 26;
        int yStart = 12;

        try {
            // 0
            this.addSlotToContainer(new SlotVolumetricFlask(this.inventoryChest, o++, xStart, yStart));
            this.addSlotToContainer(new SlotVolumetricFlask(this.inventoryChest, o++, xStart += 18, yStart));
            this.addSlotToContainer(new SlotVolumetricFlask(this.inventoryChest, o++, xStart += 18, yStart));
            this.addSlotToContainer(new SlotVolumetricFlask(this.inventoryChest, o++, xStart += 18, yStart));
            this.addSlotToContainer(new SlotVolumetricFlask(this.inventoryChest, o++, xStart += 18, yStart));
            this.addSlotToContainer(new SlotVolumetricFlask(this.inventoryChest, o++, xStart += 18, yStart));
            this.addSlotToContainer(new SlotVolumetricFlask(this.inventoryChest, o++, xStart += 18, yStart));
            this.addSlotToContainer(new SlotVolumetricFlask(this.inventoryChest, o++, xStart, yStart + 18));

            // Add Output
            this.addSlotToContainer(new SlotNoInput(this.inventoryChest, o++, 8 + (8 * 18), 59));
            o++;

            // Player Inventory
            for (var6 = 0; var6 < 3; ++var6) {
                for (var7 = 0; var7 < 9; ++var7) {
                    this.addSlotToContainer(
                        new Slot(inventory, var7 + (var6 * 9) + 9, 8 + (var7 * 18), 84 + (var6 * 18)));
                }
            }
            // Player Hotbar
            for (var6 = 0; var6 < 9; ++var6) {
                this.addSlotToContainer(new Slot(inventory, var6, 8 + (var6 * 18), 142));
            }
            detectAndSendChanges();
        } catch (Throwable t) {}
    }

    @Override
    public boolean canInteractWith(final EntityPlayer par1EntityPlayer) {
        if (this.worldObj.getBlock(this.posX, this.posY, this.posZ) != ModBlocks.blockVolumetricFlaskSetter) {
            return false;
        }
        return par1EntityPlayer.getDistanceSq(this.posX + 0.5D, this.posY + 0.5D, this.posZ + 0.5D) <= 64D;
    }

    @Override
    public ItemStack transferStackInSlot(final EntityPlayer par1EntityPlayer, final int par2) {
        ItemStack var3 = null;
        final Slot var4 = this.inventorySlots.get(par2);

        if ((var4 != null) && var4.getHasStack()) {
            final ItemStack var5 = var4.getStack();
            var3 = var5.copy();

            /*
             * if (par2 == 0) { if (!this.mergeItemStack(var5, InOutputSlotNumber, FullSlotNumber, true)) { return null;
             * } var4.onSlotChange(var5, var3); } else if (par2 >= InOutputSlotNumber && par2 < InventoryOutSlotNumber)
             * { if (!this.mergeItemStack(var5, InventoryOutSlotNumber, FullSlotNumber, false)) { return null; } } else
             * if (par2 >= InventoryOutSlotNumber && par2 < FullSlotNumber) { if (!this.mergeItemStack(var5,
             * InOutputSlotNumber, InventoryOutSlotNumber, false)) { return null; } } else if
             * (!this.mergeItemStack(var5, InOutputSlotNumber, FullSlotNumber, false)) { return null; }
             */

            if (var5.stackSize == 0) {
                var4.putStack(null);
            } else {
                var4.onSlotChanged();
            }

            if (var5.stackSize == var3.stackSize) {
                return null;
            }

            var4.onPickupFromSlot(par1EntityPlayer, var5);
        }

        return var3;
    }

    @Override
    public void detectAndSendChanges() {
        super.detectAndSendChanges();
        if ((Utils.isClient()) || (this.mTileEntity == null)) {
            return;
        }

        mCustomValue = mTileEntity.getCustomValue();
        mTimer++;

        for (Object crafter : this.crafters) {
            ICrafting var1 = (ICrafting) crafter;
            if (mTimer % 20 == 10 || oCustomValue != mCustomValue) {
                var1.sendProgressBarUpdate(this, 0, mCustomValue);
            }
        }

        oCustomValue = mCustomValue;
    }

    @SideOnly(Side.CLIENT)
    @Override
    public void updateProgressBar(int par1, int par2) {
        super.updateProgressBar(par1, par2);
        if (par1 == 0) {
            mCustomValue = (short) par2;
        }
    }

    public void log(String aString) {
        Logger.INFO("[Flask-Container] " + aString);
    }
}