From 11eb112c842473b39bef3fec9133f2fdda91b0fb Mon Sep 17 00:00:00 2001 From: Bernhard Bonigl Date: Fri, 30 Jan 2015 18:09:57 +0100 Subject: [PATCH] Properly calculate distance in subtick-distances for accuracy --- .../tconstruct/library/entity/ProjectileBase.java | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/main/java/tconstruct/library/entity/ProjectileBase.java b/src/main/java/tconstruct/library/entity/ProjectileBase.java index e5bb67d9a90..bbb798dd7fb 100644 --- a/src/main/java/tconstruct/library/entity/ProjectileBase.java +++ b/src/main/java/tconstruct/library/entity/ProjectileBase.java @@ -183,8 +183,18 @@ public void onHitEntity(MovingObjectPosition movingobjectposition) { NBTTagCompound tags = returnStack.getTagCompound().getCompoundTag("InfiTool"); float speed = MathHelper.sqrt_double(this.motionX * this.motionX + this.motionY * this.motionY + this.motionZ * this.motionZ); - float distance = speed * this.ticksInAir; - + speed = Math.max(0, speed-2); + + // absolute distance travelled minus the current tick + float distance = speed * (this.ticksInAir-1); + // distance travelled in the current tick + float dist2 = 0; + dist2 += MathHelper.abs((float)movingobjectposition.entityHit.lastTickPosX - (float)this.lastTickPosX); + dist2 += MathHelper.abs((float)movingobjectposition.entityHit.lastTickPosY - (float)this.lastTickPosY); + dist2 += MathHelper.abs((float)movingobjectposition.entityHit.lastTickPosZ - (float)this.lastTickPosZ); + dist2 = MathHelper.sqrt_double(dist2); + + distance += dist2; if(!tags.hasKey("BaseAttack")) {