9
0
mirror of https://github.com/LeavesMC/Leaves.git synced 2025-12-19 14:59:32 +00:00
Files
LeavesMC/leaves-server/minecraft-patches/features/0062-Optimize-sun-burn-tick.patch
MC_XiaoHei 90080d238e 1.21.10 (#752)
---------

Co-authored-by: Lumine1909 <133463833+Lumine1909@users.noreply.github.com>
Co-authored-by: violetc <58360096+s-yh-china@users.noreply.github.com>
Co-authored-by: Helvetica Volubi <88063803+Suisuroru@users.noreply.github.com>
2025-11-28 03:15:54 +08:00

96 lines
5.1 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: violetc <58360096+s-yh-china@users.noreply.github.com>
Date: Thu, 20 Jul 2023 15:18:50 +0800
Subject: [PATCH] Optimize sun burn tick
This patch is Powered by Gale(https://github.com/GaleMC/Gale)
diff --git a/net/minecraft/world/entity/Entity.java b/net/minecraft/world/entity/Entity.java
index 37f6e22d9f8f0fffede79b1d273d65a69f8d675c..39e31c547dcd60f48e607a9c98cfe03a38ae88b1 100644
--- a/net/minecraft/world/entity/Entity.java
+++ b/net/minecraft/world/entity/Entity.java
@@ -2174,9 +2174,20 @@ public abstract class Entity implements SyncedDataHolder, DebugValueSource, Name
@Deprecated
public float getLightLevelDependentMagicValue() {
- return this.level().hasChunkAt(this.getBlockX(), this.getBlockZ())
- ? this.level().getLightLevelDependentMagicValue(BlockPos.containing(this.getX(), this.getEyeY(), this.getZ()))
- : 0.0F;
+ // Leaves start - optimize sun burn tick
+ if (!org.leavesmc.leaves.LeavesConfig.performance.optimizeSunBurnTick) {
+ return this.level().hasChunkAt(this.getBlockX(), this.getBlockZ()) ? this.level().getLightLevelDependentMagicValue(BlockPos.containing(this.getX(), this.getEyeY(), this.getZ())) : 0.0F;
+ } else {
+ return this.getLightLevelDependentMagicValue(BlockPos.containing(this.getX(), this.getEyeY(), this.getZ()));
+ }
+ // Leaves end - optimize sun burn tick
+ }
+
+ // Leaves start - optimize sun burn tick
+ /** @deprecated */
+ @Deprecated
+ public float getLightLevelDependentMagicValue(BlockPos pos) {
+ return this.level().hasChunkAt(this.getBlockX(), this.getBlockZ()) ? this.level.getLightLevelDependentMagicValue(pos) : 0.0F;
}
public void absSnapTo(double x, double y, double z, float yRot, float xRot) {
@@ -2191,6 +2202,7 @@ public abstract class Entity implements SyncedDataHolder, DebugValueSource, Name
this.xRotO = this.getXRot();
this.setYHeadRot(yRot); // Paper - Update head rotation
}
+ // Leaves end - optimize sun burn tick
public void absSnapTo(double x, double y, double z) {
double d = Mth.clamp(x, -3.0E7, 3.0E7);
diff --git a/net/minecraft/world/entity/Mob.java b/net/minecraft/world/entity/Mob.java
index 0659e1b95055e85e3eefd206ccb01ee4a4949a5b..1cefdab82744600c6e5886646450d4c3fab03181 100644
--- a/net/minecraft/world/entity/Mob.java
+++ b/net/minecraft/world/entity/Mob.java
@@ -1565,17 +1565,39 @@ public abstract class Mob extends LivingEntity implements EquipmentUser, Leashab
protected void playAttackSound() {
}
+ // Leaves start - optimize sun burn tick
+ @Nullable private BlockPos cached_eye_blockpos;
+ @Nullable private net.minecraft.world.phys.Vec3 cached_position;
+ // Leaves end - optimize sun burn tick
+
public boolean isSunBurnTick() {
if (this.level().isBrightOutside() && !this.level().isClientSide()) {
- float lightLevelDependentMagicValue = this.getLightLevelDependentMagicValue();
- BlockPos blockPos = BlockPos.containing(this.getX(), this.getEyeY(), this.getZ());
- boolean flag = this.isInWaterOrRain() || this.isInPowderSnow || this.wasInPowderSnow;
- if (lightLevelDependentMagicValue > 0.5F
- && this.random.nextFloat() * 30.0F < (lightLevelDependentMagicValue - 0.4F) * 2.0F
- && !flag
- && this.level().canSeeSky(blockPos)) {
- return true;
+ // Leaves start - optimize sun burn tick
+ if (!org.leavesmc.leaves.LeavesConfig.performance.optimizeSunBurnTick) {
+ float lightLevelDependentMagicValue = this.getLightLevelDependentMagicValue();
+ BlockPos blockPos = BlockPos.containing(this.getX(), this.getEyeY(), this.getZ());
+ boolean flag = this.isInWaterOrRain() || this.isInPowderSnow || this.wasInPowderSnow;
+ if (lightLevelDependentMagicValue > 0.5F
+ && this.random.nextFloat() * 30.0F < (lightLevelDependentMagicValue - 0.4F) * 2.0F
+ && !flag
+ && this.level().canSeeSky(blockPos)) {
+ return true;
+ }
+ } else {
+ if (cached_eye_blockpos == null || !this.position().equals(cached_position)) {
+ this.cached_eye_blockpos = BlockPos.containing(this.getX(), this.getEyeY(), this.getZ());
+ this.cached_position = this.position();
+ }
+
+ float f = this.getLightLevelDependentMagicValue(cached_eye_blockpos); // Pass BlockPos to getBrightness
+
+ // Check brightness first
+ if (f <= 0.5F) return false;
+ if (this.random.nextFloat() * 30.0F >= (f - 0.4F) * 2.0F) return false;
+ boolean flag = this.isInWaterOrRain() || this.isInPowderSnow || this.wasInPowderSnow;
+ return !flag && this.level().canSeeSky(this.cached_eye_blockpos);
}
+ // Leaves end - optimize sun burn tick
}
return false;