Java Code Examples for net.minecraft.entity.player.EntityPlayer#hasCapability()
The following examples show how to use
net.minecraft.entity.player.EntityPlayer#hasCapability() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DamageXpHandler.java From TinkersToolLeveling with MIT License | 7 votes |
private void distributeXpToPlayerForTool(EntityPlayer player, ItemStack tool, float damage) { if(!tool.isEmpty() && player.hasCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null)) { IItemHandler itemHandler = player.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null); // check for identity. should work in most cases because the entity was killed without loading/unloading for(int i = 0; i < itemHandler.getSlots(); i++) { if(itemHandler.getStackInSlot(i) == tool) { TinkerToolLeveling.modToolLeveling.addXp(tool, Math.round(damage), player); return; } } // check for equal stack in case instance equality didn't find it for(int i = 0; i < itemHandler.getSlots(); i++) { if(ToolCore.isEqualTinkersItem(itemHandler.getStackInSlot(i), tool)) { TinkerToolLeveling.modToolLeveling.addXp(itemHandler.getStackInSlot(i), Math.round(damage), player); return; } } } }