mirror of
https://github.com/YatopiaMC/Yatopia.git
synced 2024-11-29 22:23:50 +01:00
Fix Hopper patch, make it even faster
This commit is contained in:
parent
ad2fc38875
commit
7b82d69191
@ -1,17 +1,31 @@
|
||||
From 920e25115ab67f8faed683ea741742f81a933bb4 Mon Sep 17 00:00:00 2001
|
||||
From fa38c57d5703a679e32da11c43f51706281d40f1 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
|
||||
|
||||
---
|
||||
.../net/minecraft/server/BlockDropper.java | 2 +-
|
||||
.../net/minecraft/server/BlockHopper.java | 230 ++++++++++++++++++
|
||||
.../minecraft/server/TileEntityHopper.java | 36 ++-
|
||||
2 files changed, 262 insertions(+), 4 deletions(-)
|
||||
.../minecraft/server/TileEntityHopper.java | 70 +++++-
|
||||
3 files changed, 291 insertions(+), 11 deletions(-)
|
||||
create mode 100644 src/main/java/net/minecraft/server/BlockHopper.java
|
||||
|
||||
diff --git a/src/main/java/net/minecraft/server/BlockDropper.java b/src/main/java/net/minecraft/server/BlockDropper.java
|
||||
index 1ce89c28c2..1b360140b6 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) world.getType(blockposition).get(BlockDropper.FACING);
|
||||
- IInventory iinventory = TileEntityHopper.b(world, blockposition.shift(enumdirection));
|
||||
+ IInventory iinventory = TileEntityHopper.b(world, blockposition.shift(enumdirection), false);
|
||||
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
|
||||
new file mode 100644
|
||||
index 000000000..31ee358f8
|
||||
index 0000000000..31ee358f82
|
||||
--- /dev/null
|
||||
+++ b/src/main/java/net/minecraft/server/BlockHopper.java
|
||||
@@ -0,0 +1,230 @@
|
||||
@ -247,7 +261,7 @@ index 000000000..31ee358f8
|
||||
+}
|
||||
\ No newline at end of file
|
||||
diff --git a/src/main/java/net/minecraft/server/TileEntityHopper.java b/src/main/java/net/minecraft/server/TileEntityHopper.java
|
||||
index 728c829c1..42bd33197 100644
|
||||
index 20df9bd21d..a7f9d3e5ec 100644
|
||||
--- a/src/main/java/net/minecraft/server/TileEntityHopper.java
|
||||
+++ b/src/main/java/net/minecraft/server/TileEntityHopper.java
|
||||
@@ -2,6 +2,7 @@ package net.minecraft.server;
|
||||
@ -258,15 +272,28 @@ index 728c829c1..42bd33197 100644
|
||||
import java.util.function.Supplier;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.IntStream;
|
||||
@@ -611,14 +612,28 @@ public class TileEntityHopper extends TileEntityLootable implements IHopper, ITi
|
||||
@@ -611,14 +612,44 @@ public class TileEntityHopper extends TileEntityLootable implements IHopper, ITi
|
||||
|
||||
@Nullable
|
||||
private IInventory l() {
|
||||
+ if(this.cachedPush != null)return this.cachedPush;
|
||||
+ if(this.cachedPush != null) {
|
||||
+ return this.cachedPush;
|
||||
+ }
|
||||
EnumDirection enumdirection = (EnumDirection) this.getBlock().get(BlockHopper.FACING);
|
||||
|
||||
- return b(this.getWorld(), this.position.shift(enumdirection));
|
||||
+ this.cachedPush = b(this.getWorld(), this.position.shift(enumdirection));
|
||||
+ IInventory tmp = b(this.getWorld(), this.position.shift(enumdirection), this.cachedPushAir);
|
||||
+ if(tmp != null && !(tmp instanceof IWorldInventory) && !(tmp instanceof Entity)) {
|
||||
+ this.cachedPush = tmp;
|
||||
+ }else {
|
||||
+ if(tmp == null) {
|
||||
+ this.cachedPushAir = true;
|
||||
+ }
|
||||
+ return tmp;
|
||||
+ }
|
||||
+ if(this.cachedPush == null) {
|
||||
+ this.cachedPushAir = true;
|
||||
+ }
|
||||
+ return this.cachedPush;
|
||||
}
|
||||
|
||||
@ -279,26 +306,52 @@ index 728c829c1..42bd33197 100644
|
||||
+ if(hopper.cachedAbove != null) {
|
||||
+ return hopper.cachedAbove;
|
||||
+ }
|
||||
+ IInventory inv = a(ihopper.getWorld(), ihopper.x(), ihopper.z() + 1.0D, ihopper.A());
|
||||
+ 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());
|
||||
+ return a(ihopper.getWorld(), ihopper.x(), ihopper.z() + 1.0D, ihopper.A(), false);
|
||||
+ }
|
||||
+ //YAPFA end
|
||||
}
|
||||
|
||||
public static List<EntityItem> c(IHopper ihopper) {
|
||||
@@ -658,7 +673,7 @@ public class TileEntityHopper extends TileEntityLootable implements IHopper, ITi
|
||||
@@ -633,14 +664,15 @@ 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) {
|
||||
+ return a(world, (double) blockposition.getX() + 0.5D, (double) blockposition.getY() + 0.5D, (double) blockposition.getZ() + 0.5D, true, skipBlockCheck); // YAPFA // Paper
|
||||
}
|
||||
|
||||
@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
|
||||
- Object object = null;
|
||||
+ public static IInventory a(World world, double d0, double d1, double d2, boolean skipBlockCheck) { return a(world, d0, d1, d2, false, skipBlockCheck); } // YAPFA // Paper - overload to default false
|
||||
+ public static IInventory a(World world, double d0, double d1, double d2, boolean optimizeEntities, boolean skipBlockCheck) { // YAPFA // Paper
|
||||
+ Object object = null;
|
||||
+ if(!skipBlockCheck) { // YAPFA
|
||||
BlockPosition blockposition = new BlockPosition(d0, d1, d2);
|
||||
if ( !world.isLoaded( blockposition ) ) return null; // Spigot
|
||||
IBlockData iblockdata = world.getType(blockposition);
|
||||
@@ -658,15 +690,16 @@ public class TileEntityHopper extends TileEntityLootable implements IHopper, ITi
|
||||
}
|
||||
}
|
||||
}
|
||||
-
|
||||
- if (object == null && (!optimizeEntities || !org.bukkit.craftbukkit.util.CraftMagicNumbers.getMaterial(block).isOccluding())) { // Paper
|
||||
+ }
|
||||
+
|
||||
if (object == null && (!optimizeEntities || !org.bukkit.craftbukkit.util.CraftMagicNumbers.getMaterial(block).isOccluding())) { // Paper
|
||||
+ if (object == null && (!optimizeEntities || true/*!org.bukkit.craftbukkit.util.CraftMagicNumbers.getMaterial(block).isOccluding()*/)) { // YAPFA // Paper
|
||||
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);
|
||||
|
||||
@@ -666,7 +681,7 @@ public class TileEntityHopper extends TileEntityLootable implements IHopper, ITi
|
||||
if (!list.isEmpty()) {
|
||||
object = (IInventory) list.get(world.random.nextInt(list.size()));
|
||||
}
|
||||
}
|
||||
@ -307,7 +360,7 @@ index 728c829c1..42bd33197 100644
|
||||
return (IInventory) object;
|
||||
}
|
||||
|
||||
@@ -728,4 +743,17 @@ public class TileEntityHopper extends TileEntityLootable implements IHopper, ITi
|
||||
@@ -728,4 +761,21 @@ public class TileEntityHopper extends TileEntityLootable implements IHopper, ITi
|
||||
protected Container createContainer(int i, PlayerInventory playerinventory) {
|
||||
return new ContainerHopper(i, playerinventory, this);
|
||||
}
|
||||
@ -316,10 +369,14 @@ index 728c829c1..42bd33197 100644
|
||||
+
|
||||
+ 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;
|
||||
+ }
|
||||
+
|
||||
+ // YAPFA end
|
||||
|
Loading…
Reference in New Issue
Block a user