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

I want to run some code while the player is sleeping. I had tried using the PlayerSleepInBedEvent, but that seems to only be useful for before a player goes to sleep. Searching around I noticed the onUpdate() increments the sleep timer and at the beginning of the function there is this:

FMLCommonHandler.instance().onPlayerPreTick(this);

I have looked through the FMLCommonHandler and tried serching online to figure out how use this but can't seem to figure it out. Does anyone know how to use these?

 

Thanks

  • Author

OK I got it figured out. I never used the tickHandlers before, but thankfully got it working. First I needed to register the handler in my CommonProxy since I need my code serverside

public void registerServerTickHandler()
{
TickRegistry.registerTickHandler(new ServerTickHandler(), Side.SERVER);
}

 

Then I had to set up the handler. I make sure that the tick types I want are the Player ticks for the server, which have the player as the object. Using the player I could access the sleepTimer and do stuff when I wanted to based on the timer.

public class ServerTickHandler implements ITickHandler
{
@Override
public void tickStart(EnumSet<TickType> type, Object... tickData)
{
if (type.equals(EnumSet.of(TickType.PLAYER)))
     {
         onPlayerTick((EntityPlayer)tickData[0]);
     }
}
private void onPlayerTick(EntityPlayer player)
{
int sleepTicks = player.getSleepTimer();
if(sleepTicks == 99)
{
System.out.println("about to fall asleep");
//dostuff
}

}
@Override
public void tickEnd(EnumSet<TickType> type, Object... tickData) {
// TODO Auto-generated method stub
}
@Override
public EnumSet<TickType> ticks()
{
     return EnumSet.of(TickType.PLAYER, TickType.SERVER);
}
@Override
public String getLabel() {
// TODO Auto-generated method stub
return null;
}
}

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.