summaryrefslogtreecommitdiffstats
path: root/nms-patches/EntityZombieVillager.patch
blob: 895bf78958a2bf9ca8dfcf81a5801e5ea9bbafb3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
--- a/net/minecraft/server/EntityZombieVillager.java
+++ b/net/minecraft/server/EntityZombieVillager.java
@@ -2,6 +2,10 @@
 
 import java.util.UUID;
 import javax.annotation.Nullable;
+// CraftBukkit start
+import org.bukkit.craftbukkit.event.CraftEventFactory;
+import org.bukkit.event.entity.EntityTransformEvent;
+// CraftBukkit end
 
 public class EntityZombieVillager extends EntityZombie {
 
@@ -9,6 +13,7 @@
     private static final DataWatcherObject<Integer> b = DataWatcher.a(EntityZombieVillager.class, DataWatcherRegistry.b);
     private int conversionTime;
     private UUID bD;
+    private int lastTick = MinecraftServer.currentTick; // CraftBukkit - add field
 
     public EntityZombieVillager(World world) {
         super(EntityTypes.ZOMBIE_VILLAGER, world);
@@ -54,8 +59,13 @@
     }
 
     public void tick() {
-        if (!this.world.isClientSide && this.isConverting()) {
+        if (!this.world.isClientSide && this.isConverting() && this.isAlive()) { // CraftBukkit
             int i = this.dK();
+            // CraftBukkit start - Use wall time instead of ticks for villager conversion
+            int elapsedTicks = MinecraftServer.currentTick - this.lastTick;
+            this.lastTick = MinecraftServer.currentTick;
+            i *= elapsedTicks;
+            // CraftBukkit end
 
             this.conversionTime -= i;
             if (this.conversionTime <= 0) {
@@ -100,8 +110,10 @@
         this.bD = uuid;
         this.conversionTime = i;
         this.getDataWatcher().set(EntityZombieVillager.a, Boolean.valueOf(true));
-        this.removeEffect(MobEffects.WEAKNESS);
-        this.addEffect(new MobEffect(MobEffects.INCREASE_DAMAGE, i, Math.min(this.world.getDifficulty().a() - 1, 0)));
+        // CraftBukkit start
+        this.removeEffect(MobEffects.WEAKNESS, org.bukkit.event.entity.EntityPotionEffectEvent.Cause.CONVERSION);
+        this.addEffect(new MobEffect(MobEffects.INCREASE_DAMAGE, i, Math.min(this.world.getDifficulty().a() - 1, 0)), org.bukkit.event.entity.EntityPotionEffectEvent.Cause.CONVERSION);
+        // CraftBukkit end
         this.world.broadcastEntityEffect(this, (byte) 16);
     }
 
@@ -123,7 +135,12 @@
             entityvillager.setCustomNameVisible(this.getCustomNameVisible());
         }
 
-        this.world.addEntity(entityvillager);
+        // CraftBukkit start
+        if (CraftEventFactory.callEntityTransformEvent(this, entityvillager, EntityTransformEvent.TransformReason.CURED).isCancelled()) {
+            return;
+        }
+        // CraftBukkit end
+        this.world.addEntity(entityvillager, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.CURED); // CraftBukkit - add SpawnReason
         if (this.bD != null) {
             EntityHuman entityhuman = this.world.b(this.bD);
 
@@ -132,7 +149,7 @@
             }
         }
 
-        entityvillager.addEffect(new MobEffect(MobEffects.CONFUSION, 200, 0));
+        entityvillager.addEffect(new MobEffect(MobEffects.CONFUSION, 200, 0), org.bukkit.event.entity.EntityPotionEffectEvent.Cause.CONVERSION); // CraftBukkit
         this.world.a((EntityHuman) null, 1027, new BlockPosition((int) this.locX, (int) this.locY, (int) this.locZ), 0);
     }