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

    • This is the last line before the crash: [ebwizardry]: Synchronising spell emitters for PixelTraveler But I have no idea what this means
    • What in particular? I barely used that mod this time around, and it's never been a problem in the past.
    • Im trying to build my mod using shade since i use the luaj library however i keep getting this error Reason: Task ':reobfJar' uses this output of task ':shadowJar' without declaring an explicit or implicit dependency. This can lead to incorrect results being produced, depending on what order the tasks are executed. So i try adding reobfJar.dependsOn shadowJar  Could not get unknown property 'reobfJar' for object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler. my gradle file plugins { id 'eclipse' id 'idea' id 'maven-publish' id 'net.minecraftforge.gradle' version '[6.0,6.2)' id 'com.github.johnrengelman.shadow' version '7.1.2' id 'org.spongepowered.mixin' version '0.7.+' } apply plugin: 'net.minecraftforge.gradle' apply plugin: 'org.spongepowered.mixin' apply plugin: 'com.github.johnrengelman.shadow' version = mod_version group = mod_group_id base { archivesName = mod_id } // Mojang ships Java 17 to end users in 1.18+, so your mod should target Java 17. java.toolchain.languageVersion = JavaLanguageVersion.of(17) //jarJar.enable() println "Java: ${System.getProperty 'java.version'}, JVM: ${System.getProperty 'java.vm.version'} (${System.getProperty 'java.vendor'}), Arch: ${System.getProperty 'os.arch'}" minecraft { mappings channel: mapping_channel, version: mapping_version copyIdeResources = true runs { configureEach { workingDirectory project.file('run') property 'forge.logging.markers', 'REGISTRIES' property 'forge.logging.console.level', 'debug' arg "-mixin.config=derp.mixin.json" mods { "${mod_id}" { source sourceSets.main } } } client { // Comma-separated list of namespaces to load gametests from. Empty = all namespaces. property 'forge.enabledGameTestNamespaces', mod_id } server { property 'forge.enabledGameTestNamespaces', mod_id args '--nogui' } gameTestServer { property 'forge.enabledGameTestNamespaces', mod_id } data { workingDirectory project.file('run-data') args '--mod', mod_id, '--all', '--output', file('src/generated/resources/'), '--existing', file('src/main/resources/') } } } sourceSets.main.resources { srcDir 'src/generated/resources' } repositories { flatDir { dirs './libs' } maven { url = "https://jitpack.io" } } configurations { shade implementation.extendsFrom shade } dependencies { minecraft "net.minecraftforge:forge:${minecraft_version}-${forge_version}" implementation 'org.luaj:luaj-jse-3.0.2' implementation fg.deobf("com.github.Virtuoel:Pehkui:${pehkui_version}") annotationProcessor 'org.spongepowered:mixin:0.8.5:processor' minecraftLibrary 'luaj:luaj-jse:3.0.2' shade 'luaj:luaj-jse:3.0.2' } // Example for how to get properties into the manifest for reading at runtime. tasks.named('jar', Jar).configure { manifest { attributes([ 'Specification-Title' : mod_id, 'Specification-Vendor' : mod_authors, 'Specification-Version' : '1', // We are version 1 of ourselves 'Implementation-Title' : project.name, 'Implementation-Version' : project.jar.archiveVersion, 'Implementation-Vendor' : mod_authors, 'Implementation-Timestamp': new Date().format("yyyy-MM-dd'T'HH:mm:ssZ"), "TweakClass" : "org.spongepowered.asm.launch.MixinTweaker", "TweakOrder" : 0, "MixinConfigs" : "derp.mixin.json" ]) } rename 'mixin.refmap.json', 'derp.mixin-refmap.json' } shadowJar { archiveClassifier = '' configurations = [project.configurations.shade] finalizedBy 'reobfShadowJar' } assemble.dependsOn shadowJar reobf { re shadowJar {} } publishing { publications { mavenJava(MavenPublication) { artifact jar } } repositories { maven { url "file://${project.projectDir}/mcmodsrepo" } } } my entire project:https://github.com/kevin051606/DERP-Mod/tree/Derp-1.0-1.20
    • All versions of Minecraft Forge suddenly black screen even without mods (tried reinstalling original Minecraft, Java, updating drivers doesn't work)
  • Topics

×
×
  • Create New...

Important Information

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