Folia/patches/server/0014-Do-not-access-POI-data-for-lodestone-compass.patch

27 lines
1.8 KiB
Diff
Raw Permalink Normal View History

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Spottedleaf <Spottedleaf@users.noreply.github.com>
Date: Sat, 13 May 2023 17:13:40 -0700
Subject: [PATCH] Do not access POI data for lodestone compass
Instead, we can just check the loaded chunk's block position for
the lodestone block, as that is at least safe enough for the light
engine compared to the POI access. This should make it safe for
off-region access.
2024-05-10 06:07:34 +02:00
diff --git a/src/main/java/net/minecraft/world/item/component/LodestoneTracker.java b/src/main/java/net/minecraft/world/item/component/LodestoneTracker.java
index cdd1f6939ce33e62f6609f7eb3a5dff59bf12675..5d92251dc5a53eb6b2f5ecfef1261ad6edd0e2a9 100644
--- a/src/main/java/net/minecraft/world/item/component/LodestoneTracker.java
+++ b/src/main/java/net/minecraft/world/item/component/LodestoneTracker.java
@@ -29,7 +29,10 @@ public record LodestoneTracker(Optional<GlobalPos> target, boolean tracked) {
return this;
} else {
BlockPos blockPos = this.target.get().pos();
- return world.isInWorldBounds(blockPos) && (!world.hasChunkAt(blockPos) || world.getPoiManager().existsAtPosition(PoiTypes.LODESTONE, blockPos)) // Paper - Prevent compass from loading chunks
+ // Folia start - do not access the POI data off-region
+ net.minecraft.world.level.chunk.LevelChunk chunk = world.getChunkIfLoaded(blockPos);
+ return world.isInWorldBounds(blockPos) && (chunk == null || chunk.getBlockState(blockPos).getBlock() == net.minecraft.world.level.block.Blocks.LODESTONE) // Paper - Prevent compass from loading chunks
+ // Folia end - do not access the POI data off-region
? this
: new LodestoneTracker(Optional.empty(), true);
}