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

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?

  • Author

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) {

 

}

}

 

 

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.