Tidy up entity geometry stuff:
- Add a getCentre method for entities to GeometryUtils - Replace getPositionEyes(0) with getPositionEyes(1) since it's more efficient, and by definition they must be the same - Remove all the silly getEntityBoundingBox().minY stuff, this bug has been fixed since 1.8! (which begs the question: if it was considered a bug, how on earth did it go unfixed for that long?) - A few other small things
This commit is contained in:
@@ -125,7 +125,7 @@ public final class BlockUtils {
|
||||
* is negative.
|
||||
*/
|
||||
public static IBlockState getBlockEntityIsStandingOn(Entity entity){
|
||||
BlockPos pos = new BlockPos(MathHelper.floor(entity.posX), (int)entity.getEntityBoundingBox().minY - 1,
|
||||
BlockPos pos = new BlockPos(MathHelper.floor(entity.posX), (int)entity.posY - 1,
|
||||
MathHelper.floor(entity.posZ));
|
||||
return entity.world.getBlockState(pos);
|
||||
}
|
||||
|
||||
@@ -210,7 +210,7 @@ public final class EntityUtils {
|
||||
}
|
||||
}
|
||||
|
||||
box = box.offset(destination.subtract(entity.posX, box.minY, entity.posZ));
|
||||
box = box.offset(destination.subtract(entity.posX, entity.posY, entity.posZ));
|
||||
|
||||
// All the parameters of this method are INCLUSIVE, so even the max coordinates should be rounded down
|
||||
Iterable<BlockPos> cuboid = BlockPos.getAllInBox(MathHelper.floor(box.minX), MathHelper.floor(box.minY),
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package electroblob.wizardry.util;
|
||||
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.EnumFacing.Axis;
|
||||
import net.minecraft.util.math.AxisAlignedBB;
|
||||
@@ -49,6 +50,14 @@ public final class GeometryUtils {
|
||||
return new Vec3d(box.minX + (box.maxX - box.minX) * 0.5, box.minY + (box.maxY - box.minY) * 0.5, box.minZ + (box.maxZ - box.minZ) * 0.5);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a {@link Vec3d} of the coordinates at the centre of the given entity's bounding box. This is more
|
||||
* efficient than {@code GeometryUtils.getCentre(entity.getEntityBoundingBox())} as it can use the entity's fields.
|
||||
*/
|
||||
public static Vec3d getCentre(Entity entity){
|
||||
return new Vec3d(entity.posX, entity.posY + entity.height/2, entity.posZ);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a {@link Vec3d} of the coordinates at the centre of the given face of the given block position (i.e. the
|
||||
* centre of the block plus 0.5 in the given direction).
|
||||
|
||||
@@ -768,7 +768,7 @@ public final class ParticleBuilder {
|
||||
|
||||
for(int i = 0; i < 10; i++){
|
||||
double x = entity.posX + world.rand.nextDouble() * 2 - 1;
|
||||
double y = entity.getEntityBoundingBox().minY + entity.getEyeHeight() - 0.5 + world.rand.nextDouble();
|
||||
double y = entity.posY + entity.getEyeHeight() - 0.5 + world.rand.nextDouble();
|
||||
double z = entity.posZ + world.rand.nextDouble() * 2 - 1;
|
||||
ParticleBuilder.create(Type.SPARKLE).pos(x, y, z).vel(0, 0.1, 0).clr(1, 1, 0.3f).spawn(world);
|
||||
}
|
||||
|
||||
@@ -43,7 +43,7 @@ public final class RayTracer {
|
||||
public static RayTraceResult standardBlockRayTrace(World world, EntityLivingBase entity, double range, boolean hitLiquids,
|
||||
boolean ignoreUncollidables, boolean returnLastUncollidable){
|
||||
// This method does not apply an offset like ray spells do, since it is not desirable in most other use cases.
|
||||
Vec3d origin = new Vec3d(entity.posX, entity.getEntityBoundingBox().minY + entity.getEyeHeight(), entity.posZ);
|
||||
Vec3d origin = entity.getPositionEyes(1);
|
||||
Vec3d endpoint = origin.add(entity.getLookVec().scale(range));
|
||||
return world.rayTraceBlocks(origin, endpoint, hitLiquids, ignoreUncollidables, returnLastUncollidable);
|
||||
}
|
||||
@@ -76,7 +76,7 @@ public final class RayTracer {
|
||||
@Nullable
|
||||
public static RayTraceResult standardEntityRayTrace(World world, Entity entity, double range, boolean hitLiquids){
|
||||
// This method does not apply an offset like ray spells do, since it is not desirable in most other use cases.
|
||||
Vec3d origin = new Vec3d(entity.posX, entity.getEntityBoundingBox().minY + entity.getEyeHeight(), entity.posZ);
|
||||
Vec3d origin = entity.getPositionEyes(1);
|
||||
Vec3d endpoint = origin.add(entity.getLookVec().scale(range));
|
||||
return rayTrace(world, origin, endpoint, 0, hitLiquids, false, false, Entity.class, ignoreEntityFilter(entity));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user