Skip to content

Prefab bindings

PrefabBindings is the parameter scope used during instantiation. Three sources combine, later overriding earlier: the prefab’s declared default params, instantiation-time overrides passed by the caller, and any sub-prefab rebindings. Coordinate expressions in the JSON ("@xMin", "@yFloor + 1") resolve against this map at instantiation, so one prefab template parameterises across dozens of call sites.

  • You’re calling Scene.instantiate and need to supply or override parameters.
  • You’re composing prefabs and want a sub-prefab to inherit + override the parent’s params.
  • You’re authoring a tool that introspects a prefab’s required params before instantiating it.
package me.zlex.conduit.prefab;
public final class PrefabBindings {
public static PrefabBindings empty();
public static PrefabBindings of(Map<String, Integer> values);
public PrefabBindings put(String name, int value);
public PrefabBindings putAll(Map<String, Integer> values);
public int requireInt(String name); // throws if missing
public boolean has(String name);
public Map<String, Integer> asMap();
public PrefabBindings copy();
}

requireInt throws a clear error listing every known param, so missing-binding bugs surface immediately at instantiation rather than as silent zero-fill.

import me.zlex.conduit.prefab.Prefab;
import me.zlex.conduit.prefab.PrefabBindings;
import me.zlex.conduit.prefab.Scene;
import me.zlex.conduit.prefab.SceneStore;
public final class StagingBoxAt {
public static Scene build(net.minecraft.server.level.ServerLevel level,
int cx, int cz, int half, int height) {
Prefab.Id id = Prefab.Id.of("conduit", "default-staging-box");
Prefab prefab = SceneStore.prefab(id);
PrefabBindings bindings = PrefabBindings.empty()
.putAll(prefab.params()) // prefab defaults
.put("xMin", cx - half).put("xMax", cx + half) // call-site overrides
.put("zMin", cz - half).put("zMax", cz + half)
.put("yFloor", 100).put("yCeiling", 100 + height);
return Scene.instantiate(level, new net.minecraft.core.BlockPos(0, 0, 0),
bindings, id, prefab, SceneStore.get());
}
}
  • The combine order matters — load prefab defaults first, then layer overrides. putAll is just a shorthand for a sequence of puts.
  • A typo in a param name throws on the first element that references it — the error message lists the known keys, so the fix is usually obvious.
  • Sub-prefab references can rebind a subset; the rest fall through from the parent’s bindings.