Skip to content

Commit

Permalink
AreaContainmentObject and BiomeTag examples (#2394)
Browse files Browse the repository at this point in the history
* Add `AreaContainmentObject` tag examples.

Also de-dented code for 'spawnable_blocks' to make it look more uniform :)

* Add `BiomeTag` tag examples.

Mechanism not done as they can't be tested currently.
Fixed up some funky new lines here and there.

* Add better example for `<BiomeTag.downfal_type>`

* Change `<BiomeTag.downfall_type>` one more time.

Returns specific data, and so it should probably be shown in the example.

* Update a few examples to have more clear comments.

* Clean up and `BiomeTag` mech examples.
  • Loading branch information
BreadcrumbIsTaken committed Nov 25, 2022
1 parent 2a19aac commit 475612b
Show file tree
Hide file tree
Showing 2 changed files with 97 additions and 14 deletions.
Expand Up @@ -96,6 +96,9 @@ static <T extends AreaContainmentObject> void registerTags(Class<T> type, Objec
// @description
// Returns a cuboid approximately representing the maximal bounding box of the area (anything this cuboid does not contain, is also not contained by the area, but not vice versa).
// For single-member CuboidTags, this tag returns a copy of the cuboid.
// @example
// # Narrates the cuboids bounding box, which is just the cuboid.
// - narrate <cuboid[my_cuboid].bounding_box>
// -->
processor.registerTag(CuboidTag.class, "bounding_box", (attribute, area) -> {
return area.getCuboidBoundary();
Expand All @@ -107,6 +110,8 @@ static <T extends AreaContainmentObject> void registerTags(Class<T> type, Objec
// @returns WorldTag
// @description
// Returns the area's world.
// @example
// - narrate "The cuboid, 'my_cuboid', is in world: <cuboid[my_cuboid].world.name>!"
// -->
processor.registerTag(WorldTag.class, "world", (attribute, area) -> {
return area.getWorld();
Expand All @@ -117,6 +122,10 @@ static <T extends AreaContainmentObject> void registerTags(Class<T> type, Objec
// @returns ListTag(PlayerTag)
// @description
// Gets a list of all players currently within the area.
// @example
// # Narrates a list of players' names that are within the area separated by a comma and a space.
// # For example: "List of players in 'my_cuboid': steve, alex, john, jane"
// - narrate "List of players in 'my_cuboid': <cuboid[my_cuboid].players.parse[name].separated_by[, ]>"
// -->
processor.registerTag(ListTag.class, "players", (attribute, area) -> {
ListTag result = new ListTag();
Expand All @@ -133,6 +142,10 @@ static <T extends AreaContainmentObject> void registerTags(Class<T> type, Objec
// @returns ListTag(NPCTag)
// @description
// Gets a list of all NPCs currently within the area.
// @example
// # Narrates a list of NPCs' names that are within the area separated by a comma and a space.
// # For example: "List of NPCs in 'my_cuboid': steve, alex, john, jane"
// - narrate "List of NPCs in 'my_cuboid': <cuboid[my_cuboid].npcs.parse[name].separated_by[, ]>"
// -->
if (Depends.citizens != null) {
processor.registerTag(ListTag.class, "npcs", (attribute, area) -> {
Expand All @@ -152,6 +165,10 @@ static <T extends AreaContainmentObject> void registerTags(Class<T> type, Objec
// @returns ListTag(EntityTag)
// @description
// Gets a list of all entities currently within the area, with an optional search parameter for the entity.
// @example
// # Narrates the locations of the entities that match 'axolotl' within the area.
// - foreach <cuboid[my_cuboid].entities[axolotl]> as:entity:
// - narrate <[entity].location>
// -->
processor.registerTag(ListTag.class, "entities", (attribute, area) -> {
String matcher = attribute.hasParam() ? attribute.getParam() : null;
Expand All @@ -173,6 +190,10 @@ static <T extends AreaContainmentObject> void registerTags(Class<T> type, Objec
// @description
// Gets a list of all living entities currently within the area.
// This includes Players, mobs, NPCs, etc., but excludes dropped items, experience orbs, etc.
// @example
// # Narrates the name of all the living entities within the area.
// - foreach <cuboid[my_cuboid].living_entities> as:entity:
// - narrate <[entity].name>
// -->
processor.registerTag(ListTag.class, "living_entities", (attribute, area) -> {
ListTag result = new ListTag();
Expand All @@ -189,6 +210,12 @@ static <T extends AreaContainmentObject> void registerTags(Class<T> type, Objec
// @returns ElementTag(Boolean)
// @description
// Returns a boolean indicating whether the specified location is inside this area.
// @example
// # Checks to see if "my_cuboid" contains the player's location.
// - if <cuboid[my_cuboid].contains[<player.location>]>:
// - narrate "It is contained within 'my_cuboid'!"
// - else:
// - narrate "It is not contained within 'my_cuboid'!"
// -->
processor.registerTag(ElementTag.class, LocationTag.class, "contains", (attribute, area, loc) -> {
return new ElementTag(area.doesContainLocation(loc));
Expand All @@ -200,6 +227,10 @@ static <T extends AreaContainmentObject> void registerTags(Class<T> type, Objec
// @description
// Returns each block location within the area.
// Optionally, specify a material matcher to only return locations with that block type.
// @example
// # Narrates the locations of blocks that match "*planks" within the area.
// - foreach <cuboid[my_cuboid].blocks[*planks]> as:plank:
// - narrate <[plank]>
// -->
processor.registerTag(ListTag.class, "blocks", (attribute, area) -> {
if (attribute.hasParam()) {
Expand All @@ -223,20 +254,24 @@ static <T extends AreaContainmentObject> void registerTags(Class<T> type, Objec
// Returns each LocationTag within the area that is safe for players or similar entities to spawn in.
// Optionally, specify a material matcher to only return locations with that block type.
// Uses the same spawnable check as <@link tag LocationTag.is_spawnable>
// @example
// # Spawns a creeper at a random spawnable block within the area.
// - define block <cuboid[my_cuboid].spawnable_blocks.random>
// - spawn creeper <[block]>
// -->
processor.registerTag(ListTag.class, "spawnable_blocks", (attribute, area) -> {
NMSHandler.chunkHelper.changeChunkServerThread(area.getWorld().getWorld());
try {
if (attribute.hasParam()) {
String matcher = attribute.getParam();
Predicate<Location> predicate = (l) -> SpawnableHelper.isSpawnable(l) && new LocationTag(l.getBlock().getRelative(0, -1, 0).getLocation()).tryAdvancedMatcher(matcher);
return area.getBlocks(predicate);
}
return area.getBlocks(SpawnableHelper::isSpawnable);
}
finally {
NMSHandler.chunkHelper.restoreServerThread(area.getWorld().getWorld());
NMSHandler.chunkHelper.changeChunkServerThread(area.getWorld().getWorld());
try {
if (attribute.hasParam()) {
String matcher = attribute.getParam();
Predicate<Location> predicate = (l) -> SpawnableHelper.isSpawnable(l) && new LocationTag(l.getBlock().getRelative(0, -1, 0).getLocation()).tryAdvancedMatcher(matcher);
return area.getBlocks(predicate);
}
return area.getBlocks(SpawnableHelper::isSpawnable);
}
finally {
NMSHandler.chunkHelper.restoreServerThread(area.getWorld().getWorld());
}
}, "get_spawnable_blocks");

// <--[tag]
Expand All @@ -245,6 +280,10 @@ static <T extends AreaContainmentObject> void registerTags(Class<T> type, Objec
// @description
// 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.
// @example
// # Narrates the locations of blocks that are flagged "my_flag"
// - foreach <cuboid[my_cuboid].blocks_flagged[my_flag]> as:block:
// - narrate <[block].location>
// -->
processor.registerTag(ListTag.class, ElementTag.class, "blocks_flagged", (attribute, area, flagName) -> {
return area.getBlocksFlagged(CoreUtilities.toLowerCase(flagName.toString()), attribute);
Expand All @@ -256,6 +295,9 @@ static <T extends AreaContainmentObject> void registerTags(Class<T> type, Objec
// @description
// Returns each block location on the 3D outer shell of the area.
// This tag is useful for displaying particles or blocks to mark the boundary of the area.
// @example
// # Plays the "TOTEM" effect in the shell of the area to the player.
// - playeffect effect:TOTEM at:<cuboid[my_cuboid].shell> offset:0 targets:<player>
// -->
processor.registerTag(ListTag.class, "shell", (attribute, area) -> {
return area.getShell();
Expand All @@ -266,6 +308,12 @@ static <T extends AreaContainmentObject> void registerTags(Class<T> type, Objec
// @returns ElementTag(Boolean)
// @description
// Returns whether this area is fully inside another cuboid.
// @example
// # Checks to see if "my_cuboid" is within "my_bigger_cuboid".
// - if <cuboid[my_cuboid].is_within[<cuboid[my_bigger_cuboid]>]>:
// - narrate "It is fully within 'my_bigger_cuboid'!"
// - else:
// - narrate "It is not fully within 'my_bigger_cuboid'!"
// -->
processor.registerTag(ElementTag.class, CuboidTag.class, "is_within", (attribute, area, cub2) -> {
CuboidTag cuboid = area instanceof CuboidTag ? (CuboidTag) area : area.getCuboidBoundary();
Expand Down Expand Up @@ -302,6 +350,9 @@ static <T extends AreaContainmentObject> void registerTags(Class<T> type, Objec
// @returns AreaObject
// @description
// Returns a copy of the area, with the specified world.
// @example
// # Notes a copy of "my_cuboid" but with the world "world_the_end".
// - note my_new_cuboid <cuboid[my_cuboid].with_world[world_the_end]>
// -->
processor.registerTag(type, WorldTag.class, "with_world", (attribute, area, world) -> {
return (T) area.withWorld(world);
Expand Down
Expand Up @@ -180,6 +180,9 @@ public static void registerTags() {
// @description
// Returns this biome's downfall type for when a world has weather.
// This can be RAIN, SNOW, or NONE.
// @example
// # In a plains biome, this fills with 'RAIN'.
// - narrate "The downfall type in plains biomes is: <biome[plains].downfall_type>!"
// -->
tagProcessor.registerTag(ElementTag.class, "downfall_type", (attribute, object) -> {
return new ElementTag(object.biome.getDownfallType());
Expand All @@ -190,6 +193,9 @@ public static void registerTags() {
// @returns ElementTag
// @description
// Returns this biome's name.
// @example
// # In a plains biome, this fills with 'plains'.
// - narrate "You are currently in a <biome[plains].name> biome!"
// -->
tagProcessor.registerTag(ElementTag.class, "name", (attribute, object) -> {
return new ElementTag(CoreUtilities.toLowerCase(object.biome.getName()));
Expand All @@ -201,28 +207,40 @@ public static void registerTags() {
// @mechanism BiomeTag.humidity
// @description
// Returns the humidity of this biome.
// @example
// # In a plains biome, this fills with '0.4'.
// - narrate "Humidity in a plains biome is <biome[plains].humidity>! So humid!"
// -->
tagProcessor.registerTag(ElementTag.class, "humidity", (attribute, object) -> {
return new ElementTag(object.biome.getHumidity());
});

// <--[tag]
// @attribute <BiomeTag.temperature>
// @returns ElementTag(Decimal)
// @mechanism BiomeTag.temperature
// @description
// Returns the temperature of this biome.
// @example
// # In a plains biome, this fills with '0.8'.
// - narrate "Stay warm! In a plains biome, the temperature is <biome[plains].temperature>!"
// -->
tagProcessor.registerTag(ElementTag.class, "temperature", (attribute, object) -> {
return new ElementTag(object.biome.getTemperature());
});

// <--[tag]
// @attribute <BiomeTag.spawnable_entities[(<type>)]>
// @returns ListTag(EntityTag)
// @description
// Returns all entities that spawn naturally in this biome.
// Optionally specify a type as: AMBIENT, CREATURES, MONSTERS, WATER, or ALL.
// (By default, will be "ALL").
//
// @example
// # Narrates the types of entities of type MONSTERS that can spawn in the player's biome.
// # For example, in a plains biome this could contain "SPIDER", "ZOMBIE", "CREEPER", etc.
// - foreach <player.location.biome.spawnable_entities[MONSTERS]> as:entity:
// - narrate <[entity]>
// -->
tagProcessor.registerTag(ListTag.class, "spawnable_entities", (attribute, object) -> {
List<EntityType> entityTypes;
Expand Down Expand Up @@ -297,9 +315,13 @@ public void adjust(Mechanism mechanism) {
// @description
// Sets the humidity for this biome server-wide.
// If this is greater than 0.85, fire has less chance
// to spread in this biome.
// to spread in this biome. Resets on server restart.
// @tags
// <BiomeTag.humidity>
// @example
// # Adjusts the humidity of the plains biome on server start.
// on server start:
// - adjust <biome[plains]> humidity:0.5
// -->
if (mechanism.matches("humidity") && mechanism.requireFloat()) {
biome.setHumidity(mechanism.getValue().asFloat());
Expand All @@ -312,8 +334,13 @@ public void adjust(Mechanism mechanism) {
// @description
// Sets the temperature for this biome server-wide.
// If this is less than 0.15, snow will form on the ground when weather occurs in the world and a layer of ice will form over water.
// Resets on server restart.
// @tags
// <BiomeTag.temperature>
// @example
// # Adjusts the temperature of the plains biome on server start.
// on server start:
// - adjust <biome[plains]> temperature:0.5
// -->
if (mechanism.matches("temperature") && mechanism.requireFloat()) {
biome.setTemperature(mechanism.getValue().asFloat());
Expand All @@ -325,9 +352,14 @@ public void adjust(Mechanism mechanism) {
// @input ElementTag
// @description
// Sets the downfall-type for this biome server-wide.
// This can be RAIN, SNOW, or NONE.
// This can be RAIN, SNOW, or NONE. Resets on server restart.
// @tags
// <BiomeTag.temperature>
// @example
// # Adjusts the downfall type of the plains biome on server start.
// on server start:
// - adjust <biome[plains]> temperature:-0.2
// - adjust <biome[plains]> downfall_type:SNOW
// -->
if (mechanism.matches("downfall_type") && mechanism.requireEnum(BiomeNMS.DownfallType.class)) {
biome.setPrecipitation(BiomeNMS.DownfallType.valueOf(mechanism.getValue().asString().toUpperCase()));
Expand Down

0 comments on commit 475612b

Please sign in to comment.