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

Posted

Hi,

How do i save information in the World?

I have no idea, i got really confused.

Would be very nice, if someone could help me.

  • Author

ok, so far so good.

But how i have to go on?

package randomadditions;

import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.world.WorldSavedData;

public class WorldSaveRandomData extends WorldSavedData{

public WorldSaveRandomData(String par1Str) {
	super(par1Str);
}

@Override
public void readFromNBT(NBTTagCompound var1) {
	RandomAdditions.WorldVersion = var1.getDouble("RAV");
}

@Override
public void writeToNBT(NBTTagCompound var1) {
	var1.setDouble("RAV", RandomAdditions.ModVersion);
}

}

here is my world save data:

package legendz.common;

import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.world.World;
import net.minecraft.world.WorldSavedData;
import net.minecraft.world.storage.MapStorage;

public class WorldSaveData extends WorldSavedData {

public static boolean[] alreadyGenerated = new boolean[8];

public WorldSaveData(String par1Str) {
	super(par1Str);
}

@Override
public void readFromNBT(NBTTagCompound nbt) {
	for(int i = 0; i < alreadyGenerated.length; i++){
		alreadyGenerated[i] = nbt.getBoolean("generated"+i);
	}
}

@Override
public void writeToNBT(NBTTagCompound nbt) {
	for(int i = 0; i < alreadyGenerated.length; i++){
		nbt.setBoolean("generated"+i, alreadyGenerated[i]);
	}
}

}

 

i call it in the generate method so structures will only be generated once.

here is the code where i call it:

if(world.loadItemData(WorldSaveData.class, "LegendzWorldSaveData") == null){
		WorldSavedData data = new WorldSaveData("LegendzWorldSaveData");
		world.setItemData("LegendzWorldSaveData", data);
	}

	worldSaveData = (WorldSaveData) world.loadItemData(WorldSaveData.class, "LegendzWorldSaveData");

 

hope this makes it a little more clear for you.

i had the same trouble figuring out how to store data in the world and is was a pain in the @$$ :P

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.