Posted September 27, 201411 yr Hello Everyone. So I have been experiencing some lag issues with my mod, and have tracked it down to my cables constantly updating their connections and block bounds every tick (I was doing this in updateEntity()) So what I have done, is in the block class, I have changed it to update in onNeighborBlockChange(...). Now with this, when I reload the world, all the connections are gone, and each cable has to be updated. So my question is how can I write a ForgeDirection array to NBT? I ask complicated questions, and apparently like to write really long detailed posts. But I also help others when I can.
September 27, 201411 yr You can save the ordinals of it using (for example) ForgeDirection#ordinal() . Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support. 1.12 -> 1.13 primer by williewillus. 1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support. http://www.howoldisminecraft1710.today/
September 27, 201411 yr Author So would this work? public ForgeDirection[] connections = new ForgeDirection[6]; //This is the array that stores the connected sides. //Some irrelevant code here... public void readFromNBT(NBTTagCompound nbt) { super.readFromNBT(nbt); for (int i = 0; i < connections.length; i++) { this.connections[i] = nbt.getInteger("connections_" + i); } } public void writeToNBT(NBTTagCompound nbt) { super.writeToNBT(nbt); for (int i = 0; i < connections.length; i++) { nbt.setInteger("connections_" + i, connections[i].ordinal()); } } @Override public Packet getDescriptionPacket() { NBTTagCompound tag = new NBTTagCompound(); this.writeToNBT(tag); return new S35PacketUpdateTileEntity(xCoord, yCoord, zCoord, 1, tag); } @Override public void onDataPacket(NetworkManager net, S35PacketUpdateTileEntity packet) { this.readFromNBT(packet.func_148857_g()); } I ask complicated questions, and apparently like to write really long detailed posts. But I also help others when I can.
September 27, 201411 yr This: public void readFromNBT(NBTTagCompound nbt) { super.readFromNBT(nbt); for (int i = 0; i < connections.length; i++) { this.connections[i] =ForgeDirection.getOrientation( nbt.getInteger("connections_" + i)); } }
September 27, 201411 yr Author Okay, thanks, it is working fine now I ask complicated questions, and apparently like to write really long detailed posts. But I also help others when I can.
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.