Jump to content

(1.16.2) How do I use onPlayerTick?


e2rifia

Recommended Posts

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
Link to comment
Share on other sites

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
Link to comment
Share on other sites

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);
        }
    }

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.

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

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

Announcements



×
×
  • Create New...

Important Information

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