And yes, I have a println in the method(handleClientMessage) in the Message that never triggers. Any information about this or help would be greatly appreciated.
You have your messages set up wrong. You should have two classes for each message, IMessage and IMessageHandler. In the registry call use (YourHandler.class, YourMessage.Class, messageCounter++, Side.Client)
Rollback Post to RevisionRollBack
"If It Is To Be It Is Up To Me" simple quote and I don't know where it comes from but I enjoy it.
Current Mod: Armerger | Light Drafter
package net.ilexiconn.llibrary.common.message;
import cpw.mods.fml.common.network.simpleimpl.IMessage;
import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
import cpw.mods.fml.common.network.simpleimpl.MessageContext;
import cpw.mods.fml.common.network.simpleimpl.SimpleNetworkWrapper;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.ilexiconn.llibrary.LLibrary;
import net.minecraft.entity.player.EntityPlayer;
/**
* {@link IMessage} and {@link IMessageHandler} implemented in the same class.
*
* @param <M> The message to receive data from. This should be the same class. Make sure to use this, otherwise you can't access your variables in the message!
* @author iLexiconn
* @since 0.5.0
*/
public abstract class AbstractMessage<M extends AbstractMessage> implements IMessage, IMessageHandler<M, IMessage> {
/**
* Register the message to the {@link cpw.mods.fml.common.network.simpleimpl.SimpleNetworkWrapper}.
*
* @param networkWrapper The {@link cpw.mods.fml.common.network.simpleimpl.SimpleNetworkWrapper} instance.
* @param clazz The AbstractMessage class to register.
* @param id The id to use for the registration of the message.
* @param side The {@link cpw.mods.fml.relauncher.Side} to register the message on.
*/
public static <T extends AbstractMessage<T> & IMessageHandler<T, IMessage>> void registerMessage(SimpleNetworkWrapper networkWrapper, Class<T> clazz, int id, Side side) {
networkWrapper.registerMessage(clazz, clazz, id, side);
}
protected MessageContext messageContext;
@Override
public IMessage onMessage(M message, MessageContext ctx) {
messageContext = ctx;
if (ctx.side.isClient()) {
handleClientMessage(message, LLibrary.proxy.getClientPlayer());
} else {
handleServerMessage(message, ctx.getServerHandler().playerEntity);
}
return null;
}
/**
* Executes when message received on CLIENT side. Never use fields directly from the class you're in, but use data from the 'message' field instead.
*
* @param message The message instance with all variables.
* @param player The client player entity.
*/
@SideOnly(Side.CLIENT)
public abstract void handleClientMessage(M message, EntityPlayer player);
/**
* Executes when message received on SERVER side. Never use fields directly from the class you're in, but use data from the 'message' field instead.
*
* @param message The message instance with all variables.
* @param player The player who sent the message to the server.
*/
public abstract void handleServerMessage(M message, EntityPlayer player);
}
I've never seen it done that way but you can't actually process anything minecraft related inside of the network thread, you have to create a runnable and assign that to either the Client thread or the Server thread.
I recommend following this tutorial, it's not any more code just set up differently.
Rollback Post to RevisionRollBack
"If It Is To Be It Is Up To Me" simple quote and I don't know where it comes from but I enjoy it.
Current Mod: Armerger | Light Drafter
I've never seen it done that way but you can't actually process anything minecraft related inside of the network thread, you have to create a runnable and assign that to either the Client thread or the Server thread.
I recommend following this tutorial, it's not any more code just set up differently.
Regardless if you've seen it or no it works in other situations. for example, putting
public void onLivingUpdate() {
super.onLivingUpdate();
Revival.channel.sendToAll(new MessageFoodParticles(this.getEntityId()));</div>
...
works as well as one would assume it would. So it's not the registry of the message, it's something else.
onLivingUpdate gets called on both client and server so your message gets created on the server and fails, but then it gets created on the client side and runs.
updateTask() only gets called on the server so it will fail.
I've never seen it done that way but you can't actually process anything minecraft related inside of the network thread, you have to create a runnable and assign that to either the Client thread or the Server thread.
This only applies to 1.8+, it's not the case in 1.7.10.
I would highly recommend updating to 1.8.9/1.9, though.
Rollback Post to RevisionRollBack
Chisel Facades: For all your decorative pipe-hiding needs.
Please don't PM me to ask for help or to join your mod development team. Asking your question in a public thread preserves it for people who are having the same problem in the future. I'm not interested in developing mods with people.
Example Code:
This packet is registered as:
And yes, I have a println in the method(handleClientMessage) in the Message that never triggers. Any information about this or help would be greatly appreciated.
You have your messages set up wrong. You should have two classes for each message, IMessage and IMessageHandler. In the registry call use (YourHandler.class, YourMessage.Class, messageCounter++, Side.Client)
Current Mod: Armerger | Light Drafter
Abstract Message counst as both.
I've never seen it done that way but you can't actually process anything minecraft related inside of the network thread, you have to create a runnable and assign that to either the Client thread or the Server thread.
I recommend following this tutorial, it's not any more code just set up differently.
Current Mod: Armerger | Light Drafter
Regardless if you've seen it or no it works in other situations. for example, putting
works as well as one would assume it would. So it's not the registry of the message, it's something else.
If it is working it works because of coincidence.
onLivingUpdate gets called on both client and server so your message gets created on the server and fails, but then it gets created on the client side and runs.
updateTask() only gets called on the server so it will fail.
You are using this in your handle client message
You need to be using this
Current Mod: Armerger | Light Drafter
Well, I cant believe I made such a stupid mistake >.<. Thanks for bearing with me.
This only applies to 1.8+, it's not the case in 1.7.10.
I would highly recommend updating to 1.8.9/1.9, though.
Chisel Facades: For all your decorative pipe-hiding needs.
Please don't PM me to ask for help or to join your mod development team. Asking your question in a public thread preserves it for people who are having the same problem in the future. I'm not interested in developing mods with people.