Even even more Lithium patches

This commit is contained in:
Etil
2022-01-15 16:27:50 +01:00
parent 3383476d61
commit 7d1bc255df
4 changed files with 1593 additions and 0 deletions

View File

@@ -0,0 +1,220 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: 2No2Name <2No2Name@web.de>
Date: Mon, 10 Jan 2022 18:07:44 -0500
Subject: [PATCH] lithium: collections.brain and ai.task.memory_change_counting
Original code by CaffeineMC, licensed under GNU Lesser General Public License v3.0
You can find the original code on https://github.com/CaffeineMC/lithium-fabric (Yarn mappings)
diff --git a/src/main/java/net/minecraft/world/entity/ai/Brain.java b/src/main/java/net/minecraft/world/entity/ai/Brain.java
index d1d576a616797d7658c117582435434743aeef58..8179f5bc2bcd5ddb46e790b6e906ea9a517ed5b0 100644
--- a/src/main/java/net/minecraft/world/entity/ai/Brain.java
+++ b/src/main/java/net/minecraft/world/entity/ai/Brain.java
@@ -40,13 +40,21 @@ import net.minecraft.world.entity.schedule.Schedule;
import org.apache.commons.lang3.mutable.MutableObject;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
+// JettPack start
+import it.unimi.dsi.fastutil.objects.Reference2ReferenceLinkedOpenHashMap;
+import it.unimi.dsi.fastutil.objects.Reference2ReferenceOpenHashMap;
+import java.util.ArrayList;
+// JettPack end
public class Brain<E extends LivingEntity> {
static final Logger LOGGER = LogManager.getLogger();
private final Supplier<Codec<Brain<E>>> codec;
private static final int SCHEDULE_UPDATE_DELAY = 20;
- private final Map<MemoryModuleType<?>, Optional<? extends ExpirableValue<?>>> memories = Maps.newHashMap();
- private final Map<SensorType<? extends Sensor<? super E>>, Sensor<? super E>> sensors = Maps.newLinkedHashMap();
+ // JettPack start - lithium: collections.brain
+ private final Map<MemoryModuleType<?>, Optional<? extends ExpirableValue<?>>> memories = new Reference2ReferenceOpenHashMap<>();
+ private final Map<SensorType<? extends Sensor<? super E>>, Sensor<? super E>> sensors = new Reference2ReferenceLinkedOpenHashMap<>();
+ private ArrayList<Map<Activity, Set<Behavior<? super E>>>> tasksSorted = new ArrayList<>();
+ // JettPack end
private final Map<Integer, Map<Activity, Set<Behavior<? super E>>>> availableBehaviorsByPriority = Maps.newTreeMap();
private Schedule schedule = Schedule.EMPTY;
private final Map<Activity, Set<Pair<MemoryModuleType<?>, MemoryStatus>>> activityRequirements = Maps.newHashMap();
@@ -59,6 +67,12 @@ public class Brain<E extends LivingEntity> {
public static <E extends LivingEntity> Brain.Provider<E> provider(Collection<? extends MemoryModuleType<?>> memoryModules, Collection<? extends SensorType<? extends Sensor<? super E>>> sensors) {
return new Brain.Provider<>(memoryModules, sensors);
}
+ // JettPack start - ai.task.memory_change_counting
+ private long memoryModCount = 1;
+ public long getModCount() {
+ return memoryModCount;
+ }
+ // JettPack end
public static <E extends LivingEntity> Codec<Brain<E>> codec(Collection<? extends MemoryModuleType<?>> memoryModules, Collection<? extends SensorType<? extends Sensor<? super E>>> sensors) {
final MutableObject<Codec<Brain<E>>> mutableObject = new MutableObject<>();
@@ -74,16 +88,16 @@ public class Brain<E extends LivingEntity> {
}
public <T> DataResult<Brain<E>> decode(DynamicOps<T> dynamicOps, MapLike<T> mapLike) {
- MutableObject<DataResult<Builder<Brain.MemoryValue<?>>>> mutableObject = new MutableObject<>(DataResult.success(ImmutableList.builder()));
+ MutableObject<DataResult<Builder<Brain.MemoryValue<?>>>> decode_mutableObject = new MutableObject<>(DataResult.success(ImmutableList.builder())); // JettPack - decomp fix
mapLike.entries().forEach((pair) -> {
DataResult<MemoryModuleType<?>> dataResult = Registry.MEMORY_MODULE_TYPE.byNameCodec().parse(dynamicOps, pair.getFirst());
DataResult<? extends Brain.MemoryValue<?>> dataResult2 = dataResult.flatMap((memoryModuleType) -> {
return this.captureRead(memoryModuleType, dynamicOps, (T)pair.getSecond());
});
- mutableObject.setValue(mutableObject.getValue().apply2(Builder::add, dataResult2));
+ decode_mutableObject.setValue(decode_mutableObject.getValue().apply2(Builder::add, dataResult2)); // JettPack - decomp fix
});
- ImmutableList<Brain.MemoryValue<?>> immutableList = mutableObject.getValue().resultOrPartial(Brain.LOGGER::error).map(Builder::build).orElseGet(ImmutableList::of);
- return DataResult.success(new Brain<>(memoryModules, sensors, immutableList, mutableObject::getValue));
+ ImmutableList<Brain.MemoryValue<?>> immutableList = decode_mutableObject.getValue().resultOrPartial(Brain.LOGGER::error).map(Builder::build).orElseGet(ImmutableList::of); // JettPack - decomp fix
+ return DataResult.success(new Brain<E>(memoryModules, sensors, immutableList, mutableObject::getValue)); // JettPack - decomp fix
}
private <T, U> DataResult<Brain.MemoryValue<U>> captureRead(MemoryModuleType<U> memoryModuleType, DynamicOps<T> dynamicOps, T object) {
@@ -126,6 +140,7 @@ public class Brain<E extends LivingEntity> {
for(Brain.MemoryValue<?> memoryValue : memoryEntries) {
memoryValue.setMemoryInternal(this);
}
+ this.tasksSorted = new ArrayList<>(this.availableBehaviorsByPriority.values()); // JettPack - lithium: collections.brain
}
@@ -135,7 +150,7 @@ public class Brain<E extends LivingEntity> {
Stream<Brain.MemoryValue<?>> memories() {
return this.memories.entrySet().stream().map((entry) -> {
- return Brain.MemoryValue.createUnchecked(entry.getKey(), entry.getValue());
+ return Brain.MemoryValue.createUnchecked((MemoryModuleType)entry.getKey(), (Optional)entry.getValue()); // JettPack - decomp fix
});
}
@@ -164,14 +179,19 @@ public class Brain<E extends LivingEntity> {
if (memory.isPresent() && this.isEmptyCollection(memory.get().getValue())) {
this.eraseMemory(type);
} else {
- this.memories.put(type, memory);
+ // JettPack start - lithium: ai.task.memory_change_counting
+ Object oldValue = this.memories.put(type, memory);
+ if (oldValue == null || ((Optional<?>) oldValue).isPresent() != ((Optional<?>) memory).isPresent()) {
+ this.memoryModCount++;
+ }
+ // JettPack end
}
}
}
public <U> Optional<U> getMemory(MemoryModuleType<U> type) {
- return this.memories.get(type).map(ExpirableValue::getValue);
+ return ((Optional)this.memories.get(type)).map(object -> ((ExpirableValue)object).getValue()); // JettPack - decomp fix
}
public <U> long getTimeUntilExpiry(MemoryModuleType<U> type) {
@@ -322,6 +342,7 @@ public class Brain<E extends LivingEntity> {
public void addActivity(Activity activity, ImmutableList<? extends Pair<Integer, ? extends Behavior<? super E>>> indexedTasks) {
this.addActivityAndRemoveMemoriesWhenStopped(activity, indexedTasks, ImmutableSet.of(), Sets.newHashSet());
+ this.tasksSorted = new ArrayList<>(this.availableBehaviorsByPriority.values()); // JettPack - lithium: collections.brain
}
public void addActivityWithConditions(Activity activity, ImmutableList<? extends Pair<Integer, ? extends Behavior<? super E>>> indexedTasks, Set<Pair<MemoryModuleType<?>, MemoryStatus>> requiredMemories) {
@@ -347,6 +368,7 @@ public class Brain<E extends LivingEntity> {
@VisibleForTesting
public void removeAllBehaviors() {
this.availableBehaviorsByPriority.clear();
+ this.tasksSorted = new ArrayList<>(this.availableBehaviorsByPriority.values()); // JettPack - lithium: collections.brain
}
public boolean isActive(Activity activity) {
@@ -354,7 +376,7 @@ public class Brain<E extends LivingEntity> {
}
public Brain<E> copyWithoutBehaviors() {
- Brain<E> brain = new Brain<>(this.memories.keySet(), this.sensors.keySet(), ImmutableList.of(), this.codec);
+ Brain<E> brain = new Brain<E>(this.memories.keySet(), this.sensors. keySet(), ImmutableList.of(), this.codec); // JettPack - decomp fix
for(Entry<MemoryModuleType<?>, Optional<? extends ExpirableValue<?>>> entry : this.memories.entrySet()) {
MemoryModuleType<?> memoryModuleType = entry.getKey();
@@ -405,7 +427,7 @@ public class Brain<E extends LivingEntity> {
private void startEachNonRunningBehavior(ServerLevel world, E entity) {
long l = world.getGameTime();
- for(Map<Activity, Set<Behavior<? super E>>> map : this.availableBehaviorsByPriority.values()) {
+ for(Map<Activity, Set<Behavior<? super E>>> map : this.tasksSorted) { // JettPack - lithium: collections.brain
for(Entry<Activity, Set<Behavior<? super E>>> entry : map.entrySet()) {
Activity activity = entry.getKey();
if (this.activeActivities.contains(activity)) {
@@ -464,8 +486,8 @@ public class Brain<E extends LivingEntity> {
private final MemoryModuleType<U> type;
private final Optional<? extends ExpirableValue<U>> value;
- static <U> Brain.MemoryValue<U> createUnchecked(MemoryModuleType<U> type, Optional<? extends ExpirableValue<?>> data) {
- return new Brain.MemoryValue<>(type, data);
+ static <U> Brain.MemoryValue<U> createUnchecked(MemoryModuleType<U> type, Optional<? extends ExpirableValue<U>> data) { // JettPack - decomp fix
+ return new Brain.MemoryValue<U>(type, data); // JettPack - decomp fix
}
MemoryValue(MemoryModuleType<U> type, Optional<? extends ExpirableValue<U>> data) {
diff --git a/src/main/java/net/minecraft/world/entity/ai/behavior/Behavior.java b/src/main/java/net/minecraft/world/entity/ai/behavior/Behavior.java
index c24ff2ef1054523e58892c2b35080cffb6ab744a..2238e662f0c418548e51c3ec122106b7966921f1 100644
--- a/src/main/java/net/minecraft/world/entity/ai/behavior/Behavior.java
+++ b/src/main/java/net/minecraft/world/entity/ai/behavior/Behavior.java
@@ -6,6 +6,13 @@ import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.ai.memory.MemoryModuleType;
import net.minecraft.world.entity.ai.memory.MemoryStatus;
+// JettPack start
+import it.unimi.dsi.fastutil.objects.Reference2ObjectMap;
+import it.unimi.dsi.fastutil.objects.ObjectIterator;
+import it.unimi.dsi.fastutil.objects.Reference2ObjectMap;
+import it.unimi.dsi.fastutil.objects.Reference2ObjectOpenHashMap;
+import net.minecraft.world.entity.ai.Brain;
+// JettPack end
public abstract class Behavior<E extends LivingEntity> {
private static final int DEFAULT_DURATION = 60;
@@ -27,10 +34,15 @@ public abstract class Behavior<E extends LivingEntity> {
this(requiredMemoryState, runTime, runTime);
}
+ // JettPack start - lithium: ai.task.memory_change_counting
+ private long cachedMemoryModCount;
+ private boolean cachedHasRequiredMemoryState;
+ // JettPack end
+
public Behavior(Map<MemoryModuleType<?>, MemoryStatus> requiredMemoryState, int minRunTime, int maxRunTime) {
this.minDuration = minRunTime;
this.maxDuration = maxRunTime;
- this.entryCondition = requiredMemoryState;
+ this.entryCondition = new Reference2ObjectOpenHashMap<>(requiredMemoryState); // JettPack - lithium: ai.task.memory_change_counting
// Paper start - configurable behavior tick rate and timings
String key = io.papermc.paper.util.ObfHelper.INSTANCE.deobfClassName(this.getClass().getName());
int lastSeparator = key.lastIndexOf('.');
@@ -109,15 +121,24 @@ public abstract class Behavior<E extends LivingEntity> {
}
private boolean hasRequiredMemories(E entity) {
- for(Entry<MemoryModuleType<?>, MemoryStatus> entry : this.entryCondition.entrySet()) {
- MemoryModuleType<?> memoryModuleType = entry.getKey();
- MemoryStatus memoryStatus = entry.getValue();
- if (!entity.getBrain().checkMemory(memoryModuleType, memoryStatus)) {
- return false;
+ // JettPack start - lithium: ai.task.memory_change_counting
+ Brain<?> brain = entity.getBrain();
+ long modCount = brain.getModCount();
+ if (this.cachedMemoryModCount == modCount) {
+ return this.cachedHasRequiredMemoryState;
+ }
+ this.cachedMemoryModCount = modCount;
+
+ ObjectIterator<Reference2ObjectMap.Entry<MemoryModuleType<?>, MemoryStatus>> fastIterator = ((Reference2ObjectOpenHashMap<MemoryModuleType<?>, MemoryStatus>) this.entryCondition).reference2ObjectEntrySet().fastIterator();
+ while (fastIterator.hasNext()) {
+ Reference2ObjectMap.Entry<MemoryModuleType<?>, MemoryStatus> entry = fastIterator.next();
+ if (!brain.checkMemory(entry.getKey(), entry.getValue())) {
+ return this.cachedHasRequiredMemoryState = false;
}
}
- return true;
+ return this.cachedHasRequiredMemoryState = true;
+ // JettPack end
}
public static enum Status {

View File

@@ -0,0 +1,230 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: 2No2Name <2No2Name@web.de>
Date: Tue, 11 Jan 2022 15:28:32 -0500
Subject: [PATCH] lithium: ai.brain
Original code by CaffeineMC, licensed under GNU Lesser General Public License v3.0
You can find the original code on https://github.com/CaffeineMC/lithium-fabric (Yarn mappings)
diff --git a/src/main/java/me/jellysquid/mods/lithium/common/util/collections/MaskedList.java b/src/main/java/me/jellysquid/mods/lithium/common/util/collections/MaskedList.java
new file mode 100644
index 0000000000000000000000000000000000000000..06399c159c8b779bb65149704490671e0c04d4c2
--- /dev/null
+++ b/src/main/java/me/jellysquid/mods/lithium/common/util/collections/MaskedList.java
@@ -0,0 +1,87 @@
+package me.jellysquid.mods.lithium.common.util.collections;
+
+import it.unimi.dsi.fastutil.objects.ObjectArrayList;
+
+import java.util.*;
+import java.util.function.Consumer;
+
+public class MaskedList<E> extends AbstractList<E> {
+ private final ObjectArrayList<E> allElements;
+ private final BitSet visibleMask;
+
+ public MaskedList(ObjectArrayList<E> allElements) {
+ this.allElements = allElements;
+ this.visibleMask = new BitSet();
+ }
+
+ public void setVisible(E element, final boolean visible) {
+ int i = -1;
+ if (visible) {
+ do {
+ i = this.visibleMask.nextClearBit(i + 1);
+ } while (element != this.allElements.get(i));
+ this.visibleMask.set(i);
+ } else {
+ do {
+ i = this.visibleMask.nextSetBit(i + 1);
+ } while (element != this.allElements.get(i));
+ this.visibleMask.clear(i);
+ }
+ }
+
+ @Override
+ public Iterator<E> iterator() {
+ return new Iterator<E>() {
+ int nextIndex = 0;
+
+ @Override
+ public boolean hasNext() {
+ return MaskedList.this.visibleMask.nextSetBit(this.nextIndex) != -1;
+ }
+
+ @Override
+ public E next() {
+ int index = MaskedList.this.visibleMask.nextSetBit(this.nextIndex);
+ this.nextIndex = index + 1;
+ return MaskedList.this.allElements.get(index);
+ }
+ };
+ }
+
+ @Override
+ public Spliterator<E> spliterator() {
+ return new Spliterators.AbstractSpliterator<E>(Long.MAX_VALUE, Spliterator.ORDERED | Spliterator.NONNULL) {
+ int nextIndex = 0;
+
+ @Override
+ public boolean tryAdvance(Consumer<? super E> action) {
+ int index = MaskedList.this.visibleMask.nextSetBit(this.nextIndex);
+ if (index == -1) {
+ return false;
+ }
+ this.nextIndex = index + 1;
+ action.accept(MaskedList.this.allElements.get(index));
+ return true;
+ }
+ };
+ }
+
+ @Override
+ public E get(int index) {
+ if (index < 0 || index >= this.size()) {
+ throw new IndexOutOfBoundsException(index);
+ }
+
+ int i = 0;
+ while (index >= 0) {
+ index--;
+ i = this.visibleMask.nextSetBit(i + 1);
+ }
+ return this.allElements.get(i);
+ }
+
+ @Override
+ public int size() {
+ return this.visibleMask.cardinality();
+ }
+}
diff --git a/src/main/java/net/minecraft/world/entity/ai/Brain.java b/src/main/java/net/minecraft/world/entity/ai/Brain.java
index 8179f5bc2bcd5ddb46e790b6e906ea9a517ed5b0..500a0e8505c181fa61d1b0c173bac03cd38d9616 100644
--- a/src/main/java/net/minecraft/world/entity/ai/Brain.java
+++ b/src/main/java/net/minecraft/world/entity/ai/Brain.java
@@ -44,6 +44,7 @@ import org.apache.logging.log4j.Logger;
import it.unimi.dsi.fastutil.objects.Reference2ReferenceLinkedOpenHashMap;
import it.unimi.dsi.fastutil.objects.Reference2ReferenceOpenHashMap;
import java.util.ArrayList;
+import me.jellysquid.mods.lithium.common.util.collections.MaskedList;
// JettPack end
public class Brain<E extends LivingEntity> {
@@ -55,6 +56,7 @@ public class Brain<E extends LivingEntity> {
private final Map<SensorType<? extends Sensor<? super E>>, Sensor<? super E>> sensors = new Reference2ReferenceLinkedOpenHashMap<>();
private ArrayList<Map<Activity, Set<Behavior<? super E>>>> tasksSorted = new ArrayList<>();
// JettPack end
+ private MaskedList<Behavior<? super E>> flatTasks; // JettPack - lithium: ai.brain
private final Map<Integer, Map<Activity, Set<Behavior<? super E>>>> availableBehaviorsByPriority = Maps.newTreeMap();
private Schedule schedule = Schedule.EMPTY;
private final Map<Activity, Set<Pair<MemoryModuleType<?>, MemoryStatus>>> activityRequirements = Maps.newHashMap();
@@ -74,6 +76,22 @@ public class Brain<E extends LivingEntity> {
}
// JettPack end
+ // JettPack start - ai.brain
+ private void initTaskList() {
+ ObjectArrayList<Behavior<? super E>> list = new ObjectArrayList<>();
+
+ for (Map<Activity, Set<Behavior<? super E>>> map : this.availableBehaviorsByPriority.values()) {
+ for (Set<Behavior<? super E>> set : map.values()) {
+ for (Behavior<? super E> task : set) {
+ //noinspection UseBulkOperation
+ list.add(task);
+ }
+ }
+ }
+ this.flatTasks = new MaskedList<>(list);
+ }
+ // JettPack end
+
public static <E extends LivingEntity> Codec<Brain<E>> codec(Collection<? extends MemoryModuleType<?>> memoryModules, Collection<? extends SensorType<? extends Sensor<? super E>>> sensors) {
final MutableObject<Codec<Brain<E>>> mutableObject = new MutableObject<>();
mutableObject.setValue((new MapCodec<Brain<E>>() {
@@ -141,7 +159,7 @@ public class Brain<E extends LivingEntity> {
memoryValue.setMemoryInternal(this);
}
this.tasksSorted = new ArrayList<>(this.availableBehaviorsByPriority.values()); // JettPack - lithium: collections.brain
-
+ this.flatTasks = null; // JettPack - lithium: ai.brain
}
public <T> DataResult<T> serializeStart(DynamicOps<T> ops) {
@@ -244,19 +262,12 @@ public class Brain<E extends LivingEntity> {
@Deprecated
@VisibleForDebug
public List<Behavior<? super E>> getRunningBehaviors() {
- List<Behavior<? super E>> list = new ObjectArrayList<>();
-
- for(Map<Activity, Set<Behavior<? super E>>> map : this.availableBehaviorsByPriority.values()) {
- for(Set<Behavior<? super E>> set : map.values()) {
- for(Behavior<? super E> behavior : set) {
- if (behavior.getStatus() == Behavior.Status.RUNNING) {
- list.add(behavior);
- }
- }
- }
+ // JettPack start - lithium: ai.brain
+ if (this.flatTasks == null) {
+ this.initTaskList();
}
-
- return list;
+ return this.flatTasks;
+ // JettPack end
}
public void useDefaultActivity() {
@@ -369,6 +380,7 @@ public class Brain<E extends LivingEntity> {
public void removeAllBehaviors() {
this.availableBehaviorsByPriority.clear();
this.tasksSorted = new ArrayList<>(this.availableBehaviorsByPriority.values()); // JettPack - lithium: collections.brain
+ this.flatTasks = null; // JettPack - lithium: ai.brain
}
public boolean isActive(Activity activity) {
@@ -419,7 +431,13 @@ public class Brain<E extends LivingEntity> {
long l = entity.level.getGameTime();
for(Behavior<? super E> behavior : this.getRunningBehaviors()) {
+ // JettPack start - lithium: ai.brain
behavior.doStop(world, entity, l);
+ if (this.flatTasks == null) {
+ this.initTaskList();
+ }
+ this.flatTasks.setVisible(behavior, false);
+ // JettPack end
}
}
@@ -434,6 +452,14 @@ public class Brain<E extends LivingEntity> {
for(Behavior<? super E> behavior : entry.getValue()) {
if (behavior.getStatus() == Behavior.Status.STOPPED) {
behavior.tryStart(world, entity, l);
+ // JettPack start - lithium: ai.brain
+ if (behavior.getStatus() == Behavior.Status.RUNNING) {
+ if (this.flatTasks == null) {
+ this.initTaskList();
+ }
+ this.flatTasks.setVisible(behavior, true);
+ }
+ // JettPack end
}
}
}
@@ -447,6 +473,14 @@ public class Brain<E extends LivingEntity> {
for(Behavior<? super E> behavior : this.getRunningBehaviors()) {
behavior.tickOrStop(world, entity, l);
+ // JettPack start - lithium: ai.brain
+ if (behavior.getStatus() != Behavior.Status.RUNNING) {
+ if (this.flatTasks == null) {
+ this.initTaskList();
+ }
+ this.flatTasks.setVisible(behavior, false);
+ }
+ // JettPack end
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,82 @@
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 d8baa239c8cec5a67e30e4756ef37d47f4e6e367..5927315477992dd32b6cdc283d0e84dc500ebf37 100644
--- a/src/main/java/net/minecraft/world/entity/Entity.java
+++ b/src/main/java/net/minecraft/world/entity/Entity.java
@@ -1773,10 +1773,16 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, i
}
}
+ // JettPack start - allow passing BlockPos to getBrightness
public float getBrightness() {
- return this.level.hasChunkAt(this.getBlockX(), this.getBlockZ()) ? this.level.getBrightness(new BlockPos(this.getX(), this.getEyeY(), this.getZ())) : 0.0F;
+ return this.getBrightness(new BlockPos(this.getX(), this.getEyeY(), this.getZ()));
}
+ public float getBrightness(BlockPos pos) {
+ return this.level.hasChunkAt(this.getBlockX(), this.getBlockZ()) ? this.level.getBrightness(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);
@@ -4142,6 +4148,12 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, i
return this.getZ((2.0D * this.random.nextDouble() - 1.0D) * widthScale);
}
+ // 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 0e2b3d889953fcc2ff012d923d12cd9afc109776..759bef4e466eeea020c09f653ad971b3c9640e7b 100644
--- a/src/main/java/net/minecraft/world/entity/Mob.java
+++ b/src/main/java/net/minecraft/world/entity/Mob.java
@@ -1617,15 +1617,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.getBrightness();
- 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.getBrightness(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;