85 lines
4.0 KiB
Diff
85 lines
4.0 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: Simon Gardling <titaniumtown@gmail.com>
|
|
Date: Fri, 14 Jan 2022 12:00:42 -0500
|
|
Subject: [PATCH] some entity micro opts
|
|
|
|
Original code by Titaniumtown, licensed under GNU General Public License v3.0
|
|
You can find the original code on https://gitlab.com/Titaniumtown/JettPack
|
|
|
|
diff --git a/src/main/java/net/minecraft/world/entity/Entity.java b/src/main/java/net/minecraft/world/entity/Entity.java
|
|
index d4ae6b345762d224f89ca65634ff4af178dc634f..4e92962cc351bf3abcf51b8952eff5686eda5ea9 100644
|
|
--- a/src/main/java/net/minecraft/world/entity/Entity.java
|
|
+++ b/src/main/java/net/minecraft/world/entity/Entity.java
|
|
@@ -1881,12 +1881,18 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource {
|
|
}
|
|
}
|
|
|
|
+ // JettPack start - allow passing BlockPos to getLightLevelDependentMagicValue
|
|
/** @deprecated */
|
|
@Deprecated
|
|
public float getLightLevelDependentMagicValue() {
|
|
- return this.level.hasChunkAt(this.getBlockX(), this.getBlockZ()) ? this.level.getLightLevelDependentMagicValue(new BlockPos(this.getX(), this.getEyeY(), this.getZ())) : 0.0F;
|
|
+ return this.level.getLightLevelDependentMagicValue(new BlockPos(this.getX(), this.getEyeY(), this.getZ()));
|
|
}
|
|
|
|
+ public float getLightLevelDependentMagicValue(BlockPos pos) {
|
|
+ return this.level.hasChunkAt(this.getBlockX(), this.getBlockZ()) ? this.level.getLightLevelDependentMagicValue(pos) : 0.0F;
|
|
+ }
|
|
+ // JettPack end
|
|
+
|
|
public void absMoveTo(double x, double y, double z, float yaw, float pitch) {
|
|
this.absMoveTo(x, y, z);
|
|
this.setYRot(yaw % 360.0F);
|
|
@@ -4334,6 +4340,12 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource {
|
|
}
|
|
// Paper end - block invalid positions
|
|
|
|
+ // JettPack start
|
|
+ public final int getPositionHashCode() {
|
|
+ return this.position.hashCode();
|
|
+ }
|
|
+ // JettPack end
|
|
+
|
|
public final void setPosRaw(double x, double y, double z) {
|
|
// Paper start
|
|
this.setPosRaw(x, y, z, false);
|
|
diff --git a/src/main/java/net/minecraft/world/entity/Mob.java b/src/main/java/net/minecraft/world/entity/Mob.java
|
|
index 78b1fc7b4cacfc98a9e3e6ba93e17c3307d5449c..63911fd0d2a5f194ed4632f209555b3146ed7b79 100644
|
|
--- a/src/main/java/net/minecraft/world/entity/Mob.java
|
|
+++ b/src/main/java/net/minecraft/world/entity/Mob.java
|
|
@@ -1647,15 +1647,31 @@ public abstract class Mob extends LivingEntity {
|
|
|
|
}
|
|
|
|
+ // JettPack start - cache eye blockpos
|
|
+ private BlockPos cached_eye_blockpos;
|
|
+ private int cached_position_hashcode;
|
|
+ // JettPack end
|
|
public boolean isSunBurnTick() {
|
|
if (this.level.isDay() && !this.level.isClientSide) {
|
|
- float f = this.getLightLevelDependentMagicValue();
|
|
- BlockPos blockposition = new BlockPos(this.getX(), this.getEyeY(), this.getZ());
|
|
+ // JettPack start - optimizations and cache eye blockpos
|
|
+ int positionHashCode = this.getPositionHashCode();
|
|
+ if (this.cached_position_hashcode != positionHashCode) {
|
|
+ this.cached_eye_blockpos = new BlockPos(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;
|
|
+
|
|
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)) { // JettPack - move brightness checks up
|
|
return true;
|
|
}
|
|
+ // JettPack end
|
|
}
|
|
|
|
return false;
|