mirror of
https://github.com/Winds-Studio/Leaf.git
synced 2025-12-19 15:09:25 +00:00
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) {
|