From e8e77766c4086e68dd23111d5ea9d633a3f9d4d4 Mon Sep 17 00:00:00 2001 From: FalsePattern Date: Mon, 23 Dec 2024 15:37:52 +0100 Subject: [PATCH] fixed crash with HBM NTM nukes --- build.gradle.kts | 2 +- .../falsepattern/endlessids/EndlessIDs.java | 2 +- .../mixin/helpers/IHBMBiomeSyncPacket.java | 32 +++++ .../com/hbm/packet/BiomeSyncPacket.java | 33 +++++ .../biome/ntm/BiomeSyncPacketMixin.java | 119 ++++++++++++++++++ .../ntm/BiomeSyncPacket_HandlerMixin.java | 71 +++++++++++ .../common/biome/ntm/WorldUtilMixin.java | 103 +++++++++++++++ .../endlessids/mixin/plugin/Mixin.java | 5 + 8 files changed, 365 insertions(+), 2 deletions(-) create mode 100644 src/main/java/com/falsepattern/endlessids/mixin/helpers/IHBMBiomeSyncPacket.java create mode 100644 src/main/java/com/falsepattern/endlessids/mixin/helpers/stubpackage/com/hbm/packet/BiomeSyncPacket.java create mode 100644 src/main/java/com/falsepattern/endlessids/mixin/mixins/common/biome/ntm/BiomeSyncPacketMixin.java create mode 100644 src/main/java/com/falsepattern/endlessids/mixin/mixins/common/biome/ntm/BiomeSyncPacket_HandlerMixin.java create mode 100644 src/main/java/com/falsepattern/endlessids/mixin/mixins/common/biome/ntm/WorldUtilMixin.java diff --git a/build.gradle.kts b/build.gradle.kts index 0a3bcba..0f3334e 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -63,7 +63,7 @@ repositories { dependencies { ////////////////Our dependencies//////////////// - implementationSplit("com.falsepattern:falsepatternlib-mc1.7.10:1.5.4") + implementationSplit("com.falsepattern:falsepatternlib-mc1.7.10:1.5.5") implementation("it.unimi.dsi:fastutil:8.5.13") implementationSplit("com.falsepattern:chunkapi-mc1.7.10:0.6.0") diff --git a/src/main/java/com/falsepattern/endlessids/EndlessIDs.java b/src/main/java/com/falsepattern/endlessids/EndlessIDs.java index e75ddcc..3e4b9c8 100644 --- a/src/main/java/com/falsepattern/endlessids/EndlessIDs.java +++ b/src/main/java/com/falsepattern/endlessids/EndlessIDs.java @@ -44,7 +44,7 @@ import cpw.mods.fml.common.event.FMLPreInitializationEvent; name = Tags.MODNAME, acceptedMinecraftVersions = "[1.7.10]", dependencies = "required-after:chunkapi@[0.6.0,);" + - "required-after:falsepatternlib@[1.5.4,);" + + "required-after:falsepatternlib@[1.5.5,);" + "after:antiidconflict") public class EndlessIDs { public static final byte[] ZERO_LENGTH_BIOME_ARRAY_PLACEHOLDER = new byte[0]; diff --git a/src/main/java/com/falsepattern/endlessids/mixin/helpers/IHBMBiomeSyncPacket.java b/src/main/java/com/falsepattern/endlessids/mixin/helpers/IHBMBiomeSyncPacket.java new file mode 100644 index 0000000..a1fdcc0 --- /dev/null +++ b/src/main/java/com/falsepattern/endlessids/mixin/helpers/IHBMBiomeSyncPacket.java @@ -0,0 +1,32 @@ +/* + * EndlessIDs + * + * Copyright (C) 2022-2024 FalsePattern + * All Rights Reserved + * + * The above copyright notice, this permission notice and the words "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, either version 3 of the License, or + * (at your option) any later version. + * + * 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 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; + +public interface IHBMBiomeSyncPacket { + void eid$setBiome(short biome); + short eid$getBiome(); + + void eid$setBiomeArray(short[] biomeArray); + short[] eid$getBiomeArray(); +} diff --git a/src/main/java/com/falsepattern/endlessids/mixin/helpers/stubpackage/com/hbm/packet/BiomeSyncPacket.java b/src/main/java/com/falsepattern/endlessids/mixin/helpers/stubpackage/com/hbm/packet/BiomeSyncPacket.java new file mode 100644 index 0000000..5b094a6 --- /dev/null +++ b/src/main/java/com/falsepattern/endlessids/mixin/helpers/stubpackage/com/hbm/packet/BiomeSyncPacket.java @@ -0,0 +1,33 @@ +/* + * EndlessIDs + * + * Copyright (C) 2022-2024 FalsePattern + * All Rights Reserved + * + * The above copyright notice, this permission notice and the words "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, either version 3 of the License, or + * (at your option) any later version. + * + * 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 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.hbm.packet; + +import com.falsepattern.endlessids.mixin.helpers.IHBMBiomeSyncPacket; + +public abstract class BiomeSyncPacket extends com.hbm.packet.BiomeSyncPacket implements IHBMBiomeSyncPacket { + public int chunkX; + public int chunkZ; + public byte blockX; + public byte blockZ; +} diff --git a/src/main/java/com/falsepattern/endlessids/mixin/mixins/common/biome/ntm/BiomeSyncPacketMixin.java b/src/main/java/com/falsepattern/endlessids/mixin/mixins/common/biome/ntm/BiomeSyncPacketMixin.java new file mode 100644 index 0000000..63f053e --- /dev/null +++ b/src/main/java/com/falsepattern/endlessids/mixin/mixins/common/biome/ntm/BiomeSyncPacketMixin.java @@ -0,0 +1,119 @@ +/* + * EndlessIDs + * + * Copyright (C) 2022-2024 FalsePattern + * All Rights Reserved + * + * The above copyright notice, this permission notice and the words "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, either version 3 of the License, or + * (at your option) any later version. + * + * 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 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.ntm; + +import com.falsepattern.endlessids.EndlessIDs; +import com.falsepattern.endlessids.mixin.helpers.IHBMBiomeSyncPacket; +import com.hbm.packet.BiomeSyncPacket; +import io.netty.buffer.ByteBuf; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +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 java.util.Arrays; + +@Mixin(value = BiomeSyncPacket.class, + remap = false) +public abstract class BiomeSyncPacketMixin implements IHBMBiomeSyncPacket { + @Shadow + int chunkX; + @Shadow + int chunkZ; + @Shadow + byte[] biomeArray; + @Shadow + byte blockX; + @Shadow + byte blockZ; + + @Unique + private short eid$biome; + @Unique + private short[] eid$biomeArray; + + @Override + public void eid$setBiome(short biome) { + eid$biome = biome; + } + + @Override + public short eid$getBiome() { + return eid$biome; + } + + @Override + public void eid$setBiomeArray(short[] biomeArray) { + this.biomeArray = EndlessIDs.FAKE_BIOME_ARRAY_PLACEHOLDER; + eid$biomeArray = Arrays.copyOf(biomeArray, biomeArray.length); + } + + @Override + public short[] eid$getBiomeArray() { + return eid$biomeArray; + } + + @Inject(method = "toBytes", + at = @At("HEAD"), + cancellable = true, + require = 1) + private void toBytes(ByteBuf buf, CallbackInfo ci) { + ci.cancel(); + buf.writeInt(chunkX); + buf.writeInt(chunkZ); + if (eid$biomeArray == null) { + buf.writeBoolean(false); + buf.writeShort(eid$biome); + buf.writeByte(blockX); + buf.writeByte(blockZ); + } else { + buf.writeBoolean(true); + for (int i = 0; i < 256; i++) { + buf.writeShort(eid$biomeArray[i]); + } + } + } + + @Inject(method = "fromBytes", + at = @At(value = "HEAD"), + cancellable = true, + require = 1) + private void fromBytes(ByteBuf buf, CallbackInfo ci) { + ci.cancel(); + chunkX = buf.readInt(); + chunkZ = buf.readInt(); + if (!buf.readBoolean()) { + eid$biome = buf.readShort(); + blockX = buf.readByte(); + blockZ = buf.readByte(); + } else { + eid$biomeArray = new short[256]; + for (int i = 0; i < 256; i++) { + eid$biomeArray[i] = buf.readShort(); + } + } + } +} diff --git a/src/main/java/com/falsepattern/endlessids/mixin/mixins/common/biome/ntm/BiomeSyncPacket_HandlerMixin.java b/src/main/java/com/falsepattern/endlessids/mixin/mixins/common/biome/ntm/BiomeSyncPacket_HandlerMixin.java new file mode 100644 index 0000000..6a47ed5 --- /dev/null +++ b/src/main/java/com/falsepattern/endlessids/mixin/mixins/common/biome/ntm/BiomeSyncPacket_HandlerMixin.java @@ -0,0 +1,71 @@ +/* + * EndlessIDs + * + * Copyright (C) 2022-2024 FalsePattern + * All Rights Reserved + * + * The above copyright notice, this permission notice and the words "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, either version 3 of the License, or + * (at your option) any later version. + * + * 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 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.ntm; + +import com.falsepattern.endlessids.mixin.helpers.ChunkBiomeHook; +import com.falsepattern.endlessids.mixin.helpers.stubpackage.com.hbm.packet.BiomeSyncPacket; +import lombok.val; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; + +import net.minecraft.client.Minecraft; +import cpw.mods.fml.common.network.simpleimpl.IMessage; +import cpw.mods.fml.common.network.simpleimpl.IMessageHandler; +import cpw.mods.fml.common.network.simpleimpl.MessageContext; + +@Mixin(value = com.hbm.packet.BiomeSyncPacket.Handler.class, + remap = false) +public abstract class BiomeSyncPacket_HandlerMixin implements IMessageHandler { + @Inject(method = "onMessage(Lcom/hbm/packet/BiomeSyncPacket;Lcpw/mods/fml/common/network/simpleimpl/MessageContext;)Lcpw/mods/fml/common/network/simpleimpl/IMessage;", + at = @At(value = "HEAD"), + cancellable = true, + require = 1) + private void onMessage(com.hbm.packet.BiomeSyncPacket $m, MessageContext ctx, CallbackInfoReturnable cir) { + val world = Minecraft.getMinecraft().theWorld; + val m = (BiomeSyncPacket) $m; + if (world.getChunkProvider().chunkExists(m.chunkX, m.chunkZ)) { + val chunk = world.getChunkFromChunkCoords(m.chunkX, m.chunkZ); + val chunkHook = (ChunkBiomeHook) chunk; + chunk.isModified = true; + val biomeArray = m.eid$getBiomeArray(); + val chunkBiomeArray = chunkHook.getBiomeShortArray(); + if (biomeArray == null) { + val bX = m.blockX & 0xf; + val bZ = m.blockZ & 0xf; + chunkBiomeArray[bZ << 4 | bX] = m.eid$getBiome(); + val cX = (m.chunkX << 4) + bX; + val cZ = (m.chunkZ << 4) + bZ; + world.markBlockRangeForRenderUpdate(cX, 0, cZ, cX, 255, cZ); + } else { + System.arraycopy(biomeArray, 0, chunkBiomeArray, 0, 256); + val cX = m.chunkX << 4; + val cZ = m.chunkZ << 4; + world.markBlockRangeForRenderUpdate(cX, 0, cZ, cX + 15, 255, cZ + 15); + } + } + cir.setReturnValue(null); + } +} diff --git a/src/main/java/com/falsepattern/endlessids/mixin/mixins/common/biome/ntm/WorldUtilMixin.java b/src/main/java/com/falsepattern/endlessids/mixin/mixins/common/biome/ntm/WorldUtilMixin.java new file mode 100644 index 0000000..ca0f99d --- /dev/null +++ b/src/main/java/com/falsepattern/endlessids/mixin/mixins/common/biome/ntm/WorldUtilMixin.java @@ -0,0 +1,103 @@ +/* + * EndlessIDs + * + * Copyright (C) 2022-2024 FalsePattern + * All Rights Reserved + * + * The above copyright notice, this permission notice and the words "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, either version 3 of the License, or + * (at your option) any later version. + * + * 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 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.ntm; + +import com.falsepattern.endlessids.constants.ExtendedConstants; +import com.falsepattern.endlessids.mixin.helpers.ChunkBiomeHook; +import com.falsepattern.endlessids.mixin.helpers.IHBMBiomeSyncPacket; +import com.hbm.packet.BiomeSyncPacket; +import com.hbm.packet.PacketDispatcher; +import com.hbm.world.WorldUtil; +import lombok.val; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +import net.minecraft.world.ChunkCoordIntPair; +import net.minecraft.world.World; +import net.minecraft.world.biome.BiomeGenBase; +import net.minecraft.world.chunk.Chunk; +import cpw.mods.fml.common.network.NetworkRegistry; + +@Mixin(value = WorldUtil.class, + remap = false) +public abstract class WorldUtilMixin { + @Inject(method = "setBiome", + at = @At("HEAD"), + cancellable = true, + require = 1) + private static void extendSetBiome(World world, int x, int z, BiomeGenBase biome, CallbackInfo ci) { + ci.cancel(); + val chunk = world.getChunkFromBlockCoords(x, z); + ((ChunkBiomeHook)chunk).getBiomeShortArray()[(z & 0xf) << 4 | x & 0xf] = + (short) (biome.biomeID & ExtendedConstants.biomeIDMask); + chunk.isModified = true; + } + + @Inject(method = "syncBiomeChange(Lnet/minecraft/world/World;II)V", + at = @At("HEAD"), + cancellable = true, + require = 1) + private static void extendSyncBiomeChange(World world, int x, int z, CallbackInfo ci) { + ci.cancel(); + Chunk chunk = world.getChunkFromBlockCoords(x, z); + val packet = new BiomeSyncPacket(x >> 4, z >> 4, null); + ((IHBMBiomeSyncPacket)packet).eid$setBiomeArray(((ChunkBiomeHook)chunk).getBiomeShortArray()); + PacketDispatcher.wrapper.sendToAllAround(packet, new NetworkRegistry.TargetPoint(world.provider.dimensionId, + x, 128.0F, z, + 1024.0F)); + } + + @Inject(method = "syncBiomeChangeBlock", + at = @At("HEAD"), + cancellable = true, + require = 1) + private static void extendSyncBiomeChangeBlock(World world, int x, int z, CallbackInfo ci) { + ci.cancel(); + Chunk chunk = world.getChunkFromBlockCoords(x, z); + short biome = ((ChunkBiomeHook)chunk).getBiomeShortArray()[(z & 15) << 4 | x & 15]; + val packet = new BiomeSyncPacket(x, z, (byte)0); + ((IHBMBiomeSyncPacket)packet).eid$setBiome(biome); + PacketDispatcher.wrapper.sendToAllAround(packet, new NetworkRegistry.TargetPoint(world.provider.dimensionId, + x, 128.0F, z, + 1024.0F)); + } + + @Inject(method = "syncBiomeChange(Lnet/minecraft/world/World;Lnet/minecraft/world/chunk/Chunk;)V", + at = @At("HEAD"), + cancellable = true, + require = 1) + private static void extendSyncBiomeChange(World world, Chunk chunk, CallbackInfo ci) { + ci.cancel(); + ChunkCoordIntPair coord = chunk.getChunkCoordIntPair(); + val packet = new BiomeSyncPacket(coord.chunkXPos, coord.chunkZPos, null); + ((IHBMBiomeSyncPacket)packet).eid$setBiomeArray(((ChunkBiomeHook)chunk).getBiomeShortArray()); + PacketDispatcher.wrapper.sendToAllAround(packet, new NetworkRegistry.TargetPoint(world.provider.dimensionId, + coord.getCenterXPos(), + 128.0F, + coord.getCenterZPosition(), + 1024.0F)); + } +} 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 89ad855..3af2bc2 100644 --- a/src/main/java/com/falsepattern/endlessids/mixin/plugin/Mixin.java +++ b/src/main/java/com/falsepattern/endlessids/mixin/plugin/Mixin.java @@ -152,6 +152,11 @@ public enum Mixin implements IMixin { GSChunkProviderSpaceLakesMixin(Side.COMMON, condition(() -> GeneralConfig.extendBiome).and(require(TargetedMod.GALAXYSPACE)), "biome.galaxyspace.ChunkProviderSpaceLakesMixin"), GSChunkProviderVenusSSMixin(Side.COMMON, condition(() -> GeneralConfig.extendBiome).and(require(TargetedMod.GALAXYSPACE)), "biome.galaxyspace.ChunkProviderVenusSSMixin"), //endregion GalaxySpace + //region HBM's Nuclear Tech Nod + NTMBiomeSyncPacket_HandlerMixin(Side.COMMON, condition(() -> GeneralConfig.extendBiome).and(require(TargetedMod.HBM_NTM)), "biome.ntm.BiomeSyncPacket_HandlerMixin"), + NTMBiomeSyncPacketMixin(Side.COMMON, condition(() -> GeneralConfig.extendBiome).and(require(TargetedMod.HBM_NTM)), "biome.ntm.BiomeSyncPacketMixin"), + NTMWorldUtilMixin(Side.COMMON, condition(() -> GeneralConfig.extendBiome).and(require(TargetedMod.HBM_NTM)), "biome.ntm.WorldUtilMixin"), + //endregion HBM's Nuclear Tech Nod //region Highlands HighlandsConfigMixin(Side.COMMON, condition(() -> GeneralConfig.extendBiome).and(require(TargetedMod.HIGHLANDS)), "biome.highlands.ConfigMixin"), //endregion Highlands