mirror of
https://github.com/PaperMC/Paper.git
synced 2024-11-22 02:25:28 +01:00
8c5b837e05
Firstly, the old methods all routed to the CompletableFuture method. However, the CF method could not guarantee that if the caller was off-main that the future would be "completed" on-main. Since the callback methods used the CF one, this meant that the callback methods did not guarantee that the callbacks were to be called on the main thread. Now, all methods route to getChunkAtAsync(x, z, gen, urgent, cb) so that the methods with the callback are guaranteed to invoke the callback on the main thread. The CF behavior remains unchanged; it may still appear to complete on main if invoked off-main. Secondly, remove the scheduleOnMain invocation in the async chunk completion. This unnecessarily delays the callback by 1 tick. Thirdly, add getChunksAtAsync(minX, minZ, maxX, maxZ, ...) which will load chunks within an area. This method is provided as a helper as keeping all chunks loaded within an area can be complicated to implement for plugins (due to the lacking ticket API), and is already implemented internally anyways. Fourthly, remove the ticket addition that occured with getChunkAt and getChunkAtAsync. The ticket addition may delay the unloading of the chunk unnecessarily. It also fixes a very rare timing bug where the future/callback would be completed after the chunk unloads.
92 lines
4.3 KiB
Diff
92 lines
4.3 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: Jake Potrebic <jake.m.potrebic@gmail.com>
|
|
Date: Sun, 18 Dec 2022 13:40:05 -0800
|
|
Subject: [PATCH] More DragonBattle API
|
|
|
|
== AT ==
|
|
public net.minecraft.world.level.dimension.end.EndDragonFight GATEWAY_COUNT
|
|
public net.minecraft.world.level.dimension.end.EndDragonFight gateways
|
|
public net.minecraft.world.level.dimension.end.EndDragonFight respawnCrystals
|
|
public net.minecraft.world.level.dimension.end.EndDragonFight spawnNewGateway(Lnet/minecraft/core/BlockPos;)V
|
|
|
|
diff --git a/src/main/java/net/minecraft/world/level/dimension/end/EndDragonFight.java b/src/main/java/net/minecraft/world/level/dimension/end/EndDragonFight.java
|
|
index 39b1d6ee10d4a10ab4fb339621ca80f27d383324..8ec6b33126096fb9e1de5f41290097e004d7a455 100644
|
|
--- a/src/main/java/net/minecraft/world/level/dimension/end/EndDragonFight.java
|
|
+++ b/src/main/java/net/minecraft/world/level/dimension/end/EndDragonFight.java
|
|
@@ -442,6 +442,24 @@ public class EndDragonFight {
|
|
this.gateways.clear();
|
|
}
|
|
|
|
+ // Paper start - More DragonBattle API
|
|
+ public boolean spawnNewGatewayIfPossible() {
|
|
+ if (!this.gateways.isEmpty()) {
|
|
+ this.spawnNewGateway();
|
|
+ return true;
|
|
+ }
|
|
+ return false;
|
|
+ }
|
|
+
|
|
+ public List<EndCrystal> getSpikeCrystals() {
|
|
+ final List<EndCrystal> endCrystals = new java.util.ArrayList<>();
|
|
+ for (final SpikeFeature.EndSpike spike : SpikeFeature.getSpikesForLevel(this.level)) {
|
|
+ endCrystals.addAll(this.level.getEntitiesOfClass(EndCrystal.class, spike.getTopBoundingBox()));
|
|
+ }
|
|
+ return endCrystals;
|
|
+ }
|
|
+ // Paper end - More DragonBattle API
|
|
+
|
|
private void spawnNewGateway() {
|
|
if (!this.gateways.isEmpty()) {
|
|
int i = (Integer) this.gateways.remove(this.gateways.size() - 1);
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/boss/CraftDragonBattle.java b/src/main/java/org/bukkit/craftbukkit/boss/CraftDragonBattle.java
|
|
index dc7fdc120f4317ee1b7935ef226eddb0406aee6e..6bfabb38b51115beb2a65a165f235347838b6006 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/boss/CraftDragonBattle.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/boss/CraftDragonBattle.java
|
|
@@ -137,4 +137,46 @@ public class CraftDragonBattle implements DragonBattle {
|
|
private DragonRespawnAnimation toNMSRespawnPhase(RespawnPhase phase) {
|
|
return (phase != RespawnPhase.NONE) ? DragonRespawnAnimation.values()[phase.ordinal()] : null;
|
|
}
|
|
+ // Paper start - More DragonBattle API
|
|
+ @Override
|
|
+ public int getGatewayCount() {
|
|
+ return EndDragonFight.GATEWAY_COUNT - this.handle.gateways.size();
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public boolean spawnNewGateway() {
|
|
+ return this.handle.spawnNewGatewayIfPossible();
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public void spawnNewGateway(final io.papermc.paper.math.Position position) {
|
|
+ this.handle.spawnNewGateway(io.papermc.paper.util.MCUtil.toBlockPos(position));
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public java.util.List<org.bukkit.entity.EnderCrystal> getRespawnCrystals() {
|
|
+ if (this.handle.respawnCrystals == null) {
|
|
+ return java.util.Collections.emptyList();
|
|
+ }
|
|
+
|
|
+ final java.util.List<org.bukkit.entity.EnderCrystal> enderCrystals = new java.util.ArrayList<>();
|
|
+ for (final net.minecraft.world.entity.boss.enderdragon.EndCrystal endCrystal : this.handle.respawnCrystals) {
|
|
+ if (!endCrystal.isRemoved() && endCrystal.isAlive() && endCrystal.valid) {
|
|
+ enderCrystals.add(((org.bukkit.entity.EnderCrystal) endCrystal.getBukkitEntity()));
|
|
+ }
|
|
+ }
|
|
+ return java.util.Collections.unmodifiableList(enderCrystals);
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public java.util.List<org.bukkit.entity.EnderCrystal> getHealingCrystals() {
|
|
+ final java.util.List<org.bukkit.entity.EnderCrystal> enderCrystals = new java.util.ArrayList<>();
|
|
+ for (final net.minecraft.world.entity.boss.enderdragon.EndCrystal endCrystal : this.handle.getSpikeCrystals()) {
|
|
+ if (!endCrystal.isRemoved() && endCrystal.isAlive() && endCrystal.valid) {
|
|
+ enderCrystals.add(((org.bukkit.entity.EnderCrystal) endCrystal.getBukkitEntity()));
|
|
+ }
|
|
+ }
|
|
+ return java.util.Collections.unmodifiableList(enderCrystals);
|
|
+ }
|
|
+ // Paper end - More DragonBattle API
|
|
}
|