Skip to content

Instantly share code, notes, and snippets.

@matshou
Last active October 18, 2016 01:02
Show Gist options
  • Save matshou/cbb718033a0334c67265bb1c12b88c54 to your computer and use it in GitHub Desktop.
Save matshou/cbb718033a0334c67265bb1c12b88c54 to your computer and use it in GitHub Desktop.
Example: Packet handler as an outer class
package com.padwolf.minecraft.t1d.packets;
import com.padwolf.minecraft.t1d.refs.Functions;
import cpw.mods.fml.common.network.simpleimpl.IMessage;
import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
import cpw.mods.fml.common.network.simpleimpl.MessageContext;
public class MessagePacketHandler implements IMessageHandler<MessagePacket, IMessage>
{
public MessagePacketHandler() {}
@Override
public IMessage onMessage(MessagePacket message, MessageContext ctx)
{
Functions.sendChatMessage(ctx.getServerHandler().playerEntity, String.format("Received %s from %s", message.data, ctx.getServerHandler().playerEntity.getDisplayName()));
return null; // no response in this case
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment