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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
|
--- a/net/minecraft/world/entity/monster/Zombie.java
+++ b/net/minecraft/world/entity/monster/Zombie.java
@@ -65,6 +54,25 @@
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.state.BlockState;
import org.joml.Vector3f;
+import net.minecraft.core.BlockPos;
+import net.minecraft.nbt.CompoundTag;
+import net.minecraft.nbt.NbtOps;
+import net.minecraft.nbt.Tag;
+import net.minecraft.network.syncher.EntityDataAccessor;
+import net.minecraft.network.syncher.EntityDataSerializers;
+import net.minecraft.network.syncher.SynchedEntityData;
+// CraftBukkit start
+import net.minecraft.server.MinecraftServer;
+import net.minecraft.server.level.ServerLevel;
+import net.minecraft.sounds.SoundEvent;
+import net.minecraft.sounds.SoundEvents;
+import net.minecraft.sounds.SoundSource;
+import net.minecraft.tags.FluidTags;
+import org.bukkit.event.entity.CreatureSpawnEvent;
+import org.bukkit.event.entity.EntityCombustByEntityEvent;
+import org.bukkit.event.entity.EntityTargetEvent;
+import org.bukkit.event.entity.EntityTransformEvent;
+// CraftBukkit end
public class Zombie extends Monster {
private static final UUID SPEED_MODIFIER_BABY_UUID = UUID.fromString("B9766B59-9566-4402-BC1F-2EE2A276D836");
@@ -84,7 +93,8 @@
private final BreakDoorGoal breakDoorGoal = new BreakDoorGoal(this, DOOR_BREAKING_PREDICATE);
private boolean canBreakDoors;
private int inWaterTime;
- private int conversionTime;
+ public int conversionTime;
+ private int lastTick = MinecraftServer.currentTick; // CraftBukkit - add field
public Zombie(EntityType<? extends Zombie> entityType, Level level) {
super(entityType, level);
@@ -202,7 +211,10 @@
public void tick() {
if (!this.level().isClientSide && this.isAlive() && !this.isNoAi()) {
if (this.isUnderWaterConverting()) {
- this.conversionTime--;
+ // CraftBukkit start - Use wall time instead of ticks for conversion
+ int elapsedTicks = MinecraftServer.currentTick - this.lastTick;
+ this.conversionTime -= elapsedTicks;
+ // CraftBukkit end
if (this.conversionTime < 0) {
this.doUnderWaterConversion();
}
@@ -219,6 +231,7 @@
}
super.tick();
+ this.lastTick = MinecraftServer.currentTick; // CraftBukkit
}
@Override
@@ -248,7 +263,8 @@
super.aiStep();
}
- private void startUnderWaterConversion(int conversionTime) {
+ public void startUnderWaterConversion(int conversionTime) {
+ this.lastTick = MinecraftServer.currentTick; // CraftBukkit
this.conversionTime = conversionTime;
this.getEntityData().set(DATA_DROWNED_CONVERSION_ID, true);
}
@@ -261,10 +278,15 @@
}
protected void convertToZombieType(EntityType<? extends Zombie> entityType) {
- Zombie zombie = this.convertTo(entityType, true);
- if (zombie != null) {
- zombie.handleAttributes(zombie.level().getCurrentDifficultyAt(zombie.blockPosition()).getSpecialMultiplier());
- zombie.setCanBreakDoors(zombie.supportsBreakDoorGoal() && this.canBreakDoors());
+ Zombie entityzombie = (Zombie) this.convertTo(entityType, true, EntityTransformEvent.TransformReason.DROWNED, CreatureSpawnEvent.SpawnReason.DROWNED);
+
+ if (entityzombie != null) {
+ entityzombie.handleAttributes(entityzombie.level().getCurrentDifficultyAt(entityzombie.blockPosition()).getSpecialMultiplier());
+ entityzombie.setCanBreakDoors(entityzombie.supportsBreakDoorGoal() && this.canBreakDoors());
+ // CraftBukkit start - SPIGOT-5208: End conversion to stop event spam
+ } else {
+ ((org.bukkit.entity.Zombie) getBukkitEntity()).setConversionTime(-1);
+ // CraftBukkit end
}
}
@@ -294,29 +315,22 @@
int floor2 = Mth.floor(this.getZ());
Zombie zombie = new Zombie(this.level());
- for (int i = 0; i < 50; i++) {
- int i1 = floor + Mth.nextInt(this.random, 7, 40) * Mth.nextInt(this.random, -1, 1);
- int i2 = floor1 + Mth.nextInt(this.random, 7, 40) * Mth.nextInt(this.random, -1, 1);
- int i3 = floor2 + Mth.nextInt(this.random, 7, 40) * Mth.nextInt(this.random, -1, 1);
- BlockPos blockPos = new BlockPos(i1, i2, i3);
- EntityType<?> type = zombie.getType();
- SpawnPlacements.Type placementType = SpawnPlacements.getPlacementType(type);
- if (NaturalSpawner.isSpawnPositionOk(placementType, this.level(), blockPos, type)
- && SpawnPlacements.checkSpawnRules(type, serverLevel, MobSpawnType.REINFORCEMENT, blockPos, this.level().random)) {
- zombie.setPos((double)i1, (double)i2, (double)i3);
- if (!this.level().hasNearbyAlivePlayer((double)i1, (double)i2, (double)i3, 7.0)
- && this.level().isUnobstructed(zombie)
- && this.level().noCollision(zombie)
- && !this.level().containsAnyLiquid(zombie.getBoundingBox())) {
- zombie.setTarget(target);
- zombie.finalizeSpawn(
- serverLevel, this.level().getCurrentDifficultyAt(zombie.blockPosition()), MobSpawnType.REINFORCEMENT, null, null
- );
- serverLevel.addFreshEntityWithPassengers(zombie);
- this.getAttribute(Attributes.SPAWN_REINFORCEMENTS_CHANCE)
- .addPermanentModifier(new AttributeModifier("Zombie reinforcement caller charge", -0.05F, AttributeModifier.Operation.ADDITION));
- zombie.getAttribute(Attributes.SPAWN_REINFORCEMENTS_CHANCE)
- .addPermanentModifier(new AttributeModifier("Zombie reinforcement callee charge", -0.05F, AttributeModifier.Operation.ADDITION));
+ for (int l = 0; l < 50; ++l) {
+ int i1 = i + Mth.nextInt(this.random, 7, 40) * Mth.nextInt(this.random, -1, 1);
+ int j1 = j + Mth.nextInt(this.random, 7, 40) * Mth.nextInt(this.random, -1, 1);
+ int k1 = k + Mth.nextInt(this.random, 7, 40) * Mth.nextInt(this.random, -1, 1);
+ BlockPos blockposition = new BlockPos(i1, j1, k1);
+ EntityType<?> entitytypes = entityzombie.getType();
+ SpawnPlacements.Surface entitypositiontypes_surface = SpawnPlacements.getPlacementType(entitytypes);
+
+ if (NaturalSpawner.isSpawnPositionOk(entitypositiontypes_surface, this.level(), blockposition, entitytypes) && SpawnPlacements.checkSpawnRules(entitytypes, worldserver, EnumMobSpawn.REINFORCEMENT, blockposition, this.level().random)) {
+ entityzombie.setPos((double) i1, (double) j1, (double) k1);
+ if (!this.level().hasNearbyAlivePlayer((double) i1, (double) j1, (double) k1, 7.0D) && this.level().isUnobstructed(entityzombie) && this.level().noCollision((Entity) entityzombie) && !this.level().containsAnyLiquid(entityzombie.getBoundingBox())) {
+ entityzombie.setTarget(entityliving, EntityTargetEvent.TargetReason.REINFORCEMENT_TARGET, true); // CraftBukkit
+ entityzombie.finalizeSpawn(worldserver, this.level().getCurrentDifficultyAt(entityzombie.blockPosition()), EnumMobSpawn.REINFORCEMENT, (GroupDataEntity) null, (CompoundTag) null);
+ worldserver.addFreshEntityWithPassengers(entityzombie, CreatureSpawnEvent.SpawnReason.REINFORCEMENTS); // CraftBukkit
+ this.getAttribute(Attributes.SPAWN_REINFORCEMENTS_CHANCE).addPermanentModifier(new AttributeModifier("Zombie reinforcement caller charge", -0.05000000074505806D, AttributeModifier.Operation.ADDITION));
+ entityzombie.getAttribute(Attributes.SPAWN_REINFORCEMENTS_CHANCE).addPermanentModifier(new AttributeModifier("Zombie reinforcement callee charge", -0.05000000074505806D, AttributeModifier.Operation.ADDITION));
break;
}
}
@@ -331,9 +346,17 @@
public boolean doHurtTarget(Entity entity) {
boolean flag = super.doHurtTarget(entity);
if (flag) {
- float effectiveDifficulty = this.level().getCurrentDifficultyAt(this.blockPosition()).getEffectiveDifficulty();
- if (this.getMainHandItem().isEmpty() && this.isOnFire() && this.random.nextFloat() < effectiveDifficulty * 0.3F) {
- entity.setSecondsOnFire(2 * (int)effectiveDifficulty);
+ float f = this.level().getCurrentDifficultyAt(this.blockPosition()).getEffectiveDifficulty();
+
+ if (this.getMainHandItem().isEmpty() && this.isOnFire() && this.random.nextFloat() < f * 0.3F) {
+ // CraftBukkit start
+ EntityCombustByEntityEvent event = new EntityCombustByEntityEvent(this.getBukkitEntity(), entity.getBukkitEntity(), 2 * (int) f); // PAIL: fixme
+ this.level().getCraftServer().getPluginManager().callEvent(event);
+
+ if (!event.isCancelled()) {
+ entity.setSecondsOnFire(event.getDuration(), false);
+ }
+ // CraftBukkit end
}
}
@@ -409,25 +438,36 @@
if (level.getDifficulty() != Difficulty.HARD && this.random.nextBoolean()) {
return flag;
}
+ // CraftBukkit start
+ flag = zombifyVillager(level, entityvillager, this.blockPosition(), this.isSilent(), CreatureSpawnEvent.SpawnReason.INFECTION) == null;
+ }
- ZombieVillager zombieVillager = villager.convertTo(EntityType.ZOMBIE_VILLAGER, false);
- if (zombieVillager != null) {
- zombieVillager.finalizeSpawn(
- level, level.getCurrentDifficultyAt(zombieVillager.blockPosition()), MobSpawnType.CONVERSION, new Zombie.ZombieGroupData(false, true), null
- );
- zombieVillager.setVillagerData(villager.getVillagerData());
- zombieVillager.setGossips(villager.getGossips().store(NbtOps.INSTANCE));
- zombieVillager.setTradeOffers(villager.getOffers().createTag());
- zombieVillager.setVillagerXp(villager.getVillagerXp());
- if (!this.isSilent()) {
- level.levelEvent(null, 1026, this.blockPosition(), 0);
+ return flag;
+ }
+
+ public static ZombieVillager zombifyVillager(ServerLevel worldserver, Villager entityvillager, net.minecraft.core.BlockPos blockPosition, boolean silent, CreatureSpawnEvent.SpawnReason spawnReason) {
+ {
+ ZombieVillager entityzombievillager = (ZombieVillager) entityvillager.convertTo(EntityType.ZOMBIE_VILLAGER, false, EntityTransformEvent.TransformReason.INFECTION, spawnReason);
+ // CraftBukkit end
+
+ if (entityzombievillager != null) {
+ entityzombievillager.finalizeSpawn(worldserver, worldserver.getCurrentDifficultyAt(entityzombievillager.blockPosition()), EnumMobSpawn.CONVERSION, new Zombie.ZombieGroupData(false, true), (CompoundTag) null);
+ entityzombievillager.setVillagerData(entityvillager.getVillagerData());
+ entityzombievillager.setGossips((Tag) entityvillager.getGossips().store(NbtOps.INSTANCE));
+ entityzombievillager.setTradeOffers(entityvillager.getOffers().createTag());
+ entityzombievillager.setVillagerXp(entityvillager.getVillagerXp());
+ // CraftBukkit start
+ if (!silent) {
+ worldserver.levelEvent((Player) null, 1026, blockPosition, 0);
}
flag = false;
}
}
- return flag;
+ return entityzombievillager;
+ }
+ // CraftBukkit end
}
@Override
@@ -471,14 +511,15 @@
chicken.setChickenJockey(true);
this.startRiding(chicken);
}
- } else if ((double)random.nextFloat() < 0.05) {
- Chicken chicken1 = EntityType.CHICKEN.create(this.level());
- if (chicken1 != null) {
- chicken1.moveTo(this.getX(), this.getY(), this.getZ(), this.getYRot(), 0.0F);
- chicken1.finalizeSpawn(level, difficulty, MobSpawnType.JOCKEY, null, null);
- chicken1.setChickenJockey(true);
- this.startRiding(chicken1);
- level.addFreshEntity(chicken1);
+ } else if ((double) randomsource.nextFloat() < 0.05D) {
+ Chicken entitychicken1 = (Chicken) EntityType.CHICKEN.create(this.level());
+
+ if (entitychicken1 != null) {
+ entitychicken1.moveTo(this.getX(), this.getY(), this.getZ(), this.getYRot(), 0.0F);
+ entitychicken1.finalizeSpawn(level, difficulty, EnumMobSpawn.JOCKEY, (GroupDataEntity) null, (CompoundTag) null);
+ entitychicken1.setChickenJockey(true);
+ this.startRiding(entitychicken1);
+ level.addFreshEntity(entitychicken1, CreatureSpawnEvent.SpawnReason.MOUNT); // CraftBukkit
}
}
}
|