Jump to content

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


Recommended Posts

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.

Posted

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

Posted

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

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.

Announcements



×
×
  • Create New...

Important Information

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