[SPIGOT-6107] EntityTransformEvent returns incorrect entity when villager gets infected Created: 26/Aug/20 Updated: 27/Aug/20 Resolved: 26/Aug/20 |
|
Status: | Resolved |
Project: | Spigot |
Component/s: | None |
Affects Version/s: | None |
Fix Version/s: | None |
Type: | Bug | Priority: | Minor |
Reporter: | Sasha Sorokin | Assignee: | Unassigned |
Resolution: | Cannot Reproduce | Votes: | 0 |
Labels: | api, bug, spigot | ||
Environment: |
Windows 10 running Java 1.8.0_261 |
Version: | git-Spigot-9639cf7-4b9bc9d (MC: 1.16.1) (Implementing API version 1.16.1-R0.1-SNAPSHOT) |
Guidelines Read: | Yes |
Description |
EntityTransformEvent event supposed to fire whenever one entity gets converted to another for various reasons (e.g. zombie turning drowned). It gets its job fine until it comes to zombie infecting a villager, where incorrect entity is returned. Here's the example of code: @EventHandler public void onEntityTrasformed(EntityTransformEvent event) { if (event.getTransformReason() != EntityTransformEvent.TransformReason.INFECTION) { return; } // Because EntityTransformEvent#getEntity returns entity before conversion // for TransformReason such as mushroom gets sheared or zombie villager // gets cured, I can assume this is going to return me a villager, right? Villager infectedVillager = (Villager) event.getEntity(); ZombieVillager newCarrier = (ZombieVillager) event.getTransformedEntity(); // Something being done to these variables above getServer().broadcastMessage(":crab: :crab: Villager infected :crab: :crab:"); } It feels reasonable for EntityTransformEvent#getEntity to return Villager before it was converted, so let's convert summon a zombie in hard difficulty and uh... watch. Villager gets hurt many times until finally transformed to a zombie, but what's this? Where's our message? Let's see the console and here it is. The {{ java.lang.ClassCastException}}. Because we attempted to convert zombie to a villager. Wait! What zombie? The one that attacked our villager, of course. And there is no way you're going to get the villager that got transformed, even that if you're debugging and go below the trace, you can find actual villager class. It feels like a bug that should be fixed, because, again, it returned us a mushroom before it got converted into a cow after we sheared it, and a zombie villager after it got cured, and none of these events happened by themselves, the player was initiator. Otherwise, if that's correct behavior, provide a way to get the entity before it was transformed and document the behavior, because it really is not obvious. |
Comments |
Comment by Sasha Sorokin [ 27/Aug/20 ] |
@md_5 I'm not sure update to 1.16.2 is yet possible, it's a very recent version and contained many internal changes (as from what I heard), even Paper had problems with upgrading worlds. No mods such as OptiFine or Sodium upgraded to it either and players on my server depend on it. Guess I'm doomed then? |
Comment by md_5 [ 26/Aug/20 ] |
Works fine for me in 1.16.2, update |