net.minecraft.world.entity.raid

This commit is contained in:
Jake Potrebic
2024-12-13 19:53:42 -08:00
parent aa7204fd62
commit 368d2116ba
4 changed files with 128 additions and 156 deletions

View File

@@ -1,30 +1,30 @@
--- a/net/minecraft/world/entity/raid/Raid.java --- a/net/minecraft/world/entity/raid/Raid.java
+++ b/net/minecraft/world/entity/raid/Raid.java +++ b/net/minecraft/world/entity/raid/Raid.java
@@ -107,6 +107,11 @@ @@ -104,6 +_,11 @@
private Raid.RaidStatus status; private Raid.RaidStatus status;
private int celebrationTicks; private int celebrationTicks;
private Optional<BlockPos> waveSpawnPos; private Optional<BlockPos> waveSpawnPos = Optional.empty();
+ // Paper start + // Paper start
+ private static final String PDC_NBT_KEY = "BukkitValues"; + private static final String PDC_NBT_KEY = "BukkitValues";
+ private static final org.bukkit.craftbukkit.persistence.CraftPersistentDataTypeRegistry PDC_TYPE_REGISTRY = new org.bukkit.craftbukkit.persistence.CraftPersistentDataTypeRegistry(); + private static final org.bukkit.craftbukkit.persistence.CraftPersistentDataTypeRegistry PDC_TYPE_REGISTRY = new org.bukkit.craftbukkit.persistence.CraftPersistentDataTypeRegistry();
+ public final org.bukkit.craftbukkit.persistence.CraftPersistentDataContainer persistentDataContainer = new org.bukkit.craftbukkit.persistence.CraftPersistentDataContainer(PDC_TYPE_REGISTRY); + public final org.bukkit.craftbukkit.persistence.CraftPersistentDataContainer persistentDataContainer = new org.bukkit.craftbukkit.persistence.CraftPersistentDataContainer(PDC_TYPE_REGISTRY);
+ // Paper end + // Paper end
public Raid(int id, ServerLevel world, BlockPos pos) { public Raid(int id, ServerLevel level, BlockPos center) {
this.raidEvent = new ServerBossEvent(Raid.RAID_NAME_COMPONENT, BossEvent.BossBarColor.RED, BossEvent.BossBarOverlay.NOTCHED_10); this.id = id;
@@ -150,6 +155,11 @@ @@ -136,6 +_,11 @@
this.heroesOfTheVillage.add(NbtUtils.loadUUID(nbtbase)); this.heroesOfTheVillage.add(NbtUtils.loadUUID(tag));
} }
} }
+ // Paper start + // Paper start
+ if (nbt.contains(PDC_NBT_KEY, net.minecraft.nbt.Tag.TAG_COMPOUND)) { + if (compound.contains(PDC_NBT_KEY, net.minecraft.nbt.Tag.TAG_COMPOUND)) {
+ this.persistentDataContainer.putAll(nbt.getCompound(PDC_NBT_KEY)); + this.persistentDataContainer.putAll(compound.getCompound(PDC_NBT_KEY));
+ } + }
+ // Paper end + // Paper end
} }
@@ -177,6 +187,12 @@ public boolean isOver() {
@@ -162,6 +_,12 @@
return this.status == Raid.RaidStatus.LOSS; return this.status == Raid.RaidStatus.LOSS;
} }
@@ -37,15 +37,15 @@
public float getTotalHealth() { public float getTotalHealth() {
return this.totalHealth; return this.totalHealth;
} }
@@ -281,6 +297,7 @@ @@ -252,6 +_,7 @@
boolean flag = this.active;
this.active = this.level.hasChunkAt(this.center); this.active = this.level.hasChunkAt(this.center);
if (this.level.getDifficulty() == Difficulty.PEACEFUL) { if (this.level.getDifficulty() == Difficulty.PEACEFUL) {
+ org.bukkit.craftbukkit.event.CraftEventFactory.callRaidStopEvent(this, org.bukkit.event.raid.RaidStopEvent.Reason.PEACE); // CraftBukkit + org.bukkit.craftbukkit.event.CraftEventFactory.callRaidStopEvent(this, org.bukkit.event.raid.RaidStopEvent.Reason.PEACE); // CraftBukkit
this.stop(); this.stop();
return; return;
} }
@@ -300,13 +317,16 @@ @@ -271,13 +_,16 @@
if (!this.level.isVillage(this.center)) { if (!this.level.isVillage(this.center)) {
if (this.groupsSpawned > 0) { if (this.groupsSpawned > 0) {
this.status = Raid.RaidStatus.LOSS; this.status = Raid.RaidStatus.LOSS;
@@ -56,33 +56,33 @@
} }
} }
++this.ticksActive; this.ticksActive++;
if (this.ticksActive >= 48000L) { if (this.ticksActive >= 48000L) {
+ org.bukkit.craftbukkit.event.CraftEventFactory.callRaidStopEvent(this, org.bukkit.event.raid.RaidStopEvent.Reason.TIMEOUT); // CraftBukkit + org.bukkit.craftbukkit.event.CraftEventFactory.callRaidStopEvent(this, org.bukkit.event.raid.RaidStopEvent.Reason.TIMEOUT); // CraftBukkit
this.stop(); this.stop();
return; return;
} }
@@ -374,6 +394,7 @@ @@ -346,6 +_,7 @@
} }
if (j > 5) { if (i > 5) {
+ org.bukkit.craftbukkit.event.CraftEventFactory.callRaidStopEvent(this, org.bukkit.event.raid.RaidStopEvent.Reason.UNSPAWNABLE); // CraftBukkit + org.bukkit.craftbukkit.event.CraftEventFactory.callRaidStopEvent(this, org.bukkit.event.raid.RaidStopEvent.Reason.UNSPAWNABLE); // CraftBukkit
this.stop(); this.stop();
break; break;
} }
@@ -386,6 +407,7 @@ @@ -357,6 +_,7 @@
} else {
this.status = Raid.RaidStatus.VICTORY; this.status = Raid.RaidStatus.VICTORY;
Iterator iterator = this.heroesOfTheVillage.iterator();
+ List<org.bukkit.entity.Player> winners = new java.util.ArrayList<>(); // CraftBukkit + List<org.bukkit.entity.Player> winners = new java.util.ArrayList<>(); // CraftBukkit
while (iterator.hasNext()) { for (UUID uuid : this.heroesOfTheVillage) {
UUID uuid = (UUID) iterator.next();
Entity entity = this.level.getEntity(uuid); Entity entity = this.level.getEntity(uuid);
@@ -400,10 +422,12 @@ if (entity instanceof LivingEntity) {
@@ -368,10 +_,12 @@
entityplayer.awardStat(Stats.RAID_WIN); if (livingEntity instanceof ServerPlayer serverPlayer) {
CriteriaTriggers.RAID_WIN.trigger(entityplayer); serverPlayer.awardStat(Stats.RAID_WIN);
+ winners.add(entityplayer.getBukkitEntity()); // CraftBukkit CriteriaTriggers.RAID_WIN.trigger(serverPlayer);
+ winners.add(serverPlayer.getBukkitEntity()); // CraftBukkit
} }
} }
} }
@@ -91,84 +91,84 @@
} }
} }
@@ -411,6 +435,7 @@ @@ -379,6 +_,7 @@
} else if (this.isOver()) { } else if (this.isOver()) {
++this.celebrationTicks; this.celebrationTicks++;
if (this.celebrationTicks >= 600) { if (this.celebrationTicks >= 600) {
+ org.bukkit.craftbukkit.event.CraftEventFactory.callRaidStopEvent(this, org.bukkit.event.raid.RaidStopEvent.Reason.FINISHED); // CraftBukkit + org.bukkit.craftbukkit.event.CraftEventFactory.callRaidStopEvent(this, org.bukkit.event.raid.RaidStopEvent.Reason.FINISHED); // CraftBukkit
this.stop(); this.stop();
return; return;
} }
@@ -544,6 +569,10 @@ @@ -491,6 +_,10 @@
int j = araid_wave.length; DifficultyInstance currentDifficultyAt = this.level.getCurrentDifficultyAt(pos);
int k = 0; boolean shouldSpawnBonusGroup = this.shouldSpawnBonusGroup();
+ // CraftBukkit start + // CraftBukkit start
+ Raider leader = null; + Raider leader = null;
+ List<Raider> raiders = new java.util.ArrayList<>(); + List<Raider> raiders = new java.util.ArrayList<>();
+ // CraftBukkit end + // CraftBukkit end
while (k < j) { for (Raid.RaiderType raiderType : Raid.RaiderType.VALUES) {
Raid.RaiderType raid_wave = araid_wave[k]; int i1 = this.getDefaultNumSpawns(raiderType, i, shouldSpawnBonusGroup)
int l = this.getDefaultNumSpawns(raid_wave, i, flag1) + this.getPotentialBonusSpawns(raid_wave, this.random, i, difficultydamagescaler, flag1); + this.getPotentialBonusSpawns(raiderType, this.random, i, currentDifficultyAt, shouldSpawnBonusGroup);
@@ -559,9 +588,11 @@ @@ -506,9 +_,11 @@
entityraider.setPatrolLeader(true); raider.setPatrolLeader(true);
this.setLeader(i, entityraider); this.setLeader(i, raider);
flag = true; flag = true;
+ leader = entityraider; // CraftBukkit + leader = raider; // CraftBukkit
} }
this.joinRaid(i, entityraider, pos, false); this.joinRaid(i, raider, pos, false);
+ raiders.add(entityraider); // CraftBukkit + raiders.add(raider); // CraftBukkit
if (raid_wave.entityType == EntityType.RAVAGER) { if (raiderType.entityType == EntityType.RAVAGER) {
Raider entityraider1 = null; Raider raider1 = null;
if (i == this.getNumGroups(Difficulty.NORMAL)) {
@@ -580,6 +611,7 @@ @@ -526,6 +_,7 @@
this.joinRaid(i, entityraider1, pos, false); this.joinRaid(i, raider1, pos, false);
entityraider1.moveTo(pos, 0.0F, 0.0F); raider1.moveTo(pos, 0.0F, 0.0F);
entityraider1.startRiding(entityraider); raider1.startRiding(raider);
+ raiders.add(entityraider); // CraftBukkit + raiders.add(raider); // CraftBukkit
} }
} }
}
@@ -597,6 +629,7 @@ @@ -535,6 +_,7 @@
++this.groupsSpawned; this.groupsSpawned++;
this.updateBossbar(); this.updateBossbar();
this.setDirty(); this.setDirty();
+ org.bukkit.craftbukkit.event.CraftEventFactory.callRaidSpawnWaveEvent(this, leader, raiders); // CraftBukkit + org.bukkit.craftbukkit.event.CraftEventFactory.callRaidSpawnWaveEvent(this, leader, raiders); // CraftBukkit
} }
public void joinRaid(int wave, Raider raider, @Nullable BlockPos pos, boolean existing) { public void joinRaid(int wave, Raider raider, @Nullable BlockPos pos, boolean isRecruited) {
@@ -612,7 +645,7 @@ @@ -549,7 +_,7 @@
raider.finalizeSpawn(this.level, this.level.getCurrentDifficultyAt(pos), EntitySpawnReason.EVENT, (SpawnGroupData) null); raider.finalizeSpawn(this.level, this.level.getCurrentDifficultyAt(pos), EntitySpawnReason.EVENT, null);
raider.applyRaidBuffs(this.level, wave, false); raider.applyRaidBuffs(this.level, wave, false);
raider.setOnGround(true); raider.setOnGround(true);
- this.level.addFreshEntityWithPassengers(raider); - this.level.addFreshEntityWithPassengers(raider);
+ this.level.addFreshEntityWithPassengers(raider, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.RAID); // CraftBukkit + this.level.addFreshEntityWithPassengers(raider, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.RAID); // CraftBukkit
} }
} }
}
@@ -839,6 +872,11 @@ @@ -770,6 +_,11 @@
} }
nbt.put("HeroesOfTheVillage", nbttaglist); compound.put("HeroesOfTheVillage", listTag);
+ // Paper start + // Paper start
+ if (!this.persistentDataContainer.isEmpty()) { + if (!this.persistentDataContainer.isEmpty()) {
+ nbt.put(PDC_NBT_KEY, this.persistentDataContainer.toTagCompound()); + compound.put(PDC_NBT_KEY, this.persistentDataContainer.toTagCompound());
+ } + }
+ // Paper end + // Paper end
return nbt; return compound;
} }
@@ -865,6 +903,12 @@ @@ -802,6 +_,12 @@
this.heroesOfTheVillage.add(entity.getUUID()); public void addHeroOfTheVillage(Entity player) {
this.heroesOfTheVillage.add(player.getUUID());
} }
+
+ // CraftBukkit start - a method to get all raiders + // CraftBukkit start - a method to get all raiders
+ public java.util.Collection<Raider> getRaiders() { + public java.util.Collection<Raider> getRaiders() {
+ return this.groupRaiderMap.values().stream().flatMap(Set::stream).collect(java.util.stream.Collectors.toSet()); + return this.groupRaiderMap.values().stream().flatMap(Set::stream).collect(java.util.stream.Collectors.toSet());
+ } + }
+ // CraftBukkit end + // CraftBukkit end
+
private static enum RaidStatus {
ONGOING, VICTORY, LOSS, STOPPED; static enum RaidStatus {
ONGOING,

View File

@@ -0,0 +1,54 @@
--- a/net/minecraft/world/entity/raid/Raider.java
+++ b/net/minecraft/world/entity/raid/Raider.java
@@ -212,17 +_,24 @@
if (this.hasActiveRaid()
&& !flag
&& ItemStack.matches(item, Raid.getOminousBannerInstance(this.registryAccess().lookupOrThrow(Registries.BANNER_PATTERN)))) {
+ // Paper start - EntityPickupItemEvent fixes
+ if (org.bukkit.craftbukkit.event.CraftEventFactory.callEntityPickupItemEvent(this, entity, 0, false).isCancelled()) {
+ return;
+ }
+ // Paper end - EntityPickupItemEvent fixes
EquipmentSlot equipmentSlot = EquipmentSlot.HEAD;
ItemStack itemBySlot = this.getItemBySlot(equipmentSlot);
double d = this.getEquipmentDropChance(equipmentSlot);
if (!itemBySlot.isEmpty() && Math.max(this.random.nextFloat() - 0.1F, 0.0F) < d) {
+ this.forceDrops = true; // Paper - Add missing forceDrop toggles
this.spawnAtLocation(level, itemBySlot);
+ this.forceDrops = false; // Paper - Add missing forceDrop toggles
}
this.onItemPickup(entity);
this.setItemSlot(equipmentSlot, item);
this.take(entity, item.getCount());
- entity.discard();
+ entity.discard(org.bukkit.event.entity.EntityRemoveEvent.Cause.PICKUP); // CraftBukkit - add Bukkit remove cause
this.getCurrentRaid().setLeader(this.getWave(), this);
this.setPatrolLeader(true);
} else {
@@ -296,7 +_,7 @@
for (Raider raider : getServerLevel(this.mob)
.getNearbyEntities(Raider.class, this.shoutTargeting, this.mob, this.mob.getBoundingBox().inflate(8.0, 8.0, 8.0))) {
- raider.setTarget(this.mob.getTarget());
+ raider.setTarget(this.mob.getTarget(), org.bukkit.event.entity.EntityTargetEvent.TargetReason.FOLLOW_LEADER, true); // CraftBukkit
}
}
@@ -307,7 +_,7 @@
if (target != null) {
for (Raider raider : getServerLevel(this.mob)
.getNearbyEntities(Raider.class, this.shoutTargeting, this.mob, this.mob.getBoundingBox().inflate(8.0, 8.0, 8.0))) {
- raider.setTarget(target);
+ raider.setTarget(target, org.bukkit.event.entity.EntityTargetEvent.TargetReason.FOLLOW_LEADER, true); // CraftBukkit
raider.setAggressive(true);
}
@@ -392,6 +_,7 @@
}
private boolean cannotPickUpBanner() {
+ if (!getServerLevel(this.mob).getGameRules().getBoolean(net.minecraft.world.level.GameRules.RULE_MOBGRIEFING) || !this.mob.canPickUpLoot()) return false; // Paper - respect game and entity rules for picking up items
if (!this.mob.hasActiveRaid()) {
return true;
} else if (this.mob.getCurrentRaid().isOver()) {

View File

@@ -1,16 +1,17 @@
--- a/net/minecraft/world/entity/raid/Raids.java --- a/net/minecraft/world/entity/raid/Raids.java
+++ b/net/minecraft/world/entity/raid/Raids.java +++ b/net/minecraft/world/entity/raid/Raids.java
@@ -115,11 +115,23 @@ @@ -112,11 +_,23 @@
}
Raid raid = this.getOrCreateRaid(player.serverLevel(), blockposition2);
Raid raid = this.getOrCreateRaid(player.serverLevel(), blockPos);
+ /* CraftBukkit - moved down + /* CraftBukkit - moved down
if (!raid.isStarted() && !this.raidMap.containsKey(raid.getId())) { if (!raid.isStarted() && !this.raidMap.containsKey(raid.getId())) {
this.raidMap.put(raid.getId(), raid); this.raidMap.put(raid.getId(), raid);
} }
+ */ -
- if (!raid.isStarted() || raid.getRaidOmenLevel() < raid.getMaxRaidOmenLevel()) { - if (!raid.isStarted() || raid.getRaidOmenLevel() < raid.getMaxRaidOmenLevel()) {
+ */
+
+ if (!raid.isStarted() || (raid.isInProgress() && raid.getRaidOmenLevel() < raid.getMaxRaidOmenLevel())) { // CraftBukkit - fixed a bug with raid: players could add up Bad Omen level even when the raid had finished + if (!raid.isStarted() || (raid.isInProgress() && raid.getRaidOmenLevel() < raid.getMaxRaidOmenLevel())) { // CraftBukkit - fixed a bug with raid: players could add up Bad Omen level even when the raid had finished
+ // CraftBukkit start + // CraftBukkit start
+ if (!org.bukkit.craftbukkit.event.CraftEventFactory.callRaidTriggerEvent(raid, player)) { + if (!org.bukkit.craftbukkit.event.CraftEventFactory.callRaidTriggerEvent(raid, player)) {

View File

@@ -1,83 +0,0 @@
--- a/net/minecraft/world/entity/raid/Raider.java
+++ b/net/minecraft/world/entity/raid/Raider.java
@@ -40,6 +40,9 @@
import net.minecraft.world.level.ServerLevelAccessor;
import net.minecraft.world.level.pathfinder.Path;
import net.minecraft.world.phys.Vec3;
+// CraftBukkit start
+import org.bukkit.event.entity.EntityRemoveEvent;
+// CraftBukkit end
public abstract class Raider extends PatrollingMonster {
@@ -225,18 +228,25 @@
boolean flag = this.hasActiveRaid() && this.getCurrentRaid().getLeader(this.getWave()) != null;
if (this.hasActiveRaid() && !flag && ItemStack.matches(itemstack, Raid.getOminousBannerInstance(this.registryAccess().lookupOrThrow(Registries.BANNER_PATTERN)))) {
+ // Paper start - EntityPickupItemEvent fixes
+ if (org.bukkit.craftbukkit.event.CraftEventFactory.callEntityPickupItemEvent(this, itemEntity, 0, false).isCancelled()) {
+ return;
+ }
+ // Paper end - EntityPickupItemEvent fixes
EquipmentSlot enumitemslot = EquipmentSlot.HEAD;
ItemStack itemstack1 = this.getItemBySlot(enumitemslot);
double d0 = (double) this.getEquipmentDropChance(enumitemslot);
if (!itemstack1.isEmpty() && (double) Math.max(this.random.nextFloat() - 0.1F, 0.0F) < d0) {
+ this.forceDrops = true; // Paper - Add missing forceDrop toggles
this.spawnAtLocation(world, itemstack1);
+ this.forceDrops = false; // Paper - Add missing forceDrop toggles
}
this.onItemPickup(itemEntity);
this.setItemSlot(enumitemslot, itemstack);
this.take(itemEntity, itemstack.getCount());
- itemEntity.discard();
+ itemEntity.discard(EntityRemoveEvent.Cause.PICKUP); // CraftBukkit - add Bukkit remove cause
this.getCurrentRaid().setLeader(this.getWave(), this);
this.setPatrolLeader(true);
} else {
@@ -290,7 +300,7 @@
@Nullable
private ItemEntity pursuedBannerItemEntity;
- public ObtainRaidLeaderBannerGoal(final Raider entityraider) {
+ public ObtainRaidLeaderBannerGoal(final T entityraider) { // CraftBukkit - decompile error
this.mob = entityraider;
this.setFlags(EnumSet.of(Goal.Flag.MOVE));
}
@@ -335,6 +345,7 @@
}
private boolean cannotPickUpBanner() {
+ if (!getServerLevel(this.mob).getGameRules().getBoolean(net.minecraft.world.level.GameRules.RULE_MOBGRIEFING) || !this.mob.canPickUpLoot()) return false; // Paper - respect game and entity rules for picking up items
if (!this.mob.hasActiveRaid()) {
return true;
} else if (this.mob.getCurrentRaid().isOver()) {
@@ -518,7 +529,7 @@
}
}
- protected static class HoldGroundAttackGoal extends Goal {
+ public static class HoldGroundAttackGoal extends Goal {
private final Raider mob;
private final float hostileRadiusSqr;
@@ -547,7 +558,7 @@
while (iterator.hasNext()) {
Raider entityraider = (Raider) iterator.next();
- entityraider.setTarget(this.mob.getTarget());
+ entityraider.setTarget(this.mob.getTarget(), org.bukkit.event.entity.EntityTargetEvent.TargetReason.FOLLOW_LEADER, true); // CraftBukkit
}
}
@@ -564,7 +575,7 @@
while (iterator.hasNext()) {
Raider entityraider = (Raider) iterator.next();
- entityraider.setTarget(entityliving);
+ entityraider.setTarget(this.mob.getTarget(), org.bukkit.event.entity.EntityTargetEvent.TargetReason.FOLLOW_LEADER, true); // CraftBukkit
entityraider.setAggressive(true);
}