Posted March 16, 20232 yr Hello, I've been trying to make a 2x1 block and I can't do it, and I get to this point but I need to remove both blocks at the same time, can someone help me? public class CustomModeBlock extends HorizontalDirectionalBlock { //SHAPE public static final DirectionProperty FACING = HORIZONTAL_FACING; //NUEVO public static final BooleanProperty BEING_PLACED = BooleanProperty.create("being_placed" ); //public static final EnumProperty<DoubleBlockHalf> HALF = BlockStateProperties.DOUBLE_BLOCK_HALF; //LAS PROPIEDADES DEL BLOQUE public CustomModeBlock(Properties properties) { super(properties); } //FACING @Override protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> builder) { builder.add(HORIZONTAL_FACING); builder.add(CustomModeBlock.BEING_PLACED); //builder.add(FACING); //builder.add(HALF); } //NUEVO @Override public BlockState getStateForPlacement(BlockPlaceContext pContext) { Direction direction = pContext.getHorizontalDirection().getOpposite(); BlockPos blockPos = pContext.getClickedPos(); BlockPos blockPos1 = blockPos.relative(direction); Level level = pContext.getLevel(); return level.getBlockState(blockPos1).canBeReplaced(pContext) && level.getWorldBorder().isWithinBounds(blockPos1) ? this.defaultBlockState().setValue(FACING, direction) : null; } @Override public void setPlacedBy(Level pLevel, BlockPos pPos, BlockState pState, LivingEntity pEntity, ItemStack pStack) { BlockPos blockPos = pPos.relative(pState.getValue(FACING).getCounterClockWise()); pLevel.setBlock(blockPos, pState, 3); } @Override public boolean canSurvive(BlockState pState, LevelReader pReader, BlockPos pPos) { if (pState.getValue(BEING_PLACED) == true){ return true; } if (pReader.getBlockState(pPos.relative(FACING).getBlock().equals(getStateForPlacement))){ return true; } return false; } @Override public BlockState rotate(BlockState pState, Rotation pRotation) { return pState.setValue(FACING, pRotation.rotate(pState.getValue(FACING))); } @Override public BlockState mirror(BlockState pState, Mirror pMirror) { return pState.rotate(pMirror.getRotation(pState.getValue(FACING))); } //SHAPE @Override public VoxelShape getShape(BlockState pState, BlockGetter pLevel, BlockPos pPos, CollisionContext pContext) { switch (pState.getValue(FACING)){ case NORTH: return SHAPE_N; case SOUTH: return SHAPE_S; case EAST: return SHAPE_E; case WEST: return SHAPE_W; default: return SHAPE_N; } }
March 17, 20232 yr the explosive barrel or the door create a method to check if the companion is present is this is half.top check below block if half.bottom check the block above create a method to set the companion block and create a method to delete the block and its companion and doo the relevant code in // ########## ########## ########## ########## @Override @Nullable public BlockState getStateForPlacement(BlockPlaceContext context) { // ########## ########## ########## ########## @Override public void neighborChanged(BlockState blkstate, Level warudo, BlockPos pos, Block blk, BlockPos pos_of_changed, boolean p_55566_) { System.out.println("neighborChanged" + ", " + pos + ", " + pos_of_changed); } // ########## ########## ########## ########## @Override public void destroy(LevelAccessor accesor, BlockPos pos, BlockState blkstate) { // ########## ########## ########## ########## @Override public void onBlockExploded(BlockState blkstate, Level warudo, BlockPos pos, Explosion explosion) // ########## ########## ########## ########## @Override public void wasExploded(Level warudo, BlockPos pos, Explosion explosion) { // ########## ########## ########## ########## i dont think you need to manually drop the block as an item the normal block mechanics must be enough
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.