@Override
 public EnumAnimation c_(ItemStack itemstack) {
   CustomItem item = MaterialData.getCustomItem(itemstack.getData());
   if (item instanceof Food) {
     return EnumAnimation.EAT;
   }
   return super.c_(itemstack);
 }
 @Override
 public ItemStack b(ItemStack itemstack, World world, EntityHuman entityhuman) {
   CustomItem item = MaterialData.getCustomItem(itemstack.getData());
   if (item instanceof Food) {
     --itemstack.count;
     entityhuman.getFoodData().eat(((Food) item).getHungerRestored(), 0.6F);
   }
   return itemstack;
 }
  @Override
  public ItemStack a(ItemStack itemstack, World world, EntityHuman entityhuman) {
    CustomItem item = MaterialData.getCustomItem(itemstack.getData());
    if (item instanceof Food) {
      Bukkit.getScheduler()
          .scheduleSyncDelayedTask(Spout.getInstance(), new FoodUpdate(entityhuman, itemstack), 2);
    }

    return itemstack;
  }
Example #4
0
  public boolean handlePlayerInteraction(EntityHuman entityhuman) {
    if (super.handlePlayerInteraction(entityhuman)) {
      return true;
    }

    ItemStack itemStack = entityhuman.inventory.getItemInHand();

    if (getOwner().equals(entityhuman) && itemStack != null && canUseItem()) {
      if (itemStack.id == Item.SHEARS.id && getOwner().getPlayer().isSneaking()) {
        if (!canEquip()) {
          return false;
        }
        for (EquipmentSlot slot : EquipmentSlot.values()) {
          ItemStack itemInSlot = ((MySkeleton) myPet).getEquipment(slot);
          if (itemInSlot != null) {
            EntityItem entityitem = this.a(itemInSlot.cloneItemStack(), 1.0F);
            entityitem.motY += (double) (this.random.nextFloat() * 0.05F);
            entityitem.motX +=
                (double) ((this.random.nextFloat() - this.random.nextFloat()) * 0.1F);
            entityitem.motZ +=
                (double) ((this.random.nextFloat() - this.random.nextFloat()) * 0.1F);
            setPetEquipment(slot.getSlotId(), null);
          }
        }
        return true;
      } else if (checkForEquipment(itemStack) && getOwner().getPlayer().isSneaking()) {
        if (!canEquip()) {
          return false;
        }
        EquipmentSlot slot = EquipmentSlot.getSlotById(b(itemStack));
        ItemStack itemInSlot = ((MySkeleton) myPet).getEquipment(slot);
        if (itemInSlot != null && !entityhuman.abilities.canInstantlyBuild) {
          EntityItem entityitem = this.a(itemInSlot.cloneItemStack(), 1.0F);
          entityitem.motY += (double) (this.random.nextFloat() * 0.05F);
          entityitem.motX += (double) ((this.random.nextFloat() - this.random.nextFloat()) * 0.1F);
          entityitem.motZ += (double) ((this.random.nextFloat() - this.random.nextFloat()) * 0.1F);
        }
        ItemStack itemStackClone = itemStack.cloneItemStack();
        itemStackClone.count = 1;
        setPetEquipment(b(itemStack), itemStackClone);
        if (!entityhuman.abilities.canInstantlyBuild) {
          --itemStack.count;
        }
        if (itemStack.count <= 0) {
          entityhuman.inventory.setItem(entityhuman.inventory.itemInHandIndex, null);
        }
        return true;
      }
    }
    return false;
  }
Example #5
0
 public boolean checkForEquipment(ItemStack itemstack) {
   int slot = b(itemstack);
   if (slot == 0) {
     if (itemstack.getItem() instanceof ItemSword) {
       return true;
     } else if (itemstack.getItem() instanceof ItemAxe) {
       return true;
     } else if (itemstack.getItem() instanceof ItemSpade) {
       return true;
     } else if (itemstack.getItem() instanceof ItemHoe) {
       return true;
     } else if (itemstack.getItem() instanceof ItemPickaxe) {
       return true;
     } else if (itemstack.getItem() instanceof ItemBow) {
       return true;
     }
     return false;
   } else {
     return true;
   }
 }