Jump to content

Recommended Posts

Posted

So I've done a lot of research and read through the Entity.java, EntityLivingBase.java, EntityArrow.java, and all various forge events but I can't seem to find a way to do this. I have a situation where I'm canceling the damage from an arrow in a certain case, which is easy. However, despite coming up with multiple methods to simply cancel the damage and knockback, the animation and sound remain. The disableDamage player capability doesn't work. The invulnerable boolean doesn't work, is protected, and appears to only set disableDamage anyway. I tried canceling the sound if the entity in question was the shooting entity, the instance of the arrow, or the player itself but it had no affect; upon too much inspection, the trail of methods led me all the way to a place where the specific sounds I want to cancel don't use forge events to work.

 

Does anyone know how to go about this? I must be missing something. Also, turning the player completely invulnerable, i.e. creative, isn't an option unless someone knows how to add extra commands post event. I found a post method in event_bus but I have no idea how to work it.

 

Any help would be very much appreciated!

Posted

Hi

 

I tried tracing through the chain of calls starting from EntityArrow and I wound up in

 

EntityPlayer:
    public boolean attackEntityFrom(DamageSource par1DamageSource, float par2)
    {
        if (ForgeHooks.onLivingAttack(this, par1DamageSource, par2)) return false;

 

It looks to me like you should be able to register a LivingAttackEvent handler, inspect the source to see if it's an arrow, and if so cancel it.

 

Have you used the Forge Event Bus before?  They're pretty simple once you've seen it once.

https://github.com/TheGreyGhost/TestFramework/blob/master/src/testframework/clientonly/EventHandlers/ItemEventHandler.java

Just replace DrawBlockHighlightEvent with LivingAttackEvent and change the method code to suit.

And register your handler in postInit

 

MinecraftForge.EVENT_BUS.register(new ItemEventHandler());

 

Easy as that...

 

-TGG

 

 

Posted

Yeah, I cancel the damage through LivingHurtEvent. I was focusing on canceling the damage and never thought of canceling the attack in the first place. I'll give it a shot; thanks.

Posted

I remember why I counted this one out. I only cancel the damage when the player is blocking and looking at the entity firing the projectile. Getting the target entity is simple. However, the reason I use LivingHurtEvent is because I can trace the entity that caused the damage. If it's an instance of EntityArrow, I can check the entity that shot it and compare that to the target entity. However, if I use LivingAttackEvent, I only have access to the player, where I can still find the target entity, and the damage source, which I'm not sure is linked to an instance of an entity. However, if there's a way to get the attacking entity from that, I would love to hear it!

Posted

Hi

 

Tracing through the DamageSource it looks like you can:

 

damagesource = DamageSource.causeArrowDamage(this, this.shootingEntity);

    public static DamageSource causeArrowDamage(EntityArrow par0EntityArrow, Entity par1Entity)
    {
        return (new EntityDamageSourceIndirect("arrow", par0EntityArrow, par1Entity)).setProjectile();
    }

public class EntityDamageSourceIndirect extends EntityDamageSource
{
    private Entity indirectEntity;

    public EntityDamageSourceIndirect(String par1Str, Entity par2Entity, Entity par3Entity)
    {
        super(par1Str, par2Entity);
        this.indirectEntity = par3Entity;

and

 

EntityDamageSourceIndirect:
    public Entity getEntity()
    {
        return this.indirectEntity;
    }

 

The event parameter provides you with the damage source

event.source

 

-TGG

Posted

The sound and animation still aren't canceled and I haven't been able to find out where they are called. Checking more code to see exactly what makes creative mode the way it is; everything I've found in the player settings hasn't helped it.

Posted

Problem Solved!

 

Turns out only the very first solution that I tried didn't work… all the others worked perfectly. What actually happened is that Eclipse somehow changed its build path and saved the copy of the code that didn't work…

 

I only noticed the problem when I removed some print streams and it didn't stop printing.

 

In summary, Eclipse error like a noob...

  • 5 years later...
Posted

so i did not understand a word of what you all were saying. I have a problem where when I get hit no sound occurs. can someone help please.

  • Guest locked this topic
Guest
This topic is now closed to further replies.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.