Jump to content

Recommended Posts

Posted

Hi,

 

I'm trying to make a coremod (to update my tile entity's nbt when an S35PacketUpdateTileEntity is received) since Forge isn't out for 1.8 yet and I have run into a problem with Labels. I need to jump to an existing label, and I'm not sure how. Anyone know how to do this? Heres my code:

@Override
public byte[] transform(String name, String transformedName, byte[] clazz) {
	if (name.equals(NHPCName.replace("/", "."))){
		ClassNode classnode = CoreUtils.getClassNode(clazz);
		MethodNode teMethodNode = CoreUtils.getMethodNode(classnode, handleUpdateTileEntityName, "(Lnet/minecraft/network/play/server/S35PacketUpdateTileEntity;)V");

		InsnList instructions = new InsnList();

		instructions.add(new VarInsnNode(Opcodes.ALOAD, 2));
		instructions.add(new TypeInsnNode(Opcodes.INSTANCEOF, "com/eternaldoom/realmsofchaos/blocks/TileEntityDisplayCase"));
		Label l7 = new Label();
		instructions.add(new JumpInsnNode(Opcodes.IFNE, new LabelNode(l7)));	

		teMethodNode.instructions.insertBefore(getInsertionPoint(teMethodNode), instructions);
    }
	return clazz;
}

I'm trying to patch this method in NetHandlerPlayClient:

public void handleUpdateTileEntity(S35PacketUpdateTileEntity packetIn)
    {
        PacketThreadUtil.func_180031_a(packetIn, this, this.gameController);

        if (this.gameController.theWorld.isBlockLoaded(packetIn.func_179823_a()))
        {
            TileEntity tileentity = this.gameController.theWorld.getTileEntity(packetIn.func_179823_a());
            int i = packetIn.getTileEntityType();

            if (i == 1 && tileentity instanceof TileEntityMobSpawner || i == 2 && tileentity instanceof TileEntityCommandBlock || i == 3 && tileentity instanceof TileEntityBeacon || i == 4 && tileentity instanceof TileEntitySkull || i == 5 && tileentity instanceof TileEntityFlowerPot || i == 6 && tileentity instanceof TileEntityBanner)
            {
                tileentity.readFromNBT(packetIn.getNbtCompound());
            }
        }
    }

I just need to add my tile entity to the if statement. The problem is, I need to jump to the label L7 (tileentity.readFromNBT) and I can't figure out how.

Check out my mod, Realms of Chaos, here.

 

If I helped you, be sure to press the "Thank You" button!

Posted

Never mind, that was a stupid question, all I had to do was call a method in my class. Heres my code if anyone is interested:

if (name.equals(netHandlerPlayClientName.replace("/", "."))){
		ClassNode classnode = CoreUtils.getClassNode(clazz);
		MethodNode teMethodNode = CoreUtils.getMethodNode(classnode, handleUpdateTileEntityName, "(Lnet/minecraft/network/play/server/S35PacketUpdateTileEntity;)V");

		InsnList instructions = new InsnList();

		instructions.add(new VarInsnNode(Opcodes.ALOAD, 2));
		instructions.add(new VarInsnNode(Opcodes.ALOAD, 1));
		instructions.add(new MethodInsnNode(Opcodes.INVOKESTATIC, "com/eternaldoom/realmsofchaos/asm/CoreMethods", "handleTileEntityPackets", "(Lnet/minecraft/tileentity/TileEntity;Lnet/minecraft/network/play/server/S35PacketUpdateTileEntity;)V", false));

		teMethodNode.instructions.insertBefore(getTEInsertionPoint(teMethodNode), instructions);
		return CoreUtils.getBytes(classnode);
    }

Check out my mod, Realms of Chaos, here.

 

If I helped you, be sure to press the "Thank You" button!

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.