BlockInWorld .java

net.minecraft.world.level.block.state.pattern.BlockInWorld (class): members: cachedEntity, loadChunks, hasState, getEntity, getState, getLevel, getPos.

net.minecraft.world.level.block.state.patternclass53 linescommon1.4 KB

API Surface (3)

BlockState getState()
LevelReader getLevel()
BlockPos getPos()

Fields & Constants (6)

level
pos
loadChunks
state
entity
cachedEntity

Code Graph: Dependencies (4)

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

Full Source

BlockInWorld.java53 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.world.level.block.state.pattern;
2
3
import java.util.function.Predicate;
4
import net.minecraft.core.BlockPos;
5
import net.minecraft.world.level.LevelReader;
6
import net.minecraft.world.level.block.entity.BlockEntity;
7
import net.minecraft.world.level.block.state.BlockState;
8
import org.jspecify.annotations.Nullable;
9
10
public class BlockInWorld {
11
	private final LevelReader level;
12
	private final BlockPos pos;
13
	private final boolean loadChunks;
14
	private @Nullable BlockState state;
15
	private @Nullable BlockEntity entity;
16
	private boolean cachedEntity;
17
18
	public BlockInWorld(final LevelReader level, final BlockPos pos, final boolean loadChunks) {
19
		this.level = level;
20
		this.pos = pos.immutable();
21
		this.loadChunks = loadChunks;
22
	}
23
24
	public BlockState getState() {
25
		if (this.state == null && (this.loadChunks || this.level.hasChunkAt(this.pos))) {
26
			this.state = this.level.getBlockState(this.pos);
27
		}
28
29
		return this.state;
30
	}
31
32
	public @Nullable BlockEntity getEntity() {
33
		if (this.entity == null && !this.cachedEntity) {
34
			this.entity = this.level.getBlockEntity(this.pos);
35
			this.cachedEntity = true;
36
		}
37
38
		return this.entity;
39
	}
40
41
	public LevelReader getLevel() {
42
		return this.level;
43
	}
44
45
	public BlockPos getPos() {
46
		return this.pos;
47
	}
48
49
	public static Predicate<@Nullable BlockInWorld> hasState(final Predicate<BlockState> predicate) {
50
		return input -> input != null && predicate.test(input.getState());
51
	}
52
}
53

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