Jump to content

Add to the hud?


Jdb100

Recommended Posts

Sorry about that i am a COMPLETE noob with the gui and hud stuff but what i am trying to add is a bar with a number on it and the bar decreases when you use an item(already got this working)  so it is basically a mana bar if you want to think about it like that.

Link to comment
Share on other sites

I'm not 100% sure how to do this, but I believe it to be rather simple if you are familiar to tickHandlers.

I can look into it after work if you haven't found a solution until I get back.

 

Inn any case do you have a max value the variable could be? if so to know how much of the bar to draw is an easy % calculation,

and once you figure out how to get something drawn on the HUD it's easy as pie to draw the bar you want to :)

 

If you guys dont get it.. then well ya.. try harder...

Link to comment
Share on other sites

FMLClientHandler.instance().getClient().ingameGUI.

 

Call this somewhere it will be called every tick(inside a tick handler).

And you can use the ingameGUI.drawXXXX methods to draw strings or textures to the screen.

I believe that if you want to draw textures you will need to bind the texture by using the GL11 method glBindTexture, but I'm not sure.

 

Hope this helps you to get a place where you can start looking and exploring the code :)

 

Edit:

Read this post http://www.minecraftforge.net/forum/index.php?topic=516.0

It's about tick handlers, just ignore it ModLoader answer inn post #2 and look at what CPW said :)

If you guys dont get it.. then well ya.. try harder...

Link to comment
Share on other sites

@MazeTar thanks for the help you are awesome!

 

@endershadow fontrender is just simply a thing to get the font so just add

 

private FontRenderer par1FontRenderer

 

the first two integers looks like the coords and i am guessing that the third one is the color

 

Edit: ya first two are coords and third is color but i can't figure out what to put for color

Link to comment
Share on other sites

thanks. one problem, when I add

FontRenderer font;

it asks me to initialize it so I end up with this

FontRenderer font = new FontRenderer();

but then it wants me to make that method public. if I make it public, will that make my mod a core mod? and if so, is there any way I can get around having to make it public

Link to comment
Share on other sites

I crash every time i try and use this

 

2013-02-04 12:29:11 [iNFO] [sTDERR] java.lang.NullPointerException
2013-02-04 12:29:11 [iNFO] [sTDERR] 	at cpw.mods.fml.common.SingleIntervalHandler.ticks(SingleIntervalHandler.java:28)
2013-02-04 12:29:11 [iNFO] [sTDERR] 	at cpw.mods.fml.common.FMLCommonHandler.tickStart(FMLCommonHandler.java:115)
2013-02-04 12:29:11 [iNFO] [sTDERR] 	at cpw.mods.fml.common.FMLCommonHandler.onPreClientTick(FMLCommonHandler.java:356)
2013-02-04 12:29:11 [iNFO] [sTDERR] 	at net.minecraft.client.Minecraft.runTick(Minecraft.java:1455)
2013-02-04 12:29:11 [iNFO] [sTDERR] 	at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:846)
2013-02-04 12:29:11 [iNFO] [sTDERR] 	at net.minecraft.client.Minecraft.run(Minecraft.java:771)
2013-02-04 12:29:11 [iNFO] [sTDERR] 	at java.lang.Thread.run(Unknown Source)

 

I looks like i might need to reinstall forge

 

here is my tick handler

 

package net.Dungeon;

import java.util.EnumSet;

import cpw.mods.fml.client.FMLClientHandler;
import cpw.mods.fml.common.ITickHandler;
import cpw.mods.fml.common.TickType;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.FontRenderer;
import net.minecraft.client.gui.GuiIngame;

public class DungeonTickHandler implements ITickHandler
{

Minecraft mc = Minecraft.getMinecraft();

@Override
public void tickStart(EnumSet<TickType> type, Object... tickData) {
	// TODO Auto-generated method stub
	FMLClientHandler.instance().getClient().ingameGUI.drawString(mc.fontRenderer,"Level : " + Dungeon.level, 100, 100, 0);
}

@Override
public void tickEnd(EnumSet<TickType> type, Object... tickData) {
	// TODO Auto-generated method stub

}

@Override
public EnumSet<TickType> ticks() {
	// TODO Auto-generated method stub
	return EnumSet.of(TickType.RENDER);
}

@Override
public String getLabel() {
	// TODO Auto-generated method stub
	return null;
}


}

 

 

 

then i used this to register the tickhandler

 

TickRegistry.registerTickHandler(level , Side.Client);

 

i also for some reason had to do this

 

DungeonTickHandler level;

 

because it wouldn't accept this

 

TickRegistry.registerTickHandler(DungeonTickHandler , Side.Client);

Link to comment
Share on other sites

No you don't have to re install forge, that won't help.

The problem is NOT with forge but with your own code.

