Uploaded image for project: 'Spigot'
  1. Spigot
  2. SPIGOT-6107

EntityTransformEvent returns incorrect entity when villager gets infected

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Cannot Reproduce
    • Icon: Minor Minor
    • None
    • None
    • Windows 10 running Java 1.8.0_261

    • git-Spigot-9639cf7-4b9bc9d (MC: 1.16.1) (Implementing API version 1.16.1-R0.1-SNAPSHOT)
    • Yes

      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.

            Unassigned Unassigned
            RouhKeen Sasha Sorokin
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: