Jump to content

[1.7.2] Drawing a string on the top-left corner of the screen.


Recommended Posts

Posted

I have gotten it to work in 1.6.2 before, but updating it to 1.7.2? pain in the ass.

 

Let me explain my situation, everything works fine, got my events working and tested with [system.out.println("test")]

Whenever I replace System.out.println("test") and run it with my thingy I'm using, it creates GL11 errors.

 

Is it because I changed the event to boolean, because I'm transferring my ModLoader mod to Forge during 1.7.2 with no ModLoader inside Forge... which I used the "onTickInGame" method, but I really don't know how to transfer a boolean to a void...

Coding:

 

Event Class:

@SubscribeEvent
public boolean onWorldTick(TickEvent.WorldTickEvent event)
{
	Minecraft mc = Minecraft.getMinecraft();
	Tracker trck = Tracker.wl; //wl = this (Tracker) 
	trck.doFunction(); //[something with this too in crash report]
	return true;
}

 

doFunction method:

public boolean doFunction()
    {
    	Minecraft minecraft = Minecraft.getMinecraft();
        if (minecraft == null || minecraft.currentScreen != null || minecraft.gameSettings == null || minecraft.gameSettings.showDebugInfo)
        {
            return true;
        }
        String s = (new StringBuilder()).append("No mobs tracked! D: (Press ").append(minecraft.gameSettings.getKeyDisplayString(key1.func_151463_i())).append(" to enable/disable this mod.)").toString();
        if (membyte != null)
        {
            s = (new StringBuilder()).append("Mob Info: [").append(MobStatus.infoList()).append("]\n").toString();
            s = (new StringBuilder()).append(s).append("At Coords: X: ").append((int)MobStatus.cur_posX).append(" Y: ").append((int)MobStatus.cur_posY).append(" Z: ").append((int)MobStatus.cur_posZ).append("\n").toString();
            EntityPlayerSP entityplayersp = minecraft.thePlayer;
            
            if (entityplayersp != null)
            {
                s = (new StringBuilder()).append(s).append("X~Away: ").append((int)(MobStatus.cur_posX - ((EntityPlayer)(entityplayersp)).posX)).append(" Y~Away: ").append((int)(MobStatus.cur_posY - ((EntityPlayer)(entityplayersp)).posY)).append(" Z~Away: ").append((int)(MobStatus.cur_posZ - ((EntityPlayer)(entityplayersp)).posZ)).toString();
            }
        }
        int i = 0;
        byte byte0 = 7;
        String as[] = s.split("\n");
        int j = as.length;
        int k = 0;

        do
        {
            if (k >= j)
            {
                break;
            }
            String s1 = as[k];
            if (++i > byte0)
            {
                break;
            }
            minecraft.fontRenderer.drawStringWithShadow(s1, 23, 10 + i * 10, 0xffffff); //[main error]
            k++;
        }
        while (true);

        canChangeSettings++;

        if (!coords)
        {
            return true;
        }

        if (minecraft.theWorld == null)
        {
            return true;
        }

        if (membyte2 != null && MobStatus.isMobDead)
        {
            MobStatus.curMob = null;
        }

        MobStatus.curMob = null;
        boolean flag = false;
        Iterator iterator = minecraft.theWorld.loadedEntityList.iterator();

        do
        {
            if (!iterator.hasNext())
            {
                break;
            }

            Object obj = iterator.next();

            if (obj instanceof EntityMob)
            {
                if (MobStatus.curMob != null && obj.equals(MobStatus.cur_Mob))
                {
                    flag = true;
                }

                if (MobStatus.curMob == null || minecraft.thePlayer != null && minecraft.thePlayer.getDistanceToEntity((EntityMob)obj) < minecraft.thePlayer.getDistanceToEntity(MobStatus.curMob))
                {
                    MobStatus.curMob = (EntityMob)obj;
                }
            }
        }
        while (true);
     }
        return true;
    }

 

Event Registration [@Init]

    @EventHandler
    public void preInit(FMLPreInitializationEvent event)
    {
    	//MinecraftForge.EVENT_BUS.register(new WorldUpdateTick());
    }

 

Crash Report:

java.lang.RuntimeException: No OpenGL context found in the current thread.
at org.lwjgl.opengl.GLContext.getCapabilities(GLContext.java:124)
at org.lwjgl.opengl.GL11.glEnable(GL11.java:1012)
at net.minecraft.client.gui.FontRenderer.drawString(FontRenderer.java:245)
at net.minecraft.client.gui.FontRenderer.drawStringWithShadow(FontRenderer.java:237)
at com.coolboy4531.Tracker.doFunction(Tracker.java:115)
at com.coolboy4531.WorldUpdateTick.onWorldTick(WorldUpdateTick.java:15)
at cpw.mods.fml.common.eventhandler.ASMEventHandler_4_WorldUpdateTick_onWorldTick_WorldTickEvent.invoke(.dynamic)
at cpw.mods.fml.common.eventhandler.ASMEventHandler.invoke(ASMEventHandler.java:39)
at cpw.mods.fml.common.eventhandler.EventBus.post(EventBus.java:108)
at cpw.mods.fml.common.FMLCommonHandler.onPostWorldTick(FMLCommonHandler.java:242)
at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:666)
at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:568)
at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:114)
at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:452)
at net.minecraft.server.MinecraftServer$2.run(MinecraftServer.java:705)

 

Any help will be appreciated.

Thanks ;)

 

 

 

Posted

If you want to draw a string why are you using onWorldTick? you should use TickEvent.RenderTickEvent. to render and TickEvent.WorldTickEvent for logic (what I can see your trying to track mobs I think), like GotoLink said look at your code there are errors there.

Posted

The biggest help you can get is by your own doing: learn how to code.

You make nearly one mistakes per line at the moment.

 

This.

 

Also, your error happens at

 

at com.coolboy4531.Tracker.doFunction(Tracker.java:115)

 

Go there.

 

Figure out why.

 

You didn't even include enough code of that class for me to locate that line so I couldn't help you if I wanted to, which I don't, because you're making mistakes left and right (why does doFunction() return a boolean if that boolean is ignored?  Why do you do a Minecraft.getMinecraft() both before calling the function and inside the function instead of passing it?  Or better yet, what purpose is it being put to in the event listener class?  StringBuilder().append().toString()?  Was

String s = "I need " + a_variable + " stringified"

wasn't good enough?)

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

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



×
×
  • Create New...

Important Information

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