Fixed collision with Projectiles.

This commit is contained in:
Jonathan Williams 2014-04-04 15:02:13 -04:00
parent 26fe974b00
commit edfe23fb01
1 changed files with 107 additions and 57 deletions

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;
}
@ -99,72 +102,119 @@ public class ProjectileUser
_callback.Expire(this);
return true;
}
//Check Hit Player
if (_hitPlayer)
{
for (Object entity : ((CraftWorld)_thrown.getWorld()).getHandle().entityList)
{
if (entity instanceof net.minecraft.server.v1_7_R1.Entity)
{
Entity bukkitEntity = ((net.minecraft.server.v1_7_R1.Entity) entity).getBukkitEntity();
if (bukkitEntity instanceof LivingEntity)
{
LivingEntity ent = (LivingEntity)bukkitEntity;
//Avoid Self
if (ent.equals(_thrower))
continue;
if (ent instanceof Player)
if (((Player)ent).getGameMode() == GameMode.CREATIVE)
continue;
EntityType disguise = null;
if (_disguise != null && _disguise.getDisguise(ent) != null)
double distanceToEntity = 0.0D;
LivingEntity victim = null;
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)
{
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)
{
Entity bukkitEntity = ((net.minecraft.server.v1_7_R1.Entity) entity).getBukkitEntity();
if (bukkitEntity instanceof LivingEntity)
{
LivingEntity ent = (LivingEntity)bukkitEntity;
//Avoid Self
if (ent.equals(_thrower))
continue;
if (ent instanceof Player)
if (((Player)ent).getGameMode() == GameMode.CREATIVE)
continue;
EntityType disguise = null;
if (_disguise != null && _disguise.getDisguise(ent) != null)
{
if (_disguise.getDisguise(ent) instanceof DisguiseSquid)
disguise = EntityType.SQUID;
}
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)
{
double d1 = vec3d.distanceSquared(entityCollisionPosition.pos);
if ((d1 < distanceToEntity) || (distanceToEntity == 0.0D))
{
if (_disguise.getDisguise(ent) instanceof DisguiseSquid)
disguise = EntityType.SQUID;
}
//Hit Player
if (UtilEnt.hitBox(_thrown.getLocation(), ent, _hitboxMult, disguise))
{
_callback.Collide(ent, null, this);
return true;
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())
//Idle
if (_idle)
{
_callback.Collide(null, block, this);
return true;
if (_thrown.getVelocity().length() < 0.2 &&
!UtilBlock.airFoliage(_thrown.getLocation().getBlock().getRelative(BlockFace.DOWN)))
{
_callback.Idle(this);
return true;
}
}
}
//Idle
if (_idle)
{
if (_thrown.getVelocity().length() < 0.2 &&
!UtilBlock.airFoliage(_thrown.getLocation().getBlock().getRelative(BlockFace.DOWN)))
{
_callback.Idle(this);
return true;
}
}
}
catch (Exception ex)
{
if (_hitBlock)