/
WorkbenchContainer.java
131 lines (121 loc) · 3.86 KB
/
WorkbenchContainer.java
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
package mods.natura.gui;
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.inventory.SlotCrafting;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.CraftingManager;
import net.minecraft.world.World;
public class WorkbenchContainer extends Container
{
public InventoryCrafting craftMatrix;
public IInventory craftResult;
private World worldObj;
public WorkbenchContainer(InventoryPlayer inventoryplayer, World world)
{
craftMatrix = new InventoryCrafting(this, 3, 3);
craftResult = new InventoryCraftResult();
worldObj = world;
this.addSlotToContainer(new SlotCrafting(inventoryplayer.player, craftMatrix, craftResult, 0, 124, 35));
for (int i = 0; i < 3; i++)
{
for (int l = 0; l < 3; l++)
{
this.addSlotToContainer(new Slot(craftMatrix, l + i * 3, 30 + l * 18, 17 + i * 18));
}
}
for (int column = 0; column < 3; column++)
{
for (int row = 0; row < 9; row++)
{
this.addSlotToContainer(new Slot(inventoryplayer, row + column * 9 + 9, 8 + row * 18, 84 + column * 18));
}
}
for (int column = 0; column < 9; column++)
{
this.addSlotToContainer(new Slot(inventoryplayer, column, 8 + column * 18, 142));
}
onCraftMatrixChanged(craftMatrix);
}
public void onCraftMatrixChanged (IInventory iinventory)
{
craftResult.setInventorySlotContents(0, CraftingManager.getInstance().findMatchingRecipe(craftMatrix, worldObj));
}
public void onContainerClosed (EntityPlayer entityplayer)
{
super.onContainerClosed(entityplayer);
if (worldObj.isRemote)
{
return;
}
for (int i = 0; i < 9; i++)
{
ItemStack itemstack = craftMatrix.getStackInSlot(i);
if (itemstack != null)
{
entityplayer.entityDropItem(itemstack, 0);
}
}
}
public boolean canInteractWith (EntityPlayer entityplayer)
{
return true;
}
@Override
public ItemStack transferStackInSlot (EntityPlayer entityplayer, 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, 10, 46, true))
{
return null;
}
}
else if (i >= 10 && i < 37)
{
if (!mergeItemStack(itemstack1, 37, 46, false))
{
return null;
}
}
else if (i >= 37 && i < 46)
{
if (!mergeItemStack(itemstack1, 10, 37, false))
{
return null;
}
}
else if (!mergeItemStack(itemstack1, 10, 46, false))
{
return null;
}
if (itemstack1.stackSize == 0)
{
slot.putStack(null);
}
else
{
slot.onSlotChanged();
}
if (itemstack1.stackSize != itemstack.stackSize)
{
slot.onPickupFromSlot(entityplayer, itemstack1);
}
else
{
return null;
}
}
return itemstack;
}
}