2023-11-25 23:01:26 +01:00
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
2024-01-21 19:37:09 +01:00
index 805459ba815520165c86a537fbb1f3e04b85bfbd..a327973e37b5b8d4e15683ef24548482ac3dc3d5 100644
2023-11-25 23:01:26 +01:00
--- a/src/main/java/net/minecraft/advancements/critereon/SimpleCriterionTrigger.java
+++ b/src/main/java/net/minecraft/advancements/critereon/SimpleCriterionTrigger.java
2023-12-06 19:18:53 +01:00
@@ -45,14 +45,14 @@ public abstract class SimpleCriterionTrigger<T extends SimpleCriterionTrigger.Si
2023-11-25 23:01:26 +01:00
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);
2024-01-16 12:41:40 +01:00
+ LootContext lootContext = null; // EntityPredicate.createContext(player, player); // Paper - Perf: lazily create LootContext for criterions
2023-11-25 23:01:26 +01:00
List<CriterionTrigger.Listener<T>> list = null;
for(CriterionTrigger.Listener<T> listener : set) {
T simpleInstance = listener.trigger();
if (predicate.test(simpleInstance)) {
2023-12-06 19:18:53 +01:00
Optional<ContextAwarePredicate> optional = simpleInstance.player();
2023-11-25 23:01:26 +01:00
- if (optional.isEmpty() || optional.get().matches(lootContext)) {
2024-01-16 12:41:40 +01:00
+ if (optional.isEmpty() || optional.get().matches(lootContext = (lootContext == null ? EntityPredicate.createContext(player, player) : lootContext))) { // Paper - Perf: lazily create LootContext for criterions
2023-11-25 23:01:26 +01:00
if (list == null) {
list = Lists.newArrayList();
}