More Raid API

== AT ==
public net.minecraft.world.entity.raid.Raid raidEvent
This commit is contained in:
Jake Potrebic 2022-03-04 09:46:33 -08:00
parent e57ad97c91
commit e06fe76018
3 changed files with 91 additions and 18 deletions

View file

@ -1,20 +1,43 @@
--- 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
@@ -175,7 +175,13 @@ @@ -107,6 +107,11 @@
private Raid.RaidStatus status;
private int celebrationTicks;
private Optional<BlockPos> waveSpawnPos;
+ // Paper start
+ 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();
+ public final org.bukkit.craftbukkit.persistence.CraftPersistentDataContainer persistentDataContainer = new org.bukkit.craftbukkit.persistence.CraftPersistentDataContainer(PDC_TYPE_REGISTRY);
+ // Paper end
public boolean isLoss() { public Raid(int id, ServerLevel world, BlockPos pos) {
this.raidEvent = new ServerBossEvent(Raid.RAID_NAME_COMPONENT, BossEvent.BossBarColor.RED, BossEvent.BossBarOverlay.NOTCHED_10);
@@ -150,6 +155,11 @@
this.heroesOfTheVillage.add(NbtUtils.loadUUID(nbtbase));
}
}
+ // Paper start
+ if (nbt.contains(PDC_NBT_KEY, net.minecraft.nbt.Tag.TAG_COMPOUND)) {
+ this.persistentDataContainer.putAll(nbt.getCompound(PDC_NBT_KEY));
+ }
+ // Paper end
}
@@ -177,6 +187,12 @@
return this.status == Raid.RaidStatus.LOSS; return this.status == Raid.RaidStatus.LOSS;
+ } }
+
+ // CraftBukkit start + // CraftBukkit start
+ public boolean isInProgress() { + public boolean isInProgress() {
+ return this.status == RaidStatus.ONGOING; + return this.status == RaidStatus.ONGOING;
} + }
+ // CraftBukkit end + // CraftBukkit end
+
public float getTotalHealth() { public float getTotalHealth() {
return this.totalHealth; return this.totalHealth;
@@ -281,6 +287,7 @@ }
@@ -281,6 +297,7 @@
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) {
@ -22,7 +45,7 @@
this.stop(); this.stop();
return; return;
} }
@@ -300,13 +307,16 @@ @@ -300,13 +317,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;
@ -39,7 +62,7 @@
this.stop(); this.stop();
return; return;
} }
@@ -374,6 +384,7 @@ @@ -374,6 +394,7 @@
} }
if (j > 5) { if (j > 5) {
@ -47,7 +70,7 @@
this.stop(); this.stop();
break; break;
} }
@@ -386,6 +397,7 @@ @@ -386,6 +407,7 @@
this.status = Raid.RaidStatus.VICTORY; this.status = Raid.RaidStatus.VICTORY;
Iterator iterator = this.heroesOfTheVillage.iterator(); Iterator iterator = this.heroesOfTheVillage.iterator();
@ -55,7 +78,7 @@
while (iterator.hasNext()) { while (iterator.hasNext()) {
UUID uuid = (UUID) iterator.next(); UUID uuid = (UUID) iterator.next();
Entity entity = this.level.getEntity(uuid); Entity entity = this.level.getEntity(uuid);
@@ -400,10 +412,12 @@ @@ -400,10 +422,12 @@
entityplayer.awardStat(Stats.RAID_WIN); entityplayer.awardStat(Stats.RAID_WIN);
CriteriaTriggers.RAID_WIN.trigger(entityplayer); CriteriaTriggers.RAID_WIN.trigger(entityplayer);
@ -68,7 +91,7 @@
} }
} }
@@ -411,6 +425,7 @@ @@ -411,6 +435,7 @@
} else if (this.isOver()) { } else if (this.isOver()) {
++this.celebrationTicks; ++this.celebrationTicks;
if (this.celebrationTicks >= 600) { if (this.celebrationTicks >= 600) {
@ -76,7 +99,7 @@
this.stop(); this.stop();
return; return;
} }
@@ -544,6 +559,10 @@ @@ -544,6 +569,10 @@
int j = araid_wave.length; int j = araid_wave.length;
int k = 0; int k = 0;
@ -87,7 +110,7 @@
while (k < j) { while (k < j) {
Raid.RaiderType raid_wave = araid_wave[k]; Raid.RaiderType raid_wave = araid_wave[k];
int l = this.getDefaultNumSpawns(raid_wave, i, flag1) + this.getPotentialBonusSpawns(raid_wave, this.random, i, difficultydamagescaler, flag1); int l = this.getDefaultNumSpawns(raid_wave, i, flag1) + this.getPotentialBonusSpawns(raid_wave, this.random, i, difficultydamagescaler, flag1);
@@ -559,9 +578,11 @@ @@ -559,9 +588,11 @@
entityraider.setPatrolLeader(true); entityraider.setPatrolLeader(true);
this.setLeader(i, entityraider); this.setLeader(i, entityraider);
flag = true; flag = true;
@ -99,7 +122,7 @@
if (raid_wave.entityType == EntityType.RAVAGER) { if (raid_wave.entityType == EntityType.RAVAGER) {
Raider entityraider1 = null; Raider entityraider1 = null;
@@ -580,6 +601,7 @@ @@ -580,6 +611,7 @@
this.joinRaid(i, entityraider1, pos, false); this.joinRaid(i, entityraider1, pos, false);
entityraider1.moveTo(pos, 0.0F, 0.0F); entityraider1.moveTo(pos, 0.0F, 0.0F);
entityraider1.startRiding(entityraider); entityraider1.startRiding(entityraider);
@ -107,7 +130,7 @@
} }
} }
@@ -597,6 +619,7 @@ @@ -597,6 +629,7 @@
++this.groupsSpawned; ++this.groupsSpawned;
this.updateBossbar(); this.updateBossbar();
this.setDirty(); this.setDirty();
@ -115,7 +138,7 @@
} }
public void joinRaid(int wave, Raider raider, @Nullable BlockPos pos, boolean existing) { public void joinRaid(int wave, Raider raider, @Nullable BlockPos pos, boolean existing) {
@@ -612,7 +635,7 @@ @@ -612,7 +645,7 @@
raider.finalizeSpawn(this.level, this.level.getCurrentDifficultyAt(pos), EntitySpawnReason.EVENT, (SpawnGroupData) null); raider.finalizeSpawn(this.level, this.level.getCurrentDifficultyAt(pos), EntitySpawnReason.EVENT, (SpawnGroupData) null);
raider.applyRaidBuffs(this.level, wave, false); raider.applyRaidBuffs(this.level, wave, false);
raider.setOnGround(true); raider.setOnGround(true);
@ -124,7 +147,19 @@
} }
} }
@@ -865,6 +888,12 @@ @@ -839,6 +872,11 @@
}
nbt.put("HeroesOfTheVillage", nbttaglist);
+ // Paper start
+ if (!this.persistentDataContainer.isEmpty()) {
+ nbt.put(PDC_NBT_KEY, this.persistentDataContainer.toTagCompound());
+ }
+ // Paper end
return nbt;
}
@@ -865,6 +903,12 @@
this.heroesOfTheVillage.add(entity.getUUID()); this.heroesOfTheVillage.add(entity.getUUID());
} }

