Skip to content

Commit

Permalink
add '.types' to 'location.flood_fill'
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Nov 17, 2020
1 parent a23bdc5 commit 4584219
Showing 1 changed file with 27 additions and 5 deletions.
Expand Up @@ -707,11 +707,10 @@ public static class FloodFiller {

public AreaContainmentObject areaLimit;

public Material requiredMaterial;
public HashSet<Material> requiredMaterials;

public void run(LocationTag start, AreaContainmentObject area, Material mat) {
public void run(LocationTag start, AreaContainmentObject area) {
iterationLimit = Settings.blockTagsMaxBlocks();
requiredMaterial = mat;
areaLimit = area;
result = new HashSet<>();
flood(start.getBlockLocation());
Expand All @@ -724,7 +723,7 @@ public void flood(LocationTag loc) {
if (!loc.isChunkLoaded()) {
return;
}
if (loc.getBlock().getType() != requiredMaterial) {
if (!requiredMaterials.contains(loc.getBlock().getType())) {
return;
}
result.add(loc);
Expand Down Expand Up @@ -2058,7 +2057,30 @@ else if (yaw < 315) {
}
return null;
}
flooder.run(object, area, object.getBlock().getType());
flooder.requiredMaterials = new HashSet<>();

// <--[tag]
// @attribute <LocationTag.flood_fill[<limit>].types[<material>|...]>
// @returns ListTag(LocationTag)
// @description
// Returns the set of all blocks, starting at the given location,
// that can be directly reached in a way that only travels through blocks of the specified material type(s).
// This will not travel diagonally, only the 6 cardinal directions (N/E/S/W/Up/Down).
// As this is potentially infinite for some block types (like air, stone, etc.) should there be any opening however small, a limit must be given.
// The limit value can be: a CuboidTag, an EllipsoidTag, or an ElementTag(Decimal) to use as a radius.
// Note that the returned list will not be in any particular order.
// 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());
}
attribute.fulfill(1);
}
else {
flooder.requiredMaterials.add(object.getBlock().getType());
}
flooder.run(object, area);
}
finally {
NMSHandler.getChunkHelper().restoreServerThread(object.getWorld());
Expand Down

0 comments on commit 4584219

Please sign in to comment.