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.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • I create my mod pack,yesterday my mod pack is fine but i add one mod and error. I'm delete this mmod but minecraft is still stop on CONFIG_LOAD then I tried to delete config and restart it but again. If you can pleace help me. https://imgur.com/ngZBzuv
    • game crashes before even opening (log:https://mclo.gs/M8xvX7c)
    • I have created a custom entity that extends "TamableAnimal", but I am wanting to have it spawn in the ocean. I have it spawning right now, but it spawns way too frequently even with weight set to 1. I am guessing it is because it is rolling in the spawn pool of land animals since TameableAnimal extends Animal and is different than WaterAnimal, and since no land animals spawn in the ocean it just fills every inch up with my custom entity. I have followed basic tutorials for spawning entities with Forge, but I feel like I am missing something about how to change what spawn pool this custom entity ends up in. Is it possible to change that or do I need to refactor it to be based off of WaterAnimal to get those spawn? My biome modifier JSON file: { "type": "forge:add_spawns", "biomes": "#minecraft:is_ocean", "spawners": { "type": "darwinsmysticalmounts:water_wyvern", "weight": 20, "minCount": 1, "maxCount": 1 } } My client event: event.register(ModEntityTypes.WATER_WYVERN.get(), SpawnPlacements.Type.NO_RESTRICTIONS, Heightmap.Types.MOTION_BLOCKING_NO_LEAVES, WaterWyvernEntity::checkWaterWyvernSpawnRules, SpawnPlacementRegisterEvent.Operation.REPLACE); And the actual custom spawn rule that makes it spawn in the water: public static boolean checkWaterWyvernSpawnRules(EntityType<WaterWyvernEntity> pAnimal, LevelAccessor pLevel, MobSpawnType pSpawnType, BlockPos pPos, RandomSource pRandom) { return pPos.getY() > pLevel.getSeaLevel() - 16 && pLevel.getFluidState(pPos.below()).is(FluidTags.WATER); }  
    • Starting today, I am unable to load my modded minecraft world. Forge crash log initially said it was a specific mod called Doggy Talents, which I disabled. Then it blamed JEI, and when that was disabled it blamed another mod so I assume it's something more than a specific mod. Minecraft launcher log claims "Exit Code 1". Nothing had changed since last night when it was working fine Forge Log: https://pastebin.com/S1GiBGVJ Client Log: https://pastebin.com/aLwuGUNL  
    • I am using AMD, yes. I downloaded the website's drivers and am still having the issue. I also used the Cleanup Utility just in case. 
  • Topics

×
×
  • Create New...

Important Information

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