🗂 My worlds
diff --git a/llms.txt b/llms.txt
index 5b9c1b4..24efe96 100644
--- a/llms.txt
+++ b/llms.txt
@@ -12,7 +12,7 @@ Key facts:
- Learning: 64 quests (counting, times tables, colours, shapes, coding) and Blockly coding for Bit the robot.
## Features
-- [All features, with screenshots and FAQ](features.html): Course Maker, Play Together, Bit coding, Photo Mode, animals and pets, farming, fun blocks, villages, quests, Spark circuits, power tools, Adventure mode, tablets and phones
+- [All features, with screenshots and FAQ](features.html): Course Maker, Play Together, Bit coding, Photo Mode, animals and pets (armor, backpack, pet beds and doghouses), farming, fun blocks, villages, quests, Spark circuits, power tools, Adventure mode, tablets and phones
- [Play the game](./)
## Policies
diff --git a/src/blocks.js b/src/blocks.js
index 75c33a4..799bf1d 100644
--- a/src/blocks.js
+++ b/src/blocks.js
@@ -23,6 +23,8 @@ export const B = {
PISTON: 96, PISTON_OUT: 101, PISTON_HEAD: 106,
// Course Maker: build your own obstacle courses and races.
COURSE_START: 107, COURSE_CHECK: 108, COURSE_FINISH: 109, COIN: 110, COIN_TAKEN: 111,
+ // Pet upgrades: a cushion pets rest on and a doghouse.
+ PET_BED: 112, KENNEL: 113,
};
export const BLOCKS = [];
@@ -155,6 +157,10 @@ def(B.COURSE_CHECK, 'Checkpoint', { top: TILE.COURSE_CHECK, bottom: TILE.PAD_SID
def(B.COURSE_FINISH, 'Course Finish', { top: TILE.COURSE_FINISH, bottom: TILE.PAD_SIDE, side: TILE.PAD_SIDE }, { course: 'finish' });
def(B.COIN, 'Coin', TILE.COIN, { solid: false, transparent: true, shape: 'plant', emissive: true, course: 'coin' });
def(B.COIN_TAKEN, 'Coin (collected)', TILE.COIN_TAKEN, { solid: false, transparent: true, shape: 'plant', course: 'taken', placeable: false });
+// ---- Pet beds ----
+// Tell a pet to sit near one and it walks over; pets resting by a bed or kennel slowly get better.
+def(B.PET_BED, 'Pet Bed', TILE.PET_BED, { ...flat, pet: 'bed' });
+def(B.KENNEL, 'Doghouse', { top: TILE.KENNEL_TOP, bottom: TILE.PLANKS, side: TILE.KENNEL_SIDE }, { pet: 'kennel' });
/** Facing-aware block: turns a placed directional item into the variant facing `dir`. */
export function sparkFacing(id, dir) {
const b = BLOCKS[id];
diff --git a/src/ideas.js b/src/ideas.js
index 3d26341..8841ed4 100644
--- a/src/ideas.js
+++ b/src/ideas.js
@@ -18,6 +18,7 @@ export const IDEAS = [
'Build a garden with every colour of flower 🌷',
'Make a waterfall into a pool 💧',
'Build a tiny village for your pets 🐶',
+ 'Build a cosy doghouse with a pet bed inside a fence 🏠',
'Make a racetrack with speed strips 🏁',
'Build a snowman on top of a mountain ⛄',
'Make a neon city that glows at night 🌃',
diff --git a/src/items.js b/src/items.js
index bed6fe9..7c77e5d 100644
--- a/src/items.js
+++ b/src/items.js
@@ -17,6 +17,7 @@ export const I = {
PARTY_HAT: 330, CROWN: 331, SUNGLASSES: 332,
WOOD_SWORD: 340, STONE_SWORD: 341, IRON_SWORD: 342, DIAMOND_SWORD: 343,
BOW: 344, ARROW: 345, SHIELD: 346, WOOL_ARMOR: 347, IRON_ARMOR: 348, DIAMOND_ARMOR: 349,
+ COZY_PET_COAT: 360, IRON_PET_ARMOR: 361, STAR_PET_ARMOR: 362, PET_BACKPACK: 363,
};
const TIERS = [
@@ -76,6 +77,14 @@ item(I.PARTY_HAT, 'Party Hat', { sprite: 'partyhat', color: [240, 80, 160], stac
item(I.CROWN, 'Tiny Crown', { sprite: 'crown', color: [250, 210, 60], stack: 16, accessory: 'crown' });
item(I.SUNGLASSES, 'Sunglasses', { sprite: 'glasses', color: [30, 30, 40], stack: 16, accessory: 'glasses' });
+// Pet armor (right-click your pet while holding it) cuts the damage the pet takes; the backpack gives it 9 slots.
+// `petArmor` is the share of damage blocked.
+item(I.COZY_PET_COAT, 'Cozy Pet Coat', { sprite: 'petarmor', color: [120, 170, 235], stack: 1, petArmor: 0.25 });
+item(I.IRON_PET_ARMOR, 'Iron Pet Armor', { sprite: 'petarmor', color: [205, 208, 215], stack: 1, petArmor: 0.5 });
+item(I.STAR_PET_ARMOR, 'Starlight Pet Armor', { sprite: 'petarmor', color: [250, 205, 70], stack: 1, petArmor: 0.75 });
+item(I.PET_BACKPACK, 'Pet Backpack', { sprite: 'backpack', color: [200, 80, 70], stack: 1, petBackpack: true });
+export const PET_BAG_SLOTS = 9;
+
// Creative power tools. Shape tools: right-click two points to build, left-click two points to erase.
// They build with the last block you held.
item(I.LINE_WAND, 'Bridge Wand', { sprite: 'wand', color: [255, 220, 90], stack: 1, creativeOnly: true, shape: 'line' });
@@ -124,6 +133,8 @@ mine([B.LANTERN], 0.3);
mine([B.PORTAL_BLUE, B.PORTAL_ORANGE, B.PORTAL_GREEN, B.PORTAL_PURPLE], 0.4);
mine([B.CACTUS], 0.4);
mine(BLOCKS.filter((b) => b?.spark).map((b) => b.id), 0.3);
+mine([B.PET_BED], 0.3);
+mine([B.KENNEL], 1.5, 'axe');
mine(BLOCKS.filter((b) => b?.course).map((b) => b.id), 0.3);
mine([B.WOOL_WHITE, B.WOOL_RED, B.WOOL_BLUE, B.WOOL_YELLOW, B.WOOL_GREEN, B.WOOL_BLACK], 0.8);
@@ -173,6 +184,12 @@ recipe(B.CRAFTING_TABLE, 1, [[B.PLANKS, 4]]);
recipe(I.BREAD, 1, [[I.WHEAT, 3]]);
recipe(I.HOE, 1, [[B.PLANKS, 2], [I.STICK, 2]]);
recipe(I.PARTY_HAT, 1, [[B.WOOL_RED, 1], [B.WOOL_YELLOW, 1]]);
+recipe(I.COZY_PET_COAT, 1, [[B.WOOL_BLUE, 3], [B.WOOL_WHITE, 2]]);
+recipe(I.IRON_PET_ARMOR, 1, [[I.IRON_INGOT, 5]], 'table');
+recipe(I.STAR_PET_ARMOR, 1, [[I.DIAMOND, 2], [I.GOLD_INGOT, 3], [B.STAR, 1]], 'table');
+recipe(I.PET_BACKPACK, 1, [[B.WOOL_RED, 3], [I.IRON_INGOT, 1], [I.STICK, 2]], 'table');
+recipe(B.PET_BED, 1, [[B.WOOL_RED, 2], [B.PLANKS, 2]]);
+recipe(B.KENNEL, 1, [[B.PLANKS, 6], [B.WOOL_RED, 1]], 'table');
recipe(I.CROWN, 1, [[I.GOLD_INGOT, 2]], 'table');
recipe(B.STAR, 1, [[I.GOLD_INGOT, 1], [B.GLASS, 1]], 'table');
recipe(I.WOOD_SWORD, 1, [[B.PLANKS, 2], [I.STICK, 1]], 'table');
@@ -315,6 +332,16 @@ const SPRITES = {
'....########....', '....##dddd##....', '....########....', '....########....', '....########....', '....########....',
'.....######.....', '................', '................', '................',
],
+ petarmor: [
+ '................', '................', '...#########....', '..###########...', '.####dddddd####.', '.###d######d###.',
+ '.###d#yyyy#d###.', '.###d######d###.', '..##dddddddd##..', '..###########...', '...##.#####.##..', '...##.......##..',
+ '................', '................', '................', '................',
+ ],
+ backpack: [
+ '................', '.....dddddd.....', '....d######d....', '...d########d...', '...##########...', '...#dddddddd#...',
+ '...#d######d#...', '...#d#yyyy#d#...', '...#d######d#...', '...#dddddddd#...', '...##########...', '...d########d...',
+ '....dddddddd....', '................', '................', '................',
+ ],
partyhat: [
'.......dd.......', '.......##.......', '......####......', '......#dd#......', '.....######.....', '.....##dd##.....',
'....########....', '....###dd###....', '...##########...', '...####dd####...', '..############..', '................',
diff --git a/src/main.js b/src/main.js
index d872fc0..f31f6db 100644
--- a/src/main.js
+++ b/src/main.js
@@ -11,6 +11,7 @@ import { I, ITEMS, itemIcon, itemName, miningInfo, dropFor, STATION_BLOCK } from
import { Inventory } from './inventory.js';
import { Survival, MAX_HEALTH, MAX_AIR, MAX_HUNGER } from './survival.js';
import { CraftUI } from './craftui.js';
+import { PetUI } from './petui.js';
import { Mobs, TYPES } from './mobs.js';
import { TouchControls, isTouchDevice } from './touch.js';
import { Quests, QUESTS } from './quests.js';
@@ -250,6 +251,11 @@ const together = new Together({
else if (act === 'feed') mobs.feed(mob);
else if (act === 'shear') { const wool = mobs.shear(mob); if (wool != null) together.send({ k: 'give', item: wool, n: 1 + Math.floor(Math.random() * 3) }, from); }
else if (act === 'sit' && mob.tamed) mobs.toggleSit(mob);
+ else if (act === 'gear' && mob.tamed) { // a guest put pet armor or a backpack on one of the host's pets
+ const g = ITEMS.get(acc);
+ if (g?.petArmor) mobs.wearArmor(mob, acc);
+ else if (g?.petBackpack && !mob.bag) mobs.setBackpack(mob, true);
+ }
else if (act === 'wear' && mob.tamed && ['party', 'crown', 'glasses'].includes(acc)) mobs.wear(mob, acc);
dirtySave = true;
},
@@ -660,13 +666,14 @@ function pickerTab(id) {
const def = ITEMS.get(id), blk = id < 256 ? BLOCKS[id] : null;
if (blk) {
if (blk.spark) return 'spark';
+ if (blk.pet) return 'friends';
if (blk.course) return 'fun';
if (blk.plant || NATURE.has(id)) return 'nature';
if (blk.bounce || blk.speed || blk.slippery || blk.fan || blk.note !== undefined || blk.confetti || blk.portal || blk.star || blk.emissive) return 'fun';
return 'build';
}
if (def?.shape || def?.paint || def?.tool || def?.hoe || def?.water || def?.glider || def?.damage || def?.bow || def?.shield || def?.armor) return 'tools';
- if (def?.spawns || def?.accessory || id === I.ROBOT) return 'friends';
+ if (def?.spawns || def?.accessory || def?.petArmor || def?.petBackpack || id === I.ROBOT) return 'friends';
return 'items';
}
let pickerFilter = 'all';
@@ -770,6 +777,29 @@ mobs.onTame = (pet) => {
dirtySave = true;
};
+const petUI = new PetUI({
+ mobs,
+ getInv: () => inv,
+ atlasCanvas: atlas.canvas,
+ isSurvival: () => isSurvival(),
+ getHeld: () => heldItem(),
+ onSit: (pet) => { const r = mobs.toggleSit(pet); toast(sitMessage(pet, r)); dirtySave = true; return r; },
+ onChange: () => { renderHotbar(); dirtySave = true; },
+ toast: (t) => toast(t),
+});
+function sitMessage(pet, r) { return r === 'bed' ? `${pet.petName} is heading to bed 🛏️` : r ? `${pet.petName} is sitting` : `${pet.petName} is following you`; }
+let lastPetHurtToast = 0;
+mobs.onPetHurt = (pet) => {
+ if (performance.now() - lastPetHurtToast < 15000) return;
+ lastPetHurtToast = performance.now();
+ toast(`${pet.petName} got bumped! Pet armor helps, and a pet bed makes it better 🛏️`);
+};
+mobs.onPetFaint = (pet, atBed) => {
+ toast(atBed ? `${pet.petName} was sleepy and went to its bed 💤` : `${pet.petName} needs a rest. Let it sit and recover 💤`);
+ sfx.pop();
+ dirtySave = true;
+};
+
mobs.onBaby = (baby) => {
quests.emit('baby', { type: baby.type });
if (baby.pos.distanceTo(player.pos) < 24) { toast(`A baby ${TYPES[baby.type].name.toLowerCase()} was born!`); sfx.craft(); }
@@ -777,7 +807,7 @@ mobs.onBaby = (baby) => {
};
// ---------- game state & pointer lock ----------
-let state = 'menu'; // 'menu' | 'locking' | 'playing' | 'inventory' | 'craft' | 'dead'
+let state = 'menu'; // 'menu' | 'locking' | 'playing' | 'inventory' | 'craft' | 'pet' | 'dead'
const keys = new Set();
const mouse = { left: false, right: false, nextAction: 0 };
@@ -823,6 +853,15 @@ function openOverlay() {
exitLock();
}
+function openPetPanel(mob) {
+ insights.step('opened pet panel');
+ clearInput();
+ touch?.setEnabled(false);
+ state = 'pet';
+ petUI.open(mob);
+ exitLock();
+}
+
let bookFromMenu = false;
function openQuestBook(fromMenu) {
insights.step('opened quest book');
@@ -930,6 +969,7 @@ function closeOverlay(relock) {
if (bookFromMenu) { state = 'menu'; return; }
}
if (state === 'craft') craftUI.close();
+ if (state === 'pet') petUI.close();
if (relock) enterPlay(); else showMenu();
}
@@ -958,6 +998,7 @@ function startPlaying() {
$('menu').classList.add('hidden');
$('inventory').classList.add('hidden');
$('craft').classList.add('hidden');
+ $('pet').classList.add('hidden');
$('death').classList.add('hidden');
$('hud').classList.remove('hidden');
$('lock-note').textContent = '';
@@ -993,6 +1034,7 @@ upright.addEventListener('change', () => {
$('rotate-back').addEventListener('click', cancelSideways);
$('inv-done').addEventListener('click', () => closeOverlay(true));
$('craft-done').addEventListener('click', () => closeOverlay(true));
+$('pet-done').addEventListener('click', () => closeOverlay(true));
$('qb-done').addEventListener('click', () => closeOverlay(true));
$('btn-quests').addEventListener('click', () => openQuestBook(true));
$('qt-head').addEventListener('click', () => { if (state === 'playing') openQuestBook(false); });
@@ -1228,7 +1270,7 @@ $('acc-delete').addEventListener('click', async () => {
// Every pop-up panel gets a ✕ that is always on screen, and tapping the dimmed area
// outside a panel closes it too. (Phones have no Escape key, and on a small screen the
// Done button can be scrolled out of sight under a long list.)
-for (const [overlay, done] of [['inventory', 'inv-done'], ['craft', 'craft-done'], ['worlds', 'w-done'], ['trade', 'tr-done'], ['questbook', 'qb-done'], ['together', 'tg-close'], ['account', 'acc-done'], ['gate', 'gate-cancel'], ['photo', 'ph-close'], ['report', 'report-done']]) {
+for (const [overlay, done] of [['inventory', 'inv-done'], ['craft', 'craft-done'], ['pet', 'pet-done'], ['worlds', 'w-done'], ['trade', 'tr-done'], ['questbook', 'qb-done'], ['together', 'tg-close'], ['account', 'acc-done'], ['gate', 'gate-cancel'], ['photo', 'ph-close'], ['report', 'report-done']]) {
const ov = $(overlay);
const x = document.createElement('button');
x.type = 'button'; x.className = 'x-close'; x.textContent = '✕'; x.setAttribute('aria-label', 'Close');
@@ -1570,7 +1612,7 @@ document.addEventListener('keydown', (e) => {
if (e.code === 'Escape' || e.code === 'KeyP') closePhoto();
return;
}
- if (state === 'robot' || state === 'trade') {
+ if (state === 'robot' || state === 'trade' || state === 'pet') {
if (e.code === 'Escape') closeOverlay(false);
return;
}
@@ -2000,6 +2042,8 @@ function guestMobAction(mob, held) {
if (mouse.left) { mobs.effect(mob, mobs.happyMat); mobs.voice(mob); ask('pat'); quests.emit('pat', { type: mob.type }); return; }
const acc = ITEMS.get(held)?.accessory;
if (mob.tamed && acc) { ask('wear', { acc }); if (isSurvival()) { inv.takeFromSlot(selected, 1); renderHotbar(); } quests.emit('accessory', { kind: acc }); return; }
+ const pg = ITEMS.get(held);
+ if (mob.tamed && (pg?.petArmor || pg?.petBackpack)) { ask('gear', { acc: held }); if (isSurvival()) { inv.takeFromSlot(selected, 1); renderHotbar(); } quests.emit('petgear', { kind: pg.petArmor ? 'armor' : 'backpack' }); return; }
if (mob.tamed && held !== I.APPLE) { ask('sit'); return; }
if (held === I.APPLE) { ask('feed'); mobs.effect(mob, mobs.heartMat); if (isSurvival()) { inv.takeFromSlot(selected, 1); renderHotbar(); } return; }
if (mob.type === 'sheep' && !mob.sheared) { ask('shear'); quests.emit('shear', {}); }
@@ -2035,9 +2079,30 @@ function actMob(now) {
}
return;
}
+ const gear = ITEMS.get(held);
+ if (mob.tamed && gear?.petArmor) {
+ const prev = mobs.wearArmor(mob, held);
+ if (isSurvival()) { inv.takeFromSlot(selected, 1); if (prev) inv.add(prev, 1); renderHotbar(); }
+ toast(`${mob.petName} looks tough! 🛡️`);
+ quests.emit('petgear', { kind: 'armor' });
+ tip('petgear', 'Right-click a pet that wears armor or a backpack to open its panel.');
+ dirtySave = true;
+ return;
+ }
+ if (mob.tamed && gear?.petBackpack) {
+ if (mob.bag) { toast(`${mob.petName} already has a backpack`); return; }
+ mobs.setBackpack(mob, true);
+ if (isSurvival()) { inv.takeFromSlot(selected, 1); renderHotbar(); }
+ toast(`${mob.petName} can carry things for you now! 🎒`);
+ quests.emit('petgear', { kind: 'backpack' });
+ tip('petgear', 'Right-click a pet that wears armor or a backpack to open its panel.');
+ dirtySave = true;
+ return;
+ }
+ if (mob.tamed && held !== I.APPLE && (mob.bag || mob.armor)) { openPetPanel(mob); return; }
if (mob.tamed && held !== I.APPLE) {
const sits = mobs.toggleSit(mob);
- toast(sits ? `${mob.petName} is sitting` : `${mob.petName} is following you`);
+ toast(sitMessage(mob, sits));
dirtySave = true;
return;
}
@@ -2468,14 +2533,14 @@ $('btn-install').addEventListener('click', () => {
// Expose for debugging in the console.
window.minicrafter = {
get world() { return world; }, get player() { return player; }, get target() { return target; },
- get inv() { return inv; }, adv, projectiles, spark, together, account, course, photo, insights, openPhoto, closePhoto, get state() { return state; }, placeFacing, lightLevel, hurtPlayer, bow, gainXp, isAdventure, createWorld, history, tool, undoRedo, crops, waterAt, critters, findPortals, get fireflyTarget() { return fireflyTarget; }, worlds, get currentWorldId() { return currentWorldId; }, openWorld, get mobTarget() { return mobTarget; }, get robotTarget() { return robotTarget; }, survival, mobs, quests, robot, robotUI, keys, mouse, save, setMode,
+ get inv() { return inv; }, adv, projectiles, spark, together, account, course, photo, insights, openPhoto, closePhoto, get state() { return state; }, placeFacing, lightLevel, hurtPlayer, bow, gainXp, isAdventure, createWorld, history, tool, undoRedo, crops, waterAt, critters, findPortals, get fireflyTarget() { return fireflyTarget; }, worlds, get currentWorldId() { return currentWorldId; }, openWorld, get mobTarget() { return mobTarget; }, openPetPanel, get robotTarget() { return robotTarget; }, survival, mobs, quests, robot, robotUI, keys, mouse, save, setMode,
select: (i) => select(i),
openOverlay: () => openOverlay(),
/** Dev/test helper: enter play mode without pointer lock (for automated testing). */
forcePlay() {
state = 'playing'; hasPlayed = true;
$('menu').classList.add('hidden'); $('hud').classList.remove('hidden');
- $('craft').classList.add('hidden'); $('inventory').classList.add('hidden');
+ $('craft').classList.add('hidden'); $('inventory').classList.add('hidden'); $('pet').classList.add('hidden');
touch?.setEnabled(true);
},
setTime(t) { timeOfDay = t; },
diff --git a/src/mobs.js b/src/mobs.js
index aa27308..724fd9f 100644
--- a/src/mobs.js
+++ b/src/mobs.js
@@ -2,7 +2,8 @@
// patted, fed apples (two in love make a baby), and sheep can be sheared.
// Nothing here can hurt the player and animals can't be hurt either.
import * as THREE from 'three';
-import { B, SOLID } from './blocks.js';
+import { B, BLOCKS, SOLID } from './blocks.js';
+import { ITEMS, I, PET_BAG_SLOTS } from './items.js';
import { CS } from './world.js';
import { villagesNear, JOB_INFO } from './villages.js';
@@ -35,6 +36,10 @@ export const TYPES = {
sporeling: { name: 'Sporeling', plural: 'Sporelings', hw: 0.3, h: 1.2, speed: 1.5, hostile: true, ranged: true, hp: 8, dmg: 2 },
};
const MAX_HOSTILE = 8;
+export const PET_MAX_HP = 12; // pets never get lost: at 0 they faint and wake up at their bed (or by you)
+const PET_REGEN = 0.04; // hit points per second just walking about
+const PET_REST_REGEN = 0.6; // ...and while resting next to a bed or doghouse
+const BED_SEARCH = 8; // "sit" sends a pet to a bed this close
// ---------- model building ----------
const SHADE = [0.8, 0.8, 1.0, 0.55, 0.68, 0.68]; // +x -x +y -y +z -z (BoxGeometry face order)
@@ -258,6 +263,9 @@ export class Mobs {
this.maxHostile = MAX_HOSTILE;
this.canSpawnMonster = null; // (x, y, z) -> bool (is it dark enough?)
this.onAttack = null; // (mob, damage)
+ this.onPetHurt = null; // (pet)
+ this.onPetFaint = null; // (pet, atBed)
+ this.lastPlayer = null;
this.onShoot = null; // (mob)
this.onPoof = null; // (mob, cause)
this.monsterTimer = 0;
@@ -297,11 +305,16 @@ export class Mobs {
kept: !!opts.kept, // bred, fed or spawned by the player: never despawns
soundTimer: 4 + Math.random() * 10, hop: 0,
tamed: false, sitting: !!opts.sitting, petName: null, tag: null, wag: 0,
+ petHp: opts.petHp ?? PET_MAX_HP, armor: 0, bag: null, bed: opts.bed || null, toBed: null, restCheck: 0, resting: false,
job: opts.job || null, home: opts.home || null, villagerName: opts.villagerName || null,
hostile, hp: TYPES[type].hp || 0, mat, flash: 0, attackCd: 1, shootCd: 2 + Math.random() * 2,
};
mob.targetYaw = mob.yaw;
- if (opts.tamed) this.tame(mob, opts.petName);
+ if (opts.tamed) {
+ this.tame(mob, opts.petName);
+ if (ITEMS.get(opts.armor)?.petArmor) this.wearArmor(mob, opts.armor, true);
+ if (Array.isArray(opts.bag)) { this.setBackpack(mob, true, true); this.loadBag(mob, opts.bag); }
+ }
if (type === 'villager') {
mob.tag = nameTag(`${mob.villagerName} the ${JOB_INFO[mob.job]?.title || 'Villager'}`);
mob.tag.position.set(0, TYPES.villager.h + 0.3, 0);
@@ -362,6 +375,7 @@ export class Mobs {
if (!this.world) return;
this.mat.color.setScalar(light);
if (this.puppet) { this.updatePuppets(dt); return; }
+ this.lastPlayer = player;
const W = this.world;
// Night creatures: only in Adventure, only in the dark, and they poof in sunlight.
@@ -396,7 +410,8 @@ export class Mobs {
for (const mob of this.list) {
const d = Math.hypot(mob.pos.x - player.pos.x, mob.pos.z - player.pos.z);
- if (mob.tamed && !mob.sitting && d > 20) this.teleportToPlayer(mob, player);
+ if (mob.tamed) this.petTick(mob, dt, player);
+ if (mob.tamed && !mob.sitting && !mob.toBed && d > 20) this.teleportToPlayer(mob, player);
if (d > ACTIVE_DIST || !this.isLoaded(mob.pos.x, mob.pos.z)) continue;
this.think(mob, dt, player);
@@ -430,7 +445,10 @@ export class Mobs {
this.move(mob, 'x', px / pd * (minD - pd) * 0.5);
this.move(mob, 'z', pz / pd * (minD - pd) * 0.5);
}
- if (mob.pos.y < -10) { this.remove(mob); continue; }
+ if (mob.pos.y < -10) {
+ if (mob.tamed) { if (!this.teleportToPlayer(mob, player)) mob.pos.set(player.pos.x, player.pos.y + 1, player.pos.z); mob.vel.set(0, 0, 0); } // a pet (and its backpack) is never lost
+ else { this.remove(mob); continue; }
+ }
// Animation
let dy = mob.targetYaw - mob.yaw;
@@ -510,6 +528,7 @@ export class Mobs {
// Pets: sit when asked, otherwise follow their owner.
if (mob.tamed) {
+ if (mob.toBed) { this.walkToBed(mob, dt); return; }
if (mob.sitting) { mob.walking = false; return; }
const d = Math.hypot(player.pos.x - mob.pos.x, player.pos.z - mob.pos.z);
if (d > 3.2) {
@@ -623,9 +642,12 @@ export class Mobs {
} else {
mob.walking = d > 0.9;
if (mob.walking && mob.onGround && Math.random() < dt * 3) mob.vel.y = 5.5; // hop hop
- if (d < this.size(mob).hw + 0.9 && Math.abs(dy) < 1.6 && mob.attackCd <= 0) {
- mob.attackCd = 1.1;
- this.onAttack?.(mob, t.dmg);
+ const reach = this.size(mob).hw + 0.9;
+ if (mob.attackCd <= 0) {
+ const pet = this.list.find((p) => p.tamed && Math.hypot(p.pos.x - mob.pos.x, p.pos.z - mob.pos.z) < reach && Math.abs(p.pos.y - mob.pos.y) < 1.6);
+ const meHit = d < reach && Math.abs(dy) < 1.6;
+ if (meHit && (!pet || Math.random() < 0.6)) { mob.attackCd = 1.1; this.onAttack?.(mob, t.dmg); }
+ else if (pet) { mob.attackCd = 1.1; this.hurtPet(pet, t.dmg); }
}
}
mob.soundTimer -= dt;
@@ -798,13 +820,150 @@ export class Mobs {
return true;
}
+ /** Sit / follow. Returns false (now following), true (sitting) or 'bed' (walking to its bed). */
toggleSit(mob) {
if (!mob.tamed) return false;
- mob.sitting = !mob.sitting;
mob.walking = false;
mob.wag = 1;
this.voice(mob);
- return mob.sitting;
+ if (mob.sitting || mob.toBed) { mob.sitting = false; mob.toBed = null; return false; }
+ const bed = this.findBed(mob.pos, BED_SEARCH);
+ if (bed) { mob.bed = [bed.x, bed.y, bed.z]; mob.toBed = { ...bed, t: 0 }; for (let i = 0; i < 2; i++) this.effect(mob, this.heartMat); return 'bed'; }
+ mob.sitting = true;
+ return true;
+ }
+
+ // ---------- pet upgrades: beds, health, armor, backpack ----------
+ /** Nearest pet bed or doghouse within r blocks of pos, or null. */
+ findBed(pos, r) {
+ const W = this.world;
+ const cx = Math.floor(pos.x), cy = Math.floor(pos.y), cz = Math.floor(pos.z);
+ if (!this.isLoaded(pos.x, pos.z)) return null;
+ const n = Math.ceil(r);
+ let best = null, bd = Infinity;
+ for (let y = cy - 1; y <= cy + 1; y++) for (let z = cz - n; z <= cz + n; z++) for (let x = cx - n; x <= cx + n; x++) {
+ if (!BLOCKS[W.getBlock(x, y, z)]?.pet) continue;
+ const d = Math.hypot(x + 0.5 - pos.x, z + 0.5 - pos.z);
+ if (d <= r && d < bd) { bd = d; best = { x, y, z }; }
+ }
+ return best;
+ }
+
+ /** Where a pet stands to use the bed at b (on a flat bed, or on top of a doghouse). */
+ bedSpot(b) {
+ const blk = BLOCKS[this.world.getBlock(b.x, b.y, b.z)];
+ if (!blk?.pet) return null;
+ return new THREE.Vector3(b.x + 0.5, b.y + (blk.solid ? 1 : 0.1), b.z + 0.5);
+ }
+
+ walkToBed(mob, dt) {
+ const b = mob.toBed, spot = this.bedSpot(b);
+ if (!spot) { mob.toBed = null; mob.sitting = true; mob.walking = false; return; } // bed was picked up
+ b.t += dt;
+ const d = Math.hypot(spot.x - mob.pos.x, spot.z - mob.pos.z);
+ const solid = spot.y - b.y > 0.5;
+ if (d <= (solid ? 1.5 : 0.35) || b.t > 10) {
+ if (d > (solid ? 1.5 : 0.35) && !this.collides(mob, spot)) { mob.pos.copy(spot); mob.vel.set(0, 0, 0); } // took too long: hop in
+ mob.toBed = null; mob.sitting = true; mob.walking = false; mob.wag = 1.5;
+ this.effect(mob, this.happyMat);
+ return;
+ }
+ mob.targetYaw = Math.atan2(spot.x - mob.pos.x, spot.z - mob.pos.z);
+ mob.walking = true; mob.timer = 0.5;
+ }
+
+ /** Slow healing, faster while resting by a bed. */
+ petTick(mob, dt, player) {
+ if (mob.petHp >= PET_MAX_HP) { mob.resting = false; return; }
+ mob.restCheck -= dt;
+ if (mob.restCheck <= 0) { mob.restCheck = 1; mob.resting = mob.sitting && !!this.findBed(mob.pos, 2.5); }
+ mob.petHp = Math.min(PET_MAX_HP, mob.petHp + (mob.resting ? PET_REST_REGEN : PET_REGEN) * dt);
+ if (mob.resting && Math.random() < dt * 0.7) this.effect(mob, this.heartMat);
+ }
+
+ /** A night creature bumped a pet. Armor soaks up part of it. Pets never die: at 0 they faint. */
+ hurtPet(mob, dmg) {
+ if (!mob.tamed || this.puppet) return;
+ const cut = ITEMS.get(mob.armor)?.petArmor || 0;
+ mob.petHp -= Math.max(0.5, dmg * (1 - cut));
+ this.voice(mob);
+ this.onPetHurt?.(mob);
+ if (mob.petHp <= 0) this.faint(mob);
+ }
+
+ /** Too bumped to carry on: wakes up resting at its bed (or beside you) with a few hit points. */
+ faint(mob) {
+ mob.petHp = 3; mob.toBed = null; mob.sitting = true; mob.walking = false;
+ const spot = mob.bed ? this.bedSpot({ x: mob.bed[0], y: mob.bed[1], z: mob.bed[2] }) : null;
+ const atBed = !!spot && !this.collides(mob, spot);
+ if (atBed) { mob.pos.copy(spot); mob.vel.set(0, 0, 0); }
+ else if (this.lastPlayer) this.teleportToPlayer(mob, this.lastPlayer);
+ this.onPetFaint?.(mob, atBed);
+ }
+
+ /** Puts pet armor on (returns the item id of the armor it was wearing before, or 0). */
+ wearArmor(mob, id, quiet = false) {
+ const def = ITEMS.get(id);
+ if (!mob.tamed || !def?.petArmor) return null;
+ const prev = mob.armor || 0;
+ this.dropGear(mob, 'armorMesh');
+ mob.armor = id;
+ mob.armorMesh = this.gearMesh(mob, 'armor', def.color);
+ mob.group.add(mob.armorMesh);
+ if (!quiet) { this.effect(mob, this.happyMat); mob.wag = 2; this.voice(mob); }
+ return prev;
+ }
+
+ /** Takes pet armor off; returns its item id (or 0). */
+ removeArmor(mob) {
+ const id = mob.armor || 0;
+ this.dropGear(mob, 'armorMesh'); mob.armor = 0;
+ return id;
+ }
+
+ /** Adds or removes the backpack (and its 9 slots). */
+ setBackpack(mob, on, quiet = false) {
+ if (!mob.tamed) return false;
+ this.dropGear(mob, 'bagMesh');
+ if (on) {
+ mob.bag = mob.bag || new Array(PET_BAG_SLOTS).fill(null);
+ mob.bagMesh = this.gearMesh(mob, 'bag', ITEMS.get(I.PET_BACKPACK).color);
+ mob.group.add(mob.bagMesh);
+ if (!quiet) { this.effect(mob, this.happyMat); mob.wag = 2; this.voice(mob); }
+ } else mob.bag = null;
+ return true;
+ }
+
+ loadBag(mob, arr) {
+ if (!mob.bag) return;
+ arr.slice(0, PET_BAG_SLOTS).forEach((s, i) => {
+ if (Array.isArray(s) && ITEMS.has(s[0]) && s[1] > 0) mob.bag[i] = { id: s[0], count: Math.min(Math.floor(s[1]), ITEMS.get(s[0]).stack ?? 64) };
+ });
+ }
+
+ dropGear(mob, key) {
+ if (!mob[key]) return;
+ mob.group.remove(mob[key]);
+ mob[key].traverse((o) => o.geometry?.dispose());
+ mob[key] = null;
+ }
+
+ /** Little blocky armor plate or backpack that sits on the pet's back (sizes depend on dog or cat). */
+ gearMesh(mob, kind, rgb) {
+ const dog = mob.type === 'dog';
+ const trim = kind === 'armor' && mob.armor === I.STAR_PET_ARMOR ? [255, 245, 190] : rgb.map((v) => Math.min(255, v + 40));
+ const dark = rgb.map((v) => v * 0.6);
+ let geo;
+ if (kind === 'armor') {
+ geo = dog
+ ? merge([box(0.46, 0.24, 0.5, rgb, 0, 0.6, -0.04), box(0.47, 0.05, 0.1, trim, 0, 0.6, 0.15), box(0.3, 0.2, 0.05, rgb, 0, 0.5, 0.43), box(0.1, 0.06, 0.1, trim, 0, 0.74, -0.04)])
+ : merge([box(0.36, 0.19, 0.4, rgb, 0, 0.46, -0.04), box(0.37, 0.04, 0.08, trim, 0, 0.46, 0.1), box(0.22, 0.15, 0.05, rgb, 0, 0.38, 0.33), box(0.08, 0.05, 0.08, trim, 0, 0.57, -0.04)]);
+ } else {
+ geo = dog
+ ? merge([box(0.3, 0.26, 0.22, rgb, 0, 0.88, -0.14), box(0.32, 0.06, 0.24, dark, 0, 1.0, -0.14), box(0.08, 0.08, 0.02, [255, 205, 70], 0, 0.9, -0.26)])
+ : merge([box(0.24, 0.22, 0.2, rgb, 0, 0.68, -0.12), box(0.26, 0.05, 0.22, dark, 0, 0.78, -0.12), box(0.07, 0.07, 0.02, [255, 205, 70], 0, 0.7, -0.23)]);
+ }
+ return new THREE.Mesh(geo, this.mat);
}
teleportToPlayer(mob, player) {
@@ -841,7 +1000,7 @@ export class Mobs {
for (const m of this.list) {
if (m.hostile || !centers.some((c) => Math.abs(m.pos.x - c.x) < radius && Math.abs(m.pos.z - c.z) < radius)) continue;
const flags = (m.baby ? 1 : 0) | (m.sheared ? 2 : 0) | (m.tamed ? 4 : 0) | (m.sitting ? 8 : 0) | (m.walking ? 16 : 0);
- out.push([m.id, m.type, +m.pos.x.toFixed(2), +m.pos.y.toFixed(2), +m.pos.z.toFixed(2), +m.yaw.toFixed(2), flags, m.woolColor ?? 0, m.accessory || 0, m.petName || 0, m.job || 0, m.villagerName || 0]);
+ out.push([m.id, m.type, +m.pos.x.toFixed(2), +m.pos.y.toFixed(2), +m.pos.z.toFixed(2), +m.yaw.toFixed(2), flags, m.woolColor ?? 0, m.accessory || 0, m.petName || 0, m.job || 0, m.villagerName || 0, m.armor || 0, m.bag ? 1 : 0]);
}
return out;
}
@@ -870,6 +1029,11 @@ export class Mobs {
if (m.baby !== baby) { m.baby = baby; this.applyScale(m); }
if (tamed && !m.tamed) this.tame(m, petName);
if (a[8] && a[8] !== m.accessory && ['party', 'crown', 'glasses'].includes(a[8])) this.wear(m, a[8]);
+ if (m.tamed) { // armor and backpack are just looks on a guest's screen; the contents stay with the host
+ const arm = ITEMS.get(a[12])?.petArmor ? a[12] : 0;
+ if (arm !== m.armor) { if (arm) this.wearArmor(m, arm, true); else this.removeArmor(m); }
+ if (!!a[13] !== !!m.bag) this.setBackpack(m, !!a[13], true);
+ }
}
for (const m of [...this.list]) if (!seen.has(m.id)) this.remove(m);
}
@@ -908,6 +1072,8 @@ export class Mobs {
t: m.type, x: +m.pos.x.toFixed(2), y: +m.pos.y.toFixed(2), z: +m.pos.z.toFixed(2), yaw: +m.yaw.toFixed(2),
baby: m.baby, age: Math.round(m.age), sheared: m.sheared, regrow: Math.round(m.regrow), wool: m.woolColor,
tamed: m.tamed || undefined, sit: m.sitting || undefined, name: m.petName || undefined, acc: m.accessory || undefined,
+ arm: m.armor || undefined, bag: m.bag ? m.bag.map((s) => (s ? [s.id, s.count] : 0)) : undefined,
+ bed: m.bed || undefined, hp: m.tamed && m.petHp < PET_MAX_HP ? +m.petHp.toFixed(1) : undefined,
}));
}
@@ -915,7 +1081,9 @@ export class Mobs {
if (!Array.isArray(arr)) return;
for (const d of arr.slice(0, 64)) {
if (!TYPES[d.t] || !Number.isFinite(d.x)) continue;
- const mob = this.spawn(d.t, d.x, d.y, d.z, { yaw: d.yaw, baby: d.baby, age: d.age, sheared: d.sheared, regrow: d.regrow, woolColor: d.wool ?? undefined, kept: true, tamed: d.tamed, sitting: d.sit, petName: d.name });
+ const mob = this.spawn(d.t, d.x, d.y, d.z, { yaw: d.yaw, baby: d.baby, age: d.age, sheared: d.sheared, regrow: d.regrow, woolColor: d.wool ?? undefined, kept: true, tamed: d.tamed, sitting: d.sit, petName: d.name,
+ armor: d.arm, bag: Array.isArray(d.bag) ? d.bag : undefined, petHp: Number.isFinite(d.hp) ? Math.min(PET_MAX_HP, Math.max(1, d.hp)) : undefined,
+ bed: Array.isArray(d.bed) && d.bed.length === 3 && d.bed.every(Number.isFinite) ? d.bed : undefined });
if (mob && d.acc) this.wear(mob, d.acc);
}
}
diff --git a/src/petui.js b/src/petui.js
new file mode 100644
index 0000000..72b28dc
--- /dev/null
+++ b/src/petui.js
@@ -0,0 +1,138 @@
+// Pet panel: a pet's health, armor and backpack (9 slots), in the same click-to-pick-up style as the
+// crafting screen. Opens when you right-click a pet that wears armor or a backpack.
+import { ITEMS, I, itemIcon, itemName, PET_BAG_SLOTS } from './items.js';
+import { PET_MAX_HP } from './mobs.js';
+
+const $ = (id) => document.getElementById(id);
+
+export class PetUI {
+ /**
+ * @param {object} o
+ * @param {() => import('./inventory.js').Inventory} o.getInv
+ * @param {HTMLCanvasElement} o.atlasCanvas
+ * @param {() => boolean} o.isSurvival creative has no inventory, so the bag is filled from the held item
+ * @param {() => number} o.getHeld id of the selected hotbar item (creative)
+ * @param {(mob) => string|boolean} o.onSit toggles sit/follow, returns the new state
+ * @param {() => void} o.onChange
+ * @param {(text: string) => void} o.toast
+ */
+ constructor(o) {
+ Object.assign(this, o);
+ this.mob = null;
+ this.cursor = null;
+ this.cursorEl = $('cursor-stack');
+ $('pet-armor-off').addEventListener('click', () => this.takeOffArmor());
+ $('pet-bag-off').addEventListener('click', () => this.takeOffBag());
+ $('pet-sit').addEventListener('click', () => { if (this.mob) { this.onSit(this.mob); this.render(); } });
+ }
+
+ icon(id) { return itemIcon(this.atlasCanvas, id); }
+
+ open(mob) { this.mob = mob; $('pet').classList.remove('hidden'); this.render(); }
+
+ close() {
+ if (this.cursor && this.isSurvival()) { // never lose an item held on the cursor
+ let left = this.getInv().add(this.cursor.id, this.cursor.count);
+ for (let i = 0; left > 0 && this.mob?.bag && i < PET_BAG_SLOTS; i++) if (!this.mob.bag[i]) { this.mob.bag[i] = { id: this.cursor.id, count: left }; left = 0; }
+ this.cursor = left > 0 ? { id: this.cursor.id, count: left } : null;
+ }
+ this.cursor = null;
+ this.cursorEl.classList.add('hidden');
+ $('pet').classList.add('hidden');
+ this.mob = null;
+ this.onChange();
+ }
+
+ slotHTML(s) {
+ if (!s) return '';
+ return `
})
${s.count > 1 ? `
${s.count}` : ''}`;
+ }
+
+ render() {
+ const m = this.mob;
+ if (!m) return;
+ $('pet-title').textContent = `${m.petName || 'Your pet'} the ${m.type}`;
+ const full = Math.round(m.petHp / 2), total = PET_MAX_HP / 2;
+ $('pet-hearts').textContent = '❤️'.repeat(full) + '🤍'.repeat(Math.max(0, total - full)) + (m.petHp < PET_MAX_HP ? ' Resting in a pet bed helps!' : '');
+ const def = ITEMS.get(m.armor);
+ $('pet-armor-name').textContent = def ? `${def.name} (blocks ${Math.round(def.petArmor * 100)}% of bumps)` : 'No armor. Right-click your pet holding pet armor.';
+ $('pet-armor-icon').innerHTML = def ? `
})
` : '';
+ $('pet-armor-off').classList.toggle('hidden', !def);
+ $('pet-sit').textContent = m.sitting || m.toBed ? 'Come with me' : 'Sit / go to bed';
+ $('pet-bag-wrap').classList.toggle('hidden', !m.bag);
+ if (m.bag) this.fill($('pet-bag'), m.bag, 0, PET_BAG_SLOTS);
+ const surv = this.isSurvival();
+ $('pet-inv-wrap').classList.toggle('hidden', !surv || !m.bag);
+ if (surv && m.bag) {
+ const inv = this.getInv();
+ this.fill($('pet-backpack'), inv.slots, 9, 36);
+ this.fill($('pet-hotbar'), inv.slots, 0, 9);
+ }
+ $('pet-note').textContent = !m.bag ? 'Give your pet a Pet Backpack to carry 9 stacks of stuff for you.'
+ : surv ? 'Click an item to pick it up, then click a slot to put it down.'
+ : 'Creative: click an empty slot to add the item you are holding, or a full slot to clear it.';
+ if (this.cursor) { this.cursorEl.innerHTML = this.slotHTML(this.cursor); this.cursorEl.classList.remove('hidden'); } else this.cursorEl.classList.add('hidden');
+ }
+
+ fill(container, arr, from, to) {
+ container.innerHTML = '';
+ for (let i = from; i < to; i++) {
+ const d = document.createElement('div');
+ d.className = 'slot';
+ d.innerHTML = this.slotHTML(arr[i]);
+ d.addEventListener('mousedown', (e) => { e.preventDefault(); this.click(arr, i, e.button === 2); });
+ container.appendChild(d);
+ }
+ }
+
+ click(arr, i, right) {
+ if (!this.isSurvival()) { // creative: no stock to move around
+ if (arr !== this.mob.bag) return;
+ if (arr[i]) arr[i] = null;
+ else { const id = this.getHeld(); if (ITEMS.has(id)) arr[i] = { id, count: Math.min(ITEMS.get(id).stack ?? 64, 16) }; }
+ this.render(); this.onChange();
+ return;
+ }
+ const s = arr[i], c = this.cursor;
+ const max = (id) => ITEMS.get(id)?.stack ?? 64;
+ if (!c) {
+ if (!s) return;
+ if (right && s.count > 1) { const half = Math.ceil(s.count / 2); this.cursor = { id: s.id, count: half }; s.count -= half; }
+ else { this.cursor = s; arr[i] = null; }
+ } else if (!s) {
+ if (right) { arr[i] = { id: c.id, count: 1 }; c.count--; if (!c.count) this.cursor = null; }
+ else { arr[i] = c; this.cursor = null; }
+ } else if (s.id === c.id) {
+ const n = Math.min(max(s.id) - s.count, right ? 1 : c.count);
+ s.count += n; c.count -= n;
+ if (!c.count) this.cursor = null;
+ } else { arr[i] = c; this.cursor = s; }
+ this.render(); this.onChange();
+ }
+
+ takeOffArmor() {
+ const m = this.mob;
+ if (!m?.armor) return;
+ const id = m.armor;
+ if (this.isSurvival() && !this.getInv().canFit(id, 1)) { this.toast('Your inventory is full'); return; }
+ this.mobs.removeArmor(m);
+ if (this.isSurvival()) this.getInv().add(id, 1);
+ this.render(); this.onChange();
+ }
+
+ takeOffBag() {
+ const m = this.mob;
+ if (!m?.bag) return;
+ const inv = this.getInv(), surv = this.isSurvival();
+ if (surv) {
+ // Everything has to fit back in your pockets: the pet never drops or loses anything.
+ const spare = inv.slots.filter((s) => !s).length;
+ const stacks = m.bag.filter(Boolean).length;
+ if (spare < stacks + 1 && !(stacks === 0 && inv.canFit(I.PET_BACKPACK, 1))) { this.toast('Make some room in your inventory first'); return; }
+ for (let i = 0; i < PET_BAG_SLOTS; i++) { const s = m.bag[i]; if (s) { inv.add(s.id, s.count); m.bag[i] = null; } }
+ inv.add(I.PET_BACKPACK, 1);
+ }
+ this.mobs.setBackpack(m, false);
+ this.render(); this.onChange();
+ }
+}
diff --git a/src/quests.js b/src/quests.js
index baeb5dd..14ceffc 100644
--- a/src/quests.js
+++ b/src/quests.js
@@ -41,6 +41,8 @@ export const QUESTS = [
{ id: 'baby', track: 'all', icon: '🍼', title: 'Animal Family', text: 'Feed apples to two animals of the same kind and watch what happens.', event: 'baby', count: 1, stars: 3 },
{ id: 'firefly', track: 'all', icon: '✨', title: 'Firefly Catcher', text: 'At night, fireflies blink over the grass. Click or tap 3 of them to catch them in glowing lanterns.', event: 'firefly', count: 3, stars: 2 },
{ id: 'hat', track: 'all', icon: '🎩', title: 'Party Time', text: 'Give your pet a Party Hat, Tiny Crown or Sunglasses (right-click your pet while holding it).', event: 'accessory', count: 1, stars: 2 },
+ { id: 'petgear', track: 'all', icon: '🎒', title: 'Pet Gear', text: 'Craft pet armor or a Pet Backpack, then right-click your pet while holding it. A pet with a backpack can carry things for you!', event: 'petgear', count: 1, stars: 2 },
+ { id: 'petbed', track: 'all', icon: '🛏️', title: 'Cosy Corner', text: 'Place a Pet Bed or a Doghouse, then right-click your pet near it. It will walk over and rest there.', event: 'place', test: (d) => d.id === B.PET_BED || d.id === B.KENNEL, count: 1, stars: 2 },
{ id: 'star', track: 'all', icon: '⭐', title: 'Treasure Hunter', text: 'Someone hides a Hidden Star block somewhere (in a maze or a castle). Find it and click it!', event: 'star', count: 1, stars: 2 },
{ id: 'portal', track: 'all', icon: '🌀', title: 'Portal Jumper', text: 'Place two portals of the same colour, then walk into one. Where do you pop out?', event: 'portal', count: 1, stars: 2 },
{ id: 'torch', track: 'all', icon: '🔦', title: 'Light the Way', text: 'Place 5 torches to light up a dark cave. Make torches from a stick and coal.', event: 'place', test: (d) => d.id === B.TORCH, count: 5, stars: 2 },
diff --git a/src/textures.js b/src/textures.js
index acc5eab..1c9a2ae 100644
--- a/src/textures.js
+++ b/src/textures.js
@@ -27,6 +27,7 @@ export const TILE = {
SPARK_LAMP: 89, SPARK_LAMP_ON: 90, SPARK_DOOR: 91, SPARK_DOOR_OPEN: 92,
PISTON_FRONT: 93, PISTON_SIDE: 94, PISTON_BACK: 95, PISTON_INNER: 96,
COURSE_START: 97, COURSE_CHECK: 98, COURSE_FINISH: 99, COIN: 100, COIN_TAKEN: 101, PAD_SIDE: 102,
+ PET_BED: 103, KENNEL_TOP: 104, KENNEL_SIDE: 105,
};
/** Rainbow colours for the 8 musical step-stones (do re mi fa sol la ti do). */
@@ -397,6 +398,20 @@ export function createAtlas() {
paint(TILE.PISTON_INNER, (x, y) => (edge(x, y) ? [50, 52, 60] : x >= 6 && x <= 9 && y >= 6 && y <= 9 ? [140, 140, 150] : vary([60, 62, 70], 0.1)));
+ // ---- Pet bed and kennel ----
+ paint(TILE.PET_BED, (x, y) => {
+ if (x < 2 || y < 2 || x > T - 3 || y > T - 3) return vary([150, 105, 60], 0.08); // wooden rim
+ const paw = (x >= 6 && x <= 9 && y >= 8 && y <= 11) || [[4, 6], [7, 5], [10, 5], [12, 6]].some(([px, py]) => Math.abs(x - px) < 1.2 && Math.abs(y - py) < 1.2);
+ return paw ? [255, 235, 240] : vary([225, 90, 120], 0.07); // pink cushion with a paw print
+ });
+ paint(TILE.KENNEL_TOP, (x, y) => (y % 4 === 3 ? [120, 45, 40] : vary([190, 70, 60], 0.08))); // red roof tiles
+ paint(TILE.KENNEL_SIDE, (x, y) => {
+ const dx = x - 7.5, arch = y >= 5 && (Math.abs(dx) < 3.2 && (y >= 8 || Math.hypot(dx, y - 8) < 3.2));
+ if (arch) return [40, 28, 24]; // the doorway
+ if (y < 3) return [120, 45, 40]; // eave
+ return (x % 5 === 0) ? vary([165, 120, 70], 0.06) : vary([205, 160, 100], 0.07);
+ });
+
// Ores: stone + clusters of mineral pixels.
const ore = (tile, color, clusters) => {
copy(TILE.STONE, tile);
diff --git a/src/together.js b/src/together.js
index 5be5ae1..edc019f 100644
--- a/src/together.js
+++ b/src/together.js
@@ -286,7 +286,7 @@ export class Together {
break;
}
case 'emo': if (EMOJI[d.e]) { this.showEmoji(peer, d.e); this.send({ k: 'emo', id, e: d.e }); } break;
- case 'mob': if (Number.isInteger(d.id) && ['pat', 'feed', 'shear', 'sit', 'wear'].includes(d.act)) this.onMobAction?.(d.id, d.act, d.acc, id, peer); break;
+ case 'mob': if (Number.isInteger(d.id) && ['pat', 'feed', 'shear', 'sit', 'wear', 'gear'].includes(d.act)) this.onMobAction?.(d.id, d.act, d.acc, id, peer); break;
default: break;
}
}
diff --git a/style.css b/style.css
index 96f5050..bb0668b 100644
--- a/style.css
+++ b/style.css
@@ -487,3 +487,16 @@ body.touch #quest-tracker { right: calc(max(10px, env(safe-area-inset-right)) +
.report-panel { width: min(420px, 100%); }
.report-choices { display: grid; gap: 6px; margin: 10px 0; }
.report-choices .wide-btn { margin-top: 0; text-align: left; }
+
+/* Pet panel (armor + backpack) */
+.pet-panel { width: min(520px, 100%); }
+.pet-panel h3 { margin: 14px 0 6px; font-size: 1rem; }
+.pet-hearts { margin: 4px 0 10px; font-size: 1.1rem; }
+.pet-armor { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
+.pet-armor .slot { width: 44px; height: 44px; flex: none; }
+.pet-armor .slot img { width: 34px; height: 34px; }
+.pet-actions { display: flex; gap: 10px; margin-top: 14px; flex-wrap: wrap; }
+.pet-panel { max-height: 100%; overflow-y: auto; }
+.pet-panel .slot-grid { grid-template-columns: repeat(9, minmax(0, 50px)); }
+.pet-panel .slot-grid .slot { width: auto; height: auto; aspect-ratio: 1; }
+.pet-panel .slot-grid .slot img { width: 68%; height: auto; }
diff --git a/sw.js b/sw.js
index fd980a0..7084564 100644
--- a/sw.js
+++ b/sw.js
@@ -1,6 +1,6 @@
// Service worker: caches the whole game so it works offline once loaded.
// Bump VERSION whenever files change so players get the update.
-const VERSION = 'minicrafter-v29';
+const VERSION = 'minicrafter-v30';
const CORE = [
'./', './index.html', './style.css', './privacy.html', './terms.html', './legal.css', './features.html', './features.css', './manifest.webmanifest', './site-config.json',
'./icons/icon-192.png', './icons/icon-512.png', './icons/icon-maskable-512.png', './icons/apple-touch-icon.png', './icons/favicon-32.png',
@@ -16,6 +16,7 @@ const CORE = [
'./src/photo.js',
'./src/insights.js',
'./src/craftui.js',
+ './src/petui.js',
'./src/critters.js',
'./src/ideas.js',
'./src/inventory.js',
diff --git a/tests/smoke.mjs b/tests/smoke.mjs
index e5602a8..e9657ff 100644
--- a/tests/smoke.mjs
+++ b/tests/smoke.mjs
@@ -170,6 +170,36 @@ try {
const hit = m.critters.raycastFirefly(new THREE.Vector3(p.pos.x, p.pos.y + 2, p.pos.z), new THREE.Vector3(0, 0, -1), 5);
out.critters = !!frog && dog.accessory === 'party' && hit?.fly === fly;
+ // Pet upgrades: armor cuts damage, backpack contents survive save/load and teleports, beds send pets to rest.
+ const IT = await import('./src/items.js');
+ const cat = m.mobs.spawn('cat', p.pos.x + 2, p.pos.y, p.pos.z + 2, { kept: true, tamed: true });
+ const bare = (() => { const h = cat.petHp; m.mobs.hurtPet(cat, 4); const d = h - cat.petHp; cat.petHp = h; return d; })();
+ m.mobs.wearArmor(cat, IT.I.IRON_PET_ARMOR);
+ const armored = (() => { const h = cat.petHp; m.mobs.hurtPet(cat, 4); const d = h - cat.petHp; cat.petHp = h; return d; })();
+ m.mobs.setBackpack(cat, true);
+ cat.bag[3] = { id: IT.I.DIAMOND, count: 5 };
+ m.mobs.teleportToPlayer(cat, p);
+ const saved = JSON.parse(JSON.stringify(m.mobs.serialize()));
+ const sCat = saved.find((d) => d.t === 'cat' && d.arm === IT.I.IRON_PET_ARMOR);
+ const old = saved.filter((d) => !d.arm).map((d) => ({ ...d, bag: undefined })); // older saves have none of the new fields
+ m.mobs.reset(m.world); m.mobs.load([...old, sCat].filter(Boolean));
+ const cat2 = m.mobs.list.find((q) => q.type === 'cat' && q.armor);
+ const bx = Math.floor(p.pos.x) + 3, bz = Math.floor(p.pos.z), by = Math.floor(p.pos.y);
+ for (let ix = bx - 6; ix <= bx + 1; ix++) for (let iz = bz - 3; iz <= bz + 3; iz++) { m.world.setBlock(ix, by - 1, iz, B.STONE); for (let iy = by; iy < by + 3; iy++) m.world.setBlock(ix, iy, iz, B.AIR); } // a floor to walk on
+ m.world.setBlock(bx, by, bz, B.PET_BED);
+ cat2.pos.set(p.pos.x, p.pos.y, p.pos.z + 1); cat2.sitting = false;
+ const how = m.mobs.toggleSit(cat2);
+ for (let i = 0; i < 400 && cat2.toBed; i++) m.mobs.update(0.05, p, 1, false);
+ const rec = (out) => IT.RECIPES.some((r) => r.out === out);
+ cat2.petHp = 2; cat2.restCheck = 0;
+ for (let i = 0; i < 400; i++) m.mobs.update(0.05, p, 1, false); // 20 seconds resting
+ const hpBefore = cat2.petHp;
+ m.mobs.faint(cat2);
+ out.pets = bare > armored * 1.9 && cat2?.bag?.[3]?.count === 5 && cat2.bag[3].id === IT.I.DIAMOND && how === 'bed'
+ && cat2.sitting && !cat2.toBed && hpBefore > 6 && cat2.petHp === 3
+ && [IT.I.COZY_PET_COAT, IT.I.IRON_PET_ARMOR, IT.I.STAR_PET_ARMOR, IT.I.PET_BACKPACK, B.PET_BED, B.KENNEL].every(rec);
+ out.petsDetail = JSON.stringify({ bare, armored, how, sit: cat2.sitting, toBed: !!cat2.toBed, hpBefore, hp: cat2.petHp, bag: cat2.bag?.[3], pos: cat2.pos.toArray().map((v) => +v.toFixed(2)), bed: [bx, by, bz], found: m.mobs.findBed(cat2.pos, 2.5), resting: cat2.resting, blk: m.world.getBlock(bx, by, bz) });
+
// Phase 4: share links round-trip and reject bad data; portals are found; daily idea shows.
const S = await import('./src/share.js');
const link = await S.makeShareLink({ name: 'CI', seed: 'ci', mode: 'creative' }, { edits: { '0,0': [[100, B.BRICK]] } }, 'http://x/');
@@ -256,6 +286,7 @@ try {
ok(features.tools, 'power tools: shapes, size cap and undo');
ok(features.garden, 'wildflowers generate and watering grows wheat');
ok(features.critters, 'frogs spawn, pets wear hats, fireflies can be targeted');
+ ok(features.pets, 'pet armor cuts damage, backpack survives save/teleport, pets rest in beds, old saves load', features.petsDetail);
ok(features.phase4, 'share links round-trip and reject bad data; portals; daily idea');
ok(features.adventure, 'adventure: XP levels, hunger, tougher falls (gentle modes unchanged)');
ok(features.a2, 'adventure A2: no monsters in gentle modes; arrows and swords defeat them');