package com.slugterra.packets;

import com.slugterra.entity.EntityMecha;

import io.netty.buffer.ByteBuf;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraftforge.fml.common.network.ByteBufUtils;
import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler;
import net.minecraftforge.fml.common.network.simpleimpl.MessageContext;

public class MechaAnimPacket implements IMessage {

	private String text;

	public MechaAnimPacket() { }

	public MechaAnimPacket(String text) {
		this.text = text;
	}

	@Override
	public void fromBytes(ByteBuf buf) {
		text = ByteBufUtils.readUTF8String(buf); // this class is very useful in general for writing more complex objects
	}

	@Override
	public void toBytes(ByteBuf buf) {
		ByteBufUtils.writeUTF8String(buf, text);
	}

	public static class Handler implements IMessageHandler<MechaAnimPacket, IMessage> {

		@Override
		public IMessage onMessage(MechaAnimPacket message, MessageContext ctx) {
			EntityPlayerMP player = ctx.getServerHandler().playerEntity;
			((EntityMecha)player.getRidingEntity()).senseJump();
			System.out.println(String.format("Received %s from %s", message.text, ctx.getServerHandler().playerEntity.getDisplayName()));
			return null; // no response in this case
		}
	}
}
@@ -1097,22 +1097,12 @@
 %0A%09%09%09
-((EntityMecha)
+if (
 play
@@ -1125,149 +1125,87 @@
 ty()
-).senseJump();%0A%09%09%09System.out.println(String.format(%22Received %25s from %25s%22, message.text, ctx.getServerHandler().playerEntity.getDisplayName())
+ instanceof EntityMecha)%0A%09%09%09%09((EntityMecha)player.getRidingEntity()).senseJump(
 );%0A%09

Add safety check and remove debug message