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.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • If you're seeking an unparalleled solution to recover lost or stolen cryptocurrency, let me introduce you to GearHead Engineers Solutions. Their exceptional team of cybersecurity experts doesn't just restore your funds; they restore your peace of mind. With a blend of cutting-edge technology and unparalleled expertise, GearHead Engineers swiftly navigates the intricate web of the digital underworld to reclaim what's rightfully yours. In your moment of distress, they become your steadfast allies, guiding you through the intricate process of recovery with transparency, trustworthiness, and unwavering professionalism. Their team of seasoned web developers and cyber specialists possesses the acumen to dissect the most sophisticated schemes, leaving no stone unturned in their quest for justice. They don't just stop at recovering your assets; they go the extra mile to identify and track down the perpetrators, ensuring they face the consequences of their deceitful actions. What sets  GearHead Engineers apart is not just their technical prowess, but their unwavering commitment to their clients. From the moment you reach out to them, you're met with compassion, understanding, and a resolute determination to right the wrongs inflicted upon you. It's not just about reclaiming lost funds; it's about restoring faith in the digital landscape and empowering individuals to reclaim control over their financial futures. If you find yourself ensnared in the clutches of cybercrime, don't despair. Reach out to GearHead Engineers and let them weave their magic. With their expertise by your side, you can turn the tide against adversity and emerge stronger than ever before. In the realm of cybersecurity, GearHead Engineers reigns supreme. Don't just take my word for it—experience their unparalleled excellence for yourself. Your journey to recovery starts here.
    • Ok so this specific code freezes the game on world creation. This is what gets me so confused, i get that it might not be the best thing, but is it really so generation heavy?
    • Wizard web recovery has exhibited unparalleled strength in the realm of recovery. They stand out as the premier team to collaborate with if you encounter withdrawal difficulties from the platform where you’ve invested. Recently, I engaged with them to recover over a million dollars trapped in an investment platform I’d been involved with for months. I furnished their team with every detail of the investment, including accounts, names, and wallet addresses to which I sent the funds. This decision proved to be the best I’ve made, especially after realizing the company had scammed me.   Wizard web recovery ensures exemplary service delivery and ensures the perpetrators face justice. They employ advanced techniques to ensure you regain access to your funds. Understandably, many individuals who have fallen victim to investment scams may still regret engaging in online services again due to the trauma of being scammed. However, I implore you to take action. Seek assistance from Wizard Web Recovery today and witness their remarkable capabilities. I am grateful that I resisted their enticements, and despite the time it took me to discover Wizard web recovery, they ultimately fulfilled my primary objective. Without wizard web recovery intervention, I would have remained despondent and perplexed indefinitely.
    • I've tested the same code on three different envionrments (Desktop win10, desktop Linux and Laptop Linux) and it kinda blows up all the same. Gonna try this code and see if i can tune it
  • Topics

×
×
  • Create New...

Important Information

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