Ejemplo n.º 1
0
  /**
   * Called when a player interacts with a mob. e.g. gets milk from a cow, gets into the saddle on a
   * pig.
   */
  public boolean interact(EntityPlayer par1EntityPlayer) {
    ItemStack itemstack = par1EntityPlayer.inventory.getCurrentItem();

    if (!isTamed()) {
      if (itemstack != null && itemstack.itemID == Item.bone.shiftedIndex && !isAngry()) {
        if (!par1EntityPlayer.capabilities.isCreativeMode) {
          itemstack.stackSize--;
        }

        if (itemstack.stackSize <= 0) {
          par1EntityPlayer.inventory.setInventorySlotContents(
              par1EntityPlayer.inventory.currentItem, null);
        }

        if (!worldObj.isRemote) {
          if (rand.nextInt(3) == 0) {
            setTamed(true);
            setPathToEntity(null);
            setAttackTarget(null);
            aiSit.func_48407_a(true);
            setEntityHealth(20);
            setOwner(par1EntityPlayer.username);
            func_48142_a(true);
            worldObj.setEntityState(this, (byte) 7);
          } else {
            func_48142_a(false);
            worldObj.setEntityState(this, (byte) 6);
          }
        }

        return true;
      }
    } else {
      if (itemstack != null && (Item.itemsList[itemstack.itemID] instanceof ItemFood)) {
        ItemFood itemfood = (ItemFood) Item.itemsList[itemstack.itemID];

        if (itemfood.isWolfsFavoriteMeat() && dataWatcher.getWatchableObjectInt(18) < 20) {
          if (!par1EntityPlayer.capabilities.isCreativeMode) {
            itemstack.stackSize--;
          }

          heal(itemfood.getHealAmount());

          if (itemstack.stackSize <= 0) {
            par1EntityPlayer.inventory.setInventorySlotContents(
                par1EntityPlayer.inventory.currentItem, null);
          }

          return true;
        }
      }

      if (par1EntityPlayer.username.equalsIgnoreCase(getOwnerName())
          && !worldObj.isRemote
          && !isWheat(itemstack)) {
        aiSit.func_48407_a(!isSitting());
        isJumping = false;
        setPathToEntity(null);
      }
    }

    return super.interact(par1EntityPlayer);
  }