simplify biome id logic (#1677)

Co-authored-by: Alex <mc.cache@web.de>
This commit is contained in:
Hannes Greule 2022-04-01 19:25:48 +02:00 committed by GitHub
parent 4970db0405
commit a240b002de
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 17 additions and 46 deletions

View File

@ -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<Biome> 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<Biome> registry = MinecraftServer
.getServer()
.registryAccess()
.ownedRegistryOrThrow(Registry.BIOME_REGISTRY);
ResourceLocation resourceLocation = ResourceLocation.tryParse(biomeType.getId());
Biome biome = registry.get(resourceLocation);
return registry.getId(biome);
}
@Override

View File

@ -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<Biome> 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<Biome> registry = MinecraftServer
.getServer()
.registryAccess()
.ownedRegistryOrThrow(Registry.BIOME_REGISTRY);
ResourceLocation resourceLocation = ResourceLocation.tryParse(biomeType.getId());
Biome biome = registry.get(resourceLocation);
return registry.getId(biome);
}
@Override

View File

@ -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<Biome> biomeBase = CraftBlock.biomeToBiomeBase(registry, BukkitAdapter.adapt(biomeType));
return registry.asHolderIdMap().getId(biomeBase);
} else {
WritableRegistry<Biome> biomeRegistry = (WritableRegistry<Biome>) 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