Skip to content

Commit

Permalink
Revert "Use Bukkit Registry API where possible (#2573)"
Browse files Browse the repository at this point in the history
This reverts commit f260e19.
  • Loading branch information
SirYwell committed Nov 11, 2024
1 parent 1904f74 commit 357f823
Showing 1 changed file with 51 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,9 @@
import org.bstats.charts.SimplePie;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.Registry;
import org.bukkit.NamespacedKey;
import org.bukkit.Tag;
import org.bukkit.block.Biome;
import org.bukkit.command.BlockCommandSender;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
Expand All @@ -88,6 +89,7 @@
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.List;
import java.util.Locale;
import java.util.Optional;

import static com.google.common.base.Preconditions.checkNotNull;
Expand Down Expand Up @@ -248,23 +250,21 @@ private void setupWorldData() {
// 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
setupTags();
setupBiomes(false); // 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));
}

@SuppressWarnings({"deprecation", "unchecked"})
private void initializeRegistries() {
// Biome
Registry.BIOME.forEach(biome -> {
if (!biome.name().equals("CUSTOM")) {
String key = biome.getKey().toString();
BiomeType.REGISTRY.register(key, new BiomeType(key));
}
});
// FAWE start - move Biomes to their own method. 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.
setupBiomes(true);
// FAWE end
/*
// Block & Item
Registry.MATERIAL.forEach(material -> {
for (Material material : Material.values()) {
if (material.isBlock() && !material.isLegacy()) {
BlockType.REGISTRY.register(material.getKey().toString(), new BlockType(material.getKey().toString(), blockState -> {
// TODO Use something way less hacky than this.
Expand All @@ -291,14 +291,17 @@ private void initializeRegistries() {
if (material.isItem() && !material.isLegacy()) {
ItemType.REGISTRY.register(material.getKey().toString(), new ItemType(material.getKey().toString()));
}
});
*/
// Entity
Registry.ENTITY_TYPE.forEach(entityType -> {
String key = entityType.getKey().toString();
EntityType.REGISTRY.register(key, new EntityType(key));
});
}
*/

// Entity
for (org.bukkit.entity.EntityType entityType : org.bukkit.entity.EntityType.values()) {
String mcid = entityType.getName();
if (mcid != null) {
String lowerCaseMcId = mcid.toLowerCase(Locale.ROOT);
EntityType.REGISTRY.register("minecraft:" + lowerCaseMcId, new EntityType("minecraft:" + lowerCaseMcId));
}
}
// ... :|
GameModes.get("");
WeatherTypes.get("");
Expand All @@ -319,6 +322,38 @@ private void setupTags() {
}
}

// FAWE start
private void setupBiomes(boolean expectFail) {
if (this.adapter.value().isPresent()) {
// Biomes are stored globally in the server. Registries are not kept per-world in Minecraft.
// The WorldServer get-registries method simply delegates to the MinecraftServer method.
for (final NamespacedKey biome : ((BukkitImplAdapter<?>) adapter.value().get()).getRegisteredBiomes()) {
BiomeType biomeType;
if ((biomeType = BiomeType.REGISTRY.get(biome.toString())) == null) { // only register once
biomeType = new BiomeType(biome.toString());
BiomeType.REGISTRY.register(biome.toString(), biomeType);
}
biomeType.setLegacyId(adapter.value().get().getInternalBiomeId(biomeType));
}
} else {
if (!expectFail) {
LOGGER.warn("Failed to load biomes via adapter (not present). Will load via bukkit");
}
for (Biome biome : Biome.values()) {
// Custom is bad
if (biome.name().equals("CUSTOM")) {
continue;
}
String lowerCaseBiome = biome.getKey().toString().toLowerCase(Locale.ROOT);
// only register once
if (BiomeType.REGISTRY.get(lowerCaseBiome) == null) {
BiomeType.REGISTRY.register(lowerCaseBiome, new BiomeType(lowerCaseBiome));
}
}
}
}
// FAWE end

private void loadAdapter() {
WorldEdit worldEdit = WorldEdit.getInstance();

Expand Down

0 comments on commit 357f823

Please sign in to comment.