Search in sources :

Example 1 with BeltTunnelTileEntity

use of com.simibubi.create.content.logistics.block.belts.tunnel.BeltTunnelTileEntity in project Create by Creators-of-Create.

the class BeltTunnelInteractionHandler method getTunnelOnPosition.

public static BeltTunnelTileEntity getTunnelOnPosition(Level world, BlockPos pos) {
    pos = pos.above();
    if (!(world.getBlockState(pos).getBlock() instanceof BeltTunnelBlock))
        return null;
    BlockEntity te = world.getBlockEntity(pos);
    if (te == null || !(te instanceof BeltTunnelTileEntity))
        return null;
    return ((BeltTunnelTileEntity) te);
}
Also used : BeltTunnelTileEntity(com.simibubi.create.content.logistics.block.belts.tunnel.BeltTunnelTileEntity) BeltTunnelBlock(com.simibubi.create.content.logistics.block.belts.tunnel.BeltTunnelBlock) BlockEntity(net.minecraft.world.level.block.entity.BlockEntity)

Example 2 with BeltTunnelTileEntity

use of com.simibubi.create.content.logistics.block.belts.tunnel.BeltTunnelTileEntity in project Create by Creators-of-Create.

the class BeltTunnelInteractionHandler method flapTunnelsAndCheckIfStuck.

public static boolean flapTunnelsAndCheckIfStuck(BeltInventory beltInventory, TransportedItemStack current, float nextOffset) {
    int currentSegment = (int) current.beltPosition;
    int upcomingSegment = (int) nextOffset;
    Direction movementFacing = beltInventory.belt.getMovementFacing();
    if (!beltInventory.beltMovementPositive && nextOffset == 0)
        upcomingSegment = -1;
    if (currentSegment == upcomingSegment)
        return false;
    if (stuckAtTunnel(beltInventory, upcomingSegment, current.stack, movementFacing)) {
        current.beltPosition = currentSegment + (beltInventory.beltMovementPositive ? .99f : .01f);
        return true;
    }
    Level world = beltInventory.belt.getLevel();
    boolean onServer = !world.isClientSide || beltInventory.belt.isVirtual();
    boolean removed = false;
    BeltTunnelTileEntity nextTunnel = getTunnelOnSegment(beltInventory, upcomingSegment);
    if (nextTunnel instanceof BrassTunnelTileEntity) {
        BrassTunnelTileEntity brassTunnel = (BrassTunnelTileEntity) nextTunnel;
        if (brassTunnel.hasDistributionBehaviour()) {
            if (!brassTunnel.canTakeItems())
                return true;
            if (onServer) {
                brassTunnel.setStackToDistribute(current.stack);
                current.stack = ItemStack.EMPTY;
                beltInventory.belt.sendData();
                beltInventory.belt.setChanged();
            }
            removed = true;
        }
    } else if (nextTunnel != null) {
        BlockState blockState = nextTunnel.getBlockState();
        if (current.stack.getCount() > 1 && AllBlocks.ANDESITE_TUNNEL.has(blockState) && BeltTunnelBlock.isJunction(blockState) && movementFacing.getAxis() == blockState.getValue(BeltTunnelBlock.HORIZONTAL_AXIS)) {
            for (Direction d : Iterate.horizontalDirections) {
                if (d.getAxis() == blockState.getValue(BeltTunnelBlock.HORIZONTAL_AXIS))
                    continue;
                if (!nextTunnel.flaps.containsKey(d))
                    continue;
                BlockPos outpos = nextTunnel.getBlockPos().below().relative(d);
                if (!world.isLoaded(outpos))
                    return true;
                DirectBeltInputBehaviour behaviour = TileEntityBehaviour.get(world, outpos, DirectBeltInputBehaviour.TYPE);
                if (behaviour == null)
                    continue;
                if (!behaviour.canInsertFromSide(d))
                    continue;
                ItemStack toinsert = ItemHandlerHelper.copyStackWithSize(current.stack, 1);
                if (!behaviour.handleInsertion(toinsert, d, false).isEmpty())
                    return true;
                if (onServer)
                    flapTunnel(beltInventory, upcomingSegment, d, false);
                current.stack.shrink(1);
                beltInventory.belt.sendData();
                if (current.stack.getCount() <= 1)
                    break;
            }
        }
    }
    if (onServer) {
        flapTunnel(beltInventory, currentSegment, movementFacing, false);
        flapTunnel(beltInventory, upcomingSegment, movementFacing.getOpposite(), true);
    }
    if (removed)
        return true;
    return false;
}
Also used : BrassTunnelTileEntity(com.simibubi.create.content.logistics.block.belts.tunnel.BrassTunnelTileEntity) BeltTunnelTileEntity(com.simibubi.create.content.logistics.block.belts.tunnel.BeltTunnelTileEntity) BlockState(net.minecraft.world.level.block.state.BlockState) DirectBeltInputBehaviour(com.simibubi.create.foundation.tileEntity.behaviour.belt.DirectBeltInputBehaviour) Level(net.minecraft.world.level.Level) BlockPos(net.minecraft.core.BlockPos) ItemStack(net.minecraft.world.item.ItemStack) Direction(net.minecraft.core.Direction)

Example 3 with BeltTunnelTileEntity

use of com.simibubi.create.content.logistics.block.belts.tunnel.BeltTunnelTileEntity in project Create by Creators-of-Create.

the class BeltTunnelInteractionHandler method flapTunnel.

public static void flapTunnel(BeltInventory beltInventory, int offset, Direction side, boolean inward) {
    BeltTunnelTileEntity te = getTunnelOnSegment(beltInventory, offset);
    if (te == null)
        return;
    te.flap(side, inward);
}
Also used : BeltTunnelTileEntity(com.simibubi.create.content.logistics.block.belts.tunnel.BeltTunnelTileEntity)

Aggregations

BeltTunnelTileEntity (com.simibubi.create.content.logistics.block.belts.tunnel.BeltTunnelTileEntity)3 BeltTunnelBlock (com.simibubi.create.content.logistics.block.belts.tunnel.BeltTunnelBlock)1 BrassTunnelTileEntity (com.simibubi.create.content.logistics.block.belts.tunnel.BrassTunnelTileEntity)1 DirectBeltInputBehaviour (com.simibubi.create.foundation.tileEntity.behaviour.belt.DirectBeltInputBehaviour)1 BlockPos (net.minecraft.core.BlockPos)1 Direction (net.minecraft.core.Direction)1 ItemStack (net.minecraft.world.item.ItemStack)1 Level (net.minecraft.world.level.Level)1 BlockEntity (net.minecraft.world.level.block.entity.BlockEntity)1 BlockState (net.minecraft.world.level.block.state.BlockState)1