Jump to content

[1.8.8] [SOLVED] Overlay String on itemstack


ADonkeyTaboggan

Recommended Posts

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

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

    • Try deliting feur builder  It caused this issue in my modpack
    • I am not using hardcoded recipes, I'm using Vanilla's already existing code for leather armor dying. (via extending and implementing DyeableArmorItem / DyeableLeatherItem respectively) I have actually figured out that it's something to do with registering item colors to the ItemColors instance, but I'm trying to figure out where exactly in my mod's code I would be placing a call to the required event handler. Unfortunately the tutorial is criminally undescriptive. The most I've found is that it has to be done during client initialization. I'm currently trying to do the necessary setup via hijacking the item registry since trying to modify the item classes directly (via using SubscribeEvent in the item's constructor didn't work. Class so far: // mrrp mrow - mcmod item painter v1.0 - catzrule ch package catzadvitems.init; import net.minecraft.client.color.item.ItemColors; import net.minecraft.world.item.Item; import net.minecraftforge.registries.ObjectHolder; import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent; import net.minecraftforge.fml.common.Mod; import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.client.event.ColorHandlerEvent; import catzadvitems.item.DyeableWoolArmorItem; @Mod.EventBusSubscriber(bus = Mod.EventBusSubscriber.Bus.MOD) public class Painter { @ObjectHolder("cai:dyeable_wool_chestplate") public static final Item W_CHEST = null; @ObjectHolder("cai:dyeable_wool_leggings") public static final Item W_LEGS = null; @ObjectHolder("cai:dyeable_wool_boots") public static final Item W_SOCKS = null; public Painter() { // left blank, idk if forge throws a fit if constructors are missing, not taking the chance of it happening. } @SubscribeEvent public static void init(FMLClientSetupEvent event) { new Painter(); } @Mod.EventBusSubscriber private static class ForgeBusEvents { @SubscribeEvent public static void registerItemColors(ColorHandlerEvent.Item event) { ItemColors col = event.getItemColors(); col.register(DyeableUnderArmorItem::getItemDyedColor, W_CHEST, W_LEGS, W_SOCKS); //placeholder for other dye-able items here later.. } } } (for those wondering, i couldn't think of a creative wool helmet name)
    • nvm found out it was because i had create h and not f
    • Maybe there's something happening in the 'leather armor + dye' recipe itself that would be updating the held item texture?
    • @SubscribeEvent public static void onRenderPlayer(RenderPlayerEvent.Pre e) { e.setCanceled(true); model.renderToBuffer(e.getPoseStack(), pBuffer, e.getPackedLight(), 0f, 0f, 0f, 0f, 0f); //ToaPlayerRenderer.render(); } Since getting the render method from a separate class is proving to be bit of a brick wall for me (but seems to be the solution in older versions of minecraft/forge) I've decided to try and pursue using the renderToBuffer method directly from the model itself. I've tried this route before but can't figure out what variables to feed it for the vertexConsumer and still can't seem to figure it out; if this is even a path to pursue.  The vanilla model files do not include any form of render methods, and seem to be fully constructed from their layer definitions? Their renderer files seem to take their layers which are used by the render method in the vanilla MobRenderer class. But for modded entities we @Override this function and don't have to feed the method variables because of that? I assume that the render method in the extended renderer takes the layer definitions from the renderer classes which take those from the model files. Or maybe instead of trying to use a render method I should be calling the super from the renderer like   new ToaPlayerRenderer(context, false); Except I'm not sure what I would provide for context? There's a context method in the vanilla EntityRendererProvider class which doesn't look especially helpful. I've been trying something like <e.getEntity(), model<e.getEntity()>> since that generally seems to be what is provided to the renderers for context, but I don't know if it's THE context I'm looking for? Especially since the method being called doesn't want to take this or variations of this.   In short; I feel like I'm super super close but I have to be missing something obvious? Maybe this insane inane ramble post will provide some insight into this puzzle?
  • Topics

×
×
  • Create New...

Important Information

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