Skip to content

Commit 4f1a7ec

Browse files
Fix #10323: Inefficient Ender Dragon respawn sequence
This issue likely arose from the method findExitPortal(), which has been optimized. This optimization will ensure better server performance during the respawn sequence and smoother gameplay. Signed-off-by: Afonso Jacinto <[email protected]>
1 parent 1acf3b3 commit 4f1a7ec

File tree

1 file changed

+83
-0
lines changed

1 file changed

+83
-0
lines changed

paper-server/patches/sources/net/minecraft/world/level/dimension/end/EndDragonFight.java.patch

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
--- a/net/minecraft/world/level/dimension/end/EndDragonFight.java
22
+++ b/net/minecraft/world/level/dimension/end/EndDragonFight.java
3+
@@ -48,6 +_,7 @@
4+
import net.minecraft.world.level.block.state.pattern.BlockPattern;
5+
import net.minecraft.world.level.block.state.pattern.BlockPatternBuilder;
6+
import net.minecraft.world.level.block.state.predicate.BlockPredicate;
7+
+import net.minecraft.world.level.block.state.BlockState;
8+
import net.minecraft.world.level.chunk.ChunkAccess;
9+
import net.minecraft.world.level.chunk.LevelChunk;
10+
import net.minecraft.world.level.chunk.status.ChunkStatus;
311
@@ -69,8 +_,9 @@
412
private static final int GATEWAY_DISTANCE = 96;
513
public static final int DRAGON_SPAWN_Y = 128;
@@ -37,6 +45,81 @@
3745
this.dragonUUID = null;
3846
}
3947
}
48+
@@ -267,21 +_,45 @@
49+
return false;
50+
}
51+
52+
+ // Paper start - Fix inefficient Ender Dragon respawn sequence
53+
@Nullable
54+
public BlockPattern.BlockPatternMatch findExitPortal() {
55+
+
56+
+ BlockPos location = EndPodiumFeature.getLocation(this.origin);
57+
+ int i1 = this.level.getHeightmapPos(Heightmap.Types.MOTION_BLOCKING, location).getY();
58+
+ BlockPos current_position;
59+
+ BlockState state;
60+
+
61+
+ for (int i2 = i1; i2 >= this.level.getMinY(); i2--) {
62+
+
63+
+ current_position = new BlockPos(location.getX(), i2, location.getZ());
64+
+ state = level.getBlockState(current_position);
65+
+
66+
+ if (state.getBlock() == Blocks.BEDROCK) {
67+
+ BlockPattern.BlockPatternMatch blockPatternMatch1 = this.exitPortalPattern.find(this.level, current_position);
68+
+ if (blockPatternMatch1 != null) {
69+
+ if (this.portalLocation == null) {
70+
+ this.portalLocation = blockPatternMatch1.getBlock(3, 3, 3).getPos();
71+
+ }
72+
+
73+
+ return blockPatternMatch1;
74+
+ }
75+
+ }
76+
+ }
77+
+
78+
ChunkPos chunkPos = new ChunkPos(this.origin);
79+
80+
for (int i = -8 + chunkPos.x; i <= 8 + chunkPos.x; i++) {
81+
- for (int i1 = -8 + chunkPos.z; i1 <= 8 + chunkPos.z; i1++) {
82+
+ for (i1 = -8 + chunkPos.z; i1 <= 8 + chunkPos.z; i1++) {
83+
LevelChunk chunk = this.level.getChunk(i, i1);
84+
85+
for (BlockEntity blockEntity : chunk.getBlockEntities().values()) {
86+
if (blockEntity instanceof TheEndPortalBlockEntity) {
87+
BlockPattern.BlockPatternMatch blockPatternMatch = this.exitPortalPattern.find(this.level, blockEntity.getBlockPos());
88+
if (blockPatternMatch != null) {
89+
- BlockPos pos = blockPatternMatch.getBlock(3, 3, 3).getPos();
90+
+
91+
if (this.portalLocation == null) {
92+
- this.portalLocation = pos;
93+
+ this.portalLocation = blockPatternMatch.getBlock(3, 3, 3).getPos();
94+
}
95+
96+
return blockPatternMatch;
97+
@@ -290,23 +_,10 @@
98+
}
99+
}
100+
}
101+
-
102+
- BlockPos location = EndPodiumFeature.getLocation(this.origin);
103+
- int i1 = this.level.getHeightmapPos(Heightmap.Types.MOTION_BLOCKING, location).getY();
104+
-
105+
- for (int i2 = i1; i2 >= this.level.getMinY(); i2--) {
106+
- BlockPattern.BlockPatternMatch blockPatternMatch1 = this.exitPortalPattern.find(this.level, new BlockPos(location.getX(), i2, location.getZ()));
107+
- if (blockPatternMatch1 != null) {
108+
- if (this.portalLocation == null) {
109+
- this.portalLocation = blockPatternMatch1.getBlock(3, 3, 3).getPos();
110+
- }
111+
-
112+
- return blockPatternMatch1;
113+
- }
114+
- }
115+
-
116+
+
117+
return null;
118+
}
119+
+ // Paper end - Fix inefficient Ender Dragon respawn sequence
120+
121+
private boolean isArenaLoaded() {
122+
if (this.skipArenaLoadedCheck) {
40123
@@ -365,12 +_,22 @@
41124
this.dragonEvent.setVisible(false);
42125
this.spawnExitPortal(true);

0 commit comments

Comments
 (0)