Quellcode durchsuchen

Add more features to the mini game

Toby Chui vor 2 Wochen
Ursprung
Commit
c47f2be02b

+ 49 - 5
src/web/Blocky/README.md

@@ -140,7 +140,12 @@ rose, the grays) and the others are mixed from two dyes on the grid.
 Six glass make 16 panes; six iron ingots make 16 iron bars, which share the
 pane shape with a see-through bar texture. Panes and bars join each other. A pane is a thin post that grows arms toward
 neighbouring panes and solid blocks (`paneLinks` in `shapes.js`); its
-collision and selection boxes follow the arms.
+collision and selection boxes follow the arms. Iron bars link the same way but are
+modelled as solid metal (`ironBars` in `mesher.js`, tile `iron_bar_metal`):
+a 2 x 2 post on its own, and toward each linked side a half panel 2 px deep
+with rails at the top and bottom, a bar in its middle and a half bar on the
+edge that meets the neighbour's into a whole one. The flat `iron_bars` tile
+is only the item icon.
 
 ## Spark circuits
 
@@ -152,7 +157,13 @@ ticks), pressure plates, spark torches and spark blocks. A wire carries level 15
 source and loses 1 per block (`updateWires`, a relaxation over the wire
 network). A powered block powers what touches it: lamps light up, a spark
 torch on a powered block turns off (an inverter), pistons push up to 12
-blocks (sticky pistons pull one back), powered rails boost carts. Parts react
+blocks (sticky pistons pull one back), powered rails boost carts. An
+extending piston shoves the player, animals and dropped items out of the
+head and the blocks it moved (`Game.pistonPush`, called through
+`world.onPistonPush`): their box is tested against each moved box swept
+back over the cell it came from and placed just past its far face, or, with
+no room there (a wall), moved as far as collisions allow; the player also
+gets a 5 blocks/s shove. Parts react
 through scheduled ticks two game ticks later. `POWER` flags each block: 1
 wire, 2 source, 4 reacts, 8 rail. Lever and button meta is the face they are
 attached to plus bit 8 for on / pressed; a pressed button's release time is
@@ -177,7 +188,9 @@ signal one way, in the direction the player faced when placing them, after
 `B.RETIMER_ON` (lit) share meta: bits 0-1 facing (`HDIR`), bits 2-3 steps -
 1. The input is the block behind (wire, source, a powered block or another
 retimer pointing in); a lit retimer powers the block in front strongly and
-nothing at its sides. Changes on their way wait in `world.retimerDue`, so a
+nothing at its sides. Wire is drawn joining a retimer only at its back and
+front; a wire beside it neither branches into its side nor runs on into it
+(`wire` in `mesher.js`). Changes on their way wait in `world.retimerDue`, so a
 pulse shorter than the delay is stretched to it.
 
 ## Rails and carts
@@ -263,6 +276,34 @@ Settings > Realistic Graphics. `js/realistic.js` with `render.js`:
 - Turning the mode off disposes every target. It needs float render targets
   (`EXT_color_buffer_float`); without them the setting stays off.
 
+## Stairs
+
+Wooden, cobblestone, stone, stone brick, brick and sandstone stairs (six
+blocks in a staircase pattern make four). Meta bits 0-1 are the side the
+steps climb toward (away from the player who placed them), bit 2 hangs them
+upside down (placed under a block or on the upper half of a side). A stair
+joins the stairs beside it (`stairShape` in `shapes.js`): one behind it
+turned across makes an outer corner, one in front turned across an inner
+corner, unless a stair on the far side continues a straight run.
+`stairBoxes` gives the half slab and the raised step; collision, meshing
+(`stairs` in `mesher.js`, faces lit from the open cell they look into) and
+the corner logic all use it, while the selection box is the whole block.
+Stairs have light opacity 3, so a stair roof gives shade without leaving
+the stair itself dark. Torches stand on upside down stairs.
+
+Walking: the 0.6 auto-step climbs the 0.5 steps from the front (from behind
+the full height blocks you), and a player who walks off a step lands on one
+up to 0.6 lower at once instead of falling, so stairs go down without
+leaving the ground. Both move the camera smoothly (`Player.eyeSmooth`).
+
+## Swimming out
+
+Jumping against a bank in water or lava gives a stronger push once the spot
+0.6 higher and a little ahead is free of blocks and above the liquid
+(`Player.canClimbOut`), so a bank level with the water surface can be
+climbed without building a step. A bank a full block above the surface
+still cannot.
+
 ## Signs
 
 Six planks and a stick make three signs. Placed on top of a block a sign
@@ -270,9 +311,12 @@ stands on a post, turned in 16 steps to face the player (`B.SIGN`, meta =
 step); placed on a side it hangs on the wall (`B.WALL_SIGN`, meta = face).
 `mesher.js` draws the board and post as boxes turned about the block's
 vertical axis (`yawBox`, parts in `shapes.js`: `SIGN_BOARD`, `SIGN_POST`,
-`SIGN_WALL_BOARD`, `signAngle`). The text is a tile entity
+`SIGN_WALL_BOARD`, `signAngle`). The board uses its own light wood tile
+(`sign_board`, soft seams) and its broad faces are lit evenly whichever way
+the sign turns, so the writing stays readable. The text is a tile entity
 `{ type: "sign", lines: [4], ver }`; `js/signs.js` gives every sign within
-40 blocks a plane in front of its board with the lines drawn on a canvas
+40 blocks a plane in front of its board with the lines drawn on a 512 x 256
+canvas in bold dark type
 (redrawn when `ver` changes, lit like other objects). Placing a sign opens
 the Edit Sign screen (4 lines of up to 15 characters; Enter moves down, Esc
 or Done closes) and right clicking one opens it again. Breaking a sign or

+ 25 - 7
src/web/Blocky/js/blocks.js

@@ -24,7 +24,9 @@ export const B = {
     BLUE_FLOWER: 71, GLASS_PANE: 72, SPARK_ORE: 73, SPARK_WIRE: 74, SPARK_TORCH: 75, SPARK_TORCH_OFF: 76,
     LEVER: 77, BUTTON: 78, SPARK_LAMP: 79, SPARK_LAMP_ON: 80, PISTON: 81, STICKY_PISTON: 82,
     PISTON_HEAD: 83, RAIL: 84, POWERED_RAIL: 85, SPARK_BLOCK: 86, PLATE_WOOD: 87, PLATE_STONE: 88,
-    RETIMER: 89, RETIMER_ON: 90, SIGN: 91, WALL_SIGN: 92, IRON_BARS: 93
+    RETIMER: 89, RETIMER_ON: 90, SIGN: 91, WALL_SIGN: 92, IRON_BARS: 93,
+    PLANK_STAIRS: 94, COBBLE_STAIRS: 95, STONE_STAIRS: 96, STONE_BRICK_STAIRS: 97, BRICK_STAIRS: 98,
+    SANDSTONE_STAIRS: 99
 };
 
 //Wool and dye colours: key, name, colour
