Skip to content

Fake Levels

MehVahdJukaar edited this page Jul 25, 2026 · 1 revision

Fake Levels and Fake Players

A Level that isn't a world, and a Player that isn't a person.

Plenty of vanilla and modded code demands a Level or a Player when there isn't a real one around. Rendering a block in a GUI, previewing a structure, running a block's use from a machine, simulating a placement to see what would happen. A fake level is a real Level subclass backed by nothing: no chunks, no ticking, no saving, but blocks, block entities and recipes work, so anything that only reads from the level is happy.

This is one of the more unusual things in the library and it solves a class of problem that's otherwise very annoying.

Getting Started

Levels are cached by id, so ask the manager rather than constructing one:

Level fake = FakeLevelManager.getDefault(realLevel);

// or your own, keyed by id, so several systems don't share one
FakeLevel mine = FakeLevelManager.getClient("my_preview", realLevel, MyFakeLevel::new);

Set blocks in it and render or query them like normal:

fake.setBlock(BlockPos.ZERO, Blocks.FURNACE.defaultBlockState(), 3);
BlockEntity be = fake.getBlockEntity(BlockPos.ZERO);

FakeServerLevel is the server side variant, for code that hard casts to ServerLevel.

Fake levels have a controllable day time (setDayTimeFraction, setDayTimePerTick), which matters when you're rendering a preview and don't want it to depend on the real world's time of day.

Call FakeLevelManager.invalidate(id) when you're done with one, or invalidateAll().

Fake players

Player fake = PlatHelper.getFakeServerPlayer(profile, serverLevel);

// and to check, since other mods' fake players show up too
PlatHelper.isFakePlayer(somePlayer);

Used when a machine or block needs to act "as" a player: breaking blocks, using items, triggering events that require a player. FakeGenericPlayer and FakeLocalPlayer are the implementations.

DummyBlockGetter is the lighter option when all you need is a BlockGetter for a handful of positions and not a whole level.

Clone this wiki locally