PaperMC/paper-server/nms-patches/net/minecraft/world/entity/monster/EntityZombieVillager.patch
CraftBukkit/Spigot 9ee989ea81 Update to Minecraft 1.18.2
By: md_5 <git@md-5.net>
2022-03-01 02:00:00 +11:00

100 lines
4.5 KiB
Diff

--- a/net/minecraft/world/entity/monster/EntityZombieVillager.java
+++ b/net/minecraft/world/entity/monster/EntityZombieVillager.java
@@ -48,6 +48,13 @@
import net.minecraft.world.level.gameevent.GameEvent;
import org.slf4j.Logger;
+// CraftBukkit start
+import net.minecraft.server.MinecraftServer;
+import org.bukkit.entity.ZombieVillager;
+import org.bukkit.event.entity.CreatureSpawnEvent;
+import org.bukkit.event.entity.EntityTransformEvent;
+// CraftBukkit end
+
public class EntityZombieVillager extends EntityZombie implements VillagerDataHolder {
private static final Logger LOGGER = LogUtils.getLogger();
@@ -65,6 +72,7 @@
@Nullable
private NBTTagCompound tradeOffers;
private int villagerXp;
+ private int lastTick = MinecraftServer.currentTick; // CraftBukkit - add field
public EntityZombieVillager(EntityTypes<? extends EntityZombieVillager> entitytypes, World world) {
super(entitytypes, world);
@@ -83,7 +91,7 @@
@Override
public void addAdditionalSaveData(NBTTagCompound nbttagcompound) {
super.addAdditionalSaveData(nbttagcompound);
- DataResult dataresult = VillagerData.CODEC.encodeStart(DynamicOpsNBT.INSTANCE, this.getVillagerData());
+ DataResult<NBTBase> dataresult = VillagerData.CODEC.encodeStart(DynamicOpsNBT.INSTANCE, this.getVillagerData()); // CraftBukkit - decompile error
Logger logger = EntityZombieVillager.LOGGER;
Objects.requireNonNull(logger);
@@ -139,6 +147,10 @@
public void tick() {
if (!this.level.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;
+ i *= elapsedTicks;
+ // CraftBukkit end
this.villagerConversionTime -= i;
if (this.villagerConversionTime <= 0) {
@@ -147,6 +159,7 @@
}
super.tick();
+ this.lastTick = MinecraftServer.currentTick; // CraftBukkit
}
@Override
@@ -191,8 +204,11 @@
this.conversionStarter = uuid;
this.villagerConversionTime = i;
this.getEntityData().set(EntityZombieVillager.DATA_CONVERTING_ID, true);
- this.removeEffect(MobEffects.WEAKNESS);
- this.addEffect(new MobEffect(MobEffects.DAMAGE_BOOST, i, Math.min(this.level.getDifficulty().getId() - 1, 0)));
+ // CraftBukkit start
+ this.setPersistenceRequired(true); // CraftBukkit - SPIGOT-4684 update persistence
+ this.removeEffect(MobEffects.WEAKNESS, org.bukkit.event.entity.EntityPotionEffectEvent.Cause.CONVERSION);
+ this.addEffect(new MobEffect(MobEffects.DAMAGE_BOOST, i, Math.min(this.level.getDifficulty().getId() - 1, 0)), org.bukkit.event.entity.EntityPotionEffectEvent.Cause.CONVERSION);
+ // CraftBukkit end
this.level.broadcastEntityEvent(this, (byte) 16);
}
@@ -209,7 +225,13 @@
}
private void finishConversion(WorldServer worldserver) {
- EntityVillager entityvillager = (EntityVillager) this.convertTo(EntityTypes.VILLAGER, false);
+ // CraftBukkit start
+ EntityVillager entityvillager = (EntityVillager) this.convertTo(EntityTypes.VILLAGER, false, EntityTransformEvent.TransformReason.CURED, CreatureSpawnEvent.SpawnReason.CURED);
+ if (entityvillager == null) {
+ ((ZombieVillager) getBukkitEntity()).setConversionTime(-1); // SPIGOT-5208: End conversion to stop event spam
+ return;
+ }
+ // CraftBukkit end
EnumItemSlot[] aenumitemslot = EnumItemSlot.values();
int i = aenumitemslot.length;
@@ -224,7 +246,9 @@
double d0 = (double) this.getEquipmentDropChance(enumitemslot);
if (d0 > 1.0D) {
+ this.forceDrops = true; // CraftBukkit
this.spawnAtLocation(itemstack);
+ this.forceDrops = false; // CraftBukkit
}
}
}
@@ -250,7 +274,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
if (!this.isSilent()) {
worldserver.levelEvent((EntityHuman) null, 1027, this.blockPosition(), 0);
}