Jump to content

Recommended Posts

Posted

Hello hello!

 

I wanted to know how I can make something that displays text on the screen (or runs any other function) for let's say 3 seconds.

Thanks!

Posted

Have you already tried something?

 

Basically it is:

You simply set a timer variable which will decrements in each client tick. And if the timer is expired you will not render the text anymore.

Posted
9 minutes ago, Lhykos said:

Have you already tried something?

 

Basically it is:

You simply set a timer variable which will decrements in each client tick. And if the timer is expired you will not render the text anymore.

 

I can try that, but what if I need to display more than one text at ones (the text must be dynamic too)

Or lets say I want the text to fade out

Posted (edited)

You'll have to learn OpenGL.

What you seem to want, is called a HUD. (Heads Up Display).

I have a very old example here. It is from the 1.7 days, but it should be mostly correct still. ScaledResolution only needs the mc instance now, the width & height is done for you.

Do note, this involves Minecraft#getMinecraft() which is client-side only. As such, it must only be called client-side, as it will crash otherwise.

(The example I linked, is meant to print the given string in the middle of the screen, fully centered)

 

As Lhykos has states, you will need a timer. How you create that, is up to you.

Edited by Matryoshika

Also previously known as eAndPi.

"Pi, is there a station coming up where we can board your train of thought?" -Kronnn

Published Mods: Underworld

Handy links: Vic_'s Forge events Own WIP Tutorials.

Posted
1 minute ago, Matryoshika said:

You'll have to learn OpenGL.

What you seem to want, is called a HUD. (Heads Up Display).

I have a very old example here. It is from the 1.7 days, but it should be mostly correct still. ScaledResolution only needs the mc instance now, the width & height is done for you.

Do note, this involves Minecraft#getMinecraft() which is client-side only. As such, it must only be called client-side, as it will crash otherwise.

 

As Lhykos has states, you will need a timer. How you create that, is up to you.

 

Yeah I already know how to display the text and everything, it works perfectly.

the only thing I needed was the display time and animation

Posted
Just now, Bets said:

Yeah I already know how to display the text and everything, it works perfectly.

the only thing I needed was the display time and animation

I'm not sure if you can fade out a text in Minecraft on a normal way. I never done that before :D

 

  • Like 1
Posted
1 minute ago, Lhykos said:

I'm not sure if you can fade out a text in Minecraft on a normal way. I never done that before :D

 

 

I'll try making something :) If I'll succeed I will let you know

Posted (edited)

I totally forgot about the subtitles and overlay messages from Minecraft!

In the GuiIngame class by line 241. Here is handled how to fade out and display a overlay message for a specific time. (When a record is played. In that fancy, colored way)


But like Matryoshika already said. Here you have to know how to use OpenGL. :)

Edited by Lhykos
  • Like 1
Posted
3 minutes ago, Lhykos said:

I totally forgot about the subtitles and overlay messages from Minecraft!

In the GuiIngame class by line 241. Here is handled how to fade out and display a overlay message for a specific time. (When a record is played. In that fancy, colored way)


But like Matryoshika already said. Here you have to know how to use OpenGL. :)

 

Oh right! forgot about these! I'll check them out

Posted

So I tried to understand how this works without success.

there's GlStateManager.enableBlend(); and other stuff, but how do I "link" them to my drawCenteredString?

Posted (edited)

You have not to link them.

You call 'GlStateManager.enableBlend()' before you draw the string with 'fontrenderer.drawCenteredString(...)' to enable the transparency.

And don't forget to call 'GlStateManager.disableBlend()') when you are finished.

 

And to your color you have to add the alpha via "bit shifting":

int color = alpha << 24 + color;

Btw. here is a link to understand the bit shifting.

 

For a "really good" transparency you call this:

GlStateManager.tryBlendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ZERO);

to tell OpenGL how to handle the blending mode.

 

It's more copy & paste from the source code, but that should explain it. :)

Edited by Lhykos
edit wrong code
Posted
1 hour ago, Lhykos said:

