9
0
mirror of https://github.com/Winds-Studio/Leaf.git synced 2025-12-29 11:59:24 +00:00
Files
Leaf/leaf-server/minecraft-patches/features/0289-cache-eye-block-position.patch
Dreeam d36ed6c316 Remove OP lock (#486)
Current implementation of OP lock is not an appropriate solution to prevent plugins that contain backdoor or malicious code. There are many ways to bypass this check to manipulate the OP list or permissions. The best way to prevent this kind of grief is to get plugins from valid and trustworthy places.
2025-08-31 23:53:19 -04:00

130 lines
7.2 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 bb16f3ebffcafcb11d3112e03f5767ac71b359f6..29fa9cfa1aa2d507da852f5fe33ea6e4143da194 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 Vec3 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,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
// Leaf end - Fix Pufferfish and Purpur patches
@@ -2151,8 +2163,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 +2293,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 +4534,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 +4543,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 453c3eb95bebd426d0457f27bda261033dd7b14d..8baa17d2eadfa83b1fcb36fcd1408e917b883989 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);