Jump to content

Editing the WorldInfo


Footbal

Recommended Posts

I'm developing a mod which adds a property called respawnEnabled to the WorldInfo instance similar to isHardCoreModeEnabled and many of the other variables in net.minecraft.world.storage.WorldInfo. The mod uses this property to modify the behavior of the respawn code found in net.minecraft.network.netServerHandler and the gui code found in net.minecraft.client.gui.GuiGameOver so that if this property is true (it's a boolean), the game will proceed with the non-hardcore respawning behavior even if the game is in hardcore mode.

 

My problem is that GuiGameOver doesn't seem to see that respawnEnabled is true, so it presents the player with the hardcore death screen. BUT, the respawn code DOES see the property as true, so clicking the "Delete World" button will actually respawn the player (since the delete world and respawn button send the same command and it's dealt with down the line).

 

The only reason I can see for this is that there are TWO instances of WorldInfo in the game. I can't find a reason for this, nor can I find where the second instance would come from. Can anyone shed light on this problem? If it's any help, the respawn code gets its WorldInfo instance from a WorldServer object and GuiGameOver gets its instance from a WorldClient object. If it really is an issue of client vs server instances, how do I access both of those instances from another class like Block?

Link to comment
Share on other sites

Hi

 

you're right, there are more than one.  One on the client side, and several on the server side.

See

http://greyminecraftcoder.blogspot.com.au/2013/10/server-side-class-linkage-map.html

(MinecraftServer.worldInstances)

and

http://greyminecraftcoder.blogspot.com.au/2013/10/client-side-class-linkage-map.html

 

If your method in Block is activated on both sides, it will probably be given a World object, which you can use to get to the right WorldInfo on both sides.

 

-TGG

 

Link to comment
Share on other sites

Thanks, that explains a lot. However, the problem I'm now having is with persistence. Using the World object passed to onBlockPlacedBy, I was able to successfully edit the WorldInfo instances (seemingly all of them) with worldObject.getWorldInfo(). Both the respawn and gui code worked using this command.

 

After exiting to the menu and reloading the world, however, it was only the respawn code that now recognized this instance of WorldInfo. Here's what I did to accomplish this level of persistence:

added respawn variable initialization to WorldInfo(WorldInfo info) constructor

added respawn variable to NBTTagCompound in updateTagCompound(...) using setBoolean("respawnEnabled", this.respawnEnabled)

added respawn variable initialization to WorldInfo(NBTTagCompound compound) constructor

 

This clearly works on some level because whatever WorldInfo object NetServerHandler is pulling is correct after saving, but the one GuiGameOver is pulling is not. Most confusingly of all, I tried setting my variable directly to the gui's WorldInfo with Minecraft.getMinecraft().theWorld.getWorldInfo() and it STILL didn't work, even when the WorldInfo object was directly descended from the Minecraft object in both the gui and block code.

 

There's only one constructor in WorldInfo that I didn't add my property too, and that's the one that takes in a WorldSettings object as an argument. Could this be the one that GuiGameOver is using? If so, how do you recommend I make sure the client knows about my property?

Link to comment
Share on other sites

Hi

 

Hmmm you're starting to get into areas that I don't know much about. 

 

The only clue I might give is that Forge has a couple of events related to World saving and loading that might let you access the world object at the right time, if you subscribe to them, perhaps you can store your "immune to hardcore" variable somewhere else other than the WorldInfo (say - in your own config file), and copy it to/from the WorldInfo in the appropriate events.  Might also make your mod more compatible with other mods.

 

eg see WorldEvent.Load

 

I don't really understand which of the WorldInfo constructors does what, sorry!

 

-TGG

 

 

Link to comment
Share on other sites

Thanks for your help. At this point, you're right, I'll probably have to look for other implementations, since it's acting so strange. I'll do some experimentation with the various instances of WorldInfo and see if I can figure out how to do it.

 

To anyone else interested, I'll probably post whatever solution I find.

 

Thanks!

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



×
×
  • Create New...

Important Information

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