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/0288-optimize-getOnPos.patch

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 f15b3dcc06361eb1b3d791c8143e7e9623ee5e8a..841d63333f55701357ed4dfd0d1be3faa5eeb3b1 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() {