mirror of
https://github.com/Winds-Studio/Leaf.git
synced 2025-12-21 07:59:26 +00:00
123 lines
6.9 KiB
Diff
123 lines
6.9 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: hayanesuru <hayanesuru@outlook.jp>
|
|
Date: Sat, 9 Aug 2025 15:43:24 +0900
|
|
Subject: [PATCH] optimize get eye block position
|
|
|
|
|
|
diff --git a/net/minecraft/world/entity/Entity.java b/net/minecraft/world/entity/Entity.java
|
|
index bb16f3ebffcafcb11d3112e03f5767ac71b359f6..22b7b1bd62f730a760ce0cf0a2ddb701324e3c3e 100644
|
|
--- a/net/minecraft/world/entity/Entity.java
|
|
+++ b/net/minecraft/world/entity/Entity.java
|
|
@@ -553,20 +553,14 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
|
|
|
|
// Leaf start - Fix Pufferfish and Purpur patches
|
|
// Gale start - JettPack - optimize sun burn tick - cache eye blockpos
|
|
- private BlockPos cached_eye_blockpos;
|
|
- private net.minecraft.world.phys.Vec3 cached_position;
|
|
+ private BlockPos leaf$cached_eye_blockpos = BlockPos.ZERO;
|
|
+ @Nullable private BlockPos leaf$cached_position = null;
|
|
// Gale end - JettPack - optimize sun burn tick - cache eye blockpos
|
|
// Purpur start - copied from Mob - API for any mob to burn daylight
|
|
public boolean isSunBurnTick() {
|
|
if (this.level().isBrightOutside() && !this.level().isClientSide) {
|
|
// Gale start - JettPack - optimize sun burn tick - optimizations and cache eye blockpos
|
|
- if (this.cached_position != this.position) {
|
|
- this.cached_eye_blockpos = BlockPos.containing(this.getX(), this.getEyeY(), this.getZ());
|
|
- this.cached_position = this.position;
|
|
- }
|
|
-
|
|
- float lightLevelDependentMagicValue = this.getLightLevelDependentMagicValue(cached_eye_blockpos); // Pass BlockPos to getBrightness
|
|
-
|
|
+ float lightLevelDependentMagicValue = this.getLightLevelDependentMagicValue();
|
|
// Check brightness first
|
|
if (lightLevelDependentMagicValue <= 0.5F) return false;
|
|
if (this.random.nextFloat() * 30.0F >= (lightLevelDependentMagicValue - 0.4F) * 2.0F) return false;
|
|
@@ -574,11 +568,22 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
|
|
|
|
boolean flag = this.isInWaterOrRain() || this.isInPowderSnow || this.wasInPowderSnow;
|
|
|
|
- return !flag && this.level().canSeeSky(this.cached_eye_blockpos); // Gale - JettPack - optimize sun burn tick - optimizations and cache eye blockpos
|
|
+ return !flag && this.level().canSeeSky(this.leaf$getEyeBlockPos()); // Gale - JettPack - optimize sun burn tick - optimizations and cache eye blockpos
|
|
}
|
|
|
|
return false; // Gale - JettPack - optimize sun burn tick - optimizations and cache eye blockpos - diff on change
|
|
}
|
|
+
|
|
+ // Leaf start
|
|
+ public BlockPos leaf$getEyeBlockPos() {
|
|
+ if (this.leaf$cached_position != this.blockPosition) {
|
|
+ this.leaf$cached_eye_blockpos = this.blockPosition.atY(Mth.floor(this.getEyeY()));
|
|
+ this.leaf$cached_position = this.blockPosition;
|
|
+ }
|
|
+ return this.leaf$cached_eye_blockpos;
|
|
+ }
|
|
+ // Leaf end
|
|
+
|
|
// Purpur end - copied from Mob - API for any mob to burn daylight
|
|
// Leaf end - Fix Pufferfish and Purpur patches
|
|
|
|
@@ -2151,8 +2156,9 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
|
|
&& abstractBoat.getBoundingBox().maxY >= eyeY
|
|
&& abstractBoat.getBoundingBox().minY <= eyeY
|
|
)) {
|
|
- BlockPos blockPos = BlockPos.containing(this.getX(), eyeY, this.getZ());
|
|
- FluidState fluidState = this.level().getFluidState(blockPos);
|
|
+ BlockPos blockPos = leaf$getEyeBlockPos(); // Leaf
|
|
+ FluidState fluidState = this.level().getFluidStateIfLoadedUnchecked(blockPos.getX(), blockPos.getY(), blockPos.getZ()); // Leaf
|
|
+ if (fluidState == null) { fluidState = this.level().getFluidState(blockPos); } // Leaf
|
|
double d = blockPos.getY() + fluidState.getHeight(this.level(), blockPos);
|
|
if (d > eyeY) {
|
|
// Leaf start - Optimize isEyeInFluid
|
|
@@ -2280,20 +2286,10 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
|
|
|
|
@Deprecated
|
|
public float getLightLevelDependentMagicValue() {
|
|
- return this.getLightLevelDependentMagicValue(BlockPos.containing(this.getX(), this.getEyeY(), this.getZ())); // Gale - JettPack - optimize sun burn tick - allow passing BlockPos to getLightLevelDependentMagicValue
|
|
- }
|
|
-
|
|
- // Gale start - JettPack - optimize sun burn tick - allow passing BlockPos to getLightLevelDependentMagicValue
|
|
- /**
|
|
- * @deprecated
|
|
- */
|
|
- @Deprecated
|
|
- public float getLightLevelDependentMagicValue(BlockPos pos) {
|
|
- return this.level().hasChunkAt(this.getBlockX(), this.getBlockZ())
|
|
- ? this.level.getLightLevelDependentMagicValue(pos)
|
|
+ return this.level.hasChunkAt(this.getBlockX(), this.getBlockZ()) // Leaf
|
|
+ ? this.level.getLightLevelDependentMagicValue(leaf$getEyeBlockPos()) // Leaf
|
|
: 0.0F;
|
|
}
|
|
- // Gale end - JettPack - optimize sun burn tick - allow passing BlockPos to getLightLevelDependentMagicValue
|
|
|
|
public void absSnapTo(double x, double y, double z, float yRot, float xRot) {
|
|
this.absSnapTo(x, y, z);
|
|
@@ -4531,6 +4527,7 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
|
|
EntityDimensions dimensions = this.getDimensions(pose);
|
|
this.dimensions = dimensions;
|
|
this.eyeHeight = dimensions.eyeHeight();
|
|
+ this.leaf$cached_position = null; // Leaf
|
|
}
|
|
|
|
public void refreshDimensions() {
|
|
@@ -4539,6 +4536,7 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
|
|
EntityDimensions dimensions = this.getDimensions(pose);
|
|
this.dimensions = dimensions;
|
|
this.eyeHeight = dimensions.eyeHeight();
|
|
+ this.leaf$cached_position = null; // Leaf
|
|
this.reapplyPosition();
|
|
boolean flag = dimensions.width() <= 4.0F && dimensions.height() <= 4.0F;
|
|
if (!this.level.isClientSide
|
|
diff --git a/net/minecraft/world/entity/LivingEntity.java b/net/minecraft/world/entity/LivingEntity.java
|
|
index b8665f74bc5592b0022636e62482e21c84692d39..dc66b2c59984ce62b1d3c4a97c769771229fb4f8 100644
|
|
--- a/net/minecraft/world/entity/LivingEntity.java
|
|
+++ b/net/minecraft/world/entity/LivingEntity.java
|
|
@@ -464,7 +464,7 @@ public abstract class LivingEntity extends Entity implements Attackable, Waypoin
|
|
}
|
|
|
|
if (this.isEyeInWater() // Leaf - Optimize isEyeInFluid
|
|
- && !serverLevel1.getBlockState(BlockPos.containing(this.getX(), this.getEyeY(), this.getZ())).is(Blocks.BUBBLE_COLUMN)) {
|
|
+ && !serverLevel1.getBlockState(leaf$getEyeBlockPos()).is(Blocks.BUBBLE_COLUMN)) { // Leaf
|
|
boolean flag1 = !this.canBreatheUnderwater()
|
|
&& !MobEffectUtil.hasWaterBreathing(this)
|
|
&& (!flag || !((Player)this).getAbilities().invulnerable);
|