i want a projectile that destroys blocks when it comes in contact but i dont know what code i would need to make that happen.
i am guessing it would be something like on block hit destroy block at this x,y,z or on block hit turn block at this x,y,z to air anyway you get the picture.
P.S. if it is possible to add a in instance of obsidian and bedrock so it cant destroy those blocks
One possible solution to this would be an Entity that extends EntityThrowable and overrides onImpact.
Using the MovingObjectPosition parameter of onImpact, you can check if it was a block hit using the typeOfHit field and then get the block position using blockX/Y/Z fields. You can use World#getBlock to get the Block at the specified position and World#setBlock or World#setBlockToAir to set the block at the specified position.
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.
par1MovingObjectPosition.entityHit.attackEntityFrom(DamageSource.causeThrownDamage(this, this.getThrower()), (float)b0);
}
if (par1MovingObjectPosition.typeOfHit != null) <--here is what i have for the type of hit in the MovingObjectPosition class it shows that 0=block 1=entity but when i put in 0 or 1 it shows an error saying "Incompatible operand types EnumMovingObjectType and int"
(also please tell me if i am putting it in the right place)
for (int i = 0; i < 8; ++i)
{
this.worldObj.spawnParticle("", this.posX, this.posY, this.posZ, 0.0D, 0.0D, 0.0D);
}
i am guessing it would be something like on block hit destroy block at this x,y,z or on block hit turn block at this x,y,z to air anyway you get the picture.
P.S. if it is possible to add a in instance of obsidian and bedrock so it cant destroy those blocks
Using the MovingObjectPosition parameter of onImpact, you can check if it was a block hit using the typeOfHit field and then get the block position using blockX/Y/Z fields. You can use World#getBlock to get the Block at the specified position and World#setBlock or World#setBlockToAir to set the block at the specified position.
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.
public class MyEntityProjectile9 extends EntityThrowable
{
public MyEntityProjectile9(World par1World)
{
super(par1World);
}
public MyEntityProjectile9(World par1World, EntityLivingBase par2EntityLivingBase)
{
super(par1World, par2EntityLivingBase);
}
public MyEntityProjectile9(World par1World, double par2, double par4, double par6)
{
super(par1World, par2, par4, par6);
}
@Override
protected float getGravityVelocity()
{
return 0.0F;
}
/**
* Called when this EntityThrowable hits a block or entity.
*/
protected void onImpact(MovingObjectPosition par1MovingObjectPosition)
{
if (par1MovingObjectPosition.entityHit != null)
{
byte b0 = 9;
/**if (par1MovingObjectPosition.entityHit instanceof EntityBlaze)
{
b0 = 15;
}*/
par1MovingObjectPosition.entityHit.attackEntityFrom(DamageSource.causeThrownDamage(this, this.getThrower()), (float)b0);
}
if (par1MovingObjectPosition.typeOfHit != null) <--here is what i have for the type of hit in the MovingObjectPosition class it shows that 0=block 1=entity but when i put in 0 or 1 it shows an error saying "Incompatible operand types EnumMovingObjectType and int"
(also please tell me if i am putting it in the right place)
for (int i = 0; i < 8; ++i)
{
this.worldObj.spawnParticle("", this.posX, this.posY, this.posZ, 0.0D, 0.0D, 0.0D);
}
if (!this.worldObj.isRemote)
{
this.explode();
}
}private void explode()
{
float f = 0.9F;
this.worldObj.createExplosion(this, this.posX, this.posY, this.posZ, f, true);
}
}
Then can you also show me example of what the whole thing should look like