@@ -79,7 +81,7 @@ export const BLOCKS = [];
 export const ITEMS = [];
 
 const DEFAULTS = {
-    shape: "cube",      //cube, cross, crop, torch, slab, cactus, liquid, farmland, ladder, fire, door, fence, gate, bed, none
+    shape: "cube",      //cube, cross, crop, torch, slab, stairs, cactus, liquid, farmland, ladder, fire, door, fence, gate, bed, none
     solid: true,        //has collision
     opaque: true,       //full cube that hides neighbour faces
     lightOpacity: 15,
@@ -171,6 +173,15 @@ def(B.STONE_SLAB, "Stone Slab", { tex: { top: "slab_top", bottom: "slab_top", si
 def(B.PLANK_SLAB, "Plank Slab", { tex: "planks", shape: "slab", opaque: false, lightOpacity: 0, hardness: 2, tool: "axe", sound: "wood" });
 def(B.COBBLE_SLAB, "Cobblestone Slab", { tex: "cobblestone", shape: "slab", opaque: false, lightOpacity: 0, hardness: 2, tool: "pickaxe", tier: 1 });
 def(B.SANDSTONE_SLAB, "Sandstone Slab", { tex: { top: "sandstone_top", bottom: "sandstone_bottom", side: "sandstone_side" }, shape: "slab", opaque: false, lightOpacity: 0, hardness: 0.8, tool: "pickaxe", tier: 1 });
+//Stairs: meta bits 0-1 the side they climb toward, bit 2 upside down
+//(shapes.js). They dim light a little, so a stair roof gives shade.
+const STAIRS = { shape: "stairs", opaque: false, lightOpacity: 3, tool: "pickaxe", tier: 1 };
+def(B.PLANK_STAIRS, "Wooden Stairs", Object.assign({}, STAIRS, { tex: "planks", hardness: 2, tool: "axe", tier: 0, sound: "wood" }));
+def(B.COBBLE_STAIRS, "Cobblestone Stairs", Object.assign({}, STAIRS, { tex: "cobblestone", hardness: 2 }));
+def(B.STONE_STAIRS, "Stone Stairs", Object.assign({}, STAIRS, { tex: "stone", hardness: 1.5 }));
+def(B.STONE_BRICK_STAIRS, "Stone Brick Stairs", Object.assign({}, STAIRS, { tex: "stone_bricks", hardness: 1.5 }));
+def(B.BRICK_STAIRS, "Brick Stairs", Object.assign({}, STAIRS, { tex: "bricks", hardness: 2 }));
+def(B.SANDSTONE_STAIRS, "Sandstone Stairs", Object.assign({}, STAIRS, { tex: { top: "sandstone_top", bottom: "sandstone_bottom", side: "sandstone_side" }, hardness: 0.8 }));
 def(B.IRON_BLOCK, "Block of Iron", { tex: "iron_block", hardness: 5, tool: "pickaxe", tier: 2, sound: "metal" });
 def(B.GOLD_BLOCK, "Block of Gold", { tex: "gold_block", hardness: 3, tool: "pickaxe", tier: 3, sound: "metal" });
 def(B.CRYSTAL_BLOCK, "Block of Crystal", { tex: "crystal_block", hardness: 5, tool: "pickaxe", tier: 3, sound: "metal" });
@@ -181,11 +192,12 @@ WOOL_COLORS.forEach(([key, name], i) => {
 });
 def(B.BLUE_FLOWER, "Blue Flower", Object.assign({}, NONSOLID_PLANT, { tex: "blue_flower", replaceable: true }));
 def(B.GLASS_PANE, "Glass Pane", { tex: "glass", shape: "pane", opaque: false, lightOpacity: 0, hardness: 0.3, sound: "glass", cutout: true, drops: () => [] });
-def(B.IRON_BARS, "Iron Bars", { tex: "iron_bars", shape: "pane", opaque: false, lightOpacity: 0, hardness: 5, tool: "pickaxe", tier: 1, sound: "metal", cutout: true });
+//Iron bars link like panes but are modelled as solid bars (ironBars in mesher.js)
+def(B.IRON_BARS, "Iron Bars", { tex: "iron_bar_metal", shape: "pane", opaque: false, lightOpacity: 0, hardness: 5, tool: "pickaxe", tier: 1, sound: "metal" });
 //Signs: a standing sign turns in 16 steps (meta), a wall sign hangs on the
 //face given by meta; the text lives in a tile entity (signs.js)
-def(B.SIGN, "Sign", { tex: "planks", shape: "sign", solid: false, opaque: false, lightOpacity: 0, hardness: 1, tool: "axe", sound: "wood", support: "solid", interact: "sign" });
-def(B.WALL_SIGN, "Sign", { tex: "planks", shape: "sign", solid: false, opaque: false, lightOpacity: 0, hardness: 1, tool: "axe", sound: "wood", support: "wall", interact: "sign", noItem: true, drops: () => [[B.SIGN, 1]] });
+def(B.SIGN, "Sign", { tex: "sign_board", shape: "sign", solid: false, opaque: false, lightOpacity: 0, hardness: 1, tool: "axe", sound: "wood", support: "solid", interact: "sign" });
+def(B.WALL_SIGN, "Sign", { tex: "sign_board", shape: "sign", solid: false, opaque: false, lightOpacity: 0, hardness: 1, tool: "axe", sound: "wood", support: "wall", interact: "sign", noItem: true, drops: () => [[B.SIGN, 1]] });
 
 //The spark (signal) system
 def(B.SPARK_ORE, "Spark Ore", { tex: "spark_ore", hardness: 3, tool: "pickaxe", tier: 3, drops: (m, rng) => [[I.SPARK_DUST, 4 + Math.floor(rng() * 2)]] });
@@ -249,7 +261,7 @@ for (let i = 0; i < 256; i++) {
 export const FLAME_CATCH = new Uint8Array(256);
 export const FLAME_BURN = new Uint8Array(256);
 for (const [id, c, b] of [
-    [B.PLANKS, 5, 20], [B.PLANK_SLAB, 5, 20], [B.PLATE_WOOD, 5, 20], [B.SIGN, 5, 20], [B.WALL_SIGN, 5, 20], [B.LOG, 5, 5], [B.LEAVES, 30, 60], [B.WORKBENCH, 5, 20],
+    [B.PLANKS, 5, 20], [B.PLANK_SLAB, 5, 20], [B.PLANK_STAIRS, 5, 20], [B.PLATE_WOOD, 5, 20], [B.SIGN, 5, 20], [B.WALL_SIGN, 5, 20], [B.LOG, 5, 5], [B.LEAVES, 30, 60], [B.WORKBENCH, 5, 20],
     [B.CHEST, 5, 20], [B.FENCE, 5, 20], [B.FENCE_GATE, 5, 20], [B.DOOR, 5, 20], [B.BED, 5, 20],
     [B.LADDER, 5, 20], [B.TALL_GRASS, 60, 100], [B.FLOWER_YELLOW, 60, 100], [B.FLOWER_RED, 60, 100],
     [B.DEAD_BUSH, 60, 100], [B.SAPLING, 60, 100], [B.WHEAT, 60, 100], [B.WOOL, 30, 60],
@@ -423,6 +435,7 @@ item(I.FURNACE_MINECART, "Furnace Minecart", { icon: { flat: "furnace_minecart"
 ITEMS[B.LOG].fuel = 300;
 ITEMS[B.PLANKS].fuel = 300;
 ITEMS[B.PLANK_SLAB].fuel = 150;
+ITEMS[B.PLANK_STAIRS].fuel = 300;
 ITEMS[B.SAPLING].fuel = 100;
 ITEMS[B.WORKBENCH].fuel = 300;
 ITEMS[B.CHEST].fuel = 300;
@@ -654,6 +667,10 @@ shaped(B.STONE_SLAB, 6, ["MMM"], { M: B.STONE });
 shaped(B.PLANK_SLAB, 6, ["MMM"], { M: B.PLANKS });
 shaped(B.COBBLE_SLAB, 6, ["MMM"], { M: B.COBBLE });
 shaped(B.SANDSTONE_SLAB, 6, ["MMM"], { M: B.SANDSTONE });
+for (const [stairs, material] of [[B.PLANK_STAIRS, B.PLANKS], [B.COBBLE_STAIRS, B.COBBLE], [B.STONE_STAIRS, B.STONE],
+    [B.STONE_BRICK_STAIRS, B.STONE_BRICKS], [B.BRICK_STAIRS, B.BRICKS], [B.SANDSTONE_STAIRS, B.SANDSTONE]]) {
+    shaped(stairs, 4, ["M..", "MM.", "MMM"], { M: material });
+}
 shaped(B.LAMP, 1, [".G.", "GTG", ".G."], { G: B.GLASS, T: B.TORCH });
 shaped(I.DOOR, 3, ["PP", "PP", "PP"], { P: B.PLANKS });
 shaped(B.FENCE, 3, ["PSP", "PSP"], { P: B.PLANKS, S: I.STICK });
@@ -762,7 +779,8 @@ export function fuelTicks(id) {
 export function creativeGroups() {
     const building = [B.STONE, B.COBBLE, B.MOSSY_COBBLE, B.STONE_BRICKS, B.BRICKS, B.DIRT, B.GRASS, B.SAND, B.SANDSTONE,
         B.GRAVEL, B.CLAY, B.LOG, B.PLANKS, B.LEAVES, B.GLASS, B.LAMP, B.STONE_SLAB, B.PLANK_SLAB,
-        B.COBBLE_SLAB, B.SANDSTONE_SLAB, B.IRON_BLOCK, B.GOLD_BLOCK, B.CRYSTAL_BLOCK, B.COAL_ORE, B.IRON_ORE,
+        B.COBBLE_SLAB, B.SANDSTONE_SLAB, B.PLANK_STAIRS, B.COBBLE_STAIRS, B.STONE_STAIRS, B.STONE_BRICK_STAIRS,
+        B.BRICK_STAIRS, B.SANDSTONE_STAIRS, B.IRON_BLOCK, B.GOLD_BLOCK, B.CRYSTAL_BLOCK, B.COAL_ORE, B.IRON_ORE,
         B.GOLD_ORE, B.CRYSTAL_ORE, B.OBSIDIAN, B.LADDER, B.TORCH, B.WORKBENCH, B.FURNACE, B.CHEST,
         B.FENCE, B.FENCE_GATE, I.DOOR, I.BED, B.GLASS_PANE, B.IRON_BARS, B.SIGN, B.WOOL];
     for (let i = 0; i < WOOL_COLORS.length; i++) {

+ 5 - 1
src/web/Blocky/js/commands.js

@@ -35,7 +35,11 @@ const ALIASES = {
     gold_block: B.GOLD_BLOCK,
     crystal_block: B.CRYSTAL_BLOCK,
     mossy_cobble: B.MOSSY_COBBLE,
-    double_stone_slab: B.STONE_SLAB
+    double_stone_slab: B.STONE_SLAB,
+    plank_stairs: B.PLANK_STAIRS,
+    wood_stairs: B.PLANK_STAIRS,
+    oak_stairs: B.PLANK_STAIRS,
+    cobble_stairs: B.COBBLE_STAIRS
 };
 
 function names() {

+ 1 - 1
src/web/Blocky/js/entities.js

@@ -9,7 +9,7 @@
 import { B, BLOCKS } from "./blocks.js";
 import { moveAxis } from "./physics.js";
 
-const ITEM_HALF = 0.125;
+export const ITEM_HALF = 0.125;
 const DESPAWN = 300;
 
 export class Entities {

+ 98 - 2
src/web/Blocky/js/game.js

@@ -20,7 +20,8 @@ import { World, WORLD_H } from "./world.js";
 import { BIOME, BIOME_NAMES } from "./worldgen.js";
 import { Player, DIFFICULTY } from "./player.js";
 import { Inventory } from "./inventory.js";
-import { Entities } from "./entities.js";
+import { Entities, ITEM_HALF } from "./entities.js";
+import { moveAxis, regionBlocked } from "./physics.js";
 import { selectionBox, collisionBoxes, FACE_DIR, doorHinge } from "./shapes.js";
 import { deflateString, mulberry32, clamp, lerp } from "./util.js";
 
@@ -106,6 +107,7 @@ export class Game {
                     this.sound.play("click");
                 }
             },
+            onPistonPush: (cells, d) => this.pistonPush(cells, d),
             onFizz: (x, y, z) => {
                 this.sound.play("fizz");
                 this.renderer.spawnParticles(x + 0.5, y + 1, z + 0.5, [200, 200, 200], 12, 0.4, 2);
@@ -1050,6 +1052,93 @@ export class Game {
         return [hit.x + d[0], hit.y + d[1], hit.z + d[2]];
     }
 
+    //Move an entity box out of the cells a piston just filled, along the
+    //piston direction d, to the far face of what moved (stopped by blocks
+    //beyond). Returns the distance.
+    pushOut(box, cells, d) {
+        const w = this.world;
+        const a = d[0] !== 0 ? 0 : d[1] !== 0 ? 1 : 2, s = d[a];
+        const pos = [0, 0, 0];
+        let need = 0;
+        for (const [cx, cy, cz] of cells) {
+            const id = w.getBlock(cx, cy, cz);
+            if (!SOLID[id]) {
+                continue;
+            }
+            for (const b of collisionBoxes(id, w.getMeta(cx, cy, cz), w, cx, cy, cz)) {
+                pos[0] = cx; pos[1] = cy; pos[2] = cz;
+                //The box swept over the block it moved through (the head's
+                //plate crosses its whole cell)
+                let hit = true;
+                for (let k = 0; k < 3 && hit; k++) {
+                    const lo = pos[k] + b[k] - (k === a && s > 0 ? 1 : 0), hi = pos[k] + b[k + 3] + (k === a && s < 0 ? 1 : 0);
+                    hit = box[k] < hi - 1e-6 && box[k + 3] > lo + 1e-6;
+                }
+                if (hit) {
+                    need = Math.max(need, s > 0 ? pos[a] + b[a + 3] - box[a] : box[a + 3] - (pos[a] + b[a]));
+                }
+            }
+        }
+        if (need <= 0) {
+            return 0;
+        }
+        //Straight past the far face when there is room (the moving parts
+        //push from behind, so they must not stop it); otherwise as far as
+        //the blocks allow, which pins it against the head
+        const shift = s * (need + 0.01);
+        box[a] += shift;
+        box[a + 3] += shift;
+        if (!regionBlocked(w, box[0], box[1], box[2], box[3], box[4], box[5])) {
+            return Math.abs(shift);
+        }
+        box[a] -= shift;
+        box[a + 3] -= shift;
+        return Math.abs(moveAxis(w, box, a, shift));
+    }
+
+    //A piston extended: push the player, animals and dropped items out of
+    //the head and the blocks it moved, with a little momentum
+    pistonPush(cells, d) {
+        const p = this.player;
+        const box = p.box();
+        const moved = this.pushOut(box, cells, d);
+        if (moved > 0) {
+            p.x = (box[0] + box[3]) / 2;
+            p.y = box[1];
+            p.z = (box[2] + box[5]) / 2;
+            if (d[1] !== 0) {
+                p.vy = Math.max(p.vy * d[1], 0) * d[1];
+                p.fallDistance = 0;
+                p.eyeSmooth -= d[1] * moved;
+            } else {
+                p.vx = d[0] !== 0 ? d[0] * Math.max(p.vx * d[0], 5) : p.vx;
+                p.vz = d[2] !== 0 ? d[2] * Math.max(p.vz * d[2], 5) : p.vz;
+            }
+        }
+        for (const m of this.mobs.list) {
+            const mb = this.mobs.box(m);
+            if (this.pushOut(mb, cells, d) > 0) {
+                m.x = (mb[0] + mb[3]) / 2;
+                m.y = mb[1];
+                m.z = (mb[2] + mb[5]) / 2;
+                m.vx += d[0] * 5;
+                m.vz += d[2] * 5;
+                m.vy = d[1] !== 0 ? Math.max(m.vy, 0) : m.vy;
+            }
+        }
+        for (const e of this.entities.items) {
+            const ib = [e.x - ITEM_HALF, e.y - ITEM_HALF, e.z - ITEM_HALF, e.x + ITEM_HALF, e.y + ITEM_HALF, e.z + ITEM_HALF];
+            if (this.pushOut(ib, cells, d) > 0) {
+                e.x = (ib[0] + ib[3]) / 2;
+                e.y = (ib[1] + ib[4]) / 2;
+                e.z = (ib[2] + ib[5]) / 2;
+                e.vx += d[0] * 3;
+                e.vy = Math.max(e.vy, d[1] * 3);
+                e.vz += d[2] * 3;
+            }
+        }
+    }
+
     //Would this block at (x, y, z) collide with the player?
     blocksPlayer(bid, meta, x, y, z) {
         if (!SOLID[bid]) {
@@ -1142,6 +1231,13 @@ export class Game {
             meta = face;
         } else if (bid === B.FENCE_GATE) {
             meta = facingFromYaw(p.yaw);
+        } else if (SHAPE[bid] === "stairs") {
+            //The steps climb away from the player; placed under a block or
+            //on the upper half of a side they hang upside down
+            meta = facingFromYaw(p.yaw);
+            if (face === 3 || (face !== 2 && hit.point[1] - hit.y > 0.5)) {
+                meta |= 4;
+            }
         } else if (def.orient) {
             const lx = -Math.sin(p.yaw), lz = -Math.cos(p.yaw);
             if (Math.abs(lx) > Math.abs(lz)) {
@@ -1486,7 +1582,7 @@ export class Game {
             roll += Math.sin(p.hurtTime * 40) * 0.04 * p.hurtTime;
         }
         const cos = Math.cos(p.yaw), sin = Math.sin(p.yaw);
-        cam.position.set(p.x + cos * bx, p.eyeY + by, p.z - sin * bx);
+        cam.position.set(p.x + cos * bx, p.eyeY + p.eyeSmooth + by, p.z - sin * bx);
         cam.rotation.set(p.pitch, p.yaw, roll);
         let fov = this.settings.fov;
         if (p.sprinting) {

+ 7 - 2
src/web/Blocky/js/icons.js

@@ -7,7 +7,8 @@
 */
 
 import { ITEMS, BLOCKS, SHAPE, blockFaceLayer } from "./blocks.js";
-import { drawIsoIcon, drawFlatIcon, ICON, GRASS_TINT, FOLIAGE_TINT } from "./textures.js";
+import { drawIsoIcon, drawIsoBoxes, drawFlatIcon, ICON, GRASS_TINT, FOLIAGE_TINT } from "./textures.js";
+import { STAIR_ITEM_BOXES } from "./mesher.js";
 
 export function buildIcons(tex) {
     const ids = [];
@@ -48,7 +49,11 @@ export function buildIcons(tex) {
             opts.topTint = FOLIAGE_TINT;
             opts.sideTint = FOLIAGE_TINT;
         }
-        drawIsoIcon(ctx, x, y, tiles, opts);
+        if (shape === "stairs") {
+            drawIsoBoxes(ctx, x, y, tiles, STAIR_ITEM_BOXES, opts);
+        } else {
+            drawIsoIcon(ctx, x, y, tiles, opts);
+        }
     });
     const icons = { pos, cols, rows };
     //One style rule carries the sheet; elements only set size and offset

+ 133 - 23
src/web/Blocky/js/mesher.js

@@ -8,7 +8,7 @@
     Cube faces get smooth lighting and ambient occlusion: every corner
     averages the light of the four voxels in front of it and darkens with
     the solid blocks around it. Everything else (plants, crops, torches,
-    slabs, cactus, farmland, ladders, water) is built from boxes and planes
+    slabs, stairs, cactus, farmland, ladders, water) is built from boxes and planes
     with flat light.
 
     Vertex layout: position (3), uv (2), layer (1), light (sky, block) (2),
@@ -20,7 +20,7 @@ import { WORLD_H } from "./worldgen.js";
 import {
     FACE_DIR, doorBox, gateAlongZ, fenceLinks, rotatePoint, paneLinks, LEVER_BASE, BUTTON_BOX, BUTTON_PRESSED,
     signAngle, SIGN_BOARD, SIGN_POST, SIGN_WALL_BOARD,
-    PISTON_BASE, HEAD_PLATE, HEAD_ROD
+    PISTON_BASE, HEAD_PLATE, HEAD_ROD, stairShape, stairBoxes
 } from "./shapes.js";
 
 const P = 18;
@@ -250,6 +250,8 @@ export function meshSection(world, chunk, sy, opts) {
                         }
                         return false;
                     });
+                } else if (shape === "stairs") {
+                    stairs(solidBuf, p, x, y, z, id, meta);
                 } else if (shape === "cactus") {
                     const e = 1 / 16;
                     boxFaces(solidBuf, p, x, y, z, id, meta, e, 0, e, 1 - e, 1, 1 - e, (f, np) => {
@@ -395,6 +397,53 @@ function boxFaces(buf, p, x, y, z, id, meta, x0, y0, z0, x1, y1, z1, cull, topFa
     }
 }
 
+//Does another box of the set cover face f of box i completely (two boxes
+//of one block touching inside it)?
+function faceCovered(boxes, i, f) {
+    const b = boxes[i];
+    const axis = FACE_AXIS[f], pos = FACE_SIGN[f] > 0;
+    const plane = pos ? b[axis + 3] : b[axis];
+    const a1 = (axis + 1) % 3, a2 = (axis + 2) % 3;
+    for (let j = 0; j < boxes.length; j++) {
+        const o = boxes[j];
+        if (j === i || (pos ? o[axis] : o[axis + 3]) !== plane) {
+            continue;
+        }
+        if (o[a1] <= b[a1] && o[a1 + 3] >= b[a1 + 3] && o[a2] <= b[a2] && o[a2 + 3] >= b[a2 + 3]) {
+            return true;
+        }
+    }
+    return false;
+}
+
+//Stairs: the half slab and the raised step, joined into corners with the
+//stairs around them. Faces take the light of the open cell they look
+//into, since the stair itself dims light.
+function stairs(buf, p, x, y, z, id, meta) {
+    const boxes = stairBoxes(meta, stairShape((a, b, c) => pBlk[pi(a, b, c)], (a, b, c) => pMeta[pi(a, b, c)], x, y, z, meta));
+    for (let i = 0; i < boxes.length; i++) {
+        const bx = boxes[i];
+        for (let f = 0; f < 6; f++) {
+            const axis = FACE_AXIS[f];
+            const np = p + FACE_OFF[f];
+            const onEdge = FACE_SIGN[f] > 0 ? bx[axis + 3] >= 1 : bx[axis] <= 0;
+            if (onEdge ? pOpq[np] === 1 : faceCovered(boxes, i, f)) {
+                continue;
+            }
+            const lp = !pOpq[np] ? np : !pOpq[p + P2] ? p + P2 : p;
+            const ls = (pLight[lp] >> 4) / 15, lb = (pLight[lp] & 15) / 15;
+            const layer = blockFaceLayer(id, f, meta);
+            const sh = FACE_SHADE[f];
+            for (const c of FACE_VERTS[f]) {
+                const vx = c[0] ? bx[3] : bx[0], vy = c[1] ? bx[4] : bx[1], vz = c[2] ? bx[5] : bx[2];
+                const uv = faceUV(f, vx, vy, vz);
+                buf.vert(x + vx, y + vy, z + vz, uv[0], uv[1], layer, ls, lb, sh, sh, sh);
+            }
+            buf.quad(false);
+        }
+    }
+}
+
 const U = 1 / 16;
 
 //Bed half: a mattress on a frame, raised on two legs at its outer end, so a
@@ -564,6 +613,10 @@ function pane(buf, p, x, y, z, id, meta) {
     const getId = (a, b, c) => pBlk[pi(a, b, c)];
     const getMeta = (a, b, c) => pMeta[pi(a, b, c)];
     const links = paneLinks(getId, getMeta, x, y, z);
+    if (id === B.IRON_BARS) {
+        ironBars(buf, p, x, y, z, id, meta, links);
+        return;
+    }
     const capped = (f, np) => (f === 2 || f === 3) && (pOpq[np] === 1 || SHAPE[pBlk[np]] === "pane");
     boxFaces(buf, p, x, y, z, id, meta, 7 * U, 0, 7 * U, 9 * U, 1, 9 * U, capped);
     const arms = [
@@ -577,6 +630,36 @@ function pane(buf, p, x, y, z, id, meta) {
     });
 }
 
+//Iron bars: a 2 x 2 post, and toward each linked side a framed half panel
+//(rails at the top and bottom, a bar in the middle of the half and a half
+//bar on the edge that meets the neighbour's into a whole one), 2 px deep.
+//Pieces are listed for the +x arm as [along0, y0, along1, y1].
+const BAR_ARM = [
+    [9, 0, 16, 1], [9, 15, 16, 16],
+    [11, 1, 13, 15], [15, 1, 16, 15]
+];
+
+function ironBars(buf, p, x, y, z, id, meta, links) {
+    const capped = (f, np) => (f === 2 || f === 3) && (pOpq[np] === 1 || pBlk[np] === B.IRON_BARS);
+    boxFaces(buf, p, x, y, z, id, meta, 7 * U, 0, 7 * U, 9 * U, 1, 9 * U, capped);
+    //Arm k (+x, -x, +z, -z): its end face and how an along range maps to x / z
+    const END = [0, 1, 4, 5];
+    for (let k = 0; k < 4; k++) {
+        if (!links[k]) {
+            continue;
+        }
+        for (const [a0, y0, a1, y1] of BAR_ARM) {
+            //Mirror the +x layout for the arms pointing the other way
+            const lo = k === 0 || k === 2 ? a0 : 16 - a1, hi = k === 0 || k === 2 ? a1 : 16 - a0;
+            const box = k < 2 ? [lo, y0, 7, hi, y1, 9] : [7, y0, lo, 9, y1, hi];
+            //Only faces on the block's own edge can be hidden by a neighbour
+            const atEnd = a1 === 16;
+            boxFaces(buf, p, x, y, z, id, meta, box[0] * U, box[1] * U, box[2] * U, box[3] * U, box[4] * U, box[5] * U,
+                (f, np) => (atEnd && f === END[k]) || (((f === 2 && y1 === 16) || (f === 3 && y0 === 0)) && pOpq[np] === 1));
+        }
+    }
+}
+
 const WIRE_LINKS = new Set([B.SPARK_WIRE, B.LEVER, B.BUTTON, B.PLATE_WOOD, B.PLATE_STONE, B.RETIMER, B.RETIMER_ON, B.SPARK_TORCH, B.SPARK_TORCH_OFF, B.SPARK_LAMP,
     B.SPARK_LAMP_ON, B.PISTON, B.STICKY_PISTON, B.SPARK_BLOCK, B.POWERED_RAIL]);
 
@@ -594,7 +677,12 @@ function wire(buf, p, x, y, z, id, meta) {
     const above = pOpq[p + P2];
     const links = dirs.map(([dx, dz]) => {
         const np = p + dx + dz * P;
-        if (WIRE_LINKS.has(pBlk[np])) {
+        const nid = pBlk[np];
+        //A retimer only takes wire at its back (input) and front (output)
+        if (nid === B.RETIMER || nid === B.RETIMER_ON) {
+            return (dx !== 0) === ((pMeta[np] & 1) === 0);
+        }
+        if (WIRE_LINKS.has(nid)) {
             return true;
         }
         if (!above && pBlk[np + P2] === B.SPARK_WIRE) {
@@ -603,11 +691,19 @@ function wire(buf, p, x, y, z, id, meta) {
         return !pOpq[np] && pBlk[np - P2] === B.SPARK_WIRE;
     });
     const n = links.filter(Boolean).length;
+    //A lone wire is a cross and a dead end runs on straight, but never
+    //into the side of a retimer
+    const retimerSide = (k) => {
+        const nid = pBlk[p + dirs[k][0] + dirs[k][1] * P];
+        return !links[k] && (nid === B.RETIMER || nid === B.RETIMER_ON);
+    };
     if (n === 0) {
-        links.fill(true);
+        for (let k = 0; k < 4; k++) {
+            links[k] = !retimerSide(k);
+        }
     } else if (n === 1) {
         const k = links.indexOf(true);
-        links[k ^ 1] = true;
+        links[k ^ 1] = !retimerSide(k ^ 1);
     }
     const t = meta / 15;
     const r = 0.34 + 0.66 * t, g = 0.03 + 0.1 * t, bl = 0.03 + 0.07 * t;
@@ -638,14 +734,16 @@ function retimer(buf, p, x, y, z, id, meta) {
 
 //A box in sign space (see SIGN_BOARD) turned by angle a about the block's
 //vertical axis, lit by the sign's own cell
-function yawBox(buf, p, x, y, z, b, a, layer) {
+//frontShade, when given, lights the two broad faces (along the box's local
+//z) the same whichever way the box is turned
+function yawBox(buf, p, x, y, z, b, a, layer, frontShade = 0) {
     const s = Math.sin(a), c = Math.cos(a);
     const ls = (pLight[p] >> 4) / 15, lb = (pLight[p] & 15) / 15;
     for (let f = 0; f < 6; f++) {
         //World normal of this face picks the shade
         const n = [[1, 0], [-1, 0], [0, 0], [0, 0], [0, 1], [0, -1]][f];
         const nx = n[0] * c + n[1] * s;
-        const sh = f === 2 ? 1 : f === 3 ? 0.5 : Math.abs(nx) > 0.7 ? 0.6 : 0.8;
+        const sh = f === 2 ? 1 : f === 3 ? 0.5 : frontShade && f >= 4 ? frontShade : Math.abs(nx) > 0.7 ? 0.6 : 0.8;
         for (const v of FACE_VERTS[f]) {
             const lx = v[0] ? b[3] : b[0], ly = v[1] ? b[4] : b[1], lz = v[2] ? b[5] : b[2];
             const uv = faceUV(f, lx, ly, lz);
@@ -658,11 +756,11 @@ function yawBox(buf, p, x, y, z, b, a, layer) {
 
 //Sign: a board on a post (standing) or a board on the wall behind it
 function sign(buf, p, x, y, z, id, meta) {
-    const a = signAngle(id, meta), layer = layerOfTile("planks");
+    const a = signAngle(id, meta), layer = layerOfTile("sign_board");
     if (id === B.WALL_SIGN) {
-        yawBox(buf, p, x, y, z, SIGN_WALL_BOARD, a, layer);
+        yawBox(buf, p, x, y, z, SIGN_WALL_BOARD, a, layer, 0.9);
     } else {
-        yawBox(buf, p, x, y, z, SIGN_BOARD, a, layer);
+        yawBox(buf, p, x, y, z, SIGN_BOARD, a, layer, 0.9);
         yawBox(buf, p, x, y, z, SIGN_POST, a, layerOfTile("log_side"));
     }
 }
@@ -856,33 +954,45 @@ export function cardGeometry(tile) {
     return buf.take();
 }
 
+//How stairs are shown in the hand, as dropped items and as icons: the step
+//on the -x half
+export const STAIR_ITEM_BOXES = [[0, 0, 0, 1, 0.5, 1], [0, 0.5, 0, 0.5, 1, 1]];
+
 //Geometry for held items and dropped items, centred on the origin.
-//Blocks are unit cubes (slabs half height), everything else a flat card.
+//Blocks are unit cubes (slabs half height, stairs two boxes), everything
+//else a flat card.
 export function itemGeometry(id) {
     const buf = new GeoBuf(64);
     buf.reset();
     const it = ITEMS[id];
     const blockId = it && it.block;
     const shape = blockId ? SHAPE[blockId] : null;
-    const cubeLike = blockId && (shape === "cube" || shape === "slab" || shape === "cactus" || shape === "farmland" || shape === "piston" ||
-        shape === "plate" || shape === "retimer");
+    const cubeLike = blockId && (shape === "cube" || shape === "slab" || shape === "stairs" || shape === "cactus" || shape === "farmland" ||
+        shape === "piston" || shape === "plate" || shape === "retimer");
     if (cubeLike) {
         const def = BLOCKS[blockId];
         const meta = def.orient ? 4 : 0;
         const top = shape === "slab" ? 0.5 : shape === "plate" ? 1 / 16 : shape === "retimer" ? 2 / 16 : 1;
         const inset = shape === "cactus" ? 1 / 16 : 0;
+        const boxes = shape === "stairs" ? STAIR_ITEM_BOXES : [[inset, 0, inset, 1 - inset, top, 1 - inset]];
         const tintC = def.tint === "foliage" ? [0.48, 0.86, 0.32] : def.tint === "grass" ? [0.62, 1.0, 0.43] : null;
-        for (let f = 0; f < 6; f++) {
-            const layer = blockFaceLayer(blockId, f, meta);
-            const s = FACE_SHADE[f];
-            const tinted = tintC && (def.tint === "foliage" || f === 2);
-            const r = (tinted ? tintC[0] : 1) * s, g = (tinted ? tintC[1] : 1) * s, b = (tinted ? tintC[2] : 1) * s;
-            for (const c of FACE_VERTS[f]) {
-                const vx = c[0] ? 1 - inset : inset, vy = c[1] ? top : 0, vz = c[2] ? 1 - inset : inset;
-                const uv = faceUV(f, vx, vy, vz);
-                buf.vert(vx - 0.5, vy - 0.5, vz - 0.5, uv[0], uv[1], layer, 1, 0, r, g, b);
+        for (let i = 0; i < boxes.length; i++) {
+            const bx = boxes[i];
+            for (let f = 0; f < 6; f++) {
+                if (faceCovered(boxes, i, f)) {
+                    continue;
+                }
+                const layer = blockFaceLayer(blockId, f, meta);
+                const s = FACE_SHADE[f];
+                const tinted = tintC && (def.tint === "foliage" || f === 2);
+                const r = (tinted ? tintC[0] : 1) * s, g = (tinted ? tintC[1] : 1) * s, b = (tinted ? tintC[2] : 1) * s;
+                for (const c of FACE_VERTS[f]) {
+                    const vx = c[0] ? bx[3] : bx[0], vy = c[1] ? bx[4] : bx[1], vz = c[2] ? bx[5] : bx[2];
+                    const uv = faceUV(f, vx, vy, vz);
+                    buf.vert(vx - 0.5, vy - 0.5, vz - 0.5, uv[0], uv[1], layer, 1, 0, r, g, b);
+                }
+                buf.quad(false);
             }
-            buf.quad(false);
         }
         return { geo: buf.take(), cube: true };
     }

+ 43 - 3
src/web/Blocky/js/player.js

@@ -5,7 +5,10 @@
 
     Movement: walking, sprinting, sneaking (which keeps you from walking off
     edges), jumping, swimming, ladder climbing and creative flight, with a
-    0.6 block auto-step so slabs can be walked up.
+    0.6 block auto-step so slabs and stairs can be walked up, and a snap
+    down onto a step up to 0.6 below so they can be walked down. Steps
+    move the camera smoothly (eyeSmooth). Swimming against a bank pushes
+    you out once its top is within reach.
 
     Survival: 20 health points, 20 food points with a hidden saturation
     buffer and exhaustion counter. Exhaustion comes from actions and from a
@@ -45,6 +48,7 @@ export class Player {
         this.horizontalHit = false;
         this.fallDistance = 0;
         this.walkDist = 0;
+        this.eyeSmooth = 0;
         this.creative = false;
         this.difficulty = 2;
         this.health = 20;
@@ -76,6 +80,7 @@ export class Player {
         this.x = x; this.y = y; this.z = z;
         this.vx = this.vy = this.vz = 0;
         this.fallDistance = 0;
+        this.eyeSmooth = 0;
     }
 
     //Is the given world point under the surface of a liquid (water or lava)?
@@ -89,6 +94,19 @@ export class Player {
         return py - y < h + 0.02;
     }
 
+    //Swimming against a bank: would the spot 0.6 higher and a little ahead
+    //(along wx, wz) be free of blocks and above any liquid? Then the bank
+    //can be climbed, even one level with the water surface.
+    canClimbOut(wx, wz) {
+        const b = this.box();
+        const ox = wx * 0.2, oz = wz * 0.2, lift = 0.6;
+        if (regionBlocked(this.world, b[0] + ox, b[1] + lift, b[2] + oz, b[3] + ox, b[4] + lift, b[5] + oz)) {
+            return false;
+        }
+        const fx = this.x + ox, fy = this.y + lift, fz = this.z + oz;
+        return !this.waterAt(fx, fy, fz) && !this.waterAt(fx, fy, fz, B.LAVA);
+    }
+
     sense() {
         const w = this.world;
         this.inLava = this.waterAt(this.x, this.y + 0.25, this.z, B.LAVA) || this.waterAt(this.x, this.y + 0.9, this.z, B.LAVA);
@@ -171,7 +189,7 @@ export class Player {
             if (input.jump) {
                 this.vy = Math.min(this.vy + 14 * dt, 1.8);
                 if (this.horizontalHit) {
-                    this.vy = 3.5;
+                    this.vy = this.canClimbOut(wx, wz) ? 6 : 3.5;
                 }
             }
             this.vy = Math.max(this.vy, -1.8);
@@ -180,8 +198,10 @@ export class Player {
             this.vy *= Math.exp(-2.2 * dt);
             if (input.jump) {
                 this.vy = Math.min(this.vy + 26 * dt, 3.2);
+                //Against a bank: 4.5 alone tops out just under a bank level
+                //with the surface, so once its top is in reach push harder
                 if (this.horizontalHit) {
-                    this.vy = 4.5;
+                    this.vy = this.canClimbOut(wx, wz) ? 6.5 : 4.5;
                 }
             }
             this.vy = Math.max(this.vy, -3.5);
@@ -243,6 +263,7 @@ export class Player {
             const az = moveAxis(w, alt, 2, mz);
             moveAxis(w, alt, 1, -up);
             if (ax * ax + az * az > rx * rx + rz * rz + 1e-6) {
+                this.eyeSmooth -= alt[1] - box[1];
                 for (let i = 0; i < 6; i++) {
                     box[i] = alt[i];
                 }
@@ -257,6 +278,25 @@ export class Player {
             this.vz = 0;
         }
         this.horizontalHit = hitX || hitZ;
+        //Walked off a step (stairs, a slab): land on the one below right away
+        //instead of falling, so walking downstairs keeps you on the ground
+        if (wasGround && !this.onGround && this.vy <= 0 && !input.jump && !this.flying && !this.inWater && !this.inLava && !this.onLadder) {
+            const probe = box.slice();
+            const down = moveAxis(w, probe, 1, -STEP);
+            if (down > -STEP + 1e-6) {
+                this.eyeSmooth -= down;
+                for (let i = 0; i < 6; i++) {
+                    box[i] = probe[i];
+                }
+                this.onGround = true;
+                this.vy = 0;
+            }
+        }
+        //The camera follows steps smoothly
+        this.eyeSmooth = clamp(this.eyeSmooth * Math.exp(-18 * dt), -0.6, 0.6);
+        if (Math.abs(this.eyeSmooth) < 1e-3) {
+            this.eyeSmooth = 0;
+        }
         //Holding sneak while flying into the ground lands you
         if (this.flying && this.onGround && input.sneak) {
             this.flying = false;

+ 6 - 0
src/web/Blocky/js/power.js

@@ -274,6 +274,12 @@ function extend(w, x, y, z, id, meta, onSound) {
     w.setBlock(x, y, z, id, meta | 8);
     w.setBlock(x + d[0], y + d[1], z + d[2], B.PISTON_HEAD, f | (id === B.STICKY_PISTON ? 8 : 0));
     w.pistonMoving = false;
+    //The head and the moved blocks shove whatever stands in their new cells
+    if (w.onPistonPush) {
+        const cells = line.map(([px, py, pz]) => [px + d[0], py + d[1], pz + d[2]]);
+        cells.push([x + d[0], y + d[1], z + d[2]]);
+        w.onPistonPush(cells, d);
+    }
     onSound(true);
 }
 

+ 79 - 3
src/web/Blocky/js/shapes.js

@@ -2,11 +2,12 @@
     Blocky - shapes.js
 
     Collision and selection boxes of the non-cube block shapes, in block
-    local coordinates [x0, y0, z0, x1, y1, z1]. Fences look at their
-    neighbours, so the box functions take the world and the position too.
+    local coordinates [x0, y0, z0, x1, y1, z1]. Fences and stairs look at
+    their neighbours, so the box functions take the world and the position
+    too.
 */
 
-import { B, SHAPE, SOLID, isOpaqueAt } from "./blocks.js";
+import { B, SHAPE, SOLID, HDIR, isOpaqueAt } from "./blocks.js";
 
 const FULL = [0, 0, 0, 1, 1, 1];
 const NONE = [];
@@ -98,6 +99,79 @@ function unionBox(boxes) {
     return u;
 }
 
+//Stair meta: bits 0-1 the side the steps climb toward (HDIR), bit 2 upside
+//down (the half slab on top, the step hanging under it)
+export const STAIR_FLIP = 4;
+
+//How a stair joins the stairs next to it, as kind * 4 + side: kind 0
+//straight, 1 outer corner (only the quarter between the climbing side and
+//`side` is raised: a stair behind it turns away), 2 inner corner (the
+//climbing half and the `side` half are raised: a stair in front of it
+//turns away). Only stairs of the same half join; a stair that continues a
+//straight run on the far side keeps the run straight.
+export function stairShape(getId, getMeta, x, y, z, meta) {
+    const f = meta & 3, flip = meta & STAIR_FLIP;
+    const stairMeta = (ax, az) => (SHAPE[getId(ax, y, az)] === "stairs" && (getMeta(ax, y, az) & STAIR_FLIP) === flip ? getMeta(ax, y, az) : -1);
+    const sameRun = (ax, az) => {
+        const m = stairMeta(ax, az);
+        return m >= 0 && (m & 3) === f;
+    };
+    const d = HDIR[f];
+    const behind = stairMeta(x + d[0], z + d[1]);
+    if (behind >= 0 && ((behind & 3) & 1) !== (f & 1)) {
+        const s = behind & 3;
+        if (!sameRun(x - HDIR[s][0], z - HDIR[s][1])) {
+            return 4 + s;
+        }
+    }
+    const front = stairMeta(x - d[0], z - d[1]);
+    if (front >= 0 && ((front & 3) & 1) !== (f & 1)) {
+        const s = front & 3;
+        if (!sameRun(x + HDIR[s][0], z + HDIR[s][1])) {
+            return 8 + s;
+        }
+    }
+    return f;
+}
+
+//[x0, x1, z0, z1] of the half of a block toward side
+function halfToward(side) {
+    const d = HDIR[side];
+    return [d[0] > 0 ? 0.5 : 0, d[0] < 0 ? 0.5 : 1, d[1] > 0 ? 0.5 : 0, d[1] < 0 ? 0.5 : 1];
+}
+
+//The part of both halves, as a box between y0 and y1
+function halvesBox(a, b, y0, y1) {
+    return [Math.max(a[0], b[0]), y0, Math.max(a[2], b[2]), Math.min(a[1], b[1]), y1, Math.min(a[3], b[3])];
+}
+
+//Boxes of a stair: the half slab first, then the raised step (two boxes for
+//an inner corner). They never overlap.
+export function stairBoxes(meta, shape) {
+    const flip = meta & STAIR_FLIP;
+    const out = [flip ? [0, 0.5, 0, 1, 1, 1] : [0, 0, 0, 1, 0.5, 1]];
+    const y0 = flip ? 0 : 0.5, y1 = flip ? 0.5 : 1;
+    const kind = shape >> 2, side = shape & 3;
+    const up = halfToward(meta & 3);
+    if (kind === 1) {
+        out.push(halvesBox(up, halfToward(side), y0, y1));
+        return out;
+    }
+    out.push([up[0], y0, up[2], up[1], y1, up[3]]);
+    if (kind === 2) {
+        out.push(halvesBox(halfToward(side), halfToward((meta & 3) ^ 2), y0, y1));
+    }
+    return out;
+}
+
+//A stair placed in the world, joined to its neighbours
+export function stairBoxesAt(world, x, y, z, meta) {
+    if (!world) {
+        return stairBoxes(meta, meta & 3);
+    }
+    return stairBoxes(meta, stairShape((a, b, c) => world.getBlock(a, b, c), (a, b, c) => world.getMeta(a, b, c), x, y, z, meta));
+}
+
 const DOOR_T = 3 / 16;
 //Closed door panel along the edge the door faces (0 +x, 1 +z, 2 -x, 3 -z)
 const DOOR_PANEL = [
@@ -165,6 +239,8 @@ export function collisionBoxes(id, meta, world, x, y, z) {
                 return [FULL];
             }
             return [meta === 1 ? [0, 0.5, 0, 1, 1, 1] : [0, 0, 0, 1, 0.5, 1]];
+        case "stairs":
+            return stairBoxesAt(world, x, y, z, meta);
         case "cactus":
             return [[0.0625, 0, 0.0625, 0.9375, 1, 0.9375]];
         case "farmland":

+ 4 - 4
src/web/Blocky/js/signs.js

@@ -14,7 +14,7 @@ import { signAngle, SIGN_BOARD, SIGN_WALL_BOARD } from "./shapes.js";
 export const SIGN_LINES = 4;
 export const SIGN_LINE_MAX = 15;
 const RANGE = 40;
-const CW = 256, CH = 128;
+const CW = 512, CH = 256;
 
 export class Signs {
     constructor(game) {
@@ -97,14 +97,14 @@ export class Signs {
         const canvas = mesh.userData.canvas;
         const ctx = canvas.getContext("2d");
         ctx.clearRect(0, 0, CW, CH);
-        ctx.fillStyle = "#24170a";
+        ctx.fillStyle = "#140c04";
         ctx.textAlign = "center";
         ctx.textBaseline = "middle";
-        ctx.font = "bold 25px Arial, Helvetica, sans-serif";
+        ctx.font = "bold 56px Arial, Helvetica, sans-serif";
         for (let i = 0; i < SIGN_LINES; i++) {
             const text = (lines[i] || "").slice(0, SIGN_LINE_MAX);
             if (text) {
-                ctx.fillText(text, CW / 2, CH * (i + 0.5) / SIGN_LINES, CW - 8);
+                ctx.fillText(text, CW / 2, CH * (i + 0.5) / SIGN_LINES, CW - 16);
             }
         }
         mesh.material.map.needsUpdate = true;

+ 65 - 0
src/web/Blocky/js/textures.js

@@ -230,6 +230,26 @@ function paintPlanks(t, base = [168, 134, 82]) {
     }
 }
 
+//Sign boards: light wood with soft seams, so the writing stands out
+function paintSignBoard(t) {
+    const base = [204, 168, 112];
+    for (let b = 0; b < 4; b++) {
+        const f = 0.96 + t.r() * 0.06;
+        for (let yy = 0; yy < 4; yy++) {
+            const y = b * 4 + yy;
+            for (let x = 0; x < 16; x++) {
+                let k = f;
+                if (yy === 3) {
+                    k *= 0.86;
+                } else if (t.r() < 0.1) {
+                    k *= 0.94;
+                }
+                t.set(x, y, t.vary([base[0] * k, base[1] * k, base[2] * k], 3));
+            }
+        }
+    }
+}
+
 function paintLogSide(t) {
     const base = [104, 82, 52];
     for (let x = 0; x < 16; x++) {
@@ -1308,6 +1328,16 @@ function paintIronBars(t) {
     }
 }
 
+//The metal of iron bar models: lighter along one edge, darker along the other
+function paintIronBarMetal(t) {
+    for (let y = 0; y < 16; y++) {
+        for (let x = 0; x < 16; x++) {
+            const base = x % 4 === 0 ? [196, 198, 202] : x % 4 === 3 ? [112, 114, 118] : [154, 156, 160];
+            t.set(x, y, t.vary(base, 7));
+        }
+    }
+}
+
 function paintSignItem(t) {
     t.clear();
     t.rect(1, 2, 14, 8, [176, 136, 80], 10);
@@ -1603,6 +1633,7 @@ const PAINTERS = {
     log_side: paintLogSide,
     log_top: paintLogTop,
     planks: (t) => paintPlanks(t),
+    sign_board: paintSignBoard,
     leaves: paintLeaves,
     glass: paintGlass,
     coal_ore: (t) => paintOre(t, [36, 36, 40], 5),
@@ -1753,6 +1784,7 @@ Object.assign(PAINTERS, {
     lever_item: paintLeverItem,
     button_item: paintButtonItem,
     iron_bars: paintIronBars,
+    iron_bar_metal: paintIronBarMetal,
     sign_item: paintSignItem,
     retimer_top: (t) => paintRetimerTop(t, false),
     retimer_top_on: (t) => paintRetimerTop(t, true),
@@ -1899,6 +1931,39 @@ export function drawIsoIcon(ctx, ox, oy, tiles, opts = {}) {
     ctx.setTransform(1, 0, 0, 1, 0, 0);
 }
 
+//Draw an isometric icon made of several boxes in block units
+//[x0, y0, z0, x1, y1, z1] (stairs), back boxes first. Each box shows its
+//top, +z (front left) and +x (front right) faces cut from the tiles.
+export function drawIsoBoxes(ctx, ox, oy, tiles, boxes, opts = {}) {
+    const sc = 0.86;
+    const off = (1 - sc) * ICON / 2;
+    const tf = (a, b, c, d, e, f) => {
+        ctx.setTransform(a * sc, b * sc, c * sc, d * sc, ox + e * sc + off, oy + f * sc + off);
+    };
+    //Part of a tile in tile pixels, drawn at the same spot of the face
+    const part = (img, u0, v0, u1, v1) => {
+        if (u1 - u0 > 0 && v1 - v0 > 0) {
+            ctx.drawImage(img, u0, v0, u1 - u0, v1 - v0, u0, v0, u1 - u0, v1 - v0);
+        }
+    };
+    ctx.imageSmoothingEnabled = false;
+    const top = shadedTile(tiles.top, 1, opts.topTint);
+    const left = shadedTile(tiles.left, 0.78, opts.sideTint);
+    const right = shadedTile(tiles.right, 0.6, opts.sideTint);
+    for (const [x0, y0, z0, x1, y1, z1] of boxes) {
+        //Top: u runs toward -z, v toward +x
+        tf(2, -1, 2, 1, 0, 16 + 32 * (1 - y1));
+        part(top, 16 * (1 - z1), 16 * x0, 16 * (1 - z0), 16 * x1);
+        //+z face: u along x, v down from the top
+        tf(2, 1, 0, 2, 32 - 32 * z1, 16 * z1);
+        part(left, 16 * x0, 16 * (1 - y1), 16 * x1, 16 * (1 - y0));
+        //+x face: u toward -z
+        tf(2, -1, 0, 2, 32 * x1, 16 * x1 + 16);
+        part(right, 16 * (1 - z1), 16 * (1 - y1), 16 * (1 - z0), 16 * (1 - y0));
+    }
+    ctx.setTransform(1, 0, 0, 1, 0, 0);
+}
+
 export function drawFlatIcon(ctx, ox, oy, tile, tint) {
     ctx.imageSmoothingEnabled = false;
     ctx.drawImage(shadedTile(tile, 1, tint), ox + 4, oy + 4, ICON - 8, ICON - 8);

+ 3 - 2
src/web/Blocky/js/world.js

@@ -99,6 +99,7 @@ export class World {
         this.onBlockBroken = opts.onBlockBroken || null;
         this.onFizz = opts.onFizz || null;
         this.onPowerSound = opts.onPowerSound || null;
+        this.onPistonPush = opts.onPistonPush || null;
         this.powerBusy = false;
         this.pistonMoving = false;
         this.buttonDue = new Map();
@@ -802,8 +803,8 @@ export class World {
                 if (isOpaqueAt(aid, am)) {
                     return true;
                 }
-                //Torches also stand on top slabs and fence posts
-                return BLOCKS[id].support === "torch" && meta === 2 && ((IS_SLAB[aid] === 1 && am === 1) || aid === B.FENCE);
+                //Torches also stand on top slabs, upside down stairs and fence posts
+                return BLOCKS[id].support === "torch" && meta === 2 && ((IS_SLAB[aid] === 1 && am === 1) || (SHAPE[aid] === "stairs" && (am & 4)) || aid === B.FENCE);
             }
             case "door":
                 if (meta & 8) {