vmp: ingredient matching cache
(First yarn port yay)
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: ishland <ishlandmc@yeah.net>
|
||||
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)
|
||||
85
patches/server/0088-vmp-ingredient-matching-cache.patch
Normal file
85
patches/server/0088-vmp-ingredient-matching-cache.patch
Normal file
@@ -0,0 +1,85 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: ishland <ishlandmc@yeah.net>
|
||||
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<ItemStack> {
|
||||
@Nullable
|
||||
private IntList stackingIds;
|
||||
public boolean exact; // CraftBukkit
|
||||
+ private Set<Item> matchingItems = null; // Mirai
|
||||
+ private boolean isEmptyMatch = false; // Mirai
|
||||
|
||||
public Ingredient(Stream<? extends Ingredient.Value> entries) {
|
||||
this.values = (Ingredient.Value[]) entries.toArray((i) -> {
|
||||
@@ -65,32 +70,25 @@ public final class Ingredient implements Predicate<ItemStack> {
|
||||
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<Item> 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());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user