Jump to content

GUI Screen issues


RafaMv

Recommended Posts

Hey guys, I am trying to create a GUI that opens when I click on my custom entity. This is a basic GUI, which will show some information about the entity. This is what I've done so far:

 

Gui Class:

 

 

public class GuiAnalyzer extends GuiScreen {

 

private ResourceLocation texture = new ResourceLocation(BygoneAgeGuiInformation.ANALYZER.getPrimaryGuiPath());

private int xSize;

private int ySize;

 

public GuiAnalyzer() {

super();

this.xSize = 176;

this.ySize = 188;

}

 

@Override

public void initGui() {

System.out.println("Hello?");

this.buttonList.clear();

this.buttonList.add(new GuiButton(0, 40 + (this.width - this.xSize) / 2, 40 + (this.height - this.ySize) / 2, 100, 20, "TEST"));

super.initGui();

}

 

@Override

public void drawScreen(int x, int y, float f) {

drawDefaultBackground();

 

GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);

this.mc.renderEngine.bindTexture(texture);

drawTexturedModalRect((this.width - this.xSize) / 2, (this.height - this.ySize) / 2, 0, 0, this.xSize, this.ySize);

 

super.drawScreen(x, y, f);

}

 

@Override

public void onGuiClosed() {

super.onGuiClosed();

}

 

}

 

 

 

How I am trying to open this guiscreen:

 

 

@Override

public boolean interact(EntityPlayer player) {

if (!this.worldObj.isRemote) {

player.openGui(BygoneAge.instance, BygoneAgeGuiInformation.ANALYZER.getGuiId(), this.worldObj, (int) this.posX, (int) this.posY, (int) this.posZ);

}

return super.interact(player);

}

 

 

 

Gui Handler:

 

 

@Override

public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {

TileEntity tileEntity = world.getTileEntity(x, y, z);

if (tileEntity != null) {

                        if (ID == BygoneAgeGuiInformation.ANALYZER.getGuiId()) {

return ID == BygoneAgeGuiInformation.ANALYZER.getGuiId() ? new GuiAnalyzer() : null;

}

}

return null;

}

 

 

 

Am I missing some thing? Btw, any idea how can I have access to the entity?

Link to comment
Share on other sites

Found my mistake. I was trying to check the id after checking the tileentity at position (x, y, z) which is obviously null. Ops! :x

 

However I am having trouble with the getValues from the entity class. For some reason the values that I'm getting is from the server side, which are not updated (different values compared to the client). Only the getHealth() and getSpeed() are correct. Note: I'm using DataWatcher in one of these variables and it doesn't work either.

 

My common proxy:

 

 

public class CommonProxy {

 

(...)

 

public void registerNetwork() {

NetworkRegistry.INSTANCE.registerGuiHandler(BygoneAge.instance, new BygoneAgeGuiHandler());

}

 

}

 

 

 

My client proxy:

 

 

 

@Override

public void registerRender() {

(...)

}

 

@Override

public void registerTileEntitySpecialRender() {

(...)

}

 

 

 

 

My main class:

 

 

@Mod(modid = BygoneAge.MODID, name = BygoneAge.MODNAME, version = BygoneAge.VERSION)

public class BygoneAge {

 

public static final String MODID = "bygoneage";

public static final String VERSION = "Alpha v0.6.0";

public static final String MODNAME = "Bygone Age";

public static final String DEPENDENCIES = "Forge and AnimationAPI";

    public static EntityBygoneAgeCreature creatureToAnalyze;

public static CreativeTabs bygoneAgeTab = new CreativeTabs("BygoneAgeTab") {

@SideOnly(Side.CLIENT)

public Item getTabIconItem() {

return Item.getItemFromBlock(BygoneAgeBlocks.hatchery);

}

};

 

 

@Instance(MODID)

public static BygoneAge instance;

 

@SidedProxy(clientSide = "com.rafamv.bygoneage.proxy.ClientProxy", serverSide = "com.rafamv.bygoneage.proxy.ServerProxy")

public static CommonProxy bygoneAgeProxy;

 

@EventHandler

public void preInit(FMLPreInitializationEvent preEvent) {

BygoneAgeBlocks.registryAll();

BygoneAgeItems.registryAll();

}

 

@EventHandler

public void init(FMLInitializationEvent event) {

bygoneAgeProxy.registerRender();

bygoneAgeProxy.registerTileEntitySpecialRender();

bygoneAgeProxy.tileEntityRegistry();

bygoneAgeProxy.registerNetwork();

BygoneAgeEntities.registryAll();

BygoneAgeRecipe.registryAll();

}

 

@EventHandler

public void postInit(FMLPostInitializationEvent postEvent) {

 

}

}

 

 

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



×
×
  • Create New...

Important Information

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