OSDN Git Service

PacketHandler.javaにactuveTabを送受信に追加
authormozipi <mozipi@users.sourceforge.jp>
Mon, 10 Dec 2012 16:46:09 +0000 (01:46 +0900)
committermozipi <mozipi@users.sourceforge.jp>
Mon, 10 Dec 2012 16:46:09 +0000 (01:46 +0900)
りりごんさんとかぶってるけど問題ないので放置
TileEntityScienceCraftingTable.javaとかGuiScienceCraftingTableとかも機能追加

common/chemicraft/GuiScienceCraftingTable.java
common/chemicraft/PacketHandler.java
common/chemicraft/TileEntityScienceCraftingTable.java

index 1f55bda..6f6ccf9 100644 (file)
@@ -10,17 +10,12 @@ import net.minecraft.src.InventoryPlayer;
 import net.minecraft.src.ItemStack;
 import cpw.mods.fml.common.Side;
 import cpw.mods.fml.common.asm.SideOnly;
+import cpw.mods.fml.common.network.PacketDispatcher;
 
 @SideOnly(Side.CLIENT)
 public class GuiScienceCraftingTable extends GuiContainer {
 
        /**
-        * ActiveなTabの名前
-        */
-       private static String activeTabName;
-
-
-       /**
         * 分解機GUIのInventoryBasicクラス
         */
        private static InventoryBasic decompositionSlots = new InventoryBasic("Decomposition", 17);
@@ -47,15 +42,26 @@ public class GuiScienceCraftingTable extends GuiContainer {
 
 
 
+       /**
+        * the TileEntity.
+        */
+       private TileEntityScienceCraftingTable tileEntity;
+
+
+
        public GuiScienceCraftingTable(InventoryPlayer par1InventoryPlayer, TileEntityScienceCraftingTable par2){
                super(new ContainerScienceCraftingTable(par1InventoryPlayer, par2));
+               //TileEntityを設定
+               this.tileEntity = par2;
                //TabListにTabを追加する
                this.addTabs(0, "Decomposition", new ItemStack(Block.tnt.blockID, 1, 1));
                this.addTabs(1, "Test", new ItemStack(Block.bedrock.blockID, 1, 1));
                //ActiveTabの初期化
                for(int i = 0;i < tabList.size();i++){
-                       if(this.tabList.get(i).getTabName().equals(par2.getActiveTab())){
-                               this.activeTabName = this.tabList.get(i).getTabName();
+                       String field_00001 = this.tabList.get(i).getTabName();
+                       String field_00002 = this.tileEntity.getActiveTab();
+                       if(field_00001.equals(field_00002)){
+                               this.tileEntity.setActiveTab(this.tabList.get(i).getTabName());
                        }
                }
        }
@@ -68,10 +74,10 @@ public class GuiScienceCraftingTable extends GuiContainer {
 
                int var1 = par1 - this.guiLeft;
                int var2 = par2 - this.guiTop;
-               if(var1 < this.tabList.size() * 28 && var1 >= 0){
+               if(var1 < this.tabList.size() * 28 && var1 >= 0 && var2 < 0){
                        String var3 = this.tabList.get(var1 / 28).getTabName();
-                       if(!var3.equals(this.activeTabName)){
-                               this.activeTabName = var3;
+                       if(!var3.equals(this.tileEntity.getActiveTab())){
+                               this.tileEntity.setActiveTab(var3);
                        }
                }
        }
@@ -80,17 +86,19 @@ public class GuiScienceCraftingTable extends GuiContainer {
 
        @Override
        protected void drawGuiContainerBackgroundLayer(float par1, int par2, int par3){
-               //Active Reset
+               //ActiveTab Reset.
                this.func_00003();
                //Texture Load.
                this.func_00002();
                //Draw Tabs.
                this.func_00001(par1, par2, par3);
                //Draw GUI
-               if(this.activeTabName.equals("Decomposition")){
+               if(this.tileEntity.getActiveTab().equals("Decomposition")){
                        this.mc.renderEngine.bindTexture(this.guiImageMap.get("Decomposition"));
                        this.drawTexturedModalRect(this.guiLeft, this.guiTop, 0, 0, this.xSize, this.ySize);
                }
+               //TileEntity of ActiveTab Reset.
+               this.tileEntity.setActiveTab(this.tileEntity.getActiveTab());
        }
 
 
@@ -126,7 +134,7 @@ public class GuiScienceCraftingTable extends GuiContainer {
 
        private void func_00003(){
                for(int i = 0;i < this.tabList.size();i++){
-                       if(!this.tabList.get(i).getTabName().equals(this.activeTabName)){
+                       if(!this.tabList.get(i).getTabName().equals(this.tileEntity.getActiveTab())){
                                this.tabList.get(i).setActive(false);
                        }else{
                                this.tabList.get(i).setActive(true);
@@ -137,26 +145,6 @@ public class GuiScienceCraftingTable extends GuiContainer {
 
 
        /**
-        * Activeなtabの名前を返します
-        * @return ActiveなTabの名前
-        */
-       public static String getActiveTabName(){
-               return activeTabName;
-       }
-
-
-
-       /**
-        * ActiveなTabに対応したInventoryBasicクラスを返します
-        * @return ActiveなTabに対応したInventoryBasicクラス
-        */
-       public static InventoryBasic getActiveInventory(){
-               return decompositionSlots;
-       }
-
-
-
-       /**
         * ChemiCraftTabを追加します。
         * @param id TabのID
         * @param texture OverlayするTextureID
index bd26cda..c6e4f9e 100644 (file)
@@ -28,19 +28,25 @@ public class PacketHandler implements IPacketHandler {
        public void onPacketData(NetworkManager manager, Packet250CustomPayload packet, Player player) {\r
                if (packet.channel.equals("chemicraft")) {\r
                        ByteArrayDataInput var1 = ByteStreams.newDataInput(packet.data);\r
+\r
+                       //TileEntityのx, y, z座標\r
                        int x, y, z;\r
+                       //activeTab\r
+                       String activeTab;\r
 \r
-                       // パケットからデータ読み込み\r
+                       //座標読み込み\r
                        x = var1.readInt();\r
                        y = var1.readInt();\r
                        z = var1.readInt();\r
+                       //activeTab読み込み\r
+                       activeTab = var1.readUTF();\r
 \r
                        // TileEntityを取得し読み込んだデータを送る\r
                        World world = ChemiCraft.proxy.getClientWorld();\r
                        TileEntity tileEntity = world.getBlockTileEntity(x, y, z);\r
                        if (tileEntity instanceof TileEntityScienceCraftingTable) {\r
                                TileEntityScienceCraftingTable var2 = (TileEntityScienceCraftingTable) tileEntity;\r
-                               var2.handlePacket(null);\r
+                               var2.setActiveTab(activeTab);\r
                        }\r
                }\r
        }\r
@@ -49,17 +55,24 @@ public class PacketHandler implements IPacketHandler {
        public static Packet getPacket(TileEntityScienceCraftingTable tileEntity) {\r
                ByteArrayOutputStream var1 = new ByteArrayOutputStream(128);\r
                DataOutputStream var2 = new DataOutputStream(var1);\r
+\r
+               //Blockのx, y, z座標\r
                int x, y, z;\r
+               //activeTab\r
+               String activeTab;\r
 \r
-               // データの用意\r
+               // x, y, z座標を代入\r
                x = tileEntity.xCoord;\r
                y = tileEntity.yCoord;\r
                z = tileEntity.zCoord;\r
+               //activeTabに代入\r
+               activeTab = tileEntity.getActiveTab();\r
 \r
                try {\r
                        var2.writeInt(x);\r
                        var2.writeInt(y);\r
                        var2.writeInt(z);\r
+                       var2.writeUTF(activeTab);\r
                } catch (IOException e) {\r
                        e.printStackTrace();\r
                }\r
index 0e26ea7..253e1c4 100644 (file)
@@ -1,5 +1,6 @@
 package chemicraft;
 
+import cpw.mods.fml.common.network.PacketDispatcher;
 import net.minecraft.src.EntityPlayer;
 import net.minecraft.src.IInventory;
 import net.minecraft.src.ItemStack;
@@ -25,6 +26,7 @@ public class TileEntityScienceCraftingTable extends TileEntity implements IInven
 
 
        public TileEntityScienceCraftingTable() {
+               super();
                //ActiveTabのデフォルトを設定
                this.activeTab = "Decomposition";
        }
@@ -33,18 +35,21 @@ public class TileEntityScienceCraftingTable extends TileEntity implements IInven
        @Override
        public void updateEntity() {
                super.updateEntity();
+               System.out.println(this.activeTab);
        }
 
 
        @Override
        public void readFromNBT(NBTTagCompound par1) {
-               par1.setString("activeTab", this.activeTab);
+               super.readFromNBT(par1);
+               this.activeTab = par1.getString("activeTab");
        }
 
 
        @Override
        public void writeToNBT(NBTTagCompound par1) {
-               this.activeTab = par1.getString("activeTab");
+               super.writeToNBT(par1);
+               par1.setString("activeTab", this.activeTab);
        }
 
 
@@ -53,6 +58,12 @@ public class TileEntityScienceCraftingTable extends TileEntity implements IInven
        }
 
 
+       public void setActiveTab(String activeTab){
+               PacketDispatcher.sendPacketToServer(this.getDescriptionPacket());
+               this.activeTab = activeTab;
+       }
+
+
        @Override
        public int getSizeInventory() {
                return inventory.length;
@@ -116,10 +127,6 @@ public class TileEntityScienceCraftingTable extends TileEntity implements IInven
        }
 
 
-       public void handlePacket(Object[] data) {
-
-       }
-
 
        @Override
        public int getStartInventorySide(ForgeDirection side) {