RepeaterBlock .java

net.minecraft.world.level.block.RepeaterBlock (class): members: sideInputDiodesOnly, LOCKED, DELAY, shouldRedstoneWireConnectTo, getDelay, isLocked, ticks.

net.minecraft.world.level.blockclass119 linescommonextends DiodeBlock4.4 KB

API Surface (9)

InteractionResult useWithoutItem(final BlockState state, final Level level, final BlockPos pos, final Player player, final BlockHitResult hitResult)
int getDelay(final BlockState state)
BlockState getStateForPlacement(final BlockPlaceContext context)
BlockState updateShape(final BlockState state, final LevelReader level, final ScheduledTickAccess ticks, final BlockPos pos, final Direction directionToNeighbour, final BlockPos neighbourPos, final BlockState neighbourState, final RandomSource random)
boolean shouldRedstoneWireConnectTo(final BlockState state, final BlockGetter level, final BlockPos pos, final @Nullable Direction direction)
boolean isLocked(final LevelReader level, final BlockPos pos, final BlockState state)
boolean sideInputDiodesOnly()
void animateTick(final BlockState state, final Level level, final BlockPos pos, final RandomSource random)
void createBlockStateDefinition(final StateDefinition.Builder<Block, BlockState> builder)

Fields & Constants (9)

LOCKED
DELAY
state
level
ticks
pos
directionToNeighbour
neighbourPos
neighbourState

Full Source

RepeaterBlock.java119 lines · Minecraft 26.3 · verbatim
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.InteractionResult;
8
import net.minecraft.world.entity.player.Player;
9
import net.minecraft.world.item.context.BlockPlaceContext;
10
import net.minecraft.world.level.BlockGetter;
11
import net.minecraft.world.level.Level;
12
import net.minecraft.world.level.LevelReader;
13
import net.minecraft.world.level.ScheduledTickAccess;
14
import net.minecraft.world.level.block.state.BlockBehaviour;
15
import net.minecraft.world.level.block.state.BlockState;
16
import net.minecraft.world.level.block.state.StateDefinition;
17
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
18
import net.minecraft.world.level.block.state.properties.BooleanProperty;
19
import net.minecraft.world.level.block.state.properties.IntegerProperty;
20
import net.minecraft.world.phys.BlockHitResult;
21
import org.jspecify.annotations.Nullable;
22
23
/**
24
 * Access widened by fabric-transitive-access-wideners-v1 to accessible
25
 */
26
public class RepeaterBlock extends DiodeBlock {
27
	public static final BooleanProperty LOCKED = BlockStateProperties.LOCKED;
28
	public static final IntegerProperty DELAY = BlockStateProperties.DELAY;
29
30
	/**
31
	 * Access widened by fabric-transitive-access-wideners-v1 to accessible
32
	 */
33
	public RepeaterBlock(final BlockBehaviour.Properties properties) {
34
		super(properties);
35
		this.registerDefaultState(this.stateDefinition.any().setValue(FACING, Direction.NORTH).setValue(DELAY, 1).setValue(LOCKED, false).setValue(POWERED, false));
36
	}
37
38
	@Override
39
	protected InteractionResult useWithoutItem(final BlockState state, final Level level, final BlockPos pos, final Player player, final BlockHitResult hitResult) {
40
		if (!player.getAbilities().mayBuild) {
41
			return InteractionResult.PASS;
42
		}
43
44
		level.setBlockAndUpdate(pos, state.cycle(DELAY));
45
		return InteractionResult.SUCCESS;
46
	}
47
48
	@Override
49
	protected int getDelay(final BlockState state) {
50
		return state.getValue(DELAY) * 2;
51
	}
52
53
	@Override
54
	public BlockState getStateForPlacement(final BlockPlaceContext context) {
55
		BlockState state = super.getStateForPlacement(context);
56
		return state.setValue(LOCKED, this.isLocked(context.getLevel(), context.getClickedPos(), state));
57
	}
58
59
	@Override
60
	protected BlockState updateShape(
61
		final BlockState state,
62
		final LevelReader level,
63
		final ScheduledTickAccess ticks,
64
		final BlockPos pos,
65
		final Direction directionToNeighbour,
66
		final BlockPos neighbourPos,
67
		final BlockState neighbourState,
68
		final RandomSource random
69
	) {
70
		if (directionToNeighbour == Direction.DOWN && !this.canSurviveOn(level, neighbourPos, neighbourState)) {
71
			return Blocks.AIR.defaultBlockState();
72
		} else {
73
			return !level.isClientSide() && directionToNeighbour.getAxis() != state.getValue(FACING).getAxis()
74
				? state.setValue(LOCKED, this.isLocked(level, pos, state))
75
				: super.updateShape(state, level, ticks, pos, directionToNeighbour, neighbourPos, neighbourState, random);
76
		}
77
	}
78
79
	@Override
80
	protected boolean shouldRedstoneWireConnectTo(final BlockState state, final BlockGetter level, final BlockPos pos, final @Nullable Direction direction) {
81
		Direction repeaterDirection = state.getValue(FACING);
82
		return repeaterDirection == direction || repeaterDirection.getOpposite() == direction;
83
	}
84
85
	@Override
86
	public boolean isLocked(final LevelReader level, final BlockPos pos, final BlockState state) {
87
		return this.getAlternateSignal(level, pos, state) > 0;
88
	}
89
90
	@Override
91
	protected boolean sideInputDiodesOnly() {
92
		return true;
93
	}
94
95
	@Override
96
	public void animateTick(final BlockState state, final Level level, final BlockPos pos, final RandomSource random) {
97
		if (state.getValue(POWERED)) {
98
			Direction direction = state.getValue(FACING);
99
			double x = pos.getX() + 0.5 + (random.nextDouble() - 0.5) * 0.2;
100
			double y = pos.getY() + 0.4 + (random.nextDouble() - 0.5) * 0.2;
101
			double z = pos.getZ() + 0.5 + (random.nextDouble() - 0.5) * 0.2;
102
			float offset = -5.0F;
103
			if (random.nextBoolean()) {
104
				offset = state.getValue(DELAY) * 2 - 1;
105
			}
106
107
			offset /= 16.0F;
108
			double xo = offset * direction.getStepX();
109
			double zo = offset * direction.getStepZ();
110
			level.addParticle(DustParticleOptions.REDSTONE, x + xo, y, z + zo, 0.0, 0.0, 0.0);
111
		}
112
	}
113
114
	@Override
115
	protected void createBlockStateDefinition(final StateDefinition.Builder<Block, BlockState> builder) {
116
		builder.add(FACING, DELAY, LOCKED, POWERED);
117
	}
118
}
119

Decompiled Minecraft 26.3 source of RepeaterBlock (net/minecraft/world/level/block/RepeaterBlock.java) with Mojang official mappings, stored verbatim on the site.