Jump to content

Saving A ForgeDirection[] to NBT [SOLVED] [1.7.10]


TheEpicTekkit

Recommended Posts

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.

Link to comment
Share on other sites

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/

Link to comment
Share on other sites

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.

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.