View file

@ -103,4 +103,34 @@ public final class CraftRaid implements Raid {
public net.minecraft.world.entity.raid.Raid getHandle() { public net.minecraft.world.entity.raid.Raid getHandle() {
return this.handle; return this.handle;
} }
// Paper start - more Raid API
@Override
public int getId() {
return this.handle.getId();
}
@Override
public org.bukkit.boss.BossBar getBossBar() {
return new org.bukkit.craftbukkit.boss.CraftBossBar(this.handle.raidEvent);
}
@Override
public org.bukkit.persistence.PersistentDataContainer getPersistentDataContainer() {
return this.handle.persistentDataContainer;
}
@Override
public boolean equals(final Object o) {
if (this == o) return true;
if (o == null || this.getClass() != o.getClass()) return false;
final org.bukkit.craftbukkit.CraftRaid craftRaid = (org.bukkit.craftbukkit.CraftRaid) o;
return this.handle.equals(craftRaid.handle);
}
@Override
public int hashCode() {
return this.handle.hashCode();
}
// Paper end - more Raid API
} }

View file

@ -2311,6 +2311,14 @@ public class CraftWorld extends CraftRegionAccessor implements World {
return (raid == null) ? null : new CraftRaid(raid); return (raid == null) ? null : new CraftRaid(raid);
} }
// Paper start - more Raid API
@Override
public @Nullable Raid getRaid(final int id) {
final net.minecraft.world.entity.raid.@Nullable Raid nmsRaid = this.world.getRaids().raidMap.get(id);
return nmsRaid != null ? new CraftRaid(nmsRaid) : null;
}
// Paper end - more Raid API
@Override @Override
public List<Raid> getRaids() { public List<Raid> getRaids() {
Raids persistentRaid = this.world.getRaids(); Raids persistentRaid = this.world.getRaids();