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.List;
import com.simibubi.create.content.contraptions.relays.belt.transport.BeltTunnelInteractionHandler;
import org.apache.commons.lang3.mutable.MutableBoolean;
import com.simibubi.create.AllBlocks;
@ -198,6 +200,8 @@ public class BeltBlock extends HorizontalKineticBlock implements ITE<BeltTileEnt
return;
if (!entityIn.isAlive())
return;
if (BeltTunnelInteractionHandler.getTunnelOnPosition(worldIn, pos) != null)
return;
withTileEntityDo(worldIn, pos, te -> {
ItemEntity itemEntity = (ItemEntity) entityIn;
IItemHandler handler = te.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY)
@ -362,7 +366,7 @@ public class BeltBlock extends HorizontalKineticBlock implements ITE<BeltTileEnt
ISelectionContext context) {
if (state.getBlock() != this)
return VoxelShapes.empty();
VoxelShape shape = getShape(state, worldIn, pos, context);
return getTileEntityOptional(worldIn, pos).map(te -> {
if (context.getEntity() == null)
@ -371,10 +375,10 @@ public class BeltBlock extends HorizontalKineticBlock implements ITE<BeltTileEnt
BeltTileEntity controller = te.getControllerTE();
if (controller == null)
return shape;
if (controller.passengers == null || !controller.passengers.containsKey(context.getEntity()))
if (controller.passengers == null || !controller.passengers.containsKey(context.getEntity()))
return BeltShapes.getCollisionShape(state);
return shape;
}).orElse(shape);
}

View file

@ -43,8 +43,8 @@ public class BeltTunnelInteractionHandler {
World world = beltInventory.belt.getWorld();
boolean onServer = !world.isRemote || beltInventory.belt.isVirtual();
boolean removed = false;
BeltTunnelTileEntity nextTunnel = getTunnelOnSegement(beltInventory, upcomingSegment);
BeltTunnelTileEntity nextTunnel = getTunnelOnSegment(beltInventory, upcomingSegment);
if (nextTunnel instanceof BrassTunnelTileEntity) {
BrassTunnelTileEntity brassTunnel = (BrassTunnelTileEntity) nextTunnel;
if (brassTunnel.hasDistributionBehaviour()) {
@ -80,13 +80,13 @@ public class BeltTunnelInteractionHandler {
continue;
if (!behaviour.canInsertFromSide(d))
continue;
ItemStack toinsert = ItemHandlerHelper.copyStackWithSize(current.stack, 1);
if (!behaviour.handleInsertion(toinsert, d, false).isEmpty())
return true;
if (onServer)
if (onServer)
flapTunnel(beltInventory, upcomingSegment, d, false);
current.stack.shrink(1);
beltInventory.belt.sendData();
if (current.stack.getCount() <= 1)
@ -124,25 +124,25 @@ public class BeltTunnelInteractionHandler {
}
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)
return;
te.flap(side, inward);
}
protected static BeltTunnelTileEntity getTunnelOnSegement(BeltInventory beltInventory, int offset) {
protected static BeltTunnelTileEntity getTunnelOnSegment(BeltInventory beltInventory, int offset) {
BeltTileEntity belt = beltInventory.belt;
if (belt.getBlockState()
.get(BeltBlock.SLOPE) != BeltSlope.HORIZONTAL)
return null;
BlockPos pos = BeltHelper.getPositionForOffset(belt, offset)
.up();
if (!(belt.getWorld()
.getBlockState(pos)
.getBlock() instanceof BeltTunnelBlock))
return getTunnelOnPosition(belt.getWorld(), BeltHelper.getPositionForOffset(belt, offset));
}
public static BeltTunnelTileEntity getTunnelOnPosition(World world, BlockPos pos) {
pos = pos.up();
if (!(world.getBlockState(pos).getBlock() instanceof BeltTunnelBlock))
return null;
TileEntity te = belt.getWorld()
.getTileEntity(pos);
TileEntity te = world.getTileEntity(pos);
if (te == null || !(te instanceof BeltTunnelTileEntity))
return null;
return ((BeltTunnelTileEntity) te);