9
0
mirror of https://github.com/Winds-Studio/Leaf.git synced 2025-12-27 10:59:16 +00:00
Files
Leaf/leaf-server/minecraft-patches/features/0286-optimize-getOnPos.patch
hayanesuru 043cb215fd Optimize canHoldAnyFluid in canMaybePassThrough (#527)
* optimize canHoldAnyFluid in canMaybePassThrough

* rebuild patches

* support reload
2025-10-12 14:26:33 -04:00

56 lines
2.9 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: hayanesuru <hayanesuru@outlook.jp>
Date: Sat, 9 Aug 2025 15:43:17 +0900
Subject: [PATCH] optimize getOnPos
diff --git a/net/minecraft/world/entity/Entity.java b/net/minecraft/world/entity/Entity.java
index a0625e490f054916e2f6cf08371c85c9b514b988..0b7bb37a29c3a5534db6f2bd781f7ef3bcc378cd 100644
--- a/net/minecraft/world/entity/Entity.java
+++ b/net/minecraft/world/entity/Entity.java
@@ -1450,24 +1450,29 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
}
protected BlockPos getOnPos(float yOffset) {
- if (this.mainSupportingBlockPos.isPresent() && this.level().getChunkIfLoadedImmediately(this.mainSupportingBlockPos.get()) != null) { // Paper - ensure no loads
+ // Leaf start - optimize getOnPos
+ if (this.mainSupportingBlockPos.isPresent() /*&& this.level().getChunkIfLoadedImmediately(this.mainSupportingBlockPos.get()) != null*/) { // Paper - ensure no loads
BlockPos blockPos = this.mainSupportingBlockPos.get();
- if (!(yOffset > 1.0E-5F)) {
- return blockPos;
- } else {
- BlockState blockState = this.level().getBlockState(blockPos);
- return (!(yOffset <= 0.5) || !blockState.is(BlockTags.FENCES))
- && !blockState.is(BlockTags.WALLS)
- && !(blockState.getBlock() instanceof FenceGateBlock)
- ? blockPos.atY(Mth.floor(this.position.y - yOffset))
- : blockPos;
+ net.minecraft.world.level.chunk.LevelChunk chunk = this.level().getChunkIfLoaded(blockPos);
+ if (chunk != null) {
+ if (!(yOffset > 1.0E-5F)) {
+ return blockPos;
+ } else {
+ BlockState blockState = chunk.getBlockStateFinal(blockPos.getX(), blockPos.getY(), blockPos.getZ());
+ int flags = blockState.tagFlag;
+ return (!(yOffset <= 0.5) || (flags & org.dreeam.leaf.util.BlockMasks.FENCE_TAG) == 0)
+ && (flags & org.dreeam.leaf.util.BlockMasks.WALL_TAG) == 0
+ && (flags & org.dreeam.leaf.util.BlockMasks.FENCE_GATE_CL) == 0
+ ? blockPos.atY(Mth.floor(this.position.y - yOffset))
+ : blockPos;
+ }
}
- } else {
- int floor = Mth.floor(this.position.x);
- int floor1 = Mth.floor(this.position.y - yOffset);
- int floor2 = Mth.floor(this.position.z);
- return new BlockPos(floor, floor1, floor2);
}
+ int floor = Mth.floor(this.position.x);
+ int floor1 = Mth.floor(this.position.y - yOffset);
+ int floor2 = Mth.floor(this.position.z);
+ return new BlockPos(floor, floor1, floor2);
+ // Leaf end - optimize getOnPos
}
protected float getBlockJumpFactor() {