96 lines
5.2 KiB
Diff
96 lines
5.2 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|||
|
|
From: Helvetica Volubi <suisuroru@blue-millennium.fun>
|
||
|
|
Date: Tue, 21 Apr 2026 23:52:23 +0800
|
||
|
|
Subject: [PATCH] Leaves: Optimized dragon respawn
|
||
|
|
|
||
|
|
Co-authored by: violetc <58360096+s-yh-china@users.noreply.github.com>
|
||
|
|
As part of: Leaves (https://github.com/LeavesMC/Leaves/blob/4ade1001e4dd19c47d95c27f0b12df3175697f29/leaves-server/minecraft-patches/features/0049-Optimized-dragon-respawn.patch)
|
||
|
|
Licensed under: GPL-3.0 (https://www.gnu.org/licenses/gpl-3.0.html)
|
||
|
|
|
||
|
|
diff --git a/net/minecraft/world/level/dimension/end/EnderDragonFight.java b/net/minecraft/world/level/dimension/end/EnderDragonFight.java
|
||
|
|
index 824ef3f458505569fe5b8efb2055ecea7ba6cc56..64a2fc0e49a6fc50773f6e0c40c2535a7533d41b 100644
|
||
|
|
--- a/net/minecraft/world/level/dimension/end/EnderDragonFight.java
|
||
|
|
+++ b/net/minecraft/world/level/dimension/end/EnderDragonFight.java
|
||
|
|
@@ -317,7 +317,67 @@ public class EnderDragonFight extends SavedData {
|
||
|
|
return false;
|
||
|
|
}
|
||
|
|
|
||
|
|
+ // Leaves start - optimizedDragonRespawn
|
||
|
|
+ private int cachePortalChunkIteratorX = -8;
|
||
|
|
+ private int cachePortalChunkIteratorZ = -8;
|
||
|
|
+ private int cachePortalOriginIteratorY = -1;
|
||
|
|
+
|
||
|
|
public BlockPattern.@Nullable BlockPatternMatch findExitPortal() {
|
||
|
|
+ if (moe.monnairealms.camellia.config.modules.optimizations.OptimizedDragonRespawnConfig.optimizedRespawn) {
|
||
|
|
+ int i, j;
|
||
|
|
+ for (i = cachePortalChunkIteratorX; i <= 8; ++i) {
|
||
|
|
+ for (j = cachePortalChunkIteratorZ; j <= 8; ++j) {
|
||
|
|
+ LevelChunk worldChunk = this.level.getChunk(i, j);
|
||
|
|
+ for (BlockEntity blockEntity : worldChunk.getBlockEntities().values()) {
|
||
|
|
+ if (blockEntity instanceof net.minecraft.world.level.block.entity.TheEndGatewayBlockEntity) {
|
||
|
|
+ continue;
|
||
|
|
+ }
|
||
|
|
+ if (blockEntity instanceof TheEndPortalBlockEntity) {
|
||
|
|
+ BlockPattern.BlockPatternMatch blockPatternMatch = this.exitPortalPattern.find(this.level, blockEntity.getBlockPos());
|
||
|
|
+ if (blockPatternMatch != null) {
|
||
|
|
+ BlockPos blockPos = blockPatternMatch.getBlock(3, 3, 3).getPos();
|
||
|
|
+ if (this.exitPortalLocation == null) {
|
||
|
|
+ this.exitPortalLocation = blockPos;
|
||
|
|
+ }
|
||
|
|
+ //No need to judge whether optimizing option is open
|
||
|
|
+ cachePortalChunkIteratorX = i;
|
||
|
|
+ cachePortalChunkIteratorZ = j;
|
||
|
|
+ return blockPatternMatch;
|
||
|
|
+ }
|
||
|
|
+ }
|
||
|
|
+ }
|
||
|
|
+ }
|
||
|
|
+ }
|
||
|
|
+
|
||
|
|
+ if (this.needsStateScanning || this.exitPortalLocation == null) {
|
||
|
|
+ if (cachePortalOriginIteratorY != -1) {
|
||
|
|
+ i = cachePortalOriginIteratorY;
|
||
|
|
+ } else {
|
||
|
|
+ i = this.level.getHeightmapPos(Heightmap.Types.MOTION_BLOCKING, EndPodiumFeature.getLocation(BlockPos.ZERO)).getY();
|
||
|
|
+ }
|
||
|
|
+ boolean notFirstSearch = false;
|
||
|
|
+ for (j = i; j >= 0; --j) {
|
||
|
|
+ BlockPattern.BlockPatternMatch result2 = null;
|
||
|
|
+ if (notFirstSearch) {
|
||
|
|
+ result2 = org.leavesmc.leaves.util.BlockPatternHelper.partialSearchAround(this.exitPortalPattern, this.level, new BlockPos(EndPodiumFeature.getLocation(BlockPos.ZERO).getY(), j, EndPodiumFeature.getLocation(BlockPos.ZERO).getZ()));
|
||
|
|
+ } else {
|
||
|
|
+ result2 = this.exitPortalPattern.find(this.level, new BlockPos(EndPodiumFeature.getLocation(BlockPos.ZERO).getX(), j, EndPodiumFeature.getLocation(BlockPos.ZERO).getZ()));
|
||
|
|
+ }
|
||
|
|
+ if (result2 != null) {
|
||
|
|
+ if (this.exitPortalLocation == null) {
|
||
|
|
+ this.exitPortalLocation = result2.getBlock(3, 3, 3).getPos();
|
||
|
|
+ }
|
||
|
|
+ cachePortalOriginIteratorY = j;
|
||
|
|
+ return result2;
|
||
|
|
+ }
|
||
|
|
+ notFirstSearch = true;
|
||
|
|
+ }
|
||
|
|
+ }
|
||
|
|
+
|
||
|
|
+ return null;
|
||
|
|
+ }
|
||
|
|
+ // Leaves end - optimizedDragonRespawn
|
||
|
|
+
|
||
|
|
ChunkPos chunkOrigin = ChunkPos.containing(this.origin);
|
||
|
|
|
||
|
|
for (int x = -8 + chunkOrigin.x(); x <= 8 + chunkOrigin.x(); x++) {
|
||
|
|
@@ -623,8 +683,12 @@ public class EnderDragonFight extends SavedData {
|
||
|
|
}
|
||
|
|
return false; // CraftBukkit - return value
|
||
|
|
}
|
||
|
|
-
|
||
|
|
public boolean respawnDragon(final List<EndCrystal> crystals) { // CraftBukkit - return boolean
|
||
|
|
+ // Leaves - start optimizedDragonRespawn
|
||
|
|
+ cachePortalChunkIteratorX = -8;
|
||
|
|
+ cachePortalChunkIteratorZ = -8;
|
||
|
|
+ cachePortalOriginIteratorY = -1;
|
||
|
|
+ // Leaves - end optimizedDragonRespawn
|
||
|
|
if (this.dragonKilled && this.respawnStage == null) {
|
||
|
|
for (BlockPattern.BlockPatternMatch portal = this.findExitPortal(); portal != null; portal = this.findExitPortal()) {
|
||
|
|
for (int x = 0; x < this.exitPortalPattern.getWidth(); x++) {
|