Jump to content

Recommended Posts

Posted

Hi there,

 

Is it possible to render text on item textures like this: http://i.imgur.com/Y0k4yEN.png (made in paint.net). Would this just be the case of using RenderGameOverlay and scaling down the text and making the pos the current hotbar slot? or is there a better way.

 

Thanks for your time.

 

Edit: I'm pretty sure RenderGameOverlay won't work because if I opened my inventory, that guiscreen(I think thats what it is anyway) would be a "higher" "layer". I would also like to draw text on items in my main inventory (Not just hotbar). My guess/assumption is it could be done by overlaying text on the item texture? not sure though.

 

Again, thanks if anyone checked out the thread.

Posted

1. If you want items to render like that for any possible gui (mod or not) then only way would be to ASM vanilla rendering methods.

 

2. If you want to do this per-gui, e.g be ONLY rendering like that in GameOverlay (normal game view) then you would have to use RenderGameOverlay and cancel hotbar rendering, then basically re-render it yourself using vanilla-like methods (I mean - literally copy rendering methods and edit them to display additional stuff).

 

3. You can try tricks like that for any known gui (inventory, creative, furnace, workbench, etc...) by replacing its GUI with OpenGui event (not sure naming), but that will always require you to remake stuff and will be incomatybile with other mods that do similar.

 

So basically - yeah: ASM (1) or not-fully-gratifying-simple-solution (2) or crazy-works-of-a-mad-man (3) (you don't want this).

 

EDIT

Additional note, since all that is not strongly backed by MC source. It might be that 2D item rendering methods are defined in instance object (meaning, they are not static). In that case you could replace (game startup) given object with your own extension that applies changes to some methods.

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

Posted

Thanks for the detailed reply!

 

So to sum up what I'm trying to do: I want to render the remaining durability "on top" of every item that the player has that has durability. I think making this work on EVERY gui is a little overkill for a small tweak (visually anyway) that this is, so I would probably be happy for it just to render when the player is looking at their own inventory. So the two situations would be:

 

1: Looking in your own inventory (not even player inventories attached to other guis).

2: Rendering the damage of items on the hotbar in the GameOverlay.

 

For situation 2, I pretty much know how to achieve that, would handling situation 1 be the same as your 3rd method?

 

Again, thanks for the time.

 

Edit: Wording

Posted

Solution 3 is writing new classes and replacing things when the player opens a GUI.  You'd have to write a new ChestGUI, new WorkbenchGUI, FurnaceGui, InventoryGUI, and so on.

 

Solution 1 will always show the additional text, doesn't matter who's gui, where it is, anything.

 

Just because of what you're trying to do, I actually would recommend looking into ASMing the item renderer function.  It's not only the simplest, but most effective.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted

2. If you want to do this per-gui, e.g be ONLY rendering like that in GameOverlay (normal game view) then you would have to use RenderGameOverlay and cancel hotbar rendering, then basically re-render it yourself using vanilla-like methods (I mean - literally copy rendering methods and edit them to display additional stuff).

 

3. You can try tricks like that for any known gui (inventory, creative, furnace, workbench, etc...) by replacing its GUI with OpenGui event (not sure naming), but that will always require you to remake stuff and will be incomatybile with other mods that do similar.

 

2. Tells you quite well what to do (been there, done that).

 

3. Also tells you quite well what to do. To be more helpful: You want to extends GuiInventory.class and:

- Normally I'd say: "drawSlot" - but it's private, so that gives us bigger problems with hackier solutions:

- Override "public void drawScreen(int mouseX, int mouseY, float partialTicks)". drawScreen handles a lot of stuff, which also includes calling this thing:

for (int i1 = 0; i1 < this.inventorySlots.inventorySlots.size(); ++i1)
        {
            Slot slot = (Slot)this.inventorySlots.inventorySlots.get(i1);
            this.drawSlot(slot); /////////////////////////////////////////////// THIS THING!

            if (this.isMouseOverSlot(slot, mouseX, mouseY) && slot.canBeHovered())
            {
                this.theSlot = slot;
                GlStateManager.disableLighting();
                GlStateManager.disableDepth();
                int j1 = slot.xDisplayPosition;
                k1 = slot.yDisplayPosition;
                GlStateManager.colorMask(true, true, true, false);
                this.drawGradientRect(j1, k1, j1 + 16, k1 + 16, -2130706433, -2130706433);
                GlStateManager.colorMask(true, true, true, true);
                GlStateManager.enableLighting();
                GlStateManager.enableDepth();
            }
        }

 

So in your extending class you will want to literally copy drawScreen method from super class (mind that GuiInventory extends InventoryEffectRenderer extends GuiContainer which requires you to ALSO copy code from InventoryEffectRenderer#drawScreen).

 

Then on stage of calling this.drawSlot, you will simply make a call to custom-made method that will be (literally) a copy of vanilla method (the private one) with small change as to what to render (add your string rendering there).

 

As said - to actually replace Gui with another Gui you need to use proper event in which you will open your custom extension instead of vanilla. (search in client events, I don't remember exact event names, but somewhere aroung OpenGuiEvent).

 

That's it. Similar logic goes with (2.) - look how GuiIngame (GuiIngameForge? I don't remember now.) handles hotbar.

 

 

*Insta-read Draco's post*

Goddamit, well-said (true that). But alredy wrote that shit above so here it goes. :D

 

EDIT

Oh and P.S: If you decide to go with ASM - yeah, you want to manipulate GuiContainer#drawSlot or replace call to it in GuiContainer#drawScreen with call to your custom method. (I mean, that would do nicely for all containers in game :D, but there are more cases).

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

Posted

Thanks both of you for your help.

 

I have briefly looked into ASM and I feel it's a little overkill for what I'm trying to achieve (Also past my Java knowledge)

 

I decided to implement the feature on the GameOverlay: http://i.imgur.com/AduYrDh.png and it works great but with one problem. The text renders behind the items (You probably noticed that though). is there a way in the RenderGameOverlay to specify zIndex?

 

And again, thanks for everybodys help. It will be really helpful in future if I want to implement something that requires ASM.

Posted

You can use GlStateManager to translate the text like so:

 

GlStateManager.pushMatrix();
GlStateManager.translatef(0, 0, 50);
// draw text
GlStateManager.popMatrix();

 

To those whom it may concern, perhaps there could be an ItemStackRenderEvent fired every time an ItemStack is rendered, no matter what inventory.

Don't make mods if you don't know Java.

Check out my website: http://shadowfacts.net

Developer of many mods

Posted

I have briefly looked into ASM and I feel it's a little overkill for what I'm trying to achieve (Also past my Java knowledge)

 

ASM is very powerful and very hard to think in terms of writing.  Everyone who does it inserts as extremely few bytes as possible, usually an INVOKE_VIRTUAL call to a static method that you can write in regular Java.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted

To those whom it may concern, perhaps there could be an ItemStackRenderEvent fired every time an ItemStack is rendered, no matter what inventory.

 

I can't seem to find a reference to this event?

 

That's because it doesn't exist. shadowfacts was suggesting it be added to Forge.

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

Oh whoops, I read his reply incorrectly. However it does sound like a great idea for rendering to all itemstacks easily.

 

Also using GlStateManager.translate solved my problem with the text rendering.. Thanks everyone for their input.

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.