| 1 | package net.minecraft.world.level.block;
|
| 2 |
|
| 3 | import net.minecraft.core.BlockPos;
|
| 4 | import net.minecraft.core.Direction;
|
| 5 | import net.minecraft.core.particles.ParticleTypes;
|
| 6 | import net.minecraft.util.RandomSource;
|
| 7 | import net.minecraft.world.item.context.BlockPlaceContext;
|
| 8 | import net.minecraft.world.level.Level;
|
| 9 | import net.minecraft.world.level.block.state.BlockBehaviour;
|
| 10 | import net.minecraft.world.level.block.state.BlockState;
|
| 11 | import net.minecraft.world.level.block.state.StateDefinition;
|
| 12 |
|
| 13 | /**
|
| 14 | * Access widened by fabric-transitive-access-wideners-v1 to accessible
|
| 15 | */
|
| 16 | public class EndRodBlock extends RodBlock {
|
| 17 | /**
|
| 18 | * Access widened by fabric-transitive-access-wideners-v1 to accessible
|
| 19 | */
|
| 20 | public EndRodBlock(final BlockBehaviour.Properties properties) {
|
| 21 | super(properties);
|
| 22 | this.registerDefaultState(this.stateDefinition.any().setValue(FACING, Direction.UP));
|
| 23 | }
|
| 24 |
|
| 25 | @Override
|
| 26 | public BlockState getStateForPlacement(final BlockPlaceContext context) {
|
| 27 | Direction clickedFace = context.getClickedFace();
|
| 28 | BlockState blockState = context.getLevel().getBlockState(context.getClickedPos().relative(clickedFace.getOpposite()));
|
| 29 | return blockState.is(this) && blockState.getValue(FACING) == clickedFace
|
| 30 | ? this.defaultBlockState().setValue(FACING, clickedFace.getOpposite())
|
| 31 | : this.defaultBlockState().setValue(FACING, clickedFace);
|
| 32 | }
|
| 33 |
|
| 34 | @Override
|
| 35 | public void animateTick(final BlockState state, final Level level, final BlockPos pos, final RandomSource random) {
|
| 36 | Direction direction = state.getValue(FACING);
|
| 37 | double x = pos.getX() + 0.55 - random.nextFloat() * 0.1F;
|
| 38 | double y = pos.getY() + 0.55 - random.nextFloat() * 0.1F;
|
| 39 | double z = pos.getZ() + 0.55 - random.nextFloat() * 0.1F;
|
| 40 | double r = 0.4F - (random.nextFloat() + random.nextFloat()) * 0.4F;
|
| 41 | if (random.nextInt(5) == 0) {
|
| 42 | level.addParticle(
|
| 43 | ParticleTypes.END_ROD,
|
| 44 | x + direction.getStepX() * r,
|
| 45 | y + direction.getStepY() * r,
|
| 46 | z + direction.getStepZ() * r,
|
| 47 | random.nextGaussian() * 0.005,
|
| 48 | random.nextGaussian() * 0.005,
|
| 49 | random.nextGaussian() * 0.005
|
| 50 | );
|
| 51 | }
|
| 52 | }
|
| 53 |
|
| 54 | @Override
|
| 55 | protected void createBlockStateDefinition(final StateDefinition.Builder<Block, BlockState> builder) {
|
| 56 | builder.add(FACING);
|
| 57 | }
|
| 58 | }
|
| 59 |
|