mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-15 17:45:06 +00:00
Overlooked chat message support *sigh*. Fixes wierd mods that communicate through custom
chat messages rather than anything else. Hi Superior enchanting!
This commit is contained in:
1 parent
a697d043fc
commit
8fccfa21df
10 files changed
+126
-45
No files matched your search
@@ -321,19 +321,18 @@ public abstract class BaseMod implements cpw.mods.fml.common.modloader.BaseModPr
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Only implemented on the client side
|
* Only implemented on the client side
|
||||||
* {@link #onChatMessageReceived(EntityPlayer, Packet3Chat)}
|
* {@link #serverChat(EntityPlayer, Packet3Chat)}
|
||||||
*
|
*
|
||||||
* @param text
|
* @param text
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void receiveChatPacket(String text)
|
public void clientChat(String text)
|
||||||
{
|
{
|
||||||
// TODO
|
// TODO
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Only called on the client side
|
* Called client side to receive a custom payload for this mod
|
||||||
* {@link #onPacket250Received(EntityPlayer, Packet250CustomPayload)}
|
|
||||||
*
|
*
|
||||||
* @param packet
|
* @param packet
|
||||||
*/
|
*/
|
||||||
@@ -407,17 +406,6 @@ public abstract class BaseMod implements cpw.mods.fml.common.modloader.BaseModPr
|
|||||||
return getName() + " " + getVersion();
|
return getName() + " " + getVersion();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Called when a 250 packet is received on a channel registered to this mod
|
|
||||||
*
|
|
||||||
* @param source
|
|
||||||
* @param payload
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public void onPacket250Received(EntityPlayer source, Packet250CustomPayload payload)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when a chat message is received. Return true to stop further processing
|
* Called when a chat message is received. Return true to stop further processing
|
||||||
*
|
*
|
||||||
@@ -425,20 +413,10 @@ public abstract class BaseMod implements cpw.mods.fml.common.modloader.BaseModPr
|
|||||||
* @param chat
|
* @param chat
|
||||||
* @return true if you want to consume the message so it is not available for further processing
|
* @return true if you want to consume the message so it is not available for further processing
|
||||||
*/
|
*/
|
||||||
public boolean onChatMessageReceived(EntityPlayer source, Packet3Chat chat)
|
@Override
|
||||||
|
public void serverChat(NetServerHandler source, String message)
|
||||||
{
|
{
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
/**
|
|
||||||
* Called when a server command is received
|
|
||||||
* @param command
|
|
||||||
* @return true if you want to consume the message so it is not available for further processing
|
|
||||||
*/
|
|
||||||
public boolean onServerCommand(String command, String sender, ICommandManager listener)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when a new client logs in.
|
* Called when a new client logs in.
|
||||||
*
|
*
|
||||||
@@ -460,17 +438,6 @@ public abstract class BaseMod implements cpw.mods.fml.common.modloader.BaseModPr
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* Called when a client changes dimensions on the server.
|
|
||||||
*
|
|
||||||
* @param player
|
|
||||||
*/
|
|
||||||
public void onClientDimensionChanged(EntityPlayer player)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* Spawn the entity of the supplied type, if it is your mod's
|
* Spawn the entity of the supplied type, if it is your mod's
|
||||||
|
|||||||
@@ -77,15 +77,13 @@ public interface BaseModProxy
|
|||||||
|
|
||||||
public abstract void onClientLogin(EntityPlayer player);
|
public abstract void onClientLogin(EntityPlayer player);
|
||||||
|
|
||||||
public abstract void onPacket250Received(EntityPlayer source, Packet250CustomPayload payload);
|
|
||||||
|
|
||||||
public abstract void serverDisconnect();
|
public abstract void serverDisconnect();
|
||||||
|
|
||||||
public abstract void serverConnect(NetHandler handler);
|
public abstract void serverConnect(NetHandler handler);
|
||||||
|
|
||||||
public abstract void receiveCustomPacket(Packet250CustomPayload packet);
|
public abstract void receiveCustomPacket(Packet250CustomPayload packet);
|
||||||
|
|
||||||
public abstract void receiveChatPacket(String text);
|
public abstract void clientChat(String text);
|
||||||
|
|
||||||
public abstract void onItemPickup(EntityPlayer player, ItemStack item);
|
public abstract void onItemPickup(EntityPlayer player, ItemStack item);
|
||||||
|
|
||||||
@@ -93,4 +91,6 @@ public interface BaseModProxy
|
|||||||
double entY, double entZ);
|
double entY, double entZ);
|
||||||
|
|
||||||
public abstract void serverCustomPayload(NetServerHandler handler, Packet250CustomPayload packet);
|
public abstract void serverCustomPayload(NetServerHandler handler, Packet250CustomPayload packet);
|
||||||
|
|
||||||
|
public abstract void serverChat(NetServerHandler source, String message);
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
package cpw.mods.fml.common.modloader;
|
||||||
|
|
||||||
|
import net.minecraft.src.NetHandler;
|
||||||
|
import net.minecraft.src.NetServerHandler;
|
||||||
|
import net.minecraft.src.Packet3Chat;
|
||||||
|
import cpw.mods.fml.common.network.IChatListener;
|
||||||
|
|
||||||
|
public class ModLoaderChatListener implements IChatListener
|
||||||
|
{
|
||||||
|
|
||||||
|
private BaseModProxy mod;
|
||||||
|
|
||||||
|
public ModLoaderChatListener(BaseModProxy mod)
|
||||||
|
{
|
||||||
|
this.mod = mod;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Packet3Chat serverChat(NetHandler handler, Packet3Chat message)
|
||||||
|
{
|
||||||
|
mod.serverChat((NetServerHandler)handler, message.field_73476_b);
|
||||||
|
return message;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Packet3Chat clientChat(NetHandler handler, Packet3Chat message)
|
||||||
|
{
|
||||||
|
mod.clientChat(message.field_73476_b);
|
||||||
|
return message;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -40,6 +40,7 @@ import cpw.mods.fml.common.IPickupNotifier;
|
|||||||
import cpw.mods.fml.common.IWorldGenerator;
|
import cpw.mods.fml.common.IWorldGenerator;
|
||||||
import cpw.mods.fml.common.Loader;
|
import cpw.mods.fml.common.Loader;
|
||||||
import cpw.mods.fml.common.TickType;
|
import cpw.mods.fml.common.TickType;
|
||||||
|
import cpw.mods.fml.common.network.IChatListener;
|
||||||
import cpw.mods.fml.common.network.IConnectionHandler;
|
import cpw.mods.fml.common.network.IConnectionHandler;
|
||||||
import cpw.mods.fml.common.network.IGuiHandler;
|
import cpw.mods.fml.common.network.IGuiHandler;
|
||||||
import cpw.mods.fml.common.network.IPacketHandler;
|
import cpw.mods.fml.common.network.IPacketHandler;
|
||||||
@@ -197,4 +198,9 @@ public class ModLoaderHelper
|
|||||||
mlmc.addServerCommand(command);
|
mlmc.addServerCommand(command);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static IChatListener buildChatListener(BaseModProxy mod)
|
||||||
|
{
|
||||||
|
return new ModLoaderChatListener(mod);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -530,6 +530,7 @@ public class ModLoaderModContainer implements ModContainer
|
|||||||
GameRegistry.registerCraftingHandler(ModLoaderHelper.buildCraftingHelper(mod));
|
GameRegistry.registerCraftingHandler(ModLoaderHelper.buildCraftingHelper(mod));
|
||||||
GameRegistry.registerPickupHandler(ModLoaderHelper.buildPickupHelper(mod));
|
GameRegistry.registerPickupHandler(ModLoaderHelper.buildPickupHelper(mod));
|
||||||
GameRegistry.registerDispenserHandler(ModLoaderHelper.buildDispenseHelper(mod));
|
GameRegistry.registerDispenserHandler(ModLoaderHelper.buildDispenseHelper(mod));
|
||||||
|
NetworkRegistry.instance().registerChatListener(ModLoaderHelper.buildChatListener(mod));
|
||||||
NetworkRegistry.instance().registerConnectionHandler(ModLoaderHelper.buildConnectionHelper(mod));
|
NetworkRegistry.instance().registerConnectionHandler(ModLoaderHelper.buildConnectionHelper(mod));
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ import net.minecraft.src.NetworkManager;
|
|||||||
import net.minecraft.src.Packet;
|
import net.minecraft.src.Packet;
|
||||||
import net.minecraft.src.Packet1Login;
|
import net.minecraft.src.Packet1Login;
|
||||||
import net.minecraft.src.Packet250CustomPayload;
|
import net.minecraft.src.Packet250CustomPayload;
|
||||||
|
import net.minecraft.src.Packet3Chat;
|
||||||
import net.minecraft.src.ServerConfigurationManager;
|
import net.minecraft.src.ServerConfigurationManager;
|
||||||
import net.minecraft.src.World;
|
import net.minecraft.src.World;
|
||||||
import net.minecraft.src.WorldType;
|
import net.minecraft.src.WorldType;
|
||||||
@@ -390,4 +391,9 @@ public class FMLNetworkHandler
|
|||||||
}
|
}
|
||||||
return add;
|
return add;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Packet3Chat handleChatMessage(NetHandler handler, Packet3Chat chat)
|
||||||
|
{
|
||||||
|
return NetworkRegistry.instance().handleChat(handler, chat);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
package cpw.mods.fml.common.network;
|
||||||
|
|
||||||
|
import net.minecraft.src.NetHandler;
|
||||||
|
import net.minecraft.src.NetServerHandler;
|
||||||
|
import net.minecraft.src.Packet3Chat;
|
||||||
|
|
||||||
|
public interface IChatListener
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Called when there is a chat message received on the server
|
||||||
|
* @param handler
|
||||||
|
* @param message
|
||||||
|
*/
|
||||||
|
public Packet3Chat serverChat(NetHandler handler, Packet3Chat message);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called when there is a chat message recived on the client
|
||||||
|
*
|
||||||
|
* @param handler
|
||||||
|
* @param message
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public Packet3Chat clientChat(NetHandler handler, Packet3Chat message);
|
||||||
|
}
|
||||||
@@ -16,6 +16,7 @@ import net.minecraft.src.NetServerHandler;
|
|||||||
import net.minecraft.src.NetworkManager;
|
import net.minecraft.src.NetworkManager;
|
||||||
import net.minecraft.src.Packet1Login;
|
import net.minecraft.src.Packet1Login;
|
||||||
import net.minecraft.src.Packet250CustomPayload;
|
import net.minecraft.src.Packet250CustomPayload;
|
||||||
|
import net.minecraft.src.Packet3Chat;
|
||||||
import net.minecraft.src.World;
|
import net.minecraft.src.World;
|
||||||
|
|
||||||
import com.google.common.base.Charsets;
|
import com.google.common.base.Charsets;
|
||||||
@@ -36,6 +37,10 @@ import cpw.mods.fml.common.ModContainer;
|
|||||||
import cpw.mods.fml.common.Side;
|
import cpw.mods.fml.common.Side;
|
||||||
import cpw.mods.fml.common.network.FMLPacket.Type;
|
import cpw.mods.fml.common.network.FMLPacket.Type;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author cpw
|
||||||
|
*
|
||||||
|
*/
|
||||||
public class NetworkRegistry
|
public class NetworkRegistry
|
||||||
{
|
{
|
||||||
|
|
||||||
@@ -56,6 +61,7 @@ public class NetworkRegistry
|
|||||||
private Set<IConnectionHandler> connectionHandlers = Sets.newLinkedHashSet();
|
private Set<IConnectionHandler> connectionHandlers = Sets.newLinkedHashSet();
|
||||||
private Map<ModContainer, IGuiHandler> serverGuiHandlers = Maps.newHashMap();
|
private Map<ModContainer, IGuiHandler> serverGuiHandlers = Maps.newHashMap();
|
||||||
private Map<ModContainer, IGuiHandler> clientGuiHandlers = Maps.newHashMap();
|
private Map<ModContainer, IGuiHandler> clientGuiHandlers = Maps.newHashMap();
|
||||||
|
private List<IChatListener> chatListeners = Lists.newArrayList();
|
||||||
|
|
||||||
public static NetworkRegistry instance()
|
public static NetworkRegistry instance()
|
||||||
{
|
{
|
||||||
@@ -144,6 +150,15 @@ public class NetworkRegistry
|
|||||||
connectionHandlers.add(handler);
|
connectionHandlers.add(handler);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Register a chat listener
|
||||||
|
* @param listener
|
||||||
|
*/
|
||||||
|
public void registerChatListener(IChatListener listener)
|
||||||
|
{
|
||||||
|
chatListeners.add(listener);
|
||||||
|
}
|
||||||
|
|
||||||
void playerLoggedIn(EntityPlayerMP player, NetServerHandler netHandler, NetworkManager manager)
|
void playerLoggedIn(EntityPlayerMP player, NetServerHandler netHandler, NetworkManager manager)
|
||||||
{
|
{
|
||||||
generateChannelRegistration(player, netHandler, manager);
|
generateChannelRegistration(player, netHandler, manager);
|
||||||
@@ -308,4 +323,18 @@ public class NetworkRegistry
|
|||||||
IGuiHandler handler = clientGuiHandlers.get(mc);
|
IGuiHandler handler = clientGuiHandlers.get(mc);
|
||||||
FMLCommonHandler.instance().showGuiScreen(handler.getClientGuiElement(modGuiId, player, world, x, y, z));
|
FMLCommonHandler.instance().showGuiScreen(handler.getClientGuiElement(modGuiId, player, world, x, y, z));
|
||||||
}
|
}
|
||||||
|
public Packet3Chat handleChat(NetHandler handler, Packet3Chat chat)
|
||||||
|
{
|
||||||
|
Side s = Side.CLIENT;
|
||||||
|
if (handler instanceof NetServerHandler)
|
||||||
|
{
|
||||||
|
s = Side.SERVER;
|
||||||
|
}
|
||||||
|
for (IChatListener listener : chatListeners)
|
||||||
|
{
|
||||||
|
chat = s.isClient() ? listener.clientChat(handler, chat) : listener.serverChat(handler, chat);
|
||||||
|
}
|
||||||
|
|
||||||
|
return chat;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -9,7 +9,15 @@
|
|||||||
import net.minecraft.server.MinecraftServer;
|
import net.minecraft.server.MinecraftServer;
|
||||||
|
|
||||||
public class NetServerHandler extends NetHandler
|
public class NetServerHandler extends NetHandler
|
||||||
@@ -957,6 +959,11 @@
|
@@ -591,6 +593,7 @@
|
||||||
|
|
||||||
|
public void func_72481_a(Packet3Chat p_72481_1_)
|
||||||
|
{
|
||||||
|
+ p_72481_1_ = FMLNetworkHandler.handleChatMessage(this, p_72481_1_);
|
||||||
|
if (this.field_72574_e.func_71126_v() == 2)
|
||||||
|
{
|
||||||
|
this.func_72567_b(new Packet3Chat("Cannot send chat message."));
|
||||||
|
@@ -957,6 +960,11 @@
|
||||||
|
|
||||||
public void func_72501_a(Packet250CustomPayload p_72501_1_)
|
public void func_72501_a(Packet250CustomPayload p_72501_1_)
|
||||||
{
|
{
|
||||||
@@ -21,7 +29,7 @@
|
|||||||
DataInputStream var2;
|
DataInputStream var2;
|
||||||
ItemStack var3;
|
ItemStack var3;
|
||||||
ItemStack var4;
|
ItemStack var4;
|
||||||
@@ -1029,4 +1036,11 @@
|
@@ -1029,4 +1037,11 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -41,7 +41,15 @@
|
|||||||
this.func_72552_c(new Packet204ClientInfo(this.field_72563_h.field_71474_y.field_74363_ab, this.field_72563_h.field_71474_y.field_74339_e, this.field_72563_h.field_71474_y.field_74343_n, this.field_72563_h.field_71474_y.field_74344_o, this.field_72563_h.field_71474_y.field_74318_M));
|
this.func_72552_c(new Packet204ClientInfo(this.field_72563_h.field_71474_y.field_74363_ab, this.field_72563_h.field_71474_y.field_74339_e, this.field_72563_h.field_71474_y.field_74343_n, this.field_72563_h.field_71474_y.field_74344_o, this.field_72563_h.field_71474_y.field_74318_M));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1167,6 +1173,11 @@
|
@@ -605,6 +611,7 @@
|
||||||
|
|
||||||
|
public void func_72481_a(Packet3Chat p_72481_1_)
|
||||||
|
{
|
||||||
|
+ p_72481_1_ = FMLNetworkHandler.handleChatMessage(this, p_72481_1_);
|
||||||
|
this.field_72563_h.field_71456_v.func_73827_b().func_73765_a(p_72481_1_.field_73476_b);
|
||||||
|
}
|
||||||
|
|
||||||
|
@@ -1167,6 +1174,11 @@
|
||||||
|
|
||||||
public void func_72501_a(Packet250CustomPayload p_72501_1_)
|
public void func_72501_a(Packet250CustomPayload p_72501_1_)
|
||||||
{
|
{
|
||||||
@@ -53,7 +61,7 @@
|
|||||||
if ("MC|TPack".equals(p_72501_1_.field_73630_a))
|
if ("MC|TPack".equals(p_72501_1_.field_73630_a))
|
||||||
{
|
{
|
||||||
String[] var2 = (new String(p_72501_1_.field_73629_c)).split("\u0000");
|
String[] var2 = (new String(p_72501_1_.field_73629_c)).split("\u0000");
|
||||||
@@ -1211,4 +1222,10 @@
|
@@ -1211,4 +1223,10 @@
|
||||||
{
|
{
|
||||||
return this.field_72555_g;
|
return this.field_72555_g;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user