Jump to content

Damage on passing through enemy


GravityWolf

Recommended Posts

Use this.

 

@Override

public void onUpdate(ItemStack stack, World world,

Entity entity, int par4, boolean par5) {

super.onUpdate(stack, world, entity, par4, par5);

if(((EntityPlayer)entity).getItemInUse() != stack) return;

entity.fallDistance = 0;

 

double x = entity.posX, y = entity.posY, z = entity.posZ;

 

if(!(entity instanceof EntityPlayer)||entity.motionX*entity.motionX + entity.motionY*entity.motionY + entity.motionZ*entity.motionZ < 0.01)/*you may want to play with this number*/

return;

 

AxisAlignedBB box =  AxisAlignedBB.getBoundingBox(x - 0.5D, y-1.0D, z-0.5D, x + 0.5D, y+1.0D, z+0.5D);

List<Entity> entList = world.getEntitiesWithinAABBExcludingEntity(null, box);

 

for(Entity ent: entList)

{

if(ent instanceof EntityLiving)

{

/*may need an if(!world.isRemote) here*/

((EntityLiving)ent).attackEntityFrom(DamageSource.causePlayerDamage((EntityPlayer)entity), 1);

}

}

}

 

 

Link to comment
Share on other sites

Use this.

 

@Override

public void onUpdate(ItemStack stack, World world,

Entity entity, int par4, boolean par5) {

super.onUpdate(stack, world, entity, par4, par5);

if(((EntityPlayer)entity).getItemInUse() != stack) return;

entity.fallDistance = 0;

 

double x = entity.posX, y = entity.posY, z = entity.posZ;

 

if(!(entity instanceof EntityPlayer)||entity.motionX*entity.motionX + entity.motionY*entity.motionY + entity.motionZ*entity.motionZ < 0.01)/*you may want to play with this number*/

return;

 

AxisAlignedBB box =  AxisAlignedBB.getBoundingBox(x - 0.5D, y-1.0D, z-0.5D, x + 0.5D, y+1.0D, z+0.5D);

List<Entity> entList = world.getEntitiesWithinAABBExcludingEntity(null, box);

 

for(Entity ent: entList)

{

if(ent instanceof EntityLiving)

{

/*may need an if(!world.isRemote) here*/

((EntityLiving)ent).attackEntityFrom(DamageSource.causePlayerDamage((EntityPlayer)entity), 1);

}

}

}

 

 

 

may I ask why you decided to copy paste my code from earlier into a context to make it seem like your own? even after the topic has been effectively finished, and the code you pasted changed.

Link to comment
Share on other sites

The fall damage was fixed, that's what we added the event for. we removed the fall damage statement from the on update method as it was not wanted, and is a messier way of doing it, as other mods may set fall damage after it, based on speed or whatever. using the event will guarantee that the fall damage is negated, without having problems with other mods.

Link to comment
Share on other sites

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

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

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