mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-04-23 00:29:51 +00:00
add vanilla biomes option on fabric
This commit is contained in:
@@ -60,25 +60,13 @@ public final class FabricAddon implements BaseAddon {
|
|||||||
terraFabricPlugin.getEventManager()
|
terraFabricPlugin.getEventManager()
|
||||||
.getHandler(FunctionalEventHandler.class)
|
.getHandler(FunctionalEventHandler.class)
|
||||||
.register(this, ConfigPackPreLoadEvent.class)
|
.register(this, ConfigPackPreLoadEvent.class)
|
||||||
.then(event -> {
|
.then(event -> event.getPack().getContext().put(event.loadTemplate(new PreLoadCompatibilityOptions())))
|
||||||
try {
|
|
||||||
event.getPack().getContext().put(event.loadTemplate(new PreLoadCompatibilityOptions()));
|
|
||||||
} catch(ConfigException e) {
|
|
||||||
logger.error("Error loading config template", e);
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.global();
|
.global();
|
||||||
|
|
||||||
terraFabricPlugin.getEventManager()
|
terraFabricPlugin.getEventManager()
|
||||||
.getHandler(FunctionalEventHandler.class)
|
.getHandler(FunctionalEventHandler.class)
|
||||||
.register(this, ConfigPackPostLoadEvent.class)
|
.register(this, ConfigPackPostLoadEvent.class)
|
||||||
.then(event -> {
|
.then(event -> event.getPack().getContext().put(event.loadTemplate(new PostLoadCompatibilityOptions())))
|
||||||
try {
|
|
||||||
event.getPack().getContext().put(event.loadTemplate(new PostLoadCompatibilityOptions()));
|
|
||||||
} catch(ConfigException e) {
|
|
||||||
logger.error("Error loading config template", e);
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.priority(100)
|
.priority(100)
|
||||||
.global();
|
.global();
|
||||||
|
|
||||||
|
|||||||
@@ -31,5 +31,11 @@ import java.util.Set;
|
|||||||
|
|
||||||
@SuppressWarnings("FieldMayBeFinal")
|
@SuppressWarnings("FieldMayBeFinal")
|
||||||
public class PreLoadCompatibilityOptions implements ConfigTemplate, Properties {
|
public class PreLoadCompatibilityOptions implements ConfigTemplate, Properties {
|
||||||
|
@Value("fabric.use-vanilla-biomes")
|
||||||
|
@Default
|
||||||
|
private boolean vanillaBiomes = false;
|
||||||
|
|
||||||
|
public boolean useVanillaBiomes() {
|
||||||
|
return vanillaBiomes;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,6 +19,8 @@ package com.dfsek.terra.fabric.util;
|
|||||||
|
|
||||||
import com.dfsek.terra.fabric.config.BiomeColors;
|
import com.dfsek.terra.fabric.config.BiomeColors;
|
||||||
|
|
||||||
|
import com.dfsek.terra.fabric.config.PreLoadCompatibilityOptions;
|
||||||
|
|
||||||
import com.mojang.serialization.Lifecycle;
|
import com.mojang.serialization.Lifecycle;
|
||||||
import net.minecraft.block.entity.LootableContainerBlockEntity;
|
import net.minecraft.block.entity.LootableContainerBlockEntity;
|
||||||
import net.minecraft.block.entity.MobSpawnerBlockEntity;
|
import net.minecraft.block.entity.MobSpawnerBlockEntity;
|
||||||
@@ -73,6 +75,26 @@ public final class FabricUtil {
|
|||||||
Registry<net.minecraft.world.biome.Biome> biomeRegistry = registryManager.get(Registry.BIOME_KEY);
|
Registry<net.minecraft.world.biome.Biome> biomeRegistry = registryManager.get(Registry.BIOME_KEY);
|
||||||
net.minecraft.world.biome.Biome vanilla = ((ProtoPlatformBiome) biome.getPlatformBiome()).get(biomeRegistry);
|
net.minecraft.world.biome.Biome vanilla = ((ProtoPlatformBiome) biome.getPlatformBiome()).get(biomeRegistry);
|
||||||
|
|
||||||
|
|
||||||
|
if(pack.getContext().get(PreLoadCompatibilityOptions.class).useVanillaBiomes()) {
|
||||||
|
((ProtoPlatformBiome) biome.getPlatformBiome()).setDelegate(vanilla);
|
||||||
|
} else {
|
||||||
|
net.minecraft.world.biome.Biome minecraftBiome = createBiome(biome, vanilla);
|
||||||
|
|
||||||
|
Identifier identifier = new Identifier("terra", FabricUtil.createBiomeID(pack, id));
|
||||||
|
|
||||||
|
if(biomeRegistry.containsId(identifier)) {
|
||||||
|
((ProtoPlatformBiome) biome.getPlatformBiome()).setDelegate(biomeRegistry.get(identifier));
|
||||||
|
} else {
|
||||||
|
Registry.register(biomeRegistry, identifier, minecraftBiome);
|
||||||
|
((ProtoPlatformBiome) biome.getPlatformBiome()).setDelegate(minecraftBiome);
|
||||||
|
terraVanillaBiomes.computeIfAbsent(biomeRegistry.getKey(vanilla).orElseThrow(), b -> new ArrayList<>()).add(
|
||||||
|
biomeRegistry.getKey(minecraftBiome).orElseThrow());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static net.minecraft.world.biome.Biome createBiome(Biome biome, net.minecraft.world.biome.Biome vanilla) {
|
||||||
GenerationSettings.Builder generationSettings = new GenerationSettings.Builder();
|
GenerationSettings.Builder generationSettings = new GenerationSettings.Builder();
|
||||||
|
|
||||||
BiomeEffectsAccessor accessor = (BiomeEffectsAccessor) vanilla.getEffects();
|
BiomeEffectsAccessor accessor = (BiomeEffectsAccessor) vanilla.getEffects();
|
||||||
@@ -127,7 +149,7 @@ public final class FabricUtil {
|
|||||||
accessor.getGrassColor().ifPresent(effects::grassColor);
|
accessor.getGrassColor().ifPresent(effects::grassColor);
|
||||||
}
|
}
|
||||||
|
|
||||||
net.minecraft.world.biome.Biome minecraftBiome = new net.minecraft.world.biome.Biome.Builder()
|
return new net.minecraft.world.biome.Biome.Builder()
|
||||||
.precipitation(vanilla.getPrecipitation())
|
.precipitation(vanilla.getPrecipitation())
|
||||||
.category(vanilla.getCategory())
|
.category(vanilla.getCategory())
|
||||||
.temperature(vanilla.getTemperature())
|
.temperature(vanilla.getTemperature())
|
||||||
@@ -136,17 +158,6 @@ public final class FabricUtil {
|
|||||||
.spawnSettings(vanilla.getSpawnSettings())
|
.spawnSettings(vanilla.getSpawnSettings())
|
||||||
.generationSettings(generationSettings.build())
|
.generationSettings(generationSettings.build())
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
Identifier identifier = new Identifier("terra", FabricUtil.createBiomeID(pack, id));
|
|
||||||
|
|
||||||
if(biomeRegistry.containsId(identifier)) {
|
|
||||||
((ProtoPlatformBiome) biome.getPlatformBiome()).setDelegate(biomeRegistry.get(identifier));
|
|
||||||
} else {
|
|
||||||
Registry.register(biomeRegistry, identifier, minecraftBiome);
|
|
||||||
((ProtoPlatformBiome) biome.getPlatformBiome()).setDelegate(minecraftBiome);
|
|
||||||
terraVanillaBiomes.computeIfAbsent(biomeRegistry.getKey(vanilla).orElseThrow(), b -> new ArrayList<>()).add(
|
|
||||||
biomeRegistry.getKey(minecraftBiome).orElseThrow());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Map<RegistryKey<net.minecraft.world.biome.Biome>, List<RegistryKey<net.minecraft.world.biome.Biome>>> getTerraVanillaBiomes() {
|
public static Map<RegistryKey<net.minecraft.world.biome.Biome>, List<RegistryKey<net.minecraft.world.biome.Biome>>> getTerraVanillaBiomes() {
|
||||||
|
|||||||
Reference in New Issue
Block a user