aboutsummaryrefslogtreecommitdiffhomepage
path: root/Spigot-Server-Patches/0123-Improve-Minecraft-Hopper-Performance.patch
blob: ce33e0af16705891ceac61b4f8ee997666ee427d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
From b90b6e56102b563fc5dedfd20d1cfc5f901201d4 Mon Sep 17 00:00:00 2001
From: Aikar <aikar@aikar.co>
Date: Wed, 27 Apr 2016 22:09:52 -0400
Subject: [PATCH] Improve Minecraft Hopper Performance

Removes unnecessary extra calls to .update() that are very expensive
Also reset cooldown each hopper tick that a hopper is full.
Also don't constantly clone ItemStacks without merit

diff --git a/src/main/java/net/minecraft/server/TileEntity.java b/src/main/java/net/minecraft/server/TileEntity.java
index d0c0371fc..d2662ae14 100644
--- a/src/main/java/net/minecraft/server/TileEntity.java
+++ b/src/main/java/net/minecraft/server/TileEntity.java
@@ -33,6 +33,7 @@ public abstract class TileEntity {
         return (MinecraftKey) TileEntity.f.b(oclass);
     }
 
+    static boolean IGNORE_TILE_UPDATES = false; // Paper
     public World getWorld() {
         return this.world;
     }
@@ -111,6 +112,7 @@ public abstract class TileEntity {
 
     public void update() {
         if (this.world != null) {
+            if (IGNORE_TILE_UPDATES) return; // Paper
             IBlockData iblockdata = this.world.getType(this.position);
 
             this.g = iblockdata.getBlock().toLegacyData(iblockdata);
diff --git a/src/main/java/net/minecraft/server/TileEntityHopper.java b/src/main/java/net/minecraft/server/TileEntityHopper.java
index 6acce15e7..44b6ecc5d 100644
--- a/src/main/java/net/minecraft/server/TileEntityHopper.java
+++ b/src/main/java/net/minecraft/server/TileEntityHopper.java
@@ -220,11 +220,13 @@ public class TileEntityHopper extends TileEntityLootable implements IHopper, ITi
                             this.setCooldown(world.spigotConfig.hopperTransfer); // Spigot
                             return false;
                         }
-                        int origCount = event.getItem().getAmount(); // Spigot
-                        ItemStack itemstack1 = addItem(this, iinventory, CraftItemStack.asNMSCopy(event.getItem()), enumdirection);
-
+                        // Paper start
+                        org.bukkit.inventory.ItemStack eventStack = event.getItem();
+                        int origCount = eventStack.getAmount(); // Spigot
+                        ItemStack itemstack1 = addItem(this, iinventory, CraftItemStack.asNMSCopy(eventStack), enumdirection);
+                        // Paper end
                         if (itemstack1.isEmpty()) {
-                            if (event.getItem().equals(oitemstack)) {
+                            if (eventStack.equals(oitemstack)) { // Paper
                                 iinventory.update();
                             } else {
                                 this.setItem(i, itemstack);
@@ -377,11 +379,13 @@ public class TileEntityHopper extends TileEntityLootable implements IHopper, ITi
                 }
                 return false;
             }
-            int origCount = event.getItem().getAmount(); // Spigot
-            ItemStack itemstack2 = addItem(iinventory, ihopper, CraftItemStack.asNMSCopy(event.getItem()), null);
-
+            // Paper start
+            org.bukkit.inventory.ItemStack eventStack = event.getItem();
+            int origCount = eventStack.getAmount(); // Spigot
+            ItemStack itemstack2 = addItem(iinventory, ihopper, CraftItemStack.asNMSCopy(eventStack), null);
+            // Paper end
             if (itemstack2.isEmpty()) {
-                if (event.getItem().equals(oitemstack)) {
+                if (eventStack.equals(oitemstack)) { // Paper
                     iinventory.update();
                 } else {
                     iinventory.setItem(i, itemstack1);
@@ -459,7 +463,9 @@ public class TileEntityHopper extends TileEntityLootable implements IHopper, ITi
             boolean flag1 = iinventory1.w_();
 
             if (itemstack1.isEmpty()) {
+                IGNORE_TILE_UPDATES = true; // Paper
                 iinventory1.setItem(i, itemstack);
+                IGNORE_TILE_UPDATES = false; // Paper
                 itemstack = ItemStack.a;
                 flag = true;
             } else if (a(itemstack1, itemstack)) {
@@ -562,6 +568,7 @@ public class TileEntityHopper extends TileEntityLootable implements IHopper, ITi
         this.f = i;
     }
 
+    boolean isCooledDown() { return J(); } // Paper - OBFHELPER
     private boolean J() {
         return this.f > 0;
     }
-- 
2.12.2