From 1813e158756834c02d18597ad42e1f3eb739fc46 Mon Sep 17 00:00:00 2001 From: aromaa Date: Fri, 19 Jan 2024 01:50:05 +0200 Subject: [PATCH] Fix flat level generator breaking after first usage --- .../flat/FlatLevelGeneratorSettingsMixin.java | 50 +++++++++++++++++++ src/mixins/resources/mixins.sponge.core.json | 1 + 2 files changed, 51 insertions(+) create mode 100644 src/mixins/java/org/spongepowered/common/mixin/core/world/level/levelgen/flat/FlatLevelGeneratorSettingsMixin.java diff --git a/src/mixins/java/org/spongepowered/common/mixin/core/world/level/levelgen/flat/FlatLevelGeneratorSettingsMixin.java b/src/mixins/java/org/spongepowered/common/mixin/core/world/level/levelgen/flat/FlatLevelGeneratorSettingsMixin.java new file mode 100644 index 00000000000..9c703ccb909 --- /dev/null +++ b/src/mixins/java/org/spongepowered/common/mixin/core/world/level/levelgen/flat/FlatLevelGeneratorSettingsMixin.java @@ -0,0 +1,50 @@ +/* + * This file is part of Sponge, licensed under the MIT License (MIT). + * + * Copyright (c) SpongePowered + * Copyright (c) contributors + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package org.spongepowered.common.mixin.core.world.level.levelgen.flat; + +import net.minecraft.world.level.levelgen.flat.FlatLevelGeneratorSettings; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Redirect; +import org.spongepowered.asm.mixin.injection.Slice; + +import java.util.List; + +@Mixin(FlatLevelGeneratorSettings.class) +public abstract class FlatLevelGeneratorSettingsMixin { + + @Redirect(method = "adjustGenerationSettings", at = @At(value = "INVOKE", target = "Ljava/util/List;set(ILjava/lang/Object;)Ljava/lang/Object;"), + slice = @Slice( + from = @At(value = "FIELD", target = "Lnet/minecraft/world/level/levelgen/Heightmap$Types;MOTION_BLOCKING:Lnet/minecraft/world/level/levelgen/Heightmap$Types;"), + to = @At(value = "FIELD", target = "Lnet/minecraft/world/level/levelgen/GenerationStep$Decoration;TOP_LAYER_MODIFICATION:Lnet/minecraft/world/level/levelgen/GenerationStep$Decoration;") + ) + ) + private E impl$preventLayerOverwrite(final List instance, final int index, final E element) { + //Not really sure what vanilla is trying to do here but this doesn't make much sense and, + //we hit NPE on the next call to this method. This doesn't happen on vanilla as it always + //creates a new instance. + return null; + } +} diff --git a/src/mixins/resources/mixins.sponge.core.json b/src/mixins/resources/mixins.sponge.core.json index 1053207e50e..53d1c28d5bc 100644 --- a/src/mixins/resources/mixins.sponge.core.json +++ b/src/mixins/resources/mixins.sponge.core.json @@ -217,6 +217,7 @@ "world.level.levelgen.NoiseGeneratorSettingsMixin", "world.level.levelgen.WorldOptionsMixin", "world.level.levelgen.flat.FlatLayerInfoMixin", + "world.level.levelgen.flat.FlatLevelGeneratorSettingsMixin", "world.level.levelgen.structure.LegacyStructureDataHandlerMixin", "world.level.portal.PortalShapeMixin", "world.level.saveddata.MapIdTrackerMixin",