Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

  • Author

Am I on the right track here?

 

@Override
public void writeToNBT(NBTTagCompound nbt){
    	super.writeToNBT(nbt);  
    	nbt.setByte("renderValue", this.renderValue);
    	nbt.setString("state", this.state);
    	
    	NBTTagCompound siren = new NBTTagCompound();

    	for (int i = 0; i < sirens.size(); i++){
        	siren.setInteger("x" + i, sirens.get(i).xCoord);
        	siren.setInteger("y" + i, sirens.get(i).yCoord);
        	siren.setInteger("z" + i, sirens.get(i).zCoord);
        	siren.setInteger("listSize", i);
    	}
    	

    	NBTTagList list = new NBTTagList();
    	
    	list.appendTag(siren);
    	
    	nbt.setTag("sirens", list);
}

@Override
public void readFromNBT(NBTTagCompound nbt){
	super.readFromNBT(nbt);
	this.renderValue = nbt.getByte("renderValue");
	this.state = nbt.getString("state");

	NBTTagList list = (NBTTagList) nbt.getTag("sirens"); 
	NBTTagCompound siren = list.getCompoundTagAt(0);

	for (int i = 0; i < siren.getInteger("listSize"); i ++){
		TileEntity tile = new TileEntity();
		//tile.xCoord is (siren.getInteger("x" + i);
		this.sirens.add(tile);
	}

}

Yes and No, you redesigned wheel.

 

Example:

NBTTagCompound mainNBT = new NBTTagCompound(); //pareent nbt
NBTTagList history = new NBTTagList(); // the list
NBTTagCompound level; //tag in list on "i" index
for (int lvl = 0; lvl <= this.getLevel(); ++lvl)
{
level = new NBTTagCompound(); // each "i" index has one NBT

level.setString("A", a); // write whatever you want in given NBT index

history.appendTag(level); // apend index to list
}
mainNBT.setTag("History", history); // write list to main NBT

 

The NBTTagList ships its size.

 

Reading:

NBTTagList history = stats.getTagList("History", 10);
NBTTagCompound level;
for (int lvl = 0; lvl < history.tagCount(); ++lvl)
{
level = (NBTTagCompound) history.getCompoundTagAt(lvl);
...

 

EDIT

Personal note:

If your whole array will look like this: x1, y1, z1, x2, y2, z2, x3, y3, z3, ....    then you know that i*1 is x, i*2 is y, i*3 is z (for i >= 1).

You can use "NBTTagIntArray" - will be a bit smaller and faster, but whatever, reading/writing is done once in a while so you might aswell not bother.

1.7.10 is no longer supported by forge, you are on your own.

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...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.