Package net.minecraft.server

Examples of net.minecraft.server.Entity


        boolean cancel = false;

        final long time = System.currentTimeMillis();

        // Get the damagee (entity that got hit)
        Entity entity = data.damagee;

        // Safeguard, if entity is complex, this check will fail
        // due to giant and hard to define hitboxes
        if(entity instanceof EntityComplex || entity instanceof EntityComplexPart) {
            return false;
View Full Code Here


        boolean cancel = false;

        final long time = System.currentTimeMillis();

        // Get the width of the damagee
        Entity entity = data.damagee;

        // Safeguard, if entity is Giant or Ender Dragon, this check will fail
        // due to giant and hard to define hitboxes
        if(entity instanceof EntityComplex || entity instanceof EntityComplexPart) {
            return false;
View Full Code Here

  /**
   * Replaces the current entity, if needed, with the BKCommonLib Hook entity type
   */
  protected void prepareHook() {
    final Entity oldInstance = getHandle(Entity.class);
    if (oldInstance instanceof NMSEntityHook) {
      // Already hooked
      return;
    }

    // Check whether conversion is allowed
    final String oldInstanceName = oldInstance.getClass().getName();
    final CommonEntityType type = CommonEntityType.byEntity(entity);
    if (!type.nmsType.isType(oldInstance)) {
      throw new RuntimeException("Can not assign controllers to a custom Entity Type (" + oldInstanceName + ")");
    }
    if (!type.hasNMSEntity()) {
View Full Code Here

      throw new RuntimeException("Failed to set controller:", t);
    }
  }

  private void replaceEntity(final Entity newInstance) {
    final Entity oldInstance = getHandle(Entity.class);
    oldInstance.dead = true;
    newInstance.dead = false;
    oldInstance.valid = false;
    newInstance.valid = true;

    // *** Bukkit Entity ***
    ((CraftEntity) entity).setHandle(newInstance);
    if (entity instanceof InventoryHolder) {
      Inventory inv = ((InventoryHolder) entity).getInventory();
      if (inv instanceof CraftInventory && newInstance instanceof IInventory) {
        SafeField.set(inv, "inventory", newInstance);
      }
    }

    // *** Give the old entity a new Bukkit Entity ***
    EntityRef.bukkitEntity.set(oldInstance, EntityRef.createEntity(oldInstance));

    // *** Passenger/Vehicle ***
    if (newInstance.vehicle != null) {
      newInstance.vehicle.passenger = newInstance;
    }
    if (newInstance.passenger != null) {
      newInstance.passenger.vehicle = newInstance;
    }

    // Only do this replacement logic for Entities that are already spawned
    if (this.isSpawned()) {
      // Now proceed to replace this NMS Entity in all places imaginable.
      // First load the chunk so we can at least work on something
      Chunk chunk = CommonNMS.getNative(getWorld().getChunkAt(getChunkX(), getChunkZ()));

      // *** Entities By ID Map ***
      final IntHashMap<Object> entitiesById = WorldServerRef.entitiesById.get(oldInstance.world);
      if (entitiesById.remove(oldInstance.getId()) == null) {
        CommonUtil.nextTick(new Runnable() {
          public void run() {
            entitiesById.put(newInstance.getId(), newInstance);
          }
        });
View Full Code Here

  public boolean teleport(Location location, TeleportCause cause) {
    if (isDead()) {
      return false;
    }
    // Preparations prior to teleportation
    final Entity entityHandle = CommonNMS.getNative(entity);
    final CommonEntity<?> passenger = get(getPassenger());
    final World newworld = CommonNMS.getNative(location.getWorld());
    final boolean isWorldChange = entityHandle.world != newworld;
    final EntityNetworkController<?> oldNetworkController = getNetworkController();
    final boolean hasNetworkController = !(oldNetworkController instanceof DefaultEntityNetworkController);
    WorldUtil.loadChunks(location, 3);

    // If in a vehicle, make sure we eject first
    if (isInsideVehicle()) {
      getVehicle().eject();
    }

    // If vehicle, eject the passenger first
    if (hasPassenger()) {
      setPassengerSilent(null);
    }

    // Perform actual teleportation
    final boolean succ;
    if (!isWorldChange || entity instanceof Player) {
      // First: stop tracking the entity
      final EntityTracker tracker = WorldUtil.getTracker(getWorld());
      tracker.stopTracking(entity);

      // Destroy packets are queued: Make sure to send them RIGHT NOW
      for (Player bukkitPlayer : WorldUtil.getPlayers(getWorld())) {
        CommonPlayer player = get(bukkitPlayer);
        if (player != null) {
          player.flushEntityRemoveQueue();
        }
      }

      // Teleport
      succ = entity.teleport(location, cause);

      // Start tracking the entity again
      if (!hasNetworkController && !isWorldChange) {
        tracker.startTracking(entity);
      }
    } else {
      // Remove from one world and add to the other
      entityHandle.world.removeEntity(entityHandle);
      entityHandle.dead = false;
      entityHandle.world = newworld;
      entityHandle.setLocation(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch());
      entityHandle.world.addEntity(entityHandle);
      succ = true;
    }
    if (hasNetworkController) {
      this.setNetworkController(oldNetworkController);
View Full Code Here

    if (type == CommonEntityType.UNKNOWN) {
      throw new IllegalArgumentException("The Entity Type '" + entityType + "' is invalid!");
    }
    final CommonEntity<org.bukkit.entity.Entity> entity = type.createCommonEntity(null);
    // Spawn a new NMS Entity
    Entity handle;
    if (type.hasNMSEntity()) {
      handle = (Entity) type.createNMSHookEntity(entity);
    } else {
      throw new RuntimeException("The Entity Type '"  + entityType + "' has no suitable Entity constructor to use!");
    }
View Full Code Here

   * Removes a single entity from the world
   *
   * @param entity to remove
   */
  public static void removeEntity(org.bukkit.entity.Entity entity) {
    Entity e = CommonNMS.getNative(entity);
    e.world.removeEntity(e);
    WorldServerRef.entityTracker.get(e.world).stopTracking(entity);
  }
View Full Code Here

   * Adds a single entity to the server
   *
   * @param entity to add
   */
  public static void addEntity(org.bukkit.entity.Entity entity) {
    Entity nmsentity = CommonNMS.getNative(entity);
    nmsentity.world.getChunkAt(MathUtil.toChunk(nmsentity.locX), MathUtil.toChunk(nmsentity.locZ));
    nmsentity.dead = false;
    // Remove an entity tracker for this entity if it was present
    WorldUtil.getTracker(entity.getWorld()).stopTracking(entity);
    // Add the entity to the world
View Full Code Here

  public boolean isMoving() {
    return isMovingHorizontally() || isMovingVertically();
  }

  public void setWorld(World world) {
    final Entity handle = getHandle(Entity.class);
    handle.world = CommonNMS.getNative(world);
    handle.dimension = WorldUtil.getDimension(world);
  }
View Full Code Here

  public void makeSound(Sound sound, float volume, float pitch) {
    makeSound(CraftSound.getSound(sound), volume, pitch);
  }

  public void makeSound(String soundName, float volume, float pitch) {
    final Entity handle = getHandle(Entity.class);
    handle.world.makeSound(handle, soundName, volume, pitch);
  }
View Full Code Here

TOP

Related Classes of net.minecraft.server.Entity

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.