BlockState .java

net.minecraft.world.level.block.state.BlockState (class, 27 lines): members: asState, CONSTANT_OR_DISPATCH_CODEC, FULL_CODEC, CODEC. imports: Property.

net.minecraft.world.level.block.stateclass27 linescommonextends BlockBehaviour.BlockStateBase1.2 KB

Implements

API Surface (1)

BlockState asState()

Fields & Constants (3)

FULL_CODEC
CONSTANT_OR_DISPATCH_CODEC
CODEC

Code Graph: Dependencies (4)

Edges (calls / imports / inherits / references) resolved by graphify from the AST. Every chip opens the class source.

Full Source

BlockState.java27 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.world.level.block.state;
2
3
import com.mojang.datafixers.util.Either;
4
import com.mojang.serialization.Codec;
5
import net.fabricmc.fabric.api.block.v1.FabricBlockState;
6
import net.minecraft.core.registries.BuiltInRegistries;
7
import net.minecraft.world.level.block.Block;
8
import net.minecraft.world.level.block.state.properties.Property;
9
10
public class BlockState extends BlockBehaviour.BlockStateBase implements FabricBlockState {
11
	public static final Codec<BlockState> FULL_CODEC = codec(BuiltInRegistries.BLOCK.byNameCodec(), Block::defaultBlockState, Block::getStateDefinition).stable();
12
	private static final Codec<Either<Block, BlockState>> CONSTANT_OR_DISPATCH_CODEC = Codec.either(BuiltInRegistries.BLOCK.byNameCodec(), FULL_CODEC);
13
	public static final Codec<BlockState> CODEC = CONSTANT_OR_DISPATCH_CODEC.xmap(
14
		either -> either.map(Block::defaultBlockState, f -> (BlockState)f),
15
		state -> state == state.getBlock().defaultBlockState() ? Either.left(state.getBlock()) : Either.right(state)
16
	);
17
18
	public BlockState(final Block owner, final Property<?>[] propertyKeys, final Comparable<?>[] propertyValues) {
19
		super(owner, propertyKeys, propertyValues);
20
	}
21
22
	@Override
23
	protected BlockState asState() {
24
		return this;
25
	}
26
}
27

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