Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class RadiantClusterBlock extends DirectionalBlock implements IWaterLoggable
- {
- public static final BooleanProperty WATERLOGGED = BlockStateProperties.WATERLOGGED;
- protected static final VoxelShape RADIANT_CLUSTER_VERTICAL = Block.makeCuboidShape(2.0D, 0.0D, 2.0D, 14.0D, 5.0D, 14.0D);
- protected static final VoxelShape RADIANT_CLUSTER_NS = Block.makeCuboidShape(2.0D, 2.0D, 0.0D, 14.0D, 14.0D, 5.0D);
- protected static final VoxelShape RADIANT_CLUSTER_EW = Block.makeCuboidShape(0.0D, 2.0D, 2.0D, 5.0D, 14.0D, 14.0D);
- private final int min;
- private final int max;
- public RadiantClusterBlock(int minIn, int maxIn,AbstractBlock.Properties builder) {
- super(builder);
- this.min = minIn;
- this.max = maxIn;
- this.setDefaultState(this.stateContainer.getBaseState().with(FACING, Direction.UP).with(WATERLOGGED, Boolean.valueOf(false)));
- }
- @Override
- public int getExpDrop(BlockState state, IWorldReader world, BlockPos pos, int fortune, int silktouch) {
- Random rand = new Random();
- return MathHelper.nextInt(rand, this.min, this.max);
- }
- @SuppressWarnings("deprecation")
- @Override
- public BlockState rotate(BlockState state, Rotation rot) {
- return state.with(FACING, rot.rotate(state.get(FACING)));
- }
- @SuppressWarnings("deprecation")
- @Override
- public BlockState mirror(BlockState state, Mirror mirrorIn) {
- return state.with(FACING, mirrorIn.mirror(state.get(FACING)));
- }
- @SuppressWarnings("deprecation")
- @Override
- public VoxelShape getShape(BlockState state, IBlockReader worldIn, BlockPos pos, ISelectionContext context) {
- switch(state.get(FACING).getAxis()) {
- case X:
- default:
- return RADIANT_CLUSTER_EW;
- case Z:
- return RADIANT_CLUSTER_NS;
- case Y:
- return RADIANT_CLUSTER_VERTICAL;
- }
- }
- @Override
- public BlockState getStateForPlacement(BlockItemUseContext context) {
- Direction direction = context.getFace();
- BlockState blockstate = context.getWorld().getBlockState(context.getPos().offset(direction.getOpposite()));
- FluidState fluidstate = context.getWorld().getFluidState(context.getPos());
- boolean flag = fluidstate.getFluid() == Fluids.WATER;
- super.getStateForPlacement(context).with(WATERLOGGED, Boolean.valueOf(flag));
- return blockstate.isIn(this) && blockstate.get(FACING) == direction ? this.getDefaultState().with(FACING, direction.getOpposite()) : this.getDefaultState().with(FACING, direction);
- }
- @Override
- public int getLightValue(BlockState state, IBlockReader world, BlockPos pos) {
- return 7;
- }
- protected boolean isValidGround(BlockState state, IBlockReader worldIn, BlockPos pos) {
- if(state.isIn(BlockInit.RADIANT_CLUSTER.get()) || state.isIn(Blocks.CACTUS.getBlock()))
- return false;
- else
- return true;
- }
- @SuppressWarnings("deprecation")
- @Override
- public boolean isValidPosition(BlockState state, IWorldReader worldIn, BlockPos pos) {
- BlockPos blockpos = pos.down();
- return this.isValidGround(worldIn.getBlockState(blockpos), worldIn, blockpos);
- }
- @SuppressWarnings("deprecation")
- @Override
- public BlockState updatePostPlacement(BlockState stateIn, Direction facing, BlockState facingState, IWorld worldIn, BlockPos currentPos, BlockPos facingPos) {
- if (!stateIn.isValidPosition(worldIn, currentPos)) {
- return Blocks.AIR.getDefaultState();
- } else {
- if (stateIn.get(WATERLOGGED)) {
- worldIn.getPendingFluidTicks().scheduleTick(currentPos, Fluids.WATER, Fluids.WATER.getTickRate(worldIn));
- }
- return super.updatePostPlacement(stateIn, facing, facingState, worldIn, currentPos, facingPos);
- }
- }
- @SuppressWarnings("deprecation")
- @Override
- public FluidState getFluidState(BlockState state) {
- return state.get(WATERLOGGED) ? Fluids.WATER.getStillFluidState(false) : super.getFluidState(state);
- }
- @OnlyIn(Dist.CLIENT)
- public void animateTick(BlockState stateIn, World worldIn, BlockPos pos, Random rand) {
- Direction direction = stateIn.get(FACING);
- double d0 = (double) pos.getX() + 0.75D - (double) (rand.nextFloat() * 0.2F);
- double d1 = (double) pos.getY() + 0.75D - (double) (rand.nextFloat() * 0.15F);
- double d2 = (double) pos.getZ() + 0.75D - (double) (rand.nextFloat() * 0.2F);
- double d3 = (double) (0.4F - (rand.nextFloat() + rand.nextFloat()) * 0.4F);
- if (rand.nextInt(5) == 0) {
- worldIn.addParticle(ParticleInit.RADIANT_SPARK.get(), d0 + (double) direction.getXOffset() * d3, d1 + (double) direction.getYOffset() * d3, d2 + (double) direction.getZOffset() * d3, rand.nextGaussian() * 0.005D, rand.nextGaussian() * 0.005D, rand.nextGaussian() * 0.005D);
- }
- }
- @SuppressWarnings("deprecation")
- @Override
- public PushReaction getPushReaction(BlockState state) { return PushReaction.BLOCK; }
- protected void fillStateContainer(StateContainer.Builder<Block, BlockState> builder) { builder.add(FACING, WATERLOGGED); }
- @SuppressWarnings("deprecation")
- @Override
- public boolean allowsMovement(BlockState state, IBlockReader worldIn, BlockPos pos, PathType type) { return false; }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement