diff options
author | MrPowerGamerBR <[email protected]> | 2023-11-25 19:01:26 -0300 |
---|---|---|
committer | GitHub <[email protected]> | 2023-11-25 17:01:26 -0500 |
commit | faa2f475b090f3e811972eb48514a0a03647eab6 (patch) | |
tree | a7b3b4988fcf273b0752e42ceff18753a9f2baec | |
parent | 334b2f20dbdece82cd2e74ef007f7c12dbf7c0fa (diff) | |
download | Paper-faa2f475b090f3e811972eb48514a0a03647eab6.tar.gz Paper-faa2f475b090f3e811972eb48514a0a03647eab6.zip |
Lazily create LootContext for criterions (#9969)
For each player on each tick, enter block triggers are invoked, and these create loot contexts that are promptly thrown away since the trigger doesn't pass the predicate
To avoid this, we now lazily create the LootContext if the criterion passes the predicate AND if any of the listener triggers require a loot context instance
-rw-r--r-- | patches/server/1053-Lazily-create-LootContext-for-criterions.patch | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/patches/server/1053-Lazily-create-LootContext-for-criterions.patch b/patches/server/1053-Lazily-create-LootContext-for-criterions.patch new file mode 100644 index 0000000000..ef6c752ac2 --- /dev/null +++ b/patches/server/1053-Lazily-create-LootContext-for-criterions.patch @@ -0,0 +1,30 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: MrPowerGamerBR <[email protected]> +Date: Tue, 21 Nov 2023 12:16:39 -0300 +Subject: [PATCH] Lazily create LootContext for criterions + +For each player on each tick, enter block triggers are invoked, and these create loot contexts that are promptly thrown away since the trigger doesn't pass the predicate + +To avoid this, we now lazily create the LootContext if the criterion passes the predicate AND if any of the listener triggers require a loot context instance + +diff --git a/src/main/java/net/minecraft/advancements/critereon/SimpleCriterionTrigger.java b/src/main/java/net/minecraft/advancements/critereon/SimpleCriterionTrigger.java +index f0367a9cce13ef576fbb7023c0aba6eb48963606..997ddf7cd0051ba67e9c4ef7da39481649303791 100644 +--- a/src/main/java/net/minecraft/advancements/critereon/SimpleCriterionTrigger.java ++++ b/src/main/java/net/minecraft/advancements/critereon/SimpleCriterionTrigger.java +@@ -54,14 +54,14 @@ public abstract class SimpleCriterionTrigger<T extends SimpleCriterionTrigger.Si + PlayerAdvancements playerAdvancements = player.getAdvancements(); + Set<CriterionTrigger.Listener<T>> set = (Set) playerAdvancements.criterionData.get(this); // Paper - fix AdvancementDataPlayer leak + if (set != null && !set.isEmpty()) { +- LootContext lootContext = EntityPredicate.createContext(player, player); ++ LootContext lootContext = null; // EntityPredicate.createContext(player, player); // Paper - lazily create LootContext for criterions + List<CriterionTrigger.Listener<T>> list = null; + + for(CriterionTrigger.Listener<T> listener : set) { + T simpleInstance = listener.trigger(); + if (predicate.test(simpleInstance)) { + Optional<ContextAwarePredicate> optional = simpleInstance.playerPredicate(); +- if (optional.isEmpty() || optional.get().matches(lootContext)) { ++ if (optional.isEmpty() || optional.get().matches(lootContext = (lootContext == null ? EntityPredicate.createContext(player, player) : lootContext))) { // Paper - lazily create LootContext for criterions + if (list == null) { + list = Lists.newArrayList(); + } |