From a890e322f104865c85f25f924b7c9a4a7ad7de42 Mon Sep 17 00:00:00 2001 From: Shane Freeder Date: Sat, 14 Dec 2024 18:42:28 +0000 Subject: [PATCH] net/minecraft/world/entity/ai/sensing (but, actually) --- .../world/entity/ai/sensing/Sensor.java.patch | 21 +++++++------- .../ai/sensing/TemptingSensor.java.patch | 29 +++++++------------ 2 files changed, 20 insertions(+), 30 deletions(-) diff --git a/paper-server/patches/sources/net/minecraft/world/entity/ai/sensing/Sensor.java.patch b/paper-server/patches/sources/net/minecraft/world/entity/ai/sensing/Sensor.java.patch index 7d220911a0..a052e1e5a2 100644 --- a/paper-server/patches/sources/net/minecraft/world/entity/ai/sensing/Sensor.java.patch +++ b/paper-server/patches/sources/net/minecraft/world/entity/ai/sensing/Sensor.java.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/entity/ai/sensing/Sensor.java +++ b/net/minecraft/world/entity/ai/sensing/Sensor.java -@@ -29,8 +29,19 @@ +@@ -29,8 +_,19 @@ .ignoreInvisibilityTesting(); private final int scanRate; private long timeToTick; @@ -8,7 +8,7 @@ + private final String configKey; + // Paper end - public Sensor(int senseInterval) { + public Sensor(int scanRate) { + // Paper start - configurable sensor tick rate and timings + String key = io.papermc.paper.util.MappingEnvironment.reobf() ? io.papermc.paper.util.ObfHelper.INSTANCE.deobfClassName(this.getClass().getName()) : this.getClass().getName(); + int lastSeparator = key.lastIndexOf('.'); @@ -17,18 +17,17 @@ + } + this.configKey = key.toLowerCase(java.util.Locale.ROOT); + // Paper end - this.scanRate = senseInterval; - this.timeToTick = (long)RANDOM.nextInt(senseInterval); + this.scanRate = scanRate; + this.timeToTick = RANDOM.nextInt(scanRate); } -@@ -41,8 +52,10 @@ +@@ -41,7 +_,9 @@ - public final void tick(ServerLevel world, E entity) { + public final void tick(ServerLevel level, E entity) { if (--this.timeToTick <= 0L) { -- this.timeToTick = (long)this.scanRate; +- this.timeToTick = this.scanRate; + // Paper start - configurable sensor tick rate and timings -+ this.timeToTick = java.util.Objects.requireNonNullElse(world.paperConfig().tickRates.sensor.get(entity.getType(), this.configKey), this.scanRate); - this.updateTargetingConditionRanges(entity); ++ this.timeToTick = java.util.Objects.requireNonNullElse(level.paperConfig().tickRates.sensor.get(entity.getType(), this.configKey), this.scanRate); + // Paper end - this.doTick(world, entity); + this.updateTargetingConditionRanges(entity); + this.doTick(level, entity); } - } diff --git a/paper-server/patches/sources/net/minecraft/world/entity/ai/sensing/TemptingSensor.java.patch b/paper-server/patches/sources/net/minecraft/world/entity/ai/sensing/TemptingSensor.java.patch index 2bd53d40cd..7ec237343c 100644 --- a/paper-server/patches/sources/net/minecraft/world/entity/ai/sensing/TemptingSensor.java.patch +++ b/paper-server/patches/sources/net/minecraft/world/entity/ai/sensing/TemptingSensor.java.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/entity/ai/sensing/TemptingSensor.java +++ b/net/minecraft/world/entity/ai/sensing/TemptingSensor.java -@@ -19,6 +19,14 @@ +@@ -16,6 +_,14 @@ import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.ItemStack; @@ -13,33 +13,24 @@ +// CraftBukkit end + public class TemptingSensor extends Sensor { - private static final TargetingConditions TEMPT_TARGETING = TargetingConditions.forNonCombat().ignoreLineOfSight(); -@@ -31,7 +39,7 @@ - protected void doTick(ServerLevel world, PathfinderMob entity) { - Brain behaviorcontroller = entity.getBrain(); - TargetingConditions pathfindertargetcondition = TemptingSensor.TEMPT_TARGETING.copy().range((double) ((float) entity.getAttributeValue(Attributes.TEMPT_RANGE))); -- Stream stream = world.players().stream().filter(EntitySelector.NO_SPECTATORS).filter((entityplayer) -> { -+ Stream stream = world.players().stream().filter(EntitySelector.NO_SPECTATORS).filter((entityplayer) -> { // CraftBukkit - decompile error - return pathfindertargetcondition.test(world, entity, entityplayer); - }).filter(this::playerHoldingTemptation).filter((entityplayer) -> { - return !entity.hasPassenger((Entity) entityplayer); -@@ -43,7 +51,17 @@ + private final Predicate temptations; +@@ -38,7 +_,17 @@ + .collect(Collectors.toList()); if (!list.isEmpty()) { - Player entityhuman = (Player) list.get(0); - -- behaviorcontroller.setMemory(MemoryModuleType.TEMPTING_PLAYER, (Object) entityhuman); + Player player = list.get(0); +- brain.setMemory(MemoryModuleType.TEMPTING_PLAYER, player); + // CraftBukkit start -+ EntityTargetLivingEntityEvent event = CraftEventFactory.callEntityTargetLivingEvent(entity, entityhuman, EntityTargetEvent.TargetReason.TEMPT); ++ EntityTargetLivingEntityEvent event = CraftEventFactory.callEntityTargetLivingEvent(entity, player, EntityTargetEvent.TargetReason.TEMPT); + if (event.isCancelled()) { + return; + } + if (event.getTarget() instanceof HumanEntity) { -+ behaviorcontroller.setMemory(MemoryModuleType.TEMPTING_PLAYER, ((CraftHumanEntity) event.getTarget()).getHandle()); ++ brain.setMemory(MemoryModuleType.TEMPTING_PLAYER, ((CraftHumanEntity) event.getTarget()).getHandle()); + } else { -+ behaviorcontroller.eraseMemory(MemoryModuleType.TEMPTING_PLAYER); ++ brain.eraseMemory(MemoryModuleType.TEMPTING_PLAYER); + } + // CraftBukkit end } else { - behaviorcontroller.eraseMemory(MemoryModuleType.TEMPTING_PLAYER); + brain.eraseMemory(MemoryModuleType.TEMPTING_PLAYER); }