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

Sometimes, when I open my customGui, the server shuts down and shows this error:

 

Stacktrace:
at net.minecraft.client.gui.GuiScreen.drawWorldBackground(GuiScreen.java:396)
at net.minecraft.client.gui.GuiScreen.drawDefaultBackground(GuiScreen.java:391)
at com.guje.test_mod.TestBlockGui.drawScreen(TestBlockGui.java:71)

"com.guje.test_mod.TestBlockGui.drawScreen(TestBlockGui.java:71)"

 

Well that's the line your error is on, and something about it is null, feel like providing code so we can help you?

  • Author

In line 71 there is only

 

drawDefaultBackground();

 

rest of the class:

package com.guje.test_mod;

import org.lwjgl.opengl.GL11;

import net.minecraft.block.Block;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.gui.GuiTextField;
import net.minecraft.util.ResourceLocation;
import net.minecraft.world.World;

public class TestBlockGui extends GuiScreen {

private int textureX;
private int textureY;
private int posY;
private int posX;
private int bY;
private int bX;
private int bZ;
private ResourceLocation texture;
private World world;
private String blockId;
private String blockMetadata;
private GuiTextField text_BlockId;
private GuiTextField text_BlockMetadata;

public TestBlockGui(Block block, World world, int bX, int bY, int bZ) {
	super();
	this.textureX = 175;
	this.textureY = 221;
	this.bX = bX;
	this.bY = bY;
	this.bZ = bZ;
	this.world = world;
	this.blockId = block.getIdFromBlock(block)+"";
	this.blockMetadata = world.getBlockMetadata(bX, bY, bZ)+"";
	texture = new ResourceLocation(Hack_n_Mine.MODID, "textures/gui/hackingGui.png");
}

@Override
public void initGui() {
	buttonList.clear();
	posX = (this.width - textureX) / 2;
	posY = (this.height - textureY) / 2;
	text_BlockId = new GuiTextField(fontRendererObj, posX + 77, posY + 5, 40, 10);
	text_BlockId.setText(blockId);
	text_BlockId.setMaxStringLength(5);
	text_BlockMetadata = new GuiTextField(fontRendererObj, posX + 77, posY + 18, 40, 10);
	text_BlockMetadata.setText(blockMetadata);
	text_BlockMetadata.setMaxStringLength(5);
	super.initGui();
}

@Override
protected void keyTyped(char c, int i) {
	text_BlockId.textboxKeyTyped(c, i);
	text_BlockMetadata.textboxKeyTyped(c, i);
	super.keyTyped(c, i);
}

@Override
protected void mouseClicked(int i, int j, int f) {
	text_BlockId.mouseClicked(i, j, f);
	text_BlockMetadata.mouseClicked(i, j, f);
	super.mouseClicked(i, j, f);
}

@Override
public void drawScreen(int x, int y, float f) {
	drawDefaultBackground();
	GL11.glColor4f(1F,1F,1F,1F);
	posX = (this.width - textureX) / 2;
	posY = (this.height - textureY) / 2;

	mc.renderEngine.bindTexture(texture);
	drawTexturedModalRect(posX, posY, 0, 0, textureX, textureY);
	text_BlockId.drawTextBox();
	text_BlockMetadata.drawTextBox();
	fontRendererObj.drawString("BlockID", posX + 5, posY + 7, 0x404040);
	fontRendererObj.drawString("BlockMetadata", posX + 5, posY + 19, 0x404040);
	super.drawScreen(x, y, f);
}

@Override
public void onGuiClosed() {
	//Set blockId and metadata
	Block b = Block.getBlockById(Integer.parseInt(text_BlockId.getText()));
	int m = Integer.parseInt(text_BlockMetadata.getText());
	world.setBlock(bX, bY, bZ, b, m, 3);
	super.onGuiClosed();
}

}

  • Author

in this function

 

    @Override
    public boolean onItemUse(ItemStack item, EntityPlayer player,
    		World world, int x, int y, int z,
    		int par7, float xFloat, float yFloat,
    		float zFloat) {
    	if (!player.canPlayerEdit(x, y, z, par7, item)){
    		return false;
    	}
    	if (!world.isRemote){
    		Block target = world.getBlock(x, y, z);
    		Minecraft.getMinecraft().displayGuiScreen(new TestBlockGui(target,world,x,y,z));
    	}
    	return true;

    	if (!world.isRemote){
    		Block target = world.getBlock(x, y, z);
    		Minecraft.getMinecraft().displayGuiScreen(new TestBlockGui(target,world,x,y,z));
    	}

 

You're checking to see if it's on the server side, isRemote returns true for client and false for servers. Minecraft is a client only class.

  • Author

I thought about that. But when i change it like that, there aren't any changes made to the server, so it doesn't work

If you're opening a GUI like that you have to do it on the client side, if your GUI is going to interact with the server, you will probably need to use packets to tell the server what to do.

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.