tcr/java/src/game/entity/projectile/EntityDynamite.java
2025-03-12 18:13:11 +01:00

80 lines
2.4 KiB
Java
Executable file

package game.entity.projectile;
import game.entity.DamageSource;
import game.entity.types.EntityLiving;
import game.entity.types.EntityThrowable;
import game.entity.types.IObjectData;
import game.init.Config;
import game.init.ItemRegistry;
import game.init.Items;
import game.nbt.NBTTagCompound;
import game.renderer.particle.ParticleType;
import game.world.HitPosition;
import game.world.World;
public class EntityDynamite extends EntityThrowable implements IObjectData
{
public int explosionSize;
public EntityDynamite(World worldIn)
{
super(worldIn);
}
public EntityDynamite(World worldIn, EntityLiving throwerIn, int power)
{
super(worldIn, throwerIn);
this.explosionSize = power & 7;
}
public EntityDynamite(World worldIn, double x, double y, double z, int power)
{
super(worldIn, x, y, z);
this.explosionSize = power & 7;
}
protected void onImpact(HitPosition pos)
{
if (pos.entity != null && Config.knockDynamite)
{
pos.entity.attackEntityFrom(DamageSource.causeThrownDamage(this, this.getThrower()), 0);
}
if (!this.worldObj.client)
{
float f = 4.0F * (((float)this.explosionSize)+1.0f);
EntityLiving thrower = this.getThrower();
this.worldObj.createAltExplosion(thrower == null ? this : thrower, this.posX, this.posY + (double)(this.height / 2.0F), this.posZ, f, true);
}
for (int k = 0; k < 8; ++k)
{
this.worldObj.spawnParticle(ParticleType.ITEM_CRACK, this.posX, this.posY, this.posZ, ((double)this.rand.floatv() - 0.5D) * 0.08D, ((double)this.rand.floatv() - 0.5D) * 0.08D, ((double)this.rand.floatv() - 0.5D) * 0.08D, ItemRegistry.getIdFromItem(Items.dynamite), this.explosionSize);
}
if (!this.worldObj.client)
{
this.setDead();
}
}
public void writeEntityToNBT(NBTTagCompound tagCompound)
{
super.writeEntityToNBT(tagCompound);
tagCompound.setByte("Power", (byte)this.explosionSize);
}
public void readEntityFromNBT(NBTTagCompound tagCompund)
{
super.readEntityFromNBT(tagCompund);
this.explosionSize = ((int)tagCompund.getByte("Power")) & 7;
}
public int getPacketData() {
return this.explosionSize;
}
// public boolean hasSpawnVelocity() {
// return false;
// }
}