Skip to content

Commit

Permalink
world.entities and location.flood_fill matchers
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed May 23, 2021
1 parent f5e47f2 commit 7f99eb4
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 20 deletions.
Expand Up @@ -722,7 +722,9 @@ public static class FloodFiller {

public AreaContainmentObject areaLimit;

public HashSet<Material> requiredMaterials;
public Material requiredMaterial;

public String matcher;

public void run(LocationTag start, AreaContainmentObject area) {
iterationLimit = Settings.blockTagsMaxBlocks();
Expand All @@ -738,7 +740,7 @@ public void flood(LocationTag loc) {
if (!loc.isChunkLoaded()) {
return;
}
if (!requiredMaterials.contains(loc.getBlock().getType())) {
if (matcher == null ? loc.getBlock().getType() != requiredMaterial : !BukkitScriptEvent.tryMaterial(loc.getBlock().getType(), matcher)) {
return;
}
result.add(loc);
Expand Down Expand Up @@ -2109,10 +2111,9 @@ else if (yaw < 315) {
attribute.echoError("LocationTag trying to read block, but cannot because the chunk is unloaded. Use the 'chunkload' command to ensure the chunk is loaded.");
return null;
}
flooder.requiredMaterials = new HashSet<>();

// <--[tag]
// @attribute <LocationTag.flood_fill[<limit>].types[<material>|...]>
// @attribute <LocationTag.flood_fill[<limit>].types[<matcher>]>
// @returns ListTag(LocationTag)
// @description
// Returns the set of all blocks, starting at the given location,
Expand All @@ -2124,13 +2125,11 @@ else if (yaw < 315) {
// The result will be an empty list if the block at the start location is not one of the input materials.
// -->
if (attribute.startsWith("types", 2) && attribute.hasContext(2)) {
for (MaterialTag material : attribute.contextAsType(2, ListTag.class).filter(MaterialTag.class, attribute.context)) {
flooder.requiredMaterials.add(material.getMaterial());
}
flooder.matcher = attribute.getContext(2);
attribute.fulfill(1);
}
else {
flooder.requiredMaterials.add(object.getBlock().getType());
flooder.requiredMaterial = object.getBlock().getType();
}
flooder.run(object, area);
}
Expand Down
Expand Up @@ -218,26 +218,18 @@ public static void registerTags() {
/////////////////

// <--[tag]
// @attribute <WorldTag.entities[(<entity>|...)]>
// @attribute <WorldTag.entities[(<matcher>)]>
// @returns ListTag(EntityTag)
// @description
// Returns a list of entities in this world.
// Optionally specify entity types to filter down to.
// Optionally specify an entity type matcher to filter down to.
// -->
registerTag("entities", (attribute, object) -> {
ListTag entities = new ListTag();
ListTag typeFilter = attribute.hasContext(1) ? attribute.contextAsType(1, ListTag.class) : null;
String matcher = attribute.hasContext(1) ? attribute.getContext(1) : null;
for (Entity entity : object.getEntitiesForTag()) {
EntityTag current = new EntityTag(entity);
if (typeFilter != null) {
for (String type : typeFilter) {
if (current.comparedTo(type)) {
entities.addObject(current.getDenizenObject());
break;
}
}
}
else {
if (matcher == null || BukkitScriptEvent.tryEntity(current, matcher)) {
entities.addObject(current.getDenizenObject());
}
}
Expand Down

0 comments on commit 7f99eb4

Please sign in to comment.