Place items in the world
Lay item stacks on the ground from World Builder, a world file and a script, and restock an arrow stall a minute after someone takes its arrows.
In multiplayer, the level does not put any items of its own on the ground. Only the recipe books and smithing tools that crafting stations need are kept. To put arrows in an armoury or food on a market stall, lay them down yourself. Players pick them up with the game’s usual prompt.
You will do it three ways: in World Builder, by hand in a world resource’s
items list, and from a server script. The script is an arrow stall that
lays a fresh stack a minute after someone takes the last one.
What you will learn
Section titled “What you will learn”- Placing item stacks in World Builder and setting their amount, quality, health and condition.
- Writing a world resource’s
itemslist by hand. - Laying a named stack down with
GroundItem.spawnand finding it again by name. - Restocking when
groundItemPickupreports that a player took it.
server/ server.json worlds/market.world.json exported from World Builder resources/arrow-stall/ package.json tsconfig.json from Use TypeScript src/server/stall.ts lays the arrows down and restocks them src/server/index.ts /where, and the first stock1. Place items in World Builder
Section titled “1. Place items in World Builder”- Open World Builder and your project, as in the furnishing tutorial.
- In the Library tab, open the
itemsfolder. Every item class the game ships is listed by the game’s category. Searchingitems/Food, for example, lists the food. Quest items are not listed. - Click an item’s row, then left-click in the world to put a stack down. Turn it with Shift+mouse wheel or R first if you like.
- Select the stack and open the Object tab:
- Name: what a script finds it by, up to 64 bytes.
- Amount: how many units lie in the stack. Items the game does not stack, such as an apple, must use 1.
- Quality: the game’s grade, or 0 for the class’s own.
- Own health and Own condition: turn these on to set them. Off uses the class’s own.
- Save the project, set Resource name to
market, export the world resource and add it tomod.world_resourcesinserver.json, as in step 6 of the furnishing tutorial.
In the editor, most items show their own mesh. An item a character wears, such as a hat, shows as a small box, because the editor cannot stand it up as a mesh. Players see the real item.
Items keep their own size, so Ctrl+mouse wheel does nothing for them.
2. Or write them into the world file
Section titled “2. Or write them into the world file”An exported <name>.world.json keeps items in its items list. You can
write entries by hand too:
{ "items": [ { "item": "arrow_crude", "amount": 12, "position": [3103.0, 818.5, 57.3], "rotation": [0, 0, 0, 1], "name": "armoury-arrows" } ]}| Field | Type | Default | Meaning |
|---|---|---|---|
item |
string | required | The item class, by GUID or by name such as arrow_crude. |
position |
[x, y, z] |
required | Where it lies. The stack is placed there, not dropped, so put it on the ground. |
rotation |
[x, y, z, w] |
no rotation | How it lies. |
amount |
whole number, 1 to 10000 | 1 | Units in the stack. An item the game does not stack must use 1. |
name |
string | none | Up to 64 bytes. |
quality |
whole number, 0 to 255 | the class’s own | The game’s grade. |
health |
number, 0 to 1 | the class’s own | The item’s health. |
condition |
number, 0 to 1 | the class’s own | The item’s condition. |
The server lays the items down every time it starts, in the global world, which every player sees. Items that players picked up are back after a restart. An unknown item class, or a stack no player’s game could build, stops the server at startup with an error naming the entry.
3. Create the resource
Section titled “3. Create the resource”Create resources/arrow-stall and copy the server tsconfig.json from
Use TypeScript.
{ "name": "arrow-stall", "version": "1.0.0", "scripts": { "build": "tsc -p tsconfig.json" }, "devDependencies": { "@kingdomsconnected/types": "latest", "typescript": "^5.9.2" }, "mafiahub": { "serverScripts": ["dist/server/index.js"] }}4. Lay the arrows down and restock them
Section titled “4. Lay the arrows down and restock them”GroundItem.spawn(item, position, rotation, amount, virtualWorld, properties)
lays one stack down and returns it. Everything after item is optional.
properties can hold name, quality, health, condition and
carryable.
The stall lays a stack of arrows down, and lays a fresh one a minute after someone takes it:
/** Where the stall's arrows lie. Put your own position here; /where tells you yours. */const STALL = { item: "arrow_crude", amount: 12, name: "stall-arrows", position: new Vector3(3103.0, 818.5, 57.3),};
/** How long the stall stays empty after someone takes the arrows. */const RESTOCK_MS = 60_000;
/** Lays the arrows down, unless the stall's stack is still lying there. */export function stock(): void { if (GroundItem.all().some((stack) => stack.name === STALL.name)) return; GroundItem.spawn(STALL.item, STALL.position, undefined, STALL.amount, undefined, { name: STALL.name });}
export function installRestock(): void { Events.on("groundItemPickup", (stack, player) => { if (stack.name !== STALL.name) return; console.log(`${player ? player.nickname : "Someone"} took the stall's arrows`); setTimeout(stock, RESTOCK_MS); });}groundItemPickupis raised once the server has given the stack to the player. You can still read the stack’sname,itemClassandamountin the handler.GroundItem.all().find((stack) => stack.name === "stall-arrows")finds a stack later by its name.stockchecks the same way, so it never lays a second stack beside one that is still there.- The name stays on the server. Players never see it.
GroundItem.spawnthrows when the item class is unknown, when the amount is more than 1 for an item the game does not stack, or when the name is longer than 64 bytes.
5. Find a position and stock the stall
Section titled “5. Find a position and stock the stall”Positions are in metres, with z up. Stand where the stack should lie and
type /where, or read the position in World Builder’s Object tab. The
stack is placed exactly where you say rather than dropped, so use the height
of the ground.
import { installRestock, stock } from "./stall.js";
installRestock();stock();
Events.on("playerCommand", (player, command) => { if (command !== "where") return; const p = player.position; Chat.sendToPlayer(player, `You are at ${p.x.toFixed(2)}, ${p.y.toFixed(2)}, ${p.z.toFixed(2)}`);});A stack a script lays down is kept in memory only, so lay it down again when
the server starts. Calling stock() at the top of the script does that.
Like every entity a resource creates, the stack goes when the resource
stops, so a reload lays one fresh stack where STALL.position now says.
Try it
Section titled “Try it”- Run
npm installandnpm run build, thenensure arrow-stallin the server console. - Type
/wherewhere the stall should be, copy the numbers intoSTALL.position, build again and runensure arrow-stall. - Twelve crude arrows lie at that spot. Pick them up with the game’s prompt. The server console says who took them.
- Wait a minute. A fresh stack lies in the same place.
- If you exported
market.world.json, its stacks lie where you placed them. Pick one up and restart the server: it is back.
Next steps
Section titled “Next steps”- A custom item registered with
Items.registercan be laid down the same way, by the GUID thatItems.registerreturns. See Give a custom item its own icon and model. carryable: truelays down an item that players carry in their arms, such as a sack, instead of putting it in their inventory. See Carry items and bodies in the arms.WorldResource.find("market")?.itemslists the export’s stacks that nobody has picked up yet, each with the name the export gave it. See World exports in scripts.- Pickup, stacking and the other
GroundItemcalls are in Items: give, take and drop.