net/minecraft/world/entity/ai/sensing (but, actually)

This commit is contained in:
Shane Freeder 2024-12-14 18:42:28 +00:00
parent e90ba22ef7
commit a890e322f1
No known key found for this signature in database
GPG key ID: A3F61EA5A085289C
2 changed files with 20 additions and 30 deletions

View file

@ -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);
}

View file

@ -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<PathfinderMob> {
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<net.minecraft.server.level.ServerPlayer> 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<ItemStack> 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);
}