Randomly placing different variants of rock. This is my rock block class
package com.tzs.asm.blocks;
import java.util.stream.Stream;
import net.minecraft.block.AbstractBlock;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.SoundType;
import net.minecraft.block.material.Material;
import net.minecraft.block.material.MaterialColor;
import net.minecraft.item.BlockItemUseContext;
import net.minecraft.state.DirectionProperty;
import net.minecraft.state.StateContainer.Builder;
import net.minecraft.state.properties.BlockStateProperties;
import net.minecraft.util.Direction;
import net.minecraft.util.Mirror;
import net.minecraft.util.Rotation;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.shapes.IBooleanFunction;
import net.minecraft.util.math.shapes.ISelectionContext;
import net.minecraft.util.math.shapes.VoxelShape;
import net.minecraft.util.math.shapes.VoxelShapes;
import net.minecraft.world.IBlockReader;
import net.minecraft.world.IWorld;
public class rockBlock extends Block {
public static final DirectionProperty FACING = BlockStateProperties.HORIZONTAL_FACING;
public rockBlock() {
super(AbstractBlock.Properties.of(Material.STONE, MaterialColor.COLOR_GRAY).speedFactor(0.3f)
.friction(0.5f).harvestLevel(1).sound(SoundType.STONE).noOcclusion());
this.registerDefaultState(this.stateDefinition.any().setValue(FACING, Direction.NORTH));
}
@SuppressWarnings("deprecation")
@Override
public BlockState mirror(BlockState state, Mirror mirrorIn) {
return state.rotate(mirrorIn.getRotation(state.getValue(FACING)));
}
@Override
public BlockState rotate(BlockState state, IWorld world, BlockPos pos, Rotation direction) {
return state.setValue(FACING, direction.rotate(state.getValue(FACING)));
}
@Override
public BlockState getStateForPlacement(BlockItemUseContext context) {
return this.defaultBlockState().setValue(FACING, context.getHorizontalDirection().getOpposite());
}
@Override
protected void createBlockStateDefinition(Builder<Block, BlockState> builder) {
super.createBlockStateDefinition(builder);
builder.add(FACING);
}
private static final VoxelShape rockN = Stream.of(
Block.box(8.450000000000001, 0, 5.275, 9.450000000000001, 0.40000000000000036, 5.975),
Block.box(6.850000000000001, 0, 5.975, 9.850000000000001, 1, 10.975),
Block.box(5.850000000000001, 0, 8.575, 6.850000000000001, 0.40000000000000036, 10.674999999999999),
Block.box(7.350000000000001, 0, 6.775, 9.350000000000001, 0.40000000000000036, 9.775)
).reduce((v1, v2) -> VoxelShapes.join(v1, v2, IBooleanFunction.OR)).get();
private static final VoxelShape rockE = Stream.of(
Block.box(10.025000000000002, 0, 8.45, 10.725000000000001, 0.40000000000000036, 9.45),
Block.box(5.025000000000002, 0, 6.85, 10.025000000000002, 1, 9.85),
Block.box(5.325000000000003, 0, 5.85, 7.4250000000000025, 0.40000000000000036, 6.85),
Block.box(6.225000000000001, 0, 7.35, 9.225000000000001, 0.40000000000000036, 9.35)
).reduce((v1, v2) -> VoxelShapes.join(v1, v2, IBooleanFunction.OR)).get();
private static final VoxelShape rockS = Stream.of(
Block.box(6.5500000000000025, 0, 10.025, 7.5500000000000025, 0.40000000000000036, 10.725),
Block.box(6.150000000000002, 0, 5.025, 9.150000000000002, 1, 10.025),
Block.box(9.150000000000002, 0, 5.325000000000001, 10.150000000000002, 0.40000000000000036, 7.425000000000001),
Block.box(6.650000000000002, 0, 6.225, 8.650000000000002, 0.40000000000000036, 9.225)
).reduce((v1, v2) -> VoxelShapes.join(v1, v2, IBooleanFunction.OR)).get();
private static final VoxelShape rockW = Stream.of(
Block.box(5.275000000000002, 0, 6.550000000000001, 5.975000000000001, 0.40000000000000036, 7.550000000000001),
Block.box(5.975000000000001, 0, 6.15, 10.975000000000001, 1, 9.15),
Block.box(8.575000000000001, 0, 9.15, 10.675, 0.40000000000000036, 10.15),
Block.box(6.775000000000002, 0, 6.65, 9.775000000000002, 0.40000000000000036, 8.65)
).reduce((v1, v2) -> VoxelShapes.join(v1, v2, IBooleanFunction.OR)).get();
@Override
public VoxelShape getShape(BlockState state, IBlockReader worldIn, BlockPos pos, ISelectionContext context) {
switch(state.getValue(FACING)) {
case EAST:
return rockE;
case SOUTH:
return rockS;
case WEST:
return rockW;
default:
return rockN;
}
}
}