Fix compatibilty with HDSkins

This commit is contained in:
Sollace 2024-04-23 17:57:50 +01:00
parent cda7ec1d9e
commit d83a3b0239
No known key found for this signature in database
GPG key ID: E52FACE7B5C773DB
4 changed files with 88 additions and 16 deletions

View file

@ -32,7 +32,6 @@ import net.minecraft.registry.Registry;
import net.minecraft.registry.RegistryBuilder; import net.minecraft.registry.RegistryBuilder;
import net.minecraft.registry.RegistryKeys; import net.minecraft.registry.RegistryKeys;
import net.minecraft.util.Identifier; import net.minecraft.util.Identifier;
import net.minecraft.world.biome.OverworldBiomeCreator;
public class Datagen implements DataGeneratorEntrypoint { public class Datagen implements DataGeneratorEntrypoint {
public static final Logger LOGGER = LogManager.getLogger(); public static final Logger LOGGER = LogManager.getLogger();
@ -73,11 +72,7 @@ public class Datagen implements DataGeneratorEntrypoint {
@Override @Override
public void buildRegistry(RegistryBuilder builder) { public void buildRegistry(RegistryBuilder builder) {
builder.addRegistry(RegistryKeys.BIOME, registerable -> { builder.addRegistry(RegistryKeys.BIOME, UWorldGen.REGISTRY);
final var placedFeatureLookup = registerable.getRegistryLookup(RegistryKeys.PLACED_FEATURE);
final var carverLookup = registerable.getRegistryLookup(RegistryKeys.CONFIGURED_CARVER);
registerable.register(UWorldGen.SWEET_APPLE_ORCHARD, OverworldBiomeCreator.createNormalForest(placedFeatureLookup, carverLookup, false, false, false));
});
builder.addRegistry(RegistryKeys.DAMAGE_TYPE, UDamageTypes.REGISTRY); builder.addRegistry(RegistryKeys.DAMAGE_TYPE, UDamageTypes.REGISTRY);
} }
} }

View file

@ -8,7 +8,7 @@ import net.minecraft.registry.RegistryKey;
import net.minecraft.registry.RegistryKeys; import net.minecraft.registry.RegistryKeys;
public interface UDamageTypes { public interface UDamageTypes {
DynamicRegistry<DamageType> REGISTRY = new DynamicRegistry<>(RegistryKeys.DAMAGE_TYPE, key -> new DamageType(key.getValue().getNamespace() + "." + key.getValue().getPath(), 0)); DynamicRegistry<DamageType> REGISTRY = new DynamicRegistry<>(RegistryKeys.DAMAGE_TYPE, (lookup, key) -> new DamageType(key.getValue().getNamespace() + "." + key.getValue().getPath(), 0));
RegistryKey<DamageType> EXHAUSTION = register("magical_exhaustion"); RegistryKey<DamageType> EXHAUSTION = register("magical_exhaustion");
RegistryKey<DamageType> ALICORN_AMULET = register("alicorn_amulet"); RegistryKey<DamageType> ALICORN_AMULET = register("alicorn_amulet");

View file

@ -1,30 +1,42 @@
package com.minelittlepony.unicopia.server.world; package com.minelittlepony.unicopia.server.world;
import java.util.List; import java.util.List;
import java.util.function.Consumer;
import com.minelittlepony.unicopia.Unicopia; import com.minelittlepony.unicopia.Unicopia;
import com.minelittlepony.unicopia.block.ShellsBlock; import com.minelittlepony.unicopia.block.ShellsBlock;
import com.minelittlepony.unicopia.block.UBlocks; import com.minelittlepony.unicopia.block.UBlocks;
import com.minelittlepony.unicopia.server.world.gen.OverworldBiomeSelectionCallback; import com.minelittlepony.unicopia.server.world.gen.OverworldBiomeSelectionCallback;
import com.minelittlepony.unicopia.util.registry.DynamicRegistry;
import net.fabricmc.fabric.api.biome.v1.BiomeModifications; import net.fabricmc.fabric.api.biome.v1.BiomeModifications;
import net.fabricmc.fabric.api.biome.v1.BiomeSelectors; import net.fabricmc.fabric.api.biome.v1.BiomeSelectors;
import net.minecraft.block.BlockState; import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks; import net.minecraft.block.Blocks;
import net.minecraft.client.sound.MusicType;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.SpawnGroup;
import net.minecraft.registry.Registries; import net.minecraft.registry.Registries;
import net.minecraft.registry.Registry; import net.minecraft.registry.Registry;
import net.minecraft.registry.RegistryKey; import net.minecraft.registry.RegistryKey;
import net.minecraft.registry.RegistryKeys; import net.minecraft.registry.RegistryKeys;
import net.minecraft.registry.tag.BiomeTags; import net.minecraft.registry.tag.BiomeTags;
import net.minecraft.sound.BiomeMoodSound;
import net.minecraft.sound.SoundEvents;
import net.minecraft.util.collection.DataPool; import net.minecraft.util.collection.DataPool;
import net.minecraft.util.math.Direction; import net.minecraft.util.math.Direction;
import net.minecraft.util.math.Vec3i; import net.minecraft.util.math.Vec3i;
import net.minecraft.util.math.intprovider.UniformIntProvider; import net.minecraft.util.math.intprovider.UniformIntProvider;
import net.minecraft.world.biome.Biome; import net.minecraft.world.biome.Biome;
import net.minecraft.world.biome.BiomeEffects;
import net.minecraft.world.biome.BiomeKeys; import net.minecraft.world.biome.BiomeKeys;
import net.minecraft.world.biome.GenerationSettings;
import net.minecraft.world.biome.OverworldBiomeCreator;
import net.minecraft.world.biome.SpawnSettings;
import net.minecraft.world.gen.GenerationStep; import net.minecraft.world.gen.GenerationStep;
import net.minecraft.world.gen.blockpredicate.BlockPredicate; import net.minecraft.world.gen.blockpredicate.BlockPredicate;
import net.minecraft.world.gen.feature.ConfiguredFeatures; import net.minecraft.world.gen.feature.ConfiguredFeatures;
import net.minecraft.world.gen.feature.DefaultBiomeFeatures;
import net.minecraft.world.gen.feature.Feature; import net.minecraft.world.gen.feature.Feature;
import net.minecraft.world.gen.feature.PlacedFeature; import net.minecraft.world.gen.feature.PlacedFeature;
import net.minecraft.world.gen.feature.PlacedFeatures; import net.minecraft.world.gen.feature.PlacedFeatures;
@ -38,6 +50,8 @@ import net.minecraft.world.gen.stateprovider.RandomizedIntBlockStateProvider;
import net.minecraft.world.gen.stateprovider.WeightedBlockStateProvider; import net.minecraft.world.gen.stateprovider.WeightedBlockStateProvider;
public interface UWorldGen { public interface UWorldGen {
DynamicRegistry<Biome> REGISTRY = new DynamicRegistry<>(RegistryKeys.BIOME, (lookup, key) -> { throw new RuntimeException("Registerable is required"); });
PineapplePlantFeature PINEAPPLE_PLANT_FEATURE = Registry.register(Registries.FEATURE, Unicopia.id("pineapple_plant"), new PineapplePlantFeature()); PineapplePlantFeature PINEAPPLE_PLANT_FEATURE = Registry.register(Registries.FEATURE, Unicopia.id("pineapple_plant"), new PineapplePlantFeature());
RegistryKey<PlacedFeature> PINEAPPLE_PLANT_PLACED_FEATURE = FeatureRegistry.registerPlaceableFeature(Unicopia.id("pineapple_plant"), PINEAPPLE_PLANT_FEATURE, PineapplePlantFeature.Config.INSTANCE, List.of( RegistryKey<PlacedFeature> PINEAPPLE_PLANT_PLACED_FEATURE = FeatureRegistry.registerPlaceableFeature(Unicopia.id("pineapple_plant"), PINEAPPLE_PLANT_FEATURE, PineapplePlantFeature.Config.INSTANCE, List.of(
RarityFilterPlacementModifier.of(100), RarityFilterPlacementModifier.of(100),
@ -69,7 +83,50 @@ public interface UWorldGen {
BiomePlacementModifier.of() BiomePlacementModifier.of()
)); ));
RegistryKey<Biome> SWEET_APPLE_ORCHARD = RegistryKey.of(RegistryKeys.BIOME, Unicopia.id("sweet_apple_orchard")); RegistryKey<Biome> SWEET_APPLE_ORCHARD = REGISTRY.register(Unicopia.id("sweet_apple_orchard"), (lookup, key) -> {
return new Biome.Builder()
.precipitation(true)
.temperature(0.8F)
.downfall(0.8F)
.effects(new BiomeEffects.Builder()
.waterColor(4159204)
.waterFogColor(329011)
.fogColor(12638463)
.skyColor(OverworldBiomeCreator.getSkyColor(0.8F))
.moodSound(BiomeMoodSound.CAVE)
.music(MusicType.createIngameMusic(SoundEvents.MUSIC_OVERWORLD_FOREST))
.build())
.spawnSettings(applyAll(new SpawnSettings.Builder(),
DefaultBiomeFeatures::addFarmAnimals,
DefaultBiomeFeatures::addBatsAndMonsters
).spawn(SpawnGroup.CREATURE, new SpawnSettings.SpawnEntry(EntityType.WOLF, 5, 4, 4))
.build())
.generationSettings(applyAll(new GenerationSettings.LookupBackedBuilder(lookup.getRegistryLookup(RegistryKeys.PLACED_FEATURE), lookup.getRegistryLookup(RegistryKeys.CONFIGURED_CARVER)),
DefaultBiomeFeatures::addLandCarvers,
DefaultBiomeFeatures::addAmethystGeodes,
DefaultBiomeFeatures::addDungeons,
DefaultBiomeFeatures::addMineables,
DefaultBiomeFeatures::addSprings,
DefaultBiomeFeatures::addFrozenTopLayer,
DefaultBiomeFeatures::addDefaultOres,
DefaultBiomeFeatures::addDefaultDisks,
DefaultBiomeFeatures::addForestFlowers,
DefaultBiomeFeatures::addDefaultFlowers,
DefaultBiomeFeatures::addForestGrass,
DefaultBiomeFeatures::addDefaultMushrooms,
DefaultBiomeFeatures::addDefaultVegetation
)
.build())
.build();
});
@SafeVarargs
static <T> T applyAll(T t, Consumer<T> ...consumers) {
for (Consumer<T> consumer : consumers) {
consumer.accept(t);
}
return t;
}
static void bootstrap() { static void bootstrap() {
BiomeModifications.addFeature(BiomeSelectors.tag(BiomeTags.IS_JUNGLE), GenerationStep.Feature.VEGETAL_DECORATION, PINEAPPLE_PLANT_PLACED_FEATURE); BiomeModifications.addFeature(BiomeSelectors.tag(BiomeTags.IS_JUNGLE), GenerationStep.Feature.VEGETAL_DECORATION, PINEAPPLE_PLANT_PLACED_FEATURE);

View file

@ -2,44 +2,64 @@ package com.minelittlepony.unicopia.util.registry;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.function.Function; import java.util.concurrent.atomic.AtomicBoolean;
import net.fabricmc.fabric.api.event.registry.DynamicRegistrySetupCallback; import net.fabricmc.fabric.api.event.registry.DynamicRegistrySetupCallback;
import net.minecraft.registry.Registerable; import net.minecraft.registry.Registerable;
import net.minecraft.registry.Registry; import net.minecraft.registry.Registry;
import net.minecraft.registry.RegistryBuilder; import net.minecraft.registry.RegistryBuilder;
import net.minecraft.registry.RegistryEntryLookup;
import net.minecraft.registry.RegistryKey; import net.minecraft.registry.RegistryKey;
import net.minecraft.registry.RegistryKeys;
import net.minecraft.util.Identifier; import net.minecraft.util.Identifier;
public class DynamicRegistry<T> implements RegistryBuilder.BootstrapFunction<T> { public class DynamicRegistry<T> implements RegistryBuilder.BootstrapFunction<T> {
private final RegistryKey<Registry<T>> registry; private final RegistryKey<Registry<T>> registry;
private final Map<RegistryKey<T>, Entry<T>> keys = new HashMap<>(); private final Map<RegistryKey<T>, Entry<T>> keys = new HashMap<>();
private final Function<RegistryKey<T>, T> valueFactory; private final Registerant<T> valueFactory;
public DynamicRegistry(RegistryKey<Registry<T>> registry, Function<RegistryKey<T>, T> valueFactory) { public DynamicRegistry(RegistryKey<Registry<T>> registry, Registerant<T> valueFactory) {
this.registry = registry; this.registry = registry;
this.valueFactory = valueFactory; this.valueFactory = valueFactory;
DynamicRegistrySetupCallback.EVENT.register(registries -> { DynamicRegistrySetupCallback.EVENT.register(registries -> {
registries.getOptional(registry).ifPresent(r -> { registries.getOptional(registry).ifPresent(r -> {
keys.forEach((key, entry)-> Registry.register(r, key.getValue(), entry.factory().apply(key))); AtomicBoolean added = new AtomicBoolean(false);
registries.registerEntryAdded(RegistryKeys.MULTI_NOISE_BIOME_SOURCE_PARAMETER_LIST, (raw, id, value) -> {
if (added.getAndSet(true)) {
return;
}
final WrapperLookup lookup = registries.asDynamicRegistryManager()::getWrapperOrThrow;
keys.forEach((key, entry) -> {
if (!r.contains(key)) {
Registry.register(r, key, entry.factory().apply(lookup, key));
}
});
});
}); });
}); });
} }
@Override @Override
public void run(Registerable<T> registerable) { public void run(Registerable<T> registerable) {
keys.forEach((key, entry) -> registerable.register(key, entry.factory().apply(key))); final WrapperLookup lookup = registerable::getRegistryLookup;
keys.forEach((key, entry) -> registerable.register(key, entry.factory().apply(lookup, key)));
} }
public RegistryKey<T> register(Identifier id) { public RegistryKey<T> register(Identifier id) {
return register(id, valueFactory); return register(id, valueFactory);
} }
public RegistryKey<T> register(Identifier id, Function<RegistryKey<T>, T> valueFactory) { public RegistryKey<T> register(Identifier id, Registerant<T> valueFactory) {
return keys.computeIfAbsent(RegistryKey.of(registry, id), k -> new Entry<>(k, valueFactory)).key(); return keys.computeIfAbsent(RegistryKey.of(registry, id), k -> new Entry<>(k, valueFactory)).key();
} }
record Entry<T>(RegistryKey<T> key, Function<RegistryKey<T>, T> factory) {} record Entry<T>(RegistryKey<T> key, Registerant<T> factory) {}
public interface Registerant<T> {
T apply(WrapperLookup lookup, RegistryKey<T> key);
}
public interface WrapperLookup {
<S> RegistryEntryLookup<S> getRegistryLookup(RegistryKey<? extends Registry<? extends S>> registryRef);
}
} }