diff --git a/CHANGELOG.md b/CHANGELOG.md index d39128b..9c0c1f5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,14 @@ # Changelog +## 0.4.0 + +La Ménagerie and the Critterbook. + +- **La Ménagerie**, the journal: its own menu, opened with `/mobsquad journal` or from the book in the Bunkhouse menu. Each launch critter has a page with its Critterbook number, a half-ridiculous line about it, how to coax it, its special and your best one's level. Locked pages show only their number. +- **Pages open when you meet a critter**: within 10 blocks with a clear line of sight, or when you coax or are given one. You're told, with a link to the journal. Pages are saved in the player's file as `page` lines; files from before 0.4.0 open pages for the critters already in them. +- **Critterbook numbers** for all 88 mobs in Java Edition, in the order each first appeared, from the Minecraft Wiki's history sections. Same-version ties go by first snapshot, then alphabetically. The launch critters: creeper 1, skeleton 3, chicken 9, enderman 15, iron golem 25, fox 62, bee 63, axolotl 69, allay 75. The list ships in the jar as `critterbook.txt`. +- Not yet: spirit coats (the page says they come later) and quest chapters opening pages. + ## 0.3.0 Levels and specials. diff --git a/README.md b/README.md index b811525..64e99fd 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ Coax mobs into critters for Paper: they follow you, fight only hostile mobs, and live safely in a shared Bunkhouse. No client mods. Gotta coax em all... Pokemob! -**Status:** 0.3.0. Critters level up from 1 to 100 and every launch critter has its special. Passed with bots on throwaway Paper 26.1.2 and 26.2 servers (133 checks each). On 26.3 the bots can't use blocks, so only the commands and the coaxing puzzles ran there (52 checks). Bots can't crouch where the server sees it, so the creeper and fox puzzles were tested with a test-only stand-in for crouching; real crouching is untested. The skeleton's longer range and the enderman's teleport out of trouble have no bot test yet. Nothing has been seen in a real game client yet. +**Status:** 0.4.0. La Ménagerie, the journal, with Critterbook numbers. Passed with bots on throwaway Paper 26.1.2 and 26.2 servers (147 checks each). On 26.3 the bots can't use blocks, so the Bunkhouse menu and everything sent out from it didn't run there (65 checks ran). Bots can't crouch where the server sees it, so the creeper and fox puzzles were tested with a test-only stand-in for crouching; real crouching is untested. The skeleton's longer range and the enderman's teleport out of trouble have no bot test yet. Nothing has been seen in a real game client yet, including how the journal looks. ## What it does @@ -19,6 +19,7 @@ Coax mobs into critters for Paper: they follow you, fight only hostile mobs, and - Enderman: right-click it, then swing at a block within 8 blocks, and it fetches it for you. Only blocks an enderman can carry, and only where you could dig yourself, so claims say no. When it's badly hurt, it teleports to you. - Skeleton: covering fire from 15 blocks, reaching further and shooting faster at each milestone. - Iron golem: takes a quarter of any hostile mob's hit on you within 8 blocks, and throws the mobs it hits back. +- **La Ménagerie.** Your journal, with a page for each critter: its Critterbook number, a line about it, how to coax it and its special. A page opens the first time you're within 10 blocks of that critter and can see it, or when you get one. `/mobsquad journal` or the book in the Bunkhouse menu opens it. Critterbook numbers follow the order each mob first appeared in Minecraft Java Edition, so the creeper is No. 1 and the allay No. 75. Every mob in the game has a number already, and the numbers never change. - **Vittles.** Right-click them to perk up a tuckered-out critter on the spot. Craft two from bread, a carrot and sweet berries. - **Bunkhouses.** An admin marks a vault block as a Bunkhouse. Anyone who right-clicks it sees only their own critters. Click one to send it out or call it back. Critters never exist as items, so they can't be dropped, traded or duplicated. - **Following.** A critter out with you walks after you and steps beside you if it's left more than 24 blocks behind. @@ -37,9 +38,10 @@ Settings are in `plugins/MobSquad/config.yml`: worlds where MobSquad is off, the | Command | Who | What it does | | --- | --- | --- | -| `/mobsquad` | everyone | How it works, in three lines. | +| `/mobsquad` | everyone | How it works, in four lines. | | `/mobsquad list` | everyone | Your critters and your Wranglin' level. | | `/mobsquad hints` | everyone | How to coax each critter. | +| `/mobsquad journal` | everyone | Opens La Ménagerie. | | `/mobsquad dinnerbell` | everyone | Gives you a dinnerbell. | | `/mobsquad bunkhouse add` and `remove` | admins | Marks or unmarks the vault you're looking at. | | `/mobsquad give ` | admins | Puts a critter in a player's Bunkhouse. | diff --git a/build.gradle.kts b/build.gradle.kts index 45edca8..db300c1 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -3,7 +3,7 @@ plugins { } group = "com.extantape" -version = "0.3.0" +version = "0.4.0" java { toolchain.languageVersion.set(JavaLanguageVersion.of(25)) diff --git a/docs/decisions.md b/docs/decisions.md index 42a0c9b..ea8d35a 100644 --- a/docs/decisions.md +++ b/docs/decisions.md @@ -26,3 +26,6 @@ Dated decisions for this repo, newest last. - 2026-11-15: the fox waits 5 seconds before fetching a dropped item, so you can still drop something for a friend, and fetches an item only once. Items count as yours when you threw them, broke the block they came from or beat the mob that dropped them. - 2026-11-15: the creeper's blast needs no player within its radius plus 3 blocks, and hits only mobs a critter may fight. Every 6 seconds (0.75 s less per milestone); a plain hit in between. - 2026-11-15: the four "later" parts of specials in the brief (speed eggs, glowing sting, pounce, sharing arrows) wait for a later release. +- 2026-11-15: Critterbook numbers come from the first Java Edition entry in each mob's History section on the Minecraft Wiki, including experimental snapshots (the camel, sniffer, breeze, bogged and creaking first appeared behind experiments). A texture added before the mob doesn't count (piglin, silverfish). Mobs from the same version are ordered by first snapshot, then alphabetically by entity id. The 88 numbered are the mobs the wiki lists as current in Java Edition, without unused, removed, joke, Education or upcoming ones. The list is `src/main/resources/critterbook.txt`; numbers never change, and new mobs get the next numbers. +- 2026-11-15: a page opens when you're within 10 blocks of a living launch critter (anyone's, or wild) and have a clear line of sight, checked every 2 seconds, or when a critter is added to your Bunkhouse. Owning a critter always opens its page. +- 2026-11-15, written by the lead, for the owner's say: the eight page lines other than the creeper's, which is the owner's own (brief, "Voice"). diff --git a/docs/test-audit.md b/docs/test-audit.md index 084bb2a..a714c51 100644 --- a/docs/test-audit.md +++ b/docs/test-audit.md @@ -2,6 +2,14 @@ Kept by this repo's owning session, per `~/Code/CLAUDE.md`, "Test self-audits". Newest first. +## 2026-11-15: 0.4.0 + +- Promises added: README "La Ménagerie", the journal command, CHANGELOG 0.4.0, the Critterbook decisions. +- Covered by unit tests (ModelTest): Critterbook numbers run 1 to 88 with no gaps; the nine launch numbers are pinned so they can't change; page lines round-trip; an older file opens pages for critters already in it. +- Covered by bots (147 checks on 26.1.2 and 26.2, 65 on 26.3; the journal runs on all three): the command opens the journal; a new player's pages are all locked, in Critterbook order; meeting a fox opens and saves its page; a creeper behind a wall and a chicken 25 blocks away aren't met, and the creeper is once the wall goes; getting a critter opens its page; open pages show the critter and locked ones stay hidden; clicking an open page sends a book and a locked one doesn't; nothing can be taken from the journal; the Bunkhouse menu opens it (26.1.2 and 26.2). +- Gaps skipped: what the book pages say and how they look (bots get the book packet but don't render it; the text is plain data in Journal.java); meeting while MobSquad is off in a world (same settings check as the Bunkhouse, covered). +- Gaps for later: spirit coats and quest chapters when they land. + ## 2026-11-15: 0.3.0 - Promises added: README "Levels" and "Specials", the Safety line on the two block-touching specials, CHANGELOG 0.3.0, the new decisions entries. diff --git a/src/main/java/com/extantape/mobsquad/MobSquadPlugin.java b/src/main/java/com/extantape/mobsquad/MobSquadPlugin.java index fafacba..07d819b 100644 --- a/src/main/java/com/extantape/mobsquad/MobSquadPlugin.java +++ b/src/main/java/com/extantape/mobsquad/MobSquadPlugin.java @@ -13,6 +13,7 @@ import com.extantape.mobsquad.world.Posse; import com.extantape.mobsquad.world.Safety; import com.extantape.mobsquad.world.Specials; +import com.extantape.mobsquad.world.Journal; import com.extantape.mobsquad.model.Growth; import com.mojang.brigadier.Command; import com.mojang.brigadier.arguments.IntegerArgumentType; @@ -44,6 +45,7 @@ public final class MobSquadPlugin extends JavaPlugin { private Dinnerbell dinnerbell; private Coaxing coaxing; private Vittles vittles; + private Journal journal; @Override public void onEnable() { @@ -62,7 +64,11 @@ public void onEnable() { var pm = getServer().getPluginManager(); pm.registerEvents(specials, this); pm.registerEvents(new Safety(squads), this); - pm.registerEvents(new BunkhouseMenu(squads, bunkhouses), this); + Journal journal = new Journal(this, squads); + squads.pageOpener((p, s) -> journal.open(p, s, "got")); + this.journal = journal; + pm.registerEvents(journal, this); + pm.registerEvents(new BunkhouseMenu(squads, bunkhouses, journal), this); pm.registerEvents(dinnerbell, this); pm.registerEvents(coaxing, this); pm.registerEvents(vittles, this); @@ -81,6 +87,7 @@ public void onLoad(EntitiesLoadEvent e) { getServer().getScheduler().runTaskTimer(this, posse, Posse.FOLLOW_TICKS, Posse.FOLLOW_TICKS); getServer().getScheduler().runTaskTimer(this, coaxing, Coaxing.PERIOD, Coaxing.PERIOD); getServer().getScheduler().runTaskTimer(this, specials, Specials.PERIOD, Specials.PERIOD); + getServer().getScheduler().runTaskTimer(this, journal, Journal.PERIOD, Journal.PERIOD); getServer().getScheduler().runTaskTimer(this, squads::saveAll, 20L * 300, 20L * 300); getLifecycleManager().registerEventHandler(LifecycleEvents.COMMANDS, e -> e.registrar().register( Commands.literal("mobsquad") @@ -88,6 +95,7 @@ public void onLoad(EntitiesLoadEvent e) { .executes(this::help) .then(Commands.literal("list").executes(this::list)) .then(Commands.literal("hints").executes(this::hints)) + .then(Commands.literal("journal").executes(this::journal)) .then(Commands.literal("dinnerbell").executes(this::giveBell)) .then(Commands.literal("bunkhouse").requires(src -> src.getSender().hasPermission("mobsquad.admin")) .then(Commands.literal("add").executes(c -> bunkhouse(c, true))) @@ -132,6 +140,7 @@ private int help(CommandContext c) { say(c, "MobSquad: coax a mob and it waits in your Bunkhouse. Right-click a Bunkhouse to send critters out and call them back.", NamedTextColor.GOLD); say(c, "/mobsquad list shows your critters. /mobsquad dinnerbell gives you a bell that calls them all home.", NamedTextColor.GRAY); say(c, "/mobsquad hints tells you how to coax each critter. Vittles perk up a tuckered-out critter on the spot.", NamedTextColor.GRAY); + say(c, "/mobsquad journal opens La Ménagerie, with a page for every critter you've met.", NamedTextColor.GRAY); return Command.SINGLE_SUCCESS; } @@ -167,6 +176,15 @@ private int hints(CommandContext c) { return Command.SINGLE_SUCCESS; } + private int journal(CommandContext c) { + if (!(c.getSource().getExecutor() instanceof Player p)) { + say(c, "Only a player has a journal.", NamedTextColor.YELLOW); + return 0; + } + journal.show(p); + return Command.SINGLE_SUCCESS; + } + private int giveBell(CommandContext c) { if (!(c.getSource().getExecutor() instanceof Player p)) { say(c, "Only a player can carry a dinnerbell.", NamedTextColor.YELLOW); diff --git a/src/main/java/com/extantape/mobsquad/Squads.java b/src/main/java/com/extantape/mobsquad/Squads.java index b56985c..3e4206f 100644 --- a/src/main/java/com/extantape/mobsquad/Squads.java +++ b/src/main/java/com/extantape/mobsquad/Squads.java @@ -23,6 +23,7 @@ public final class Squads { private final Map online = new HashMap<>(); private Posse posse; private Settings settings; + private java.util.function.BiConsumer pageOpener; public Squads(Store store, Logger log, Settings settings) { this.store = store; @@ -88,11 +89,17 @@ public void addWranglin(Player p, long xp) { if (after > before) p.sendMessage(Component.text("Your Wranglin' is now level " + after + ".", NamedTextColor.GOLD)); } + /** Called when a player gets a critter whose La Ménagerie page they haven't opened. */ + public void pageOpener(java.util.function.BiConsumer opener) { + this.pageOpener = opener; + } + public void add(Player p, Critter c) { Wrangler w = get(p); if (w == null) return; w.critters.add(c); save(w); + if (!w.pages.contains(c.species()) && pageOpener != null) pageOpener.accept(p, c.species()); } /** Experience for a critter that's out; tells its owner when it levels up or passes a milestone. */ diff --git a/src/main/java/com/extantape/mobsquad/model/Critterbook.java b/src/main/java/com/extantape/mobsquad/model/Critterbook.java new file mode 100644 index 0000000..a986508 --- /dev/null +++ b/src/main/java/com/extantape/mobsquad/model/Critterbook.java @@ -0,0 +1,54 @@ +package com.extantape.mobsquad.model; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.nio.charset.StandardCharsets; +import java.util.Collections; +import java.util.LinkedHashMap; +import java.util.Map; + +/** + * Critterbook numbers (brief, "La Ménagerie"): every mob in Java Edition in the order it first appeared, read from + * {@code critterbook.txt} in the jar. Numbers never change. + */ +public final class Critterbook { + private static final Map NUMBERS = load(); + + private Critterbook() {} + + private static Map load() { + Map m = new LinkedHashMap<>(); + try (InputStream in = Critterbook.class.getResourceAsStream("/critterbook.txt")) { + if (in == null) throw new IllegalStateException("critterbook.txt is missing from the jar"); + BufferedReader r = new BufferedReader(new InputStreamReader(in, StandardCharsets.UTF_8)); + for (String line; (line = r.readLine()) != null; ) { + int hash = line.indexOf('#'); + String s = (hash < 0 ? line : line.substring(0, hash)).strip(); + if (s.isEmpty()) continue; + String[] p = s.split("\\s+"); + m.put(p[1], Integer.parseInt(p[0])); + } + } catch (IOException e) { + throw new IllegalStateException("couldn't read critterbook.txt", e); + } + return Collections.unmodifiableMap(m); + } + + /** Every numbered mob, entity id to number, in number order. */ + public static Map all() { + return NUMBERS; + } + + public static int number(Species s) { + return NUMBERS.get(s.id()); + } + + /** Launch critters in Critterbook order. */ + public static java.util.List inOrder() { + java.util.List l = new java.util.ArrayList<>(java.util.List.of(Species.values())); + l.sort(java.util.Comparator.comparingInt(Critterbook::number)); + return l; + } +} diff --git a/src/main/java/com/extantape/mobsquad/model/Wrangler.java b/src/main/java/com/extantape/mobsquad/model/Wrangler.java index cb9f754..0f6a441 100644 --- a/src/main/java/com/extantape/mobsquad/model/Wrangler.java +++ b/src/main/java/com/extantape/mobsquad/model/Wrangler.java @@ -9,6 +9,8 @@ public final class Wrangler { public final UUID player; public long wranglinXp; public final List critters = new ArrayList<>(); + /** The La Ménagerie pages this player has opened. */ + public final java.util.Set pages = java.util.EnumSet.noneOf(Species.class); public Wrangler(UUID player) { this.player = player; diff --git a/src/main/java/com/extantape/mobsquad/store/Store.java b/src/main/java/com/extantape/mobsquad/store/Store.java index 0f1d481..4891b17 100644 --- a/src/main/java/com/extantape/mobsquad/store/Store.java +++ b/src/main/java/com/extantape/mobsquad/store/Store.java @@ -18,10 +18,11 @@ *
  * wranglin 150
  * critter 6b1f...  chicken 1 0 0 Clucky
