Jump to content
  • Home
  • Files
  • Docs
Topics
  • All Content

  • This Topic
  • This Forum

  • Advanced Search
  • Existing user? Sign In  

    Sign In



    • Not recommended on shared computers


    • Forgot your password?

  • Sign Up
  • All Activity
  • Home
  • Mod Developer Central
  • Modder Support
  • (1.16.2) How do I use onPlayerTick?
Currently Supported: 1.16.X (Latest) and 1.15.X (LTS)
Sign in to follow this  
Followers 0
e2rifia

(1.16.2) How do I use onPlayerTick?

By e2rifia, January 16 in Modder Support

  • Reply to this topic
  • Start new topic

Recommended Posts

e2rifia    0

e2rifia

e2rifia    0

  • Tree Puncher
  • e2rifia
  • Members
  • 0
  • 23 posts
Posted January 16 (edited)

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 January 16 by e2rifia
  • Quote

Share this post


Link to post
Share on other sites

diesieben07    7695

diesieben07

diesieben07    7695

  • Reality Controller
  • diesieben07
  • Forum Team
  • 7695
  • 56361 posts
Posted January 16
13 minutes ago, e2rifia said:

ServerPlayerEntity player = (ServerPlayerEntity) event.player;

This will immediately crash the game, there are not just server side entities. The fact that it doesn't mean your event handler is not even running. It is not running, because @EventBusSubscriber only works with static event handler methods.

  • Thanks 1
  • Quote

Share this post


Link to post
Share on other sites

e2rifia    0

e2rifia

e2rifia    0

  • Tree Puncher
  • e2rifia
  • Members
  • 0
  • 23 posts
Posted January 16 (edited)

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 January 16 by e2rifia
  • Quote

Share this post


Link to post
Share on other sites

diesieben07    7695

diesieben07

diesieben07    7695

  • Reality Controller
  • diesieben07
  • Forum Team
  • 7695
  • 56361 posts
Posted January 16
15 minutes ago, e2rifia said:

One step ahead?

?

 

15 minutes ago, e2rifia said:

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

}

Now you are spawning the entity on both client and server. You need to check World#isRemote and only spawn it on the server.

 

15 minutes ago, e2rifia said:

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

@EventBusSubscriber is fine, you just need to user static methods with it.

  • Like 1
  • Quote

Share this post


Link to post
Share on other sites

e2rifia    0

e2rifia

e2rifia    0

  • Tree Puncher
  • e2rifia
  • Members
  • 0
  • 23 posts
Posted January 16

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

  • Quote

Share this post


Link to post
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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  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.

    • Insert image from URL
×
  • Desktop
  • Tablet
  • Phone
Sign in to follow this  
Followers 0
Go To Topic Listing



  • Recently Browsing

    No registered users viewing this page.

  • Posts

    • ESCCarp
      Forge says this file does not have an app associated with it.

      By ESCCarp · Posted 32 minutes ago

      i do  
    • LexManos
      forge a jar file not exe

      By LexManos · Posted 1 hour ago

      Some zip managers like to take control of the .jar file extension away from Java. Make sure you have Java installed and try running Jarfix once, then try the installer again.   Also, 1.12 is out of support, update.
    • Modder31
      forge a jar file not exe

      By Modder31 · Posted 1 hour ago

      i am unable to install jar files only exe files i would ask if you could change all the files to exe files, like the older versions i want the most recent version of 1.12.2 for a certain mod but cant cause its a jar file
    • diesieben07
      Forge says this file does not have an app associated with it.

      By diesieben07 · Posted 1 hour ago

      Make sure you have Java installed.
    • ESCCarp
      Forge says this file does not have an app associated with it.

      By ESCCarp · Posted 1 hour ago

      When i try to install forge it says "This file does not have a app associated with it for preforming this action". Please help me fix it i really want to play with my friends on modded servers.
  • Topics

    • ESCCarp
      2
      Forge says this file does not have an app associated with it.

      By ESCCarp
      Started 1 hour ago

    • Modder31
      1
      forge a jar file not exe

      By Modder31
      Started 1 hour ago

    • JaydenB14
      1
      Minecraft Unexpected error on 1.7.10 forge modded

      By JaydenB14
      Started 3 hours ago

    • Molotove_
      1
      Problem adding RAM to a Forge Server

      By Molotove_
      Started 4 hours ago

    • Ariel David
      2
      Do i need minecraft installed

      By Ariel David
      Started 5 hours ago

  • Who's Online (See full list)

    • rjakobs
    • MrBelieve
    • samjviana
    • Kyloren_du22
    • Talp1
  • All Activity
  • Home
  • Mod Developer Central
  • Modder Support
  • (1.16.2) How do I use onPlayerTick?
  • Theme

Copyright © 2019 ForgeDevelopment LLC · Ads by Longitude Ads LLC Powered by Invision Community