Jump to content

Handling Messages From Server


Twijn

Recommended Posts

I am a moderator on a server, and when 100+ people are on it gets a bit hard to keep up on chat.  So, what I thought was I could make a Mod that will display messages on the top left of the screen that possibly breaks chat rules, ex. profanity, to where I can just press a button and it will say something in chat or press another button and it will be dismissed. I'm somewhat decent at writing Bukkit plugins, so Forge can't be that different? I was clearly wrong.

 

So to restate what I want to do, if someone in the server chat says something, I want a notification on the top right of the screen, similar to how achievements are shown. This will have 2 buttons to either accept the warning for them and say something in chat or to entirely dismiss the notification.  I know how to do all of the filters and everything, so all I really need to know is:

 

-How to get the chat events from the server (and getting the message from it)

-How to display a notification on the side

-How to send a message to the server

 

This mod will not be installed server-side.

Link to comment
Share on other sites

For 1 and 2: Learn Forge events. @SubscribeEvent.

 

1. Since "This mod will not be installed server-side.", you probably want o catch client-received chat msgs:

* Use ClientChatReceivedEvent

 

2.

* Use RenderGameOverlayEvent.

Notes:

- Pick Pre or Post. (rather post)

- Use event.type (choose one of phases, otherwise you will render many times).

- event also ships scale param (which apparently not many know, so just saying).

 

3. Since mod is not on server, I assume you are asking about chat messages:

Lookup GuiScreen#sendChatMessage(String).

Or more directly: Minecraft#thePlayer#sendChatMessage(String).

 

Additional notes: Since mod will be client-only, you can use: @Mod(clientSideOnly = true).

 

