From d6bf72d59b95a87e1cec16787e3a8d7ca5fb2a8a Mon Sep 17 00:00:00 2001 From: Hugman Date: Fri, 5 Jun 2020 12:28:09 +0200 Subject: [PATCH] 1.16 fix for nether biomes (#658) * 20w22a support for nether biomes * Apply suggestions from code review Co-authored-by: Joseph Burton * Checked style and bumped version * Fixed some testmods * Made TestCrimsonForestBiome an inner class in FabricBiomeTest Co-authored-by: Joseph Burton --- .../mixin/biome/MixinTheNetherDimension.java | 16 ++++---- .../src/main/resources/fabric.mod.json | 2 +- .../fabric/test/biome/FabricBiomeTest.java | 38 +++++++++++++++++++ .../src/testmod/resources/fabric.mod.json | 16 ++++++++ 4 files changed, 64 insertions(+), 8 deletions(-) create mode 100644 fabric-biomes-v1/src/testmod/java/net/fabricmc/fabric/test/biome/FabricBiomeTest.java create mode 100644 fabric-biomes-v1/src/testmod/resources/fabric.mod.json diff --git a/fabric-biomes-v1/src/main/java/net/fabricmc/fabric/mixin/biome/MixinTheNetherDimension.java b/fabric-biomes-v1/src/main/java/net/fabricmc/fabric/mixin/biome/MixinTheNetherDimension.java index a425d5602..4e39863e2 100644 --- a/fabric-biomes-v1/src/main/java/net/fabricmc/fabric/mixin/biome/MixinTheNetherDimension.java +++ b/fabric-biomes-v1/src/main/java/net/fabricmc/fabric/mixin/biome/MixinTheNetherDimension.java @@ -18,12 +18,14 @@ package net.fabricmc.fabric.mixin.biome; import java.util.ArrayList; import java.util.List; +import java.util.Optional; import com.google.common.collect.ImmutableList; import com.mojang.datafixers.util.Pair; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.ModifyArg; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; import net.minecraft.world.biome.Biome; import net.minecraft.world.biome.source.MultiNoiseBiomeSource; @@ -32,11 +34,11 @@ import net.fabricmc.fabric.impl.biome.InternalBiomeData; @Mixin(MultiNoiseBiomeSource.class) public class MixinTheNetherDimension { - @ModifyArg(method = "method_28467", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/biome/source/MultiNoiseBiomeSource;(JLjava/util/List;Ljava/util/Optional;)V")) - private static List> modifyNetherBiomes(List> list) { - // the provided set is immutable, so we construct our own - List> newList = new ArrayList<>(list); - newList.addAll(InternalBiomeData.getNetherBiomes().stream().flatMap((biome) -> biome.streamNoises().map((point) -> Pair.of(point, biome))).collect(ImmutableList.toImmutableList())); - return newList; + @Inject(method = "method_28467", at = @At("RETURN"), cancellable = true) + private static void method_28467(long l, CallbackInfoReturnable info) { + List newList = new ArrayList<>(info.getReturnValue().method_28443()); + newList.addAll(InternalBiomeData.getNetherBiomes()); + MultiNoiseBiomeSource multiNoiseBiomeSource = new MultiNoiseBiomeSource(l, newList.stream().flatMap((biome) -> biome.streamNoises().map((point) -> Pair.of(point, biome))).collect(ImmutableList.toImmutableList()), Optional.of(MultiNoiseBiomeSource.class_5305.field_24723)); + info.setReturnValue(multiNoiseBiomeSource); } } diff --git a/fabric-biomes-v1/src/main/resources/fabric.mod.json b/fabric-biomes-v1/src/main/resources/fabric.mod.json index 2bc6e9fe4..51e667d97 100644 --- a/fabric-biomes-v1/src/main/resources/fabric.mod.json +++ b/fabric-biomes-v1/src/main/resources/fabric.mod.json @@ -17,7 +17,7 @@ ], "depends": { "fabricloader": ">=0.4.0", - "minecraft": ">=1.16-alpha.20.10.a" + "minecraft": ">=1.16-alpha.20.22.a" }, "description": "Hooks for adding biomes to the default world generator.", "mixins": [ diff --git a/fabric-biomes-v1/src/testmod/java/net/fabricmc/fabric/test/biome/FabricBiomeTest.java b/fabric-biomes-v1/src/testmod/java/net/fabricmc/fabric/test/biome/FabricBiomeTest.java new file mode 100644 index 000000000..3efce6212 --- /dev/null +++ b/fabric-biomes-v1/src/testmod/java/net/fabricmc/fabric/test/biome/FabricBiomeTest.java @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2016, 2017, 2018, 2019 FabricMC + * + * 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 net.fabricmc.fabric.test.biome; + +import net.minecraft.util.Identifier; +import net.minecraft.util.registry.Registry; +import net.minecraft.world.biome.Biomes; +import net.minecraft.world.biome.CrimsonForestBiome; + +import net.fabricmc.api.ModInitializer; +import net.fabricmc.fabric.api.biomes.v1.NetherBiomes; + +public class FabricBiomeTest implements ModInitializer { + public static final String MOD_ID = "fabric-biome-api-v1-testmod"; + + @Override public void onInitialize() { + TestCrimsonForestBiome biome = Registry.register(Registry.BIOME, new Identifier(MOD_ID, "test_crimson_forest"), new TestCrimsonForestBiome()); + NetherBiomes.addNetherBiome(Biomes.BEACH); + NetherBiomes.addNetherBiome(biome); + } + + public class TestCrimsonForestBiome extends CrimsonForestBiome { + } +} diff --git a/fabric-biomes-v1/src/testmod/resources/fabric.mod.json b/fabric-biomes-v1/src/testmod/resources/fabric.mod.json new file mode 100644 index 000000000..0532023ac --- /dev/null +++ b/fabric-biomes-v1/src/testmod/resources/fabric.mod.json @@ -0,0 +1,16 @@ +{ + "schemaVersion": 1, + "id": "fabric-biomes-v1-testmod", + "name": "Fabric Biomes (v1) Test Mod", + "version": "1.0.0", + "environment": "*", + "license": "Apache-2.0", + "depends": { + "fabric-biomes-v1": "*" + }, + "entrypoints": { + "main": [ + "net.fabricmc.fabric.test.biome.FabricBiomeTest" + ] + } +}