Posted June 8, 201510 yr How would I be able to get what the player is typing in the chat bar, before they send it. I'm working on an autocorrect mod for my friend. Is there a way to do this or not? Thanks
June 8, 201510 yr I don't think there is hook for before sending anything. Depending how autocorrecting your autocorrect will be you might do some tricks. Minecraft client knows current Gui opened. (mc.currentScreen). There is ClientTickEvent that is fired by FML client-side every phase: START and END of tick (choose one always). You can check if gui instanceof GuiChat and get currently written text box and apply autocorrect, problem is you would need to do it in some tricky way to not interfere with player's input. (Obviously not every tick). If you can't think of a way to do it (I can, but don't know what are you planning) then you are left with implementing custom GuiChat (there is also GuiChatNew, look it up) and using GuiOpenEvent - replace GuiChat with yours. (better way I think, if you are planning that big feature, yet - more coding). EDIT Obviously, you can also use other events - Input events, e.g "click 'Insert' to check spelling". 1.7.10 is no longer supported by forge, you are on your own.
June 8, 201510 yr EDIT Obviously, you can also use other events - Input events, e.g "click 'Insert' to check spelling". Actually, I don't think you can. Last time I tried I think I found that input events aren't fired when chat gui is open. I think your suggestion about using tick event is probably better. Check out my tutorials here: http://jabelarminecraft.blogspot.com/
June 8, 201510 yr Author I don't think there is hook for before sending anything. Depending how autocorrecting your autocorrect will be you might do some tricks. Minecraft client knows current Gui opened. (mc.currentScreen). There is ClientTickEvent that is fired by FML client-side every phase: START and END of tick (choose one always). You can check if gui instanceof GuiChat and get currently written text box and apply autocorrect, problem is you would need to do it in some tricky way to not interfere with player's input. (Obviously not every tick). If you can't think of a way to do it (I can, but don't know what are you planning) then you are left with implementing custom GuiChat (there is also GuiChatNew, look it up) and using GuiOpenEvent - replace GuiChat with yours. (better way I think, if you are planning that big feature, yet - more coding). EDIT Obviously, you can also use other events - Input events, e.g "click 'Insert' to check spelling". I was thinking of having a guibutton popup above the word as you're typing it and that way if you spelled the word incorrectly and want to correct it you can click the button that you want. I'm interested in hearing what you had in mind though. If you would like to tell me that is, I don't mind :>
June 8, 201510 yr That would be actually possible without overriding whole Gui. Right now I can think of at least few different combinations of tools that would allow you to do it. 1. Replace GuiChat with your own Chat - do whatever you want then (literally, whatever). * Use GuiOpenEvent to check if event.gui is chat, and open other (your gui). - Requires knowledge about coding Gui. 2. Utilize few hooks to do it. * Use ClientTickeEvent - Save String with text typed in chat in last tick. If the text changed in current tick (lower that to e.g 20 ticks for performance), scan changed string and pull out all new-typed words (so that you won't have to auto-correct ones that were typed before), make shitload of String operations and autocorrect stuff. Replace word with corrected string and set chat field to edited string. * Use mc.currentScreen (inside TickEvent from above) - get buttonList from current GuiChat and add new Button to every new-typed word. You can easily put that button e.g above the word. * You can use FontRenderer to get length of given text. * Adding button will do nothing - you just added it, now you need to add action to it: Use ActionPerformedEvent, check if clicked button is your new button - perform auto-correcting. Then you can remove that button. The actual problem is that last time I was doing stuff (I replaced GuiChat) in this field was year ago or more. Things might have changed, what I am not sure of is the fact if you can actually add/remove button in any moment. Pretty much all I can tell, lookup net.minecraftforge.client.event if you are looking for something more. 1.7.10 is no longer supported by forge, you are on your own.
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.