mirror of
https://github.com/Winds-Studio/Leaf.git
synced 2025-12-26 10:29:13 +00:00
92 lines
4.7 KiB
Diff
92 lines
4.7 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: hayanesuru <hayanesuru@outlook.jp>
|
|
Date: Sat, 9 Aug 2025 15:42:48 +0900
|
|
Subject: [PATCH] optimize onClimbable
|
|
|
|
|
|
diff --git a/net/minecraft/world/entity/Entity.java b/net/minecraft/world/entity/Entity.java
|
|
index d61761dc1683e439af4ebfc393bc8c70de23340f..85789dfd30fe4f3b1108634e84b10f168bf6f64e 100644
|
|
--- a/net/minecraft/world/entity/Entity.java
|
|
+++ b/net/minecraft/world/entity/Entity.java
|
|
@@ -4992,7 +4992,8 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
|
|
// Gale start - don't load chunks to activate climbing entities
|
|
public @Nullable BlockState getInBlockStateIfLoaded() {
|
|
if (this.inBlockState == null) {
|
|
- this.inBlockState = this.level.getBlockStateIfLoaded(this.blockPosition());
|
|
+ BlockPos pos = this.blockPosition(); // Leaf - optimize onClimbable
|
|
+ this.inBlockState = this.level.getBlockStateIfLoadedUnchecked(pos.getX(), pos.getY(), pos.getZ()); // Leaf - optimize onClimbable
|
|
}
|
|
|
|
return this.inBlockState;
|
|
diff --git a/net/minecraft/world/entity/LivingEntity.java b/net/minecraft/world/entity/LivingEntity.java
|
|
index 5b8fbc73b4d165b56c7133ed4a0156570ecb58a1..f0a0a19e2adff03e73e75c3db831dbf74ebf3861 100644
|
|
--- a/net/minecraft/world/entity/LivingEntity.java
|
|
+++ b/net/minecraft/world/entity/LivingEntity.java
|
|
@@ -2217,10 +2217,10 @@ public abstract class LivingEntity extends Entity implements Attackable, Waypoin
|
|
public boolean onClimbableCached() {
|
|
if (!this.blockPosition().equals(this.lastClimbingPosition)) {
|
|
// Gale start - don't load chunks to activate climbing entities
|
|
- Boolean onClimbableIfLoaded = this.onClimbable(this.level().galeConfig().smallOptimizations.loadChunks.toActivateClimbingEntities);
|
|
+ int onClimbableIfLoaded = this.onClimbable1(this.level().galeConfig().smallOptimizations.loadChunks.toActivateClimbingEntities); // Leaf - optimize onClimbable
|
|
|
|
- if (onClimbableIfLoaded != null) {
|
|
- this.cachedOnClimbable = onClimbableIfLoaded;
|
|
+ if (onClimbableIfLoaded != 2) { // Leaf - optimize onClimbable
|
|
+ this.cachedOnClimbable = onClimbableIfLoaded == 1; // Leaf - optimize onClimbable
|
|
this.lastClimbingPosition = this.blockPosition();
|
|
} else {
|
|
this.cachedOnClimbable = false;
|
|
@@ -2235,35 +2235,39 @@ public abstract class LivingEntity extends Entity implements Attackable, Waypoin
|
|
|
|
public boolean onClimbable() {
|
|
// Gale start - don't load chunks to activate climbing entities
|
|
- return onClimbable(true);
|
|
+ return onClimbable1(true) == 1; // Leaf - optimize onClimbable
|
|
}
|
|
|
|
- public Boolean onClimbable(boolean loadChunk) {
|
|
+ // Leaf start - optimize onClimbable
|
|
+ public int onClimbable1(boolean loadChunk) {
|
|
// Gale end - don't load chunks to activate climbing entities
|
|
if (this.isSpectator()) {
|
|
- return false;
|
|
+ return 0;
|
|
} else {
|
|
BlockPos blockPos = this.blockPosition();
|
|
// Gale start - don't load chunks to activate climbing
|
|
- BlockState inBlockState;
|
|
+ BlockState inBlockState = this.getInBlockStateIfLoaded();
|
|
if (loadChunk) {
|
|
- inBlockState = this.getInBlockState();
|
|
- } else {
|
|
- inBlockState = this.getInBlockStateIfLoaded();
|
|
- if (inBlockState == null) return null;
|
|
+ if (inBlockState == null) {
|
|
+ inBlockState = this.getInBlockState();
|
|
+ }
|
|
+ } else if (inBlockState == null) {
|
|
+ return 2;
|
|
}
|
|
// Gale end - don't load chunks to activate climbing entities
|
|
- if (inBlockState.is(BlockTags.CLIMBABLE)) {
|
|
+ final int flags = inBlockState.tagFlag;
|
|
+ if ((flags & org.dreeam.leaf.util.BlockMasks.CLIMBABLE_TAG) != 0) {
|
|
this.lastClimbablePos = Optional.of(blockPos);
|
|
- return true;
|
|
- } else if (inBlockState.getBlock() instanceof TrapDoorBlock && this.trapdoorUsableAsLadder(blockPos, inBlockState)) {
|
|
+ return 1;
|
|
+ } else if ((flags & org.dreeam.leaf.util.BlockMasks.TRAP_DOOR_CL) != 0 && this.trapdoorUsableAsLadder(blockPos, inBlockState)) {
|
|
this.lastClimbablePos = Optional.of(blockPos);
|
|
- return true;
|
|
+ return 1;
|
|
} else {
|
|
- return false;
|
|
+ return 0;
|
|
}
|
|
}
|
|
}
|
|
+ // Leaf end - optimize onClimbable
|
|
|
|
private boolean trapdoorUsableAsLadder(BlockPos pos, BlockState state) {
|
|
if (!state.getValue(TrapDoorBlock.OPEN)) {
|