Forge does not ever suddenly break when you are coding something, unless you modify base classes(which means you modify forge, which you really shouldn't). So when there is a crash like that the problem is with your own code.

 

Now the problem we are facing is that something is throwing a NullPointerException, this means it expected something but got Nothing, not even a value, just pure nothingness, Null.

 

So when you look at the Stack Trace, you see it throws a Null pointer exception right after doing some stuff related to Ticks, and that seems logical since the things you did lately are all related to ticks.

 

So look inn your TickHandler and see if you can find the place where it sends null and fix it.

Possible hint:

 

getLabel() is expecting a string but returning null, this might be the problem, try setting it to any kind of string

 

 

When it comes to the fact that you have to instantiate the TickHandler you created that's quite natural, you need to call a =new DungeonTickHandler to get access to a new version of it, since it is NOT static.

I'm not sure if the class should be static or not, but I'm sure you can find it out by testing or reading the javadocs/forge documentation :)

 

 

 

 

If you guys dont get it.. then well ya.. try harder...

Link to comment
Share on other sites

Well do you have any way to get futher down the stacktrace to see what is causing the null pointer exception, just find the first line which contains on of your classes and you should find the source.

 

Also have you tried using breakpoints and the debugger to find the error?

What else have you tried? :)

If you guys dont get it.. then well ya.. try harder...

Link to comment
Share on other sites

WAIT!!!

 

Did you say you

DungeonTickHandler level;

 

but never did

level = new DungeonTickHandler;

!!!

 

Theres your null pointer right there!

You never instantiate the level variable of type DungeonTickHandler to a new DungeonTickHandler.

When you don't have it as a static class, you must instantiate it before use or else it will always be NULL.

This is not beacuse of MCP or Forge, but basic Java, recommended reading/soruce: http://thenewboston.org/list.php?cat=31

 

If you guys dont get it.. then well ya.. try harder...

Link to comment
Share on other sites

FacePalmed so hard there! I know this sounds stupid but i actually know quite a bit in java and after looking at that i just can't think how i forgot that i think it is becuase i was doing a bunch of ints before so they looked like

 

public int whatever;

Link to comment
Share on other sites

Believe me, I did the same, when I read your post earlier I didn't notice it untill now that I was reading it again and going "WTF?"

Haha, well there the null pointer should be gone ^^

Is it working now? :D

If you guys dont get it.. then well ya.. try harder...

Link to comment
Share on other sites

ya works like a charm

 

for everyone else who needs help this is what i did and it worked (thanks to Mazetar he did the whole thing)

package net.Dungeon;

import java.util.EnumSet;

import cpw.mods.fml.client.FMLClientHandler;
import cpw.mods.fml.common.ITickHandler;
import cpw.mods.fml.common.TickType;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.FontRenderer;
import net.minecraft.client.gui.GuiIngame;
import net.minecraft.client.gui.GuiScreen;

public class DungeonTickHandler implements ITickHandler
{

Minecraft mc = Minecraft.getMinecraft();

@Override
public void tickStart(EnumSet<TickType> type, Object... tickData) {
	// TODO Auto-generated method stub

}


@Override
public EnumSet<TickType> ticks() {
	// TODO Auto-generated method stub
	return EnumSet.of(TickType.RENDER, TickType.CLIENT);
}

@Override
public String getLabel() {
	// TODO Auto-generated method stub
	return "Dungeon TickHandler";
}


@Override
public void tickEnd(EnumSet<TickType> type, Object... tickData) 
{
	// TODO Auto-generated method stub
	if(type.equals(EnumSet.of(TickType.RENDER)))
	{
	onRenderTick();
	}
	else if(type.equals(EnumSet.of(TickType.CLIENT)))
	{
	GuiScreen guiScreen = this.mc.currentScreen;
	if(guiScreen == null)
	{
	onTickInGame();
	}
	else
	{
	onTickInGUI(guiScreen);
	}
	}

}


private void onTickInGUI(GuiScreen guiScreen) {
	// TODO Auto-generated method stub

}


private void onTickInGame() {
	// TODO Auto-generated method stub

}


private void onRenderTick() {
	// TODO Auto-generated method stub
	mc.fontRenderer.drawStringWithShadow("Dungeon Tokens : " + Dungeon.token, 0, 0, 16777215);
	mc.fontRenderer.drawStringWithShadow("Dungeon Level : " + Dungeon.manalevel, 0, 10, 16777215);

}




}

 

then in your @mod class add

 

DungeonTickHandler tickhandler = new DungeonTickHandler(); 

@Init
public void load(FMLInitializationEvent event)
{
TickRegistry.registerTickHandler(tickhandler, Side.CLIENT);
}

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.

×
×
  • Create New...

Important Information

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