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 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 by Yario

  • Replies 61
  • Views 15.2k
  • Created
  • Last Reply

Top Posters In This Topic

Most Popular Posts

  • @DifferentiationIt's working wiht you in multiplayer with client-side mod only ?

  • @Differentiation, you're missing how mods are used. It is possible for people to make mods that only get applied to one side. For example, if I wanted to have my client render everything in pink for s

  • So the way it works is that when the server processes an attack it updates the client with an SPacketEntityStatus packet. Unfortunately, it is implemented in a very minimalistic way, presumably for pe

Posted Images

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.

  • 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.

  • Author

I need an event when the player is attacked not when the player attack :(

  • Author

I can't find LivingDamageEvent maybe you wanted to write LivingHurtEvent but it is server side only.

  • Author

I am using forge for mc 1.9.4 and I can't find LivingDamageEvent

Capture.PNG

Edited by Yario

  • Author

@diesieben07

@SubscribeEvent
public void onAttack(LivingAttackEvent event)
{
    System.out.println("test"); //Never Reached
}

Not working :/

  • Author

It works in solo but not in multiplayer that's why I through it was only server side

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 by Differentiation

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 by Differentiation

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 by Differentiation

  • 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

  • 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

 

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.

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 by Differentiation

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 by Differentiation

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.