@Override
  public boolean interact(EntityPlayer player) {
    ItemStack itemStack = player.inventory.getCurrentItem();

    if (itemStack != null
        && itemStack.getItem() == MPItems.spawn_egg_mp
        && itemStack.getItemDamage() == 1014) {
      if (!this.worldObj.isRemote) {
        EntityAgeable entityageable = this.createChild(this);

        if (entityageable != null) {
          entityageable.setGrowingAge(-24000);
          entityageable.setLocationAndAngles(this.posX, this.posY, this.posZ, 0.0F, 0.0F);
          this.worldObj.spawnEntityInWorld(entityageable);

          if (itemStack.hasDisplayName()) {
            entityageable.setCustomNameTag(itemStack.getDisplayName());
          }
          if (!player.capabilities.isCreativeMode) {
            --itemStack.stackSize;

            if (itemStack.stackSize <= 0) {
              player.inventory.setInventorySlotContents(
                  player.inventory.currentItem, (ItemStack) null);
            }
          }
        }
      }
      return true;
    }
    return super.interact(player);
  }
Пример #2
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 var2 = par1EntityPlayer.inventory.getCurrentItem();

    if (var2 != null && var2.getItem() == Items.spawn_egg) {
      if (!this.worldObj.isClient) {
        Class var3 = EntityList.getClassFromID(var2.getItemDamage());

        if (var3 != null && var3.isAssignableFrom(this.getClass())) {
          EntityAgeable var4 = this.createChild(this);

          if (var4 != null) {
            var4.setGrowingAge(-24000);
            var4.setLocationAndAngles(this.posX, this.posY, this.posZ, 0.0F, 0.0F);
            this.worldObj.spawnEntityInWorld(var4);

            if (var2.hasDisplayName()) {
              var4.setCustomNameTag(var2.getDisplayName());
            }

            if (!par1EntityPlayer.capabilities.isCreativeMode) {
              --var2.stackSize;

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

      return true;
    } else {
      return false;
    }
  }