Skip to content

Commit

Permalink
use better internal backing for previous commit (precise_target)
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Oct 31, 2019
1 parent 040bd25 commit 0830edc
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 25 deletions.
Expand Up @@ -22,10 +22,6 @@

public abstract class EntityHelper {

public Entity rayTraceEntity(Location start, Entity entity, Vector direction, double range) {
throw new UnsupportedOperationException();
}

public void setSneaking(Player player, boolean sneak) {
player.setSneaking(sneak);
}
Expand Down
Expand Up @@ -40,6 +40,7 @@
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
import org.bukkit.inventory.*;
import org.bukkit.potion.*;
import org.bukkit.util.RayTraceResult;
import org.bukkit.util.Vector;

import java.util.*;
Expand Down Expand Up @@ -2270,9 +2271,9 @@ else if (mtr.angle == BlockFace.EAST) {
if (range < 1) {
range = 200;
}
Entity entity = NMSHandler.getEntityHelper().rayTraceEntity(object.getEyeLocation(), object.getBukkitEntity(), object.getEyeLocation().getDirection(), range);
if (entity != null) {
return new EntityTag(entity);
RayTraceResult result = object.getWorld().rayTraceEntities(object.getEyeLocation(), object.getEyeLocation().getDirection(), range, (e) -> !e.equals(object.getBukkitEntity()));
if (result != null && result.getHitEntity() != null) {
return new EntityTag(result.getHitEntity());
}
return null;
});
Expand Down
Expand Up @@ -45,6 +45,7 @@
import org.bukkit.material.Door;
import org.bukkit.material.MaterialData;
import org.bukkit.util.BlockIterator;
import org.bukkit.util.RayTraceResult;
import org.bukkit.util.Vector;

import java.util.*;
Expand Down Expand Up @@ -1303,6 +1304,7 @@ else if (object.getBlockTypeForTag(attribute) == Material.FLOWER_POT) {
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);
Expand All @@ -1322,6 +1324,7 @@ else if (object.getBlockTypeForTag(attribute) == Material.FLOWER_POT) {
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();
Expand All @@ -1341,6 +1344,7 @@ else if (object.getBlockTypeForTag(attribute) == Material.FLOWER_POT) {
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);
Expand All @@ -1360,9 +1364,9 @@ else if (object.getBlockTypeForTag(attribute) == Material.FLOWER_POT) {
if (range < 1) {
range = 200;
}
Entity entity = NMSHandler.getEntityHelper().rayTraceEntity(object, null, object.getDirection(), range);
if (entity != null) {
return new EntityTag(entity);
RayTraceResult result = object.getWorld().rayTraceEntities(object, object.getDirection(), range);
if (result != null && result.getHitEntity() != null) {
return new EntityTag(result.getHitEntity());
}
return null;
});
Expand Down
Expand Up @@ -558,21 +558,6 @@ public Location rayTraceBlock(Location start, Vector direction, double range) {
return null;
}

@Override
public Entity rayTraceEntity(Location start, Entity entity, Vector direction, double range) {
Location end = start.clone().add(direction.multiply(range));
Vec3D startVec = new Vec3D(start.getX(), start.getY(), start.getZ());
Vec3D endVec = new Vec3D(end.getX(), end.getY(), end.getZ());
net.minecraft.server.v1_14_R1.World nmsWorld = ((CraftWorld) start.getWorld()).getHandle();
net.minecraft.server.v1_14_R1.Entity nmsEntity = entity == null ? null : ((CraftEntity) entity).getHandle();
AxisAlignedBB aabb = new AxisAlignedBB(startVec, endVec);
MovingObjectPositionEntity pos = ProjectileHelper.a(nmsWorld, nmsEntity, startVec, endVec, aabb, null);
if (pos != null && pos.getEntity() != null) {
return pos.getEntity().getBukkitEntity();
}
return null;
}

@Override
public Location rayTrace(Location start, Vector direction, double range) {
Vector startVec = start.toVector();
Expand Down

0 comments on commit 0830edc

Please sign in to comment.