Yatopia/patches/server/0021-Optimize-Hopper-logic.patch
Ivan Pekov 5f55124016
Initial 1.16.2 support
This update had major internal changes, which took us 8 hours to figure out and resolve all things untill we have a successful build.
YatopiaMC members wish you happy playing using Yatopia for your server software

MAKE A BACKUP OF YOUR WORLD BEFORE RUNNING IT ON YOUR SERVER. YOU HAVE BEEN WARNED.
People have reported to paper that after upgrading villagers are gone. There could be even more issues we are unknown of.
MAKE A BACKUP OF YOUR WORLD BEFORE RUNNING IT ON YOUR SERVER. YOU HAVE BEEN WARNED.

Co-authored-by: Ovydux <68059159+Ovydux@users.noreply.github.com>
Co-authored-by: Simon Gardling <Titaniumtown@gmail.com>
Co-authored-by: budgidiere <sgidiere@gmail.com>
2020-08-13 18:53:32 +03:00

139 lines
7.0 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: tr7zw <tr7zw@live.de>
Date: Fri, 26 Jun 2020 01:11:47 +0200
Subject: [PATCH] Optimize Hopper logic
diff --git a/src/main/java/net/minecraft/server/BlockDropper.java b/src/main/java/net/minecraft/server/BlockDropper.java
index 65c212690d8ba7c8ea55d4d3b6af1ba3d9f4a7f6..da8c0ee5184a234f485c2f05e2c6edd965576cbe 100644
--- a/src/main/java/net/minecraft/server/BlockDropper.java
+++ b/src/main/java/net/minecraft/server/BlockDropper.java
@@ -36,7 +36,7 @@ public class BlockDropper extends BlockDispenser {
if (!itemstack.isEmpty()) {
EnumDirection enumdirection = (EnumDirection) worldserver.getType(blockposition).get(BlockDropper.FACING);
- IInventory iinventory = TileEntityHopper.b((World) worldserver, blockposition.shift(enumdirection));
+ IInventory iinventory = TileEntityHopper.b((World) worldserver, blockposition.shift(enumdirection), false); // Yatopia
ItemStack itemstack1;
if (iinventory == null) {
diff --git a/src/main/java/net/minecraft/server/BlockHopper.java b/src/main/java/net/minecraft/server/BlockHopper.java
index a29294fbc7cd6fcfff0df9eadd11de3bd7f1405e..2f66740de68667e5c0054a0bc7990256163087cd 100644
--- a/src/main/java/net/minecraft/server/BlockHopper.java
+++ b/src/main/java/net/minecraft/server/BlockHopper.java
@@ -110,6 +110,12 @@ public class BlockHopper extends BlockTileEntity {
@Override
public void doPhysics(IBlockData iblockdata, World world, BlockPosition blockposition, Block block, BlockPosition blockposition1, boolean flag) {
this.a(world, blockposition, iblockdata);
+ // Yatopia start
+ TileEntity tileEntity = world.getTileEntity(blockposition);
+ if (tileEntity instanceof TileEntityHopper) {
+ ((TileEntityHopper) tileEntity).flushCaches();
+ }
+ // Yatopia end
}
private void a(World world, BlockPosition blockposition, IBlockData iblockdata) {
diff --git a/src/main/java/net/minecraft/server/TileEntityHopper.java b/src/main/java/net/minecraft/server/TileEntityHopper.java
index 95bede605c6401af10f18b641cd12c9d8ec2f207..b4ec6fb407f86bd03d003d9b555df0c58cd6ced5 100644
--- a/src/main/java/net/minecraft/server/TileEntityHopper.java
+++ b/src/main/java/net/minecraft/server/TileEntityHopper.java
@@ -661,14 +661,47 @@ public class TileEntityHopper extends TileEntityLootable implements IHopper, ITi
@Nullable
private IInventory l() {
+ // Yatopia start
+ if (cachedPush != null) {
+ return cachedPush;
+ }
+ // Yatopia end
EnumDirection enumdirection = (EnumDirection) this.getBlock().get(BlockHopper.FACING);
- return b(this.getWorld(), this.position.shift(enumdirection));
+ // Yatopia start - replace logic
+ //return b(this.getWorld(), this.position.shift(enumdirection));
+ IInventory tmp = b(this.getWorld(), this.position.shift(enumdirection), cachedPushAir);
+ if (tmp != null && !(tmp instanceof IWorldInventory) && !(tmp instanceof Entity)) {
+ this.cachedPush = tmp;
+ } else {
+ cachedPushAir = true;
+ return tmp;
+ }
+ if (this.cachedPush == null) {
+ this.cachedPushAir = true;
+ }
+ return this.cachedPush;
+ // Yatopia end
}
@Nullable
public static IInventory b(IHopper ihopper) {
+ // Yatopia start - replaced logic
+ if (ihopper instanceof TileEntityHopper) {
+ TileEntityHopper hopper = (TileEntityHopper) ihopper;
+ if (hopper.cachedAbove != null) {
+ return hopper.cachedAbove;
+ }
+ IInventory inv = a(ihopper.getWorld(), ihopper.x(), ihopper.z() + 1.0D, ihopper.A(), hopper.cachedPullAir);
+ hopper.cachedAbove = inv;
+ if (hopper.cachedAbove == null) {
+ hopper.cachedPullAir = true;
+ }
+ return inv;
+ } else {
return a(ihopper.getWorld(), ihopper.x(), ihopper.z() + 1.0D, ihopper.A());
+ }
+ // Yatopia end
}
public static List<EntityItem> c(IHopper ihopper) {
@@ -683,14 +716,16 @@ public class TileEntityHopper extends TileEntityLootable implements IHopper, ITi
}
@Nullable
- public static IInventory b(World world, BlockPosition blockposition) {
- return a(world, (double) blockposition.getX() + 0.5D, (double) blockposition.getY() + 0.5D, (double) blockposition.getZ() + 0.5D, true); // Paper
+ public static IInventory b(World world, BlockPosition blockposition, boolean skipBlockCheck) { // Yatopia
+ return a(world, (double) blockposition.getX() + 0.5D, (double) blockposition.getY() + 0.5D, (double) blockposition.getZ() + 0.5D, true, skipBlockCheck); // Paper // Yatopia
}
@Nullable
- public static IInventory a(World world, double d0, double d1, double d2) { return a(world, d0, d1, d2, false); } // Paper - overload to default false
- public static IInventory a(World world, double d0, double d1, double d2, boolean optimizeEntities) { // Paper
+ public static IInventory a(World world, double d0, double d1, double d2) { return a(world, d0, d1, d2, false); } // Yatopia
+ public static IInventory a(World world, double d0, double d1, double d2, boolean skipBlockCheck) { return a(world, d0, d1, d2, false, skipBlockCheck); } // Paper - overload to default false // Yatopia
+ public static IInventory a(World world, double d0, double d1, double d2, boolean optimizeEntities, boolean skipBlockCheck) { // Paper // Yatopia
Object object = null;
+ if (!skipBlockCheck) { // Yatopia
BlockPosition blockposition = new BlockPosition(d0, d1, d2);
if ( !world.isLoaded( blockposition ) ) return null; // Spigot
IBlockData iblockdata = world.getType(blockposition);
@@ -708,8 +743,9 @@ public class TileEntityHopper extends TileEntityLootable implements IHopper, ITi
}
}
}
+ } // Yatopia
- if (object == null && (!optimizeEntities || !org.bukkit.craftbukkit.util.CraftMagicNumbers.getMaterial(block).isOccluding())) { // Paper
+ if (object == null && !optimizeEntities) { // Paper // Yatopia
List<Entity> list = world.getEntities((Entity) null, new AxisAlignedBB(d0 - 0.5D, d1 - 0.5D, d2 - 0.5D, d0 + 0.5D, d1 + 0.5D, d2 + 0.5D), IEntitySelector.d);
if (!list.isEmpty()) {
@@ -779,4 +815,16 @@ public class TileEntityHopper extends TileEntityLootable implements IHopper, ITi
protected Container createContainer(int i, PlayerInventory playerinventory) {
return new ContainerHopper(i, playerinventory, this);
}
+
+ // Yatopia start
+ private IInventory cachedAbove = null;
+ private IInventory cachedPush = null;
+ private boolean cachedPushAir = false;
+ private boolean cachedPullAir = false;
+ public void flushCaches() {
+ cachedAbove = null;
+ cachedPush = null;
+ cachedPushAir = false;
+ cachedPullAir = false;
+ }
}