Jump to content

GUI opening


memcallen

Recommended Posts

I'm getting an error on player.openGui I've seen it on multiple gui tuts. but its not working for me

 

common proxy:

package com.example.gammacraft.Proxy;

import com.example.gammacraft.gui.ProcessorGui;

import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.world.World;
import cpw.mods.fml.common.network.IGuiHandler;

public class ProxyCommon implements IGuiHandler{
   public void registerRenderers(){
   }

   @Override
   public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {
      return null;
   }

   @Override
   public Object getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {
      if ( ID == ProcessorGui.GUI_ID ){
            return new ProcessorGui();}else{
      return null;}
   }
}

 

for the main file I put

NetworkRegistry.INSTANCE.registerGuiHandler(Instance, proxy);

in my init function

 

and the block file is:

package com.example.gammacraft.blocks;

import com.example.gammacraft.TileEntity.BluePrintTableTileEntity;
import com.example.gammacraft.gui.BluePrintTableGui;

import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.block.BlockContainer;
import net.minecraft.block.material.Material;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.IIcon;
import net.minecraft.world.World;

public class BluePrintTable extends BlockContainer{



@SideOnly(Side.CLIENT)
public static IIcon top;
@SideOnly(Side.CLIENT)
public static IIcon side;


public BluePrintTable(int i, Material p_i45386_1_) {
	super(p_i45386_1_);
	this.setBlockName("BluePrintTable");
	this.setCreativeTab(CreativeTabs.tabMisc);
}

@Override
public TileEntity createNewTileEntity(World var1, int var2) {
	return new BluePrintTableTileEntity();
}


public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int metadata, float Hitx, float Hity, float Hitz) {

player.openGui(BluePrintTableGui.class, 20, world, x, y, z);
    return true;
}


}

 

the guiScreen is:

package com.example.gammacraft.gui;



import com.example.gammacraft.TileEntity.BluePrintTableTileEntity;

import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.util.ResourceLocation;

public class BluePrintTableGui extends GuiScreen{
public static final int GUI_ID = 20;


public static final ResourceLocation texture = new ResourceLocation("gammacraft","textures/BluePrintTable.png");

  public BluePrintTableGui() {}
      
      @Override
      public void drawScreen(int par1, int par2, float par3) {
              this.drawDefaultBackground();
              this.drawRect(50, 50, 100, 100, 5);
      }


}

 

the stacktrace is

---- Minecraft Crash Report ----

// Don't be sad, have a hug! <3

 

Time: 9/12/14 7:19 PM

Description: Unexpected error

 

java.lang.NullPointerException: Unexpected error

at cpw.mods.fml.common.network.NetworkRegistry.getLocalGuiContainer(NetworkRegistry.java:263)

at cpw.mods.fml.common.network.internal.FMLNetworkHandler.openGui(FMLNetworkHandler.java:93)

at net.minecraft.entity.player.EntityPlayer.openGui(EntityPlayer.java:2255)

at com.example.gammacraft.blocks.BluePrintTable.onBlockActivated(BluePrintTable.java:44)

at net.minecraft.client.multiplayer.PlayerControllerMP.onPlayerRightClick(PlayerControllerMP.java:349)

at net.minecraft.client.Minecraft.func_147121_ag(Minecraft.java:1442)

at net.minecraft.client.Minecraft.runTick(Minecraft.java:1949)

at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:953)

at net.minecraft.client.Minecraft.run(Minecraft.java:870)

at net.minecraft.client.main.Main.main(Main.java:103)

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)

at java.lang.reflect.Method.invoke(Unknown Source)

at net.minecraft.launchwrapper.Launch.launch(Launch.java:134)

at net.minecraft.launchwrapper.Launch.main(Launch.java:28)

 

 

A detailed walkthrough of the error, its code path and all known details is as follows:

---------------------------------------------------------------------------------------

 

-- Head --

Stacktrace:

at cpw.mods.fml.common.network.NetworkRegistry.getLocalGuiContainer(NetworkRegistry.java:263)

at cpw.mods.fml.common.network.internal.FMLNetworkHandler.openGui(FMLNetworkHandler.java:93)

at net.minecraft.entity.player.EntityPlayer.openGui(EntityPlayer.java:2255)

