GenuineSounds

Protocol error, unexpected packet.

Dec 31st, 2012
399
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 6.40 KB | None | 0 0
  1. Tile Entity
  2. -----------------------------------------------------------------------------------------------------
  3. package net.minecraft.src;
  4.  
  5. import net.minecraft.block.Block;
  6. import net.minecraft.nbt.NBTTagCompound;
  7. import net.minecraft.network.INetworkManager;
  8. import net.minecraft.network.packet.Packet;
  9. import net.minecraft.network.packet.Packet132TileEntityData;
  10. import net.minecraft.tileentity.TileEntity;
  11.  
  12. public class GenuineTileEntityTrophySilver extends TileEntity {
  13.  
  14.     public String type;
  15.  
  16.     public float size;
  17.  
  18.     public GenuineTileEntityTrophySilver() {
  19.         this.type = "Chicken";
  20.         this.size = 0.5F;
  21.     }
  22.  
  23.     @Override
  24.     public void readFromNBT(NBTTagCompound nbttagcompound) {
  25.         super.readFromNBT(nbttagcompound);
  26.         this.type = nbttagcompound.getString("type");
  27.         this.size = nbttagcompound.getFloat("size");
  28.         System.out.println("Load Type: " + type);
  29.     }
  30.  
  31.     @Override
  32.     public void writeToNBT(NBTTagCompound nbttagcompound) {
  33.         super.writeToNBT(nbttagcompound);
  34.         nbttagcompound.setString("type", this.type);
  35.         nbttagcompound.setFloat("size", this.size);
  36.         System.out.println("Saved Type: " + type);
  37.     }
  38.  
  39.     @Override
  40.     public Packet getDescriptionPacket() {
  41.         NBTTagCompound nbt = new NBTTagCompound();
  42.         nbt.setString("type", type);
  43.         nbt.setFloat("size", size);
  44.         return new Packet132TileEntityData(xCoord, yCoord, zCoord, 0, nbt);
  45.     }
  46.  
  47.     @Override
  48.     public void onDataPacket(INetworkManager net, Packet132TileEntityData pkt) {
  49.         this.type = pkt.customParam1.getString("type");
  50.         this.size = pkt.customParam1.getFloat("size");
  51.         super.onDataPacket(net, pkt);
  52.     }
  53. }
  54.  
  55. GUI - Relevant parts being on GUI close.
  56. -----------------------------------------------------------------------------------------------------
  57.  
  58. package net.minecraft.src;
  59.  
  60. import java.lang.reflect.Field;
  61. import java.lang.reflect.Modifier;
  62. import java.util.Iterator;
  63. import java.util.Map;
  64.  
  65. import net.minecraft.client.gui.GuiButton;
  66. import net.minecraft.client.gui.GuiScreen;
  67. import net.minecraft.client.multiplayer.NetClientHandler;
  68. import net.minecraft.entity.EntityList;
  69. import net.minecraft.entity.EntityLiving;
  70. import net.minecraft.entity.player.EntityPlayer;
  71. import net.minecraft.nbt.NBTTagCompound;
  72. import net.minecraft.network.packet.Packet130UpdateSign;
  73. import net.minecraft.world.World;
  74.  
  75. public class GenuineGuiTrophySilver extends GuiScreen {
  76.  
  77.     private static boolean init;
  78.  
  79.     private static void generateEntityList() {
  80.         Field field = EntityList.class.getDeclaredFields()[1];
  81.         field.setAccessible(true);
  82.         Map map = null;
  83.         try {
  84.             map = (Map) field.get(null);
  85.         }
  86.         catch (Exception exception) {
  87.             exception.printStackTrace();
  88.         }
  89.         if (map != null) {
  90.             Iterator iterator = map.keySet().iterator();
  91.             while (iterator.hasNext()) {
  92.                 Class class1 = (Class) iterator.next();
  93.                 try {
  94.                     if (EntityLiving.class.isAssignableFrom(class1) && class1.getConstructor(new Class[] { World.class }) != null && !Modifier.isAbstract(class1.getModifiers())) {
  95.                         String s = (String) map.get(class1);
  96.                         if (!mod_GenuineTrophy.trophyListContains(s))
  97.                             mod_GenuineTrophy.registerTrophy(s);
  98.                     }
  99.                 }
  100.                 catch (SecurityException securityexception) {}
  101.                 catch (NoSuchMethodException nosuchmethodexception) {}
  102.             }
  103.         }
  104.         GenuineGuiTrophySilver.init = true;
  105.     }
  106.  
  107.     private GenuineTileEntityTrophySilver trophy;
  108.  
  109.     private EntityPlayer player;
  110.  
  111.     private int pageMax;
  112.  
  113.     private int pageCurrent;
  114.  
  115.     public GenuineGuiTrophySilver(GenuineTileEntityTrophySilver tileEntitySilver, EntityPlayer entityPlayer) {
  116.         this.trophy = tileEntitySilver;
  117.         this.player = entityPlayer;
  118.         this.pageMax = 1;
  119.         this.pageCurrent = 1;
  120.     }
  121.  
  122.     @Override
  123.     public void onGuiClosed() {
  124.         NetClientHandler var1 = this.mc.getSendQueue();
  125.         if (var1 != null)
  126.             var1.addToSendQueue(this.trophy.getDescriptionPacket());
  127.         super.onGuiClosed();
  128.     }
  129.  
  130.     @Override
  131.     protected void actionPerformed(GuiButton guibutton) {
  132.         boolean flag = guibutton.enabled;
  133.         if (this.trophy == null || !flag)
  134.             return;
  135.         if (guibutton.id == 0 || guibutton.id == 1) {
  136.             if (guibutton.id == 0)
  137.                 this.pageCurrent--;
  138.             if (guibutton.id == 1)
  139.                 this.pageCurrent++;
  140.             for (int k = 0; k < this.controlList.size() - 2; k++)
  141.                 ((GuiButton) this.controlList.get(k + 2)).drawButton = false;
  142.             for (int k = 32 * (this.pageCurrent - 1); k < 32 * this.pageCurrent; k++)
  143.                 if (k < this.controlList.size() - 2)
  144.                     ((GuiButton) this.controlList.get(k + 2)).drawButton = true;
  145.         } else {
  146.             this.trophy.type = guibutton.displayString.equalsIgnoreCase("Human") ? "Monster" : guibutton.displayString;
  147.             this.trophy.size = 0.5F;
  148.             this.mc.displayGuiScreen(null);
  149.             this.mc.setIngameFocus();
  150.             ModLoader.openGUI(this.player, new GenuineGuiTrophySilverOptions(this.trophy));
  151.         }
  152.     }
  153.  
  154.     @Override
  155.     public void drawScreen(int i, int j, float f) {
  156.         this.drawDefaultBackground();
  157.         this.drawCenteredString(this.fontRenderer, "Select which mob to display.", this.width / 2, this.height / 8 - 20, 0xffffff);
  158.         this.drawCenteredString(this.fontRenderer, "Page: " + this.pageCurrent + "/" + this.pageMax, this.width / 2, this.height / 8 + 185, 0xffffff);
  159.         super.drawScreen(i, j, f);
  160.     }
  161.  
  162.     @Override
  163.     public void initGui() {
  164.         if (!GenuineGuiTrophySilver.init)
  165.             GenuineGuiTrophySilver.generateEntityList();
  166.         this.controlList.add(new GuiButton(0, this.width / 2 - 120, this.height / 8 + 180, 75, 20, "Prev"));
  167.         this.controlList.add(new GuiButton(1, this.width / 2 + 50, this.height / 8 + 180, 75, 20, "Next"));
  168.         int npcInt = 0;
  169.         for (int k = 0; k < mod_GenuineTrophy.getTrophyListSize() - npcInt; k++) {
  170.             String s = mod_GenuineTrophy.getTrophy(k);
  171.             GuiButton temp = new GuiButton(k + 2, this.width / 2 - 178 + k % 4 * 90, this.height / 8 + 22 * ((k >> 2) % 8), 88, 20, s);
  172.             if (k > 31)
  173.                 temp.drawButton = false;
  174.             this.controlList.add(temp);
  175.         }
  176.         this.pageMax = (int) Math.floor((this.controlList.size() - 3) / 32F) + 1;
  177.         if (this.pageMax == 1)
  178.             ((GuiButton) this.controlList.get(0)).enabled = ((GuiButton) this.controlList.get(1)).enabled = false;
  179.     }
  180.  
  181.     @Override
  182.     public void updateScreen() {
  183.         if (this.pageCurrent <= 1)
  184.             ((GuiButton) this.controlList.get(0)).enabled = false;
  185.         else
  186.             ((GuiButton) this.controlList.get(0)).enabled = true;
  187.         if (this.pageCurrent >= this.pageMax)
  188.             ((GuiButton) this.controlList.get(1)).enabled = false;
  189.         else
  190.             ((GuiButton) this.controlList.get(1)).enabled = true;
  191.         super.updateScreen();
  192.     }
  193. }
Advertisement
Comments
  • User was banned
Add Comment
Please, Sign In to add comment