Paper/nms-patches/EntityZombieVillager.patch

89 lines
3.9 KiB
Diff

--- a/net/minecraft/server/EntityZombieVillager.java
+++ b/net/minecraft/server/EntityZombieVillager.java
@@ -2,13 +2,18 @@
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 {
- private static final DataWatcherObject<Boolean> a = DataWatcher.a(EntityZombieVillager.class, DataWatcherRegistry.i);
+ public static final DataWatcherObject<Boolean> a = DataWatcher.a(EntityZombieVillager.class, DataWatcherRegistry.i); // PAIL
private static final DataWatcherObject<Integer> b = DataWatcher.a(EntityZombieVillager.class, DataWatcherRegistry.b);
- private int conversionTime;
+ public int conversionTime; // PAIL
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) {
@@ -96,12 +106,14 @@
return (Boolean) this.getDataWatcher().get(EntityZombieVillager.a);
}
- protected void a(@Nullable UUID uuid, int i) {
+ public void a(@Nullable UUID uuid, int i) { // PAIL
this.bD = uuid;
this.conversionTime = i;
this.getDataWatcher().set(EntityZombieVillager.a, 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);
}
@@ -116,14 +128,20 @@
entityvillager.setAgeRaw(-24000);
}
- this.world.kill(this);
+ // this.world.kill(this); // CraftBukkit - moved down
entityvillager.setNoAI(this.isNoAI());
if (this.hasCustomName()) {
entityvillager.setCustomName(this.getCustomName());
entityvillager.setCustomNameVisible(this.getCustomNameVisible());
}
- this.world.addEntity(entityvillager);
+ // CraftBukkit start
+ if (CraftEventFactory.callEntityTransformEvent(this, entityvillager, EntityTransformEvent.TransformReason.CURED).isCancelled()) {
+ return;
+ }
+ this.world.kill(this); // CraftBukkit - from above
+ this.world.addEntity(entityvillager, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.CURED); // CraftBukkit - add SpawnReason
+ // CraftBukkit end
if (this.bD != null) {
EntityHuman entityhuman = this.world.b(this.bD);
@@ -132,7 +150,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);
}