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 --- a/net/minecraft/world/entity/ai/sensing/Sensor.java
+++ b/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(); .ignoreInvisibilityTesting();
private final int scanRate; private final int scanRate;
private long timeToTick; private long timeToTick;
@ -8,7 +8,7 @@
+ private final String configKey; + private final String configKey;
+ // Paper end + // Paper end
public Sensor(int senseInterval) { public Sensor(int scanRate) {
+ // Paper start - configurable sensor tick rate and timings + // 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(); + 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('.'); + int lastSeparator = key.lastIndexOf('.');
@ -17,18 +17,17 @@
+ } + }
+ this.configKey = key.toLowerCase(java.util.Locale.ROOT); + this.configKey = key.toLowerCase(java.util.Locale.ROOT);
+ // Paper end + // Paper end
this.scanRate = senseInterval; this.scanRate = scanRate;
this.timeToTick = (long)RANDOM.nextInt(senseInterval); 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) { if (--this.timeToTick <= 0L) {
- this.timeToTick = (long)this.scanRate; - this.timeToTick = this.scanRate;
+ // Paper start - configurable sensor tick rate and timings + // 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.timeToTick = java.util.Objects.requireNonNullElse(level.paperConfig().tickRates.sensor.get(entity.getType(), this.configKey), this.scanRate);
this.updateTargetingConditionRanges(entity);
+ // Paper end + // 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 --- a/net/minecraft/world/entity/ai/sensing/TemptingSensor.java
+++ b/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.entity.player.Player;
import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.ItemStack;
@ -13,33 +13,24 @@
+// CraftBukkit end +// CraftBukkit end
+ +
public class TemptingSensor extends Sensor<PathfinderMob> { public class TemptingSensor extends Sensor<PathfinderMob> {
private static final TargetingConditions TEMPT_TARGETING = TargetingConditions.forNonCombat().ignoreLineOfSight(); private static final TargetingConditions TEMPT_TARGETING = TargetingConditions.forNonCombat().ignoreLineOfSight();
@@ -31,7 +39,7 @@ private final Predicate<ItemStack> temptations;
protected void doTick(ServerLevel world, PathfinderMob entity) { @@ -38,7 +_,17 @@
Brain<?> behaviorcontroller = entity.getBrain(); .collect(Collectors.toList());
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 @@
if (!list.isEmpty()) { if (!list.isEmpty()) {
Player entityhuman = (Player) list.get(0); Player player = list.get(0);
- brain.setMemory(MemoryModuleType.TEMPTING_PLAYER, player);
- behaviorcontroller.setMemory(MemoryModuleType.TEMPTING_PLAYER, (Object) entityhuman);
+ // CraftBukkit start + // CraftBukkit start
+ EntityTargetLivingEntityEvent event = CraftEventFactory.callEntityTargetLivingEvent(entity, entityhuman, EntityTargetEvent.TargetReason.TEMPT); + EntityTargetLivingEntityEvent event = CraftEventFactory.callEntityTargetLivingEvent(entity, player, EntityTargetEvent.TargetReason.TEMPT);
+ if (event.isCancelled()) { + if (event.isCancelled()) {
+ return; + return;
+ } + }
+ if (event.getTarget() instanceof HumanEntity) { + if (event.getTarget() instanceof HumanEntity) {
+ behaviorcontroller.setMemory(MemoryModuleType.TEMPTING_PLAYER, ((CraftHumanEntity) event.getTarget()).getHandle()); + brain.setMemory(MemoryModuleType.TEMPTING_PLAYER, ((CraftHumanEntity) event.getTarget()).getHandle());
+ } else { + } else {
+ behaviorcontroller.eraseMemory(MemoryModuleType.TEMPTING_PLAYER); + brain.eraseMemory(MemoryModuleType.TEMPTING_PLAYER);
+ } + }
+ // CraftBukkit end + // CraftBukkit end
} else { } else {
behaviorcontroller.eraseMemory(MemoryModuleType.TEMPTING_PLAYER); brain.eraseMemory(MemoryModuleType.TEMPTING_PLAYER);
} }