Exemple #1
0
  public static void playAnimation(
      Entity entity, PacketType type, int animationId, int particalCount) {
    if (type == PacketType.ANIMATION) {
      getWorld(entity).getTracker().a(entity, new PacketPlayOutAnimation(entity, animationId));
    } else if (type == PacketType.ENTITY_STATUS) {
      getWorld(entity)
          .getTracker()
          .a(entity, new PacketPlayOutEntityStatus(entity, (byte) animationId));
    } else if (type == PacketType.NONE) {
      if (animationId == Animations.DRINK.getId()) {
        makeSound(entity, "random.drink", 0.5F, random.nextFloat() * 0.1F + 0.9F);
      } else if (animationId == Animations.EAT_FOOD.getId()) {
        for (int j = 0; j < particalCount; ++j) {
          Vec3D vec3d =
              new Vec3D((random.nextFloat() - 0.5D) * 0.1D, Math.random() * 0.1D + 0.1D, 0.0D);

          vec3d = vec3d.a(-entity.pitch * 3.141593F / 180.0F);
          vec3d = vec3d.b(-entity.yaw * 3.141593F / 180.0F);
          double d0 = -random.nextFloat() * 0.6D - 0.3D;
          Vec3D vec3d1 = new Vec3D((random.nextFloat() - 0.5D) * 0.3D, d0, 0.6D);

          vec3d1 = vec3d1.a(-entity.pitch * 3.141593F / 180.0F);
          vec3d1 = vec3d1.b(-entity.yaw * 3.141593F / 180.0F);
          vec3d1 = vec3d1.add(entity.locX, entity.locY + entity.getHeadHeight(), entity.locZ);
          ItemStack itemstack = entity.getEquipment()[0];
          if (itemstack.usesData())
            getWorld(entity)
                .addParticle(
                    EnumParticle.ITEM_CRACK,
                    vec3d1.a,
                    vec3d1.b,
                    vec3d1.c,
                    vec3d.a,
                    vec3d.b + 0.05D,
                    vec3d.c,
                    new int[] {Item.getId(itemstack.getItem()), itemstack.getData()});
          else {
            getWorld(entity)
                .addParticle(
                    EnumParticle.ITEM_CRACK,
                    vec3d1.a,
                    vec3d1.b,
                    vec3d1.c,
                    vec3d.a,
                    vec3d.b + 0.05D,
                    vec3d.c,
                    new int[] {Item.getId(itemstack.getItem())});
          }
        }

        makeSound(
            entity,
            "random.eat",
            0.5F + 0.5F * random.nextInt(2),
            (random.nextFloat() - random.nextFloat()) * 0.2F + 1.0F);
      }
    }
  }
  public static Integer getMaterialId(String name) {
    Item item = Item.d(name);
    if (item == null) return null;

    return Item.getId(item);
  }