Fixed collision with Projectiles.

This commit is contained in:
Jonathan Williams 2014-04-04 15:02:13 -04:00
parent 26fe974b00
commit edfe23fb01

View File

@ -3,11 +3,14 @@ package mineplex.core.projectile;
import mineplex.core.updater.event.UpdateEvent;
import mineplex.core.updater.UpdateType;
import mineplex.core.common.util.UtilBlock;
import mineplex.core.common.util.UtilEnt;
import mineplex.core.common.util.UtilParticle;
import mineplex.core.common.util.UtilParticle.ParticleType;
import mineplex.core.disguise.DisguiseManager;
import mineplex.core.disguise.disguises.DisguiseSquid;
import net.minecraft.server.v1_7_R1.AxisAlignedBB;
import net.minecraft.server.v1_7_R1.MathHelper;
import net.minecraft.server.v1_7_R1.MovingObjectPosition;
import net.minecraft.server.v1_7_R1.Vec3D;
import org.bukkit.Effect;
import org.bukkit.GameMode;
@ -15,6 +18,8 @@ import org.bukkit.Sound;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.craftbukkit.v1_7_R1.CraftWorld;
import org.bukkit.craftbukkit.v1_7_R1.entity.CraftEntity;
import org.bukkit.craftbukkit.v1_7_R1.entity.CraftLivingEntity;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.LivingEntity;
@ -42,7 +47,6 @@ public class ProjectileUser
private int _effectData = 0;
private UpdateType _effectRate = UpdateType.TICK;
private double _hitboxMult = 1;
private DisguiseManager _disguise;
public ProjectileUser(ProjectileManager throwInput, Entity thrown, LivingEntity thrower, IThrown callback,
@ -72,7 +76,6 @@ public class ProjectileUser
_effectData = effectData;
_effectRate = effectRate;
_hitboxMult = hitboxMult;
_disguise = disguise;
}
@ -100,11 +103,23 @@ public class ProjectileUser
return true;
}
double distanceToEntity = 0.0D;
LivingEntity victim = null;
//Check Hit Player
if (_hitPlayer)
net.minecraft.server.v1_7_R1.Entity nmsEntity = ((CraftEntity)_thrown).getHandle();
Vec3D vec3d = nmsEntity.world.getVec3DPool().create(nmsEntity.locX, nmsEntity.locY, nmsEntity.locZ);
Vec3D vec3d1 = nmsEntity.world.getVec3DPool().create(nmsEntity.locX + nmsEntity.motX, nmsEntity.locY + nmsEntity.motY, nmsEntity.locZ + nmsEntity.motZ);
MovingObjectPosition finalObjectPosition = nmsEntity.world.rayTrace(vec3d, vec3d1, false, true, false);
vec3d = nmsEntity.world.getVec3DPool().create(nmsEntity.locX, nmsEntity.locY, nmsEntity.locZ);
vec3d1 = nmsEntity.world.getVec3DPool().create(nmsEntity.locX + nmsEntity.motX, nmsEntity.locY + nmsEntity.motY, nmsEntity.locZ + nmsEntity.motZ);
if (finalObjectPosition != null)
{
for (Object entity : ((CraftWorld)_thrown.getWorld()).getHandle().entityList)
vec3d1 = nmsEntity.world.getVec3DPool().create(finalObjectPosition.pos.c, finalObjectPosition.pos.d, finalObjectPosition.pos.e);
}
for (Object entity : ((CraftWorld)_thrown.getWorld()).getHandle().getEntities(((CraftEntity)_thrown).getHandle(), ((CraftEntity)_thrown).getHandle().boundingBox.a(((CraftEntity)_thrown).getHandle().motX, ((CraftEntity)_thrown).getHandle().motY, ((CraftEntity)_thrown).getHandle().motZ).grow(1.0D, 1.0D, 1.0D)))
{
if (entity instanceof net.minecraft.server.v1_7_R1.Entity)
{
@ -129,31 +144,66 @@ public class ProjectileUser
disguise = EntityType.SQUID;
}
//Hit Player
if (UtilEnt.hitBox(_thrown.getLocation(), ent, _hitboxMult, disguise))
float f1 = (float)(nmsEntity.boundingBox.b() * .6);
AxisAlignedBB axisalignedbb1 = ((CraftEntity)ent).getHandle().boundingBox.grow(f1, f1, f1);
MovingObjectPosition entityCollisionPosition = axisalignedbb1.a(vec3d, vec3d1);
if (entityCollisionPosition != null)
{
_callback.Collide(ent, null, this);
double d1 = vec3d.distanceSquared(entityCollisionPosition.pos);
if ((d1 < distanceToEntity) || (distanceToEntity == 0.0D))
{
victim = ent;
distanceToEntity = d1;
}
}
}
}
}
if (victim != null)
{
finalObjectPosition = new MovingObjectPosition(((CraftLivingEntity)victim).getHandle());
_callback.Collide(victim, null, this);
}
if (finalObjectPosition != null)
{
if (finalObjectPosition.entity != null && _hitPlayer)
{
nmsEntity.motX = ((float) (finalObjectPosition.pos.c - nmsEntity.locX));
nmsEntity.motY = ((float) (finalObjectPosition.pos.d - nmsEntity.locY));
nmsEntity.motZ = ((float) (finalObjectPosition.pos.e - nmsEntity.locZ));
float f2 = MathHelper.sqrt(nmsEntity.motX * nmsEntity.motX + nmsEntity.motY * nmsEntity.motY + nmsEntity.motZ * nmsEntity.motZ);
nmsEntity.locX -= nmsEntity.motX / f2 * 0.0500000007450581D;
nmsEntity.locY -= nmsEntity.motY / f2 * 0.0500000007450581D;
nmsEntity.locZ -= nmsEntity.motZ / f2 * 0.0500000007450581D;
_callback.Collide(victim, null, this);
return true;
}
}
else if (_hitBlock)
{
Block block = _thrown.getWorld().getBlockAt(finalObjectPosition.b, finalObjectPosition.c, finalObjectPosition.d);
if (!UtilBlock.airFoliage(block) && !block.isLiquid())
{
nmsEntity.motX = ((float) (finalObjectPosition.pos.c - nmsEntity.locX));
nmsEntity.motY = ((float) (finalObjectPosition.pos.d - nmsEntity.locY));
nmsEntity.motZ = ((float) (finalObjectPosition.pos.e - nmsEntity.locZ));
float f2 = MathHelper.sqrt(nmsEntity.motX * nmsEntity.motX + nmsEntity.motY * nmsEntity.motY + nmsEntity.motZ * nmsEntity.motZ);
nmsEntity.locX -= nmsEntity.motX / f2 * 0.0500000007450581D;
nmsEntity.locY -= nmsEntity.motY / f2 * 0.0500000007450581D;
nmsEntity.locZ -= nmsEntity.motZ / f2 * 0.0500000007450581D;
_callback.Collide(null, block, this);
return true;
}
}
}
try
{
//Check Hit Block
if (_hitBlock)
{
Block block = _thrown.getLocation().add(_thrown.getVelocity().normalize().multiply(0.6)).getBlock();
if (!UtilBlock.airFoliage(block) && !block.isLiquid())
{
_callback.Collide(null, block, this);
return true;
}
}
//Idle
if (_idle)
{