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.CraftChunk;
import org.bukkit.craftbukkit.v1_17_R1.CraftServer; import org.bukkit.craftbukkit.v1_17_R1.CraftServer;
import org.bukkit.craftbukkit.v1_17_R1.CraftWorld; 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.CraftBlockState;
import org.bukkit.craftbukkit.v1_17_R1.block.data.CraftBlockData; import org.bukkit.craftbukkit.v1_17_R1.block.data.CraftBlockData;
import org.bukkit.craftbukkit.v1_17_R1.entity.CraftEntity; import org.bukkit.craftbukkit.v1_17_R1.entity.CraftEntity;
@ -635,22 +634,13 @@ public final class PaperweightFaweAdapter extends CachedBukkitAdapter implements
@Override @Override
public int getInternalBiomeId(BiomeType biomeType) { public int getInternalBiomeId(BiomeType biomeType) {
if (biomeType.getId().startsWith("minecraft:")) { final Registry<Biome> registry = MinecraftServer
Biome biomeBase = CraftBlock.biomeToBiomeBase( .getServer()
MinecraftServer.getServer().registryAccess().ownedRegistryOrThrow(Registry.BIOME_REGISTRY), .registryAccess()
BukkitAdapter.adapt(biomeType) .ownedRegistryOrThrow(Registry.BIOME_REGISTRY);
); ResourceLocation resourceLocation = ResourceLocation.tryParse(biomeType.getId());
return MinecraftServer.getServer().registryAccess().ownedRegistryOrThrow(Registry.BIOME_REGISTRY).getId(biomeBase); Biome biome = registry.get(resourceLocation);
} else { return registry.getId(biome);
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));
}
} }
@Override @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.CraftChunk;
import org.bukkit.craftbukkit.v1_18_R1.CraftServer; import org.bukkit.craftbukkit.v1_18_R1.CraftServer;
import org.bukkit.craftbukkit.v1_18_R1.CraftWorld; 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.CraftBlockState;
import org.bukkit.craftbukkit.v1_18_R1.block.data.CraftBlockData; import org.bukkit.craftbukkit.v1_18_R1.block.data.CraftBlockData;
import org.bukkit.craftbukkit.v1_18_R1.entity.CraftEntity; import org.bukkit.craftbukkit.v1_18_R1.entity.CraftEntity;
@ -627,22 +626,13 @@ public final class PaperweightFaweAdapter extends CachedBukkitAdapter implements
@Override @Override
public int getInternalBiomeId(BiomeType biomeType) { public int getInternalBiomeId(BiomeType biomeType) {
if (biomeType.getId().startsWith("minecraft:")) { final Registry<Biome> registry = MinecraftServer
Biome biomeBase = CraftBlock.biomeToBiomeBase( .getServer()
MinecraftServer.getServer().registryAccess().ownedRegistryOrThrow(Registry.BIOME_REGISTRY), .registryAccess()
BukkitAdapter.adapt(biomeType) .ownedRegistryOrThrow(Registry.BIOME_REGISTRY);
); ResourceLocation resourceLocation = ResourceLocation.tryParse(biomeType.getId());
return MinecraftServer.getServer().registryAccess().ownedRegistryOrThrow(Registry.BIOME_REGISTRY).getId(biomeBase); Biome biome = registry.get(resourceLocation);
} else { return registry.getId(biome);
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));
}
} }
@Override @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.item.ItemType;
import com.sk89q.worldedit.world.registry.BlockMaterial; import com.sk89q.worldedit.world.registry.BlockMaterial;
import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos;
import net.minecraft.core.Holder;
import net.minecraft.core.Registry; import net.minecraft.core.Registry;
import net.minecraft.core.WritableRegistry; import net.minecraft.core.WritableRegistry;
import net.minecraft.nbt.IntTag; 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.CraftChunk;
import org.bukkit.craftbukkit.v1_18_R2.CraftServer; import org.bukkit.craftbukkit.v1_18_R2.CraftServer;
import org.bukkit.craftbukkit.v1_18_R2.CraftWorld; 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.CraftBlockState;
import org.bukkit.craftbukkit.v1_18_R2.block.data.CraftBlockData; import org.bukkit.craftbukkit.v1_18_R2.block.data.CraftBlockData;
import org.bukkit.craftbukkit.v1_18_R2.entity.CraftEntity; import org.bukkit.craftbukkit.v1_18_R2.entity.CraftEntity;
@ -637,16 +635,9 @@ public final class PaperweightFaweAdapter extends CachedBukkitAdapter implements
.getServer() .getServer()
.registryAccess() .registryAccess()
.ownedRegistryOrThrow(Registry.BIOME_REGISTRY); .ownedRegistryOrThrow(Registry.BIOME_REGISTRY);
if (biomeType.getId().startsWith("minecraft:")) { ResourceLocation resourceLocation = ResourceLocation.tryParse(biomeType.getId());
Holder<Biome> biomeBase = CraftBlock.biomeToBiomeBase(registry, BukkitAdapter.adapt(biomeType)); Biome biome = registry.get(resourceLocation);
return registry.asHolderIdMap().getId(biomeBase); return registry.getId(biome);
} 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));
}
} }
@Override @Override