78 lines
4.3 KiB
Diff
78 lines
4.3 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: MrHua269 <wangxyper@163.com>
|
|
Date: Sun, 4 Aug 2024 22:14:21 +0800
|
|
Subject: [PATCH] Gale Optimize sun burn tick
|
|
|
|
|
|
diff --git a/src/main/java/net/minecraft/world/entity/Entity.java b/src/main/java/net/minecraft/world/entity/Entity.java
|
|
index e8984feea7fb06600329bae05b15d317f8ae78a0..071de4ddcff846f469d510b4147c3ed3cb31d7af 100644
|
|
--- a/src/main/java/net/minecraft/world/entity/Entity.java
|
|
+++ b/src/main/java/net/minecraft/world/entity/Entity.java
|
|
@@ -315,7 +315,7 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
|
|
public double xo;
|
|
public double yo;
|
|
public double zo;
|
|
- private Vec3 position;
|
|
+ public Vec3 position; // Gale - JettPack - optimize sun burn tick - private -> public
|
|
private BlockPos blockPosition;
|
|
private ChunkPos chunkPosition;
|
|
private Vec3 deltaMovement;
|
|
@@ -2122,9 +2122,19 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
|
|
/** @deprecated */
|
|
@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;
|
|
+ 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) : 0.0F;
|
|
+ }
|
|
+ // Gale end - JettPack - optimize sun burn tick - allow passing BlockPos to getLightLevelDependentMagicValue
|
|
+
|
|
public void absMoveTo(double x, double y, double z, float yaw, float pitch) {
|
|
this.absMoveTo(x, y, z);
|
|
this.absRotateTo(yaw, pitch);
|
|
diff --git a/src/main/java/net/minecraft/world/entity/Mob.java b/src/main/java/net/minecraft/world/entity/Mob.java
|
|
index 2384a9e68f99b61382d9d8a46523d226786ee584..73c65124d6996b4a74a044e562f04eda573589fc 100644
|
|
--- a/src/main/java/net/minecraft/world/entity/Mob.java
|
|
+++ b/src/main/java/net/minecraft/world/entity/Mob.java
|
|
@@ -1774,13 +1774,29 @@ public abstract class Mob extends LivingEntity implements EquipmentUser, Leashab
|
|
|
|
protected void playAttackSound() {}
|
|
|
|
+ // Gale start - JettPack - optimize sun burn tick - cache eye blockpos
|
|
+ private BlockPos cached_eye_blockpos;
|
|
+ private int cached_position_hashcode;
|
|
+ // Gale end - JettPack - optimize sun burn tick - cache eye blockpos
|
|
+
|
|
public boolean isSunBurnTick() {
|
|
if (this.level().isDay() && !this.level().isClientSide) {
|
|
- float f = this.getLightLevelDependentMagicValue();
|
|
- BlockPos blockposition = BlockPos.containing(this.getX(), this.getEyeY(), this.getZ());
|
|
+ // Gale start - JettPack - optimize sun burn tick - optimizations and cache eye blockpos
|
|
+ int positionHashCode = this.position.hashCode();
|
|
+ if (this.cached_position_hashcode != positionHashCode) {
|
|
+ this.cached_eye_blockpos = BlockPos.containing(this.getX(), this.getEyeY(), this.getZ());
|
|
+ this.cached_position_hashcode = positionHashCode;
|
|
+ }
|
|
+
|
|
+ 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;
|
|
+ // Gale end - JettPack - optimize sun burn tick - optimizations and cache eye blockpos
|
|
boolean flag = this.isInWaterRainOrBubble() || this.isInPowderSnow || this.wasInPowderSnow;
|
|
|
|
- if (f > 0.5F && this.random.nextFloat() * 30.0F < (f - 0.4F) * 2.0F && !flag && this.level().canSeeSky(blockposition)) {
|
|
+ if (!flag && this.level().canSeeSky(this.cached_eye_blockpos)) { // Gale - JettPack - optimize sun burn tick - optimizations and cache eye blockpos
|
|
return true;
|
|
}
|
|
}
|