import com.frotty27.nameplatebuilder.api.NameplateData;
import com.hypixel.hytale.component.*;
import com.hypixel.hytale.component.system.tick.EntityTickingSystem;
import com.hypixel.hytale.server.core.modules.entity.tracker.EntityTrackerSystems;
import com.hypixel.hytale.server.npc.entities.NPCEntity;
import com.hypixel.hytale.server.core.universe.world.storage.EntityStore;
final class MyNpcNameplateSystem extends EntityTickingSystem<EntityStore> {
private static final String ROLE_NAME = "Kweebec";
private final ComponentType<EntityStore, NPCEntity> npcType;
private final ComponentType<EntityStore, NameplateData> nameplateDataType;
MyNpcNameplateSystem(ComponentType<EntityStore, NameplateData> nameplateDataType) {
this.npcType = NPCEntity.getComponentType();
this.nameplateDataType = nameplateDataType;
}
@Override
public Archetype<EntityStore> getQuery() {
return Archetype.of(npcType);
}
@Override
public SystemGroup<EntityStore> getGroup() {
return EntityTrackerSystems.QUEUE_UPDATE_GROUP;
}
@Override
public void tick(float dt, int index, ArchetypeChunk<EntityStore> chunk,
Store<EntityStore> store, CommandBuffer<EntityStore> cb) {
// Filter by NPC role name
NPCEntity npc = chunk.getComponent(index, npcType);
if (npc == null || !ROLE_NAME.equals(npc.getRoleName())) {
return;
}
Ref<EntityStore> ref = chunk.getReferenceTo(index);
// Skip if already initialized
if (store.getComponent(ref, nameplateDataType) != null) {
return;
}
// First time — seed nameplate data
NameplateData data = new NameplateData();
data.setText("health", "100/100");
data.setText("level", "Lv. 10");
data.setText("faction", "<Forest>");
// Use putComponent via CommandBuffer (NOT store.addComponent)
cb.putComponent(ref, nameplateDataType, data);
}
}