You have not to link them.

You call 'GlStateManager.enableBlend()' before you draw the string with 'fontrenderer.drawCenteredString(...)' to enable the transparency.

And don't forget to call 'GlStateManager.disableBlend()') when you are finished.

 

And to your color you have to add the alpha via "bit shifting":


int color = alpha << 24 & color;

Btw. here is a link to understand the bit shifting.

 

For a "really good" transparency you call this:


GlStateManager.tryBlendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ZERO);

to tell OpenGL how to handle the blending mode.

 

It's more copy & paste from the source code, but that should explain it. :)

1

 

So all I need to do is something like this inside my RenderGameOverlayEvent.Text event handler?

GlStateManager.enableBlend();
GlStateManager.tryBlendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ZERO);
mc.ingameGUI.drawCenteredString(mc.fontRendererObj, "fade string", sr.getScaledWidth() / 2, sr.getScaledHeight() - 97, color);
GlStateManager.disableBlend();

 

 

Posted

You should use the fontRendererObj directly:

 mc.fontRendererObj.drawString("fade string", sr.getScaledWidth() / 2 - mc.fontRendererObj.getStringWidth("fade string") / 2 , sr.getScaledHeight() - 97,  color);

 

And don't forget to add the alpha:

int color += (alpha << 24)

 

That's how you get the transparency. For the fade-out you still need to setup a timer or use the partialTicks like in the GuiIngame.

  • Like 1
Posted
3 hours ago, Lhykos said:

You should use the fontRendererObj directly:


 mc.fontRendererObj.drawString("fade string", sr.getScaledWidth() / 2 - mc.fontRendererObj.getStringWidth("fade string") / 2 , sr.getScaledHeight() - 97,  color);

 

And don't forget to add the alpha:


int color += (alpha << 24)

 

That's how you get the transparency. For the fade-out you still need to setup a timer or use the partialTicks like in the GuiIngame.

 

It works well when I'm running the game from eclipse, but when I compile it and load it with a regular client it sometimes does not fade.

Posted

Does anyone know why is this happening? The name of the item I hold (when the name is displayed) is interrupting the title fade. perhaps because both are fading at the same time? All it will do (if I'm holding an item and the item's name is displayed) is just disable the fade animation.

 

The code for the fade I made is this:

if (aTimer > 0) {
	aTimer--;
	if (aTimer > 5 && aTimer <= 250) {
		theAlpha = (gainTimer << 24);
	}
    mc.fontRendererObj.drawString("FADING TEXT", sr.getScaledWidth() / 2 - mc.fontRendererObj.getStringWidth("FADING TEXT") / 		2,sr.getScaledHeight() - 95, theAlpha);
}

 

Posted
11 hours ago, Bets said:

Does anyone know why is this happening? The name of the item I hold (when the name is displayed) is interrupting the title fade. perhaps because both are fading at the same time? All it will do (if I'm holding an item and the item's name is displayed) is just disable the fade animation.

 

The code for the fade I made is this:


if (aTimer > 0) {
	aTimer--;
	if (aTimer > 5 && aTimer <= 250) {
		theAlpha = (gainTimer << 24);
	}
    mc.fontRendererObj.drawString("FADING TEXT", sr.getScaledWidth() / 2 - mc.fontRendererObj.getStringWidth("FADING TEXT") / 		2,sr.getScaledHeight() - 95, theAlpha);
}

 

What is 'gainTimer', it is the color?
It where important to understand how bit shifting is working. For me you try to set the alpha by shifting 24 in a timer value. This doesn't work.

The better question is, why you want to display the item name twice? It's showing you the name already above the hotbar.

 

Posted
9 hours ago, Lhykos said:

What is 'gainTimer', it is the color?
It where important to understand how bit shifting is working. For me you try to set the alpha by shifting 24 in a timer value. This doesn't work.

The better question is, why you want to display the item name twice? It's showing you the name already above the hotbar.

 

 

