Advertisement
Guest User

Untitled

a guest
Apr 25th, 2021
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.43 KB | None | 0 0
  1. public class RadiantClusterBlock extends DirectionalBlock implements IWaterLoggable
  2. {
  3. public static final BooleanProperty WATERLOGGED = BlockStateProperties.WATERLOGGED;
  4. protected static final VoxelShape RADIANT_CLUSTER_VERTICAL = Block.makeCuboidShape(2.0D, 0.0D, 2.0D, 14.0D, 5.0D, 14.0D);
  5. protected static final VoxelShape RADIANT_CLUSTER_NS = Block.makeCuboidShape(2.0D, 2.0D, 0.0D, 14.0D, 14.0D, 5.0D);
  6. protected static final VoxelShape RADIANT_CLUSTER_EW = Block.makeCuboidShape(0.0D, 2.0D, 2.0D, 5.0D, 14.0D, 14.0D);
  7. private final int min;
  8. private final int max;
  9.  
  10. public RadiantClusterBlock(int minIn, int maxIn,AbstractBlock.Properties builder) {
  11. super(builder);
  12. this.min = minIn;
  13. this.max = maxIn;
  14. this.setDefaultState(this.stateContainer.getBaseState().with(FACING, Direction.UP).with(WATERLOGGED, Boolean.valueOf(false)));
  15. }
  16.  
  17. @Override
  18. public int getExpDrop(BlockState state, IWorldReader world, BlockPos pos, int fortune, int silktouch) {
  19. Random rand = new Random();
  20. return MathHelper.nextInt(rand, this.min, this.max);
  21. }
  22. @SuppressWarnings("deprecation")
  23. @Override
  24. public BlockState rotate(BlockState state, Rotation rot) {
  25. return state.with(FACING, rot.rotate(state.get(FACING)));
  26. }
  27. @SuppressWarnings("deprecation")
  28. @Override
  29. public BlockState mirror(BlockState state, Mirror mirrorIn) {
  30. return state.with(FACING, mirrorIn.mirror(state.get(FACING)));
  31. }
  32. @SuppressWarnings("deprecation")
  33. @Override
  34. public VoxelShape getShape(BlockState state, IBlockReader worldIn, BlockPos pos, ISelectionContext context) {
  35. switch(state.get(FACING).getAxis()) {
  36. case X:
  37. default:
  38. return RADIANT_CLUSTER_EW;
  39. case Z:
  40. return RADIANT_CLUSTER_NS;
  41. case Y:
  42. return RADIANT_CLUSTER_VERTICAL;
  43. }
  44. }
  45. @Override
  46. public BlockState getStateForPlacement(BlockItemUseContext context) {
  47. Direction direction = context.getFace();
  48. BlockState blockstate = context.getWorld().getBlockState(context.getPos().offset(direction.getOpposite()));
  49. FluidState fluidstate = context.getWorld().getFluidState(context.getPos());
  50. boolean flag = fluidstate.getFluid() == Fluids.WATER;
  51.  
  52. super.getStateForPlacement(context).with(WATERLOGGED, Boolean.valueOf(flag));
  53. return blockstate.isIn(this) && blockstate.get(FACING) == direction ? this.getDefaultState().with(FACING, direction.getOpposite()) : this.getDefaultState().with(FACING, direction);
  54. }
  55. @Override
  56. public int getLightValue(BlockState state, IBlockReader world, BlockPos pos) {
  57. return 7;
  58. }
  59. protected boolean isValidGround(BlockState state, IBlockReader worldIn, BlockPos pos) {
  60. if(state.isIn(BlockInit.RADIANT_CLUSTER.get()) || state.isIn(Blocks.CACTUS.getBlock()))
  61. return false;
  62. else
  63. return true;
  64. }
  65.  
  66. @SuppressWarnings("deprecation")
  67. @Override
  68. public boolean isValidPosition(BlockState state, IWorldReader worldIn, BlockPos pos) {
  69. BlockPos blockpos = pos.down();
  70. return this.isValidGround(worldIn.getBlockState(blockpos), worldIn, blockpos);
  71. }
  72. @SuppressWarnings("deprecation")
  73. @Override
  74. public BlockState updatePostPlacement(BlockState stateIn, Direction facing, BlockState facingState, IWorld worldIn, BlockPos currentPos, BlockPos facingPos) {
  75. if (!stateIn.isValidPosition(worldIn, currentPos)) {
  76. return Blocks.AIR.getDefaultState();
  77. } else {
  78. if (stateIn.get(WATERLOGGED)) {
  79. worldIn.getPendingFluidTicks().scheduleTick(currentPos, Fluids.WATER, Fluids.WATER.getTickRate(worldIn));
  80. }
  81.  
  82. return super.updatePostPlacement(stateIn, facing, facingState, worldIn, currentPos, facingPos);
  83. }
  84. }
  85. @SuppressWarnings("deprecation")
  86. @Override
  87. public FluidState getFluidState(BlockState state) {
  88. return state.get(WATERLOGGED) ? Fluids.WATER.getStillFluidState(false) : super.getFluidState(state);
  89. }
  90.  
  91. @OnlyIn(Dist.CLIENT)
  92. public void animateTick(BlockState stateIn, World worldIn, BlockPos pos, Random rand) {
  93. Direction direction = stateIn.get(FACING);
  94. double d0 = (double) pos.getX() + 0.75D - (double) (rand.nextFloat() * 0.2F);
  95. double d1 = (double) pos.getY() + 0.75D - (double) (rand.nextFloat() * 0.15F);
  96. double d2 = (double) pos.getZ() + 0.75D - (double) (rand.nextFloat() * 0.2F);
  97. double d3 = (double) (0.4F - (rand.nextFloat() + rand.nextFloat()) * 0.4F);
  98. if (rand.nextInt(5) == 0) {
  99. 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);
  100. }
  101. }
  102.  
  103. @SuppressWarnings("deprecation")
  104. @Override
  105. public PushReaction getPushReaction(BlockState state) { return PushReaction.BLOCK; }
  106.  
  107. protected void fillStateContainer(StateContainer.Builder<Block, BlockState> builder) { builder.add(FACING, WATERLOGGED); }
  108.  
  109. @SuppressWarnings("deprecation")
  110. @Override
  111. public boolean allowsMovement(BlockState state, IBlockReader worldIn, BlockPos pos, PathType type) { return false; }
  112. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement