0
0

[1.20.4]Spigot PluginでCustom BiomeのNamespaceを取得する

Last updated at Posted at 2024-04-26

結論

Java Code
java
    public BiomeBase getBiomeBase(Location location) {
        World bukkitWorld = location.getWorld();
        if(bukkitWorld == null)
            return null;

        int x = location.getBlockX();
        int y = location.getBlockY();
        int z = location.getBlockZ();
        net.minecraft.world.level.World nmsWorld = ((CraftWorld) bukkitWorld).getHandle();
        return nmsWorld.getNoiseBiome(x >> 2, y >> 2, z >> 2).a();
    }
    public MinecraftKey getBiomeKey(Location location) {
        DedicatedServer dedicatedServer = ((CraftServer) Bukkit.getServer()).getServer();
        IRegistry<BiomeBase> registry = dedicatedServer.aZ().d(Registries.at);

        return registry.b(getBiomeBase(location));
    }
Kotlin Code
Kotlin
    private fun getBiomeBase(loc: Location): BiomeBase {
        val bukkitWorld = loc.world
        val x = loc.blockX
        val y = loc.blockY
        val z = loc.blockZ
        val nmsWorld: net.minecraft.world.level.World = (bukkitWorld as CraftWorld).handle
        return nmsWorld.getNoiseBiome(x shr 2, y shr 2, z shr 2).a()
    }

    fun getBiomeKey(loc: Location): MinecraftKey? {
        val dedicatedServer = (Bukkit.getServer() as CraftServer).server
        val registry: IRegistry<BiomeBase?> = dedicatedServer.aZ().d(Registries.at)
        return registry.b(getBiomeBase(loc))
    }

未来のためのメモ

dedicatedServer.aZ()
MinecraftServer.registryAccess()
dedicatedServer.aZ().d()
RegistryAccess.ownedRegistryOrThrow()
Registries.at
Registries.BIOME

参考

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0