RoleChangeSystem
Package: com.hypixel.hytale.server.npc.systems
public class RoleChangeSystem extends TickingSystem<EntityStore>Processes queued runtime role changes for NPC entities. When an NPC’s role needs to change (triggered by ActionRole), the request is queued in the RoleChangeQueue resource. This system drains the queue each tick, performing the role swap by removing the entity, stripping role-specific components, updating the role name/index, and re-adding the entity to trigger RoleBuilderSystem.
Execution Order
Section titled “Execution Order”| Dependency | Direction |
|---|---|
NewSpawnStartTickingSystem | AFTER |
Static Methods
Section titled “Static Methods”public static void requestRoleChange( @Nonnull Ref<EntityStore> ref, @Nonnull Role role, int roleIndex, boolean changeAppearance, @Nonnull Store<EntityStore> store)public static void requestRoleChange( @Nonnull Ref<EntityStore> ref, @Nonnull Role role, int roleIndex, boolean changeAppearance, @Nullable String state, @Nullable String subState, @Nonnull ComponentAccessor<EntityStore> store)Queues a role change request. Marks role.setRoleChangeRequested() to prevent further ticking of the old role.
Tick Logic
Section titled “Tick Logic”@Overridepublic void tick(float dt, int systemIndex, @Nonnull Store<EntityStore> store)Drains the queue. For each valid request:
- Removes the entity from the store with
RemoveReason.UNLOAD. - Nulls the role, removes all role-specific components (
BeaconSupport, event supports,Timers,StateEvaluator,ValueStore,Repulsion). - Updates role name and index.
- Re-adds the entity with
AddReason.LOAD(triggeringRoleBuilderSystem). - If
changeAppearanceis set, applies the new role’s appearance. - If a target state is specified, sets the new role’s state.
Inner Types
Section titled “Inner Types”RoleChangeSystem.RoleChangeQueue
Section titled “RoleChangeSystem.RoleChangeQueue”public static class RoleChangeQueue implements Resource<EntityStore>ECS resource holding a Deque<RoleChangeRequest> of pending role change operations.
RoleChangeSystem.RoleChangeRequest
Section titled “RoleChangeSystem.RoleChangeRequest”private static class RoleChangeRequestData class holding: reference (Ref), roleIndex (int), changeAppearance (boolean), state (String, nullable), subState (String, nullable).
Related Types
Section titled “Related Types”- RoleBuilderSystem — rebuilds the role after the change
- NewSpawnStartTickingSystem — runs before this system