Class CustomEntity

java.lang.Object
dev.lone.itemsadder.api.CustomEntity
Direct Known Subclasses:
CustomPlayer

public class CustomEntity extends Object
Wrapper for a custom entity spawned or converted by ItemsAdder.
  • Constructor Details

    • CustomEntity

      public CustomEntity()
  • Method Details

    • getNamespacedIdsInRegistry

      public static Set<String> getNamespacedIdsInRegistry()
      Gets all custom entity namespaced ids currently registered.
      Returns:
      the registered custom entity namespaced ids.
    • isInRegistry

      public static boolean isInRegistry(String namespacedId)
      Checks if a custom entity is registered.
      Parameters:
      namespacedId - the custom entity namespaced id.
      Returns:
      true if the custom entity exists in the registry.
    • spawn

      @Nullable public static @Nullable CustomEntity spawn(String namespacedId, Location location)
      Spawns a custom entity at a location.
      Parameters:
      namespacedId - the custom entity namespaced id.
      location - the spawn location.
      Returns:
      the spawned custom entity wrapper, or null if it cannot be spawned.
    • spawn

      @Nullable public static @Nullable CustomEntity spawn(String namespacedId, Location location, boolean frustumCulling)
      Spawns a custom entity at a location.
      Parameters:
      namespacedId - the custom entity namespaced id.
      location - the spawn location.
      frustumCulling - true to enable client-side frustum culling.
      Returns:
      the spawned custom entity wrapper, or null if it cannot be spawned.
    • spawn

      @Nullable public static @Nullable CustomEntity spawn(String namespacedId, Location location, List<Player> viewers, boolean frustumCulling, @Nullable @Nullable Consumer<LivingEntity> function)
      Spawns a custom entity visible to specific viewers.
      Parameters:
      namespacedId - the custom entity namespaced id.
      location - the spawn location.
      viewers - the players that should see the entity.
      frustumCulling - true to enable client-side frustum culling.
      function - optional callback executed with the base entity.
      Returns:
      the spawned custom entity wrapper, or null if it cannot be spawned.
    • spawn

      @Nullable public static @Nullable CustomEntity spawn(String namespacedId, Location location, boolean frustumCulling, boolean noBase, boolean noHitbox)
      Spawns a custom entity with advanced base entity options.
      Parameters:
      namespacedId - the custom entity namespaced id.
      location - the spawn location.
      frustumCulling - true to enable client-side frustum culling.
      noBase - true to avoid spawning the base entity.
      noHitbox - true to spawn without hitbox.
      Returns:
      the spawned custom entity wrapper, or null if it cannot be spawned.
    • spawn

      @Nullable public static @Nullable CustomEntity spawn(String namespacedId, Location location, List<Player> viewers, boolean frustumCulling, boolean noBase, boolean noHitbox, @Nullable @Nullable Consumer<LivingEntity> function)
      Spawns a custom entity visible to specific viewers with advanced base entity options.
      Parameters:
      namespacedId - the custom entity namespaced id.
      location - the spawn location.
      viewers - the players that should see the entity.
      frustumCulling - true to enable client-side frustum culling.
      noBase - true to avoid spawning the base entity.
      noHitbox - true to spawn without hitbox.
      function - optional callback executed with the base entity.
      Returns:
      the spawned custom entity wrapper, or null if it cannot be spawned.
    • convert

      @Nullable public static @Nullable CustomEntity convert(String namespacedId, LivingEntity bukkitEntity)
      Converts an existing living entity into a custom entity.
      Parameters:
      namespacedId - the custom entity namespaced id.
      bukkitEntity - the existing Bukkit entity.
      Returns:
      the converted custom entity wrapper, or null if it cannot be converted.
    • convert

      @Nullable public static @Nullable CustomEntity convert(String namespacedId, LivingEntity bukkitEntity, boolean frustumCulling)
      Converts an existing living entity into a custom entity.
      Parameters:
      namespacedId - the custom entity namespaced id.
      bukkitEntity - the existing Bukkit entity.
      frustumCulling - true to enable client-side frustum culling.
      Returns:
      the converted custom entity wrapper, or null if it cannot be converted.
    • convert

      @Nullable public static @Nullable CustomEntity convert(String namespacedId, LivingEntity bukkitEntity, boolean frustumCulling, boolean noHitbox, boolean canBaseEntityBeDestroyed, boolean hideBaseEntity)
      Converts an existing living entity into a custom entity with advanced options.
      Parameters:
      namespacedId - the custom entity namespaced id.
      bukkitEntity - the existing Bukkit entity.
      frustumCulling - true to enable client-side frustum culling.
      noHitbox - true to remove the custom entity hitbox.
      canBaseEntityBeDestroyed - true if the base entity can be destroyed with the custom entity.
      hideBaseEntity - true to hide the original Bukkit entity.
      Returns:
      the converted custom entity wrapper, or null if it cannot be converted.
    • convert

      @Nullable public static @Nullable CustomEntity convert(String namespacedId, LivingEntity bukkitEntity, List<Player> viewers, boolean frustumCulling)
      Converts an existing living entity into a custom entity visible to specific viewers.
      Parameters:
      namespacedId - the custom entity namespaced id.
      bukkitEntity - the existing Bukkit entity.
      viewers - the players that should see the entity.
      frustumCulling - true to enable client-side frustum culling.
      Returns:
      the converted custom entity wrapper, or null if it cannot be converted.
    • byAlreadySpawned

      @Nullable public static @Nullable CustomEntity byAlreadySpawned(Entity entity)
      Gets a custom entity wrapper from an already spawned entity.
      Parameters:
      entity - the Bukkit entity to check.
      Returns:
      the custom entity wrapper, or null if the entity is not custom.
    • isCustomEntity

      public static boolean isCustomEntity(Entity entity)
      Checks if a Bukkit entity is registered as a custom entity.
      Parameters:
      entity - the Bukkit entity to check.
      Returns:
      true if the entity is a custom entity.
    • isCustomEntity

      public static boolean isCustomEntity(UUID uuid)
      Checks if an entity UUID is registered as a custom entity.
      Parameters:
      uuid - the entity UUID to check.
      Returns:
      true if the UUID belongs to a custom entity.
    • getEntity

      public Entity getEntity()
      Gets the base Bukkit entity used by this custom entity.
      Returns:
      the base Bukkit entity.
    • getType

      public EntityType getType()
      Gets the Bukkit entity type of the base entity.
      Returns:
      the entity type.
    • getLocation

      public Location getLocation()
      Gets the current custom entity location.
      Returns:
      the current location.
    • teleport

      public void teleport(Location location)
      Teleports this custom entity.
      Parameters:
      location - the destination location.
    • getNamespacedID

      public String getNamespacedID()
      Gets the custom entity namespaced id.
      Returns:
      the namespaced id.
    • getNamespace

      public String getNamespace()
      Gets the namespace of this custom entity.
      Returns:
      the namespace.
    • getId

      public String getId()
      Gets the id of this custom entity without namespace.
      Returns:
      the id.
    • respawn

      public void respawn(Player player)
      Forces this custom entity bones to respawn for a player.
      Parameters:
      player - the player.
    • addViewer

      public void addViewer(Player player)
      Adds a viewer to this custom entity.
      Parameters:
      player - the player to add as viewer.
    • removeViewer

      public void removeViewer(Player player)
      Removes a viewer from this custom entity.
      Parameters:
      player - the player to remove.
    • setFrustumCulling

      public void setFrustumCulling(boolean cull)
      Sets whether this custom entity uses frustum culling.
      Parameters:
      cull - true to enable frustum culling.
    • getFrustumCulling

      public boolean getFrustumCulling()
      Gets whether this custom entity uses frustum culling.
      Returns:
      true if frustum culling is enabled.
    • playAnimation

      public boolean playAnimation(String name, @Nullable @Nullable Runnable callback)
      Plays an animation on this custom entity.
      Parameters:
      name - the animation name.
      callback - optional callback executed when the animation finishes.
      Returns:
      true if the animation exists and was started.
    • playAnimation

      public boolean playAnimation(String name)
      Plays an animation on this custom entity.
      Parameters:
      name - the animation name.
      Returns:
      true if the animation exists and was started.
    • stopAnimation

      public void stopAnimation()
      Stops the current animation.
    • isPlayingAnimation

      public boolean isPlayingAnimation(String name)
      Checks if an animation is currently playing.
      Parameters:
      name - the animation name.
      Returns:
      true if the animation is playing.
    • hasAnimation

      public static boolean hasAnimation(String entityNamespacedId, String animationName)
      Checks if a registered custom entity has an animation.
      Parameters:
      entityNamespacedId - the custom entity namespaced id.
      animationName - the animation name.
      Returns:
      true if the animation exists.
    • hasAnimation

      public boolean hasAnimation(String name)
      Checks if this custom entity has an animation.
      Parameters:
      name - the animation name.
      Returns:
      true if the animation exists.
    • getAnimationsNames

      public static List<String> getAnimationsNames(String entityNamespacedId)
      Gets all animation names for a registered custom entity.
      Parameters:
      entityNamespacedId - the custom entity namespaced id.
      Returns:
      the animation names.
    • getAnimationsNames

      public List<String> getAnimationsNames()
      Gets all animation names for this custom entity.
      Returns:
      the animation names.
    • destroy

      public void destroy()
      Destroys this custom entity.
    • playDamageEffect

      public void playDamageEffect(boolean fire)
      Plays the damage effect on this custom entity.
      Parameters:
      fire - true to include the fire damage effect.
    • setColorAllBones

      public void setColorAllBones(int color)
      Sets the color of all rendered bones.
      Parameters:
      color - the RGB color.
    • setEnchantedAllBones

      public void setEnchantedAllBones(boolean enchanted)
      Sets the enchanted glint state of all rendered bones.
      Parameters:
      enchanted - true to show the enchanted glint.
    • hasMountBones

      public boolean hasMountBones()
      Checks if this custom entity has mount bones.
      Returns:
      true if at least one mount bone exists.
    • addPassenger

      public boolean addPassenger(LivingEntity passenger)
      Will add new passenger to the next unoccupied mount bone
      Parameters:
      passenger - the Entity to add as a passenger
      Returns:
      true if the passenger was successfully added, otherwise false (e.g. if there is no free space)
    • removePassenger

      public static void removePassenger(LivingEntity passenger)
      Removes a passenger from any custom entity mount.
      Parameters:
      passenger - the passenger to remove.
    • getPassengers

      public Set<LivingEntity> getPassengers()
      Gets all passengers currently mounted on this custom entity.
      Returns:
      the mounted passengers.
    • hasPassenger

      public boolean hasPassenger(LivingEntity passenger)
      Parameters:
      passenger - passenger Entity to check
      Returns:
      true if this passenger rides the customEntity, otherwise false
    • hasPassenger

      public boolean hasPassenger()
      Returns:
      true if there is at least one passenger, otherwise false
    • getBones

      public Set<CustomEntity.Bone> getBones()
      Returns:
      all bones of the current CustomEntity
    • getMountBones

      public Set<CustomEntity.MountBone> getMountBones()
      Returns:
      all mount bones of the current CustomEntity
    • getBone

      @Nullable public @Nullable CustomEntity.Bone getBone(String name)
      Parameters:
      name - bone name
      Returns:
      CustomEntity.Bone at the specified name. Returns null if not found.
    • getMountBoneByPassenger

      @Nullable public @Nullable CustomEntity.MountBone getMountBoneByPassenger(LivingEntity passenger)
      Gets the CustomEntity.MountBone currently ridden by the specified passenger if so
      Parameters:
      passenger - passenger to check
      Returns:
      Optional of the CustomEntity.MountBone. Not empty if there is such passenger
    • getLoot

      public List<ItemStack> getLoot()
      Gets the loot generated by this custom entity.
      Returns:
      the generated loot.
    • getLoot

      public List<ItemStack> getLoot(@Nullable @Nullable ItemStack tool)
      Gets the loot generated by this custom entity.
      Parameters:
      tool - the tool used to kill the entity, or null.
      Returns:
      the generated loot.
    • getLoot

      public static List<ItemStack> getLoot(LivingEntity bukkitEntity, @Nullable @Nullable ItemStack tool)
      Gets the loot generated by a custom entity.
      Parameters:
      bukkitEntity - the base Bukkit entity.
      tool - the tool used to kill the entity, or null.
      Returns:
      the generated loot, or an empty list if the entity is not custom.