use of com.simibubi.create.content.logistics.block.funnel.BeltFunnelBlock in project Create by Creators-of-Create.
the class BeltTunnelBlock method canHaveWindow.
protected boolean canHaveWindow(BlockGetter reader, BlockPos pos, Axis axis) {
Direction fw = Direction.get(AxisDirection.POSITIVE, axis);
BlockState blockState1 = reader.getBlockState(pos.relative(fw));
BlockState blockState2 = reader.getBlockState(pos.relative(fw.getOpposite()));
boolean funnel1 = blockState1.getBlock() instanceof BeltFunnelBlock && blockState1.getValue(BeltFunnelBlock.SHAPE) == BeltFunnelBlock.Shape.EXTENDED && blockState1.getValue(BeltFunnelBlock.HORIZONTAL_FACING) == fw.getOpposite();
boolean funnel2 = blockState2.getBlock() instanceof BeltFunnelBlock && blockState2.getValue(BeltFunnelBlock.SHAPE) == BeltFunnelBlock.Shape.EXTENDED && blockState2.getValue(BeltFunnelBlock.HORIZONTAL_FACING) == fw;
boolean valid1 = blockState1.getBlock() instanceof BeltTunnelBlock || funnel1;
boolean valid2 = blockState2.getBlock() instanceof BeltTunnelBlock || funnel2;
boolean canHaveWindow = valid1 && valid2 && !(funnel1 && funnel2);
return canHaveWindow;
}
use of com.simibubi.create.content.logistics.block.funnel.BeltFunnelBlock in project Create by Creators-of-Create.
the class DirectBeltInputBehaviour method tryExportingToBeltFunnel.
@Nullable
public ItemStack tryExportingToBeltFunnel(ItemStack stack, @Nullable Direction side, boolean simulate) {
BlockPos funnelPos = tileEntity.getBlockPos().above();
Level world = getWorld();
BlockState funnelState = world.getBlockState(funnelPos);
if (!(funnelState.getBlock() instanceof BeltFunnelBlock))
return null;
if (funnelState.getValue(BeltFunnelBlock.SHAPE) != Shape.PULLING)
return null;
if (side != null && FunnelBlock.getFunnelFacing(funnelState) != side)
return null;
BlockEntity te = world.getBlockEntity(funnelPos);
if (!(te instanceof FunnelTileEntity))
return null;
if (funnelState.getValue(BeltFunnelBlock.POWERED))
return stack;
ItemStack insert = FunnelBlock.tryInsert(world, funnelPos, stack, simulate);
if (insert.getCount() != stack.getCount() && !simulate)
((FunnelTileEntity) te).flap(true);
return insert;
}
use of com.simibubi.create.content.logistics.block.funnel.BeltFunnelBlock in project Create by Creators-of-Create.
the class BeltFunnelInteractionHandler method checkForFunnels.
public static boolean checkForFunnels(BeltInventory beltInventory, TransportedItemStack currentItem, float nextOffset) {
boolean beltMovementPositive = beltInventory.beltMovementPositive;
int firstUpcomingSegment = (int) Math.floor(currentItem.beltPosition);
int step = beltMovementPositive ? 1 : -1;
firstUpcomingSegment = Mth.clamp(firstUpcomingSegment, 0, beltInventory.belt.beltLength - 1);
for (int segment = firstUpcomingSegment; beltMovementPositive ? segment <= nextOffset : segment + 1 >= nextOffset; segment += step) {
BlockPos funnelPos = BeltHelper.getPositionForOffset(beltInventory.belt, segment).above();
Level world = beltInventory.belt.getLevel();
BlockState funnelState = world.getBlockState(funnelPos);
if (!(funnelState.getBlock() instanceof BeltFunnelBlock))
continue;
Direction funnelFacing = funnelState.getValue(BeltFunnelBlock.HORIZONTAL_FACING);
Direction movementFacing = beltInventory.belt.getMovementFacing();
boolean blocking = funnelFacing == movementFacing.getOpposite();
if (funnelFacing == movementFacing)
continue;
if (funnelState.getValue(BeltFunnelBlock.SHAPE) == Shape.PUSHING)
continue;
float funnelEntry = segment + .5f;
if (funnelState.getValue(BeltFunnelBlock.SHAPE) == Shape.EXTENDED)
funnelEntry += .499f * (beltMovementPositive ? -1 : 1);
boolean hasCrossed = nextOffset > funnelEntry && beltMovementPositive || nextOffset < funnelEntry && !beltMovementPositive;
if (!hasCrossed)
return false;
if (blocking)
currentItem.beltPosition = funnelEntry;
if (world.isClientSide || funnelState.getOptionalValue(BeltFunnelBlock.POWERED).orElse(false))
if (blocking)
return true;
else
continue;
BlockEntity te = world.getBlockEntity(funnelPos);
if (!(te instanceof FunnelTileEntity))
return true;
FunnelTileEntity funnelTE = (FunnelTileEntity) te;
InvManipulationBehaviour inserting = funnelTE.getBehaviour(InvManipulationBehaviour.TYPE);
FilteringBehaviour filtering = funnelTE.getBehaviour(FilteringBehaviour.TYPE);
if (inserting == null || filtering != null && !filtering.test(currentItem.stack))
if (blocking)
return true;
else
continue;
int amountToExtract = funnelTE.getAmountToExtract();
ItemStack toInsert = currentItem.stack.copy();
if (amountToExtract > toInsert.getCount())
if (blocking)
return true;
else
continue;
if (amountToExtract != -1) {
toInsert.setCount(amountToExtract);
ItemStack remainder = inserting.simulate().insert(toInsert);
if (!remainder.isEmpty())
if (blocking)
return true;
else
continue;
}
ItemStack remainder = inserting.insert(toInsert);
if (toInsert.equals(remainder, false))
if (blocking)
return true;
else
continue;
int notFilled = currentItem.stack.getCount() - toInsert.getCount();
if (!remainder.isEmpty()) {
remainder.grow(notFilled);
} else if (notFilled > 0)
remainder = ItemHandlerHelper.copyStackWithSize(currentItem.stack, notFilled);
funnelTE.flap(true);
funnelTE.onTransfer(toInsert);
currentItem.stack = remainder;
beltInventory.belt.sendData();
if (blocking)
return true;
}
return false;
}
use of com.simibubi.create.content.logistics.block.funnel.BeltFunnelBlock in project Create by Creators-of-Create.
the class BeltTunnelTileEntity method updateTunnelConnections.
public void updateTunnelConnections() {
flaps.clear();
sides.clear();
BlockState tunnelState = getBlockState();
for (Direction direction : Iterate.horizontalDirections) {
if (direction.getAxis() != tunnelState.getValue(BlockStateProperties.HORIZONTAL_AXIS)) {
boolean positive = direction.getAxisDirection() == AxisDirection.POSITIVE ^ direction.getAxis() == Axis.Z;
Shape shape = tunnelState.getValue(BeltTunnelBlock.SHAPE);
if (BeltTunnelBlock.isStraight(tunnelState))
continue;
if (positive && shape == Shape.T_LEFT)
continue;
if (!positive && shape == Shape.T_RIGHT)
continue;
}
sides.add(direction);
// Flap might be occluded
BlockState nextState = level.getBlockState(worldPosition.relative(direction));
if (nextState.getBlock() instanceof BeltTunnelBlock)
continue;
if (nextState.getBlock() instanceof BeltFunnelBlock)
if (nextState.getValue(BeltFunnelBlock.SHAPE) == BeltFunnelBlock.Shape.EXTENDED && nextState.getValue(BeltFunnelBlock.HORIZONTAL_FACING) == direction.getOpposite())
continue;
flaps.put(direction, new InterpolatedChasingValue().start(.25f).target(0).withSpeed(.05f));
}
sendData();
}
Aggregations