Prevent Belts under Tunnels from picking up item entities

This commit is contained in:
reidbhuntley 2021-06-20 15:00:31 -04:00
parent ba0e851487
commit 813a1ccaba
2 changed files with 21 additions and 17 deletions

View File

@ -4,6 +4,8 @@ import java.util.ArrayList;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
import com.simibubi.create.content.contraptions.relays.belt.transport.BeltTunnelInteractionHandler;
import org.apache.commons.lang3.mutable.MutableBoolean; import org.apache.commons.lang3.mutable.MutableBoolean;
import com.simibubi.create.AllBlocks; import com.simibubi.create.AllBlocks;
@ -198,6 +200,8 @@ public class BeltBlock extends HorizontalKineticBlock implements ITE<BeltTileEnt
return; return;
if (!entityIn.isAlive()) if (!entityIn.isAlive())
return; return;
if (BeltTunnelInteractionHandler.getTunnelOnPosition(worldIn, pos) != null)
return;
withTileEntityDo(worldIn, pos, te -> { withTileEntityDo(worldIn, pos, te -> {
ItemEntity itemEntity = (ItemEntity) entityIn; ItemEntity itemEntity = (ItemEntity) entityIn;
IItemHandler handler = te.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY) IItemHandler handler = te.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY)

View File

@ -43,7 +43,7 @@ public class BeltTunnelInteractionHandler {
World world = beltInventory.belt.getWorld(); World world = beltInventory.belt.getWorld();
boolean onServer = !world.isRemote || beltInventory.belt.isVirtual(); boolean onServer = !world.isRemote || beltInventory.belt.isVirtual();
boolean removed = false; boolean removed = false;
BeltTunnelTileEntity nextTunnel = getTunnelOnSegement(beltInventory, upcomingSegment); BeltTunnelTileEntity nextTunnel = getTunnelOnSegment(beltInventory, upcomingSegment);
if (nextTunnel instanceof BrassTunnelTileEntity) { if (nextTunnel instanceof BrassTunnelTileEntity) {
BrassTunnelTileEntity brassTunnel = (BrassTunnelTileEntity) nextTunnel; BrassTunnelTileEntity brassTunnel = (BrassTunnelTileEntity) nextTunnel;
@ -124,25 +124,25 @@ public class BeltTunnelInteractionHandler {
} }
public static void flapTunnel(BeltInventory beltInventory, int offset, Direction side, boolean inward) { public static void flapTunnel(BeltInventory beltInventory, int offset, Direction side, boolean inward) {
BeltTunnelTileEntity te = getTunnelOnSegement(beltInventory, offset); BeltTunnelTileEntity te = getTunnelOnSegment(beltInventory, offset);
if (te == null) if (te == null)
return; return;
te.flap(side, inward); te.flap(side, inward);
} }
protected static BeltTunnelTileEntity getTunnelOnSegement(BeltInventory beltInventory, int offset) { protected static BeltTunnelTileEntity getTunnelOnSegment(BeltInventory beltInventory, int offset) {
BeltTileEntity belt = beltInventory.belt; BeltTileEntity belt = beltInventory.belt;
if (belt.getBlockState() if (belt.getBlockState()
.get(BeltBlock.SLOPE) != BeltSlope.HORIZONTAL) .get(BeltBlock.SLOPE) != BeltSlope.HORIZONTAL)
return null; return null;
BlockPos pos = BeltHelper.getPositionForOffset(belt, offset) return getTunnelOnPosition(belt.getWorld(), BeltHelper.getPositionForOffset(belt, offset));
.up(); }
if (!(belt.getWorld()
.getBlockState(pos) public static BeltTunnelTileEntity getTunnelOnPosition(World world, BlockPos pos) {
.getBlock() instanceof BeltTunnelBlock)) pos = pos.up();
if (!(world.getBlockState(pos).getBlock() instanceof BeltTunnelBlock))
return null; return null;
TileEntity te = belt.getWorld() TileEntity te = world.getTileEntity(pos);
.getTileEntity(pos);
if (te == null || !(te instanceof BeltTunnelTileEntity)) if (te == null || !(te instanceof BeltTunnelTileEntity))
return null; return null;
return ((BeltTunnelTileEntity) te); return ((BeltTunnelTileEntity) te);