Posted April 10, 20169 yr Ok I got my mod working in singleplayer mode as i wanted it to. I was hopin it to run the same when joinin a server as it's a client side only simple mod... ..but no ;( Sry guys if it sounds like an obvious thing i'm really new to forge ^^ here's my code Main.java (imports) @Mod(modid = Main.MODID, name = Main.MODNAME, version=Main.VERSION, clientSideOnly=true) public class Main { public static final String MODID = "mymod"; public static final String MODNAME = "MyMod"; public static final String VERSION = "1.8.9-0.1"; PlayerWatcherHandler playerHandler = new PlayerWatcherHandler(); @Instance(value = Main.MODID) public static Main instance; @EventHandler public void preInit(FMLPreInitializationEvent e) { MinecraftForge.EVENT_BUS.register(playerHandler); } @EventHandler public void init(FMLInitializationEvent e) { } @EventHandler public void postInit(FMLPostInitializationEvent e) { } } ////////////////////////////////////////////////////////////////////////////////////////////////// playerwatcherhandler.java (imports) public class PlayerWatcherHandler { public PlayerWatcherHandler() {} @SubscribeEvent public void speedy(PlayerEvent evt){ if (evt.entityPlayer.isSprinting()) System.out.println("Gonzales"); } } This code print out gonzales when i run in singleplayer game but doesn't in multipleplayer... Why ? how to solve that ?
April 10, 20169 yr First of all, you don't want to use PlayerEvent. For what you're doing you should probably either use LivingEvent.LivingUpdateEvent, or TickEvent.PlayerTickEvent (the latter must be registered to the FML bus, not the Event bus). Obviously since your mod is client side only, it's not going to print in the server log... but did you check the client log (fml-client-latest.log in the .minecraft/logs folder)?
April 10, 20169 yr Author I'm not speakin of logs but of the stdout I run it in Eclipse . (And i use --username and --password args for being able to join a server (even try with my own server to be sure it wasn't some kind of protection on the server i was connectin too.. but same result)) Btw i also tried with breakpoints in debug mode and playerEvent is triggered only once in mp (right after the world loading event; then it will not be triggered anymore unlike in singleplayer where it's systematicaly triggered...) I will try with the events you suggested and let u know
April 10, 20169 yr Author Ty so much !!! with TickEvent.PlayerTickEvent it works !! didn't try the livingEvent as my target is the player the Player seemed more appropriate. But how do you guess which event to use or not to use ? like how can one guesses a method named "isEating" means "isRightClicking" ^^ ?
April 10, 20169 yr First of all, you don't want to use PlayerEvent. For what you're doing you should probably either use LivingEvent.LivingUpdateEvent, or TickEvent.PlayerTickEvent (the latter must be registered to the FML bus, not the Event bus). The OP is using 1.8.9, where the Forge and FML event buses have been merged. Anything that was fired on the FML bus is now fired on the Forge bus. Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.
April 10, 20169 yr But how do you guess which event to use or not to use ? like how can one guesses a method named "isEating" means "isRightClicking" ^^ ? Here's a useful list of forge events and their descriptions: https://dl.dropboxusercontent.com/s/h777x7ugherqs0w/forgeevents.html
April 10, 20169 yr Author ty guys ^^ that last event is makin me struggling @SubscribeEvent public void fightin(LivingAttackEvent evt){ if (((evt.entityLiving instanceof EntityPlayer) && (evt.source.getEntity() instanceof IMob)) || ((evt.entityLiving instanceof IMob) && (evt.source.getEntity() instanceof EntityPlayer))){ system.out.println(FIGHT); } } I need to detect when the player is in fight but in multiplayer mode. So Other players would be considered as hostile living entity
April 10, 20169 yr If DamageSource#getEntity is not null, then you are pretty much guaranteed to be in a fight. Either a mob or player hit you directly, or some sort of projectile struck you. However, you should be aware that many events such as LivingHurtEvent and LivingAttackEvent are typically posted only on the server* - you are only aware of them during single-player because the server is integrated with the client. * Unless you (the client player) triggered the event, e.g. when you attack something LivingAttackEvent will be posted for you on your client as well as on the server, but not necessarily when something attacks you. You can find out by printing to the console during the events and then triggering them in single- and multi-player. http://i.imgur.com/NdrFdld.png[/img]
April 10, 20169 yr Author Yes ty, that explains a lot ^^ as i wasn't even able to detect attack even from IMob when on server... So there is no simple way to know what did the dmg to my player when connected on server ? (as when it gets attacked it's only fired on server side ?)
April 10, 20169 yr Yes ty, that explains a lot ^^ as i wasn't even able to detect attack even from IMob when on server... So there is no simple way to know what did the dmg to my player when connected on server ? (as when it gets attacked it's only fired on server side ?) Not if you insist on making a client-side only mod. http://i.imgur.com/NdrFdld.png[/img]
April 10, 20169 yr Author OK ty for all that info dude It makes sense on one hand as it's not cause u get hurt that u know the dmg source (I mean IRL)... So the paradigm is logical And yes I insist ^^ as I really want my mod to be able to operate on any server I think i will just go for if u lose health your in fight when in MP mode... won't be wrong so often as u mostly get hurt when in fight (it's more rare to get hurt cause starvin, suffocatin or burnin... than cause in fight when in MP mode) might be enough occurate for my use
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.