mirror of
https://github.com/GeyserMC/Geyser.git
synced 2025-01-23 00:41:59 +01:00
Add predicate caching
This commit is contained in:
parent
885c4d9d3b
commit
25109b71b3
1 changed files with 6 additions and 1 deletions
|
@ -26,6 +26,8 @@
|
|||
package org.geysermc.geyser.translator.item;
|
||||
|
||||
import com.google.common.collect.Multimap;
|
||||
import it.unimi.dsi.fastutil.objects.Object2BooleanMap;
|
||||
import it.unimi.dsi.fastutil.objects.Object2BooleanOpenHashMap;
|
||||
import net.kyori.adventure.key.Key;
|
||||
import org.cloudburstmc.protocol.bedrock.data.TrimMaterial;
|
||||
import org.geysermc.geyser.api.item.custom.v2.predicate.CustomItemPredicate;
|
||||
|
@ -78,10 +80,13 @@ public final class CustomItemTranslator {
|
|||
return null;
|
||||
}
|
||||
|
||||
// Cache predicate values so they're not recalculated every time when there are multiple item definitions using the same predicates
|
||||
Object2BooleanMap<CustomItemPredicate> calculatedPredicates = new Object2BooleanOpenHashMap<>();
|
||||
for (GeyserCustomMappingData customMapping : customItems) {
|
||||
boolean allMatch = true;
|
||||
for (CustomItemPredicate predicate : customMapping.definition().predicates()) {
|
||||
if (!predicateMatches(session, predicate, stackSize, components)) {
|
||||
boolean value = calculatedPredicates.computeIfAbsent(predicate, x -> predicateMatches(session, predicate, stackSize, components));
|
||||
if (!value) {
|
||||
allMatch = false;
|
||||
break;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue