2016-03-01 20:39:42 +01:00
From 73f97633e63c73fac4b4bb32d4c7bfa3535afa9e Mon Sep 17 00:00:00 2001
2015-02-22 02:27:58 +01:00
From: md_5 <git@md-5.net>
Date: Sun, 22 Feb 2015 12:27:40 +1100
Subject: [PATCH] Use FastMatches for ItemStack Dirty Check
The check to find dirty itemstacks and send update packets each tick can be very intensive as it checks the entire itemstack, including the entire NBT map. To save on this, 19/20 times we will simply compare the basic count/data/type. If for some strange reason the NBT of an item already existing in an inventory is changes, it will take up to 1 second to show, with an average time of half a second. This odd 0.5 second delay is far preferable to lag every tick, and shouldn't be noticed by anyone.
diff --git a/src/main/java/net/minecraft/server/Container.java b/src/main/java/net/minecraft/server/Container.java
2016-02-29 22:33:06 +01:00
index 1d6ec51..000b4db 100644
2015-02-22 02:27:58 +01:00
--- a/src/main/java/net/minecraft/server/Container.java
+++ b/src/main/java/net/minecraft/server/Container.java
@@ -28,6 +28,7 @@ public abstract class Container {
2015-02-28 12:36:22 +01:00
private final Set<Slot> h = Sets.newHashSet();
protected List<ICrafting> listeners = Lists.newArrayList();
private Set<EntityHuman> i = Sets.newHashSet();
2015-02-22 02:27:58 +01:00
+ private int tickCount; // Spigot
2015-02-28 12:36:22 +01:00
2015-02-22 02:27:58 +01:00
// CraftBukkit start
public boolean checkReachable = true;
@@ -75,7 +76,7 @@ public abstract class Container {
ItemStack itemstack = ((Slot) this.c.get(i)).getItem();
ItemStack itemstack1 = (ItemStack) this.b.get(i);
- if (!ItemStack.matches(itemstack1, itemstack)) {
+ if (!ItemStack.fastMatches(itemstack1, itemstack) || (tickCount % 20 == 0 && !ItemStack.matches(itemstack1, itemstack))) { // Spigot
itemstack1 = itemstack == null ? null : itemstack.cloneItemStack();
this.b.set(i, itemstack1);
@@ -84,6 +85,7 @@ public abstract class Container {
}
}
}
+ tickCount++; // Spigot
}
diff --git a/src/main/java/net/minecraft/server/ItemStack.java b/src/main/java/net/minecraft/server/ItemStack.java
2016-03-01 20:39:42 +01:00
index e11dbef..4a2e0df 100644
2015-02-22 02:27:58 +01:00
--- a/src/main/java/net/minecraft/server/ItemStack.java
+++ b/src/main/java/net/minecraft/server/ItemStack.java
2016-03-01 20:39:42 +01:00
@@ -449,6 +449,18 @@ public final class ItemStack {
2015-02-22 02:27:58 +01:00
return itemstack == null && itemstack1 == null ? true : (itemstack != null && itemstack1 != null ? (itemstack.tag == null && itemstack1.tag != null ? false : itemstack.tag == null || itemstack.tag.equals(itemstack1.tag)) : false);
}
+ // Spigot Start
+ public static boolean fastMatches(ItemStack itemstack, ItemStack itemstack1) {
+ if (itemstack == null && itemstack1 == null) {
+ return true;
+ }
+ if (itemstack != null && itemstack1 != null) {
+ return itemstack.count == itemstack1.count && itemstack.item == itemstack1.item && itemstack.damage == itemstack1.damage;
+ }
+ return false;
+ }
+ // Spigot End
+
public static boolean matches(ItemStack itemstack, ItemStack itemstack1) {
2016-02-29 22:33:06 +01:00
return itemstack == null && itemstack1 == null ? true : (itemstack != null && itemstack1 != null ? itemstack.e(itemstack1) : false);
2015-02-22 02:27:58 +01:00
}
--
2016-02-29 22:33:06 +01:00
2.5.0
2015-02-22 02:27:58 +01:00