Topic category: Troubleshooting, bugs, and solutions
I added a mechanic to my mod that changes which weapons specific mobs spawn with. So far, I have added this to Zombies, Husks and Zombified Piglins.
Before this mechanic, Zombies and Husks, for example, had a chance to spawn with an Iron Shovel or an Iron Sword. This is vanilla behavior.
For now I changed this so that Zombies can also spawn with a custom weapon, that Husks tend to spawn with golden tools and that Zombified Piglins have a chance to spawn with a golden axe.
In the procedure below, I tried to make sure that this mechanic only triggers as soon as mobs appear for the first time, but I've observed that it also triggers seemingly randomly, making mobs have a chance to switch to a different item when they're not supposed to. This is the bug I want to get rid of.
I accomplished this in Survival Expansion v2.0.1, where skeletons and their variants spawn with the opposite type of their usual weapon sometimes (e.g, Wither Skeletons sometimes spawn with bows, making their behavior with bows used) without the mob switching back to its usual weapon.
How? In my case, my procedure triggers randomly and still tries to control what weapons mobs have for seemingly no reason. I've observed this when zombies kill me (near my spawn point), and then I respawn. I even had the mob spawning gamerule off.
I probably just figured out a fix for this by adding a one tick delay. Only drawback - at first tick of a mob spawning, the procedure does not trigger, making it noticeable that the mob's wielding won't comply with my new mechanic until the next tick.
My speculation for this problem is that when I immediately try to trigger my procedure as a mob spawns, that mob still wouldn't have loaded properly, causing the issue I have mentioned earlier.
https://imgur.com/a/85e4bGy