This repository has been archived by the owner on Sep 23, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 47
/
0075-some-entity-micro-opts.patch
84 lines (75 loc) · 3.97 KB
/
0075-some-entity-micro-opts.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
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 4279b170440faf28a061360d40ed6303d8cc1a97..9fc77dc845fc993ebb9d96f9af107f7e1e8e8a39 100644
--- a/src/main/java/net/minecraft/world/entity/Entity.java
+++ b/src/main/java/net/minecraft/world/entity/Entity.java
@@ -1890,12 +1890,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);
@@ -4317,6 +4323,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 9980df9128dfc51f2afbca8f4aa2031e3728796a..a60cca663da4200d482c19d0b41a9514825a1e9b 100644
--- a/src/main/java/net/minecraft/world/entity/Mob.java
+++ b/src/main/java/net/minecraft/world/entity/Mob.java
@@ -1641,15 +1641,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;