Posted June 15, 20169 yr Context: I'm trying to disable the ability of Silverfish to summon more Silverfish, because I hate that particular design choice too much for my own good health. I'll probably try to replace it with some other ability that doesn't give me The Rage, but first I have to nuke it. I'm poking around in EntitySilverfish and it's a custom AI task. "AHA!" I said to myself, "I can just remove it from the task list when they spawn!" (via the EntityJoinWorldEvent event). Alas, it's a package scoped internal class, and the instance of the class on each EntitySilverfish is in a private variable. So my first idea won't work: entity.tasks.removeTask(entity.summonSilverfish); // instance of AI class - private, can't access and my second idea won't work, to whit iterating over entity.tasks.taskEntries to find the one that is of class EntitySilverfish.AISummonSilverfish, and remove THAT. Can't check for that, since it's private. I can nuke silverfish from spawning entirely by catching LivingSpawnEvent.CheckSpawn and denying them, but completely forbidding them is overkill, and I'm not sure how to catch if they've been summoned by a silverfish at this point. Soooo... how can I remove this private class from the list when I'm not even allowed to know its a thing?
June 15, 20169 yr Use reflection to access the EntitySilverfish#summonSilverfish field, then remove that value from the task list. Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.
June 15, 20169 yr Author Use reflection to access the EntitySilverfish#summonSilverfish field, then remove that value from the task list. Herpderp. Thanks, not entirely used to reflection yet so I never think of it as a tool.
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.