Jump to content

Recommended Posts

Posted

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.

Posted

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.

Posted

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?

Posted

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?

Posted

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.

Posted

Okay, so I got that, however, I'm still somewhat confused on what I put to make a new GUI, and where I actually put the GUI textures I want to use.

Posted

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.

Posted

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.

Posted

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.

Posted

"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

Posted

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.

Posted

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.

Posted

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

Posted

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.

Posted

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.

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



×
×
  • Create New...

Important Information

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