OSDN Git Service

化合台完成
[chemicraft/chemicraft.git] / common / chemicraft / gui / GuiChemicalCombinationTable.java
1 package chemicraft.gui;
2
3 import java.util.ArrayList;
4 import java.util.Arrays;
5
6 import net.minecraft.src.EntityItem;
7 import net.minecraft.src.EntityPlayer;
8 import net.minecraft.src.GuiButton;
9 import net.minecraft.src.GuiContainer;
10 import net.minecraft.src.GuiTextField;
11 import net.minecraft.src.IInventory;
12 import net.minecraft.src.ItemStack;
13 import net.minecraft.src.World;
14 import chemicraft.ChemiCraft;
15 import chemicraft.container.ContainerChemicalCombinationTable;
16 import chemicraft.tileentity.TileEntityChemicalCombinationTable;
17 import chemicraft.util.ComparatorItemStack;
18 import cpw.mods.fml.common.network.PacketDispatcher;
19
20 public class GuiChemicalCombinationTable extends GuiContainer {
21
22         private GuiTextField atomList;
23
24         private TileEntityChemicalCombinationTable tileentity;
25
26         public GuiChemicalCombinationTable(EntityPlayer par1EntityPlayer, TileEntityChemicalCombinationTable par2) {
27                 super(new ContainerChemicalCombinationTable(par1EntityPlayer, par2));
28                 this.tileentity = par2;
29         }
30
31         @Override
32         public void initGui(){
33                 super.initGui();
34                 this.atomList = new GuiTextField(this.fontRenderer, 92, 7, 80, 15);
35                 this.atomList.setFocused(false);
36                 this.atomList.setMaxStringLength(20);
37                 this.controlList.add(new GuiButton(0, this.guiLeft + 132 - 41, this.guiTop + 63, 40, 20, "Add"));
38                 this.controlList.add(new GuiButton(1, this.guiLeft + 132, this.guiTop + 63, 40, 20, "Eject"));
39         }
40
41         @Override
42         protected void drawGuiContainerBackgroundLayer(float var1, int var2, int var3) {
43                 this.mc.renderEngine.bindTexture(this.mc.renderEngine.getTexture(ChemiCraft.instance.guiChemicalCombinationTexture));
44                 this.drawTexturedModalRect(this.guiLeft, this.guiTop, 0, 0, this.xSize, this.ySize);
45         }
46
47         @Override
48         protected void actionPerformed(GuiButton par1GuiButton) {
49                 if(par1GuiButton.id == 0){
50                         this.field_00001(this.tileentity);
51                         PacketDispatcher.sendPacketToServer(this.tileentity.getDescriptionPacket());
52                 }else if(par1GuiButton.id == 1){
53                         this.field_00002(this.tileentity);
54                         PacketDispatcher.sendPacketToServer(this.tileentity.getDescriptionPacket());
55                 }
56                 return;
57         }
58
59         protected void field_00001(TileEntityChemicalCombinationTable par1){
60                 IInventory inv = par1.getInvMaterial();
61                 ItemStack[] stacks = new ItemStack[inv.getSizeInventory()];
62                 for(int i = 0;i < stacks.length;i++){
63                         if(inv.getStackInSlot(i) != null){
64                                 stacks[i] = inv.getStackInSlot(i);
65                         }
66                 }
67                 Arrays.sort(stacks, new ComparatorItemStack());
68                 stacks = ChemiCraft.instance.arrayAuxiliary.deleteNull(stacks);
69
70                 for(int i = 0;i < stacks.length;i++){
71                         if(stacks[i].stackSize > 1){
72                                 par1.setAtoms(ChemiCraft.ATOMSLIST[stacks[i].getItemDamage()], stacks[i].stackSize);
73                         }else{
74                                 par1.setAtoms(ChemiCraft.ATOMSLIST[stacks[i].getItemDamage()], 1);
75                         }
76                 }
77
78                 for(int i = 0;i < inv.getSizeInventory();i++){
79                         inv.setInventorySlotContents(i, null);
80                 }
81         }
82
83         protected void field_00002(TileEntityChemicalCombinationTable par1) {
84                 ArrayList<String> var1 = par1.getAtomsList();
85                 ArrayList<Integer> var2 = par1.getAtomsAmountList();
86
87                 for (int i = 0;i < var1.size();i++) {
88                         for (int j = 0;j < ChemiCraft.ATOMSLIST.length;j++) {
89                                 if (var1.get(i).equals(ChemiCraft.ATOMSLIST[j])) {
90                                         int var3 = var2.get(i);
91                                         while(var3 > 0){
92                                                 if(var3 > 64){
93                                                         ItemStack itemstack = new ItemStack(ChemiCraft.instance.itemAtoms, 64, j);
94                                                         this.tileentity.setDropItems(itemstack);
95                                                         PacketDispatcher.sendPacketToServer(this.tileentity.getDescriptionPacket());
96                                                         var3 -= 64;
97                                                 }else{
98                                                         ItemStack itemstack = new ItemStack(ChemiCraft.instance.itemAtoms, var3, j);
99                                                         this.tileentity.setDropItems(itemstack);
100                                                         PacketDispatcher.sendPacketToServer(this.tileentity.getDescriptionPacket());
101                                                         var3 = 0;
102                                                 }
103                                         }
104                                         break;
105                                 }
106                         }
107                 }
108                 IInventory invr = par1.getInvResult();
109                 if (invr.getStackInSlot(0) != null) {
110                         invr.setInventorySlotContents(0, null);
111                 }
112                 par1.emptytoAtomsList();
113         }
114
115         @Override
116         protected void drawGuiContainerForegroundLayer() {
117                 this.atomList.setText(this.tileentity.getAtoms());
118                 this.atomList.drawTextBox();
119         }
120
121 }