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

Assume a player creates a new world.

 

After the world has done its initial generation, either right before the player joins the world or right after, I want to execute my arbitrary code.

 

Let's say print "Hello World" once to the console.

 

How would I go about doing this?

 

Client side only, don't care about server.

 

 

  • Author

My apologies, I thought that the client ran the world gen code for single player games.

 

The client actually runs a local instance of the server?

  • Author

Understood, thank you!

 

Let me readjust my question in that case :)

 

I would like to execute arbitrary code once the world gen has finished, ie "Hello world".

it's hard to answer without knowing what you need, but maybe you are yet to determine what you need...

 

try this: respond to "join world" event; if the entity that fired event is a player, do your stuff and leave a simple signature in player's extra data (nbt). check for that signature at the start of "join world" event handler and don't do anything if it's not the first time for player to join.

things to note: 1) the event mentioned above fires for every player on the server instance and on any number of client instances. you may want to check whether world is remote (meaning client).  2) your signature (if it's a nbt string) needs to be below "persisted_nbt_tag" so that you wouldn't need to handle player "clone" event and copy the signature (i haven't checked whether that's still a thing in 1.15, but i'm willing to bet it is).

 

give it a try. if it's too early for you, there are ways of delaying things for a few seconds...

Edited by MFMods

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.