Java Code Examples for net.minecraft.util.math.Box#rayTrace()
The following examples show how to use
net.minecraft.util.math.Box#rayTrace() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: KillauraLegitHack.java From Wurst7 with GNU General Public License v3.0 | 5 votes |
private boolean faceEntityClient(LivingEntity entity) { // get position & rotation Vec3d eyesPos = RotationUtils.getEyesPos(); Vec3d lookVec = RotationUtils.getServerLookVec(); // try to face center of boundingBox Box bb = entity.getBoundingBox(); if(faceVectorClient(bb.getCenter())) return true; // if not facing center, check if facing anything in boundingBox return bb.rayTrace(eyesPos, eyesPos.add(lookVec.multiply(range.getValue()))) != null; }
Example 2
Source File: Tracer.java From fabric-carpet with MIT License | 4 votes |
public static EntityHitResult rayTraceEntities(Entity source, Vec3d start, Vec3d end, Box box, Predicate<Entity> predicate, double maxSqDistance) { World world = source.world; double targetDistance = maxSqDistance; Entity target = null; Vec3d targetHitPos = null; for (Entity current : world.getEntities(source, box, predicate)) { Box currentBox = current.getBoundingBox().expand(current.getTargetingMargin()); Optional<Vec3d> currentHit = currentBox.rayTrace(start, end); if (currentBox.contains(start)) { if (targetDistance >= 0) { target = current; targetHitPos = currentHit.orElse(start); targetDistance = 0; } } else if (currentHit.isPresent()) { Vec3d currentHitPos = currentHit.get(); double currentDistance = start.squaredDistanceTo(currentHitPos); if (currentDistance < targetDistance || targetDistance == 0) { if (current.getRootVehicle() == source.getRootVehicle()) { if (targetDistance == 0) { target = current; targetHitPos = currentHitPos; } } else { target = current; targetHitPos = currentHitPos; targetDistance = currentDistance; } } } } if (target == null) return null; return new EntityHitResult(target, targetHitPos); }