mirror of
https://github.com/PaperMC/Paper.git
synced 2024-12-28 23:38:25 +01:00
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
This commit is contained in:
parent
4853ebd729
commit
5f134afc4b
1 changed files with 13 additions and 2 deletions
|
@ -1,6 +1,6 @@
|
||||||
--- a/net/minecraft/advancements/critereon/SimpleCriterionTrigger.java
|
--- a/net/minecraft/advancements/critereon/SimpleCriterionTrigger.java
|
||||||
+++ b/net/minecraft/advancements/critereon/SimpleCriterionTrigger.java
|
+++ b/net/minecraft/advancements/critereon/SimpleCriterionTrigger.java
|
||||||
@@ -15,32 +15,32 @@
|
@@ -15,41 +15,41 @@
|
||||||
import net.minecraft.world.level.storage.loot.LootContext;
|
import net.minecraft.world.level.storage.loot.LootContext;
|
||||||
|
|
||||||
public abstract class SimpleCriterionTrigger<T extends SimpleCriterionTrigger.SimpleInstance> implements CriterionTrigger<T> {
|
public abstract class SimpleCriterionTrigger<T extends SimpleCriterionTrigger.SimpleInstance> implements CriterionTrigger<T> {
|
||||||
|
@ -37,5 +37,16 @@
|
||||||
- Set<CriterionTrigger.Listener<T>> set = this.players.get(playerAdvancements);
|
- Set<CriterionTrigger.Listener<T>> set = this.players.get(playerAdvancements);
|
||||||
+ Set<CriterionTrigger.Listener<T>> set = (Set) playerAdvancements.criterionData.get(this); // Paper - fix AdvancementDataPlayer leak
|
+ Set<CriterionTrigger.Listener<T>> set = (Set) playerAdvancements.criterionData.get(this); // Paper - fix AdvancementDataPlayer leak
|
||||||
if (set != null && !set.isEmpty()) {
|
if (set != null && !set.isEmpty()) {
|
||||||
LootContext lootContext = EntityPredicate.createContext(player, player);
|
- LootContext lootContext = EntityPredicate.createContext(player, player);
|
||||||
|
+ LootContext lootContext = null; // EntityPredicate.createContext(player, player); // Paper - Perf: lazily create LootContext for criterions
|
||||||
List<CriterionTrigger.Listener<T>> list = null;
|
List<CriterionTrigger.Listener<T>> list = null;
|
||||||
|
|
||||||
|
for (CriterionTrigger.Listener<T> listener : set) {
|
||||||
|
T simpleInstance = listener.trigger();
|
||||||
|
if (predicate.test(simpleInstance)) {
|
||||||
|
Optional<ContextAwarePredicate> optional = simpleInstance.player();
|
||||||
|
- if (optional.isEmpty() || optional.get().matches(lootContext)) {
|
||||||
|
+ if (optional.isEmpty() || optional.get().matches(lootContext = (lootContext == null ? EntityPredicate.createContext(player, player) : lootContext))) { // Paper - Perf: lazily create LootContext for criterions
|
||||||
|
if (list == null) {
|
||||||
|
list = Lists.newArrayList();
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue