Jump to content

Recommended Posts

Posted

I am wanting to store data throughout the game which can be synchronised with every player, so everyone has the same data. I have been told that using a capability would be the best way to do this. I am just unsure of the procedure involved. Would I attach the capability to the EntityPlayer? If so, how am I meant to store that data on the server side, and how am I meant to synchronise it?

Posted

I've read both of those pages :) I am trying to create a quest book and if one player completes the quest it will be completed for every player. I'm just really confused about how the capability system that is attached to the player stores data server side? I just cant wrap my head around it!

Posted

I tried using WorldSaveData but I was told capabilities were a more suitable choice :(! When I used WorldSaveData I had a few issues as it wasn't saving the data after the game closed? And I needed a way to only initialise the NBT in the WorldSaveData once!

Posted
  On 6/11/2016 at 5:34 PM, MrPlantPots said:

I tried using WorldSaveData but I was told capabilities were a more suitable choice :(! When I used WorldSaveData I had a few issues as it wasn't saving the data after the game closed? And I needed a way to only initialise the NBT in the WorldSaveData once!

 

I assumed each player would have their own quest progress (or progress shared in a party) like HQM, so I told you to use a capability. If the progress is global, world saved data is the correct choice.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Posted

The party option sounds appealing however, this is only intended for small servers where everybody plays together. I think I'm going to stick with global progress!!!

 

Here was my attempt:

 

 

WorldSaveData class:

public class SPNWorldSavedData extends WorldSavedData {
  private static final String DATA_NAME = "QUESTBOOK";

  private NBTTagCompound data = new NBTTagCompound();
  
  // Required constructors
  public SPNWorldSavedData() {
    super(DATA_NAME);
  }
  public SPNWorldSavedData(String s) {
    super(s);
  }
@Override
public void readFromNBT(NBTTagCompound nbt) {
	// TODO Auto-generated method stub
	data = nbt;

}
@Override
public void writeToNBT(NBTTagCompound nbt) {
	// TODO Auto-generated method stub
	nbt = data;
}

public static SPNWorldSavedData get(World world) {
	  // The IS_GLOBAL constant is there for clarity, and should be simplified into the right branch.
	  MapStorage storage = world.getMapStorage();
	  SPNWorldSavedData instance = (SPNWorldSavedData) storage.loadData(SPNWorldSavedData.class, DATA_NAME);

	  if (instance == null) {
	    instance = new SPNWorldSavedData();
	    storage.setData(DATA_NAME, instance);
	  }
	  return instance;
	}

public NBTTagCompound getData() {
	return data;
}

}

 

Code in world gen to initialise the WorldSaveData:

		SPNWorldSavedData data = SPNWorldSavedData.get(world);
		data.readFromNBT(NBTHandler.getNBTTag());
		data.setDirty(true);

 

Code in event handler to read data:

            SPNWorldSavedData data = SPNWorldSavedData.get(event.getEntityLiving().getEntityWorld());
            NBTTagCompound nbt = new NBTTagCompound();
            nbt = data.getData();
            System.out.println(nbt.getString("obj0name"));
            Minecraft.getMinecraft().thePlayer.sendChatMessage("HIYA: "+nbt.getString("obj0description"));

 

Reference Class (NBTHandler, purely used for organising code):

public class NBTHandler {

static NBTTagCompound nbt;
static ItemStack book;

public static void init() {
	nbt = new NBTTagCompound();
	nbt.setString("obj0name", "NAME0");
	nbt.setString("obj0description", "DESCRIPTION0");
	nbt.setBoolean("obj0state", false);
	nbt.setInteger("obj0QID", 0);


	Block block = SupernaturalBlocks.angel_block;


	book = new ItemStack(SupernaturalItems.blood_bottle, 1, 15);
	System.out.println(book.getItem().getUnlocalizedName());
	book.setTagCompound(nbt);
}

public static NBTTagCompound getNBTTag() {
	return nbt;
}

public static ItemStack getBook() {
	return book;
}

}

Posted

By initialise the WorldSaveData I meant add the NBT tags I created in the other class which I am now going to move into the worldSaveData class. The event it is in is currently an EntityJump event, however it will eventually be with the right click of the book. And the Reference class was unnecessary I'm not sure why I made it.

I just need some help with writing the initial Quest Data to the WorldSaveData and then how I can read and write to it!

Posted

Is there anything wrong with this code:

public class SPNWorldSavedData extends WorldSavedData {
  private static final String DATA_NAME = "QUESTBOOK";

  private NBTTagCompound data = new NBTTagCompound();
  
  // Required constructors
  public SPNWorldSavedData() {
    super(DATA_NAME);
  }
  public SPNWorldSavedData(String s) {
    super(s);
  }
@Override
public void readFromNBT(NBTTagCompound nbt) {
	// TODO Auto-generated method stub

}
@Override
public void writeToNBT(NBTTagCompound nbt) {
	// TODO Auto-generated method stub

}

public static SPNWorldSavedData get(World world) {
	  // The IS_GLOBAL constant is there for clarity, and should be simplified into the right branch.
	  MapStorage storage = world.getMapStorage();
	  SPNWorldSavedData instance = (SPNWorldSavedData) storage.loadData(SPNWorldSavedData.class, DATA_NAME);

	  if (instance == null) {
	    instance = new SPNWorldSavedData();
	    storage.setData(DATA_NAME, instance);
	    instance.getData().setString("obj0description", "DESCRIPTION");
	    instance.markDirty();
	  }
	  return instance;
	}

public NBTTagCompound getData() {
	return data;
}

}

 

And how would I read and write to this data? Would this work:

SPNWorldSavedData data = SPNWorldSavedData.get(world);
data.getData().setString("obj0description", "value");
data.markDirty();

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

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

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Im trying to make a server for me and my friends. I have no mods on it, (yet) but i keep getting this on the terminal right before it closes out. it insist even open long enogth m=for me to log on .this is my most resent crash report thanks in advance.   ---- Minecraft Crash Report ---- // I blame Dinnerbone. Time: 2025-05-01 18:17:25 Description: Exception in server tick loop java.lang.IllegalStateException: Failed to initialize server     at TRANSFORMER/minecraft@1.21.5/net.minecraft.server.MinecraftServer.runServer(MinecraftServer.java:676) ~[server-1.21.5-20250325.162830-srg.jar%23141!/:?] {re:classloading,pl:accesstransformer:B}     at TRANSFORMER/minecraft@1.21.5/net.minecraft.server.MinecraftServer.lambda$spin$2(MinecraftServer.java:276) ~[server-1.21.5-20250325.162830-srg.jar%23141!/:?] {re:classloading,pl:accesstransformer:B}     at java.base/java.lang.Thread.run(Thread.java:1583) [?:?] {} A detailed walkthrough of the error, its code path and all known details is as follows: --------------------------------------------------------------------------------------- -- System Details -- Details:     Minecraft Version: 1.21.5     Minecraft Version ID: 1.21.5     Operating System: Linux (amd64) version 6.11.0-19-generic     Java Version: 21.0.6, Ubuntu     Java VM Version: OpenJDK 64-Bit Server VM (mixed mode, sharing), Ubuntu     Memory: 99161192 bytes (94 MiB) / 233832448 bytes (223 MiB) up to 1004535808 bytes (958 MiB)     CPUs: 2     Processor Vendor: GenuineIntel     Processor Name: Intel(R) Pentium(R) CPU B950 @ 2.10GHz     Identifier: Intel64 Family 6 Model 42 Stepping 7     Microarchitecture: Sandy Bridge (Client)     Frequency (GHz): 2.10     Number of physical packages: 1     Number of physical CPUs: 2     Number of logical CPUs: 2     Graphics card #0 name: 2nd Generation Core Processor Family Integrated Graphics Controller     Graphics card #0 vendor: Intel Corporation (0x8086)     Graphics card #0 VRAM (MiB): 256.00     Graphics card #0 deviceId: 0x0106     Graphics card #0 versionInfo: unknown     Virtual memory max (MiB): 5743.06     Virtual memory used (MiB): 3361.15     Swap memory total (MiB): 3828.00     Swap memory used (MiB): 811.72     Space in storage for jna.tmpdir (MiB): <path not set>     Space in storage for org.lwjgl.system.SharedLibraryExtractPath (MiB): <path not set>     Space in storage for io.netty.native.workdir (MiB): <path not set>     Space in storage for java.io.tmpdir (MiB): available: 421206.25, total: 467297.75     Space in storage for workdir (MiB): available: 421206.25, total: 467297.75     JVM Flags: 0 total;     Server Running: true     Active Data Packs: vanilla, mod_data, mod/neoforge     Available Data Packs: minecart_improvements, redstone_experiments, trade_rebalance, vanilla, mod/neoforge, mod_data     Enabled Feature Flags: minecraft:vanilla     World Generation: Stable     World Seed: -7131934175611965967     Suppressed Exceptions: ~~NONE~~     Is Modded: Definitely; Server brand changed to 'neoforge'     Type: Dedicated Server (map_server.txt)     ModLauncher: 11.0.4+main.d2e20e43     ModLauncher launch target: neoforgeserver     ModLauncher services:         sponge-mixin-0.15.2+mixin.0.8.7.jar mixin PLUGINSERVICE         loader-7.0.10.jar slf4jfixer PLUGINSERVICE         loader-7.0.10.jar runtime_enum_extender PLUGINSERVICE         at-modlauncher-11.0.2.jar accesstransformer PLUGINSERVICE         loader-7.0.10.jar runtimedistcleaner PLUGINSERVICE         modlauncher-11.0.4.jar mixin TRANSFORMATIONSERVICE         modlauncher-11.0.4.jar fml TRANSFORMATIONSERVICE     FML Language Providers:         javafml@7.0         minecraft@7.0     Mod List:         server-1.21.5-20250325.162830-srg.jar             |Minecraft                     |minecraft                     |1.21.5              |Manifest: NOSIGNATURE         neoforge-21.5.63-beta-universal.jar               |NeoForge                      |neoforge                      |21.5.63-beta        |Manifest: NOSIGNATURE     Crash Report UUID: 99fdd6a6-3898-4cfe-ab2c-80b1ace92081     FML: 7.0.10     NeoForge: 21.5.63-beta
    • My minecraft version is 1.20.1, I haven't had too many issues other than a mod not working sometimes, in which case I usually just delete and sift through the preexisting mods to try to find the issue, but I hit a big wall of not knowing what my issue is now. I just want to make a modpack for me and my partner!!! Here's the latest log url, https://pastebin.com/9LjctgYN 
    • i was having same problem, thanks 
    • I have no idea - look like it just stops
    • https://mclo.gs/Fy9ZzcR UPDATED LOGS still stays stuck at 0% when trying to load a world   https://mclo.gs/Fy9ZzcR UPDATED LOGS still stays stuck at 0% when trying to load a world  
  • Topics

×
×
  • Create New...

Important Information

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