OSDN Git Service

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