mirror of
https://github.com/PaperMC/Paper.git
synced 2024-12-12 09:51:12 +01:00
77a5779e24
Upstream has released updates that appear to apply and compile correctly. This update has not been tested by PaperMC and as with ANY update, please do your own testing Bukkit Changes: 2ec53f49 PR-1050: Fix empty result check for Complex Recipes 10671012 PR-1044: Add CrafterCraftEvent 4d87ffe0 Use correct method in JavaDoc ae5e5817 SPIGOT-7850: Add API for Bogged shear state 46b6d445 SPIGOT-7837: Support data pack banner patterns d5d0cefc Fix JavaDoc error b3c2b83d PR-1036: Add API for InventoryView derivatives 1fe2c75a SPIGOT-7809: Add ShieldMeta CraftBukkit Changes: 8ee6fd1b8 SPIGOT-7857: Improve ItemMeta block data deserialization 8f26c30c6 SPIGOT-7857: Fix spurious internal NBT tag when deserializing BlockStateMeta 759061b93 SPIGOT-7855: Fire does not spread or burn blocks 00fc9fb64 SPIGOT-7853: AnvilInventory#getRepairCost() always returns 0 7501e2e04 PR-1450: Add CrafterCraftEvent 8c51673e7 SPIGOT-5731: PortalCreateEvent#getEntity returns null for nether portals ignited by flint and steel d53d0d0b1 PR-1456: Fix inverted logic in CraftCrafterView#setSlotDisabled 682a678c8 SPIGOT-7850: Add API for Bogged shear state fccf5243a SPIGOT-7837: Support data pack banner patterns 9c3bd4390 PR-1431: Add API for InventoryView derivatives 0cc6acbc4 SPIGOT-7849: Fix FoodComponent serialize with "using-converts-to" using null 2c5474952 Don't rely on tags for CraftItemMetas 20d107e46 SPIGOT-7846: Fix ItemMeta for hanging signs 76f59e315 Remove redundant clone in Dropper InventoryMoveItemEvent e61a53d25 SPIGOT-7817: Call InventoryMoveItemEvent for Crafters 894682e2d SPIGOT-7839: Remove redundant Java version checks 2c12b2187 SPIGOT-7809: Add ShieldMeta and fix setting shield base colours Spigot Changes: fb8fb722 Rebuild patches 34bd42b7 SPIGOT-7835: Fix issue with custom hopper settings
134 lines
6.9 KiB
Diff
134 lines
6.9 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: Phoenix616 <max@themoep.de>
|
|
Date: Mon, 28 Jun 2021 22:38:29 +0100
|
|
Subject: [PATCH] Rate options and timings for sensors and behaviors
|
|
|
|
This adds config options to specify the tick rate for sensors
|
|
and behaviors of different entity types as well as timings
|
|
for those in order to be able to have some metrics as to which
|
|
ones might need tweaking.
|
|
|
|
diff --git a/src/main/java/co/aikar/timings/MinecraftTimings.java b/src/main/java/co/aikar/timings/MinecraftTimings.java
|
|
index 4bd813161a5d76a83cdbd0a9209b9ea9e60ffe1b..e2764186bd6b838ed5cd86c15597a08d079ef984 100644
|
|
--- a/src/main/java/co/aikar/timings/MinecraftTimings.java
|
|
+++ b/src/main/java/co/aikar/timings/MinecraftTimings.java
|
|
@@ -115,6 +115,14 @@ public final class MinecraftTimings {
|
|
return Timings.ofSafe("Minecraft", "## tickEntity - " + entityType + " - " + type, tickEntityTimer);
|
|
}
|
|
|
|
+ public static Timing getBehaviorTimings(String type) {
|
|
+ return Timings.ofSafe("## Behavior - " + type);
|
|
+ }
|
|
+
|
|
+ public static Timing getSensorTimings(String type, int rate) {
|
|
+ return Timings.ofSafe("## Sensor - " + type + " (Default rate: " + rate + ")");
|
|
+ }
|
|
+
|
|
/**
|
|
* Get a named timer for the specified tile entity type to track type specific timings.
|
|
* @param entity
|
|
diff --git a/src/main/java/net/minecraft/world/entity/ai/behavior/Behavior.java b/src/main/java/net/minecraft/world/entity/ai/behavior/Behavior.java
|
|
index f639cafa64d98a001e622882c647701547f5c3ac..9379dd4056018b52c93ed4888dcdc94579bd9691 100644
|
|
--- a/src/main/java/net/minecraft/world/entity/ai/behavior/Behavior.java
|
|
+++ b/src/main/java/net/minecraft/world/entity/ai/behavior/Behavior.java
|
|
@@ -14,6 +14,10 @@ public abstract class Behavior<E extends LivingEntity> implements BehaviorContro
|
|
private long endTimestamp;
|
|
private final int minDuration;
|
|
private final int maxDuration;
|
|
+ // Paper start - configurable behavior tick rate and timings
|
|
+ private final String configKey;
|
|
+ private final co.aikar.timings.Timing timing;
|
|
+ // Paper end - configurable behavior tick rate and timings
|
|
|
|
public Behavior(Map<MemoryModuleType<?>, MemoryStatus> requiredMemoryState) {
|
|
this(requiredMemoryState, 60);
|
|
@@ -27,6 +31,15 @@ public abstract class Behavior<E extends LivingEntity> implements BehaviorContro
|
|
this.minDuration = minRunTime;
|
|
this.maxDuration = maxRunTime;
|
|
this.entryCondition = requiredMemoryState;
|
|
+ // Paper start - configurable behavior 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('.');
|
|
+ if (lastSeparator != -1) {
|
|
+ key = key.substring(lastSeparator + 1);
|
|
+ }
|
|
+ this.configKey = key.toLowerCase(java.util.Locale.ROOT);
|
|
+ this.timing = co.aikar.timings.MinecraftTimings.getBehaviorTimings(configKey);
|
|
+ // Paper end - configurable behavior tick rate and timings
|
|
}
|
|
|
|
@Override
|
|
@@ -36,11 +49,19 @@ public abstract class Behavior<E extends LivingEntity> implements BehaviorContro
|
|
|
|
@Override
|
|
public final boolean tryStart(ServerLevel world, E entity, long time) {
|
|
+ // Paper start - configurable behavior tick rate and timings
|
|
+ int tickRate = java.util.Objects.requireNonNullElse(world.paperConfig().tickRates.behavior.get(entity.getType(), this.configKey), -1);
|
|
+ if (tickRate > -1 && time < this.endTimestamp + tickRate) {
|
|
+ return false;
|
|
+ }
|
|
+ // Paper end - configurable behavior tick rate and timings
|
|
if (this.hasRequiredMemories(entity) && this.checkExtraStartConditions(world, entity)) {
|
|
this.status = Behavior.Status.RUNNING;
|
|
int i = this.minDuration + world.getRandom().nextInt(this.maxDuration + 1 - this.minDuration);
|
|
this.endTimestamp = time + (long)i;
|
|
+ this.timing.startTiming(); // Paper - behavior timings
|
|
this.start(world, entity, time);
|
|
+ this.timing.stopTiming(); // Paper - behavior timings
|
|
return true;
|
|
} else {
|
|
return false;
|
|
@@ -52,11 +73,13 @@ public abstract class Behavior<E extends LivingEntity> implements BehaviorContro
|
|
|
|
@Override
|
|
public final void tickOrStop(ServerLevel world, E entity, long time) {
|
|
+ this.timing.startTiming(); // Paper - behavior timings
|
|
if (!this.timedOut(time) && this.canStillUse(world, entity, time)) {
|
|
this.tick(world, entity, time);
|
|
} else {
|
|
this.doStop(world, entity, time);
|
|
}
|
|
+ this.timing.stopTiming(); // Paper - behavior timings
|
|
}
|
|
|
|
protected void tick(ServerLevel world, E entity, long time) {
|
|
diff --git a/src/main/java/net/minecraft/world/entity/ai/sensing/Sensor.java b/src/main/java/net/minecraft/world/entity/ai/sensing/Sensor.java
|
|
index 671fc7725d7c801a2ba009da5bd1bc1a9530f187..85b4b24361e785acf75571ff98f924c00ae80748 100644
|
|
--- a/src/main/java/net/minecraft/world/entity/ai/sensing/Sensor.java
|
|
+++ b/src/main/java/net/minecraft/world/entity/ai/sensing/Sensor.java
|
|
@@ -26,8 +26,21 @@ public abstract class Sensor<E extends LivingEntity> {
|
|
.ignoreInvisibilityTesting();
|
|
private final int scanRate;
|
|
private long timeToTick;
|
|
+ // Paper start - configurable sensor tick rate and timings
|
|
+ private final String configKey;
|
|
+ private final co.aikar.timings.Timing timing;
|
|
+ // Paper end
|
|
|
|
public Sensor(int senseInterval) {
|
|
+ // 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('.');
|
|
+ if (lastSeparator != -1) {
|
|
+ key = key.substring(lastSeparator + 1);
|
|
+ }
|
|
+ this.configKey = key.toLowerCase(java.util.Locale.ROOT);
|
|
+ this.timing = co.aikar.timings.MinecraftTimings.getSensorTimings(configKey, senseInterval);
|
|
+ // Paper end
|
|
this.scanRate = senseInterval;
|
|
this.timeToTick = (long)RANDOM.nextInt(senseInterval);
|
|
}
|
|
@@ -38,8 +51,12 @@ public abstract class Sensor<E extends LivingEntity> {
|
|
|
|
public final void tick(ServerLevel world, E entity) {
|
|
if (--this.timeToTick <= 0L) {
|
|
- this.timeToTick = (long)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.timing.startTiming();
|
|
+ // Paper end
|
|
this.doTick(world, entity);
|
|
+ this.timing.stopTiming(); // Paper - sensor timings
|
|
}
|
|
}
|
|
|