Jump to content

Chronicide

Members
  • Posts

    13
  • Joined

  • Last visited

Converted

  • Gender
    Undisclosed
  • Personal Text
    I am new!

Chronicide's Achievements

Tree Puncher

Tree Puncher (2/8)

0

Reputation

  1. Hey Reika, Thanks for your help. Between your post and a tutorial I found about packets, I was able to create and send the packet I need. Everything is flowing properly now, but I still can't get the chat to trigger the redstone power. I've managed to track it down to my packet not referencing the world that has my block's metadata. right now, I have two ways of triggering my block's power. I can right click it, or I can type a chat message. Right clicking it works, chatting doesn't. I printed the world.toString() for both, and on the one that works has a worldserver id, while the one that doesn't (from my chat) uses a world id. So I need my packet to get a reference to the current world server that the tile is in... regardless of whether I'm playing in SSP or SMP. I've tried a ton of stuff, but nothing seems to work. Any ideas?
  2. After some more thinking, I realize that when going from client to server (or vise versa) you need to work in packets. That being said, I still have no idea as to how to go about this. Any suggestions?
  3. Hey everyone, I've made a new power supplying block. When I began, I made it behave like a button by overriding onBlockActivated and managing the power duration with a combination of the block metadata and an overridden updateTick. It worked perfectly. I placed the new block, added some redstone wires next to it, right clicked, and the redstone wire lit up for the proper number of ticks. So, I was happy with that. Now I needed to change the trigger from a right click to a chat event. The idea is to have a power supply that activates when a keyword is said within a specific range of it. This sounds like a job for a tile entity. I try to develop incrementally (as I'm learning to mod as I go, and don't want to commit to some code until I know it works) Eventually, I want a gui like the sign to set the password when the block is placed, but for now, I'm just hardcoding the password to see if I can get it to work. Here is my tile entity: public class TileEntityPasswordBlock extends TileEntity { public String password = "Testing"; public void writeToNBT(NBTTagCompound par1NBTTagCompound) { super.writeToNBT(par1NBTTagCompound); par1NBTTagCompound.setString("Password", this.password); } public void readFromNBT(NBTTagCompound par1NBTTagCompound) { super.readFromNBT(par1NBTTagCompound); this.password = par1NBTTagCompound.getString("Password"); if (this.password.length() > 15) { this.password = this.password.substring(0, 15); } } public Packet getDescriptionPacket() { NBTTagCompound nbtTag = new NBTTagCompound(); this.writeToNBT(nbtTag); return new Packet132TileEntityData(this.xCoord, this.yCoord, this.zCoord, 1, nbtTag); } public void onDataPacket(INetworkManager net, Packet132TileEntityData packet) { readFromNBT(packet.customParam1); } public void checkChatForPassword(String chat) { if (this.worldObj != null) { this.blockType = this.getBlockType(); if (this.blockType != null && this.blockType instanceof PasswordBlock) { ((PasswordBlock)this.blockType).passwordDetected(this.worldObj, this.xCoord, this.yCoord, this.zCoord); } } } } Note that I'm not bothering to check that chat message for the password yet. For now, I just want it to light up when anything is said in chat. My password block extends BlockContainer and overrides createNewTileEntity, and I've added a method to trigger the redstone that is called by the tile entity: @Override public TileEntity createNewTileEntity(World world) { return new TileEntityPasswordBlock(); } @SideOnly(Side.CLIENT) public void passwordDetected(World world, int x, int y, int z) { int i = world.getBlockMetadata(x, y, z); world.setBlockMetadataWithNotify(x, y, z, 10, 0); if (i == 0) { world.notifyBlocksOfNeighborChange(x, y, z, this.blockID); } world.scheduleBlockUpdate(x, y, z, this.blockID, 0); } Now I just need to call checkChatForPassword on every TileEntityPasswordBlock and pass in the chat. I've already created a ServerChatEvent handler that intercepts chat, loops through players and delivers the chat to only those players within a given distance of the sender. I thought that this would be the ideal place to loop through my tile entities and and pass the current chat to their checkChatForPassword. Unfortunately, 1) I could not find how to list the tile entites, and 2) the PasswordBlocks' passwordDetected is ClientOnly, and the ServerChatEvent works on the server thread. Even if I did hook it up, it wouldn't work because it need to be on the client thread. How can I achieve this? I'm running low on ideas here, and would appreciate anything you guys could offer. Thanks! - Scott (This is my second try at posting this... the first doesn't look to have worked. If I notice two copies of this thread, I'll be sure to delete one.)
  4. Zetal, I can't thank you enough. Months and months of making a small change, compiling, obfuscating, zipping, and installing my mod to test the tiny change. I can't believe how stupid I've been. Also, being able to read the console from the server allowed me to catch a bug in a utility class that prevented my chat handing event from working. Issue is resolved, and I'd have never figured it out without your help. Thanks!
  5. I haven't changed anything in the event handler class. I just changed where I registered it. public class ServerChatEventHandler { @ForgeSubscribe public void onServerChatEvent(ServerChatEvent event) { EntityPlayerMP sender = event.player; List<EntityPlayerMP> players = MinecraftServer.getServer().getConfigurationManager().playerEntityList; for (EntityPlayerMP receiver : players) { receiver.sendChatToPlayer("You hear " + sender.username + " say '" + event.message); } } } My register code (in the mod's main class... along side @PreInit, @Init, @PostInit: private static MinecraftServer server; @ServerStarting public void serverStart(FMLServerStartingEvent event) { server = event.getServer(); MinecraftForge.EVENT_BUS.register(new ServerChatEventHandler()); } And not to show how slow I am, but how do I run the server in eclipse? It would be awesome not to have to compile to test the server components.
  6. I have to concede my ignorance here. I tried putting that serverStart code in my mod's main class, and it didn't do anything. Where am I supposed to put that? Is there any example or tutorial out there for how to properly build a mod that works both in SMP and SSP? Just for the sake of clarity, I've added the following to my mod's main class: private static MinecraftServer server; @ServerStarting public void serverStart(FMLServerStartingEvent event) { server = event.getServer(); MinecraftForge.EVENT_BUS.register(new ServerChatEventHandler()); }
  7. Hey everyone, The part of my mod that I'm working on involves the server handling all chat messages. I want the server to receive the chat message, and decide who it should go to. Right now, as an initial proof of concept, I'm trying to have the server intercept the message and then hand deliver it to everyone with some text appended. Once I have that working, I'll focus on my logic around deciding who each message should go to. Here's what I have: public class ServerChatEventHandler { @ForgeSubscribe public void onServerChatEvent(ServerChatEvent event) { EntityPlayerMP sender = event.player; List<EntityPlayerMP> players = MinecraftServer.getServer().getConfigurationManager().playerEntityList; for (EntityPlayerMP receiver : players) { receiver.sendChatToPlayer("You hear " + sender.username + " say '" + event.message); } } } then in my mod class: @Init public void load(FMLInitializationEvent event) { proxy.registerRenderers(); MinecraftForge.EVENT_BUS.register(new ServerChatEventHandler()); } This works as expected on a single player game... since I don't cancel the event, I receive the original message and the one sent by the server. When I pack up my mod and deploy it to my test server, it swallows all chat messages. I type something in chat, and it disappears. Does anyone know what I'm doing wrong? My code as it is shouldn't prevent the original chat message from going through, but it does just that when used on in SMP. I would appreciate any advice anyone could offer. Thanks! - Scott
  8. That's a chat listener, not a handler. So, I can modify the result of all chat (i.e., change all bad words to !@#$%^&) but I can't handle who receives the chat message. The chat message goes to everyone. Packet3Chat can't be cancelled either, so the listener must return something. I'm looking for a handler hook, so that I can have complete control over how a chat message is actually delivered. I hope that helps make the destinction... Chronicide
  9. Hi there, I've been trying to find some what tohandle chat as well. Would you be willing to explain how you injected your own handler? Nothing that I've tried has come close to working. Thanks for your time!
  10. Hey LexManos, thanks for the reply. Is there some way that I can subclass the chat packet and handle it myself? I traced a chat message via debug, and it looks like it originates in the ChatGUI, is passed to the EntityClientPlayerMP, then wraps the message in a Packet3Chat object and adds it the the MemoryCollection cue. From there, the NetServerHandler handles the chat. I'm new to minecraft modding... is there some way to jump in at any of the above stages to take control? I can extend any of the above methods that I want, but without some way to call the overridden method it won't do any good. I was thinking that I may be able to create my own chat gui/packet/network handler, but at that point I'm essentailly recreating forge. I saw that there was a PR for a chat handler hook that was closed, so I'm not sure If I should make a new request. Thanks again for your help!
  11. Thanks TheDragon. No worries, I'm new to this too,and I appreciate any thoughts anyone can offer! =) I had a similar idea, but there was a couple of issues with that. First, you cannot send an empty Packet3Chat. You can initialize it with an empty string, but it will still send the empty string, so everyone will receive a blank row in their chat. The second and more troublesome issue is that there is still no way to selectively send the Packet3Chat to only certain players. It's an all or nothing sort of deal (at least, that's the case with adding a class that implements IChatListener... I'm hoping there is another method that will work). Even if I decided I could live with players receiving blank rows in their chat, I still have no way to limit it to those players within a given radius of the sender. Again, I appreciate the idea. I'm thinking that I might have to subclass some other class, like NetHandler or something. I just need to find the class that is responsible for actually delivering the chat to everyone. if I can subclass it, I hope that I can override the default behaviour. Does anyone have a good grasp of the lifecycle of a chat message (as in, which classes/methods are involved)?
  12. Hello again, thanks for getting back to me so quickly! I was able to create a class that implements IChatListener, register it and modify chat programatically. My problem now is that I have no choice but to return a Packet3Chat object, which is then pushed to all players. I have no way to limit the chat to only certain players. Is there something that I'm missing?
  13. Hi everyone, I've been reading through the javadocs, but I can't find any way to use forge to handle chat. Specifically, I want to detect when a player sends a general chat message, intercept the message and only deliver it to players within a certain radius of the sender. Most of that would be fairly straightforward, if only I could find where to initially intercept all chat (and how to detect which player sent the mesage_. Does anyone know how to do this with the latest forge/minecraft. Thanks! - Chronicide
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.