Search in sources :

Example 1 with SelectionSpace

use of com.teamabnormals.blueprint.core.util.modification.targeting.SelectionSpace in project blueprint by team-abnormals.

the class AdvancementModificationManager method apply.

@Override
protected void apply(Map<ResourceLocation, JsonElement> map, ResourceManager resourceManager, ProfilerFiller profiler) {
    this.reset();
    SelectionSpace unmodifiedAdvancements = this.getUnmodifiedEntries();
    for (Map.Entry<ResourceLocation, JsonElement> entry : map.entrySet()) {
        ResourceLocation resourcelocation = entry.getKey();
        if (resourcelocation.getPath().startsWith("_"))
            continue;
        try {
            TargetedModifier<Builder, Void, DeserializationContext> targetedAdvancementModifier = TargetedModifier.deserialize(entry.getValue().getAsJsonObject(), "advancement", new DeserializationContext(resourcelocation, this.lootPredicateManager), AdvancementModifiers.REGISTRY, true);
            this.addModifiers(targetedAdvancementModifier.getTargetSelector().getTargetNames(unmodifiedAdvancements), targetedAdvancementModifier.getPriority(), targetedAdvancementModifier.getConfiguredModifiers());
        } catch (IllegalArgumentException | JsonParseException jsonparseexception) {
            Blueprint.LOGGER.error("Parsing error loading Advancement Modifier: {}", resourcelocation, jsonparseexception);
        }
    }
    Blueprint.LOGGER.info("Advancement Modification Manager has assigned {} sets of modifiers", this.size());
}
Also used : SelectionSpace(com.teamabnormals.blueprint.core.util.modification.targeting.SelectionSpace) JsonElement(com.google.gson.JsonElement) ResourceLocation(net.minecraft.resources.ResourceLocation) GsonBuilder(com.google.gson.GsonBuilder) Builder(net.minecraft.advancements.Advancement.Builder) DeserializationContext(net.minecraft.advancements.critereon.DeserializationContext) JsonParseException(com.google.gson.JsonParseException) Map(java.util.Map)

Example 2 with SelectionSpace

use of com.teamabnormals.blueprint.core.util.modification.targeting.SelectionSpace in project blueprint by team-abnormals.

the class BiomeSourceModificationManager method onServerAboutToStart.

