OSDN Git Service

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