OSDN Git Service

修正・変更
[chemicraft/chemicraft.git] / common / pcc / chemicraft / container / ContainerPyrolysisTable.java
1 package pcc.chemicraft.container;
2
3 import net.minecraft.entity.player.EntityPlayer;
4 import net.minecraft.inventory.Container;
5 import net.minecraft.inventory.Slot;
6 import net.minecraft.item.ItemStack;
7 import net.minecraft.world.World;
8 import pcc.chemicraft.ChemiCraft;
9 import pcc.chemicraft.inventory.InventoryPyrolysisTableFuel;
10 import pcc.chemicraft.inventory.InventoryPyrolysisTableMaterial;
11 import pcc.chemicraft.inventory.InventoryPyrolysisTableResult;
12 import pcc.chemicraft.slot.SlotPyrolysisTableFuel;
13 import pcc.chemicraft.slot.SlotPyrolysisTableMaterial;
14 import pcc.chemicraft.slot.SlotPyrolysisTableResult;
15 import pcc.chemicraft.tileentity.TileEntityPyrolysisTable;
16
17
18 public class ContainerPyrolysisTable extends Container {
19
20         private World worldObj;
21
22         private int posX;
23         private int posY;
24         private int posZ;
25
26         private TileEntityPyrolysisTable tileentity;
27
28         private InventoryPyrolysisTableMaterial invm;
29         private InventoryPyrolysisTableResult invr;
30         private InventoryPyrolysisTableFuel invf;
31
32         public ContainerPyrolysisTable(EntityPlayer par1EntityPlayer, TileEntityPyrolysisTable par2){
33                 super();
34                 this.tileentity = par2;
35                 this.worldObj = par2.worldObj;
36                 this.posX = par2.xCoord;
37                 this.posY = par2.yCoord;
38                 this.posZ = par2.zCoord;
39                 this.invm = par2.getInvMaterial();
40                 this.invr = par2.getInvResult();
41                 this.invf = par2.getInvFuel();
42                 this.invm.setEventHandler(this);
43                 this.invr.setEventHandler(this);
44                 this.invf.setEventHandler(this);
45
46                 for (int i = 0; i < 4; i++) {
47                         for (int j = 0; j < 4; j++) {
48                                 this.addSlotToContainer(new SlotPyrolysisTableResult(this.tileentity.getInvResult(), i*4 + j, 88+i*18, 17+j*18));
49                         }
50                 }
51                 this.addSlotToContainer(new SlotPyrolysisTableMaterial(this.tileentity.getInvMaterial(), 0, 27, 20));
52                 this.addSlotToContainer(new SlotPyrolysisTableFuel(this.tileentity.getInvFuel(), 0, 27, 63));
53
54                 int var3;
55                 for (var3 = 0; var3 < 3; ++var3)
56                 {
57                         for (int var4 = 0; var4 < 9; ++var4)
58                         {
59                                 this.addSlotToContainer(new Slot(par1EntityPlayer.inventory, var4 + var3 * 9 + 9, 8 + var4 * 18, 121 + var3 * 18));
60                         }
61                 }
62
63                 for (var3 = 0; var3 < 9; ++var3)
64                 {
65                         this.addSlotToContainer(new Slot(par1EntityPlayer.inventory, var3, 8 + var3 * 18, 179));
66                 }
67         }
68
69         @Override
70         public boolean canInteractWith(EntityPlayer par1EntityPlayer) {
71                 return this.worldObj.getBlockId(this.posX, this.posY, this.posZ) != ChemiCraft.instance.pyrolysisTableID ? false : par1EntityPlayer.getDistanceSq((double)this.posX + 0.5D, (double)this.posY + 0.5D, (double)this.posZ + 0.5D) <= 64.0D;
72         }
73
74         @Override
75         public ItemStack transferStackInSlot(EntityPlayer par1EntityPlayer, int par2)
76         {
77                 ItemStack var3 = null;
78                 Slot var4 = (Slot)this.inventorySlots.get(par2);
79
80                 if (var4 != null && var4.getHasStack())
81                 {
82                         ItemStack var5 = var4.getStack();
83                         var3 = var5.copy();
84
85                         if (par2 < 18 ){
86                                 if (!this.mergeItemStack(var5, 18, this.inventorySlots.size(), true))
87                                 {
88                                         return null;
89                                 }
90                         }
91                         else if (!this.mergeItemStack(var5, 16, 18, false))
92                         {
93                                 return null;
94                         }
95
96                         if (var5.stackSize == 0)
97                         {
98                                 var4.putStack((ItemStack)null);
99                         }
100                         else
101                         {
102                                 var4.onSlotChanged();
103                         }
104                 }
105
106                 return var3;
107         }
108
109 }