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.

(1.16.2) How do I use onPlayerTick?

Featured Replies

Posted

I fiddled around, trying to somehow get onPlayerTick to do something.

This is when I tried to make my head a flamethrower, but it doesn't spawn fireballs.

What did I do wrong? Please point it out.

 

@Mod(the class below)
@Mod.EventBusSubscriber(modid = the class below)
a public class {

 

@SubscribeEvent
    public void onPlayerTick(TickEvent.PlayerTickEvent event) {
        ServerPlayerEntity player = (ServerPlayerEntity) event.player;

        Vector3d v3 = player.getLook(1);
        SmallFireballEntity fireball = new SmallFireballEntity(player.getEntityWorld(), player.getPosX(), player.getPosY() + player.getEyeHeight(), player.getPosZ(), v3.x, v3.y, v3.z);
        fireball.setShooter(player);
        player.getEntityWorld().addEntity(fireball);
    }

Edited by e2rifia

  • Author

One step ahead?

 

@SubscribeEvent
    public void clientTickEnd(TickEvent.PlayerTickEvent event){
        if (event.phase != Phase.START || event.player == null) return;
        PlayerEntity player = event.player;
        Vector3d v3 = player.getLook(1);
        SmallFireballEntity fireball = new SmallFireballEntity(player.getEntityWorld(), player.getPosX(), player.getPosY() + player.getEyeHeight(), player.getPosZ(), v3.x, v3.y, v3.z);
        fireball.setShooter(player);
        player.getEntityWorld().addEntity(fireball);

}

 

Should I move it out of @EventBusSubscriber to somewhere else?

Edited by e2rifia

  • Author

It works! It works!

 

public static void onPlayerTick(TickEvent.PlayerTickEvent event){
        if (event.phase != Phase.START || event.player == null) return;
        if (!event.player.world.isRemote) {
        PlayerEntity player = event.player;
        Vector3d v3 = player.getLook(1);
        SmallFireballEntity fireball = new SmallFireballEntity(player.getEntityWorld(), player.getPosX(), player.getPosY() + player.getEyeHeight(), player.getPosZ(), v3.x, v3.y, v3.z);
        fireball.setShooter(player);
        player.getEntityWorld().addEntity(fireball);
        }
    }

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.