Search in sources :

Example 1 with BeltBlock

use of com.simibubi.create.content.contraptions.relays.belt.BeltBlock in project Create by Creators-of-Create.

the class BeltFunnelBlock method onWrenched.

@Override
public InteractionResult onWrenched(BlockState state, UseOnContext context) {
    Level world = context.getLevel();
    if (world.isClientSide)
        return InteractionResult.SUCCESS;
    Shape shape = state.getValue(SHAPE);
    Shape newShape = shape;
    if (shape == Shape.PULLING)
        newShape = Shape.PUSHING;
    else if (shape == Shape.PUSHING)
        newShape = Shape.PULLING;
    else if (shape == Shape.EXTENDED)
        newShape = Shape.RETRACTED;
    else if (shape == Shape.RETRACTED) {
        BlockState belt = world.getBlockState(context.getClickedPos().below());
        if (belt.getBlock() instanceof BeltBlock && belt.getValue(BeltBlock.SLOPE) != BeltSlope.HORIZONTAL)
            newShape = Shape.RETRACTED;
        else
            newShape = Shape.EXTENDED;
    }
    if (newShape == shape)
        return InteractionResult.SUCCESS;
    world.setBlockAndUpdate(context.getClickedPos(), state.setValue(SHAPE, newShape));
    if (newShape == Shape.EXTENDED) {
        Direction facing = state.getValue(HORIZONTAL_FACING);
        BlockState opposite = world.getBlockState(context.getClickedPos().relative(facing));
        if (opposite.getBlock() instanceof BeltFunnelBlock && opposite.getValue(SHAPE) == Shape.EXTENDED && opposite.getValue(HORIZONTAL_FACING) == facing.getOpposite())
            AllTriggers.triggerFor(AllTriggers.BELT_FUNNEL_KISS, context.getPlayer());
    }
    return InteractionResult.SUCCESS;
}
Also used : BeltBlock(com.simibubi.create.content.contraptions.relays.belt.BeltBlock) VoxelShape(net.minecraft.world.phys.shapes.VoxelShape) BlockState(net.minecraft.world.level.block.state.BlockState) Level(net.minecraft.world.level.Level) Direction(net.minecraft.core.Direction)

Example 2 with BeltBlock

use of com.simibubi.create.content.contraptions.relays.belt.BeltBlock in project Create by Creators-of-Create.

the class BeltFunnelBlock method isOnValidBelt.

public static boolean isOnValidBelt(BlockState state, LevelReader world, BlockPos pos) {
    BlockState stateBelow = world.getBlockState(pos.below());
    if ((stateBelow.getBlock() instanceof BeltBlock))
        return BeltBlock.canTransportObjects(stateBelow);
    DirectBeltInputBehaviour directBeltInputBehaviour = TileEntityBehaviour.get(world, pos.below(), DirectBeltInputBehaviour.TYPE);
    if (directBeltInputBehaviour == null)
        return false;
    return directBeltInputBehaviour.canSupportBeltFunnels();
}
Also used : BeltBlock(com.simibubi.create.content.contraptions.relays.belt.BeltBlock) BlockState(net.minecraft.world.level.block.state.BlockState) DirectBeltInputBehaviour(com.simibubi.create.foundation.tileEntity.behaviour.belt.DirectBeltInputBehaviour)

Aggregations

BeltBlock (com.simibubi.create.content.contraptions.relays.belt.BeltBlock)2 BlockState (net.minecraft.world.level.block.state.BlockState)2 DirectBeltInputBehaviour (com.simibubi.create.foundation.tileEntity.behaviour.belt.DirectBeltInputBehaviour)1 Direction (net.minecraft.core.Direction)1 Level (net.minecraft.world.level.Level)1 VoxelShape (net.minecraft.world.phys.shapes.VoxelShape)1