mirror of
https://github.com/YatopiaMC/Yatopia.git
synced 2024-08-25 07:12:47 +02:00
322 lines
12 KiB
Diff
322 lines
12 KiB
Diff
From de38322ff67af98006f66df5432393809f1f8c4a 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/BlockHopper.java | 229 ++++++++++++++++++
|
|
.../minecraft/server/TileEntityHopper.java | 34 ++-
|
|
2 files changed, 260 insertions(+), 3 deletions(-)
|
|
create mode 100644 src/main/java/net/minecraft/server/BlockHopper.java
|
|
|
|
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..63e024e9d
|
|
--- /dev/null
|
|
+++ b/src/main/java/net/minecraft/server/BlockHopper.java
|
|
@@ -0,0 +1,229 @@
|
|
+package net.minecraft.server;
|
|
+
|
|
+import java.util.OptionalInt;
|
|
+import net.minecraft.server.Block;
|
|
+import net.minecraft.server.BlockActionContext;
|
|
+import net.minecraft.server.BlockPosition;
|
|
+import net.minecraft.server.BlockProperties;
|
|
+import net.minecraft.server.BlockStateBoolean;
|
|
+import net.minecraft.server.BlockStateDirection;
|
|
+import net.minecraft.server.BlockStateList;
|
|
+import net.minecraft.server.BlockTileEntity;
|
|
+import net.minecraft.server.Container;
|
|
+import net.minecraft.server.Entity;
|
|
+import net.minecraft.server.EntityHuman;
|
|
+import net.minecraft.server.EntityLiving;
|
|
+import net.minecraft.server.EnumBlockMirror;
|
|
+import net.minecraft.server.EnumBlockRotation;
|
|
+import net.minecraft.server.EnumDirection;
|
|
+import net.minecraft.server.EnumHand;
|
|
+import net.minecraft.server.EnumInteractionResult;
|
|
+import net.minecraft.server.EnumRenderType;
|
|
+import net.minecraft.server.IBlockAccess;
|
|
+import net.minecraft.server.IBlockData;
|
|
+import net.minecraft.server.IBlockDataHolder;
|
|
+import net.minecraft.server.IBlockState;
|
|
+import net.minecraft.server.IChatBaseComponent;
|
|
+import net.minecraft.server.IHopper;
|
|
+import net.minecraft.server.IInventory;
|
|
+import net.minecraft.server.ITileInventory;
|
|
+import net.minecraft.server.InventoryUtils;
|
|
+import net.minecraft.server.ItemStack;
|
|
+import net.minecraft.server.MinecraftKey;
|
|
+import net.minecraft.server.MovingObjectPositionBlock;
|
|
+import net.minecraft.server.OperatorBoolean;
|
|
+import net.minecraft.server.PathMode;
|
|
+import net.minecraft.server.StatisticList;
|
|
+import net.minecraft.server.TileEntity;
|
|
+import net.minecraft.server.TileEntityHopper;
|
|
+import net.minecraft.server.VoxelShape;
|
|
+import net.minecraft.server.VoxelShapeCollision;
|
|
+import net.minecraft.server.VoxelShapes;
|
|
+import net.minecraft.server.World;
|
|
+
|
|
+public class BlockHopper extends BlockTileEntity {
|
|
+ public static final BlockStateDirection FACING = BlockProperties.M;
|
|
+ public static final BlockStateBoolean ENABLED = BlockProperties.f;
|
|
+ private static final VoxelShape c = Block.a((double) 0.0, (double) 10.0, (double) 0.0, (double) 16.0, (double) 16.0,
|
|
+ (double) 16.0);
|
|
+ private static final VoxelShape d = Block.a((double) 4.0, (double) 4.0, (double) 4.0, (double) 12.0, (double) 10.0,
|
|
+ (double) 12.0);
|
|
+ private static final VoxelShape e = VoxelShapes.a((VoxelShape) d, (VoxelShape) c);
|
|
+ private static final VoxelShape f = VoxelShapes.a((VoxelShape) e, (VoxelShape) IHopper.a,
|
|
+ (OperatorBoolean) OperatorBoolean.ONLY_FIRST);
|
|
+ private static final VoxelShape g = VoxelShapes.a((VoxelShape) f,
|
|
+ (VoxelShape) Block.a((double) 6.0, (double) 0.0, (double) 6.0, (double) 10.0, (double) 4.0, (double) 10.0));
|
|
+ private static final VoxelShape h = VoxelShapes.a((VoxelShape) f, (VoxelShape) Block.a((double) 12.0, (double) 4.0,
|
|
+ (double) 6.0, (double) 16.0, (double) 8.0, (double) 10.0));
|
|
+ private static final VoxelShape i = VoxelShapes.a((VoxelShape) f,
|
|
+ (VoxelShape) Block.a((double) 6.0, (double) 4.0, (double) 0.0, (double) 10.0, (double) 8.0, (double) 4.0));
|
|
+ private static final VoxelShape j = VoxelShapes.a((VoxelShape) f, (VoxelShape) Block.a((double) 6.0, (double) 4.0,
|
|
+ (double) 12.0, (double) 10.0, (double) 8.0, (double) 16.0));
|
|
+ private static final VoxelShape k = VoxelShapes.a((VoxelShape) f,
|
|
+ (VoxelShape) Block.a((double) 0.0, (double) 4.0, (double) 6.0, (double) 4.0, (double) 8.0, (double) 10.0));
|
|
+ private static final VoxelShape w = IHopper.a;
|
|
+ private static final VoxelShape x = VoxelShapes.a((VoxelShape) IHopper.a, (VoxelShape) Block.a((double) 12.0,
|
|
+ (double) 8.0, (double) 6.0, (double) 16.0, (double) 10.0, (double) 10.0));
|
|
+ private static final VoxelShape y = VoxelShapes.a((VoxelShape) IHopper.a,
|
|
+ (VoxelShape) Block.a((double) 6.0, (double) 8.0, (double) 0.0, (double) 10.0, (double) 10.0, (double) 4.0));
|
|
+ private static final VoxelShape z = VoxelShapes.a((VoxelShape) IHopper.a, (VoxelShape) Block.a((double) 6.0,
|
|
+ (double) 8.0, (double) 12.0, (double) 10.0, (double) 10.0, (double) 16.0));
|
|
+ private static final VoxelShape A = VoxelShapes.a((VoxelShape) IHopper.a,
|
|
+ (VoxelShape) Block.a((double) 0.0, (double) 8.0, (double) 6.0, (double) 4.0, (double) 10.0, (double) 10.0));
|
|
+
|
|
+ public BlockHopper(Block.Info var0) {
|
|
+ super(var0);
|
|
+ this.p((IBlockData) ((IBlockData) ((IBlockData) this.blockStateList.getBlockData()).set((IBlockState) FACING,
|
|
+ (Comparable) EnumDirection.DOWN)).set((IBlockState) ENABLED, (Comparable) Boolean.valueOf(true)));
|
|
+ }
|
|
+
|
|
+ public VoxelShape a(IBlockData var0, IBlockAccess var1, BlockPosition var2, VoxelShapeCollision var3) {
|
|
+ switch ((EnumDirection) var0.get((IBlockState) FACING)) {
|
|
+ case DOWN : {
|
|
+ return g;
|
|
+ }
|
|
+ case NORTH : {
|
|
+ return i;
|
|
+ }
|
|
+ case SOUTH : {
|
|
+ return j;
|
|
+ }
|
|
+ case WEST : {
|
|
+ return k;
|
|
+ }
|
|
+ case EAST : {
|
|
+ return h;
|
|
+ }
|
|
+ }
|
|
+ return f;
|
|
+ }
|
|
+
|
|
+ public VoxelShape j(IBlockData var0, IBlockAccess var1, BlockPosition var2) {
|
|
+ switch ((EnumDirection) var0.get((IBlockState) FACING)) {
|
|
+ case DOWN : {
|
|
+ return w;
|
|
+ }
|
|
+ case NORTH : {
|
|
+ return y;
|
|
+ }
|
|
+ case SOUTH : {
|
|
+ return z;
|
|
+ }
|
|
+ case WEST : {
|
|
+ return A;
|
|
+ }
|
|
+ case EAST : {
|
|
+ return x;
|
|
+ }
|
|
+ }
|
|
+ return IHopper.a;
|
|
+ }
|
|
+
|
|
+ public IBlockData getPlacedState(BlockActionContext var0) {
|
|
+ EnumDirection var1;
|
|
+ return (IBlockData) ((IBlockData) this.getBlockData().set((IBlockState) FACING,
|
|
+ (Comparable) ((var1 = var0.getClickedFace().opposite()).m() == EnumDirection.EnumAxis.Y
|
|
+ ? EnumDirection.DOWN
|
|
+ : var1))).set((IBlockState) ENABLED, (Comparable) Boolean.valueOf(true));
|
|
+ }
|
|
+
|
|
+ public TileEntity createTile(IBlockAccess var0) {
|
|
+ return new TileEntityHopper();
|
|
+ }
|
|
+
|
|
+ public void postPlace(World var0, BlockPosition var1, IBlockData var2, EntityLiving var3, ItemStack var4) {
|
|
+ TileEntity var5;
|
|
+ if (var4.hasName() && (var5 = var0.getTileEntity(var1)) instanceof TileEntityHopper) {
|
|
+ ((TileEntityHopper) var5).setCustomName(var4.getName());
|
|
+ }
|
|
+ }
|
|
+
|
|
+ public void onPlace(IBlockData var0, World var1, BlockPosition var2, IBlockData var3, boolean var4) {
|
|
+ if (var3.getBlock() == var0.getBlock()) {
|
|
+ return;
|
|
+ }
|
|
+ this.a(var1, var2, var0);
|
|
+ }
|
|
+
|
|
+ public EnumInteractionResult interact(IBlockData var0, World var1, BlockPosition var2, EntityHuman var3,
|
|
+ EnumHand var4, MovingObjectPositionBlock var5) {
|
|
+ if (var1.isClientSide) {
|
|
+ return EnumInteractionResult.SUCCESS;
|
|
+ }
|
|
+ TileEntity var6 = var1.getTileEntity(var2);
|
|
+ if (var6 instanceof TileEntityHopper) {
|
|
+ var3.openContainer((ITileInventory) ((TileEntityHopper) var6));
|
|
+ var3.a(StatisticList.INSPECT_HOPPER);
|
|
+ }
|
|
+ return EnumInteractionResult.SUCCESS;
|
|
+ }
|
|
+
|
|
+ public void doPhysics(IBlockData var0, World var1, BlockPosition var2, Block var3, BlockPosition var4,
|
|
+ boolean var5) {
|
|
+ this.a(var1, var2, var0);
|
|
+ //YAPFA start
|
|
+ TileEntity tileEntity = var1.getTileEntity(var2);
|
|
+ if (tileEntity instanceof TileEntityHopper) {
|
|
+ ((TileEntityHopper)tileEntity).flushCaches();
|
|
+ }
|
|
+ // YAPFA end
|
|
+ }
|
|
+
|
|
+ private void a(World var0, BlockPosition var1, IBlockData var2) {
|
|
+ boolean var3;
|
|
+ boolean bl = var3 = !var0.isBlockIndirectlyPowered(var1);
|
|
+ if (var3 != (Boolean) var2.get((IBlockState) ENABLED)) {
|
|
+ var0.setTypeAndData(var1, (IBlockData) var2.set((IBlockState) ENABLED, (Comparable) Boolean.valueOf(var3)),
|
|
+ 4);
|
|
+ }
|
|
+ }
|
|
+
|
|
+ public void remove(IBlockData var0, World var1, BlockPosition var2, IBlockData var3, boolean var4) {
|
|
+ if (var0.getBlock() == var3.getBlock()) {
|
|
+ return;
|
|
+ }
|
|
+ TileEntity var5 = var1.getTileEntity(var2);
|
|
+ if (var5 instanceof TileEntityHopper) {
|
|
+ InventoryUtils.dropInventory((World) var1, (BlockPosition) var2, (IInventory) ((TileEntityHopper) var5));
|
|
+ var1.updateAdjacentComparators(var2, (Block) this);
|
|
+ }
|
|
+ super.remove(var0, var1, var2, var3, var4);
|
|
+ }
|
|
+
|
|
+ public EnumRenderType c(IBlockData var0) {
|
|
+ return EnumRenderType.MODEL;
|
|
+ }
|
|
+
|
|
+ public boolean isComplexRedstone(IBlockData var0) {
|
|
+ return true;
|
|
+ }
|
|
+
|
|
+ public int a(IBlockData var0, World var1, BlockPosition var2) {
|
|
+ return Container.a((TileEntity) var1.getTileEntity(var2));
|
|
+ }
|
|
+
|
|
+ public IBlockData a(IBlockData var0, EnumBlockRotation var1) {
|
|
+ return (IBlockData) var0.set((IBlockState) FACING,
|
|
+ (Comparable) var1.a((EnumDirection) var0.get((IBlockState) FACING)));
|
|
+ }
|
|
+
|
|
+ public IBlockData a(IBlockData var0, EnumBlockMirror var1) {
|
|
+ return var0.a(var1.a((EnumDirection) var0.get((IBlockState) FACING)));
|
|
+ }
|
|
+
|
|
+ protected void a(BlockStateList.a<Block, IBlockData> var0) {
|
|
+ var0.a(new IBlockState[]{FACING, ENABLED});
|
|
+ }
|
|
+
|
|
+ public void a(IBlockData var0, World var1, BlockPosition var2, Entity var3) {
|
|
+ TileEntity var4 = var1.getTileEntity(var2);
|
|
+ if (var4 instanceof TileEntityHopper) {
|
|
+ ((TileEntityHopper) var4).a(var3);
|
|
+ }
|
|
+ }
|
|
+
|
|
+ public boolean a(IBlockData var0, IBlockAccess var1, BlockPosition var2, PathMode var3) {
|
|
+ return false;
|
|
+ }
|
|
+
|
|
+}
|
|
\ 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 c755faed4..5220e8673 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;
|
|
|
|
import java.util.Iterator;
|
|
import java.util.List;
|
|
+import java.util.Optional;
|
|
import java.util.function.Supplier;
|
|
import java.util.stream.Collectors;
|
|
import java.util.stream.IntStream;
|
|
@@ -618,7 +619,23 @@ public class TileEntityHopper extends TileEntityLootable implements IHopper, ITi
|
|
|
|
@Nullable
|
|
public static IInventory b(IHopper ihopper) {
|
|
- return a(ihopper.getWorld(), ihopper.z(), ihopper.A() + 1.0D, ihopper.B());
|
|
+ //YAPFA start
|
|
+ if(ihopper instanceof TileEntityHopper) {
|
|
+ TileEntityHopper hopper = (TileEntityHopper) ihopper;
|
|
+ if(hopper.cachedAbove != null) {
|
|
+ if(hopper.cachedAbove.isPresent()) {
|
|
+ return hopper.cachedAbove.get();
|
|
+ }else {
|
|
+ //should look for items?
|
|
+ }
|
|
+ }
|
|
+ IInventory inv = a(ihopper.getWorld(), ihopper.z(), ihopper.A() + 1.0D, ihopper.B());
|
|
+ hopper.cachedAbove = Optional.ofNullable(inv);
|
|
+ return inv;
|
|
+ }else {
|
|
+ return a(ihopper.getWorld(), ihopper.z(), ihopper.A() + 1.0D, ihopper.B());
|
|
+ }
|
|
+ //YAPFA end
|
|
}
|
|
|
|
public static List<EntityItem> c(IHopper ihopper) {
|
|
@@ -658,7 +675,7 @@ public class TileEntityHopper extends TileEntityLootable implements IHopper, ITi
|
|
}
|
|
}
|
|
}
|
|
-
|
|
+
|
|
if (object == null && (!optimizeEntities || !org.bukkit.craftbukkit.util.CraftMagicNumbers.getMaterial(block).isOccluding())) { // 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 +683,7 @@ public class TileEntityHopper extends TileEntityLootable implements IHopper, ITi
|
|
object = (IInventory) list.get(world.random.nextInt(list.size()));
|
|
}
|
|
}
|
|
-
|
|
+
|
|
return (IInventory) object;
|
|
}
|
|
|
|
@@ -728,4 +745,15 @@ public class TileEntityHopper extends TileEntityLootable implements IHopper, ITi
|
|
protected Container createContainer(int i, PlayerInventory playerinventory) {
|
|
return new ContainerHopper(i, playerinventory, this);
|
|
}
|
|
+
|
|
+ // YAPFA start
|
|
+
|
|
+ private Optional<IInventory> cachedAbove = null;
|
|
+
|
|
+ public void flushCaches() {
|
|
+ cachedAbove = null;
|
|
+ }
|
|
+
|
|
+ // YAPFA end
|
|
+
|
|
}
|
|
--
|
|
2.25.1.windows.1
|
|
|