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.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;
  }
Beispiel #2
0
  public EntityItem a(ItemStack itemstack, boolean flag) {
    if (itemstack == null) {
      return null;
    } else {
      EntityItem entityitem =
          new EntityItem(
              this.world,
              this.locX,
              this.locY - 0.30000001192092896D + (double) this.getHeadHeight(),
              this.locZ,
              itemstack);

      entityitem.pickupDelay = 40;
      float f = 0.1F;
      float f1;

      if (flag) {
        f1 = this.random.nextFloat() * 0.5F;
        float f2 = this.random.nextFloat() * 3.1415927F * 2.0F;

        entityitem.motX = (double) (-MathHelper.sin(f2) * f1);
        entityitem.motZ = (double) (MathHelper.cos(f2) * f1);
        entityitem.motY = 0.20000000298023224D;
      } else {
        f = 0.3F;
        entityitem.motX =
            (double)
                (-MathHelper.sin(this.yaw / 180.0F * 3.1415927F)
                    * MathHelper.cos(this.pitch / 180.0F * 3.1415927F)
                    * f);
        entityitem.motZ =
            (double)
                (MathHelper.cos(this.yaw / 180.0F * 3.1415927F)
                    * MathHelper.cos(this.pitch / 180.0F * 3.1415927F)
                    * f);
        entityitem.motY = (double) (-MathHelper.sin(this.pitch / 180.0F * 3.1415927F) * f + 0.1F);
        f = 0.02F;
        f1 = this.random.nextFloat() * 3.1415927F * 2.0F;
        f *= this.random.nextFloat();
        entityitem.motX += Math.cos((double) f1) * (double) f;
        entityitem.motY += (double) ((this.random.nextFloat() - this.random.nextFloat()) * 0.1F);
        entityitem.motZ += Math.sin((double) f1) * (double) f;
      }

      this.a(entityitem);
      this.a(StatisticList.v, 1);
      return entityitem;
    }
  }
Beispiel #3
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;
  }
Beispiel #4
0
  public void die() {
    if (this.h) {
      for (int i = 0; i < this.getSize(); ++i) {
        ItemStack itemstack = this.getItem(i);

        if (itemstack != null) {
          float f = this.random.nextFloat() * 0.8F + 0.1F;
          float f1 = this.random.nextFloat() * 0.8F + 0.1F;
          float f2 = this.random.nextFloat() * 0.8F + 0.1F;

          while (itemstack.count > 0) {
            int j = this.random.nextInt(21) + 10;

            if (j > itemstack.count) {
              j = itemstack.count;
            }

            itemstack.count -= j;
            EntityItem entityitem =
                new EntityItem(
                    this.world,
                    this.locX + (double) f,
                    this.locY + (double) f1,
                    this.locZ + (double) f2,
                    new ItemStack(itemstack.id, j, itemstack.getData()));

            if (itemstack.hasTag()) {
              entityitem.itemStack.setTag((NBTTagCompound) itemstack.getTag().clone());
            }

            float f3 = 0.05F;

            entityitem.motX = (double) ((float) this.random.nextGaussian() * f3);
            entityitem.motY = (double) ((float) this.random.nextGaussian() * f3 + 0.2F);
            entityitem.motZ = (double) ((float) this.random.nextGaussian() * f3);
            this.world.addEntity(entityitem);
          }
        }
      }
    }

    super.die();
    if (this.g != null) {
      this.g.a();
    }
  }
  public void remove(World world, int i, int j, int k) {
    TileEntityDispenser tileentitydispenser = (TileEntityDispenser) world.getTileEntity(i, j, k);

    if (tileentitydispenser != null) {
      for (int l = 0; l < tileentitydispenser.getSize(); ++l) {
        ItemStack itemstack = tileentitydispenser.getItem(l);

        if (itemstack != null) {
          float f = this.a.nextFloat() * 0.8F + 0.1F;
          float f1 = this.a.nextFloat() * 0.8F + 0.1F;
          float f2 = this.a.nextFloat() * 0.8F + 0.1F;

          while (itemstack.count > 0) {
            int i1 = this.a.nextInt(21) + 10;

            if (i1 > itemstack.count) {
              i1 = itemstack.count;
            }

            itemstack.count -= i1;
            EntityItem entityitem =
                new EntityItem(
                    world,
                    (double) ((float) i + f),
                    (double) ((float) j + f1),
                    (double) ((float) k + f2),
                    new ItemStack(itemstack.id, i1, itemstack.getData()));

            if (itemstack.hasTag()) {
              entityitem.itemStack.setTag((NBTTagCompound) itemstack.getTag().clone());
            }

            float f3 = 0.05F;

            entityitem.motX = (double) ((float) this.a.nextGaussian() * f3);
            entityitem.motY = (double) ((float) this.a.nextGaussian() * f3 + 0.2F);
            entityitem.motZ = (double) ((float) this.a.nextGaussian() * f3);
            world.addEntity(entityitem);
          }
        }
      }
    }

    super.remove(world, i, j, k);
  }
