Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.junix.logicboard.blocks;
- import com.junix.logicboard.setup.Registration;
- import com.junix.logicboard.setup.Component;
- import net.minecraft.core.BlockPos;
- import net.minecraft.core.Direction;
- import net.minecraft.world.InteractionHand;
- import net.minecraft.world.InteractionResult;
- import net.minecraft.world.entity.player.Player;
- import net.minecraft.world.item.context.BlockPlaceContext;
- import net.minecraft.world.level.Level;
- import net.minecraft.world.level.block.Block;
- import net.minecraft.world.level.block.state.BlockState;
- import net.minecraft.world.level.block.state.StateDefinition;
- import net.minecraft.world.level.block.state.properties.BlockStateProperties;
- import net.minecraft.world.level.block.state.properties.BooleanProperty;
- import net.minecraft.world.level.block.state.properties.DirectionProperty;
- import net.minecraft.world.phys.BlockHitResult;
- import org.jetbrains.annotations.NotNull;
- import org.jetbrains.annotations.Nullable;
- public class Switch extends Component {
- public static final DirectionProperty FACING = BlockStateProperties.HORIZONTAL_FACING;
- public static final BooleanProperty POWERED = BlockStateProperties.POWERED;
- public Switch() {
- super(Registration.METAL_BLOCK_PROPERTIES);
- registerDefaultState(defaultBlockState()
- .setValue(FACING, Direction.NORTH)
- .setValue(POWERED, Boolean.TRUE));
- }
- @Nullable
- @Override
- public BlockState getStateForPlacement(BlockPlaceContext context) {
- return defaultBlockState().setValue(FACING, context.getHorizontalDirection().getOpposite());
- }
- @Override
- protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> builder) {
- builder.add(POWERED, FACING);
- }
- @Override
- public @NotNull InteractionResult use(BlockState blockState, Level level, BlockPos blockPos, Player player, InteractionHand interactionHand, BlockHitResult blockHitResult) {
- if (!player.getAbilities().mayBuild)
- return InteractionResult.PASS;
- else {
- level.setBlock(blockPos, blockState.cycle(POWERED), Block.UPDATE_ALL);
- return InteractionResult.sidedSuccess(level.isClientSide);
- }
- }
- @Override
- public int getSourceDistance(BlockState blockState) {
- return 0;
- }
- @Override
- public boolean isSignalSource(Direction direction) {
- return true;
- }
- @Override
- public boolean isConnectable(BlockState blockState, Direction direction) {
- return false;
- }
- }
Add Comment
Please, Sign In to add comment