9
0
mirror of https://github.com/BX-Team/DivineMC.git synced 2025-12-19 14:59:25 +00:00
Files
DivineMC/divinemc-server/minecraft-patches/features/0020-Carpet-AMS-Addition-Optimized-dragon-respawn.patch
wiyba 6e0570e215 Updated Upstream (Purpur)
Upstream has released updates that appear to apply and compile correctly

Purpur Changes:
2025-10-31 15:33:03 +03:00

112 lines
6.2 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: NONPLAYT <76615486+NONPLAYT@users.noreply.github.com>
Date: Wed, 11 Jun 2025 19:33:13 +0300
Subject: [PATCH] Carpet-AMS-Addition: Optimized dragon respawn
This patch is based on the following mixins and classes:
* "club/mcams/carpet/mixin/rule/optimizedDragonRespawn/BlockPatternMixin.java"
* "club/mcams/carpet/mixin/rule/optimizedDragonRespawn/EnderDragonFightMixin.java"
* "club/mcams/carpet/helpers/rule/optimizedDragonRespawn/BlockPatternHelper.java"
By: 1024-byteeeee
As part of: Carpet-AMS-Addition (https://github.com/Minecraft-AMS/Carpet-AMS-Addition)
Licensed under: LGPL-3.0 (https://www.gnu.org/licenses/lgpl-3.0.html)
diff --git a/net/minecraft/world/level/block/state/pattern/BlockPattern.java b/net/minecraft/world/level/block/state/pattern/BlockPattern.java
index f7bb979f08634a7e1b77c59040f59fb5e11aafa5..e0eca73d9e8a77b2a4972db61001394c6bf1d2c4 100644
--- a/net/minecraft/world/level/block/state/pattern/BlockPattern.java
+++ b/net/minecraft/world/level/block/state/pattern/BlockPattern.java
@@ -59,7 +59,7 @@ public class BlockPattern {
}
@Nullable
- private BlockPattern.BlockPatternMatch matches(BlockPos pos, Direction finger, Direction thumb, LoadingCache<BlockPos, BlockInWorld> cache) {
+ public BlockPattern.BlockPatternMatch matches(BlockPos pos, Direction finger, Direction thumb, LoadingCache<BlockPos, BlockInWorld> cache) { // DivineMC - Carpet-AMS-Addition: Optimized dragon respawn - make public
for (int i = 0; i < this.width; i++) {
for (int i1 = 0; i1 < this.height; i1++) {
for (int i2 = 0; i2 < this.depth; i2++) {
diff --git a/net/minecraft/world/level/dimension/end/EndDragonFight.java b/net/minecraft/world/level/dimension/end/EndDragonFight.java
index fcb0fb9ca663ec40e1541d099bc3d710963f6c9d..db9843fddf43bdc287978728f08230c0e6178195 100644
--- a/net/minecraft/world/level/dimension/end/EndDragonFight.java
+++ b/net/minecraft/world/level/dimension/end/EndDragonFight.java
@@ -274,8 +274,68 @@ public class EndDragonFight {
return false;
}
+ // DivineMC start - Carpet-AMS-Addition: Optimized dragon respawn
+ private int cachePortalChunkIteratorX = -8;
+ private int cachePortalChunkIteratorZ = -8;
+ private int cachePortalOriginIteratorY = -1;
+
@Nullable
public BlockPattern.BlockPatternMatch findExitPortal() {
+ if (org.bxteam.divinemc.config.DivineConfig.PerformanceCategory.optimizedDragonRespawn) {
+ 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.portalLocation == null) {
+ this.portalLocation = blockPos;
+ }
+
+ cachePortalChunkIteratorX = i;
+ cachePortalChunkIteratorZ = j;
+ return blockPatternMatch;
+ }
+ }
+ }
+ }
+ }
+
+ if (this.needsStateScanning || this.portalLocation == 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.bxteam.divinemc.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.portalLocation == null) {
+ this.portalLocation = result2.getBlock(3, 3, 3).getPos();
+ }
+ cachePortalOriginIteratorY = j;
+ return result2;
+ }
+ notFirstSearch = true;
+ }
+ }
+
+ return null;
+ }
+ // DivineMC end - Carpet-AMS-Addition: Optimized dragon respawn
+
ChunkPos chunkPos = new ChunkPos(this.origin);
for (int i = -8 + chunkPos.x; i <= 8 + chunkPos.x; i++) {
@@ -573,6 +633,11 @@ public class EndDragonFight {
}
public boolean respawnDragon(List<EndCrystal> crystals) { // CraftBukkit - return boolean
+ // DivineMC start - Carpet-AMS-Addition: Optimized dragon respawn
+ cachePortalChunkIteratorX = -8;
+ cachePortalChunkIteratorZ = -8;
+ cachePortalOriginIteratorY = -1;
+ // DivineMC end - Carpet-AMS-Addition: Optimized dragon respawn
if (this.dragonKilled && this.respawnStage == null) {
for (BlockPattern.BlockPatternMatch blockPatternMatch = this.findExitPortal(); blockPatternMatch != null; blockPatternMatch = this.findExitPortal()) {
for (int i = 0; i < this.exitPortalPattern.getWidth(); i++) {