Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update ChunkTag, AreaContainmentObject and ColorTag tag param usage. #2364

Merged
merged 5 commits into from
Aug 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -190,14 +190,7 @@ static <T extends AreaContainmentObject> void registerTags(Class<T> type, Objec
// @description
// Returns a boolean indicating whether the specified location is inside this area.
// -->
processor.registerTag(ElementTag.class, "contains", (attribute, area) -> {
if (!attribute.hasParam()) {
return null;
}
LocationTag loc = attribute.paramAsType(LocationTag.class);
if (loc == null) {
return null;
}
processor.registerTag(ElementTag.class, LocationTag.class, "contains", (attribute, area, loc) -> {
return new ElementTag(area.doesContainLocation(loc));
}, "contains_location");

Expand Down Expand Up @@ -253,11 +246,8 @@ static <T extends AreaContainmentObject> void registerTags(Class<T> type, Objec
// Gets a list of all block locations with a specified flag within the area.
// Searches the internal flag lists, rather than through all possible blocks.
// -->
processor.registerTag(ListTag.class, "blocks_flagged", (attribute, area) -> {
if (!attribute.hasParam()) {
return null;
}
return area.getBlocksFlagged(CoreUtilities.toLowerCase(attribute.getParam()), attribute);
processor.registerTag(ListTag.class, ElementTag.class, "blocks_flagged", (attribute, area, flagName) -> {
return area.getBlocksFlagged(CoreUtilities.toLowerCase(flagName.toString()), attribute);
});

// <--[tag]
Expand All @@ -276,14 +266,7 @@ static <T extends AreaContainmentObject> void registerTags(Class<T> type, Objec
// @description
// Returns whether this area is fully inside another cuboid.
// -->
processor.registerTag(ElementTag.class, "is_within", (attribute, area) -> {
if (!attribute.hasParam()) {
return null;
}
CuboidTag cub2 = attribute.paramAsType(CuboidTag.class);
if (cub2 == null) {
return null;
}
processor.registerTag(ElementTag.class, CuboidTag.class, "is_within", (attribute, area, cub2) -> {
CuboidTag cuboid = area instanceof CuboidTag ? (CuboidTag) area : area.getCuboidBoundary();
if (cub2 != null) {
boolean contains = true;
Expand Down Expand Up @@ -319,14 +302,7 @@ static <T extends AreaContainmentObject> void registerTags(Class<T> type, Objec
// @description
// Returns a copy of the area, with the specified world.
// -->
processor.registerTag(type, "with_world", (attribute, area) -> {
if (!attribute.hasParam()) {
return null;
}
WorldTag world = attribute.paramAsType(WorldTag.class);
if (world == null) {
return null;
}
processor.registerTag(type, WorldTag.class, "with_world", (attribute, area, world) -> {
return (T) area.withWorld(world);
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -290,12 +290,8 @@ public static void registerTags() {
// @description
// Returns the chunk with the specified coordinates added to it.
// -->
tagProcessor.registerTag(ChunkTag.class, "add", (attribute, object) -> {
if (!attribute.hasParam()) {
attribute.echoError("The tag ChunkTag.add[<#>,<#>] must have a value.");
return null;
}
List<String> coords = CoreUtilities.split(attribute.getParam(), ',');
tagProcessor.registerTag(ChunkTag.class, ElementTag.class, "add", (attribute, object, addCoords) -> {
List<String> coords = CoreUtilities.split(addCoords.toString(), ',');
if (coords.size() < 2) {
attribute.echoError("The tag ChunkTag.add[<#>,<#>] requires two values!");
return null;
Expand All @@ -317,12 +313,8 @@ public static void registerTags() {
// @description
// Returns the chunk with the specified coordinates subtracted from it.
// -->
tagProcessor.registerTag(ChunkTag.class, "sub", (attribute, object) -> {
if (!attribute.hasParam()) {
attribute.echoError("The tag ChunkTag.add[<#>,<#>] must have a value.");
return null;
}
List<String> coords = CoreUtilities.split(attribute.getParam(), ',');
tagProcessor.registerTag(ChunkTag.class, ElementTag.class, "sub", (attribute, object, subCoords) -> {
List<String> coords = CoreUtilities.split(subCoords.toString(), ',');
if (coords.size() < 2) {
attribute.echoError("The tag ChunkTag.sub[<#>,<#>] requires two values!");
return null;
Expand Down Expand Up @@ -644,16 +636,12 @@ public static void registerTags() {
// Gets a list of all block locations with a specified flag within the CuboidTag.
// Searches the internal flag lists, rather than through all possible blocks.
// -->
tagProcessor.registerTag(ListTag.class, "blocks_flagged", (attribute, object) -> {
if (!attribute.hasParam()) {
attribute.echoError("ChunkTag.blocks_flagged[...] must have an input value.");
return null;
}
tagProcessor.registerTag(ListTag.class, ElementTag.class, "blocks_flagged", (attribute, object, flagNameInput) -> {
Chunk chunk = object.getChunkForTag(attribute);
if (chunk == null) {
return null;
}
String flagName = CoreUtilities.toLowerCase(attribute.getParam());
String flagName = CoreUtilities.toLowerCase(flagNameInput.toString());
ListTag blocks = new ListTag();
LocationFlagSearchHelper.getFlaggedLocations(chunk, flagName, (loc) -> {
blocks.addObject(new LocationTag(loc));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -475,15 +475,8 @@ public static void registerTags() {
// @description
// Returns the color that results if you mix this color with another.
// -->
tagProcessor.registerTag(ColorTag.class, "mix", (attribute, object) -> { // Temporarily non-static because the input could be 'random'
ColorTag mixed_with = attribute.paramAsType(ColorTag.class);
if (mixed_with != null) {
return new ColorTag(object.mixWith(mixed_with));
}
else {
Debug.echoError("'" + attribute.getParam() + "' is not a valid color!");
return null;
}
tagProcessor.registerTag(ColorTag.class, ColorTag.class, "mix", (attribute, object, mixWith) -> { // Temporarily non-static because the input could be 'random'
return new ColorTag(object.mixWith(mixWith));
});

// <--[tag]
Expand Down