at com.example.gammacraft.blocks.BluePrintTable.onBlockActivated(BluePrintTable.java:44)

at net.minecraft.client.multiplayer.PlayerControllerMP.onPlayerRightClick(PlayerControllerMP.java:349)

at net.minecraft.client.Minecraft.func_147121_ag(Minecraft.java:1442)

 

-- Affected level --

Details:

Level name: MpServer

All players: 1 total; [EntityClientPlayerMP['Player867'/221, l='MpServer', x=276.37, y=78.62, z=652.86]]

Chunk stats: MultiplayerChunkCache: 225, 225

Level seed: 0

Level generator: ID 00 - default, ver 1. Features enabled: false

Level generator options:

Level spawn location: World: (248,64,248), Chunk: (at 8,4,8 in 15,15; contains blocks 240,0,240 to 255,255,255), Region: (0,0; contains chunks 0,0 to 31,31, blocks 0,0,0 to 511,255,511)

Level time: 39191 game time, 39191 day time

Level dimension: 0

Level storage version: 0x00000 - Unknown?

Level weather: Rain time: 0 (now: false), thunder time: 0 (now: false)

Level game mode: Game mode: creative (ID 1). Hardcore: false. Cheats: false

Forced entities: 58 total; [EntityClientPlayerMP['Player867'/221, l='MpServer', x=276.37, y=78.62, z=652.86], EntityBat['Bat'/400, l='MpServer', x=344.75, y=48.10, z=683.25], EntitySheep['Sheep'/401, l='MpServer', x=338.47, y=70.00, z=683.44], EntityPig['Pig'/287, l='MpServer', x=203.50, y=67.00, z=715.31], EntityPig['Pig'/395, l='MpServer', x=344.61, y=69.00, z=627.08], EntityPig['Pig'/394, l='MpServer', x=338.36, y=71.00, z=616.26], EntityPig['Pig'/393, l='MpServer', x=342.84, y=72.00, z=609.84], EntityPig['Pig'/392, l='MpServer', x=349.28, y=70.00, z=614.47], EntityBat['Bat'/399, l='MpServer', x=347.22, y=47.10, z=681.94], EntityBat['Bat'/398, l='MpServer', x=336.13, y=47.10, z=685.34], EntityMinecartChest['entity.MinecartChest.name'/397, l='MpServer', x=342.50, y=38.50, z=680.50], EntityMinecartChest['entity.MinecartChest.name'/396, l='MpServer', x=337.50, y=38.50, z=669.50], EntitySheep['Sheep'/385, l='MpServer', x=329.50, y=80.00, z=677.33], EntityPig['Pig'/384, l='MpServer', x=322.50, y=81.00, z=666.31], EntitySquid['Squid'/307, l='MpServer', x=232.33, y=56.16, z=587.08], EntityBat['Bat'/309, l='MpServer', x=235.49, y=19.66, z=670.56], EntityBat['Bat'/308, l='MpServer', x=237.25, y=51.10, z=668.47], EntityChicken['Chicken'/310, l='MpServer', x=228.41, y=75.00, z=718.56], EntitySheep['Sheep'/315, l='MpServer', x=248.38, y=72.00, z=646.47], EntityBat['Bat'/314, l='MpServer', x=249.75, y=29.10, z=625.75], EntityBat['Bat'/317, l='MpServer', x=249.93, y=12.98, z=663.66], EntityBat['Bat'/316, l='MpServer', x=249.99, y=12.10, z=657.67], EntitySheep['Sheep'/319, l='MpServer', x=245.84, y=77.00, z=671.44], EntityBat['Bat'/318, l='MpServer', x=248.37, y=21.56, z=667.28], EntityPig['Pig'/288, l='MpServer', x=201.03, y=67.00, z=713.84], EntityPig['Pig'/292, l='MpServer', x=215.69, y=76.00, z=691.09], EntityPig['Pig'/293, l='MpServer', x=221.53, y=73.00, z=702.47], EntityPig['Pig'/294, l='MpServer', x=220.69, y=74.00, z=718.50], EntityChicken['Chicken'/295, l='MpServer', x=208.81, y=69.00, z=704.25], EntityChicken['Chicken'/296, l='MpServer', x=209.81, y=68.00, z=717.16], EntityPig['Pig'/297, l='MpServer', x=209.96, y=69.00, z=715.58], EntityPig['Pig'/351, l='MpServer', x=285.50, y=67.00, z=686.84], EntityPig['Pig'/350, l='MpServer', x=281.28, y=70.00, z=677.50], EntityPig['Pig'/349, l='MpServer', x=277.52, y=77.00, z=655.44], EntityPig['Pig'/348, l='MpServer', x=283.53, y=73.00, z=667.44], EntityPig['Pig'/347, l='MpServer', x=274.32, y=78.00, z=638.50], EntityPig['Pig'/346, l='MpServer', x=277.69, y=78.00, z=638.50], EntityBat['Bat'/326, l='MpServer', x=258.75, y=50.10, z=628.25], EntityBat['Bat'/327, l='MpServer', x=261.28, y=48.10, z=626.75], EntityBat['Bat'/325, l='MpServer', x=261.38, y=35.74, z=595.95], EntityPig['Pig'/334, l='MpServer', x=258.84, y=65.00, z=712.06], EntityPig['Pig'/335, l='MpServer', x=270.16, y=64.00, z=708.38], EntityPig['Pig'/332, l='MpServer', x=258.50, y=68.00, z=678.03], EntityPig['Pig'/333, l='MpServer', x=262.78, y=71.00, z=674.50], EntitySheep['Sheep'/330, l='MpServer', x=270.13, y=76.00, z=638.53], EntityPig['Pig'/331, l='MpServer', x=260.50, y=71.00, z=672.16], EntityBat['Bat'/328, l='MpServer', x=262.50, y=48.10, z=626.75], EntityBat['Bat'/329, l='MpServer', x=258.72, y=50.10, z=628.25], EntityPig['Pig'/369, l='MpServer', x=315.78, y=66.00, z=682.88], EntityPig['Pig'/368, l='MpServer', x=304.88, y=81.00, z=658.75], EntitySheep['Sheep'/383, l='MpServer', x=331.50, y=82.00, z=669.66], EntityPig['Pig'/382, l='MpServer', x=320.05, y=85.00, z=654.12], EntityPig['Pig'/352, l='MpServer', x=286.46, y=64.69, z=690.58], EntityPig['Pig'/353, l='MpServer', x=283.53, y=64.00, z=694.78], EntityPig['Pig'/354, l='MpServer', x=275.94, y=64.00, z=710.97], EntityPig['Pig'/364, l='MpServer', x=292.61, y=65.47, z=684.72], EntitySheep['Sheep'/365, l='MpServer', x=290.59, y=70.00, z=672.31], EntityPig['Pig'/363, l='MpServer', x=301.47, y=66.00, z=680.31]]

