From 2e8cff7f7c7f1794ad507eb7da613c7fe0c1fc38 Mon Sep 17 00:00:00 2001
From: crafter23456 <64259198+crafter23456@users.noreply.github.com>
Date: Thu, 24 Mar 2022 16:09:19 +0100
Subject: [PATCH 1/4] optimise hoppers
---
.../main/java/net/minecraft/server/BlockChest.java | 7 ++++++-
.../src/main/java/net/minecraft/server/Chunk.java | 11 +++++++++++
.../java/net/minecraft/server/TileEntityHopper.java | 4 +++-
3 files changed, 20 insertions(+), 2 deletions(-)
diff --git a/NachoSpigot-Server/src/main/java/net/minecraft/server/BlockChest.java b/NachoSpigot-Server/src/main/java/net/minecraft/server/BlockChest.java
index 06b15497d..c6cc53988 100644
--- a/NachoSpigot-Server/src/main/java/net/minecraft/server/BlockChest.java
+++ b/NachoSpigot-Server/src/main/java/net/minecraft/server/BlockChest.java
@@ -50,7 +50,12 @@ public void onPlace(World world, BlockPosition blockposition, IBlockData iblockd
while (iterator.hasNext()) {
EnumDirection enumdirection = (EnumDirection) iterator.next();
BlockPosition blockposition1 = blockposition.shift(enumdirection);
- IBlockData iblockdata1 = world.getType(blockposition1);
+ // FlamePaper start - Dont load chunks for chests
+ final IBlockData iblockdata1 = world.isLoaded(blockposition1) ? world.getType(blockposition1) : null;
+ if (iblockdata1 == null) {
+ continue;
+ }
+ // FlamePaper end
if (iblockdata1.getBlock() == this) {
this.e(world, blockposition1, iblockdata1);
diff --git a/NachoSpigot-Server/src/main/java/net/minecraft/server/Chunk.java b/NachoSpigot-Server/src/main/java/net/minecraft/server/Chunk.java
index a784879a0..4a6a079ef 100644
--- a/NachoSpigot-Server/src/main/java/net/minecraft/server/Chunk.java
+++ b/NachoSpigot-Server/src/main/java/net/minecraft/server/Chunk.java
@@ -824,6 +824,7 @@ public void a(Entity entity) {
// PaperSpigot start - update counts
if (entity instanceof EntityItem) {
itemCounts[k]++;
+ itemCount++; // FlamePaper - Hopper item lookup optimization
} else if (entity instanceof IInventory) {
inventoryEntityCounts[k]++;
}
@@ -863,6 +864,7 @@ public void removeEntity(Entity entity, int i) { // Nacho - deobfuscate
// PaperSpigot start - update counts
if (entity instanceof EntityItem) {
itemCounts[i]--;
+ itemCount++; // FlamePaper - Hopper item lookup optimization
} else if (entity instanceof IInventory) {
inventoryEntityCounts[i]--;
}
@@ -1630,4 +1632,13 @@ public static enum EnumTileEntityState {
private EnumTileEntityState() {}
}
+
+ // FlamePaper start - Hopper item lookup optimization
+ private int itemCount = 0;
+
+ public int getItemCount() {
+ return itemCount;
+ }
+ // FlamePaper end - Hopper item lookup optimization
+
}
diff --git a/NachoSpigot-Server/src/main/java/net/minecraft/server/TileEntityHopper.java b/NachoSpigot-Server/src/main/java/net/minecraft/server/TileEntityHopper.java
index 460a43705..d987b6933 100644
--- a/NachoSpigot-Server/src/main/java/net/minecraft/server/TileEntityHopper.java
+++ b/NachoSpigot-Server/src/main/java/net/minecraft/server/TileEntityHopper.java
@@ -617,7 +617,9 @@ public static IInventory getInventory(World world, double d0, double d1, double
}
}
- if (object == null && searchForEntities) {
+ net.minecraft.server.Chunk chunk = world.getChunkAtWorldCoords(blockposition);
+
+ if (object == null && searchForEntities && !org.bukkit.craftbukkit.util.CraftMagicNumbers.getMaterial(block).isOccluding() && chunk.getItemCount() > 0) {
List list = world.a((Entity) null, new AxisAlignedBB(d0 - 0.5D, d1 - 0.5D, d2 - 0.5D, d0 + 0.5D, d1 + 0.5D, d2 + 0.5D), IEntitySelector.c);
if (list.size() > 0) {
From ea5eba7ba177c9f2c7b699439967696350c9019f Mon Sep 17 00:00:00 2001
From: crafter23456 <64259198+crafter23456@users.noreply.github.com>
Date: Thu, 24 Mar 2022 16:11:48 +0100
Subject: [PATCH 2/4] dont compile mockito
---
NachoSpigot-Server/pom.xml | 1 +
1 file changed, 1 insertion(+)
diff --git a/NachoSpigot-Server/pom.xml b/NachoSpigot-Server/pom.xml
index 936824373..d67bcd1e2 100644
--- a/NachoSpigot-Server/pom.xml
+++ b/NachoSpigot-Server/pom.xml
@@ -147,6 +147,7 @@
org.mockito
mockito-core
1.10.19
+ test
org.hamcrest
From df38e3a3ed32570cdc4ebf57ea259ec0fe148870 Mon Sep 17 00:00:00 2001
From: crafter23456 <64259198+crafter23456@users.noreply.github.com>
Date: Fri, 25 Mar 2022 14:36:19 +0100
Subject: [PATCH 3/4] further optimisations
---
.../src/main/java/net/minecraft/server/Chunk.java | 11 ++++++-----
.../java/net/minecraft/server/TileEntityHopper.java | 2 +-
README.md | 3 +++
3 files changed, 10 insertions(+), 6 deletions(-)
diff --git a/NachoSpigot-Server/src/main/java/net/minecraft/server/Chunk.java b/NachoSpigot-Server/src/main/java/net/minecraft/server/Chunk.java
index 4a6a079ef..2c929cc15 100644
--- a/NachoSpigot-Server/src/main/java/net/minecraft/server/Chunk.java
+++ b/NachoSpigot-Server/src/main/java/net/minecraft/server/Chunk.java
@@ -824,7 +824,6 @@ public void a(Entity entity) {
// PaperSpigot start - update counts
if (entity instanceof EntityItem) {
itemCounts[k]++;
- itemCount++; // FlamePaper - Hopper item lookup optimization
} else if (entity instanceof IInventory) {
inventoryEntityCounts[k]++;
}
@@ -864,7 +863,6 @@ public void removeEntity(Entity entity, int i) { // Nacho - deobfuscate
// PaperSpigot start - update counts
if (entity instanceof EntityItem) {
itemCounts[i]--;
- itemCount++; // FlamePaper - Hopper item lookup optimization
} else if (entity instanceof IInventory) {
inventoryEntityCounts[i]--;
}
@@ -1634,10 +1632,13 @@ private EnumTileEntityState() {}
}
// FlamePaper start - Hopper item lookup optimization
- private int itemCount = 0;
+ public int getItemCount(BlockPosition blockPosition) {
+ int k = MathHelper.floor(blockPosition.getY() / 16.0D);
- public int getItemCount() {
- return itemCount;
+ k = Math.max(0, k);
+ k = Math.min(this.entitySlices.length - 1, k);
+
+ return itemCounts[k];
}
// FlamePaper end - Hopper item lookup optimization
diff --git a/NachoSpigot-Server/src/main/java/net/minecraft/server/TileEntityHopper.java b/NachoSpigot-Server/src/main/java/net/minecraft/server/TileEntityHopper.java
index d987b6933..97b607dc4 100644
--- a/NachoSpigot-Server/src/main/java/net/minecraft/server/TileEntityHopper.java
+++ b/NachoSpigot-Server/src/main/java/net/minecraft/server/TileEntityHopper.java
@@ -619,7 +619,7 @@ public static IInventory getInventory(World world, double d0, double d1, double
net.minecraft.server.Chunk chunk = world.getChunkAtWorldCoords(blockposition);
- if (object == null && searchForEntities && !org.bukkit.craftbukkit.util.CraftMagicNumbers.getMaterial(block).isOccluding() && chunk.getItemCount() > 0) {
+ if (object == null && searchForEntities && !org.bukkit.craftbukkit.util.CraftMagicNumbers.getMaterial(block).isOccluding() && chunk.getItemCount(blockposition) > 0) {
List list = world.a((Entity) null, new AxisAlignedBB(d0 - 0.5D, d1 - 0.5D, d2 - 0.5D, d0 + 0.5D, d1 + 0.5D, d2 + 0.5D), IEntitySelector.c);
if (list.size() > 0) {
diff --git a/README.md b/README.md
index c5c3812ab..4da422924 100644
--- a/README.md
+++ b/README.md
@@ -187,6 +187,9 @@ See: [Contributors Page](https://github.com/CobbleSword/NachoSpigot/graphs/contr
[KigPaper-0191] Don't calculate initial light if not requested
[KigPaper-0220] Entity: Use EnumMap in CraftPlayer#playEffect()
+[FlamePaper-0032] Dont load chunks for chests
+[FlamePaper-0033] Dont check occluding hoppers
+[FlamePaper-0034] Hopper item lookup optimization
[FlamePaper-0102] Fixed chunk memory leak
[FlamePaper-0103] Limit CraftChatMessage iterations
[FlamePaper-0104] Return last slot by default
From 4ab8d65b56c4a7f6938c1595ed5f14f17e2c63ed Mon Sep 17 00:00:00 2001
From: crafter23456 <64259198+crafter23456@users.noreply.github.com>
Date: Fri, 25 Mar 2022 14:38:29 +0100
Subject: [PATCH 4/4] already in other PR
---
NachoSpigot-Server/pom.xml | 1 -
1 file changed, 1 deletion(-)
diff --git a/NachoSpigot-Server/pom.xml b/NachoSpigot-Server/pom.xml
index d67bcd1e2..936824373 100644
--- a/NachoSpigot-Server/pom.xml
+++ b/NachoSpigot-Server/pom.xml
@@ -147,7 +147,6 @@
org.mockito
mockito-core
1.10.19
- test
org.hamcrest