Jump to content

NullPointerException: Rendering screen


Guje

Recommended Posts

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)

Link to comment
Share on other sites

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();
}

}

Link to comment
Share on other sites

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;

Link to comment
Share on other sites

    	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.

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.