From 34d2566622a16ac2224c5938cda088a05ce16e4c Mon Sep 17 00:00:00 2001 From: bladestech Date: Sun, 25 Oct 2026 12:22:40 +0200 Subject: [PATCH 1/4] EZdebug+ 0.1.0: a Debug Potion that shows EZvac's devices at work Drinking it outlines every EZvac sign and piece of equipment near the player, coloured by kind or by what the equipment is doing, and puffs clouds on working vents and equipment. Only that player sees it; milk, death, the timer or /ezdb off end it. Built only on EZvac API 1.2. Co-Authored-By: Claude Opus 5.5 --- .github/workflows/build.yml | 46 ++++++ .github/workflows/modrinth.yml | 100 +++++++++++ CHANGELOG.md | 23 +++ CONTRIBUTING.md | 33 ++++ README.md | 76 +++++++++ pom.xml | 111 +++++++++++++ .../com/github/blade/ezdebug/Commands.java | 83 ++++++++++ .../com/github/blade/ezdebug/DebugPotion.java | 144 ++++++++++++++++ .../com/github/blade/ezdebug/DebugVision.java | 155 ++++++++++++++++++ .../github/blade/ezdebug/EzDebugPlugin.java | 74 +++++++++ .../com/github/blade/ezdebug/Outlines.java | 130 +++++++++++++++ .../github/blade/ezdebug/model/Activity.java | 33 ++++ .../blade/ezdebug/model/DebugSettings.java | 66 ++++++++ .../github/blade/ezdebug/model/Palette.java | 48 ++++++ src/main/resources/config.yml | 33 ++++ src/main/resources/plugin.yml | 17 ++ .../github/blade/ezdebug/PluginBitsTest.java | 25 +++ .../blade/ezdebug/model/DebugModelTest.java | 114 +++++++++++++ 18 files changed, 1311 insertions(+) create mode 100644 .github/workflows/build.yml create mode 100644 .github/workflows/modrinth.yml create mode 100644 CHANGELOG.md create mode 100644 CONTRIBUTING.md create mode 100644 README.md create mode 100644 pom.xml create mode 100644 src/main/java/com/github/blade/ezdebug/Commands.java create mode 100644 src/main/java/com/github/blade/ezdebug/DebugPotion.java create mode 100644 src/main/java/com/github/blade/ezdebug/DebugVision.java create mode 100644 src/main/java/com/github/blade/ezdebug/EzDebugPlugin.java create mode 100644 src/main/java/com/github/blade/ezdebug/Outlines.java create mode 100644 src/main/java/com/github/blade/ezdebug/model/Activity.java create mode 100644 src/main/java/com/github/blade/ezdebug/model/DebugSettings.java create mode 100644 src/main/java/com/github/blade/ezdebug/model/Palette.java create mode 100644 src/main/resources/config.yml create mode 100644 src/main/resources/plugin.yml create mode 100644 src/test/java/com/github/blade/ezdebug/PluginBitsTest.java create mode 100644 src/test/java/com/github/blade/ezdebug/model/DebugModelTest.java diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..0f27d4d --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,46 @@ +# Builds EZdebugPlus and runs its test suite on a clean machine. +# +# "on:" lists the events that start this workflow. +name: Build + +on: + push: + branches: [main] # every push to main + pull_request: + branches: [main] # every pull request targeting main + workflow_dispatch: # lets you run it by hand from the Actions tab + +jobs: + build: + name: Build and test + runs-on: ubuntu-latest # a fresh throwaway Linux machine, per run + + steps: + # Copy the repository onto the machine. + - name: Check out the repository + uses: actions/checkout@v4 + + # Install Java 21 and cache the Maven dependency downloads, so later + # runs do not re-download paper-api and the EZvac API every time. + - name: Set up Java 21 + uses: actions/setup-java@v4 + with: + distribution: temurin + java-version: '21' + cache: maven + + # -B is "batch mode": no interactive prompts, cleaner logs. + # "verify" runs the full lifecycle including the test suite. + - name: Build and run tests + run: mvn -B clean verify + + # Keep the built jar so you can download it from the run's summary page. + # Useful for testing a contributor's pull request without building it + # yourself. Retained for 30 days. + - name: Upload the built jar + uses: actions/upload-artifact@v4 + with: + name: EZdebugPlus-jar + path: target/EZdebugPlus-*.jar + if-no-files-found: error + retention-days: 30 diff --git a/.github/workflows/modrinth.yml b/.github/workflows/modrinth.yml new file mode 100644 index 0000000..4a2becc --- /dev/null +++ b/.github/workflows/modrinth.yml @@ -0,0 +1,100 @@ +# Publishes each GitHub release to Modrinth, so the Modrinth page never falls +# behind GitHub. +# +# It uploads the jar attached to the release (the one the Build workflow +# made) with the release notes as its changelog. Prereleases such as the +# pilots go up as "beta", everything else as "release". A version Modrinth +# already has is skipped, so running it twice is harmless. +# +# Needs the repository variable MODRINTH_PROJECT (the Modrinth project's id) and +# the repository secret MODRINTH_TOKEN: a Modrinth personal access token +# with the Create versions, Read versions and Read projects scopes, from an +# account allowed to upload versions to the project. The token is only ever +# sent to Modrinth's own API. +name: Publish to Modrinth + +on: + release: + types: [published] # whenever a release is published on GitHub + workflow_dispatch: # or by hand, e.g. for a release made before this existed + inputs: + tag: + description: Release tag to publish, e.g. 0.1.0 + required: true + +permissions: + contents: read # enough to read releases and download their jars + +env: + MODRINTH_PROJECT: ${{ vars.MODRINTH_PROJECT }} + EZVAC_PROJECT: dCv4gYwb # modrinth.com/plugin/ezvac-plugin, which EZdebug+ needs + GAME_VERSIONS: '["1.21", "1.21.1"]' + LOADERS: '["paper", "purpur"]' + # Modrinth asks API clients to say who they are. + USER_AGENT: EZvac-Plugin/EZdebugPlus release publisher (github.com/EZvac-Plugin/EZdebugPlus) + +jobs: + publish: + name: Publish to Modrinth + runs-on: ubuntu-latest + # Does nothing until the Modrinth project exists and its id is set as a repository variable. + if: vars.MODRINTH_PROJECT != '' + + steps: + # The release's own jar, so Modrinth gets exactly the file GitHub has. + - name: Download the release and its jar + env: + GH_TOKEN: ${{ github.token }} + TAG: ${{ github.event.release.tag_name || inputs.tag }} + run: | + mkdir dist + # The jar can arrive a moment after the release is published; retry briefly. + for attempt in 1 2 3 4 5 6; do + gh release download "$TAG" --repo "$GITHUB_REPOSITORY" --pattern 'EZdebugPlus-*.jar' \ + --dir dist --clobber && break + sleep 10 + done + count=$(ls dist/EZdebugPlus-*.jar 2>/dev/null | wc -l) + if [ "$count" -ne 1 ]; then + echo "::error::Release $TAG should have exactly one EZdebugPlus jar attached; found $count." + exit 1 + fi + gh release view "$TAG" --repo "$GITHUB_REPOSITORY" --json name,body,isPrerelease > dist/release.json + echo "TAG=$TAG" >> "$GITHUB_ENV" + + - name: Skip if Modrinth already has this version + run: | + if curl -fsS -A "$USER_AGENT" "https://api.modrinth.com/v2/project/$MODRINTH_PROJECT/version" \ + | jq -e --arg tag "$TAG" 'any(.[]; .version_number == $tag)' > /dev/null; then + echo "Modrinth already has $TAG; nothing to do." + echo "SKIP=true" >> "$GITHUB_ENV" + fi + + - name: Upload to Modrinth + if: env.SKIP != 'true' + env: + MODRINTH_TOKEN: ${{ secrets.MODRINTH_TOKEN }} + run: | + jar=$(ls dist/EZdebugPlus-*.jar) + jq -n --slurpfile release dist/release.json --arg tag "$TAG" --arg project "$MODRINTH_PROJECT" --arg ezvac "$EZVAC_PROJECT" \ + --argjson games "$GAME_VERSIONS" --argjson loaders "$LOADERS" '{ + name: $release[0].name, + version_number: $tag, + changelog: $release[0].body, + version_type: (if $release[0].isPrerelease then "beta" else "release" end), + game_versions: $games, + loaders: $loaders, + dependencies: [{project_id: $ezvac, dependency_type: "required"}], + featured: false, + status: "listed", + project_id: $project, + file_parts: ["file"], + primary_file: "file" + }' > dist/version.json + curl -sS --fail-with-body -A "$USER_AGENT" \ + -H "Authorization: $MODRINTH_TOKEN" \ + -F "data=.jar`. +Every push and pull request is built and tested by GitHub Actions. + +## How it fits together + +- **The code only touches EZvac through its public API** (`ezvac-api`, from JitPack). Never reach into EZvac's internals: that is what keeps EZdebug+ working across EZvac releases. +- **The pure, unit-tested logic is in `model/`:** + - `Palette` picks the colour for a device and what it's doing; + - `Activity` says which vents and equipment are at work; + - `DebugSettings` reads and checks config.yml. + + Add tests there when you change them. +- **The Bukkit side:** + - `DebugPotion`: the item, drinking it, milk, death, relogs, and EZvac's device events; + - `DebugVision`: who has debug vision and the redraw task; + - `Outlines`: the glowing block displays, shown only to debug players; + - `Commands`. diff --git a/README.md b/README.md new file mode 100644 index 0000000..1c921f1 --- /dev/null +++ b/README.md @@ -0,0 +1,76 @@ +# EZdebug+ + +**See EZvac at work.** An addon for [EZvac](https://github.com/EZvac-Plugin/EZvac), +the realistic HVAC and indoor-climate plugin for Paper and Purpur. + +`/ezdb debug` gives you a **Debug Potion**. Drink it, and for 8 minutes: +- **every EZvac sign glows** with an outline, in a colour for its kind. You + can see them through walls, so a thermostat behind a painting or a monitor + in a plant room is easy to find; +- **every piece of equipment glows** too: grey while it's stopped, cyan + while it cools, orange while it heats; +- **working vents puff a little cloud,** cyan or orange, while their system + cools or heats, and so does running equipment. + +Only you see any of it: other players see nothing. Night Vision shows the +countdown and helps in dark plant rooms. **Milk** ends it, like any potion, +and so does dying. + +> **Requires** EZvac with API 1.2 or newer, on Paper or Purpur 1.21.1 with +> Java 21. + +## Colours + +| Outline | Colour | +| --- | --- | +| Thermostats | aqua | +| Thermometers, hygrometers, thermo-hygrometers | white | +| RPM monitors | yellow | +| Settings panels | pink | +| Sensor hubs | green | +| Dehumidifier and humidifier signs | blue | +| Equipment | grey when stopped, cyan cooling, orange heating | + +Clouds are cyan for cooling and orange for heating. Every colour can be +changed in config.yml. + +## Commands and permissions + +| Command | Does | +| --- | --- | +| `/ezdb debug [player]` | Gives a Debug Potion, to you or to someone else | +| `/ezdb off [player]` | Ends debug vision at once | +| `/ezdb reload` | Reloads config.yml | + +All need `ezdebug.use` (ops by default). `/ezdebug` works too. + +## Configuration + +`plugins/EZdebugPlus/config.yml`, explained line by line: +- `duration-minutes` (8); +- `radius`: how close devices must be (32 blocks); +- `refresh-ticks`: how often the view is redrawn (10, twice a second); +- `effect`: the countdown effect (`night_vision`, or `none`); +- `colors`. + +A bad value warns in the console and that part uses its defaults. + +## How it works + +EZdebug+ is built only on EZvac's public API: `devices(world)` lists every +device with its position, the equipment and thermostat views say what's +running, and the device events keep the outlines in step. Outlines are block +displays that only debug players are shown; they're never saved with the +world. See [EZvac's API guide](https://github.com/EZvac-Plugin/EZvac/blob/main/docs/api.md). + +## Building + +```shell +mvn clean package +``` + +The jar is written to `target/EZdebugPlus-.jar`. + +## License + +MIT; see [LICENSE](LICENSE). diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..43ecc75 --- /dev/null +++ b/pom.xml @@ -0,0 +1,111 @@ + + 4.0.0 + + com.github.blade + ezdebugplus + 0.1.0 + jar + + EZdebugPlus + EZdebug+: a Debug Potion that shows EZvac's devices at work. An addon for EZvac. + + + + MIT License + https://opensource.org/licenses/MIT + repo + + + + + 21 + UTF-8 + + api-1.2-local + + + + + papermc + https://repo.papermc.io/repository/maven-public/ + + + + jitpack.io + https://jitpack.io + + + + + + io.papermc.paper + paper-api + 1.21.1-R0.1-SNAPSHOT + provided + + + + com.github.EZvac-Plugin.EZvac + ezvac-api + ${ezvac.api.version} + provided + + + org.junit.jupiter + junit-jupiter + 5.11.4 + test + + + org.junit.platform + junit-platform-launcher + 1.11.4 + test + + + + + clean package + EZdebugPlus-${project.version} + + + src/main/resources + true + + + ${project.basedir} + META-INF + + LICENSE + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.11.0 + + 21 + + + + org.apache.maven.plugins + maven-surefire-plugin + 3.2.2 + + + org.apache.maven.plugins + maven-resources-plugin + 3.3.1 + + + org.apache.maven.plugins + maven-jar-plugin + 3.3.0 + + + + diff --git a/src/main/java/com/github/blade/ezdebug/Commands.java b/src/main/java/com/github/blade/ezdebug/Commands.java new file mode 100644 index 0000000..554af3b --- /dev/null +++ b/src/main/java/com/github/blade/ezdebug/Commands.java @@ -0,0 +1,83 @@ +package com.github.blade.ezdebug; + +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.format.NamedTextColor; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.command.TabCompleter; +import org.bukkit.entity.Player; + +import java.util.List; +import java.util.Locale; + +/** {@code /ezdb debug [player]}, {@code /ezdb off [player]}, {@code /ezdb reload}. */ +final class Commands implements CommandExecutor, TabCompleter { + private final EzDebugPlugin plugin; + + Commands(EzDebugPlugin plugin) { + this.plugin = plugin; + } + + @Override + public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + String action = args.length == 0 ? "" : args[0].toLowerCase(Locale.ROOT); + switch (action) { + case "debug" -> { + Player target = target(sender, args); + if (target == null) return true; + var leftOver = target.getInventory().addItem(plugin.potion().create()); + leftOver.values().forEach(item -> target.getWorld().dropItem(target.getLocation(), item)); + target.sendMessage(Component.text("Here's a Debug Potion. Drink it to see EZvac at work.", + NamedTextColor.AQUA)); + if (target != sender) + sender.sendMessage(Component.text("Gave " + target.getName() + " a Debug Potion.", NamedTextColor.GREEN)); + } + case "off" -> { + Player target = target(sender, args); + if (target == null) return true; + if (!plugin.vision().active(target)) { + sender.sendMessage(Component.text(target.getName() + " has no debug vision.", NamedTextColor.GRAY)); + return true; + } + plugin.potion().clearCarrier(target); + plugin.vision().end(target, true); + if (target != sender) + sender.sendMessage(Component.text("Ended " + target.getName() + "'s debug vision.", NamedTextColor.GREEN)); + } + case "reload" -> { + plugin.loadSettings(); + plugin.vision().start(); + sender.sendMessage(Component.text("EZdebug+ settings reloaded.", NamedTextColor.GREEN)); + } + default -> sender.sendMessage(Component.text("Usage: /ezdb [player] | /ezdb reload", + NamedTextColor.RED)); + } + return true; + } + + /** The named player, or the sender; null (after saying why) when there is none. */ + private static Player target(CommandSender sender, String[] args) { + if (args.length >= 2) { + Player named = sender.getServer().getPlayerExact(args[1]); + if (named == null) sender.sendMessage(Component.text("No player named " + args[1] + " is online.", NamedTextColor.RED)); + return named; + } + if (sender instanceof Player player) return player; + sender.sendMessage(Component.text("From the console, name a player.", NamedTextColor.RED)); + return null; + } + + @Override + public List onTabComplete(CommandSender sender, Command command, String alias, String[] args) { + if (args.length == 1) return filter(args[0], List.of("debug", "off", "reload")); + if (args.length == 2 && !args[0].equalsIgnoreCase("reload")) + return filter(args[1], sender.getServer().getOnlinePlayers().stream().map(Player::getName).toList()); + return List.of(); + } + + private static List filter(String typed, List options) { + String prefix = typed.toLowerCase(Locale.ROOT); + return options.stream().filter(option -> option.toLowerCase(Locale.ROOT).startsWith(prefix)).toList(); + } +} diff --git a/src/main/java/com/github/blade/ezdebug/DebugPotion.java b/src/main/java/com/github/blade/ezdebug/DebugPotion.java new file mode 100644 index 0000000..51d82a3 --- /dev/null +++ b/src/main/java/com/github/blade/ezdebug/DebugPotion.java @@ -0,0 +1,144 @@ +package com.github.blade.ezdebug; + +import com.github.blade.hvac.api.Position; +import com.github.blade.hvac.api.event.DeviceAddedEvent; +import com.github.blade.hvac.api.event.DeviceRemovedEvent; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.format.NamedTextColor; +import net.kyori.adventure.text.format.TextDecoration; +import org.bukkit.Color; +import org.bukkit.Material; +import org.bukkit.NamespacedKey; +import org.bukkit.Registry; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.Listener; +import org.bukkit.event.entity.PlayerDeathEvent; +import org.bukkit.event.player.PlayerItemConsumeEvent; +import org.bukkit.event.player.PlayerJoinEvent; +import org.bukkit.event.player.PlayerQuitEvent; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.PotionMeta; +import org.bukkit.persistence.PersistentDataType; +import org.bukkit.potion.PotionEffect; +import org.bukkit.potion.PotionEffectType; + +import java.util.List; +import java.util.Locale; + +/** + * The Debug Potion: the item, drinking it, and everything that ends it + * (milk, death, the timer). The remaining time is kept with the player + * across relogs. Main thread only. + */ +final class DebugPotion implements Listener { + private static final Color TEAL = Color.fromRGB(0x2EC4B6); + + private final EzDebugPlugin plugin; + private final NamespacedKey potionKey; + private final NamespacedKey remainingKey; + + DebugPotion(EzDebugPlugin plugin) { + this.plugin = plugin; + this.potionKey = new NamespacedKey(plugin, "debug"); + this.remainingKey = new NamespacedKey(plugin, "remaining_ticks"); + } + + /** A Debug Potion. It has no water in it, so nothing mistakes it for a water bottle. */ + ItemStack create() { + ItemStack item = new ItemStack(Material.POTION); + PotionMeta meta = (PotionMeta) item.getItemMeta(); + meta.setBasePotionType(null); + meta.setColor(TEAL); + meta.displayName(Component.text("Debug Potion", NamedTextColor.AQUA).decoration(TextDecoration.ITALIC, false)); + meta.lore(List.of( + Component.text("See EZvac at work ยท " + clock(plugin.settings().durationTicks()), NamedTextColor.GRAY) + .decoration(TextDecoration.ITALIC, false), + Component.text("Milk ends it.", NamedTextColor.DARK_GRAY).decoration(TextDecoration.ITALIC, false))); + meta.getPersistentDataContainer().set(potionKey, PersistentDataType.BYTE, (byte) 1); + item.setItemMeta(meta); + return item; + } + + boolean isPotion(ItemStack item) { + if (item == null || item.getType() != Material.POTION || !item.hasItemMeta()) return false; + return item.getItemMeta().getPersistentDataContainer().has(potionKey, PersistentDataType.BYTE); + } + + /** "8:00". */ + static String clock(long ticks) { + long seconds = ticks / 20; + return String.format(Locale.US, "%d:%02d", seconds / 60, seconds % 60); + } + + @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) + public void onDrink(PlayerItemConsumeEvent event) { + Player player = event.getPlayer(); + if (event.getItem().getType() == Material.MILK_BUCKET) { + if (plugin.vision().active(player)) plugin.vision().end(player, true); + return; + } + if (!isPotion(event.getItem())) return; + long ticks = plugin.settings().durationTicks(); + plugin.vision().begin(player, ticks); + PotionEffectType carrier = carrier(); + if (carrier != null) player.addPotionEffect(new PotionEffect(carrier, (int) ticks, 0, true, false, true)); + player.sendMessage(Component.text("Debug vision for " + clock(ticks) + ": EZvac's signs and equipment glow," + + " and working vents puff colour. Milk ends it.", NamedTextColor.AQUA)); + } + + /** The vanilla effect that shows the countdown, or null for none. */ + private PotionEffectType carrier() { + String effect = plugin.settings().effect(); + if (effect.equals("none")) return null; + NamespacedKey key = NamespacedKey.fromString(effect); + PotionEffectType type = key == null ? null : Registry.EFFECT.get(key); + if (type == null) plugin.getLogger().warning("effect '" + effect + "' is not a potion effect; none is shown."); + return type; + } + + /** Ends the countdown effect too, when debug vision is switched off by command. */ + void clearCarrier(Player player) { + PotionEffectType carrier = carrier(); + if (carrier != null) player.removePotionEffect(carrier); + } + + @EventHandler(priority = EventPriority.MONITOR) + public void onDeath(PlayerDeathEvent event) { + plugin.vision().end(event.getPlayer(), false); + } + + @EventHandler + public void onQuit(PlayerQuitEvent event) { + Player player = event.getPlayer(); + long left = plugin.vision().remaining(player); + if (left > 0) player.getPersistentDataContainer().set(remainingKey, PersistentDataType.LONG, left); + else player.getPersistentDataContainer().remove(remainingKey); + plugin.vision().end(player, false); + } + + @EventHandler + public void onJoin(PlayerJoinEvent event) { + resume(event.getPlayer()); + } + + /** Picks up a relogging player's remaining time; their countdown effect came back with them. */ + void resume(Player player) { + Long left = player.getPersistentDataContainer().get(remainingKey, PersistentDataType.LONG); + player.getPersistentDataContainer().remove(remainingKey); + if (left != null && left > 0) plugin.vision().begin(player, left); + } + + @EventHandler + public void onDeviceRemoved(DeviceRemovedEvent event) { + Position at = event.getDevice().position(); + plugin.vision().forget(at); + } + + @EventHandler + public void onDeviceAdded(DeviceAddedEvent event) { + // Shown on the next refresh, but debug players would rather see it at once. + plugin.getServer().getScheduler().runTask(plugin, () -> plugin.vision().refresh()); + } +} diff --git a/src/main/java/com/github/blade/ezdebug/DebugVision.java b/src/main/java/com/github/blade/ezdebug/DebugVision.java new file mode 100644 index 0000000..d5d3028 --- /dev/null +++ b/src/main/java/com/github/blade/ezdebug/DebugVision.java @@ -0,0 +1,155 @@ +package com.github.blade.ezdebug; + +import com.github.blade.ezdebug.model.Activity; +import com.github.blade.ezdebug.model.DebugSettings; +import com.github.blade.ezdebug.model.Palette; +import com.github.blade.hvac.api.EquipmentView; +import com.github.blade.hvac.api.EzvacApi; +import com.github.blade.hvac.api.HvacDevice; +import com.github.blade.hvac.api.Position; +import com.github.blade.hvac.api.ThermostatView; +import com.github.blade.hvac.api.VentView; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.format.NamedTextColor; +import org.bukkit.Color; +import org.bukkit.Particle; +import org.bukkit.World; +import org.bukkit.entity.Player; +import org.bukkit.scheduler.BukkitTask; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Optional; +import java.util.OptionalInt; +import java.util.UUID; + +/** + * Who has debug vision, until when, and what they see: outlines on every + * EZvac sign and piece of equipment near them, and clouds on vents and + * equipment at work. Main thread only. + */ +final class DebugVision { + private final EzDebugPlugin plugin; + private final Outlines outlines; + /** Each debug player's end, in server ticks. */ + private final Map endsAt = new HashMap<>(); + private BukkitTask task; + private long tick; + + DebugVision(EzDebugPlugin plugin) { + this.plugin = plugin; + this.outlines = new Outlines(plugin); + } + + void start() { + stopTask(); + long period = plugin.settings().refreshTicks(); + task = plugin.getServer().getScheduler().runTaskTimer(plugin, () -> { + tick += period; + refresh(); + }, period, period); + } + + private void stopTask() { + if (task != null) task.cancel(); + task = null; + } + + void shutdown() { + stopTask(); + outlines.removeAll(); + } + + boolean active(Player player) { + return endsAt.containsKey(player.getUniqueId()); + } + + /** Ticks of debug vision a player has left, 0 when none. */ + long remaining(Player player) { + Long end = endsAt.get(player.getUniqueId()); + return end == null ? 0L : Math.max(0L, end - tick); + } + + /** Debug vision on for this long, from now (a new potion starts the clock again). */ + void begin(Player player, long ticks) { + endsAt.put(player.getUniqueId(), tick + ticks); + refresh(); + } + + /** Debug vision off. Quietly, when the player is leaving. */ + void end(Player player, boolean tell) { + if (endsAt.remove(player.getUniqueId()) == null) return; + refresh(); + if (tell) player.sendMessage(Component.text("Debug vision fades.", NamedTextColor.GRAY)); + } + + /** A device was removed: its outline goes at once. */ + void forget(Position at) { + outlines.remove(at); + } + + boolean outlined(Position at) { + return outlines.showing(at); + } + + int outlineCount() { + return outlines.size(); + } + + /** Redraws everything: called on the task, and when someone starts or stops. */ + void refresh() { + List viewers = new ArrayList<>(); + for (UUID id : new ArrayList<>(endsAt.keySet())) { + Player player = plugin.getServer().getPlayer(id); + if (player == null) continue; + if (endsAt.get(id) <= tick) { + endsAt.remove(id); + player.sendMessage(Component.text("Debug vision fades.", NamedTextColor.GRAY)); + continue; + } + viewers.add(player); + } + Map wanted = new HashMap<>(); + Map> byWorld = new HashMap<>(); + for (Player player : viewers) byWorld.computeIfAbsent(player.getWorld(), ignored -> new ArrayList<>()).add(player); + for (Map.Entry> entry : byWorld.entrySet()) draw(entry.getKey(), entry.getValue(), wanted); + outlines.show(wanted); + } + + private void draw(World world, List players, Map wanted) { + EzvacApi ezvac = plugin.ezvac(); + DebugSettings settings = plugin.settings(); + Palette palette = settings.palette(); + double radius = settings.radius(); + Activity activity = new Activity(ezvac.thermostats(world)); + for (HvacDevice device : ezvac.devices(world)) { + List near = new ArrayList<>(); + for (Player player : players) if (near(player, device.position(), radius)) near.add(player); + if (near.isEmpty()) continue; + OptionalInt color = palette.outline(device); + if (color.isPresent()) wanted.put(device.position(), new Outlines.Wanted(color.getAsInt(), new HashSet<>(near))); + Optional working = switch (device) { + case VentView vent -> activity.vent(vent); + case EquipmentView equipment -> Activity.equipment(equipment); + default -> Optional.empty(); + }; + if (working.isPresent()) for (Player player : near) cloud(player, device.position(), palette.activity(working.get())); + } + } + + private static boolean near(Player player, Position at, double radius) { + double dx = player.getLocation().getX() - (at.x() + 0.5); + double dy = player.getLocation().getY() - (at.y() + 0.5); + double dz = player.getLocation().getZ() - (at.z() + 0.5); + return dx * dx + dy * dy + dz * dz <= radius * radius; + } + + /** A little coloured cloud on a block, for this player's eyes only. */ + private static void cloud(Player player, Position at, int rgb) { + player.spawnParticle(Particle.DUST, at.x() + 0.5, at.y() + 0.6, at.z() + 0.5, 6, 0.25, 0.2, 0.25, 0.0, + new Particle.DustOptions(Color.fromRGB(rgb), 1.2f)); + } +} diff --git a/src/main/java/com/github/blade/ezdebug/EzDebugPlugin.java b/src/main/java/com/github/blade/ezdebug/EzDebugPlugin.java new file mode 100644 index 0000000..162406c --- /dev/null +++ b/src/main/java/com/github/blade/ezdebug/EzDebugPlugin.java @@ -0,0 +1,74 @@ +package com.github.blade.ezdebug; + +import com.github.blade.ezdebug.model.DebugSettings; +import com.github.blade.hvac.api.EzvacApi; +import org.bukkit.command.PluginCommand; +import org.bukkit.entity.Player; +import org.bukkit.plugin.java.JavaPlugin; + +import java.util.Objects; + +/** + * EZdebug+: a Debug Potion that lets admins see EZvac at work. Built only on + * EZvac's public API (1.2 or newer). + */ +public final class EzDebugPlugin extends JavaPlugin { + private EzvacApi ezvac; + private DebugSettings settings; + private DebugVision vision; + private DebugPotion potion; + + @Override + public void onEnable() { + try { + ezvac = EzvacApi.get(); + } catch (IllegalStateException missing) { + getLogger().severe(missing.getMessage()); + getServer().getPluginManager().disablePlugin(this); + return; + } + if (!supported(ezvac.apiVersion())) { + getLogger().severe("EZdebug+ needs EZvac API 1.2 or newer, but EZvac " + ezvac.pluginVersion() + + " offers API " + ezvac.apiVersion() + ". Update EZvac."); + getServer().getPluginManager().disablePlugin(this); + return; + } + saveDefaultConfig(); + loadSettings(); + vision = new DebugVision(this); + potion = new DebugPotion(this); + getServer().getPluginManager().registerEvents(potion, this); + Commands commands = new Commands(this); + PluginCommand command = Objects.requireNonNull(getCommand("ezdb"), "ezdb is missing from plugin.yml"); + command.setExecutor(commands); + command.setTabCompleter(commands); + for (Player player : getServer().getOnlinePlayers()) potion.resume(player); + vision.start(); + getLogger().info("EZdebug+ enabled on EZvac " + ezvac.pluginVersion() + " (API " + ezvac.apiVersion() + ")."); + } + + @Override + public void onDisable() { + if (vision != null) vision.shutdown(); + } + + /** API 1.2 or newer, within major version 1. */ + static boolean supported(String apiVersion) { + String[] parts = apiVersion.split("\\."); + try { + return parts.length >= 2 && Integer.parseInt(parts[0]) == 1 && Integer.parseInt(parts[1]) >= 2; + } catch (NumberFormatException unknown) { + return false; + } + } + + void loadSettings() { + reloadConfig(); + settings = DebugSettings.load(getConfig(), getLogger()::warning); + } + + EzvacApi ezvac() { return ezvac; } + DebugSettings settings() { return settings; } + DebugVision vision() { return vision; } + DebugPotion potion() { return potion; } +} diff --git a/src/main/java/com/github/blade/ezdebug/Outlines.java b/src/main/java/com/github/blade/ezdebug/Outlines.java new file mode 100644 index 0000000..0050c62 --- /dev/null +++ b/src/main/java/com/github/blade/ezdebug/Outlines.java @@ -0,0 +1,130 @@ +package com.github.blade.ezdebug; + +import com.github.blade.hvac.api.Position; +import org.bukkit.Color; +import org.bukkit.Location; +import org.bukkit.World; +import org.bukkit.block.Block; +import org.bukkit.entity.BlockDisplay; +import org.bukkit.entity.Display; +import org.bukkit.entity.Player; +import org.bukkit.plugin.Plugin; +import org.bukkit.util.Transformation; +import org.joml.AxisAngle4f; +import org.joml.Vector3f; + +import java.util.HashMap; +import java.util.HashSet; +import java.util.Iterator; +import java.util.Map; +import java.util.Set; +import java.util.UUID; + +/** + * Glowing outlines around devices, seen only by players with debug vision. + * Each is a block display: a copy of the device's own block, a hair larger, + * glowing in the device's colour. Hidden from everyone by default and shown + * to each debug player who should see it. Never saved with the world. + * Main thread only. + */ +final class Outlines { + /** Slightly larger than the block, so the copy never flickers against it. */ + private static final float SCALE = 1.02f; + + private static final class Outline { + final BlockDisplay display; + final Set viewers = new HashSet<>(); + int color; + + Outline(BlockDisplay display, int color) { + this.display = display; + this.color = color; + } + } + + /** What one refresh wants outlined: a colour, and who sees it. */ + record Wanted(int color, Set viewers) {} + + private final Plugin plugin; + private final Map outlines = new HashMap<>(); + + Outlines(Plugin plugin) { + this.plugin = plugin; + } + + /** Makes the outlines match this refresh: new ones go up, colours change, stale ones come down. */ + void show(Map wanted) { + for (Iterator> it = outlines.entrySet().iterator(); it.hasNext(); ) { + Map.Entry entry = it.next(); + if (!wanted.containsKey(entry.getKey()) || !entry.getValue().display.isValid()) { + entry.getValue().display.remove(); + it.remove(); + } + } + for (Map.Entry entry : wanted.entrySet()) { + Outline outline = outlines.get(entry.getKey()); + if (outline == null) { + BlockDisplay display = spawn(entry.getKey(), entry.getValue().color()); + if (display == null) continue; + outline = new Outline(display, entry.getValue().color()); + outlines.put(entry.getKey(), outline); + } else if (outline.color != entry.getValue().color()) { + outline.color = entry.getValue().color(); + outline.display.setGlowColorOverride(Color.fromRGB(outline.color)); + } + reveal(outline, entry.getValue().viewers()); + } + } + + private void reveal(Outline outline, Set viewers) { + Set now = new HashSet<>(); + for (Player player : viewers) { + now.add(player.getUniqueId()); + if (outline.viewers.add(player.getUniqueId())) player.showEntity(plugin, outline.display); + } + for (Iterator it = outline.viewers.iterator(); it.hasNext(); ) { + UUID viewer = it.next(); + if (now.contains(viewer)) continue; + Player player = plugin.getServer().getPlayer(viewer); + if (player != null) player.hideEntity(plugin, outline.display); + it.remove(); + } + } + + /** A copy of the block at this spot, glowing; null when its world or chunk isn't loaded. */ + private BlockDisplay spawn(Position at, int color) { + World world = plugin.getServer().getWorld(at.world()); + if (world == null || !world.isChunkLoaded(at.x() >> 4, at.z() >> 4)) return null; + Block block = world.getBlockAt(at.x(), at.y(), at.z()); + if (block.getType().isAir()) return null; + float shift = (1f - SCALE) / 2f; + return world.spawn(new Location(world, at.x(), at.y(), at.z()), BlockDisplay.class, display -> { + display.setPersistent(false); + display.setVisibleByDefault(false); + display.setBlock(block.getBlockData()); + display.setGlowing(true); + display.setGlowColorOverride(Color.fromRGB(color)); + display.setBrightness(new Display.Brightness(15, 15)); + display.setTransformation(new Transformation(new Vector3f(shift, shift, shift), new AxisAngle4f(), + new Vector3f(SCALE, SCALE, SCALE), new AxisAngle4f())); + }); + } + + /** Takes one device's outline down at once, when the device is removed. */ + void remove(Position at) { + Outline outline = outlines.remove(at); + if (outline != null) outline.display.remove(); + } + + /** True while an outline is up at this spot. */ + boolean showing(Position at) { + return outlines.containsKey(at); + } + + int size() { return outlines.size(); } + + void removeAll() { + for (Outline outline : outlines.values()) outline.display.remove(); + outlines.clear(); + } +} diff --git a/src/main/java/com/github/blade/ezdebug/model/Activity.java b/src/main/java/com/github/blade/ezdebug/model/Activity.java new file mode 100644 index 0000000..1cc20d5 --- /dev/null +++ b/src/main/java/com/github/blade/ezdebug/model/Activity.java @@ -0,0 +1,33 @@ +package com.github.blade.ezdebug.model; + +import com.github.blade.hvac.api.EquipmentView; +import com.github.blade.hvac.api.ThermostatView; +import com.github.blade.hvac.api.VentView; + +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; +import java.util.Optional; + +/** Which vents and equipment are at work right now, from EZvac's views of one world. Pure. */ +public final class Activity { + private final Map working = new HashMap<>(); + + /** @param thermostats the thermostats of one world: system names are unique within a world */ + public Activity(Collection thermostats) { + for (ThermostatView thermostat : thermostats) + if (thermostat.enabled() && thermostat.mode() != ThermostatView.Mode.IDLE) + working.put(thermostat.system(), thermostat.mode()); + } + + /** What a vent is blowing: its system's mode while the system cools or heats, else empty. */ + public Optional vent(VentView vent) { + return Optional.ofNullable(working.get(vent.system())); + } + + /** What a unit is doing while it runs, else empty. */ + public static Optional equipment(EquipmentView equipment) { + if (!equipment.running() || equipment.mode() == ThermostatView.Mode.IDLE) return Optional.empty(); + return Optional.of(equipment.mode()); + } +} diff --git a/src/main/java/com/github/blade/ezdebug/model/DebugSettings.java b/src/main/java/com/github/blade/ezdebug/model/DebugSettings.java new file mode 100644 index 0000000..9b261f9 --- /dev/null +++ b/src/main/java/com/github/blade/ezdebug/model/DebugSettings.java @@ -0,0 +1,66 @@ +package com.github.blade.ezdebug.model; + +import org.bukkit.configuration.ConfigurationSection; +import org.bukkit.configuration.MemoryConfiguration; + +import java.util.Locale; +import java.util.function.Consumer; +import java.util.function.Supplier; + +/** + * Everything in config.yml, checked. A bad value warns and its part falls + * back to the defaults; the rest load as written. + * + * @param durationSeconds how long a Debug Potion lasts + * @param radius devices are shown within this many blocks of the player + * @param refreshTicks how often outlines and clouds are redrawn + * @param effect the vanilla effect that shows the countdown (a key such as night_vision), or "none" + * @param palette the colours + */ +public record DebugSettings(int durationSeconds, double radius, long refreshTicks, String effect, Palette palette) { + public DebugSettings { + if (durationSeconds < 1) throw new IllegalArgumentException("duration-minutes must be above 0"); + if (!(radius >= 4 && radius <= 128)) throw new IllegalArgumentException("radius must be 4 to 128 blocks"); + if (refreshTicks < 2 || refreshTicks > 100) throw new IllegalArgumentException("refresh-ticks must be 2 to 100"); + effect = effect == null || effect.isBlank() ? "none" : effect.trim().toLowerCase(Locale.ROOT); + } + + public static DebugSettings defaults() { + return load(new MemoryConfiguration(), warning -> { }); + } + + public long durationTicks() { return durationSeconds * 20L; } + + public static DebugSettings load(ConfigurationSection config, Consumer warn) { + Palette p = Palette.defaults(); + Palette palette = part("colors", warn, () -> new Palette( + color(config, "colors.thermostat", p.thermostat()), color(config, "colors.thermometer", p.thermometer()), + color(config, "colors.rpm-monitor", p.rpmMonitor()), color(config, "colors.settings-panel", p.settingsPanel()), + color(config, "colors.sensor-hub", p.sensorHub()), color(config, "colors.climate-unit", p.climateUnit()), + color(config, "colors.stopped", p.stopped()), color(config, "colors.cooling", p.cooling()), + color(config, "colors.heating", p.heating())), () -> p); + return part("debug", warn, () -> new DebugSettings( + (int) Math.round(config.getDouble("duration-minutes", 8.0) * 60.0), + config.getDouble("radius", 32.0), config.getLong("refresh-ticks", 10L), + config.getString("effect", "night_vision"), palette), + () -> new DebugSettings(480, 32.0, 10L, "night_vision", palette)); + } + + /** {@code "#RRGGBB"} as 0xRRGGBB. */ + static int color(ConfigurationSection config, String path, int fallback) { + String text = config.getString(path); + if (text == null) return fallback; + String hex = text.trim(); + if (!hex.matches("#[0-9a-fA-F]{6}")) throw new IllegalArgumentException(path + " must be #RRGGBB, not '" + text + "'"); + return Integer.parseInt(hex.substring(1), 16); + } + + private static T part(String name, Consumer warn, Supplier reader, Supplier fallback) { + try { + return reader.get(); + } catch (IllegalArgumentException invalid) { + warn.accept(invalid.getMessage() + ", so the " + name + " settings use their defaults until config.yml is fixed."); + return fallback.get(); + } + } +} diff --git a/src/main/java/com/github/blade/ezdebug/model/Palette.java b/src/main/java/com/github/blade/ezdebug/model/Palette.java new file mode 100644 index 0000000..37f3231 --- /dev/null +++ b/src/main/java/com/github/blade/ezdebug/model/Palette.java @@ -0,0 +1,48 @@ +package com.github.blade.ezdebug.model; + +import com.github.blade.hvac.api.ClimateUnitView; +import com.github.blade.hvac.api.EquipmentView; +import com.github.blade.hvac.api.HvacDevice; +import com.github.blade.hvac.api.InstrumentView; +import com.github.blade.hvac.api.ThermostatView; +import com.github.blade.hvac.api.VentView; + +import java.util.OptionalInt; + +/** + * The colours debug vision draws in, as 0xRRGGBB. Every EZvac sign is + * outlined in its kind's colour; equipment is outlined by what it is doing; + * clouds show cooling or heating. Pure. + */ +public record Palette(int thermostat, int thermometer, int rpmMonitor, int settingsPanel, int sensorHub, + int climateUnit, int stopped, int cooling, int heating) { + public static Palette defaults() { + return new Palette(0x55FFFF, 0xFFFFFF, 0xFFFF55, 0xFF77FF, 0x55FF55, 0x5599FF, 0x8A8A8A, 0x55DDFF, 0xFF9933); + } + + /** The outline colour for a device, or empty for devices that aren't outlined (vents, sensor buttons). */ + public OptionalInt outline(HvacDevice device) { + return switch (device) { + case ThermostatView ignored -> OptionalInt.of(thermostat); + case EquipmentView equipment -> OptionalInt.of(equipment.running() ? activity(equipment.mode()) : stopped); + case ClimateUnitView ignored -> OptionalInt.of(climateUnit); + case VentView ignored -> OptionalInt.empty(); + case InstrumentView instrument -> switch (instrument.kind()) { + case THERMOMETER, HYGROMETER, THERMO_HYGROMETER -> OptionalInt.of(thermometer); + case RPM_MONITOR -> OptionalInt.of(rpmMonitor); + case SETTINGS_PANEL -> OptionalInt.of(settingsPanel); + case SENSOR_HUB -> OptionalInt.of(sensorHub); + case TEMPERATURE_SENSOR, HUMIDITY_SENSOR, TEMPERATURE_HUMIDITY_SENSOR, WEATHER_SENSOR -> OptionalInt.empty(); + }; + }; + } + + /** Cooling or heating, for clouds and running equipment; a unit running in IDLE reads as stopped. */ + public int activity(ThermostatView.Mode mode) { + return switch (mode) { + case COOLING -> cooling; + case HEATING -> heating; + case IDLE -> stopped; + }; + } +} diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml new file mode 100644 index 0000000..4e1da6b --- /dev/null +++ b/src/main/resources/config.yml @@ -0,0 +1,33 @@ +# EZdebug+: a Debug Potion that shows EZvac at work. /ezdb debug gives one; +# drinking it outlines every EZvac sign and piece of equipment near you, and +# working vents and equipment puff a small cloud: cyan while cooling, orange +# while heating. Only the player who drank it sees any of it. Milk ends it. + +# How long a Debug Potion lasts. +duration-minutes: 8 + +# Devices are shown within this many blocks of you (4 to 128). +radius: 32 + +# How often outlines and clouds are redrawn, in ticks (20 = a second). +refresh-ticks: 10 + +# A vanilla effect shown for as long as it lasts, so the countdown is on +# screen. night_vision also helps in dark plant rooms; none shows nothing. +effect: night_vision + +# Outline and cloud colours, as #RRGGBB. +colors: + thermostat: "#55FFFF" + # Thermometers, hygrometers and thermo-hygrometers. + thermometer: "#FFFFFF" + rpm-monitor: "#FFFF55" + settings-panel: "#FF77FF" + sensor-hub: "#55FF55" + # Dehumidifier and humidifier signs. + climate-unit: "#5599FF" + # Equipment that isn't running. + stopped: "#8A8A8A" + # Equipment running, and clouds, while cooling or heating. + cooling: "#55DDFF" + heating: "#FF9933" diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml new file mode 100644 index 0000000..4f21ed5 --- /dev/null +++ b/src/main/resources/plugin.yml @@ -0,0 +1,17 @@ +name: EZdebugPlus +version: '${project.version}' +main: com.github.blade.ezdebug.EzDebugPlugin +api-version: '1.21' +author: bladestech +description: "EZdebug+: a Debug Potion that shows EZvac's devices at work. An addon for EZvac." +depend: [EZvac] +commands: + ezdb: + description: EZdebug+ commands. + usage: /ezdb [player] | /ezdb reload + permission: ezdebug.use + aliases: [ezdebug] +permissions: + ezdebug.use: + description: Allows /ezdb debug, off and reload. + default: op diff --git a/src/test/java/com/github/blade/ezdebug/PluginBitsTest.java b/src/test/java/com/github/blade/ezdebug/PluginBitsTest.java new file mode 100644 index 0000000..ad80dec --- /dev/null +++ b/src/test/java/com/github/blade/ezdebug/PluginBitsTest.java @@ -0,0 +1,25 @@ +package com.github.blade.ezdebug; + +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.*; + +/** The API version check and the potion's clock. */ +class PluginBitsTest { + @Test + void needsApi12OrNewerWithinMajorVersionOne() { + assertTrue(EzDebugPlugin.supported("1.2")); + assertTrue(EzDebugPlugin.supported("1.10")); + assertFalse(EzDebugPlugin.supported("1.1")); + assertFalse(EzDebugPlugin.supported("1.0")); + assertFalse(EzDebugPlugin.supported("2.0"), "a new major version may break us"); + assertFalse(EzDebugPlugin.supported("odd")); + } + + @Test + void theClockReadsMinutesAndSeconds() { + assertEquals("8:00", DebugPotion.clock(9600)); + assertEquals("0:30", DebugPotion.clock(600)); + assertEquals("1:05", DebugPotion.clock(1300)); + } +} diff --git a/src/test/java/com/github/blade/ezdebug/model/DebugModelTest.java b/src/test/java/com/github/blade/ezdebug/model/DebugModelTest.java new file mode 100644 index 0000000..b7168e4 --- /dev/null +++ b/src/test/java/com/github/blade/ezdebug/model/DebugModelTest.java @@ -0,0 +1,114 @@ +package com.github.blade.ezdebug.model; + +import com.github.blade.hvac.api.ClimateUnitView; +import com.github.blade.hvac.api.EquipmentView; +import com.github.blade.hvac.api.InstrumentView; +import com.github.blade.hvac.api.Position; +import com.github.blade.hvac.api.ThermostatView; +import com.github.blade.hvac.api.VentView; +import com.github.blade.hvac.api.event.EquipmentStateChangeEvent; +import org.bukkit.configuration.file.YamlConfiguration; +import org.junit.jupiter.api.Test; + +import java.io.InputStreamReader; +import java.nio.charset.StandardCharsets; +import java.util.ArrayList; +import java.util.List; +import java.util.Objects; +import java.util.Optional; +import java.util.OptionalInt; +import java.util.UUID; + +import static org.junit.jupiter.api.Assertions.*; + +/** The colours, what counts as at work, and config.yml. */ +class DebugModelTest { + private static final UUID WORLD = UUID.fromString("0b6c3f0e-6a77-4f3e-9d6b-2f1c9a7e4d10"); + private static final Position AT = new Position(WORLD, 1, 64, 1); + private final Palette palette = Palette.defaults(); + + private static ThermostatView thermostat(String system, ThermostatView.Mode mode, boolean enabled) { + return new ThermostatView(system + "-t", system, AT, 70, 72, mode, enabled, false, 40, 1, 1); + } + + private static EquipmentView equipment(boolean running, ThermostatView.Mode mode) { + return new EquipmentView(EquipmentStateChangeEvent.Kind.FURNACE, "house", AT, true, running, mode, + running ? 2700 : 0); + } + + private static InstrumentView instrument(InstrumentView.Kind kind) { + return new InstrumentView(kind, "x", AT, Optional.empty(), List.of()); + } + + @Test + void everySignHasItsKindsColourAndButtonsAndVentsHaveNone() { + assertEquals(OptionalInt.of(palette.thermostat()), palette.outline(thermostat("house", ThermostatView.Mode.IDLE, true))); + assertEquals(OptionalInt.of(palette.thermometer()), palette.outline(instrument(InstrumentView.Kind.HYGROMETER))); + assertEquals(OptionalInt.of(palette.rpmMonitor()), palette.outline(instrument(InstrumentView.Kind.RPM_MONITOR))); + assertEquals(OptionalInt.of(palette.settingsPanel()), palette.outline(instrument(InstrumentView.Kind.SETTINGS_PANEL))); + assertEquals(OptionalInt.of(palette.sensorHub()), palette.outline(instrument(InstrumentView.Kind.SENSOR_HUB))); + assertEquals(OptionalInt.of(palette.climateUnit()), palette.outline(new ClimateUnitView("dry", + ClimateUnitView.Kind.DEHUMIDIFIER, AT, 50, 40, true, ClimateUnitView.State.IDLE, 0))); + for (InstrumentView.Kind kind : InstrumentView.Kind.values()) + if (kind.sensor()) assertEquals(OptionalInt.empty(), palette.outline(instrument(kind)), kind + " is a button"); + assertEquals(OptionalInt.empty(), palette.outline(new VentView("house", AT, VentView.Medium.AIR))); + } + + @Test + void equipmentIsColouredByWhatItDoes() { + assertEquals(OptionalInt.of(palette.stopped()), palette.outline(equipment(false, ThermostatView.Mode.IDLE))); + assertEquals(OptionalInt.of(palette.heating()), palette.outline(equipment(true, ThermostatView.Mode.HEATING))); + assertEquals(OptionalInt.of(palette.cooling()), palette.outline(equipment(true, ThermostatView.Mode.COOLING))); + assertEquals(OptionalInt.of(palette.stopped()), palette.outline(equipment(true, ThermostatView.Mode.IDLE))); + } + + @Test + void ventsWorkWhileTheirSystemCoolsOrHeats() { + Activity activity = new Activity(List.of(thermostat("house", ThermostatView.Mode.HEATING, true), + thermostat("office", ThermostatView.Mode.IDLE, true), + thermostat("garage", ThermostatView.Mode.COOLING, false))); + assertEquals(Optional.of(ThermostatView.Mode.HEATING), activity.vent(new VentView("house", AT, VentView.Medium.AIR))); + assertEquals(Optional.empty(), activity.vent(new VentView("office", AT, VentView.Medium.AIR)), "idle"); + assertEquals(Optional.empty(), activity.vent(new VentView("garage", AT, VentView.Medium.AIR)), "switched off"); + assertEquals(Optional.empty(), activity.vent(new VentView("shed", AT, VentView.Medium.AIR)), "no thermostat"); + assertEquals(Optional.of(ThermostatView.Mode.HEATING), Activity.equipment(equipment(true, ThermostatView.Mode.HEATING))); + assertEquals(Optional.empty(), Activity.equipment(equipment(false, ThermostatView.Mode.IDLE))); + } + + @Test + void theBundledConfigIsTheDefaults() throws Exception { + YamlConfiguration bundled = new YamlConfiguration(); + try (var reader = new InputStreamReader(Objects.requireNonNull( + DebugModelTest.class.getResourceAsStream("/config.yml")), StandardCharsets.UTF_8)) { + bundled.load(reader); + } + List warnings = new ArrayList<>(); + assertEquals(DebugSettings.defaults(), DebugSettings.load(bundled, warnings::add)); + assertTrue(warnings.isEmpty(), warnings::toString); + DebugSettings defaults = DebugSettings.defaults(); + assertEquals(480, defaults.durationSeconds(), "8 minutes"); + assertEquals(9600, defaults.durationTicks()); + assertEquals("night_vision", defaults.effect()); + } + + @Test + void badValuesWarnAndFallBack() { + YamlConfiguration config = new YamlConfiguration(); + config.set("colors.heating", "orange"); + config.set("radius", 2000); + config.set("duration-minutes", 3); + List warnings = new ArrayList<>(); + DebugSettings loaded = DebugSettings.load(config, warnings::add); + assertEquals(2, warnings.size(), warnings::toString); + assertEquals(Palette.defaults(), loaded.palette()); + assertEquals(32.0, loaded.radius()); + assertEquals(480, loaded.durationSeconds(), "the whole part falls back, as in LiveExposure"); + + YamlConfiguration short_ = new YamlConfiguration(); + short_.set("duration-minutes", 0.5); + short_.set("effect", "NONE"); + DebugSettings quick = DebugSettings.load(short_, warning -> fail(warning)); + assertEquals(30, quick.durationSeconds()); + assertEquals("none", quick.effect()); + } +} From d951bc8f74ffbd326635a4e47251b3785f26f57b Mon Sep 17 00:00:00 2001 From: bladestech Date: Sun, 25 Oct 2026 12:31:54 +0200 Subject: [PATCH 2/4] Frame signs in coloured specks instead of outlining them A block display can't copy a sign's board, which Minecraft draws with a block-entity renderer, so signs never glowed. They get a dotted frame in their kind's colour instead; equipment keeps its glowing outline. Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 7 +- CONTRIBUTING.md | 3 +- README.md | 22 +++--- .../com/github/blade/ezdebug/DebugVision.java | 42 +++++++++-- .../com/github/blade/ezdebug/Outlines.java | 8 +-- .../github/blade/ezdebug/model/Palette.java | 6 +- .../github/blade/ezdebug/model/SignFrame.java | 72 +++++++++++++++++++ src/main/resources/config.yml | 4 +- .../blade/ezdebug/model/DebugModelTest.java | 42 +++++++---- 9 files changed, 165 insertions(+), 41 deletions(-) create mode 100644 src/main/java/com/github/blade/ezdebug/model/SignFrame.java diff --git a/CHANGELOG.md b/CHANGELOG.md index 2c19a2e..9e40e41 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,10 +10,9 @@ The first release: the Debug Potion. Needs EZvac with API 1.2 or newer. - **`/ezdb debug [player]`** gives a Debug Potion (`ezdebug.use`, ops). - **Drinking it** gives 8 minutes of debug vision, seen only by that player: - - glowing outlines on every EZvac sign, coloured by kind, visible through - walls; - - glowing outlines on all equipment: grey stopped, cyan cooling, orange - heating; + - a coloured frame around every EZvac sign, coloured by kind; + - glowing outlines on all equipment, visible through walls: grey stopped, + cyan cooling, orange heating; - small clouds on the vents of systems that are cooling or heating, and on running equipment. - **Ending it:** milk, death, the timer, or `/ezdb off`. The remaining time diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 48c016e..5a8ed93 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -22,6 +22,7 @@ Every push and pull request is built and tested by GitHub Actions. - **The code only touches EZvac through its public API** (`ezvac-api`, from JitPack). Never reach into EZvac's internals: that is what keeps EZdebug+ working across EZvac releases. - **The pure, unit-tested logic is in `model/`:** - `Palette` picks the colour for a device and what it's doing; + - `SignFrame` places the specks around a sign's board; - `Activity` says which vents and equipment are at work; - `DebugSettings` reads and checks config.yml. @@ -29,5 +30,5 @@ Every push and pull request is built and tested by GitHub Actions. - **The Bukkit side:** - `DebugPotion`: the item, drinking it, milk, death, relogs, and EZvac's device events; - `DebugVision`: who has debug vision and the redraw task; - - `Outlines`: the glowing block displays, shown only to debug players; + - `Outlines`: equipment's glowing block displays, shown only to debug players; - `Commands`. diff --git a/README.md b/README.md index 1c921f1..628a501 100644 --- a/README.md +++ b/README.md @@ -4,11 +4,11 @@ the realistic HVAC and indoor-climate plugin for Paper and Purpur. `/ezdb debug` gives you a **Debug Potion**. Drink it, and for 8 minutes: -- **every EZvac sign glows** with an outline, in a colour for its kind. You - can see them through walls, so a thermostat behind a painting or a monitor - in a plant room is easy to find; -- **every piece of equipment glows** too: grey while it's stopped, cyan - while it cools, orange while it heats; +- **every EZvac sign gets a coloured frame:** a ring of specks around its + board, in a colour for its kind; +- **every piece of equipment glows** with an outline you can see through + walls, so equipment hidden in a casing is easy to find: grey while it's + stopped, cyan while it cools, orange while it heats; - **working vents puff a little cloud,** cyan or orange, while their system cools or heats, and so does running equipment. @@ -21,7 +21,7 @@ and so does dying. ## Colours -| Outline | Colour | +| Device | Colour | | --- | --- | | Thermostats | aqua | | Thermometers, hygrometers, thermo-hygrometers | white | @@ -31,7 +31,9 @@ and so does dying. | Dehumidifier and humidifier signs | blue | | Equipment | grey when stopped, cyan cooling, orange heating | -Clouds are cyan for cooling and orange for heating. Every colour can be +Clouds are cyan for cooling and orange for heating. (Signs get a frame +rather than a glow: Minecraft draws sign boards in a way a glowing copy +can't trace.) Every colour can be changed in config.yml. ## Commands and permissions @@ -59,9 +61,9 @@ A bad value warns in the console and that part uses its defaults. EZdebug+ is built only on EZvac's public API: `devices(world)` lists every device with its position, the equipment and thermostat views say what's -running, and the device events keep the outlines in step. Outlines are block -displays that only debug players are shown; they're never saved with the -world. See [EZvac's API guide](https://github.com/EZvac-Plugin/EZvac/blob/main/docs/api.md). +running, and the device events keep the outlines in step. Equipment outlines +are block displays that only debug players are shown; they're never saved +with the world. Frames and clouds are particles sent to debug players only. See [EZvac's API guide](https://github.com/EZvac-Plugin/EZvac/blob/main/docs/api.md). ## Building diff --git a/src/main/java/com/github/blade/ezdebug/DebugVision.java b/src/main/java/com/github/blade/ezdebug/DebugVision.java index d5d3028..81ce552 100644 --- a/src/main/java/com/github/blade/ezdebug/DebugVision.java +++ b/src/main/java/com/github/blade/ezdebug/DebugVision.java @@ -3,6 +3,7 @@ import com.github.blade.ezdebug.model.Activity; import com.github.blade.ezdebug.model.DebugSettings; import com.github.blade.ezdebug.model.Palette; +import com.github.blade.ezdebug.model.SignFrame; import com.github.blade.hvac.api.EquipmentView; import com.github.blade.hvac.api.EzvacApi; import com.github.blade.hvac.api.HvacDevice; @@ -13,7 +14,16 @@ import net.kyori.adventure.text.format.NamedTextColor; import org.bukkit.Color; import org.bukkit.Particle; +import org.bukkit.Tag; import org.bukkit.World; +import org.bukkit.block.Block; +import org.bukkit.block.BlockFace; +import org.bukkit.block.data.BlockData; +import org.bukkit.block.data.Directional; +import org.bukkit.block.data.Rotatable; +import org.bukkit.block.data.type.HangingSign; +import org.bukkit.block.data.type.WallHangingSign; +import org.bukkit.block.data.type.WallSign; import org.bukkit.entity.Player; import org.bukkit.scheduler.BukkitTask; @@ -27,9 +37,9 @@ import java.util.UUID; /** - * Who has debug vision, until when, and what they see: outlines on every - * EZvac sign and piece of equipment near them, and clouds on vents and - * equipment at work. Main thread only. + * Who has debug vision, until when, and what they see: a coloured frame + * around every EZvac sign near them, glowing outlines on equipment, and + * clouds on vents and equipment at work. Main thread only. */ final class DebugVision { private final EzDebugPlugin plugin; @@ -129,8 +139,12 @@ private void draw(World world, List players, Map near = new ArrayList<>(); for (Player player : players) if (near(player, device.position(), radius)) near.add(player); if (near.isEmpty()) continue; - OptionalInt color = palette.outline(device); - if (color.isPresent()) wanted.put(device.position(), new Outlines.Wanted(color.getAsInt(), new HashSet<>(near))); + OptionalInt color = palette.color(device); + if (color.isPresent()) { + if (device instanceof EquipmentView) + wanted.put(device.position(), new Outlines.Wanted(color.getAsInt(), new HashSet<>(near))); + else frame(world, device.position(), color.getAsInt(), near); + } Optional working = switch (device) { case VentView vent -> activity.vent(vent); case EquipmentView equipment -> Activity.equipment(equipment); @@ -147,6 +161,24 @@ private static boolean near(Player player, Position at, double radius) { return dx * dx + dy * dy + dz * dz <= radius * radius; } + /** A dotted frame around a sign's board, in its kind's colour, for these players' eyes only. */ + private static void frame(World world, Position at, int rgb, List players) { + if (!world.isChunkLoaded(at.x() >> 4, at.z() >> 4)) return; + Block block = world.getBlockAt(at.x(), at.y(), at.z()); + if (!Tag.ALL_SIGNS.isTagged(block.getType())) return; + BlockData sign = block.getBlockData(); + SignFrame.Mount mount = sign instanceof WallSign ? SignFrame.Mount.WALL + : sign instanceof WallHangingSign || sign instanceof HangingSign ? SignFrame.Mount.HANGING + : SignFrame.Mount.STANDING; + BlockFace facing = sign instanceof Directional directional ? directional.getFacing() + : sign instanceof Rotatable rotatable ? rotatable.getRotation() : BlockFace.SOUTH; + Particle.DustOptions dust = new Particle.DustOptions(Color.fromRGB(rgb), 0.6f); + for (SignFrame.Point point : SignFrame.of(mount, facing.getDirection().getX(), facing.getDirection().getZ())) + for (Player player : players) + player.spawnParticle(Particle.DUST, at.x() + point.x(), at.y() + point.y(), at.z() + point.z(), 1, + 0.0, 0.0, 0.0, 0.0, dust); + } + /** A little coloured cloud on a block, for this player's eyes only. */ private static void cloud(Player player, Position at, int rgb) { player.spawnParticle(Particle.DUST, at.x() + 0.5, at.y() + 0.6, at.z() + 0.5, 6, 0.25, 0.2, 0.25, 0.0, diff --git a/src/main/java/com/github/blade/ezdebug/Outlines.java b/src/main/java/com/github/blade/ezdebug/Outlines.java index 0050c62..d622a7e 100644 --- a/src/main/java/com/github/blade/ezdebug/Outlines.java +++ b/src/main/java/com/github/blade/ezdebug/Outlines.java @@ -21,9 +21,9 @@ import java.util.UUID; /** - * Glowing outlines around devices, seen only by players with debug vision. - * Each is a block display: a copy of the device's own block, a hair larger, - * glowing in the device's colour. Hidden from everyone by default and shown + * Glowing outlines around equipment, seen only by players with debug vision. + * Each is a block display: a copy of the dispenser, a hair larger, glowing in + * the colour of what it's doing. (Signs can't glow: see SignFrame.) Hidden from everyone by default and shown * to each debug player who should see it. Never saved with the world. * Main thread only. */ @@ -91,7 +91,7 @@ private void reveal(Outline outline, Set viewers) { } } - /** A copy of the block at this spot, glowing; null when its world or chunk isn't loaded. */ + /** A copy of the block at this spot, a hair larger, glowing; null when its world or chunk isn't loaded. */ private BlockDisplay spawn(Position at, int color) { World world = plugin.getServer().getWorld(at.world()); if (world == null || !world.isChunkLoaded(at.x() >> 4, at.z() >> 4)) return null; diff --git a/src/main/java/com/github/blade/ezdebug/model/Palette.java b/src/main/java/com/github/blade/ezdebug/model/Palette.java index 37f3231..d8ebe3b 100644 --- a/src/main/java/com/github/blade/ezdebug/model/Palette.java +++ b/src/main/java/com/github/blade/ezdebug/model/Palette.java @@ -11,7 +11,7 @@ /** * The colours debug vision draws in, as 0xRRGGBB. Every EZvac sign is - * outlined in its kind's colour; equipment is outlined by what it is doing; + * framed in its kind's colour; equipment is outlined by what it is doing; * clouds show cooling or heating. Pure. */ public record Palette(int thermostat, int thermometer, int rpmMonitor, int settingsPanel, int sensorHub, @@ -20,8 +20,8 @@ public static Palette defaults() { return new Palette(0x55FFFF, 0xFFFFFF, 0xFFFF55, 0xFF77FF, 0x55FF55, 0x5599FF, 0x8A8A8A, 0x55DDFF, 0xFF9933); } - /** The outline colour for a device, or empty for devices that aren't outlined (vents, sensor buttons). */ - public OptionalInt outline(HvacDevice device) { + /** A device's colour: its sign's frame, or equipment's outline; empty for vents and sensor buttons. */ + public OptionalInt color(HvacDevice device) { return switch (device) { case ThermostatView ignored -> OptionalInt.of(thermostat); case EquipmentView equipment -> OptionalInt.of(equipment.running() ? activity(equipment.mode()) : stopped); diff --git a/src/main/java/com/github/blade/ezdebug/model/SignFrame.java b/src/main/java/com/github/blade/ezdebug/model/SignFrame.java new file mode 100644 index 0000000..0949b77 --- /dev/null +++ b/src/main/java/com/github/blade/ezdebug/model/SignFrame.java @@ -0,0 +1,72 @@ +package com.github.blade.ezdebug.model; + +import java.util.ArrayList; +import java.util.List; + +/** + * A dotted frame of coloured specks around a sign's board, in the colour of + * its kind. Signs can't glow: Minecraft draws their boards with a + * block-entity renderer that a display entity can't copy. The frame sits just + * in front of the board and a little wider, so it rings the board and the + * screen on it. Pure: points are relative to the sign block's corner. + */ +public final class SignFrame { + private SignFrame() {} + + /** How a sign is put up, which decides where its board is (EZvac's own screen measurements). */ + public enum Mount { + /** On the side of a block: the board lies against that block. */ + WALL(1.0, 0.5, 0.53, -0.375), + /** On a post: the board is in the middle of the block, near its top. */ + STANDING(1.0, 0.5, 0.77, 0.04), + /** A hanging sign, on a wall or under a ceiling: a smaller board, low in the block. */ + HANGING(0.875, 0.625, 0.31, 0.0625); + + final double width, height, centreY; + /** Where the board's front face is, along the way the sign faces, from the block's middle. */ + final double front; + + Mount(double width, double height, double centreY, double front) { + this.width = width; + this.height = height; + this.centreY = centreY; + this.front = front; + } + } + + /** The frame is this much wider and taller than the board, so it rings it. */ + static final double MARGIN = 1.1; + /** And this far in front of the board's face, so the board never hides it. */ + static final double AHEAD = 0.12; + /** Specks along each side, corners included. */ + static final int PER_SIDE = 5; + + /** One speck. */ + public record Point(double x, double y, double z) {} + + /** @param facingX the way the sign's text faces, as a horizontal direction */ + public static List of(Mount mount, double facingX, double facingZ) { + double length = Math.hypot(facingX, facingZ); + double fx = length == 0.0 ? 0.0 : facingX / length, fz = length == 0.0 ? 1.0 : facingZ / length; + // Along the board: facing turned a quarter, so the frame lies flat on the board's face. + double rx = fz, rz = -fx; + double cx = 0.5 + fx * (mount.front + AHEAD), cz = 0.5 + fz * (mount.front + AHEAD); + double halfWidth = mount.width * MARGIN / 2.0, halfHeight = mount.height * MARGIN / 2.0; + List points = new ArrayList<>(); + for (int i = 0; i < PER_SIDE; i++) { + double t = -1.0 + 2.0 * i / (PER_SIDE - 1); + double along = t * halfWidth; + points.add(at(cx, cz, rx, rz, along, mount.centreY + halfHeight)); + points.add(at(cx, cz, rx, rz, along, mount.centreY - halfHeight)); + if (i == 0 || i == PER_SIDE - 1) continue; + double up = t * halfHeight; + points.add(at(cx, cz, rx, rz, -halfWidth, mount.centreY + up)); + points.add(at(cx, cz, rx, rz, halfWidth, mount.centreY + up)); + } + return points; + } + + private static Point at(double cx, double cz, double rx, double rz, double along, double y) { + return new Point(cx + rx * along, y, cz + rz * along); + } +} diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 4e1da6b..8ead629 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -1,5 +1,5 @@ # EZdebug+: a Debug Potion that shows EZvac at work. /ezdb debug gives one; -# drinking it outlines every EZvac sign and piece of equipment near you, and +# drinking it frames every EZvac sign and outlines the equipment near you, and # working vents and equipment puff a small cloud: cyan while cooling, orange # while heating. Only the player who drank it sees any of it. Milk ends it. @@ -16,7 +16,7 @@ refresh-ticks: 10 # screen. night_vision also helps in dark plant rooms; none shows nothing. effect: night_vision -# Outline and cloud colours, as #RRGGBB. +# Colours, as #RRGGBB: the frames around signs, equipment outlines, and clouds. colors: thermostat: "#55FFFF" # Thermometers, hygrometers and thermo-hygrometers. diff --git a/src/test/java/com/github/blade/ezdebug/model/DebugModelTest.java b/src/test/java/com/github/blade/ezdebug/model/DebugModelTest.java index b7168e4..e1f91ef 100644 --- a/src/test/java/com/github/blade/ezdebug/model/DebugModelTest.java +++ b/src/test/java/com/github/blade/ezdebug/model/DebugModelTest.java @@ -42,24 +42,24 @@ private static InstrumentView instrument(InstrumentView.Kind kind) { @Test void everySignHasItsKindsColourAndButtonsAndVentsHaveNone() { - assertEquals(OptionalInt.of(palette.thermostat()), palette.outline(thermostat("house", ThermostatView.Mode.IDLE, true))); - assertEquals(OptionalInt.of(palette.thermometer()), palette.outline(instrument(InstrumentView.Kind.HYGROMETER))); - assertEquals(OptionalInt.of(palette.rpmMonitor()), palette.outline(instrument(InstrumentView.Kind.RPM_MONITOR))); - assertEquals(OptionalInt.of(palette.settingsPanel()), palette.outline(instrument(InstrumentView.Kind.SETTINGS_PANEL))); - assertEquals(OptionalInt.of(palette.sensorHub()), palette.outline(instrument(InstrumentView.Kind.SENSOR_HUB))); - assertEquals(OptionalInt.of(palette.climateUnit()), palette.outline(new ClimateUnitView("dry", + assertEquals(OptionalInt.of(palette.thermostat()), palette.color(thermostat("house", ThermostatView.Mode.IDLE, true))); + assertEquals(OptionalInt.of(palette.thermometer()), palette.color(instrument(InstrumentView.Kind.HYGROMETER))); + assertEquals(OptionalInt.of(palette.rpmMonitor()), palette.color(instrument(InstrumentView.Kind.RPM_MONITOR))); + assertEquals(OptionalInt.of(palette.settingsPanel()), palette.color(instrument(InstrumentView.Kind.SETTINGS_PANEL))); + assertEquals(OptionalInt.of(palette.sensorHub()), palette.color(instrument(InstrumentView.Kind.SENSOR_HUB))); + assertEquals(OptionalInt.of(palette.climateUnit()), palette.color(new ClimateUnitView("dry", ClimateUnitView.Kind.DEHUMIDIFIER, AT, 50, 40, true, ClimateUnitView.State.IDLE, 0))); for (InstrumentView.Kind kind : InstrumentView.Kind.values()) - if (kind.sensor()) assertEquals(OptionalInt.empty(), palette.outline(instrument(kind)), kind + " is a button"); - assertEquals(OptionalInt.empty(), palette.outline(new VentView("house", AT, VentView.Medium.AIR))); + if (kind.sensor()) assertEquals(OptionalInt.empty(), palette.color(instrument(kind)), kind + " is a button"); + assertEquals(OptionalInt.empty(), palette.color(new VentView("house", AT, VentView.Medium.AIR))); } @Test void equipmentIsColouredByWhatItDoes() { - assertEquals(OptionalInt.of(palette.stopped()), palette.outline(equipment(false, ThermostatView.Mode.IDLE))); - assertEquals(OptionalInt.of(palette.heating()), palette.outline(equipment(true, ThermostatView.Mode.HEATING))); - assertEquals(OptionalInt.of(palette.cooling()), palette.outline(equipment(true, ThermostatView.Mode.COOLING))); - assertEquals(OptionalInt.of(palette.stopped()), palette.outline(equipment(true, ThermostatView.Mode.IDLE))); + assertEquals(OptionalInt.of(palette.stopped()), palette.color(equipment(false, ThermostatView.Mode.IDLE))); + assertEquals(OptionalInt.of(palette.heating()), palette.color(equipment(true, ThermostatView.Mode.HEATING))); + assertEquals(OptionalInt.of(palette.cooling()), palette.color(equipment(true, ThermostatView.Mode.COOLING))); + assertEquals(OptionalInt.of(palette.stopped()), palette.color(equipment(true, ThermostatView.Mode.IDLE))); } @Test @@ -111,4 +111,22 @@ void badValuesWarnAndFallBack() { assertEquals(30, quick.durationSeconds()); assertEquals("none", quick.effect()); } + + @Test + void aSignsFrameRingsItsBoard() { + // A wall sign facing north lies against the block to its south. + List frame = SignFrame.of(SignFrame.Mount.WALL, 0, -1); + assertEquals(2 * SignFrame.PER_SIDE + 2 * (SignFrame.PER_SIDE - 2), frame.size(), "corners counted once"); + double z = 0.5 - (-0.375 + SignFrame.AHEAD); + for (SignFrame.Point point : frame) assertEquals(z, point.z(), 1e-9, "flat, just in front of the board"); + double minX = frame.stream().mapToDouble(SignFrame.Point::x).min().orElseThrow(); + double maxX = frame.stream().mapToDouble(SignFrame.Point::x).max().orElseThrow(); + assertEquals(1.1, maxX - minX, 1e-9, "a little wider than the board"); + double minY = frame.stream().mapToDouble(SignFrame.Point::y).min().orElseThrow(); + double maxY = frame.stream().mapToDouble(SignFrame.Point::y).max().orElseThrow(); + assertEquals(0.53, (minY + maxY) / 2, 1e-9, "centred on the board"); + // Facing east, the frame lies along z instead. + List east = SignFrame.of(SignFrame.Mount.WALL, 1, 0); + for (SignFrame.Point point : east) assertEquals(0.5 + (-0.375 + SignFrame.AHEAD), point.x(), 1e-9); + } } From a7ec36942264e3348c2d6d365fa412f30264538d Mon Sep 17 00:00:00 2001 From: bladestech Date: Sun, 25 Oct 2026 12:32:01 +0200 Subject: [PATCH 3/4] Tidy the README's wrapping Co-Authored-By: Claude Opus 5.5 --- README.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 628a501..4cee0ba 100644 --- a/README.md +++ b/README.md @@ -31,10 +31,9 @@ and so does dying. | Dehumidifier and humidifier signs | blue | | Equipment | grey when stopped, cyan cooling, orange heating | -Clouds are cyan for cooling and orange for heating. (Signs get a frame -rather than a glow: Minecraft draws sign boards in a way a glowing copy -can't trace.) Every colour can be -changed in config.yml. +Clouds are cyan for cooling and orange for heating. Every colour can be +changed in config.yml. Signs get a frame rather than a glow: Minecraft draws +sign boards in a way a glowing copy can't trace. ## Commands and permissions @@ -63,7 +62,8 @@ EZdebug+ is built only on EZvac's public API: `devices(world)` lists every device with its position, the equipment and thermostat views say what's running, and the device events keep the outlines in step. Equipment outlines are block displays that only debug players are shown; they're never saved -with the world. Frames and clouds are particles sent to debug players only. See [EZvac's API guide](https://github.com/EZvac-Plugin/EZvac/blob/main/docs/api.md). +with the world. Frames and clouds are particles sent to debug players only. +See [EZvac's API guide](https://github.com/EZvac-Plugin/EZvac/blob/main/docs/api.md). ## Building From 0bb73d334027d00ec92f63ffb7351541d3427ec5 Mon Sep 17 00:00:00 2001 From: bladestech Date: Sun, 25 Oct 2026 12:44:37 +0200 Subject: [PATCH 4/4] Build against EZvac ALPHA 2.2 Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 2 +- README.md | 4 ++-- pom.xml | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9e40e41..45fd0d9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,7 @@ All notable changes to EZdebug+ are recorded here. ## 0.1.0 -The first release: the Debug Potion. Needs EZvac with API 1.2 or newer. +The first release: the Debug Potion. Needs EZvac ALPHA 2.2 or newer (API 1.2). ### Added diff --git a/README.md b/README.md index 4cee0ba..fea7709 100644 --- a/README.md +++ b/README.md @@ -16,8 +16,8 @@ Only you see any of it: other players see nothing. Night Vision shows the countdown and helps in dark plant rooms. **Milk** ends it, like any potion, and so does dying. -> **Requires** EZvac with API 1.2 or newer, on Paper or Purpur 1.21.1 with -> Java 21. +> **Requires** EZvac ALPHA 2.2 or newer (EZvac API 1.2), on Paper or Purpur +> 1.21.1 with Java 21. ## Colours diff --git a/pom.xml b/pom.xml index 43ecc75..08b8fb0 100644 --- a/pom.xml +++ b/pom.xml @@ -22,8 +22,8 @@ 21 UTF-8 - - api-1.2-local + + ALPHA-2.2