Jump to content

Recommended Posts

Posted

Hi, I'm doing a little experimenting with NBT Tags. I'm  trying to save and load data player specific but I do not know how to access it correctly. It just results in a crash when I try to save/load to the tag. The additional properties attach to the player in my main file. Here is my code for the extended properties and Item class that call it:

Both Save and Load NBT arent working.

Extended Properties Class:

public static boolean[] recipes;
public static String[] recipeNames;

@Override
public void saveNBTData(NBTTagCompound compound) {
	NBTTagList cookValues = new NBTTagList();
	for (int i = 0; i < recipes.length; i++) {
		compound.setBoolean(recipeNames[i], recipes[i]);
		cookValues.appendTag(compound);
	}
	compound.setTag("Cookbook", cookValues);
}

@Override
public void loadNBTData(NBTTagCompound compound) {
	NBTTagList cookValues = compound.getTagList("Cookbook");
	for (int i = 0; i < cookValues.tagCount(); i++) {
		this.recipes[i] = compound.getBoolean(recipeNames[i]);
		System.out.println(recipes[i]);
	}
}

@Override
public void init(Entity entity, World world) {

}

public void writeRecipe(boolean par1, int par2, String par3) {
	recipes[par2] = par1;
	this.recipeNames[par2] = par3;
} 

 

Food Class:

@Override
public void onFoodEaten(ItemStack itemstack, World world,
		EntityPlayer player) {
	player.getFoodStats().addStats(this);
	world.playSoundAtEntity(player, "random.burp", 0.5F,
			world.rand.nextFloat() * 0.1F + 0.9F);
	this.addPotionEffects(itemstack, world, player);
	((EventCookbook) player.getExtendedProperties("Cookbook")).writeRecipe(
			true, 0);
} 

 

Any help appreciated

 

Edit: Fixed it on my own

Guest
This topic is now closed to further replies.

Announcements



×
×
  • Create New...

Important Information

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