Beispiel #1
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.getItem() == Items.DYE
          && itemStack.getData() <= 15
          && itemStack.getData() != getMyPet().getColor().getDyeData()
          && !getMyPet().isSheared()) {
        getMyPet().setColor(DyeColor.getByDyeData((byte) itemStack.getData()));
        if (!entityhuman.abilities.canInstantlyBuild) {
          if (--itemStack.count <= 0) {
            entityhuman.inventory.setItem(entityhuman.inventory.itemInHandIndex, null);
          }
        }
        return true;
      } else if (itemStack.getItem() == Items.SHEARS
          && MySheep.CAN_BE_SHEARED
          && !getMyPet().isSheared()) {
        getMyPet().setSheared(true);
        int woolDropCount = 1 + this.random.nextInt(3);

        for (int j = 0; j < woolDropCount; ++j) {
          EntityItem entityitem =
              this.a(new ItemStack(Blocks.WOOL, 1, getMyPet().getColor().getDyeData()), 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);
        if (!entityhuman.abilities.canInstantlyBuild) {
          itemStack.damage(1, entityhuman);
        }
        return true;
      } else if (MySheep.GROW_UP_ITEM.compare(itemStack)
          && getMyPet().isBaby()
          && getOwner().getPlayer().isSneaking()) {
        if (!entityhuman.abilities.canInstantlyBuild) {
          if (--itemStack.count <= 0) {
            entityhuman.inventory.setItem(entityhuman.inventory.itemInHandIndex, null);
          }
        }
        getMyPet().setBaby(false);
        return true;
      }
    }
    return false;
  }