Files
Shiroha/camellia-server/minecraft-patches/features/0022-Prevent-tamable-animals-check-can-teleport-in-an-unl.patch
T
2026-07-14 11:32:51 +08:00

25 lines
1.6 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: MrHua269 <mrhua269@gmail.com>
Date: Wed, 8 Jul 2026 21:28:42 +0800
Subject: [PATCH] Prevent tamable animals check can teleport in an unloaded
chunk
Based on the implementation of Canvas(https://github.com/CraftCanvasMC/Canvas/commit/af2aacb12cbccfd328dda4961167786f5d9dad53)
We need to check canTeleport for TamableAnimal but this logic could do the check in another tick region itself, so we need to prevent that. But it needs to push off this check to schedule to the correct tickregion, which needs costly rewriting of this logic, so we could simply allow the read when the owner's position is loaded
diff --git a/net/minecraft/world/entity/TamableAnimal.java b/net/minecraft/world/entity/TamableAnimal.java
index 95ba821a895c7ea8fffcbf1df2e7b3c174463d9e..1e076d368f2e34b83b94e939ca9856bae4e9f86e 100644
--- a/net/minecraft/world/entity/TamableAnimal.java
+++ b/net/minecraft/world/entity/TamableAnimal.java
@@ -318,7 +318,8 @@ public abstract class TamableAnimal extends Animal implements OwnableEntity {
return false;
}
- BlockState blockStateBelow = this.level().getBlockState(pos.below());
+ BlockState blockStateBelow = this.level().getBlockStateIfLoaded(pos.below()); // Shiroha - Prevent tamable animals check can teleport in an unloaded chunk
+ if (blockStateBelow == null) return false; // Shiroha - Prevent tamable animals check can teleport in an unloaded chunk
if (!this.canFlyToOwner() && blockStateBelow.getBlock() instanceof LeavesBlock) {
return false;
}