mirror of
https://github.com/Winds-Studio/Leaf.git
synced 2025-12-28 19:39:17 +00:00
* Fix TE Lag * Sepals Rearrange the attackable conditions * Cache ItemStack max stack size * fix build * extra: Skip dirty stats copy when requesting player stats * extra: Reset dirty flag when loading maps from the disk * extra: Supporting block cache * extra: Avoid useless deque clear on - credit: @MachineBreaker * experimental/draft: Optimize SortedArraySet * experimental/draft: Simplify SortedArraySet - sometime complex stuff doesnt mean faster. * extra: Change maps/sets in brain + remove streams from villagers * extra: Remove 'copyOf' from Baby Villager Sensor * experimental: Rewrite trigger in SimpleCriterionTrigger * [ci/skip] fix comments * Faster setter for SimpleCriterionTrigger * extra: Cache and optimize fluidOnEyes * Sync changes * [ci/skip] cleanup * extra: QuadTree implementation for isChunkNearPlayer * [ci/skip] cleanup * [ci/skip] cleanup * [ci/skip] clean up * [ci/skip] cleanup * Only player pushable * Store chunkPos with keys * [ci/skip] cleanup * [ci/skip] cleanup * cleanup * rebuild patches * cache some more stuff * extra: optimize collectTickingChunks * remove quadTree optimization for now (will open a new PR just for that) * temp: Lazily optimize isChunkNearPlayer * Inline filter & merge as a single loop * [ci/skip] Add diff on change * extra: optimize everything but the testing itself on getEntities * [ci/skip] cleanup * Optimize chunkUnloadQueue * Remove iterators from inventory * [ci/skip] Add TODOs * i hate programming * remove forEach * extra: Alternative Brain Behaviour * remove: opt getEntities + cache fluidOnEyes * extra: Improve checkDespawn - credits: @kidofcubes * extra: Improve pushEntity and getEntities * yeet this * VERY EXPERIMENTAL: getEntities Optimization * fix bunch of issues from getEntities patch * extra: slightly optimize getNearestPlayer - credits: @kidofcubes * drop a patch for now (will open a new pr) * move these to a new branch * fix and optimize checkDespawn patches * Rebuild Patches * [ci/skip] Update benchmark * [ci/skip] cleanup * Drop * [ci/skip] Drop * Rebuild * [ci/skip] * Add configurable brain running behavior cache update interval * Move to new pr * [ci/skip] Update benchmark --------- Co-authored-by: MachineBreaker <saltspigotpp@gmail.com> Co-authored-by: kidofcubes <kidofcubes@gmail.com> Co-authored-by: Dreeam <61569423+Dreeam-qwq@users.noreply.github.com>
72 lines
3.3 KiB
Diff
72 lines
3.3 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: cao-awa <cao.awa.www@gmail.com>
|
|
Date: Fri, 23 Aug 2024 00:23:32 +0800
|
|
Subject: [PATCH] Sepals: Rearrange the attackable conditions
|
|
|
|
Original license: GPLv3
|
|
Original project: https://github.com/cao-awa/Sepals
|
|
|
|
Rearrange the attackable conditions
|
|
let less costs predicate running first
|
|
reduce the probability of high-costs calculating
|
|
|
|
-- The complaints --
|
|
Mojang's attackable predicate is:
|
|
|
|
!entity.getBrain().hasMemoryModule(MemoryModuleType.HAS_HUNTING_COOLDOWN)
|
|
&& Sensor.testAttackableTargetPredicate(entity, target)
|
|
&& FrogEntity.isValidFrogFood(target)
|
|
&& !this.isTargetUnreachable(entity, target)
|
|
&& target.isInRange(entity, 10.0)
|
|
|
|
in this case, 'Sensor#testAttackableTargetPredicate' has calls 'TargetPredicate#test'
|
|
that cause a very lots raycast calculate when entities too much in the area
|
|
but... minecraft's raycast is absolutely bad, very slow
|
|
|
|
the 'TargetPredicate#test' in this case (800 frogs) has make 9.8ms costs in once game tick
|
|
among them, 'BlockView.raycast' contributed 7.3ms
|
|
|
|
then i make it be:
|
|
|
|
FrogEntity.isValidFrogFood(target) &&
|
|
entity.getBrain().hasMemoryModule(MemoryModuleType.HAS_HUNTING_COOLDOWN) &&
|
|
target.isInRange(entity, 10.0) &&
|
|
Sensor.testAttackableTargetPredicate(entity, target) &&
|
|
isTargetUnreachable(entity, target);
|
|
|
|
the 'isValidFrogFood' is simple conditions, check the entity's tag has in 'frog_food'
|
|
and a extra check when entity is slime then skip it when it size not 1
|
|
|
|
the 'isInRange' and 'hasMemoryModule' also simple, it only a few math calculates
|
|
|
|
Test Result:
|
|
800 frogs cramming in a 7x7 space:
|
|
|
|
| Environment | time | Percent(Avg.) |
|
|
|-------------------------------------------------:|:------:|:-------------:|
|
|
| Vanilla (FrogAttackablesSensor#matches) | 10 ms | 100 % |
|
|
| With Lithium (FrogAttackablesSensor#matches) | 5.7 ms | 57 % |
|
|
| With Sepals (SepalsFrogBrain#attackable) | 0.1 ms | 1 % |
|
|
| With Sepals+Lithium (SepalsFrogBrain#attackable) | 0.1 ms | 1 % |
|
|
|
|
diff --git a/net/minecraft/world/entity/ai/sensing/FrogAttackablesSensor.java b/net/minecraft/world/entity/ai/sensing/FrogAttackablesSensor.java
|
|
index d163a363273b52b3b3f0b5a74ac4d4ab37d24bb7..e88479ba1ebeff67a93baad4f6f8c83119ff5ff7 100644
|
|
--- a/net/minecraft/world/entity/ai/sensing/FrogAttackablesSensor.java
|
|
+++ b/net/minecraft/world/entity/ai/sensing/FrogAttackablesSensor.java
|
|
@@ -13,11 +13,11 @@ public class FrogAttackablesSensor extends NearestVisibleLivingEntitySensor {
|
|
|
|
@Override
|
|
protected boolean isMatchingEntity(ServerLevel level, LivingEntity entity, LivingEntity target) {
|
|
- return !entity.getBrain().hasMemoryValue(MemoryModuleType.HAS_HUNTING_COOLDOWN)
|
|
+ return Frog.canEat(target)
|
|
+ && !entity.getBrain().hasMemoryValue(MemoryModuleType.HAS_HUNTING_COOLDOWN)
|
|
+ && target.closerThan(entity, 10.0)
|
|
&& Sensor.isEntityAttackable(level, entity, target)
|
|
- && Frog.canEat(target)
|
|
- && !this.isUnreachableAttackTarget(entity, target)
|
|
- && target.closerThan(entity, 10.0);
|
|
+ && !this.isUnreachableAttackTarget(entity, target); // Sepals - Rearrange the attackable conditions
|
|
}
|
|
|
|
private boolean isUnreachableAttackTarget(LivingEntity attacker, LivingEntity target) {
|