Jump to content

iPanja

Members
  • Posts

    3
  • Joined

  • Last visited

Everything posted by iPanja

  1. Ok thank you Cadiboo and Draco18s. My main problem was that the client was attempting to save the information, and I have now changed that to the server side. Thanks again. I'll make it static as well.
  2. Originally, this code/event was triggered twice, presumably by the server and the client. After adding this statement, it only ran once when the player right clicked. I'm storing this variable purely for testing purposes. When I can get this to work, I will just be storing variables that have been generated along with the world that will be loaded at runtime, but will not be manipulated at runtime. My understanding of that line is to load the new values to the NBT in the save file, which I then mark dirty on the next line hoping it will save to the disk. Thank you for your response, I hope I cleared some of the things up. I'm not new to Java, not very advanced though either. A lot of my problems come from my understanding of forge, and how I should be using it instead of how I think it is supposed to work.
  3. I am trying to save information with the world. I have followed the docs to the best of my ability, along with reading similar posts on this forum, but I am still unable to get this to work. Currently, I have the Data class below which extends from WorldSavedData. It stores the data in one NBTTagCompound. Data Class public class ACSave extends WorldSavedData{ private static final String IDENTIFIER = "AC_DATA"; private NBTTagCompound data = new NBTTagCompound(); public ACSave(String identifier) { super(identifier); } public ACSave() { super(IDENTIFIER); } @Override public void readFromNBT(NBTTagCompound nbt) { data = nbt; } @Override public NBTTagCompound writeToNBT(NBTTagCompound nbt) { nbt = data; return nbt; } public static ACSave get(World world) { ACSave save = (ACSave) world.getMapStorage().getOrLoadData(ACSave.class, IDENTIFIER); if(save == null) { Minecraft.getMinecraft().player.sendChatMessage("Creating a new World Configuration File"); save = new ACSave(); world.getMapStorage().setData(IDENTIFIER, save); }else { Minecraft.getMinecraft().player.sendChatMessage("Using a pre-existing Configuration File!"); } return save; } } The follow event handler class calls upon this class. When the player loads into the world it creates a new ACSave object and calls the get() method. Whenever the player right clicks it increases the integer "Yeet" by one, displaying the new value in chat. It then marks the ACSave object as dirty, so it should be saving but it never does. Whether I wait or stop the world the data file is never created/saved. When I relaunch the world the data is all lost. On another NBT data related post, the user showed that the console ouptuted a line saying how the class was marked dirty when he exited the world, but that has never happened for me. When the world stops nothing special happens at all. public class ACEventHandler { ACSave save; NBTTagCompound nbt = new NBTTagCompound(); @SubscribeEvent public void RightClickBlock(PlayerInteractEvent.RightClickItem event) { if(event.getEntity() == Minecraft.getMinecraft().player) { nbt.setInteger("Yeets", nbt.getInteger("Yeets") + 1); save.readFromNBT(nbt); save.markDirty(); Minecraft.getMinecraft().player.sendChatMessage("Yeet Count: " + nbt.getInteger("Yeets")); } } @SubscribeEvent public void EntityJoinWorldEvent(EntityJoinWorldEvent event) { if(event.getEntity() == Minecraft.getMinecraft().player) { save = ACSave.get(Minecraft.getMinecraft().world); nbt = save.writeToNBT(nbt); } } } I know there have been a lot of NTB related questions, and I am sorry if this is another stupid question. Again, to reiterate the data is not being saved, even though I have marked it as dirty. The data file is not being created at any point, and every time I start a world the save is null so it creates a new one.
×
×
  • Create New...

Important Information

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