Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

Saving some Information in World!


CreativeMD
 Share

Recommended Posts

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);
}

}

Link to comment
Share on other sites

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

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

 Share



×
×
  • Create New...

Important Information

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