| 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.DustParticleOptions;
|
| 6 | import net.minecraft.util.RandomSource;
|
| 7 | import net.minecraft.world.item.context.BlockPlaceContext;
|
| 8 | import net.minecraft.world.level.BlockGetter;
|
| 9 | import net.minecraft.world.level.Level;
|
| 10 | import net.minecraft.world.level.LevelReader;
|
| 11 | import net.minecraft.world.level.ScheduledTickAccess;
|
| 12 | import net.minecraft.world.level.block.state.BlockBehaviour;
|
| 13 | import net.minecraft.world.level.block.state.BlockState;
|
| 14 | import net.minecraft.world.level.block.state.StateDefinition;
|
| 15 | import net.minecraft.world.level.block.state.properties.BooleanProperty;
|
| 16 | import net.minecraft.world.level.block.state.properties.EnumProperty;
|
| 17 | import net.minecraft.world.level.redstone.ExperimentalRedstoneUtils;
|
| 18 | import net.minecraft.world.level.redstone.Orientation;
|
| 19 | import net.minecraft.world.phys.shapes.CollisionContext;
|
| 20 | import net.minecraft.world.phys.shapes.VoxelShape;
|
| 21 | import org.jspecify.annotations.Nullable;
|
| 22 |
|
| 23 | /**
|
| 24 | * Access widened by fabric-transitive-access-wideners-v1 to accessible
|
| 25 | */
|
| 26 | public class RedstoneWallTorchBlock extends RedstoneTorchBlock {
|
| 27 | public static final EnumProperty<Direction> FACING = HorizontalDirectionalBlock.FACING;
|
| 28 | public static final BooleanProperty LIT = RedstoneTorchBlock.LIT;
|
| 29 |
|
| 30 | /**
|
| 31 | * Access widened by fabric-transitive-access-wideners-v1 to accessible
|
| 32 | */
|
| 33 | public RedstoneWallTorchBlock(final BlockBehaviour.Properties properties) {
|
| 34 | super(properties);
|
| 35 | this.registerDefaultState(this.stateDefinition.any().setValue(FACING, Direction.NORTH).setValue(LIT, true));
|
| 36 | }
|
| 37 |
|
| 38 | @Override
|
| 39 | protected VoxelShape getShape(final BlockState state, final BlockGetter level, final BlockPos pos, final CollisionContext context) {
|
| 40 | return WallTorchBlock.getShape(state);
|
| 41 | }
|
| 42 |
|
| 43 | @Override
|
| 44 | protected boolean canSurvive(final BlockState state, final LevelReader level, final BlockPos pos) {
|
| 45 | return WallTorchBlock.canSurvive(level, pos, state.getValue(FACING));
|
| 46 | }
|
| 47 |
|
| 48 | @Override
|
| 49 | protected BlockState updateShape(
|
| 50 | final BlockState state,
|
| 51 | final LevelReader level,
|
| 52 | final ScheduledTickAccess ticks,
|
| 53 | final BlockPos pos,
|
| 54 | final Direction directionToNeighbour,
|
| 55 | final BlockPos neighbourPos,
|
| 56 | final BlockState neighbourState,
|
| 57 | final RandomSource random
|
| 58 | ) {
|
| 59 | return directionToNeighbour.getOpposite() == state.getValue(FACING) && !state.canSurvive(level, pos) ? Blocks.AIR.defaultBlockState() : state;
|
| 60 | }
|
| 61 |
|
| 62 | @Override
|
| 63 | public @Nullable BlockState getStateForPlacement(final BlockPlaceContext context) {
|
| 64 | BlockState state = Blocks.WALL_TORCH.getStateForPlacement(context);
|
| 65 | return state == null ? null : this.defaultBlockState().setValue(FACING, state.getValue(FACING));
|
| 66 | }
|
| 67 |
|
| 68 | @Override
|
| 69 | public void animateTick(final BlockState state, final Level level, final BlockPos pos, final RandomSource random) {
|
| 70 | if (state.getValue(LIT)) {
|
| 71 | Direction opposite = state.getValue(FACING).getOpposite();
|
| 72 | double r = 0.27;
|
| 73 | double x = pos.getX() + 0.5 + (random.nextDouble() - 0.5) * 0.2 + 0.27 * opposite.getStepX();
|
| 74 | double y = pos.getY() + 0.7 + (random.nextDouble() - 0.5) * 0.2 + 0.22;
|
| 75 | double z = pos.getZ() + 0.5 + (random.nextDouble() - 0.5) * 0.2 + 0.27 * opposite.getStepZ();
|
| 76 | level.addParticle(DustParticleOptions.REDSTONE, x, y, z, 0.0, 0.0, 0.0);
|
| 77 | }
|
| 78 | }
|
| 79 |
|
| 80 | @Override
|
| 81 | protected boolean hasNeighborSignal(final Level level, final BlockPos pos, final BlockState state) {
|
| 82 | Direction opposite = state.getValue(FACING).getOpposite();
|
| 83 | return level.hasSignal(pos.relative(opposite), opposite);
|
| 84 | }
|
| 85 |
|
| 86 | @Override
|
| 87 | protected int getSignal(final BlockState state, final BlockGetter level, final BlockPos pos, final Direction direction) {
|
| 88 | return state.getValue(FACING) != direction ? this.ownSignal(state, level, pos) : 0;
|
| 89 | }
|
| 90 |
|
| 91 | @Override
|
| 92 | protected BlockState rotate(final BlockState state, final Rotation rotation) {
|
| 93 | return state.setValue(FACING, rotation.rotate(state.getValue(FACING)));
|
| 94 | }
|
| 95 |
|
| 96 | @Override
|
| 97 | protected BlockState mirror(final BlockState state, final Mirror mirror) {
|
| 98 | return state.rotate(mirror.getRotation(state.getValue(FACING)));
|
| 99 | }
|
| 100 |
|
| 101 | @Override
|
| 102 | protected void createBlockStateDefinition(final StateDefinition.Builder<Block, BlockState> builder) {
|
| 103 | builder.add(FACING, LIT);
|
| 104 | }
|
| 105 |
|
| 106 | @Override
|
| 107 | protected @Nullable Orientation randomOrientation(final Level level, final BlockState state) {
|
| 108 | return ExperimentalRedstoneUtils.initialOrientation(level, state.getValue(FACING).getOpposite(), Direction.UP);
|
| 109 | }
|
| 110 | }
|
| 111 |
|