From 00688eb30d077b2ead32d4dac471a8834a2f387b Mon Sep 17 00:00:00 2001 From: FalsePattern Date: Fri, 6 Jun 2025 12:07:04 +0200 Subject: [PATCH] fix witchery BrewActionBiomeChange compat #223 --- .../BrewActionBiomeChange$ChunkCoord.java | 36 +++++++ .../witchery/BrewActionBiomeChangeMixin.java | 96 +++++++++++++++++++ .../endlessids/mixin/plugin/Mixin.java | 1 + 3 files changed, 133 insertions(+) create mode 100644 src/main/java/com/falsepattern/endlessids/mixin/helpers/stubpackage/com/emoniph/witchery/brewing/action/effect/BrewActionBiomeChange$ChunkCoord.java create mode 100644 src/main/java/com/falsepattern/endlessids/mixin/mixins/common/biome/witchery/BrewActionBiomeChangeMixin.java diff --git a/src/main/java/com/falsepattern/endlessids/mixin/helpers/stubpackage/com/emoniph/witchery/brewing/action/effect/BrewActionBiomeChange$ChunkCoord.java b/src/main/java/com/falsepattern/endlessids/mixin/helpers/stubpackage/com/emoniph/witchery/brewing/action/effect/BrewActionBiomeChange$ChunkCoord.java new file mode 100644 index 0000000..636b6c8 --- /dev/null +++ b/src/main/java/com/falsepattern/endlessids/mixin/helpers/stubpackage/com/emoniph/witchery/brewing/action/effect/BrewActionBiomeChange$ChunkCoord.java @@ -0,0 +1,36 @@ +/* + * EndlessIDs + * + * Copyright (C) 2022-2025 FalsePattern, The MEGA Team + * All Rights Reserved + * + * The above copyright notice, this permission notice and the word "MEGA" + * shall be included in all copies or substantial portions of the Software. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, only version 3 of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ + +package com.falsepattern.endlessids.mixin.helpers.stubpackage.com.emoniph.witchery.brewing.action.effect; + +import net.minecraft.world.World; +import net.minecraft.world.chunk.Chunk; + +public class BrewActionBiomeChange$ChunkCoord { + public BrewActionBiomeChange$ChunkCoord(int x, int z) { + + } + + public Chunk getChunk(World world) { + return null; + } +} diff --git a/src/main/java/com/falsepattern/endlessids/mixin/mixins/common/biome/witchery/BrewActionBiomeChangeMixin.java b/src/main/java/com/falsepattern/endlessids/mixin/mixins/common/biome/witchery/BrewActionBiomeChangeMixin.java new file mode 100644 index 0000000..d276d1e --- /dev/null +++ b/src/main/java/com/falsepattern/endlessids/mixin/mixins/common/biome/witchery/BrewActionBiomeChangeMixin.java @@ -0,0 +1,96 @@ +/* + * EndlessIDs + * + * Copyright (C) 2022-2025 FalsePattern, The MEGA Team + * All Rights Reserved + * + * The above copyright notice, this permission notice and the word "MEGA" + * shall be included in all copies or substantial portions of the Software. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, only version 3 of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ + +package com.falsepattern.endlessids.mixin.mixins.common.biome.witchery; + +import com.emoniph.witchery.brewing.action.effect.BrewActionBiomeChange; +import com.falsepattern.endlessids.mixin.helpers.ChunkBiomeHook; +import com.falsepattern.endlessids.mixin.helpers.stubpackage.com.emoniph.witchery.brewing.action.effect.BrewActionBiomeChange$ChunkCoord; +import com.llamalad7.mixinextras.injector.wrapoperation.Operation; +import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation; +import com.llamalad7.mixinextras.sugar.Share; +import com.llamalad7.mixinextras.sugar.ref.LocalRef; +import lombok.val; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Overwrite; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Redirect; + +import net.minecraft.init.Blocks; +import net.minecraft.world.World; +import net.minecraft.world.biome.BiomeGenBase; +import net.minecraft.world.chunk.Chunk; + +import java.util.Arrays; +import java.util.HashMap; +import java.util.Map; + +@Mixin(BrewActionBiomeChange.class) +public abstract class BrewActionBiomeChangeMixin { + @WrapOperation(method = "changeBiome", + at = @At(value = "INVOKE", + target = "Ljava/util/Map$Entry;getValue()Ljava/lang/Object;"), + remap = false, + require = 1) + private Object removeByteArrayGet(Map.Entry instance, Operation original, + @Share("biomeArray") LocalRef biome) { + biome.set((short[]) original.call(instance)); + return null; + } + + @Redirect(method = "changeBiome", + at = @At(value = "INVOKE", + target = "Lnet/minecraft/world/chunk/Chunk;setBiomeArray([B)V"), + remap = false, + require = 1) + private void extendedSetBiomeArray(Chunk instance, byte[] ignored, @Share("biomeArray") LocalRef biome) { + ((ChunkBiomeHook)instance).setBiomeShortArray(biome.get()); + } + + /** + * @author FalsePattern + * @reason Doing this with normal mixins would be extremely tedious because of the local variable shuffling. + * Nobody else's patches should be landing here anyway. + */ + @SuppressWarnings({"rawtypes", "unchecked"}) + @Overwrite(remap = false) + private void drawLine(World world, int x1, int x2, int z, HashMap chunkMap, BiomeGenBase biome) { + for(int x = x1; x <= x2; ++x) { + BrewActionBiomeChange$ChunkCoord coord = new BrewActionBiomeChange$ChunkCoord(x >> 4, z >> 4); + short[] map = (short[])chunkMap.get(coord); + if (map == null) { + Chunk chunk = world.getChunkFromBlockCoords(x, z); + val sarr = ((ChunkBiomeHook) chunk).getBiomeShortArray(); + map = Arrays.copyOf(sarr, sarr.length); + chunkMap.put(coord, map); + } + + map[(z & 15) << 4 | x & 15] = (short) biome.biomeID; + if (biome.rainfall == 0.0F) { + int y = world.getTopSolidOrLiquidBlock(x, z); + if (world.getBlock(x, y, z) == Blocks.snow_layer) { + world.setBlockToAir(x, y, z); + } + } + } + } +} diff --git a/src/main/java/com/falsepattern/endlessids/mixin/plugin/Mixin.java b/src/main/java/com/falsepattern/endlessids/mixin/plugin/Mixin.java index a7cea19..5f5061f 100644 --- a/src/main/java/com/falsepattern/endlessids/mixin/plugin/Mixin.java +++ b/src/main/java/com/falsepattern/endlessids/mixin/plugin/Mixin.java @@ -226,6 +226,7 @@ public enum Mixin implements IMixin { //endregion TwilightForest //region Witchery WitcheryWorldChunkManagerMirrorMixin(Side.COMMON, condition(() -> GeneralConfig.extendBiome).and(require(TargetedMod.WITCHERY)), "biome.witchery.WorldChunkManagerMirrorMixin"), + WitcheryBrewActionBiomeChangeMixin(Side.COMMON, condition(() -> GeneralConfig.extendBiome).and(require(TargetedMod.WITCHERY)), "biome.witchery.BrewActionBiomeChangeMixin"), //endregion Witchery //endregion biome //region blockitem