Skip to content

Commit

Permalink
Fix #332 by switching approach to nether biome injection
Browse files Browse the repository at this point in the history
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
  • Loading branch information
EnnuiL committed Jul 29, 2023
1 parent 0ddf030 commit 0f52d44
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 138 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<RegistryKey<Biome>> 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<RegistryKey<Biome>> NETHER_BIOMES = new HashSet<>();

public static final Map<RegistryKey<Biome>, MultiNoiseUtil.NoiseHypercube> NETHER_BIOME_NOISE_POINTS = new Reference2ObjectOpenHashMap<>();

private NetherBiomeData() {}
Expand All @@ -56,20 +45,10 @@ public static void addNetherBiome(RegistryKey<Biome> 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> 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 <T> MultiNoiseUtil.ParameterRangeList<T> withModdedBiomeEntries(
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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<Biome> quilt$holderProvider;

@Inject(method = "<init>", at = @At("RETURN"))
private void quilt$grabHolderProvider(MultiNoiseBiomeSourceParameterList.Preset preset, HolderProvider<Biome> holderProvider, CallbackInfo ci) {
this.quilt$holderProvider = holderProvider;
}
import org.quiltmc.qsl.worldgen.biome.impl.NetherBiomeData;

@Override
public HolderProvider<Biome> 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 <T> void modifyNetherPreset(Function<RegistryKey<Biome>, T> function, CallbackInfoReturnable<MultiNoiseUtil.ParameterRangeList<T>> cir) {
cir.setReturnValue(NetherBiomeData.withModdedBiomeEntries(cir.getReturnValue(), function));
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@
"package": "org.quiltmc.qsl.worldgen.biome.mixin",
"compatibilityLevel": "JAVA_17",
"mixins": [
"MultiNoiseBiomeSourceParameterListMixin",
"C_cnkaoojoMixin",
"ChunkNoiseSamplerMixin",
"MultiNoiseBiomeSourceMixin",
"MultiNoiseSamplerMixin",
"RandomStateMixin",
"TheEndBiomeSourceMixin",
Expand Down

0 comments on commit 0f52d44

Please sign in to comment.