Oh and this is 1.8+ ONLY (some of this doesn't exist earlier).

1.7.10 is no longer supported by forge, you are on your own.

Link to comment
Share on other sites

If the mod is not installed server side, then I'm pretty sure you cannot get chat messages other than the ones you yourself send or receive.

 

Also, I'm not sure if all chat messages are guaranteed to be routed through the server, either, for example any sent by mods directly on a client's machine, but I don't think you'd be interested in those anyway, right?

Link to comment
Share on other sites

For 1 and 2: Learn Forge events. @SubscribeEvent.

 

1. Since "This mod will not be installed server-side.", you probably want o catch client-received chat msgs:

* Use ClientChatReceivedEvent

 

2.

* Use RenderGameOverlayEvent.

Notes:

- Pick Pre or Post. (rather post)

- Use event.type (choose one of phases, otherwise you will render many times).

- event also ships scale param (which apparently not many know, so just saying).

 

3. Since mod is not on server, I assume you are asking about chat messages:

Lookup GuiScreen#sendChatMessage(String).

Or more directly: Minecraft#thePlayer#sendChatMessage(String).

 

Additional notes: Since mod will be client-only, you can use: @Mod(clientSideOnly = true).

 

Oh and this is 1.8+ ONLY (some of this doesn't exist earlier).

 

I've found everything, except I can't figure out how to do the RenderGameOverlay thing.  Do you have any code showing it being used, or something?

Link to comment
Share on other sites

1. Register event class.

2.

@SubscribeEvent
public void onRenderOvelay(RenderGameOverlayEvent.Post event)
{
	if (event.type == ElementType.EXPERIENCE || event.type == ElementType.FOOD)
	{
		event.setCanceled(true); // You can use event like this to cancel rendering of food and exp
	}

	if (event.type == ElementType.HEALTH)
	{
		int w = event.resolution.getScaledWidth(); // the resolution I mentioned
		int h = event.resolution.getScaledHeight();

		// You can draw whatever you want here.

		// big note regarding this part: If you ever change bound texture during rendering event you need to set it back to icons, otherwise you will mess up rest of UI. Similar rules apply to GL states (e.g alpha, colorization), etc.
		this.mc.getTextureManager().bindTexture(Gui.icons); // not needed, example per comment above.
	}
}

1.7.10 is no longer supported by forge, you are on your own.

Link to comment
Share on other sites

Check out literally any part of vanilla gui code.

 

Rendering (GL): You can use GL directly or utilize Tesselator+WorldRenderer with nice vertex formats.

 

Rendering (textures): First you bind texture using Minecraft#getTextureManager().bindTexture(ResourceLocation).

Then you can draw it using Gui#drawTexturedModalRect(x, y, u, v, width, height).

Do note that this method expects a .png ResourceLocation with size of multiple of 256.

It will draw that .png on x/y coords (from top left) from u/v of .png file (from top/left) with width and height.

 

Rendering Items/Blocks/Entities - for entities there is utility (lookup player inventory gui), for items and blocks you need to go into ItemRenderer, I don't remember right now.

 

Point of interest: Useful methods re placed in Gui which you can extend and use. I personally rewritten them to be static and to accept RGBA and doubles.

1.7.10 is no longer supported by forge, you are on your own.

Link to comment
Share on other sites

Check out literally any part of vanilla gui code.

 

Rendering (GL): You can use GL directly or utilize Tesselator+WorldRenderer with nice vertex formats.

 

Rendering (textures): First you bind texture using Minecraft#getTextureManager().bindTexture(ResourceLocation).

Then you can draw it using Gui#drawTexturedModalRect(x, y, u, v, width, height).

Do note that this method expects a .png ResourceLocation with size of multiple of 256.

It will draw that .png on x/y coords (from top left) from u/v of .png file (from top/left) with width and height.

 

Rendering Items/Blocks/Entities - for entities there is utility (lookup player inventory gui), for items and blocks you need to go into ItemRenderer, I don't remember right now.

 

Point of interest: Useful methods re placed in Gui which you can extend and use. I personally rewritten them to be static and to accept RGBA and doubles.

 

Ok, but where do you actually put the textures in the files to where it can reach it? It keeps saying file not found.

Link to comment
Share on other sites

With questions like that you should seriously consider using google.

 

Every direct and somewhat common question (in this case - resource - which are used by every mod ever) is almost always answered somewhere on google.

 

Anyway - each mod has Domain (modid) which directs to: resources folder.

Basically you make this somewhere:

public static final ResourceLocation	txt = new ResourceLocation(ModID + ":" + "textures/gui/something.png");

This will point to:

<src/main/resources>/assets/[modid]/textures/gui/something.png // Where <...> is part of workspace, I wrote it for (in)convenience.

And you can sue "txt" as texture in #bindTexture().

1.7.10 is no longer supported by forge, you are on your own.

Link to comment
Share on other sites

"It doesn't work" says nothing. Always post full code on given case.

 

Nevermind, I got it.  It was just me being stupid and not realizing that the tutorials I was looking at was extending "Gui"...

 

The thing that I'm stuck on now is being able to get a message that the player (From typing it in) sends to the server, and cancelling it if it has some character in front of it. Basically, I want to make commands like they do in hack mods (for example .help). Except it of course won't be used to hack and stuff. :P

Link to comment
Share on other sites

The thing that I'm stuck on now is being able to get a message that the player (From typing it in) sends to the server, and cancelling it if it has some character in front of it. Basically, I want to make commands like they do in hack mods (for example .help). Except it of course won't be used to hack and stuff. :P

 

There's no way to intercept chat messages on the client before they're sent to the server without some ASM or possibly messing around with Netty to intercept the packet.

 

Why not just create an

ICommand

and register it with

ClientCommandHandler

.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Link to comment
Share on other sites

The thing that I'm stuck on now is being able to get a message that the player (From typing it in) sends to the server, and cancelling it if it has some character in front of it. Basically, I want to make commands like they do in hack mods (for example .help). Except it of course won't be used to hack and stuff. :P

 

There's no way to intercept chat messages on the client before they're sent to the server without some ASM or possibly messing around with Netty to intercept the packet.

 

Why not just create an

ICommand

and register it with

ClientCommandHandler

.

 

Okay, I'll try that.

Link to comment
Share on other sites

The thing that I'm stuck on now is being able to get a message that the player (From typing it in) sends to the server, and cancelling it if it has some character in front of it. Basically, I want to make commands like they do in hack mods (for example .help). Except it of course won't be used to hack and stuff. :P

 

There's no way to intercept chat messages on the client before they're sent to the server without some ASM or possibly messing around with Netty to intercept the packet.

 

Why not just create an

ICommand

and register it with

ClientCommandHandler

.

 

Okay, I've done all of that and it seems to work just fine! The one thing I want to know now is how to get a list of all of the players then allow it to autofill to those players on the command

Link to comment
Share on other sites

Since this is client side mod - the world on your client (Minecraft#theWorld) is only part of world you see.

 

It will only ever "contain" entities (including players) that you actually see (in view range). This list is available in World#getLoadedEntityList().

Only those entity instances exist on clients.

 

For players there is exception - you don't have their instances, but you hold their profiles. We are talking about "tab" player list.

Lookup GuiPlayerTabOverlay.

1.7.10 is no longer supported by forge, you are on your own.

Link to comment
Share on other sites

I've googled GuiPlayerTabOverlay and nothing useful is found? Do you possibly have a link?

 

Also, will having "custom" tab menus affect it? (For example, things like this: http://prntscr.com/anfbta )

 

It's a class. Look at it in your IDE.

 

Custom menus won't affect it, the raw data will always be made available by Minecraft.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Link to comment
Share on other sites

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • https://pastebin.com/VwpAW6PX My game crashes upon launch when trying to implement the Oculus mod to this mod compilation, above is the crash report, I do not know where to begin to attempt to fix this issue and require assistance.
    • https://youtube.com/shorts/gqLTSMymgUg?si=5QOeSvA4TTs-bL46
    • CubeHaven is a SMP server with unique features that can't be found on the majority of other servers! Java: MC.CUBEHAVEN.NET Bedrock: MC.CUBEHAVEN.NET:19132 3 different stores: - CubeHaven Store: Our store to purchase using real money. - Bitcoin Store: Store for Bitcoin. Bitcoin can be earned from playing the server. Giving options for players if they want to spend real money or grind to obtain exclusive packages. - Black Market: A hidden store for trading that operates outside our traditional stores, like custom enchantments, exclusive items and more. Some of our features include: Rank Up: Progress through different ranks to unlock new privileges and perks. 📈 Skills: RPG-style skill system that enhances your gaming experience! 🎮 Leaderboards: Compete and shine! Top players are rewarded weekly! 🏆 Random Teleporter: Travel instantly across different worlds with a click! 🌐 Custom World Generation: Beautifully generated world. 🌍 Dungeons: Explore challenging and rewarding dungeons filled with treasures and monsters. 🏰 Kits: Unlock ranks and gain access to various kits. 🛠️ Fishing Tournament: Compete in a friendly fishing tournament! 🎣 Chat Games: Enjoy games right within the chat! 🎲 Minions: Get some help from your loyal minions. 👥 Piñata Party: Enjoy a festive party with Piñatas! 🎉 Quests: Over 1000 quests that you can complete! 📜 Bounty Hunter: Set a bounty on a player's head. 💰 Tags: Displayed on nametags, in the tab list, and in chat. 🏷️ Coinflip: Bet with other players on coin toss outcomes, victory, or defeat! 🟢 Invisible & Glowing Frames: Hide your frames for a cleaner look or apply a glow to it for a beautiful look. 🔲✨[ Player Warp: Set your own warp points for other players to teleport to. 🌟 Display Shop: Create your own shop and sell to other players! 🛒 Item Skins: Customize your items with unique skins. 🎨 Pets: Your cute loyal companion to follow you wherever you go! 🐾 Cosmetics: Enhance the look of your character with beautiful cosmetics! 💄 XP-Bottle: Store your exp safely in a bottle for later use! 🍶 Chest & Inventory Sorting: Keep your items neatly sorted in your inventory or chest! 📦 Glowing: Stand out from other players with a colorful glow! ✨ Player Particles: Over 100 unique particle effects to show off. 🎇 Portable Inventories: Over virtual inventories with ease. 🧳 And a lot more! Become part of our growing community today! Discord: https://cubehaven.net/discord Java: MC.CUBEHAVEN.NET Bedrock: MC.CUBEHAVEN.NET:19132
    • # Problematic frame: # C [libopenal.so+0x9fb4d] It is always the same issue - this refers to the Linux OS - so your system may prevent Java from working   I am not familiar with Linux - check for similar/related issues  
  • Topics

×
×
  • Create New...

Important Information

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