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.

[Solved][1.7.10]Pressing key opens backpack stored in inventory slot

Featured Replies

Posted

My Keyhandler works but the problem is, how do i access the backpack when it is in a armorslot? I tried it with checking and that stuff. It goes through all the if's and print out:

 

player

not holding

in armor slot

armoritem in slot

right item

armor slot/Client

 

but in the end it doesnt open ._.

 

 

 

 

public class GuiHandler implements IGuiHandler

{

private Minecraft mc;

 

@Override

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

{

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

mc = Minecraft.getMinecraft();

 

switch(ID)

{

case 0: return ID == 0 ? new ContainerAltar(player.inventory, (TileEntityAltar) tileEntity) : null;

case 2: return ID == 2 ? new ContainerCobaltFurnace(player.inventory, (TileEntityCobaltFurnace) tileEntity) : null;

case 3: return ID == 3 ? new ContainerRitualStone(player.inventory, (TileEntityRitualStone) tileEntity) : null;

case 4: return ID == 4 && world.getBlock(x, y, z) == CMStuff.cobexworkbench ? new ContainerBlueWoodWorkBench(player.inventory, world, x, y, z) : null;

case 5:

 

ItemStack[] armor = mc.thePlayer.inventory.armorInventory;

 

if (player != null) {

System.out.println("player");

if (player.getHeldItem() != null) {

System.out.println("hold in hands");

if (player.getHeldItem().getItem() == CMStuff.cobaltbackpack) {

System.out.println("right item in Hands");

System.out.println("hands/Server");

return ID == 5 ? new ContainerBackpack(player, player.inventory, new InventoryBackpack(player.getHeldItem())) : null;

}

}

else if(armor[2] != null)

{

System.out.println("not holding");

System.out.println("in armor slot");

Item item = armor[2].getItem();

if(item instanceof ItemArmor)

{

System.out.println("armoritem in slot");

ItemArmor itemA = (ItemArmor) item;

if(itemA.getArmorMaterial() == CMStuff.WoolArmor)

{

ItemStack backpack = armor[2];

System.out.println("right item");

System.out.println("armor slot/Server");

return ID == 5 ? new ContainerBackpack(player, player.inventory, new InventoryBackpack(backpack)) : null;

}

}

}

}

}

 

return null;

}

 

@Override

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

{

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

 

switch(ID)

{

case 0: return ID == 0 ? new GuiAltar(player.inventory, (TileEntityAltar) tileEntity) : null;

case 1: return ID == 1 ? new GuiRecipeBook(player) : null;

case 2: return ID == 2 ? new GuiCobaltFurnace(player.inventory, (TileEntityCobaltFurnace) tileEntity) : null;

case 3: return ID == 3 ? new GuiRitualStone(player.inventory, (TileEntityRitualStone) tileEntity) : null;

case 4: return ID == 4 && world.getBlock(x, y, z) == CMStuff.cobexworkbench ? new GuiBlueWoodWorkBench(player.inventory, world, x, y, z) : null;

case 5:

 

ItemStack[] armor = mc.thePlayer.inventory.armorInventory;

 

if (player != null) {

System.out.println("player");

if (player.getHeldItem() != null) {

System.out.println("hold in hands");

if (player.getHeldItem().getItem() == CMStuff.cobaltbackpack) {

System.out.println("right item in Hands");

System.out.println("hands/Client");

return ID == 5 ? new GuiBackpack((ContainerBackpack) new ContainerBackpack(player, player.inventory, new InventoryBackpack(player.getHeldItem()))) : null;

}

}

else if(armor[2] != null)

{

System.out.println("not holding");

System.out.println("in armor slot");

Item item = armor[2].getItem();

if(item instanceof ItemArmor)

{

System.out.println("armoritem in slot");

ItemArmor itemA = (ItemArmor) item;

if(itemA.getArmorMaterial() == CMStuff.WoolArmor)

{

ItemStack backpack = armor[2];

System.out.println("right item");

System.out.println("armor slot/Client");

return ID == 5 ? new GuiBackpack((ContainerBackpack) new ContainerBackpack(player, player.inventory, new InventoryBackpack(backpack))) : null;

}

}

}

}

}

return null;

}

 

}

 

 

 

If the spoiler doesnt seem to work:

 

http://pastebin.com/bRQw7En6

 

i also tried it with armor[2] instead of backpack, but it still not work. When i have it in my hands and press rightclick it works perfectly, its simply the key + slot problem :/ Hope someone can help me ^^

 

 

I know the problem is the itemstack im using for the "new InventoryBackpack())) : null;", but i cant figure out how i get the one i have in the slot stored.

  • Author

Already doing that:

 

@SubscribeEvent
public void onKeyInput(KeyInputEvent event) {
	if (mc.inGameHasFocus) {
		if (key.getIsKeyPressed()) {
			CobaltPacketDispatcher.sendToServer(new CobaltOpenGuiMessage(5));
		}
	}
}

 

 

The problem is i need the itemstack or the gui/container doesnt open. And yes it is copy&paste from a tutorial about packets.

 

https://bitbucket.org/Dragonisser/cobaltmod/src

  • Author

Changed it to: ItemStack[] armor = player.inventory.armorInventory;

 

I hope that was it, what you meant but still nothing happends ._.

  • Author

It print this in the console:

 

player
not holding
in armor slot
armoritem in slot
right item
armor slot/Server

player
not holding
in armor slot
armoritem in slot
right item
armor slot/Client

  • Author

I think i found another way :3

 

 

https://bitbucket.org/Dragonisser/cobaltmod/src/76e33bd900578fe3f52ee4d4d19c3b5bcf646c9a/cobaltmod/gui/InventoryBackpack.java#cl-130

 

https://bitbucket.org/Dragonisser/cobaltmod/src/76e33bd900578fe3f52ee4d4d19c3b5bcf646c9a/cobaltmod/handler/GuiHandler.java#cl-31

 

It seems to work perfectly except i cant pickup item/blocks and move them, it only works with shiftclick ._.

 

I know where the problem is:

 

@Override
public ItemStack slotClick(int slot, int button, int flag, EntityPlayer player) {
	// this will prevent the player from interacting with the item that opened the inventory:
	if (slot >= 0 && getSlot(slot) != null && getSlot(slot).getStack() == player.getHeldItem()) {
		return null;
	}
	return super.slotClick(slot, button, flag, player);
}

  • Author

Gonna take a look at it ^^

 

I guess i need this:

public void onPickupFromSlot(EntityPlayer p_82870_1_, ItemStack p_82870_2_)

    {

        this.onSlotChanged();

    }

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.