Esempio n. 1
0
  public static void attack(EntityLiving handle, Entity target) {
    AttributeInstance attackDamage = handle.getAttributeInstance(GenericAttributes.ATTACK_DAMAGE);
    float f = (float) (attackDamage == null ? 1 : attackDamage.getValue());
    int i = 0;

    if (target instanceof EntityLiving) {
      f += EnchantmentManager.a(handle.bA(), ((EntityLiving) target).getMonsterType());
      i += EnchantmentManager.a(handle);
    }

    boolean flag = target.damageEntity(DamageSource.mobAttack(handle), f);

    if (!flag) return;
    if (i > 0) {
      target.g(
          -Math.sin(handle.yaw * Math.PI / 180.0F) * i * 0.5F,
          0.1D,
          Math.cos(handle.yaw * Math.PI / 180.0F) * i * 0.5F);
      handle.motX *= 0.6D;
      handle.motZ *= 0.6D;
    }

    int fireAspectLevel = EnchantmentManager.getFireAspectEnchantmentLevel(handle);

    if (fireAspectLevel > 0) {
      target.setOnFire(fireAspectLevel * 4);
    }
  }
Esempio n. 2
0
  @SuppressWarnings("unchecked")
  public static EntityTrackerEntry registerEntityTracker(
      Entity entity, int trackingRange, int updateFrequency, boolean sendVelocityUpdates) {
    WorldServer worldServer = getWorld(entity);
    CustomEntityTrackerEntry tracker =
        new CustomEntityTrackerEntry(entity, trackingRange, updateFrequency, sendVelocityUpdates);

    try {
      Field field = worldServer.tracker.getClass().getDeclaredField("c");
      if (!field.isAccessible()) {
        field.setAccessible(true);
      }

      Set<EntityTrackerEntry> list = (Set<EntityTrackerEntry>) field.get(worldServer.tracker);

      if (worldServer.tracker.trackedEntities.b(entity.getId())) { // if contains entity tracker
        // go to delete
        EntityTrackerEntry oldTracker = worldServer.tracker.trackedEntities.d(entity.getId());
        list.remove(oldTracker);
        oldTracker.a();
      }

      list.add(tracker);
      worldServer.tracker.trackedEntities.a(entity.getId(), tracker);
      tracker.scanPlayers(worldServer.players);
    } catch (NoSuchFieldException
        | SecurityException
        | IllegalArgumentException
        | IllegalAccessException e) {
      e.printStackTrace();
    }
    return tracker;
  }
Esempio n. 3
0
 public static void look(org.bukkit.entity.Entity entity, float yaw, float pitch) {
   Entity handle = getHandle(entity);
   if (handle == null) return;
   yaw = clampYaw(yaw);
   handle.yaw = yaw;
   setHeadYaw(handle, yaw);
   handle.pitch = pitch;
 }
Esempio n. 4
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);
      }
    }
  }
