Hi, this is my first post.
Been struggling through development of my first mod. I can't seem to figure out why my packets are not sending.
Any help would be appreciated.
In the main mod class I am creating a reference to the channel for sending packets and registering my packet handlers.
Main Class
@Mod(modid = "EpicScavengerQuest", name = "Epic Scavenger Quest", version = "1.7.10 - 0.1")
public class EpicScavengerQuest {
public static SimpleNetworkWrapper network;
@SidedProxy(clientSide ="ft.epicscavengerquest.client.ClientProxy", serverSide = "ft.epicscavengerquest.server.ServerProxy")
public static CommonProxy proxy;
@EventHandler
public void load(FMLInitializationEvent event) {
proxy.registerRenderInformation();
}
@EventHandler
public void preInit(FMLPreInitializationEvent event) {
network = NetworkRegistry.INSTANCE.newSimpleChannel("EpicScavengerQuest");
network.registerMessage(GetQuest.Handler.class, GetQuest.class, 0, Side.SERVER);
FMLCommonHandler.instance().bus().register(new ServerLoginHandler());
FMLCommonHandler.instance().bus().register(new ClientLoginHandler());
}
public EpicScavengerQuest(){
}
}
ClientLoginHandler
The debug message below is sent correctly but the code from the packet does not execute
public class ClientLoginHandler {
public ClientLoginHandler() {
}
@SubscribeEvent
public void onPlayerLogin(PlayerEvent.PlayerLoggedInEvent event) {
System.out.println("This message is being displayed, but the code in the packet below is never executed");
EpicScavengerQuest.network.sendToServer(new GetQuest(1));
}
}
This is the packet class, no errors are reported, no debug messages are sent, other code is not executed.
GetQuest
public class GetQuest implements IMessage {
private int value;
public GetQuest(){ }
public GetQuest(int quest) {
this.value = quest;
}
@Override
public void fromBytes(ByteBuf buf) {
this.value = buf.readInt();
}
@Override
public void toBytes(ByteBuf buf) {
buf.writeInt(this.value);
}
public static class Handler implements IMessageHandler<GetQuest, IMessage> {
@Override
public IMessage onMessage(GetQuest message, MessageContext ctx) {
SendQuest completed = null;
ctx.getServerHandler().playerEntity.addChatMessage(new ChatComponentText("testing GetQuest"));
System.out.println("testin");
/*
try {
completed = new SendQuest(ctx.getServerHandler().playerEntity.getDisplayName(), message.value);
} catch (ClassNotFoundException | IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return completed;
*/
return null;
}
}
}
I've Commented out additional code that is unnecessary to demonstrate the point, but left it in to illustrate what the purpose of the code will be.
onmessage is never called and I'm trying to figure out why. There are no error messages being sent and everything looks correct to me.
thanks in advance.