2020-07-17 18:05:50 +02:00
|
|
|
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
2020-06-27 20:02:39 +02:00
|
|
|
From: tr7zw <tr7zw@live.de>
|
|
|
|
Date: Fri, 26 Jun 2020 01:11:47 +0200
|
|
|
|
Subject: [PATCH] Optimize Hopper logic
|
|
|
|
|
|
|
|
|
2020-07-16 23:27:15 +02:00
|
|
|
diff --git a/src/main/java/net/minecraft/server/BlockDropper.java b/src/main/java/net/minecraft/server/BlockDropper.java
|
2020-08-13 17:53:32 +02:00
|
|
|
index 65c212690d8ba7c8ea55d4d3b6af1ba3d9f4a7f6..da8c0ee5184a234f485c2f05e2c6edd965576cbe 100644
|
2020-07-16 23:27:15 +02:00
|
|
|
--- 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()) {
|
2020-08-13 17:53:32 +02:00
|
|
|
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
|
2020-07-16 23:27:15 +02:00
|
|
|
ItemStack itemstack1;
|
|
|
|
|
|
|
|
if (iinventory == null) {
|
2020-06-27 20:02:39 +02:00
|
|
|
diff --git a/src/main/java/net/minecraft/server/BlockHopper.java b/src/main/java/net/minecraft/server/BlockHopper.java
|
2020-08-13 17:53:32 +02:00
|
|
|
index a29294fbc7cd6fcfff0df9eadd11de3bd7f1405e..2f66740de68667e5c0054a0bc7990256163087cd 100644
|
2020-07-17 18:21:30 +02:00
|
|
|
--- a/src/main/java/net/minecraft/server/BlockHopper.java
|
2020-06-27 20:02:39 +02:00
|
|
|
+++ b/src/main/java/net/minecraft/server/BlockHopper.java
|
2020-07-17 18:21:30 +02:00
|
|
|
@@ -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);
|
2020-08-13 17:53:32 +02:00
|
|
|
+ // Yatopia start
|
|
|
|
+ TileEntity tileEntity = world.getTileEntity(blockposition);
|
|
|
|
+ if (tileEntity instanceof TileEntityHopper) {
|
|
|
|
+ ((TileEntityHopper) tileEntity).flushCaches();
|
|
|
|
+ }
|
|
|
|
+ // Yatopia end
|
2020-07-17 18:21:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private void a(World world, BlockPosition blockposition, IBlockData iblockdata) {
|
2020-06-27 20:02:39 +02:00
|
|
|
diff --git a/src/main/java/net/minecraft/server/TileEntityHopper.java b/src/main/java/net/minecraft/server/TileEntityHopper.java
|
2020-08-17 20:39:05 +02:00
|
|
|
index 95bede605c6401af10f18b641cd12c9d8ec2f207..1e74b550e4f1ffc7800db24605f9b3f5f5736aae 100644
|
2020-06-27 20:02:39 +02:00
|
|
|
--- a/src/main/java/net/minecraft/server/TileEntityHopper.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/TileEntityHopper.java
|
2020-08-17 20:39:05 +02:00
|
|
|
@@ -661,14 +661,62 @@ public class TileEntityHopper extends TileEntityLootable implements IHopper, ITi
|
2020-06-27 20:02:39 +02:00
|
|
|
|
|
|
|
@Nullable
|
|
|
|
private IInventory l() {
|
2020-08-11 20:40:29 +02:00
|
|
|
+ // Yatopia start
|
2020-08-17 20:39:05 +02:00
|
|
|
+ if (!blockUnderWasComposter && cachedPush != null) {
|
2020-08-13 17:53:32 +02:00
|
|
|
+ return cachedPush;
|
|
|
|
+ }
|
|
|
|
+ // Yatopia end
|
2020-06-27 20:02:39 +02:00
|
|
|
EnumDirection enumdirection = (EnumDirection) this.getBlock().get(BlockHopper.FACING);
|
|
|
|
|
|
|
|
- return b(this.getWorld(), this.position.shift(enumdirection));
|
2020-08-13 17:53:32 +02:00
|
|
|
+ // Yatopia start - replace logic
|
|
|
|
+ //return b(this.getWorld(), this.position.shift(enumdirection));
|
2020-08-17 20:39:05 +02:00
|
|
|
+ // basically reimplement TileEntityHopper#b but in a better way in order to
|
|
|
|
+ // not make them composters bork
|
|
|
|
+ BlockPosition shifted = this.position.shift(enumdirection);
|
|
|
|
+ BlockPosition checkedPosition = new BlockPosition(shifted.getX() + 0.5D, shifted.getY() + 0.5D, shifted.getZ() + 0.5D);
|
|
|
|
+ if (blockUnderWasComposter || !cachedPushAir) {
|
|
|
|
+ if (!world.isLoaded(checkedPosition)) return null;
|
|
|
|
+ IBlockData blockData = world.getType(checkedPosition);
|
|
|
|
+ Block block = blockData.getBlock();
|
|
|
|
+ if (block instanceof IInventoryHolder) {
|
|
|
|
+ this.cachedPush = ((IInventoryHolder) block).a(blockData, world, checkedPosition);
|
|
|
|
+ blockUnderWasComposter = true;
|
|
|
|
+ } else if (block.isTileEntity()) {
|
|
|
|
+ TileEntity tileEntity = world.getTileEntity(checkedPosition);
|
|
|
|
+ if (tileEntity instanceof IInventory) {
|
|
|
|
+ IInventory inv = (IInventory) tileEntity;
|
|
|
|
+ if (inv instanceof TileEntityChest && block instanceof BlockChest) {
|
|
|
|
+ inv = BlockChest.getInventory((BlockChest) block, blockData, world, checkedPosition, true);
|
|
|
|
+ }
|
|
|
|
+ this.cachedPush = inv;
|
|
|
|
+ }
|
|
|
|
+ }
|
2020-07-16 23:27:15 +02:00
|
|
|
+ }
|
2020-08-11 20:40:29 +02:00
|
|
|
+ if (this.cachedPush == null) {
|
2020-08-13 17:53:32 +02:00
|
|
|
+ this.cachedPushAir = true;
|
2020-07-16 23:27:15 +02:00
|
|
|
+ }
|
2020-06-27 20:02:39 +02:00
|
|
|
+ return this.cachedPush;
|
2020-08-13 17:53:32 +02:00
|
|
|
+ // Yatopia end
|
2020-06-27 20:02:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Nullable
|
|
|
|
public static IInventory b(IHopper ihopper) {
|
2020-08-13 17:53:32 +02:00
|
|
|
+ // 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;
|
|
|
|
+ }
|
2020-06-27 20:02:39 +02:00
|
|
|
+ return inv;
|
2020-08-13 17:53:32 +02:00
|
|
|
+ } else {
|
|
|
|
return a(ihopper.getWorld(), ihopper.x(), ihopper.z() + 1.0D, ihopper.A());
|
|
|
|
+ }
|
2020-08-11 20:40:29 +02:00
|
|
|
+ // Yatopia end
|
2020-06-27 20:02:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public static List<EntityItem> c(IHopper ihopper) {
|
2020-08-17 20:39:05 +02:00
|
|
|
@@ -683,14 +731,16 @@ public class TileEntityHopper extends TileEntityLootable implements IHopper, ITi
|
2020-07-16 23:27:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@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
|
2020-08-13 17:53:32 +02:00
|
|
|
+ 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
|
2020-07-16 23:27:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@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
|
2020-08-13 17:53:32 +02:00
|
|
|
+ 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
|
2020-07-16 23:27:15 +02:00
|
|
|
BlockPosition blockposition = new BlockPosition(d0, d1, d2);
|
|
|
|
if ( !world.isLoaded( blockposition ) ) return null; // Spigot
|
|
|
|
IBlockData iblockdata = world.getType(blockposition);
|
2020-08-17 20:39:05 +02:00
|
|
|
@@ -708,8 +758,9 @@ public class TileEntityHopper extends TileEntityLootable implements IHopper, ITi
|
2020-06-27 20:02:39 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-08-13 17:53:32 +02:00
|
|
|
+ } // Yatopia
|
2020-08-03 18:48:42 +02:00
|
|
|
|
2020-07-16 23:27:15 +02:00
|
|
|
- if (object == null && (!optimizeEntities || !org.bukkit.craftbukkit.util.CraftMagicNumbers.getMaterial(block).isOccluding())) { // Paper
|
2020-08-13 17:53:32 +02:00
|
|
|
+ if (object == null && !optimizeEntities) { // Paper // Yatopia
|
2020-06-27 20:02:39 +02:00
|
|
|
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);
|
|
|
|
|
2020-07-16 23:27:15 +02:00
|
|
|
if (!list.isEmpty()) {
|
2020-08-17 20:39:05 +02:00
|
|
|
@@ -779,4 +830,18 @@ public class TileEntityHopper extends TileEntityLootable implements IHopper, ITi
|
2020-06-27 20:02:39 +02:00
|
|
|
protected Container createContainer(int i, PlayerInventory playerinventory) {
|
|
|
|
return new ContainerHopper(i, playerinventory, this);
|
|
|
|
}
|
2020-08-03 18:48:42 +02:00
|
|
|
+
|
|
|
|
+ // Yatopia start
|
2020-06-27 20:02:39 +02:00
|
|
|
+ private IInventory cachedAbove = null;
|
|
|
|
+ private IInventory cachedPush = null;
|
2020-07-16 23:27:15 +02:00
|
|
|
+ private boolean cachedPushAir = false;
|
|
|
|
+ private boolean cachedPullAir = false;
|
2020-08-17 20:39:05 +02:00
|
|
|
+ private boolean blockUnderWasComposter = false;
|
2020-06-27 20:02:39 +02:00
|
|
|
+ public void flushCaches() {
|
2020-08-13 17:53:32 +02:00
|
|
|
+ cachedAbove = null;
|
|
|
|
+ cachedPush = null;
|
|
|
|
+ cachedPushAir = false;
|
|
|
|
+ cachedPullAir = false;
|
2020-08-17 20:39:05 +02:00
|
|
|
+ blockUnderWasComposter = false;
|
2020-06-27 20:02:39 +02:00
|
|
|
+ }
|
|
|
|
}
|