|
| 1 | +/* |
| 2 | + * Minecraft Forge, Patchwork Project |
| 3 | + * Copyright (c) 2016-2020, 2019-2020 |
| 4 | + * |
| 5 | + * This library is free software; you can redistribute it and/or |
| 6 | + * modify it under the terms of the GNU Lesser General Public |
| 7 | + * License as published by the Free Software Foundation version 2.1 |
| 8 | + * of the License. |
| 9 | + * |
| 10 | + * This library is distributed in the hope that it will be useful, |
| 11 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 | + * Lesser General Public License for more details. |
| 14 | + * |
| 15 | + * You should have received a copy of the GNU Lesser General Public |
| 16 | + * License along with this library; if not, write to the Free Software |
| 17 | + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 18 | + */ |
| 19 | + |
| 20 | +package net.patchworkmc.mixin.levelgenerators; |
| 21 | + |
| 22 | +import java.util.function.LongFunction; |
| 23 | + |
| 24 | +import net.minecraftforge.common.extensions.IForgeWorldType; |
| 25 | +import org.spongepowered.asm.mixin.Mixin; |
| 26 | +import org.spongepowered.asm.mixin.Shadow; |
| 27 | +import org.spongepowered.asm.mixin.injection.At; |
| 28 | +import org.spongepowered.asm.mixin.injection.Redirect; |
| 29 | + |
| 30 | +import net.minecraft.world.biome.layer.AddBambooJungleLayer; |
| 31 | +import net.minecraft.world.biome.layer.BiomeLayers; |
| 32 | +import net.minecraft.world.biome.layer.EaseBiomeEdgeLayer; |
| 33 | +import net.minecraft.world.biome.layer.SetBaseBiomesLayer; |
| 34 | +import net.minecraft.world.biome.layer.type.ParentedLayer; |
| 35 | +import net.minecraft.world.biome.layer.util.LayerFactory; |
| 36 | +import net.minecraft.world.biome.layer.util.LayerSampleContext; |
| 37 | +import net.minecraft.world.biome.layer.util.LayerSampler; |
| 38 | +import net.minecraft.world.gen.chunk.OverworldChunkGeneratorConfig; |
| 39 | +import net.minecraft.world.level.LevelGeneratorType; |
| 40 | + |
| 41 | +import net.patchworkmc.api.levelgenerators.PatchworkLevelGeneratorType; |
| 42 | + |
| 43 | +@Mixin(BiomeLayers.class) |
| 44 | +public class MixinBiomeLayers { |
| 45 | + @Shadow |
| 46 | + private static <T extends LayerSampler, C extends LayerSampleContext<T>> LayerFactory<T> stack(long seed, ParentedLayer layer, LayerFactory<T> parent, int count, LongFunction<C> contextProvider) { |
| 47 | + throw new RuntimeException("Failed to shadow BiomeLayers#stack!"); |
| 48 | + } |
| 49 | + |
| 50 | + @Redirect(method = "build(Lnet/minecraft/world/level/LevelGeneratorType;Lnet/minecraft/world/gen/chunk/OverworldChunkGeneratorConfig;Ljava/util/function/LongFunction;)Lcom/google/common/collect/ImmutableList;", |
| 51 | + at = @At(value = "INVOKE", target = "net/minecraft/world/biome/layer/SetBaseBiomesLayer.create(Lnet/minecraft/world/biome/layer/util/LayerSampleContext;Lnet/minecraft/world/biome/layer/util/LayerFactory;)Lnet/minecraft/world/biome/layer/util/LayerFactory;", ordinal = 0)) |
| 52 | + private static <T extends LayerSampler, C extends LayerSampleContext<T>> LayerFactory<T> addForgeBiomeLayers(SetBaseBiomesLayer instance, C contextParam, LayerFactory<T> parentLayer, LevelGeneratorType generatorType, OverworldChunkGeneratorConfig settings, LongFunction<C> contextProvider) { |
| 53 | + if (generatorType instanceof PatchworkLevelGeneratorType) { |
| 54 | + return ((IForgeWorldType) generatorType).getBiomeLayer(parentLayer, settings, contextProvider); |
| 55 | + } else { |
| 56 | + // vanilla behaviour |
| 57 | + return instance.create(contextParam, parentLayer); |
| 58 | + } |
| 59 | + } |
| 60 | + |
| 61 | + @Redirect(method = "build(Lnet/minecraft/world/level/LevelGeneratorType;Lnet/minecraft/world/gen/chunk/OverworldChunkGeneratorConfig;Ljava/util/function/LongFunction;)Lcom/google/common/collect/ImmutableList;", |
| 62 | + at = @At(value = "INVOKE", target = "net/minecraft/world/biome/layer/AddBambooJungleLayer.create(Lnet/minecraft/world/biome/layer/util/LayerSampleContext;Lnet/minecraft/world/biome/layer/util/LayerFactory;)Lnet/minecraft/world/biome/layer/util/LayerFactory;", ordinal = 0)) |
| 63 | + private static <T extends LayerSampler, C extends LayerSampleContext<T>> LayerFactory<T> redirectBambooJungle(AddBambooJungleLayer instance, C contextParam, LayerFactory<T> parentLayer, LevelGeneratorType generatorType, OverworldChunkGeneratorConfig settings, LongFunction<C> contextProvider) { |
| 64 | + if (generatorType instanceof PatchworkLevelGeneratorType) { |
| 65 | + return parentLayer; |
| 66 | + } else { |
| 67 | + // vanilla behaviour |
| 68 | + return instance.create(contextParam, parentLayer); |
| 69 | + } |
| 70 | + } |
| 71 | + |
| 72 | + @Redirect(method = "build(Lnet/minecraft/world/level/LevelGeneratorType;Lnet/minecraft/world/gen/chunk/OverworldChunkGeneratorConfig;Ljava/util/function/LongFunction;)Lcom/google/common/collect/ImmutableList;", |
| 73 | + at = @At(value = "INVOKE", target = "Lnet/minecraft/world/biome/layer/BiomeLayers;stack(JLnet/minecraft/world/biome/layer/type/ParentedLayer;Lnet/minecraft/world/biome/layer/util/LayerFactory;ILjava/util/function/LongFunction;)Lnet/minecraft/world/biome/layer/util/LayerFactory;", ordinal = 3)) |
| 74 | + private static <T extends LayerSampler, C extends LayerSampleContext<T>> LayerFactory<T> redirectStack(long seed, ParentedLayer layer, LayerFactory<T> parentLayer, int count, LongFunction<C> contextProvider, LevelGeneratorType generatorType, OverworldChunkGeneratorConfig settings, LongFunction<C> contextProviderParam) { |
| 75 | + if (generatorType instanceof PatchworkLevelGeneratorType) { |
| 76 | + return parentLayer; |
| 77 | + } else { |
| 78 | + // vanilla behaviour |
| 79 | + return stack(seed, layer, parentLayer, count, contextProvider); |
| 80 | + } |
| 81 | + } |
| 82 | + |
| 83 | + @Redirect(method = "build(Lnet/minecraft/world/level/LevelGeneratorType;Lnet/minecraft/world/gen/chunk/OverworldChunkGeneratorConfig;Ljava/util/function/LongFunction;)Lcom/google/common/collect/ImmutableList;", |
| 84 | + at = @At(value = "INVOKE", target = "net/minecraft/world/biome/layer/EaseBiomeEdgeLayer.create(Lnet/minecraft/world/biome/layer/util/LayerSampleContext;Lnet/minecraft/world/biome/layer/util/LayerFactory;)Lnet/minecraft/world/biome/layer/util/LayerFactory;", ordinal = 0)) |
| 85 | + private static <T extends LayerSampler, C extends LayerSampleContext<T>> LayerFactory<T> redirectEaseBiomeEdge(EaseBiomeEdgeLayer instance, C contextParam, LayerFactory<T> parentLayer, LevelGeneratorType generatorType, OverworldChunkGeneratorConfig settings, LongFunction<C> contextProvider) { |
| 86 | + if (generatorType instanceof PatchworkLevelGeneratorType) { |
| 87 | + return parentLayer; |
| 88 | + } else { |
| 89 | + // vanilla behaviour |
| 90 | + return instance.create(contextParam, parentLayer); |
| 91 | + } |
| 92 | + } |
| 93 | +} |
0 commit comments