Load default biomes into registry at earliest convenience, then load custom biomes later.

Dieser Commit ist enthalten in:
dordsor21 2021-08-19 13:48:24 +01:00
Ursprung 563ad7761a
Commit f412796f28
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 1E53E88969FFCF0B
3 geänderte Dateien mit 12 neuen und 16 gelöschten Zeilen

Datei anzeigen

@ -236,18 +236,18 @@ public class WorldEditPlugin extends JavaPlugin {
// datapacks aren't loaded until just before the world is, and bukkit has no event for this // datapacks aren't loaded until just before the world is, and bukkit has no event for this
// so the earliest we can do this is in WorldInit // so the earliest we can do this is in WorldInit
setupTags(); setupTags();
setupBiomes(); // FAWE - load biomes later setupBiomes(); // FAWE - load biomes later. Initialize biomes twice to allow for the registry to be present for
// plugins requiring WE biomes during startup, as well as allowing custom biomes loaded later on to be present in WE.
WorldEdit.getInstance().getEventBus().post(new PlatformReadyEvent(platform)); WorldEdit.getInstance().getEventBus().post(new PlatformReadyEvent(platform));
} }
@SuppressWarnings({"deprecation", "unchecked"}) @SuppressWarnings({"deprecation", "unchecked"})
private void initializeRegistries() { private void initializeRegistries() {
/* // FAWE start - move Biomes to their own method // FAWE start - move Biomes to their own method. Initialize biomes twice to allow for the registry to be present for
for (Biome biome : Biome.values()) { // plugins requiring WE biomes during startup, as well as allowing custom biomes loaded later on to be present in WE.
String lowerCaseBiomeName = biome.name().toLowerCase(Locale.ROOT); setupBiomes();
BiomeType.REGISTRY.register("minecraft:" + lowerCaseBiomeName, new BiomeType("minecraft:" + lowerCaseBiomeName));
}
// FAWE end // FAWE end
/*
// Block & Item // Block & Item
for (Material material : Material.values()) { for (Material material : Material.values()) {
@ -311,14 +311,11 @@ public class WorldEditPlugin extends JavaPlugin {
// FAWE start // FAWE start
private void setupBiomes() { private void setupBiomes() {
if (this.adapter.value().isPresent()) { if (this.adapter.value().isPresent()) {
// We don't know which world is the one with the data packs // Biomes are stored globally in the server. Registries are not kept per-world in Minecraft.
// so we just loop over them. Doesn't hurt // The WorldServer get-registries method simply delegates to the MinecraftServer method.
for (org.bukkit.World world : Bukkit.getWorlds()) { for (final NamespacedKey biome : ((BukkitImplAdapter<?>) adapter.value().get()).getRegisteredBiomes()) {
// cast is needed, thanks to raw types <3 if (BiomeType.REGISTRY.get(biome.toString()) == null) { // only register once
for (final NamespacedKey biome : ((BukkitImplAdapter<?>) adapter.value().get()).getRegisteredBiomes(world)) { BiomeType.REGISTRY.register(biome.toString(), new BiomeType(biome.toString()));
if (BiomeType.REGISTRY.get(biome.toString()) == null) { // only register once
BiomeType.REGISTRY.register(biome.toString(), new BiomeType(biome.toString()));
}
} }
} }
} else { } else {

Datei anzeigen

@ -311,10 +311,9 @@ public interface BukkitImplAdapter<T> extends IBukkitAdapter {
/** /**
* Returns an iterable of all biomes known to the server. * Returns an iterable of all biomes known to the server.
* *
* @param world the world to load the registered biomes from.
* @return all biomes known to the server. * @return all biomes known to the server.
*/ */
default Iterable<NamespacedKey> getRegisteredBiomes(World world) { default Iterable<NamespacedKey> getRegisteredBiomes() {
return Arrays.stream(Biome.values()) return Arrays.stream(Biome.values())
.map(Keyed::getKey) .map(Keyed::getKey)
.collect(Collectors.toList()); .collect(Collectors.toList());