Skip to content

Commit

Permalink
WorldTag.biomes
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Nov 30, 2021
1 parent 840db0b commit d60a7b6
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 1 deletion.
Expand Up @@ -167,6 +167,10 @@ public boolean isCorrectMappingsCode() {

public abstract ProfileEditor getProfileEditor();

public List<BiomeNMS> getBiomes(World world) {
throw new UnsupportedOperationException();
}

public abstract BiomeNMS getBiomeNMS(World world, String name);

public BiomeNMS getBiomeAt(Block block) {
Expand Down
Expand Up @@ -2,6 +2,7 @@

import com.denizenscript.denizen.events.BukkitScriptEvent;
import com.denizenscript.denizen.nms.NMSHandler;
import com.denizenscript.denizen.nms.abstracts.BiomeNMS;
import com.denizenscript.denizen.utilities.debugging.Debug;
import com.denizenscript.denizen.utilities.flags.WorldFlagHandler;
import com.denizenscript.denizencore.flags.AbstractFlagTracker;
Expand Down Expand Up @@ -857,10 +858,23 @@ else if (time >= 12500) {
return list;
});

// <--[tag]
// @attribute <WorldTag.biomes>
// @returns ListTag(BiomeTag)
// @description
// Returns a list of all biomes in this world (including custom biomes).
// -->
registerTag(ListTag.class, "biomes", (attribute, object) -> {
ListTag output = new ListTag();
for (BiomeNMS biome : NMSHandler.getInstance().getBiomes(object.getWorld())) {
output.addObject(new BiomeTag(biome));
}
return output;
});

// <--[tag]
// @attribute <WorldTag.advanced_matches[<matcher>]>
// @returns ElementTag(Boolean)
// @group element checking
// @description
// Returns whether the world matches some matcher text, using the system behind <@link language Advanced Script Event Matching>.
// -->
Expand Down
Expand Up @@ -32,6 +32,7 @@
import net.minecraft.nbt.TagParser;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.MutableComponent;
import net.minecraft.resources.ResourceKey;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.level.ServerLevel;
Expand Down Expand Up @@ -61,6 +62,7 @@
import java.lang.reflect.Field;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

public class Handler extends NMSHandler {
Expand Down Expand Up @@ -231,6 +233,16 @@ public ProfileEditor getProfileEditor() {
return profileEditor;
}

@Override
public List<BiomeNMS> getBiomes(World world) {
ServerLevel level = ((CraftWorld) world).getHandle();
ArrayList<BiomeNMS> output = new ArrayList<>();
for (Map.Entry<ResourceKey<Biome>, Biome> pair : level.registryAccess().registryOrThrow(Registry.BIOME_REGISTRY).entrySet()) {
output.add(new BiomeNMSImpl(level, pair.getKey().location().toString()));
}
return output;
}

@Override
public BiomeNMS getBiomeNMS(World world, String name) {
BiomeNMSImpl impl = new BiomeNMSImpl(((CraftWorld) world).getHandle(), name);
Expand Down
Expand Up @@ -32,6 +32,7 @@
import net.minecraft.nbt.TagParser;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.MutableComponent;
import net.minecraft.resources.ResourceKey;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.level.ServerLevel;
Expand Down Expand Up @@ -61,6 +62,7 @@
import java.lang.reflect.Field;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

public class Handler extends NMSHandler {
Expand Down Expand Up @@ -231,6 +233,16 @@ public ProfileEditor getProfileEditor() {
return profileEditor;
}

@Override
public List<BiomeNMS> getBiomes(World world) {
ServerLevel level = ((CraftWorld) world).getHandle();
ArrayList<BiomeNMS> output = new ArrayList<>();
for (Map.Entry<ResourceKey<Biome>, Biome> pair : level.registryAccess().registryOrThrow(Registry.BIOME_REGISTRY).entrySet()) {
output.add(new BiomeNMSImpl(level, pair.getKey().location().toString()));
}
return output;
}

@Override
public BiomeNMS getBiomeNMS(World world, String name) {
BiomeNMSImpl impl = new BiomeNMSImpl(((CraftWorld) world).getHandle(), name);
Expand Down

0 comments on commit d60a7b6

Please sign in to comment.