From 0f52d4495ac456e9aacc51b836500318b43a9902 Mon Sep 17 00:00:00 2001 From: Ennui Langeweile <85590273+EnnuiL@users.noreply.github.com> Date: Sat, 29 Jul 2023 00:26:39 -0300 Subject: [PATCH] Fix #332 by switching approach to nether biome injection With Quilt Tags API being fixed, we could go back to the old approach! But we didn't, because I wasn't annoying enough! :p But the real reason is that it turns out the new approach does have its flaws, with a need for a caching system (and that being flawed) and some extra complexity being few of them; Removing the mixin's cache fixes #332 but well, I believe it's time to switch back to the simpler old approach now; The new one will be preserved by Git history anyway, in case the game changes in a way where we end needing it again --- ...ultiNoiseBiomeSourceParameterListHook.java | 32 ---------- .../worldgen/biome/impl/NetherBiomeData.java | 25 +------- ...terListMixin.java => C_cnkaoojoMixin.java} | 32 ++++------ .../mixin/MultiNoiseBiomeSourceMixin.java | 62 ------------------- .../main/resources/quilt_biome.mixins.json | 3 +- 5 files changed, 16 insertions(+), 138 deletions(-) delete mode 100644 library/worldgen/biome/src/main/java/org/quiltmc/qsl/worldgen/biome/impl/MultiNoiseBiomeSourceParameterListHook.java rename library/worldgen/biome/src/main/java/org/quiltmc/qsl/worldgen/biome/mixin/{MultiNoiseBiomeSourceParameterListMixin.java => C_cnkaoojoMixin.java} (50%) delete mode 100644 library/worldgen/biome/src/main/java/org/quiltmc/qsl/worldgen/biome/mixin/MultiNoiseBiomeSourceMixin.java diff --git a/library/worldgen/biome/src/main/java/org/quiltmc/qsl/worldgen/biome/impl/MultiNoiseBiomeSourceParameterListHook.java b/library/worldgen/biome/src/main/java/org/quiltmc/qsl/worldgen/biome/impl/MultiNoiseBiomeSourceParameterListHook.java deleted file mode 100644 index fd75d08d04..0000000000 --- a/library/worldgen/biome/src/main/java/org/quiltmc/qsl/worldgen/biome/impl/MultiNoiseBiomeSourceParameterListHook.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright 2023 The Quilt Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.quiltmc.qsl.worldgen.biome.impl; - -import org.jetbrains.annotations.ApiStatus; - -import net.minecraft.registry.HolderProvider; -import net.minecraft.world.biome.Biome; -import net.minecraft.world.biome.util.MultiNoiseBiomeSourceParameterList; - -/** - * Allows for acquiring the holder provider used for initializing the {@link MultiNoiseBiomeSourceParameterList} instance - * which would have been discarded otherwise. - */ -@ApiStatus.Internal -public interface MultiNoiseBiomeSourceParameterListHook { - HolderProvider getHolderProvider(); -} diff --git a/library/worldgen/biome/src/main/java/org/quiltmc/qsl/worldgen/biome/impl/NetherBiomeData.java b/library/worldgen/biome/src/main/java/org/quiltmc/qsl/worldgen/biome/impl/NetherBiomeData.java index c2d30de3b8..a716d698bb 100644 --- a/library/worldgen/biome/src/main/java/org/quiltmc/qsl/worldgen/biome/impl/NetherBiomeData.java +++ b/library/worldgen/biome/src/main/java/org/quiltmc/qsl/worldgen/biome/impl/NetherBiomeData.java @@ -19,11 +19,8 @@ import java.util.ArrayList; import java.util.Collections; -import java.util.HashSet; import java.util.Map; -import java.util.Set; import java.util.function.Function; -import java.util.stream.Collectors; import com.google.common.base.Preconditions; import com.mojang.datafixers.util.Pair; @@ -36,18 +33,10 @@ import net.minecraft.world.biome.util.MultiNoiseBiomeSourceParameterList; /** - * Internal data for modding Vanilla's {@link MultiNoiseBiomeSourceParameterList.Preset#NETHER}. + * Internal data for modding Vanilla's {@link MultiNoiseBiomeSourceParameterList.Preset#NETHER} preset. */ @ApiStatus.Internal public final class NetherBiomeData { - // The cached sets of vanilla biomes that would generate from Vanilla's nether biome preset. - private static final Set> VANILLA_NETHER_BIOMES = MultiNoiseBiomeSourceParameterList.Preset.NETHER - .method_49514() - .collect(Collectors.toSet()); - - // The cached sets of all biomes, included modded ones, that would generate from Vanilla's nether biome preset. - private static final Set> NETHER_BIOMES = new HashSet<>(); - public static final Map, MultiNoiseUtil.NoiseHypercube> NETHER_BIOME_NOISE_POINTS = new Reference2ObjectOpenHashMap<>(); private NetherBiomeData() {} @@ -56,20 +45,10 @@ public static void addNetherBiome(RegistryKey biome, MultiNoiseUtil.Noise Preconditions.checkArgument(biome != null, "Biome is null"); Preconditions.checkArgument(spawnNoisePoint != null, "MultiNoiseUtil.NoiseHypercube is null"); NETHER_BIOME_NOISE_POINTS.put(biome, spawnNoisePoint); - NetherBiomeData.clearBiomeSourceCache(); } public static boolean canGenerateInNether(RegistryKey biome) { - if (NETHER_BIOMES.isEmpty()) { - NETHER_BIOMES.addAll(VANILLA_NETHER_BIOMES); - NETHER_BIOMES.addAll(NETHER_BIOME_NOISE_POINTS.keySet()); - } - - return NETHER_BIOMES.contains(biome); - } - - private static void clearBiomeSourceCache() { - NETHER_BIOMES.clear(); + return MultiNoiseBiomeSourceParameterList.Preset.NETHER.method_49514().anyMatch(presetBiome -> presetBiome.equals(biome)); } public static MultiNoiseUtil.ParameterRangeList withModdedBiomeEntries( diff --git a/library/worldgen/biome/src/main/java/org/quiltmc/qsl/worldgen/biome/mixin/MultiNoiseBiomeSourceParameterListMixin.java b/library/worldgen/biome/src/main/java/org/quiltmc/qsl/worldgen/biome/mixin/C_cnkaoojoMixin.java similarity index 50% rename from library/worldgen/biome/src/main/java/org/quiltmc/qsl/worldgen/biome/mixin/MultiNoiseBiomeSourceParameterListMixin.java rename to library/worldgen/biome/src/main/java/org/quiltmc/qsl/worldgen/biome/mixin/C_cnkaoojoMixin.java index d01ddb039f..5fc573aa80 100644 --- a/library/worldgen/biome/src/main/java/org/quiltmc/qsl/worldgen/biome/mixin/MultiNoiseBiomeSourceParameterListMixin.java +++ b/library/worldgen/biome/src/main/java/org/quiltmc/qsl/worldgen/biome/mixin/C_cnkaoojoMixin.java @@ -1,5 +1,6 @@ /* - * Copyright 2023 The Quilt Project + * Copyright 2016, 2017, 2018, 2019 FabricMC + * Copyright 2023 QuiltMC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,30 +17,23 @@ package org.quiltmc.qsl.worldgen.biome.mixin; +import java.util.function.Function; + import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Unique; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -import net.minecraft.registry.HolderProvider; +import net.minecraft.registry.RegistryKey; import net.minecraft.world.biome.Biome; -import net.minecraft.world.biome.util.MultiNoiseBiomeSourceParameterList; - -import org.quiltmc.qsl.worldgen.biome.impl.MultiNoiseBiomeSourceParameterListHook; +import net.minecraft.world.biome.source.util.MultiNoiseUtil; -@Mixin(MultiNoiseBiomeSourceParameterList.class) -public abstract class MultiNoiseBiomeSourceParameterListMixin implements MultiNoiseBiomeSourceParameterListHook { - @Unique - private HolderProvider quilt$holderProvider; - - @Inject(method = "", at = @At("RETURN")) - private void quilt$grabHolderProvider(MultiNoiseBiomeSourceParameterList.Preset preset, HolderProvider holderProvider, CallbackInfo ci) { - this.quilt$holderProvider = holderProvider; - } +import org.quiltmc.qsl.worldgen.biome.impl.NetherBiomeData; - @Override - public HolderProvider getHolderProvider() { - return this.quilt$holderProvider; +@Mixin(targets = "net/minecraft/world/biome/util/MultiNoiseBiomeSourceParameterList$Preset$C_cnkaoojo") +public class C_cnkaoojoMixin { + @Inject(method = "apply", at = @At("RETURN"), cancellable = true, remap = false) + public void modifyNetherPreset(Function, T> function, CallbackInfoReturnable> cir) { + cir.setReturnValue(NetherBiomeData.withModdedBiomeEntries(cir.getReturnValue(), function)); } } diff --git a/library/worldgen/biome/src/main/java/org/quiltmc/qsl/worldgen/biome/mixin/MultiNoiseBiomeSourceMixin.java b/library/worldgen/biome/src/main/java/org/quiltmc/qsl/worldgen/biome/mixin/MultiNoiseBiomeSourceMixin.java deleted file mode 100644 index 65276ab184..0000000000 --- a/library/worldgen/biome/src/main/java/org/quiltmc/qsl/worldgen/biome/mixin/MultiNoiseBiomeSourceMixin.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Copyright 2023 The Quilt Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.quiltmc.qsl.worldgen.biome.mixin; - -import org.spongepowered.asm.mixin.Dynamic; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Unique; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; - -import net.minecraft.registry.Holder; -import net.minecraft.world.biome.Biome; -import net.minecraft.world.biome.source.MultiNoiseBiomeSource; -import net.minecraft.world.biome.source.util.MultiNoiseUtil; -import net.minecraft.world.biome.util.MultiNoiseBiomeSourceParameterList; -import net.minecraft.world.biome.util.MultiNoiseBiomeSourceParameterLists; - -import org.quiltmc.qsl.worldgen.biome.impl.MultiNoiseBiomeSourceParameterListHook; -import org.quiltmc.qsl.worldgen.biome.impl.NetherBiomeData; - -@Mixin(MultiNoiseBiomeSource.class) -public abstract class MultiNoiseBiomeSourceMixin { - @Unique - private static MultiNoiseUtil.ParameterRangeList> quilt$CACHED_PARAMETER_RANGE_LIST = null; - - @Dynamic - @Inject( - method = "method_49505(Lnet/minecraft/registry/Holder;)Lnet/minecraft/world/biome/source/util/MultiNoiseUtil$ParameterRangeList;", - at = @At("HEAD"), - cancellable = true - ) - private static void quilt$overrideNetherPreset( - Holder holder, - CallbackInfoReturnable>> cir - ) { - if (MultiNoiseBiomeSourceParameterLists.NETHER.equals(holder.getKey().orElseThrow())) { - if (quilt$CACHED_PARAMETER_RANGE_LIST == null) { - MultiNoiseBiomeSourceMixin.quilt$CACHED_PARAMETER_RANGE_LIST = NetherBiomeData.withModdedBiomeEntries( - holder.value().getRangeList(), - ((MultiNoiseBiomeSourceParameterListHook) holder.value()).getHolderProvider()::getHolderOrThrow - ); - } - - cir.setReturnValue(MultiNoiseBiomeSourceMixin.quilt$CACHED_PARAMETER_RANGE_LIST); - } - } -} diff --git a/library/worldgen/biome/src/main/resources/quilt_biome.mixins.json b/library/worldgen/biome/src/main/resources/quilt_biome.mixins.json index 8f1256a6f2..580670d0dc 100644 --- a/library/worldgen/biome/src/main/resources/quilt_biome.mixins.json +++ b/library/worldgen/biome/src/main/resources/quilt_biome.mixins.json @@ -3,9 +3,8 @@ "package": "org.quiltmc.qsl.worldgen.biome.mixin", "compatibilityLevel": "JAVA_17", "mixins": [ - "MultiNoiseBiomeSourceParameterListMixin", + "C_cnkaoojoMixin", "ChunkNoiseSamplerMixin", - "MultiNoiseBiomeSourceMixin", "MultiNoiseSamplerMixin", "RandomStateMixin", "TheEndBiomeSourceMixin",