Posted October 19, 201410 yr 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?
October 19, 201410 yr 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. If you don't know basic Java yet, go and follow these tutorials.
October 19, 201410 yr 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?
October 19, 201410 yr 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!
October 19, 201410 yr 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.