Posted December 28, 20177 yr I use Player API with and I have a problem: public boolean attackEntityFrom(DamageSource damageSource, float v) { if(damageSource.getEntity() != null) { //Never Reached } return super.attackEntityFrom(damageSource, v); } I saw that I need to use EntityDamageSource but It is not working. What can I do? (It is clientside) Edited December 28, 20177 yr by Yario
December 28, 20177 yr What are you trying to do? Neither hurting an entity, nor protecting from damage can be done client-side, as that is done server-side. It would not make sense if the client could overrule and go "nu-uh, that missed", or "I'm gonna attack you with 1 MILLION DAMAGE" Also previously known as eAndPi. "Pi, is there a station coming up where we can board your train of thought?" -Kronnn Published Mods: Underworld Handy links: Vic_'s Forge events Own WIP Tutorials.
December 28, 20177 yr Author I override the method attackEntityFrom of ClientPlayerBase (Player API) which is called everytime player is hit and I want to get the Entity who hit the player.
December 28, 20177 yr Author I can't find LivingDamageEvent maybe you wanted to write LivingHurtEvent but it is server side only.
December 28, 20177 yr Author I am using forge for mc 1.9.4 and I can't find LivingDamageEvent Edited December 28, 20177 yr by Yario
December 29, 20177 yr Author @diesieben07 @SubscribeEvent public void onAttack(LivingAttackEvent event) { System.out.println("test"); //Never Reached } Not working
December 29, 20177 yr Author It works in solo but not in multiplayer that's why I through it was only server side
December 29, 20177 yr 59 minutes ago, Yario said: Yes I do: MinecraftForge.EVENT_BUS.register(this); Below, I provided a direct example of how to get the attacker, target, etc. and how to use LivingAttackEvent. @SubscribeEvent public void onAttack(LivingAttackEvent event) { if (event.getEntity() instanceof EntityPlayer) { Entity attackerIn = event.getSource().getSourceOfDamage(); // this is your attacker instance, the entity attacking the target EntityPlayer targetIn = (EntityPlayer) event.getEntity(); // this is your target instance, the entity being attacked by the attacker /* * Here, you do whatever you want with your attacker and target. * You can make the target set on flame, add potion effects, etc. * Make sure you properly handle sides */ targetIn.worldObj.playSound((EntityPlayer) null, targetIn.getPosition(), SoundEvents.BLOCK_METAL_BREAK, SoundCategory.BLOCKS, 2.0F, 1.25F); // I play a sound in my attack event Random rand = worldIn.rand; // random instance for (int i = 0; i < 75; ++i) { /* my helper stuff, don't worry about it */ DinocraftServer.spawnParticle(EnumParticleTypes.BLOCK_CRACK, worldIn, targetIn.posX + (rand.nextDouble() - 0.5D) * (double)targetIn.width, targetIn.posY + rand.nextDouble() - (double)targetIn.getYOffset() + 0.25D, targetIn.posZ + (rand.nextDouble() - 0.5D) * (double)targetIn.width, Math.random() * 0.2D - 0.1D, Math.random() * 0.25D, Math.random() * 0.2D - 0.1D, Block.getIdFromBlock(Blocks.REDSTONE_BLOCK) ); // I spawn blood particles in my attack event } } } I don't even think LivingAttackEvent works on 1.9, last I heard, correct me if I'm wrong. I would recommend updating to at least 1.10.2, which is the version I used above. Edited December 29, 20177 yr by Differentiation
December 29, 20177 yr 6 minutes ago, Yario said: @Differentiation It makes no changes Well, did you actually register the constructor where you register the event? Edited December 29, 20177 yr by Differentiation
December 29, 20177 yr 6 minutes ago, Yario said: Yes but I will try in another version like you said above Let me guide you. 1. Create a new class called EventHandler. 2. Create a method called registerEvents() in the class and register your event inside. Like so: public class EventHandler { public void registerEvents() { /* All your events will be registered here */ ... MinecraftForge.EVENT_BUS.register(new YourClassNameWhereTheEventIsFound()); ... } } 3. Call this method in your mod's initialization phase. MAIN CLASS: ...... EventHandler eventHandler = new EventHandler(); @EventHandler public void registerEvents(FMLInitializationEvent event) { ... eventHandler.init(); ... } ...... You may use these steps to guide you. I hope I helped. Edited December 29, 20177 yr by Differentiation
December 29, 20177 yr Just now, Yario said: I'm not stupid I know how to use forge events... Well then explain why it doesn't work.
December 29, 20177 yr My only conclusion is that LivingAttackEvent might not work on 1.9.4. Please update to 1.10.2 and above, since I use 1.10.2 and it works mighty fine for me. Edited December 29, 20177 yr by Differentiation
December 29, 20177 yr Author If I'm here this is because I don't know why it is not working. My issue: I am making a client side mod but LivingAttackEvent is never called in multiplayer
December 29, 20177 yr Author Just now, Differentiation said: My only conclusion is that LivingAttackEvent might not work on 1.9.4. Please update to 1.10.2. I said before : 11 minutes ago, Yario said: Yes but I will try in another version like you said above
December 29, 20177 yr 3 minutes ago, Yario said: I said before : But I do hope you're aware that LivingAttackEvent is fired whenever the EntityLivingBase is attacked by another EntityLivingBase. If you are trying to test this event out by taking fall damage, don't expect anything to work.
December 29, 20177 yr 8 minutes ago, Yario said: Not working, LivingAttackEvent isn't called in 1.10.2 too Well then, you never called EventHandler::registerEvents(); in your Main class like I told you. Do any of your events even work? Try different ones and see if they work. Edited December 29, 20177 yr by Differentiation
December 29, 20177 yr 28 minutes ago, Yario said: Not working, LivingAttackEvent isn't called in 1.10.2 too It's firing perfectly for me, whenever the player is attacked by another entity. Edited December 29, 20177 yr by Differentiation
December 29, 20177 yr Author @DifferentiationIt's working wiht you in multiplayer with client-side mod only ?
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.