Long ago the island's first potluck was held in a feast hall that's now deep under the ground. Wander far enough down and you may break into it: long tables laid with candles, a hearth with its cooking pot, a larder and a shelf of old recipes. Each recipe card teaches the cooking pot a dish found nowhere else, from glowcap soup to potluck stew, as long as you carry it. And somewhere on the shelf is the menu from that first potluck, for the Curator.
| 1 | --!strict |
| 2 | -- Types for the Potluck API, for editors and AI helpers. Written by the game; don't edit. |
| 3 | -- @potluck/world 0.25, @potluck/tweak 0.1, @potluck/game 0.1, @potluck/store 0.1, @potluck/input 0.1, @potluck/ui 0.2, @potluck/sound 0.2, @potluck/net 0.2, @potluck/test 0.8, @potluck/sky 0.1, @potluck/power 0.1 |
| 4 | |
| 5 | export type Position = vector | { number } |
| 6 | |
| 7 | export type Player = { |
| 8 | id: number, |
| 9 | name: string, |
| 10 | position: vector, |
| 11 | } |
| 12 | |
| 13 | export type Part = { |
| 14 | [number]: string, |
| 15 | size: { number }, |
| 16 | at: { number }, |
| 17 | color: string?, |
| 18 | leg: boolean?, |
| 19 | head: boolean?, |
| 20 | glow: boolean?, |
| 21 | -- 0.27: how much it lights what's around it, 0 to 1 (1 a lantern's light); it glows too |
| 22 | light: number?, |
| 23 | -- 0.11: where its picture is in one of the creation's Blockbench models (world.model fills it in) |
| 24 | texture: { file: string, index: number?, color: string?, stamp: number?, faces: { [string]: { number } }? }?, |
| 25 | } |
| 26 | |
| 27 | export type CreatureDef = { |
| 28 | name: string, |
| 29 | -- a list of boxes, or (0.11) a Blockbench model in the creation's folder: "hedgehog.bbmodel" |
| 30 | body: ({ Part } | string)?, |
| 31 | size: { number }?, |
| 32 | speed: number?, |
| 33 | count: number?, |
| 34 | -- "green", "paddock", "creek", "start", a position, or (0.21) "here": |
| 35 | -- wherever each one is spawned |
| 36 | home: (string | Position)?, |
| 37 | rideable: boolean?, |
| 38 | seat: number?, |
| 39 | flies: boolean?, |
| 40 | swims: boolean?, |
| 41 | -- 0.35: rides the top of the water, as a boat does (swims too) |
| 42 | floats: boolean?, |
| 43 | -- 0.23: false so a rider doesn't steer it |
| 44 | steer: boolean?, |
| 45 | -- 0.32: true so doors it walks into open for it, and shut behind it |
| 46 | doors: boolean?, |
| 47 | behaviors: Behaviors?, |
| 48 | } |
| 49 | |
| 50 | -- What a creature does by itself, with no code (world 0.10). |
| 51 | export type Behaviors = { |
| 52 | wander: boolean?, |
| 53 | follow_food: (string | { string })?, |
| 54 | follow_when_used: (boolean | number)?, |
| 55 | flee_when_hit: (boolean | number)?, |
| 56 | hop_when_hit: (boolean | number)?, |
| 57 | chatter: (string | { string })?, |
| 58 | sound: string?, |
| 59 | } |
| 60 | |
| 61 | export type Creature = { |
| 62 | id: number, |
| 63 | kind: string, |
| 64 | position: vector, |
| 65 | rider: Player?, |
| 66 | walk_to: (self: Creature, pos: Position, speed: number?) -> (), |
| 67 | wander: (self: Creature, speed: number?) -> (), |
| 68 | stop: (self: Creature) -> (), |
| 69 | hop: (self: Creature, power: number?) -> (), |
| 70 | face: (self: Creature, pos: Position) -> (), |
| 71 | say: (self: Creature, text: string) -> (), |
| 72 | distance_to: (self: Creature, pos: Position) -> number, |
| 73 | throw_rider: (self: Creature, force: number?) -> boolean, |
| 74 | -- 0.21: something thrown from about its eyes, which hits players |
| 75 | throw: (self: Creature, opts: ThrowOptions, landed: ((at: vector, block: string?, creature: number?, player: Player?) -> ())?) -> number?, |
| 76 | remove: (self: Creature) -> (), |
| 77 | on_ground: (self: Creature) -> boolean, |
| 78 | climb: (self: Creature, speed: number) -> boolean, |
| 79 | -- 0.23: along a path of points, gently; and how far is left, how fast |
| 80 | -- it's going and how many points are left |
| 81 | follow: (self: Creature, points: { Position }?, speed: number?, more: boolean?) -> (), |
| 82 | following: (self: Creature) -> (number, number, number), |
| 83 | become: (self: Creature, kind: any) -> (), |
| 84 | [string]: any, |
| 85 | } |
| 86 | |
| 87 | export type World = { |
| 88 | creature: (def: CreatureDef) -> any, |
| 89 | -- 0.11: a Blockbench model (.bbmodel in the creation's folder) as a body, 16 pixels to a block times scale |
| 90 | model: (file: string, scale: number?) -> { Part }, |
| 91 | block: (pos: Position) -> string, |
| 92 | set_block: (pos: Position, name: string, facing: string?) -> boolean, |
| 93 | -- 0.32: whether the door or trapdoor there is open (nil for anything else) |
| 94 | is_open: (pos: Position) -> boolean?, |
| 95 | -- 0.32: opens or shuts a door (both halves) or trapdoor |
| 96 | set_open: (pos: Position, open: boolean) -> boolean, |
| 97 | facing: (pos: Position) -> string?, |
| 98 | top: (x: number, z: number) -> number, |
| 99 | find_block: (pos: Position, radius: number, name: string) -> vector?, |
| 100 | players: () -> { Player }, |
| 101 | nearest_player: (pos: Position, radius: number?) -> Player?, |
| 102 | spawn: (kind: any, pos: Position) -> number, |
| 103 | creatures: (kind: any?) -> { number }, |
| 104 | spot: (name: string) -> vector?, |
| 105 | say: (text: string) -> (), |
| 106 | time: () -> number, |
| 107 | random: (a: number?, b: number?) -> number, |
| 108 | -- 0.2 |
| 109 | after: (seconds: number, fn: () -> ()) -> number, |
| 110 | every: (seconds: number, fn: () -> ()) -> number, |
| 111 | cancel: (id: number) -> boolean, |
| 112 | on: ((event: "player_joined" | "player_left", fn: (player: Player) -> ()) -> ()) |
| 113 | & ((event: "block_placed" | "block_broken" | "block_used", fn: (player: Player, at: vector, block: string) -> ()) -> ()) |
| 114 | & ((event: "item_used", fn: (player: Player, item: string?, aim: vector) -> ()) -> ()) |
| 115 | & ((event: "player_fell", fn: (player: Player, at: vector) -> ()) -> ()) |
| 116 | & ((event: "player_hit", fn: (attacker: Player, victim: Player) -> ()) -> ()) -- 0.28 |
| 117 | & ((event: "recipe_fetch", fn: (player: Player, wants: { [string]: number }, at: vector) -> ()) -> ()) |
| 118 | & ((event: "recipe_craft", fn: (player: Player, station: string, index: number) -> ()) -> ()), -- 0.29 |
| 119 | -- 0.3 |
| 120 | pockets: (player: Player | number) -> { [string]: number }?, |
| 121 | has: (player: Player | number, block: string) -> number, |
| 122 | take: (player: Player | number, block: string, n: number?) -> boolean, |
| 123 | give: (player: Player | number, block: string, n: number?) -> number, |
| 124 | -- 0.4 |
| 125 | daytime: () -> number, |
| 126 | -- 0.33: with a position in the Long Dusk, its standing sun's light there |
| 127 | daylight: (pos: Position?) -> number, |
| 128 | find_light: (pos: Position, radius: number) -> vector?, |
| 129 | hurt: (player: Player | number, amount: number, opts: { down_to: number?, guarded: boolean? }?) -> boolean, |
| 130 | heal: (player: Player | number, amount: number) -> boolean, |
| 131 | -- 0.6 |
| 132 | healing: (player: Player | number, rate: number) -> boolean, |
| 133 | -- 0.8 |
| 134 | held: (player: Player | number) -> string?, |
| 135 | kind: (block: string) -> "soft" | "hard" | "wood" | "plant" | "glass" | "water" | "air", |
| 136 | digging: (block: string, speeds: { soft: number?, hard: number?, wood: number?, plant: number?, glass: number?, level: number? }?) -> (), |
| 137 | drops: (block: string, rule: { gives: (string | false)?, count: (number | { number })?, level: number? }?) -> (), |
| 138 | -- 0.18 |
| 139 | guard: (player: Player | number, share: number) -> boolean, |
| 140 | -- 0.24: what every game draws them wearing in a slot ("head", "body", |
| 141 | -- "legs", "feet" or "arm"); nil for nothing |
| 142 | wear: (player: Player | number, slot: string, thing: string?) -> boolean, |
| 143 | -- 0.19 |
| 144 | shoot: (player: Player | number, opts: ShotOptions, landed: ((at: vector, block: string?, creature: number?, player: Player?) -> ())?) -> number?, |
| 145 | aims: (item: string, on: boolean?) -> (), |
| 146 | -- 0.21 |
| 147 | danger: () -> "peaceful" | "gentle" | "normal" | "hard", |
| 148 | rule: (name: "fire_spreads" | "mob_griefing" | "pvp") -> boolean, -- 0.28: what the world allows |
| 149 | recipes: (station: string, list: { { give: string, n: number?, want: { [string]: number }?, note: string? } }) -> (), -- 0.29: for the item guide |
| 150 | -- 0.36: goals for the Goals screen: list them, then hand them out |
| 151 | goals: (list: { { id: string, title: string, text: string?, group: string?, after: string?, xp: number? } }) -> (), |
| 152 | achieve: (player: Player, id: string) -> boolean, |
| 153 | achieved: (player: Player, id: string) -> boolean, |
| 154 | biome: (pos: Position) -> string, -- 0.30: the kind of land the seed makes there |
| 155 | -- 0.33: "home" or "dusk" (the Long Dusk, past the wild) |
| 156 | place: (pos: Position) -> "home" | "dusk", |
| 157 | -- 0.33: sends a player there at once, through the dark, saying the place's name |
| 158 | send: (player: Player, pos: Position, name: string?) -> boolean, |
| 159 | -- 0.22 |
| 160 | reward: (player: Player | number, xp: number) -> number, |
| 161 | xp: (player: Player | number) -> (number, number), |
| 162 | spend_xp: (player: Player | number, xp: number) -> boolean, |
| 163 | xp_for: (level: number) -> number, |
| 164 | haste: (player: Player | number, share: number?) -> number, |
| 165 | perk: (player: Player | number, name: string, level: number?) -> number, |
| 166 | might: (player: Player | number, share: number?) -> number, |
| 167 | charms: (player: Player | number, item: string) -> { string }, |
| 168 | charm: (player: Player | number, item: string, charms: { string }) -> boolean, |
| 169 | -- 0.25: an item by name, the game's or one a creation made ([items.*]); |
| 170 | -- nil for a block or nothing. And the names of every item creations made. |
| 171 | item: (name: string) -> ItemInfo?, |
| 172 | items: () -> { string }, |
| 173 | } |
| 174 | |
| 175 | -- world.item's table (0.25). The game's own items have only a name, a stack |
| 176 | -- and `by = "game"`; an item a creation made has its kind and what it wrote. |
| 177 | export type ItemInfo = { |
| 178 | name: string, |
| 179 | stack: number, |
| 180 | by: string, |
| 181 | kind: ("material" | "food" | "tool" | "weapon" | "armor")?, |
| 182 | recipe: { [string]: number }?, |
| 183 | -- 0.27: what a cooking pot cooks it from, and a card a cook carries to cook it |
| 184 | cook: { [string]: number }?, |
| 185 | card: string?, |
| 186 | makes: number?, |
| 187 | food: number?, |
| 188 | says: string?, |
| 189 | slot: ("head" | "body" | "legs" | "feet" | "arm")?, |
| 190 | guard: number?, |
| 191 | warm: boolean?, |
| 192 | digs: { [string]: number }?, |
| 193 | power: number?, |
| 194 | -- 0.26: a relic's story |
| 195 | relic: string?, |
| 196 | } |
| 197 | |
| 198 | -- world.shoot's options (0.19), and the shot a creature's hit hears |
| 199 | export type ShotOptions = { aim: Position, look: ("arrow" | "stone" | "spear" | "ember" | "spores")?, speed: number?, drop: number?, power: number? } |
| 200 | -- self:throw's (0.21): `aim` the way to throw, or `at` a place to throw at |
| 201 | export type ThrowOptions = { aim: Position?, at: Position?, look: ("arrow" | "stone" | "spear" | "ember" | "spores")?, speed: number?, drop: number?, power: number? } |
| 202 | export type Shot = { id: number, look: string, power: number } |
| 203 | |
| 204 | export type Score = { name: string, value: number } |
| 205 | |
| 206 | export type Game = { |
| 207 | score: (board: string, player: Player | number, value: number, opts: { lower: boolean? }?) -> (), |
| 208 | board: (board: string, n: number?) -> { Score }, |
| 209 | links: () -> { string }, |
| 210 | send: (player: Player | number, link: string, note: string?) -> (), |
| 211 | } |
| 212 | |
| 213 | export type Stored = nil | boolean | number | string | vector | { [any]: Stored } |
| 214 | |
| 215 | export type Store = { |
| 216 | get: (key: string) -> Stored, |
| 217 | set: (key: string, value: Stored) -> (), |
| 218 | keys: () -> { string }, |
| 219 | used: () -> number, |
| 220 | } |
| 221 | |
| 222 | export type Input = { |
| 223 | on: (action: string, fn: (player: Player) -> ()) -> (), |
| 224 | held: (action: string, player: Player | number) -> boolean, |
| 225 | focus: (player: Player | number, on: boolean?) -> (), |
| 226 | focused: (player: Player | number) -> boolean, |
| 227 | } |
| 228 | |
| 229 | export type Question = { |
| 230 | title: string?, |
| 231 | text: string?, |
| 232 | choices: { string }?, |
| 233 | } |
| 234 | |
| 235 | export type UI = { |
| 236 | show: (player: Player | number | nil, id: string, text: string, opts: { at: ("right" | "left" | "bottom")? }?) -> (), |
| 237 | hide: (player: Player | number | nil, id: string) -> (), |
| 238 | -- 0.2 |
| 239 | meter: (player: Player | number | nil, id: string, value: number?, opts: { color: string? }?) -> (), |
| 240 | effect: (player: Player | number | nil, id: string, icon: string?, text: string?) -> (), |
| 241 | ask: (player: Player | number, question: Question, fn: (player: Player, choice: number?) -> ()) -> number, |
| 242 | close: (player: Player | number) -> boolean, |
| 243 | } |
| 244 | |
| 245 | export type SoundOptions = { |
| 246 | at: (Position | Creature)?, |
| 247 | volume: number?, |
| 248 | pitch: number?, |
| 249 | caption: string?, |
| 250 | } |
| 251 | |
| 252 | -- `name` is one of the game's sounds, or one of the creation's own from |
| 253 | -- `[sounds.name]` in potluck.toml (0.2), which come first. |
| 254 | export type Sound = { |
| 255 | play: (name: string, opts: SoundOptions?) -> boolean, |
| 256 | play_for: (player: Player | number, name: string, opts: SoundOptions?) -> boolean, |
| 257 | -- its own first, then the game's |
| 258 | names: () -> { string }, |
| 259 | } |
| 260 | |
| 261 | -- In the main file, on the world's host. |
| 262 | export type Net = { |
| 263 | send: (player: Player | number | nil, topic: string, value: Stored?) -> boolean, |
| 264 | on: (topic: string, fn: (player: Player, value: Stored) -> ()) -> (), |
| 265 | } |
| 266 | |
| 267 | -- In a client half (`client` in potluck.toml), on each player's own game. |
| 268 | -- 0.2: `look` is which way they look, `aim` the middle of the block they aim at. |
| 269 | export type Me = Player & { look: vector, aim: vector? } |
| 270 | |
| 271 | export type ClientNet = { |
| 272 | send: (topic: string, value: Stored?) -> boolean, |
| 273 | on: (topic: string, fn: (value: Stored) -> ()) -> (), |
| 274 | me: () -> Me, |
| 275 | } |
| 276 | |
| 277 | -- In test.luau, while the creation's tests run (the dev bridge's test, potluck-server --test). |
| 278 | export type TestPlayerOptions = { |
| 279 | at: Position?, |
| 280 | survival: boolean?, |
| 281 | carrying: { [string]: number }?, |
| 282 | } |
| 283 | |
| 284 | export type Test = { |
| 285 | case: (name: string, fn: () -> ()) -> (), |
| 286 | check: (ok: any, message: string?) -> any, |
| 287 | same: (got: any, want: any, message: string?) -> (), |
| 288 | -- these hand over to the game: keep each on a line of its own |
| 289 | wait: (seconds: number) -> (), |
| 290 | player: (name: string?, opts: TestPlayerOptions?) -> Player, |
| 291 | move: (player: Player, at: Position) -> Player, |
| 292 | place: (player: Player, at: Position, block: string, facing: string?) -> (), |
| 293 | dig: (player: Player, at: Position) -> boolean, |
| 294 | use_block: (player: Player, at: Position) -> (), |
| 295 | use_item: (player: Player, aim: Position?) -> (), |
| 296 | use: (player: Player, creature: Creature | number) -> (), |
| 297 | hit: (player: Player, target: Creature | number | Player) -> (), -- 0.9: another player too |
| 298 | ride: (player: Player, creature: Creature | number) -> (), |
| 299 | get_off: (player: Player) -> (), |
| 300 | press: (player: Player, action: string) -> (), |
| 301 | release: (player: Player, action: string) -> (), |
| 302 | answer: (player: Player, choice: number) -> (), |
| 303 | hold: (player: Player, block: string?) -> (), |
| 304 | from_half: (player: Player, topic: string, value: Stored?) -> (), -- 0.3 |
| 305 | danger: (level: "peaceful" | "gentle" | "normal" | "hard") -> (), -- 0.7: the world's, for this case |
| 306 | rule: (name: "fire_spreads" | "mob_griefing" | "pvp", on: boolean) -> (), -- 0.9: the world's, for this case |
| 307 | daytime: (time: number) -> (), -- 0.8: 0 midnight, 0.25 sunrise, 0.5 noon, 0.75 sunset; it stays there |
| 308 | -- these only look |
| 309 | kind: (name: string) -> any, |
| 310 | creature: (id: number | Creature) -> Creature?, |
| 311 | health: (player: Player | number) -> number?, |
| 312 | shown: (player: Player | number, id: string) -> string?, |
| 313 | asked: (player: Player | number) -> { title: string, text: string, choices: { string } }?, |
| 314 | -- 0.2 |
| 315 | heard: (name: string) -> number, |
| 316 | -- 0.3: the last value sent to that player's client half on a topic, and how many times |
| 317 | sent: (player: Player | number, topic: string) -> (Stored?, number), |
| 318 | } |
| 319 | |
| 320 | -- @potluck/sky 0.1: the weather and the season, the same on every game in |
| 321 | -- the world. The game draws them and plays the rain and thunder. |
| 322 | export type WeatherKind = "clear" | "cloudy" | "rain" | "storm" | "snow" | "fog" |
| 323 | export type SeasonName = "spring" | "summer" | "autumn" | "winter" |
| 324 | export type Weather = { |
| 325 | kind: WeatherKind, |
| 326 | -- how heavy, 0 to 1 |
| 327 | strength: number, |
| 328 | -- blocks a second along x and z (y is 0) |
| 329 | wind: vector, |
| 330 | } |
| 331 | export type WeatherOptions = { |
| 332 | -- 0 to 1: 0.6 when not said (0 for clear) |
| 333 | strength: number?, |
| 334 | -- blocks a second along x and z, up to 12; the wind stays as it was when not said |
| 335 | wind: Position?, |
| 336 | -- seconds it takes to come in, 0 to 120: 20 when not said |
| 337 | over: number?, |
| 338 | } |
| 339 | export type RainbowOptions = { |
| 340 | facing: number?, |
| 341 | strength: number?, |
| 342 | } |
| 343 | export type Rainbow = { |
| 344 | at: vector, |
| 345 | facing: number, |
| 346 | strength: number, |
| 347 | } |
| 348 | export type Sky = { |
| 349 | weather: () -> Weather, |
| 350 | -- kind is a WeatherKind |
| 351 | set_weather: (kind: string, opts: WeatherOptions?) -> (), |
| 352 | -- the season, and how far through it, 0 to 1 |
| 353 | season: () -> (SeasonName, number), |
| 354 | -- name is a SeasonName |
| 355 | set_season: (name: string, progress: number?) -> (), |
| 356 | -- lightning there: a glow in the sky and thunder on every game, and |
| 357 | -- `strike` for every creation; false when it's made too many (one a |
| 358 | -- second, three at once) |
| 359 | strike: (at: Position) -> boolean, |
| 360 | on: (event: "strike", fn: (at: vector) -> ()) -> (), |
| 361 | -- 0.2: a rainbow whose foot stands at `at`, arching along `facing` (a |
| 362 | -- heading in radians) as strongly as `strength` says, 0 to 1 (1 if |
| 363 | -- not said); nil takes it away |
| 364 | set_rainbow: (at: Position?, opts: RainbowOptions?) -> (), |
| 365 | rainbow: () -> Rainbow?, |
| 366 | } |
| 367 | |
| 368 | export type Knob = { [number]: any, min: number?, max: number?, label: string?, order: number? } |
| 369 | export type Tweak = (spec: { [string]: Knob }) -> { [string]: any } |
| 370 | |
| 371 | return {} |
| 372 | |
| 373 | -- @potluck/power 0.1: loads other creations put on the Power creation's |
| 374 | -- grids. `consume` says a block at a place wants watts (class 1 lights, 2 |
| 375 | -- farm, 3 machines, 4 heavy: the last classes go without first), `got` says |
| 376 | -- how many it was given a moment ago, and `release` takes it away. |
| 377 | export type Power = { |
| 378 | consume: (at: Position, watts: number, class: number?) -> (), |
| 379 | release: (at: Position) -> (), |
| 380 | got: (at: Position) -> number, |
| 381 | loads: () -> { { at: vector, watts: number, class: number, by: string } }, |
| 382 | deliver: (at: Position, watts: number) -> (), |
| 383 | } |
| 384 | |
| 385 | -- @potluck/power 0.1: loads other creations put on the Power creation's |
| 386 | -- grids. `consume` says a block at a place wants watts (class 1 lights, 2 |
| 387 | -- farm, 3 machines, 4 heavy: the higher classes go without first), `got` |
| 388 | -- says how many it was given a moment ago, and `release` takes it away. |
| 389 | export type Power = { |
| 390 | consume: (at: Position, watts: number, class: number?) -> (), |
| 391 | release: (at: Position) -> (), |
| 392 | got: (at: Position) -> number, |
| 393 | loads: () -> { { at: vector, watts: number, class: number, by: string } }, |
| 394 | deliver: (at: Position, watts: number) -> (), |
| 395 | } |