mirror of
https://github.com/BX-Team/DivineMC.git
synced 2025-12-19 14:59:25 +00:00
add back ender dragon fight optimization
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
# This file is auto generated, any changes may be overridden!
|
||||
# See CONTRIBUTING.md on how to add access transformers.
|
||||
public net.minecraft.world.level.block.state.pattern.BlockPattern matches(Lnet/minecraft/core/BlockPos;Lnet/minecraft/core/Direction;Lnet/minecraft/core/Direction;Lcom/google/common/cache/LoadingCache;)Lnet/minecraft/world/level/block/state/pattern/BlockPattern$BlockPatternMatch;
|
||||
public net.minecraft.world.level.pathfinder.SwimNodeEvaluator allowBreaching
|
||||
|
||||
@@ -1,163 +0,0 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: NONPLAYT <76615486+NONPLAYT@users.noreply.github.com>
|
||||
Date: Wed, 22 May 2024 22:44:05 +0300
|
||||
Subject: [PATCH] Carpet-AMS-Addition: Optimized dragon respawn
|
||||
|
||||
|
||||
diff --git a/src/main/java/net/minecraft/world/level/block/state/pattern/BlockPattern.java b/src/main/java/net/minecraft/world/level/block/state/pattern/BlockPattern.java
|
||||
index ee99519ebd46b1db3e76e7eb86e5cc121c867dc4..43174e6b5bd306273736d1c2971f976c149d3517 100644
|
||||
--- a/src/main/java/net/minecraft/world/level/block/state/pattern/BlockPattern.java
|
||||
+++ b/src/main/java/net/minecraft/world/level/block/state/pattern/BlockPattern.java
|
||||
@@ -59,7 +59,7 @@ public class BlockPattern {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
- private BlockPattern.BlockPatternMatch matches(BlockPos frontTopLeft, Direction forwards, Direction up, LoadingCache<BlockPos, BlockInWorld> cache) {
|
||||
+ public BlockPattern.BlockPatternMatch matches(BlockPos frontTopLeft, Direction forwards, Direction up, LoadingCache<BlockPos, BlockInWorld> cache) { // DivineMC - private -> public
|
||||
for (int i = 0; i < this.width; i++) {
|
||||
for (int j = 0; j < this.height; j++) {
|
||||
for (int k = 0; k < this.depth; k++) {
|
||||
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 b331c93c82c27f9456fec208a0c008c5bedfa8c4..ec3142ae55686e13c2984eaf8cf0bcc8db0e39a3 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
|
||||
@@ -46,6 +46,7 @@ import net.minecraft.world.entity.boss.enderdragon.phases.EnderDragonPhase;
|
||||
import net.minecraft.world.level.ChunkPos;
|
||||
import net.minecraft.world.level.block.Blocks;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
+import net.minecraft.world.level.block.entity.TheEndGatewayBlockEntity;
|
||||
import net.minecraft.world.level.block.entity.TheEndPortalBlockEntity;
|
||||
import net.minecraft.world.level.block.state.pattern.BlockInWorld;
|
||||
import net.minecraft.world.level.block.state.pattern.BlockPattern;
|
||||
@@ -292,8 +293,67 @@ public class EndDragonFight {
|
||||
return false;
|
||||
}
|
||||
|
||||
+ // DivineMC start - Optimized dragon respawn
|
||||
+ private int cachePortalChunkIteratorX = -8;
|
||||
+ private int cachePortalChunkIteratorZ = -8;
|
||||
+ private int cachePortalOriginIteratorY = -1;
|
||||
+
|
||||
@Nullable
|
||||
public BlockPattern.BlockPatternMatch findExitPortal() {
|
||||
+ if (space.bxteam.divinemc.configuration.DivineConfig.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 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;
|
||||
+ }
|
||||
+ //No need to judge whether optimizing option is open
|
||||
+ 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 = space.bxteam.divinemc.util.carpetams.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
|
||||
ChunkPos chunkcoordintpair = new ChunkPos(this.origin);
|
||||
|
||||
int i;
|
||||
@@ -624,6 +684,11 @@ public class EndDragonFight {
|
||||
}
|
||||
|
||||
public boolean respawnDragon(List<EndCrystal> list) { // CraftBukkit - return boolean
|
||||
+ // DivineMC start - Optimized dragon respawn
|
||||
+ cachePortalChunkIteratorX = -8;
|
||||
+ cachePortalChunkIteratorZ = -8;
|
||||
+ cachePortalOriginIteratorY = -1;
|
||||
+ // DivineMC end
|
||||
if (this.dragonKilled && this.respawnStage == null) {
|
||||
for (BlockPattern.BlockPatternMatch shapedetector_shapedetectorcollection = this.findExitPortal(); shapedetector_shapedetectorcollection != null; shapedetector_shapedetectorcollection = this.findExitPortal()) {
|
||||
for (int i = 0; i < this.exitPortalPattern.getWidth(); ++i) {
|
||||
diff --git a/src/main/java/space/bxteam/divinemc/configuration/DivineConfig.java b/src/main/java/space/bxteam/divinemc/configuration/DivineConfig.java
|
||||
index 911c9144cdf15930995fbd3c2b8ff01c74138c74..c88157b27b344b2ed1153a44daee751f5b53b45d 100644
|
||||
--- a/src/main/java/space/bxteam/divinemc/configuration/DivineConfig.java
|
||||
+++ b/src/main/java/space/bxteam/divinemc/configuration/DivineConfig.java
|
||||
@@ -161,7 +161,9 @@ public class DivineConfig {
|
||||
}
|
||||
|
||||
public static boolean biomeManagerOptimization = true;
|
||||
+ public static boolean optimizedDragonRespawn = true;
|
||||
private static void optimizations() {
|
||||
biomeManagerOptimization = getBoolean("settings.optimizations.biome-manager-optimization", biomeManagerOptimization);
|
||||
+ optimizedDragonRespawn = getBoolean("settings.optimizations.optimized-dragon-respawn", optimizedDragonRespawn);
|
||||
}
|
||||
}
|
||||
diff --git a/src/main/java/space/bxteam/divinemc/util/carpetams/BlockPatternHelper.java b/src/main/java/space/bxteam/divinemc/util/carpetams/BlockPatternHelper.java
|
||||
new file mode 100644
|
||||
index 0000000000000000000000000000000000000000..1bf8f3d814d513ea2806bba9c26d207d14533cbd
|
||||
--- /dev/null
|
||||
+++ b/src/main/java/space/bxteam/divinemc/util/carpetams/BlockPatternHelper.java
|
||||
@@ -0,0 +1,32 @@
|
||||
+package space.bxteam.divinemc.util.carpetams;
|
||||
+
|
||||
+import com.google.common.cache.LoadingCache;
|
||||
+import net.minecraft.core.BlockPos;
|
||||
+import net.minecraft.core.Direction;
|
||||
+import net.minecraft.world.level.Level;
|
||||
+import net.minecraft.world.level.block.state.pattern.BlockInWorld;
|
||||
+import net.minecraft.world.level.block.state.pattern.BlockPattern;
|
||||
+
|
||||
+/**
|
||||
+ * Original <a href="https://github.com/Minecraft-AMS/Carpet-AMS-Addition">here</a>
|
||||
+ *
|
||||
+ * @author 1024-byteeeee
|
||||
+ */
|
||||
+public class BlockPatternHelper {
|
||||
+ public static BlockPattern.BlockPatternMatch partialSearchAround(BlockPattern pattern, Level world, BlockPos pos) {
|
||||
+ LoadingCache<BlockPos, BlockInWorld> loadingCache = BlockPattern.createLevelCache(world, false);
|
||||
+ int i = Math.max(Math.max(pattern.getWidth(), pattern.getHeight()), pattern.getDepth());
|
||||
+
|
||||
+ for (BlockPos blockPos : BlockPos.betweenClosed(pos, pos.offset(i - 1, 0, i - 1))) {
|
||||
+ for (Direction direction : Direction.values()) {
|
||||
+ for (Direction direction2 : Direction.values()) {
|
||||
+ BlockPattern.BlockPatternMatch result;
|
||||
+ if (direction2 == direction || direction2 == direction.getOpposite() || (result = pattern.matches(blockPos, direction, direction2, loadingCache)) == null)
|
||||
+ continue;
|
||||
+ return result;
|
||||
+ }
|
||||
+ }
|
||||
+ }
|
||||
+ return null;
|
||||
+ }
|
||||
+}
|
||||
@@ -0,0 +1,82 @@
|
||||
--- a/net/minecraft/world/level/dimension/end/EndDragonFight.java
|
||||
+++ b/net/minecraft/world/level/dimension/end/EndDragonFight.java
|
||||
@@ -274,8 +_,67 @@
|
||||
return false;
|
||||
}
|
||||
|
||||
+ // DivineMC start - Optimized dragon respawn
|
||||
+ private int cachePortalChunkIteratorX = -8;
|
||||
+ private int cachePortalChunkIteratorZ = -8;
|
||||
+ private int cachePortalOriginIteratorY = -1;
|
||||
+
|
||||
@Nullable
|
||||
public BlockPattern.BlockPatternMatch findExitPortal() {
|
||||
+ if (space.bxteam.divinemc.configuration.DivineGlobalConfiguration.get().optimizations.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;
|
||||
+ }
|
||||
+ //No need to judge whether optimizing option is open
|
||||
+ 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 = space.bxteam.divinemc.util.carpetams.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 - Optimized dragon respawn
|
||||
ChunkPos chunkPos = new ChunkPos(this.origin);
|
||||
|
||||
for (int i = -8 + chunkPos.x; i <= 8 + chunkPos.x; i++) {
|
||||
@@ -571,6 +_,11 @@
|
||||
}
|
||||
|
||||
public boolean respawnDragon(List<EndCrystal> crystals) { // CraftBukkit - return boolean
|
||||
+ // DivineMC start - Optimized dragon respawn
|
||||
+ cachePortalChunkIteratorX = -8;
|
||||
+ cachePortalChunkIteratorZ = -8;
|
||||
+ cachePortalOriginIteratorY = -1;
|
||||
+ // DivineMC end - 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++) {
|
||||
@@ -72,6 +72,12 @@ public class DivineGlobalConfiguration extends ConfigurationPart {
|
||||
}
|
||||
}
|
||||
|
||||
public Optimizations optimizations;
|
||||
|
||||
public class Optimizations extends ConfigurationPart {
|
||||
public boolean optimizedDragonRespawn = true;
|
||||
}
|
||||
|
||||
public Chat chat;
|
||||
|
||||
public class Chat extends ConfigurationPart {
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
package space.bxteam.divinemc.util.carpetams;
|
||||
|
||||
import com.google.common.cache.LoadingCache;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.block.state.pattern.BlockInWorld;
|
||||
import net.minecraft.world.level.block.state.pattern.BlockPattern;
|
||||
|
||||
/**
|
||||
* Original <a href="https://github.com/Minecraft-AMS/Carpet-AMS-Addition">here</a>
|
||||
*
|
||||
* @author 1024-byteeeee
|
||||
*/
|
||||
public class BlockPatternHelper {
|
||||
public static BlockPattern.BlockPatternMatch partialSearchAround(BlockPattern pattern, Level world, BlockPos pos) {
|
||||
LoadingCache<BlockPos, BlockInWorld> loadingCache = BlockPattern.createLevelCache(world, false);
|
||||
int i = Math.max(Math.max(pattern.getWidth(), pattern.getHeight()), pattern.getDepth());
|
||||
|
||||
for (BlockPos blockPos : BlockPos.betweenClosed(pos, pos.offset(i - 1, 0, i - 1))) {
|
||||
for (Direction direction : Direction.values()) {
|
||||
for (Direction direction2 : Direction.values()) {
|
||||
BlockPattern.BlockPatternMatch result;
|
||||
if (direction2 == direction || direction2 == direction.getOpposite() || (result = pattern.matches(blockPos, direction, direction2, loadingCache)) == null)
|
||||
continue;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user