Jump to content

[1.7.10]Help updating code


LogicTechCorp

Recommended Posts

I am remaking an old mod and I cannot figure out how to update this piece of code:

 

    public Packet getAuxillaryInfoPacket()
    {
        ByteArrayOutputStream var1 = new ByteArrayOutputStream();
        DataOutputStream var2 = new DataOutputStream(var1);

        try
        {
            var2.writeByte(0);
            var2.writeInt(this.xCoord);
            var2.writeShort(this.yCoord);
            var2.writeInt(this.zCoord);

            for (int var3 = 0; var3 < 2; ++var3)
            {
                Packet.writeItemStack(this.switchBlocks[var3], var2);
            }

            var2.writeByte((byte)(this.switchBlockDirection | (this.editState ? 16 : 0)));
            var2.writeByte((byte)(this.lightLevel | (this.isLightMinimum ? 16 : 0) | (this.switchSound ? 32 : 0)));
            byte[] var5 = var1.toByteArray();
            var2.close();
            return new Packet250CustomPayload("SecretSwitches", var5);
        }
        catch (IOException var4)
        {
            var4.printStackTrace();
            return null;
        }
    }

Link to comment
Share on other sites

First, forget about all that try/catch and the DataIn/OutputStreams - that whole paradigm is not really used anymore. Please search for updated packet tutorials like I mentioned earlier. EDIT: Just to be clear, I don't mean that try/catch is no longer used at all, I mean specifically in this context it is not needed anymore.

 

For this particular case, you don't even need custom packets; use S35PacketUpdateTileEntity, which needs an NBTTagCompound - easy way is to just call your te's writeToNBT method and send that, but it's better to only send the data you need (i.e. write whatever you need to an NBTTagCompound, which you then send).

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.