Beispiel #6
0
  public void remove(World world, int i, int j, int k, int l, int i1) {
    TileEntity tileentity = world.getTileEntity(i, j, k);

    if (tileentity instanceof TileEntityBrewingStand) {
      TileEntityBrewingStand tileentitybrewingstand = (TileEntityBrewingStand) tileentity;

      for (int j1 = 0; j1 < tileentitybrewingstand.getSize(); ++j1) {
        ItemStack itemstack = tileentitybrewingstand.getItem(j1);

        if (itemstack != null) {
          float f = this.a.nextFloat() * 0.8F + 0.1F;
          float f1 = this.a.nextFloat() * 0.8F + 0.1F;
          float f2 = this.a.nextFloat() * 0.8F + 0.1F;

          while (itemstack.count > 0) {
            int k1 = this.a.nextInt(21) + 10;

            if (k1 > itemstack.count) {
              k1 = itemstack.count;
            }

            itemstack.count -= k1;
            EntityItem entityitem =
                new EntityItem(
                    world,
                    (double) ((float) i + f),
                    (double) ((float) j + f1),
                    (double) ((float) k + f2),
                    new ItemStack(itemstack.id, k1, itemstack.getData()));
            float f3 = 0.05F;

            entityitem.motX = (double) ((float) this.a.nextGaussian() * f3);
            entityitem.motY = (double) ((float) this.a.nextGaussian() * f3 + 0.2F);
            entityitem.motZ = (double) ((float) this.a.nextGaussian() * f3);
            world.addEntity(entityitem);
          }
        }
      }
    }

    super.remove(world, i, j, k, l, i1);
  }
Beispiel #7
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() == 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;
  }
  // CraftBukkit - priv to public
  public void dispense(World world, int i, int j, int k, Random random) {
    int l = world.getData(i, j, k);
    byte b0 = 0;
    byte b1 = 0;

    if (l == 3) {
      b1 = 1;
    } else if (l == 2) {
      b1 = -1;
    } else if (l == 5) {
      b0 = 1;
    } else {
      b0 = -1;
    }

    TileEntityDispenser tileentitydispenser = (TileEntityDispenser) world.getTileEntity(i, j, k);

    if (tileentitydispenser != null) {
      // CraftBukkit start
      int dispenseSlot = tileentitydispenser.findDispenseSlot();
      ItemStack itemstack = null;
      if (dispenseSlot > -1) {
        itemstack = tileentitydispenser.getContents()[dispenseSlot];

        // Copy item stack, because we want it to have 1 item
        itemstack =
            new ItemStack(itemstack.id, 1, itemstack.getData(), itemstack.getEnchantments());
      }
      // CraftBukkit end

      double d0 = (double) i + (double) b0 * 0.6D + 0.5D;
      double d1 = (double) j + 0.5D;
      double d2 = (double) k + (double) b1 * 0.6D + 0.5D;

      if (itemstack == null) {
        world.triggerEffect(1001, i, j, k, 0);
      } else {
        // CraftBukkit start
        double d3 = random.nextDouble() * 0.1D + 0.2D;
        double motX = (double) b0 * d3;
        double motY = 0.20000000298023224D;
        double motZ = (double) b1 * d3;
        motX += random.nextGaussian() * 0.007499999832361937D * 6.0D;
        motY += random.nextGaussian() * 0.007499999832361937D * 6.0D;
        motZ += random.nextGaussian() * 0.007499999832361937D * 6.0D;

        org.bukkit.block.Block block = world.getWorld().getBlockAt(i, j, k);
        org.bukkit.inventory.ItemStack bukkitItem = new CraftItemStack(itemstack).clone();

        BlockDispenseEvent event =
            new BlockDispenseEvent(block, bukkitItem, new Vector(motX, motY, motZ));
        world.getServer().getPluginManager().callEvent(event);

        if (event.isCancelled()) {
          return;
        }

        if (event.getItem().equals(bukkitItem)) {
          // Actually remove the item
          tileentitydispenser.splitStack(dispenseSlot, 1);
        }

        motX = event.getVelocity().getX();
        motY = event.getVelocity().getY();
        motZ = event.getVelocity().getZ();

        itemstack = CraftItemStack.createNMSItemStack(event.getItem());
        // CraftBukkit end

        if (itemstack.id == Item.ARROW.id) {
          EntityArrow entityarrow = new EntityArrow(world, d0, d1, d2);

          entityarrow.shoot((double) b0, 0.10000000149011612D, (double) b1, 1.1F, 6.0F);
          entityarrow.fromPlayer = true;
          world.addEntity(entityarrow);
          world.triggerEffect(1002, i, j, k, 0);
        } else if (itemstack.id == Item.EGG.id) {
          EntityEgg entityegg = new EntityEgg(world, d0, d1, d2);

          entityegg.a((double) b0, 0.10000000149011612D, (double) b1, 1.1F, 6.0F);
          world.addEntity(entityegg);
          world.triggerEffect(1002, i, j, k, 0);
        } else if (itemstack.id == Item.SNOW_BALL.id) {
          EntitySnowball entitysnowball = new EntitySnowball(world, d0, d1, d2);

          entitysnowball.a((double) b0, 0.10000000149011612D, (double) b1, 1.1F, 6.0F);
          world.addEntity(entitysnowball);
          world.triggerEffect(1002, i, j, k, 0);
        } else if (itemstack.id == Item.POTION.id && ItemPotion.c(itemstack.getData())) {
          EntityPotion entitypotion = new EntityPotion(world, d0, d1, d2, itemstack.getData());

          entitypotion.a((double) b0, 0.10000000149011612D, (double) b1, 1.375F, 3.0F);
          world.addEntity(entitypotion);
          world.triggerEffect(1002, i, j, k, 0);
        } else if (itemstack.id == Item.EXP_BOTTLE.id) {
          EntityThrownExpBottle entitythrownexpbottle =
              new EntityThrownExpBottle(world, d0, d1, d2);

          entitythrownexpbottle.a((double) b0, 0.10000000149011612D, (double) b1, 1.375F, 3.0F);
          world.addEntity(entitythrownexpbottle);
          world.triggerEffect(1002, i, j, k, 0);
        } else if (itemstack.id == Item.MONSTER_EGG.id) {
          ItemMonsterEgg.a(
              world,
              itemstack.getData(),
              d0 + (double) b0 * 0.3D,
              d1 - 0.3D,
              d2 + (double) b1 * 0.3D);
          world.triggerEffect(1002, i, j, k, 0);
        } else if (itemstack.id == Item.FIREBALL.id) {
          EntitySmallFireball entitysmallfireball =
              new EntitySmallFireball(
                  world,
                  d0 + (double) b0 * 0.3D,
                  d1,
                  d2 + (double) b1 * 0.3D,
                  (double) b0 + random.nextGaussian() * 0.05D,
                  random.nextGaussian() * 0.05D,
                  (double) b1 + random.nextGaussian() * 0.05D);

          world.addEntity(entitysmallfireball);
          world.triggerEffect(1009, i, j, k, 0);
        } else {
          EntityItem entityitem = new EntityItem(world, d0, d1 - 0.3D, d2, itemstack);
          // CraftBukkit start
          // double d3 = random.nextDouble() * 0.1D + 0.2D; // Moved up
          entityitem.motX = motX;
          entityitem.motY = motY;
          entityitem.motZ = motZ;
          // CraftBukkit end
          world.addEntity(entityitem);
          world.triggerEffect(1000, i, j, k, 0);
        }

        world.triggerEffect(2000, i, j, k, b0 + 1 + (b1 + 1) * 3);
      }
    }
  }