I'm not displaying the item name twice. this is another title for something else :)

gainTimer is the Alpha, yes. What do you mean by it doesn't work - am I doing something wrong? (it is fading out, yet the item name is interrupting this specific title fade)

Posted

Maybe I thought too complicated O.o
I think the best solution is doing it like minecraft. Simple and works perfect for me.

 

Spoiler

    displayTime--;

    if (displayTime > 0)
    {
        float f2 = (float) displayTime - event.getPartialTicks();
        int l1 = (int) (f2 * 255.0F / 100.0F);
        int color = 0xFFFF00;

        if (l1 > 255)
        {
            l1 = 255;
        }

        if (l1 > 8)
        {
            GlStateManager.enableBlend();
            GlStateManager.tryBlendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SourceFactor.ONE,
                    GlStateManager.DestFactor.ZERO);
            Minecraft.getMinecraft().fontRendererObj.drawString(message, sr.getScaledWidth() / 2 - Minecraft.getMinecraft().fontRendererObj.getStringWidth(message) / 2,
                    sr.getScaledHeight() / 2, color + (l1 << 24 & -color));
            GlStateManager.disableBlend();
        }

    }

 

 

  • Like 1
Posted
12 hours ago, Lhykos said:

Maybe I thought too complicated O.o
I think the best solution is doing it like minecraft. Simple and works perfect for me.

 

  Hide contents


    displayTime--;

    if (displayTime > 0)
    {
        float f2 = (float) displayTime - event.getPartialTicks();
        int l1 = (int) (f2 * 255.0F / 100.0F);
        int color = 0xFFFF00;

        if (l1 > 255)
        {
            l1 = 255;
        }

        if (l1 > 8)
        {
            GlStateManager.enableBlend();
            GlStateManager.tryBlendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SourceFactor.ONE,
                    GlStateManager.DestFactor.ZERO);
            Minecraft.getMinecraft().fontRendererObj.drawString(message, sr.getScaledWidth() / 2 - Minecraft.getMinecraft().fontRendererObj.getStringWidth(message) / 2,
                    sr.getScaledHeight() / 2, color + (l1 << 24 & -color));
            GlStateManager.disableBlend();
        }

    }

 

 

 

 

Haha, yeah well it works! I don't understand how - But it works xD

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

    • Delete the config of RandomTweaker (config folder) If there is no change, remove this mod
    • Hello! So i have been trying to make a mod that adds plant fiber to minecraft 1.16.5 (i believe there are mods that add plant fiber but not for 1.16.5) but the problem is that i want to modify the loot table of grass to always drop plant fiber but also keep the vanilla drops. Most common answer i have seen is GlobalLootModifiers. But my tiny brain cant understand any tutorials. So any help is appreciated.
    • Minecraft forge 1.12.2 does not load. Here is both logs. I assume its because of a mod that i have, idk. (L521)
    • Found the solution! Instead of using PlayerEvent.Clone to sync capabilities with a client use EntityJoinWorldEvent! That's how CapabilitySync class should look like: public class CapabilitySync { @SubscribeEvent public void EntityJoinWorldEvent(EntityJoinWorldEvent event) { Entity entity = event.getEntity(); if (entity.world.isRemote || !(entity instanceof EntityPlayerMP)) return; EntityPlayer player = (EntityPlayer) entity; NetworkHandler.channel.sendTo(new ServerToClient(player), (EntityPlayerMP) player); } @SubscribeEvent public void onPlayerClone(PlayerEvent.Clone event) { EntityPlayer player = event.getEntityPlayer(); IFolder folder = player.getCapability(FolderProvider.FOLDER_CAP, null); IFolder oldfolder = event.getOriginal().getCapability(FolderProvider.FOLDER_CAP, null); folder.setFolders(oldfolder.getFolders()); } }   Here is a full code if you need one! https://github.com/R4L34/capabilitynetworking
  • Who's Online (See full list)

×
×
  • Create New...

Important Information

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