Пример #1
0
 public ItemStack onItemRightClick(ItemStack stack, World world, EntityPlayer player) {
   if (player.isSneaking()) {
     ItemStack newStack = new ItemStack(ModObjects.heartWand, 1, stack.getItemDamage() + 1);
     if (newStack.getItemDamage() >= 3) {
       newStack.setItemDamage(0);
     }
     return newStack;
   } else {
     ItemStack container;
     switch (stack.getItemDamage()) {
       case 0:
         container = LifeSystem.findFilledLifeContainer(player.inventory.mainInventory);
         if (container != null && player.getHealth() < player.getMaxHealth()) {
           if (((ILifeContainer) container.getItem()).takeLife(container, 1) > 0) {
             player.heal(1f);
             player.addStat(ModAchievements.useLP, 1);
           }
         }
         break;
       case 1:
         break;
       case 2:
         container = LifeSystem.findEmptyLifeContainer(player.inventory.mainInventory);
         if (container != null && player.attackEntityFrom(ModObjects.sacrifice, 1f)) {
           if (((ILifeContainer) container.getItem()).addLife(container, 1) > 0) {
             player.addStat(ModAchievements.useHeartWand, 1);
           }
         }
         break;
     }
   }
   return stack;
 }
Пример #2
0
 @Override
 public boolean itemInteractionForEntity(
     ItemStack itemStack, EntityPlayer player, EntityLivingBase entity) {
   if (entity.worldObj.isRemote) {
     return false;
   } else {
     ItemStack container;
     switch (itemStack.getItemDamage()) {
       case 0:
         break;
       case 1:
         container = LifeSystem.findFilledLifeContainer(player.inventory.mainInventory);
         if (container != null && entity.getHealth() < entity.getMaxHealth()) {
           if (((ILifeContainer) container.getItem()).takeLife(container, 1) > 0) {
             entity.heal(1f);
             player.addStat(ModAchievements.useLP, 1);
             return true;
           }
         }
         break;
       case 2:
         break;
     }
   }
   return false;
 }