[BUG] Citizens freezing
Closed
[BUG] Citizens freezing
I had reported it as a reply in another issue, but I decided to create a separate issue.
Citizens v 2.0.31-SNAPSHOT (build 2996, tried more recent builds but it wasn't fixed) ModelEngine R3.1.5
some models of NPCs just freeze, I don't know why, they seem to be some specific ones because only few work correctly
these npcs should be walking: https://youtu.be/p-GLOttMbFY
All npcs worked before and recently stopped working, probably after some ModelEngine update. After creating a new NPC with modelengine, works normally, after a server restart it just frozes
mentioned in issue #64 (closed)
Cannot replicate. https://youtu.be/wYE4dKZJkkY Using Citizens build 2996, Model Engine R3.1.5, and Paper 1.18.2
Edited by Ticxo
Also on 1.19.4 with R3.1.6 almost all modelled citizens are no longer animating. Curiously, some models near the spawn chunk seem to be working... perhaps it has something to do with the animations not starting when a chuck is loaded in after being unloaded...?
EDIT: Attached a video of... something. These npcs are set to auto rotate to the nearest player, and have ME models set on them. They do rotate, and the model seems to be put in in the correct direction when the player logs in, but it doesn't run the idle animation or change when the player moves and the base entity rotates. Some task has to have been cancelled or something, but I see nothing in the logs indicating an error. These models work fine when used for anything else besides the /meg citizens commands.
Edited by GamingGameradded Bug label
@drawned I gave up waiting and wrote my own thing that loads a map of citizens npcId to modelIds, and applies the model on NPC spawn. It's not great code, because I made it in like 5 minutes, but it does do what you'd want it to. Plus it could be expanded to make modelled NPCs play specific animations via commands or whatever, if you wanted. When I first did this, they were still frozen, but seemingly delaying the application of the model solves the problem. Good luck, hope you can use it.
public class CitizenModelListener implements Listener { private final StrifePlugin plugin; private final Map<Integer, NpcModelData> npcModelMap = new HashMap<>(); public CitizenModelListener(StrifePlugin plugin) { this.plugin = plugin; } @EventHandler(priority = EventPriority.MONITOR) public void onNpcSpawn(NPCSpawnEvent event) { if (event.isCancelled() || event.getReason() != SpawnReason.CHUNK_LOAD) { return; } NpcModelData npcModelData = npcModelMap.get(event.getNPC().getId()); if (npcModelData != null) { applyModel(event.getNPC(), npcModelData); } } public void reloadModels(ConfigurationSection section) { for (String key : section.getKeys(false)) { try { ConfigurationSection npcSection = section.getConfigurationSection(key); NpcModelData npcModelData = new NpcModelData(); npcModelData.setModel(npcSection.getString("model-id")); npcModelData.setShowBaseEntity(npcSection.getBoolean("show-base-entity", false)); npcModelMap.put(Integer.valueOf(key), npcModelData); } catch (Exception e) { e.printStackTrace(); } } Bukkit.getLogger().info("[Strife] Loaded " + npcModelMap.size() + " npc models"); for (int i : npcModelMap.keySet()) { NPC npc = CitizensAPI.getNPCRegistry().getById(i); if (!npc.isSpawned()) { continue; } NpcModelData npcModelData = npcModelMap.get(i); applyModel(npc, npcModelData); } } private void applyModel(NPC npc, NpcModelData npcModelData) { Bukkit.getScheduler().runTaskLater(plugin, () -> { if (npc.getEntity() != null && npc.getEntity().isValid()) { if (!ModelEngineAPI.getModelTicker().isModeledEntity(npc.getEntity().getUniqueId())) { ModeledEntity modeledEntity = ModelEngineAPI.createModeledEntity(npc.getEntity()); if (modeledEntity != null) { modeledEntity.addModel(ModelEngineAPI.createActiveModel(npcModelData.getModel()), true); modeledEntity.setBaseEntityVisible(npcModelData.isShowBaseEntity()); } } } }, 10L); } }
@Data public class NpcModelData { private String model; private boolean showBaseEntity; }
@UltraFaceguy Hello, I'm a person who has hope for your alternative. And I made my own plugin to solve this problem alternatively by referring yours. but I faced a problem in your codes are not including that how and when to call
reloadModels
also I couldn't find the section arguments to pass. I would appreciate it if you could give me more information about it :D
added Possibly Resolved label