Beispiel #9
0
  public boolean damageEntity(DamageSource damagesource, int i) {
    if (!this.world.isStatic && !this.dead) {
      if (this.isInvulnerable()) {
        return false;
      } else {
        this.i(-this.k());
        this.h(10);
        this.K();
        this.setDamage(this.getDamage() + i * 10);
        if (damagesource.getEntity() instanceof EntityHuman
            && ((EntityHuman) damagesource.getEntity()).abilities.canInstantlyBuild) {
          this.setDamage(100);
        }

        if (this.getDamage() > 40) {
          if (this.passenger != null) {
            this.passenger.mount(this);
          }

          this.die();
          this.a(Item.MINECART.id, 1, 0.0F);
          if (this.type == 1) {
            EntityMinecart entityminecart = this;

            for (int j = 0; j < entityminecart.getSize(); ++j) {
              ItemStack itemstack = entityminecart.getItem(j);

              if (itemstack != null) {
                float f = this.random.nextFloat() * 0.8F + 0.1F;
                float f1 = this.random.nextFloat() * 0.8F + 0.1F;
                float f2 = this.random.nextFloat() * 0.8F + 0.1F;

                while (itemstack.count > 0) {
                  int k = this.random.nextInt(21) + 10;

                  if (k > itemstack.count) {
                    k = itemstack.count;
                  }

                  itemstack.count -= k;
                  EntityItem entityitem =
                      new EntityItem(
                          this.world,
                          this.locX + (double) f,
                          this.locY + (double) f1,
                          this.locZ + (double) f2,
                          new ItemStack(itemstack.id, k, itemstack.getData()));
                  float f3 = 0.05F;

                  entityitem.motX = (double) ((float) this.random.nextGaussian() * f3);
                  entityitem.motY = (double) ((float) this.random.nextGaussian() * f3 + 0.2F);
                  entityitem.motZ = (double) ((float) this.random.nextGaussian() * f3);
                  this.world.addEntity(entityitem);
                }
              }
            }

            this.a(Block.CHEST.id, 1, 0.0F);
          } else if (this.type == 2) {
            this.a(Block.FURNACE.id, 1, 0.0F);
          }
        }

        return true;
      }
    } else {
      return true;
    }
  }