Jump to content

[1.7.10] Sending damage to the player.


Robo51

Recommended Posts

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

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?

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.