Retry entities: 0 total; []

Server brand: fml,forge

Server type: Integrated singleplayer server

Stacktrace:

at net.minecraft.client.multiplayer.WorldClient.addWorldInfoToCrashReport(WorldClient.java:384)

at net.minecraft.client.Minecraft.addGraphicsAndWorldToCrashReport(Minecraft.java:2433)

at net.minecraft.client.Minecraft.run(Minecraft.java:899)

at net.minecraft.client.main.Main.main(Main.java:103)

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)

at java.lang.reflect.Method.invoke(Unknown Source)

at net.minecraft.launchwrapper.Launch.launch(Launch.java:134)

at net.minecraft.launchwrapper.Launch.main(Launch.java:28)

 

The proud(ish) developer of Ancients

Link to comment
Share on other sites

My guess is either the player or the world is null at the time of error, maybe its being called early? Try a

 

if(player != null)

and a

if(world != null)

 

in onBlockActivated. Separately, one at a time, for debug purposes. Ultimately I would check for both to ensure no null errors during runtime down the road. Just a shot.

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

Link to comment
Share on other sites

What tutorial did you follow? It is a lousy one if it did not show there are two components to a containerblock GUI. Client component is a regular GUIscreen, server component is a GuiContainer. One is returned in ClientProxy, the other in CommonProxy (or ServerProxy if you have one).

 

Yes, if it has no need of a server element, you can return null for the getServerGuiElement value;

 

edit: To clarify

Link to comment
Share on other sites

