コード例 #1
0
ファイル: EntityMyBlaze.java プロジェクト: jjm223/MyPet
  public boolean handlePlayerInteraction(EntityHuman entityhuman) {
    if (super.handlePlayerInteraction(entityhuman)) {
      return true;
    }

    ItemStack itemStack = entityhuman.inventory.getItemInHand();

    if (getOwner().equals(entityhuman) && itemStack != null && canUseItem()) {
      if (getMyPet().isOnFire()
          && itemStack.getItem() == Items.GLASS_BOTTLE
          && itemStack.getData() == 0
          && getOwner().getPlayer().isSneaking()) {
        getMyPet().setOnFire(false);
        makeSound("random.fizz", 1.0F, 1.0F);
        if (!entityhuman.abilities.canInstantlyBuild) {
          if (--itemStack.count <= 0) {
            entityhuman.inventory.setItem(
                entityhuman.inventory.itemInHandIndex, new ItemStack(Items.GLASS_BOTTLE));
          } else {
            if (!entityhuman.inventory.pickup(new ItemStack(Items.GLASS_BOTTLE))) {
              entityhuman.drop(new ItemStack(Items.GLASS_BOTTLE), true);
            }
          }
        }
        return true;
      } else if (!getMyPet().isOnFire()
          && itemStack.getItem() == Items.FLINT_AND_STEEL
          && getOwner().getPlayer().isSneaking()) {
        getMyPet().setOnFire(true);
        makeSound("fire.ignite", 1.0F, 1.0F);
        if (!entityhuman.abilities.canInstantlyBuild) {
          itemStack.damage(1, entityhuman);
        }
        return true;
      }
    }
    return false;
  }
コード例 #2
0
ファイル: EntityMyIronGolem.java プロジェクト: jjm223/MyPet
  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.getItem() == Item.getItemOf(Blocks.RED_FLOWER)
          && !getMyPet().hasFlower()
          && getOwner().getPlayer().isSneaking()) {
        getMyPet().setFlower(CraftItemStack.asBukkitCopy(itemStack));
        if (!entityhuman.abilities.canInstantlyBuild) {
          if (--itemStack.count <= 0) {
            entityhuman.inventory.setItem(entityhuman.inventory.itemInHandIndex, null);
          }
        }
        return true;
      } else if (itemStack.getItem() == Items.SHEARS
          && getMyPet().hasFlower()
          && getOwner().getPlayer().isSneaking()) {
        EntityItem entityitem = this.a(CraftItemStack.asNMSCopy(getMyPet().getFlower()), 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);

        makeSound("mob.sheep.shear", 1.0F, 1.0F);
        getMyPet().setFlower(null);
        if (!entityhuman.abilities.canInstantlyBuild) {
          itemStack.damage(1, entityhuman);
        }

        return true;
      }
    }
    return false;
  }