mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-02-16 10:30:42 +00:00
dont crash on minecraft:reload
This commit is contained in:
@@ -84,8 +84,7 @@ public final class FabricAddon implements BaseAddon {
|
||||
.register(this, BiomeRegistrationEvent.class)
|
||||
.then(event -> {
|
||||
logger.info("Registering biomes...");
|
||||
|
||||
Registry<net.minecraft.world.biome.Biome> biomeRegistry = event.getRegistryManager().get(Registry.BIOME_KEY);
|
||||
|
||||
terraFabricPlugin.getConfigRegistry().forEach(pack -> { // Register all Terra biomes.
|
||||
pack.getCheckedRegistry(Biome.class)
|
||||
.forEach((id, biome) -> FabricUtil.registerBiome(biome, pack, event.getRegistryManager(), id));
|
||||
|
||||
@@ -19,6 +19,8 @@ package com.dfsek.terra.fabric.generation;
|
||||
|
||||
import com.dfsek.terra.fabric.data.Codecs;
|
||||
|
||||
import com.dfsek.terra.fabric.util.ProtoPlatformBiome;
|
||||
|
||||
import com.mojang.serialization.Codec;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.registry.Registry;
|
||||
@@ -72,11 +74,7 @@ public class TerraBiomeSource extends BiomeSource {
|
||||
|
||||
@Override
|
||||
public net.minecraft.world.biome.Biome getBiome(int biomeX, int biomeY, int biomeZ, MultiNoiseSampler noiseSampler) {
|
||||
Biome biome = pack.getBiomeProvider().getBiome(biomeX << 2, biomeZ << 2, seed);
|
||||
return terraToMinecraft.computeIfAbsent(biome,
|
||||
b -> biomeRegistry
|
||||
.get(new Identifier("terra", FabricUtil
|
||||
.createBiomeID(pack, pack.key(b.getID())))));
|
||||
return ((ProtoPlatformBiome) pack.getBiomeProvider().getBiome(biomeX << 2, biomeZ << 2, seed).getPlatformBiome()).getDelegate();
|
||||
}
|
||||
|
||||
public BiomeProvider getProvider() {
|
||||
|
||||
@@ -38,6 +38,7 @@ import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.OptionalInt;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import com.dfsek.terra.api.block.entity.BlockEntity;
|
||||
@@ -141,26 +142,19 @@ public final class FabricUtil {
|
||||
.generationSettings(generationSettings.build())
|
||||
.build();
|
||||
Identifier identifier = new Identifier("terra", FabricUtil.createBiomeID(pack, id));
|
||||
FabricUtil.registerOrOverwrite(biomeRegistry, Registry.BIOME_KEY, identifier, minecraftBiome);
|
||||
|
||||
terraVanillaBiomes.computeIfAbsent(biomeRegistry.getKey(vanilla).orElseThrow(), b -> new ArrayList<>()).add(
|
||||
biomeRegistry.getKey(minecraftBiome).orElseThrow());
|
||||
|
||||
if(!biomeRegistry.containsId(identifier)) {
|
||||
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() {
|
||||
return terraVanillaBiomes;
|
||||
}
|
||||
|
||||
public static <T> void registerOrOverwrite(Registry<T> registry, RegistryKey<Registry<T>> key, Identifier identifier, T item) {
|
||||
if(registry.containsId(identifier)) {
|
||||
((MutableRegistry<T>) registry).set(registry.getRawId(registry.get(identifier)), RegistryKey.of(key, identifier), item,
|
||||
Lifecycle.stable());
|
||||
} else {
|
||||
Registry.register(registry, identifier, item);
|
||||
}
|
||||
}
|
||||
|
||||
public static BlockEntity createState(WorldAccess worldAccess, BlockPos pos) {
|
||||
net.minecraft.block.entity.BlockEntity entity = worldAccess.getBlockEntity(pos);
|
||||
if(entity instanceof SignBlockEntity) {
|
||||
|
||||
@@ -22,10 +22,14 @@ import net.minecraft.util.registry.Registry;
|
||||
|
||||
import com.dfsek.terra.api.world.biome.PlatformBiome;
|
||||
|
||||
import net.minecraft.world.biome.Biome;
|
||||
|
||||
|
||||
public class ProtoPlatformBiome implements PlatformBiome {
|
||||
private final Identifier identifier;
|
||||
|
||||
private Biome delegate;
|
||||
|
||||
public ProtoPlatformBiome(Identifier identifier) {
|
||||
this.identifier = identifier;
|
||||
}
|
||||
@@ -38,4 +42,12 @@ public class ProtoPlatformBiome implements PlatformBiome {
|
||||
public Object getHandle() {
|
||||
return identifier;
|
||||
}
|
||||
|
||||
public Biome getDelegate() {
|
||||
return delegate;
|
||||
}
|
||||
|
||||
public void setDelegate(Biome delegate) {
|
||||
this.delegate = delegate;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user