Crafting for survival: use any table (or Make things by hand in the backpack, for the simple things) to make building blocks, furnaces, an anvil, furniture, a cooking pot, lights (torches and campfires from coal), things for the garden and beehives, wooden, stone and copper tools, shears, hammers, buckets, fishing rods, flint and steel, swords, bows and arrows, slings, spears, shields, wool and copper armor, hot air balloons and circuit parts from what you've gathered.
| 1 | --!strict |
| 2 | -- Workbench: crafting for survival. Use any table (Interact while aiming at |
| 3 | -- it) and pick something to make; it takes what that needs from your |
| 4 | -- hotbar and gives you what you made (world.has, world.take, world.give). |
| 5 | -- With no table near, "Make things by hand" in the backpack opens the same |
| 6 | -- bench with only the simple things (HAND below), as your hands can make. |
| 7 | -- What you can make now comes first, and what you're short of is said. |
| 8 | -- Every recipe is in RECIPES below, so a remix can add its own, change the |
| 9 | -- prices, or craft at a different block. Things other creations make with |
| 10 | -- a recipe of their own ([items.*], world.item) are on the bench too. |
| 11 | |
| 12 | local world = require("@potluck/world@0.29") |
| 13 | local tweak = require("@potluck/tweak") |
| 14 | local ui = require("@potluck/ui@0.1") |
| 15 | local sound = require("@potluck/sound@0.1") |
| 16 | |
| 17 | local knobs = tweak { |
| 18 | generous = { 1, min = 1, max = 3, label = "Makes this many times as much", order = 1 }, |
| 19 | hint = { true, label = "Say so near a table", order = 2 }, |
| 20 | } |
| 21 | |
| 22 | local BENCH = "Table" -- the block you craft at |
| 23 | |
| 24 | -- A recipe: what it takes, what it makes and how many. A cut (stairs, |
| 25 | -- slabs and walls) takes exactly the block it's cut from. One that's |
| 26 | -- `shown` by something is listed only to players carrying some of it. |
| 27 | type Recipe = { want: { [string]: number }, give: string, n: number, cut: boolean?, shown: string? } |
| 28 | |
| 29 | -- Kinds of thing, each with its recipes. A question has eight choices at |
| 30 | -- most, so a longer list comes in pages, seven to a page and More. Tools, |
| 31 | -- swords and the anvil do their work through the Tools creation, hoes |
| 32 | -- through Farming, armor through the Armor creation, bows and the rest |
| 33 | -- through Bows, slings and spears, and a basket fills up into a balloon |
| 34 | -- through the Hot air balloon creation. |
| 35 | local KINDS = { "Building", "Home and lights", "Garden and farm", "Tools", "Weapons and armor", "Travel", "Circuits" } |
| 36 | local RECIPES: { [string]: { Recipe } } = { |
| 37 | Building = { |
| 38 | { want = { ["Oak log"] = 1 }, give = "Planks", n = 4 }, |
| 39 | { want = { ["Birch log"] = 1 }, give = "Birch planks", n = 4 }, |
| 40 | { want = { ["Pine log"] = 1 }, give = "Pine planks", n = 4 }, |
| 41 | { want = { ["Maple log"] = 1 }, give = "Maple planks", n = 4 }, |
| 42 | { want = { ["Willow log"] = 1 }, give = "Willow planks", n = 4 }, |
| 43 | { want = { ["Palm log"] = 1 }, give = "Palm planks", n = 4 }, |
| 44 | { want = { ["Redwood log"] = 1 }, give = "Redwood planks", n = 4 }, |
| 45 | { want = { ["Mahogany log"] = 1 }, give = "Mahogany planks", n = 4 }, |
| 46 | { want = { ["Cypress log"] = 1 }, give = "Cypress planks", n = 4 }, |
| 47 | { want = { ["Plum log"] = 1 }, give = "Plum planks", n = 4 }, |
| 48 | -- the Long Dusk's copper-leaved trees |
| 49 | { want = { ["Duskwood log"] = 1 }, give = "Duskwood planks", n = 4 }, |
| 50 | { want = { Sand = 4 }, give = "Sandstone", n = 1 }, |
| 51 | { want = { Stone = 4 }, give = "Mossy brick", n = 4 }, |
| 52 | -- Cave Crawlers' silk, spun |
| 53 | { want = { Silk = 4 }, give = "Cream wool", n = 1 }, |
| 54 | -- the Brickworks creation's, when it's in the world |
| 55 | { want = { Cobblestone = 8 }, give = "Kiln", n = 1 }, |
| 56 | -- the furnace creation's |
| 57 | { want = { Cobblestone = 8 }, give = "Furnace", n = 1 }, |
| 58 | -- the circuits creation's: it opens when powered |
| 59 | { want = { ["Copper ingot"] = 2 }, give = "Copper gate", n = 1 }, |
| 60 | -- the tools creation's: it makes iron and moonsilver tools and |
| 61 | -- mends worn ones |
| 62 | { want = { ["Iron ingot"] = 5, Stone = 2 }, give = "Anvil", n = 1 }, |
| 63 | }, |
| 64 | ["Home and lights"] = { |
| 65 | { want = { Planks = 6 }, give = "Table", n = 1 }, |
| 66 | -- the Long Dusk creation's: sunstone's light in a duskwood frame |
| 67 | { want = { Sunstone = 1, ["Duskwood planks"] = 2 }, give = "Sun lamp", n = 2, shown = "Sunstone" }, |
| 68 | { want = { Planks = 2 }, give = "Stool", n = 1 }, |
| 69 | { want = { Planks = 6 }, give = "Barrel", n = 1 }, |
| 70 | -- eight planks around a hole, as a chest is made; two side by side |
| 71 | -- are a double chest (the Storage creation) |
| 72 | { want = { Planks = 8 }, give = "Chest", n = 1 }, |
| 73 | { want = { Planks = 4 }, give = "Crate", n = 1 }, |
| 74 | { want = { Planks = 6 }, give = "Bookshelf", n = 1 }, |
| 75 | -- cooks pies and stews over a fire (Furnaces and campfires) |
| 76 | { want = { ["Iron ingot"] = 3 }, give = "Cooking pot", n = 1 }, |
| 77 | -- puts charms on tools and weapons for XP (the Charms creation) |
| 78 | { want = { ["Gold ingot"] = 2, Crystal = 1, Planks = 4 }, give = "Charm table", n = 1 }, |
| 79 | { want = { Coal = 1, Planks = 1 }, give = "Torch", n = 4 }, |
| 80 | { want = { Hay = 1 }, give = "Candle", n = 2 }, |
| 81 | { want = { Glass = 1, Cobblestone = 2 }, give = "Lantern", n = 1 }, |
| 82 | { want = { Cobblestone = 4, ["Oak log"] = 1 }, give = "Brazier", n = 1 }, |
| 83 | { want = { Candle = 1, ["Cream wool"] = 1 }, give = "Paper lantern", n = 2 }, |
| 84 | { want = { Planks = 3, Coal = 1 }, give = "Campfire", n = 1 }, |
| 85 | }, |
| 86 | ["Garden and farm"] = { |
| 87 | { want = { Dirt = 3 }, give = "Clay pot", n = 1 }, |
| 88 | { want = { Wheat = 4 }, give = "Hay", n = 1 }, |
| 89 | { want = { Dirt = 4 }, give = "Farmland", n = 4 }, |
| 90 | -- tills a patch at a time (the farming creation) |
| 91 | { want = { ["Copper ingot"] = 2, Planks = 2 }, give = "Copper hoe", n = 1 }, |
| 92 | -- waters crops, and reaps them (farming too) |
| 93 | { want = { ["Copper ingot"] = 3 }, give = "Watering can", n = 1 }, |
| 94 | { want = { ["Copper ingot"] = 2, Planks = 1 }, give = "Sickle", n = 1 }, |
| 95 | -- bees fill it with honey (the Bees creation) |
| 96 | { want = { Planks = 4, Hay = 2 }, give = "Beehive", n = 1 }, |
| 97 | }, |
| 98 | Tools = { |
| 99 | { want = { Planks = 3 }, give = "Wooden pickaxe", n = 1 }, |
| 100 | { want = { Planks = 3 }, give = "Wooden axe", n = 1 }, |
| 101 | { want = { Planks = 2 }, give = "Wooden shovel", n = 1 }, |
| 102 | { want = { Cobblestone = 3, Planks = 2 }, give = "Stone pickaxe", n = 1 }, |
| 103 | { want = { Cobblestone = 3, Planks = 2 }, give = "Stone axe", n = 1 }, |
| 104 | { want = { Cobblestone = 1, Planks = 2 }, give = "Stone shovel", n = 1 }, |
| 105 | -- copper ones here; iron and moonsilver at an anvil |
| 106 | { want = { ["Copper ingot"] = 3, Planks = 2 }, give = "Copper pickaxe", n = 1 }, |
| 107 | { want = { ["Copper ingot"] = 3, Planks = 2 }, give = "Copper axe", n = 1 }, |
| 108 | { want = { ["Copper ingot"] = 1, Planks = 2 }, give = "Copper shovel", n = 1 }, |
| 109 | -- shears and a hammer (the Tools creation), a bucket and a rod |
| 110 | -- (Buckets and fishing) |
| 111 | { want = { ["Iron ingot"] = 2 }, give = "Shears", n = 1 }, |
| 112 | { want = { ["Iron ingot"] = 3, Planks = 2 }, give = "Hammer", n = 1 }, |
| 113 | { want = { ["Iron ingot"] = 3 }, give = "Bucket", n = 1 }, |
| 114 | { want = { Planks = 3, ["Cream wool"] = 2 }, give = "Fishing rod", n = 1 }, |
| 115 | { want = { Planks = 3, Silk = 2 }, give = "Fishing rod", n = 1 }, |
| 116 | -- lights fires (the fire creation) |
| 117 | { want = { Flint = 1, ["Iron ingot"] = 1 }, give = "Flint and steel", n = 1 }, |
| 118 | }, |
| 119 | ["Weapons and armor"] = { |
| 120 | { want = { Planks = 2 }, give = "Wooden sword", n = 1 }, |
| 121 | { want = { Cobblestone = 2, Planks = 1 }, give = "Stone sword", n = 1 }, |
| 122 | { want = { ["Copper ingot"] = 2, Planks = 1 }, give = "Copper sword", n = 1 }, |
| 123 | -- shot and thrown (the Bows, slings and spears creation) |
| 124 | { want = { Planks = 3, ["Cream wool"] = 2 }, give = "Bow", n = 1 }, |
| 125 | -- silk strings a bow better than wool (Cave Crawlers leave it) |
| 126 | { want = { Planks = 3, Silk = 2 }, give = "Bow", n = 1 }, |
| 127 | { want = { Flint = 1, Planks = 1 }, give = "Arrow", n = 4 }, |
| 128 | { want = { Flint = 1, Planks = 1, Feather = 1 }, give = "Arrow", n = 8 }, |
| 129 | -- boar bristles fletch them as well as a feather |
| 130 | { want = { Flint = 1, Planks = 1, Bristles = 1 }, give = "Arrow", n = 8 }, |
| 131 | { want = { ["Cream wool"] = 3 }, give = "Sling", n = 1 }, |
| 132 | { want = { Flint = 1, Planks = 3 }, give = "Spear", n = 1 }, |
| 133 | { want = { Planks = 6, ["Iron ingot"] = 1 }, give = "Shield", n = 1 }, |
| 134 | -- wool and copper armor here; iron and moonsilver at an anvil |
| 135 | { want = { ["Cream wool"] = 5 }, give = "Wool cap", n = 1 }, |
| 136 | { want = { ["Cream wool"] = 8 }, give = "Wool coat", n = 1 }, |
| 137 | { want = { ["Cream wool"] = 7 }, give = "Wool leggings", n = 1 }, |
| 138 | { want = { ["Cream wool"] = 4 }, give = "Wool boots", n = 1 }, |
| 139 | -- leather from Bramble Boars |
| 140 | { want = { Leather = 5 }, give = "Leather cap", n = 1 }, |
| 141 | { want = { Leather = 8 }, give = "Leather coat", n = 1 }, |
| 142 | { want = { Leather = 7 }, give = "Leather leggings", n = 1 }, |
| 143 | { want = { Leather = 4 }, give = "Leather boots", n = 1 }, |
| 144 | { want = { ["Copper ingot"] = 5 }, give = "Copper helmet", n = 1 }, |
| 145 | { want = { ["Copper ingot"] = 8 }, give = "Copper coat", n = 1 }, |
| 146 | { want = { ["Copper ingot"] = 7 }, give = "Copper leggings", n = 1 }, |
| 147 | { want = { ["Copper ingot"] = 4 }, give = "Copper boots", n = 1 }, |
| 148 | }, |
| 149 | -- put down, a basket fills up into a hot air balloon (the balloon |
| 150 | -- creation); rails and carts are the rails creation's |
| 151 | Travel = { |
| 152 | { want = { ["Cream wool"] = 6, Planks = 4, Lantern = 1 }, give = "Balloon basket", n = 1 }, |
| 153 | { want = { ["Iron ingot"] = 6, Planks = 1 }, give = "Rail", n = 16 }, |
| 154 | { want = { ["Gold ingot"] = 6, ["Copper wire"] = 1 }, give = "Powered rail", n = 6 }, |
| 155 | { want = { ["Iron ingot"] = 5 }, give = "Cart", n = 1 }, |
| 156 | -- the Long Dusk creation's: a mirror that goes there and back |
| 157 | { want = { Glass = 4, ["Gold ingot"] = 2, Crystal = 2 }, give = "Dusk mirror", n = 1 }, |
| 158 | }, |
| 159 | -- the circuits creation's parts and machines, and storage's dispensers |
| 160 | -- and chutes |
| 161 | Circuits = { |
| 162 | { want = { ["Copper ingot"] = 1 }, give = "Copper wire", n = 8 }, |
| 163 | { want = { Cobblestone = 1, Planks = 1 }, give = "Lever", n = 1 }, |
| 164 | { want = { Stone = 1 }, give = "Button", n = 1 }, |
| 165 | { want = { Planks = 2 }, give = "Pressure plate", n = 1 }, |
| 166 | { want = { Glass = 1, Crystal = 1, Planks = 2 }, give = "Daylight sensor", n = 1 }, |
| 167 | { want = { ["Copper wire"] = 1, Torch = 1, Stone = 1 }, give = "Inverter", n = 1 }, |
| 168 | { want = { ["Copper wire"] = 1, Torch = 2, Stone = 2 }, give = "Delay", n = 1 }, |
| 169 | { want = { ["Copper ingot"] = 1, Glass = 1, Coal = 1 }, give = "Copper lamp", n = 1 }, |
| 170 | { want = { Planks = 3, Cobblestone = 4, ["Iron ingot"] = 1, ["Copper wire"] = 1 }, give = "Piston", n = 1 }, |
| 171 | { want = { Planks = 3, Cobblestone = 4, ["Iron ingot"] = 1, ["Copper wire"] = 1 }, give = "Up piston", n = 1 }, |
| 172 | { want = { Planks = 8, ["Copper wire"] = 1 }, give = "Note block", n = 1 }, |
| 173 | { want = { Cobblestone = 7, ["Copper wire"] = 1 }, give = "Dispenser", n = 1 }, |
| 174 | { want = { ["Iron ingot"] = 5, Crate = 1 }, give = "Chute", n = 1 }, |
| 175 | { want = { ["Copper wire"] = 2, ["Copper ingot"] = 1 }, give = "Grid tap", n = 1 }, |
| 176 | -- the power creation's generators, cable, lamps and meter |
| 177 | { want = { ["Copper ingot"] = 2, Planks = 1 }, give = "Power cable", n = 6 }, |
| 178 | { want = { Stone = 8, ["Copper ingot"] = 6 }, give = "Pity generator", n = 1 }, |
| 179 | { want = { ["Iron ingot"] = 1, Glass = 1, Torch = 1 }, give = "Street lamp", n = 1 }, |
| 180 | { want = { ["Copper ingot"] = 2, Glass = 1, ["Iron ingot"] = 1 }, give = "Power meter", n = 1 }, |
| 181 | { want = { Stone = 12, ["Copper ingot"] = 10, ["Iron ingot"] = 2 }, give = "Basic generator", n = 1 }, |
| 182 | { want = { Stone = 16, ["Copper ingot"] = 12, ["Iron ingot"] = 8, Glass = 2 }, give = "Intermediate generator", n = 1 }, |
| 183 | { want = { Stone = 24, ["Copper ingot"] = 12, ["Iron ingot"] = 16, Glass = 4, Crystal = 1 }, give = "Superior generator", n = 1 }, |
| 184 | { want = { Stone = 2, ["Iron ingot"] = 1 }, give = "Chimney", n = 2 }, |
| 185 | { want = { ["Copper ingot"] = 4, ["Iron ingot"] = 2, Coal = 2 }, give = "Battery", n = 1 }, |
| 186 | { want = { ["Iron ingot"] = 2, ["Copper ingot"] = 1 }, give = "Breaker", n = 1 }, |
| 187 | { want = { ["Iron ingot"] = 1, Glass = 2, ["Copper ingot"] = 1 }, give = "Solar panel", n = 1 }, |
| 188 | { want = { ["Iron ingot"] = 2, ["Copper ingot"] = 2, Glass = 1 }, give = "Tracker mast", n = 1 }, |
| 189 | { want = { ["Iron ingot"] = 1, Glass = 1, Torch = 1 }, give = "Wall lantern", n = 2 }, |
| 190 | { want = { ["Iron ingot"] = 2, Glass = 2, ["Copper ingot"] = 1, Torch = 2 }, give = "Floodlight", n = 1 }, |
| 191 | { want = { Glass = 2, ["Copper ingot"] = 1, ["Red dye"] = 1 }, give = "Red neon tube", n = 2 }, |
| 192 | { want = { Glass = 2, ["Copper ingot"] = 1, ["Green dye"] = 1 }, give = "Green neon tube", n = 2 }, |
| 193 | { want = { Glass = 2, ["Copper ingot"] = 1, ["Blue dye"] = 1 }, give = "Blue neon tube", n = 2 }, |
| 194 | { want = { Glass = 2, ["Copper ingot"] = 2, ["Pink dye"] = 1 }, give = "Grow lamp", n = 1 }, |
| 195 | { want = { ["Iron ingot"] = 3, ["Copper ingot"] = 2, Stone = 4 }, give = "Heater", n = 1 }, |
| 196 | { want = { Stone = 8, ["Iron ingot"] = 2, ["Copper ingot"] = 4 }, give = "Electric furnace", n = 1 }, |
| 197 | { want = { ["Iron ingot"] = 12, ["Copper ingot"] = 8, Glass = 6, Crystal = 2 }, give = "Beacon tower", n = 1 }, |
| 198 | { want = { Stone = 16, ["Iron ingot"] = 8, ["Copper ingot"] = 6 }, give = "Rock crusher", n = 1 }, |
| 199 | { want = { Stone = 16, ["Iron ingot"] = 12, ["Copper ingot"] = 10, Crystal = 1 }, give = "Arc furnace", n = 1 }, |
| 200 | { want = { ["Iron ingot"] = 3, ["Copper ingot"] = 1, Planks = 4 }, give = "Powered door", n = 1 }, |
| 201 | { want = { ["Iron ingot"] = 4, ["Copper ingot"] = 3, Stone = 2 }, give = "Lift pad", n = 2 }, |
| 202 | { want = { ["Iron ingot"] = 4, ["Copper ingot"] = 2, Stone = 4, Glass = 2 }, give = "Pump", n = 1 }, |
| 203 | { want = { ["Iron ingot"] = 24, ["Copper ingot"] = 12, Crystal = 2 }, give = "Quarry drill", n = 1 }, |
| 204 | { want = { Glass = 24, ["Iron ingot"] = 6, ["Copper ingot"] = 8, Crystal = 2 }, give = "Greenhouse array", n = 1 }, |
| 205 | { want = { ["Copper ingot"] = 8, Crystal = 6, Glass = 4 }, give = "Teleport pad", n = 2 }, |
| 206 | { want = { ["Iron ingot"] = 2, ["Copper ingot"] = 1, Glass = 3 }, give = "Sprinkler", n = 1 }, |
| 207 | }, |
| 208 | } |
| 209 | |
| 210 | -- Blocks that cut into stairs and slabs, with the word their shapes are |
| 211 | -- named by, and whether they make walls too (stone does, wood doesn't). |
| 212 | -- Six make four stairs, three make six slabs, six make six walls, and two |
| 213 | -- slabs make the block again. They're with Building, but only those of |
| 214 | -- blocks you carry are listed, since there are so many. |
| 215 | local CUTS: { { string } } = { |
| 216 | { "Stone", "Stone", "wall" }, { "Cobblestone", "Cobblestone", "wall" }, { "Mossy brick", "Mossy brick", "wall" }, |
| 217 | { "Sandstone", "Sandstone", "wall" }, { "Sandstone bricks", "Sandstone brick", "wall" }, { "Slate", "Slate", "wall" }, |
| 218 | { "Stone bricks", "Stone brick", "wall" }, { "Smooth stone", "Smooth stone", "wall" }, { "Granite", "Granite", "wall" }, |
| 219 | { "Polished granite", "Polished granite", "wall" }, { "Marble", "Marble", "wall" }, { "Marble bricks", "Marble brick", "wall" }, |
| 220 | { "Basalt", "Basalt", "wall" }, { "Polished basalt", "Polished basalt", "wall" }, { "Red sandstone", "Red sandstone", "wall" }, |
| 221 | { "Planks", "Oak" }, { "Birch planks", "Birch" }, { "Pine planks", "Pine" }, { "Maple planks", "Maple" }, |
| 222 | { "Willow planks", "Willow" }, { "Palm planks", "Palm" }, { "Redwood planks", "Redwood" }, |
| 223 | { "Mahogany planks", "Mahogany" }, { "Cypress planks", "Cypress" }, { "Plum planks", "Plum" }, |
| 224 | { "Hay", "Hay" }, { "Terracotta", "Terracotta" }, |
| 225 | { "Mud bricks", "Mud brick", "wall" }, { "Slate bricks", "Slate brick", "wall" }, { "Polished slate", "Polished slate", "wall" }, |
| 226 | { "Smooth sandstone", "Smooth sandstone", "wall" }, { "Basalt bricks", "Basalt brick", "wall" }, |
| 227 | { "Snow bricks", "Snow brick", "wall" }, { "Mossy cobblestone", "Mossy cobblestone", "wall" }, |
| 228 | { "Duskstone", "Duskstone", "wall" }, { "Duskstone bricks", "Duskstone brick", "wall" }, { "Duskwood planks", "Duskwood" }, |
| 229 | } |
| 230 | |
| 231 | -- Dressed stone: four of a rock make four of its bricks or its polished |
| 232 | -- face, listed for those carrying the rock. Mud bricks take a little hay to |
| 233 | -- bind them, and cobblestone grows mossy with vines or hanging moss. |
| 234 | for _, d in { |
| 235 | { "Stone", "Stone bricks" }, { "Stone", "Smooth stone" }, { "Sandstone", "Sandstone bricks" }, |
| 236 | { "Sandstone", "Smooth sandstone" }, { "Granite", "Polished granite" }, { "Marble", "Marble bricks" }, |
| 237 | { "Basalt", "Polished basalt" }, { "Basalt", "Basalt bricks" }, { "Slate", "Slate bricks" }, |
| 238 | { "Slate", "Polished slate" }, { "Snow", "Snow bricks" }, { "Red sand", "Red sandstone" }, |
| 239 | { "Duskstone", "Duskstone bricks" }, |
| 240 | } do |
| 241 | table.insert(RECIPES.Building, { want = { [d[1]] = 4 }, give = d[2], n = 4, shown = d[1] }) |
| 242 | end |
| 243 | table.insert(RECIPES.Building, { want = { Mud = 4, Hay = 1 }, give = "Mud bricks", n = 4, shown = "Mud" }) |
| 244 | table.insert(RECIPES.Building, { want = { Cobblestone = 4, Vines = 1 }, give = "Mossy cobblestone", n = 4, shown = "Vines" }) |
| 245 | table.insert(RECIPES.Building, { want = { Cobblestone = 4, ["Hanging moss"] = 1 }, give = "Mossy cobblestone", n = 4, shown = "Hanging moss" }) |
| 246 | for _, c in CUTS do |
| 247 | local block, stem = c[1], c[2] |
| 248 | local building = RECIPES.Building |
| 249 | table.insert(building, { want = { [block] = 6 }, give = stem .. " stairs", n = 4, cut = true }) |
| 250 | table.insert(building, { want = { [block] = 3 }, give = stem .. " slab", n = 6, cut = true }) |
| 251 | if c[3] then |
| 252 | table.insert(building, { want = { [block] = 6 }, give = stem .. " wall", n = 6, cut = true }) |
| 253 | end |
| 254 | table.insert(building, { want = { [stem .. " slab"] = 2 }, give = block, n = 1, cut = true }) |
| 255 | end |
| 256 | |
| 257 | -- Every wood's door and trapdoor, from its own planks, listed for those |
| 258 | -- carrying them: doors open and shut with Interact, and villagers open |
| 259 | -- them as they go in and out. |
| 260 | local HOME = RECIPES["Home and lights"] |
| 261 | for _, w in { { "Planks", "Oak" }, { "Birch planks", "Birch" }, { "Pine planks", "Pine" }, { "Maple planks", "Maple" }, { "Willow planks", "Willow" }, { "Palm planks", "Palm" }, { "Redwood planks", "Redwood" }, |
| 262 | { "Mahogany planks", "Mahogany" }, { "Cypress planks", "Cypress" }, { "Plum planks", "Plum" }, |
| 263 | { "Duskwood planks", "Duskwood" } } do |
| 264 | table.insert(HOME, { want = { [w[1]] = 6 }, give = w[2] .. " door", n = 3, cut = true }) |
| 265 | table.insert(HOME, { want = { [w[1]] = 6 }, give = w[2] .. " trapdoor", n = 2, cut = true }) |
| 266 | end |
| 267 | |
| 268 | -- Every wood's fence and fence gate, from its own planks (oak's are plain |
| 269 | -- Fence and Fence gate). Gates open and shut with Interact, and swing |
| 270 | -- away from whoever put them down; nothing steps up over either. |
| 271 | local GARDEN = RECIPES["Garden and farm"] |
| 272 | for _, w in { { "Planks", "" }, { "Birch planks", "Birch " }, { "Pine planks", "Pine " }, { "Maple planks", "Maple " }, { "Willow planks", "Willow " }, { "Palm planks", "Palm " }, { "Redwood planks", "Redwood " }, |
| 273 | { "Mahogany planks", "Mahogany " }, { "Cypress planks", "Cypress " }, { "Plum planks", "Plum " }, |
| 274 | { "Duskwood planks", "Duskwood " } } do |
| 275 | local fence = if w[2] == "" then "Fence" else w[2] .. "fence" |
| 276 | local gate = if w[2] == "" then "Fence gate" else w[2] .. "fence gate" |
| 277 | table.insert(GARDEN, { want = { [w[1]] = 3 }, give = fence, n = 2, cut = true }) |
| 278 | table.insert(GARDEN, { want = { [w[1]] = 4 }, give = gate, n = 1, cut = true }) |
| 279 | end |
| 280 | |
| 281 | -- Ladders climb (move or jump to go up, crouch to hold on), panes and bars |
| 282 | -- join up into a window or a grille |
| 283 | table.insert(HOME, { want = { Planks = 3 }, give = "Ladder", n = 3 }) |
| 284 | -- Signs to write on, and things to hold things: a pot for a plant, a frame |
| 285 | -- and a shelf for anything carried |
| 286 | table.insert(HOME, { want = { Planks = 6 }, give = "Sign", n = 3 }) |
| 287 | table.insert(HOME, { want = { Terracotta = 1 }, give = "Flower pot", n = 1 }) |
| 288 | table.insert(HOME, { want = { Planks = 4, Leather = 1 }, give = "Item frame", n = 1 }) |
| 289 | table.insert(HOME, { want = { Planks = 4 }, give = "Shelf", n = 2 }) |
| 290 | table.insert(RECIPES.Building, { want = { Glass = 3 }, give = "Glass pane", n = 8 }) |
| 291 | table.insert(RECIPES.Building, { want = { ["Iron ingot"] = 3 }, give = "Iron bars", n = 8 }) |
| 292 | |
| 293 | -- A bed in each color of wool, from three of it and any planks, listed |
| 294 | -- for those carrying that wool. Sleeping in one at night (once everyone |
| 295 | -- does) brings the morning, and you wake there. |
| 296 | local COLORS = { |
| 297 | "White", "Light gray", "Gray", "Black", "Brown", "Red", "Orange", "Yellow", |
| 298 | "Lime", "Green", "Cyan", "Light blue", "Blue", "Purple", "Magenta", "Pink", |
| 299 | } |
| 300 | for _, color in COLORS do |
| 301 | local wool = if color == "White" then "Cream wool" else color .. " wool" |
| 302 | table.insert(HOME, { want = { [wool] = 3, Planks = 3 }, give = color .. " bed", n = 1, shown = wool }) |
| 303 | end |
| 304 | |
| 305 | -- Dyes, crushed from flowers and the like or mixed from other dyes, and |
| 306 | -- what they color: wool, plaster (sand and gravel) and rugs (from wool). |
| 307 | -- Each is listed only for those carrying what it's made from, so the lists |
| 308 | -- stay short. |
| 309 | local BUILDING = RECIPES.Building |
| 310 | local function wool_of(color: string): string |
| 311 | return if color == "White" then "Cream wool" else color .. " wool" |
| 312 | end |
| 313 | for _, d in { |
| 314 | { "White flower", "White" }, { "Brown mushroom", "Brown" }, { "Red flower", "Red" }, { "Red mushroom", "Red" }, |
| 315 | { "Orange flower", "Orange" }, { "Yellow flower", "Yellow" }, { "Clover", "Lime" }, { "Cactus", "Green" }, |
| 316 | { "Fern", "Green" }, { "Blue flower", "Blue" }, { "Violet flower", "Purple" }, { "Lavender", "Purple" }, |
| 317 | { "Heather", "Magenta" }, { "Pink flower", "Pink" }, { "Coal", "Black" }, { "Charcoal", "Black" }, |
| 318 | { "Orchid", "Magenta" }, { "Bluebells", "Light blue" }, { "Fallen petals", "Pink" }, { "Pink coral branch", "Pink" }, |
| 319 | { "Orange coral branch", "Orange" }, { "Purple coral branch", "Purple" }, { "Yellow coral branch", "Yellow" }, |
| 320 | } do |
| 321 | table.insert(BUILDING, { want = { [d[1]] = 1 }, give = d[2] .. " dye", n = 2, shown = d[1] }) |
| 322 | end |
| 323 | for _, mix in { |
| 324 | { "Black", "White", "Gray" }, { "Gray", "White", "Light gray" }, { "Red", "Yellow", "Orange" }, { "Green", "White", "Lime" }, |
| 325 | { "Blue", "Green", "Cyan" }, { "Blue", "White", "Light blue" }, { "Red", "Blue", "Purple" }, { "Purple", "Pink", "Magenta" }, |
| 326 | { "Red", "White", "Pink" }, |
| 327 | } do |
| 328 | table.insert(BUILDING, { want = { [mix[1] .. " dye"] = 1, [mix[2] .. " dye"] = 1 }, give = mix[3] .. " dye", n = 2, shown = mix[1] .. " dye" }) |
| 329 | end |
| 330 | for _, color in COLORS do |
| 331 | local dye = color .. " dye" |
| 332 | if color ~= "White" then |
| 333 | table.insert(BUILDING, { want = { ["Cream wool"] = 1, [dye] = 1 }, give = color .. " wool", n = 1, shown = dye }) |
| 334 | end |
| 335 | table.insert(BUILDING, { want = { Sand = 4, Gravel = 4, [dye] = 1 }, give = color .. " plaster", n = 8, shown = dye }) |
| 336 | table.insert(HOME, { want = { [wool_of(color)] = 2 }, give = color .. " rug", n = 3, shown = wool_of(color) }) |
| 337 | -- stained glass, glazed tiles (terracotta fired with a glaze) and |
| 338 | -- candles in every color |
| 339 | table.insert(BUILDING, { want = { Glass = 8, [dye] = 1 }, give = color .. " stained glass", n = 8, shown = dye }) |
| 340 | table.insert(BUILDING, { want = { ["Glass pane"] = 8, [dye] = 1 }, give = color .. " stained glass pane", n = 8, shown = dye }) |
| 341 | table.insert(BUILDING, { want = { [color .. " stained glass"] = 3 }, give = color .. " stained glass pane", n = 8, shown = color .. " stained glass" }) |
| 342 | -- concrete (cobblestone and sand set hard) and terracotta fired in a color |
| 343 | table.insert(BUILDING, { want = { Cobblestone = 4, Sand = 4, [dye] = 1 }, give = color .. " concrete", n = 8, shown = dye }) |
| 344 | table.insert(BUILDING, { want = { Terracotta = 8, [dye] = 1 }, give = color .. " terracotta", n = 8, shown = dye }) |
| 345 | table.insert(HOME, { want = { [wool_of(color)] = 6, Planks = 1 }, give = color .. " banner", n = 1, shown = wool_of(color) }) |
| 346 | table.insert(BUILDING, { want = { Terracotta = 4, [dye] = 1 }, give = color .. " glazed tile", n = 4, shown = dye }) |
| 347 | table.insert(HOME, { want = { Candle = 2, [dye] = 1 }, give = color .. " candle", n = 2, shown = dye }) |
| 348 | end |
| 349 | |
| 350 | -- Where things other creations make go on the bench, by their kind. |
| 351 | local MADE_KINDS: { [string]: string } = { |
| 352 | material = "Building", |
| 353 | food = "Garden and farm", |
| 354 | tool = "Tools", |
| 355 | weapon = "Weapons and armor", |
| 356 | armor = "Weapons and armor", |
| 357 | } |
| 358 | |
| 359 | -- What hands can make without a table: planks and the table itself, wooden |
| 360 | -- tools and torches, the first things to find your feet with. |
| 361 | local HAND: { [string]: boolean } = { |
| 362 | Planks = true, Table = true, Chest = true, Stool = true, Torch = true, Candle = true, Fence = true, Ladder = true, |
| 363 | ["Wooden pickaxe"] = true, ["Wooden axe"] = true, ["Wooden shovel"] = true, ["Wooden sword"] = true, |
| 364 | ["Stone pickaxe"] = true, ["Stone sword"] = true, Lever = true, Button = true, ["Pressure plate"] = true, |
| 365 | } |
| 366 | -- and every dye, crushed or mixed in the hand |
| 367 | for _, color in COLORS do |
| 368 | HAND[color .. " dye"] = true |
| 369 | end |
| 370 | |
| 371 | local READY = "Ready now" |
| 372 | |
| 373 | -- What one question has looked up already, so a long list stays quick: |
| 374 | -- each kind's recipes, which names are blocks or items here, and what each |
| 375 | -- player carries (world.pockets). `fresh` forgets it all before the next. |
| 376 | local lists: { [string]: { Recipe } } = {} |
| 377 | local known: { [string]: boolean } = {} |
| 378 | local carrying: { [number]: { [string]: number } } = {} |
| 379 | local function fresh(player) |
| 380 | table.clear(lists) |
| 381 | table.clear(known) |
| 382 | table.clear(carrying) |
| 383 | carrying[player.id] = world.pockets(player) |
| 384 | end |
| 385 | |
| 386 | -- the recipes of things other creations make, by kind: read once a tick, |
| 387 | -- since a bench asks for every kind's at once and there can be a lot of items |
| 388 | local made_at, made_list = -1, {} :: { [string]: { Recipe } } |
| 389 | local function made(): { [string]: { Recipe } } |
| 390 | local now = world.time() |
| 391 | if now ~= made_at then |
| 392 | made_at, made_list = now, {} |
| 393 | for _, name in world.items() do |
| 394 | local it = world.item(name) |
| 395 | -- boats go with the travel |
| 396 | local kind = if it and it.recipe then (if string.find(name, " boat$") then "Travel" else MADE_KINDS[it.kind or "material"]) else nil |
| 397 | if it and kind then |
| 398 | local list = made_list[kind] or {} |
| 399 | made_list[kind] = list |
| 400 | table.insert(list, { want = it.recipe, give = name, n = it.makes or 1 }) |
| 401 | end |
| 402 | end |
| 403 | end |
| 404 | return made_list |
| 405 | end |
| 406 | |
| 407 | -- a kind's recipes: RECIPES' and those of things other creations make |
| 408 | local function all(kind: string): { Recipe } |
| 409 | if lists[kind] then |
| 410 | return lists[kind] |
| 411 | end |
| 412 | local list = table.clone(RECIPES[kind] or {}) |
| 413 | for _, r in made()[kind] or {} do |
| 414 | table.insert(list, r) |
| 415 | end |
| 416 | lists[kind] = list |
| 417 | return list |
| 418 | end |
| 419 | |
| 420 | local function makes(r: Recipe): number |
| 421 | return math.floor(r.n * knobs.generous) |
| 422 | end |
| 423 | |
| 424 | -- Whether a block is in this world: some come from other creations (the |
| 425 | -- kiln and paper lanterns from Brickworks). |
| 426 | local function exists(name: string): boolean |
| 427 | local k = known[name] |
| 428 | if k == nil then |
| 429 | k = (pcall(world.kind, name)) |
| 430 | known[name] = k |
| 431 | end |
| 432 | return k |
| 433 | end |
| 434 | |
| 435 | -- Things any of several will do for: a recipe that takes Planks takes any |
| 436 | -- wood's planks, oak's first. Cuts take exactly what they're cut from. |
| 437 | local ANY: { [string]: { string } } = { |
| 438 | Planks = { |
| 439 | "Planks", "Birch planks", "Pine planks", "Maple planks", "Willow planks", "Palm planks", "Redwood planks", |
| 440 | "Mahogany planks", "Cypress planks", "Plum planks", "Duskwood planks", |
| 441 | }, |
| 442 | } |
| 443 | |
| 444 | local function each(name: string, exact: boolean?): { string } |
| 445 | return if exact then { name } else ANY[name] or { name } |
| 446 | end |
| 447 | |
| 448 | -- how many of a thing the player carries (any planks for Planks) |
| 449 | local function count(player, name: string, exact: boolean?): number |
| 450 | local have = carrying[player.id] |
| 451 | local n = 0 |
| 452 | for _, one in each(name, exact) do |
| 453 | if have then |
| 454 | n += have[one] or 0 |
| 455 | elseif exists(one) then |
| 456 | n += world.has(player, one) |
| 457 | end |
| 458 | end |
| 459 | return n |
| 460 | end |
| 461 | |
| 462 | -- takes `n` of a thing (any planks for Planks), saying what it took |
| 463 | local function take(player, name: string, n: number, exact: boolean?, took: { [string]: number }) |
| 464 | for _, one in each(name, exact) do |
| 465 | if n <= 0 then |
| 466 | break |
| 467 | end |
| 468 | local have = if exists(one) then world.has(player, one) else 0 |
| 469 | local k = math.min(have, n) |
| 470 | if k > 0 then |
| 471 | world.take(player, one, k) |
| 472 | took[one] = (took[one] or 0) + k |
| 473 | n -= k |
| 474 | end |
| 475 | end |
| 476 | end |
| 477 | |
| 478 | -- whether the player has everything a recipe takes |
| 479 | local function can(player, r: Recipe): boolean |
| 480 | for block, n in r.want do |
| 481 | if count(player, block, r.cut) < n then |
| 482 | return false |
| 483 | end |
| 484 | end |
| 485 | return true |
| 486 | end |
| 487 | |
| 488 | -- what they're short of: "2 more Iron ingot" |
| 489 | local function short(player, r: Recipe): string |
| 490 | local parts = {} |
| 491 | for block, n in r.want do |
| 492 | local have = count(player, block, r.cut) |
| 493 | if have < n then |
| 494 | table.insert(parts, (n - have) .. " more " .. block) |
| 495 | end |
| 496 | end |
| 497 | table.sort(parts) |
| 498 | return table.concat(parts, " and ") |
| 499 | end |
| 500 | |
| 501 | -- what it takes: "1 Glass and 2 Cobblestone" |
| 502 | local function needs(r: Recipe): string |
| 503 | local parts = {} |
| 504 | for block, n in r.want do |
| 505 | table.insert(parts, n .. " " .. block) |
| 506 | end |
| 507 | table.sort(parts) |
| 508 | return table.concat(parts, " and ") |
| 509 | end |
| 510 | |
| 511 | -- "4 Planks for 1 Oak log", or just "1 Lantern" when that's too long for a |
| 512 | -- choice (30 letters), with what it takes said in the question instead |
| 513 | local function label(r: Recipe): (string, string?) |
| 514 | local full = makes(r) .. " " .. r.give .. " for " .. needs(r) |
| 515 | if #full <= 30 then |
| 516 | return full, nil |
| 517 | end |
| 518 | return makes(r) .. " " .. r.give, makes(r) .. " " .. r.give .. " takes " .. needs(r) .. "." |
| 519 | end |
| 520 | |
| 521 | -- Makes one, or says why not. |
| 522 | local function craft(player, r: Recipe): string |
| 523 | carrying[player.id] = nil |
| 524 | table.clear(known) |
| 525 | if not can(player, r) then |
| 526 | return "You'll need " .. needs(r) .. " for that." |
| 527 | end |
| 528 | local took = {} |
| 529 | for block, n in r.want do |
| 530 | take(player, block, n, r.cut, took) |
| 531 | end |
| 532 | local given = world.give(player, r.give, makes(r)) |
| 533 | if given == 0 then |
| 534 | -- no room: give it all back |
| 535 | for block, n in took do |
| 536 | world.give(player, block, n) |
| 537 | end |
| 538 | return "Your hotbar is full. Make some room first." |
| 539 | end |
| 540 | return "Made " .. given .. " " .. r.give .. "." |
| 541 | end |
| 542 | |
| 543 | local choose |
| 544 | |
| 545 | -- One page of a long list: what's on it, which page it is and how many |
| 546 | -- there are. Eight fit on one; past that, seven to a page and More. |
| 547 | local PAGE = 7 |
| 548 | local function page_of<T>(list: { T }, page: number): ({ T }, number, number) |
| 549 | if #list <= 8 then |
| 550 | return list, 1, 1 |
| 551 | end |
| 552 | local pages = math.ceil(#list / PAGE) |
| 553 | page = (page - 1) % pages + 1 |
| 554 | return table.move(list, (page - 1) * PAGE + 1, math.min(page * PAGE, #list), 1, {}), page, pages |
| 555 | end |
| 556 | |
| 557 | -- whether the player carries some of what a cut takes: there are a lot of |
| 558 | -- cuts, so only those of blocks they have are listed |
| 559 | local function carries(player, r: Recipe): boolean |
| 560 | for block in r.want do |
| 561 | if count(player, block, true) == 0 then |
| 562 | return false |
| 563 | end |
| 564 | end |
| 565 | return true |
| 566 | end |
| 567 | |
| 568 | -- the recipes of one kind (or all you can make now), those you can make |
| 569 | -- first; `hand` leaves out what needs a table |
| 570 | local function listing(player, kind: string, hand: boolean): { Recipe } |
| 571 | local kinds = if kind == READY then KINDS else { kind } |
| 572 | local ready, rest = {}, {} |
| 573 | for _, k in kinds do |
| 574 | for _, r in all(k) do |
| 575 | if exists(r.give) and (not hand or HAND[r.give]) and (not r.cut or carries(player, r)) and (not r.shown or count(player, r.shown, true) > 0) then |
| 576 | if can(player, r) then |
| 577 | table.insert(ready, r) |
| 578 | elseif kind ~= READY then |
| 579 | table.insert(rest, r) |
| 580 | end |
| 581 | end |
| 582 | end |
| 583 | end |
| 584 | table.move(rest, 1, #rest, #ready + 1, ready) |
| 585 | return ready |
| 586 | end |
| 587 | |
| 588 | -- the recipes of one kind, a page of them; `said` is how the last one went |
| 589 | local function recipes(player, at: vector, kind: string, said: string?, page: number?, hand: boolean?) |
| 590 | local hand = hand == true |
| 591 | fresh(player) |
| 592 | local list = listing(player, kind, hand) |
| 593 | local shown, this, pages = page_of(list, page or 1) |
| 594 | local choices, more, lacks = {}, {}, {} |
| 595 | local ready = 0 |
| 596 | for _, r in list do |
| 597 | if can(player, r) then |
| 598 | ready += 1 |
| 599 | end |
| 600 | end |
| 601 | for _, r in shown do |
| 602 | local name, long = label(r) |
| 603 | table.insert(choices, name) |
| 604 | if long then |
| 605 | table.insert(more, long) |
| 606 | end |
| 607 | if not can(player, r) then |
| 608 | table.insert(lacks, r.give .. ": " .. short(player, r) .. ".") |
| 609 | end |
| 610 | end |
| 611 | if pages > 1 then |
| 612 | table.insert(choices, "More") |
| 613 | end |
| 614 | local text = (if said then said .. "\n\n" else "") .. "What would you like to make?" |
| 615 | if ready == 0 then |
| 616 | text ..= " You haven't what any of these take yet." |
| 617 | elseif ready < #list then |
| 618 | text ..= " The first " .. ready .. " you can make now." |
| 619 | end |
| 620 | if #more > 0 then |
| 621 | text ..= "\n\n" .. table.concat(more, "\n") |
| 622 | end |
| 623 | if #lacks > 0 then |
| 624 | text ..= "\n\nStill needed:\n" .. table.concat(lacks, "\n") |
| 625 | end |
| 626 | local title = (if hand then "By hand: " else "Workbench: ") .. kind .. (if pages > 1 then " (" .. this .. " of " .. pages .. ")" else "") |
| 627 | ui.ask(player, { title = title, text = text, choices = choices }, function(who, choice) |
| 628 | if pages > 1 and choice == #shown + 1 then |
| 629 | recipes(who, at, kind, nil, this + 1, hand) |
| 630 | return |
| 631 | end |
| 632 | local r = choice and shown[choice] |
| 633 | if not r then |
| 634 | return |
| 635 | end |
| 636 | local result = craft(who, r) |
| 637 | if string.sub(result, 1, 4) == "Made" then |
| 638 | sound.play("click", { at = at, caption = "Something's made" }) |
| 639 | end |
| 640 | -- ask again, so making several is quick |
| 641 | recipes(who, at, kind, result, this, hand) |
| 642 | end) |
| 643 | end |
| 644 | |
| 645 | function choose(player, at: vector, page: number?, hand: boolean?) |
| 646 | local hand = hand == true |
| 647 | fresh(player) |
| 648 | if world.pockets(player) == nil then |
| 649 | ui.ask(player, { |
| 650 | title = "Workbench", |
| 651 | text = "In creative you've every block and item already: press the Blocks key to pick them. In survival, use a table to make things from what you've gathered.", |
| 652 | choices = { "OK" }, |
| 653 | }, function() end) |
| 654 | return |
| 655 | end |
| 656 | -- only kinds with something to make here (circuits need their creation) |
| 657 | local kinds = {} |
| 658 | for _, kind in KINDS do |
| 659 | for _, r in all(kind) do |
| 660 | if exists(r.give) and (not hand or HAND[r.give]) then |
| 661 | table.insert(kinds, kind) |
| 662 | break |
| 663 | end |
| 664 | end |
| 665 | end |
| 666 | -- first, everything that can be made right now |
| 667 | if #listing(player, READY, hand) > 0 then |
| 668 | table.insert(kinds, 1, READY) |
| 669 | end |
| 670 | local shown, this, pages = page_of(kinds, page or 1) |
| 671 | local choices = table.clone(shown) |
| 672 | if pages > 1 then |
| 673 | table.insert(choices, "More") |
| 674 | end |
| 675 | local title = if hand then "By hand" else "Workbench" |
| 676 | local text = if hand then "Hands can make the simple things. A table makes much more." else "What would you like to make?" |
| 677 | ui.ask(player, { title = title, text = text, choices = choices }, function(who, choice) |
| 678 | if pages > 1 and choice == #shown + 1 then |
| 679 | choose(who, at, this + 1, hand) |
| 680 | return |
| 681 | end |
| 682 | local kind = choice and shown[choice] |
| 683 | if kind then |
| 684 | recipes(who, at, kind, nil, nil, hand) |
| 685 | end |
| 686 | end) |
| 687 | end |
| 688 | |
| 689 | -- Every recipe in order, told to the item guide (world.recipes), which shows |
| 690 | -- what makes and uses each thing and lets someone at a table make one with +. |
| 691 | -- A remix that adds a recipe adds it to the guide too. |
| 692 | local BOOK: { Recipe } = {} |
| 693 | for _, kind in KINDS do |
| 694 | for _, r in all(kind) do |
| 695 | table.insert(BOOK, r) |
| 696 | end |
| 697 | end |
| 698 | world.recipes("Table", BOOK) |
| 699 | |
| 700 | -- The item guide's + : Storage has brought what nearby chests hold to their |
| 701 | -- pockets by now (recipe_fetch), so this takes from the pockets as ever. |
| 702 | world.on("recipe_craft", function(player, station: string, index: number) |
| 703 | local r = BOOK[index] |
| 704 | if station ~= "Table" or r == nil then |
| 705 | return |
| 706 | end |
| 707 | local ok, result = pcall(craft, player, r) |
| 708 | local said = if ok then result else "That can't be made here." |
| 709 | ui.show(player, "made", said, { at = "left" }) |
| 710 | world.after(4, function() |
| 711 | ui.hide(player, "made") |
| 712 | end) |
| 713 | if ok and string.sub(said, 1, 4) == "Made" then |
| 714 | sound.play("click", { at = player.position, caption = "Something's made" }) |
| 715 | end |
| 716 | end) |
| 717 | |
| 718 | world.on("block_used", function(player, at: vector, block: string) |
| 719 | if block == BENCH then |
| 720 | -- the backpack's "Make things by hand" is a table used at your own |
| 721 | -- feet, where there is none |
| 722 | local feet = player.position |
| 723 | local hand = math.floor(feet.x) == math.floor(at.x) and math.floor(feet.y) == math.floor(at.y) and math.floor(feet.z) == math.floor(at.z) |
| 724 | sound.play("chop", { at = at, volume = 0.3, caption = if hand then "Hands busy" else "Workbench" }) |
| 725 | choose(player, at, nil, hand) |
| 726 | end |
| 727 | end) |
| 728 | |
| 729 | -- a word to survival players who come near a table, once each time |
| 730 | local near: { [number]: boolean } = {} |
| 731 | world.every(1, function() |
| 732 | if not knobs.hint then |
| 733 | return |
| 734 | end |
| 735 | for _, p in world.players() do |
| 736 | local close = world.pockets(p) ~= nil and world.find_block(p.position, 3, BENCH) ~= nil |
| 737 | if close and not near[p.id] then |
| 738 | ui.show(p, "bench", "Use a table to make things", { at = "left" }) |
| 739 | world.after(6, function() |
| 740 | ui.hide(p, "bench") |
| 741 | end) |
| 742 | end |
| 743 | near[p.id] = close |
| 744 | end |
| 745 | end) |
| 746 | |
| 747 | world.on("player_left", function(player) |
| 748 | near[player.id] = nil |
| 749 | end) |