From 109f65da1e3175f0aa8e49bf3fafa87fe08296bb Mon Sep 17 00:00:00 2001 From: Arminias Date: Sat, 16 Mar 2024 11:01:26 +0100 Subject: [PATCH] Update to CE 2.1.4 --- gradle.properties | 2 +- .../metadata/MetadataExtensionAddon.java | 2 +- .../metadata/MetadataExtensionMod.java | 10 +- .../metadata/mixin/AnvilChunkLoaderMixin.java | 2 - .../metadata/mixin/BlockChestMixin.java | 2 + .../metadata/mixin/BlockPistonBaseMixin.java | 2 +- .../metadata/mixin/NetClientHandlerMixin.java | 12 +- .../mixin/Packet56MapChunksMixin.java | 110 +++++++++++++++++- .../metadata/mixin/TileEntityChestMixin.java | 1 + 9 files changed, 124 insertions(+), 19 deletions(-) diff --git a/gradle.properties b/gradle.properties index f42bd80..6607b1b 100644 --- a/gradle.properties +++ b/gradle.properties @@ -5,7 +5,7 @@ minecraft_version = 1.5.2 yarn_mappings = 1.5.2+build.202201092137 loader_version = 1.0.0 -mod_version = 1.0.0 +mod_version = 1.0.1 maven_group = btw.community archives_base_name = metadata-extension-addon diff --git a/src/main/java/btw/community/arminias/metadata/MetadataExtensionAddon.java b/src/main/java/btw/community/arminias/metadata/MetadataExtensionAddon.java index 9ef6426..857b518 100644 --- a/src/main/java/btw/community/arminias/metadata/MetadataExtensionAddon.java +++ b/src/main/java/btw/community/arminias/metadata/MetadataExtensionAddon.java @@ -7,7 +7,7 @@ public class MetadataExtensionAddon extends BTWAddon { public MetadataExtensionAddon() { - super("Metadata Extension Addon", "1.0", "MetadataExtension"); + super("Metadata Extension Addon", "1.0.1", "MetadataExtension"); } @Override diff --git a/src/main/java/btw/community/arminias/metadata/MetadataExtensionMod.java b/src/main/java/btw/community/arminias/metadata/MetadataExtensionMod.java index bd30411..9ec1d12 100644 --- a/src/main/java/btw/community/arminias/metadata/MetadataExtensionMod.java +++ b/src/main/java/btw/community/arminias/metadata/MetadataExtensionMod.java @@ -1,17 +1,16 @@ package btw.community.arminias.metadata; -import net.devtech.grossfabrichacks.entrypoints.PrePreLaunch; import net.devtech.grossfabrichacks.instrumentation.InstrumentationApi; import net.fabricmc.api.ModInitializer; import net.minecraft.src.Packet52MultiBlockChange; import org.objectweb.asm.tree.*; -import org.spongepowered.asm.mixin.MixinEnvironment; import static org.objectweb.asm.Opcodes.*; -public class MetadataExtensionMod implements ModInitializer, PrePreLaunch { +public class MetadataExtensionMod implements ModInitializer { @Override public void onInitialize() { + System.out.println("Hello Metadata world!"); InstrumentationApi.retransform(Packet52MultiBlockChange.class, (name, node) -> { int count = 0; boolean done = false; @@ -59,9 +58,4 @@ public void onInitialize() { } }); } - - @Override - public void onPrePreLaunch() { - - } } diff --git a/src/main/java/btw/community/arminias/metadata/mixin/AnvilChunkLoaderMixin.java b/src/main/java/btw/community/arminias/metadata/mixin/AnvilChunkLoaderMixin.java index 1fa99e5..83cda54 100644 --- a/src/main/java/btw/community/arminias/metadata/mixin/AnvilChunkLoaderMixin.java +++ b/src/main/java/btw/community/arminias/metadata/mixin/AnvilChunkLoaderMixin.java @@ -24,14 +24,12 @@ private void writeChunkToNBT(Chunk par1Chunk, World par2World, NBTTagCompound pa ((NBTTagCompoundExtension) var11).setLongArray("ExtraData", ((ExtendedBlockStorageExtension) var10).getExtraMetadataArray().data); } - @Inject(method = "readChunkFromNBT", at = @At(value = "INVOKE", target = "Lnet/minecraft/src/ExtendedBlockStorage;setBlocklightArray(Lnet/minecraft/src/NibbleArray;)V", ordinal = 0), locals = LocalCapture.CAPTURE_FAILSOFT, require = 0) //private void readChunkFromNBT(World par1World, NBTTagCompound par2NBTTagCompound, CallbackInfoReturnable cir, int var3, int var4, Chunk var5, NBTTagList var6, int var7, ExtendedBlockStorage[] var8, int var9, int var10, NBTTagCompound var11, int var12, ExtendedBlockStorage var13) { private void readChunkFromNBT(World par1World, NBTTagCompound par2NBTTagCompound, CallbackInfoReturnable cir, int var3, int var4, Chunk var5, NBTTagList var6, byte var7, ExtendedBlockStorage[] var8, boolean var9, int var10, NBTTagCompound var11, byte var12, ExtendedBlockStorage var13) { ((ExtendedBlockStorageExtension) var13).setBlockExtraMetadataArray(new HunkArray(((NBTTagCompoundExtension) var11).getLongArray("ExtraData"), 4)); } - @Inject(method = "readChunkFromNBT", at = @At(value = "INVOKE", target = "Lnet/minecraft/src/ExtendedBlockStorage;setBlocklightArray(Lnet/minecraft/src/NibbleArray;)V", ordinal = 0), locals = LocalCapture.CAPTURE_FAILSOFT, require = 0) private void readChunkFromNBT(World par1World, NBTTagCompound par2NBTTagCompound, CallbackInfoReturnable cir, int var3, int var4, Chunk var5, NBTTagList var6, int var7, ExtendedBlockStorage[] var8, int var9, int var10, NBTTagCompound var11, int var12, ExtendedBlockStorage var13) { ((ExtendedBlockStorageExtension) var13).setBlockExtraMetadataArray(new HunkArray(((NBTTagCompoundExtension) var11).getLongArray("ExtraData"), 4)); diff --git a/src/main/java/btw/community/arminias/metadata/mixin/BlockChestMixin.java b/src/main/java/btw/community/arminias/metadata/mixin/BlockChestMixin.java index b828f63..f79938f 100644 --- a/src/main/java/btw/community/arminias/metadata/mixin/BlockChestMixin.java +++ b/src/main/java/btw/community/arminias/metadata/mixin/BlockChestMixin.java @@ -9,6 +9,8 @@ @Mixin(BlockChest.class) public class BlockChestMixin { + + // TODO Remove @Inject(method = "onBlockActivated", at = @org.spongepowered.asm.mixin.injection.At(value = "HEAD")) private void onBlockActivatedInject(World world, int x, int y, int z, net.minecraft.src.EntityPlayer player, int side, float hitX, float hitY, float hitZ, CallbackInfoReturnable cir) { System.out.println(((WorldExtension) world).getBlockExtraMetadata(x, y, z)); diff --git a/src/main/java/btw/community/arminias/metadata/mixin/BlockPistonBaseMixin.java b/src/main/java/btw/community/arminias/metadata/mixin/BlockPistonBaseMixin.java index 1e64c9c..ebbb40d 100644 --- a/src/main/java/btw/community/arminias/metadata/mixin/BlockPistonBaseMixin.java +++ b/src/main/java/btw/community/arminias/metadata/mixin/BlockPistonBaseMixin.java @@ -105,7 +105,7 @@ else if (par5 == 1) var15.clearPistonTileEntity(); var11 = var15.getStoredBlockID(); var12 = var15.getBlockMetadata(); - extra = ((TileEntityPistonExtension) par1World).getBlockExtraMetadata(); + extra = ((TileEntityPistonExtension) var15).getBlockExtraMetadata(); var13 = true; } } diff --git a/src/main/java/btw/community/arminias/metadata/mixin/NetClientHandlerMixin.java b/src/main/java/btw/community/arminias/metadata/mixin/NetClientHandlerMixin.java index 1bf325d..3b9a873 100644 --- a/src/main/java/btw/community/arminias/metadata/mixin/NetClientHandlerMixin.java +++ b/src/main/java/btw/community/arminias/metadata/mixin/NetClientHandlerMixin.java @@ -18,7 +18,7 @@ public class NetClientHandlerMixin { @Shadow private WorldClient worldClient; - @Inject(method = "handleMultiBlockChange", at = @At(value = "CONSTANT", args = "intValue=255", ordinal = 0, shift = At.Shift.BY, by = 3), locals = LocalCapture.CAPTURE_FAILHARD) + @Inject(method = "handleMultiBlockChange", at = @At(value = "CONSTANT", args = "intValue=255", ordinal = 0, shift = At.Shift.BY, by = 3), locals = LocalCapture.CAPTURE_FAILSOFT, require = 0) private void handleMultiBlockChangeInject(Packet52MultiBlockChange par1Packet52MultiBlockChange, CallbackInfo ci, int var2, int var3, DataInputStream var4, int var5, short var6, short var7, int var8, int var9, int var10, int var11, int var12) { try { int extraMeta = var4.readInt(); @@ -28,6 +28,16 @@ private void handleMultiBlockChangeInject(Packet52MultiBlockChange par1Packet52M } } + @Inject(method = "handleMultiBlockChange", at = @At(value = "CONSTANT", args = "intValue=255", ordinal = 0, shift = At.Shift.BY, by = 3), locals = LocalCapture.CAPTURE_FAILSOFT, require = 0) + private void handleMultiBlockChangeInject2(Packet52MultiBlockChange par1Packet52MultiBlockChange, CallbackInfo ci, int var2, int var3, DataInputStream var4, int var5, int var6, int var7, int var8, int var9, int var10, int var11, int var12) { + try { + int extraMeta = var4.readInt(); + ((WorldClientExtension) this.worldClient).setBlockAndMetadataAndExtraMetadataAndInvalidate(var10 + var2, var12, var11 + var3, var8, var9, extraMeta); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + @Redirect(method = "handleMultiBlockChange", at = @At(value = "INVOKE", target = "Lnet/minecraft/src/WorldClient;setBlockAndMetadataAndInvalidate(IIIII)Z")) private boolean handleMultiBlockChangeRedirect(WorldClient worldClient, int par1, int par2, int par3, int par4, int par5) { return false; diff --git a/src/main/java/btw/community/arminias/metadata/mixin/Packet56MapChunksMixin.java b/src/main/java/btw/community/arminias/metadata/mixin/Packet56MapChunksMixin.java index 9d877d8..5ac0380 100644 --- a/src/main/java/btw/community/arminias/metadata/mixin/Packet56MapChunksMixin.java +++ b/src/main/java/btw/community/arminias/metadata/mixin/Packet56MapChunksMixin.java @@ -2,18 +2,118 @@ import net.minecraft.src.Packet56MapChunks; import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.Constant; -import org.spongepowered.asm.mixin.injection.ModifyConstant; +import org.spongepowered.asm.mixin.Overwrite; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.injection.*; + +import java.io.DataInputStream; +import java.io.IOException; +import java.util.zip.DataFormatException; +import java.util.zip.Inflater; @Mixin(Packet56MapChunks.class) public class Packet56MapChunksMixin { - @ModifyConstant(method = "readPacketData", constant = @Constant(intValue = 196864)) + @Shadow private int dataLength; + + @Shadow private boolean skyLightSent; + + @Shadow private int[] chunkPostX; + + @Shadow private int[] chunkPosZ; + + @Shadow public int[] field_73590_a; + + @Shadow public int[] field_73588_b; + + @Shadow private byte[][] field_73584_f; + + @Shadow private static byte[] chunkDataNotCompressed; + + /*@ModifyConstant(method = "readPacketData", constant = @Constant(intValue = 196864)) private static int readPacketDataInject(int constant) { return constant * 2; - } + }*/ - @ModifyConstant(method = "readPacketData", constant = @Constant(intValue = 8192)) + /*@Group(name = "readPacketDataInject2", min = 1, max = 1) + @ModifyConstant(method = "readPacketData", constant = @Constant(intValue = 8192, ordinal = 0)) private static int readPacketDataInject2(int constant) { return constant + 8 * 2048; } + + @Group(name = "readPacketDataInject2", min = 1, max = 1) + @ModifyConstant(method = "readPacketData", constant = @Constant(intValue = 2048, ordinal = 0), + slice = @Slice(to = @At(value = "CONSTANT", args = "intValue=256", ordinal = 0))) + private static int readPacketDataInject22(int constant) { + return constant + 8 * 2048; + }*/ + + /** + * @author Arminias + */ + @Overwrite + public void readPacketData(DataInputStream par1DataInputStream) throws IOException + { + short var2 = par1DataInputStream.readShort(); + this.dataLength = par1DataInputStream.readInt(); + this.skyLightSent = par1DataInputStream.readBoolean(); + this.chunkPostX = new int[var2]; + this.chunkPosZ = new int[var2]; + this.field_73590_a = new int[var2]; + this.field_73588_b = new int[var2]; + this.field_73584_f = new byte[var2][]; + + if (chunkDataNotCompressed.length < this.dataLength) + { + chunkDataNotCompressed = new byte[this.dataLength]; + } + + par1DataInputStream.readFully(chunkDataNotCompressed, 0, this.dataLength); + byte[] var3 = new byte[196864 * 2 * var2]; + Inflater var4 = new Inflater(); + var4.setInput(chunkDataNotCompressed, 0, this.dataLength); + + try + { + var4.inflate(var3); + } + catch (DataFormatException var12) + { + throw new IOException("Bad compressed data format"); + } + finally + { + var4.end(); + } + + int var5 = 0; + + for (int var6 = 0; var6 < var2; ++var6) + { + this.chunkPostX[var6] = par1DataInputStream.readInt(); + this.chunkPosZ[var6] = par1DataInputStream.readInt(); + this.field_73590_a[var6] = par1DataInputStream.readShort(); + this.field_73588_b[var6] = par1DataInputStream.readShort(); + int var7 = 0; + int var8 = 0; + int var9; + + for (var9 = 0; var9 < 16; ++var9) + { + var7 += this.field_73590_a[var6] >> var9 & 1; + var8 += this.field_73588_b[var6] >> var9 & 1; + } + + var9 = (2048 * 4 + 8 * 2048) * var7 + 256; + var9 += 2048 * var8; + + if (this.skyLightSent) + { + var9 += 2048 * var7; + } + + this.field_73584_f[var6] = new byte[var9]; + System.arraycopy(var3, var5, this.field_73584_f[var6], 0, var9); + var5 += var9; + } + } } diff --git a/src/main/java/btw/community/arminias/metadata/mixin/TileEntityChestMixin.java b/src/main/java/btw/community/arminias/metadata/mixin/TileEntityChestMixin.java index e903470..d07c0e4 100644 --- a/src/main/java/btw/community/arminias/metadata/mixin/TileEntityChestMixin.java +++ b/src/main/java/btw/community/arminias/metadata/mixin/TileEntityChestMixin.java @@ -11,6 +11,7 @@ @Mixin(TileEntityChest.class) public class TileEntityChestMixin extends TileEntity { + // TODO Remove @Inject(method = "openChest", at = @At(value = "HEAD")) private void openChestInject(CallbackInfo ci) { WorldExtension.cast(worldObj).setBlockExtraMetadata(this.xCoord, this.yCoord, this.zCoord, WorldExtension.cast(worldObj).getBlockExtraMetadata(this.xCoord, this.yCoord, this.zCoord) - 1);