Paper/nms-patches/EntityZombieVillager.patch
blablubbabc 9bda413457 SPIGOT-4943: Zombie villager conversion player API.
Also resetting the conversion player when stopping a conversion.
2019-05-18 10:58:58 +10:00

83 lines
3.8 KiB
Diff

--- a/net/minecraft/server/EntityZombieVillager.java
+++ b/net/minecraft/server/EntityZombieVillager.java
@@ -3,15 +3,20 @@
import com.mojang.datafixers.Dynamic;
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 implements VillagerDataHolder {
public static final DataWatcherObject<Boolean> CONVERTING = DataWatcher.a(EntityZombieVillager.class, DataWatcherRegistry.i);
private static final DataWatcherObject<VillagerData> c = DataWatcher.a(EntityZombieVillager.class, DataWatcherRegistry.q);
public int conversionTime;
- private UUID conversionPlayer;
+ public UUID conversionPlayer; // CraftBukkit - public
private NBTTagCompound bB;
private int bC;
+ private int lastTick = MinecraftServer.currentTick; // CraftBukkit - add field
public EntityZombieVillager(EntityTypes<? extends EntityZombieVillager> entitytypes, World world) {
super(entitytypes, world);
@@ -66,6 +71,11 @@
public void tick() {
if (!this.world.isClientSide && this.isAlive() && this.isConverting()) {
int i = this.getConversionProgress();
+ // 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) {
@@ -113,8 +123,11 @@
this.conversionPlayer = uuid;
this.conversionTime = i;
this.getDataWatcher().set(EntityZombieVillager.CONVERTING, true);
- this.removeEffect(MobEffects.WEAKNESS);
- this.addEffect(new MobEffect(MobEffects.INCREASE_DAMAGE, i, Math.min(this.world.getDifficulty().a() - 1, 0)));
+ // CraftBukkit start
+ this.persistent = true; // CraftBukkit - SPIGOT-4684 update persistence
+ 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);
}
@@ -133,14 +146,20 @@
entityvillager.setAgeRaw(-24000);
}
- this.die();
+ // this.die(); // CraftBukkit - moved down
entityvillager.setNoAI(this.isNoAI());
if (this.hasCustomName()) {
entityvillager.setCustomName(this.getCustomName());
entityvillager.setCustomNameVisible(this.getCustomNameVisible());
}
- worldserver.addEntity(entityvillager);
+ // CraftBukkit start
+ if (CraftEventFactory.callEntityTransformEvent(this, entityvillager, EntityTransformEvent.TransformReason.CURED).isCancelled()) {
+ return;
+ }
+ this.die(); // CraftBukkit - from above
+ worldserver.addEntity(entityvillager, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.CURED); // CraftBukkit - add SpawnReason
+ // CraftBukkit end
if (this.conversionPlayer != null) {
EntityHuman entityhuman = worldserver.b(this.conversionPlayer);
@@ -150,7 +169,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
worldserver.a((EntityHuman) null, 1027, new BlockPosition(this), 0);
}