cleanup entitybullet
This commit is contained in:
parent
d0984b143b
commit
431d54f779
1 changed files with 81 additions and 92 deletions
|
@ -21,64 +21,60 @@ import common.world.World;
|
|||
|
||||
public class EntityBullet extends Entity implements IProjectile, IObjectData
|
||||
{
|
||||
public Entity shootingEntity;
|
||||
private int ticksInAir;
|
||||
private Entity shooter;
|
||||
private int ticksMoved;
|
||||
private int age;
|
||||
private int damage = 5;
|
||||
|
||||
public EntityBullet(World worldIn)
|
||||
public EntityBullet(World world)
|
||||
{
|
||||
super(worldIn);
|
||||
super(world);
|
||||
this.renderDistWeight = 10.0D;
|
||||
this.setSize(0.5F, 0.5F);
|
||||
}
|
||||
|
||||
public EntityBullet(World worldIn, double x, double y, double z)
|
||||
public EntityBullet(World world, double x, double y, double z)
|
||||
{
|
||||
super(worldIn);
|
||||
super(world);
|
||||
this.renderDistWeight = 10.0D;
|
||||
this.setSize(0.5F, 0.5F);
|
||||
this.setPosition(x, y, z);
|
||||
}
|
||||
|
||||
public EntityBullet(World worldIn, double x, double y, double z, int data)
|
||||
public EntityBullet(World world, double x, double y, double z, int data)
|
||||
{
|
||||
this(worldIn, x, y, z);
|
||||
Entity entity2 = worldIn.getEntityByID(data);
|
||||
if(entity2 instanceof EntityLiving) {
|
||||
this.shootingEntity = entity2;
|
||||
}
|
||||
this(world, x, y, z);
|
||||
Entity entity = world.getEntityByID(data);
|
||||
if(entity instanceof EntityLiving)
|
||||
this.shooter = entity;
|
||||
}
|
||||
|
||||
public EntityBullet(World worldIn, EntityLiving shooter, EntityLiving target, float velocity, float innacuracy)
|
||||
public EntityBullet(World world, EntityLiving shooter, EntityLiving target, float velocity, float innacuracy)
|
||||
{
|
||||
super(worldIn);
|
||||
super(world);
|
||||
this.renderDistWeight = 10.0D;
|
||||
this.shootingEntity = shooter;
|
||||
|
||||
this.shooter = shooter;
|
||||
this.posY = shooter.posY + (double)shooter.getEyeHeight() - 0.10000000149011612D;
|
||||
double d0 = target.posX - shooter.posX;
|
||||
double d1 = target.getEntityBoundingBox().minY + (double)(target.height * 0.7f) - this.posY;
|
||||
double d2 = target.posZ - shooter.posZ;
|
||||
double d3 = (double)ExtMath.sqrtd(d0 * d0 + d2 * d2);
|
||||
|
||||
if (d3 >= 1.0E-7D)
|
||||
double xd = target.posX - shooter.posX;
|
||||
double yd = target.getEntityBoundingBox().minY + (double)(target.height * 0.7f) - this.posY;
|
||||
double zd = target.posZ - shooter.posZ;
|
||||
double xzd = (double)ExtMath.sqrtd(xd * xd + zd * zd);
|
||||
if (xzd >= 1.0E-7D)
|
||||
{
|
||||
float f = (float)(ExtMath.atan2(d2, d0) * 180.0D / Math.PI) - 90.0F;
|
||||
float f1 = (float)(-(ExtMath.atan2(d1, d3) * 180.0D / Math.PI));
|
||||
double d4 = d0 / d3;
|
||||
double d5 = d2 / d3;
|
||||
this.setLocationAndAngles(shooter.posX + d4, this.posY, shooter.posZ + d5, f, f1);
|
||||
this.setThrowableHeading(d0, d1, d2, velocity, innacuracy);
|
||||
float yaw = (float)(ExtMath.atan2(zd, xd) * 180.0D / Math.PI) - 90.0F;
|
||||
float pitch = (float)(-(ExtMath.atan2(yd, xzd) * 180.0D / Math.PI));
|
||||
double x = xd / xzd;
|
||||
double z = zd / xzd;
|
||||
this.setLocationAndAngles(shooter.posX + x, this.posY, shooter.posZ + z, yaw, pitch);
|
||||
this.setThrowableHeading(xd, yd, zd, velocity, innacuracy);
|
||||
}
|
||||
}
|
||||
|
||||
public EntityBullet(World worldIn, EntityLiving shooter, float velocity)
|
||||
public EntityBullet(World world, EntityLiving shooter, float velocity)
|
||||
{
|
||||
super(worldIn);
|
||||
super(world);
|
||||
this.renderDistWeight = 10.0D;
|
||||
this.shootingEntity = shooter;
|
||||
|
||||
this.shooter = shooter;
|
||||
this.setSize(0.5F, 0.5F);
|
||||
this.setLocationAndAngles(shooter.posX, shooter.posY + (double)shooter.getEyeHeight(), shooter.posZ, shooter.rotYaw, shooter.rotPitch);
|
||||
this.posX -= (double)(ExtMath.cos(this.rotYaw / 180.0F * (float)Math.PI) * 0.16F);
|
||||
|
@ -97,10 +93,10 @@ public class EntityBullet extends Entity implements IProjectile, IObjectData
|
|||
|
||||
public void setThrowableHeading(double x, double y, double z, float velocity, float inaccuracy)
|
||||
{
|
||||
float f = ExtMath.sqrtd(x * x + y * y + z * z);
|
||||
x = x / (double)f;
|
||||
y = y / (double)f;
|
||||
z = z / (double)f;
|
||||
float sq = ExtMath.sqrtd(x * x + y * y + z * z);
|
||||
x = x / (double)sq;
|
||||
y = y / (double)sq;
|
||||
z = z / (double)sq;
|
||||
x = x + this.rand.gaussian() * (double)(this.rand.chance() ? -1 : 1) * 0.007499999832361937D * (double)inaccuracy;
|
||||
y = y + this.rand.gaussian() * (double)(this.rand.chance() ? -1 : 1) * 0.007499999832361937D * (double)inaccuracy;
|
||||
z = z + this.rand.gaussian() * (double)(this.rand.chance() ? -1 : 1) * 0.007499999832361937D * (double)inaccuracy;
|
||||
|
@ -126,12 +122,11 @@ public class EntityBullet extends Entity implements IProjectile, IObjectData
|
|||
this.motionX = x;
|
||||
this.motionY = y;
|
||||
this.motionZ = z;
|
||||
|
||||
if (this.prevPitch == 0.0F && this.prevYaw == 0.0F)
|
||||
{
|
||||
float f = ExtMath.sqrtd(x * x + z * z);
|
||||
float xz = ExtMath.sqrtd(x * x + z * z);
|
||||
this.prevYaw = this.rotYaw = (float)(ExtMath.atan2(x, z) * 180.0D / Math.PI);
|
||||
this.prevPitch = this.rotPitch = (float)(ExtMath.atan2(y, (double)f) * 180.0D / Math.PI);
|
||||
this.prevPitch = this.rotPitch = (float)(ExtMath.atan2(y, (double)xz) * 180.0D / Math.PI);
|
||||
this.prevPitch = this.rotPitch;
|
||||
this.prevYaw = this.rotYaw;
|
||||
this.setLocationAndAngles(this.posX, this.posY, this.posZ, this.rotYaw, this.rotPitch);
|
||||
|
@ -144,49 +139,49 @@ public class EntityBullet extends Entity implements IProjectile, IObjectData
|
|||
|
||||
if (this.prevPitch == 0.0F && this.prevYaw == 0.0F)
|
||||
{
|
||||
float f = ExtMath.sqrtd(this.motionX * this.motionX + this.motionZ * this.motionZ);
|
||||
float xz = ExtMath.sqrtd(this.motionX * this.motionX + this.motionZ * this.motionZ);
|
||||
this.prevYaw = this.rotYaw = (float)(ExtMath.atan2(this.motionX, this.motionZ) * 180.0D / Math.PI);
|
||||
this.prevPitch = this.rotPitch = (float)(ExtMath.atan2(this.motionY, (double)f) * 180.0D / Math.PI);
|
||||
this.prevPitch = this.rotPitch = (float)(ExtMath.atan2(this.motionY, (double)xz) * 180.0D / Math.PI);
|
||||
}
|
||||
|
||||
if(!this.worldObj.client && ++this.age >= 200) {
|
||||
this.setDead();
|
||||
return;
|
||||
}
|
||||
++this.ticksInAir;
|
||||
Vec3 vec31 = new Vec3(this.posX, this.posY, this.posZ);
|
||||
Vec3 vec3 = new Vec3(this.posX + this.motionX, this.posY + this.motionY, this.posZ + this.motionZ);
|
||||
HitPosition movingobjectposition = this.worldObj.rayTraceBlocks(vec31, vec3, false, true, false);
|
||||
vec31 = new Vec3(this.posX, this.posY, this.posZ);
|
||||
vec3 = new Vec3(this.posX + this.motionX, this.posY + this.motionY, this.posZ + this.motionZ);
|
||||
++this.ticksMoved;
|
||||
Vec3 current = new Vec3(this.posX, this.posY, this.posZ);
|
||||
Vec3 next = new Vec3(this.posX + this.motionX, this.posY + this.motionY, this.posZ + this.motionZ);
|
||||
HitPosition hit = this.worldObj.rayTraceBlocks(current, next, false, true, false);
|
||||
current = new Vec3(this.posX, this.posY, this.posZ);
|
||||
next = new Vec3(this.posX + this.motionX, this.posY + this.motionY, this.posZ + this.motionZ);
|
||||
|
||||
if (movingobjectposition != null)
|
||||
if (hit != null)
|
||||
{
|
||||
vec3 = new Vec3(movingobjectposition.vec.xCoord, movingobjectposition.vec.yCoord, movingobjectposition.vec.zCoord);
|
||||
next = new Vec3(hit.vec.xCoord, hit.vec.yCoord, hit.vec.zCoord);
|
||||
}
|
||||
|
||||
Entity entity = null;
|
||||
List<Entity> list = this.worldObj.getEntitiesWithinAABBExcludingEntity(this, this.getEntityBoundingBox().addCoord(this.motionX, this.motionY, this.motionZ).expand(1.0D, 1.0D, 1.0D));
|
||||
double d0 = 0.0D;
|
||||
double min = 0.0D;
|
||||
|
||||
for (int i = 0; i < list.size(); ++i)
|
||||
{
|
||||
Entity entity1 = (Entity)list.get(i);
|
||||
Entity ent = list.get(i);
|
||||
|
||||
if (entity1.canBeCollidedWith() && (entity1 != this.shootingEntity || this.ticksInAir >= 5))
|
||||
if (ent.canBeCollidedWith() && (ent != this.shooter || this.ticksMoved >= 5))
|
||||
{
|
||||
float f1 = 0.3F;
|
||||
BoundingBox axisalignedbb1 = entity1.getEntityBoundingBox().expand((double)f1, (double)f1, (double)f1);
|
||||
HitPosition movingobjectposition1 = axisalignedbb1.calculateIntercept(vec31, vec3);
|
||||
float expand = 0.3F;
|
||||
BoundingBox bb = ent.getEntityBoundingBox().expand((double)expand, (double)expand, (double)expand);
|
||||
HitPosition entityHit = bb.calculateIntercept(current, next);
|
||||
|
||||
if (movingobjectposition1 != null)
|
||||
if (entityHit != null)
|
||||
{
|
||||
double d1 = vec31.squareDistanceTo(movingobjectposition1.vec);
|
||||
double dist = current.squareDistanceTo(entityHit.vec);
|
||||
|
||||
if (d1 < d0 || d0 == 0.0D)
|
||||
if (dist < min || min == 0.0D)
|
||||
{
|
||||
entity = entity1;
|
||||
d0 = d1;
|
||||
entity = ent;
|
||||
min = dist;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -194,48 +189,42 @@ public class EntityBullet extends Entity implements IProjectile, IObjectData
|
|||
|
||||
if (entity != null)
|
||||
{
|
||||
movingobjectposition = new HitPosition(entity);
|
||||
hit = new HitPosition(entity);
|
||||
}
|
||||
|
||||
if (movingobjectposition != null)
|
||||
if (hit != null)
|
||||
{
|
||||
if (movingobjectposition.entity != null)
|
||||
if (hit.entity != null)
|
||||
{
|
||||
float f2 = ExtMath.sqrtd(this.motionX * this.motionX + this.motionY * this.motionY + this.motionZ * this.motionZ);
|
||||
int l = ExtMath.ceild((double)f2 * (double)this.damage);
|
||||
float velo = ExtMath.sqrtd(this.motionX * this.motionX + this.motionY * this.motionY + this.motionZ * this.motionZ);
|
||||
int damage = ExtMath.ceild((double)velo * (double)this.damage);
|
||||
|
||||
DamageSource damagesource;
|
||||
DamageSource source;
|
||||
|
||||
if (this.shootingEntity == null)
|
||||
if (this.shooter == null)
|
||||
{
|
||||
damagesource = DamageSource.causeShotDamage(this, this);
|
||||
source = DamageSource.causeShotDamage(this, this);
|
||||
}
|
||||
else
|
||||
{
|
||||
damagesource = DamageSource.causeShotDamage(this, this.shootingEntity);
|
||||
source = DamageSource.causeShotDamage(this, this.shooter);
|
||||
}
|
||||
|
||||
if ((this.worldObj.client || Vars.damageBullet) && movingobjectposition.entity.attackEntityFrom(damagesource, l))
|
||||
if ((this.worldObj.client || Vars.damageBullet) && hit.entity.attackEntityFrom(source, damage))
|
||||
{
|
||||
if (movingobjectposition.entity instanceof EntityLiving)
|
||||
if (hit.entity instanceof EntityLiving living && this.shooter instanceof EntityLiving shooter)
|
||||
{
|
||||
EntityLiving entitylivingbase = (EntityLiving)movingobjectposition.entity;
|
||||
|
||||
if (this.shootingEntity instanceof EntityLiving)
|
||||
{
|
||||
EnchantmentHelper.applyThornEnchantments(entitylivingbase, this.shootingEntity);
|
||||
EnchantmentHelper.applyArthropodEnchantments((EntityLiving)this.shootingEntity, entitylivingbase);
|
||||
}
|
||||
EnchantmentHelper.applyThornEnchantments(living, shooter);
|
||||
EnchantmentHelper.applyArthropodEnchantments(shooter, living);
|
||||
}
|
||||
|
||||
this.playSound(SoundEvent.METALHIT, 0.2F);
|
||||
}
|
||||
this.setDead();
|
||||
}
|
||||
else if(!this.worldObj.client)
|
||||
{
|
||||
State state = movingobjectposition.block != null ? this.worldObj.getState(movingobjectposition.block) : null;
|
||||
if(state == null || state.getBlock().onShot(this.worldObj, movingobjectposition.block, state, this)) {
|
||||
State state = hit.block != null ? this.worldObj.getState(hit.block) : null;
|
||||
if(state == null || state.getBlock().onShot(this.worldObj, hit.block, state, this)) {
|
||||
this.playSound(SoundEvent.METALHIT, 0.5F);
|
||||
this.setDead();
|
||||
}
|
||||
|
@ -245,10 +234,10 @@ public class EntityBullet extends Entity implements IProjectile, IObjectData
|
|||
this.posX += this.motionX;
|
||||
this.posY += this.motionY;
|
||||
this.posZ += this.motionZ;
|
||||
float f3 = ExtMath.sqrtd(this.motionX * this.motionX + this.motionZ * this.motionZ);
|
||||
float xzMotion = ExtMath.sqrtd(this.motionX * this.motionX + this.motionZ * this.motionZ);
|
||||
this.rotYaw = (float)(ExtMath.atan2(this.motionX, this.motionZ) * 180.0D / Math.PI);
|
||||
|
||||
for (this.rotPitch = (float)(ExtMath.atan2(this.motionY, (double)f3) * 180.0D / Math.PI); this.rotPitch - this.prevPitch < -180.0F; this.prevPitch -= 360.0F)
|
||||
for (this.rotPitch = (float)(ExtMath.atan2(this.motionY, (double)xzMotion) * 180.0D / Math.PI); this.rotPitch - this.prevPitch < -180.0F; this.prevPitch -= 360.0F)
|
||||
{
|
||||
;
|
||||
}
|
||||
|
@ -273,16 +262,16 @@ public class EntityBullet extends Entity implements IProjectile, IObjectData
|
|||
this.setPosition(this.posX, this.posY, this.posZ);
|
||||
}
|
||||
|
||||
public void writeEntity(TagObject tagCompound)
|
||||
public void writeEntity(TagObject tag)
|
||||
{
|
||||
tagCompound.setInt("damage", this.damage);
|
||||
tagCompound.setInt("age", this.age);
|
||||
tag.setInt("damage", this.damage);
|
||||
tag.setInt("age", this.age);
|
||||
}
|
||||
|
||||
public void readEntity(TagObject tagCompund)
|
||||
public void readEntity(TagObject tag)
|
||||
{
|
||||
this.damage = tagCompund.getInt("damage");
|
||||
this.age = tagCompund.getInt("age");
|
||||
this.damage = tag.getInt("damage");
|
||||
this.age = tag.getInt("age");
|
||||
}
|
||||
|
||||
protected boolean canTriggerWalking()
|
||||
|
@ -290,9 +279,9 @@ public class EntityBullet extends Entity implements IProjectile, IObjectData
|
|||
return false;
|
||||
}
|
||||
|
||||
public void setDamage(int damageIn)
|
||||
public void setDamage(int damage)
|
||||
{
|
||||
this.damage = damageIn;
|
||||
this.damage = damage;
|
||||
}
|
||||
|
||||
public int getDamage()
|
||||
|
@ -323,7 +312,7 @@ public class EntityBullet extends Entity implements IProjectile, IObjectData
|
|||
}
|
||||
|
||||
public int getPacketData() {
|
||||
return this.shootingEntity != null ? this.shootingEntity.getId() : this.getId();
|
||||
return this.shooter != null ? this.shooter.getId() : this.getId();
|
||||
}
|
||||
|
||||
public boolean hasSpawnVelocity() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue