Posted June 5, 20169 yr I have subscribed to the ServerChatEvent and am searching the inventory for an item but the entire inventory appears to be empty. I can provide code if necessary but do not see how my code could have created this problem (for testing all I'm doing is looping through the inventory and printing to the console if an itemstack position is not null). Thanks in advance
June 5, 20169 yr I would recommend posting your code, you may have made a mistake somewhere without realising it. Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.
June 5, 20169 yr Author You're probably right, just didn't want to have to load another browser. Event Handler public class SCEventHandler { @SubscribeEvent public void HandleServerChat(ServerChatEvent event) { System.out.println("Running HandleServerChat"); ItemStack[] inventory = event.player.getInventory(); System.out.println(inventory); boolean hasMufflingCrystal = false; for (int i = 0; i < inventory.length; i++) { ItemStack item = inventory[i]; if (item != null )//&& item.getItem() instanceof ItemCrystal && item.getItemDamage() == SCNames.Items.CRYSTAL.length - 1) { System.out.println("item exists"); hasMufflingCrystal = true; } if (hasMufflingCrystal) break; } if (hasMufflingCrystal) { System.out.println("Cancelling event"); event.setCanceled(true); } } } Mod Class (part) @EventHandler public void preInit(FMLPreInitializationEvent event) { MinecraftForge.EVENT_BUS.register(new SCEventHandler()); SCItems.initItems(); SCBlocks.initBlocks(); SCTileEntities.initTileEntities(); if(event.getSide() == Side.CLIENT) { SCItems.initTextures(); } }
June 5, 20169 yr If you look at the implementation of EntityPlayer#getInventory , you'll see that it actually returns the player's armour inventory rather than their main inventory. Use EntityPlayer#inventory or PlayerMainInvWrapper . In 1.9.4+, call ICapabilityProvider#getCapability on an EntityPlayer with CapabilityItemHandler.ITEM_HANDLER_CAPABILITY and a vertical EnumFacing to get an IItemHandler wrapper of their main inventory or a null EnumFacing to get an IItemHandler wrapper of their whole inventory (main, armour and off hand). Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.
June 5, 20169 yr Oh, my fault for expecting names to make sense. Thanks. If it's any consolation, the method doesn't exist in 1.9+. Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.
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.