-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
- Loading branch information
1 parent
53c1566
commit dd77d31
Showing
3 changed files
with
33 additions
and
0 deletions.
There are no files selected for viewing
33 changes: 33 additions & 0 deletions
33
patches/server/0012-Lazily-create-LootContext-for-criterions.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 | ||
From: MrPowerGamerBR <git@mrpowergamerbr.com> | ||
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..bace327cd6409025463ef2caa2c478ebdb196665 100644 | ||
--- a/src/main/java/net/minecraft/advancements/critereon/SimpleCriterionTrigger.java | ||
+++ b/src/main/java/net/minecraft/advancements/critereon/SimpleCriterionTrigger.java | ||
@@ -54,13 +54,18 @@ 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); // SparklyPaper - 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(); | ||
+ // SparklyPaper start - lazily create LootContext for criterions | ||
+ if (lootContext == null && optional.isPresent()) { | ||
+ lootContext = EntityPredicate.createContext(player, player); | ||
+ } | ||
+ // SparklyPaper end | ||
if (optional.isEmpty() || optional.get().matches(lootContext)) { | ||
if (list == null) { | ||
list = Lists.newArrayList(); |
File renamed without changes.
File renamed without changes.