Jump to content

[1.7.2] - Making a string in a gui update while looking at the gui


Recommended Posts

Posted

Hi, I was just wondering if there was a way of updating a string that is drawn in a gui without exiting the gui first. By update I mean change value if I have done something to make it change. I have made it so that it updates every time you exit the gui and open it again, but that is all I can do.

 

Here is the code I am using:

 

  Reveal hidden contents

 

Posted

I don't know much about gui's but I think if you look at the furnaces progress bar I think you could implement that in a way so that the text changes.

I'm always happy to help others!

 

Java is not my main programming language but I have alot experience in PHP/HTML/JS/CSS3/C#/SQL

Posted
  On 3/11/2014 at 8:15 PM, stijnhero said:

I don't know much about gui's but I think if you look at the furnaces progress bar I think you could implement that in a way so that the text changes.

If I understand the code correctly that won't work because they are not really using a variable that shows up, but they are rendering a square that get's bigger and bigger. Rendering that should go fine, but I think variables need an update.
Posted

public void updateScreen() {

super.updateScreen();

 

pantheon = "Pantheon is set to " + ExtendedPlayer.get(player).getPantheon();

pantheonId = "Pantheon ID = " + ExtendedPlayer.get(player).getPantheonId();

}

this is the method that is called on exiting the screen right?

I'm always happy to help others!

 

Java is not my main programming language but I have alot experience in PHP/HTML/JS/CSS3/C#/SQL

Posted
  On 3/13/2014 at 2:53 PM, stijnhero said:

public void updateScreen() {

super.updateScreen();

 

pantheon = "Pantheon is set to " + ExtendedPlayer.get(player).getPantheon();

pantheonId = "Pantheon ID = " + ExtendedPlayer.get(player).getPantheonId();

}

this is the method that is called on exiting the screen right?

That might be possible.
Posted

Try calling it from another class to check if it works while the gui is open.

I'm always happy to help others!

 

Java is not my main programming language but I have alot experience in PHP/HTML/JS/CSS3/C#/SQL

Posted
  On 3/13/2014 at 3:29 PM, stijnhero said:

Try calling it from another class to check if it works while the gui is open.

I tried calling it from the onItemRightClick method in one of my item classes. Seems like the code inside there is reachable even when it's opened.
Posted

public void actionPerformed(GuiButton button) {

what if you add it to all the cases in side this and add a System.out.println to check if it is called ?

I'm always happy to help others!

 

Java is not my main programming language but I have alot experience in PHP/HTML/JS/CSS3/C#/SQL

Posted
  On 3/13/2014 at 4:21 PM, stijnhero said:

public void actionPerformed(GuiButton button) {

what if you add it to all the cases in side this and add a System.out.println to check if it is called ?

Doesn't help any :(
Posted
  On 3/13/2014 at 4:21 PM, stijnhero said:

public void actionPerformed(GuiButton button) {

what if you add it to all the cases in side this and add a System.out.println to check if it is called ?

That code only fires when a GuiButton is pressed. You should probably use the drawGuiForegroundLayer method to draw the strings, because that's updated every tick.

Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support.

 

1.12 -> 1.13 primer by williewillus.

 

1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support.

 

http://www.howoldisminecraft1710.today/

Posted

Yeah that was to check if anything happens with that method once he clicks the button...

I'm always happy to help others!

 

Java is not my main programming language but I have alot experience in PHP/HTML/JS/CSS3/C#/SQL

Posted
  On 3/13/2014 at 5:55 PM, larsgerrits said:

  Quote

public void actionPerformed(GuiButton button) {

what if you add it to all the cases in side this and add a System.out.println to check if it is called ?

That code only fires when a GuiButton is pressed. You should probably use the drawGuiForegroundLayer method to draw the strings, because that's updated every tick.

This would work if I had a class that extends GuiContainer, but I am extending GuiScreen which has no such method.

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

    • Make a test with another Launcher like the Curseforge Launcher, MultiMC or AT Launcher
    • can anyone help me i am opening forge and add modpacks and then it says unable to update native luancher and i redownlaod java and the luancher it self?
    • The problem occurs also in 1.20.1 Forge, but with an "Error executing task on client" instead. I have "Sinytra Connector" installed. On 1.21.5 Fabric, there is no problem. When this happens, the chat message before the death screen appears gets sent, with an extra dash added.
    • Well, as usual, it was user error. Naming mismatch in sounds.json.  Please delete this post if you find it necessary. 
    • Hello Forge community.  I'm running into an issue with a mod I'm working on.  To preface, I can call /playsound modId:name music @a and I can hear the sound I registered being played in game. Great!  However, I cannot get it to trigger via my mod code.    Registration: public static final RegistryObject<SoundEvent> A_WORLD_OF_MADNESS = SOUND_EVENTS.register("a_world_of_madness", () -> new SoundEvent(new ResourceLocation("tetheredsouls", "a_world_of_madness")));   Playback: Minecraft mc = Minecraft.getInstance(); if (!(mc.player instanceof LocalPlayer) || mc.level == null) return; LocalPlayer player = (LocalPlayer) mc.player; BlockPos pos = player.blockPosition(); SoundEvent track = ModSounds.A_WORLD_OF_MADNESS.get(); System.out.println(track); System.out.println(pos); System.out.println(player); // play exactly like the tutorial: client-only, at the player's position try { mc.level.playLocalSound( player.getX(), player.getY(), player.getZ(), track, SoundSource.MUSIC, // Or MASTER if needed 1f, 1f, false ); System.out.println("[DEBUG] playSound success: " + track.getLocation()); } catch (Exception e) { System.err.println("[ERROR] Failed to play sound: " + track.getLocation()); e.printStackTrace(); } Sounds.json:   { "theme_of_laura": { "category": "music", "sounds": [ { "name": "tetheredsouls:a_world_of_madness", "stream": true } ] } } Things I have tried: - multiple .ogg files. Short .ogg files (5 seconds, <100KB).  - default minecraft sounds imported from import net.minecraft.sounds.SoundEvents; These work given my code. No idea why these are different.  - playSound() method, as well as several others in past iterations that did not work   I would be forever grateful if somebody could point me in the right direction. I've looked at several mod github repositories and found extremely similar code to what I'm doing. I've also found several threads in this forum that did not solve my issue. I just cannot figure out what I'm doing differently, and why I'm able to queue sounds manually with playsound but the code won't play it (despite confirming the code is being run with the debug statements.)
  • Topics

×
×
  • Create New...

Important Information

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