+ * page chicken
  * 
* * A critter line is its id, species, level, experience, when it's rested (epoch milliseconds, 0 when ready) and its - * name, URL-encoded. Written to a temporary file and moved into place, so a crash leaves the old file or the new one. + * name, URL-encoded. A page line is a La Ménagerie page the player has opened; owning a critter opens its page too. Written to a temporary file and moved into place, so a crash leaves the old file or the new one. * Lines that can't be read are skipped and counted, never guessed at. */ public final class Store { @@ -55,12 +56,18 @@ public Loaded load(UUID player) throws IOException { w.critters.add(new Critter(UUID.fromString(p[1]), s, URLDecoder.decode(p[6], StandardCharsets.UTF_8), Integer.parseInt(p[3]), Long.parseLong(p[4]), Long.parseLong(p[5]))); } + case "page" -> { + Species s = Species.byId(p[1]); + if (s == null) throw new IllegalArgumentException(); + w.pages.add(s); + } default -> skipped++; } } catch (RuntimeException e) { skipped++; } } + for (Critter c : w.critters) w.pages.add(c.species()); // files from before 0.4.0 have no page lines return new Loaded(w, skipped); } @@ -72,6 +79,7 @@ public void save(Wrangler w) throws IOException { sb.append("critter ").append(c.id()).append(' ').append(c.species().id()).append(' ').append(c.level()).append(' ') .append(c.xp()).append(' ').append(c.tuckeredUntil()).append(' ') .append(URLEncoder.encode(c.name(), StandardCharsets.UTF_8)).append('\n'); + for (Species s : w.pages) sb.append("page ").append(s.id()).append('\n'); Path tmp = dir.resolve(w.player + ".txt.tmp"); Files.writeString(tmp, sb.toString(), StandardCharsets.UTF_8); Files.move(tmp, file(w.player), StandardCopyOption.REPLACE_EXISTING, StandardCopyOption.ATOMIC_MOVE); diff --git a/src/main/java/com/extantape/mobsquad/world/BunkhouseMenu.java b/src/main/java/com/extantape/mobsquad/world/BunkhouseMenu.java index 24be986..61645fc 100644 --- a/src/main/java/com/extantape/mobsquad/world/BunkhouseMenu.java +++ b/src/main/java/com/extantape/mobsquad/world/BunkhouseMenu.java @@ -33,13 +33,16 @@ * as items. */ public final class BunkhouseMenu implements Listener { - public static final int SIZE = 54, CRITTER_SLOTS = 45, INFO_SLOT = 49, CALL_BACK_SLOT = 53; + public static final int SIZE = 54, CRITTER_SLOTS = 45, INFO_SLOT = 49, CALL_BACK_SLOT = 53, JOURNAL_SLOT = 45; private final Squads squads; private final Bunkhouses bunkhouses; - public BunkhouseMenu(Squads squads, Bunkhouses bunkhouses) { + private final Journal journal; + + public BunkhouseMenu(Squads squads, Bunkhouses bunkhouses, Journal journal) { this.squads = squads; this.bunkhouses = bunkhouses; + this.journal = journal; } /** Ties an open menu to its viewer and the critters on each slot when it was drawn. */ @@ -112,13 +115,15 @@ private void draw(Holder h, Wrangler w, Player p) { inv.setItem(INFO_SLOT, item(Material.BOOK, Component.text(p.getName() + "'s Bunkhouse", NamedTextColor.GOLD), lore)); inv.setItem(CALL_BACK_SLOT, item(Material.BELL, Component.text("Call everyone back", NamedTextColor.GOLD), List.of(line("Every critter out with you comes home.", NamedTextColor.GRAY)))); + inv.setItem(JOURNAL_SLOT, item(Material.WRITTEN_BOOK, Component.text("La Ménagerie", NamedTextColor.GOLD), + List.of(line("Your journal: a page for every critter you've met.", NamedTextColor.GRAY)))); } static Component line(String text, NamedTextColor color) { return Component.text(text, color).decoration(TextDecoration.ITALIC, false); } - private static ItemStack item(Material m, Component name, List lore) { + static ItemStack item(Material m, Component name, List lore) { ItemStack it = new ItemStack(m); it.editMeta(meta -> { meta.displayName(name.decoration(TextDecoration.ITALIC, false)); @@ -161,6 +166,10 @@ public void onClick(InventoryClickEvent event) { Wrangler w = squads.get(p); if (w == null) return; int slot = event.getSlot(); + if (slot == JOURNAL_SLOT) { + org.bukkit.Bukkit.getScheduler().runTask(org.bukkit.plugin.java.JavaPlugin.getProvidingPlugin(BunkhouseMenu.class), () -> journal.show(p)); + return; + } if (slot == CALL_BACK_SLOT) { int n = squads.posse().of(p.getUniqueId()).size(); squads.posse().backAll(p.getUniqueId()); diff --git a/src/main/java/com/extantape/mobsquad/world/Journal.java b/src/main/java/com/extantape/mobsquad/world/Journal.java new file mode 100644 index 0000000..f5081a9 --- /dev/null +++ b/src/main/java/com/extantape/mobsquad/world/Journal.java @@ -0,0 +1,192 @@ +package com.extantape.mobsquad.world; + +import com.extantape.mobsquad.Squads; +import com.extantape.mobsquad.model.Critter; +import com.extantape.mobsquad.model.Critterbook; +import com.extantape.mobsquad.model.Species; +import com.extantape.mobsquad.model.Wrangler; +import java.util.ArrayList; +import java.util.EnumMap; +import java.util.List; +import java.util.Locale; +import java.util.Map; +import java.util.UUID; +import net.kyori.adventure.inventory.Book; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.event.ClickEvent; +import net.kyori.adventure.text.event.HoverEvent; +import net.kyori.adventure.text.format.NamedTextColor; +import net.kyori.adventure.text.format.TextDecoration; +import org.bukkit.Bukkit; +import org.bukkit.Material; +import org.bukkit.entity.Entity; +import org.bukkit.entity.LivingEntity; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.Listener; +import org.bukkit.event.inventory.InventoryClickEvent; +import org.bukkit.event.inventory.InventoryDragEvent; +import org.bukkit.inventory.Inventory; +import org.bukkit.inventory.InventoryHolder; +import org.bukkit.inventory.ItemStack; +import org.bukkit.plugin.Plugin; + +/** + * La Ménagerie, the journal (brief, "La Ménagerie (the journal)"). Its own menu lists the launch critters in Critterbook + * order; a critter's page opens once you've met one (seen it up close) or have one, and clicking it opens the page as a + * book. Locked pages show only their number. Each player's open pages are saved in their own file. + */ +public final class Journal implements Runnable, Listener { + public static final long PERIOD = 40; + /** How close a mob has to be, with a clear line, to count as met. */ + static final double MEET = 10; + static final int SIZE = 27, INFO_SLOT = 22; + static final Component TITLE = Component.text("La Ménagerie"); + + /** Each page's voice: half ridiculous (brief). The creeper's line is the owner's own. */ + static final Map VOICE = new EnumMap<>(Species.class); + static { + VOICE.put(Species.CHICKEN, "Thinks it can fly. It can't. But it'll teach you to fall like a feather, which is nearly as good."); + VOICE.put(Species.AXOLOTL, "Smiles all the time, even when it's pretending to be dead. Especially then."); + VOICE.put(Species.BEE, "Busy, and a little bit judgy. Stand still and let it decide you're a flower."); + VOICE.put(Species.FOX, "Finders keepers? Not this one. It brings your stuff right back, smug as anything."); + VOICE.put(Species.ALLAY, "Hums when it's happy. Hums louder when it finds diamonds. Wouldn't hurt a fly, or a zombie."); + VOICE.put(Species.CREEPER, "Momma said never look a creeper in the eye. But I like to laugh in the face of danger!"); + VOICE.put(Species.ENDERMAN, "Tall and deeply offended by eye contact. Look at its shoes instead. Compliment the shoes."); + VOICE.put(Species.SKELETON, "All bones and no manners. Hand it an arrow, though, and it'll watch your back all day."); + VOICE.put(Species.IRON_GOLEM, "Made of iron with a big soft heart. Gives the best hugs. Also throws zombies."); + } + + private final Plugin plugin; + private final Squads squads; + + public Journal(Plugin plugin, Squads squads) { + this.plugin = plugin; + this.squads = squads; + } + + static final class Holder implements InventoryHolder { + final UUID viewer; + final List slots = new ArrayList<>(); + Inventory inventory; + + Holder(UUID viewer) { + this.viewer = viewer; + } + + @Override + public Inventory getInventory() { + return inventory; + } + } + + // ----- Meeting critters. + + /** Every two seconds, opens a page for each launch critter a player is close to and can see. */ + @Override + public void run() { + for (Player p : Bukkit.getOnlinePlayers()) { + if (!p.hasPermission("mobsquad.use") || !squads.settings().enabledIn(p.getWorld().getName())) continue; + Wrangler w = squads.get(p); + if (w == null || w.pages.size() == Species.values().length) continue; + for (Entity e : p.getNearbyEntities(MEET, MEET / 2, MEET)) { + if (!(e instanceof LivingEntity l) || l.isDead()) continue; + Species s = Species.byId(e.getType().getKey().getKey()); + if (s == null || w.pages.contains(s) || !p.hasLineOfSight(e)) continue; + open(p, s, "met"); + } + } + } + + /** Opens a critter's page for a player, and tells them, with a link to the journal. */ + public void open(Player p, Species s, String how) { + Wrangler w = squads.get(p); + if (w == null || !w.pages.add(s)) return; + squads.save(w); + Component link = Component.text("[Open La Ménagerie]", NamedTextColor.AQUA) + .clickEvent(ClickEvent.runCommand("/mobsquad journal")) + .hoverEvent(HoverEvent.showText(Component.text("/mobsquad journal"))); + p.sendMessage(Component.text("New page in La Ménagerie: No. " + Critterbook.number(s) + ", the " + s.title().toLowerCase(Locale.ROOT) + "! ", NamedTextColor.GOLD).append(link)); + } + + // ----- The menu. + + public void show(Player p) { + Wrangler w = squads.get(p); + if (w == null) { + p.sendMessage(Component.text("Your journal can't be read right now. Ask an admin to check the server log.", NamedTextColor.RED)); + return; + } + Holder h = new Holder(p.getUniqueId()); + h.inventory = Bukkit.createInventory(h, SIZE, TITLE); + List order = Critterbook.inOrder(); + for (int i = 0; i < order.size(); i++) { + Species s = order.get(i); + h.slots.add(s); + h.inventory.setItem(i, icon(s, w)); + } + h.inventory.setItem(INFO_SLOT, BunkhouseMenu.item(Material.WRITTEN_BOOK, Component.text("La Ménagerie", NamedTextColor.GOLD), List.of( + BunkhouseMenu.line("You've met " + w.pages.size() + " of " + order.size() + " critters.", NamedTextColor.GRAY), + BunkhouseMenu.line("Get close to a critter, or coax one, to open its page.", NamedTextColor.DARK_GRAY), + BunkhouseMenu.line("Numbers follow the order each mob first came to Minecraft.", NamedTextColor.DARK_GRAY)))); + p.openInventory(h.inventory); + } + + private static ItemStack icon(Species s, Wrangler w) { + int n = Critterbook.number(s); + if (!w.pages.contains(s)) + return BunkhouseMenu.item(Material.GRAY_DYE, Component.text("No. " + n + " ???", NamedTextColor.DARK_GRAY), + List.of(BunkhouseMenu.line("You haven't met this one yet.", NamedTextColor.GRAY))); + Material egg = Material.matchMaterial(s.entity + "_SPAWN_EGG"); + long have = w.critters.stream().filter(c -> c.species() == s).count(); + return BunkhouseMenu.item(egg == null ? Material.EGG : egg, Component.text("No. " + n + " " + s.title(), NamedTextColor.WHITE), List.of( + BunkhouseMenu.line(s.tier.title + " critter", NamedTextColor.GRAY), + BunkhouseMenu.line(have == 0 ? "None in your Bunkhouse yet" : have + " in your Bunkhouse", NamedTextColor.GRAY), + BunkhouseMenu.line("Click to read its page.", NamedTextColor.DARK_GRAY))); + } + + /** A critter's page, as a book: who it is, how to coax it, and its special. */ + static Book page(Species s, Wrangler w) { + int n = Critterbook.number(s); + Component first = Component.text() + .append(Component.text("No. " + n + "\n", NamedTextColor.DARK_GRAY)) + .append(Component.text(s.title() + "\n", NamedTextColor.BLACK, TextDecoration.BOLD)) + .append(Component.text(s.tier.title + " critter\n\n", NamedTextColor.DARK_GRAY)) + .append(Component.text(VOICE.get(s), NamedTextColor.BLACK, TextDecoration.ITALIC)) + .build(); + Component coax = Component.text() + .append(Component.text("Coaxing\n\n", NamedTextColor.BLACK, TextDecoration.BOLD)) + .append(Component.text(s.hint + "\n\n", NamedTextColor.BLACK)) + .append(Component.text("From Wranglin' level " + s.tier.level + ".", NamedTextColor.DARK_GRAY)) + .build(); + int best = w.critters.stream().filter(c -> c.species() == s).mapToInt(Critter::level).max().orElse(0); + Component special = Component.text() + .append(Component.text("Special\n\n", NamedTextColor.BLACK, TextDecoration.BOLD)) + .append(Component.text(s.special + "\n\n", NamedTextColor.BLACK)) + .append(Component.text("It grows at levels 25, 50, 75 and 100." + (best > 0 ? " Your best is level " + best + "." : "") + "\n\n", NamedTextColor.DARK_GRAY)) + .append(Component.text("Spirit coats come later.", NamedTextColor.DARK_GRAY)) + .build(); + return Book.book(Component.text("No. " + n + " " + s.title()), Component.text("La Ménagerie"), first, coax, special); + } + + @EventHandler(priority = EventPriority.LOWEST) + public void onDrag(InventoryDragEvent event) { + if (event.getView().getTopInventory().getHolder(false) instanceof Holder) event.setCancelled(true); + } + + @EventHandler(priority = EventPriority.LOWEST) + public void onClick(InventoryClickEvent event) { + if (!(event.getView().getTopInventory().getHolder(false) instanceof Holder h)) return; + event.setCancelled(true); // nothing moves in or out of the journal + if (!(event.getWhoClicked() instanceof Player p) || !p.getUniqueId().equals(h.viewer)) return; + if (event.getClickedInventory() != event.getView().getTopInventory() || event.getSlot() >= h.slots.size()) return; + Species s = h.slots.get(event.getSlot()); + Wrangler w = squads.get(p); + if (w == null || !w.pages.contains(s)) return; + Bukkit.getScheduler().runTask(plugin, () -> { + p.closeInventory(); + p.openBook(page(s, w)); + }); + } +} diff --git a/src/main/resources/critterbook.txt b/src/main/resources/critterbook.txt new file mode 100644 index 0000000..67a9238 --- /dev/null +++ b/src/main/resources/critterbook.txt @@ -0,0 +1,92 @@ +# The Critterbook: every mob in Minecraft Java Edition, numbered in the order each first appeared in Java Edition, +# from the history sections of the Minecraft Wiki (checked 2026-11-15). Mobs added in the same version are numbered +# in the order of their first snapshot, then alphabetically. Numbers never change; new mobs get the next numbers. +# Format: number, the mob's entity id, and after # the Java version it first appeared in. +1 creeper # Classic 0.24_SURVIVAL_TEST +2 pig # Classic 0.24_SURVIVAL_TEST +3 skeleton # Classic 0.24_SURVIVAL_TEST +4 zombie # Classic 0.24_SURVIVAL_TEST +5 spider # Classic 0.26 SURVIVAL TEST +6 sheep # Classic 0.28 +7 cow # Alpha v1.0.8 +8 slime # Alpha v1.0.11 +9 chicken # Alpha v1.0.14 +10 ghast # Alpha v1.2.0 preview +11 zombified_piglin # Alpha v1.2.0 preview +12 squid # Beta 1.2 +13 wolf # Beta 1.4 +14 cave_spider # Beta 1.8 Pre-release +15 enderman # Beta 1.8 Pre-release +16 silverfish # Beta 1.8 Pre-release +17 blaze # Beta 1.9 Prerelease +18 magma_cube # Beta 1.9 Prerelease +19 mooshroom # Beta 1.9 Prerelease +20 snow_golem # Beta 1.9 Prerelease +21 villager # Beta 1.9 Prerelease +22 ender_dragon # Beta 1.9 Prerelease 4 +23 cat # 12w04a +24 ocelot # 12w04a +25 iron_golem # 12w08a +26 zombie_villager # 12w32a +27 wither # 12w34a +28 wither_skeleton # 12w36a +29 bat # 12w38a +30 witch # 12w38a +31 donkey # 13w16a +32 horse # 13w16a +33 mule # 13w16a +34 skeleton_horse # 13w16a +35 zombie_horse # 13w16a +36 endermite # 14w11a +37 elder_guardian # 14w25a +38 guardian # 14w25a +39 rabbit # 14w27a +40 shulker # 15w31a +41 husk # 16w20a +42 polar_bear # 16w20a +43 stray # 16w20a +44 evoker # 16w39a +45 llama # 16w39a +46 vex # 16w39a +47 vindicator # 16w39a +48 parrot # 17w13a +49 phantom # 18w07a +50 turtle # 18w07a +51 cod # 18w08b +52 pufferfish # 18w08b +53 salmon # 18w08b +54 tropical_fish # 18w10a +55 drowned # 18w11a +56 dolphin # 18w15a +57 panda # 18w43a +58 pillager # 18w43a +59 ravager # 18w43a +60 trader_llama # 19w05a +61 wandering_trader # 19w05a +62 fox # 19w07a +63 bee # 19w34a +64 hoglin # 20w06a +65 piglin # 20w07a +66 strider # 20w13a +67 zoglin # 20w14a +68 piglin_brute # 20w27a +69 axolotl # 20w51a +70 glow_squid # 21w03a +71 goat # 21w13a +72 warden # Deep Dark Experimental Snapshot 1 +73 frog # 22w11a +74 tadpole # 22w11a +75 allay # 22w13a +76 camel # 22w42a +77 sniffer # 23w07a +78 breeze # 23w45a +79 armadillo # 23w51a +80 bogged # 24w07a +81 creaking # 24w40a +82 happy_ghast # 25w15a +83 copper_golem # 25w31a +84 nautilus # 25w41a +85 zombie_nautilus # 25w41a +86 camel_husk # 25w44a +87 parched # 25w44a +88 sulfur_cube # 26.2 snap1 diff --git a/src/test/java/com/extantape/mobsquad/ModelTest.java b/src/test/java/com/extantape/mobsquad/ModelTest.java index dc00c8e..06bfed4 100644 --- a/src/test/java/com/extantape/mobsquad/ModelTest.java +++ b/src/test/java/com/extantape/mobsquad/ModelTest.java @@ -3,6 +3,7 @@ import static org.junit.jupiter.api.Assertions.*; import com.extantape.mobsquad.model.Critter; +import com.extantape.mobsquad.model.Critterbook; import com.extantape.mobsquad.model.Growth; import com.extantape.mobsquad.model.Levels; import com.extantape.mobsquad.model.Species; @@ -117,4 +118,46 @@ void experienceSetsTheLevel() { void everyCritterHasASpecial() { for (Species s : Species.values()) assertFalse(s.special.isBlank(), s.title()); } + + @Test + void critterbookNumbersRunOneToTheEndWithNoGaps() { + var all = Critterbook.all(); + assertEquals(88, all.size()); + int expect = 1; + for (int n : all.values()) assertEquals(expect++, n); + } + + @Test + void launchCritterNumbersNeverChange() { + assertEquals(1, Critterbook.number(Species.CREEPER)); + assertEquals(3, Critterbook.number(Species.SKELETON)); + assertEquals(9, Critterbook.number(Species.CHICKEN)); + assertEquals(15, Critterbook.number(Species.ENDERMAN)); + assertEquals(25, Critterbook.number(Species.IRON_GOLEM)); + assertEquals(62, Critterbook.number(Species.FOX)); + assertEquals(63, Critterbook.number(Species.BEE)); + assertEquals(69, Critterbook.number(Species.AXOLOTL)); + assertEquals(75, Critterbook.number(Species.ALLAY)); + assertEquals(Species.CREEPER, Critterbook.inOrder().getFirst()); + } + + @Test + void journalPagesRoundTrip(@TempDir Path dir) throws Exception { + Store store = new Store(dir); + UUID p = UUID.randomUUID(); + Wrangler w = new Wrangler(p); + w.pages.add(Species.FOX); + w.pages.add(Species.CREEPER); + store.save(w); + assertEquals(java.util.Set.of(Species.FOX, Species.CREEPER), store.load(p).wrangler().pages); + } + + @Test + void anOlderFileOpensPagesForCrittersYouHave(@TempDir Path dir) throws Exception { + UUID p = UUID.randomUUID(); + Files.writeString(dir.resolve(p + ".txt"), "wranglin 0\ncritter " + UUID.randomUUID() + " bee 1 0 0 Buzz\n"); + Store.Loaded l = new Store(dir).load(p); + assertEquals(0, l.skipped()); + assertEquals(java.util.Set.of(Species.BEE), l.wrangler().pages); + } } diff --git a/test/suite.mjs b/test/suite.mjs index 097de18..b157b5d 100644 --- a/test/suite.mjs +++ b/test/suite.mjs @@ -695,6 +695,73 @@ else if (want('specials')) { for (const g of ['randomTickSpeed 3', 'random_tick_speed 3']) await s.ask('gamerule ' + g, 150) } +// ---------- La Ménagerie ---------- +if (want('journal')) { + section('La Ménagerie') + const scout = await bot('Scout', { physics: PHYSICS }) + await uuidOf('Scout') + await s.ask('gamemode creative Scout', 200) + const JX = X + 60, JZ = Z + 60 + await s.ask(`forceload add ${JX - 16} ${JZ - 16} ${JX + 16} ${JZ + 16}`, 800) + await stand(scout, 'Scout', JX, JZ, -90, 0) + await s.ask(`kill @e[type=!player,x=${JX},y=${Y},z=${JZ},distance=..40]`, 300) + async function journal() { + const opened = new Promise((ok, fail) => { scout.once('windowOpen', ok); setTimeout(() => fail(new Error('no journal')), 6000) }) + scout.chat('/mobsquad journal') + return opened + } + let w = await journal() + check('/mobsquad journal opens La Ménagerie', JSON.stringify(w.title).includes('nagerie'), JSON.stringify(w.title)) + check('a new player\'s pages are all locked', [0, 1, 2, 3, 4, 5, 6, 7, 8].every(i => egg(w, i) === 'gray_dye'), [0, 1, 2, 3, 4, 5, 6, 7, 8].map(i => egg(w, i)).join(',')) + check('it lists the critters in Critterbook order, creeper first', /No\. 1 /.test(JSON.stringify(w.slots[0]?.customName ?? '')) && /No\. 75 /.test(JSON.stringify(w.slots[8]?.customName ?? '')), `${JSON.stringify(w.slots[0]?.customName)} / ${JSON.stringify(w.slots[8]?.customName)}`) + await closeMenu(scout) + let from = scout.chatLog.length + await s.ask(`summon fox ${JX + 5} ${Y} ${JZ} {NoAI:1b,PersistenceRequired:1b}`, 300) + check('meeting a fox opens its page', await waitSaid(scout, /New page in La Ménagerie: No\. 62, the fox!/, 6000, from), scout.chatLog.slice(from).join(' | ')) + check('the page is saved', file('Scout').includes('page fox'), file('Scout')) + // a creeper behind a wall isn't met; with the wall gone, it is + await s.ask(`fill ${JX + 3} ${Y} ${JZ - 6} ${JX + 3} ${Y + 3} ${JZ - 2} stone`, 300) + await s.ask(`summon creeper ${JX + 6} ${Y} ${JZ - 4} {NoAI:1b,PersistenceRequired:1b}`, 300) + await s.ask(`summon chicken ${JX - 25} ${Y} ${JZ} {NoAI:1b,PersistenceRequired:1b}`, 300) + from = scout.chatLog.length + await sleep(5000) + check('a critter you can\'t see isn\'t met', !said(scout, /the creeper/, from)) + check('one far away isn\'t either', !said(scout, /the chicken/, from)) + await s.ask(`fill ${JX + 3} ${Y} ${JZ - 6} ${JX + 3} ${Y + 3} ${JZ - 2} air`, 300) + check('once it\'s in sight, it is', await waitSaid(scout, /No\. 1, the creeper!/, 6000, from), scout.chatLog.slice(from).join(' | ')) + from = scout.chatLog.length + await s.ask('mobsquad give Scout bee', 400) + check('getting a critter opens its page', await waitSaid(scout, /No\. 63, the bee!/, 4000, from), scout.chatLog.slice(from).join(' | ')) + w = await journal() + const order = ['creeper', 'skeleton', 'chicken', 'enderman', 'iron_golem', 'fox', 'bee', 'axolotl', 'allay'] + const shown = order.map((k, i) => egg(w, i)) + check('open pages show their critter, locked ones stay hidden', + shown[0] === 'creeper_spawn_egg' && shown[5] === 'fox_spawn_egg' && shown[6] === 'bee_spawn_egg' && shown[2] === 'gray_dye' && shown[8] === 'gray_dye', shown.join(',')) + const book = new Promise(ok => { scout._client.once('open_book', () => ok(true)); setTimeout(() => ok(false), 5000) }) + await scout.clickWindow(5, 0, 0) + check('clicking an open page opens it as a book', await book) + await closeMenu(scout) + w = await journal() + const noBook = new Promise(ok => { scout._client.once('open_book', () => ok(true)); setTimeout(() => ok(false), 2500) }) + await scout.clickWindow(2, 0, 0) + check('a locked page doesn\'t open', !(await noBook)) + await scout.clickWindow(5, 0, 0); await sleep(300) + check('nothing can be taken out of the journal', !scout.inventory.items().some(i => /spawn_egg|dye/.test(i.name))) + await closeMenu(scout) + if (MENU) { + await s.ask('gamemode survival Scout', 200) + await stand(scout, 'Scout', X - 2, Z, 0, 20) + const bw = await openBunkhouse(scout, vault) + const jopened = new Promise((ok) => { scout.once('windowOpen', ww => ok(ww)); setTimeout(() => ok(null), 5000) }) + await scout.clickWindow(45, 0, 0) + const jw = await jopened + check('the Bunkhouse menu opens La Ménagerie', jw && JSON.stringify(jw.title).includes('nagerie'), jw && JSON.stringify(jw.title)) + await closeMenu(scout) + } + await s.ask(`kill @e[type=!player,x=${JX},y=${Y},z=${JZ},distance=..40]`, 300) + await quit(scout) +} + // ---------- vittles ---------- if (!MENU) skip('vittles') else if (want('vittles')) {