mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-10-26 14:00:14 +00:00
use registerhelper to register biomes
This commit is contained in:
1 parent
e1656bac20
commit
7c2982aa0a
5 files changed
+21
-18
No files matched your search
@@ -68,7 +68,7 @@ public class ForgeEntryPoint {
|
|||||||
@SubscribeEvent(priority = EventPriority.LOWEST)
|
@SubscribeEvent(priority = EventPriority.LOWEST)
|
||||||
public void registerBiomes(RegisterEvent event) {
|
public void registerBiomes(RegisterEvent event) {
|
||||||
event.register(Keys.BLOCKS, helper -> sanityCheck.progress(RegistryStep.BLOCK, () -> logger.debug("Block registration detected.")));
|
event.register(Keys.BLOCKS, helper -> sanityCheck.progress(RegistryStep.BLOCK, () -> logger.debug("Block registration detected.")));
|
||||||
event.register(Keys.BIOMES, helper -> sanityCheck.progress(RegistryStep.BIOME, LifecycleUtil::initialize));
|
event.register(Keys.BIOMES, helper -> sanityCheck.progress(RegistryStep.BIOME, () -> LifecycleUtil.initialize(helper)));
|
||||||
event.register(Registry.WORLD_PRESET_KEY, helper -> sanityCheck.progress(RegistryStep.WORLD_TYPE, () -> LifecycleUtil.registerWorldTypes(helper)));
|
event.register(Registry.WORLD_PRESET_KEY, helper -> sanityCheck.progress(RegistryStep.WORLD_TYPE, () -> LifecycleUtil.registerWorldTypes(helper)));
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -83,7 +83,7 @@ public class PlatformImpl extends AbstractPlatform {
|
|||||||
LOGGER.warn("Failed to execute reload", throwable);
|
LOGGER.warn("Failed to execute reload", throwable);
|
||||||
return null;
|
return null;
|
||||||
}).join();
|
}).join();
|
||||||
BiomeUtil.registerBiomes();
|
//BiomeUtil.registerBiomes();
|
||||||
server.getWorlds().forEach(world -> {
|
server.getWorlds().forEach(world -> {
|
||||||
if(world.getChunkManager().getChunkGenerator() instanceof FabricChunkGeneratorWrapper chunkGeneratorWrapper) {
|
if(world.getChunkManager().getChunkGenerator() instanceof FabricChunkGeneratorWrapper chunkGeneratorWrapper) {
|
||||||
getConfigRegistry().get(chunkGeneratorWrapper.getPack().getRegistryKey()).ifPresent(pack -> {
|
getConfigRegistry().get(chunkGeneratorWrapper.getPack().getRegistryKey()).ifPresent(pack -> {
|
||||||
|
|||||||
@@ -16,6 +16,8 @@ import net.minecraft.world.biome.Biome.Builder;
|
|||||||
import net.minecraft.world.biome.BiomeEffects;
|
import net.minecraft.world.biome.BiomeEffects;
|
||||||
import net.minecraft.world.biome.GenerationSettings;
|
import net.minecraft.world.biome.GenerationSettings;
|
||||||
import net.minecraft.world.gen.feature.ConfiguredFeature;
|
import net.minecraft.world.gen.feature.ConfiguredFeature;
|
||||||
|
import net.minecraftforge.registries.ForgeRegistries;
|
||||||
|
import net.minecraftforge.registries.RegisterEvent.RegisterHelper;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
@@ -37,11 +39,11 @@ public final class BiomeUtil {
|
|||||||
.toLowerCase() + "/" + biomeID.getNamespace().toLowerCase(Locale.ROOT) + "/" + biomeID.getID().toLowerCase(Locale.ROOT);
|
.toLowerCase() + "/" + biomeID.getNamespace().toLowerCase(Locale.ROOT) + "/" + biomeID.getID().toLowerCase(Locale.ROOT);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void registerBiomes() {
|
public static void registerBiomes(RegisterHelper<net.minecraft.world.biome.Biome> helper) {
|
||||||
logger.info("Registering biomes...");
|
logger.info("Registering biomes...");
|
||||||
ForgeEntryPoint.getPlatform().getConfigRegistry().forEach(pack -> { // Register all Terra biomes.
|
ForgeEntryPoint.getPlatform().getConfigRegistry().forEach(pack -> { // Register all Terra biomes.
|
||||||
pack.getCheckedRegistry(Biome.class)
|
pack.getCheckedRegistry(Biome.class)
|
||||||
.forEach((id, biome) -> registerBiome(biome, pack, id));
|
.forEach((id, biome) -> registerBiome(biome, pack, id, helper));
|
||||||
});
|
});
|
||||||
registerFlora(BuiltinRegistries.BIOME);
|
registerFlora(BuiltinRegistries.BIOME);
|
||||||
logger.info("Terra biomes registered.");
|
logger.info("Terra biomes registered.");
|
||||||
@@ -54,27 +56,22 @@ public final class BiomeUtil {
|
|||||||
* @param pack The ConfigPack this biome belongs to.
|
* @param pack The ConfigPack this biome belongs to.
|
||||||
*/
|
*/
|
||||||
private static void registerBiome(Biome biome, ConfigPack pack,
|
private static void registerBiome(Biome biome, ConfigPack pack,
|
||||||
com.dfsek.terra.api.registry.key.RegistryKey id) {
|
com.dfsek.terra.api.registry.key.RegistryKey id, RegisterHelper<net.minecraft.world.biome.Biome> helper) {
|
||||||
Registry<net.minecraft.world.biome.Biome> registry = BuiltinRegistries.BIOME;
|
RegistryKey<net.minecraft.world.biome.Biome> vanilla = ((ProtoPlatformBiome) biome.getPlatformBiome()).get(ForgeRegistries.BIOMES);
|
||||||
RegistryKey<net.minecraft.world.biome.Biome> vanilla = ((ProtoPlatformBiome) biome.getPlatformBiome()).get(registry);
|
|
||||||
|
|
||||||
|
|
||||||
if(pack.getContext().get(PreLoadCompatibilityOptions.class).useVanillaBiomes()) {
|
if(pack.getContext().get(PreLoadCompatibilityOptions.class).useVanillaBiomes()) {
|
||||||
((ProtoPlatformBiome) biome.getPlatformBiome()).setDelegate(vanilla);
|
((ProtoPlatformBiome) biome.getPlatformBiome()).setDelegate(vanilla);
|
||||||
} else {
|
} else {
|
||||||
net.minecraft.world.biome.Biome minecraftBiome = createBiome(biome, registry.get(vanilla));
|
net.minecraft.world.biome.Biome minecraftBiome = createBiome(biome, ForgeRegistries.BIOMES.getDelegateOrThrow(vanilla).value());
|
||||||
|
|
||||||
Identifier identifier = new Identifier("terra", createBiomeID(pack, id));
|
Identifier identifier = new Identifier("terra", createBiomeID(pack, id));
|
||||||
|
|
||||||
if(registry.containsId(identifier)) {
|
if(ForgeRegistries.BIOMES.containsKey(identifier)) {
|
||||||
((ProtoPlatformBiome) biome.getPlatformBiome()).setDelegate(FabricUtil.getEntry(registry, identifier)
|
((ProtoPlatformBiome) biome.getPlatformBiome()).setDelegate(ForgeRegistries.BIOMES.getHolder(identifier).orElseThrow().getKey().orElseThrow());
|
||||||
.orElseThrow()
|
|
||||||
.getKey()
|
|
||||||
.orElseThrow());
|
|
||||||
} else {
|
} else {
|
||||||
((ProtoPlatformBiome) biome.getPlatformBiome()).setDelegate(BuiltinRegistries.add(registry,
|
helper.register(registerKey(identifier).getValue(), minecraftBiome);
|
||||||
registerKey(identifier).getValue(),
|
((ProtoPlatformBiome) biome.getPlatformBiome()).setDelegate(ForgeRegistries.BIOMES.getHolder(identifier).orElseThrow().getKey().orElseThrow());
|
||||||
minecraftBiome).getKey().orElseThrow());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TERRA_BIOME_MAP.computeIfAbsent(vanilla.getValue(), i -> new ArrayList<>()).add(identifier);
|
TERRA_BIOME_MAP.computeIfAbsent(vanilla.getValue(), i -> new ArrayList<>()).add(identifier);
|
||||||
|
|||||||
@@ -35,10 +35,10 @@ public class LifecycleUtil {
|
|||||||
private static final Logger LOGGER = LoggerFactory.getLogger(LifecycleUtil.class);
|
private static final Logger LOGGER = LoggerFactory.getLogger(LifecycleUtil.class);
|
||||||
|
|
||||||
private static final List<Identifier> PRESETS = new ArrayList<>();
|
private static final List<Identifier> PRESETS = new ArrayList<>();
|
||||||
public static void initialize() {
|
public static void initialize(RegisterHelper<Biome> helper) {
|
||||||
ForgeEntryPoint.getPlatform().getEventManager().callEvent(
|
ForgeEntryPoint.getPlatform().getEventManager().callEvent(
|
||||||
new PlatformInitializationEvent());
|
new PlatformInitializationEvent());
|
||||||
BiomeUtil.registerBiomes();
|
BiomeUtil.registerBiomes(helper);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void registerWorldTypes(RegisterHelper<WorldPreset> helper) {
|
public static void registerWorldTypes(RegisterHelper<WorldPreset> helper) {
|
||||||
|
|||||||
@@ -26,6 +26,8 @@ import java.util.Objects;
|
|||||||
|
|
||||||
import com.dfsek.terra.api.world.biome.PlatformBiome;
|
import com.dfsek.terra.api.world.biome.PlatformBiome;
|
||||||
|
|
||||||
|
import net.minecraftforge.registries.IForgeRegistry;
|
||||||
|
|
||||||
|
|
||||||
public class ProtoPlatformBiome implements PlatformBiome {
|
public class ProtoPlatformBiome implements PlatformBiome {
|
||||||
private final Identifier identifier;
|
private final Identifier identifier;
|
||||||
@@ -40,6 +42,10 @@ public class ProtoPlatformBiome implements PlatformBiome {
|
|||||||
return FabricUtil.getEntry(registry, identifier).orElseThrow().getKey().orElseThrow();
|
return FabricUtil.getEntry(registry, identifier).orElseThrow().getKey().orElseThrow();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public RegistryKey<Biome> get(IForgeRegistry<Biome> registry) {
|
||||||
|
return registry.getHolder(identifier).orElseThrow().getKey().orElseThrow();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object getHandle() {
|
public Object getHandle() {
|
||||||
return identifier;
|
return identifier;
|
||||||
|
|||||||
Reference in new issue
Block a user