From 299126521908d61c15390dfd95489c01254e3fe0 Mon Sep 17 00:00:00 2001 From: Etil <81570777+etil2jz@users.noreply.github.com> Date: Sun, 2 Jan 2022 18:54:50 +0100 Subject: [PATCH] vmp: ingredient matching cache (First yarn port yay) --- ...kip-entity-move-if-movement-is-zero.patch} | 2 +- .../0088-vmp-ingredient-matching-cache.patch | 85 +++++++++++++++++++ 2 files changed, 86 insertions(+), 1 deletion(-) rename patches/server/{0066-Skip-entity-move-if-movement-is-zero.patch => 0066-vmp-skip-entity-move-if-movement-is-zero.patch} (94%) create mode 100644 patches/server/0088-vmp-ingredient-matching-cache.patch diff --git a/patches/server/0066-Skip-entity-move-if-movement-is-zero.patch b/patches/server/0066-vmp-skip-entity-move-if-movement-is-zero.patch similarity index 94% rename from patches/server/0066-Skip-entity-move-if-movement-is-zero.patch rename to patches/server/0066-vmp-skip-entity-move-if-movement-is-zero.patch index 3972bb4..4f09989 100644 --- a/patches/server/0066-Skip-entity-move-if-movement-is-zero.patch +++ b/patches/server/0066-vmp-skip-entity-move-if-movement-is-zero.patch @@ -1,7 +1,7 @@ From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: ishland Date: Sun, 12 Dec 2021 17:19:00 -0500 -Subject: [PATCH] Skip entity move if movement is zero +Subject: [PATCH] vmp: skip entity move if movement is zero Original code by RelativityMC, licensed under MIT You can find the original code on https://github.com/RelativityMC/VMP-fabric (Yarn mappings) diff --git a/patches/server/0088-vmp-ingredient-matching-cache.patch b/patches/server/0088-vmp-ingredient-matching-cache.patch new file mode 100644 index 0000000..518b7e8 --- /dev/null +++ b/patches/server/0088-vmp-ingredient-matching-cache.patch @@ -0,0 +1,85 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: ishland +Date: Sun, 21 Nov 2021 03:01:00 +0100 +Subject: [PATCH] vmp: ingredient matching cache + +Original code by RelativityMC, licensed under MIT +You can find the original code on https://github.com/RelativityMC/VMP-fabric (Yarn mappings) + +diff --git a/src/main/java/net/minecraft/world/item/crafting/Ingredient.java b/src/main/java/net/minecraft/world/item/crafting/Ingredient.java +index 8f35445477507bbec3c0cb1dccfd888316951595..99e9c9729de5d64cb4efbc2a72dd1bb046e97efb 100644 +--- a/src/main/java/net/minecraft/world/item/crafting/Ingredient.java ++++ b/src/main/java/net/minecraft/world/item/crafting/Ingredient.java +@@ -12,9 +12,12 @@ import it.unimi.dsi.fastutil.ints.IntList; + import java.util.Arrays; + import java.util.Collection; + import java.util.Collections; ++import java.util.HashSet; // Mirai + import java.util.Iterator; + import java.util.List; ++import java.util.Set; // Mirai + import java.util.function.Predicate; ++import java.util.stream.Collectors; // Mirai + import java.util.stream.Stream; + import java.util.stream.StreamSupport; + import javax.annotation.Nullable; +@@ -38,6 +41,8 @@ public final class Ingredient implements Predicate { + @Nullable + private IntList stackingIds; + public boolean exact; // CraftBukkit ++ private Set matchingItems = null; // Mirai ++ private boolean isEmptyMatch = false; // Mirai + + public Ingredient(Stream entries) { + this.values = (Ingredient.Value[]) entries.toArray((i) -> { +@@ -65,32 +70,25 @@ public final class Ingredient implements Predicate { + if (itemstack == null) { + return false; + } else { +- this.dissolve(); +- if (this.itemStacks.length == 0) { +- return itemstack.isEmpty(); +- } else { +- ItemStack[] aitemstack = this.itemStacks; +- int i = aitemstack.length; +- +- for (int j = 0; j < i; ++j) { +- ItemStack itemstack1 = aitemstack[j]; +- +- // CraftBukkit start +- if (this.exact) { +- if (itemstack1.getItem() == itemstack.getItem() && ItemStack.tagMatches(itemstack, itemstack1)) { +- return true; +- } +- +- continue; +- } +- // CraftBukkit end +- if (itemstack1.is(itemstack.getItem())) { +- return true; +- } +- } +- +- return false; ++ // Mirai start ++ /** ++ * @author ishland ++ * @reason optimize test() ++ */ ++ Set matchingItems = this.matchingItems; ++ boolean isEmptyMatch = this.isEmptyMatch; ++ if (matchingItems == null) { ++ matchingItems = this.matchingItems = Arrays.stream(this.values) ++ .flatMap(entry -> entry.getItems().stream()) ++ .filter(itemstack1 -> !itemstack1.isEmpty()) ++ .map(ItemStack::getItem) ++ .collect(Collectors.toCollection(HashSet::new)); ++ isEmptyMatch = this.isEmptyMatch = this.matchingItems.isEmpty(); ++ } ++ if (itemstack.isEmpty()) { ++ return isEmptyMatch; + } ++ return matchingItems.contains(itemstack.getItem()); + } + } +