aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/gtPlusPlus/core/container/ContainerProjectTable.java
blob: 05f418283351623a11ad822a1ccbcc62a3b28163 (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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
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.IInventory;
import net.minecraft.inventory.InventoryCraftResult;
import net.minecraft.inventory.InventoryCrafting;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.CraftingManager;
import net.minecraft.world.World;

import gtPlusPlus.api.objects.Logger;
import gtPlusPlus.core.block.ModBlocks;
import gtPlusPlus.core.inventories.projecttable.InventoryProjectMain;
import gtPlusPlus.core.inventories.projecttable.InventoryProjectOutput;
import gtPlusPlus.core.slots.SlotCraftingNoCollect;
import gtPlusPlus.core.slots.SlotDataStick;
import gtPlusPlus.core.slots.SlotNoInput;
import gtPlusPlus.core.tileentities.machines.TileEntityProjectTable;

public class ContainerProjectTable extends Container {

    /** The crafting matrix inventory (3x3). */
    public InventoryCrafting craftMatrix = new InventoryCrafting(this, 3, 3);

    public IInventory craftResult = new InventoryCraftResult();

    protected TileEntityProjectTable tile_entity;
    public final InventoryProjectMain inventoryGrid;
    public final InventoryProjectOutput inventoryOutputs;

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

    private final int[] slotOutputs = new int[2];
    private final int[] slotGrid = new int[9];

    public ContainerProjectTable(final InventoryPlayer inventory, final TileEntityProjectTable tile) {
        this.tile_entity = tile;
        this.inventoryGrid = tile.inventoryGrid;
        this.inventoryOutputs = tile.inventoryOutputs;
        this.tile_entity.setContainer(this);

        int var6;
        int var7;
        this.worldObj = tile.getWorldObj();
        this.posX = tile.xCoord;
        this.posY = tile.yCoord;
        this.posZ = tile.zCoord;

        int nextFreeSlot = 0;

        // Output slots
        this.addSlotToContainer(new SlotDataStick(this.inventoryOutputs, 0, 26 + (18 * 6), 8));
        this.addSlotToContainer(new SlotNoInput(this.inventoryOutputs, 1, 26 + (18 * 6), 44));

        this.addSlotToContainer(
            new SlotCraftingNoCollect(inventory.player, this.craftMatrix, this.craftResult, 0, 26 + (18 * 4), 25));

        int o = 0;
        // Storage Side
        for (var6 = 0; var6 < 3; ++var6) {
            for (var7 = 0; var7 < 3; ++var7) {
                this.addSlotToContainer(
                    new Slot(this.craftMatrix, nextFreeSlot, 8 + 18 + (var7 * 18), 8 + (var6 * 18)));
                this.slotGrid[o] = nextFreeSlot;
                nextFreeSlot++;
                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));
        }

        this.onCraftMatrixChanged(this.craftMatrix);
    }

    /**
     * Callback for when the crafting matrix is changed.
     */
    @Override
    public void onCraftMatrixChanged(IInventory p_75130_1_) {
        this.craftResult.setInventorySlotContents(
            0,
            CraftingManager.getInstance()
                .findMatchingRecipe(this.craftMatrix, this.worldObj));
    }

    /**
     * Called when the container is closed.
     */
    @Override
    public void onContainerClosed(EntityPlayer p_75134_1_) {
        super.onContainerClosed(p_75134_1_);
        if (!this.worldObj.isRemote) {
            for (int i = 0; i < 9; ++i) {
                ItemStack itemstack = this.craftMatrix.getStackInSlotOnClosing(i);
                if (itemstack != null) {
                    p_75134_1_.dropPlayerItemWithRandomChoice(itemstack, false);
                }
            }
        }
    }

    @Override
    public ItemStack slotClick(final int aSlotIndex, final int aMouseclick, final int aShifthold,
        final EntityPlayer aPlayer) {

        if (!aPlayer.worldObj.isRemote) {
            if ((aSlotIndex == 999) || (aSlotIndex == -999)) {
                // Utils.LOG_WARNING("??? - "+aSlotIndex);
            }

            if (aSlotIndex == 0) {
                Logger.INFO("Player Clicked on the Data Stick slot");
                // TODO
            }
            if (aSlotIndex == 1) {
                Logger.INFO("Player Clicked on the output slot");
                // TODO
            }

            for (final int x : this.slotGrid) {
                if (aSlotIndex == x) {
                    Logger.INFO("Player Clicked slot " + aSlotIndex + " in the crafting Grid");
                }
            }
        }
        // Utils.LOG_WARNING("Player Clicked slot "+aSlotIndex+" in the Grid");
        return super.slotClick(aSlotIndex, aMouseclick, aShifthold, aPlayer);
    }

    @Override
    public boolean canInteractWith(final EntityPlayer par1EntityPlayer) {
        if (this.worldObj.getBlock(this.posX, this.posY, this.posZ) != ModBlocks.blockProjectTable) {
            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) {

        return null;

        /*
         * ItemStack var3 = null; final Slot var4 = (Slot)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((ItemStack)null); } else { var4.onSlotChanged(); } if (var5.stackSize == var3.stackSize) {
         * return null; } var4.onPickupFromSlot(par1EntityPlayer, var5); } return var3;
         */
    }

    // Can merge Slot
    @Override
    public boolean func_94530_a(ItemStack p_94530_1_, Slot p_94530_2_) {
        return p_94530_2_.inventory != this.craftResult && super.func_94530_a(p_94530_1_, p_94530_2_);
    }

    public ItemStack getOutputContent() {
        return this.craftResult.getStackInSlot(0);
    }

    public ItemStack[] getInputComponents() {
        ItemStack[] inputs = new ItemStack[9];
        for (int r = 0; r < this.craftMatrix.getSizeInventory(); r++) {
            ItemStack temp = this.craftMatrix.getStackInSlot(r);
            inputs[r] = temp;
        }
        return inputs;
    }
}