Solved Preventing zombie villagers from being healed

Discussion in 'Spigot Plugin Development' started by torpkev, Aug 1, 2020.

  1. I was looking for a way to prevent a ZombieVillager to flip over to being cured.

    In my PlayterInteractAtEntity, I'm catching if the player right clicks the zombie villager with a golden apple, and if so, cancelling the event - but - they already have the ZombieVillager.isConverting() == true and start the shaking they get when they start to be cured.

    I don't think there is an event that catches the conversion (unless I'm missing it?) - any thoughts on how I can either set the converting flag back to false, or prevent it going to true in the first place?
    • Agree Agree x 1
  2. I think this event is only called right when the cured villager appears and therefor not useful for him.
  3. I never used it, but I saw that it implements Cancellable so I figured you can "catch" it before/during the process.
    • Agree Agree x 1
  4. It isn't ideal because they do start the cure process (which would potentially prevent someone else from starting it at the same time) - but it is definitely better than nothing. I can't for the life of me work out why ZombieVillager has an .isConverting() but not a .setConverting(boolean value)

    Catching and cancelling the EntityTransformEvent does stop them actually turning into villagers though, so gonna mark this one as Solved.

    Thanks guys
  5. Could you elaborate a bit more? I don't really understand what you try to achieve. The event gets called and cancelled within a tick so from a players point of view nothing changed (in the sense that the villager hasn't transformed).
    EDIT: Oh yeah, I get it now, the process of transforming takes time and you want to avoid that
  6. Just checked and what about this workaround: As soon as a zombie villager is created you set the conversion time to a really low number (1 tick maybe) so the delay between the player curing a zombie villager and the EntityTransformEvent is as small as possible.
  7. That is exactly kinda what I was thinking.

    I'll take the entity id in the player interact and save it in a map somewhere - set the conversion time down to 1-2 seconds - then in the EntityTransformEvent - if the entity id matches what is in my map, cancel that event. That should (hopefully) make it a very quick process and still stop the conversion. I suppose I could skip the map part, but I don't want to be checking if they're allowed to convert the zombies twice, and I don't really want to drop the conversion time for everyone regardless.

    Kind sucky that the workaround is needed (setConverting(false) would have been SO much easier) - but if it works, then no big deal.

    Appreciate the follow up - good to know I wasn't off base on it.
  8. You don't need to use PlayerInteractEvent, you can just use EntityTransformEvent to identify a newly spawned ZombieVillager.
  9. I could - but that means waiting for the timer to expire. EntityTransform doesn't fire until they actually turn. The PlayerInteractAtEntity is where I'm hoping to set the conversion time down so the EntityTransform fires quicker. But as I only want to stop SOME players from turning zombie villagers, I need to do my validation before i change conversion time.
  10. Ha.. well that would have been handy to know before I wasted all this time on things. My code currently works, but I'm going to try this out and if it works as it looks like it would, will switch over to this as it seems a lot simpler.