WeightedPressurePlateBlock .java

net.minecraft.world.level.block.WeightedPressurePlateBlock (class): members: maxWeight, getPressedTime, getSignalForState, getSignalStrength, POWER.

net.minecraft.world.level.blockclass61 linescommonextends BasePressurePlateBlock1.9 KB

API Surface (5)

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

Fields & Constants (2)

POWER
maxWeight

Full Source

WeightedPressurePlateBlock.java61 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.world.level.block;
2
3
import net.minecraft.core.BlockPos;
4
import net.minecraft.util.Mth;
5
import net.minecraft.world.entity.Entity;
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.IntegerProperty;
13
14
/**
15
 * Access widened by fabric-transitive-access-wideners-v1 to accessible
16
 */
17
public class WeightedPressurePlateBlock extends BasePressurePlateBlock {
18
	public static final IntegerProperty POWER = BlockStateProperties.POWER;
19
	private final int maxWeight;
20
21
	/**
22
	 * Access widened by fabric-transitive-access-wideners-v1 to accessible
23
	 */
24
	public WeightedPressurePlateBlock(final int maxWeight, final BlockSetType type, final BlockBehaviour.Properties properties) {
25
		super(properties, type);
26
		this.registerDefaultState(this.stateDefinition.any().setValue(POWER, 0));
27
		this.maxWeight = maxWeight;
28
	}
29
30
	@Override
31
	protected int getSignalStrength(final Level level, final BlockPos pos) {
32
		int count = Math.min(getEntityCount(level, TOUCH_AABB.move(pos), Entity.class), this.maxWeight);
33
		if (count > 0) {
34
			float percent = (float)Math.min(this.maxWeight, count) / this.maxWeight;
35
			return Mth.ceil(percent * 15.0F);
36
		} else {
37
			return 0;
38
		}
39
	}
40
41
	@Override
42
	protected int getSignalForState(final BlockState state) {
43
		return state.getValue(POWER);
44
	}
45
46
	@Override
47
	protected BlockState setSignalForState(final BlockState state, final int signal) {
48
		return state.setValue(POWER, signal);
49
	}
50
51
	@Override
52
	protected int getPressedTime() {
53
		return 10;
54
	}
55
56
	@Override
57
	protected void createBlockStateDefinition(final StateDefinition.Builder<Block, BlockState> builder) {
58
		builder.add(POWER);
59
	}
60
}
61

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