Skip to content

Commit ce24ebc

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 b9b3cd6 commit ce24ebc

File tree

1 file changed

+137
-0
lines changed

1 file changed

+137
-0
lines changed

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

Lines changed: 137 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,135 @@
3745
this.dragonUUID = null;
3846
}
3947
}
48+
@@ -267,46 +_,125 @@
49+
return false;
50+
}
51+
52+
+
53+
@Nullable
54+
+
55+
public BlockPattern.BlockPatternMatch findExitPortal() {
56+
+
57+
ChunkPos chunkPos = new ChunkPos(this.origin);
58+
59+
+
60+
+
61+
+ // Paper start
62+
+
63+
+ BlockPattern.BlockPatternMatch originSearch = findExitPortalExitAroundOrigin();
64+
+
65+
+ if (originSearch != null) {
66+
+
67+
+ return originSearch;
68+
+
69+
+ }
70+
+
71+
+ // Paper end
72+
+
73+
for (int i = -8 + chunkPos.x; i <= 8 + chunkPos.x; i++) {
74+
+
75+
for (int i1 = -8 + chunkPos.z; i1 <= 8 + chunkPos.z; i1++) {
76+
+
77+
LevelChunk chunk = this.level.getChunk(i, i1);
78+
79+
+
80+
+
81+
for (BlockEntity blockEntity : chunk.getBlockEntities().values()) {
82+
+
83+
if (blockEntity instanceof TheEndPortalBlockEntity) {
84+
+
85+
BlockPattern.BlockPatternMatch blockPatternMatch = this.exitPortalPattern.find(this.level, blockEntity.getBlockPos());
86+
+
87+
if (blockPatternMatch != null) {
88+
- BlockPos pos = blockPatternMatch.getBlock(3, 3, 3).getPos();
89+
+
90+
+ // BlockPos pos = blockPatternMatch.getBlock(3, 3, 3).getPos(); // Paper - move down
91+
+
92+
if (this.portalLocation == null) {
93+
- this.portalLocation = pos;
94+
+
95+
+ this.portalLocation = blockPatternMatch.getBlock(3, 3, 3).getPos(); // Paper
96+
+
97+
}
98+
+
99+
+
100+
101+
return blockPatternMatch;
102+
+
103+
}
104+
+
105+
}
106+
+
107+
}
108+
+
109+
}
110+
+
111+
}
112+
+
113+
+
114+
+
115+
+ // Paper start - exit portal optimization look around the origin first
116+
+
117+
+ return null;
118+
+
119+
+ }
120+
+
121+
+ public BlockPattern.@org.checkerframework.checker.nullness.qual.Nullable BlockPatternMatch findExitPortalExitAroundOrigin() {
122+
+
123+
+ BlockPos targetPos;
124+
+
125+
+ // Paper end - exit portal optimization look around the origin first
126+
127+
BlockPos location = EndPodiumFeature.getLocation(this.origin);
128+
+
129+
int i1 = this.level.getHeightmapPos(Heightmap.Types.MOTION_BLOCKING, location).getY();
130+
131+
+
132+
+
133+
for (int i2 = i1; i2 >= this.level.getMinY(); i2--) {
134+
- BlockPattern.BlockPatternMatch blockPatternMatch1 = this.exitPortalPattern.find(this.level, new BlockPos(location.getX(), i2, location.getZ()));
135+
+
136+
+ // Paper start
137+
+
138+
+ targetPos = new BlockPos(location.getX(), i2, location.getZ());
139+
+
140+
+ // Early exit if we encroached a non bedrock block because the middle column MUST be bedrock
141+
+
142+
+ if (!this.level.getBlockState(targetPos).is(net.minecraft.world.level.block.Blocks.BEDROCK)) {
143+
+
144+
+ continue;
145+
+
146+
+ }
147+
+
148+
+ BlockPattern.BlockPatternMatch blockPatternMatch1 = this.exitPortalPattern.find(this.level, targetPos);
149+
+
150+
+ // Paper end
151+
+
152+
if (blockPatternMatch1 != null) {
153+
+
154+
if (this.portalLocation == null) {
155+
+
156+
this.portalLocation = blockPatternMatch1.getBlock(3, 3, 3).getPos();
157+
+
158+
}
159+
+
160+
+
161+
162+
return blockPatternMatch1;
163+
+
164+
}
165+
+
166+
}
167+
168+
+
169+
+
170+
return null;
171+
+
172+
}
173+
+
174+
175+
private boolean isArenaLoaded() {
176+
if (this.skipArenaLoadedCheck) {
40177
@@ -365,12 +_,22 @@
41178
this.dragonEvent.setVisible(false);
42179
this.spawnExitPortal(true);

0 commit comments

Comments
 (0)