Posted December 1, 20178 yr Today I've tried implementing a world save data into my mod by extending WorldSavedData Seems like it saves property (I mean, write and read nbt are called properly) But as I check the .dat file it is empty. EDIT: I've tried debugging and seems like that this line in WriteToNBT() compound.getTagList("coordinates", Constants.NBT.TAG_LIST).appendTag(pos); is not working properly. If I print the compund it is empty System.err.println("Writing " + blockPos + " aka " + pos + " to " + compound); [14:11:38] [Server thread/INFO]: [STDERR]: Writing BlockPos{x=-151338, y=74, z=-189} aka {x:-151338,y:74,z:-189} to {} [14:11:38] [Server thread/INFO]: [STDERR]: Writing BlockPos{x=-151106, y=76, z=-400} aka {x:-151106,y:76,z:-400} to {} [14:11:38] [Server thread/INFO]: [STDERR]: Writing BlockPos{x=-51186, y=71, z=167} aka {x:-51186,y:71,z:167} to {} [14:11:38] [Server thread/INFO]: [STDERR]: Writing BlockPos{x=-51665, y=70, z=82} aka {x:-51665,y:70,z:82} to {} [14:11:38] [Server thread/INFO]: [STDERR]: Wrote to NBT {} WorldSavedData source code: package net.insane96mcp.naturalnetherportals.events; import java.util.ArrayList; import java.util.List; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; import net.minecraft.world.WorldSavedData; import net.minecraftforge.common.util.Constants; public class PortalSavedData extends WorldSavedData { public PortalSavedData() { super(IDENTIFIER); } public PortalSavedData(String name) { super(name); // TODO Auto-generated constructor stub } private List<BlockPos> portalPositions = new ArrayList<BlockPos>(); public List<BlockPos> getPortalPositions(){ return portalPositions; } public boolean addPortalPosition(BlockPos pos) { if (portalPositions.add(pos)) { markDirty(); System.out.println(String.format("Added Portal %d %d %d to list", pos.getX(), pos.getY(), pos.getZ())); return true; } System.err.println("Failed to add portal position to positions list"); return false; } private static final String IDENTIFIER = "naturalnetherportals"; public static PortalSavedData get(World world) { PortalSavedData data = (PortalSavedData)world.loadData(PortalSavedData.class, IDENTIFIER); if (data == null) { data = new PortalSavedData(); world.setData(IDENTIFIER, data); } System.err.println("get"); return data; } @Override public void readFromNBT(NBTTagCompound nbt) { NBTTagList tagList = nbt.getTagList("coordinates", Constants.NBT.TAG_LIST); for (int i = 0; i < tagList.tagCount(); i++) { portalPositions = new ArrayList<BlockPos>(); int x = tagList.getCompoundTagAt(i).getInteger("x"); int y = tagList.getCompoundTagAt(i).getInteger("y"); int z = tagList.getCompoundTagAt(i).getInteger("z"); BlockPos pos = new BlockPos(x, y, z); portalPositions.add(pos); } System.err.println("Read from NBT"); } @Override public NBTTagCompound writeToNBT(NBTTagCompound compound) { NBTTagCompound pos; for (BlockPos blockPos : portalPositions) { pos = new NBTTagCompound(); pos.setInteger("x", blockPos.getX()); pos.setInteger("y", blockPos.getY()); pos.setInteger("z", blockPos.getZ()); compound.getTagList("coordinates", Constants.NBT.TAG_LIST).appendTag(pos); } System.err.println("Wrote to NBT"); return compound; } } NBT .dat file I really don't know what I'm doing wrong here Edited December 2, 20178 yr by Insane96MCP SOLVED
December 1, 20178 yr Random question: Why are you printing to standard error? You know every mod had a mod specific logger, right? (Also... System.out is a Thing...) Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable. If you think this is the case, JUST REPORT ME. Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice. Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked. DO NOT PM ME WITH PROBLEMS. No help will be given.
December 1, 20178 yr Author 43 minutes ago, Draco18s said: Why are you printing to standard error? Maybe I have done too much C those days, damn fprintfs 43 minutes ago, Draco18s said: You know every mod had a mod specific logger, right? Ehm no Edited December 1, 20178 yr by Insane96MCP
December 1, 20178 yr public void preInit(FMLPreInitializationEvent event) { logger = event.getModLog(); } Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable. If you think this is the case, JUST REPORT ME. Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice. Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked. DO NOT PM ME WITH PROBLEMS. No help will be given.
December 1, 20178 yr Author 5 minutes ago, Draco18s said: public void preInit(FMLPreInitializationEvent event) { logger = event.getModLog(); } Oh wait. I've now relalized that I have copy pasted the err.println() instead of out.println() Is using the logger better than System...println?
December 1, 20178 yr Yes, because it includes information like what mod the message is coming from and where in the code it was called from. Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable. If you think this is the case, JUST REPORT ME. Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice. Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked. DO NOT PM ME WITH PROBLEMS. No help will be given.
December 1, 20178 yr Author 4 minutes ago, Draco18s said: Yes, because it includes information like what mod the message is coming from and where in the code it was called from. How I can display the Logger logs in Eclipse console?
December 1, 20178 yr They do, automatically. I forget what the default logging level is (things below it don't show), but I'm pretty sure Level.INFO works (I'm using it currently) but if it doesn't, you can use Level.WARN Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable. If you think this is the case, JUST REPORT ME. Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice. Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked. DO NOT PM ME WITH PROBLEMS. No help will be given.
December 1, 20178 yr Author 3 hours ago, Draco18s said: They do, automatically. I forget what the default logging level is (things below it don't show), but I'm pretty sure Level.INFO works (I'm using it currently) but if it doesn't, you can use Level.WARN Maybe there's something to set since with Level.DEBUG doesn't log into Eclipse Console
December 1, 20178 yr 10 minutes ago, Insane96MCP said: Maybe there's something to set since with Level.DEBUG doesn't log into Eclipse Console Like I said, minimum logging levels. Debug would be below it, Warn above it. Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable. If you think this is the case, JUST REPORT ME. Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice. Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked. DO NOT PM ME WITH PROBLEMS. No help will be given.
December 2, 20178 yr Author On 1/12/2017 at 10:06 PM, diesieben07 said: This means "give me a tag list with tag lists in it". But you wrote to disk in writeToNbt is a tag list with tag compounds in it, hence the data will be ignored. I'm still doing something wrong. I've changed to nbt.getTagList("coordinates", Constants.NBT.TAG_COMPOUND); but It still writes and (since there's nothing to read) reads nothing EDIT: Nevermind, I wans't adding back the taglist in the compound Right WriteToNBT() code: @Override public NBTTagCompound writeToNBT(NBTTagCompound compound) { NBTTagCompound pos; NBTTagList tagList = compound.getTagList("coordinates", Constants.NBT.TAG_COMPOUND); for (BlockPos blockPos : portalPositions) { pos = new NBTTagCompound(); pos.setInteger("x", blockPos.getX()); pos.setInteger("y", blockPos.getY()); pos.setInteger("z", blockPos.getZ()); tagList.appendTag(pos); } compound.setTag("coordinates", tagList); return compound; } Edited December 12, 20178 yr by Insane96MCP SOLVED
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.