Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (โ‹ฎ) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

I'm trying to draw some strings on the screen (obviously), but when I add a previously declared String or int (e.g. "Health: " + health) it draws "Health: 0" regardless of what value the health variable actually has. Anyone know why this is or how I can fix it?

In general some code would help... but I'm guessing this is in a GUI and its not in sync with the server. You will have to override your update packet or manually write a packet to get the info from the server.

I'll need help, and I'll give help. Just ask, you know I will!

  • Author

fr.drawString("Health: " + lowHealthVal[0] + "", xPos + 1, yPos, 16777215);

ย 

lowHealthVal is an int array and the value should be 15 and I've put in console outputs all over the place and it should be 15 but it draws 0 on the screen

  • Author

There isn't really any, it's a client side mod only.

ย 

I also have the problem where I have:

ย 

Sting name = mc.thePlayer.getCommandSenderName();

ย 

which works, I know it does, and then:

ย 

fr.drawString(name, xPos + 1, yPos, 16777215);

ย 

draws absolutely nothing. If I add quotes to it

ย 

fr.drawString("" + lowPots + "", xPos + 1, yPos, 16777215);

ย 

it draws "null" on the screen. there is no synchronization issue

  • Author

Ok here's what I have in the file that isn't working properly

@SubscribeEvent
public void onRenderInvList(RenderGameOverlayEvent.Post e) {
	if(e.type != ElementType.EXPERIENCE) {
		return;
	}
ย  ย  ย  ย  ย  ย  ย  ย  FontRenderer fr = mc.fontRenderer;
	String name = mc.thePlayer.getCommandSenderName();
ย  ย  ย  ย  ย  ย  ย  ย  System.out.println(name);
ย  ย  ย  ย  ย  ย  ย  ย  int xPos = e.resolution.getScaledWidth / 2;
ย  ย  ย  ย  ย  ย  ย  ย  int yPos = 10;
ย  ย  ย  ย  ย  ย  ย  ย  fr.drawString("" + name + "", xPos, yPos, 16777215);

}

ย 

that is it, nothing else useful there that i can see. when I run the game it draws "null" but outputs "ForgeDevName" in the console

I'm just spitballing here, but does drawstring have a SideOnly Client, and the event is subscribed on the server?

ย 

edit: DrawString is definitely only executed on the client, I just don't know 100% that events are subscribed only on the server, but I feel that must be the case. As annoying as it is, I think you have to do this through packets. Its one of those times where on the surface it looks like magic is happening in that code, but we have to remember that unless otherwise specified, a lot of code gets executed twice! (server & client) Instead of assigning the variable in the subscribed event, I would send a packet to the client and assign it in the handler. I don't know, it still doesn't sound right, but either you are pasting code you aren't actually using or its something like this.

I'll need help, and I'll give help. Just ask, you know I will!

Maybe debug it like this:

ย 

@SubscribeEvent
public void onRenderInvList(RenderGameOverlayEvent.Post e) {
	if(e.type != ElementType.EXPERIENCE) {
		return;
	}
ย  ย  ย  ย  ย  ย  ย  ย  FontRenderer fr = mc.fontRenderer;
	String name = mc.thePlayer.getCommandSenderName();

if(e.world.IsRemote)
ย  ย  ย  ย  ย  ย  ย  ย  System.out.println("Server: " + name);
else System.out.println("Client: " + name);


ย  ย  ย  ย  ย  ย  ย  ย  int xPos = e.resolution.getScaledWidth / 2;
ย  ย  ย  ย  ย  ย  ย  ย  int yPos = 10;
ย  ย  ย  ย  ย  ย  ย  ย  fr.drawString("" + name + "", xPos, yPos, 16777215);

}

ย 

I'm sure e.world isn't the right world reference, but you see where I'm going with it...

ย 

edit: on second thought, I can only imagine "onRenderInvList(RenderGameOverlayEvent.Post e)" is on the client, so yeah, I've gotta leave this to those better than me.

I'll need help, and I'll give help. Just ask, you know I will!

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...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions โ†’ Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.