Skip to content
This repository has been archived by the owner on May 29, 2022. It is now read-only.

Commit

Permalink
Hopper optimisations (#387)
Browse files Browse the repository at this point in the history
* optimise hoppers

* dont compile mockito

* further optimisations

* already in other PR
  • Loading branch information
crafter23456 authored Mar 29, 2022
1 parent f370fc6 commit 0f63b63
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
12 changes: 12 additions & 0 deletions NachoSpigot-Server/src/main/java/net/minecraft/server/Chunk.java
Original file line number Diff line number Diff line change
Expand Up @@ -1630,4 +1630,16 @@ public static enum EnumTileEntityState {

private EnumTileEntityState() {}
}

// FlamePaper start - Hopper item lookup optimization
public int getItemCount(BlockPosition blockPosition) {
int k = MathHelper.floor(blockPosition.getY() / 16.0D);

k = Math.max(0, k);
k = Math.min(this.entitySlices.length - 1, k);

return itemCounts[k];
}
// FlamePaper end - Hopper item lookup optimization

}
Original file line number Diff line number Diff line change
Expand Up @@ -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(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) {
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 0f63b63

Please sign in to comment.