Jump to content

Way to know World is still the same?


Recommended Posts

So I never thought of that, till I got today into loading a new world and notice that an event handler on my mod keeps running when player loads a new world.


So I have an event handler that makes different things happen in the world, like placing blocks, or spawning lightning.


Problem I noticed today, when I loaded a new world, while the event was still running, the event kept running in the new world until in completed.


What would be the best way to make sure the event should only run on the world that triggered it? I guess I could pass some world ID or something, but want to hear from the forum ideas first.


Thanks a lot.

Link to comment
Share on other sites

With the information you have given all I can say is: Don't hold onto the


instance for extended periods of time.

I think you should show one of those "event handlers".

Well, there is a lot going on in this file, but basically, for example, there is a timer running that every X tics spawns a lightning on the world. If I close that world and create a new one, the remaning lightnings on the list spawns in this new world.



Link to comment
Share on other sites

First of all, holy mother of data structures... List<List<Triple>> ... seriously? And that's with using Triple as a raw type (please don't!)... Correctly it would be List<List<Triple<BlockPos, IBlockState, Integer>>> . I highly suggest you make custom classes for these things instead of using the generic container classes, it makes your code much more readable.


To do this correctly you need to use a


that is attached to each dimension's


object so that the scheduled events are actually tied to the loaded world and don't live in a static field somewhere. Using static always needs to be well thought about, either it's constants (static final field of an immutable (!) object) or you really need to know what you are doing.


I knew about Triples when working on this. I was suggested to use it as a great way to make list containing all the values. Actually I did created my own at first, but I was told there was actually no need when I could use the Triple that's already there. Actually I'm practicing creating my own "Quadruple" and "Sextuple" just for fun, so yes I believe I'm gonna use my own classes.


Thanks for the tips and the guidance, gonna redo all the code from scratch so I can also attach more information when I pass it to the event handler and restrict the execution to the right world.


PS: Not sure what statics you saying I should be careful with, but gonna take a look at the code to see what you mean. I was surprised enough that the information persisted even after reloading the world, I tought it was going to get lost for some reason.

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.

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.


  • Create New...

Important Information

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