The Meaning of Life, the Universe, and Everything.
Location:
Bavaria
Join Date:
4/29/2013
Posts:
166
Location:
Germany
Minecraft:
ThexXTURBOXx
Xbox:
Zocker4Live999
Member Details
Hello guys,
I am coding a boomerang. Its class extends "EntityThrowable". But, like snowballs, when they hit blocks like grass (I mean not the grass_block, I mean grass) they just "die"/"disappear". Is there any method to get the block hit by the entity? Here is my code:
public class EntityGoldenBoomerang extends EntityThrowable
{
public EntityGoldenBoomerang(World par1World)
{
super(par1World);
}
public EntityGoldenBoomerang(World par1World, EntityLivingBase par2EntityLivingBase)
{
super(par1World, par2EntityLivingBase);
}
public EntityGoldenBoomerang(World par1World, double par2, double par4, double par6)
{
super(par1World, par2, par4, par6);
}
@Override
protected void onImpact(MovingObjectPosition par1MovingObjectPosition)
{
if (par1MovingObjectPosition.entityHit != null)
{
byte damageBoomerang = 3;
par1MovingObjectPosition.entityHit.attackEntityFrom(DamageSource.causeThrownDamage(this, this.getThrower()), damageBoomerang);
}
if (!this.worldObj.isRemote)
{
Random r = new Random();
if(r.nextInt(1000) <= 250) {
//Yes, Blaze Hit is the right sound
this.playSound("mob.blaze.hit", 0.5F, 0.4F);
this.entityDropItem(new ItemStack(ReforgedItems.GOLDEN_BOOMERANG), 0.0F);
} else {
//Yes, lavapop is the right sound
this.playSound("liquid.lavapop", 0.5F, 0.4F);
}
this.setDead();
}
}
@Override
protected float getGravityVelocity()
{
return 0.01F;
}
}
EntityThrowable#onImpact is called when the entity hits a block or another entity. Your current code should drop the item regardless of what the boomerang hit.
If MovingObjectPosition#typeOfHit is BLOCK, MovingObjectPosition#blockPos contains the position of the block that was hit.
If MovingObjectPosition#typeOfHit is ENTITY, MovingObjectPosition#entityHit contains the entity that was hit.
Side note: Don't create a new Random each time you need a random number, create one and store it in a field. In this case, the protected field Entity#rand already contains a Random.
Chisel Facades: For all your decorative pipe-hiding needs.
Please don't PM me to ask for help or to join your mod development team. Asking your question in a public thread preserves it for people who are having the same problem in the future. I'm not interested in developing mods with people.
",courier,monospace">EntityThrowable#onImpact is called when the entity hits a block or another entity. Your current code should drop the item regardless of what the boomerang hit.
If ",courier,monospace">MovingObjectPosition#typeOfHit is ",courier,monospace">BLOCK, ",courier,monospace">MovingObjectPosition#blockPos contains the position of the block that was hit.
If ",courier,monospace">MovingObjectPosition#typeOfHit is ",courier,monospace">ENTITY, ",courier,monospace">MovingObjectPosition#entityHit contains the entity that was hit.
Side note: Don't create a new ",courier,monospace">Random each time you need a random number, create one and store it in a field. In this case, the protected field ",courier,monospace">Entity#rand already contains a ",courier,monospace">Random.
Hello guys,
I am coding a boomerang. Its class extends "EntityThrowable". But, like snowballs, when they hit blocks like grass (I mean not the grass_block, I mean grass) they just "die"/"disappear". Is there any method to get the block hit by the entity? Here is my code:
remove
in the final part of code
sorry for my bad english I'm Italian
EntityThrowable#onImpact is called when the entity hits a block or another entity. Your current code should drop the item regardless of what the boomerang hit.
If MovingObjectPosition#typeOfHit is BLOCK, MovingObjectPosition#blockPos contains the position of the block that was hit.
If MovingObjectPosition#typeOfHit is ENTITY, MovingObjectPosition#entityHit contains the entity that was hit.
Side note: Don't create a new Random each time you need a random number, create one and store it in a field. In this case, the protected field Entity#rand already contains a Random.
Chisel Facades: For all your decorative pipe-hiding needs.
Please don't PM me to ask for help or to join your mod development team. Asking your question in a public thread preserves it for people who are having the same problem in the future. I'm not interested in developing mods with people.
No, because then the entity would never disappear. I only want it not disappearing when it hits locks like grass and such things
Ok, I will try this
ah sorry I hadn't read well
sorry for my bad english I'm Italian
No problem, got it working with Choonster's tips... Thank you both!