From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Martijn Muijsers Date: Wed, 23 Nov 2022 20:12:48 +0100 Subject: [PATCH] Reduce acquire POI for stuck entities License: GPL-3.0 (https://www.gnu.org/licenses/gpl-3.0.html) Gale - https://galemc.org This patch is based on the following patch: "Skip POI finding if stuck in vehicle" By: Paul Sauve As part of: Airplane (https://github.com/TECHNOVE/Airplane) Licensed under: GPL-3.0 (https://www.gnu.org/licenses/gpl-3.0.html) * Airplane copyright * Airplane Copyright (C) 2020 Technove LLC This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . diff --git a/src/main/java/net/minecraft/world/entity/ai/behavior/AcquirePoi.java b/src/main/java/net/minecraft/world/entity/ai/behavior/AcquirePoi.java index d4c91e0a0c64fcb7f1145de3f30134cb1f1f8ee6..aed7e9affaae1e0d1e3324a41e5818435f76fd0f 100644 --- a/src/main/java/net/minecraft/world/entity/ai/behavior/AcquirePoi.java +++ b/src/main/java/net/minecraft/world/entity/ai/behavior/AcquirePoi.java @@ -13,6 +13,7 @@ import net.minecraft.core.BlockPos; import net.minecraft.core.GlobalPos; import net.minecraft.core.Holder; import net.minecraft.network.protocol.game.DebugPackets; +import net.minecraft.server.level.ServerLevel; import net.minecraft.util.RandomSource; import net.minecraft.world.entity.Mob; import net.minecraft.world.entity.PathfinderMob; @@ -26,6 +27,13 @@ import org.apache.commons.lang3.mutable.MutableLong; public class AcquirePoi { public static final int SCAN_RANGE = 48; + // Gale start - Airplane - reduce acquire POI for stuck entities + public static void addAdditionalTimeToMutableLongIfEntityIsStuck(MutableLong mutableLong, ServerLevel world, PathfinderMob entity) { + long stuckEntityAdditionalWaitTime = world.galeConfig().smallOptimizations.reducedIntervals.acquirePoiForStuckEntity; + mutableLong.add(stuckEntityAdditionalWaitTime <= 0L ? 0L : entity.getNavigation().isStuck() ? stuckEntityAdditionalWaitTime : 0L); + } + // Gale end - Airplane - reduce acquire POI for stuck entities + public static BehaviorControl create(Predicate> poiPredicate, MemoryModuleType poiPosModule, boolean onlyRunIfChild, Optional entityStatus) { return create(poiPredicate, poiPosModule, poiPosModule, onlyRunIfChild, entityStatus); } @@ -42,11 +50,13 @@ public class AcquirePoi { return false; } else if (mutableLong.getValue() == 0L) { mutableLong.setValue(world.getGameTime() + (long)world.random.nextInt(20)); + addAdditionalTimeToMutableLongIfEntityIsStuck(mutableLong, world, entity); // Gale - Airplane - reduce acquire POI for stuck entities return false; } else if (world.getGameTime() < mutableLong.getValue()) { return false; } else { mutableLong.setValue(time + 20L + (long)world.getRandom().nextInt(20)); + addAdditionalTimeToMutableLongIfEntityIsStuck(mutableLong, world, entity); // Gale - Airplane - reduce acquire POI for stuck entities PoiManager poiManager = world.getPoiManager(); long2ObjectMap.long2ObjectEntrySet().removeIf((entry) -> { return !entry.getValue().isStillValid(time); diff --git a/src/main/java/org/galemc/gale/configuration/GaleWorldConfiguration.java b/src/main/java/org/galemc/gale/configuration/GaleWorldConfiguration.java index a83675d8d2f94a8e73cc2c7fa11d0aaf6f78be2c..b993c2276d14c0a384898e9705a1af6fa6d585cf 100644 --- a/src/main/java/org/galemc/gale/configuration/GaleWorldConfiguration.java +++ b/src/main/java/org/galemc/gale/configuration/GaleWorldConfiguration.java @@ -83,6 +83,26 @@ public class GaleWorldConfiguration extends ConfigurationPart { } // Gale end - Airplane - reduce projectile chunk loading + public ReducedIntervals reducedIntervals; + public class ReducedIntervals extends ConfigurationPart { + + // Gale start - Airplane - reduce acquire POI for stuck entities + /** + * Extra interval (on top of the regular interval) + * for entities that are stuck (e.g. in a vehicle) to attempt to acquire a POI. + * If they become unstuck during this time, they will immediately be free to acquire a POI again. + * Given in ticks. + * Any value < 0 behaves like 0. + *
    + *
  • Default: 200 (10 seconds)
  • + *
  • Vanilla: 0
  • + *
+ */ + public int acquirePoiForStuckEntity = 200; + // Gale end - Airplane - reduce acquire POI for stuck entities + + } + } }