Skip to content

Commit

Permalink
Update to CE 2.1.4
Browse files Browse the repository at this point in the history
  • Loading branch information
Arminias committed Mar 16, 2024
1 parent 02b4e85 commit 109f65d
Show file tree
Hide file tree
Showing 9 changed files with 124 additions and 19 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -59,9 +58,4 @@ public void onInitialize() {
}
});
}

@Override
public void onPrePreLaunch() {

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<Chunk> 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<Chunk> 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<Chunk> 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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Boolean> cir) {
System.out.println(((WorldExtension) world).getBlockExtraMetadata(x, y, z));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 109f65d

Please sign in to comment.