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'm trying to make the player take damage when they come in contact with water, however I'm not entirely sure what I'm doing wrong.

 

I've registered an EventsHandler for my mod and I believe I need to use onPlayerTick  to do what I need to do. (Total shot in the dark)

 

This is the code I'm using:

 

 

 

public class EventsHandler {

 

@SubscribeEvent

public void onPlayerTick(TickEvent.PlayerTickEvent event) {

 

class PlayerTickEvent extends TickEvent {

        public final EntityPlayer player;

 

        public PlayerTickEvent(Phase phase, EntityPlayer player)

        {

            super(Type.PLAYER, player instanceof EntityPlayerMP ? Side.SERVER : Side.CLIENT, phase);

            this.player = player;

           

            if(this.isWet()) {

                this.attackEntityFrom(DamageSource.drown, 1.0F);

            }

        }

    }

}

}

 

 

 

However this does not work,which I figured it wouldn't.

I think I need it to ?reference? the entity class for the .iswet and .attackEntityFrom methods.

 

But I'm not sure how to do so.

 

Am I headed in the right direction or am I backasswards?

I'm not trying to be rude it just comes out that way sometimes.

I'm here to try and learn as much as I can, won't you join me?

Don't subclass the events.

@SubscribeEvent
public void onPlayerTick(TickEvent.PlayerTickEvent event)
{
    if(event.side.isServer() && event.phase.equals(TickEvent.Phase.START))
    {
        //DO STUFF
    }
}

BEFORE ASKING FOR HELP READ THE EAQ!

 

I'll help if I can. Apologies if I do something obviously stupid. :D

 

If you don't know basic Java yet, go and follow these tutorials.

  • Author

So after some fiddling I came up with this:

 

 

 

public class EventsHandler {

 

  @SubscribeEvent

  public void onPlayerTick(EntityPlayer player) {

  if(player.isWet()) {

  player.attackEntityFrom(DamageSource.drown, 1.0F);

  }

  }

}

 

 

 

However I realize that this is not an event and won't actually work.

I'm confused on the event to use and how to use it.

 

Would I use this event?

And if so I'm still a little confused on how to use it properly:

 

 

 

    public static class PlayerTickEvent extends TickEvent {

        public final EntityPlayer player;

 

        public PlayerTickEvent(Phase phase, EntityPlayer player)

        {

            super(Type.PLAYER, player instanceof EntityPlayerMP ? Side.SERVER : Side.CLIENT, phase);

            this.player = player;

        }

    }

 

 

I'm not trying to be rude it just comes out that way sometimes.

I'm here to try and learn as much as I can, won't you join me?

public class EventsHandler {
      
      @SubscribeEvent
      public void onPlayerTick(PlayerTickEvent evt) {
         if(evt.player.isWet()) {
            evt.player.attackEntityFrom(DamageSource.drown, 1.0F);
         }
      }
}

Check out my mod, Realms of Chaos, here.

 

If I helped you, be sure to press the "Thank You" button!

  • Author

public class EventsHandler {
      
      @SubscribeEvent
      public void onPlayerTick(PlayerTickEvent evt) {
         if(evt.player.isWet()) {
            evt.player.attackEntityFrom(DamageSource.drown, 1.0F);
         }
      }
}

 

Thank you. :)

Using what you gave me and some examples from a tutorial it works now.

 

Much appreciated. :)

I'm not trying to be rude it just comes out that way sometimes.

I'm here to try and learn as much as I can, won't you join me?

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.