mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-02-16 10:30:42 +00:00
fix tag registration
This commit is contained in:
@@ -20,6 +20,7 @@ package com.dfsek.terra.fabric.generation;
|
||||
import com.mojang.serialization.Codec;
|
||||
import net.minecraft.util.registry.Registry;
|
||||
import net.minecraft.util.registry.RegistryEntry;
|
||||
import net.minecraft.world.biome.Biome;
|
||||
import net.minecraft.world.biome.source.BiomeSource;
|
||||
import net.minecraft.world.biome.source.util.MultiNoiseUtil.MultiNoiseSampler;
|
||||
|
||||
@@ -48,7 +49,7 @@ public class TerraBiomeSource extends BiomeSource {
|
||||
.stream(pack.getBiomeProvider()
|
||||
.getBiomes()
|
||||
.spliterator(), false)
|
||||
.map(b -> ((ProtoPlatformBiome) b.getPlatformBiome()).getDelegate()));
|
||||
.map(b -> biomes.getOrCreateEntry(((ProtoPlatformBiome) b.getPlatformBiome()).getDelegate())));
|
||||
this.biomeRegistry = biomes;
|
||||
this.seed = seed;
|
||||
this.pack = pack;
|
||||
@@ -68,13 +69,11 @@ public class TerraBiomeSource extends BiomeSource {
|
||||
|
||||
@Override
|
||||
public RegistryEntry<net.minecraft.world.biome.Biome> getBiome(int biomeX, int biomeY, int biomeZ, MultiNoiseSampler noiseSampler) {
|
||||
return biomeRegistry.entryOf(((ProtoPlatformBiome) pack
|
||||
return biomeRegistry.getOrCreateEntry(((ProtoPlatformBiome) pack
|
||||
.getBiomeProvider()
|
||||
.getBiome(biomeX << 2, biomeZ << 2, seed)
|
||||
.getPlatformBiome())
|
||||
.getDelegate()
|
||||
.getKey()
|
||||
.orElseThrow());
|
||||
.getDelegate());
|
||||
}
|
||||
|
||||
public BiomeProvider getProvider() {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.dfsek.terra.fabric.mixin.lifecycle;
|
||||
|
||||
import net.minecraft.server.DataPackContents;
|
||||
import net.minecraft.util.registry.BuiltinRegistries;
|
||||
import net.minecraft.util.registry.DynamicRegistryManager;
|
||||
import net.minecraft.util.registry.Registry;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
|
||||
@@ -74,6 +74,7 @@ public final class FabricUtil {
|
||||
private static final Map<Identifier, List<Identifier>>
|
||||
TERRA_BIOME_MAP = new HashMap<>();
|
||||
|
||||
|
||||
/**
|
||||
* Clones a Vanilla biome and injects Terra data to create a Terra-vanilla biome delegate.
|
||||
*
|
||||
@@ -83,23 +84,23 @@ public final class FabricUtil {
|
||||
public static void registerBiome(Biome biome, ConfigPack pack,
|
||||
com.dfsek.terra.api.registry.key.RegistryKey id) {
|
||||
Registry<net.minecraft.world.biome.Biome> registry = BuiltinRegistries.BIOME;
|
||||
RegistryEntry<net.minecraft.world.biome.Biome> vanilla = ((ProtoPlatformBiome) biome.getPlatformBiome()).get(registry);
|
||||
RegistryKey<net.minecraft.world.biome.Biome> vanilla = ((ProtoPlatformBiome) biome.getPlatformBiome()).get(registry);
|
||||
|
||||
|
||||
if(pack.getContext().get(PreLoadCompatibilityOptions.class).useVanillaBiomes()) {
|
||||
((ProtoPlatformBiome) biome.getPlatformBiome()).setDelegate(vanilla);
|
||||
} else {
|
||||
net.minecraft.world.biome.Biome minecraftBiome = createBiome(biome, vanilla.value());
|
||||
net.minecraft.world.biome.Biome minecraftBiome = createBiome(biome, registry.get(vanilla));
|
||||
|
||||
Identifier identifier = new Identifier("terra", FabricUtil.createBiomeID(pack, id));
|
||||
|
||||
if(registry.containsId(identifier)) {
|
||||
((ProtoPlatformBiome) biome.getPlatformBiome()).setDelegate(FabricUtil.getEntry(registry, identifier).orElseThrow());
|
||||
((ProtoPlatformBiome) biome.getPlatformBiome()).setDelegate(FabricUtil.getEntry(registry, identifier).orElseThrow().getKey().orElseThrow());
|
||||
} else {
|
||||
((ProtoPlatformBiome) biome.getPlatformBiome()).setDelegate(BuiltinRegistries.add(registry, registerKey(identifier).getValue(), minecraftBiome));
|
||||
((ProtoPlatformBiome) biome.getPlatformBiome()).setDelegate(BuiltinRegistries.add(registry, registerKey(identifier).getValue(), minecraftBiome).getKey().orElseThrow());
|
||||
}
|
||||
|
||||
TERRA_BIOME_MAP.computeIfAbsent(vanilla.getKey().orElseThrow().getValue(), i -> new ArrayList<>()).add(identifier);
|
||||
TERRA_BIOME_MAP.computeIfAbsent(vanilla.getValue(), i -> new ArrayList<>()).add(identifier);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -120,7 +121,7 @@ public final class FabricUtil {
|
||||
.ifPresentOrElse(vanilla -> terraBiomes.forEach(tb -> getEntry(registry, tb)
|
||||
.ifPresentOrElse(
|
||||
terra -> {
|
||||
logger.debug(vanilla.getKey().orElseThrow().getValue() + " (vanilla for " +
|
||||
logger.info(vanilla.getKey().orElseThrow().getValue() + " (vanilla for " +
|
||||
terra.getKey().orElseThrow().getValue() + ": " +
|
||||
vanilla.streamTags().toList());
|
||||
|
||||
@@ -219,6 +220,6 @@ public final class FabricUtil {
|
||||
public static <T> Optional<RegistryEntry<T>> getEntry(Registry<T> registry, Identifier identifier) {
|
||||
return registry.getOrEmpty(identifier)
|
||||
.flatMap(registry::getKey)
|
||||
.flatMap(registry::getEntry);
|
||||
.map(registry::getOrCreateEntry);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@ package com.dfsek.terra.fabric.util;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.registry.Registry;
|
||||
import net.minecraft.util.registry.RegistryEntry;
|
||||
import net.minecraft.util.registry.RegistryKey;
|
||||
import net.minecraft.world.biome.Biome;
|
||||
|
||||
import java.util.Objects;
|
||||
@@ -30,14 +31,14 @@ import com.dfsek.terra.api.world.biome.PlatformBiome;
|
||||
public class ProtoPlatformBiome implements PlatformBiome {
|
||||
private final Identifier identifier;
|
||||
|
||||
private RegistryEntry<Biome> delegate;
|
||||
private RegistryKey<Biome> delegate;
|
||||
|
||||
public ProtoPlatformBiome(Identifier identifier) {
|
||||
this.identifier = identifier;
|
||||
}
|
||||
|
||||
public RegistryEntry<Biome> get(Registry<net.minecraft.world.biome.Biome> registry) {
|
||||
return FabricUtil.getEntry(registry, identifier).orElseThrow();
|
||||
public RegistryKey<Biome> get(Registry<net.minecraft.world.biome.Biome> registry) {
|
||||
return FabricUtil.getEntry(registry, identifier).orElseThrow().getKey().orElseThrow();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -45,11 +46,11 @@ public class ProtoPlatformBiome implements PlatformBiome {
|
||||
return identifier;
|
||||
}
|
||||
|
||||
public RegistryEntry<Biome> getDelegate() {
|
||||
public RegistryKey<Biome> getDelegate() {
|
||||
return delegate;
|
||||
}
|
||||
|
||||
public void setDelegate(RegistryEntry<Biome> delegate) {
|
||||
public void setDelegate(RegistryKey<Biome> delegate) {
|
||||
this.delegate = Objects.requireNonNull(delegate);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user