mirror of
https://github.com/Sollace/Unicopia.git
synced 2024-11-27 15:17:59 +01:00
Fix compatibilty with HDSkins
This commit is contained in:
parent
cda7ec1d9e
commit
d83a3b0239
4 changed files with 88 additions and 16 deletions
|
@ -32,7 +32,6 @@ import net.minecraft.registry.Registry;
|
|||
import net.minecraft.registry.RegistryBuilder;
|
||||
import net.minecraft.registry.RegistryKeys;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.world.biome.OverworldBiomeCreator;
|
||||
|
||||
public class Datagen implements DataGeneratorEntrypoint {
|
||||
public static final Logger LOGGER = LogManager.getLogger();
|
||||
|
@ -73,11 +72,7 @@ public class Datagen implements DataGeneratorEntrypoint {
|
|||
|
||||
@Override
|
||||
public void buildRegistry(RegistryBuilder builder) {
|
||||
builder.addRegistry(RegistryKeys.BIOME, registerable -> {
|
||||
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.BIOME, UWorldGen.REGISTRY);
|
||||
builder.addRegistry(RegistryKeys.DAMAGE_TYPE, UDamageTypes.REGISTRY);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,7 +8,7 @@ import net.minecraft.registry.RegistryKey;
|
|||
import net.minecraft.registry.RegistryKeys;
|
||||
|
||||
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> ALICORN_AMULET = register("alicorn_amulet");
|
||||
|
|
|
@ -1,30 +1,42 @@
|
|||
package com.minelittlepony.unicopia.server.world;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import com.minelittlepony.unicopia.Unicopia;
|
||||
import com.minelittlepony.unicopia.block.ShellsBlock;
|
||||
import com.minelittlepony.unicopia.block.UBlocks;
|
||||
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.BiomeSelectors;
|
||||
import net.minecraft.block.BlockState;
|
||||
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.Registry;
|
||||
import net.minecraft.registry.RegistryKey;
|
||||
import net.minecraft.registry.RegistryKeys;
|
||||
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.math.Direction;
|
||||
import net.minecraft.util.math.Vec3i;
|
||||
import net.minecraft.util.math.intprovider.UniformIntProvider;
|
||||
import net.minecraft.world.biome.Biome;
|
||||
import net.minecraft.world.biome.BiomeEffects;
|
||||
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.blockpredicate.BlockPredicate;
|
||||
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.PlacedFeature;
|
||||
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;
|
||||
|
||||
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());
|
||||
RegistryKey<PlacedFeature> PINEAPPLE_PLANT_PLACED_FEATURE = FeatureRegistry.registerPlaceableFeature(Unicopia.id("pineapple_plant"), PINEAPPLE_PLANT_FEATURE, PineapplePlantFeature.Config.INSTANCE, List.of(
|
||||
RarityFilterPlacementModifier.of(100),
|
||||
|
@ -69,7 +83,50 @@ public interface UWorldGen {
|
|||
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() {
|
||||
BiomeModifications.addFeature(BiomeSelectors.tag(BiomeTags.IS_JUNGLE), GenerationStep.Feature.VEGETAL_DECORATION, PINEAPPLE_PLANT_PLACED_FEATURE);
|
||||
|
|
|
@ -2,44 +2,64 @@ package com.minelittlepony.unicopia.util.registry;
|
|||
|
||||
import java.util.HashMap;
|
||||
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.minecraft.registry.Registerable;
|
||||
import net.minecraft.registry.Registry;
|
||||
import net.minecraft.registry.RegistryBuilder;
|
||||
import net.minecraft.registry.RegistryEntryLookup;
|
||||
import net.minecraft.registry.RegistryKey;
|
||||
import net.minecraft.registry.RegistryKeys;
|
||||
import net.minecraft.util.Identifier;
|
||||
|
||||
public class DynamicRegistry<T> implements RegistryBuilder.BootstrapFunction<T> {
|
||||
private final RegistryKey<Registry<T>> registry;
|
||||
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.valueFactory = valueFactory;
|
||||
|
||||
DynamicRegistrySetupCallback.EVENT.register(registries -> {
|
||||
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
|
||||
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) {
|
||||
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();
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue