Skip to content
Permalink
Browse files

Fixed a bug with projectiles causing them to hang mid-air.

  • Loading branch information...
Ri5ux committed Feb 25, 2019
1 parent a005d0b commit c8802369aefce128b3cfd1c0e0aabaec16452b1a
Showing with 51 additions and 247 deletions.
  1. +46 −33 src/main/java/org/avp/entities/EntityProjectile.java
  2. +5 −214 src/main/java/org/avp/entities/EntitySpear.java
@@ -14,6 +14,7 @@
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.entity.projectile.EntityArrow;
import net.minecraft.init.Blocks;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.play.server.SPacketChangeGameState;
@@ -28,16 +29,16 @@

public abstract class EntityProjectile extends EntityArrow implements IThrowableEntity
{
protected int xTile;
protected int yTile;
protected int zTile;
protected Block inTile;
protected int xTile;
protected int yTile;
protected int zTile;
protected Block inTile;
protected boolean inGround;
protected int ticksInGround;
protected int ticksInAir;
public boolean beenInGround;
public float additionalDamage;
public int knockback;
protected int ticksInGround;
protected int ticksInAir;
public boolean beenInGround;
public float additionalDamage;
public int knockback;

public EntityProjectile(World world)
{
@@ -127,30 +128,32 @@ public void onEntityUpdate()
prevRotationPitch = rotationPitch = (float) ((Math.atan2(motionY, MathHelper.sqrt(motionX * motionX + motionZ * motionZ)) * 180D) / Math.PI);
}

BlockPos pos = new BlockPos(this.xTile, this.yTile, this.zTile);
BlockPos pos = new BlockPos(this.xTile, this.yTile, this.zTile);
IBlockState blockstate = this.world.getBlockState(pos);
Block block = blockstate.getBlock();

if (block != null)
{
AxisAlignedBB box = blockstate.getBoundingBox(this.world, pos);

if (box != null && box.contains(new Vec3d(this.posX, this.posY, this.posZ)))
{
this.inGround = true;
}
}

if (this.arrowShake > 0)
{
this.arrowShake--;
}

if (this.inGround)
{
Block blockIn = block;
Vec3d vecPos = new Vec3d(this.posX, this.posY, this.posZ);
Vec3d vecPosNext = new Vec3d(this.posX + this.motionX, this.posY + this.motionY, this.posZ + this.motionZ);
RayTraceResult hit = world.rayTraceBlocks(vecPos, vecPosNext, false, true, false);

if (blockIn == this.inTile)
if (block == Blocks.AIR && hit == null)
{
this.inGround = false;
this.motionX *= this.rand.nextFloat() * 0.2F;
this.motionY *= this.rand.nextFloat() * 0.2F;
this.motionZ *= this.rand.nextFloat() * 0.2F;
this.ticksInGround = 0;
this.ticksInAir = 0;
}

if (block == this.inTile)
{
ticksInGround++;

@@ -168,6 +171,7 @@ public void onEntityUpdate()
this.ticksInGround = 0;
this.ticksInAir = 0;
}

return;
}

@@ -183,17 +187,18 @@ public void onEntityUpdate()
}

Entity target = null;
@SuppressWarnings("unchecked")
List<Entity> possibleTargets = world.getEntitiesWithinAABBExcludingEntity(this, this.getEntityBoundingBox().expand(motionX, motionY, motionZ).expand(1.0D, 1.0D, 1.0D));
List<Entity> targets = world.getEntitiesWithinAABBExcludingEntity(this, this.getEntityBoundingBox().expand(motionX, motionY, motionZ).expand(1.0D, 1.0D, 1.0D));
double distanceTo = 0.0D;

for (int x = 0; x < possibleTargets.size(); x++)
for (int x = 0; x < targets.size(); x++)
{
Entity possibleTarget = possibleTargets.get(x);
Entity possibleTarget = targets.get(x);

if (!possibleTarget.canBeCollidedWith() || possibleTarget == shootingEntity && ticksInAir < 5)
{
continue;
}

float radius = 0.3F;
AxisAlignedBB targetBounds = possibleTarget.getEntityBoundingBox().expand(radius, radius, radius);
RayTraceResult intercept = targetBounds.calculateIntercept(vecPos, vecPosNext);
@@ -411,6 +416,11 @@ public boolean canBeCritical()
{
return false;
}

public boolean isInGround()
{
return inGround;
}

public void setAdditionalDamage(float additionalDamage)
{
@@ -431,19 +441,22 @@ public boolean canPickup(EntityPlayer entityplayer)
@Override
public void onCollideWithPlayer(EntityPlayer entityplayer)
{
if (this.inGround && this.arrowShake <= 0)
if (this.inGround)
{
if (this.canPickup(entityplayer))
{
if (!this.world.isRemote)
{
ItemStack item = new ItemStack(this.getItemstack().getItem(), 1, this.getItemstack().getItemDamage() + 1);

if (item != null && entityplayer.inventory.addItemStackToInventory(item))
if (this.getItemstack() != null)
{
GameSounds.fxPop.playSound(this, 0.2F, ((rand.nextFloat() - rand.nextFloat()) * 0.7F + 1.0F) * 2.0F);;
this.onItemPickup(entityplayer);
this.setDead();
ItemStack item = new ItemStack(this.getItemstack().getItem(), 1, this.getItemstack().getItemDamage() + 1);

if (item != null && entityplayer.inventory.addItemStackToInventory(item))
{
GameSounds.fxPop.playSound(this, 0.2F, ((rand.nextFloat() - rand.nextFloat()) * 0.7F + 1.0F) * 2.0F);
this.onItemPickup(entityplayer);
this.setDead();
}
}
}
}
Oops, something went wrong.

0 comments on commit c880236

Please sign in to comment.
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.