Class EntityReplacer

java.lang.Object
my.celium.org.entity.EntityReplacer

public final class EntityReplacer extends Object
Reusable entity replacement: swap one entity for another while preserving the state callers ask for (see ReplaceOptions).

Must run on the server thread of the entity's level; any other thread fails fast with a clear message instead of corrupting the world. Fires EntityReplacedEvent after the swap.

  • Method Details

    • replace

      public static <T extends net.minecraft.world.entity.Entity> T replace(net.minecraft.server.level.ServerLevel level, net.minecraft.world.entity.Entity oldEntity, T fresh, ReplaceOptions options)
      Discards oldEntity and spawns fresh in its place.
      Parameters:
      level - the server level both entities belong to
      oldEntity - the entity to remove (must be alive and in level)
      fresh - the replacement (must not be added to any level yet)
      options - what to carry over
      Returns:
      the spawned replacement