0
0
mirror of https://hub.spigotmc.org/stash/scm/spigot/craftbukkit.git synced 2024-11-25 08:06:14 +00:00
craftbukkit/nms-patches/net/minecraft/world/entity/monster/EntityZombieVillager.patch
2024-10-23 02:15:00 +11:00

109 lines
5.1 KiB
Diff

--- a/net/minecraft/world/entity/monster/EntityZombieVillager.java
+++ b/net/minecraft/world/entity/monster/EntityZombieVillager.java
@@ -52,6 +52,14 @@
import net.minecraft.world.level.block.state.IBlockData;
import org.slf4j.Logger;
+// CraftBukkit start
+import net.minecraft.server.MinecraftServer;
+import net.minecraft.world.entity.npc.EntityVillager;
+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();
@@ -69,6 +77,7 @@
@Nullable
private MerchantRecipeList tradeOffers;
private int villagerXp;
+ private int lastTick = MinecraftServer.currentTick; // CraftBukkit - add field
public EntityZombieVillager(EntityTypes<? extends EntityZombieVillager> entitytypes, World world) {
super(entitytypes, world);
@@ -87,7 +96,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);
@@ -122,7 +131,7 @@
}
if (nbttagcompound.contains("Offers")) {
- DataResult dataresult1 = MerchantRecipeList.CODEC.parse(this.registryAccess().createSerializationContext(DynamicOpsNBT.INSTANCE), nbttagcompound.get("Offers"));
+ DataResult<MerchantRecipeList> dataresult1 = MerchantRecipeList.CODEC.parse(this.registryAccess().createSerializationContext(DynamicOpsNBT.INSTANCE), nbttagcompound.get("Offers")); // CraftBukkit - decompile error
Logger logger1 = EntityZombieVillager.LOGGER;
Objects.requireNonNull(logger1);
@@ -149,6 +158,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) {
@@ -157,6 +170,7 @@
}
super.tick();
+ this.lastTick = MinecraftServer.currentTick; // CraftBukkit
}
@Override
@@ -197,8 +211,10 @@
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.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);
}
@@ -215,10 +231,11 @@
}
private void finishConversion(WorldServer worldserver) {
- this.convertTo(EntityTypes.VILLAGER, ConversionParams.single(this, false, false), (entityvillager) -> {
+ EntityVillager converted = this.convertTo(EntityTypes.VILLAGER, ConversionParams.single(this, false, false), (entityvillager) -> { // CraftBukkit
Iterator iterator = this.dropPreservedEquipment(worldserver, (itemstack) -> {
return !EnchantmentManager.has(itemstack, EnchantmentEffectComponents.PREVENT_ARMOR_CHANGE);
}).iterator();
+ this.forceDrops = false; // CraftBukkit
while (iterator.hasNext()) {
EnumItemSlot enumitemslot = (EnumItemSlot) iterator.next();
@@ -248,12 +265,16 @@
}
}
- 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);
}
-
- });
+ // CraftBukkit start
+ }, EntityTransformEvent.TransformReason.CURED, CreatureSpawnEvent.SpawnReason.CURED);
+ if (converted == null) {
+ ((ZombieVillager) getBukkitEntity()).setConversionTime(-1); // SPIGOT-5208: End conversion to stop event spam
+ }
+ // CraftBukkit end
}
@VisibleForTesting