Wait a sec, not all guis need a container. GuiContainer does need a container, but GuiScreen doesn't (at least not always?). In my gui handler I return (client side) the guis, and server side the container only if needed. BTW, where is ProcessorGui? I can't find it in your code.. Also, there's no way that, at onBlockActivated, player or world are null idk.

Check out my blog!

http://www.whov.altervista.org

Link to comment
Share on other sites

I too got a NPE when returning null in my gui handler for the container.  I found that it was giving me the NPE due to no slots in the container, even though I was not calling it.  I changed my block class from extending BlockContainer to just extend Block.  Then I didn't need to worry about the container I wasn't using anyway.

 

Link to comment
Share on other sites

It depends what are you doing with your tileentity. Check BlockContainer, it has only few things overriden.

If you have updated your code, could you post the latest? And are you now returning gui for client instead of null?

Link to comment
Share on other sites

They've told you all you need.

A. Your returning null on the gui, thats the clientElement. You cant return null there.

B. Your returning a gui in the serverElement. dont want that

C. You can return serverElement null UNLESS your gui extends GuiContainer. Your clientElement must return a gui class.

D. I wouldnt call this your common proxy class. Its your guihandler. The common and client proxies are different.

[shadow=gray,left][glow=red,2,300]KEEGAN[/glow][/shadow]

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Hey folks. I am working on a custom "Mecha" entity (extended from LivingEntity) that the player builds up from blocks that should get modular stats depending on the used blocks. e.g. depending on what will be used for the legs, the entity will have a different jump strength. However, something unexpected is happening when trying to override a few of LivingEntity's functions and using my new own "Mecha" specific fields: instead of their actual instance-specific value, the default value is used (0f for a float, null for an object...) This is especially strange as when executing with the same entity from a point in the code specific to the mecha entity, the correct value is used. Here are some code snippets to better illustrate what I mean: /* The main Mecha class, cut down for brevity */ public class Mecha extends LivingEntity { protected float jumpMultiplier; //somewhere later during the code when spawning the entity, jumpMultiplier is set to something like 1.5f //changing the access to public didn't help @Override //Overridden from LivingEntity, this function is only used in the jumpFromGround() function, used in the aiStep() function, used in the LivingEntity tick() function protected float getJumpPower() { //something is wrong with this function //for some reason I can't correctly access the fields and methods from the instanciated entity when I am in one of those overridden protected functions. this is very annoying LogUtils.getLogger().info(String.valueOf(this.jumpMultiplier))) //will print 0f return this.jumpMultiplier * super.getJumpPower(); } //The code above does not operate properly. Written as is, the entity will not jump, and adding debug logs shows that when executing the code, the value of this.jumpMultiplier is 0f //in contrast, it will be the correct value when done here: @Override public void tick() { super.tick(); //inherited LivingEntity logic //Custom logic LogUtils.getLogger().info(String.valueOf(this.jumpMultiplier))) //will print 1.5f } } My actual code is slightly different, as the jumpMuliplier is stored in another object (so I am calling "this.legModule.getJumpPower()" instead of the float), but even using a simple float exactly like in the code above didn't help. When running my usual code, the object I try to use is found to be null instead, leading to a crash from a nullPointerException. Here is the stacktrace of said crash: The full code can be viewed here. I have found a workaround in the case of jump strength, but have already found the same problem for another parameter I want to do, and I do not understand why the code is behaving as such, and I would very much like to be able to override those methods as intended - they seemed to work just fine like that for vanilla mobs... Any clues as to what may be happening here?
    • Please delete post. Had not noticed the newest edition for 1.20.6 which resolves the issue.
    • https://paste.ee/p/GTgAV Here's my debug log, I'm on 1.18.2 with forge 40.2.4 and I just want to get it to work!! I cant find any mod names in the error part and I would like some help from the pros!! I have 203 mods at the moment.
    • In 1.20.6 any potion brewed in the brewing stand disappears upon completion.
    • My game crashes whenever I click on Singleplayer then it crashes after the "Saving world". I'm playing on fabric 1.20.1 on forge for the easy instance loading. My game is using 12GB of RAM, I tried deleting the options.txt, and also renaming the saves file but neither worked. Here's the crash report link: https://mclo.gs/qByOqVK
  • Topics

×
×
  • Create New...

Important Information

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