Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

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.

  • Author

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

World

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.

 

http://pastebin.com/k2dhd2WG

  • Author

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

WorldSavedData

that is attached to each dimension's

World

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.

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

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.