Jump to content

[1.8] messing with guis


Failender

Recommended Posts

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));
        }
}
}

 

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.



×
×
  • Create New...

Important Information

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