Posted October 3, 201410 yr 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.
October 4, 201410 yr Author How am i going to send a packet containing the right itemstack in the armorslot?
October 4, 201410 yr 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
October 4, 201410 yr Author Changed it to: ItemStack[] armor = player.inventory.armorInventory; I hope that was it, what you meant but still nothing happends ._.
October 5, 201410 yr 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
October 5, 201410 yr 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); }
October 5, 201410 yr Author This piece of code is from my Container class. https://bitbucket.org/Dragonisser/cobaltmod/src/76e33bd900578fe3f52ee4d4d19c3b5bcf646c9a/cobaltmod/gui/ContainerBackpack.java?at=master#cl-180
October 5, 201410 yr Author But i doesnt put the backpack in any custom slot, that's why i dont understand why i should need this.
October 5, 201410 yr 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(); }
October 5, 201410 yr Author Well i did it the other way https://bitbucket.org/Dragonisser/cobaltmod/commits/283795b0c366596dc22362f56cb558f9d8ff04ab And it seems to work 100% =3
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.