Posted June 19, 201411 yr So I'm developing my mod, but have run into a brick wall of sorts. I am trying to make it so that is an entity dies(In this case a skeleton) and the player kills it, it checks the players inventory for an item. If the player has the item it will replace it with another, but I cannot find a way to access the player's inventory with the LivingDropsEvent The code: else if (drops.entityLiving instanceof EntitySkeleton){ drops.source. if (drops.source.getDamageType().equals("player")){ for (ItemStack stack : drops.source.getSourceOfDamage().inventory.Maininventory){ if (stack == null){ continue; } else { if (stack.getItem() instanceof ItemTaintedEssence){ //Find a way to reference ItemStacks and use the //SplitStack method with the size of the stack-1 as a parameter for (int i = 0; i < drops.source.getEntity().inventory.Maininventory.length; i++){ if (drops.source.getEntity().inventory.Maininventory == stack){ drops.source.getSourceOfDamage().inventory.Maininventory.splitStack(stack.stackSize-1); } } } } } } Every time I call (drops is an instance of LivingDropsEvent) drops.source.anything().inventory.mainInventory I get an error. Any help is appreciated, thanks.
June 19, 201411 yr Well, your code didn't work partly because the drops object passed into the event if from the dying entity, not from the player. What you need is to access the player that killed the entity. I believe it would look something like this: @SubscribeEvent(priority=EventPriority.NORMAL, receiveCanceled=true) public void onEvent(LivingDropsEvent event) { EntityLivingBase attacker = event.entityLiving.getLastAttacker(); if (attacker instanceof EntityPlayer) { EntityPlayer attackingPlayer = (EntityPlayer)attacker; // do what you want with attackingPlayer inventory here } } You need to understand better how Java works with referencing objects. Basically you can string various fields and methods together but only as long as they belong and are publicly accessible. And if you need to access a field of a subtype then you need to understand how to "cast" the object so that Java provides the required access. Anyway, hope this helps. Check out my tutorials here: http://jabelarminecraft.blogspot.com/
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.