Skip to content

Commit

Permalink
Added filters to precise_target tags (#2261)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mwthorn committed Nov 9, 2020
1 parent 1c49ab3 commit faa3cce
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 3 deletions.
Expand Up @@ -2070,7 +2070,26 @@ else if (mtr.angle == BlockFace.EAST) {
if (range < 1) {
range = 200;
}
RayTraceResult result = object.getWorld().rayTrace(object.getEyeLocation(), object.getEyeLocation().getDirection(), range, FluidCollisionMode.NEVER, true, 0, (e) -> !e.equals(object.getBukkitEntity()));
RayTraceResult result;
// <--[tag]
// @attribute <EntityTag.precise_target[(<range>)].type[<entity_type>|...]>
// @returns EntityTag
// @description
// Returns the entity this entity is looking at, using precise ray trace logic.
// Optionally, specify a maximum range to find the entity from (defaults to 200).
// Accepts a list of types to trace against (types not listed will be ignored).
// -->
if (attribute.startsWith("type", 2) && attribute.hasContext(2)) {
attribute.fulfill(1);
Set<EntityType> types = new HashSet<>();
for (String str : attribute.contextAsType(1, ListTag.class)) {
types.add(EntityTag.valueOf(str, attribute.context).getBukkitEntityType());
}
result = object.getWorld().rayTrace(object.getEyeLocation(), object.getEyeLocation().getDirection(), range, FluidCollisionMode.NEVER, true, 0, (e) -> !e.equals(object.getBukkitEntity()) && types.contains(e.getType()));
}
else {
result = object.getWorld().rayTrace(object.getEyeLocation(), object.getEyeLocation().getDirection(), range, FluidCollisionMode.NEVER, true, 0, (e) -> !e.equals(object.getBukkitEntity()));
}
if (result != null && result.getHitEntity() != null) {
return new EntityTag(result.getHitEntity());
}
Expand All @@ -2089,7 +2108,26 @@ else if (mtr.angle == BlockFace.EAST) {
if (range < 1) {
range = 200;
}
RayTraceResult result = object.getWorld().rayTrace(object.getEyeLocation(), object.getEyeLocation().getDirection(), range, FluidCollisionMode.NEVER, true, 0, (e) -> !e.equals(object.getBukkitEntity()));
RayTraceResult result;
// <--[tag]
// @attribute <EntityTag.precise_target_position[(<range>)].type[<entity_type>|...]>
// @returns LocationTag
// @description
// Returns the location this entity is looking at, using precise ray trace (against entities) logic.
// Optionally, specify a maximum range to find the target from (defaults to 200).
// Accepts a list of types to trace against (types not listed will be ignored).
// -->
if (attribute.startsWith("type", 2) && attribute.hasContext(2)) {
attribute.fulfill(1);
Set<EntityType> types = new HashSet<>();
for (String str : attribute.contextAsType(1, ListTag.class)) {
types.add(EntityTag.valueOf(str, attribute.context).getBukkitEntityType());
}
result = object.getWorld().rayTrace(object.getEyeLocation(), object.getEyeLocation().getDirection(), range, FluidCollisionMode.NEVER, true, 0, (e) -> !e.equals(object.getBukkitEntity()) && types.contains(e.getType()));
}
else {
result = object.getWorld().rayTrace(object.getEyeLocation(), object.getEyeLocation().getDirection(), range, FluidCollisionMode.NEVER, true, 0, (e) -> !e.equals(object.getBukkitEntity()));
}
if (result != null) {
return new LocationTag(object.getWorld(), result.getHitPosition());
}
Expand Down
Expand Up @@ -1605,7 +1605,26 @@ public static void registerTags() {
if (range <= 0) {
range = 100;
}
RayTraceResult result = object.getWorld().rayTraceEntities(object, object.getDirection(), range);
RayTraceResult result;
// <--[tag]
// @attribute <LocationTag.precise_target_position[(<range>)].type[<entity_type>|...]>
// @returns LocationTag
// @description
// Returns the precise location this location is pointing at, when tracing against entities.
// Optionally, specify a maximum range to find the entity from (defaults to 100).
// Accepts a list of types to trace against (types not listed will be ignored).
// -->
if (attribute.startsWith("type", 2) && attribute.hasContext(2)) {
attribute.fulfill(1);
Set<EntityType> types = new HashSet<>();
for (String str : attribute.contextAsType(1, ListTag.class)) {
types.add(EntityTag.valueOf(str, attribute.context).getBukkitEntityType());
}
result = object.getWorld().rayTraceEntities(object, object.getDirection(), range, (e) -> types.contains(e.getType()));
}
else {
result = object.getWorld().rayTraceEntities(object, object.getDirection(), range);
}
if (result != null) {
return new LocationTag(object.getWorld(), result.getHitPosition());
}
Expand Down

0 comments on commit faa3cce

Please sign in to comment.