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 everyone,

I am working on a Block with a guicontainer and it seems that it wont open, guess I am missing something

 

the GuiHandler is registered in the init method

 

 NetworkRegistry.INSTANCE.registerGuiHandler(instance, new GuiHandler()); 

 

The block that should open the gui

public class Base extends BlockContainer{

public Base( ) {
	super(Material.iron);
	setCreativeTab(CreativeTabs.tabFood);
}

@Override
public TileEntity createNewTileEntity(World worldIn, int meta) {
	// TODO Auto-generated method stub
	return new TileEntityBase();
}

@Override
public int getRenderType()
{
	return 3;
}

@Override
public boolean onBlockActivated(World worldIn, BlockPos pos,
		IBlockState state, EntityPlayer playerIn, EnumFacing side,
		float hitX, float hitY, float hitZ) {
	if(!worldIn.isRemote)
	{
		System.out.println("call");
		playerIn.openGui(BaseWars.instance, BaseWars.BASEGUIID, worldIn, pos.getX(), pos.getY(), pos.getZ());
	}
	return true;
}




}

 

Heres the handler


public class GuiHandler implements IGuiHandler{

@Override
public Object getServerGuiElement(int ID, EntityPlayer player, World world,
		int x, int y, int z) {
	switch (ID) {
	case BaseWars.BASEGUIID: new ContainerBase(player.inventory, (TileEntityBase) world.getTileEntity(new BlockPos(x,y,z)));

	default: return null;
	}
}

@Override
public Object getClientGuiElement(int ID, EntityPlayer player, World world,
		int x, int y, int z) {
	switch (ID) {
	case BaseWars.BASEGUIID: return new GuiBase(new ContainerBase(player.inventory, (TileEntityBase) world.getTileEntity(new BlockPos(x,y,z))));
	default: return null;		
	}
}
}

 

the GUI

 


public class GuiBase extends GuiContainer{

private final ResourceLocation background = new ResourceLocation("basewars:textures/gui/base.png");


public GuiBase(Container container) {
	super(container);
}

@Override
protected void drawGuiContainerBackgroundLayer(float partialTicks,
		int mouseX, int mouseY) {
	mc.renderEngine.bindTexture(background);
	int k = (this.width - this.xSize) /2 ;
	int l = (this.width - this.xSize) /2 ;
	drawTexturedModalRect(k, l, 0, 0, xSize, ySize);
}
}

 

and the (not finished) container

 

public class ContainerBase extends Container{

@Override
public boolean canInteractWith(EntityPlayer playerIn) {
	// TODO Auto-generated method stub
	return true;
}

public ContainerBase(IInventory playerInv, TileEntityBase base)
{

	int i= -18;


	for (int j = 0; j < 3; ++j){
            for (int k = 0; k < 9; ++k) {
                this.addSlotToContainer(new Slot(playerInv, k + j * 9 + 9, 8 + k * 18, 102 + j * 18 + i));
            }
        }

        for (int j = 0; j < 9; ++j) {
            this.addSlotToContainer(new Slot(playerInv, j, 8 + j * 18, 160 + i));
        }
}
}

 

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.