PressurePlateBlock .java

net.minecraft.world.level.block.PressurePlateBlock (class, 52 lines): members: getSignalForState, getSignalStrength, setSignalForState, POWERED.

net.minecraft.world.level.blockclass52 linescommonextends BasePressurePlateBlock1.8 KB

API Surface (4)

int getSignalForState(final BlockState state)
BlockState setSignalForState(final BlockState state, final int signal)
int getSignalStrength(final Level level, final BlockPos pos)
void createBlockStateDefinition(final StateDefinition.Builder<Block, BlockState> builder)

Fields & Constants (1)

POWERED

Full Source

PressurePlateBlock.java52 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.world.level.block;
2
3
import net.minecraft.core.BlockPos;
4
import net.minecraft.world.entity.Entity;
5
import net.minecraft.world.entity.LivingEntity;
6
import net.minecraft.world.level.Level;
7
import net.minecraft.world.level.block.state.BlockBehaviour;
8
import net.minecraft.world.level.block.state.BlockState;
9
import net.minecraft.world.level.block.state.StateDefinition;
10
import net.minecraft.world.level.block.state.properties.BlockSetType;
11
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
12
import net.minecraft.world.level.block.state.properties.BooleanProperty;
13
14
/**
15
 * Access widened by fabric-transitive-access-wideners-v1 to accessible
16
 */
17
public class PressurePlateBlock extends BasePressurePlateBlock {
18
	public static final BooleanProperty POWERED = BlockStateProperties.POWERED;
19
20
	/**
21
	 * Access widened by fabric-transitive-access-wideners-v1 to accessible
22
	 */
23
	public PressurePlateBlock(final BlockSetType type, final BlockBehaviour.Properties properties) {
24
		super(properties, type);
25
		this.registerDefaultState(this.stateDefinition.any().setValue(POWERED, false));
26
	}
27
28
	@Override
29
	protected int getSignalForState(final BlockState state) {
30
		return state.getValue(POWERED) ? 15 : 0;
31
	}
32
33
	@Override
34
	protected BlockState setSignalForState(final BlockState state, final int signal) {
35
		return state.setValue(POWERED, signal > 0);
36
	}
37
38
	@Override
39
	protected int getSignalStrength(final Level level, final BlockPos pos) {
40
		Class<? extends Entity> entityClass = switch (this.type.pressurePlateSensitivity()) {
41
			case EVERYTHING -> Entity.class;
42
			case MOBS -> LivingEntity.class;
43
		};
44
		return getEntityCount(level, TOUCH_AABB.move(pos), entityClass) > 0 ? 15 : 0;
45
	}
46
47
	@Override
48
	protected void createBlockStateDefinition(final StateDefinition.Builder<Block, BlockState> builder) {
49
		builder.add(POWERED);
50
	}
51
}
52

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