Jump to content

Looke81

Members
  • Posts

    250
  • Joined

  • Last visited

Everything posted by Looke81

  1. @Override public boolean isItemValid(ItemStack itemstack) { if (itemstack.getItem() instanceof IBauble ){ for (int a = 0; a < inventory.INV_SIZE; a++) { if(itemstack.areItemStacksEqual(itemstack, inventory.getStackInSlot(a))){ if(inventory.getStackInSlot(a) != null){ return true; } } } } return false; } Thanks. Except now I cant put an item in the inventory at all.
  2. From ItemStack Class @SideOnly(Side.CLIENT) public boolean getIsItemStackEqual(ItemStack p_179549_1_) { return this.isItemStackEqual(p_179549_1_); } private boolean isItemStackEqual(ItemStack other) { return this.stackSize != other.stackSize ? false : (this.item != other.item ? false : (this.itemDamage != other.itemDamage ? false : (this.stackTagCompound == null && other.stackTagCompound != null ? false : this.stackTagCompound == null || this.stackTagCompound.equals(other.stackTagCompound)))); } Nope http://pastebin.com/HkrTfcia
  3. I want to make sure not more than one type of item can be placed in the inventory. Probably not like this because this crashes? @Override public boolean isItemValid(ItemStack itemstack) { if (itemstack.getItem() instanceof IBauble ){ for (int a = 0; a < inventory.INV_SIZE; a++) { if(itemstack.getIsItemStackEqual(inventory.getStackInSlot(a))){ return true; } } return false; } return false; }
  4. I want to make sure you can only put one type of any item in my custom inventory. I know i need to use the isItemValid method but I don't know how to check if that item already exists in my inventory.
  5. Ok looks like I will have to take a different approach to this. Sorry I should have listened to you in the first place but I'm stubborn.
  6. Very good point. Not to mention every other mod that takes the item out of the players inventory. Is there anyway to tell when the items stacksize has been decreased?Otherwise I may have to use a different approach with this whole thing but for now il continue on. Well I thought it was a server client issue because throwing the item didn't stop my flight but i still took damage and so with this: @SubscribeEvent public void ItemTossEvent(ItemTossEvent event) { EntityPlayer player = event.player; if (event.entityItem.getEntityItem().getItem() == TatItems.itemBaublesBag) { ItemStack baublesbag = event.entityItem.getEntityItem(); InventoryBaublesBag inventorybaublesbag = (InventoryBaublesBag) BaublesBag.getInventory(baublesbag, player); for (int a = 0; a < inventorybaublesbag.inventory.length; a++) { if (inventorybaublesbag.getStackInSlot(a) != null && inventorybaublesbag.getStackInSlot(a).getItem() instanceof IBauble) { if(player.worldObj.isRemote){ System.out.println("client"); } if(!player.worldObj.isRemote){ System.out.println("server"); } ((IBauble) inventorybaublesbag.getStackInSlot(a).getItem()).onUnequipped(inventorybaublesbag.getStackInSlot(a), player); } } } } Putting the item outside the inventory prints both client and server whereas pressing "q" only prints server. So I think I am right in saying I need to send a packet from the server to the client then? Not an expert.
  7. So why doesn't it work?(it works for the throwing out of inventory but not for pressing Q)
  8. Cant I tell when the player presses the "toss key"?
  9. Yes I do that but their inventory is not an item inventory and so I need to make sure when the player dies (which ive done) or when the player tosses the item that the unequipped method is called.Becasue decrStackSize does not get called when this happens.
  10. Changed to PlayerTickEvent. Changed to .equals . onUnequiped is the method that is called when the bauble item is removed from the baubles inventory. I need to call is because I am basically making my own version of their inventory. If you haven't already: https://github.com/Azanor/Baubles
  11. If you are familiar with the mod baubles it is an api that allows you to add "rings" and "amulets". I am calling the methods that these items use when they need to be activated if they are in my custom inventory. But i need to turn these attributes off if the item inventory is removed from the players inventory. TickHandler public class TatEventHandler { @SubscribeEvent public void PlayerEvent(PlayerEvent event) { EntityPlayer player = event.entityPlayer; if (player instanceof EntityPlayer) { if (player.isDead) { for (int a = 0; a < player.inventory.mainInventory.length; a++) { if (player.inventory.getStackInSlot(a) == new ItemStack(TatItems.itemBaublesBag)) { ItemStack baublesbag = player.inventory.getStackInSlot(a); InventoryBaublesBag inventorybaublesbag = (InventoryBaublesBag) BaublesBag.getInventory(baublesbag, player); for (int b = 0; b < inventorybaublesbag.inventory.length; b++) { if (inventorybaublesbag.getStackInSlot(b) != null && inventorybaublesbag.getStackInSlot(b).getItem() instanceof IBauble) { ((IBauble) inventorybaublesbag.getStackInSlot(b).getItem()).onUnequipped(inventorybaublesbag.getStackInSlot(b), player); } } } } } } } @SubscribeEvent public void ItemTossEvent(ItemTossEvent event) { EntityPlayer player = event.player; if (event.entityItem.getEntityItem().getItem() == TatItems.itemBaublesBag) { ItemStack baublesbag = event.entityItem.getEntityItem(); InventoryBaublesBag inventorybaublesbag = (InventoryBaublesBag) BaublesBag.getInventory(baublesbag, player); for (int a = 0; a < inventorybaublesbag.inventory.length; a++) { if (inventorybaublesbag.getStackInSlot(a) != null && inventorybaublesbag.getStackInSlot(a).getItem() instanceof IBauble) { ((IBauble) inventorybaublesbag.getStackInSlot(a).getItem()).onUnequipped(inventorybaublesbag.getStackInSlot(a), player); } } } } }
  12. I have a custom inventory item that when particular items are in it it does something to the player but i need to stop that thing from happening when the item is removed from the player inventory.
  13. Hmm I'm not sure if you understand what I meant because I just used ItemTossEvent and that: * Event that is fired whenever a player tosses (Q) an item or drag-n-drops a * stack of items outside the inventory GUI screens. Canceling the event will * stop the items from entering the world, but will not prevent them being * removed from the inventory - and thus removed from the system. However the throwing outside the player gui works but the dropping on the ground only works on one side and i need it on both client and server.
  14. Ok. Can I tell if the item is removed by dropping it or if it is removed by picking up out the inventory?
  15. You can use the OnUpdate method in Item to tell if the item is in the players inventory but how do you tell when an item is removed from the players inventory?
  16. I have a custom Item inventory and I am looking for a method that calls when a new item is placed in that gives the player and itemstack. I have tried the setInventorySlotContents from IInventory and putStack from Slot. They would both work except they call when the inventory is opened as well.
  17. Thanks just one last question is there a way to get the item the player has on its mouse?
  18. How do i get the inventory from the itemstack from onUpdate?
  19. Thanks this worked except it stopped being called when the inventory was closed which was not what I wanted
  20. My inventory is an item right click inventory.
  21. OnUpdate method is not called when and item is in a custom inventory so how can I make sure Items onupdate is called?
  22. Fixed armour slot and crashing but it still multipies and I am not sure why becasue I make one item and delete the other thefore there should only be one item? private Random rand = new Random(); public void onUpdate(ItemStack itemstack, World worldIn, Entity entity, int itemSlot, boolean isSelected) { EntityPlayer player = (EntityPlayer) entity; if (player.inventory.hasItem(this)) { List stacks = player.inventoryContainer.inventoryItemStacks; List slots = player.inventoryContainer.inventorySlots; int index = rand.nextInt(35); Slot slot = (Slot) slots.get(index); ItemStack stack = (ItemStack) stacks.get(index); if (stack == null && index != itemSlot ) { player.inventory.setInventorySlotContents(index, itemstack); player.inventory.setInventorySlotContents(itemSlot, null); } else if (stack != null && index != itemSlot) { if (stack != itemstack) { player.inventory.setInventorySlotContents(index, itemstack); player.inventory.setInventorySlotContents(itemSlot, stack); } } } }
  23. Ok so it duplicates when it goes into the Armour inventory so i need to stop that from happening. crash log: http://pastebin.com/g7b85G4N
  24. ok this is what I have now and it works but sometimes is makes 2 items instead of 1 and it crashes after a couple jumps. public void onUpdate(ItemStack itemstack, World worldIn, Entity entity, int itemSlot, boolean isSelected) { EntityPlayer player = (EntityPlayer) entity; if (player.inventory.hasItem(this)) { List stacks = player.inventoryContainer.inventoryItemStacks; List slots = player.inventoryContainer.inventorySlots; int randintamount = slots.size(); int index = rand.nextInt(slots.size()); Slot slot = (Slot) slots.get(index); ItemStack stack = (ItemStack) stacks.get(index); if (player.worldObj.rand.nextInt(100) == 1) { if (stack == null) { player.inventory.setInventorySlotContents(index, itemstack); player.inventory.setInventorySlotContents(itemSlot, null); } else if (stack != null) { if (stack != itemstack) { player.inventory.setInventorySlotContents(index, itemstack); player.inventory.setInventorySlotContents(itemSlot, stack); } } } } }
×
×
  • Create New...

Important Information

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