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",