Skip to content

Commit

Permalink
clean some TODO's related to 1.12
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Jun 29, 2020
1 parent 18f03bf commit 9679a87
Show file tree
Hide file tree
Showing 8 changed files with 13 additions and 191 deletions.
Expand Up @@ -271,36 +271,6 @@ public static class MapTraceResult {

public abstract MapTraceResult mapTrace(LivingEntity from, double range);

/**
* Gets the precise location in the specified direction.
*
* @param start The location to start the check from.
* @param direction The one-length vector to use as a direction.
* @param range The maximum distance between the start and end.
* @return The location, or null if it isn't in range.
*/
public abstract Location rayTrace(Location start, Vector direction, double range);

public abstract Location rayTraceBlock(Location start, Vector direction, double range);

public abstract Location getImpactNormal(Location start, Vector direction, double range);

/**
* Gets the precise location a LivingEntity is looking at.
*
* @param from The LivingEntity to start the trace from.
* @param range The maximum distance between the LivingEntity and the location.
* @return The location, or null if it isn't in range.
*/
public Location eyeTrace(LivingEntity from, double range) {
Location start = from.getEyeLocation();
double xzLen = Math.cos((start.getPitch() % 360) * (Math.PI / 180));
double nx = xzLen * Math.sin(-start.getYaw() * (Math.PI / 180));
double ny = Math.sin(start.getPitch() * (Math.PI / 180));
double nz = xzLen * Math.cos(start.getYaw() * (Math.PI / 180));
return rayTrace(start, new Vector(nx, -ny, nz), range);
}

public Location faceLocation(Location from, Location at) {
Vector direction = from.toVector().subtract(at.toVector()).normalize();
Location newLocation = from.clone();
Expand All @@ -325,16 +295,6 @@ public void faceLocation(Entity from, Location at) {
rotate(from, rotated.getYaw(), rotated.getPitch());
}

/**
* Changes an entity's yaw and pitch to make it face another entity.
*
* @param entity The Entity whose yaw and pitch you want to change.
* @param target The Entity it should be looking at.
*/
public void faceEntity(Entity entity, Entity target) {
faceLocation(entity, target.getLocation());
}

public boolean isFacingLocation(Location from, Location at, float yawLimitDegrees, float pitchLimitDegrees) {
Vector direction = from.toVector().subtract(at.toVector()).normalize();
float pitch = 90 - (float) Math.toDegrees(Math.acos(direction.getY()));
Expand Down
Expand Up @@ -1564,10 +1564,9 @@ else if (mtr.angle == BlockFace.EAST) {
if (range < 1) {
range = 200;
}
// TODO: after 1.12 support is dropped, World#rayTraceBlocks should be used.
Location location = NMSHandler.getEntityHelper().rayTraceBlock(object.getEyeLocation(), object.getEyeLocation().getDirection(), range);
if (location != null) {
return new LocationTag(location).getBlockLocation();
RayTraceResult traced = object.getWorld().rayTraceBlocks(object.getEyeLocation(), object.getEyeLocation().getDirection(), range);
if (traced != null && traced.getHitBlock() != null) {
return new LocationTag(traced.getHitBlock().getWorld(), traced.getHitPosition());
}
return null;
});
Expand Down
Expand Up @@ -1468,10 +1468,9 @@ public static void registerTags() {
if (range < 1) {
range = 200;
}
// TODO: after 1.12 support is dropped, World#rayTraceBlocks should be used.
Location location = NMSHandler.getEntityHelper().getImpactNormal(object, object.getDirection(), range);
if (location != null) {
return new LocationTag(location);
RayTraceResult traced = object.getWorld().rayTraceBlocks(object, object.getDirection(), range);
if (traced != null && traced.getHitBlockFace() != null) {
return new LocationTag(traced.getHitBlockFace().getDirection());
}
return null;
});
Expand All @@ -1488,10 +1487,9 @@ public static void registerTags() {
if (range < 1) {
range = 200;
}
// TODO: after 1.12 support is dropped, World#rayTraceBlocks should be used.
Location location = NMSHandler.getEntityHelper().rayTraceBlock(object, object.getDirection(), range);
if (location != null) {
return new LocationTag(location).getBlockLocation();
RayTraceResult traced = object.getWorld().rayTraceBlocks(object, object.getDirection(), range);
if (traced != null && traced.getHitBlock() != null) {
return new LocationTag(traced.getHitBlock().getLocation());
}
return null;
});
Expand All @@ -1508,10 +1506,9 @@ public static void registerTags() {
if (range < 1) {
range = 200;
}
// TODO: after 1.12 support is dropped, World#rayTraceBlocks should be used.
Location location = NMSHandler.getEntityHelper().rayTrace(object, object.getDirection(), range);
if (location != null) {
return new LocationTag(location);
RayTraceResult traced = object.getWorld().rayTraceBlocks(object, object.getDirection(), range);
if (traced != null && traced.getHitBlock() != null) {
return new LocationTag(traced.getHitBlock().getWorld(), traced.getHitPosition());
}
return null;
});
Expand Down
Expand Up @@ -38,7 +38,7 @@ public GlowCommand() {
// @Group player
//
// @Description
// Makes the link player see the chosen entities as glowing.
// Makes the linked player see the chosen entities as glowing.
// BE WARNED, THIS COMMAND IS HIGHLY EXPERIMENTAL AND MAY NOT WORK AS EXPECTED.
// This command works by globally enabling the glow effect, then whitelisting who is allowed to see it.
// This command does it's best to disable glow effect when the entity is unloaded, but does not guarantee it.
Expand Down
Expand Up @@ -500,38 +500,6 @@ public MapTraceResult mapTrace(LivingEntity from, double range) {
return mtr;
}

@Override
public Location rayTraceBlock(Location start, Vector direction, double range) {
Vector startVec = start.toVector();
MovingObjectPosition l = rayTrace(start.getWorld(), startVec, startVec.clone().add(direction.multiply(range)));
if (l != null && l.pos != null) {
return new Location(start.getWorld(), l.pos.x - (l.direction.getAdjacentX() * 0.05),
l.pos.y - (l.direction.getAdjacentY() * 0.05),
l.pos.z - (l.direction.getAdjacentZ() * 0.05));
}
return null;
}

@Override
public Location rayTrace(Location start, Vector direction, double range) {
Vector startVec = start.toVector();
MovingObjectPosition l = rayTrace(start.getWorld(), startVec, startVec.clone().add(direction.multiply(range)));
if (l != null && l.pos != null) {
return new Location(start.getWorld(), l.pos.x, l.pos.y, l.pos.z);
}
return null;
}

@Override
public Location getImpactNormal(Location start, Vector direction, double range) {
Vector startVec = start.toVector();
MovingObjectPosition l = rayTrace(start.getWorld(), startVec, startVec.clone().add(direction.multiply(range)));
if (l != null && l.direction != null) {
return new Location(start.getWorld(), l.direction.getAdjacentX(), l.direction.getAdjacentY(), l.direction.getAdjacentZ());
}
return null;
}

@Override
public void move(Entity entity, Vector vector) {
((CraftEntity) entity).getHandle().move(EnumMoveType.SELF, vector.getX(), vector.getY(), vector.getZ());
Expand Down
Expand Up @@ -550,40 +550,6 @@ public MapTraceResult mapTrace(LivingEntity from, double range) {
return mtr;
}

@Override
public Location rayTraceBlock(Location start, Vector direction, double range) {
Vector startVec = start.toVector();
MovingObjectPosition l = rayTrace(start.getWorld(), startVec, startVec.clone().add(direction.multiply(range)));
if (l instanceof MovingObjectPositionBlock && l.getPos() != null) {
return new Location(start.getWorld(), l.getPos().x - (((MovingObjectPositionBlock) l).getDirection().getAdjacentX() * 0.05),
l.getPos().y - (((MovingObjectPositionBlock) l).getDirection().getAdjacentY() * 0.05),
l.getPos().z - (((MovingObjectPositionBlock) l).getDirection().getAdjacentZ() * 0.05));
}
return null;
}

@Override
public Location rayTrace(Location start, Vector direction, double range) {
Vector startVec = start.toVector();
MovingObjectPosition l = rayTrace(start.getWorld(), startVec, startVec.clone().add(direction.multiply(range)));
if (l != null && l.getPos() != null) {
return new Location(start.getWorld(), l.getPos().x, l.getPos().y, l.getPos().z);
}
return null;
}

@Override
public Location getImpactNormal(Location start, Vector direction, double range) {
Vector startVec = start.toVector();
MovingObjectPosition l = rayTrace(start.getWorld(), startVec, startVec.clone().add(direction.multiply(range)));
if (l instanceof MovingObjectPositionBlock && ((MovingObjectPositionBlock) l).getDirection() != null) {
return new Location(start.getWorld(), ((MovingObjectPositionBlock) l).getDirection().getAdjacentX(),
((MovingObjectPositionBlock) l).getDirection().getAdjacentY(),
((MovingObjectPositionBlock) l).getDirection().getAdjacentZ());
}
return null;
}

@Override
public void move(Entity entity, Vector vector) {
((CraftEntity) entity).getHandle().move(EnumMoveType.SELF, new Vec3D(vector.getX(), vector.getY(), vector.getZ()));
Expand Down
Expand Up @@ -551,40 +551,6 @@ public MapTraceResult mapTrace(LivingEntity from, double range) {
return mtr;
}

@Override
public Location rayTraceBlock(Location start, Vector direction, double range) {
Vector startVec = start.toVector();
MovingObjectPosition l = rayTrace(start.getWorld(), startVec, startVec.clone().add(direction.multiply(range)));
if (l instanceof MovingObjectPositionBlock && l.getPos() != null) {
return new Location(start.getWorld(), l.getPos().x - (((MovingObjectPositionBlock) l).getDirection().getAdjacentX() * 0.05),
l.getPos().y - (((MovingObjectPositionBlock) l).getDirection().getAdjacentY() * 0.05),
l.getPos().z - (((MovingObjectPositionBlock) l).getDirection().getAdjacentZ() * 0.05));
}
return null;
}

@Override
public Location rayTrace(Location start, Vector direction, double range) {
Vector startVec = start.toVector();
MovingObjectPosition l = rayTrace(start.getWorld(), startVec, startVec.clone().add(direction.multiply(range)));
if (l != null && l.getPos() != null) {
return new Location(start.getWorld(), l.getPos().x, l.getPos().y, l.getPos().z);
}
return null;
}

@Override
public Location getImpactNormal(Location start, Vector direction, double range) {
Vector startVec = start.toVector();
MovingObjectPosition l = rayTrace(start.getWorld(), startVec, startVec.clone().add(direction.multiply(range)));
if (l instanceof MovingObjectPositionBlock && ((MovingObjectPositionBlock) l).getDirection() != null) {
return new Location(start.getWorld(), ((MovingObjectPositionBlock) l).getDirection().getAdjacentX(),
((MovingObjectPositionBlock) l).getDirection().getAdjacentY(),
((MovingObjectPositionBlock) l).getDirection().getAdjacentZ());
}
return null;
}

@Override
public void move(Entity entity, Vector vector) {
((CraftEntity) entity).getHandle().move(EnumMoveType.SELF, new Vec3D(vector.getX(), vector.getY(), vector.getZ()));
Expand Down
Expand Up @@ -560,40 +560,6 @@ public MapTraceResult mapTrace(LivingEntity from, double range) {
return mtr;
}

@Override
public Location rayTraceBlock(Location start, Vector direction, double range) {
Vector startVec = start.toVector();
MovingObjectPosition l = rayTrace(start.getWorld(), startVec, startVec.clone().add(direction.multiply(range)));
if (l instanceof MovingObjectPositionBlock && l.getPos() != null) {
return new Location(start.getWorld(), l.getPos().x - (((MovingObjectPositionBlock) l).getDirection().getAdjacentX() * 0.05),
l.getPos().y - (((MovingObjectPositionBlock) l).getDirection().getAdjacentY() * 0.05),
l.getPos().z - (((MovingObjectPositionBlock) l).getDirection().getAdjacentZ() * 0.05));
}
return null;
}

@Override
public Location rayTrace(Location start, Vector direction, double range) {
Vector startVec = start.toVector();
MovingObjectPosition l = rayTrace(start.getWorld(), startVec, startVec.clone().add(direction.multiply(range)));
if (l != null && l.getPos() != null) {
return new Location(start.getWorld(), l.getPos().x, l.getPos().y, l.getPos().z);
}
return null;
}

@Override
public Location getImpactNormal(Location start, Vector direction, double range) {
Vector startVec = start.toVector();
MovingObjectPosition l = rayTrace(start.getWorld(), startVec, startVec.clone().add(direction.multiply(range)));
if (l instanceof MovingObjectPositionBlock && ((MovingObjectPositionBlock) l).getDirection() != null) {
return new Location(start.getWorld(), ((MovingObjectPositionBlock) l).getDirection().getAdjacentX(),
((MovingObjectPositionBlock) l).getDirection().getAdjacentY(),
((MovingObjectPositionBlock) l).getDirection().getAdjacentZ());
}
return null;
}

@Override
public void move(Entity entity, Vector vector) {
((CraftEntity) entity).getHandle().move(EnumMoveType.SELF, new Vec3D(vector.getX(), vector.getY(), vector.getZ()));
Expand Down

0 comments on commit 9679a87

Please sign in to comment.