@SuppressWarnings("unchecked")
@SubscribeEvent
public static void onServerAboutToStart(ServerAboutToStartEvent event) {
    if (INSTANCE == null)
        return;
    List<BiomeSourceModifier> modifiers = INSTANCE.modifiers;
    if (modifiers.isEmpty())
        return;
    MinecraftServer server = event.getServer();
    WorldGenSettings worldGenSettings = server.getWorldData().worldGenSettings();
    var dimensions = worldGenSettings.dimensions();
    var keySet = dimensions.keySet();
    SelectionSpace selectionSpace = (consumer) -> keySet.forEach(location -> consumer.accept(location, null));
    HashMap<ResourceLocation, ArrayList<BiomeUtil.ModdedBiomeProvider>> map = new HashMap<>();
    for (BiomeSourceModifier modifier : modifiers) {
        BiomeUtil.ModdedBiomeProvider provider = modifier.provider();
        if (provider.getWeight() <= 0)
            return;
        modifier.targetSelector().getTargetNames(selectionSpace).forEach(location -> {
            map.computeIfAbsent(location, __ -> new ArrayList<>()).add(provider);
        });
    }
    long seed = worldGenSettings.seed();
    RegistryAccess registryAccess = server.registryAccess();
    Registry<Biome> biomeRegistry = registryAccess.registryOrThrow(Registry.BIOME_REGISTRY);
    Registry<NormalNoise.NoiseParameters> noiseParametersRegistry = registryAccess.registryOrThrow(Registry.NOISE_REGISTRY);
    Registry<DensityFunction> densityFunctionRegistry = registryAccess.registryOrThrow(Registry.DENSITY_FUNCTION_REGISTRY);
    NoiseSettings defaultNoiseSettings = registryAccess.registryOrThrow(Registry.NOISE_GENERATOR_SETTINGS_REGISTRY).getOrThrow(NoiseGeneratorSettings.OVERWORLD).noiseSettings();
    DensityFunction defaultModdedness = densityFunctionRegistry.getOrThrow(ModdedBiomeSource.DEFAULT_MODDEDNESS);
    for (Map.Entry<ResourceKey<LevelStem>, LevelStem> entry : dimensions.entrySet()) {
        ResourceLocation location = entry.getKey().location();
        ArrayList<BiomeUtil.ModdedBiomeProvider> providersForKey = map.get(location);
        if (providersForKey != null && !providersForKey.isEmpty()) {
            ChunkGenerator chunkGenerator = entry.getValue().generator();
            BiomeSource source = chunkGenerator.getBiomeSource();
            // TODO: Mostly experimental! Works with Terralith, Biomes O' Plenty, and more, but still needs more testing!
            if (!(source instanceof FixedBiomeSource) && !(source instanceof CheckerboardColumnBiomeSource)) {
                boolean legacy = false;
                boolean noiseBased = chunkGenerator instanceof NoiseBasedChunkGenerator;
                NoiseSettings noiseSettings = defaultNoiseSettings;
                if (noiseBased) {
                    try {
                        NoiseGeneratorSettings settings = ((Holder<NoiseGeneratorSettings>) NOISE_GENERATOR_SETTINGS.get(chunkGenerator)).value();
                        if (settings != null) {
                            legacy = settings.useLegacyRandomSource();
                            noiseSettings = settings.noiseSettings();
                        }
                    } catch (IllegalAccessException ignored) {
                    }
                }
                DensityFunction moddedness = densityFunctionRegistry.get(new ResourceLocation(Blueprint.MOD_ID, "moddedness/" + location.getNamespace() + "/" + location.getPath()));
                ModdedBiomeSource moddedBiomeSource = new ModdedBiomeSource(biomeRegistry, noiseParametersRegistry, densityFunctionRegistry, source, noiseSettings, seed, legacy, moddedness != null ? moddedness : defaultModdedness, new ModdedBiomeSource.WeightedBiomeSlices(providersForKey.toArray(new BiomeUtil.ModdedBiomeProvider[0])));
                chunkGenerator.biomeSource = moddedBiomeSource;
                chunkGenerator.runtimeBiomeSource = moddedBiomeSource;
                if (noiseBased)
                    ((ModdedSurfaceSystem) ((NoiseBasedChunkGenerator) chunkGenerator).surfaceSystem).setModdedBiomeSource(moddedBiomeSource);
            }
        }
    }
}
Also used : JsonParseException(com.google.gson.JsonParseException) SelectionSpace(com.teamabnormals.blueprint.core.util.modification.targeting.SelectionSpace) ResourceLocation(net.minecraft.resources.ResourceLocation) BiomeSource(net.minecraft.world.level.biome.BiomeSource) HashMap(java.util.HashMap) Biome(net.minecraft.world.level.biome.Biome) AddReloadListenerEvent(net.minecraftforge.event.AddReloadListenerEvent) ArrayList(java.util.ArrayList) JsonElement(com.google.gson.JsonElement) Registry(net.minecraft.core.Registry) FixedBiomeSource(net.minecraft.world.level.biome.FixedBiomeSource) NormalNoise(net.minecraft.world.level.levelgen.synth.NormalNoise) ObfuscationReflectionHelper(net.minecraftforge.fml.util.ObfuscationReflectionHelper) MinecraftServer(net.minecraft.server.MinecraftServer) Holder(net.minecraft.core.Holder) SimpleJsonResourceReloadListener(net.minecraft.server.packs.resources.SimpleJsonResourceReloadListener) Gson(com.google.gson.Gson) Map(java.util.Map) Mod(net.minecraftforge.fml.common.Mod) SubscribeEvent(net.minecraftforge.eventbus.api.SubscribeEvent) DataUtil(com.teamabnormals.blueprint.core.util.DataUtil) ServerAboutToStartEvent(net.minecraftforge.event.server.ServerAboutToStartEvent) LinkedList(java.util.LinkedList) RegistryOps(net.minecraft.resources.RegistryOps) ProfilerFiller(net.minecraft.util.profiling.ProfilerFiller) net.minecraft.world.level.levelgen(net.minecraft.world.level.levelgen) ResourceManager(net.minecraft.server.packs.resources.ResourceManager) RegistryAccess(net.minecraft.core.RegistryAccess) Field(java.lang.reflect.Field) BiomeUtil(com.teamabnormals.blueprint.core.util.BiomeUtil) ResourceKey(net.minecraft.resources.ResourceKey) Blueprint(com.teamabnormals.blueprint.core.Blueprint) ChunkGenerator(net.minecraft.world.level.chunk.ChunkGenerator) List(java.util.List) CheckerboardColumnBiomeSource(net.minecraft.world.level.biome.CheckerboardColumnBiomeSource) LevelStem(net.minecraft.world.level.dimension.LevelStem) HashMap(java.util.HashMap) RegistryAccess(net.minecraft.core.RegistryAccess) ArrayList(java.util.ArrayList) Biome(net.minecraft.world.level.biome.Biome) ResourceLocation(net.minecraft.resources.ResourceLocation) BiomeSource(net.minecraft.world.level.biome.BiomeSource) FixedBiomeSource(net.minecraft.world.level.biome.FixedBiomeSource) CheckerboardColumnBiomeSource(net.minecraft.world.level.biome.CheckerboardColumnBiomeSource) SelectionSpace(com.teamabnormals.blueprint.core.util.modification.targeting.SelectionSpace) Holder(net.minecraft.core.Holder) BiomeUtil(com.teamabnormals.blueprint.core.util.BiomeUtil) CheckerboardColumnBiomeSource(net.minecraft.world.level.biome.CheckerboardColumnBiomeSource) MinecraftServer(net.minecraft.server.MinecraftServer) ResourceKey(net.minecraft.resources.ResourceKey) LevelStem(net.minecraft.world.level.dimension.LevelStem) ChunkGenerator(net.minecraft.world.level.chunk.ChunkGenerator) HashMap(java.util.HashMap) Map(java.util.Map) FixedBiomeSource(net.minecraft.world.level.biome.FixedBiomeSource) SubscribeEvent(net.minecraftforge.eventbus.api.SubscribeEvent)

