Yatopia/patches/removed/server/0021-Optimize-Hopper-logic.patch

145 lines
6.9 KiB
Diff
Raw Normal View History

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
diff --git a/src/main/java/net/minecraft/server/BlockHopper.java b/src/main/java/net/minecraft/server/BlockHopper.java
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);
+ // 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
index 95bede605c6401af10f18b641cd12c9d8ec2f207..0a975642ce0cce4cbce02e9be976427ed42cce65 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
@@ -661,14 +661,93 @@ public class TileEntityHopper extends TileEntityLootable implements IHopper, ITi
2020-06-27 20:02:39 +02:00
@Nullable
private IInventory l() {
+ // Yatopia start
+ if (!shouldNotCachePush && cachedPush != null) {
+ 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));
+ // Yatopia start - replace logic
+ //return b(this.getWorld(), this.position.shift(enumdirection));
+ // basically reimplement TileEntityHopper#b but in a better way in order to
+ // not make them composters bork
+ if (shouldNotCachePush || !cachedPushAir) {
+ BlockPosition shifted = this.position.shift(enumdirection);
+ BlockPosition checkedPosition = new BlockPosition(shifted.getX() + 0.5D, shifted.getY() + 0.5D, shifted.getZ() + 0.5D);
+ 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);
+ shouldNotCachePush = 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);
+ }
+ if (inv instanceof EntityMinecartContainer) {
+ shouldNotCachePush = true;
+ }
+ this.cachedPush = inv;
+ }
+ }
2020-07-16 23:27:15 +02:00
+ }
+ if (this.cachedPush == null) {
+ this.cachedPushAir = true;
2020-07-16 23:27:15 +02:00
+ }
2020-06-27 20:02:39 +02:00
+ return this.cachedPush;
+ // Yatopia end
2020-06-27 20:02:39 +02:00
}
@Nullable
public static IInventory b(IHopper ihopper) {
+ // Yatopia start - replaced logic
+ if (ihopper instanceof TileEntityHopper) {
+ TileEntityHopper hopper = (TileEntityHopper) ihopper;
+ if (!hopper.shouldNotCachePull && hopper.cachedAbove != null) {
+ return hopper.cachedAbove;
+ }
+ // reimplement here too cuz minecarts
+ BlockPosition pos = new BlockPosition(ihopper.getX(), ihopper.getY() + 1.0D, ihopper.getZ());
+ if (hopper.shouldNotCachePull || hopper.cachedPullAir) {
+ if (hopper.world.isLoaded(pos)) return null;
+ IBlockData blockData = hopper.world.getType(pos);
+ Block block = blockData.getBlock();
+ if (block instanceof IInventoryHolder) {
+ hopper.cachedAbove = ((IInventoryHolder) block).a(blockData, hopper.world, pos);
+ hopper.shouldNotCachePull = true;
+ } else if (block.isTileEntity()) {
+ TileEntity tileEntity = hopper.world.getTileEntity(pos);
+ if (tileEntity instanceof IInventory) {
+ IInventory inv = (IInventory) tileEntity;
+ if (inv instanceof TileEntityChest && block instanceof BlockChest) {
+ inv = BlockChest.getInventory((BlockChest) block, blockData, hopper.world, pos, true);
+ }
+ if (inv instanceof EntityMinecartContainer) {
+ hopper.shouldNotCachePull = true;
+ }
+ hopper.cachedAbove = inv;
+ }
+ }
+ }
+ if (hopper.cachedAbove == null) {
+ List<Entity> list = hopper.world.getEntities((Entity) null, new AxisAlignedBB(pos.getX() - 0.5D, pos.getY() - 0.5D, pos.getZ() - 0.5D, pos.getX() + 0.5D, pos.getY() + 0.5D, pos.getZ() + 0.5D), IEntitySelector.d);
+
+ if (!list.isEmpty()) {
+ hopper.cachedAbove = (IInventory) list.get(java.util.concurrent.ThreadLocalRandom.current().nextInt(list.size()));
+ }
+ }
+ if (hopper.cachedAbove == null) {
+ hopper.cachedPullAir = true;
+ }
+ return hopper.cachedAbove;
+ } else {
return a(ihopper.getWorld(), ihopper.x(), ihopper.z() + 1.0D, ihopper.A());
+ }
+ // Yatopia end
2020-06-27 20:02:39 +02:00
}
public static List<EntityItem> c(IHopper ihopper) {
@@ -779,4 +858,21 @@ 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);
}
[WIP] Better Patch System (#18) * Update build.yml * Remove 3rd party patches * Add Upsteam Submodules * Fix patches * ? * Fix patches * Add Fast Init script * Lots of stuff also it's broke * more broken * fixes * mor stuff * gfhfgh hg * fix patch * fix up script * update submodule * add papercut * update tuinity * update gitmodules * fix var name * fix more var stuff * some how it's not deleting shit anymore * should now use the branch it just made why are we doing this again? * now it does thing thing * return previous so YAPFA can use it * ok now it really does the thing * for REAL it does the thing * don't do the thing because it causes too many problems * fix api * work * use better patching for YAPFA patches * fix better patching * more fixes * new patches stuff * remove old 3rd parry patches add removed akarin patches * make new branch for making patches * hopefully build patches correctly * fix gitignore and add config patches * remove papercut files * fix some weirdness * fix bug * time to do some fixin' :eyes: * New Patch System Rebased Patches * fix full build * exit 1 * fix * Remove patch * Hopefully fix compile errors * fixes * this might work * don't use rej for our patches * tmp disable cache * some times case sensitivity is dumb * my sanity is at an all time low :) * dfg * readd cahce * fix? * Update Upstream * fix perms * fix * fix api * Redo API * rm folders * fix villager brain patch * emc explosion pref * fixed aikar's shit * betterfix * fix lagggg * Origami * Origami Fixes * Update readme * test async path finding * WIP Async Path Finding * WIP fix async path finding * same as bellow * same * update to newer funcs * fix newer funcs * fix author * Updates, Fixes, and new patches * fixes * possibly async flying path finding * minor asnyc pathfinding fix * test remove non asnyc path finder * WIP make all path finding async * Rename everything * Exec flag * Rebuild hashes * remove dupe patch * fix? * Fix packages, redirect config * old nav class is now async and back * add getchatcolor.getbyid and handle patches with a . in them better Co-authored-by: tr7zw <tr7zw@live.de> Co-authored-by: Unknown <unknown@example.com> Co-authored-by: Ovydux <68059159+Ovydux@users.noreply.github.com>
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;
+ private boolean shouldNotCachePush = false;
+ private boolean shouldNotCachePull = false;
2020-06-27 20:02:39 +02:00
+ public void flushCaches() {
+ cachedAbove = null;
+ cachedPush = null;
+ cachedPushAir = false;
+ cachedPullAir = false;
+ shouldNotCachePush = false;
+ shouldNotCachePull = false;
2020-06-27 20:02:39 +02:00
+ }
+ // Yatopia end
2020-06-27 20:02:39 +02:00
}