diff --git a/patches/server/0082-Optimize-world-generation-chunk-and-block-access.patch b/patches/server/0082-Optimize-world-generation-chunk-and-block-access.patch new file mode 100644 index 0000000..ba4246b --- /dev/null +++ b/patches/server/0082-Optimize-world-generation-chunk-and-block-access.patch @@ -0,0 +1,200 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: MartijnMuijsers +Date: Thu, 1 Dec 2022 14:33:06 +0100 +Subject: [PATCH] Optimize world generation chunk and block access + +License: LGPL-3.0 (https://www.gnu.org/licenses/lgpl-3.0.html) + +This patch is based on the following mixins and classes: +* "me/jellysquid/mods/lithium/common/util/Pos.java" +* "me/jellysquid/mods/lithium/mixin/gen/chunk_region/ChunkRegionMixin.java" +By: SuperCoder7979 , 2No2Name <2No2Name@web.de> +As part of: Lithium (https://github.com/CaffeineMC/lithium-fabric) +Licensed under: LGPL-3.0 (https://www.gnu.org/licenses/lgpl-3.0.html) + +diff --git a/src/main/java/me/jellysquid/mods/lithium/common/util/Pos.java b/src/main/java/me/jellysquid/mods/lithium/common/util/Pos.java +new file mode 100644 +index 0000000000000000000000000000000000000000..f2f10b651e4fbecdd1ea1bc28ebf40d685a67cee +--- /dev/null ++++ b/src/main/java/me/jellysquid/mods/lithium/common/util/Pos.java +@@ -0,0 +1,95 @@ ++// Gale - Lithium - position utility ++ ++package me.jellysquid.mods.lithium.common.util; ++ ++import net.minecraft.core.SectionPos; ++import net.minecraft.world.level.LevelHeightAccessor; ++ ++public class Pos { ++ ++ public static class BlockCoord { ++ public static int getYSize(LevelHeightAccessor view) { ++ return view.getHeight(); ++ } ++ public static int getMinY(LevelHeightAccessor view) { ++ return view.getMinBuildHeight(); ++ } ++ public static int getMaxYInclusive(LevelHeightAccessor view) { ++ return view.getMaxBuildHeight() - 1; ++ } ++ public static int getMaxYExclusive(LevelHeightAccessor view) { ++ return view.getMaxBuildHeight(); ++ } ++ ++ public static int getMaxInSectionCoord(int sectionCoord) { ++ return 15 + getMinInSectionCoord(sectionCoord); ++ } ++ ++ public static int getMaxYInSectionIndex(LevelHeightAccessor view, int sectionIndex){ ++ return getMaxInSectionCoord(SectionYCoord.fromSectionIndex(view, sectionIndex)); ++ } ++ ++ public static int getMinInSectionCoord(int sectionCoord) { ++ return SectionPos.sectionToBlockCoord(sectionCoord); ++ } ++ ++ public static int getMinYInSectionIndex(LevelHeightAccessor view, int sectionIndex) { ++ return getMinInSectionCoord(SectionYCoord.fromSectionIndex(view, sectionIndex)); ++ } ++ } ++ ++ public static class ChunkCoord { ++ public static int fromBlockCoord(int blockCoord) { ++ return SectionPos.blockToSectionCoord(blockCoord); ++ } ++ ++ public static int fromBlockSize(int i) { ++ return i >> 4; //same method as fromBlockCoord, just be clear about coord/size semantic difference ++ } ++ } ++ ++ public static class SectionYCoord { ++ public static int getNumYSections(LevelHeightAccessor view) { ++ return view.getSectionsCount(); ++ } ++ public static int getMinYSection(LevelHeightAccessor view) { ++ return view.getMinSection(); ++ } ++ public static int getMaxYSectionInclusive(LevelHeightAccessor view) { ++ return view.getMaxSection() - 1; ++ } ++ public static int getMaxYSectionExclusive(LevelHeightAccessor view) { ++ return view.getMaxSection(); ++ } ++ ++ public static int fromSectionIndex(LevelHeightAccessor view, int sectionCoord) { ++ return sectionCoord + SectionYCoord.getMinYSection(view); ++ } ++ public static int fromBlockCoord(int blockCoord) { ++ return SectionPos.blockToSectionCoord(blockCoord); ++ } ++ } ++ ++ public static class SectionYIndex { ++ public static int getNumYSections(LevelHeightAccessor view) { ++ return view.getSectionsCount(); ++ } ++ public static int getMinYSectionIndex(LevelHeightAccessor view) { ++ return 0; ++ } ++ public static int getMaxYSectionIndexInclusive(LevelHeightAccessor view) { ++ return view.getSectionsCount() - 1; ++ } ++ public static int getMaxYSectionIndexExclusive(LevelHeightAccessor view) { ++ return view.getSectionsCount(); ++ } ++ ++ public static int fromSectionCoord(LevelHeightAccessor view, int sectionCoord) { ++ return sectionCoord - SectionYCoord.getMinYSection(view); ++ } ++ public static int fromBlockCoord(LevelHeightAccessor view, int blockCoord) { ++ return fromSectionCoord(view, SectionPos.blockToSectionCoord(blockCoord)); ++ } ++ } ++ ++} +diff --git a/src/main/java/net/minecraft/server/level/WorldGenRegion.java b/src/main/java/net/minecraft/server/level/WorldGenRegion.java +index c9e719e676ea26ee94673538db2dfd9ce5c957ae..0ee2cb850cd1039d8fe47b503027f0fcdbfe2daa 100644 +--- a/src/main/java/net/minecraft/server/level/WorldGenRegion.java ++++ b/src/main/java/net/minecraft/server/level/WorldGenRegion.java +@@ -8,6 +8,7 @@ import java.util.concurrent.atomic.AtomicLong; + import java.util.function.Predicate; + import java.util.function.Supplier; + import javax.annotation.Nullable; ++ + import net.minecraft.Util; + import net.minecraft.core.BlockPos; + import net.minecraft.core.Direction; +@@ -83,6 +84,10 @@ public class WorldGenRegion implements WorldGenLevel { + private Supplier currentlyGenerating; + private final AtomicLong subTickCount = new AtomicLong(); + private static final ResourceLocation WORLDGEN_REGION_RANDOM = new ResourceLocation("worldgen_region_random"); ++ // Gale start - Lithium - optimize world generation chunk and block access ++ private ChunkAccess[] chunksArr; ++ private int minChunkX, minChunkZ; ++ // Gale end - Lithium - optimize world generation chunk and block access + + public WorldGenRegion(ServerLevel world, List chunks, ChunkStatus status, int placementRadius) { + this.generatingStatus = status; +@@ -105,6 +110,11 @@ public class WorldGenRegion implements WorldGenLevel { + this.lastPos = ((ChunkAccess) chunks.get(chunks.size() - 1)).getPos(); + this.structureManager = world.structureManager().forWorldGenRegion(this); + } ++ // Gale start - Lithium - optimize world generation chunk and block access ++ this.minChunkX = this.firstPos.x; ++ this.minChunkZ = this.firstPos.z; ++ this.chunksArr = chunks.toArray(new ChunkAccess[0]); ++ // Gale end - Lithium - optimize world generation chunk and block access + } + + public boolean isOldChunkAround(ChunkPos chunkPos, int checkRadius) { +@@ -122,9 +132,29 @@ public class WorldGenRegion implements WorldGenLevel { + + @Override + public ChunkAccess getChunk(int chunkX, int chunkZ) { +- return this.getChunk(chunkX, chunkZ, ChunkStatus.EMPTY); ++ // Gale start - Lithium - optimize world generation chunk and block access - use the chunk array for faster access ++ int x = chunkX - this.minChunkX; ++ int z = chunkZ - this.minChunkZ; ++ int w = this.size; ++ ++ if (x >= 0 && z >= 0 && x < w && z < w) { ++ return this.chunksArr[x + z * w]; ++ } else { ++ throw new NullPointerException("No chunk exists at " + new ChunkPos(chunkX, chunkZ)); ++ } ++ // Gale end - Lithium - optimize world generation chunk and block access - use the chunk array for faster access + } + ++ // Gale start - Lithium - optimize world generation chunk and block access ++ /** ++ * Use our chunk fetch function ++ */ ++ public ChunkAccess getChunk(BlockPos pos) { ++ // Skip checking chunk.getStatus().isAtLeast(ChunkStatus.EMPTY) here, because it is always true ++ return this.getChunk(SectionPos.blockToSectionCoord(pos.getX()), SectionPos.blockToSectionCoord(pos.getZ())); ++ } ++ // Gale end - Lithium - optimize world generation chunk and block access ++ + @Nullable + @Override + public ChunkAccess getChunk(int chunkX, int chunkZ, ChunkStatus leastStatus, boolean create) { +@@ -182,7 +212,17 @@ public class WorldGenRegion implements WorldGenLevel { + + @Override + public BlockState getBlockState(BlockPos pos) { +- return this.getChunk(SectionPos.blockToSectionCoord(pos.getX()), SectionPos.blockToSectionCoord(pos.getZ())).getBlockState(pos); ++ // Gale start - Lithium - optimize world generation chunk and block access - avoid pointer de-referencing, make method easier to inline ++ int x = SectionPos.blockToSectionCoord(pos.getX()) - this.minChunkX; ++ int z = SectionPos.blockToSectionCoord(pos.getZ()) - this.minChunkZ; ++ int w = this.size; ++ ++ if (x >= 0 && z >= 0 && x < w && z < w) { ++ return this.chunksArr[x + z * w].getBlockState(pos); ++ } else { ++ throw new NullPointerException("No chunk exists at " + new ChunkPos(pos)); ++ } ++ // Gale end - Lithium - optimize world generation chunk and block access - avoid pointer de-referencing, make method easier to inline + } + + @Override diff --git a/patches/server/0082-Cache-world-generator-sea-level.patch b/patches/server/0083-Cache-world-generator-sea-level.patch similarity index 100% rename from patches/server/0082-Cache-world-generator-sea-level.patch rename to patches/server/0083-Cache-world-generator-sea-level.patch diff --git a/patches/server/0083-Skip-entity-move-if-movement-is-zero.patch b/patches/server/0084-Skip-entity-move-if-movement-is-zero.patch similarity index 100% rename from patches/server/0083-Skip-entity-move-if-movement-is-zero.patch rename to patches/server/0084-Skip-entity-move-if-movement-is-zero.patch diff --git a/patches/server/0084-Store-mob-counts-in-an-array.patch b/patches/server/0085-Store-mob-counts-in-an-array.patch similarity index 100% rename from patches/server/0084-Store-mob-counts-in-an-array.patch rename to patches/server/0085-Store-mob-counts-in-an-array.patch diff --git a/patches/server/0085-Optimize-noise-generation.patch b/patches/server/0086-Optimize-noise-generation.patch similarity index 100% rename from patches/server/0085-Optimize-noise-generation.patch rename to patches/server/0086-Optimize-noise-generation.patch diff --git a/patches/server/0086-Ignore-durability-change-equipment-updates.patch b/patches/server/0087-Ignore-durability-change-equipment-updates.patch similarity index 100% rename from patches/server/0086-Ignore-durability-change-equipment-updates.patch rename to patches/server/0087-Ignore-durability-change-equipment-updates.patch diff --git a/patches/server/0087-Hide-flames-on-entities-with-fire-resistance.patch b/patches/server/0088-Hide-flames-on-entities-with-fire-resistance.patch similarity index 100% rename from patches/server/0087-Hide-flames-on-entities-with-fire-resistance.patch rename to patches/server/0088-Hide-flames-on-entities-with-fire-resistance.patch diff --git a/patches/server/0088-Skip-cloning-advancement-criteria.patch b/patches/server/0089-Skip-cloning-advancement-criteria.patch similarity index 100% rename from patches/server/0088-Skip-cloning-advancement-criteria.patch rename to patches/server/0089-Skip-cloning-advancement-criteria.patch diff --git a/patches/server/0089-Player-canSee-by-entity-UUID.patch b/patches/server/0090-Player-canSee-by-entity-UUID.patch similarity index 100% rename from patches/server/0089-Player-canSee-by-entity-UUID.patch rename to patches/server/0090-Player-canSee-by-entity-UUID.patch diff --git a/patches/server/0090-Spread-out-sending-all-player-info.patch b/patches/server/0091-Spread-out-sending-all-player-info.patch similarity index 100% rename from patches/server/0090-Spread-out-sending-all-player-info.patch rename to patches/server/0091-Spread-out-sending-all-player-info.patch diff --git a/patches/server/0091-Optimize-player-list-for-sending-player-info.patch b/patches/server/0092-Optimize-player-list-for-sending-player-info.patch similarity index 100% rename from patches/server/0091-Optimize-player-list-for-sending-player-info.patch rename to patches/server/0092-Optimize-player-list-for-sending-player-info.patch diff --git a/patches/server/0092-Skip-PlayerCommandSendEvent-if-there-are-no-listener.patch b/patches/server/0093-Skip-PlayerCommandSendEvent-if-there-are-no-listener.patch similarity index 100% rename from patches/server/0092-Skip-PlayerCommandSendEvent-if-there-are-no-listener.patch rename to patches/server/0093-Skip-PlayerCommandSendEvent-if-there-are-no-listener.patch diff --git a/patches/server/0093-Send-multiple-keep-alive-packets.patch b/patches/server/0094-Send-multiple-keep-alive-packets.patch similarity index 100% rename from patches/server/0093-Send-multiple-keep-alive-packets.patch rename to patches/server/0094-Send-multiple-keep-alive-packets.patch diff --git a/patches/server/0094-Prevent-entities-random-strolling-into-non-ticking-c.patch b/patches/server/0095-Prevent-entities-random-strolling-into-non-ticking-c.patch similarity index 100% rename from patches/server/0094-Prevent-entities-random-strolling-into-non-ticking-c.patch rename to patches/server/0095-Prevent-entities-random-strolling-into-non-ticking-c.patch diff --git a/patches/server/0095-Specific-interval-TPS-API.patch b/patches/server/0096-Specific-interval-TPS-API.patch similarity index 100% rename from patches/server/0095-Specific-interval-TPS-API.patch rename to patches/server/0096-Specific-interval-TPS-API.patch diff --git a/patches/server/0096-5-second-TPS-average.patch b/patches/server/0097-5-second-TPS-average.patch similarity index 100% rename from patches/server/0096-5-second-TPS-average.patch rename to patches/server/0097-5-second-TPS-average.patch diff --git a/patches/server/0097-Measure-last-tick-time.patch b/patches/server/0098-Measure-last-tick-time.patch similarity index 100% rename from patches/server/0097-Measure-last-tick-time.patch rename to patches/server/0098-Measure-last-tick-time.patch diff --git a/patches/server/0098-Last-tick-time-API.patch b/patches/server/0099-Last-tick-time-API.patch similarity index 100% rename from patches/server/0098-Last-tick-time-API.patch rename to patches/server/0099-Last-tick-time-API.patch diff --git a/patches/server/0099-Show-last-tick-time-in-tps-command.patch b/patches/server/0100-Show-last-tick-time-in-tps-command.patch similarity index 100% rename from patches/server/0099-Show-last-tick-time-in-tps-command.patch rename to patches/server/0100-Show-last-tick-time-in-tps-command.patch diff --git a/patches/server/0100-Increase-time-statistics-in-intervals.patch b/patches/server/0101-Increase-time-statistics-in-intervals.patch similarity index 100% rename from patches/server/0100-Increase-time-statistics-in-intervals.patch rename to patches/server/0101-Increase-time-statistics-in-intervals.patch diff --git a/patches/server/0101-For-collision-check-has-physics-before-same-vehicle.patch b/patches/server/0102-For-collision-check-has-physics-before-same-vehicle.patch similarity index 100% rename from patches/server/0101-For-collision-check-has-physics-before-same-vehicle.patch rename to patches/server/0102-For-collision-check-has-physics-before-same-vehicle.patch diff --git a/patches/server/0102-Skip-negligible-planar-movement-multiplication.patch b/patches/server/0103-Skip-negligible-planar-movement-multiplication.patch similarity index 100% rename from patches/server/0102-Skip-negligible-planar-movement-multiplication.patch rename to patches/server/0103-Skip-negligible-planar-movement-multiplication.patch diff --git a/patches/server/0103-Variable-main-thread-task-delay.patch b/patches/server/0104-Variable-main-thread-task-delay.patch similarity index 100% rename from patches/server/0103-Variable-main-thread-task-delay.patch rename to patches/server/0104-Variable-main-thread-task-delay.patch diff --git a/patches/server/0104-Reduce-RandomSource-instances.patch b/patches/server/0105-Reduce-RandomSource-instances.patch similarity index 100% rename from patches/server/0104-Reduce-RandomSource-instances.patch rename to patches/server/0105-Reduce-RandomSource-instances.patch diff --git a/patches/server/0105-CPU-cores-estimation.patch b/patches/server/0106-CPU-cores-estimation.patch similarity index 100% rename from patches/server/0105-CPU-cores-estimation.patch rename to patches/server/0106-CPU-cores-estimation.patch diff --git a/patches/server/0106-Add-centralized-AsyncExecutor.patch b/patches/server/0107-Add-centralized-AsyncExecutor.patch similarity index 100% rename from patches/server/0106-Add-centralized-AsyncExecutor.patch rename to patches/server/0107-Add-centralized-AsyncExecutor.patch diff --git a/patches/server/0107-Remove-Paper-async-executor.patch b/patches/server/0108-Remove-Paper-async-executor.patch similarity index 100% rename from patches/server/0107-Remove-Paper-async-executor.patch rename to patches/server/0108-Remove-Paper-async-executor.patch diff --git a/patches/server/0108-Remove-Paper-cleaner-executor.patch b/patches/server/0109-Remove-Paper-cleaner-executor.patch similarity index 100% rename from patches/server/0108-Remove-Paper-cleaner-executor.patch rename to patches/server/0109-Remove-Paper-cleaner-executor.patch diff --git a/patches/server/0109-Remove-background-executor.patch b/patches/server/0110-Remove-background-executor.patch similarity index 100% rename from patches/server/0109-Remove-background-executor.patch rename to patches/server/0110-Remove-background-executor.patch diff --git a/patches/server/0110-Remove-bootstrap-executor.patch b/patches/server/0111-Remove-bootstrap-executor.patch similarity index 100% rename from patches/server/0110-Remove-bootstrap-executor.patch rename to patches/server/0111-Remove-bootstrap-executor.patch diff --git a/patches/server/0111-Remove-world-upgrade-executors.patch b/patches/server/0112-Remove-world-upgrade-executors.patch similarity index 100% rename from patches/server/0111-Remove-world-upgrade-executors.patch rename to patches/server/0112-Remove-world-upgrade-executors.patch diff --git a/patches/server/0112-Remove-tab-complete-executor.patch b/patches/server/0113-Remove-tab-complete-executor.patch similarity index 100% rename from patches/server/0112-Remove-tab-complete-executor.patch rename to patches/server/0113-Remove-tab-complete-executor.patch diff --git a/patches/server/0113-Remove-text-filter-executor.patch b/patches/server/0114-Remove-text-filter-executor.patch similarity index 100% rename from patches/server/0113-Remove-text-filter-executor.patch rename to patches/server/0114-Remove-text-filter-executor.patch