Esempio n. 5
0
 public static org.bukkit.entity.Entity spawnCustomEntity(
     org.bukkit.World world, Location at, Class<? extends Entity> clazz, EntityType type) {
   World handle = ((CraftWorld) world).getHandle();
   Entity entity = null;
   try {
     Constructor<?> constructor = getCustomEntityConstructor(clazz, type);
     entity = (Entity) constructor.newInstance(handle);
   } catch (Exception e) {
     Messaging.logTr(Messages.ERROR_SPAWNING_CUSTOM_ENTITY, e.getMessage());
     return null;
   }
   entity.setLocation(at.getX(), at.getY(), at.getZ(), at.getYaw(), at.getPitch());
   handle.addEntity(entity);
   entity.setLocation(at.getX(), at.getY(), at.getZ(), at.getYaw(), at.getPitch());
   return entity.getBukkitEntity();
 }
  private boolean addEntityToWorld(WorldServer nmsWorld, Entity nmsEntity) {
    Validator.isTrue(Bukkit.isPrimaryThread(), "Async entity add");

    if (validateEntityMethod == null) {
      return nmsWorld.addEntity(nmsEntity, SpawnReason.CUSTOM);
    }

    final int chunkX = MathHelper.floor(nmsEntity.locX / 16.0);
    final int chunkZ = MathHelper.floor(nmsEntity.locZ / 16.0);

    if (!nmsWorld.chunkProviderServer.isChunkLoaded(chunkX, chunkZ)) {
      // This should never happen
      nmsEntity.dead = true;
      return false;
    }

    nmsWorld.getChunkAt(chunkX, chunkZ).a(nmsEntity);
    nmsWorld.entityList.add(nmsEntity);

    try {
      validateEntityMethod.invoke(nmsWorld, nmsEntity);
    } catch (Exception e) {
      e.printStackTrace();
      return false;
    }
    return true;
  }
  @Override
  public boolean standsOnEntity(
      final Entity entity,
      final double minX,
      final double minY,
      final double minZ,
      final double maxX,
      final double maxY,
      final double maxZ) {
    try {
      // TODO: Find some simplification!

      final net.minecraft.server.v1_8_R3.Entity mcEntity = ((CraftEntity) entity).getHandle();

      final AxisAlignedBB box = new AxisAlignedBB(minX, minY, minZ, maxX, maxY, maxZ);
      @SuppressWarnings("rawtypes")
      final List list = world.getEntities(mcEntity, box);
      @SuppressWarnings("rawtypes")
      final Iterator iterator = list.iterator();
      while (iterator.hasNext()) {
        final net.minecraft.server.v1_8_R3.Entity other =
            (net.minecraft.server.v1_8_R3.Entity) iterator.next();
        if (!(other instanceof EntityBoat)) { // && !(other instanceof EntityMinecart)) continue;
          continue;
        }
        if (minY >= other.locY && minY - other.locY <= 0.7) {
          return true;
        }
        // Still check this for some reason.
        final AxisAlignedBB otherBox = other.getBoundingBox();
        if (box.a > otherBox.d
            || box.d < otherBox.a
            || box.b > otherBox.e
            || box.e < otherBox.b
            || box.c > otherBox.f
            || box.f < otherBox.c) {
          continue;
        } else {
          return true;
        }
      }
    } catch (Throwable t) {
      // Ignore exceptions (Context: DisguiseCraft).
    }
    return false;
  }
Esempio n. 8
0
 @Override
 public boolean execute(CommandSender arg0, String arg1, String[] args) {
   if (args[0].equals("test")) Franky.spawn(((Player) arg0));
   if (args[0].equals("new")) {
     Entity nmsEntity = EntityNPC.spawn(((Player) arg0).getLocation());
     StartSign s =
         new StartSign(
             nmsEntity.getBukkitEntity().getUniqueId(),
             Integer.parseInt(args[1]),
             false,
             args[2],
             args[3],
             args[4],
             Integer.parseInt(args[5]),
             Integer.parseInt(args[6]));
     s.insert();
   }
   return true;
 }
Esempio n. 9
0
 public static void trySwim(org.bukkit.entity.Entity entity, float power) {
   Entity handle = getHandle(entity);
   if (RANDOM.nextFloat() < 0.8F && inWater(entity)) {
     handle.motY += power;
   }
 }
Esempio n. 10
0
 public static boolean inWater(org.bukkit.entity.Entity entity) {
   Entity mcEntity = getHandle(entity);
   if (mcEntity == null) return false;
   return mcEntity.W() || mcEntity.ab();
 }
Esempio n. 11
0
 public static boolean isAIDisabled(Entity entity) {
   net.minecraft.server.v1_8_R3.Entity nmsEntity = ((CraftEntity) entity).getHandle();
   if (!(nmsEntity instanceof EntityInsentient)) return true;
   return nmsEntity.getDataWatcher().getByte(15) != 0;
 }
Esempio n. 12
0
 public static void toggleAI(Entity entity, boolean hasAI) {
   net.minecraft.server.v1_8_R3.Entity nmsEntity = ((CraftEntity) entity).getHandle();
   if (!(nmsEntity instanceof EntityInsentient)) return;
   nmsEntity.getDataWatcher().watch(15, (byte) (hasAI ? 0 : 1));
 }