9
0
mirror of https://github.com/Winds-Studio/Leaf.git synced 2025-12-19 15:09:25 +00:00
Files
Leaf/leaf-server/minecraft-patches/features/0176-optimise-ChunkGenerator-getMobsAt.patch

67 lines
4.2 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: hayanesuru <hayanesuru@outlook.jp>
Date: Tue, 3 Jun 2025 15:16:32 +0900
Subject: [PATCH] optimise ChunkGenerator#getMobsAt
inline fillStartsForStructure
diff --git a/net/minecraft/world/level/StructureManager.java b/net/minecraft/world/level/StructureManager.java
index 8bc6a6c86cd8db53feefba7508b6031ba67e242e..90397f237c0cb79da03b3f9ca7445676324ebd11 100644
--- a/net/minecraft/world/level/StructureManager.java
+++ b/net/minecraft/world/level/StructureManager.java
@@ -78,7 +78,7 @@ public class StructureManager {
public void fillStartsForStructure(Structure structure, LongSet structureRefs, Consumer<StructureStart> startConsumer) {
for (long l : structureRefs) {
- SectionPos sectionPos = SectionPos.of(new ChunkPos(l), this.level.getMinSectionY());
+ SectionPos sectionPos = SectionPos.of(ChunkPos.getX(l), this.level.getMinSectionY(), ChunkPos.getZ(l)); // Leaf - optimise ChunkGenerator#getMobsAt
StructureStart startForStructure = this.getStartForStructure(
sectionPos, structure, this.level.getChunk(sectionPos.x(), sectionPos.z(), ChunkStatus.STRUCTURE_STARTS)
);
@@ -173,8 +173,8 @@ public class StructureManager {
}
public Map<Structure, LongSet> getAllStructuresAt(BlockPos pos) {
- SectionPos sectionPos = SectionPos.of(pos);
- return this.level.getChunk(sectionPos.x(), sectionPos.z(), ChunkStatus.STRUCTURE_REFERENCES).getAllReferences();
+ //SectionPos sectionPos = SectionPos.of(pos); // Leaf - optimise ChunkGenerator#getMobsAt
+ return this.level.getChunk(pos.getX() >> 4, pos.getZ() >> 4, ChunkStatus.STRUCTURE_REFERENCES).getAllReferences(); // Leaf - optimise ChunkGenerator#getMobsAt
}
public StructureCheckResult checkStructurePresence(ChunkPos chunkPos, Structure structure, StructurePlacement placement, boolean skipKnownStructures) {
diff --git a/net/minecraft/world/level/chunk/ChunkGenerator.java b/net/minecraft/world/level/chunk/ChunkGenerator.java
index 176adfcaa0fc458043d4bc05ead1861864b63606..755e635a2ece6ab6d3b166cb437e48b527041160 100644
--- a/net/minecraft/world/level/chunk/ChunkGenerator.java
+++ b/net/minecraft/world/level/chunk/ChunkGenerator.java
@@ -501,18 +501,20 @@ public abstract class ChunkGenerator {
Structure structure = entry.getKey();
StructureSpawnOverride structureSpawnOverride = structure.spawnOverrides().get(category);
if (structureSpawnOverride != null) {
- MutableBoolean mutableBoolean = new MutableBoolean(false);
- Predicate<StructureStart> predicate = structureSpawnOverride.boundingBox() == StructureSpawnOverride.BoundingBoxType.PIECE
- ? structureStart -> structureManager.structureHasPieceAt(pos, structureStart)
- : structureStart -> structureStart.getBoundingBox().isInside(pos);
- structureManager.fillStartsForStructure(structure, entry.getValue(), structureStart -> {
- if (mutableBoolean.isFalse() && predicate.test(structureStart)) {
- mutableBoolean.setTrue();
+ // Leaf start - optimise ChunkGenerator#getMobsAt
+ for (long l : entry.getValue()) {
+ StructureStart startForStructure = structureManager.getStartForStructure(
+ null, structure, structureManager.level.getChunk(ChunkPos.getX(l), ChunkPos.getZ(l), ChunkStatus.STRUCTURE_STARTS)
+ );
+ if (startForStructure != null && startForStructure.isValid()) {
+ if (structureSpawnOverride.boundingBox() == StructureSpawnOverride.BoundingBoxType.PIECE
+ ? structureManager.structureHasPieceAt(pos, startForStructure)
+ : startForStructure.getBoundingBox().isInside(pos)) {
+ return structureSpawnOverride.spawns();
+ }
}
- });
- if (mutableBoolean.isTrue()) {
- return structureSpawnOverride.spawns();
}
+ // Leaf end - optimise ChunkGenerator#getMobsAt
}
}