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

Im trying to open a gui container when a button is pressed by the player.

since the button press event is client side only i send a packet to the server to open the container.

but when i try to open the gui by pressing the button it closes imediatly.

 

this is code for my key handler:

@Override
public void keyDown(EnumSet<TickType> types, KeyBinding kb, boolean tickEnd, boolean isRepeat) {
	if(kb.keyCode == isBinding.keyCode){
		if(mc.currentScreen == null){
			player.addChatMessage("Key Pressed");
			this.SendPacket(1, (byte)10, -1);
			FMLNetworkHandler.openGui(player, BaseLegendz.LegendzInstance, 4, mc.theWorld, 0, 0, 0);
		}
	}
    }

private void SendPacket(int par1, byte par2, int par3){
	int byteAmount = par1;
	ByteArrayOutputStream bos = new ByteArrayOutputStream(byteAmount);
	DataOutputStream outputStream = new DataOutputStream(bos);
	try {
		outputStream.writeByte(par2);
		if(par3 > -1){
			outputStream.writeInt(par3);
		}
	} catch (Exception ex) {
	        ex.printStackTrace();
	}
	Packet250CustomPayload packet = new Packet250CustomPayload();
	packet.channel = "MinecraftLegendz";
	packet.data = bos.toByteArray();
	packet.length = bos.size();

	PacketDispatcher.sendPacketToServer(packet);
}

 

here is my gui handler.

 

@Override
public Object getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {
	TileEntity te = world.getBlockTileEntity(x, y, z);

	EntityPlayerMP var1 = (EntityPlayerMP) player;
	IPlayerLegendz playerLegendz = (IPlayerLegendz) var1.getServerPlayerBase("MinecraftLegendz");
	InventoryLegendz inventory = playerLegendz.getInventory();

	if(te != null){
		switch(ID){
		default: return null;

		case 1: return new ContainerLegendzCraftingTable(player.inventory, (TileEntityLegendzCraftingTable)te);

		case 2: return new ContainerLegendzFurnace(player.inventory, (TileEntityLegendzFurnace)te);
		}
	}
	else{
		switch(ID){
		case 4: return new ContainerInventoryLegendz(player.inventory, inventory);
		}
	}
	return null;
}

@Override
public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {
	TileEntity te = world.getBlockTileEntity(x, y, z);

	EntityPlayerSP var1 = (EntityPlayerSP) player;
	IPlayerLegendz playerLegendz = (IPlayerLegendz) var1.getPlayerBase("MinecraftLegendz");
	InventoryLegendz inventory = playerLegendz.getInventory();

	if(ID < 200){
		if(te != null){
			switch(ID){
			case 0: return new GuiLegendzCraftingTable(player.inventory, (TileEntityLegendzCraftingTable)te, player, world, x, y, z);

			case 1: return new GuiLegendzCrafting(player.inventory, (TileEntityLegendzCraftingTable)te);

			case 2: return new GuiLegendzFurnace(player.inventory, (TileEntityLegendzFurnace)te);

			case 3: return new GuiQuest(1, player, world, x, y, z);
			}
		}else{
			switch(ID){
			case 4: return new GuiLegendzInventory(player.inventory, inventory);

			case 5: return new GuiStore(player);

			case 6: return new GuiSkillTree();
			}
		}
	}
	return null;
}

 

and the gui itself.

package legendz;

import net.minecraft.client.Minecraft;
import net.minecraft.client.entity.EntityPlayerSP;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.util.StatCollector;

import org.lwjgl.opengl.GL11;

public class GuiLegendzInventory extends GuiContainer{

private PlayerClient player;

public GuiLegendzInventory(InventoryPlayer inv, InventoryLegendz inventory) {
	super(new ContainerInventoryLegendz(inv,inventory));
	EntityPlayer var1 = Minecraft.getMinecraft().thePlayer;
	EntityPlayerSP var2 = (EntityPlayerSP) var1;
	player = (PlayerClient) var2.getPlayerBase("MinecraftLegendz");
}

public boolean doesGuiPauseGame(){
	return false;
}

protected void drawGuiContainerForegroundLayer(int i, int j){
    	this.fontRenderer.drawString(StatCollector.translateToLocal("Legendz Inventory"), 30, -28, 0xFFFFFF);
        this.fontRenderer.drawString(StatCollector.translateToLocal("Inventory"), 10, this.ySize - 58, 0xFFFFFF);
}

@Override
protected void drawGuiContainerBackgroundLayer(float f, int i, int j) {
	drawDefaultBackground();
	GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
	this.mc.renderEngine.bindTexture("/mods/legendz/textures/gui/inventory.png");
        int var5 = (this.width - 176) / 2;
        int var6 = (this.height - 224) / 2;
        this.drawTexturedModalRect(var5, var6, 0, 0, 176, 224);
        this.drawCenteredString(fontRenderer, player.getBattleClass().getName(), var5+43, var6+25, 0xFFFFFF);
        
        int[] var1 = player.getStats().getTotalStats();
        
        int var2 = 36;
        int var3 = 42;
        
        for(int k = 0; k < player.statNamesShort.length; k++){
        	this.drawString(fontRenderer, player.statNamesShort[k], var5+var2, (var6+var3)+(k*10), 0xFFFFFF);
        	String var4 = ""+var1[k];
        	int xOffset = var4.length()*5;
        	this.drawString(fontRenderer, var4, var5+var2+34-xOffset, (var6+var3)+(k*10), 0xFFFFFF);
        }

}
}

  • Author

thx it works now :).

but the only problem is that when i pick up an item from the players hotbar slots it drops the item on the ground.

here is the container code btw forget to include that in the first post.

public class ContainerInventoryLegendz extends Container{

public ContainerInventoryLegendz(InventoryPlayer par1InventoryPlayer, InventoryLegendz par2InventoryLegendz){
    	
        this.addSlotToContainer(new Slot(par2InventoryLegendz, 0, 62, 17));
        this.addSlotToContainer(new Slot(par2InventoryLegendz, 1, 62, 53));
    	
        int var3;

        for (var3 = 0; var3 < 3; ++var3)
        {
            for (int var4 = 0; var4 < 9; ++var4)
            {
                this.addSlotToContainer(new Slot(par1InventoryPlayer, var4 + var3 * 9 + 9, 8 + var4 * 18, 29+84 + var3 * 18));
            }
        }

        for (var3 = 0; var3 < 9; ++var3)
        {
            this.addSlotToContainer(new Slot(par1InventoryPlayer, var3, 8 + var3 * 18, 29+142));
        }
    }

@Override
public boolean canInteractWith(EntityPlayer var1) {
	return true;
}

public ItemStack transferStackInSlot(EntityPlayer par1EntityPlayer, int par2)
    {
        return null;
    }

}

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.