From a240b002de435326aa5d0805709c5cd19ab126fe Mon Sep 17 00:00:00 2001 From: Hannes Greule Date: Fri, 1 Apr 2022 19:25:48 +0200 Subject: [PATCH] simplify biome id logic (#1677) Co-authored-by: Alex --- .../v1_17_R1_2/PaperweightFaweAdapter.java | 24 ++++++------------- .../fawe/v1_18_R1/PaperweightFaweAdapter.java | 24 ++++++------------- .../fawe/v1_18_R2/PaperweightFaweAdapter.java | 15 +++--------- 3 files changed, 17 insertions(+), 46 deletions(-) diff --git a/worldedit-bukkit/adapters/adapter-1_17_1/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_17_R1_2/PaperweightFaweAdapter.java b/worldedit-bukkit/adapters/adapter-1_17_1/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_17_R1_2/PaperweightFaweAdapter.java index 0bfdfd0b9..084778789 100644 --- a/worldedit-bukkit/adapters/adapter-1_17_1/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_17_R1_2/PaperweightFaweAdapter.java +++ b/worldedit-bukkit/adapters/adapter-1_17_1/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_17_R1_2/PaperweightFaweAdapter.java @@ -85,7 +85,6 @@ import org.bukkit.block.data.BlockData; import org.bukkit.craftbukkit.v1_17_R1.CraftChunk; import org.bukkit.craftbukkit.v1_17_R1.CraftServer; import org.bukkit.craftbukkit.v1_17_R1.CraftWorld; -import org.bukkit.craftbukkit.v1_17_R1.block.CraftBlock; import org.bukkit.craftbukkit.v1_17_R1.block.CraftBlockState; import org.bukkit.craftbukkit.v1_17_R1.block.data.CraftBlockData; import org.bukkit.craftbukkit.v1_17_R1.entity.CraftEntity; @@ -635,22 +634,13 @@ public final class PaperweightFaweAdapter extends CachedBukkitAdapter implements @Override public int getInternalBiomeId(BiomeType biomeType) { - if (biomeType.getId().startsWith("minecraft:")) { - Biome biomeBase = CraftBlock.biomeToBiomeBase( - MinecraftServer.getServer().registryAccess().ownedRegistryOrThrow(Registry.BIOME_REGISTRY), - BukkitAdapter.adapt(biomeType) - ); - return MinecraftServer.getServer().registryAccess().ownedRegistryOrThrow(Registry.BIOME_REGISTRY).getId(biomeBase); - } else { - WritableRegistry biomeRegistry = MinecraftServer.getServer().registryAccess() - .ownedRegistryOrThrow(Registry.BIOME_REGISTRY); - - ResourceLocation resourceLocation = biomeRegistry.keySet().stream() - .filter(resource -> resource.toString().equals(biomeType.getId())) - .findAny().orElse(null); - - return biomeRegistry.getId(biomeRegistry.get(resourceLocation)); - } + final Registry registry = MinecraftServer + .getServer() + .registryAccess() + .ownedRegistryOrThrow(Registry.BIOME_REGISTRY); + ResourceLocation resourceLocation = ResourceLocation.tryParse(biomeType.getId()); + Biome biome = registry.get(resourceLocation); + return registry.getId(biome); } @Override diff --git a/worldedit-bukkit/adapters/adapter-1_18/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_18_R1/PaperweightFaweAdapter.java b/worldedit-bukkit/adapters/adapter-1_18/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_18_R1/PaperweightFaweAdapter.java index f31a81c61..39e193a0a 100644 --- a/worldedit-bukkit/adapters/adapter-1_18/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_18_R1/PaperweightFaweAdapter.java +++ b/worldedit-bukkit/adapters/adapter-1_18/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_18_R1/PaperweightFaweAdapter.java @@ -85,7 +85,6 @@ import org.bukkit.block.data.BlockData; import org.bukkit.craftbukkit.v1_18_R1.CraftChunk; import org.bukkit.craftbukkit.v1_18_R1.CraftServer; import org.bukkit.craftbukkit.v1_18_R1.CraftWorld; -import org.bukkit.craftbukkit.v1_18_R1.block.CraftBlock; import org.bukkit.craftbukkit.v1_18_R1.block.CraftBlockState; import org.bukkit.craftbukkit.v1_18_R1.block.data.CraftBlockData; import org.bukkit.craftbukkit.v1_18_R1.entity.CraftEntity; @@ -627,22 +626,13 @@ public final class PaperweightFaweAdapter extends CachedBukkitAdapter implements @Override public int getInternalBiomeId(BiomeType biomeType) { - if (biomeType.getId().startsWith("minecraft:")) { - Biome biomeBase = CraftBlock.biomeToBiomeBase( - MinecraftServer.getServer().registryAccess().ownedRegistryOrThrow(Registry.BIOME_REGISTRY), - BukkitAdapter.adapt(biomeType) - ); - return MinecraftServer.getServer().registryAccess().ownedRegistryOrThrow(Registry.BIOME_REGISTRY).getId(biomeBase); - } else { - WritableRegistry biomeRegistry = MinecraftServer.getServer().registryAccess() - .ownedRegistryOrThrow(Registry.BIOME_REGISTRY); - - ResourceLocation resourceLocation = biomeRegistry.keySet().stream() - .filter(resource -> resource.toString().equals(biomeType.getId())) - .findAny().orElse(null); - - return biomeRegistry.getId(biomeRegistry.get(resourceLocation)); - } + final Registry registry = MinecraftServer + .getServer() + .registryAccess() + .ownedRegistryOrThrow(Registry.BIOME_REGISTRY); + ResourceLocation resourceLocation = ResourceLocation.tryParse(biomeType.getId()); + Biome biome = registry.get(resourceLocation); + return registry.getId(biome); } @Override diff --git a/worldedit-bukkit/adapters/adapter-1_18_2/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_18_R2/PaperweightFaweAdapter.java b/worldedit-bukkit/adapters/adapter-1_18_2/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_18_R2/PaperweightFaweAdapter.java index 22b5fd3c0..f8b9b5752 100644 --- a/worldedit-bukkit/adapters/adapter-1_18_2/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_18_R2/PaperweightFaweAdapter.java +++ b/worldedit-bukkit/adapters/adapter-1_18_2/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_18_R2/PaperweightFaweAdapter.java @@ -55,7 +55,6 @@ import com.sk89q.worldedit.world.entity.EntityType; import com.sk89q.worldedit.world.item.ItemType; import com.sk89q.worldedit.world.registry.BlockMaterial; import net.minecraft.core.BlockPos; -import net.minecraft.core.Holder; import net.minecraft.core.Registry; import net.minecraft.core.WritableRegistry; import net.minecraft.nbt.IntTag; @@ -86,7 +85,6 @@ import org.bukkit.block.data.BlockData; import org.bukkit.craftbukkit.v1_18_R2.CraftChunk; import org.bukkit.craftbukkit.v1_18_R2.CraftServer; import org.bukkit.craftbukkit.v1_18_R2.CraftWorld; -import org.bukkit.craftbukkit.v1_18_R2.block.CraftBlock; import org.bukkit.craftbukkit.v1_18_R2.block.CraftBlockState; import org.bukkit.craftbukkit.v1_18_R2.block.data.CraftBlockData; import org.bukkit.craftbukkit.v1_18_R2.entity.CraftEntity; @@ -637,16 +635,9 @@ public final class PaperweightFaweAdapter extends CachedBukkitAdapter implements .getServer() .registryAccess() .ownedRegistryOrThrow(Registry.BIOME_REGISTRY); - if (biomeType.getId().startsWith("minecraft:")) { - Holder biomeBase = CraftBlock.biomeToBiomeBase(registry, BukkitAdapter.adapt(biomeType)); - return registry.asHolderIdMap().getId(biomeBase); - } else { - WritableRegistry biomeRegistry = (WritableRegistry) registry; - ResourceLocation resourceLocation = biomeRegistry.keySet().stream() - .filter(resource -> resource.toString().equals(biomeType.getId())) - .findAny().orElse(null); - return biomeRegistry.getId(biomeRegistry.get(resourceLocation)); - } + ResourceLocation resourceLocation = ResourceLocation.tryParse(biomeType.getId()); + Biome biome = registry.get(resourceLocation); + return registry.getId(biome); } @Override