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/0287-cache-eye-block-position.patch
Dreeam 35ac5d48ed Cleanup PWT (#533)
* Unify comment format
* More configurable
* Remove one extra execute mid-tick task call in level tick when PWT is disabled

This may cause extremely rare, weird, strange, magic, mysterious issues with plugins, or potentially more.

One example is that it may cause boss mob duplication issue when `ONE MOB ONLY` was enabled in plugin SupremeBosses
2025-10-25 07:41:43 -04:00

128 lines
7.0 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] cache eye block position
diff --git a/net/minecraft/world/entity/Entity.java b/net/minecraft/world/entity/Entity.java
index 841d63333f55701357ed4dfd0d1be3faa5eeb3b1..ecfd852e64ffdb9e5eaebe7b1eeef4e99dda3b15 100644
--- a/net/minecraft/world/entity/Entity.java
+++ b/net/minecraft/world/entity/Entity.java
@@ -553,18 +553,13 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
// Purpur start - copied from Mob - API for any mob to burn daylight
// 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 Vec3 leaf$cached_position = null;
// Gale end - JettPack - optimize sun burn tick - cache eye blockpos
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;
@@ -573,11 +568,29 @@ 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 - cache eye block pos
+ public BlockPos leaf$getEyeBlockPos() {
+ if (this.leaf$cached_position != this.position) {
+ double eyeY = this.getEyeY();
+ int x = Mth.floor(this.getX());
+ int y = Mth.floor(eyeY);
+ int z = Mth.floor(this.getZ());
+ BlockPos o = leaf$cached_eye_blockpos;
+ if (o.getX() != x || o.getY() != y || o.getZ() != z) {
+ this.leaf$cached_eye_blockpos = new BlockPos(x, y, z);
+ }
+ this.leaf$cached_position = this.position;
+ }
+ return this.leaf$cached_eye_blockpos;
+ }
+ // Leaf end - cache eye block pos
+
// Purpur end - copied from Mob - API for any mob to burn daylight
public Entity(EntityType<?> entityType, Level level) {
@@ -2055,8 +2068,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
@@ -2184,20 +2198,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);
@@ -4451,6 +4455,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() {
@@ -4459,6 +4464,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 b35ef147ee813778721816e89b95b7a43e6c310e..4277c798ceee0ca329d332f8d1354dde312f0c29 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);