[Tutorial] Variables and Overlays - How to draw variables on an overlay :)

Started by mega1134227 on

Topic category: User side tutorials

Last seen on 20:43, 14. Feb 2024
Joined Feb 2016
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
[Tutorial] Variables and Overlays - How to draw variables on an overlay :)
Fri, 05/17/2019 - 13:35 (edited)

Okay so, in this tutorial I'll teach some of you how to draw variables on your screen (or just numbers to those whom are simply oblivious to the term "variable" such as my good friend Mark right here on my right...)

First thing you should know is that in java there are 3 main types of variables : "strings", which are just a line of characters to which you can "add" more characters, integers which are the same as doubles with the slight exception that Ints (integers) don't count decimal numbers and doubles do (there are many other types...) and finally, logic variables which are just a failproof way of making true or flase statement...

To "draw" a variable on your overlay you'll need to use a String. Notice how I say "draw." In Minecrafts code, it says it "draws" its variables when it uses an overlay and Minecraft can only draw strings as far as I know... But, there is a problem... When you add something to a String, it doesn't do it like you do in Math class or like Ints do, it just stacks it on top of the previous line...

 

Ex: 1 + 1 gives 11 or a + 1 gives a1

Minecraft.getMinecraft().fontRenderer.drawString("1" + "1",posX + 183, posY + 73, -16711732);

This would draw 11...

 

So, the question is, how do you draw a number that can change? It's actually pretty simple. We'll just have to use alongside the String an Int since you can add Ints or doubles to a String. The way to do this is to add an Int without putting it under String form (or you'll get an error) to an empty string (ex: "") using a "+" and puting the whole addition thingy between parentheses because it won't work otherwise... (It didn't for me)

 

Like this:

Minecraft.getMinecraft().fontRenderer.drawString(("" + mcreator_VarListminecraft_worlds.WorldVariables.get(entity.world).soul),
                            posX + 183, posY + 73, -16711732);

 

Using these you can add in many quirky systems such as an energy system or a money system and many other things! :)

Just don't forget to use your mods name instead of my Minecraft Worlds Mod name [mcreator_VarListminecraft_worlds], your type of variable save (World, Map or Session) [WorldVariables.get(entity.world)] and your own variables name [soul]... :^l

Also, if you want to have your procedures to actively update your variable on your overlay... I recommend to use the "On player tick update" thingy in your procedures. I am saying this because this is a problem that I managed to fix alone, but that, in all honesty, took me way to long to fix...

Hope this helped you!

Edited by mega1134227 on Fri, 05/17/2019 - 13:35
Last seen on 20:43, 14. Feb 2024
Joined Feb 2016
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Thx ^^
Sat, 05/18/2019 - 13:56

Thx ^^

Last seen on 06:33, 1. May 2023
Joined Mar 2020
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
my mod name?What do you mean…
Tue, 05/05/2020 - 04:39

my mod name?What do you mean?Mod display name?Mod ID/Namespace?/Mod package name?

Last seen on 13:50, 6. Apr 2024
Joined Jun 2015
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
@thesupermoder this tutorial…
Tue, 05/05/2020 - 07:26

@thesupermoder this tutorial is outdated. Now, you have the possibility to show variables on Overlay and GUI in MCreator 2020.2.