Example 3 with SelectionSpace

use of com.teamabnormals.blueprint.core.util.modification.targeting.SelectionSpace in project blueprint by team-abnormals.

the class LootModificationManager method apply.

@Override
protected void apply(Map<ResourceLocation, JsonElement> map, ResourceManager resourceManager, ProfilerFiller profiler) {
    this.reset();
    SelectionSpace unmodifiedTables = this.getUnmodifiedEntries();
    for (Map.Entry<ResourceLocation, JsonElement> entry : map.entrySet()) {
        ResourceLocation resourcelocation = entry.getKey();
        if (resourcelocation.getPath().startsWith("_"))
            continue;
        try {
            TargetedModifier<LootTableLoadEvent, Gson, Pair<Gson, PredicateManager>> targetedModifier = TargetedModifier.deserialize(entry.getValue().getAsJsonObject(), Pair.of(GSON, this.lootPredicateManager), LootModifiers.REGISTRY);
            this.addModifiers(targetedModifier.getTargetSelector().getTargetNames(unmodifiedTables), targetedModifier.getPriority(), targetedModifier.getConfiguredModifiers());
        } catch (IllegalArgumentException | JsonParseException jsonparseexception) {
            Blueprint.LOGGER.error("Parsing error loading Loot Modifier: {}", resourcelocation, jsonparseexception);
        }
    }
    Blueprint.LOGGER.info("Loot Modification Manager has assigned {} sets of modifiers", this.size());
}
Also used : SelectionSpace(com.teamabnormals.blueprint.core.util.modification.targeting.SelectionSpace) LootTableLoadEvent(net.minecraftforge.event.LootTableLoadEvent) JsonElement(com.google.gson.JsonElement) ResourceLocation(net.minecraft.resources.ResourceLocation) Gson(com.google.gson.Gson) JsonParseException(com.google.gson.JsonParseException) Map(java.util.Map) Pair(com.mojang.datafixers.util.Pair)

Aggregations

JsonElement (com.google.gson.JsonElement)3 JsonParseException (com.google.gson.JsonParseException)3 SelectionSpace (com.teamabnormals.blueprint.core.util.modification.targeting.SelectionSpace)3 Map (java.util.Map)3 ResourceLocation (net.minecraft.resources.ResourceLocation)3 Gson (com.google.gson.Gson)2 GsonBuilder (com.google.gson.GsonBuilder)1 Pair (com.mojang.datafixers.util.Pair)1 Blueprint (com.teamabnormals.blueprint.core.Blueprint)1 BiomeUtil (com.teamabnormals.blueprint.core.util.BiomeUtil)1 DataUtil (com.teamabnormals.blueprint.core.util.DataUtil)1 Field (java.lang.reflect.Field)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 Builder (net.minecraft.advancements.Advancement.Builder)1 DeserializationContext (net.minecraft.advancements.critereon.DeserializationContext)1 Holder (net.minecraft.core.Holder)1 Registry (net.minecraft.core.Registry)1