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;
}
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();
}
Aggregations