Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6587a924e9 | ||
|
|
a359ce7835 | ||
|
|
e2e348d5c5 | ||
|
|
7f9cf2a4a5 | ||
|
|
e511e7c10b | ||
|
|
05a06a4dc8 | ||
|
|
1dcd3a178e | ||
|
|
385741027a | ||
|
|
972aeaaed6 | ||
|
|
5066e71897 | ||
|
|
02901c9cbc | ||
|
|
d6fd32994f | ||
|
|
143da0a940 | ||
|
|
dc5157f973 | ||
|
|
956b91c462 | ||
|
|
c980366278 | ||
|
|
616e3d2af5 | ||
|
|
7d335f5952 | ||
|
|
211aa0733b | ||
|
|
8b418ce01c | ||
|
|
62693c2229 | ||
|
|
b8d23ee0c0 | ||
|
|
f276d412b9 | ||
|
|
954dd7097b | ||
|
|
1937a8c71d | ||
|
|
24b60706b0 |
No files matched your search
@@ -0,0 +1,113 @@
|
|||||||
|
Rivencraft Build Instructions
|
||||||
|
============================
|
||||||
|
|
||||||
|
These instructions apply when source code, models, textures, data, or other
|
||||||
|
resources have been changed.
|
||||||
|
|
||||||
|
Requirements
|
||||||
|
------------
|
||||||
|
|
||||||
|
- Java 21 JDK
|
||||||
|
- A working Gradle wrapper
|
||||||
|
- The project dependencies available in the Gradle cache, or network access
|
||||||
|
for Gradle to download them
|
||||||
|
|
||||||
|
The project targets Minecraft 1.21.1 and NeoForge 21.1.251.
|
||||||
|
|
||||||
|
1. Open the project directory
|
||||||
|
--------------------------------
|
||||||
|
|
||||||
|
cd /path/to/rivencraft
|
||||||
|
|
||||||
|
2. Check the changed files
|
||||||
|
--------------------------
|
||||||
|
|
||||||
|
Confirm that model, texture, and other resource files are inside
|
||||||
|
`src/main/resources`. Java source files belong under `src/main/java`.
|
||||||
|
|
||||||
|
For example, block models are normally stored under:
|
||||||
|
|
||||||
|
src/main/resources/assets/rivencraft/models/block/
|
||||||
|
|
||||||
|
Resource files placed under `src/main/resources` are automatically included in
|
||||||
|
the finished mod JAR by Gradle.
|
||||||
|
|
||||||
|
3. Update the version when appropriate
|
||||||
|
---------------------------------------
|
||||||
|
|
||||||
|
Rivencraft uses the version format `x.y.z.b`:
|
||||||
|
|
||||||
|
- `x`: major release
|
||||||
|
- `y`: milestone completion
|
||||||
|
- `z`: release slice
|
||||||
|
- `b`: bug fixes and additional work within that slice
|
||||||
|
|
||||||
|
Edit `mod_version` in `gradle.properties` before creating a new release. Do
|
||||||
|
not reuse a version that has already been published.
|
||||||
|
|
||||||
|
4. Build the mod
|
||||||
|
----------------
|
||||||
|
|
||||||
|
From the project directory, run:
|
||||||
|
|
||||||
|
./gradlew build --offline
|
||||||
|
|
||||||
|
If the required dependencies are not cached locally, remove `--offline`:
|
||||||
|
|
||||||
|
./gradlew build
|
||||||
|
|
||||||
|
On systems using mise-managed Java and Gradle, use:
|
||||||
|
|
||||||
|
mise exec -- ./gradlew build --offline
|
||||||
|
|
||||||
|
5. Run the automated tests
|
||||||
|
--------------------------
|
||||||
|
|
||||||
|
To build and run the GameTest suite:
|
||||||
|
|
||||||
|
./gradlew build runGameTestServer --offline
|
||||||
|
|
||||||
|
Or, with mise:
|
||||||
|
|
||||||
|
mise exec -- ./gradlew build runGameTestServer --offline
|
||||||
|
|
||||||
|
All required GameTests should pass before distributing a build.
|
||||||
|
|
||||||
|
6. Locate and inspect the JAR
|
||||||
|
-----------------------------
|
||||||
|
|
||||||
|
Build outputs are written to:
|
||||||
|
|
||||||
|
build/libs/
|
||||||
|
|
||||||
|
The filename uses the configured version, for example:
|
||||||
|
|
||||||
|
build/libs/rivencraft-0.3.6.9.jar
|
||||||
|
|
||||||
|
To verify that changed resource files are packaged:
|
||||||
|
|
||||||
|
unzip -l build/libs/rivencraft-VERSION.jar | rg 'models|textures|data'
|
||||||
|
|
||||||
|
Replace `VERSION` with the actual version number.
|
||||||
|
|
||||||
|
To create a checksum for distribution:
|
||||||
|
|
||||||
|
sha256sum build/libs/rivencraft-VERSION.jar
|
||||||
|
|
||||||
|
7. Stop the Gradle daemon when finished
|
||||||
|
----------------------------------------
|
||||||
|
|
||||||
|
This is optional, but useful after a long test run:
|
||||||
|
|
||||||
|
./gradlew --stop
|
||||||
|
|
||||||
|
Release checklist
|
||||||
|
-----------------
|
||||||
|
|
||||||
|
- Confirm the version was incremented when required.
|
||||||
|
- Confirm the build completed successfully.
|
||||||
|
- Confirm all required GameTests passed.
|
||||||
|
- Confirm changed resources are present in the JAR.
|
||||||
|
- Generate and record the SHA-256 checksum.
|
||||||
|
- Test the JAR in the target Minecraft 1.21.1 NeoForge instance.
|
||||||
|
- Publish the JAR only after client-side testing is complete.
|
||||||
@@ -6,6 +6,16 @@ It is not an official release of Mystcraft.
|
|||||||
Mystcraft Legacy source: https://github.com/Mystcraft/Mystcraft-Legacy
|
Mystcraft Legacy source: https://github.com/Mystcraft/Mystcraft-Legacy
|
||||||
Mystcraft Legacy copyright: XCompWiz and contributors
|
Mystcraft Legacy copyright: XCompWiz and contributors
|
||||||
Mystcraft Legacy license: GNU Lesser General Public License version 3
|
Mystcraft Legacy license: GNU Lesser General Public License version 3
|
||||||
|
The animated ink-vial item texture in this project is copied from Mystcraft
|
||||||
|
Legacy's assets/mystcraft/textures/items/ink_vial.png under that license.
|
||||||
|
The Notebook page atlas is copied from Legacy's assets/mystcraft/gui/bookui_pagel.png
|
||||||
|
under the same license.
|
||||||
|
The Writing Desk item texture is copied from Legacy's
|
||||||
|
assets/mystcraft/textures/items/writingdesk.png under the same license.
|
||||||
|
The Writing Desk block texture is copied from Legacy's
|
||||||
|
assets/mystcraft/textures/entity/desk.png under the same license.
|
||||||
|
The Writing Desk GUI atlas is copied from Legacy's assets/mystcraft/gui/writingdesk.png
|
||||||
|
under the same license; desk wood and inlay textures are cropped from desk.png.
|
||||||
|
|
||||||
The initial build layout is derived from the official NeoForge 1.21.1
|
The initial build layout is derived from the official NeoForge 1.21.1
|
||||||
ModDevGradle MDK: https://github.com/NeoForgeMDKs/MDK-1.21.1-ModDevGradle
|
ModDevGradle MDK: https://github.com/NeoForgeMDKs/MDK-1.21.1-ModDevGradle
|
||||||
@@ -4,10 +4,60 @@ Rivencraft is a clean, incremental port of the ideas and gameplay of
|
|||||||
[Mystcraft Legacy](https://github.com/Mystcraft/Mystcraft-Legacy) to Minecraft
|
[Mystcraft Legacy](https://github.com/Mystcraft/Mystcraft-Legacy) to Minecraft
|
||||||
1.21.1 on NeoForge.
|
1.21.1 on NeoForge.
|
||||||
|
|
||||||
The bootstrap and books/linking milestones are complete. The project currently
|
The bootstrap, books/linking, and Ages milestones are complete. Milestone 4 is
|
||||||
provides functional Linking Books and randomly seeded, persistent vanilla-like
|
building the writing system on a data-pack symbol catalog and persistent
|
||||||
Ages created from page-free Descriptive Books. Symbols, instability, and the
|
ordered-writing model. The project currently provides functional Linking Books
|
||||||
full writing mechanics have not been ported yet.
|
and randomly seeded, persistent vanilla-like Ages created from page-free
|
||||||
|
Descriptive Books. Instability and full symbol-to-world grammar interpretation
|
||||||
|
have not been ported yet.
|
||||||
|
|
||||||
|
Milestone 4 now includes stackable blank Pages plus server-created symbol,
|
||||||
|
unresolved-symbol, and baseline link-panel states. Page visuals follow the
|
||||||
|
legacy runtime-composition rules. Craft an Ink Vial from two black dye, a glass
|
||||||
|
bottle, and a water bucket; the bucket is returned. Hold vanilla paper in one
|
||||||
|
hand and use the Ink Vial in the other to prepare a baseline Link Panel Page.
|
||||||
|
Each vial holds 16 ink units, and the default link-panel cost is two units.
|
||||||
|
The spent vial returns a glass bottle. Server owners can adjust the symbol-copy
|
||||||
|
and link-panel costs in the `writing` section of `rivencraft-server.toml`.
|
||||||
|
The Writing Desk can copy a selected written page from its collection tabs.
|
||||||
|
The Writing Desk is now craftable from planks, a glass bottle, and a feather.
|
||||||
|
It occupies two adjacent blocks, with one shared inventory; loaded paper and
|
||||||
|
the selected page appear on its Legacy-inspired model.
|
||||||
|
Desks placed before 0.3.6.1 keep their old one-block footprint until broken
|
||||||
|
and placed again; leave an adjacent space when replacing one.
|
||||||
|
Its 88 collection tabs, paper input, ink vial input, empty glass-bottle return,
|
||||||
|
16-unit ink meter, and inventory persist
|
||||||
|
through world saves; breaking it drops stored contents. The desk screen is a
|
||||||
|
functional foundation using Legacy's original desk and scrollbar textures.
|
||||||
|
Four tabs are visible at once; the controls above and below them move by four
|
||||||
|
(1–4, 5–8, through 85–88). Each viewer can browse a different group. Existing
|
||||||
|
four-tab desks retain their collections and supplies when upgraded.
|
||||||
|
With a notebook selected, pick up a Page from your inventory and click an empty
|
||||||
|
position on the left surface to store one page there. Clear search/filter/sort
|
||||||
|
and turn off `ALL` to place pages at specific positions; occupied positions are
|
||||||
|
never overwritten. A notebook tab exposes all 27 notebook positions (scroll to
|
||||||
|
reach the rest); a loose-page tab exposes only its one occupied position.
|
||||||
|
Empty tabs have no page storage until a notebook or page is put in the tab slot.
|
||||||
|
Click a page on the desk surface to select it for copying. Drag a page from one
|
||||||
|
notebook position to an empty position to move it, or onto another page to swap
|
||||||
|
their positions. This also works between notebooks shown in the `ALL` view.
|
||||||
|
Drag a page out of the panel to turn it back into an item. Drop it over a player
|
||||||
|
inventory slot or desk tab to place it there; a tab with a notebook adds it to
|
||||||
|
the first open position. Dropping elsewhere leaves the page on the cursor for
|
||||||
|
normal inventory placement. The source notebook or tab loses the page only after
|
||||||
|
a valid drop.
|
||||||
|
Put vanilla paper in the
|
||||||
|
upper-left slot and Ink Vials in the upper-right; a copy appears in the
|
||||||
|
lower-left result slot when the selected page is valid. Taking it consumes one
|
||||||
|
paper and, by default, one ink. An available vial refills an empty ink meter
|
||||||
|
when inserted or when copying uses its last ink, and returns a vanilla glass
|
||||||
|
bottle to the lower-right slot. Removing a bottle also retries a blocked refill.
|
||||||
|
Refilling waits if that slot is full or contains another item. The `AZ` control sorts
|
||||||
|
visible pages by name; `ALL` shows pages held across every desk tab. Search and
|
||||||
|
category filtering narrow the view without granting new pages, and cross-tab
|
||||||
|
copy selection is checked by the server.
|
||||||
|
Selecting a stored page on the desk surface shows its Legacy-proportioned
|
||||||
|
portrait preview and name above the player inventory.
|
||||||
|
|
||||||
## Linking Book
|
## Linking Book
|
||||||
|
|
||||||
@@ -60,6 +110,10 @@ according to the configured Return Link policy.
|
|||||||
|
|
||||||
Server owners can set `descriptive_books.return_link_mode` in Rivencraft's
|
Server owners can set `descriptive_books.return_link_mode` in Rivencraft's
|
||||||
server config to `ON_CREATION` (default), `ALWAYS`, or `DISABLED`.
|
server config to `ON_CREATION` (default), `ALWAYS`, or `DISABLED`.
|
||||||
|
Age creation, persistence, lifecycle commands, configuration, backups, and
|
||||||
|
administrator recovery are documented in [docs/AGES.md](docs/AGES.md).
|
||||||
|
Data-pack runtime profiles are documented in
|
||||||
|
[docs/AGE_PROFILES.md](docs/AGE_PROFILES.md).
|
||||||
|
|
||||||
## Requirements
|
## Requirements
|
||||||
|
|
||||||
@@ -77,6 +131,9 @@ view. Without either integration, Rivencraft uses its built-in animated linking
|
|||||||
panel. Clients can set `book_preview.mode` in
|
panel. Clients can set `book_preview.mode` in
|
||||||
`rivencraft-client.toml` to `AUTO`, `IMMERSIVE_PORTALS`, `PONDER`, or `LEGACY`.
|
`rivencraft-client.toml` to `AUTO`, `IMMERSIVE_PORTALS`, `PONDER`, or `LEGACY`.
|
||||||
Unavailable optional renderers safely fall back to `LEGACY`.
|
Unavailable optional renderers safely fall back to `LEGACY`.
|
||||||
|
The complete backend matrix, supported combinations, cleanup behavior, and
|
||||||
|
known upstream limits are documented in
|
||||||
|
[docs/PREVIEW_COMPATIBILITY.md](docs/PREVIEW_COMPATIBILITY.md).
|
||||||
|
|
||||||
## Build and run
|
## Build and run
|
||||||
|
|
||||||
|
|||||||
|
After Width: | Height: | Size: 80 KiB |
@@ -1,9 +1,35 @@
|
|||||||
# Age administration
|
# Age creation and administration
|
||||||
|
|
||||||
|
## Creation
|
||||||
|
|
||||||
|
A page-free Descriptive Book creates an Age when the player assigns a name and
|
||||||
|
presses **Create**. Rivencraft immediately assigns a UUID, derives a unique
|
||||||
|
Minecraft-safe dimension identifier from the requested name, rolls a seed and
|
||||||
|
traits, and persists that definition before asking Dynamic Dimensions to create
|
||||||
|
the runtime world. Names that normalize to the same identifier receive stable
|
||||||
|
suffixes such as `_2` and `_3`.
|
||||||
|
|
||||||
|
The selected terrain profile, biome distribution, lighting, weather, celestial
|
||||||
|
period, celestial angle, and phase are deterministic and become part of the
|
||||||
|
saved definition. A five-by-five cobblestone platform with clear headroom is
|
||||||
|
prepared at a safe arrival point. The completed book and every copy carrying
|
||||||
|
the same UUID resolve to that definition.
|
||||||
|
|
||||||
|
Creating an Age can take several ticks. The book cannot be reopened while its
|
||||||
|
creation request is active. If creation is interrupted after the definition is
|
||||||
|
saved, using the book again resumes from the same immutable definition instead
|
||||||
|
of rolling a replacement.
|
||||||
|
|
||||||
|
## Persistence
|
||||||
|
|
||||||
Rivencraft owns each Age definition for the lifetime of a world. A definition
|
Rivencraft owns each Age definition for the lifetime of a world. A definition
|
||||||
contains the Age UUID, canonical name, seed, generation version, runtime
|
contains the Age UUID, canonical name, seed, generation version, runtime
|
||||||
dimension identifier, spawn, and deterministic traits. Definitions are stored
|
dimension identifier, spawn, and deterministic traits. Definitions are stored
|
||||||
in the Overworld saved data and are never rerolled during ordinary loading.
|
in the Overworld saved data and are never rerolled during ordinary loading.
|
||||||
|
Runtime terrain and entity data remain in the normal world dimension storage
|
||||||
|
managed by Minecraft and Dynamic Dimensions. Back up the complete world folder
|
||||||
|
while the server is stopped; copying only a dimension folder does not preserve
|
||||||
|
the authoritative Age registry.
|
||||||
|
|
||||||
## Lifecycle
|
## Lifecycle
|
||||||
|
|
||||||
@@ -37,3 +63,47 @@ The commands require permission level 2.
|
|||||||
|
|
||||||
Opening a Descriptive Book for an unloaded Age loads it again from its saved
|
Opening a Descriptive Book for an unloaded Age loads it again from its saved
|
||||||
definition.
|
definition.
|
||||||
|
|
||||||
|
## Configuration
|
||||||
|
|
||||||
|
Rivencraft writes gameplay settings to the world/server configuration managed
|
||||||
|
by NeoForge. `descriptive_books.return_link_mode` accepts:
|
||||||
|
|
||||||
|
- `ON_CREATION` (default): create one Return Link the first time a player
|
||||||
|
enters each Age.
|
||||||
|
- `ALWAYS`: create a Return Link after every successful Descriptive Book trip.
|
||||||
|
- `DISABLED`: never create Return Links automatically.
|
||||||
|
|
||||||
|
Each client has a separate `rivencraft-client.toml`. Its `book_preview.mode`
|
||||||
|
setting accepts `AUTO`, `IMMERSIVE_PORTALS`, `PONDER`, or `LEGACY`. This changes
|
||||||
|
only presentation and cannot change server-side Age generation or travel
|
||||||
|
validation. See [PREVIEW_COMPATIBILITY.md](PREVIEW_COMPATIBILITY.md) for the
|
||||||
|
selection matrix and integration limits.
|
||||||
|
|
||||||
|
Runtime generation profiles are server data-pack resources. Their schema,
|
||||||
|
override rules, reload behavior, and deterministic fallback are documented in
|
||||||
|
[AGE_PROFILES.md](AGE_PROFILES.md).
|
||||||
|
|
||||||
|
## Administrator recovery
|
||||||
|
|
||||||
|
Use this sequence when a book cannot load an existing Age:
|
||||||
|
|
||||||
|
1. Stop the server and make a copy of the complete world folder.
|
||||||
|
2. Start the server and run `/rivencraft age list`. Confirm that the expected
|
||||||
|
canonical name and dimension identifier remain registered.
|
||||||
|
3. If the Age is listed as unloaded, open its Descriptive Book to reload it.
|
||||||
|
This keeps the UUID, seed, profile, traits, and existing world folder.
|
||||||
|
4. If a data-pack profile is missing or invalid, restore or repair that pack,
|
||||||
|
run `/reload`, then unload and reopen the Age. A removed custom profile uses
|
||||||
|
the deterministic `rivencraft:standard` fallback and logs the substitution.
|
||||||
|
5. If the definition is missing, restore the complete world backup. Moving a
|
||||||
|
dimension folder into another world cannot reconstruct its UUID or books.
|
||||||
|
6. If the definition exists but its dimension data is damaged, restore the
|
||||||
|
matching dimension data and authoritative world saved data from the same
|
||||||
|
backup generation. Do not combine them from different backups.
|
||||||
|
|
||||||
|
There is intentionally no delete command in Milestone 3. Do not manually
|
||||||
|
delete an Age definition or rename its dimension folder: books may exist in
|
||||||
|
inventories, containers, Book Stands, or unloaded chunks, and would be
|
||||||
|
orphaned. `/rivencraft age unload` is the supported reversible maintenance
|
||||||
|
operation.
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
# Asset provenance
|
||||||
|
|
||||||
|
Rivencraft reuses selected assets from
|
||||||
|
[Mystcraft Legacy](https://github.com/Mystcraft/Mystcraft-Legacy) under that
|
||||||
|
project's GNU LGPL v3 license. Rivencraft itself uses the same license.
|
||||||
|
|
||||||
|
| Rivencraft asset | Upstream asset | Upstream revision | Changes |
|
||||||
|
| --- | --- | --- | --- |
|
||||||
|
| `assets/rivencraft/textures/item/page.png` | `assets/mystcraft/textures/items/page_background.png` | `9bc8ddc061845df0cd5ea47f4fdef773cff786ae` | Namespace/path rename only |
|
||||||
|
| `assets/rivencraft/textures/gui/notebook_pages.png` | `assets/mystcraft/gui/bookui_pagel.png` | `9bc8ddc061845df0cd5ea47f4fdef773cff786ae` | Namespace/path rename only; Notebook draws the native 30×40 page at atlas coordinates `(156, 0)` |
|
||||||
|
| `assets/rivencraft/textures/item/writing_desk.png` | `assets/mystcraft/textures/items/writingdesk.png` | `9bc8ddc061845df0cd5ea47f4fdef773cff786ae` | Namespace/path rename only |
|
||||||
|
| `assets/rivencraft/textures/block/writing_desk.png` | `assets/mystcraft/textures/entity/desk.png` | `9bc8ddc061845df0cd5ea47f4fdef773cff786ae` | Namespace/path rename only |
|
||||||
|
| `assets/rivencraft/textures/block/writing_desk_wood.png` and `writing_desk_inlay.png` | `assets/mystcraft/textures/entity/desk.png` | `9bc8ddc061845df0cd5ea47f4fdef773cff786ae` | Cropped opaque wood and red inlay regions for the two-block model |
|
||||||
|
| `assets/rivencraft/textures/gui/writing_desk_legacy.png` | `assets/mystcraft/gui/writingdesk.png` | `9bc8ddc061845df0cd5ea47f4fdef773cff786ae` | Namespace/path rename only; full desk panel, tabs, and cycling controls at original atlas coordinates |
|
||||||
|
| `assets/rivencraft/textures/gui/scrollbar.png` | `assets/mystcraft/gui/scrollbar.png` | `9bc8ddc061845df0cd5ea47f4fdef773cff786ae` | Namespace/path rename only; tiled track and normal/pressed thumb |
|
||||||
|
| `assets/rivencraft/textures/item/linking_book_unwritten.png` | `assets/mystcraft/textures/items/unlinked.png` | `9bc8ddc061845df0cd5ea47f4fdef773cff786ae` | Namespace/path rename only |
|
||||||
|
| `assets/rivencraft/textures/item/page_link_panel.png` | `page_background.png` and `PageBuilder.BasicPageSprite` | `9bc8ddc061845df0cd5ea47f4fdef773cff786ae` | Reproduces the legacy 160 px scale, black panel at `(25,30)`–`(135,75)`, and 128 px resample |
|
||||||
|
| `assets/rivencraft/textures/item/page_symbol*.png` and `page_unresolved.png` | `page_background.png`, `textures/symbolcomponents.png`, `WordData`, `ModSymbols`, and `PageBuilder.PageSprite` | `9bc8ddc061845df0cd5ea47f4fdef773cff786ae` | Static 1.21.1 renditions of the legacy runtime-composed four-word symbol pages; `normal_time` uses the legacy Full Length poem |
|
||||||
|
|
||||||
|
Mystcraft Legacy identifies XCompWiz as its project developer and includes the
|
||||||
|
full LGPL v3 text in its root `LICENSE` file. Rivencraft's root `LICENSE`
|
||||||
|
provides the same license terms.
|
||||||
@@ -31,9 +31,10 @@ acceptance issue and all required implementation issues are complete.
|
|||||||
**Complete.**
|
**Complete.**
|
||||||
3. **Ages** — persistent generated dimensions, deterministic traits,
|
3. **Ages** — persistent generated dimensions, deterministic traits,
|
||||||
lifecycle management, data-pack integration, and optional destination
|
lifecycle management, data-pack integration, and optional destination
|
||||||
renderer compatibility. **Active.** See
|
renderer compatibility. **Complete.** See
|
||||||
[Milestone 3](https://gitea.tail180fb1.ts.net/dnorberg/rivencraft/milestone/8).
|
[Milestone 3](https://gitea.tail180fb1.ts.net/dnorberg/rivencraft/milestone/8).
|
||||||
4. **Writing system** — pages, symbols, notebooks, desks, and book assembly.
|
4. **Writing system** — pages, symbols, notebooks, desks, and book assembly.
|
||||||
|
**In progress.**
|
||||||
5. **Age grammar** — translate symbol combinations into modern biome, noise,
|
5. **Age grammar** — translate symbol combinations into modern biome, noise,
|
||||||
dimension-type, and world-generation configuration. Optional integrations
|
dimension-type, and world-generation configuration. Optional integrations
|
||||||
may add composable biome regions and seasonal behavior.
|
may add composable biome regions and seasonal behavior.
|
||||||
@@ -53,15 +54,23 @@ documented in [AGE_PROFILES.md](AGE_PROFILES.md).
|
|||||||
The core mod must remain usable without Create, Ponder, or Immersive Portals.
|
The core mod must remain usable without Create, Ponder, or Immersive Portals.
|
||||||
The built-in legacy animation is the dependency-free destination preview.
|
The built-in legacy animation is the dependency-free destination preview.
|
||||||
Optional preview modes may use Create/Ponder snapshots or Immersive Portals
|
Optional preview modes may use Create/Ponder snapshots or Immersive Portals
|
||||||
live rendering when their dependencies are installed.
|
live rendering when their dependencies are installed. The tested selection
|
||||||
|
matrix and integration boundaries are documented in
|
||||||
|
[PREVIEW_COMPATIBILITY.md](PREVIEW_COMPATIBILITY.md).
|
||||||
|
|
||||||
The writing system and Age grammar will build on the existing page-free Age
|
The writing system and Age grammar will build on the existing page-free Age
|
||||||
path. Page-free books remain a useful deterministic fallback and test fixture
|
path. Page-free books remain a useful deterministic fallback and test fixture
|
||||||
after written symbol combinations become available.
|
after written symbol combinations become available.
|
||||||
|
|
||||||
|
Milestone 4 begins with a versioned, data-pack-defined symbol catalog and an
|
||||||
|
immutable ordered-writing model. See [WRITING_DATA.md](WRITING_DATA.md). These
|
||||||
|
contracts preserve unknown symbol identifiers and store author intent; they do
|
||||||
|
not interpret symbols into Age generation, which remains Milestone 5 work.
|
||||||
|
|
||||||
## Provenance rules
|
## Provenance rules
|
||||||
|
|
||||||
- New code uses the `net.dnorberg.rivencraft` package.
|
- New code uses the `net.dnorberg.rivencraft` package.
|
||||||
|
- Reused legacy art is recorded in [ASSET_PROVENANCE.md](ASSET_PROVENANCE.md).
|
||||||
- Adapted Mystcraft code retains its upstream copyright notice and is tracked
|
- Adapted Mystcraft code retains its upstream copyright notice and is tracked
|
||||||
in a nearby source comment or commit.
|
in a nearby source comment or commit.
|
||||||
- Generated, binary, and third-party dependency content is not copied from the
|
- Generated, binary, and third-party dependency content is not copied from the
|
||||||
|
|||||||
@@ -0,0 +1,78 @@
|
|||||||
|
# Destination preview compatibility
|
||||||
|
|
||||||
|
Rivencraft has three destination preview backends. The selected backend is a
|
||||||
|
client presentation detail; the server validates travel and Age generation is
|
||||||
|
independent of every preview integration.
|
||||||
|
|
||||||
|
## Selection matrix
|
||||||
|
|
||||||
|
Set `book_preview.mode` in `rivencraft-client.toml`.
|
||||||
|
|
||||||
|
| Configured mode | Immersive Portals installed | Create/Ponder installed | Selected backend |
|
||||||
|
| --- | --- | --- | --- |
|
||||||
|
| `AUTO` | yes | either | Immersive Portals |
|
||||||
|
| `AUTO` | no | yes | Ponder snapshot |
|
||||||
|
| `AUTO` | no | no | built-in legacy animation |
|
||||||
|
| `IMMERSIVE_PORTALS` | yes | either | Immersive Portals |
|
||||||
|
| `IMMERSIVE_PORTALS` | no | either | built-in legacy animation |
|
||||||
|
| `PONDER` | either | yes | Ponder snapshot |
|
||||||
|
| `PONDER` | either | no | built-in legacy animation |
|
||||||
|
| `LEGACY` | either | either | built-in legacy animation |
|
||||||
|
|
||||||
|
Explicit optional modes fall back directly to `LEGACY`. They do not silently
|
||||||
|
select the other optional integration. GameTests exercise every row and every
|
||||||
|
dependency-presence permutation.
|
||||||
|
|
||||||
|
## Book behavior
|
||||||
|
|
||||||
|
Held Linking and Descriptive Books render the selected backend in the preview
|
||||||
|
panel. Immersive Portals additionally exposes **Explore**: the player remains
|
||||||
|
at the opening position, mouse look controls the remote camera, and
|
||||||
|
right-click returns to the standard book view.
|
||||||
|
|
||||||
|
Books on a Book Stand use the same preview panel, but Explore is disabled so
|
||||||
|
the player cannot move away and leave a remote preview session owned by the
|
||||||
|
stand screen. Closing either screen releases its server chunk loader. Linking,
|
||||||
|
disconnecting, unloading the destination Age, and stopping the server also
|
||||||
|
release affected loaders.
|
||||||
|
|
||||||
|
The Immersive Portals backend force-loads the initial 3 by 3 destination area
|
||||||
|
before registering its wider preview chunk loader. The Ponder backend clears
|
||||||
|
the previous snapshot before applying replacement block data. The live backend
|
||||||
|
clears its framebuffer on each render and restores the Minecraft viewport
|
||||||
|
afterward. These rules prevent stale snapshot frames and book UI elements from
|
||||||
|
being captured in the preview.
|
||||||
|
|
||||||
|
## Supported combinations and upstream limits
|
||||||
|
|
||||||
|
The compatibility baseline is Minecraft 1.21.1, NeoForge 21.1.251, Create
|
||||||
|
6.0.10, and Immersive Portals 6.0.7. Core Age generation and the `LEGACY`
|
||||||
|
backend run without Create or Immersive Portals; the headless GameTest server
|
||||||
|
uses that dependency-free path.
|
||||||
|
|
||||||
|
Immersive Portals 6.0.7 is incompatible with Sodium 0.8.13 for Minecraft
|
||||||
|
1.21.1: its Sodium compatibility mixin references the removed
|
||||||
|
`OcclusionCuller.Visitor` class and crashes while entering a world. Sodium
|
||||||
|
0.6.13 avoids that specific mixin failure. This compatibility boundary belongs
|
||||||
|
to Immersive Portals and Sodium, before Rivencraft's preview code runs.
|
||||||
|
|
||||||
|
Immersive Portals reports that some Create contraptions can be invisible when
|
||||||
|
the two mods are installed together. Rivencraft does not replace either mod's
|
||||||
|
world or contraption renderer, so this remains an upstream rendering limit.
|
||||||
|
The `PONDER` or `LEGACY` mode is the supported fallback when live rendering is
|
||||||
|
unstable in a particular graphics or mod configuration.
|
||||||
|
|
||||||
|
## Release verification
|
||||||
|
|
||||||
|
For preview-related releases:
|
||||||
|
|
||||||
|
1. Run `./gradlew runGameTestServer` to verify the complete selection matrix,
|
||||||
|
core Age creation, persistence, and travel without optional renderers.
|
||||||
|
2. Open held Linking and Descriptive Books once with each available backend.
|
||||||
|
3. Open both book types from a Book Stand and confirm Explore is disabled.
|
||||||
|
4. With Immersive Portals, enter and leave Explore, travel between dimensions,
|
||||||
|
close the screen, and disconnect; confirm destination chunks render and no
|
||||||
|
preview loader remains active.
|
||||||
|
5. With Ponder, reopen different destinations and confirm the previous
|
||||||
|
snapshot does not bleed into the next one.
|
||||||
|
|
||||||
@@ -0,0 +1,93 @@
|
|||||||
|
# Writing and symbol data
|
||||||
|
|
||||||
|
Milestone 4 stores what a player wrote without deciding what that writing does
|
||||||
|
to an Age. Milestone 5 owns grammar validation, symbol interaction, instability,
|
||||||
|
and translation into biome, noise, dimension-type, and other world-generation
|
||||||
|
configuration.
|
||||||
|
|
||||||
|
## Symbol catalog
|
||||||
|
|
||||||
|
The authoritative server catalog loads JSON resources from
|
||||||
|
`data/<namespace>/rivencraft/symbols/<path>.json`. The resource ID is the
|
||||||
|
symbol ID. For example, `data/rivencraft/rivencraft/symbols/terrain/standard.json`
|
||||||
|
defines `rivencraft:terrain/standard`.
|
||||||
|
|
||||||
|
Schema version 1 contains display metadata only:
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"schema_version": 1,
|
||||||
|
"name": "symbol.rivencraft.terrain.standard",
|
||||||
|
"description": "symbol.rivencraft.terrain.standard.description",
|
||||||
|
"category": "rivencraft:terrain"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
`name` and `description` are translation keys, not arbitrary formatted text or
|
||||||
|
executable behavior. `category` is a namespaced organizational identifier.
|
||||||
|
Invalid definitions are logged and excluded by the server. Menus and future
|
||||||
|
page synchronization must obtain resolved display metadata from the server;
|
||||||
|
clients never make a symbol valid by naming it.
|
||||||
|
|
||||||
|
Rivencraft ships a small catalog covering terrain, biomes, lighting, weather,
|
||||||
|
celestial behavior, and features. It exists to exercise the complete writing
|
||||||
|
workflow before Milestone 5 implements the full legacy grammar.
|
||||||
|
|
||||||
|
## Persistent writing
|
||||||
|
|
||||||
|
`SymbolReference` stores only a namespaced symbol ID. `WritingEntry` is either
|
||||||
|
a symbol reference or a baseline link-panel marker. `OrderedWriting` retains up
|
||||||
|
to 256 entries in exact player-authored order. All three contracts have both
|
||||||
|
persistent codecs and bounded network codecs.
|
||||||
|
|
||||||
|
Removing a data pack never removes its IDs from saved writing. A missing ID is
|
||||||
|
resolved as client-safe **Unresolved Symbol** display metadata while retaining
|
||||||
|
the original namespaced ID for diagnostics and later restoration. This is
|
||||||
|
deliberately different from treating an unknown symbol as valid grammar.
|
||||||
|
|
||||||
|
## Pages
|
||||||
|
|
||||||
|
The single stackable `rivencraft:page` item has a bounded, persistent
|
||||||
|
`rivencraft:page_content` component. Its explicit states are blank, symbol,
|
||||||
|
unresolved symbol, and baseline link panel. Symbol and unresolved-symbol pages
|
||||||
|
retain their namespaced symbol reference; unresolved pages can be inspected and
|
||||||
|
removed but are rejected as usable writing until their data pack returns.
|
||||||
|
|
||||||
|
Only server-side writing operations may create a known symbol
|
||||||
|
page or link panel from vanilla paper. The shared `PageItem` creation and validation gates reject
|
||||||
|
new pages for identifiers absent from the server catalog. Later Writing Desk
|
||||||
|
and Book Binder packets must call these gates rather than accepting page
|
||||||
|
contents supplied by a client.
|
||||||
|
|
||||||
|
The item model uses server-assigned custom-model data derived from the symbol
|
||||||
|
identifier. Built-in pages reproduce Mystcraft Legacy's four-word poem
|
||||||
|
composition from its page background and symbol-component sheet. Data-pack
|
||||||
|
symbols without a bundled resource-pack model use the legacy question-mark
|
||||||
|
fallback while keeping their real identifier and display metadata.
|
||||||
|
|
||||||
|
The Notebook surface displays pages by their persistent slot index instead of
|
||||||
|
packing occupied pages together. Empty positions through the last placed page
|
||||||
|
appear darkened. While carrying a Page, all available positions are shown for
|
||||||
|
placement. The surface draws the native 30×40 portrait page region from
|
||||||
|
Legacy's book UI atlas; symbols are layered at a uniform scale, while the
|
||||||
|
square item models remain unchanged in inventories.
|
||||||
|
|
||||||
|
## Ink and baseline link panels
|
||||||
|
|
||||||
|
An Ink Vial is crafted from two black dye, a glass bottle, and a water bucket.
|
||||||
|
The bucket remains after crafting. Each vial holds 16 ink units, stored in a
|
||||||
|
persistent, network-synchronized component; only vials with identical remaining
|
||||||
|
ink stack together. When depleted, a vial returns a glass bottle that can be
|
||||||
|
used to craft another. The animated item texture comes from Mystcraft Legacy.
|
||||||
|
|
||||||
|
The server config sets ink costs independently for symbol copying (default one
|
||||||
|
unit) and baseline link-panel preparation (default two units). To prepare a
|
||||||
|
panel, hold vanilla paper in one hand and use an Ink Vial in the other. The
|
||||||
|
server checks the held items and sufficient ink before consuming
|
||||||
|
anything. A stack of paper yields exactly one Link Panel Page per use;
|
||||||
|
if the inventory is full, the result is dropped instead of deleted. Symbol
|
||||||
|
copying is implemented by the Writing Desk: it previews a copy of the selected
|
||||||
|
resolved page, then spends paper and ink only when that copy is taken. The
|
||||||
|
desk's 16-unit ink meter refills from an Ink Vial when needed and returns a
|
||||||
|
vanilla glass bottle. Link-property modifiers are
|
||||||
|
deferred beyond this baseline flow.
|
||||||
@@ -35,7 +35,7 @@ mod_name=Rivencraft
|
|||||||
# The license of the mod. Review your options at https://choosealicense.com/. All Rights Reserved is the default.
|
# The license of the mod. Review your options at https://choosealicense.com/. All Rights Reserved is the default.
|
||||||
mod_license=LGPL-3.0-or-later
|
mod_license=LGPL-3.0-or-later
|
||||||
# The mod version. Rivencraft uses the x.y.z.b policy documented in README.md.
|
# The mod version. Rivencraft uses the x.y.z.b policy documented in README.md.
|
||||||
mod_version=0.2.28.0
|
mod_version=0.3.6.9
|
||||||
immersive_portals_version=6.0.7
|
immersive_portals_version=6.0.7
|
||||||
# The group ID for the mod. It is only important when publishing as an artifact to a Maven repository.
|
# The group ID for the mod. It is only important when publishing as an artifact to a Maven repository.
|
||||||
# This should match the base package used for the mod sources.
|
# This should match the base package used for the mod sources.
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import com.mojang.logging.LogUtils;
|
|||||||
import net.dnorberg.rivencraft.registry.ModCreativeTabs;
|
import net.dnorberg.rivencraft.registry.ModCreativeTabs;
|
||||||
import net.dnorberg.rivencraft.registry.ModDataComponents;
|
import net.dnorberg.rivencraft.registry.ModDataComponents;
|
||||||
import net.dnorberg.rivencraft.registry.ModItems;
|
import net.dnorberg.rivencraft.registry.ModItems;
|
||||||
|
import net.dnorberg.rivencraft.registry.ModMenus;
|
||||||
import net.dnorberg.rivencraft.registry.ModSounds;
|
import net.dnorberg.rivencraft.registry.ModSounds;
|
||||||
import net.dnorberg.rivencraft.registry.ModBlocks;
|
import net.dnorberg.rivencraft.registry.ModBlocks;
|
||||||
import net.dnorberg.rivencraft.registry.ModBlockEntities;
|
import net.dnorberg.rivencraft.registry.ModBlockEntities;
|
||||||
@@ -18,6 +19,7 @@ import net.dnorberg.rivencraft.config.RivencraftClientConfig;
|
|||||||
import net.dnorberg.rivencraft.book.AgeDimensionService;
|
import net.dnorberg.rivencraft.book.AgeDimensionService;
|
||||||
import net.dnorberg.rivencraft.book.AgeWeatherService;
|
import net.dnorberg.rivencraft.book.AgeWeatherService;
|
||||||
import net.dnorberg.rivencraft.book.AgeRuntimeProfiles;
|
import net.dnorberg.rivencraft.book.AgeRuntimeProfiles;
|
||||||
|
import net.dnorberg.rivencraft.writing.SymbolCatalog;
|
||||||
import net.neoforged.bus.api.IEventBus;
|
import net.neoforged.bus.api.IEventBus;
|
||||||
import net.neoforged.fml.ModContainer;
|
import net.neoforged.fml.ModContainer;
|
||||||
import net.neoforged.fml.common.Mod;
|
import net.neoforged.fml.common.Mod;
|
||||||
@@ -40,6 +42,7 @@ public final class Rivencraft {
|
|||||||
ModBlocks.register(modEventBus);
|
ModBlocks.register(modEventBus);
|
||||||
ModBlockEntities.register(modEventBus);
|
ModBlockEntities.register(modEventBus);
|
||||||
ModItems.register(modEventBus);
|
ModItems.register(modEventBus);
|
||||||
|
ModMenus.register(modEventBus);
|
||||||
ModSounds.register(modEventBus);
|
ModSounds.register(modEventBus);
|
||||||
ModCreativeTabs.register(modEventBus);
|
ModCreativeTabs.register(modEventBus);
|
||||||
NeoForge.EVENT_BUS.addListener(BookStandConversionHandler::onRightClickBlock);
|
NeoForge.EVENT_BUS.addListener(BookStandConversionHandler::onRightClickBlock);
|
||||||
@@ -50,6 +53,7 @@ public final class Rivencraft {
|
|||||||
NeoForge.EVENT_BUS.addListener(AgeLifecycleEvents::onServerStopping);
|
NeoForge.EVENT_BUS.addListener(AgeLifecycleEvents::onServerStopping);
|
||||||
NeoForge.EVENT_BUS.addListener(RivencraftCommands::register);
|
NeoForge.EVENT_BUS.addListener(RivencraftCommands::register);
|
||||||
NeoForge.EVENT_BUS.addListener(AgeRuntimeProfiles::register);
|
NeoForge.EVENT_BUS.addListener(AgeRuntimeProfiles::register);
|
||||||
|
NeoForge.EVENT_BUS.addListener(SymbolCatalog::register);
|
||||||
LOGGER.info("Initializing Rivencraft");
|
LOGGER.info("Initializing Rivencraft");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,92 @@
|
|||||||
|
package net.dnorberg.rivencraft.block;
|
||||||
|
|
||||||
|
import com.mojang.serialization.MapCodec;
|
||||||
|
import net.dnorberg.rivencraft.block.entity.WritingDeskBlockEntity;
|
||||||
|
import net.dnorberg.rivencraft.menu.WritingDeskMenu;
|
||||||
|
import net.dnorberg.rivencraft.writing.WritingDeskCatalog;
|
||||||
|
import net.minecraft.core.BlockPos;
|
||||||
|
import net.minecraft.core.Direction;
|
||||||
|
import net.minecraft.network.chat.Component;
|
||||||
|
import net.minecraft.server.level.ServerPlayer;
|
||||||
|
import net.minecraft.world.Containers;
|
||||||
|
import net.minecraft.world.InteractionResult;
|
||||||
|
import net.minecraft.world.SimpleMenuProvider;
|
||||||
|
import net.minecraft.world.entity.player.Player;
|
||||||
|
import net.minecraft.world.item.context.BlockPlaceContext;
|
||||||
|
import net.minecraft.world.level.Level;
|
||||||
|
import net.minecraft.world.level.block.BaseEntityBlock;
|
||||||
|
import net.minecraft.world.level.block.RenderShape;
|
||||||
|
import net.minecraft.world.level.block.state.BlockState;
|
||||||
|
import net.minecraft.world.level.block.state.StateDefinition;
|
||||||
|
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
|
||||||
|
import net.minecraft.world.level.block.state.properties.DirectionProperty;
|
||||||
|
import net.minecraft.world.level.block.state.properties.BooleanProperty;
|
||||||
|
import net.minecraft.world.item.ItemStack;
|
||||||
|
import net.minecraft.world.entity.LivingEntity;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||||
|
import net.minecraft.world.phys.BlockHitResult;
|
||||||
|
|
||||||
|
public final class WritingDeskBlock extends BaseEntityBlock {
|
||||||
|
public static final MapCodec<WritingDeskBlock> CODEC = simpleCodec(WritingDeskBlock::new);
|
||||||
|
public static final DirectionProperty FACING = BlockStateProperties.HORIZONTAL_FACING;
|
||||||
|
public static final BooleanProperty EXTENSION = BooleanProperty.create("extension");
|
||||||
|
|
||||||
|
public WritingDeskBlock(Properties properties) {
|
||||||
|
super(properties);
|
||||||
|
registerDefaultState(stateDefinition.any().setValue(FACING, Direction.NORTH).setValue(EXTENSION, false));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override public MapCodec<? extends BaseEntityBlock> codec() { return CODEC; }
|
||||||
|
@Override protected void createBlockStateDefinition(StateDefinition.Builder<net.minecraft.world.level.block.Block, BlockState> builder) {
|
||||||
|
builder.add(FACING, EXTENSION);
|
||||||
|
}
|
||||||
|
@Override public BlockState getStateForPlacement(BlockPlaceContext context) {
|
||||||
|
Direction facing = context.getHorizontalDirection().getOpposite();
|
||||||
|
BlockPos extension = context.getClickedPos().relative(facing.getClockWise());
|
||||||
|
return context.getLevel().getBlockState(extension).canBeReplaced(context)
|
||||||
|
? defaultBlockState().setValue(FACING, facing) : null;
|
||||||
|
}
|
||||||
|
@Override public void setPlacedBy(Level level, BlockPos pos, BlockState state,
|
||||||
|
@Nullable LivingEntity placer, ItemStack stack) {
|
||||||
|
super.setPlacedBy(level, pos, state, placer, stack);
|
||||||
|
level.setBlock(pos.relative(state.getValue(FACING).getClockWise()),
|
||||||
|
state.setValue(EXTENSION, true), 3);
|
||||||
|
}
|
||||||
|
@Override protected RenderShape getRenderShape(BlockState state) { return RenderShape.MODEL; }
|
||||||
|
@Override public BlockEntity newBlockEntity(BlockPos pos, BlockState state) {
|
||||||
|
return state.getValue(EXTENSION) ? null : new WritingDeskBlockEntity(pos, state);
|
||||||
|
}
|
||||||
|
@Override protected InteractionResult useWithoutItem(BlockState state, Level level, BlockPos pos,
|
||||||
|
Player player, BlockHitResult hit) {
|
||||||
|
BlockPos controller = state.getValue(EXTENSION)
|
||||||
|
? pos.relative(state.getValue(FACING).getCounterClockWise()) : pos;
|
||||||
|
if (!level.isClientSide && player instanceof ServerPlayer serverPlayer
|
||||||
|
&& level.getBlockEntity(controller) instanceof WritingDeskBlockEntity desk) {
|
||||||
|
serverPlayer.openMenu(new SimpleMenuProvider(
|
||||||
|
(id, inventory, ignored) -> new WritingDeskMenu(id, inventory, desk),
|
||||||
|
Component.translatable("container.rivencraft.writing_desk")),
|
||||||
|
buffer -> {
|
||||||
|
buffer.writeBlockPos(controller);
|
||||||
|
WritingDeskCatalog.write(buffer, WritingDeskCatalog.available(desk));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return InteractionResult.sidedSuccess(level.isClientSide);
|
||||||
|
}
|
||||||
|
@Override protected void onRemove(BlockState state, Level level, BlockPos pos, BlockState replacement, boolean moving) {
|
||||||
|
if (!state.is(replacement.getBlock())) {
|
||||||
|
if (!level.isClientSide && !state.getValue(EXTENSION)
|
||||||
|
&& level.getBlockEntity(pos) instanceof WritingDeskBlockEntity desk) {
|
||||||
|
Containers.dropContents(level, pos, desk);
|
||||||
|
level.updateNeighbourForOutputSignal(pos, this);
|
||||||
|
}
|
||||||
|
BlockPos other = pos.relative(state.getValue(FACING).getClockWise(),
|
||||||
|
state.getValue(EXTENSION) ? -1 : 1);
|
||||||
|
BlockState otherState = level.getBlockState(other);
|
||||||
|
if (otherState.is(this) && otherState.getValue(EXTENSION) != state.getValue(EXTENSION)) {
|
||||||
|
level.setBlock(other, net.minecraft.world.level.block.Blocks.AIR.defaultBlockState(), 35);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
super.onRemove(state, level, pos, replacement, moving);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,196 @@
|
|||||||
|
package net.dnorberg.rivencraft.block.entity;
|
||||||
|
|
||||||
|
import net.dnorberg.rivencraft.item.InkVialItem;
|
||||||
|
import net.dnorberg.rivencraft.writing.WritingInkService;
|
||||||
|
import net.dnorberg.rivencraft.registry.ModBlockEntities;
|
||||||
|
import net.dnorberg.rivencraft.registry.ModItems;
|
||||||
|
import net.minecraft.core.BlockPos;
|
||||||
|
import net.minecraft.core.HolderLookup;
|
||||||
|
import net.minecraft.core.NonNullList;
|
||||||
|
import net.minecraft.nbt.CompoundTag;
|
||||||
|
import net.minecraft.network.protocol.Packet;
|
||||||
|
import net.minecraft.network.protocol.game.ClientGamePacketListener;
|
||||||
|
import net.minecraft.network.protocol.game.ClientboundBlockEntityDataPacket;
|
||||||
|
import net.minecraft.world.Container;
|
||||||
|
import net.minecraft.world.ContainerHelper;
|
||||||
|
import net.minecraft.world.entity.player.Player;
|
||||||
|
import net.minecraft.world.item.ItemStack;
|
||||||
|
import net.minecraft.world.item.Items;
|
||||||
|
import net.minecraft.world.level.Level;
|
||||||
|
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||||
|
import net.minecraft.world.level.block.state.BlockState;
|
||||||
|
|
||||||
|
/** Collection tabs, paper, ink vials and empty-vial return are owned by the block. */
|
||||||
|
public final class WritingDeskBlockEntity extends BlockEntity implements Container {
|
||||||
|
public static final int COLLECTIONS = 88;
|
||||||
|
public static final int INK = COLLECTIONS;
|
||||||
|
public static final int RETURN = INK + 1;
|
||||||
|
public static final int PAPER = INK + 2;
|
||||||
|
/** Unused by new desks; retained so old saves cannot silently lose slot contents. */
|
||||||
|
public static final int LEGACY_OUTPUT = INK + 3;
|
||||||
|
public static final int SIZE = INK + 4;
|
||||||
|
private NonNullList<ItemStack> items = NonNullList.withSize(SIZE, ItemStack.EMPTY);
|
||||||
|
private int activeCollection;
|
||||||
|
private int inkRemaining;
|
||||||
|
private ItemStack displayPage = ItemStack.EMPTY;
|
||||||
|
|
||||||
|
public WritingDeskBlockEntity(BlockPos pos, BlockState state) {
|
||||||
|
super(ModBlockEntities.WRITING_DESK.get(), pos, state);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int activeCollection() { return activeCollection; }
|
||||||
|
public int inkRemaining() { return inkRemaining; }
|
||||||
|
public ItemStack displayPage() { return displayPage; }
|
||||||
|
public void setDisplayPage(ItemStack page) {
|
||||||
|
ItemStack next = page.isEmpty() ? ItemStack.EMPTY : page.copyWithCount(1);
|
||||||
|
if (!ItemStack.matches(displayPage, next)) {
|
||||||
|
displayPage = next;
|
||||||
|
setChanged();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public void setActiveCollection(int index) {
|
||||||
|
if (index >= 0 && index < COLLECTIONS && activeCollection != index) {
|
||||||
|
activeCollection = index;
|
||||||
|
setChanged();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override public int getContainerSize() { return SIZE; }
|
||||||
|
@Override public boolean isEmpty() { return items.stream().allMatch(ItemStack::isEmpty); }
|
||||||
|
@Override public ItemStack getItem(int slot) { return items.get(slot); }
|
||||||
|
@Override public ItemStack removeItem(int slot, int amount) {
|
||||||
|
ItemStack removed = ContainerHelper.removeItem(items, slot, amount);
|
||||||
|
if (!removed.isEmpty()) {
|
||||||
|
if (slot < COLLECTIONS) displayPage = ItemStack.EMPTY;
|
||||||
|
setChanged();
|
||||||
|
if (slot == RETURN) refillEmptyInkBar();
|
||||||
|
}
|
||||||
|
return removed;
|
||||||
|
}
|
||||||
|
@Override public ItemStack removeItemNoUpdate(int slot) { return ContainerHelper.takeItem(items, slot); }
|
||||||
|
@Override public void setItem(int slot, ItemStack stack) {
|
||||||
|
items.set(slot, stack);
|
||||||
|
if (stack.getCount() > getMaxStackSize()) stack.setCount(getMaxStackSize());
|
||||||
|
if (slot < COLLECTIONS) displayPage = ItemStack.EMPTY;
|
||||||
|
setChanged();
|
||||||
|
if (slot == INK || slot == RETURN) refillEmptyInkBar();
|
||||||
|
}
|
||||||
|
@Override public boolean stillValid(Player player) {
|
||||||
|
return level != null && level.isLoaded(worldPosition)
|
||||||
|
&& level.getBlockEntity(worldPosition) == this
|
||||||
|
&& player.distanceToSqr(worldPosition.getX() + 0.5, worldPosition.getY() + 0.5,
|
||||||
|
worldPosition.getZ() + 0.5) <= 64.0;
|
||||||
|
}
|
||||||
|
@Override public boolean canPlaceItem(int slot, ItemStack stack) {
|
||||||
|
if (slot < COLLECTIONS) return stack.is(ModItems.NOTEBOOK.get()) || stack.is(ModItems.PAGE.get());
|
||||||
|
return switch (slot) {
|
||||||
|
case INK -> stack.is(ModItems.INK_VIAL.get());
|
||||||
|
case RETURN -> false;
|
||||||
|
case PAPER -> stack.is(Items.PAPER);
|
||||||
|
case LEGACY_OUTPUT -> false;
|
||||||
|
default -> false;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean hasBottleSpace() {
|
||||||
|
ItemStack returned = items.get(RETURN);
|
||||||
|
return returned.isEmpty() || returned.is(Items.GLASS_BOTTLE)
|
||||||
|
&& returned.getCount() < returned.getMaxStackSize();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Consume one vial only when the empty meter can return its glass bottle. */
|
||||||
|
private void refillEmptyInkBar() {
|
||||||
|
if (level == null || level.isClientSide || inkRemaining != 0 || !hasBottleSpace()) return;
|
||||||
|
ItemStack vial = items.get(INK);
|
||||||
|
if (!vial.is(ModItems.INK_VIAL.get())) return;
|
||||||
|
int ink = Math.clamp(InkVialItem.remaining(vial), 0, InkVialItem.CAPACITY);
|
||||||
|
if (ink == 0) return;
|
||||||
|
inkRemaining = ink;
|
||||||
|
vial.shrink(1);
|
||||||
|
if (vial.isEmpty()) items.set(INK, ItemStack.EMPTY);
|
||||||
|
ItemStack returned = items.get(RETURN);
|
||||||
|
if (returned.isEmpty()) items.set(RETURN, new ItemStack(Items.GLASS_BOTTLE));
|
||||||
|
else returned.grow(1);
|
||||||
|
setChanged();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** The output is virtual; inputs are committed only after a result can be given to a player. */
|
||||||
|
public boolean canConsumeCopyMaterials() {
|
||||||
|
ItemStack paper = items.get(PAPER);
|
||||||
|
if (!canPlaceItem(PAPER, paper) || paper.isEmpty()) return false;
|
||||||
|
int cost = WritingInkService.symbolCopyCost();
|
||||||
|
if (inkRemaining >= cost) return true;
|
||||||
|
ItemStack vial = items.get(INK);
|
||||||
|
return vial.is(ModItems.INK_VIAL.get()) && inkRemaining + InkVialItem.remaining(vial) >= cost
|
||||||
|
&& hasBottleSpace();
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean consumeCopyMaterials() {
|
||||||
|
if (!canConsumeCopyMaterials()) return false;
|
||||||
|
int cost = WritingInkService.symbolCopyCost();
|
||||||
|
if (inkRemaining < cost) {
|
||||||
|
ItemStack vial = items.get(INK);
|
||||||
|
inkRemaining += Math.clamp(InkVialItem.remaining(vial), 0, InkVialItem.CAPACITY);
|
||||||
|
vial.shrink(1);
|
||||||
|
if (vial.isEmpty()) items.set(INK, ItemStack.EMPTY);
|
||||||
|
ItemStack returned = items.get(RETURN);
|
||||||
|
if (returned.isEmpty()) items.set(RETURN, new ItemStack(Items.GLASS_BOTTLE));
|
||||||
|
else returned.grow(1);
|
||||||
|
}
|
||||||
|
inkRemaining -= cost;
|
||||||
|
removeItem(PAPER, 1);
|
||||||
|
setChanged();
|
||||||
|
if (inkRemaining == 0) refillEmptyInkBar();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
@Override public void setLevel(Level level) {
|
||||||
|
super.setLevel(level);
|
||||||
|
refillEmptyInkBar();
|
||||||
|
}
|
||||||
|
@Override public void clearContent() {
|
||||||
|
items.clear();
|
||||||
|
items = NonNullList.withSize(SIZE, ItemStack.EMPTY);
|
||||||
|
inkRemaining = 0;
|
||||||
|
displayPage = ItemStack.EMPTY;
|
||||||
|
setChanged();
|
||||||
|
}
|
||||||
|
@Override protected void loadAdditional(CompoundTag tag, HolderLookup.Provider registries) {
|
||||||
|
super.loadAdditional(tag, registries);
|
||||||
|
items = NonNullList.withSize(SIZE, ItemStack.EMPTY);
|
||||||
|
ContainerHelper.loadAllItems(tag, items, registries);
|
||||||
|
// Pre-88-tab desks stored materials in slots 4..7. Move them once;
|
||||||
|
// never interpret those stacks as newly added collection tabs.
|
||||||
|
if (tag.getInt("InventoryVersion") < 1) {
|
||||||
|
for (int i = 0; i < 4; i++) {
|
||||||
|
items.set(INK + i, items.get(4 + i));
|
||||||
|
items.set(4 + i, ItemStack.EMPTY);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
activeCollection = Math.clamp(tag.getInt("ActiveCollection"), 0, COLLECTIONS - 1);
|
||||||
|
inkRemaining = Math.clamp(tag.getInt("InkRemaining"), 0, InkVialItem.CAPACITY);
|
||||||
|
displayPage = tag.contains("DisplayPage", CompoundTag.TAG_COMPOUND)
|
||||||
|
? ItemStack.parse(registries, tag.getCompound("DisplayPage")).orElse(ItemStack.EMPTY)
|
||||||
|
: ItemStack.EMPTY;
|
||||||
|
refillEmptyInkBar();
|
||||||
|
}
|
||||||
|
@Override protected void saveAdditional(CompoundTag tag, HolderLookup.Provider registries) {
|
||||||
|
super.saveAdditional(tag, registries);
|
||||||
|
ContainerHelper.saveAllItems(tag, items, registries);
|
||||||
|
tag.putInt("InventoryVersion", 1);
|
||||||
|
tag.putInt("ActiveCollection", activeCollection);
|
||||||
|
tag.putInt("InkRemaining", inkRemaining);
|
||||||
|
if (!displayPage.isEmpty()) tag.put("DisplayPage", displayPage.save(registries));
|
||||||
|
}
|
||||||
|
@Override public Packet<ClientGamePacketListener> getUpdatePacket() {
|
||||||
|
return ClientboundBlockEntityDataPacket.create(this);
|
||||||
|
}
|
||||||
|
@Override public CompoundTag getUpdateTag(HolderLookup.Provider registries) {
|
||||||
|
return saveWithoutMetadata(registries);
|
||||||
|
}
|
||||||
|
@Override public void setChanged() {
|
||||||
|
super.setChanged();
|
||||||
|
if (level != null && !level.isClientSide) {
|
||||||
|
level.sendBlockUpdated(worldPosition, getBlockState(), getBlockState(), 2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,132 @@
|
|||||||
|
package net.dnorberg.rivencraft.book;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
import net.dnorberg.rivencraft.Rivencraft;
|
||||||
|
import net.minecraft.core.BlockPos;
|
||||||
|
import net.minecraft.gametest.framework.GameTest;
|
||||||
|
import net.minecraft.gametest.framework.GameTestHelper;
|
||||||
|
import net.minecraft.nbt.CompoundTag;
|
||||||
|
import net.minecraft.nbt.ListTag;
|
||||||
|
import net.minecraft.resources.ResourceLocation;
|
||||||
|
import net.neoforged.neoforge.gametest.GameTestHolder;
|
||||||
|
import net.neoforged.neoforge.gametest.PrefixGameTestTemplate;
|
||||||
|
|
||||||
|
/** Saved-data migration and round-trip acceptance coverage for persistent Ages. */
|
||||||
|
@GameTestHolder(Rivencraft.MOD_ID)
|
||||||
|
@PrefixGameTestTemplate(false)
|
||||||
|
public final class AgePersistenceGameTests {
|
||||||
|
private AgePersistenceGameTests() {
|
||||||
|
}
|
||||||
|
|
||||||
|
@GameTest(template = "empty")
|
||||||
|
public static void everyTraitCombinationRoundTripsWithoutRerolling(GameTestHelper helper) {
|
||||||
|
ListTag entries = new ListTag();
|
||||||
|
AgeTraits.BiomeDistribution[] distributions = AgeTraits.BiomeDistribution.values();
|
||||||
|
AgeTraits.Lighting[] lightingValues = AgeTraits.Lighting.values();
|
||||||
|
AgeTraits.Weather[] weatherValues = AgeTraits.Weather.values();
|
||||||
|
|
||||||
|
for (int index = 0; index < distributions.length; index++) {
|
||||||
|
UUID id = new UUID(0x524956454E000000L + index, 0x4147450000000000L + index);
|
||||||
|
AgeTraits traits = new AgeTraits(
|
||||||
|
distributions[index],
|
||||||
|
lightingValues[index % lightingValues.length],
|
||||||
|
weatherValues[index % weatherValues.length],
|
||||||
|
index == 0 ? AgeTraits.STOPPED_CELESTIAL_PERIOD : 0.25D + index * 0.15D,
|
||||||
|
index * 37.5F,
|
||||||
|
index * 0.1F
|
||||||
|
);
|
||||||
|
entries.add(entry(
|
||||||
|
id,
|
||||||
|
"Persistent " + distributions[index],
|
||||||
|
9000L + index,
|
||||||
|
AgeGenerationProfiles.all().get(index % AgeGenerationProfiles.all().size()),
|
||||||
|
3 + index,
|
||||||
|
1200L + index,
|
||||||
|
ResourceLocation.fromNamespaceAndPath(Rivencraft.MOD_ID, "age/persistent_" + index),
|
||||||
|
new BlockPos(index, 70 + index, -index),
|
||||||
|
traits
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
CompoundTag root = new CompoundTag();
|
||||||
|
root.put("Ages", entries);
|
||||||
|
AgeRegistrySavedData first = AgeRegistrySavedData.load(root, helper.getLevel().registryAccess());
|
||||||
|
CompoundTag serialized = first.save(new CompoundTag(), helper.getLevel().registryAccess());
|
||||||
|
AgeRegistrySavedData restored = AgeRegistrySavedData.load(serialized, helper.getLevel().registryAccess());
|
||||||
|
|
||||||
|
for (int index = 0; index < distributions.length; index++) {
|
||||||
|
UUID id = new UUID(0x524956454E000000L + index, 0x4147450000000000L + index);
|
||||||
|
helper.assertValueEqual(restored.find(id).orElseThrow(), first.find(id).orElseThrow(),
|
||||||
|
distributions[index] + " and its weather, lighting, celestial, and identity data must round-trip");
|
||||||
|
}
|
||||||
|
helper.succeed();
|
||||||
|
}
|
||||||
|
|
||||||
|
@GameTest(template = "empty")
|
||||||
|
public static void legacyDefinitionReceivesStableDefaults(GameTestHelper helper) {
|
||||||
|
UUID id = UUID.fromString("4d797374-6372-6166-7400-000000000001");
|
||||||
|
CompoundTag legacy = new CompoundTag();
|
||||||
|
legacy.putUUID("Id", id);
|
||||||
|
legacy.putString("Name", " Legacy Age ");
|
||||||
|
legacy.putLong("Seed", 8675309L);
|
||||||
|
legacy.putString("GenerationProfile", AgeDefinition.RANDOM_VANILLA_PROFILE.toString());
|
||||||
|
legacy.putLong("CreatedGameTime", 42L);
|
||||||
|
ListTag entries = new ListTag();
|
||||||
|
entries.add(legacy);
|
||||||
|
CompoundTag root = new CompoundTag();
|
||||||
|
root.put("Ages", entries);
|
||||||
|
|
||||||
|
AgeRegistrySavedData migrated = AgeRegistrySavedData.load(root, helper.getLevel().registryAccess());
|
||||||
|
AgeDefinition definition = migrated.find(id).orElseThrow();
|
||||||
|
helper.assertValueEqual(definition.id(), id, "Migration must retain the Age UUID");
|
||||||
|
helper.assertValueEqual(definition.name(), "Legacy Age", "Migration must normalize and retain the Age name");
|
||||||
|
helper.assertValueEqual(definition.seed(), 8675309L, "Migration must retain the Age seed");
|
||||||
|
helper.assertValueEqual(definition.generationProfile(), AgeDefinition.RANDOM_VANILLA_PROFILE,
|
||||||
|
"Migration must retain the legacy generation profile for deterministic runtime fallback");
|
||||||
|
helper.assertValueEqual(definition.generationVersion(), 1,
|
||||||
|
"Definitions predating generation versions must receive version 1");
|
||||||
|
helper.assertValueEqual(definition.dimensionId(), AgeDefinition.dimensionId(id),
|
||||||
|
"Definitions predating named dimensions must retain the UUID-derived dimension");
|
||||||
|
helper.assertValueEqual(definition.traits(), AgeTraits.LEGACY_DEFAULTS,
|
||||||
|
"Definitions predating traits must receive stable legacy defaults");
|
||||||
|
|
||||||
|
CompoundTag serialized = migrated.save(new CompoundTag(), helper.getLevel().registryAccess());
|
||||||
|
AgeDefinition reloaded = AgeRegistrySavedData.load(serialized, helper.getLevel().registryAccess())
|
||||||
|
.find(id).orElseThrow();
|
||||||
|
helper.assertValueEqual(reloaded, definition, "A migrated definition must not reroll on its next restart");
|
||||||
|
helper.succeed();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static CompoundTag entry(
|
||||||
|
UUID id,
|
||||||
|
String name,
|
||||||
|
long seed,
|
||||||
|
ResourceLocation profile,
|
||||||
|
int version,
|
||||||
|
long createdTime,
|
||||||
|
ResourceLocation dimension,
|
||||||
|
BlockPos spawn,
|
||||||
|
AgeTraits traits
|
||||||
|
) {
|
||||||
|
CompoundTag entry = new CompoundTag();
|
||||||
|
entry.putUUID("Id", id);
|
||||||
|
entry.putString("Name", name);
|
||||||
|
entry.putLong("Seed", seed);
|
||||||
|
entry.putString("GenerationProfile", profile.toString());
|
||||||
|
entry.putInt("GenerationVersion", version);
|
||||||
|
entry.putLong("CreatedGameTime", createdTime);
|
||||||
|
entry.putString("Dimension", dimension.toString());
|
||||||
|
entry.putInt("SpawnX", spawn.getX());
|
||||||
|
entry.putInt("SpawnY", spawn.getY());
|
||||||
|
entry.putInt("SpawnZ", spawn.getZ());
|
||||||
|
CompoundTag serializedTraits = new CompoundTag();
|
||||||
|
serializedTraits.putString("BiomeDistribution", traits.biomeDistribution().name());
|
||||||
|
serializedTraits.putString("Lighting", traits.lighting().name());
|
||||||
|
serializedTraits.putString("Weather", traits.weather().name());
|
||||||
|
serializedTraits.putDouble("CelestialPeriod", traits.celestialPeriod());
|
||||||
|
serializedTraits.putFloat("CelestialAngle", traits.celestialAngle());
|
||||||
|
serializedTraits.putFloat("CelestialPhase", traits.celestialPhase());
|
||||||
|
entry.put("Traits", serializedTraits);
|
||||||
|
return entry;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -103,7 +103,7 @@ public final class AgeRegistrySavedData extends SavedData {
|
|||||||
return created;
|
return created;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static AgeRegistrySavedData load(CompoundTag tag, HolderLookup.Provider registries) {
|
static AgeRegistrySavedData load(CompoundTag tag, HolderLookup.Provider registries) {
|
||||||
AgeRegistrySavedData data = new AgeRegistrySavedData();
|
AgeRegistrySavedData data = new AgeRegistrySavedData();
|
||||||
ListTag serializedAges = tag.getList(AGES_TAG, CompoundTag.TAG_COMPOUND);
|
ListTag serializedAges = tag.getList(AGES_TAG, CompoundTag.TAG_COMPOUND);
|
||||||
for (int index = 0; index < serializedAges.size(); index++) {
|
for (int index = 0; index < serializedAges.size(); index++) {
|
||||||
@@ -111,12 +111,18 @@ public final class AgeRegistrySavedData extends SavedData {
|
|||||||
if (!entry.hasUUID(ID_TAG)) {
|
if (!entry.hasUUID(ID_TAG)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
ResourceLocation profile = ResourceLocation.tryParse(entry.getString(PROFILE_TAG));
|
ResourceLocation profile = entry.contains(PROFILE_TAG, CompoundTag.TAG_STRING)
|
||||||
|
&& !entry.getString(PROFILE_TAG).isBlank()
|
||||||
|
? ResourceLocation.tryParse(entry.getString(PROFILE_TAG))
|
||||||
|
: null;
|
||||||
if (profile == null) {
|
if (profile == null) {
|
||||||
profile = AgeDefinition.RANDOM_VANILLA_PROFILE;
|
profile = AgeDefinition.RANDOM_VANILLA_PROFILE;
|
||||||
}
|
}
|
||||||
UUID id = entry.getUUID(ID_TAG);
|
UUID id = entry.getUUID(ID_TAG);
|
||||||
ResourceLocation dimensionId = ResourceLocation.tryParse(entry.getString(DIMENSION_TAG));
|
ResourceLocation dimensionId = entry.contains(DIMENSION_TAG, CompoundTag.TAG_STRING)
|
||||||
|
&& !entry.getString(DIMENSION_TAG).isBlank()
|
||||||
|
? ResourceLocation.tryParse(entry.getString(DIMENSION_TAG))
|
||||||
|
: null;
|
||||||
if (dimensionId == null) {
|
if (dimensionId == null) {
|
||||||
dimensionId = AgeDefinition.dimensionId(id);
|
dimensionId = AgeDefinition.dimensionId(id);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,12 +2,20 @@ package net.dnorberg.rivencraft.client;
|
|||||||
|
|
||||||
import net.dnorberg.rivencraft.Rivencraft;
|
import net.dnorberg.rivencraft.Rivencraft;
|
||||||
import net.dnorberg.rivencraft.registry.ModBlockEntities;
|
import net.dnorberg.rivencraft.registry.ModBlockEntities;
|
||||||
|
import net.dnorberg.rivencraft.registry.ModDataComponents;
|
||||||
|
import net.dnorberg.rivencraft.registry.ModItems;
|
||||||
|
import net.minecraft.client.renderer.item.ItemProperties;
|
||||||
|
import net.minecraft.resources.ResourceLocation;
|
||||||
import net.neoforged.api.distmarker.Dist;
|
import net.neoforged.api.distmarker.Dist;
|
||||||
import net.neoforged.bus.api.SubscribeEvent;
|
import net.neoforged.bus.api.SubscribeEvent;
|
||||||
import net.neoforged.fml.common.EventBusSubscriber;
|
import net.neoforged.fml.common.EventBusSubscriber;
|
||||||
import net.neoforged.fml.event.lifecycle.FMLClientSetupEvent;
|
import net.neoforged.fml.event.lifecycle.FMLClientSetupEvent;
|
||||||
import net.neoforged.neoforge.common.NeoForge;
|
import net.neoforged.neoforge.common.NeoForge;
|
||||||
import net.neoforged.neoforge.client.event.EntityRenderersEvent;
|
import net.neoforged.neoforge.client.event.EntityRenderersEvent;
|
||||||
|
import net.neoforged.neoforge.client.event.RegisterMenuScreensEvent;
|
||||||
|
import net.dnorberg.rivencraft.client.screen.NotebookScreen;
|
||||||
|
import net.dnorberg.rivencraft.client.screen.WritingDeskScreen;
|
||||||
|
import net.dnorberg.rivencraft.registry.ModMenus;
|
||||||
|
|
||||||
@EventBusSubscriber(modid = Rivencraft.MOD_ID, value = Dist.CLIENT)
|
@EventBusSubscriber(modid = Rivencraft.MOD_ID, value = Dist.CLIENT)
|
||||||
public final class ClientEvents {
|
public final class ClientEvents {
|
||||||
@@ -17,10 +25,22 @@ public final class ClientEvents {
|
|||||||
@SubscribeEvent
|
@SubscribeEvent
|
||||||
public static void registerRenderers(EntityRenderersEvent.RegisterRenderers event) {
|
public static void registerRenderers(EntityRenderersEvent.RegisterRenderers event) {
|
||||||
event.registerBlockEntityRenderer(ModBlockEntities.BOOK_STAND.get(), BookStandRenderer::new);
|
event.registerBlockEntityRenderer(ModBlockEntities.BOOK_STAND.get(), BookStandRenderer::new);
|
||||||
|
event.registerBlockEntityRenderer(ModBlockEntities.WRITING_DESK.get(), WritingDeskRenderer::new);
|
||||||
|
}
|
||||||
|
|
||||||
|
@SubscribeEvent
|
||||||
|
public static void registerScreens(RegisterMenuScreensEvent event) {
|
||||||
|
event.register(ModMenus.NOTEBOOK.get(), NotebookScreen::new);
|
||||||
|
event.register(ModMenus.WRITING_DESK.get(), WritingDeskScreen::new);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SubscribeEvent
|
@SubscribeEvent
|
||||||
public static void clientSetup(FMLClientSetupEvent event) {
|
public static void clientSetup(FMLClientSetupEvent event) {
|
||||||
|
event.enqueueWork(() -> ItemProperties.register(
|
||||||
|
ModItems.LINKING_BOOK.get(),
|
||||||
|
ResourceLocation.fromNamespaceAndPath(Rivencraft.MOD_ID, "bound"),
|
||||||
|
(stack, level, entity, seed) -> stack.has(ModDataComponents.LINK_TARGET.get()) ? 1.0F : 0.0F
|
||||||
|
));
|
||||||
NeoForge.EVENT_BUS.addListener(ClientBookInteractionHandler::onRightClickItem);
|
NeoForge.EVENT_BUS.addListener(ClientBookInteractionHandler::onRightClickItem);
|
||||||
NeoForge.EVENT_BUS.addListener(ClientBookInteractionHandler::onRightClickBlock);
|
NeoForge.EVENT_BUS.addListener(ClientBookInteractionHandler::onRightClickBlock);
|
||||||
NeoForge.EVENT_BUS.addListener(ClientBookExploreOverlay::onClientTickPre);
|
NeoForge.EVENT_BUS.addListener(ClientBookExploreOverlay::onClientTickPre);
|
||||||
|
|||||||
@@ -0,0 +1,20 @@
|
|||||||
|
package net.dnorberg.rivencraft.client;
|
||||||
|
|
||||||
|
import net.dnorberg.rivencraft.menu.WritingDeskMenu;
|
||||||
|
import net.dnorberg.rivencraft.network.WritingDeskCatalogPayload;
|
||||||
|
import net.minecraft.client.Minecraft;
|
||||||
|
import net.neoforged.neoforge.network.handling.IPayloadContext;
|
||||||
|
|
||||||
|
public final class ClientWritingDeskCatalog {
|
||||||
|
private ClientWritingDeskCatalog() {}
|
||||||
|
|
||||||
|
public static void handle(WritingDeskCatalogPayload payload, IPayloadContext context) {
|
||||||
|
context.enqueueWork(() -> {
|
||||||
|
var player = Minecraft.getInstance().player;
|
||||||
|
if (player != null && player.containerMenu instanceof WritingDeskMenu menu
|
||||||
|
&& menu.containerId == payload.containerId()) {
|
||||||
|
menu.setCatalog(payload.symbols());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,55 @@
|
|||||||
|
package net.dnorberg.rivencraft.client;
|
||||||
|
|
||||||
|
import com.mojang.blaze3d.vertex.PoseStack;
|
||||||
|
import com.mojang.math.Axis;
|
||||||
|
import net.dnorberg.rivencraft.block.WritingDeskBlock;
|
||||||
|
import net.dnorberg.rivencraft.block.entity.WritingDeskBlockEntity;
|
||||||
|
import net.minecraft.client.Minecraft;
|
||||||
|
import net.minecraft.client.renderer.MultiBufferSource;
|
||||||
|
import net.minecraft.client.renderer.blockentity.BlockEntityRenderer;
|
||||||
|
import net.minecraft.client.renderer.blockentity.BlockEntityRendererProvider;
|
||||||
|
import net.minecraft.world.item.ItemDisplayContext;
|
||||||
|
import net.minecraft.world.item.ItemStack;
|
||||||
|
import net.minecraft.world.item.Items;
|
||||||
|
|
||||||
|
/** Visible selected page and loaded paper, as on the Legacy desk. */
|
||||||
|
public final class WritingDeskRenderer implements BlockEntityRenderer<WritingDeskBlockEntity> {
|
||||||
|
public WritingDeskRenderer(BlockEntityRendererProvider.Context context) {}
|
||||||
|
|
||||||
|
@Override public void render(WritingDeskBlockEntity desk, float partialTick, PoseStack pose,
|
||||||
|
MultiBufferSource buffers, int light, int overlay) {
|
||||||
|
int paper = desk.getItem(WritingDeskBlockEntity.PAPER).getCount();
|
||||||
|
ItemStack page = desk.displayPage();
|
||||||
|
if (paper == 0 && page.isEmpty()) return;
|
||||||
|
pose.pushPose();
|
||||||
|
pose.translate(0.5, 0, 0.5);
|
||||||
|
pose.mulPose(Axis.YP.rotationDegrees(
|
||||||
|
180.0F - desk.getBlockState().getValue(WritingDeskBlock.FACING).toYRot()));
|
||||||
|
if (paper > 0) {
|
||||||
|
ItemStack sheet = new ItemStack(Items.PAPER);
|
||||||
|
int layers = Math.min(4, 1 + paper / 16);
|
||||||
|
for (int i = 0; i < layers; i++) {
|
||||||
|
drawFlat(desk, sheet, pose, buffers, light, overlay, 1.22, 0.27 + i * 0.008, -0.14, 0.55F);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!page.isEmpty()) {
|
||||||
|
drawFlat(desk, page, pose, buffers, light, overlay, 1.0, 0.572, 0.0, 0.8F);
|
||||||
|
}
|
||||||
|
pose.popPose();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void drawFlat(WritingDeskBlockEntity desk, ItemStack stack, PoseStack pose,
|
||||||
|
MultiBufferSource buffers, int light, int overlay,
|
||||||
|
double x, double y, double z, float scale) {
|
||||||
|
pose.pushPose();
|
||||||
|
pose.translate(x, y, z);
|
||||||
|
pose.mulPose(Axis.XP.rotationDegrees(90));
|
||||||
|
pose.scale(scale, scale, scale);
|
||||||
|
Minecraft.getInstance().getItemRenderer().renderStatic(stack, ItemDisplayContext.FIXED,
|
||||||
|
light, overlay, pose, buffers, desk.getLevel(), 0);
|
||||||
|
pose.popPose();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override public boolean shouldRenderOffScreen(WritingDeskBlockEntity blockEntity) { return true; }
|
||||||
|
@Override public int getViewDistance() { return 64; }
|
||||||
|
}
|
||||||
@@ -1,44 +1,22 @@
|
|||||||
package net.dnorberg.rivencraft.client.preview;
|
package net.dnorberg.rivencraft.client.preview;
|
||||||
|
|
||||||
import net.dnorberg.rivencraft.config.RivencraftClientConfig;
|
import net.dnorberg.rivencraft.config.RivencraftClientConfig;
|
||||||
|
import net.dnorberg.rivencraft.compat.PreviewBackendSelector;
|
||||||
import net.neoforged.fml.ModList;
|
import net.neoforged.fml.ModList;
|
||||||
|
|
||||||
/** Selects the configured destination preview while keeping optional integrations optional. */
|
/** Selects the configured destination preview while keeping optional integrations optional. */
|
||||||
public final class DestinationPreviewRenderers {
|
public final class DestinationPreviewRenderers {
|
||||||
private enum Backend {
|
|
||||||
IMMERSIVE_PORTALS,
|
|
||||||
PONDER,
|
|
||||||
LEGACY
|
|
||||||
}
|
|
||||||
|
|
||||||
private DestinationPreviewRenderers() {
|
private DestinationPreviewRenderers() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static DestinationPreviewRenderer create() {
|
public static DestinationPreviewRenderer create() {
|
||||||
boolean ponderAvailable = ModList.get().isLoaded("create");
|
boolean ponderAvailable = ModList.get().isLoaded("create");
|
||||||
// The mode and priority are established before the optional IP renderer
|
|
||||||
// lands, so selecting it currently follows the documented safe fallback.
|
|
||||||
boolean immersivePortalsAvailable = ModList.get().isLoaded("immersive_portals_core");
|
boolean immersivePortalsAvailable = ModList.get().isLoaded("immersive_portals_core");
|
||||||
return switch (selectBackend(
|
return switch (PreviewBackendSelector.select(
|
||||||
RivencraftClientConfig.previewMode(), immersivePortalsAvailable, ponderAvailable)) {
|
RivencraftClientConfig.previewMode(), immersivePortalsAvailable, ponderAvailable)) {
|
||||||
case IMMERSIVE_PORTALS -> new ImmersivePortalsDestinationPreviewRenderer();
|
case IMMERSIVE_PORTALS -> new ImmersivePortalsDestinationPreviewRenderer();
|
||||||
case PONDER -> new PonderDestinationPreviewRenderer();
|
case PONDER -> new PonderDestinationPreviewRenderer();
|
||||||
case LEGACY -> new LegacyDestinationPreviewRenderer();
|
case LEGACY -> new LegacyDestinationPreviewRenderer();
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Backend selectBackend(
|
|
||||||
RivencraftClientConfig.PreviewMode mode,
|
|
||||||
boolean immersivePortalsAvailable,
|
|
||||||
boolean ponderAvailable
|
|
||||||
) {
|
|
||||||
return switch (mode) {
|
|
||||||
case AUTO -> immersivePortalsAvailable
|
|
||||||
? Backend.IMMERSIVE_PORTALS
|
|
||||||
: ponderAvailable ? Backend.PONDER : Backend.LEGACY;
|
|
||||||
case IMMERSIVE_PORTALS -> immersivePortalsAvailable ? Backend.IMMERSIVE_PORTALS : Backend.LEGACY;
|
|
||||||
case PONDER -> ponderAvailable ? Backend.PONDER : Backend.LEGACY;
|
|
||||||
case LEGACY -> Backend.LEGACY;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -42,7 +42,11 @@ public final class ImmersivePortalsDestinationPreviewRenderer implements Destina
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void accept(LinkPreviewPayload payload) {
|
public void accept(LinkPreviewPayload payload) {
|
||||||
|
if (destination != null) {
|
||||||
|
ImmersivePortalsPreviewAudioGuard.clear(destination.dimension());
|
||||||
|
}
|
||||||
destination = payload;
|
destination = payload;
|
||||||
|
ImmersivePortalsPreviewAudioGuard.mute(payload.dimension());
|
||||||
resetView();
|
resetView();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -118,6 +122,7 @@ public final class ImmersivePortalsDestinationPreviewRenderer implements Destina
|
|||||||
FRAMEBUFFER.clear(true);
|
FRAMEBUFFER.clear(true);
|
||||||
minecraft.getMainRenderTarget().bindWrite(true);
|
minecraft.getMainRenderTarget().bindWrite(true);
|
||||||
MyRenderHelper.restoreViewPort();
|
MyRenderHelper.restoreViewPort();
|
||||||
|
ImmersivePortalsPreviewAudioGuard.markCameraRestorePending();
|
||||||
GuiPortalRendering.submitNextFrameRendering(info, FRAMEBUFFER);
|
GuiPortalRendering.submitNextFrameRendering(info, FRAMEBUFFER);
|
||||||
hasCompletedFrame = true;
|
hasCompletedFrame = true;
|
||||||
graphics.renderOutline(left, top, width, height, exploring ? 0xFFE0C36A : 0xFF7B6AA8);
|
graphics.renderOutline(left, top, width, height, exploring ? 0xFFE0C36A : 0xFF7B6AA8);
|
||||||
@@ -234,5 +239,8 @@ public final class ImmersivePortalsDestinationPreviewRenderer implements Destina
|
|||||||
public void close() {
|
public void close() {
|
||||||
clearMovement();
|
clearMovement();
|
||||||
hasCompletedFrame = false;
|
hasCompletedFrame = false;
|
||||||
|
if (destination != null) {
|
||||||
|
ImmersivePortalsPreviewAudioGuard.clear(destination.dimension());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,62 @@
|
|||||||
|
package net.dnorberg.rivencraft.client.preview;
|
||||||
|
|
||||||
|
import net.minecraft.client.Minecraft;
|
||||||
|
import net.minecraft.client.Camera;
|
||||||
|
import net.minecraft.client.multiplayer.ClientLevel;
|
||||||
|
import net.minecraft.resources.ResourceKey;
|
||||||
|
import net.minecraft.world.level.Level;
|
||||||
|
|
||||||
|
/** Prevents an Immersive Portals preview world from contributing sounds to a book screen. */
|
||||||
|
public final class ImmersivePortalsPreviewAudioGuard {
|
||||||
|
private static ResourceKey<Level> mutedDimension;
|
||||||
|
private static boolean cameraRestorePending;
|
||||||
|
|
||||||
|
private ImmersivePortalsPreviewAudioGuard() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void mute(ResourceKey<Level> dimension) {
|
||||||
|
mutedDimension = dimension;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void clear(ResourceKey<Level> dimension) {
|
||||||
|
if (dimension.equals(mutedDimension)) {
|
||||||
|
mutedDimension = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean shouldMute(ClientLevel level) {
|
||||||
|
Minecraft minecraft = Minecraft.getInstance();
|
||||||
|
return mutedDimension != null
|
||||||
|
&& level.dimension().equals(mutedDimension)
|
||||||
|
&& (minecraft.player == null || level != minecraft.player.level());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void markCameraRestorePending() {
|
||||||
|
cameraRestorePending = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Immersive Portals' GUI renderer leaves the shared main camera in the
|
||||||
|
* remote world after its end-of-frame render. Restore it before the next
|
||||||
|
* frame uses that camera for rain effects and the sound listener.
|
||||||
|
*/
|
||||||
|
public static void restorePlayerCamera() {
|
||||||
|
Minecraft minecraft = Minecraft.getInstance();
|
||||||
|
if (!cameraRestorePending) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
cameraRestorePending = false;
|
||||||
|
if (minecraft.level == null || minecraft.getCameraEntity() == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Camera camera = minecraft.gameRenderer.getMainCamera();
|
||||||
|
camera.setup(
|
||||||
|
minecraft.level,
|
||||||
|
minecraft.getCameraEntity(),
|
||||||
|
!minecraft.options.getCameraType().isFirstPerson(),
|
||||||
|
minecraft.options.getCameraType().isMirrored(),
|
||||||
|
camera.getPartialTickTime()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,324 @@
|
|||||||
|
package net.dnorberg.rivencraft.client.screen;
|
||||||
|
|
||||||
|
import java.util.Locale;
|
||||||
|
import net.dnorberg.rivencraft.Rivencraft;
|
||||||
|
import net.dnorberg.rivencraft.item.PageItem;
|
||||||
|
import net.dnorberg.rivencraft.menu.NotebookMenu;
|
||||||
|
import net.dnorberg.rivencraft.registry.ModItems;
|
||||||
|
import net.minecraft.client.gui.GuiGraphics;
|
||||||
|
import net.minecraft.client.gui.components.Button;
|
||||||
|
import net.minecraft.client.gui.components.EditBox;
|
||||||
|
import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen;
|
||||||
|
import net.minecraft.network.chat.Component;
|
||||||
|
import net.minecraft.resources.ResourceLocation;
|
||||||
|
import net.minecraft.world.entity.player.Inventory;
|
||||||
|
import net.minecraft.world.inventory.ClickType;
|
||||||
|
import net.minecraft.world.item.ItemStack;
|
||||||
|
|
||||||
|
/** A page surface modelled on Legacy's folder GUI, backed by the Notebook menu. */
|
||||||
|
public final class NotebookScreen extends AbstractContainerScreen<NotebookMenu> {
|
||||||
|
private static final int SURFACE_TOP = 20;
|
||||||
|
private static final int SURFACE_BOTTOM = 132;
|
||||||
|
private static final int SURFACE_RIGHT = 156;
|
||||||
|
private static final int PAGE_WIDTH = 30;
|
||||||
|
private static final int PAGE_HEIGHT = 40;
|
||||||
|
private static final int PAGE_STEP_X = 31;
|
||||||
|
private static final int PAGE_STEP_Y = 41;
|
||||||
|
private static final int PAGE_COLUMNS = 5;
|
||||||
|
private static final ResourceLocation PAGE_ATLAS = texture("gui/notebook_pages");
|
||||||
|
private static final ResourceLocation GENERIC_SYMBOL = texture("item/page_symbol");
|
||||||
|
private static final ResourceLocation UNRESOLVED_SYMBOL = texture("item/page_unresolved");
|
||||||
|
private static final ResourceLocation STANDARD_TERRAIN = texture("item/page_symbol_terrain_standard");
|
||||||
|
private static final ResourceLocation NATIVE_BIOMES = texture("item/page_symbol_biome_native");
|
||||||
|
private static final ResourceLocation NORMAL_LIGHTING = texture("item/page_symbol_lighting_normal");
|
||||||
|
private static final ResourceLocation NORMAL_WEATHER = texture("item/page_symbol_weather_normal");
|
||||||
|
private static final ResourceLocation NORMAL_TIME = texture("item/page_symbol_celestial_normal_time");
|
||||||
|
private static final ResourceLocation CAVES = texture("item/page_symbol_feature_caves");
|
||||||
|
private EditBox textInput;
|
||||||
|
private boolean draggingScrollbar;
|
||||||
|
private boolean surfaceClickPendingRelease;
|
||||||
|
private int selectedSlot = -1;
|
||||||
|
private int scroll;
|
||||||
|
|
||||||
|
public NotebookScreen(NotebookMenu menu, Inventory inventory, Component title) {
|
||||||
|
super(menu, inventory, title);
|
||||||
|
imageWidth = 176;
|
||||||
|
imageHeight = 213;
|
||||||
|
inventoryLabelY = 123;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void init() {
|
||||||
|
super.init();
|
||||||
|
Button sortButton = Button.builder(Component.literal("AZ"), button -> {})
|
||||||
|
.bounds(leftPos, topPos, 18, 18).build();
|
||||||
|
Button allButton = Button.builder(Component.literal("ALL"), button -> {})
|
||||||
|
.bounds(leftPos + 20, topPos, 26, 18).build();
|
||||||
|
sortButton.active = false;
|
||||||
|
allButton.active = false;
|
||||||
|
addRenderableWidget(sortButton);
|
||||||
|
addRenderableWidget(allButton);
|
||||||
|
textInput = new EditBox(font, leftPos + 48, topPos, 128, 18,
|
||||||
|
Component.translatable("screen.rivencraft.notebook.search"));
|
||||||
|
textInput.setMaxLength(32);
|
||||||
|
textInput.setHint(Component.translatable("screen.rivencraft.notebook.search"));
|
||||||
|
textInput.setResponder(value -> scroll = 0);
|
||||||
|
addRenderableWidget(textInput);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void render(GuiGraphics graphics, int mouseX, int mouseY, float partialTick) {
|
||||||
|
super.render(graphics, mouseX, mouseY, partialTick);
|
||||||
|
int pageSlots = displayedPageSlots();
|
||||||
|
scroll = Math.min(scroll, maxScroll(pageSlots));
|
||||||
|
graphics.enableScissor(leftPos, topPos + SURFACE_TOP, leftPos + SURFACE_RIGHT,
|
||||||
|
topPos + SURFACE_BOTTOM);
|
||||||
|
for (int index = 0; index < pageSlots; index++) {
|
||||||
|
int x = leftPos + (index % PAGE_COLUMNS) * PAGE_STEP_X;
|
||||||
|
int y = topPos + SURFACE_TOP + (index / PAGE_COLUMNS) * PAGE_STEP_Y - scroll;
|
||||||
|
if (y + PAGE_HEIGHT > topPos + SURFACE_TOP && y < topPos + SURFACE_BOTTOM) {
|
||||||
|
drawPage(graphics, index, x, y);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
graphics.disableScissor();
|
||||||
|
drawScrollbar(graphics, pageSlots);
|
||||||
|
int hovered = pageAt(mouseX, mouseY);
|
||||||
|
if (!menu.getCarried().isEmpty() && inSurface(mouseX, mouseY)) {
|
||||||
|
graphics.renderItem(menu.getCarried(), mouseX - 8, mouseY - 8);
|
||||||
|
} else if (hovered >= 0 && !menu.getSlot(hovered).getItem().isEmpty()) {
|
||||||
|
ItemStack page = menu.getSlot(hovered).getItem();
|
||||||
|
if (matchesSearch(page)) graphics.renderTooltip(font, page, mouseX, mouseY);
|
||||||
|
} else {
|
||||||
|
renderTooltip(graphics, mouseX, mouseY);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void renderBg(GuiGraphics graphics, float partialTick, int mouseX, int mouseY) {
|
||||||
|
graphics.fill(leftPos, topPos + SURFACE_TOP, leftPos + SURFACE_RIGHT,
|
||||||
|
topPos + SURFACE_BOTTOM, 0xB0000000);
|
||||||
|
drawBeveledPanel(graphics, leftPos, topPos + 132, imageWidth, 81);
|
||||||
|
for (int row = 0; row < 3; row++) {
|
||||||
|
for (int column = 0; column < 9; column++) drawSlot(graphics, 7 + column * 18, 134 + row * 18);
|
||||||
|
}
|
||||||
|
for (int column = 0; column < 9; column++) drawSlot(graphics, 7 + column * 18, 192);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void renderLabels(GuiGraphics graphics, int mouseX, int mouseY) {
|
||||||
|
graphics.drawString(font, playerInventoryTitle, inventoryLabelX, inventoryLabelY, 0x404040, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean mouseClicked(double mouseX, double mouseY, int button) {
|
||||||
|
if (inScrollbar(mouseX, mouseY) && button == 0) {
|
||||||
|
draggingScrollbar = true;
|
||||||
|
setScrollFromMouse(mouseY, displayedPageSlots());
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
int index = pageAt(mouseX, mouseY);
|
||||||
|
if (index >= 0 && (button == 0 || button == 1)) {
|
||||||
|
ItemStack page = menu.getSlot(index).getItem();
|
||||||
|
if ((!page.isEmpty() && !matchesSearch(page))
|
||||||
|
|| (page.isEmpty() && !menu.getCarried().is(ModItems.PAGE.get()))) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
setFocused(null);
|
||||||
|
textInput.setFocused(false);
|
||||||
|
selectedSlot = index;
|
||||||
|
slotClicked(menu.getSlot(index), index, button, ClickType.PICKUP);
|
||||||
|
surfaceClickPendingRelease = true;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return super.mouseClicked(mouseX, mouseY, button);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean mouseDragged(double mouseX, double mouseY, int button, double dragX, double dragY) {
|
||||||
|
if (draggingScrollbar && button == 0) {
|
||||||
|
setScrollFromMouse(mouseY, displayedPageSlots());
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return super.mouseDragged(mouseX, mouseY, button, dragX, dragY);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean mouseReleased(double mouseX, double mouseY, int button) {
|
||||||
|
if (draggingScrollbar || surfaceClickPendingRelease) {
|
||||||
|
draggingScrollbar = false;
|
||||||
|
surfaceClickPendingRelease = false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
draggingScrollbar = false;
|
||||||
|
return super.mouseReleased(mouseX, mouseY, button);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean mouseScrolled(double mouseX, double mouseY, double scrollX, double scrollY) {
|
||||||
|
if (inSurface(mouseX, mouseY) || inScrollbar(mouseX, mouseY)) {
|
||||||
|
scroll = Math.clamp(scroll - (int)Math.signum(scrollY) * 20,
|
||||||
|
0, maxScroll(displayedPageSlots()));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return super.mouseScrolled(mouseX, mouseY, scrollX, scrollY);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean keyPressed(int keyCode, int scanCode, int modifiers) {
|
||||||
|
if (textInput.isFocused()) {
|
||||||
|
if (keyCode == 256) {
|
||||||
|
setFocused(null);
|
||||||
|
textInput.setFocused(false);
|
||||||
|
} else {
|
||||||
|
textInput.keyPressed(keyCode, scanCode, modifiers);
|
||||||
|
}
|
||||||
|
// EditBox does not consume ordinary letter key presses; the matching charTyped
|
||||||
|
// event handles text input. Do not pass them to the container's inventory keys.
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (!textInput.isFocused() && selectedSlot >= 0 && (keyCode == 263 || keyCode == 262)) {
|
||||||
|
moveSelected(keyCode == 262);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return super.keyPressed(keyCode, scanCode, modifiers);
|
||||||
|
}
|
||||||
|
|
||||||
|
private int displayedPageSlots() {
|
||||||
|
if (menu.getCarried().is(ModItems.PAGE.get())) {
|
||||||
|
return NotebookMenu.NOTEBOOK_SLOTS;
|
||||||
|
}
|
||||||
|
for (int index = NotebookMenu.NOTEBOOK_SLOTS - 1; index >= 0; index--) {
|
||||||
|
if (!menu.getSlot(index).getItem().isEmpty()) {
|
||||||
|
return index + 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean matchesSearch(ItemStack page) {
|
||||||
|
return textInput.getValue().isBlank()
|
||||||
|
|| page.getHoverName().getString().toLowerCase(Locale.ROOT)
|
||||||
|
.contains(textInput.getValue().toLowerCase(Locale.ROOT));
|
||||||
|
}
|
||||||
|
|
||||||
|
private int pageAt(double mouseX, double mouseY) {
|
||||||
|
if (!inSurface(mouseX, mouseY)) return -1;
|
||||||
|
int localX = (int)mouseX - leftPos;
|
||||||
|
int localY = (int)mouseY - topPos - SURFACE_TOP + scroll;
|
||||||
|
int column = localX / PAGE_STEP_X;
|
||||||
|
int index = (localY / PAGE_STEP_Y) * PAGE_COLUMNS + column;
|
||||||
|
return column < PAGE_COLUMNS && localX % PAGE_STEP_X < PAGE_WIDTH
|
||||||
|
&& localY % PAGE_STEP_Y < PAGE_HEIGHT && index < displayedPageSlots()
|
||||||
|
? index : -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean inSurface(double mouseX, double mouseY) {
|
||||||
|
return mouseX >= leftPos && mouseX < leftPos + SURFACE_RIGHT
|
||||||
|
&& mouseY >= topPos + SURFACE_TOP && mouseY < topPos + SURFACE_BOTTOM;
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean inScrollbar(double mouseX, double mouseY) {
|
||||||
|
return mouseX >= leftPos + SURFACE_RIGHT && mouseX < leftPos + imageWidth
|
||||||
|
&& mouseY >= topPos + SURFACE_TOP && mouseY < topPos + SURFACE_BOTTOM;
|
||||||
|
}
|
||||||
|
|
||||||
|
private int maxScroll(int pageCount) {
|
||||||
|
int rows = (pageCount + PAGE_COLUMNS - 1) / PAGE_COLUMNS;
|
||||||
|
return Math.max(0, rows * PAGE_STEP_Y - (SURFACE_BOTTOM - SURFACE_TOP));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setScrollFromMouse(double mouseY, int pageCount) {
|
||||||
|
int maximum = maxScroll(pageCount);
|
||||||
|
double fraction = (mouseY - topPos - SURFACE_TOP - 10.0)
|
||||||
|
/ (SURFACE_BOTTOM - SURFACE_TOP - 20.0);
|
||||||
|
scroll = Math.clamp((int)(Math.clamp(fraction, 0.0, 1.0) * maximum), 0, maximum);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void drawScrollbar(GuiGraphics graphics, int pageCount) {
|
||||||
|
int x = leftPos + SURFACE_RIGHT;
|
||||||
|
int y = topPos + SURFACE_TOP;
|
||||||
|
int height = SURFACE_BOTTOM - SURFACE_TOP;
|
||||||
|
graphics.fill(x, y, x + 20, y + height, 0xFF858585);
|
||||||
|
graphics.renderOutline(x, y, 20, height, 0xFF262626);
|
||||||
|
for (int line = y + 5; line < y + height - 4; line += 5) {
|
||||||
|
graphics.fill(x + 4, line, x + 16, line + 1, 0xFFB7B7B7);
|
||||||
|
}
|
||||||
|
int maximum = maxScroll(pageCount);
|
||||||
|
int thumbY = y + 4 + (maximum == 0 ? 0 : scroll * (height - 23) / maximum);
|
||||||
|
graphics.fill(x + 4, thumbY, x + 16, thumbY + 15, 0xFFC9C9C9);
|
||||||
|
graphics.renderOutline(x + 4, thumbY, 12, 15, 0xFF414141);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void drawPage(GuiGraphics graphics, int index, int x, int y) {
|
||||||
|
ItemStack page = menu.getSlot(index).getItem();
|
||||||
|
boolean dimmed = page.isEmpty() || !matchesSearch(page);
|
||||||
|
// Legacy's Notebook draws the atlas' native 30x40 page, not a stretched item icon.
|
||||||
|
graphics.blit(PAGE_ATLAS, x, y, PAGE_WIDTH, PAGE_HEIGHT,
|
||||||
|
156, 0, PAGE_WIDTH, PAGE_HEIGHT, 256, 256);
|
||||||
|
if (!page.isEmpty()) {
|
||||||
|
switch (PageItem.content(page).kind()) {
|
||||||
|
case BLANK -> { }
|
||||||
|
case LINK_PANEL -> graphics.fill(x + 5, y + 6, x + 25, y + 20, 0xFF000000);
|
||||||
|
case SYMBOL, UNRESOLVED_SYMBOL -> graphics.blit(symbolTexture(page), x + 1, y + 6,
|
||||||
|
28, 28, 16, 16, 96, 96, 128, 128);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (dimmed) {
|
||||||
|
graphics.fill(x, y, x + PAGE_WIDTH, y + PAGE_HEIGHT, 0xB8000000);
|
||||||
|
}
|
||||||
|
if (index == selectedSlot && !page.isEmpty()) {
|
||||||
|
graphics.renderOutline(x, y, PAGE_WIDTH, PAGE_HEIGHT, 0xFFFFD061);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static ResourceLocation symbolTexture(ItemStack page) {
|
||||||
|
var content = PageItem.content(page);
|
||||||
|
if (content.kind() == net.dnorberg.rivencraft.writing.PageContent.Kind.UNRESOLVED_SYMBOL) {
|
||||||
|
return UNRESOLVED_SYMBOL;
|
||||||
|
}
|
||||||
|
return symbolTexture(content.symbol().orElseThrow().id());
|
||||||
|
}
|
||||||
|
|
||||||
|
static ResourceLocation symbolTexture(ResourceLocation id) {
|
||||||
|
return switch (id.toString()) {
|
||||||
|
case "rivencraft:terrain/standard" -> STANDARD_TERRAIN;
|
||||||
|
case "rivencraft:biome/native" -> NATIVE_BIOMES;
|
||||||
|
case "rivencraft:lighting/normal" -> NORMAL_LIGHTING;
|
||||||
|
case "rivencraft:weather/normal" -> NORMAL_WEATHER;
|
||||||
|
case "rivencraft:celestial/normal_time" -> NORMAL_TIME;
|
||||||
|
case "rivencraft:feature/caves" -> CAVES;
|
||||||
|
default -> GENERIC_SYMBOL;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
private static ResourceLocation texture(String path) {
|
||||||
|
return ResourceLocation.fromNamespaceAndPath(Rivencraft.MOD_ID, "textures/" + path + ".png");
|
||||||
|
}
|
||||||
|
|
||||||
|
private void moveSelected(boolean next) {
|
||||||
|
int target = selectedSlot + (next ? 1 : -1);
|
||||||
|
if (selectedSlot < 0 || target < 0 || target >= NotebookMenu.NOTEBOOK_SLOTS
|
||||||
|
|| menu.getSlot(selectedSlot).getItem().isEmpty()) return;
|
||||||
|
int buttonId = (next ? NotebookMenu.MOVE_NEXT_BASE : NotebookMenu.MOVE_PREVIOUS_BASE) + selectedSlot;
|
||||||
|
if (menu.clickMenuButton(minecraft.player, buttonId)) {
|
||||||
|
minecraft.gameMode.handleInventoryButtonClick(menu.containerId, buttonId);
|
||||||
|
selectedSlot = target;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void drawBeveledPanel(GuiGraphics graphics, int x, int y, int width, int height) {
|
||||||
|
graphics.fill(x, y, x + width, y + height, 0xFFC6C6C6);
|
||||||
|
graphics.fill(x, y, x + width, y + 2, 0xFFFFFFFF);
|
||||||
|
graphics.fill(x, y, x + 2, y + height, 0xFFFFFFFF);
|
||||||
|
graphics.fill(x, y + height - 2, x + width, y + height, 0xFF555555);
|
||||||
|
graphics.fill(x + width - 2, y, x + width, y + height, 0xFF555555);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void drawSlot(GuiGraphics graphics, int x, int y) {
|
||||||
|
graphics.fill(leftPos + x, topPos + y, leftPos + x + 18, topPos + y + 18, 0xFF8B8B8B);
|
||||||
|
graphics.fill(leftPos + x, topPos + y, leftPos + x + 18, topPos + y + 1, 0xFF373737);
|
||||||
|
graphics.fill(leftPos + x, topPos + y, leftPos + x + 1, topPos + y + 18, 0xFF373737);
|
||||||
|
graphics.fill(leftPos + x + 17, topPos + y, leftPos + x + 18, topPos + y + 18, 0xFFFFFFFF);
|
||||||
|
graphics.fill(leftPos + x, topPos + y + 17, leftPos + x + 18, topPos + y + 18, 0xFFFFFFFF);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,450 @@
|
|||||||
|
package net.dnorberg.rivencraft.client.screen;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Locale;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Comparator;
|
||||||
|
import net.dnorberg.rivencraft.Rivencraft;
|
||||||
|
import net.dnorberg.rivencraft.item.PageItem;
|
||||||
|
import net.dnorberg.rivencraft.menu.WritingDeskMenu;
|
||||||
|
import net.dnorberg.rivencraft.block.entity.WritingDeskBlockEntity;
|
||||||
|
import net.dnorberg.rivencraft.registry.ModDataComponents;
|
||||||
|
import net.dnorberg.rivencraft.registry.ModItems;
|
||||||
|
import net.dnorberg.rivencraft.writing.NotebookContents;
|
||||||
|
import net.dnorberg.rivencraft.writing.SymbolDisplayMetadata;
|
||||||
|
import net.minecraft.client.gui.GuiGraphics;
|
||||||
|
import net.minecraft.client.gui.components.Button;
|
||||||
|
import net.minecraft.client.gui.components.EditBox;
|
||||||
|
import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen;
|
||||||
|
import net.minecraft.network.chat.Component;
|
||||||
|
import net.minecraft.resources.ResourceLocation;
|
||||||
|
import net.minecraft.world.entity.player.Inventory;
|
||||||
|
import net.minecraft.world.inventory.Slot;
|
||||||
|
import net.minecraft.world.item.ItemStack;
|
||||||
|
|
||||||
|
/** Legacy desk atlas layout, with four visible tabs out of the desk's 88 collections. */
|
||||||
|
public final class WritingDeskScreen extends AbstractContainerScreen<WritingDeskMenu> {
|
||||||
|
private static final ResourceLocation PAGE_ATLAS = ResourceLocation.fromNamespaceAndPath(
|
||||||
|
Rivencraft.MOD_ID, "textures/gui/notebook_pages.png");
|
||||||
|
private static final ResourceLocation LEGACY_DESK = ResourceLocation.fromNamespaceAndPath(
|
||||||
|
Rivencraft.MOD_ID, "textures/gui/writing_desk_legacy.png");
|
||||||
|
private static final ResourceLocation SCROLLBAR = ResourceLocation.fromNamespaceAndPath(
|
||||||
|
Rivencraft.MOD_ID, "textures/gui/scrollbar.png");
|
||||||
|
private int lastCollection = -1;
|
||||||
|
private int selectedPage;
|
||||||
|
private int scrollRows;
|
||||||
|
private boolean allMode;
|
||||||
|
private boolean sortAlphabetically;
|
||||||
|
private int selectedCollection = -1;
|
||||||
|
private ResourceLocation selectedCategory;
|
||||||
|
private EditBox search;
|
||||||
|
private Button categoryButton;
|
||||||
|
private Button allButton;
|
||||||
|
private Button sortButton;
|
||||||
|
private boolean draggingScrollbar;
|
||||||
|
private record DisplayPage(int collection, int index, ItemStack stack) {}
|
||||||
|
private DisplayPage pageDragSource;
|
||||||
|
private double pageDragStartX;
|
||||||
|
private double pageDragStartY;
|
||||||
|
private boolean draggingPage;
|
||||||
|
|
||||||
|
private boolean isPhysicalPageView() {
|
||||||
|
return !allMode && !sortAlphabetically && selectedCategory == null
|
||||||
|
&& (search == null || search.getValue().isBlank());
|
||||||
|
}
|
||||||
|
|
||||||
|
public WritingDeskScreen(WritingDeskMenu menu, Inventory inventory, Component title) {
|
||||||
|
super(menu, inventory, title);
|
||||||
|
imageWidth = 409;
|
||||||
|
imageHeight = 186;
|
||||||
|
titleLabelX = 222;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override protected void init() {
|
||||||
|
super.init();
|
||||||
|
sortButton = addRenderableWidget(Button.builder(Component.literal("AZ"), button -> {
|
||||||
|
sortAlphabetically = !sortAlphabetically;
|
||||||
|
scrollRows = 0;
|
||||||
|
}).bounds(leftPos + 58, topPos, 20, 18).build());
|
||||||
|
allButton = addRenderableWidget(Button.builder(Component.literal("ALL"), button -> {
|
||||||
|
allMode = !allMode;
|
||||||
|
scrollRows = 0;
|
||||||
|
if (!allMode) {
|
||||||
|
selectedCollection = -1;
|
||||||
|
selectedPage = 0;
|
||||||
|
if (minecraft != null && minecraft.gameMode != null)
|
||||||
|
minecraft.gameMode.handleInventoryButtonClick(menu.containerId, WritingDeskMenu.PAGE_BUTTON_BASE);
|
||||||
|
}
|
||||||
|
}).bounds(leftPos + 80, topPos, 28, 18).build());
|
||||||
|
search = new EditBox(font, leftPos + 110, topPos, 101, 18,
|
||||||
|
Component.translatable("screen.rivencraft.writing_desk.search"));
|
||||||
|
search.setMaxLength(64);
|
||||||
|
search.setHint(Component.translatable("screen.rivencraft.writing_desk.search"));
|
||||||
|
search.setResponder(value -> scrollRows = 0);
|
||||||
|
addRenderableWidget(search);
|
||||||
|
categoryButton = addRenderableWidget(Button.builder(Component.literal("C"), button -> {
|
||||||
|
List<ResourceLocation> categories = menu.catalog().stream()
|
||||||
|
.map(SymbolDisplayMetadata::category).distinct().sorted().toList();
|
||||||
|
int next = selectedCategory == null ? 0 : categories.indexOf(selectedCategory) + 1;
|
||||||
|
selectedCategory = next >= categories.size() ? null : categories.get(next);
|
||||||
|
categoryButton.setMessage(Component.literal(selectedCategory == null ? "C" : "C*"));
|
||||||
|
scrollRows = 0;
|
||||||
|
}).bounds(leftPos + 213, topPos, 18, 18).build());
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<DisplayPage> filteredPages() {
|
||||||
|
String query = search == null ? "" : search.getValue().trim().toLowerCase(Locale.ROOT);
|
||||||
|
List<DisplayPage> entries = new ArrayList<>();
|
||||||
|
int from = allMode ? 0 : menu.activeCollection();
|
||||||
|
int until = allMode ? WritingDeskBlockEntity.COLLECTIONS : from + 1;
|
||||||
|
for (int collection = from; collection < until; collection++) {
|
||||||
|
List<ItemStack> pages = pages(collection);
|
||||||
|
int last = -1;
|
||||||
|
for (int i = 0; i < pages.size(); i++) if (!pages.get(i).isEmpty()) last = i;
|
||||||
|
// A notebook has exactly its normal GUI capacity; a loose page has one position.
|
||||||
|
if (isPhysicalPageView()) last = menu.pageCapacity(collection) - 1;
|
||||||
|
for (int i = 0; i <= last; i++) {
|
||||||
|
ItemStack page = i < pages.size() ? pages.get(i) : ItemStack.EMPTY;
|
||||||
|
if (page.isEmpty() && (allMode || sortAlphabetically || !query.isEmpty() || selectedCategory != null)) continue;
|
||||||
|
if (!page.isEmpty() && !query.isEmpty()
|
||||||
|
&& !page.getHoverName().getString().toLowerCase(Locale.ROOT).contains(query)
|
||||||
|
&& !PageItem.content(page).symbol().map(symbol -> symbol.id().toString()
|
||||||
|
.toLowerCase(Locale.ROOT).contains(query)).orElse(false)) continue;
|
||||||
|
if (!page.isEmpty() && selectedCategory != null) {
|
||||||
|
ResourceLocation id = PageItem.content(page).symbol().map(symbol -> symbol.id()).orElse(null);
|
||||||
|
if (menu.catalog().stream().noneMatch(metadata -> metadata.id().equals(id)
|
||||||
|
&& metadata.category().equals(selectedCategory))) continue;
|
||||||
|
}
|
||||||
|
entries.add(new DisplayPage(collection, i, page));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (sortAlphabetically) entries.sort(Comparator
|
||||||
|
.comparing((DisplayPage entry) -> entry.stack().getHoverName().getString(), String.CASE_INSENSITIVE_ORDER)
|
||||||
|
.thenComparingInt(DisplayPage::collection).thenComparingInt(DisplayPage::index));
|
||||||
|
return entries;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override public void renderBackground(GuiGraphics graphics, int mouseX, int mouseY, float partialTick) {
|
||||||
|
// Keep the world visible, but still draw our GUI backing. The vanilla
|
||||||
|
// container implementation normally calls renderBg from this method.
|
||||||
|
renderBg(graphics, partialTick, mouseX, mouseY);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override protected void renderBg(GuiGraphics graphics, float partialTick, int mouseX, int mouseY) {
|
||||||
|
int x = leftPos;
|
||||||
|
int y = topPos;
|
||||||
|
// Legacy GuiWritingDesk draws the entire 176x166 panel, not a stretched swatch.
|
||||||
|
graphics.blit(LEGACY_DESK, x + 233, y + 20, 0, 0, 176, 166);
|
||||||
|
drawTabControl(graphics, 20, 203, menu.firstVisibleTab() > 0);
|
||||||
|
for (int i = 0; i < 4; i++) {
|
||||||
|
int tab = menu.firstVisibleTab() + i;
|
||||||
|
int tabY = y + 29 + i * 37;
|
||||||
|
if (tab == menu.activeCollection() && !allMode) graphics.setColor(0.5F, 0.5F, 1F, 1F);
|
||||||
|
graphics.blit(LEGACY_DESK, x, tabY, 0, 166, 58, 37);
|
||||||
|
graphics.setColor(1F, 1F, 1F, 1F);
|
||||||
|
graphics.drawString(font, Integer.toString(tab + 1), x + 8, tabY + 8, 0xFF181818, false);
|
||||||
|
ItemStack collection = menu.getSlot(tab).getItem();
|
||||||
|
if (!collection.isEmpty()) {
|
||||||
|
String name = collection.getHoverName().getString();
|
||||||
|
float scale = Math.min(1F, 50F / Math.max(1, font.width(name)));
|
||||||
|
graphics.pose().pushPose();
|
||||||
|
graphics.pose().translate(x + 4, tabY + 25, 0);
|
||||||
|
graphics.pose().scale(scale, scale, 1);
|
||||||
|
graphics.drawString(font, name, 0, 0, 0xFF404040, false);
|
||||||
|
graphics.pose().popPose();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
drawTabControl(graphics, 177, 212, menu.firstVisibleTab() < WritingDeskBlockEntity.COLLECTIONS - 4);
|
||||||
|
// GuiElementVSlider: 4-pixel caps, repeated 22-pixel track, 12x15 thumb.
|
||||||
|
graphics.blit(SCROLLBAR, x + 213, y + 20, 0, 0, 20, 4, 32, 32);
|
||||||
|
for (int offset = 4; offset < 162; offset += 22)
|
||||||
|
graphics.blit(SCROLLBAR, x + 213, y + 20 + offset, 0, 4, 20, Math.min(22, 162 - offset), 32, 32);
|
||||||
|
graphics.blit(SCROLLBAR, x + 213, y + 182, 0, 26, 20, 4, 32, 32);
|
||||||
|
int totalRows = (filteredPages().size() + 4) / 5;
|
||||||
|
int maxScroll = Math.max(0, totalRows - 4);
|
||||||
|
scrollRows = Math.clamp(scrollRows, 0, maxScroll);
|
||||||
|
int thumbY = y + 24 + (maxScroll == 0 ? 0 : scrollRows * 143 / maxScroll);
|
||||||
|
graphics.blit(SCROLLBAR, x + 217, thumbY, 20, draggingScrollbar ? 15 : 0, 12, 15, 32, 32);
|
||||||
|
graphics.fill(x + 365, y + 27, x + 381, y + 97, 0xFF303035);
|
||||||
|
graphics.fill(x + 366, y + 28, x + 380, y + 96, 0xFF6666AA);
|
||||||
|
int filled = 68 * menu.inkRemaining() / 16;
|
||||||
|
if (filled > 0) graphics.fill(x + 366, y + 96 - filled, x + 380, y + 96, 0xFF15151B);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void drawTabControl(GuiGraphics graphics, int y, int textureY, boolean enabled) {
|
||||||
|
if (!enabled) graphics.setColor(0.4F, 0.4F, 0.4F, 1F);
|
||||||
|
graphics.blit(LEGACY_DESK, leftPos, topPos + y, 0, textureY, 58, 9);
|
||||||
|
graphics.setColor(1F, 1F, 1F, 1F);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override protected void renderLabels(GuiGraphics graphics, int mouseX, int mouseY) {
|
||||||
|
// Legacy leaves the inventory grid unlabeled.
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override public void render(GuiGraphics graphics, int mouseX, int mouseY, float partialTick) {
|
||||||
|
super.render(graphics, mouseX, mouseY, partialTick);
|
||||||
|
if (sortAlphabetically) graphics.renderOutline(leftPos + 58, topPos, 20, 18, 0xFFFFD061);
|
||||||
|
if (allMode) graphics.renderOutline(leftPos + 80, topPos, 28, 18, 0xFFFFD061);
|
||||||
|
renderCollection(graphics);
|
||||||
|
if (draggingPage && pageDragSource != null) {
|
||||||
|
DisplayPage target = pageAtMouse(mouseX, mouseY);
|
||||||
|
if (target != null && canMovePage(pageDragSource, target)) {
|
||||||
|
int x = leftPos + 58 + ((int) mouseX - leftPos - 58) / 31 * 31;
|
||||||
|
int y = topPos + 20 + ((int) mouseY - topPos - 20) / 41 * 41;
|
||||||
|
graphics.renderOutline(x, y, 30, 40, 0xFF57D478);
|
||||||
|
}
|
||||||
|
graphics.renderItem(pageDragSource.stack(), mouseX - 8, mouseY - 8);
|
||||||
|
}
|
||||||
|
renderTooltip(graphics, mouseX, mouseY);
|
||||||
|
if (mouseX >= leftPos + 365 && mouseX < leftPos + 381
|
||||||
|
&& mouseY >= topPos + 27 && mouseY < topPos + 97) {
|
||||||
|
graphics.renderTooltip(font, Component.translatable("screen.rivencraft.writing_desk.ink",
|
||||||
|
menu.inkRemaining(), 16), mouseX, mouseY);
|
||||||
|
}
|
||||||
|
if (mouseX >= leftPos + 213 && mouseX < leftPos + 231
|
||||||
|
&& mouseY >= topPos && mouseY < topPos + 18) {
|
||||||
|
graphics.renderTooltip(font, Component.literal(selectedCategory == null
|
||||||
|
? "All categories" : selectedCategory.toString()), mouseX, mouseY);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<ItemStack> pages(int collectionIndex) {
|
||||||
|
ItemStack collection = menu.getSlot(collectionIndex).getItem();
|
||||||
|
if (collection.is(ModItems.PAGE.get())) return List.of(collection);
|
||||||
|
if (collection.is(ModItems.NOTEBOOK.get())) {
|
||||||
|
return collection.getOrDefault(ModDataComponents.NOTEBOOK_CONTENTS.get(), NotebookContents.EMPTY).pages();
|
||||||
|
}
|
||||||
|
return List.of();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void renderCollection(GuiGraphics graphics) {
|
||||||
|
if (lastCollection != menu.activeCollection()) {
|
||||||
|
lastCollection = menu.activeCollection();
|
||||||
|
scrollRows = 0;
|
||||||
|
selectedPage = 0;
|
||||||
|
selectedCollection = -1;
|
||||||
|
}
|
||||||
|
List<DisplayPage> entries = filteredPages();
|
||||||
|
for (int i = scrollRows * 5; i < entries.size() && i < scrollRows * 5 + 20; i++) {
|
||||||
|
int column = i % 5;
|
||||||
|
int row = i / 5 - scrollRows;
|
||||||
|
DisplayPage entry = entries.get(i);
|
||||||
|
ItemStack page = entry.stack();
|
||||||
|
int x = leftPos + 58 + column * 31;
|
||||||
|
int y = topPos + 20 + row * 41;
|
||||||
|
drawPage(graphics, page, x, y);
|
||||||
|
if (page.isEmpty()) graphics.fill(x, y, x + 30, y + 40, 0xB8000000);
|
||||||
|
int active = selectedCollection >= 0 ? selectedCollection : menu.activeCollection();
|
||||||
|
if (entry.collection() == active && entry.index() == selectedPage && !page.isEmpty())
|
||||||
|
graphics.renderOutline(x, y, 30, 40, 0xFFFFD061);
|
||||||
|
}
|
||||||
|
int active = selectedCollection >= 0 ? selectedCollection : menu.activeCollection();
|
||||||
|
List<ItemStack> source = pages(active);
|
||||||
|
if (selectedPage >= source.size() || source.get(selectedPage).isEmpty()) return;
|
||||||
|
ItemStack selected = source.get(selectedPage);
|
||||||
|
drawPage(graphics, selected, leftPos + 265, topPos + 26);
|
||||||
|
String title = font.plainSubstrByWidth(selected.getHoverName().getString(), 95);
|
||||||
|
graphics.fill(leftPos + 261, topPos + 81, leftPos + 360, topPos + 95, 0xFF202020);
|
||||||
|
graphics.drawString(font, title, leftPos + 263, topPos + 84, 0xFFE0E0E0, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void drawPage(GuiGraphics graphics, ItemStack page, int x, int y) {
|
||||||
|
graphics.blit(PAGE_ATLAS, x, y, 30, 40, 156, 0, 30, 40, 256, 256);
|
||||||
|
if (page.isEmpty()) return;
|
||||||
|
switch (PageItem.content(page).kind()) {
|
||||||
|
case BLANK -> { }
|
||||||
|
case LINK_PANEL -> graphics.fill(x + 5, y + 6, x + 25, y + 20, 0xFF000000);
|
||||||
|
case SYMBOL, UNRESOLVED_SYMBOL -> graphics.blit(NotebookScreen.symbolTexture(page), x + 1, y + 6,
|
||||||
|
28, 28, 16, 16, 96, 96, 128, 128);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private DisplayPage pageAtMouse(double mouseX, double mouseY) {
|
||||||
|
int x = (int) Math.floor(mouseX - leftPos - 58);
|
||||||
|
int y = (int) Math.floor(mouseY - topPos - 20);
|
||||||
|
if (x < 0 || x >= 155 || y < 0 || y >= 164 || x % 31 >= 30 || y % 41 >= 40) return null;
|
||||||
|
int index = (y / 41 + scrollRows) * 5 + x / 31;
|
||||||
|
List<DisplayPage> entries = filteredPages();
|
||||||
|
return index < entries.size() ? entries.get(index) : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean canMovePage(DisplayPage source, DisplayPage target) {
|
||||||
|
return !source.stack().isEmpty()
|
||||||
|
&& (menu.getSlot(source.collection()).getItem().is(ModItems.NOTEBOOK.get())
|
||||||
|
|| menu.getSlot(source.collection()).getItem().is(ModItems.PAGE.get()))
|
||||||
|
&& (menu.getSlot(target.collection()).getItem().is(ModItems.NOTEBOOK.get())
|
||||||
|
|| menu.getSlot(target.collection()).getItem().is(ModItems.PAGE.get()))
|
||||||
|
&& (source.collection() != target.collection() || source.index() != target.index());
|
||||||
|
}
|
||||||
|
|
||||||
|
private int extractTargetSlot(double mouseX, double mouseY) {
|
||||||
|
for (Slot slot : menu.slots) {
|
||||||
|
int index = slot.index;
|
||||||
|
if (index >= WritingDeskBlockEntity.COLLECTIONS && index <= WritingDeskMenu.COPY_RESULT) continue;
|
||||||
|
if (!slot.isActive() || !isHovering(slot.x, slot.y, 16, 16, mouseX, mouseY)) continue;
|
||||||
|
ItemStack held = pageDragSource.stack();
|
||||||
|
if (!slot.mayPlace(held)) return -1;
|
||||||
|
ItemStack current = slot.getItem();
|
||||||
|
if (current.isEmpty()) return index;
|
||||||
|
if (index < WritingDeskBlockEntity.COLLECTIONS && current.is(ModItems.NOTEBOOK.get())) {
|
||||||
|
List<ItemStack> pages = current.getOrDefault(
|
||||||
|
ModDataComponents.NOTEBOOK_CONTENTS.get(), NotebookContents.EMPTY).pages();
|
||||||
|
if (pages.size() < NotebookContents.MAX_PAGES || pages.stream().anyMatch(ItemStack::isEmpty))
|
||||||
|
return index;
|
||||||
|
} else if (index > WritingDeskMenu.COPY_RESULT && ItemStack.isSameItemSameComponents(current, held)
|
||||||
|
&& current.getCount() < slot.getMaxStackSize(held)) return index;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override public boolean mouseClicked(double mouseX, double mouseY, int button) {
|
||||||
|
if (button == 0) {
|
||||||
|
pageDragSource = null;
|
||||||
|
draggingPage = false;
|
||||||
|
}
|
||||||
|
int surfaceX = (int) Math.floor(mouseX - leftPos - 58);
|
||||||
|
int surfaceY = (int) Math.floor(mouseY - topPos - 20);
|
||||||
|
if ((button == 0 || button == 1) && !menu.getCarried().isEmpty()
|
||||||
|
&& surfaceX >= 0 && surfaceX < 155 && surfaceY >= 0 && surfaceY < 164) {
|
||||||
|
if (menu.getCarried().is(ModItems.PAGE.get()) && surfaceX % 31 < 30 && surfaceY % 41 < 40) {
|
||||||
|
int index = (surfaceY / 41 + scrollRows) * 5 + surfaceX / 31;
|
||||||
|
List<DisplayPage> entries = filteredPages();
|
||||||
|
// Only displayed positions are addressable. Filtering never turns
|
||||||
|
// empty screen space into additional storage for a loose-page tab.
|
||||||
|
int collection = index < entries.size() ? entries.get(index).collection() : menu.activeCollection();
|
||||||
|
int page = index < entries.size() ? entries.get(index).index() : index;
|
||||||
|
if (index < entries.size() && page < menu.pageCapacity(collection)
|
||||||
|
&& minecraft != null && minecraft.gameMode != null) {
|
||||||
|
minecraft.gameMode.handleInventoryButtonClick(menu.containerId,
|
||||||
|
WritingDeskMenu.PLACE_PAGE_BUTTON_BASE + collection * NotebookContents.MAX_PAGES + page);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (button == 0) {
|
||||||
|
if (mouseX >= leftPos && mouseX < leftPos + 58) {
|
||||||
|
int y = (int) mouseY - topPos;
|
||||||
|
if (y >= 20 && y < 29 || y >= 177 && y < 186) {
|
||||||
|
if (minecraft != null && minecraft.gameMode != null)
|
||||||
|
minecraft.gameMode.handleInventoryButtonClick(menu.containerId,
|
||||||
|
y < 29 ? WritingDeskMenu.PREVIOUS_TABS : WritingDeskMenu.NEXT_TABS);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (mouseX >= leftPos + 213 && mouseX < leftPos + 233
|
||||||
|
&& mouseY >= topPos + 20 && mouseY < topPos + 186) {
|
||||||
|
draggingScrollbar = true;
|
||||||
|
setScrollFromMouse(mouseY);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
int x = (int) Math.floor(mouseX - leftPos - 58);
|
||||||
|
int y = (int) Math.floor(mouseY - topPos - 20);
|
||||||
|
if (x >= 0 && x < 155 && y >= 0 && y < 164) {
|
||||||
|
DisplayPage entry = pageAtMouse(mouseX, mouseY);
|
||||||
|
if (entry != null && !entry.stack().isEmpty()) {
|
||||||
|
selectedCollection = entry.collection();
|
||||||
|
selectedPage = entry.index();
|
||||||
|
if (menu.getCarried().isEmpty()) {
|
||||||
|
pageDragSource = entry;
|
||||||
|
pageDragStartX = mouseX;
|
||||||
|
pageDragStartY = mouseY;
|
||||||
|
}
|
||||||
|
if (minecraft != null && minecraft.gameMode != null) {
|
||||||
|
int id = WritingDeskMenu.ALL_PAGE_BUTTON_BASE
|
||||||
|
+ entry.collection() * NotebookContents.MAX_PAGES + entry.index();
|
||||||
|
minecraft.gameMode.handleInventoryButtonClick(menu.containerId, id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (button == 0 && mouseX >= leftPos && mouseX < leftPos + 58) {
|
||||||
|
for (int i = 0; i < 4; i++) {
|
||||||
|
int top = topPos + 29 + i * 37;
|
||||||
|
boolean overSlot = mouseX >= leftPos + 36 && mouseX < leftPos + 54
|
||||||
|
&& mouseY >= top + 4 && mouseY < top + 22;
|
||||||
|
if (mouseY >= top && mouseY < top + 37 && !overSlot) {
|
||||||
|
allMode = false;
|
||||||
|
selectedCollection = -1;
|
||||||
|
if (minecraft != null && minecraft.gameMode != null) {
|
||||||
|
minecraft.gameMode.handleInventoryButtonClick(menu.containerId, menu.firstVisibleTab() + i);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return super.mouseClicked(mouseX, mouseY, button);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override public boolean mouseScrolled(double mouseX, double mouseY, double scrollX, double scrollY) {
|
||||||
|
if (mouseX >= leftPos + 58 && mouseX < leftPos + 233
|
||||||
|
&& mouseY >= topPos + 20 && mouseY < topPos + 186) {
|
||||||
|
int rows = (filteredPages().size() + 4) / 5;
|
||||||
|
scrollRows = Math.clamp(scrollRows - (int) Math.signum(scrollY), 0, Math.max(0, rows - 4));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return super.mouseScrolled(mouseX, mouseY, scrollX, scrollY);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setScrollFromMouse(double mouseY) {
|
||||||
|
int rows = (filteredPages().size() + 4) / 5;
|
||||||
|
int max = Math.max(0, rows - 4);
|
||||||
|
scrollRows = Math.clamp((int) Math.round((mouseY - topPos - 31.5) * max / 143.0), 0, max);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override public boolean mouseDragged(double mouseX, double mouseY, int button, double dragX, double dragY) {
|
||||||
|
if (button == 0 && pageDragSource != null) {
|
||||||
|
if (Math.abs(mouseX - pageDragStartX) >= 4 || Math.abs(mouseY - pageDragStartY) >= 4)
|
||||||
|
draggingPage = true;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (button == 0 && draggingScrollbar) {
|
||||||
|
setScrollFromMouse(mouseY);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return super.mouseDragged(mouseX, mouseY, button, dragX, dragY);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override public boolean mouseReleased(double mouseX, double mouseY, int button) {
|
||||||
|
if (button == 0 && pageDragSource != null) {
|
||||||
|
if (draggingPage) {
|
||||||
|
DisplayPage target = pageAtMouse(mouseX, mouseY);
|
||||||
|
if (target != null && canMovePage(pageDragSource, target)
|
||||||
|
&& minecraft != null && minecraft.gameMode != null) {
|
||||||
|
selectedCollection = target.collection();
|
||||||
|
selectedPage = target.index();
|
||||||
|
minecraft.gameMode.handleInventoryButtonClick(menu.containerId,
|
||||||
|
WritingDeskMenu.movePageButtonId(pageDragSource.collection(), pageDragSource.index(),
|
||||||
|
target.collection(), target.index()));
|
||||||
|
} else if (target == null && minecraft != null && minecraft.gameMode != null) {
|
||||||
|
int targetSlot = extractTargetSlot(mouseX, mouseY);
|
||||||
|
minecraft.gameMode.handleInventoryButtonClick(menu.containerId,
|
||||||
|
WritingDeskMenu.extractPageButtonId(pageDragSource.collection(), pageDragSource.index(),
|
||||||
|
targetSlot));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
pageDragSource = null;
|
||||||
|
draggingPage = false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (button == 0 && draggingScrollbar) {
|
||||||
|
draggingScrollbar = false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return super.mouseReleased(mouseX, mouseY, button);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override public boolean keyPressed(int keyCode, int scanCode, int modifiers) {
|
||||||
|
if (search != null && search.isFocused()) {
|
||||||
|
if (keyCode == 256) {
|
||||||
|
setFocused(null);
|
||||||
|
search.setFocused(false);
|
||||||
|
} else {
|
||||||
|
search.keyPressed(keyCode, scanCode, modifiers);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return super.keyPressed(keyCode, scanCode, modifiers);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
package net.dnorberg.rivencraft.compat;
|
||||||
|
|
||||||
|
import net.dnorberg.rivencraft.config.RivencraftClientConfig;
|
||||||
|
|
||||||
|
/** Pure selection policy for optional destination preview integrations. */
|
||||||
|
public final class PreviewBackendSelector {
|
||||||
|
public enum Backend {
|
||||||
|
IMMERSIVE_PORTALS,
|
||||||
|
PONDER,
|
||||||
|
LEGACY
|
||||||
|
}
|
||||||
|
|
||||||
|
private PreviewBackendSelector() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Backend select(
|
||||||
|
RivencraftClientConfig.PreviewMode mode,
|
||||||
|
boolean immersivePortalsAvailable,
|
||||||
|
boolean ponderAvailable
|
||||||
|
) {
|
||||||
|
return switch (mode) {
|
||||||
|
case AUTO -> immersivePortalsAvailable
|
||||||
|
? Backend.IMMERSIVE_PORTALS
|
||||||
|
: ponderAvailable ? Backend.PONDER : Backend.LEGACY;
|
||||||
|
case IMMERSIVE_PORTALS -> immersivePortalsAvailable ? Backend.IMMERSIVE_PORTALS : Backend.LEGACY;
|
||||||
|
case PONDER -> ponderAvailable ? Backend.PONDER : Backend.LEGACY;
|
||||||
|
case LEGACY -> Backend.LEGACY;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -15,6 +15,8 @@ public final class RivencraftConfig {
|
|||||||
|
|
||||||
public static final ModConfigSpec SPEC;
|
public static final ModConfigSpec SPEC;
|
||||||
private static final ModConfigSpec.EnumValue<ReturnLinkMode> RETURN_LINK_MODE;
|
private static final ModConfigSpec.EnumValue<ReturnLinkMode> RETURN_LINK_MODE;
|
||||||
|
private static final ModConfigSpec.IntValue SYMBOL_INK_COST;
|
||||||
|
private static final ModConfigSpec.IntValue LINK_PANEL_INK_COST;
|
||||||
|
|
||||||
static {
|
static {
|
||||||
ModConfigSpec.Builder builder = new ModConfigSpec.Builder();
|
ModConfigSpec.Builder builder = new ModConfigSpec.Builder();
|
||||||
@@ -25,6 +27,12 @@ public final class RivencraftConfig {
|
|||||||
)
|
)
|
||||||
.defineEnum("return_link_mode", ReturnLinkMode.ON_CREATION);
|
.defineEnum("return_link_mode", ReturnLinkMode.ON_CREATION);
|
||||||
builder.pop();
|
builder.pop();
|
||||||
|
builder.push("writing");
|
||||||
|
SYMBOL_INK_COST = builder.comment("Ink units consumed when the Writing Desk copies one symbol page.")
|
||||||
|
.defineInRange("symbol_ink_cost", 1, 1, 16);
|
||||||
|
LINK_PANEL_INK_COST = builder.comment("Ink units consumed when preparing one baseline link-panel page.")
|
||||||
|
.defineInRange("link_panel_ink_cost", 2, 1, 16);
|
||||||
|
builder.pop();
|
||||||
SPEC = builder.build();
|
SPEC = builder.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -34,4 +42,12 @@ public final class RivencraftConfig {
|
|||||||
public static ReturnLinkMode returnLinkMode() {
|
public static ReturnLinkMode returnLinkMode() {
|
||||||
return RETURN_LINK_MODE.get();
|
return RETURN_LINK_MODE.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static int symbolInkCost() {
|
||||||
|
return SYMBOL_INK_COST.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int linkPanelInkCost() {
|
||||||
|
return LINK_PANEL_INK_COST.get();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -12,6 +12,8 @@ import net.dnorberg.rivencraft.book.LinkTarget;
|
|||||||
import net.dnorberg.rivencraft.book.LinkingService;
|
import net.dnorberg.rivencraft.book.LinkingService;
|
||||||
import net.dnorberg.rivencraft.book.AgeVisitSavedData;
|
import net.dnorberg.rivencraft.book.AgeVisitSavedData;
|
||||||
import net.dnorberg.rivencraft.book.AgeTraits;
|
import net.dnorberg.rivencraft.book.AgeTraits;
|
||||||
|
import net.dnorberg.rivencraft.compat.PreviewBackendSelector;
|
||||||
|
import net.dnorberg.rivencraft.config.RivencraftClientConfig;
|
||||||
import net.dnorberg.rivencraft.item.DescriptiveBookItem;
|
import net.dnorberg.rivencraft.item.DescriptiveBookItem;
|
||||||
import net.dnorberg.rivencraft.item.LinkingBookItem;
|
import net.dnorberg.rivencraft.item.LinkingBookItem;
|
||||||
import net.dnorberg.rivencraft.registry.ModDataComponents;
|
import net.dnorberg.rivencraft.registry.ModDataComponents;
|
||||||
@@ -40,6 +42,53 @@ public final class LinkingGameTests {
|
|||||||
private LinkingGameTests() {
|
private LinkingGameTests() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@GameTest(template = "empty")
|
||||||
|
public static void previewBackendSelectionCoversOptionalDependencyMatrix(GameTestHelper helper) {
|
||||||
|
assertPreviewBackend(helper, RivencraftClientConfig.PreviewMode.AUTO, true, true,
|
||||||
|
PreviewBackendSelector.Backend.IMMERSIVE_PORTALS);
|
||||||
|
assertPreviewBackend(helper, RivencraftClientConfig.PreviewMode.AUTO, true, false,
|
||||||
|
PreviewBackendSelector.Backend.IMMERSIVE_PORTALS);
|
||||||
|
assertPreviewBackend(helper, RivencraftClientConfig.PreviewMode.AUTO, false, true,
|
||||||
|
PreviewBackendSelector.Backend.PONDER);
|
||||||
|
assertPreviewBackend(helper, RivencraftClientConfig.PreviewMode.AUTO, false, false,
|
||||||
|
PreviewBackendSelector.Backend.LEGACY);
|
||||||
|
|
||||||
|
for (boolean ponderAvailable : new boolean[] {false, true}) {
|
||||||
|
assertPreviewBackend(helper, RivencraftClientConfig.PreviewMode.IMMERSIVE_PORTALS, true,
|
||||||
|
ponderAvailable, PreviewBackendSelector.Backend.IMMERSIVE_PORTALS);
|
||||||
|
assertPreviewBackend(helper, RivencraftClientConfig.PreviewMode.IMMERSIVE_PORTALS, false,
|
||||||
|
ponderAvailable, PreviewBackendSelector.Backend.LEGACY);
|
||||||
|
}
|
||||||
|
for (boolean immersivePortalsAvailable : new boolean[] {false, true}) {
|
||||||
|
assertPreviewBackend(helper, RivencraftClientConfig.PreviewMode.PONDER,
|
||||||
|
immersivePortalsAvailable, true, PreviewBackendSelector.Backend.PONDER);
|
||||||
|
assertPreviewBackend(helper, RivencraftClientConfig.PreviewMode.PONDER,
|
||||||
|
immersivePortalsAvailable, false, PreviewBackendSelector.Backend.LEGACY);
|
||||||
|
}
|
||||||
|
for (boolean immersivePortalsAvailable : new boolean[] {false, true}) {
|
||||||
|
for (boolean ponderAvailable : new boolean[] {false, true}) {
|
||||||
|
assertPreviewBackend(helper, RivencraftClientConfig.PreviewMode.LEGACY,
|
||||||
|
immersivePortalsAvailable, ponderAvailable, PreviewBackendSelector.Backend.LEGACY);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
helper.succeed();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void assertPreviewBackend(
|
||||||
|
GameTestHelper helper,
|
||||||
|
RivencraftClientConfig.PreviewMode mode,
|
||||||
|
boolean immersivePortalsAvailable,
|
||||||
|
boolean ponderAvailable,
|
||||||
|
PreviewBackendSelector.Backend expected
|
||||||
|
) {
|
||||||
|
helper.assertValueEqual(
|
||||||
|
PreviewBackendSelector.select(mode, immersivePortalsAvailable, ponderAvailable),
|
||||||
|
expected,
|
||||||
|
mode + " selection with Immersive Portals=" + immersivePortalsAvailable
|
||||||
|
+ " and Ponder=" + ponderAvailable
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
@GameTest(template = "empty")
|
@GameTest(template = "empty")
|
||||||
public static void dataPackAgeProfilesResolveRegisteredResources(GameTestHelper helper) {
|
public static void dataPackAgeProfilesResolveRegisteredResources(GameTestHelper helper) {
|
||||||
var registries = helper.getLevel().registryAccess();
|
var registries = helper.getLevel().registryAccess();
|
||||||
@@ -192,6 +241,78 @@ public final class LinkingGameTests {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@GameTest(template = "empty", timeoutTicks = 400)
|
||||||
|
public static void everyTerrainProfileProvidesSafeArrivalAndReturnTravel(GameTestHelper helper) {
|
||||||
|
ServerPlayer player = helper.makeMockServerPlayerInLevel();
|
||||||
|
BlockPos returnPosition = player.blockPosition();
|
||||||
|
helper.getLevel().setBlock(returnPosition.below(), Blocks.STONE.defaultBlockState(), 2);
|
||||||
|
helper.getLevel().setBlock(returnPosition, Blocks.AIR.defaultBlockState(), 2);
|
||||||
|
helper.getLevel().setBlock(returnPosition.above(), Blocks.AIR.defaultBlockState(), 2);
|
||||||
|
LinkTarget returnTarget = new LinkTarget(
|
||||||
|
GlobalPos.of(helper.getLevel().dimension(), returnPosition),
|
||||||
|
player.getYRot(),
|
||||||
|
player.getXRot()
|
||||||
|
);
|
||||||
|
long worldSeed = helper.getLevel().getServer().overworld().getSeed();
|
||||||
|
runTerrainProfileTravel(helper, player, returnTarget, AgeGenerationProfiles.all(), 0, worldSeed);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void runTerrainProfileTravel(
|
||||||
|
GameTestHelper helper,
|
||||||
|
ServerPlayer player,
|
||||||
|
LinkTarget returnTarget,
|
||||||
|
java.util.List<net.minecraft.resources.ResourceLocation> profiles,
|
||||||
|
int index,
|
||||||
|
long worldSeed
|
||||||
|
) {
|
||||||
|
if (index >= profiles.size()) {
|
||||||
|
helper.succeed();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var profile = profiles.get(index);
|
||||||
|
AgeReference reference = referenceSelectingProfile(profile, worldSeed);
|
||||||
|
LinkTarget destination = AgeDimensionService.resolve(player, reference).orElse(null);
|
||||||
|
helper.assertTrue(destination != null, profile + " must create a destination");
|
||||||
|
if (destination == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
helper.runAfterDelay(1, () -> {
|
||||||
|
AgeDefinition definition = AgeRegistrySavedData.get(helper.getLevel()).find(reference.id()).orElseThrow();
|
||||||
|
helper.assertValueEqual(definition.generationProfile(), profile,
|
||||||
|
"The acceptance fixture must select " + profile);
|
||||||
|
var ageLevel = player.getServer().getLevel(destination.location().dimension());
|
||||||
|
helper.assertTrue(ageLevel != null, profile + " must create a loaded runtime dimension");
|
||||||
|
BlockPos spawn = destination.location().pos();
|
||||||
|
helper.assertTrue(ageLevel != null && ageLevel.getBlockState(spawn.below()).is(Blocks.COBBLESTONE),
|
||||||
|
profile + " must create a solid arrival platform");
|
||||||
|
helper.assertTrue(ageLevel != null && ageLevel.getBlockState(spawn).isAir()
|
||||||
|
&& ageLevel.getBlockState(spawn.above()).isAir(),
|
||||||
|
profile + " must create clear arrival headroom");
|
||||||
|
helper.assertValueEqual(LinkingService.travelWithFooting(player, destination),
|
||||||
|
LinkingService.LinkResult.SUCCESS, profile + " must accept safe inbound travel");
|
||||||
|
helper.assertValueEqual(LinkingService.travel(player, returnTarget),
|
||||||
|
LinkingService.LinkResult.SUCCESS, profile + " must permit return travel");
|
||||||
|
helper.runAfterDelay(1, () -> runTerrainProfileTravel(
|
||||||
|
helper, player, returnTarget, profiles, index + 1, worldSeed));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private static AgeReference referenceSelectingProfile(
|
||||||
|
net.minecraft.resources.ResourceLocation profile,
|
||||||
|
long worldSeed
|
||||||
|
) {
|
||||||
|
UUID id = UUID.randomUUID();
|
||||||
|
for (int candidate = 0; candidate < 100_000; candidate++) {
|
||||||
|
String name = "Profile Acceptance " + profile.getPath() + " " + id + " " + candidate;
|
||||||
|
var dimension = AgeDefinition.namedDimensionId(name);
|
||||||
|
long seed = worldSeed + dimension.hashCode();
|
||||||
|
if (AgeRuntimeProfiles.select(seed).equals(profile)) {
|
||||||
|
return new AgeReference(id, name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
throw new IllegalStateException("Could not select profile " + profile);
|
||||||
|
}
|
||||||
|
|
||||||
@GameTest(template = "empty", timeoutTicks = 100)
|
@GameTest(template = "empty", timeoutTicks = 100)
|
||||||
public static void unloadedAgeReloadsWithTheSameDefinition(GameTestHelper helper) {
|
public static void unloadedAgeReloadsWithTheSameDefinition(GameTestHelper helper) {
|
||||||
UUID id = UUID.randomUUID();
|
UUID id = UUID.randomUUID();
|
||||||
@@ -480,7 +601,9 @@ public final class LinkingGameTests {
|
|||||||
}
|
}
|
||||||
helper.assertTrue(level.getChunkSource().getGenerator().getBiomeSource().possibleBiomes().stream().allMatch(holder -> holder.is(biome)),
|
helper.assertTrue(level.getChunkSource().getGenerator().getBiomeSource().possibleBiomes().stream().allMatch(holder -> holder.is(biome)),
|
||||||
"The material test Age must select " + biome.location());
|
"The material test Age must select " + biome.location());
|
||||||
// Sample away from the generated arrival platform around the Age spawn.
|
// Sample away from the generated arrival platform. Vanilla surface rules
|
||||||
|
// can place a shallow local patch such as gravel over the biome's base block.
|
||||||
|
boolean foundExpectedSurface = false;
|
||||||
int sampleX = 64;
|
int sampleX = 64;
|
||||||
int sampleZ = 64;
|
int sampleZ = 64;
|
||||||
level.getChunk(sampleX >> 4, sampleZ >> 4);
|
level.getChunk(sampleX >> 4, sampleZ >> 4);
|
||||||
@@ -489,10 +612,15 @@ public final class LinkingGameTests {
|
|||||||
sampleX,
|
sampleX,
|
||||||
sampleZ
|
sampleZ
|
||||||
) - 1;
|
) - 1;
|
||||||
var surfaceState = level.getBlockState(new BlockPos(sampleX, surfaceY, sampleZ));
|
for (int depth = 0; depth <= 8; depth++) {
|
||||||
helper.assertTrue(surfaceState.is(expectedBlock),
|
if (level.getBlockState(new BlockPos(sampleX, surfaceY - depth, sampleZ)).is(expectedBlock)) {
|
||||||
|
foundExpectedSurface = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
helper.assertTrue(foundExpectedSurface,
|
||||||
biome.location() + " terrain must expose " + expectedBlock.getDescriptionId()
|
biome.location() + " terrain must expose " + expectedBlock.getDescriptionId()
|
||||||
+ " at the surface, found " + surfaceState);
|
+ " across the sampled surface");
|
||||||
}
|
}
|
||||||
|
|
||||||
@GameTest(template = "empty")
|
@GameTest(template = "empty")
|
||||||
|
|||||||
@@ -0,0 +1,321 @@
|
|||||||
|
package net.dnorberg.rivencraft.gametest;
|
||||||
|
|
||||||
|
import com.mojang.serialization.JsonOps;
|
||||||
|
import io.netty.buffer.Unpooled;
|
||||||
|
import java.util.List;
|
||||||
|
import net.dnorberg.rivencraft.Rivencraft;
|
||||||
|
import net.dnorberg.rivencraft.writing.OrderedWriting;
|
||||||
|
import net.dnorberg.rivencraft.writing.PageContent;
|
||||||
|
import net.dnorberg.rivencraft.writing.SymbolCatalog;
|
||||||
|
import net.dnorberg.rivencraft.writing.SymbolReference;
|
||||||
|
import net.dnorberg.rivencraft.writing.WritingEntry;
|
||||||
|
import net.dnorberg.rivencraft.writing.NotebookContents;
|
||||||
|
import net.dnorberg.rivencraft.item.PageItem;
|
||||||
|
import net.dnorberg.rivencraft.item.InkVialItem;
|
||||||
|
import net.dnorberg.rivencraft.writing.WritingInkService;
|
||||||
|
import net.dnorberg.rivencraft.registry.ModDataComponents;
|
||||||
|
import net.dnorberg.rivencraft.registry.ModItems;
|
||||||
|
import net.dnorberg.rivencraft.menu.NotebookMenu;
|
||||||
|
import net.minecraft.gametest.framework.GameTest;
|
||||||
|
import net.minecraft.gametest.framework.GameTestHelper;
|
||||||
|
import net.minecraft.network.FriendlyByteBuf;
|
||||||
|
import net.minecraft.nbt.CompoundTag;
|
||||||
|
import net.minecraft.resources.ResourceLocation;
|
||||||
|
import net.minecraft.world.item.ItemStack;
|
||||||
|
import net.minecraft.world.item.Items;
|
||||||
|
import net.minecraft.world.InteractionHand;
|
||||||
|
import net.minecraft.world.inventory.ClickType;
|
||||||
|
import net.neoforged.neoforge.gametest.GameTestHolder;
|
||||||
|
import net.neoforged.neoforge.gametest.PrefixGameTestTemplate;
|
||||||
|
|
||||||
|
/** Acceptance coverage for Milestone 4's persistent writing contracts. */
|
||||||
|
@GameTestHolder(Rivencraft.MOD_ID)
|
||||||
|
@PrefixGameTestTemplate(false)
|
||||||
|
public final class WritingDataGameTests {
|
||||||
|
private WritingDataGameTests() {
|
||||||
|
}
|
||||||
|
|
||||||
|
@GameTest(template = "empty")
|
||||||
|
public static void orderedWritingPreservesKnownUnknownAndLinkPanelEntries(GameTestHelper helper) {
|
||||||
|
SymbolReference known = reference("rivencraft:terrain/standard");
|
||||||
|
SymbolReference unknown = reference("example:removed_symbol");
|
||||||
|
OrderedWriting original = new OrderedWriting(List.of(
|
||||||
|
WritingEntry.symbol(known),
|
||||||
|
WritingEntry.symbol(unknown),
|
||||||
|
WritingEntry.linkPanel()
|
||||||
|
));
|
||||||
|
|
||||||
|
var json = OrderedWriting.CODEC.encodeStart(JsonOps.INSTANCE, original).result().orElseThrow();
|
||||||
|
OrderedWriting persistentCopy = OrderedWriting.CODEC.parse(JsonOps.INSTANCE, json).result().orElseThrow();
|
||||||
|
helper.assertValueEqual(persistentCopy, original,
|
||||||
|
"Persistent writing codec must retain entry order and unknown symbol IDs");
|
||||||
|
|
||||||
|
FriendlyByteBuf buffer = new FriendlyByteBuf(Unpooled.buffer());
|
||||||
|
OrderedWriting.STREAM_CODEC.encode(buffer, original);
|
||||||
|
OrderedWriting networkCopy = OrderedWriting.STREAM_CODEC.decode(buffer);
|
||||||
|
helper.assertValueEqual(networkCopy, original,
|
||||||
|
"Network writing codec must retain entry order and unknown symbol IDs");
|
||||||
|
helper.succeed();
|
||||||
|
}
|
||||||
|
|
||||||
|
@GameTest(template = "empty")
|
||||||
|
public static void serverCatalogResolvesBuiltinsAndKeepsUnknownReferencesReadable(GameTestHelper helper) {
|
||||||
|
SymbolReference known = reference("rivencraft:terrain/standard");
|
||||||
|
SymbolReference unknown = reference("example:removed_symbol");
|
||||||
|
helper.assertTrue(SymbolCatalog.symbols().size() >= 6,
|
||||||
|
"The built-in catalog must exercise every Milestone 4 writing workflow");
|
||||||
|
helper.assertTrue(SymbolCatalog.isKnown(known),
|
||||||
|
"The built-in Standard Terrain symbol must be server-authoritative");
|
||||||
|
helper.assertFalse(SymbolCatalog.isKnown(unknown),
|
||||||
|
"An absent data-pack symbol must remain unresolved");
|
||||||
|
var unresolved = SymbolCatalog.display(unknown);
|
||||||
|
helper.assertFalse(unresolved.resolved(),
|
||||||
|
"Unknown symbol display metadata must be marked unresolved");
|
||||||
|
helper.assertValueEqual(unresolved.id(), unknown.id(),
|
||||||
|
"Unresolved display metadata must preserve the original namespaced ID");
|
||||||
|
helper.succeed();
|
||||||
|
}
|
||||||
|
|
||||||
|
@GameTest(template = "empty")
|
||||||
|
public static void pageStatesPersistAndNetworkRoundTrip(GameTestHelper helper) {
|
||||||
|
SymbolReference known = reference("rivencraft:terrain/standard");
|
||||||
|
SymbolReference removed = reference("example:removed_symbol");
|
||||||
|
List<PageContent> states = List.of(
|
||||||
|
PageContent.BLANK,
|
||||||
|
PageContent.symbol(known),
|
||||||
|
PageContent.unresolved(removed),
|
||||||
|
PageContent.LINK_PANEL
|
||||||
|
);
|
||||||
|
|
||||||
|
for (PageContent state : states) {
|
||||||
|
var json = PageContent.CODEC.encodeStart(JsonOps.INSTANCE, state).result().orElseThrow();
|
||||||
|
PageContent persistentCopy = PageContent.CODEC.parse(JsonOps.INSTANCE, json).result().orElseThrow();
|
||||||
|
helper.assertValueEqual(persistentCopy, state, "Page content must persist exactly");
|
||||||
|
|
||||||
|
FriendlyByteBuf buffer = new FriendlyByteBuf(Unpooled.buffer());
|
||||||
|
PageContent.STREAM_CODEC.encode(buffer, state);
|
||||||
|
helper.assertValueEqual(PageContent.STREAM_CODEC.decode(buffer), state,
|
||||||
|
"Page content must network-sync exactly");
|
||||||
|
}
|
||||||
|
helper.succeed();
|
||||||
|
}
|
||||||
|
|
||||||
|
@GameTest(template = "empty")
|
||||||
|
public static void pageItemPreservesContentAndRejectsForgedUnknownSymbols(GameTestHelper helper) {
|
||||||
|
SymbolReference known = reference("rivencraft:terrain/standard");
|
||||||
|
SymbolReference unknown = reference("example:forged_symbol");
|
||||||
|
ItemStack page = PageItem.createSymbolPage(known);
|
||||||
|
CompoundTag serialized = (CompoundTag) page.saveOptional(helper.getLevel().registryAccess());
|
||||||
|
ItemStack restored = ItemStack.parseOptional(helper.getLevel().registryAccess(), serialized);
|
||||||
|
helper.assertValueEqual(restored.get(ModDataComponents.PAGE_CONTENT.get()), PageContent.symbol(known),
|
||||||
|
"Symbol page content must survive an ItemStack save/load");
|
||||||
|
helper.assertValueEqual(
|
||||||
|
restored.get(ModDataComponents.PAGE_SYMBOL_DISPLAY.get()),
|
||||||
|
SymbolCatalog.display(known),
|
||||||
|
"Server-selected display metadata must survive for remote clients"
|
||||||
|
);
|
||||||
|
|
||||||
|
ItemStack recovered = PageItem.createRecoveredPage(unknown);
|
||||||
|
helper.assertFalse(PageItem.isUsableWriting(recovered),
|
||||||
|
"An unresolved page must remain recoverable without becoming valid writing");
|
||||||
|
try {
|
||||||
|
PageItem.createSymbolPage(unknown);
|
||||||
|
helper.fail("The server must reject new pages for unknown symbols");
|
||||||
|
} catch (IllegalArgumentException expected) {
|
||||||
|
helper.succeed();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@GameTest(template = "empty")
|
||||||
|
public static void notebookContentsPreserveOrderGapsNamesAndUnknownPages(GameTestHelper helper) {
|
||||||
|
ItemStack first = PageItem.createSymbolPage(reference("rivencraft:terrain/standard"));
|
||||||
|
first.set(net.minecraft.core.component.DataComponents.CUSTOM_NAME,
|
||||||
|
net.minecraft.network.chat.Component.literal("Foundation"));
|
||||||
|
ItemStack unknown = PageItem.createRecoveredPage(reference("example:removed_symbol"));
|
||||||
|
NotebookContents contents = new NotebookContents(List.of(first, ItemStack.EMPTY, unknown));
|
||||||
|
ItemStack notebook = new ItemStack(ModItems.NOTEBOOK.get());
|
||||||
|
notebook.set(ModDataComponents.NOTEBOOK_CONTENTS.get(), contents);
|
||||||
|
|
||||||
|
CompoundTag serialized = (CompoundTag)notebook.saveOptional(helper.getLevel().registryAccess());
|
||||||
|
ItemStack restored = ItemStack.parseOptional(helper.getLevel().registryAccess(), serialized);
|
||||||
|
NotebookContents restoredContents = restored.get(ModDataComponents.NOTEBOOK_CONTENTS.get());
|
||||||
|
helper.assertTrue(restoredContents != null, "Notebook contents must survive ItemStack persistence");
|
||||||
|
helper.assertValueEqual(restoredContents.pages().size(), 3,
|
||||||
|
"Notebook persistence must retain ordered positions");
|
||||||
|
helper.assertTrue(restoredContents.pages().get(1).isEmpty(),
|
||||||
|
"Notebook persistence must retain empty positions between pages");
|
||||||
|
helper.assertValueEqual(restoredContents.pages().get(0).getHoverName().getString(), "Foundation",
|
||||||
|
"Renamed contained pages must retain their names");
|
||||||
|
helper.assertValueEqual(PageItem.content(restoredContents.pages().get(2)).kind(),
|
||||||
|
PageContent.Kind.UNRESOLVED_SYMBOL,
|
||||||
|
"Unknown symbol pages must remain present and removable");
|
||||||
|
helper.succeed();
|
||||||
|
}
|
||||||
|
|
||||||
|
@GameTest(template = "empty")
|
||||||
|
public static void notebookMenuValidatesInsertionAndPersistsReorder(GameTestHelper helper) {
|
||||||
|
var player = helper.makeMockServerPlayerInLevel();
|
||||||
|
ItemStack notebook = new ItemStack(ModItems.NOTEBOOK.get());
|
||||||
|
player.setItemInHand(InteractionHand.MAIN_HAND, notebook);
|
||||||
|
NotebookMenu menu = new NotebookMenu(7, player.getInventory(), InteractionHand.MAIN_HAND);
|
||||||
|
ItemStack first = PageItem.createSymbolPage(reference("rivencraft:terrain/standard"));
|
||||||
|
first.set(net.minecraft.core.component.DataComponents.CUSTOM_NAME,
|
||||||
|
net.minecraft.network.chat.Component.literal("Terrain Base"));
|
||||||
|
ItemStack second = PageItem.createRecoveredPage(reference("example:removed_symbol"));
|
||||||
|
|
||||||
|
helper.assertFalse(menu.getSlot(0).mayPlace(new ItemStack(Items.DIRT)),
|
||||||
|
"Notebook slots must reject non-Page items");
|
||||||
|
menu.getSlot(0).set(first);
|
||||||
|
menu.getSlot(1).set(second);
|
||||||
|
helper.assertTrue(menu.clickMenuButton(player, NotebookMenu.MOVE_NEXT_BASE),
|
||||||
|
"The server menu must accept a valid adjacent reorder");
|
||||||
|
|
||||||
|
NotebookContents saved = notebook.get(ModDataComponents.NOTEBOOK_CONTENTS.get());
|
||||||
|
helper.assertTrue(saved != null, "Menu changes must persist immediately to the Notebook item");
|
||||||
|
helper.assertValueEqual(saved.pages().get(1).getHoverName().getString(), "Terrain Base",
|
||||||
|
"Reordering must preserve existing Page item data");
|
||||||
|
helper.assertValueEqual(PageItem.content(saved.pages().get(0)).kind(),
|
||||||
|
PageContent.Kind.UNRESOLVED_SYMBOL,
|
||||||
|
"Reordering must preserve unresolved pages");
|
||||||
|
helper.succeed();
|
||||||
|
}
|
||||||
|
|
||||||
|
@GameTest(template = "empty")
|
||||||
|
public static void notebookMenuSurvivesInventoryStackReplacementAndClicks(GameTestHelper helper) {
|
||||||
|
var player = helper.makeMockServerPlayerInLevel();
|
||||||
|
player.setItemInHand(InteractionHand.MAIN_HAND, new ItemStack(ModItems.NOTEBOOK.get()));
|
||||||
|
NotebookMenu menu = new NotebookMenu(8, player.getInventory(), InteractionHand.MAIN_HAND);
|
||||||
|
|
||||||
|
// Slot synchronization may replace the ItemStack object while the Notebook remains held.
|
||||||
|
player.setItemInHand(InteractionHand.MAIN_HAND, player.getMainHandItem().copy());
|
||||||
|
helper.assertTrue(menu.stillValid(player),
|
||||||
|
"Replacing the held stack object must not close an open Notebook menu");
|
||||||
|
menu.getSlot(0).set(PageItem.createSymbolPage(reference("rivencraft:terrain/standard")));
|
||||||
|
helper.assertTrue(player.getMainHandItem().has(ModDataComponents.NOTEBOOK_CONTENTS.get()),
|
||||||
|
"Page edits must persist to the current held Notebook stack");
|
||||||
|
|
||||||
|
player.getInventory().setItem(9, new ItemStack(Items.DIRT));
|
||||||
|
menu.clicked(NotebookMenu.NOTEBOOK_SLOTS, 0, ClickType.PICKUP, player);
|
||||||
|
helper.assertTrue(menu.getCarried().is(Items.DIRT),
|
||||||
|
"Clicking a player inventory item must pick it up without closing the Notebook");
|
||||||
|
helper.assertTrue(menu.stillValid(player),
|
||||||
|
"Normal inventory clicks must leave the Notebook menu valid");
|
||||||
|
helper.succeed();
|
||||||
|
}
|
||||||
|
|
||||||
|
@GameTest(template = "empty")
|
||||||
|
public static void notebookMenuPreservesSparsePagePositions(GameTestHelper helper) {
|
||||||
|
var player = helper.makeMockServerPlayerInLevel();
|
||||||
|
player.setItemInHand(InteractionHand.MAIN_HAND, new ItemStack(ModItems.NOTEBOOK.get()));
|
||||||
|
NotebookMenu menu = new NotebookMenu(9, player.getInventory(), InteractionHand.MAIN_HAND);
|
||||||
|
ItemStack page = PageItem.createSymbolPage(reference("rivencraft:terrain/standard"));
|
||||||
|
menu.setCarried(page);
|
||||||
|
|
||||||
|
menu.clicked(9, 0, ClickType.PICKUP, player);
|
||||||
|
helper.assertTrue(menu.getCarried().isEmpty(),
|
||||||
|
"Clicking a distant empty Notebook slot must place the carried Page");
|
||||||
|
NotebookContents saved = player.getMainHandItem().get(ModDataComponents.NOTEBOOK_CONTENTS.get());
|
||||||
|
helper.assertTrue(saved != null && saved.pages().size() > 9,
|
||||||
|
"Notebook persistence must extend through the highest occupied position");
|
||||||
|
for (int index = 0; index < 9; index++) {
|
||||||
|
helper.assertTrue(saved.pages().get(index).isEmpty(),
|
||||||
|
"Earlier empty page positions must remain empty rather than being packed together");
|
||||||
|
}
|
||||||
|
helper.assertValueEqual(PageItem.content(saved.pages().get(9)).kind(), PageContent.Kind.SYMBOL,
|
||||||
|
"The Page must remain in the selected distant position");
|
||||||
|
helper.succeed();
|
||||||
|
}
|
||||||
|
|
||||||
|
@GameTest(template = "empty")
|
||||||
|
public static void inkVialsPersistAndOnlyStackWithMatchingContents(GameTestHelper helper) {
|
||||||
|
ItemStack vial = new ItemStack(ModItems.INK_VIAL.get());
|
||||||
|
vial.set(ModDataComponents.INK_REMAINING.get(), 7);
|
||||||
|
CompoundTag serialized = (CompoundTag) vial.saveOptional(helper.getLevel().registryAccess());
|
||||||
|
ItemStack restored = ItemStack.parseOptional(helper.getLevel().registryAccess(), serialized);
|
||||||
|
helper.assertValueEqual(InkVialItem.remaining(restored), 7,
|
||||||
|
"Remaining ink must survive ItemStack persistence");
|
||||||
|
helper.assertTrue(ItemStack.isSameItemSameComponents(vial, restored),
|
||||||
|
"Vials with equal ink contents must be eligible to stack");
|
||||||
|
helper.assertFalse(ItemStack.isSameItemSameComponents(vial, new ItemStack(ModItems.INK_VIAL.get())),
|
||||||
|
"Vials with different ink contents must not stack");
|
||||||
|
helper.succeed();
|
||||||
|
}
|
||||||
|
|
||||||
|
@GameTest(template = "empty")
|
||||||
|
public static void linkPanelPreparationConsumesOnePageAndConfiguredInkOnlyOnSuccess(GameTestHelper helper) {
|
||||||
|
var player = helper.makeMockServerPlayerInLevel();
|
||||||
|
ItemStack pages = new ItemStack(Items.PAPER, 2);
|
||||||
|
ItemStack vial = new ItemStack(ModItems.INK_VIAL.get());
|
||||||
|
player.setItemInHand(InteractionHand.MAIN_HAND, vial);
|
||||||
|
player.setItemInHand(InteractionHand.OFF_HAND, pages);
|
||||||
|
|
||||||
|
helper.assertTrue(WritingInkService.prepareLinkPanel(player, InteractionHand.MAIN_HAND),
|
||||||
|
"Paper and sufficient ink must prepare one link panel");
|
||||||
|
helper.assertValueEqual(pages.getCount(), 1, "Preparation must consume exactly one paper");
|
||||||
|
helper.assertValueEqual(InkVialItem.remaining(player.getMainHandItem()),
|
||||||
|
InkVialItem.CAPACITY - WritingInkService.linkPanelCost(),
|
||||||
|
"Preparation must consume exactly the server-configured ink cost");
|
||||||
|
long panels = player.getInventory().items.stream()
|
||||||
|
.filter(stack -> stack.is(ModItems.PAGE.get())
|
||||||
|
&& PageItem.content(stack).kind() == PageContent.Kind.LINK_PANEL)
|
||||||
|
.mapToInt(ItemStack::getCount).sum();
|
||||||
|
helper.assertValueEqual(panels, 1L, "Preparation must output exactly one link panel");
|
||||||
|
|
||||||
|
ItemStack written = PageItem.createSymbolPage(reference("rivencraft:terrain/standard"));
|
||||||
|
player.setItemInHand(InteractionHand.OFF_HAND, written);
|
||||||
|
int inkBefore = InkVialItem.remaining(player.getMainHandItem());
|
||||||
|
helper.assertFalse(WritingInkService.prepareLinkPanel(player, InteractionHand.MAIN_HAND),
|
||||||
|
"A written Page must not be overwritten as a link panel");
|
||||||
|
helper.assertValueEqual(InkVialItem.remaining(player.getMainHandItem()), inkBefore,
|
||||||
|
"Rejected writing must not consume ink");
|
||||||
|
helper.assertValueEqual(PageItem.content(written).kind(), PageContent.Kind.SYMBOL,
|
||||||
|
"Rejected writing must not modify the input Page");
|
||||||
|
|
||||||
|
ItemStack lowInk = new ItemStack(ModItems.INK_VIAL.get());
|
||||||
|
lowInk.set(ModDataComponents.INK_REMAINING.get(), WritingInkService.linkPanelCost() - 1);
|
||||||
|
player.setItemInHand(InteractionHand.MAIN_HAND, lowInk);
|
||||||
|
player.setItemInHand(InteractionHand.OFF_HAND, new ItemStack(Items.PAPER));
|
||||||
|
helper.assertFalse(WritingInkService.prepareLinkPanel(player, InteractionHand.MAIN_HAND),
|
||||||
|
"Insufficient ink must reject link-panel preparation");
|
||||||
|
helper.assertValueEqual(InkVialItem.remaining(player.getMainHandItem()),
|
||||||
|
WritingInkService.linkPanelCost() - 1,
|
||||||
|
"Insufficient ink must remain untouched");
|
||||||
|
helper.assertTrue(player.getOffhandItem().is(Items.PAPER),
|
||||||
|
"Insufficient ink must leave paper untouched");
|
||||||
|
|
||||||
|
lowInk.set(ModDataComponents.INK_REMAINING.get(), WritingInkService.linkPanelCost());
|
||||||
|
helper.assertTrue(WritingInkService.prepareLinkPanel(player, InteractionHand.MAIN_HAND),
|
||||||
|
"Exact remaining ink must be usable");
|
||||||
|
helper.assertTrue(player.getMainHandItem().is(Items.GLASS_BOTTLE),
|
||||||
|
"A depleted Ink Vial must return a reusable glass bottle");
|
||||||
|
helper.assertValueEqual(PageItem.content(player.getOffhandItem()).kind(),
|
||||||
|
PageContent.Kind.LINK_PANEL,
|
||||||
|
"A single paper must be replaced by one Link Panel Page");
|
||||||
|
helper.succeed();
|
||||||
|
}
|
||||||
|
|
||||||
|
@GameTest(template = "empty")
|
||||||
|
public static void stackedInkVialsSplitWithoutChangingTheOtherVials(GameTestHelper helper) {
|
||||||
|
var player = helper.makeMockServerPlayerInLevel();
|
||||||
|
player.setItemInHand(InteractionHand.MAIN_HAND, new ItemStack(ModItems.INK_VIAL.get(), 2));
|
||||||
|
player.setItemInHand(InteractionHand.OFF_HAND, new ItemStack(Items.PAPER));
|
||||||
|
|
||||||
|
helper.assertTrue(WritingInkService.prepareLinkPanel(player, InteractionHand.MAIN_HAND),
|
||||||
|
"A stack of full vials must support preparing one panel");
|
||||||
|
helper.assertValueEqual(player.getMainHandItem().getCount(), 1,
|
||||||
|
"Using one vial must leave the other full vial in hand");
|
||||||
|
helper.assertValueEqual(InkVialItem.remaining(player.getMainHandItem()), InkVialItem.CAPACITY,
|
||||||
|
"The unconsumed vial must remain full");
|
||||||
|
long partialVials = player.getInventory().items.stream()
|
||||||
|
.filter(stack -> stack.is(ModItems.INK_VIAL.get())
|
||||||
|
&& InkVialItem.remaining(stack) == InkVialItem.CAPACITY - WritingInkService.linkPanelCost())
|
||||||
|
.mapToInt(ItemStack::getCount).sum();
|
||||||
|
helper.assertValueEqual(partialVials, 1L,
|
||||||
|
"The used vial must reappear with only its own ink reduced");
|
||||||
|
helper.succeed();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static SymbolReference reference(String id) {
|
||||||
|
return new SymbolReference(ResourceLocation.parse(id));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,622 @@
|
|||||||
|
package net.dnorberg.rivencraft.gametest;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import net.dnorberg.rivencraft.Rivencraft;
|
||||||
|
import net.dnorberg.rivencraft.block.entity.WritingDeskBlockEntity;
|
||||||
|
import net.dnorberg.rivencraft.block.WritingDeskBlock;
|
||||||
|
import net.dnorberg.rivencraft.menu.WritingDeskMenu;
|
||||||
|
import net.dnorberg.rivencraft.item.PageItem;
|
||||||
|
import net.dnorberg.rivencraft.registry.ModBlocks;
|
||||||
|
import net.dnorberg.rivencraft.registry.ModDataComponents;
|
||||||
|
import net.dnorberg.rivencraft.registry.ModItems;
|
||||||
|
import net.dnorberg.rivencraft.writing.NotebookContents;
|
||||||
|
import net.dnorberg.rivencraft.writing.SymbolReference;
|
||||||
|
import net.dnorberg.rivencraft.writing.WritingDeskCatalog;
|
||||||
|
import net.minecraft.core.BlockPos;
|
||||||
|
import net.minecraft.core.Direction;
|
||||||
|
import net.minecraft.resources.ResourceLocation;
|
||||||
|
import net.minecraft.gametest.framework.GameTest;
|
||||||
|
import net.minecraft.gametest.framework.GameTestHelper;
|
||||||
|
import net.minecraft.world.entity.item.ItemEntity;
|
||||||
|
import net.minecraft.world.item.ItemStack;
|
||||||
|
import net.minecraft.world.item.Items;
|
||||||
|
import net.minecraft.world.inventory.ClickType;
|
||||||
|
import net.minecraft.world.level.block.Blocks;
|
||||||
|
import net.minecraft.world.phys.AABB;
|
||||||
|
import net.neoforged.neoforge.gametest.GameTestHolder;
|
||||||
|
import net.neoforged.neoforge.gametest.PrefixGameTestTemplate;
|
||||||
|
|
||||||
|
@GameTestHolder(Rivencraft.MOD_ID)
|
||||||
|
@PrefixGameTestTemplate(false)
|
||||||
|
public final class WritingDeskGameTests {
|
||||||
|
private WritingDeskGameTests() {}
|
||||||
|
|
||||||
|
@GameTest(template = "empty")
|
||||||
|
public static void inventoryAndActiveCollectionPersist(GameTestHelper helper) {
|
||||||
|
BlockPos pos = helper.absolutePos(new BlockPos(1, 1, 1));
|
||||||
|
var original = new WritingDeskBlockEntity(pos, ModBlocks.WRITING_DESK.get().defaultBlockState());
|
||||||
|
original.setItem(0, new ItemStack(ModItems.NOTEBOOK.get()));
|
||||||
|
original.setItem(WritingDeskBlockEntity.INK, new ItemStack(ModItems.INK_VIAL.get()));
|
||||||
|
original.setItem(WritingDeskBlockEntity.PAPER, new ItemStack(Items.PAPER, 12));
|
||||||
|
original.setActiveCollection(2);
|
||||||
|
var saved = original.saveWithoutMetadata(helper.getLevel().registryAccess());
|
||||||
|
var restored = new WritingDeskBlockEntity(pos, ModBlocks.WRITING_DESK.get().defaultBlockState());
|
||||||
|
restored.loadWithComponents(saved, helper.getLevel().registryAccess());
|
||||||
|
helper.assertTrue(restored.getItem(0).is(ModItems.NOTEBOOK.get()), "Notebook lost on save/load");
|
||||||
|
helper.assertTrue(restored.getItem(WritingDeskBlockEntity.INK).is(ModItems.INK_VIAL.get()), "Ink lost on save/load");
|
||||||
|
helper.assertValueEqual(restored.getItem(WritingDeskBlockEntity.PAPER).getCount(), 12, "Pages lost on save/load");
|
||||||
|
helper.assertValueEqual(restored.activeCollection(), 2, "Active collection lost on save/load");
|
||||||
|
helper.succeed();
|
||||||
|
}
|
||||||
|
|
||||||
|
@GameTest(template = "empty")
|
||||||
|
public static void breakingDeskDropsItsStoredItemsOnce(GameTestHelper helper) {
|
||||||
|
BlockPos relative = new BlockPos(1, 1, 1);
|
||||||
|
BlockPos pos = helper.absolutePos(relative);
|
||||||
|
helper.getLevel().setBlock(pos, ModBlocks.WRITING_DESK.get().defaultBlockState(), 3);
|
||||||
|
WritingDeskBlockEntity desk = (WritingDeskBlockEntity) helper.getLevel().getBlockEntity(pos);
|
||||||
|
desk.setItem(0, new ItemStack(ModItems.NOTEBOOK.get()));
|
||||||
|
desk.setItem(WritingDeskBlockEntity.INK, new ItemStack(ModItems.INK_VIAL.get()));
|
||||||
|
desk.setItem(WritingDeskBlockEntity.PAPER, new ItemStack(Items.PAPER, 12));
|
||||||
|
helper.getLevel().setBlock(pos, Blocks.AIR.defaultBlockState(), 3);
|
||||||
|
var drops = helper.getLevel().getEntitiesOfClass(ItemEntity.class, new AABB(pos).inflate(2));
|
||||||
|
int notebooks = drops.stream().filter(e -> e.getItem().is(ModItems.NOTEBOOK.get())).mapToInt(e -> e.getItem().getCount()).sum();
|
||||||
|
int bottles = drops.stream().filter(e -> e.getItem().is(Items.GLASS_BOTTLE)).mapToInt(e -> e.getItem().getCount()).sum();
|
||||||
|
int pages = drops.stream().filter(e -> e.getItem().is(Items.PAPER)).mapToInt(e -> e.getItem().getCount()).sum();
|
||||||
|
helper.assertValueEqual(notebooks, 1, "Notebook must drop exactly once");
|
||||||
|
helper.assertValueEqual(bottles, 1, "Consumed vial must return one glass bottle on break");
|
||||||
|
helper.assertValueEqual(pages, 12, "Pages must drop without loss");
|
||||||
|
helper.succeed();
|
||||||
|
}
|
||||||
|
|
||||||
|
@GameTest(template = "empty")
|
||||||
|
public static void menuTransfersWithoutDuplicationAndClosesWhenReplaced(GameTestHelper helper) {
|
||||||
|
BlockPos pos = helper.absolutePos(new BlockPos(1, 1, 1));
|
||||||
|
helper.getLevel().setBlock(pos, ModBlocks.WRITING_DESK.get().defaultBlockState(), 3);
|
||||||
|
WritingDeskBlockEntity desk = (WritingDeskBlockEntity) helper.getLevel().getBlockEntity(pos);
|
||||||
|
var player = helper.makeMockServerPlayerInLevel();
|
||||||
|
player.moveTo(pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5);
|
||||||
|
player.getInventory().setItem(9, new ItemStack(Items.PAPER, 12));
|
||||||
|
WritingDeskMenu menu = new WritingDeskMenu(1, player.getInventory(), desk);
|
||||||
|
helper.assertTrue(menu.stillValid(player), "Placed desk must keep its menu valid");
|
||||||
|
helper.assertTrue(menu.clickMenuButton(player, 3), "Active collection control must accept a valid tab");
|
||||||
|
helper.assertValueEqual(desk.activeCollection(), 3, "Selected tab must be stored on the desk");
|
||||||
|
menu.quickMoveStack(player, WritingDeskMenu.COPY_RESULT + 1);
|
||||||
|
helper.assertValueEqual(desk.getItem(WritingDeskBlockEntity.PAPER).getCount(), 12, "Shift-click must deposit all pages");
|
||||||
|
helper.assertTrue(player.getInventory().getItem(9).isEmpty(), "Shift-click must consume player source stack");
|
||||||
|
menu.quickMoveStack(player, WritingDeskBlockEntity.PAPER);
|
||||||
|
helper.assertTrue(desk.getItem(WritingDeskBlockEntity.PAPER).isEmpty(), "Shift-click must empty desk source slot");
|
||||||
|
int total = player.getInventory().items.stream().filter(stack -> stack.is(Items.PAPER))
|
||||||
|
.mapToInt(ItemStack::getCount).sum();
|
||||||
|
helper.assertValueEqual(total, 12, "Round-trip must not lose or duplicate pages");
|
||||||
|
helper.getLevel().setBlock(pos, Blocks.AIR.defaultBlockState(), 3);
|
||||||
|
helper.assertFalse(menu.stillValid(player), "Removed desk must invalidate menu");
|
||||||
|
helper.succeed();
|
||||||
|
}
|
||||||
|
|
||||||
|
@GameTest(template = "empty")
|
||||||
|
public static void takingCopySpendsPaperAndOneInkThenReturnsGlassBottle(GameTestHelper helper) {
|
||||||
|
BlockPos pos = helper.absolutePos(new BlockPos(1, 1, 1));
|
||||||
|
helper.getLevel().setBlock(pos, ModBlocks.WRITING_DESK.get().defaultBlockState(), 3);
|
||||||
|
WritingDeskBlockEntity desk = (WritingDeskBlockEntity) helper.getLevel().getBlockEntity(pos);
|
||||||
|
ItemStack source = PageItem.createLinkPanelPage();
|
||||||
|
desk.setItem(0, source.copy());
|
||||||
|
desk.setItem(WritingDeskBlockEntity.PAPER, new ItemStack(Items.PAPER, 2));
|
||||||
|
desk.setItem(WritingDeskBlockEntity.INK, new ItemStack(ModItems.INK_VIAL.get()));
|
||||||
|
var player = helper.makeMockServerPlayerInLevel();
|
||||||
|
player.moveTo(pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5);
|
||||||
|
WritingDeskMenu menu = new WritingDeskMenu(1, player.getInventory(), desk);
|
||||||
|
menu.broadcastChanges();
|
||||||
|
helper.assertTrue(menu.getSlot(WritingDeskMenu.COPY_RESULT).getItem().is(ModItems.PAGE.get()),
|
||||||
|
"A source page with paper and ink must preview one copy");
|
||||||
|
helper.assertValueEqual(desk.getItem(WritingDeskBlockEntity.PAPER).getCount(), 2,
|
||||||
|
"Previewing must not consume paper");
|
||||||
|
helper.assertValueEqual(desk.inkRemaining(), 16, "Inserting a vial must fill the empty bar before copying");
|
||||||
|
menu.clicked(WritingDeskMenu.COPY_RESULT, 0, ClickType.PICKUP, player);
|
||||||
|
helper.assertTrue(menu.getCarried().is(ModItems.PAGE.get()), "Taking result must give the copied page");
|
||||||
|
helper.assertValueEqual(desk.getItem(WritingDeskBlockEntity.PAPER).getCount(), 1,
|
||||||
|
"Taking a copy must consume one paper");
|
||||||
|
helper.assertValueEqual(desk.inkRemaining(), 15, "First copy must consume one ink");
|
||||||
|
helper.assertTrue(desk.getItem(WritingDeskBlockEntity.INK).isEmpty(), "Refill must consume one vial");
|
||||||
|
helper.assertTrue(desk.getItem(WritingDeskBlockEntity.RETURN).is(Items.GLASS_BOTTLE),
|
||||||
|
"Refill must return a vanilla glass bottle");
|
||||||
|
helper.assertTrue(desk.getItem(0).is(ModItems.PAGE.get()), "Source page must remain untouched");
|
||||||
|
helper.assertTrue(menu.quickMoveStack(player, WritingDeskMenu.COPY_RESULT).is(ModItems.PAGE.get()),
|
||||||
|
"A second copy must remain available from the same ink fill");
|
||||||
|
helper.assertTrue(desk.getItem(WritingDeskBlockEntity.PAPER).isEmpty(),
|
||||||
|
"Two copies must consume exactly two paper");
|
||||||
|
helper.assertValueEqual(desk.inkRemaining(), 14, "Two copies must spend exactly two of sixteen ink");
|
||||||
|
helper.assertValueEqual(desk.getItem(WritingDeskBlockEntity.RETURN).getCount(), 1,
|
||||||
|
"A second copy must not consume another vial");
|
||||||
|
var saved = desk.saveWithoutMetadata(helper.getLevel().registryAccess());
|
||||||
|
var restored = new WritingDeskBlockEntity(pos, ModBlocks.WRITING_DESK.get().defaultBlockState());
|
||||||
|
restored.loadWithComponents(saved, helper.getLevel().registryAccess());
|
||||||
|
helper.assertValueEqual(restored.inkRemaining(), 14, "Ink meter must persist across saves");
|
||||||
|
helper.succeed();
|
||||||
|
}
|
||||||
|
|
||||||
|
@GameTest(template = "empty")
|
||||||
|
public static void emptyDeskInkBarRefillsWithoutCopying(GameTestHelper helper) {
|
||||||
|
BlockPos pos = helper.absolutePos(new BlockPos(1, 1, 1));
|
||||||
|
helper.getLevel().setBlock(pos, ModBlocks.WRITING_DESK.get().defaultBlockState(), 3);
|
||||||
|
WritingDeskBlockEntity desk = (WritingDeskBlockEntity) helper.getLevel().getBlockEntity(pos);
|
||||||
|
desk.setItem(WritingDeskBlockEntity.INK, new ItemStack(ModItems.INK_VIAL.get(), 2));
|
||||||
|
helper.assertValueEqual(desk.inkRemaining(), 16, "Inserting a vial must refill immediately");
|
||||||
|
helper.assertValueEqual(desk.getItem(WritingDeskBlockEntity.INK).getCount(), 1,
|
||||||
|
"Refill must consume exactly one vial");
|
||||||
|
helper.assertTrue(desk.getItem(WritingDeskBlockEntity.RETURN).is(Items.GLASS_BOTTLE),
|
||||||
|
"Refill must put a vanilla glass bottle in the return slot");
|
||||||
|
helper.runAfterDelay(2, () -> {
|
||||||
|
helper.assertValueEqual(desk.inkRemaining(), 16, "Full bar must not refill again");
|
||||||
|
helper.assertValueEqual(desk.getItem(WritingDeskBlockEntity.INK).getCount(), 1,
|
||||||
|
"Full bar must leave the second vial untouched");
|
||||||
|
helper.assertValueEqual(desk.getItem(WritingDeskBlockEntity.RETURN).getCount(), 1,
|
||||||
|
"Full bar must not create another bottle");
|
||||||
|
helper.succeed();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@GameTest(template = "empty")
|
||||||
|
public static void emptyDeskInkBarWaitsForBottleSpace(GameTestHelper helper) {
|
||||||
|
BlockPos pos = helper.absolutePos(new BlockPos(1, 1, 1));
|
||||||
|
helper.getLevel().setBlock(pos, ModBlocks.WRITING_DESK.get().defaultBlockState(), 3);
|
||||||
|
WritingDeskBlockEntity desk = (WritingDeskBlockEntity) helper.getLevel().getBlockEntity(pos);
|
||||||
|
desk.setItem(WritingDeskBlockEntity.RETURN, new ItemStack(Items.GLASS_BOTTLE, 64));
|
||||||
|
desk.setItem(WritingDeskBlockEntity.INK, new ItemStack(ModItems.INK_VIAL.get()));
|
||||||
|
helper.assertValueEqual(desk.inkRemaining(), 0, "Full bottle slot must block automatic refill");
|
||||||
|
helper.assertTrue(desk.getItem(WritingDeskBlockEntity.INK).is(ModItems.INK_VIAL.get()),
|
||||||
|
"Blocked refill must preserve the vial");
|
||||||
|
helper.assertValueEqual(desk.getItem(WritingDeskBlockEntity.RETURN).getCount(), 64,
|
||||||
|
"Blocked refill must preserve the bottle stack");
|
||||||
|
desk.removeItem(WritingDeskBlockEntity.RETURN, 1);
|
||||||
|
helper.assertValueEqual(desk.inkRemaining(), 16, "Removing a bottle must immediately permit refill");
|
||||||
|
helper.assertTrue(desk.getItem(WritingDeskBlockEntity.INK).isEmpty(),
|
||||||
|
"Refill must consume the waiting vial");
|
||||||
|
helper.assertValueEqual(desk.getItem(WritingDeskBlockEntity.RETURN).getCount(), 64,
|
||||||
|
"Refill must return one glass bottle to the available space");
|
||||||
|
helper.succeed();
|
||||||
|
}
|
||||||
|
|
||||||
|
@GameTest(template = "empty")
|
||||||
|
public static void shiftClickCopiesOnlyWhenResourcesAndBottleSpaceExist(GameTestHelper helper) {
|
||||||
|
BlockPos pos = helper.absolutePos(new BlockPos(1, 1, 1));
|
||||||
|
helper.getLevel().setBlock(pos, ModBlocks.WRITING_DESK.get().defaultBlockState(), 3);
|
||||||
|
WritingDeskBlockEntity desk = (WritingDeskBlockEntity) helper.getLevel().getBlockEntity(pos);
|
||||||
|
desk.setItem(0, PageItem.createLinkPanelPage());
|
||||||
|
desk.setItem(WritingDeskBlockEntity.PAPER, new ItemStack(Items.PAPER, 2));
|
||||||
|
desk.setItem(WritingDeskBlockEntity.RETURN, new ItemStack(Items.GLASS_BOTTLE, 64));
|
||||||
|
desk.setItem(WritingDeskBlockEntity.INK, new ItemStack(ModItems.INK_VIAL.get()));
|
||||||
|
var player = helper.makeMockServerPlayerInLevel();
|
||||||
|
player.moveTo(pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5);
|
||||||
|
WritingDeskMenu menu = new WritingDeskMenu(1, player.getInventory(), desk);
|
||||||
|
helper.assertTrue(menu.quickMoveStack(player, WritingDeskMenu.COPY_RESULT).isEmpty(),
|
||||||
|
"Full bottle return must block refill without consuming supplies");
|
||||||
|
helper.assertValueEqual(desk.getItem(WritingDeskBlockEntity.PAPER).getCount(), 2,
|
||||||
|
"Blocked copy must leave paper untouched");
|
||||||
|
desk.removeItem(WritingDeskBlockEntity.RETURN, 1);
|
||||||
|
ItemStack copied = menu.quickMoveStack(player, WritingDeskMenu.COPY_RESULT);
|
||||||
|
helper.assertTrue(copied.is(ModItems.PAGE.get()), "Shift-click must transfer one copy");
|
||||||
|
helper.assertValueEqual(desk.getItem(WritingDeskBlockEntity.PAPER).getCount(), 1,
|
||||||
|
"Shift-click must consume one paper");
|
||||||
|
helper.assertValueEqual(desk.inkRemaining(), 15, "Shift-click must consume one ink");
|
||||||
|
int copies = player.getInventory().items.stream().filter(stack -> stack.is(ModItems.PAGE.get()))
|
||||||
|
.mapToInt(ItemStack::getCount).sum();
|
||||||
|
helper.assertValueEqual(copies, 1, "Shift-click must give exactly one page");
|
||||||
|
helper.succeed();
|
||||||
|
}
|
||||||
|
|
||||||
|
@GameTest(template = "empty")
|
||||||
|
public static void selectedNotebookPageControlsCopyPreview(GameTestHelper helper) {
|
||||||
|
BlockPos pos = helper.absolutePos(new BlockPos(1, 1, 1));
|
||||||
|
helper.getLevel().setBlock(pos, ModBlocks.WRITING_DESK.get().defaultBlockState(), 3);
|
||||||
|
WritingDeskBlockEntity desk = (WritingDeskBlockEntity) helper.getLevel().getBlockEntity(pos);
|
||||||
|
ItemStack notebook = new ItemStack(ModItems.NOTEBOOK.get());
|
||||||
|
notebook.set(ModDataComponents.NOTEBOOK_CONTENTS.get(),
|
||||||
|
new NotebookContents(List.of(ItemStack.EMPTY, PageItem.createLinkPanelPage())));
|
||||||
|
desk.setItem(0, notebook);
|
||||||
|
desk.setItem(WritingDeskBlockEntity.PAPER, new ItemStack(Items.PAPER));
|
||||||
|
desk.setItem(WritingDeskBlockEntity.INK, new ItemStack(ModItems.INK_VIAL.get()));
|
||||||
|
var player = helper.makeMockServerPlayerInLevel();
|
||||||
|
player.moveTo(pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5);
|
||||||
|
WritingDeskMenu menu = new WritingDeskMenu(1, player.getInventory(), desk);
|
||||||
|
menu.broadcastChanges();
|
||||||
|
helper.assertTrue(menu.getSlot(WritingDeskMenu.COPY_RESULT).getItem().isEmpty(),
|
||||||
|
"An empty selected position must not create a copy");
|
||||||
|
helper.assertTrue(menu.clickMenuButton(player, WritingDeskMenu.PAGE_BUTTON_BASE + 1), "Second page selection must be accepted");
|
||||||
|
menu.broadcastChanges();
|
||||||
|
helper.assertTrue(menu.getSlot(WritingDeskMenu.COPY_RESULT).getItem().is(ModItems.PAGE.get()),
|
||||||
|
"Selecting the populated page must show a copy");
|
||||||
|
helper.succeed();
|
||||||
|
}
|
||||||
|
|
||||||
|
@GameTest(template = "empty")
|
||||||
|
public static void twoViewersCannotTakeTheSameLastSheet(GameTestHelper helper) {
|
||||||
|
BlockPos pos = helper.absolutePos(new BlockPos(1, 1, 1));
|
||||||
|
helper.getLevel().setBlock(pos, ModBlocks.WRITING_DESK.get().defaultBlockState(), 3);
|
||||||
|
WritingDeskBlockEntity desk = (WritingDeskBlockEntity) helper.getLevel().getBlockEntity(pos);
|
||||||
|
desk.setItem(0, PageItem.createLinkPanelPage());
|
||||||
|
desk.setItem(WritingDeskBlockEntity.PAPER, new ItemStack(Items.PAPER));
|
||||||
|
desk.setItem(WritingDeskBlockEntity.INK, new ItemStack(ModItems.INK_VIAL.get()));
|
||||||
|
var first = helper.makeMockServerPlayerInLevel();
|
||||||
|
var second = helper.makeMockServerPlayerInLevel();
|
||||||
|
first.moveTo(pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5);
|
||||||
|
second.moveTo(pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5);
|
||||||
|
WritingDeskMenu firstMenu = new WritingDeskMenu(1, first.getInventory(), desk);
|
||||||
|
WritingDeskMenu secondMenu = new WritingDeskMenu(2, second.getInventory(), desk);
|
||||||
|
firstMenu.broadcastChanges();
|
||||||
|
secondMenu.broadcastChanges();
|
||||||
|
helper.assertTrue(firstMenu.quickMoveStack(first, WritingDeskMenu.COPY_RESULT).is(ModItems.PAGE.get()),
|
||||||
|
"First viewer should take the last available copy");
|
||||||
|
helper.assertTrue(secondMenu.quickMoveStack(second, WritingDeskMenu.COPY_RESULT).isEmpty(),
|
||||||
|
"Second viewer must not copy the already-consumed paper");
|
||||||
|
helper.assertTrue(desk.getItem(WritingDeskBlockEntity.PAPER).isEmpty(),
|
||||||
|
"Shared desk must spend paper only once");
|
||||||
|
helper.succeed();
|
||||||
|
}
|
||||||
|
|
||||||
|
@GameTest(template = "empty")
|
||||||
|
public static void catalogAggregatesKnownSymbolsAcrossCollections(GameTestHelper helper) {
|
||||||
|
BlockPos pos = helper.absolutePos(new BlockPos(1, 1, 1));
|
||||||
|
helper.getLevel().setBlock(pos, ModBlocks.WRITING_DESK.get().defaultBlockState(), 3);
|
||||||
|
WritingDeskBlockEntity desk = (WritingDeskBlockEntity) helper.getLevel().getBlockEntity(pos);
|
||||||
|
ResourceLocation known = ResourceLocation.parse("rivencraft:terrain/standard");
|
||||||
|
ItemStack page = PageItem.createSymbolPage(new SymbolReference(known));
|
||||||
|
ItemStack notebook = new ItemStack(ModItems.NOTEBOOK.get());
|
||||||
|
notebook.set(ModDataComponents.NOTEBOOK_CONTENTS.get(), new NotebookContents(List.of(page.copy())));
|
||||||
|
desk.setItem(0, page);
|
||||||
|
desk.setItem(1, notebook);
|
||||||
|
helper.assertValueEqual(WritingDeskCatalog.available(desk).size(), 1,
|
||||||
|
"Duplicate symbols across loose pages and notebooks must appear once");
|
||||||
|
helper.assertValueEqual(WritingDeskCatalog.available(desk).getFirst().id(), known,
|
||||||
|
"Catalog must retain the authoritative symbol ID");
|
||||||
|
var player = helper.makeMockServerPlayerInLevel();
|
||||||
|
player.moveTo(pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5);
|
||||||
|
WritingDeskMenu menu = new WritingDeskMenu(1, player.getInventory(), desk);
|
||||||
|
helper.assertFalse(menu.clickMenuButton(player, WritingDeskMenu.CATALOG_BUTTON_BASE + 1), "Out-of-range catalog index must be rejected");
|
||||||
|
helper.assertTrue(menu.clickMenuButton(player, WritingDeskMenu.CATALOG_BUTTON_BASE), "Known catalog symbol must be selectable");
|
||||||
|
desk.setItem(WritingDeskBlockEntity.PAPER, new ItemStack(Items.PAPER));
|
||||||
|
desk.setItem(WritingDeskBlockEntity.INK, new ItemStack(ModItems.INK_VIAL.get()));
|
||||||
|
menu.broadcastChanges();
|
||||||
|
helper.assertTrue(menu.getSlot(WritingDeskMenu.COPY_RESULT).getItem().is(ModItems.PAGE.get()),
|
||||||
|
"Catalog selection must preview a copy of the known symbol");
|
||||||
|
desk.setItem(0, ItemStack.EMPTY);
|
||||||
|
desk.setItem(1, ItemStack.EMPTY);
|
||||||
|
menu.broadcastChanges();
|
||||||
|
helper.assertTrue(menu.catalog().isEmpty(), "Removed sources must invalidate catalog for the viewer");
|
||||||
|
helper.assertTrue(menu.getSlot(WritingDeskMenu.COPY_RESULT).getItem().isEmpty(),
|
||||||
|
"Removed sources must invalidate the copy output");
|
||||||
|
helper.succeed();
|
||||||
|
}
|
||||||
|
|
||||||
|
@GameTest(template = "empty")
|
||||||
|
public static void fullInventoryCannotConsumeCopyMaterials(GameTestHelper helper) {
|
||||||
|
BlockPos pos = helper.absolutePos(new BlockPos(1, 1, 1));
|
||||||
|
helper.getLevel().setBlock(pos, ModBlocks.WRITING_DESK.get().defaultBlockState(), 3);
|
||||||
|
WritingDeskBlockEntity desk = (WritingDeskBlockEntity) helper.getLevel().getBlockEntity(pos);
|
||||||
|
desk.setItem(0, PageItem.createLinkPanelPage());
|
||||||
|
desk.setItem(WritingDeskBlockEntity.PAPER, new ItemStack(Items.PAPER));
|
||||||
|
desk.setItem(WritingDeskBlockEntity.INK, new ItemStack(ModItems.INK_VIAL.get()));
|
||||||
|
var player = helper.makeMockServerPlayerInLevel();
|
||||||
|
player.moveTo(pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5);
|
||||||
|
for (int i = 0; i < 36; i++) player.getInventory().setItem(i, new ItemStack(Items.COBBLESTONE, 64));
|
||||||
|
WritingDeskMenu menu = new WritingDeskMenu(1, player.getInventory(), desk);
|
||||||
|
helper.assertTrue(menu.quickMoveStack(player, WritingDeskMenu.COPY_RESULT).isEmpty(),
|
||||||
|
"Full inventory must reject shift-click copy");
|
||||||
|
helper.assertValueEqual(desk.getItem(WritingDeskBlockEntity.PAPER).getCount(), 1,
|
||||||
|
"Rejected copy must preserve paper");
|
||||||
|
helper.assertValueEqual(desk.inkRemaining(), 16, "Rejected copy must preserve the filled ink meter");
|
||||||
|
helper.assertTrue(desk.getItem(WritingDeskBlockEntity.INK).isEmpty(),
|
||||||
|
"The vial should already have refilled the empty meter");
|
||||||
|
helper.succeed();
|
||||||
|
}
|
||||||
|
|
||||||
|
@GameTest(template = "empty")
|
||||||
|
public static void twoBlockDeskSharesOneInventoryAndBreaksTogether(GameTestHelper helper) {
|
||||||
|
BlockPos pos = helper.absolutePos(new BlockPos(1, 1, 1));
|
||||||
|
var block = ModBlocks.WRITING_DESK.get();
|
||||||
|
var state = block.defaultBlockState().setValue(WritingDeskBlock.FACING, Direction.NORTH);
|
||||||
|
helper.getLevel().setBlock(pos, state, 3);
|
||||||
|
block.setPlacedBy(helper.getLevel(), pos, state, null, new ItemStack(block));
|
||||||
|
BlockPos extension = pos.relative(Direction.EAST);
|
||||||
|
helper.assertTrue(helper.getLevel().getBlockState(extension).is(block),
|
||||||
|
"Placing a desk must reserve the adjacent second block");
|
||||||
|
helper.assertTrue(helper.getLevel().getBlockState(extension).getValue(WritingDeskBlock.EXTENSION),
|
||||||
|
"Adjacent half must be marked as an extension");
|
||||||
|
WritingDeskBlockEntity desk = (WritingDeskBlockEntity) helper.getLevel().getBlockEntity(pos);
|
||||||
|
helper.assertTrue(helper.getLevel().getBlockEntity(extension) == null,
|
||||||
|
"Extension must not duplicate the inventory");
|
||||||
|
desk.setItem(WritingDeskBlockEntity.PAPER, new ItemStack(Items.PAPER, 7));
|
||||||
|
helper.getLevel().destroyBlock(extension, true);
|
||||||
|
helper.assertTrue(helper.getLevel().getBlockState(pos).isAir(),
|
||||||
|
"Breaking the extension must remove the controller");
|
||||||
|
var drops = helper.getLevel().getEntitiesOfClass(ItemEntity.class, new AABB(pos).inflate(3));
|
||||||
|
int desks = drops.stream().filter(e -> e.getItem().is(block.asItem()))
|
||||||
|
.mapToInt(e -> e.getItem().getCount()).sum();
|
||||||
|
int paper = drops.stream().filter(e -> e.getItem().is(Items.PAPER))
|
||||||
|
.mapToInt(e -> e.getItem().getCount()).sum();
|
||||||
|
helper.assertValueEqual(desks, 1, "Breaking either half must drop one desk");
|
||||||
|
helper.assertValueEqual(paper, 7, "Breaking either half must drop stored paper once");
|
||||||
|
helper.succeed();
|
||||||
|
}
|
||||||
|
|
||||||
|
@GameTest(template = "empty")
|
||||||
|
public static void breakingControllerRemovesExtensionWithoutDuplicateDesk(GameTestHelper helper) {
|
||||||
|
BlockPos pos = helper.absolutePos(new BlockPos(1, 1, 1));
|
||||||
|
var block = ModBlocks.WRITING_DESK.get();
|
||||||
|
var state = block.defaultBlockState().setValue(WritingDeskBlock.FACING, Direction.NORTH);
|
||||||
|
helper.getLevel().setBlock(pos, state, 3);
|
||||||
|
block.setPlacedBy(helper.getLevel(), pos, state, null, new ItemStack(block));
|
||||||
|
BlockPos extension = pos.relative(Direction.EAST);
|
||||||
|
helper.getLevel().destroyBlock(pos, true);
|
||||||
|
helper.assertTrue(helper.getLevel().getBlockState(extension).isAir(),
|
||||||
|
"Breaking the controller must remove the extension");
|
||||||
|
var drops = helper.getLevel().getEntitiesOfClass(ItemEntity.class, new AABB(pos).inflate(3));
|
||||||
|
int desks = drops.stream().filter(e -> e.getItem().is(block.asItem()))
|
||||||
|
.mapToInt(e -> e.getItem().getCount()).sum();
|
||||||
|
helper.assertValueEqual(desks, 1, "Controller break must drop exactly one desk");
|
||||||
|
helper.succeed();
|
||||||
|
}
|
||||||
|
|
||||||
|
@GameTest(template = "empty")
|
||||||
|
public static void openDeskDoesNotOccludeTerrain(GameTestHelper helper) {
|
||||||
|
helper.assertFalse(ModBlocks.WRITING_DESK.get().defaultBlockState().canOcclude(),
|
||||||
|
"Open shelves must not cull terrain behind the desk");
|
||||||
|
helper.succeed();
|
||||||
|
}
|
||||||
|
|
||||||
|
@GameTest(template = "empty")
|
||||||
|
public static void allPagesSelectionUsesTheRequestedPhysicalTab(GameTestHelper helper) {
|
||||||
|
BlockPos pos = helper.absolutePos(new BlockPos(1, 1, 1));
|
||||||
|
helper.getLevel().setBlock(pos, ModBlocks.WRITING_DESK.get().defaultBlockState(), 3);
|
||||||
|
WritingDeskBlockEntity desk = (WritingDeskBlockEntity) helper.getLevel().getBlockEntity(pos);
|
||||||
|
ItemStack first = PageItem.createLinkPanelPage();
|
||||||
|
ItemStack second = PageItem.createSymbolPage(new SymbolReference(
|
||||||
|
ResourceLocation.parse("rivencraft:terrain/standard")));
|
||||||
|
desk.setItem(0, first);
|
||||||
|
ItemStack notebook = new ItemStack(ModItems.NOTEBOOK.get());
|
||||||
|
notebook.set(ModDataComponents.NOTEBOOK_CONTENTS.get(),
|
||||||
|
new NotebookContents(List.of(ItemStack.EMPTY, second)));
|
||||||
|
desk.setItem(1, notebook);
|
||||||
|
desk.setItem(WritingDeskBlockEntity.PAPER, new ItemStack(Items.PAPER));
|
||||||
|
desk.setItem(WritingDeskBlockEntity.INK, new ItemStack(ModItems.INK_VIAL.get()));
|
||||||
|
var player = helper.makeMockServerPlayerInLevel();
|
||||||
|
player.moveTo(pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5);
|
||||||
|
WritingDeskMenu menu = new WritingDeskMenu(1, player.getInventory(), desk);
|
||||||
|
helper.assertFalse(menu.clickMenuButton(player, WritingDeskMenu.ALL_PAGE_BUTTON_BASE + 2 * NotebookContents.MAX_PAGES),
|
||||||
|
"ALL view must reject empty cross-tab positions");
|
||||||
|
helper.assertTrue(menu.clickMenuButton(player, WritingDeskMenu.ALL_PAGE_BUTTON_BASE + NotebookContents.MAX_PAGES + 1),
|
||||||
|
"ALL view must accept the populated second tab page");
|
||||||
|
helper.assertTrue(ItemStack.matches(menu.getSlot(WritingDeskMenu.COPY_RESULT).getItem(), second),
|
||||||
|
"Copy preview must match the physical page selected from the other tab");
|
||||||
|
helper.assertValueEqual(desk.activeCollection(), 0,
|
||||||
|
"Selecting from ALL must not silently change the active tab");
|
||||||
|
helper.succeed();
|
||||||
|
}
|
||||||
|
|
||||||
|
@GameTest(template = "empty")
|
||||||
|
public static void tabGroupsCycleByFourAndProtectHiddenSlots(GameTestHelper helper) {
|
||||||
|
BlockPos pos = helper.absolutePos(new BlockPos(1, 1, 1));
|
||||||
|
helper.getLevel().setBlock(pos, ModBlocks.WRITING_DESK.get().defaultBlockState(), 3);
|
||||||
|
var desk = (WritingDeskBlockEntity) helper.getLevel().getBlockEntity(pos);
|
||||||
|
var player = helper.makeMockServerPlayerInLevel();
|
||||||
|
player.moveTo(pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5);
|
||||||
|
var menu = new WritingDeskMenu(1, player.getInventory(), desk);
|
||||||
|
var otherViewer = new WritingDeskMenu(2, player.getInventory(), desk);
|
||||||
|
menu.clickMenuButton(player, WritingDeskMenu.PREVIOUS_TABS);
|
||||||
|
helper.assertValueEqual(menu.firstVisibleTab(), 0, "Previous must stop at tabs 1-4");
|
||||||
|
menu.clickMenuButton(player, WritingDeskMenu.NEXT_TABS);
|
||||||
|
helper.assertValueEqual(menu.firstVisibleTab(), 4, "Next must show tabs 5-8");
|
||||||
|
helper.assertValueEqual(otherViewer.firstVisibleTab(), 0, "Cycling must not move another viewer's slots");
|
||||||
|
helper.assertFalse(menu.getSlot(0).isActive(), "Earlier tab slots must be hidden");
|
||||||
|
helper.assertTrue(menu.getSlot(4).isActive(), "New group's slots must be interactive");
|
||||||
|
desk.setItem(0, new ItemStack(ModItems.NOTEBOOK.get()));
|
||||||
|
menu.clicked(0, 0, ClickType.PICKUP, player);
|
||||||
|
helper.assertTrue(menu.getCarried().isEmpty(), "Hidden slot clicks must not take items");
|
||||||
|
helper.assertTrue(menu.quickMoveStack(player, 0).isEmpty(), "Hidden shift-click must be rejected");
|
||||||
|
player.getInventory().setItem(9, new ItemStack(ModItems.NOTEBOOK.get()));
|
||||||
|
menu.quickMoveStack(player, WritingDeskMenu.COPY_RESULT + 1);
|
||||||
|
helper.assertTrue(desk.getItem(4).is(ModItems.NOTEBOOK.get()), "Shift-click must use the visible group");
|
||||||
|
for (int i = 0; i < 30; i++) menu.clickMenuButton(player, WritingDeskMenu.NEXT_TABS);
|
||||||
|
helper.assertValueEqual(menu.firstVisibleTab(), 84, "Last group must be tabs 85-88");
|
||||||
|
helper.assertTrue(menu.clickMenuButton(player, 87), "Tab 88 must be selectable without page-ID collisions");
|
||||||
|
helper.assertValueEqual(desk.activeCollection(), 87, "Tab 88 must become active");
|
||||||
|
helper.assertFalse(menu.clickMenuButton(player, 88), "Tab 89 must not exist");
|
||||||
|
desk.setItem(87, PageItem.createLinkPanelPage());
|
||||||
|
desk.setItem(WritingDeskBlockEntity.PAPER, new ItemStack(Items.PAPER));
|
||||||
|
desk.setItem(WritingDeskBlockEntity.INK, new ItemStack(ModItems.INK_VIAL.get()));
|
||||||
|
helper.assertTrue(menu.clickMenuButton(player, WritingDeskMenu.ALL_PAGE_BUTTON_BASE + 87 * NotebookContents.MAX_PAGES),
|
||||||
|
"ALL must select a physical page from tab 88");
|
||||||
|
helper.assertTrue(menu.quickMoveStack(player, WritingDeskMenu.COPY_RESULT).is(ModItems.PAGE.get()),
|
||||||
|
"Tab 88's page must be copyable");
|
||||||
|
menu.clickMenuButton(player, WritingDeskMenu.PREVIOUS_TABS);
|
||||||
|
helper.assertValueEqual(menu.firstVisibleTab(), 80, "Previous must move back four tabs");
|
||||||
|
helper.succeed();
|
||||||
|
}
|
||||||
|
|
||||||
|
@GameTest(template = "empty")
|
||||||
|
public static void oldDeskInventoryMigratesAndAll88TabsPersist(GameTestHelper helper) {
|
||||||
|
BlockPos pos = helper.absolutePos(new BlockPos(1, 1, 1));
|
||||||
|
var registries = helper.getLevel().registryAccess();
|
||||||
|
var oldItems = net.minecraft.core.NonNullList.withSize(8, ItemStack.EMPTY);
|
||||||
|
oldItems.set(0, new ItemStack(ModItems.NOTEBOOK.get()));
|
||||||
|
oldItems.set(3, PageItem.createLinkPanelPage());
|
||||||
|
oldItems.set(4, new ItemStack(ModItems.INK_VIAL.get(), 2));
|
||||||
|
oldItems.set(5, new ItemStack(Items.GLASS_BOTTLE, 3));
|
||||||
|
oldItems.set(6, new ItemStack(Items.PAPER, 12));
|
||||||
|
oldItems.set(7, PageItem.createLinkPanelPage());
|
||||||
|
var oldTag = new net.minecraft.nbt.CompoundTag();
|
||||||
|
net.minecraft.world.ContainerHelper.saveAllItems(oldTag, oldItems, registries);
|
||||||
|
oldTag.putInt("InkRemaining", 7);
|
||||||
|
oldTag.putInt("ActiveCollection", 3);
|
||||||
|
var desk = new WritingDeskBlockEntity(pos, ModBlocks.WRITING_DESK.get().defaultBlockState());
|
||||||
|
desk.loadWithComponents(oldTag, registries);
|
||||||
|
for (int i = 0; i < 4; i++) {
|
||||||
|
helper.assertTrue(ItemStack.matches(desk.getItem(i), oldItems.get(i)), "Original tab must survive migration");
|
||||||
|
helper.assertTrue(ItemStack.matches(desk.getItem(WritingDeskBlockEntity.INK + i), oldItems.get(4 + i)),
|
||||||
|
"Original supplies and legacy output must survive migration");
|
||||||
|
helper.assertTrue(desk.getItem(4 + i).isEmpty(), "Supplies must not be duplicated into new tabs");
|
||||||
|
}
|
||||||
|
helper.assertValueEqual(desk.inkRemaining(), 7, "Migration must preserve ink meter");
|
||||||
|
helper.assertValueEqual(desk.activeCollection(), 3, "Migration must preserve active tab");
|
||||||
|
for (int i = 0; i < WritingDeskBlockEntity.COLLECTIONS; i++) desk.setItem(i, PageItem.createLinkPanelPage());
|
||||||
|
desk.setActiveCollection(87);
|
||||||
|
var restored = new WritingDeskBlockEntity(pos, ModBlocks.WRITING_DESK.get().defaultBlockState());
|
||||||
|
restored.loadWithComponents(desk.saveWithoutMetadata(registries), registries);
|
||||||
|
for (int i = 0; i < WritingDeskBlockEntity.COLLECTIONS; i++)
|
||||||
|
helper.assertTrue(restored.getItem(i).is(ModItems.PAGE.get()), "All 88 tab contents must survive save/load");
|
||||||
|
helper.assertValueEqual(restored.activeCollection(), 87, "Tab 88 selection must survive save/load");
|
||||||
|
helper.assertValueEqual(restored.getItem(WritingDeskBlockEntity.PAPER).getCount(), 12, "Reload must not repeat migration");
|
||||||
|
helper.succeed();
|
||||||
|
}
|
||||||
|
|
||||||
|
@GameTest(template = "empty")
|
||||||
|
public static void surfacePlacesCarriedPagesWithoutLossOrOverwrite(GameTestHelper helper) {
|
||||||
|
BlockPos pos = helper.absolutePos(new BlockPos(1, 1, 1));
|
||||||
|
helper.getLevel().setBlock(pos, ModBlocks.WRITING_DESK.get().defaultBlockState(), 3);
|
||||||
|
var desk = (WritingDeskBlockEntity) helper.getLevel().getBlockEntity(pos);
|
||||||
|
desk.setItem(87, new ItemStack(ModItems.NOTEBOOK.get()));
|
||||||
|
var player = helper.makeMockServerPlayerInLevel();
|
||||||
|
player.moveTo(pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5);
|
||||||
|
var menu = new WritingDeskMenu(1, player.getInventory(), desk);
|
||||||
|
ItemStack held = PageItem.createLinkPanelPage().copyWithCount(3);
|
||||||
|
ItemStack expectedPage = held.copyWithCount(1);
|
||||||
|
player.getInventory().setItem(9, held);
|
||||||
|
menu.clicked(WritingDeskMenu.COPY_RESULT + 1, 0, ClickType.PICKUP, player);
|
||||||
|
int lastPosition = WritingDeskMenu.PLACE_PAGE_BUTTON_BASE + 87 * NotebookContents.MAX_PAGES + 26;
|
||||||
|
helper.assertTrue(menu.clickMenuButton(player, lastPosition), "Surface must place into final notebook position");
|
||||||
|
helper.assertValueEqual(menu.getCarried().getCount(), 2, "Placing must consume exactly one held page");
|
||||||
|
var pages = desk.getItem(87).get(ModDataComponents.NOTEBOOK_CONTENTS.get()).pages();
|
||||||
|
helper.assertValueEqual(pages.size(), 27, "Placement must preserve addressed position");
|
||||||
|
helper.assertTrue(pages.get(0).isEmpty() && pages.get(25).isEmpty(), "Placement must preserve preceding gaps");
|
||||||
|
helper.assertTrue(ItemStack.matches(pages.get(26), expectedPage), "Stored page must preserve components");
|
||||||
|
helper.assertFalse(menu.clickMenuButton(player, lastPosition), "Occupied position must not be overwritten");
|
||||||
|
helper.assertValueEqual(menu.getCarried().getCount(), 2, "Rejected placement must preserve cursor");
|
||||||
|
helper.assertFalse(menu.clickMenuButton(player, WritingDeskMenu.PLACE_PAGE_BUTTON_BASE + 88 * NotebookContents.MAX_PAGES),
|
||||||
|
"Out-of-range placement must be rejected");
|
||||||
|
helper.assertValueEqual(menu.pageCapacity(87), NotebookContents.MAX_PAGES, "Notebook tab must expose normal notebook capacity");
|
||||||
|
helper.assertValueEqual(menu.pageCapacity(0), 0, "Empty tab has no page storage");
|
||||||
|
helper.assertFalse(menu.clickMenuButton(player, WritingDeskMenu.PLACE_PAGE_BUTTON_BASE), "Empty tab must require a collection first");
|
||||||
|
desk.setItem(0, PageItem.createLinkPanelPage());
|
||||||
|
helper.assertValueEqual(menu.pageCapacity(0), 1, "Loose page tab must expose exactly one position");
|
||||||
|
helper.assertFalse(menu.clickMenuButton(player, WritingDeskMenu.PLACE_PAGE_BUTTON_BASE), "Loose page must not be replaced");
|
||||||
|
helper.assertFalse(menu.clickMenuButton(player, WritingDeskMenu.PLACE_PAGE_BUTTON_BASE + 1), "Loose page tab must not grow extra positions");
|
||||||
|
helper.assertValueEqual(menu.getCarried().getCount(), 2, "Rejected placements must preserve cursor");
|
||||||
|
helper.assertTrue(menu.clickMenuButton(player, lastPosition - 1), "A second empty notebook position must accept a page");
|
||||||
|
helper.assertTrue(menu.clickMenuButton(player, lastPosition - 2), "A third empty notebook position must accept the last page");
|
||||||
|
helper.assertTrue(menu.getCarried().isEmpty(), "Final placement must clear cursor");
|
||||||
|
menu.setCarried(new ItemStack(Items.DIAMOND));
|
||||||
|
helper.assertFalse(menu.clickMenuButton(player, lastPosition - 3), "Non-page items must be rejected");
|
||||||
|
helper.assertTrue(menu.getCarried().is(Items.DIAMOND), "Rejected item must remain held");
|
||||||
|
var restored = new WritingDeskBlockEntity(pos, ModBlocks.WRITING_DESK.get().defaultBlockState());
|
||||||
|
restored.loadWithComponents(desk.saveWithoutMetadata(helper.getLevel().registryAccess()), helper.getLevel().registryAccess());
|
||||||
|
helper.assertValueEqual(restored.getItem(87).get(ModDataComponents.NOTEBOOK_CONTENTS.get()).pageCount(), 3,
|
||||||
|
"Placed pages must persist in the notebook");
|
||||||
|
helper.succeed();
|
||||||
|
}
|
||||||
|
|
||||||
|
@GameTest(template = "empty")
|
||||||
|
public static void deskSurfaceDragMovesAndSwapsNotebookPages(GameTestHelper helper) {
|
||||||
|
BlockPos pos = helper.absolutePos(new BlockPos(1, 1, 1));
|
||||||
|
helper.getLevel().setBlock(pos, ModBlocks.WRITING_DESK.get().defaultBlockState(), 3);
|
||||||
|
var desk = (WritingDeskBlockEntity) helper.getLevel().getBlockEntity(pos);
|
||||||
|
ItemStack linkPanel = PageItem.createLinkPanelPage();
|
||||||
|
ItemStack terrain = PageItem.createSymbolPage(new SymbolReference(
|
||||||
|
ResourceLocation.parse("rivencraft:terrain/standard")));
|
||||||
|
ItemStack firstBook = new ItemStack(ModItems.NOTEBOOK.get());
|
||||||
|
firstBook.set(ModDataComponents.NOTEBOOK_CONTENTS.get(), new NotebookContents(List.of(linkPanel, terrain)));
|
||||||
|
desk.setItem(0, firstBook);
|
||||||
|
desk.setItem(1, new ItemStack(ModItems.NOTEBOOK.get()));
|
||||||
|
desk.setItem(2, PageItem.createLinkPanelPage());
|
||||||
|
var player = helper.makeMockServerPlayerInLevel();
|
||||||
|
player.moveTo(pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5);
|
||||||
|
var menu = new WritingDeskMenu(1, player.getInventory(), desk);
|
||||||
|
int moveToEmpty = WritingDeskMenu.movePageButtonId(0, 0, 0, 26);
|
||||||
|
helper.assertTrue(menu.clickMenuButton(player, moveToEmpty), "Drag must move to a distant empty notebook position");
|
||||||
|
var pages = desk.getItem(0).get(ModDataComponents.NOTEBOOK_CONTENTS.get()).pages();
|
||||||
|
helper.assertTrue(pages.get(0).isEmpty(), "Moving must clear the source position");
|
||||||
|
helper.assertTrue(ItemStack.matches(pages.get(26), linkPanel), "Moving must preserve page components");
|
||||||
|
helper.assertValueEqual(desk.getItem(0).get(ModDataComponents.NOTEBOOK_CONTENTS.get()).pageCount(), 2,
|
||||||
|
"Moving must preserve total page count");
|
||||||
|
helper.assertTrue(menu.clickMenuButton(player, WritingDeskMenu.movePageButtonId(0, 26, 0, 1)),
|
||||||
|
"Drag onto an occupied position must swap pages");
|
||||||
|
pages = desk.getItem(0).get(ModDataComponents.NOTEBOOK_CONTENTS.get()).pages();
|
||||||
|
helper.assertTrue(ItemStack.matches(pages.get(1), linkPanel) && ItemStack.matches(pages.get(26), terrain),
|
||||||
|
"Swap must preserve both pages");
|
||||||
|
helper.assertTrue(menu.clickMenuButton(player, WritingDeskMenu.movePageButtonId(0, 1, 1, 5)),
|
||||||
|
"Drag into another notebook must work");
|
||||||
|
var otherPages = desk.getItem(1).get(ModDataComponents.NOTEBOOK_CONTENTS.get()).pages();
|
||||||
|
helper.assertTrue(ItemStack.matches(otherPages.get(5), linkPanel)
|
||||||
|
&& desk.getItem(0).get(ModDataComponents.NOTEBOOK_CONTENTS.get()).pages().get(1).isEmpty(),
|
||||||
|
"Cross notebook move must have one destination and no old source");
|
||||||
|
helper.assertFalse(menu.clickMenuButton(player, WritingDeskMenu.movePageButtonId(0, 1, 1, 6)),
|
||||||
|
"Dragging an empty source must be rejected");
|
||||||
|
helper.assertTrue(menu.clickMenuButton(player, WritingDeskMenu.movePageButtonId(2, 0, 1, 6)),
|
||||||
|
"A loose page should move into a notebook position");
|
||||||
|
helper.assertTrue(desk.getItem(2).isEmpty()
|
||||||
|
&& desk.getItem(1).get(ModDataComponents.NOTEBOOK_CONTENTS.get()).pages().get(6).is(ModItems.PAGE.get()),
|
||||||
|
"Moving a loose page must empty its tab without losing the item");
|
||||||
|
helper.assertFalse(menu.clickMenuButton(player, WritingDeskMenu.movePageButtonId(1, 5, 1, 5)),
|
||||||
|
"A no-op drag must be rejected");
|
||||||
|
menu.setCarried(new ItemStack(Items.DIAMOND));
|
||||||
|
helper.assertFalse(menu.clickMenuButton(player, WritingDeskMenu.movePageButtonId(1, 5, 1, 6)),
|
||||||
|
"Held inventory items must not be moved by a panel drag");
|
||||||
|
helper.assertTrue(ItemStack.matches(desk.getItem(1).get(ModDataComponents.NOTEBOOK_CONTENTS.get()).pages().get(5), linkPanel),
|
||||||
|
"Rejected drags must leave notebook data intact");
|
||||||
|
helper.succeed();
|
||||||
|
}
|
||||||
|
|
||||||
|
@GameTest(template = "empty")
|
||||||
|
public static void deskSurfaceDragExtractsPagesToInventoryAndTabs(GameTestHelper helper) {
|
||||||
|
BlockPos pos = helper.absolutePos(new BlockPos(1, 1, 1));
|
||||||
|
helper.getLevel().setBlock(pos, ModBlocks.WRITING_DESK.get().defaultBlockState(), 3);
|
||||||
|
var desk = (WritingDeskBlockEntity) helper.getLevel().getBlockEntity(pos);
|
||||||
|
ItemStack page = PageItem.createLinkPanelPage();
|
||||||
|
ItemStack source = new ItemStack(ModItems.NOTEBOOK.get());
|
||||||
|
source.set(ModDataComponents.NOTEBOOK_CONTENTS.get(),
|
||||||
|
new NotebookContents(List.of(page, page, page, page, page, page)));
|
||||||
|
desk.setItem(0, source);
|
||||||
|
ItemStack otherBook = new ItemStack(ModItems.NOTEBOOK.get());
|
||||||
|
ItemStack terrain = PageItem.createSymbolPage(new SymbolReference(
|
||||||
|
ResourceLocation.parse("rivencraft:terrain/standard")));
|
||||||
|
otherBook.set(ModDataComponents.NOTEBOOK_CONTENTS.get(), new NotebookContents(List.of(terrain)));
|
||||||
|
desk.setItem(2, otherBook);
|
||||||
|
var player = helper.makeMockServerPlayerInLevel();
|
||||||
|
player.moveTo(pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5);
|
||||||
|
player.getInventory().setItem(10, page.copyWithCount(2));
|
||||||
|
var menu = new WritingDeskMenu(1, player.getInventory(), desk);
|
||||||
|
int inventoryStart = WritingDeskMenu.COPY_RESULT + 1;
|
||||||
|
|
||||||
|
helper.assertTrue(menu.clickMenuButton(player, WritingDeskMenu.extractPageButtonId(0, 0, -1)),
|
||||||
|
"Dropping away from a slot must return the page to the cursor");
|
||||||
|
helper.assertTrue(ItemStack.matches(menu.getCarried(), page), "Cursor must hold the original page item");
|
||||||
|
helper.assertFalse(menu.clickMenuButton(player, WritingDeskMenu.extractPageButtonId(0, 1, inventoryStart)),
|
||||||
|
"Extraction must not replace an occupied cursor");
|
||||||
|
menu.setCarried(ItemStack.EMPTY);
|
||||||
|
helper.assertTrue(menu.clickMenuButton(player, WritingDeskMenu.extractPageButtonId(0, 1, inventoryStart)),
|
||||||
|
"Dropping on player inventory must transfer a page");
|
||||||
|
helper.assertTrue(ItemStack.matches(player.getInventory().getItem(9), page),
|
||||||
|
"Transferred page must retain its components");
|
||||||
|
helper.assertTrue(menu.clickMenuButton(player, WritingDeskMenu.extractPageButtonId(0, 2, 1)),
|
||||||
|
"Dropping on an empty tab must store a loose page");
|
||||||
|
helper.assertTrue(ItemStack.matches(desk.getItem(1), page), "Tab must hold the extracted page");
|
||||||
|
helper.assertTrue(menu.clickMenuButton(player, WritingDeskMenu.extractPageButtonId(0, 3, 2)),
|
||||||
|
"Dropping on a notebook tab must insert the page");
|
||||||
|
var otherPages = desk.getItem(2).get(ModDataComponents.NOTEBOOK_CONTENTS.get()).pages();
|
||||||
|
helper.assertTrue(ItemStack.matches(otherPages.get(0), terrain)
|
||||||
|
&& ItemStack.matches(otherPages.get(1), page), "Notebook drop must preserve existing pages");
|
||||||
|
helper.assertTrue(menu.clickMenuButton(player, WritingDeskMenu.extractPageButtonId(0, 4, inventoryStart + 1)),
|
||||||
|
"Dropping on a matching inventory stack must merge one page");
|
||||||
|
helper.assertValueEqual(player.getInventory().getItem(10).getCount(), 3, "Merge must add exactly one page");
|
||||||
|
helper.assertFalse(menu.clickMenuButton(player, WritingDeskMenu.extractPageButtonId(0, 5, 1)),
|
||||||
|
"Occupied loose-page tabs must reject a drop");
|
||||||
|
helper.assertFalse(menu.clickMenuButton(player, WritingDeskMenu.extractPageButtonId(0, 5, WritingDeskBlockEntity.INK)),
|
||||||
|
"Ink slot must not accept an extracted page");
|
||||||
|
helper.assertValueEqual(desk.getItem(0).get(ModDataComponents.NOTEBOOK_CONTENTS.get()).pageCount(), 1,
|
||||||
|
"Rejected drops must leave the remaining source page in the notebook");
|
||||||
|
helper.assertTrue(menu.clickMenuButton(player, WritingDeskMenu.extractPageButtonId(1, 0, -1)),
|
||||||
|
"A loose page shown on the panel must be draggable back to the cursor");
|
||||||
|
helper.assertTrue(desk.getItem(1).isEmpty() && ItemStack.matches(menu.getCarried(), page),
|
||||||
|
"Extracting a loose page must empty its tab and return the same item");
|
||||||
|
helper.succeed();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,47 @@
|
|||||||
|
package net.dnorberg.rivencraft.item;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import net.dnorberg.rivencraft.registry.ModDataComponents;
|
||||||
|
import net.dnorberg.rivencraft.writing.WritingInkService;
|
||||||
|
import net.minecraft.ChatFormatting;
|
||||||
|
import net.minecraft.network.chat.Component;
|
||||||
|
import net.minecraft.world.InteractionHand;
|
||||||
|
import net.minecraft.world.InteractionResultHolder;
|
||||||
|
import net.minecraft.world.entity.player.Player;
|
||||||
|
import net.minecraft.world.item.Item;
|
||||||
|
import net.minecraft.world.item.ItemStack;
|
||||||
|
import net.minecraft.world.item.TooltipFlag;
|
||||||
|
import net.minecraft.world.level.Level;
|
||||||
|
|
||||||
|
/** A stackable vial; the ink component is per vial, not shared across a stack. */
|
||||||
|
public final class InkVialItem extends Item {
|
||||||
|
public static final int CAPACITY = 16;
|
||||||
|
|
||||||
|
public InkVialItem(Properties properties) {
|
||||||
|
super(properties);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int remaining(ItemStack vial) {
|
||||||
|
return vial.getOrDefault(ModDataComponents.INK_REMAINING.get(), CAPACITY);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public InteractionResultHolder<ItemStack> use(Level level, Player player, InteractionHand hand) {
|
||||||
|
if (!WritingInkService.canPrepareLinkPanel(player, hand)) {
|
||||||
|
return InteractionResultHolder.pass(player.getItemInHand(hand));
|
||||||
|
}
|
||||||
|
if (!level.isClientSide) {
|
||||||
|
WritingInkService.prepareLinkPanel(player, hand);
|
||||||
|
}
|
||||||
|
return InteractionResultHolder.sidedSuccess(player.getItemInHand(hand), level.isClientSide);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void appendHoverText(ItemStack stack, TooltipContext context,
|
||||||
|
List<Component> tooltip, TooltipFlag flag) {
|
||||||
|
tooltip.add(Component.translatable("item.rivencraft.ink_vial.remaining",
|
||||||
|
remaining(stack), CAPACITY).withStyle(ChatFormatting.GRAY));
|
||||||
|
tooltip.add(Component.translatable("item.rivencraft.ink_vial.usage")
|
||||||
|
.withStyle(ChatFormatting.GRAY));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,48 @@
|
|||||||
|
package net.dnorberg.rivencraft.item;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import net.dnorberg.rivencraft.menu.NotebookMenu;
|
||||||
|
import net.dnorberg.rivencraft.registry.ModDataComponents;
|
||||||
|
import net.dnorberg.rivencraft.writing.NotebookContents;
|
||||||
|
import net.minecraft.ChatFormatting;
|
||||||
|
import net.minecraft.network.chat.Component;
|
||||||
|
import net.minecraft.server.level.ServerPlayer;
|
||||||
|
import net.minecraft.world.InteractionHand;
|
||||||
|
import net.minecraft.world.InteractionResultHolder;
|
||||||
|
import net.minecraft.world.SimpleMenuProvider;
|
||||||
|
import net.minecraft.world.entity.player.Player;
|
||||||
|
import net.minecraft.world.item.Item;
|
||||||
|
import net.minecraft.world.item.ItemStack;
|
||||||
|
import net.minecraft.world.item.TooltipFlag;
|
||||||
|
import net.minecraft.world.level.Level;
|
||||||
|
|
||||||
|
public final class NotebookItem extends Item {
|
||||||
|
public NotebookItem(Properties properties) {
|
||||||
|
super(properties);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public InteractionResultHolder<ItemStack> use(Level level, Player player, InteractionHand hand) {
|
||||||
|
ItemStack notebook = player.getItemInHand(hand);
|
||||||
|
if (!level.isClientSide && player instanceof ServerPlayer serverPlayer) {
|
||||||
|
serverPlayer.openMenu(new SimpleMenuProvider(
|
||||||
|
(containerId, inventory, ignored) -> new NotebookMenu(containerId, inventory, hand),
|
||||||
|
notebook.getHoverName()),
|
||||||
|
buffer -> buffer.writeBoolean(hand == InteractionHand.OFF_HAND));
|
||||||
|
}
|
||||||
|
return InteractionResultHolder.sidedSuccess(notebook, level.isClientSide);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void appendHoverText(ItemStack stack, TooltipContext context,
|
||||||
|
List<Component> tooltip, TooltipFlag flag) {
|
||||||
|
NotebookContents contents = stack.getOrDefault(
|
||||||
|
ModDataComponents.NOTEBOOK_CONTENTS.get(), NotebookContents.EMPTY);
|
||||||
|
tooltip.add(Component.translatable("item.rivencraft.notebook.pages",
|
||||||
|
contents.pageCount(), NotebookContents.MAX_PAGES).withStyle(ChatFormatting.GRAY));
|
||||||
|
if (contents.unresolvedCount() > 0) {
|
||||||
|
tooltip.add(Component.translatable("item.rivencraft.notebook.unresolved",
|
||||||
|
contents.unresolvedCount()).withStyle(ChatFormatting.RED));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,135 @@
|
|||||||
|
package net.dnorberg.rivencraft.item;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import net.dnorberg.rivencraft.registry.ModDataComponents;
|
||||||
|
import net.dnorberg.rivencraft.registry.ModItems;
|
||||||
|
import net.dnorberg.rivencraft.writing.PageContent;
|
||||||
|
import net.dnorberg.rivencraft.writing.SymbolCatalog;
|
||||||
|
import net.dnorberg.rivencraft.writing.SymbolDisplayMetadata;
|
||||||
|
import net.dnorberg.rivencraft.writing.SymbolReference;
|
||||||
|
import net.minecraft.ChatFormatting;
|
||||||
|
import net.minecraft.core.component.DataComponents;
|
||||||
|
import net.minecraft.network.chat.Component;
|
||||||
|
import net.minecraft.world.item.component.CustomModelData;
|
||||||
|
import net.minecraft.world.item.Item;
|
||||||
|
import net.minecraft.world.item.ItemStack;
|
||||||
|
import net.minecraft.world.item.TooltipFlag;
|
||||||
|
|
||||||
|
/** One stackable Page item whose server-owned component identifies its writing state. */
|
||||||
|
public final class PageItem extends Item {
|
||||||
|
public PageItem(Properties properties) {
|
||||||
|
super(properties);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ItemStack createSymbolPage(SymbolReference reference) {
|
||||||
|
if (!SymbolCatalog.isKnown(reference)) {
|
||||||
|
throw new IllegalArgumentException("Cannot create a page for unknown symbol " + reference.id());
|
||||||
|
}
|
||||||
|
return create(PageContent.symbol(reference));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ItemStack createLinkPanelPage() {
|
||||||
|
return create(PageContent.LINK_PANEL);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Restores saved unknown references without granting them validity for new writing operations. */
|
||||||
|
public static ItemStack createRecoveredPage(SymbolReference reference) {
|
||||||
|
return create(PageContent.unresolved(reference));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static PageContent content(ItemStack stack) {
|
||||||
|
PageContent content = stack.get(ModDataComponents.PAGE_CONTENT.get());
|
||||||
|
return content == null ? PageContent.BLANK : content;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Server-side gate for Desk and Binder inputs; unresolved pages remain removable but not usable. */
|
||||||
|
public static boolean isUsableWriting(ItemStack stack) {
|
||||||
|
if (!stack.is(ModItems.PAGE.get())) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
PageContent resolved = content(stack).resolve();
|
||||||
|
return resolved.kind() == PageContent.Kind.BLANK
|
||||||
|
|| resolved.kind() == PageContent.Kind.LINK_PANEL
|
||||||
|
|| resolved.isResolvedSymbol();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Component getName(ItemStack stack) {
|
||||||
|
Component customName = stack.get(DataComponents.CUSTOM_NAME);
|
||||||
|
if (customName != null) {
|
||||||
|
return customName;
|
||||||
|
}
|
||||||
|
PageContent content = content(stack);
|
||||||
|
return switch (content.kind()) {
|
||||||
|
case BLANK -> Component.translatable("item.rivencraft.page.blank");
|
||||||
|
case LINK_PANEL -> Component.translatable("item.rivencraft.page.link_panel");
|
||||||
|
case UNRESOLVED_SYMBOL -> Component.translatable("item.rivencraft.page.unresolved");
|
||||||
|
case SYMBOL -> symbolName(stack, content.symbol().orElseThrow());
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void appendHoverText(ItemStack stack, TooltipContext context,
|
||||||
|
List<Component> tooltipComponents, TooltipFlag tooltipFlag) {
|
||||||
|
PageContent content = content(stack);
|
||||||
|
if (content.kind() == PageContent.Kind.BLANK) {
|
||||||
|
tooltipComponents.add(Component.translatable("item.rivencraft.page.blank.description")
|
||||||
|
.withStyle(ChatFormatting.GRAY));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (content.kind() == PageContent.Kind.LINK_PANEL) {
|
||||||
|
tooltipComponents.add(Component.translatable("item.rivencraft.page.link_panel.description")
|
||||||
|
.withStyle(ChatFormatting.GRAY));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
SymbolReference reference = content.symbol().orElseThrow();
|
||||||
|
SymbolDisplayMetadata metadata = content.kind() == PageContent.Kind.SYMBOL
|
||||||
|
? stack.getOrDefault(ModDataComponents.PAGE_SYMBOL_DISPLAY.get(), SymbolCatalog.display(reference))
|
||||||
|
: SymbolDisplayMetadata.unresolved(reference);
|
||||||
|
if (metadata.resolved()) {
|
||||||
|
tooltipComponents.add(Component.translatable(metadata.descriptionTranslationKey())
|
||||||
|
.withStyle(ChatFormatting.GRAY));
|
||||||
|
} else {
|
||||||
|
tooltipComponents.add(Component.translatable(
|
||||||
|
"symbol.rivencraft.unresolved.description", reference.unresolvedName())
|
||||||
|
.withStyle(ChatFormatting.RED));
|
||||||
|
}
|
||||||
|
tooltipComponents.add(Component.literal(reference.id().toString()).withStyle(ChatFormatting.DARK_GRAY));
|
||||||
|
}
|
||||||
|
|
||||||
|
private static ItemStack create(PageContent content) {
|
||||||
|
ItemStack stack = new ItemStack(ModItems.PAGE.get());
|
||||||
|
stack.set(ModDataComponents.PAGE_CONTENT.get(), content);
|
||||||
|
stack.set(DataComponents.CUSTOM_MODEL_DATA, new CustomModelData(modelIndex(content)));
|
||||||
|
if (content.kind() == PageContent.Kind.SYMBOL) {
|
||||||
|
stack.set(ModDataComponents.PAGE_SYMBOL_DISPLAY.get(),
|
||||||
|
SymbolCatalog.display(content.symbol().orElseThrow()));
|
||||||
|
}
|
||||||
|
return stack;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Component symbolName(ItemStack stack, SymbolReference reference) {
|
||||||
|
SymbolDisplayMetadata metadata = stack.getOrDefault(
|
||||||
|
ModDataComponents.PAGE_SYMBOL_DISPLAY.get(), SymbolCatalog.display(reference));
|
||||||
|
return metadata.resolved()
|
||||||
|
? Component.translatable(metadata.nameTranslationKey())
|
||||||
|
: Component.translatable("item.rivencraft.page.unresolved");
|
||||||
|
}
|
||||||
|
|
||||||
|
private static int modelIndex(PageContent content) {
|
||||||
|
return switch (content.kind()) {
|
||||||
|
case BLANK -> 0;
|
||||||
|
case LINK_PANEL -> 1;
|
||||||
|
case UNRESOLVED_SYMBOL -> 2;
|
||||||
|
case SYMBOL -> switch (content.symbol().orElseThrow().id().toString()) {
|
||||||
|
case "rivencraft:terrain/standard" -> 100;
|
||||||
|
case "rivencraft:biome/native" -> 101;
|
||||||
|
case "rivencraft:lighting/normal" -> 102;
|
||||||
|
case "rivencraft:weather/normal" -> 103;
|
||||||
|
case "rivencraft:celestial/normal_time" -> 104;
|
||||||
|
case "rivencraft:feature/caves" -> 105;
|
||||||
|
default -> 3;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,194 @@
|
|||||||
|
package net.dnorberg.rivencraft.menu;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import net.dnorberg.rivencraft.registry.ModDataComponents;
|
||||||
|
import net.dnorberg.rivencraft.registry.ModItems;
|
||||||
|
import net.dnorberg.rivencraft.registry.ModMenus;
|
||||||
|
import net.dnorberg.rivencraft.writing.NotebookContents;
|
||||||
|
import net.minecraft.core.NonNullList;
|
||||||
|
import net.minecraft.network.RegistryFriendlyByteBuf;
|
||||||
|
import net.minecraft.world.Container;
|
||||||
|
import net.minecraft.world.InteractionHand;
|
||||||
|
import net.minecraft.world.SimpleContainer;
|
||||||
|
import net.minecraft.world.entity.player.Inventory;
|
||||||
|
import net.minecraft.world.entity.player.Player;
|
||||||
|
import net.minecraft.world.inventory.AbstractContainerMenu;
|
||||||
|
import net.minecraft.world.inventory.ClickType;
|
||||||
|
import net.minecraft.world.inventory.Slot;
|
||||||
|
import net.minecraft.world.item.ItemStack;
|
||||||
|
|
||||||
|
public final class NotebookMenu extends AbstractContainerMenu {
|
||||||
|
public static final int NOTEBOOK_SLOTS = NotebookContents.MAX_PAGES;
|
||||||
|
public static final int MOVE_PREVIOUS_BASE = 0;
|
||||||
|
public static final int MOVE_NEXT_BASE = NOTEBOOK_SLOTS;
|
||||||
|
private static final int PLAYER_INVENTORY_START = NOTEBOOK_SLOTS;
|
||||||
|
private final Inventory playerInventory;
|
||||||
|
private final InteractionHand hand;
|
||||||
|
private final int openedHotbarSlot;
|
||||||
|
private final NotebookContainer contents;
|
||||||
|
|
||||||
|
public NotebookMenu(int containerId, Inventory inventory, RegistryFriendlyByteBuf data) {
|
||||||
|
this(containerId, inventory, data.readBoolean() ? InteractionHand.OFF_HAND : InteractionHand.MAIN_HAND);
|
||||||
|
}
|
||||||
|
|
||||||
|
public NotebookMenu(int containerId, Inventory inventory, InteractionHand hand) {
|
||||||
|
super(ModMenus.NOTEBOOK.get(), containerId);
|
||||||
|
this.playerInventory = inventory;
|
||||||
|
this.hand = hand;
|
||||||
|
this.openedHotbarSlot = inventory.selected;
|
||||||
|
this.contents = new NotebookContainer(inventory, hand);
|
||||||
|
|
||||||
|
for (int row = 0; row < 3; row++) {
|
||||||
|
for (int column = 0; column < 9; column++) {
|
||||||
|
// The client draws these pages on a filtered, scrollable surface instead.
|
||||||
|
addSlot(new PageSlot(contents, column + row * 9, -1000, -1000));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (int row = 0; row < 3; row++) {
|
||||||
|
for (int column = 0; column < 9; column++) {
|
||||||
|
int inventoryIndex = column + row * 9 + 9;
|
||||||
|
addSlot(playerSlot(inventoryIndex, 8 + column * 18, 135 + row * 18));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (int column = 0; column < 9; column++) {
|
||||||
|
addSlot(playerSlot(column, 8 + column * 18, 193));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private Slot playerSlot(int inventoryIndex, int x, int y) {
|
||||||
|
boolean locked = hand == InteractionHand.MAIN_HAND && inventoryIndex == openedHotbarSlot;
|
||||||
|
return locked ? new LockedSlot(playerInventory, inventoryIndex, x, y)
|
||||||
|
: new Slot(playerInventory, inventoryIndex, x, y);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean stillValid(Player player) {
|
||||||
|
return player.isAlive()
|
||||||
|
&& (hand == InteractionHand.OFF_HAND || player.getInventory().selected == openedHotbarSlot)
|
||||||
|
&& player.getItemInHand(hand).is(ModItems.NOTEBOOK.get());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ItemStack quickMoveStack(Player player, int index) {
|
||||||
|
Slot slot = slots.get(index);
|
||||||
|
if (!slot.hasItem()) {
|
||||||
|
return ItemStack.EMPTY;
|
||||||
|
}
|
||||||
|
ItemStack source = slot.getItem();
|
||||||
|
ItemStack original = source.copy();
|
||||||
|
if (index < PLAYER_INVENTORY_START) {
|
||||||
|
if (!moveItemStackTo(source, PLAYER_INVENTORY_START, slots.size(), true)) {
|
||||||
|
return ItemStack.EMPTY;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (!source.is(ModItems.PAGE.get())
|
||||||
|
|| !moveItemStackTo(source, 0, PLAYER_INVENTORY_START, false)) {
|
||||||
|
return ItemStack.EMPTY;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (source.isEmpty()) {
|
||||||
|
slot.setByPlayer(ItemStack.EMPTY);
|
||||||
|
} else {
|
||||||
|
slot.setChanged();
|
||||||
|
}
|
||||||
|
return original;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean clickMenuButton(Player player, int id) {
|
||||||
|
int source;
|
||||||
|
int target;
|
||||||
|
if (id >= MOVE_PREVIOUS_BASE && id < MOVE_NEXT_BASE) {
|
||||||
|
source = id;
|
||||||
|
target = source - 1;
|
||||||
|
} else if (id >= MOVE_NEXT_BASE && id < MOVE_NEXT_BASE + NOTEBOOK_SLOTS) {
|
||||||
|
source = id - MOVE_NEXT_BASE;
|
||||||
|
target = source + 1;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (source < 0 || source >= NOTEBOOK_SLOTS || target < 0 || target >= NOTEBOOK_SLOTS
|
||||||
|
|| contents.getItem(source).isEmpty()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
contents.swap(source, target);
|
||||||
|
broadcastChanges();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void clicked(int slotId, int button, ClickType clickType, Player player) {
|
||||||
|
if (!stillValid(player)) {
|
||||||
|
player.closeContainer();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (clickType == ClickType.SWAP
|
||||||
|
&& (button == openedHotbarSlot && hand == InteractionHand.MAIN_HAND
|
||||||
|
|| button == 40 && hand == InteractionHand.OFF_HAND)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
super.clicked(slotId, button, clickType, player);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final class PageSlot extends Slot {
|
||||||
|
private PageSlot(Container container, int slot, int x, int y) {
|
||||||
|
super(container, slot, x, y);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override public boolean mayPlace(ItemStack stack) { return stack.is(ModItems.PAGE.get()); }
|
||||||
|
@Override public int getMaxStackSize() { return 1; }
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final class LockedSlot extends Slot {
|
||||||
|
private LockedSlot(Container container, int slot, int x, int y) {
|
||||||
|
super(container, slot, x, y);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override public boolean mayPickup(Player player) { return false; }
|
||||||
|
@Override public boolean mayPlace(ItemStack stack) { return false; }
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final class NotebookContainer extends SimpleContainer {
|
||||||
|
private final Inventory inventory;
|
||||||
|
private final InteractionHand hand;
|
||||||
|
private boolean loading;
|
||||||
|
|
||||||
|
private NotebookContainer(Inventory inventory, InteractionHand hand) {
|
||||||
|
super(NOTEBOOK_SLOTS);
|
||||||
|
this.inventory = inventory;
|
||||||
|
this.hand = hand;
|
||||||
|
ItemStack notebook = inventory.player.getItemInHand(hand);
|
||||||
|
loading = true;
|
||||||
|
List<ItemStack> saved = notebook.getOrDefault(
|
||||||
|
ModDataComponents.NOTEBOOK_CONTENTS.get(), NotebookContents.EMPTY).pages();
|
||||||
|
for (int index = 0; index < saved.size(); index++) {
|
||||||
|
super.setItem(index, saved.get(index).copy());
|
||||||
|
}
|
||||||
|
loading = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void swap(int first, int second) {
|
||||||
|
loading = true;
|
||||||
|
ItemStack held = getItem(first);
|
||||||
|
setItem(first, getItem(second));
|
||||||
|
setItem(second, held);
|
||||||
|
loading = false;
|
||||||
|
setChanged();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setChanged() {
|
||||||
|
super.setChanged();
|
||||||
|
ItemStack notebook = inventory.player.getItemInHand(hand);
|
||||||
|
if (loading || !notebook.is(ModItems.NOTEBOOK.get())) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
NonNullList<ItemStack> saved = NonNullList.withSize(NOTEBOOK_SLOTS, ItemStack.EMPTY);
|
||||||
|
for (int index = 0; index < NOTEBOOK_SLOTS; index++) {
|
||||||
|
ItemStack page = getItem(index);
|
||||||
|
saved.set(index, page.isEmpty() ? ItemStack.EMPTY : page.copyWithCount(1));
|
||||||
|
}
|
||||||
|
notebook.set(ModDataComponents.NOTEBOOK_CONTENTS.get(), new NotebookContents(saved));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,447 @@
|
|||||||
|
package net.dnorberg.rivencraft.menu;
|
||||||
|
|
||||||
|
import net.dnorberg.rivencraft.block.entity.WritingDeskBlockEntity;
|
||||||
|
import net.dnorberg.rivencraft.item.PageItem;
|
||||||
|
import net.dnorberg.rivencraft.registry.ModDataComponents;
|
||||||
|
import net.dnorberg.rivencraft.registry.ModItems;
|
||||||
|
import net.dnorberg.rivencraft.registry.ModMenus;
|
||||||
|
import net.dnorberg.rivencraft.writing.NotebookContents;
|
||||||
|
import net.dnorberg.rivencraft.writing.PageContent;
|
||||||
|
import net.dnorberg.rivencraft.writing.SymbolCatalog;
|
||||||
|
import net.dnorberg.rivencraft.writing.SymbolDisplayMetadata;
|
||||||
|
import net.dnorberg.rivencraft.writing.SymbolReference;
|
||||||
|
import net.dnorberg.rivencraft.writing.WritingDeskCatalog;
|
||||||
|
import net.dnorberg.rivencraft.network.WritingDeskCatalogPayload;
|
||||||
|
import net.minecraft.resources.ResourceLocation;
|
||||||
|
import net.minecraft.server.level.ServerPlayer;
|
||||||
|
import net.neoforged.neoforge.network.PacketDistributor;
|
||||||
|
import java.util.List;
|
||||||
|
import net.minecraft.network.RegistryFriendlyByteBuf;
|
||||||
|
import net.minecraft.world.Container;
|
||||||
|
import net.minecraft.world.SimpleContainer;
|
||||||
|
import net.minecraft.world.entity.player.Inventory;
|
||||||
|
import net.minecraft.world.entity.player.Player;
|
||||||
|
import net.minecraft.world.inventory.AbstractContainerMenu;
|
||||||
|
import net.minecraft.world.inventory.DataSlot;
|
||||||
|
import net.minecraft.world.inventory.Slot;
|
||||||
|
import net.minecraft.world.item.ItemStack;
|
||||||
|
import net.minecraft.world.item.Items;
|
||||||
|
|
||||||
|
public final class WritingDeskMenu extends AbstractContainerMenu {
|
||||||
|
public static final int COPY_RESULT = WritingDeskBlockEntity.SIZE;
|
||||||
|
public static final int VISIBLE_TABS = 4;
|
||||||
|
public static final int PREVIOUS_TABS = 90;
|
||||||
|
public static final int NEXT_TABS = 91;
|
||||||
|
public static final int PAGE_BUTTON_BASE = 128;
|
||||||
|
public static final int CATALOG_BUTTON_BASE = 512;
|
||||||
|
public static final int ALL_PAGE_BUTTON_BASE = 32768;
|
||||||
|
public static final int PLACE_PAGE_BUTTON_BASE = 65536;
|
||||||
|
private static final int PAGE_ADDRESS_COUNT = WritingDeskBlockEntity.COLLECTIONS * NotebookContents.MAX_PAGES;
|
||||||
|
public static final int MOVE_PAGE_BUTTON_BASE = PLACE_PAGE_BUTTON_BASE + PAGE_ADDRESS_COUNT;
|
||||||
|
private static final int PLAYER_START = COPY_RESULT + 1;
|
||||||
|
private static final int EXTRACT_TARGET_COUNT = PLAYER_START + 36 + 1;
|
||||||
|
public static final int EXTRACT_PAGE_BUTTON_BASE = MOVE_PAGE_BUTTON_BASE + PAGE_ADDRESS_COUNT * PAGE_ADDRESS_COUNT;
|
||||||
|
private final Container desk;
|
||||||
|
private final WritingDeskBlockEntity blockEntity;
|
||||||
|
private final SimpleContainer result = new SimpleContainer(1);
|
||||||
|
private final boolean clientSide;
|
||||||
|
private int syncedActiveCollection;
|
||||||
|
private int syncedInkRemaining;
|
||||||
|
private int firstVisibleTab;
|
||||||
|
private int selectedPage;
|
||||||
|
private int selectedCollection = -1;
|
||||||
|
private ResourceLocation selectedSymbol;
|
||||||
|
private List<SymbolDisplayMetadata> catalog = List.of();
|
||||||
|
private final ServerPlayer serverViewer;
|
||||||
|
|
||||||
|
public WritingDeskMenu(int id, Inventory inventory, RegistryFriendlyByteBuf data) {
|
||||||
|
this(id, inventory, inventory.player.level().getBlockEntity(data.readBlockPos())
|
||||||
|
instanceof WritingDeskBlockEntity found ? found : null);
|
||||||
|
catalog = WritingDeskCatalog.read(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
public WritingDeskMenu(int id, Inventory inventory, WritingDeskBlockEntity blockEntity) {
|
||||||
|
super(ModMenus.WRITING_DESK.get(), id);
|
||||||
|
this.blockEntity = blockEntity;
|
||||||
|
this.desk = blockEntity == null ? new SimpleContainer(WritingDeskBlockEntity.SIZE) : blockEntity;
|
||||||
|
this.clientSide = inventory.player.level().isClientSide;
|
||||||
|
this.serverViewer = inventory.player instanceof ServerPlayer serverPlayer ? serverPlayer : null;
|
||||||
|
if (blockEntity != null && !clientSide) catalog = WritingDeskCatalog.available(blockEntity);
|
||||||
|
firstVisibleTab = blockEntity == null ? 0 : blockEntity.activeCollection() / VISIBLE_TABS * VISIBLE_TABS;
|
||||||
|
addDataSlot(new DataSlot() {
|
||||||
|
@Override public int get() { return firstVisibleTab; }
|
||||||
|
@Override public void set(int value) { firstVisibleTab = value; }
|
||||||
|
});
|
||||||
|
addDataSlot(new DataSlot() {
|
||||||
|
@Override public int get() { return WritingDeskMenu.this.blockEntity == null
|
||||||
|
? syncedActiveCollection : WritingDeskMenu.this.blockEntity.activeCollection(); }
|
||||||
|
@Override public void set(int value) { syncedActiveCollection = value; }
|
||||||
|
});
|
||||||
|
addDataSlot(new DataSlot() {
|
||||||
|
@Override public int get() { return WritingDeskMenu.this.blockEntity == null
|
||||||
|
? syncedInkRemaining : WritingDeskMenu.this.blockEntity.inkRemaining(); }
|
||||||
|
@Override public void set(int value) { syncedInkRemaining = value; }
|
||||||
|
});
|
||||||
|
for (int i = 0; i < WritingDeskBlockEntity.COLLECTIONS; i++) {
|
||||||
|
addSlot(new DeskSlot(desk, i, 37, 34 + (i % VISIBLE_TABS) * 37, 1));
|
||||||
|
}
|
||||||
|
addSlot(new DeskSlot(desk, WritingDeskBlockEntity.INK, 385, 28, 16));
|
||||||
|
addSlot(new DeskSlot(desk, WritingDeskBlockEntity.RETURN, 385, 80, 64));
|
||||||
|
addSlot(new DeskSlot(desk, WritingDeskBlockEntity.PAPER, 241, 28, 64));
|
||||||
|
addSlot(new DeskSlot(desk, WritingDeskBlockEntity.LEGACY_OUTPUT, -1000, -1000, 64));
|
||||||
|
addSlot(new CopySlot(result, 0, 241, 80));
|
||||||
|
for (int row = 0; row < 3; row++) {
|
||||||
|
for (int column = 0; column < 9; column++) {
|
||||||
|
addSlot(new Slot(inventory, column + row * 9 + 9, 241 + column * 18, 104 + row * 18));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (int column = 0; column < 9; column++) {
|
||||||
|
addSlot(new Slot(inventory, column, 241 + column * 18, 162));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public int activeCollection() { return syncedActiveCollection; }
|
||||||
|
public int firstVisibleTab() { return firstVisibleTab; }
|
||||||
|
public int inkRemaining() { return syncedInkRemaining; }
|
||||||
|
public int pageCapacity(int collectionIndex) {
|
||||||
|
if (collectionIndex < 0 || collectionIndex >= WritingDeskBlockEntity.COLLECTIONS) return 0;
|
||||||
|
ItemStack collection = desk.getItem(collectionIndex);
|
||||||
|
return collection.is(ModItems.NOTEBOOK.get()) ? NotebookContents.MAX_PAGES
|
||||||
|
: collection.is(ModItems.PAGE.get()) ? 1 : 0;
|
||||||
|
}
|
||||||
|
public List<SymbolDisplayMetadata> catalog() { return catalog; }
|
||||||
|
public void setCatalog(List<SymbolDisplayMetadata> symbols) { catalog = List.copyOf(symbols); }
|
||||||
|
|
||||||
|
public static int movePageButtonId(int sourceCollection, int sourcePage, int targetCollection, int targetPage) {
|
||||||
|
int source = sourceCollection * NotebookContents.MAX_PAGES + sourcePage;
|
||||||
|
int target = targetCollection * NotebookContents.MAX_PAGES + targetPage;
|
||||||
|
return MOVE_PAGE_BUTTON_BASE + source * PAGE_ADDRESS_COUNT + target;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** targetSlot is -1 for the cursor, otherwise a visible player or desk-tab slot. */
|
||||||
|
public static int extractPageButtonId(int sourceCollection, int sourcePage, int targetSlot) {
|
||||||
|
int source = sourceCollection * NotebookContents.MAX_PAGES + sourcePage;
|
||||||
|
return EXTRACT_PAGE_BUTTON_BASE + source * EXTRACT_TARGET_COUNT + targetSlot + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override public boolean clickMenuButton(Player player, int id) {
|
||||||
|
if (blockEntity == null || !stillValid(player)) return false;
|
||||||
|
if (id == PREVIOUS_TABS || id == NEXT_TABS) {
|
||||||
|
firstVisibleTab = Math.clamp(firstVisibleTab + (id == NEXT_TABS ? VISIBLE_TABS : -VISIBLE_TABS),
|
||||||
|
0, WritingDeskBlockEntity.COLLECTIONS - VISIBLE_TABS);
|
||||||
|
return true;
|
||||||
|
} else if (id >= 0 && id < WritingDeskBlockEntity.COLLECTIONS) {
|
||||||
|
if (id < firstVisibleTab || id >= firstVisibleTab + VISIBLE_TABS) return false;
|
||||||
|
blockEntity.setActiveCollection(id);
|
||||||
|
selectedPage = 0;
|
||||||
|
selectedCollection = -1;
|
||||||
|
selectedSymbol = null;
|
||||||
|
} else if (id >= EXTRACT_PAGE_BUTTON_BASE
|
||||||
|
&& id < EXTRACT_PAGE_BUTTON_BASE + PAGE_ADDRESS_COUNT * EXTRACT_TARGET_COUNT) {
|
||||||
|
int offset = id - EXTRACT_PAGE_BUTTON_BASE;
|
||||||
|
int source = offset / EXTRACT_TARGET_COUNT;
|
||||||
|
int targetSlot = offset % EXTRACT_TARGET_COUNT - 1;
|
||||||
|
if (!extractPage(source / NotebookContents.MAX_PAGES, source % NotebookContents.MAX_PAGES,
|
||||||
|
targetSlot)) return false;
|
||||||
|
} else if (id >= MOVE_PAGE_BUTTON_BASE && id < MOVE_PAGE_BUTTON_BASE + PAGE_ADDRESS_COUNT * PAGE_ADDRESS_COUNT) {
|
||||||
|
int offset = id - MOVE_PAGE_BUTTON_BASE;
|
||||||
|
int source = offset / PAGE_ADDRESS_COUNT;
|
||||||
|
int target = offset % PAGE_ADDRESS_COUNT;
|
||||||
|
if (!movePage(source / NotebookContents.MAX_PAGES, source % NotebookContents.MAX_PAGES,
|
||||||
|
target / NotebookContents.MAX_PAGES, target % NotebookContents.MAX_PAGES)) return false;
|
||||||
|
} else if (id >= PLACE_PAGE_BUTTON_BASE
|
||||||
|
&& id < PLACE_PAGE_BUTTON_BASE + WritingDeskBlockEntity.COLLECTIONS * NotebookContents.MAX_PAGES) {
|
||||||
|
int offset = id - PLACE_PAGE_BUTTON_BASE;
|
||||||
|
if (!placeCarriedPage(offset / NotebookContents.MAX_PAGES, offset % NotebookContents.MAX_PAGES)) return false;
|
||||||
|
} else if (id >= PAGE_BUTTON_BASE && id < PAGE_BUTTON_BASE + NotebookContents.MAX_PAGES) {
|
||||||
|
selectedPage = id - PAGE_BUTTON_BASE;
|
||||||
|
selectedCollection = -1;
|
||||||
|
selectedSymbol = null;
|
||||||
|
} else if (id >= ALL_PAGE_BUTTON_BASE && id < ALL_PAGE_BUTTON_BASE + WritingDeskBlockEntity.COLLECTIONS * NotebookContents.MAX_PAGES) {
|
||||||
|
int offset = id - ALL_PAGE_BUTTON_BASE;
|
||||||
|
int collection = offset / NotebookContents.MAX_PAGES;
|
||||||
|
int page = offset % NotebookContents.MAX_PAGES;
|
||||||
|
if (pageAt(collection, page).isEmpty()) return false;
|
||||||
|
selectedCollection = collection;
|
||||||
|
selectedPage = page;
|
||||||
|
selectedSymbol = null;
|
||||||
|
} else if (id >= CATALOG_BUTTON_BASE && id < CATALOG_BUTTON_BASE + catalog.size()) {
|
||||||
|
if (!catalog.equals(WritingDeskCatalog.available(blockEntity))) {
|
||||||
|
refreshCatalog();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
ResourceLocation requested = catalog.get(id - CATALOG_BUTTON_BASE).id();
|
||||||
|
if (!WritingDeskCatalog.available(blockEntity).stream().anyMatch(entry -> entry.id().equals(requested))) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
selectedSymbol = requested;
|
||||||
|
} else return false;
|
||||||
|
refreshOutput();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean placeCarriedPage(int collectionIndex, int pageIndex) {
|
||||||
|
// Resolve the actual storage position on the server, never a filtered list index.
|
||||||
|
ItemStack carried = getCarried();
|
||||||
|
if (clientSide || !carried.is(ModItems.PAGE.get())) return false;
|
||||||
|
ItemStack collection = desk.getItem(collectionIndex);
|
||||||
|
if (collection.is(ModItems.NOTEBOOK.get())) {
|
||||||
|
var pages = new java.util.ArrayList<>(collection.getOrDefault(
|
||||||
|
ModDataComponents.NOTEBOOK_CONTENTS.get(), NotebookContents.EMPTY).pages());
|
||||||
|
while (pages.size() <= pageIndex) pages.add(ItemStack.EMPTY);
|
||||||
|
if (!pages.get(pageIndex).isEmpty()) return false;
|
||||||
|
pages.set(pageIndex, carried.copyWithCount(1));
|
||||||
|
ItemStack updated = collection.copy();
|
||||||
|
updated.set(ModDataComponents.NOTEBOOK_CONTENTS.get(), new NotebookContents(pages));
|
||||||
|
desk.setItem(collectionIndex, updated);
|
||||||
|
} else return false;
|
||||||
|
carried.shrink(1);
|
||||||
|
setCarried(carried.isEmpty() ? ItemStack.EMPTY : carried);
|
||||||
|
selectedCollection = collectionIndex;
|
||||||
|
selectedPage = pageIndex;
|
||||||
|
selectedSymbol = null;
|
||||||
|
refreshCatalog();
|
||||||
|
broadcastChanges();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean movePage(int sourceCollection, int sourcePage, int targetCollection, int targetPage) {
|
||||||
|
if (!getCarried().isEmpty() || sourceCollection == targetCollection && sourcePage == targetPage) return false;
|
||||||
|
ItemStack sourceBook = desk.getItem(sourceCollection);
|
||||||
|
ItemStack targetBook = desk.getItem(targetCollection);
|
||||||
|
boolean sourceNotebook = sourceBook.is(ModItems.NOTEBOOK.get());
|
||||||
|
boolean targetNotebook = targetBook.is(ModItems.NOTEBOOK.get());
|
||||||
|
if ((!sourceNotebook && (!sourceBook.is(ModItems.PAGE.get()) || sourcePage != 0))
|
||||||
|
|| (!targetNotebook && (!targetBook.is(ModItems.PAGE.get()) || targetPage != 0))) return false;
|
||||||
|
var sourcePages = sourceNotebook ? new java.util.ArrayList<>(sourceBook.getOrDefault(
|
||||||
|
ModDataComponents.NOTEBOOK_CONTENTS.get(), NotebookContents.EMPTY).pages()) : null;
|
||||||
|
if (sourceNotebook && (sourcePage >= sourcePages.size() || sourcePages.get(sourcePage).isEmpty())) return false;
|
||||||
|
ItemStack moving = sourceNotebook ? sourcePages.get(sourcePage) : sourceBook;
|
||||||
|
if (moving.getCount() != 1) return false;
|
||||||
|
if (!targetNotebook && targetBook.getCount() != 1) return false;
|
||||||
|
var targetPages = targetNotebook ? sourceCollection == targetCollection ? sourcePages
|
||||||
|
: new java.util.ArrayList<>(targetBook.getOrDefault(
|
||||||
|
ModDataComponents.NOTEBOOK_CONTENTS.get(), NotebookContents.EMPTY).pages()) : null;
|
||||||
|
if (targetNotebook) while (targetPages.size() <= targetPage) targetPages.add(ItemStack.EMPTY);
|
||||||
|
ItemStack displaced = targetNotebook ? targetPages.get(targetPage) : targetBook;
|
||||||
|
if (targetNotebook) targetPages.set(targetPage, moving);
|
||||||
|
if (sourceNotebook) {
|
||||||
|
sourcePages.set(sourcePage, displaced);
|
||||||
|
ItemStack updatedSource = sourceBook.copy();
|
||||||
|
updatedSource.set(ModDataComponents.NOTEBOOK_CONTENTS.get(), new NotebookContents(sourcePages));
|
||||||
|
desk.setItem(sourceCollection, updatedSource);
|
||||||
|
} else desk.setItem(sourceCollection, displaced.isEmpty() ? ItemStack.EMPTY : displaced.copyWithCount(1));
|
||||||
|
if (targetNotebook && sourceCollection != targetCollection) {
|
||||||
|
ItemStack updatedTarget = targetBook.copy();
|
||||||
|
updatedTarget.set(ModDataComponents.NOTEBOOK_CONTENTS.get(), new NotebookContents(targetPages));
|
||||||
|
desk.setItem(targetCollection, updatedTarget);
|
||||||
|
} else if (!targetNotebook) desk.setItem(targetCollection, moving.copyWithCount(1));
|
||||||
|
selectedCollection = targetCollection;
|
||||||
|
selectedPage = targetPage;
|
||||||
|
selectedSymbol = null;
|
||||||
|
refreshCatalog();
|
||||||
|
broadcastChanges();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean extractPage(int sourceCollection, int sourcePage, int targetSlot) {
|
||||||
|
if (!getCarried().isEmpty() || targetSlot < -1 || targetSlot >= slots.size()) return false;
|
||||||
|
ItemStack sourceBook = desk.getItem(sourceCollection);
|
||||||
|
boolean sourceNotebook = sourceBook.is(ModItems.NOTEBOOK.get());
|
||||||
|
if (!sourceNotebook && (!sourceBook.is(ModItems.PAGE.get()) || sourcePage != 0)) return false;
|
||||||
|
var sourcePages = sourceNotebook ? new java.util.ArrayList<>(sourceBook.getOrDefault(
|
||||||
|
ModDataComponents.NOTEBOOK_CONTENTS.get(), NotebookContents.EMPTY).pages()) : null;
|
||||||
|
if (sourceNotebook && (sourcePage >= sourcePages.size() || sourcePages.get(sourcePage).isEmpty())) return false;
|
||||||
|
ItemStack moving = sourceNotebook ? sourcePages.get(sourcePage).copyWithCount(1) : sourceBook.copyWithCount(1);
|
||||||
|
if (!sourceNotebook && sourceBook.getCount() != 1) return false;
|
||||||
|
|
||||||
|
if (targetSlot == -1) {
|
||||||
|
setCarried(moving);
|
||||||
|
} else {
|
||||||
|
if (targetSlot >= WritingDeskBlockEntity.COLLECTIONS && targetSlot < PLAYER_START) return false;
|
||||||
|
Slot target = slots.get(targetSlot);
|
||||||
|
if (!target.isActive() || !target.mayPlace(moving)) return false;
|
||||||
|
ItemStack current = target.getItem();
|
||||||
|
if (targetSlot < WritingDeskBlockEntity.COLLECTIONS && current.is(ModItems.NOTEBOOK.get())) {
|
||||||
|
var targetPages = targetSlot == sourceCollection ? sourcePages
|
||||||
|
: new java.util.ArrayList<>(current.getOrDefault(
|
||||||
|
ModDataComponents.NOTEBOOK_CONTENTS.get(), NotebookContents.EMPTY).pages());
|
||||||
|
int position = -1;
|
||||||
|
for (int i = 0; i < NotebookContents.MAX_PAGES; i++) {
|
||||||
|
if (i >= targetPages.size() || targetPages.get(i).isEmpty()) {
|
||||||
|
position = i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (position < 0) return false;
|
||||||
|
while (targetPages.size() <= position) targetPages.add(ItemStack.EMPTY);
|
||||||
|
targetPages.set(position, moving);
|
||||||
|
if (targetSlot != sourceCollection) {
|
||||||
|
ItemStack updatedTarget = current.copy();
|
||||||
|
updatedTarget.set(ModDataComponents.NOTEBOOK_CONTENTS.get(), new NotebookContents(targetPages));
|
||||||
|
target.setByPlayer(updatedTarget);
|
||||||
|
}
|
||||||
|
} else if (current.isEmpty()) {
|
||||||
|
target.setByPlayer(moving);
|
||||||
|
} else if (targetSlot >= PLAYER_START && ItemStack.isSameItemSameComponents(current, moving)
|
||||||
|
&& current.getCount() < target.getMaxStackSize(moving)) {
|
||||||
|
target.setByPlayer(current.copyWithCount(current.getCount() + 1));
|
||||||
|
} else return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (sourceNotebook) {
|
||||||
|
sourcePages.set(sourcePage, ItemStack.EMPTY);
|
||||||
|
ItemStack updatedSource = sourceBook.copy();
|
||||||
|
updatedSource.set(ModDataComponents.NOTEBOOK_CONTENTS.get(), new NotebookContents(sourcePages));
|
||||||
|
desk.setItem(sourceCollection, updatedSource);
|
||||||
|
} else desk.setItem(sourceCollection, ItemStack.EMPTY);
|
||||||
|
selectedCollection = sourceCollection;
|
||||||
|
selectedPage = sourcePage;
|
||||||
|
selectedSymbol = null;
|
||||||
|
refreshCatalog();
|
||||||
|
broadcastChanges();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override public boolean stillValid(Player player) {
|
||||||
|
return blockEntity != null && blockEntity.stillValid(player);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override public ItemStack quickMoveStack(Player player, int index) {
|
||||||
|
if (!stillValid(player) || index < 0 || index >= slots.size()) return ItemStack.EMPTY;
|
||||||
|
if (index == COPY_RESULT) {
|
||||||
|
refreshOutput();
|
||||||
|
if (!canCopy()) return ItemStack.EMPTY;
|
||||||
|
ItemStack copy = selectedSource().copyWithCount(1);
|
||||||
|
ItemStack movingCopy = copy.copy();
|
||||||
|
if (!moveItemStackTo(movingCopy, PLAYER_START, slots.size(), true) || !movingCopy.isEmpty()) {
|
||||||
|
return ItemStack.EMPTY;
|
||||||
|
}
|
||||||
|
blockEntity.consumeCopyMaterials();
|
||||||
|
refreshOutput();
|
||||||
|
return copy;
|
||||||
|
}
|
||||||
|
Slot slot = slots.get(index);
|
||||||
|
if (!slot.isActive()) return ItemStack.EMPTY;
|
||||||
|
if (!slot.hasItem()) return ItemStack.EMPTY;
|
||||||
|
ItemStack moving = slot.getItem();
|
||||||
|
ItemStack original = moving.copy();
|
||||||
|
if (index < COPY_RESULT) {
|
||||||
|
if (!moveItemStackTo(moving, PLAYER_START, slots.size(), true)) return ItemStack.EMPTY;
|
||||||
|
} else if (!moveIntoDesk(moving)) {
|
||||||
|
return ItemStack.EMPTY;
|
||||||
|
}
|
||||||
|
if (moving.isEmpty()) slot.setByPlayer(ItemStack.EMPTY);
|
||||||
|
else slot.setChanged();
|
||||||
|
return original;
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean moveIntoDesk(ItemStack moving) {
|
||||||
|
if (moving.is(ModItems.INK_VIAL.get())) return moveItemStackTo(moving,
|
||||||
|
WritingDeskBlockEntity.INK, WritingDeskBlockEntity.INK + 1, false);
|
||||||
|
if (moving.is(ModItems.NOTEBOOK.get())) return moveItemStackTo(moving, firstVisibleTab, firstVisibleTab + VISIBLE_TABS, false);
|
||||||
|
if (moving.is(Items.PAPER))
|
||||||
|
return moveItemStackTo(moving, WritingDeskBlockEntity.PAPER,
|
||||||
|
WritingDeskBlockEntity.PAPER + 1, false);
|
||||||
|
if (moving.is(ModItems.PAGE.get())) return moveItemStackTo(moving, firstVisibleTab, firstVisibleTab + VISIBLE_TABS, false);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private ItemStack selectedSource() {
|
||||||
|
if (selectedSymbol != null) {
|
||||||
|
SymbolReference reference = new SymbolReference(selectedSymbol);
|
||||||
|
return SymbolCatalog.isKnown(reference)
|
||||||
|
&& blockEntity != null
|
||||||
|
&& WritingDeskCatalog.available(blockEntity).stream()
|
||||||
|
.anyMatch(entry -> entry.id().equals(selectedSymbol))
|
||||||
|
? PageItem.createSymbolPage(reference) : ItemStack.EMPTY;
|
||||||
|
}
|
||||||
|
int collectionIndex = selectedCollection >= 0 ? selectedCollection
|
||||||
|
: blockEntity == null ? syncedActiveCollection : blockEntity.activeCollection();
|
||||||
|
return pageAt(collectionIndex, selectedPage);
|
||||||
|
}
|
||||||
|
|
||||||
|
private ItemStack pageAt(int collectionIndex, int pageIndex) {
|
||||||
|
if (collectionIndex < 0 || collectionIndex >= WritingDeskBlockEntity.COLLECTIONS
|
||||||
|
|| pageIndex < 0 || pageIndex >= NotebookContents.MAX_PAGES) return ItemStack.EMPTY;
|
||||||
|
ItemStack collection = desk.getItem(collectionIndex);
|
||||||
|
if (collection.is(ModItems.PAGE.get())) return pageIndex == 0 ? collection : ItemStack.EMPTY;
|
||||||
|
if (collection.is(ModItems.NOTEBOOK.get())) {
|
||||||
|
List<ItemStack> pages = collection.getOrDefault(
|
||||||
|
ModDataComponents.NOTEBOOK_CONTENTS.get(), NotebookContents.EMPTY).pages();
|
||||||
|
return pageIndex < pages.size() ? pages.get(pageIndex) : ItemStack.EMPTY;
|
||||||
|
}
|
||||||
|
return ItemStack.EMPTY;
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean canCopy() {
|
||||||
|
ItemStack source = selectedSource();
|
||||||
|
return blockEntity != null && source.is(ModItems.PAGE.get())
|
||||||
|
&& PageItem.content(source).kind() != PageContent.Kind.BLANK
|
||||||
|
&& PageItem.isUsableWriting(source) && blockEntity.canConsumeCopyMaterials();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void refreshOutput() {
|
||||||
|
if (clientSide) return;
|
||||||
|
if (blockEntity != null) blockEntity.setDisplayPage(selectedSource());
|
||||||
|
ItemStack preview = canCopy() ? selectedSource().copyWithCount(1) : ItemStack.EMPTY;
|
||||||
|
if (!ItemStack.matches(result.getItem(0), preview)) result.setItem(0, preview);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void refreshCatalog() {
|
||||||
|
if (clientSide || blockEntity == null) return;
|
||||||
|
List<SymbolDisplayMetadata> current = WritingDeskCatalog.available(blockEntity);
|
||||||
|
if (!current.equals(catalog)) {
|
||||||
|
catalog = current;
|
||||||
|
if (serverViewer != null && serverViewer.containerMenu == this) {
|
||||||
|
PacketDistributor.sendToPlayer(serverViewer, new WritingDeskCatalogPayload(containerId, catalog));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override public void broadcastChanges() {
|
||||||
|
refreshCatalog();
|
||||||
|
refreshOutput();
|
||||||
|
super.broadcastChanges();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override public void clicked(int slotId, int button, net.minecraft.world.inventory.ClickType clickType,
|
||||||
|
Player player) {
|
||||||
|
if (!stillValid(player)) {
|
||||||
|
player.closeContainer();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
refreshCatalog();
|
||||||
|
refreshOutput();
|
||||||
|
if (slotId >= 0 && slotId < slots.size() && !slots.get(slotId).isActive()) return;
|
||||||
|
super.clicked(slotId, button, clickType, player);
|
||||||
|
}
|
||||||
|
|
||||||
|
private final class CopySlot extends Slot {
|
||||||
|
private CopySlot(Container container, int index, int x, int y) { super(container, index, x, y); }
|
||||||
|
@Override public boolean mayPlace(ItemStack stack) { return false; }
|
||||||
|
@Override public boolean mayPickup(Player player) {
|
||||||
|
return clientSide ? hasItem() : WritingDeskMenu.this.stillValid(player) && canCopy();
|
||||||
|
}
|
||||||
|
@Override public void onTake(Player player, ItemStack stack) {
|
||||||
|
if (!clientSide && blockEntity.consumeCopyMaterials()) refreshOutput();
|
||||||
|
super.onTake(player, stack);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private final class DeskSlot extends Slot {
|
||||||
|
private final int limit;
|
||||||
|
private DeskSlot(Container container, int index, int x, int y, int limit) {
|
||||||
|
super(container, index, x, y);
|
||||||
|
this.limit = limit;
|
||||||
|
}
|
||||||
|
@Override public boolean isActive() {
|
||||||
|
int slot = getContainerSlot();
|
||||||
|
return slot >= WritingDeskBlockEntity.COLLECTIONS
|
||||||
|
|| slot >= firstVisibleTab && slot < firstVisibleTab + VISIBLE_TABS;
|
||||||
|
}
|
||||||
|
@Override public boolean mayPickup(Player player) { return isActive(); }
|
||||||
|
@Override public boolean mayPlace(ItemStack stack) { return isActive() && container.canPlaceItem(getContainerSlot(), stack); }
|
||||||
|
@Override public int getMaxStackSize() { return limit; }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,59 @@
|
|||||||
|
package net.dnorberg.rivencraft.mixin.client;
|
||||||
|
|
||||||
|
import net.dnorberg.rivencraft.client.preview.ImmersivePortalsPreviewAudioGuard;
|
||||||
|
import net.minecraft.client.multiplayer.ClientLevel;
|
||||||
|
import net.minecraft.core.Holder;
|
||||||
|
import net.minecraft.sounds.SoundEvent;
|
||||||
|
import net.minecraft.sounds.SoundSource;
|
||||||
|
import net.minecraft.world.entity.Entity;
|
||||||
|
import net.minecraft.world.entity.player.Player;
|
||||||
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
|
import org.spongepowered.asm.mixin.injection.At;
|
||||||
|
import org.spongepowered.asm.mixin.injection.Inject;
|
||||||
|
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||||
|
|
||||||
|
/** Mutes only the remote client world displayed by a Rivencraft book preview. */
|
||||||
|
@Mixin(value = ClientLevel.class, priority = 2000)
|
||||||
|
public abstract class ClientLevelSoundMixin {
|
||||||
|
@Inject(
|
||||||
|
method = "playSound(DDDLnet/minecraft/sounds/SoundEvent;Lnet/minecraft/sounds/SoundSource;FFZJ)V",
|
||||||
|
at = @At("HEAD"),
|
||||||
|
cancellable = true
|
||||||
|
)
|
||||||
|
private void rivencraft$mutePreviewPositionSound(
|
||||||
|
double x, double y, double z, SoundEvent sound, SoundSource source,
|
||||||
|
float volume, float pitch, boolean distanceDelay, long seed, CallbackInfo callback
|
||||||
|
) {
|
||||||
|
rivencraft$cancelPreviewSound(callback);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Inject(
|
||||||
|
method = "playLocalSound(Lnet/minecraft/world/entity/Entity;Lnet/minecraft/sounds/SoundEvent;Lnet/minecraft/sounds/SoundSource;FF)V",
|
||||||
|
at = @At("HEAD"),
|
||||||
|
cancellable = true
|
||||||
|
)
|
||||||
|
private void rivencraft$mutePreviewLocalEntitySound(
|
||||||
|
Entity entity, SoundEvent sound, SoundSource source, float volume, float pitch,
|
||||||
|
CallbackInfo callback
|
||||||
|
) {
|
||||||
|
rivencraft$cancelPreviewSound(callback);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Inject(
|
||||||
|
method = "playSeededSound(Lnet/minecraft/world/entity/player/Player;Lnet/minecraft/world/entity/Entity;Lnet/minecraft/core/Holder;Lnet/minecraft/sounds/SoundSource;FFJ)V",
|
||||||
|
at = @At("HEAD"),
|
||||||
|
cancellable = true
|
||||||
|
)
|
||||||
|
private void rivencraft$mutePreviewSeededEntitySound(
|
||||||
|
Player player, Entity entity, Holder<SoundEvent> sound, SoundSource source,
|
||||||
|
float volume, float pitch, long seed, CallbackInfo callback
|
||||||
|
) {
|
||||||
|
rivencraft$cancelPreviewSound(callback);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void rivencraft$cancelPreviewSound(CallbackInfo callback) {
|
||||||
|
if (ImmersivePortalsPreviewAudioGuard.shouldMute((ClientLevel)(Object)this)) {
|
||||||
|
callback.cancel();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
package net.dnorberg.rivencraft.mixin.client;
|
||||||
|
|
||||||
|
import net.dnorberg.rivencraft.client.preview.ImmersivePortalsPreviewAudioGuard;
|
||||||
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
|
import org.spongepowered.asm.mixin.Pseudo;
|
||||||
|
import org.spongepowered.asm.mixin.injection.At;
|
||||||
|
import org.spongepowered.asm.mixin.injection.Inject;
|
||||||
|
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||||
|
|
||||||
|
/** Restores the player camera after Immersive Portals finishes GUI-world rendering. */
|
||||||
|
@Pseudo
|
||||||
|
@Mixin(targets = "qouteall.imm_ptl.core.render.GuiPortalRendering", remap = false)
|
||||||
|
public abstract class ImmersivePortalsGuiRenderingMixin {
|
||||||
|
@Inject(method = "_onGameRenderEnd", at = @At("RETURN"), remap = false)
|
||||||
|
private static void rivencraft$restorePlayerCamera(CallbackInfo callback) {
|
||||||
|
ImmersivePortalsPreviewAudioGuard.restorePlayerCamera();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -9,6 +9,7 @@ import net.dnorberg.rivencraft.block.entity.BookStandBlockEntity;
|
|||||||
import net.dnorberg.rivencraft.client.ClientLinkPreviewHandler;
|
import net.dnorberg.rivencraft.client.ClientLinkPreviewHandler;
|
||||||
import net.dnorberg.rivencraft.client.ClientBookInteractionHandler;
|
import net.dnorberg.rivencraft.client.ClientBookInteractionHandler;
|
||||||
import net.dnorberg.rivencraft.client.ClientAgeCelestialAngles;
|
import net.dnorberg.rivencraft.client.ClientAgeCelestialAngles;
|
||||||
|
import net.dnorberg.rivencraft.client.ClientWritingDeskCatalog;
|
||||||
import net.dnorberg.rivencraft.event.AgeCelestialAngleSync;
|
import net.dnorberg.rivencraft.event.AgeCelestialAngleSync;
|
||||||
import net.dnorberg.rivencraft.item.DescriptiveBookItem;
|
import net.dnorberg.rivencraft.item.DescriptiveBookItem;
|
||||||
import net.dnorberg.rivencraft.item.LinkingBookItem;
|
import net.dnorberg.rivencraft.item.LinkingBookItem;
|
||||||
@@ -48,7 +49,7 @@ public final class ModNetworking {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void register(RegisterPayloadHandlersEvent event) {
|
public static void register(RegisterPayloadHandlersEvent event) {
|
||||||
PayloadRegistrar registrar = event.registrar("9");
|
PayloadRegistrar registrar = event.registrar("11");
|
||||||
registrar.playToServer(RequestDescriptiveBookScreenPayload.TYPE, RequestDescriptiveBookScreenPayload.STREAM_CODEC,
|
registrar.playToServer(RequestDescriptiveBookScreenPayload.TYPE, RequestDescriptiveBookScreenPayload.STREAM_CODEC,
|
||||||
ModNetworking::requestDescriptiveBookScreen);
|
ModNetworking::requestDescriptiveBookScreen);
|
||||||
registrar.playToClient(OpenDescriptiveBookScreenPayload.TYPE, OpenDescriptiveBookScreenPayload.STREAM_CODEC,
|
registrar.playToClient(OpenDescriptiveBookScreenPayload.TYPE, OpenDescriptiveBookScreenPayload.STREAM_CODEC,
|
||||||
@@ -68,6 +69,8 @@ public final class ModNetworking {
|
|||||||
ClientLinkPreviewHandler::handle);
|
ClientLinkPreviewHandler::handle);
|
||||||
registrar.playToClient(AgeCelestialAnglePayload.TYPE, AgeCelestialAnglePayload.STREAM_CODEC,
|
registrar.playToClient(AgeCelestialAnglePayload.TYPE, AgeCelestialAnglePayload.STREAM_CODEC,
|
||||||
ClientAgeCelestialAngles::handle);
|
ClientAgeCelestialAngles::handle);
|
||||||
|
registrar.playToClient(WritingDeskCatalogPayload.TYPE, WritingDeskCatalogPayload.STREAM_CODEC,
|
||||||
|
ClientWritingDeskCatalog::handle);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void requestDescriptiveBookScreen(RequestDescriptiveBookScreenPayload payload, IPayloadContext context) {
|
private static void requestDescriptiveBookScreen(RequestDescriptiveBookScreenPayload payload, IPayloadContext context) {
|
||||||
|
|||||||
@@ -0,0 +1,26 @@
|
|||||||
|
package net.dnorberg.rivencraft.network;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import net.dnorberg.rivencraft.Rivencraft;
|
||||||
|
import net.dnorberg.rivencraft.writing.SymbolDisplayMetadata;
|
||||||
|
import net.dnorberg.rivencraft.writing.WritingDeskCatalog;
|
||||||
|
import net.minecraft.network.RegistryFriendlyByteBuf;
|
||||||
|
import net.minecraft.network.codec.StreamCodec;
|
||||||
|
import net.minecraft.network.protocol.common.custom.CustomPacketPayload;
|
||||||
|
import net.minecraft.resources.ResourceLocation;
|
||||||
|
|
||||||
|
/** Current server-approved symbols from this open Writing Desk menu. */
|
||||||
|
public record WritingDeskCatalogPayload(int containerId, List<SymbolDisplayMetadata> symbols)
|
||||||
|
implements CustomPacketPayload {
|
||||||
|
public static final Type<WritingDeskCatalogPayload> TYPE = new Type<>(
|
||||||
|
ResourceLocation.fromNamespaceAndPath(Rivencraft.MOD_ID, "writing_desk_catalog"));
|
||||||
|
public static final StreamCodec<RegistryFriendlyByteBuf, WritingDeskCatalogPayload> STREAM_CODEC =
|
||||||
|
StreamCodec.of(
|
||||||
|
(buffer, payload) -> {
|
||||||
|
buffer.writeVarInt(payload.containerId());
|
||||||
|
WritingDeskCatalog.write(buffer, payload.symbols());
|
||||||
|
},
|
||||||
|
buffer -> new WritingDeskCatalogPayload(buffer.readVarInt(), WritingDeskCatalog.read(buffer)));
|
||||||
|
|
||||||
|
@Override public Type<? extends CustomPacketPayload> type() { return TYPE; }
|
||||||
|
}
|
||||||
@@ -2,6 +2,7 @@ package net.dnorberg.rivencraft.registry;
|
|||||||
|
|
||||||
import net.dnorberg.rivencraft.Rivencraft;
|
import net.dnorberg.rivencraft.Rivencraft;
|
||||||
import net.dnorberg.rivencraft.block.entity.BookStandBlockEntity;
|
import net.dnorberg.rivencraft.block.entity.BookStandBlockEntity;
|
||||||
|
import net.dnorberg.rivencraft.block.entity.WritingDeskBlockEntity;
|
||||||
import net.minecraft.core.registries.Registries;
|
import net.minecraft.core.registries.Registries;
|
||||||
import net.minecraft.world.level.block.entity.BlockEntityType;
|
import net.minecraft.world.level.block.entity.BlockEntityType;
|
||||||
import net.neoforged.bus.api.IEventBus;
|
import net.neoforged.bus.api.IEventBus;
|
||||||
@@ -16,6 +17,9 @@ public final class ModBlockEntities {
|
|||||||
BLOCK_ENTITIES.register("book_stand", () -> BlockEntityType.Builder
|
BLOCK_ENTITIES.register("book_stand", () -> BlockEntityType.Builder
|
||||||
.of(BookStandBlockEntity::new, ModBlocks.BOOK_STAND.get())
|
.of(BookStandBlockEntity::new, ModBlocks.BOOK_STAND.get())
|
||||||
.build(null));
|
.build(null));
|
||||||
|
public static final DeferredHolder<BlockEntityType<?>, BlockEntityType<WritingDeskBlockEntity>> WRITING_DESK =
|
||||||
|
BLOCK_ENTITIES.register("writing_desk", () -> BlockEntityType.Builder
|
||||||
|
.of(WritingDeskBlockEntity::new, ModBlocks.WRITING_DESK.get()).build(null));
|
||||||
|
|
||||||
private ModBlockEntities() {
|
private ModBlockEntities() {
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package net.dnorberg.rivencraft.registry;
|
|||||||
|
|
||||||
import net.dnorberg.rivencraft.Rivencraft;
|
import net.dnorberg.rivencraft.Rivencraft;
|
||||||
import net.dnorberg.rivencraft.block.BookStandBlock;
|
import net.dnorberg.rivencraft.block.BookStandBlock;
|
||||||
|
import net.dnorberg.rivencraft.block.WritingDeskBlock;
|
||||||
import net.minecraft.world.level.block.Blocks;
|
import net.minecraft.world.level.block.Blocks;
|
||||||
import net.minecraft.world.level.block.state.BlockBehaviour;
|
import net.minecraft.world.level.block.state.BlockBehaviour;
|
||||||
import net.neoforged.bus.api.IEventBus;
|
import net.neoforged.bus.api.IEventBus;
|
||||||
@@ -16,6 +17,10 @@ public final class ModBlocks {
|
|||||||
BookStandBlock::new,
|
BookStandBlock::new,
|
||||||
BlockBehaviour.Properties.ofFullCopy(Blocks.LECTERN)
|
BlockBehaviour.Properties.ofFullCopy(Blocks.LECTERN)
|
||||||
);
|
);
|
||||||
|
public static final DeferredBlock<WritingDeskBlock> WRITING_DESK = BLOCKS.registerBlock(
|
||||||
|
"writing_desk", WritingDeskBlock::new,
|
||||||
|
BlockBehaviour.Properties.ofFullCopy(Blocks.CRAFTING_TABLE).noOcclusion()
|
||||||
|
);
|
||||||
|
|
||||||
private ModBlocks() {
|
private ModBlocks() {
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package net.dnorberg.rivencraft.registry;
|
package net.dnorberg.rivencraft.registry;
|
||||||
|
|
||||||
import net.dnorberg.rivencraft.Rivencraft;
|
import net.dnorberg.rivencraft.Rivencraft;
|
||||||
|
import net.dnorberg.rivencraft.item.PageItem;
|
||||||
import net.minecraft.core.registries.Registries;
|
import net.minecraft.core.registries.Registries;
|
||||||
import net.minecraft.network.chat.Component;
|
import net.minecraft.network.chat.Component;
|
||||||
import net.minecraft.world.item.CreativeModeTab;
|
import net.minecraft.world.item.CreativeModeTab;
|
||||||
@@ -19,6 +20,18 @@ public final class ModCreativeTabs {
|
|||||||
.displayItems((parameters, output) -> {
|
.displayItems((parameters, output) -> {
|
||||||
output.accept(ModItems.DESCRIPTIVE_BOOK.get());
|
output.accept(ModItems.DESCRIPTIVE_BOOK.get());
|
||||||
output.accept(ModItems.LINKING_BOOK.get());
|
output.accept(ModItems.LINKING_BOOK.get());
|
||||||
|
output.accept(ModItems.NOTEBOOK.get());
|
||||||
|
output.accept(ModItems.INK_VIAL.get());
|
||||||
|
output.accept(ModItems.WRITING_DESK.get());
|
||||||
|
})
|
||||||
|
.build());
|
||||||
|
|
||||||
|
public static final DeferredHolder<CreativeModeTab, CreativeModeTab> PAGES =
|
||||||
|
CREATIVE_TABS.register("rivencraft_pages", () -> CreativeModeTab.builder()
|
||||||
|
.title(Component.translatable("itemGroup.rivencraft.pages"))
|
||||||
|
.icon(PageItem::createLinkPanelPage)
|
||||||
|
.displayItems((parameters, output) -> {
|
||||||
|
output.accept(PageItem.createLinkPanelPage());
|
||||||
})
|
})
|
||||||
.build());
|
.build());
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,10 @@ package net.dnorberg.rivencraft.registry;
|
|||||||
import net.dnorberg.rivencraft.Rivencraft;
|
import net.dnorberg.rivencraft.Rivencraft;
|
||||||
import net.dnorberg.rivencraft.book.LinkTarget;
|
import net.dnorberg.rivencraft.book.LinkTarget;
|
||||||
import net.dnorberg.rivencraft.book.AgeReference;
|
import net.dnorberg.rivencraft.book.AgeReference;
|
||||||
|
import net.dnorberg.rivencraft.writing.PageContent;
|
||||||
|
import net.dnorberg.rivencraft.writing.NotebookContents;
|
||||||
|
import net.dnorberg.rivencraft.writing.SymbolDisplayMetadata;
|
||||||
|
import com.mojang.serialization.Codec;
|
||||||
import net.minecraft.core.component.DataComponentType;
|
import net.minecraft.core.component.DataComponentType;
|
||||||
import net.minecraft.core.registries.Registries;
|
import net.minecraft.core.registries.Registries;
|
||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.resources.ResourceLocation;
|
||||||
@@ -39,6 +43,30 @@ public final class ModDataComponents {
|
|||||||
.networkSynchronized(ByteBufCodecs.STRING_UTF8)
|
.networkSynchronized(ByteBufCodecs.STRING_UTF8)
|
||||||
.cacheEncoding()
|
.cacheEncoding()
|
||||||
.build());
|
.build());
|
||||||
|
public static final DeferredHolder<DataComponentType<?>, DataComponentType<PageContent>> PAGE_CONTENT =
|
||||||
|
DATA_COMPONENTS.register("page_content", () -> DataComponentType.<PageContent>builder()
|
||||||
|
.persistent(PageContent.CODEC)
|
||||||
|
.networkSynchronized(PageContent.STREAM_CODEC)
|
||||||
|
.cacheEncoding()
|
||||||
|
.build());
|
||||||
|
public static final DeferredHolder<DataComponentType<?>, DataComponentType<SymbolDisplayMetadata>> PAGE_SYMBOL_DISPLAY =
|
||||||
|
DATA_COMPONENTS.register("page_symbol_display", () -> DataComponentType.<SymbolDisplayMetadata>builder()
|
||||||
|
.persistent(SymbolDisplayMetadata.CODEC)
|
||||||
|
.networkSynchronized(SymbolDisplayMetadata.STREAM_CODEC)
|
||||||
|
.cacheEncoding()
|
||||||
|
.build());
|
||||||
|
public static final DeferredHolder<DataComponentType<?>, DataComponentType<NotebookContents>> NOTEBOOK_CONTENTS =
|
||||||
|
DATA_COMPONENTS.register("notebook_contents", () -> DataComponentType.<NotebookContents>builder()
|
||||||
|
.persistent(NotebookContents.CODEC)
|
||||||
|
.networkSynchronized(NotebookContents.STREAM_CODEC)
|
||||||
|
.cacheEncoding()
|
||||||
|
.build());
|
||||||
|
public static final DeferredHolder<DataComponentType<?>, DataComponentType<Integer>> INK_REMAINING =
|
||||||
|
DATA_COMPONENTS.register("ink_remaining", () -> DataComponentType.<Integer>builder()
|
||||||
|
.persistent(Codec.intRange(0, 16))
|
||||||
|
.networkSynchronized(ByteBufCodecs.VAR_INT)
|
||||||
|
.cacheEncoding()
|
||||||
|
.build());
|
||||||
|
|
||||||
private ModDataComponents() {
|
private ModDataComponents() {
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,11 @@ package net.dnorberg.rivencraft.registry;
|
|||||||
import net.dnorberg.rivencraft.Rivencraft;
|
import net.dnorberg.rivencraft.Rivencraft;
|
||||||
import net.dnorberg.rivencraft.item.DescriptiveBookItem;
|
import net.dnorberg.rivencraft.item.DescriptiveBookItem;
|
||||||
import net.dnorberg.rivencraft.item.LinkingBookItem;
|
import net.dnorberg.rivencraft.item.LinkingBookItem;
|
||||||
|
import net.dnorberg.rivencraft.item.PageItem;
|
||||||
|
import net.dnorberg.rivencraft.item.NotebookItem;
|
||||||
|
import net.dnorberg.rivencraft.item.InkVialItem;
|
||||||
import net.minecraft.world.item.Item;
|
import net.minecraft.world.item.Item;
|
||||||
|
import net.minecraft.world.item.BlockItem;
|
||||||
import net.neoforged.bus.api.IEventBus;
|
import net.neoforged.bus.api.IEventBus;
|
||||||
import net.neoforged.neoforge.registries.DeferredItem;
|
import net.neoforged.neoforge.registries.DeferredItem;
|
||||||
import net.neoforged.neoforge.registries.DeferredRegister;
|
import net.neoforged.neoforge.registries.DeferredRegister;
|
||||||
@@ -21,6 +25,22 @@ public final class ModItems {
|
|||||||
LinkingBookItem::new,
|
LinkingBookItem::new,
|
||||||
new Item.Properties().stacksTo(1)
|
new Item.Properties().stacksTo(1)
|
||||||
);
|
);
|
||||||
|
public static final DeferredItem<PageItem> PAGE = ITEMS.registerItem(
|
||||||
|
"page",
|
||||||
|
PageItem::new,
|
||||||
|
new Item.Properties().stacksTo(64)
|
||||||
|
);
|
||||||
|
public static final DeferredItem<NotebookItem> NOTEBOOK = ITEMS.registerItem(
|
||||||
|
"notebook",
|
||||||
|
NotebookItem::new,
|
||||||
|
new Item.Properties().stacksTo(1)
|
||||||
|
);
|
||||||
|
public static final DeferredItem<InkVialItem> INK_VIAL = ITEMS.registerItem(
|
||||||
|
"ink_vial",
|
||||||
|
InkVialItem::new,
|
||||||
|
new Item.Properties().stacksTo(16)
|
||||||
|
);
|
||||||
|
public static final DeferredItem<BlockItem> WRITING_DESK = ITEMS.registerSimpleBlockItem(ModBlocks.WRITING_DESK);
|
||||||
|
|
||||||
private ModItems() {
|
private ModItems() {
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,28 @@
|
|||||||
|
package net.dnorberg.rivencraft.registry;
|
||||||
|
|
||||||
|
import net.dnorberg.rivencraft.Rivencraft;
|
||||||
|
import net.dnorberg.rivencraft.menu.NotebookMenu;
|
||||||
|
import net.dnorberg.rivencraft.menu.WritingDeskMenu;
|
||||||
|
import net.minecraft.core.registries.Registries;
|
||||||
|
import net.minecraft.world.inventory.MenuType;
|
||||||
|
import net.neoforged.bus.api.IEventBus;
|
||||||
|
import net.neoforged.neoforge.common.extensions.IMenuTypeExtension;
|
||||||
|
import net.neoforged.neoforge.registries.DeferredHolder;
|
||||||
|
import net.neoforged.neoforge.registries.DeferredRegister;
|
||||||
|
|
||||||
|
public final class ModMenus {
|
||||||
|
private static final DeferredRegister<MenuType<?>> MENUS =
|
||||||
|
DeferredRegister.create(Registries.MENU, Rivencraft.MOD_ID);
|
||||||
|
|
||||||
|
public static final DeferredHolder<MenuType<?>, MenuType<NotebookMenu>> NOTEBOOK =
|
||||||
|
MENUS.register("notebook", () -> IMenuTypeExtension.create(NotebookMenu::new));
|
||||||
|
public static final DeferredHolder<MenuType<?>, MenuType<WritingDeskMenu>> WRITING_DESK =
|
||||||
|
MENUS.register("writing_desk", () -> IMenuTypeExtension.create(WritingDeskMenu::new));
|
||||||
|
|
||||||
|
private ModMenus() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void register(IEventBus modEventBus) {
|
||||||
|
MENUS.register(modEventBus);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,88 @@
|
|||||||
|
package net.dnorberg.rivencraft.writing;
|
||||||
|
|
||||||
|
import com.mojang.serialization.Codec;
|
||||||
|
import com.mojang.serialization.DataResult;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import net.dnorberg.rivencraft.item.PageItem;
|
||||||
|
import net.dnorberg.rivencraft.registry.ModItems;
|
||||||
|
import net.minecraft.network.RegistryFriendlyByteBuf;
|
||||||
|
import net.minecraft.network.codec.ByteBufCodecs;
|
||||||
|
import net.minecraft.network.codec.StreamCodec;
|
||||||
|
import net.minecraft.world.item.ItemStack;
|
||||||
|
|
||||||
|
/** A bounded, position-preserving collection of Page stacks stored on a Notebook item. */
|
||||||
|
public record NotebookContents(List<ItemStack> pages) {
|
||||||
|
public static final int MAX_PAGES = 27;
|
||||||
|
public static final NotebookContents EMPTY = new NotebookContents(List.of());
|
||||||
|
public static final Codec<NotebookContents> CODEC = ItemStack.OPTIONAL_CODEC.listOf()
|
||||||
|
.validate(NotebookContents::validate)
|
||||||
|
.xmap(NotebookContents::new, NotebookContents::pages);
|
||||||
|
public static final StreamCodec<RegistryFriendlyByteBuf, NotebookContents> STREAM_CODEC = StreamCodec.of(
|
||||||
|
NotebookContents::encode, NotebookContents::decode);
|
||||||
|
|
||||||
|
public NotebookContents {
|
||||||
|
if (pages.size() > MAX_PAGES) {
|
||||||
|
throw new IllegalArgumentException("Notebook exceeds " + MAX_PAGES + " page positions");
|
||||||
|
}
|
||||||
|
List<ItemStack> copies = new ArrayList<>(pages.size());
|
||||||
|
for (ItemStack page : pages) {
|
||||||
|
validatePage(page).getOrThrow();
|
||||||
|
copies.add(page.copy());
|
||||||
|
}
|
||||||
|
pages = List.copyOf(copies);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int pageCount() {
|
||||||
|
return (int)pages.stream().filter(page -> !page.isEmpty()).count();
|
||||||
|
}
|
||||||
|
|
||||||
|
public int unresolvedCount() {
|
||||||
|
return (int)pages.stream()
|
||||||
|
.filter(page -> !page.isEmpty()
|
||||||
|
&& PageContent.Kind.UNRESOLVED_SYMBOL == PageItem.content(page).kind())
|
||||||
|
.count();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static DataResult<List<ItemStack>> validate(List<ItemStack> pages) {
|
||||||
|
if (pages.size() > MAX_PAGES) {
|
||||||
|
return DataResult.error(() -> "Notebook exceeds " + MAX_PAGES + " page positions");
|
||||||
|
}
|
||||||
|
for (ItemStack page : pages) {
|
||||||
|
DataResult<ItemStack> result = validatePage(page);
|
||||||
|
if (result.error().isPresent()) {
|
||||||
|
return DataResult.error(() -> result.error().orElseThrow().message());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return DataResult.success(pages);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static DataResult<ItemStack> validatePage(ItemStack page) {
|
||||||
|
if (page.isEmpty()) {
|
||||||
|
return DataResult.success(page);
|
||||||
|
}
|
||||||
|
if (!page.is(ModItems.PAGE.get())) {
|
||||||
|
return DataResult.error(() -> "Notebook contains a non-Page item");
|
||||||
|
}
|
||||||
|
return page.getCount() == 1
|
||||||
|
? DataResult.success(page)
|
||||||
|
: DataResult.error(() -> "Notebook Page stacks must contain exactly one item");
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void encode(RegistryFriendlyByteBuf buffer, NotebookContents contents) {
|
||||||
|
ByteBufCodecs.VAR_INT.encode(buffer, contents.pages.size());
|
||||||
|
contents.pages.forEach(page -> ItemStack.OPTIONAL_STREAM_CODEC.encode(buffer, page));
|
||||||
|
}
|
||||||
|
|
||||||
|
private static NotebookContents decode(RegistryFriendlyByteBuf buffer) {
|
||||||
|
int size = ByteBufCodecs.VAR_INT.decode(buffer);
|
||||||
|
if (size < 0 || size > MAX_PAGES) {
|
||||||
|
throw new IllegalArgumentException("Invalid Notebook page count " + size);
|
||||||
|
}
|
||||||
|
List<ItemStack> pages = new ArrayList<>(size);
|
||||||
|
for (int index = 0; index < size; index++) {
|
||||||
|
pages.add(ItemStack.OPTIONAL_STREAM_CODEC.decode(buffer));
|
||||||
|
}
|
||||||
|
return new NotebookContents(pages);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,47 @@
|
|||||||
|
package net.dnorberg.rivencraft.writing;
|
||||||
|
|
||||||
|
import com.mojang.serialization.Codec;
|
||||||
|
import com.mojang.serialization.DataResult;
|
||||||
|
import io.netty.buffer.ByteBuf;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
|
import net.minecraft.network.codec.ByteBufCodecs;
|
||||||
|
import net.minecraft.network.codec.StreamCodec;
|
||||||
|
|
||||||
|
/** Immutable ordered writing shared by pages, notebooks, desks, and books. */
|
||||||
|
public record OrderedWriting(List<WritingEntry> entries) {
|
||||||
|
public static final int MAX_ENTRIES = 256;
|
||||||
|
public static final OrderedWriting EMPTY = new OrderedWriting(List.of());
|
||||||
|
public static final Codec<OrderedWriting> CODEC = WritingEntry.CODEC.listOf()
|
||||||
|
.validate(entries -> entries.size() <= MAX_ENTRIES
|
||||||
|
? DataResult.success(entries)
|
||||||
|
: DataResult.error(() -> "Writing exceeds " + MAX_ENTRIES + " entries"))
|
||||||
|
.xmap(OrderedWriting::new, OrderedWriting::entries);
|
||||||
|
public static final StreamCodec<ByteBuf, OrderedWriting> STREAM_CODEC = StreamCodec.of(
|
||||||
|
OrderedWriting::encode, OrderedWriting::decode);
|
||||||
|
|
||||||
|
public OrderedWriting {
|
||||||
|
entries = List.copyOf(Objects.requireNonNull(entries, "entries"));
|
||||||
|
if (entries.size() > MAX_ENTRIES) {
|
||||||
|
throw new IllegalArgumentException("Writing exceeds " + MAX_ENTRIES + " entries");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void encode(ByteBuf buffer, OrderedWriting writing) {
|
||||||
|
ByteBufCodecs.VAR_INT.encode(buffer, writing.entries.size());
|
||||||
|
writing.entries.forEach(entry -> WritingEntry.STREAM_CODEC.encode(buffer, entry));
|
||||||
|
}
|
||||||
|
|
||||||
|
private static OrderedWriting decode(ByteBuf buffer) {
|
||||||
|
int size = ByteBufCodecs.VAR_INT.decode(buffer);
|
||||||
|
if (size < 0 || size > MAX_ENTRIES) {
|
||||||
|
throw new IllegalArgumentException("Invalid writing entry count " + size);
|
||||||
|
}
|
||||||
|
List<WritingEntry> entries = new ArrayList<>(size);
|
||||||
|
for (int index = 0; index < size; index++) {
|
||||||
|
entries.add(WritingEntry.STREAM_CODEC.decode(buffer));
|
||||||
|
}
|
||||||
|
return new OrderedWriting(entries);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,95 @@
|
|||||||
|
package net.dnorberg.rivencraft.writing;
|
||||||
|
|
||||||
|
import com.mojang.serialization.Codec;
|
||||||
|
import com.mojang.serialization.DataResult;
|
||||||
|
import com.mojang.serialization.codecs.RecordCodecBuilder;
|
||||||
|
import io.netty.buffer.ByteBuf;
|
||||||
|
import java.util.Locale;
|
||||||
|
import java.util.Objects;
|
||||||
|
import java.util.Optional;
|
||||||
|
import net.minecraft.network.codec.ByteBufCodecs;
|
||||||
|
import net.minecraft.network.codec.StreamCodec;
|
||||||
|
|
||||||
|
/** Persistent contents of a Page item. Unknown symbols remain explicit and recoverable. */
|
||||||
|
public record PageContent(Kind kind, Optional<SymbolReference> symbol) {
|
||||||
|
public static final PageContent BLANK = new PageContent(Kind.BLANK, Optional.empty());
|
||||||
|
public static final PageContent LINK_PANEL = new PageContent(Kind.LINK_PANEL, Optional.empty());
|
||||||
|
private static final Codec<Kind> KIND_CODEC = Codec.STRING.comapFlatMap(
|
||||||
|
value -> {
|
||||||
|
try {
|
||||||
|
return DataResult.success(Kind.valueOf(value.toUpperCase(Locale.ROOT)));
|
||||||
|
} catch (IllegalArgumentException exception) {
|
||||||
|
return DataResult.error(() -> "Unknown page content kind: " + value);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
value -> value.name().toLowerCase(Locale.ROOT)
|
||||||
|
);
|
||||||
|
private static final Codec<PageContent> RECORD_CODEC = RecordCodecBuilder.create(instance -> instance.group(
|
||||||
|
KIND_CODEC.fieldOf("kind").forGetter(PageContent::kind),
|
||||||
|
SymbolReference.CODEC.optionalFieldOf("symbol").forGetter(PageContent::symbol)
|
||||||
|
).apply(instance, PageContent::new));
|
||||||
|
public static final Codec<PageContent> CODEC = RECORD_CODEC.flatXmap(PageContent::validate, PageContent::validate);
|
||||||
|
public static final StreamCodec<ByteBuf, PageContent> STREAM_CODEC = StreamCodec.of(
|
||||||
|
PageContent::encode, PageContent::decode);
|
||||||
|
|
||||||
|
public PageContent {
|
||||||
|
Objects.requireNonNull(kind, "kind");
|
||||||
|
symbol = Objects.requireNonNull(symbol, "symbol");
|
||||||
|
boolean needsSymbol = kind == Kind.SYMBOL || kind == Kind.UNRESOLVED_SYMBOL;
|
||||||
|
if (needsSymbol != symbol.isPresent()) {
|
||||||
|
throw new IllegalArgumentException("Page contents do not match kind " + kind);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static PageContent symbol(SymbolReference symbol) {
|
||||||
|
return new PageContent(Kind.SYMBOL, Optional.of(symbol));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static PageContent unresolved(SymbolReference symbol) {
|
||||||
|
return new PageContent(Kind.UNRESOLVED_SYMBOL, Optional.of(symbol));
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Re-resolves persisted data against the authoritative current server catalog. */
|
||||||
|
public PageContent resolve() {
|
||||||
|
if (kind != Kind.SYMBOL && kind != Kind.UNRESOLVED_SYMBOL) {
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
SymbolReference reference = symbol.orElseThrow();
|
||||||
|
return SymbolCatalog.isKnown(reference) ? symbol(reference) : unresolved(reference);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isResolvedSymbol() {
|
||||||
|
return kind == Kind.SYMBOL;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static DataResult<PageContent> validate(PageContent content) {
|
||||||
|
boolean needsSymbol = content.kind == Kind.SYMBOL || content.kind == Kind.UNRESOLVED_SYMBOL;
|
||||||
|
return needsSymbol == content.symbol.isPresent()
|
||||||
|
? DataResult.success(content)
|
||||||
|
: DataResult.error(() -> "Page contents do not match kind " + content.kind);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void encode(ByteBuf buffer, PageContent content) {
|
||||||
|
ByteBufCodecs.VAR_INT.encode(buffer, content.kind.ordinal());
|
||||||
|
content.symbol.ifPresent(reference -> SymbolReference.STREAM_CODEC.encode(buffer, reference));
|
||||||
|
}
|
||||||
|
|
||||||
|
private static PageContent decode(ByteBuf buffer) {
|
||||||
|
int ordinal = ByteBufCodecs.VAR_INT.decode(buffer);
|
||||||
|
if (ordinal < 0 || ordinal >= Kind.values().length) {
|
||||||
|
throw new IllegalArgumentException("Unknown page content kind ordinal " + ordinal);
|
||||||
|
}
|
||||||
|
Kind kind = Kind.values()[ordinal];
|
||||||
|
Optional<SymbolReference> symbol = kind == Kind.SYMBOL || kind == Kind.UNRESOLVED_SYMBOL
|
||||||
|
? Optional.of(SymbolReference.STREAM_CODEC.decode(buffer))
|
||||||
|
: Optional.empty();
|
||||||
|
return new PageContent(kind, symbol);
|
||||||
|
}
|
||||||
|
|
||||||
|
public enum Kind {
|
||||||
|
BLANK,
|
||||||
|
SYMBOL,
|
||||||
|
UNRESOLVED_SYMBOL,
|
||||||
|
LINK_PANEL
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,67 @@
|
|||||||
|
package net.dnorberg.rivencraft.writing;
|
||||||
|
|
||||||
|
import com.google.gson.Gson;
|
||||||
|
import com.google.gson.GsonBuilder;
|
||||||
|
import com.google.gson.JsonElement;
|
||||||
|
import com.mojang.serialization.JsonOps;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Optional;
|
||||||
|
import net.dnorberg.rivencraft.Rivencraft;
|
||||||
|
import net.minecraft.resources.ResourceLocation;
|
||||||
|
import net.minecraft.server.packs.resources.ResourceManager;
|
||||||
|
import net.minecraft.server.packs.resources.SimpleJsonResourceReloadListener;
|
||||||
|
import net.minecraft.util.profiling.ProfilerFiller;
|
||||||
|
import net.neoforged.neoforge.event.AddReloadListenerEvent;
|
||||||
|
|
||||||
|
/** Authoritative server catalog loaded from data/<namespace>/rivencraft/symbols. */
|
||||||
|
public final class SymbolCatalog {
|
||||||
|
private static final Gson GSON = new GsonBuilder().create();
|
||||||
|
private static final String DIRECTORY = "rivencraft/symbols";
|
||||||
|
private static volatile Map<ResourceLocation, SymbolDefinition> symbols = Map.of();
|
||||||
|
|
||||||
|
private SymbolCatalog() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void register(AddReloadListenerEvent event) {
|
||||||
|
event.addListener(new Loader());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Optional<SymbolDefinition> find(SymbolReference reference) {
|
||||||
|
return Optional.ofNullable(symbols.get(reference.id()));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean isKnown(SymbolReference reference) {
|
||||||
|
return symbols.containsKey(reference.id());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static SymbolDisplayMetadata display(SymbolReference reference) {
|
||||||
|
SymbolDefinition definition = symbols.get(reference.id());
|
||||||
|
return definition == null
|
||||||
|
? SymbolDisplayMetadata.unresolved(reference)
|
||||||
|
: definition.display(reference.id());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Map<ResourceLocation, SymbolDefinition> symbols() {
|
||||||
|
return symbols;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final class Loader extends SimpleJsonResourceReloadListener {
|
||||||
|
private Loader() {
|
||||||
|
super(GSON, DIRECTORY);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void apply(Map<ResourceLocation, JsonElement> resources,
|
||||||
|
ResourceManager resourceManager,
|
||||||
|
ProfilerFiller profiler) {
|
||||||
|
Map<ResourceLocation, SymbolDefinition> loaded = new HashMap<>();
|
||||||
|
resources.forEach((id, json) -> SymbolDefinition.CODEC.parse(JsonOps.INSTANCE, json)
|
||||||
|
.resultOrPartial(error -> Rivencraft.LOGGER.error(
|
||||||
|
"Ignoring invalid writing symbol {}: {}", id, error))
|
||||||
|
.ifPresent(definition -> loaded.put(id, definition)));
|
||||||
|
symbols = Map.copyOf(loaded);
|
||||||
|
Rivencraft.LOGGER.info("Loaded {} writing symbols", loaded.size());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,47 @@
|
|||||||
|
package net.dnorberg.rivencraft.writing;
|
||||||
|
|
||||||
|
import com.mojang.serialization.Codec;
|
||||||
|
import com.mojang.serialization.DataResult;
|
||||||
|
import com.mojang.serialization.codecs.RecordCodecBuilder;
|
||||||
|
import java.util.Objects;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
import net.minecraft.resources.ResourceLocation;
|
||||||
|
|
||||||
|
/** Server-loaded, non-executable display metadata for a writing symbol. */
|
||||||
|
public record SymbolDefinition(
|
||||||
|
int schemaVersion,
|
||||||
|
String nameTranslationKey,
|
||||||
|
String descriptionTranslationKey,
|
||||||
|
ResourceLocation category
|
||||||
|
) {
|
||||||
|
public static final int CURRENT_SCHEMA_VERSION = 1;
|
||||||
|
private static final Pattern TRANSLATION_KEY = Pattern.compile("[a-z0-9_.-]+");
|
||||||
|
private static final Codec<String> TRANSLATION_KEY_CODEC = Codec.STRING.comapFlatMap(
|
||||||
|
value -> TRANSLATION_KEY.matcher(value).matches()
|
||||||
|
? DataResult.success(value)
|
||||||
|
: DataResult.error(() -> "Invalid translation key: " + value),
|
||||||
|
value -> value
|
||||||
|
);
|
||||||
|
public static final Codec<SymbolDefinition> CODEC = RecordCodecBuilder.<SymbolDefinition>create(instance -> instance.group(
|
||||||
|
Codec.INT.fieldOf("schema_version").forGetter(SymbolDefinition::schemaVersion),
|
||||||
|
TRANSLATION_KEY_CODEC.fieldOf("name").forGetter(SymbolDefinition::nameTranslationKey),
|
||||||
|
TRANSLATION_KEY_CODEC.fieldOf("description").forGetter(SymbolDefinition::descriptionTranslationKey),
|
||||||
|
ResourceLocation.CODEC.fieldOf("category").forGetter(SymbolDefinition::category)
|
||||||
|
).apply(instance, SymbolDefinition::new)).flatXmap(SymbolDefinition::validate, SymbolDefinition::validate);
|
||||||
|
|
||||||
|
public SymbolDefinition {
|
||||||
|
Objects.requireNonNull(nameTranslationKey, "nameTranslationKey");
|
||||||
|
Objects.requireNonNull(descriptionTranslationKey, "descriptionTranslationKey");
|
||||||
|
Objects.requireNonNull(category, "category");
|
||||||
|
}
|
||||||
|
|
||||||
|
public SymbolDisplayMetadata display(ResourceLocation id) {
|
||||||
|
return new SymbolDisplayMetadata(id, nameTranslationKey, descriptionTranslationKey, category, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static DataResult<SymbolDefinition> validate(SymbolDefinition definition) {
|
||||||
|
return definition.schemaVersion == CURRENT_SCHEMA_VERSION
|
||||||
|
? DataResult.success(definition)
|
||||||
|
: DataResult.error(() -> "Unsupported symbol schema_version " + definition.schemaVersion);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,44 @@
|
|||||||
|
package net.dnorberg.rivencraft.writing;
|
||||||
|
|
||||||
|
import com.mojang.serialization.Codec;
|
||||||
|
import com.mojang.serialization.codecs.RecordCodecBuilder;
|
||||||
|
import io.netty.buffer.ByteBuf;
|
||||||
|
import net.dnorberg.rivencraft.Rivencraft;
|
||||||
|
import net.minecraft.network.codec.ByteBufCodecs;
|
||||||
|
import net.minecraft.network.codec.StreamCodec;
|
||||||
|
import net.minecraft.resources.ResourceLocation;
|
||||||
|
|
||||||
|
/** Client-safe symbol presentation selected by the authoritative server catalog. */
|
||||||
|
public record SymbolDisplayMetadata(
|
||||||
|
ResourceLocation id,
|
||||||
|
String nameTranslationKey,
|
||||||
|
String descriptionTranslationKey,
|
||||||
|
ResourceLocation category,
|
||||||
|
boolean resolved
|
||||||
|
) {
|
||||||
|
public static final Codec<SymbolDisplayMetadata> CODEC = RecordCodecBuilder.create(instance -> instance.group(
|
||||||
|
ResourceLocation.CODEC.fieldOf("id").forGetter(SymbolDisplayMetadata::id),
|
||||||
|
Codec.STRING.fieldOf("name").forGetter(SymbolDisplayMetadata::nameTranslationKey),
|
||||||
|
Codec.STRING.fieldOf("description").forGetter(SymbolDisplayMetadata::descriptionTranslationKey),
|
||||||
|
ResourceLocation.CODEC.fieldOf("category").forGetter(SymbolDisplayMetadata::category),
|
||||||
|
Codec.BOOL.fieldOf("resolved").forGetter(SymbolDisplayMetadata::resolved)
|
||||||
|
).apply(instance, SymbolDisplayMetadata::new));
|
||||||
|
public static final StreamCodec<ByteBuf, SymbolDisplayMetadata> STREAM_CODEC = StreamCodec.composite(
|
||||||
|
ResourceLocation.STREAM_CODEC, SymbolDisplayMetadata::id,
|
||||||
|
ByteBufCodecs.STRING_UTF8, SymbolDisplayMetadata::nameTranslationKey,
|
||||||
|
ByteBufCodecs.STRING_UTF8, SymbolDisplayMetadata::descriptionTranslationKey,
|
||||||
|
ResourceLocation.STREAM_CODEC, SymbolDisplayMetadata::category,
|
||||||
|
ByteBufCodecs.BOOL, SymbolDisplayMetadata::resolved,
|
||||||
|
SymbolDisplayMetadata::new
|
||||||
|
);
|
||||||
|
|
||||||
|
public static SymbolDisplayMetadata unresolved(SymbolReference reference) {
|
||||||
|
return new SymbolDisplayMetadata(
|
||||||
|
reference.id(),
|
||||||
|
"symbol.rivencraft.unresolved",
|
||||||
|
"symbol.rivencraft.unresolved.description",
|
||||||
|
ResourceLocation.fromNamespaceAndPath(Rivencraft.MOD_ID, "unresolved"),
|
||||||
|
false
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
package net.dnorberg.rivencraft.writing;
|
||||||
|
|
||||||
|
import com.mojang.serialization.Codec;
|
||||||
|
import io.netty.buffer.ByteBuf;
|
||||||
|
import java.util.Objects;
|
||||||
|
import net.minecraft.network.codec.StreamCodec;
|
||||||
|
import net.minecraft.resources.ResourceLocation;
|
||||||
|
|
||||||
|
/** Stable namespaced identity for one writing symbol. */
|
||||||
|
public record SymbolReference(ResourceLocation id) {
|
||||||
|
public static final Codec<SymbolReference> CODEC = ResourceLocation.CODEC.xmap(
|
||||||
|
SymbolReference::new, SymbolReference::id);
|
||||||
|
public static final StreamCodec<ByteBuf, SymbolReference> STREAM_CODEC = ResourceLocation.STREAM_CODEC.map(
|
||||||
|
SymbolReference::new, SymbolReference::id);
|
||||||
|
|
||||||
|
public SymbolReference {
|
||||||
|
Objects.requireNonNull(id, "id");
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Remains useful when the defining data pack has been removed. */
|
||||||
|
public String unresolvedName() {
|
||||||
|
return id.toString();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,63 @@
|
|||||||
|
package net.dnorberg.rivencraft.writing;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Comparator;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.TreeMap;
|
||||||
|
import net.dnorberg.rivencraft.block.entity.WritingDeskBlockEntity;
|
||||||
|
import net.dnorberg.rivencraft.item.PageItem;
|
||||||
|
import net.dnorberg.rivencraft.registry.ModDataComponents;
|
||||||
|
import net.dnorberg.rivencraft.registry.ModItems;
|
||||||
|
import net.minecraft.network.RegistryFriendlyByteBuf;
|
||||||
|
import net.minecraft.resources.ResourceLocation;
|
||||||
|
import net.minecraft.world.item.ItemStack;
|
||||||
|
|
||||||
|
/** A bounded, server-derived view of symbols physically present in the desk. */
|
||||||
|
public final class WritingDeskCatalog {
|
||||||
|
private static final int MAX_ENTRIES = WritingDeskBlockEntity.COLLECTIONS * NotebookContents.MAX_PAGES;
|
||||||
|
|
||||||
|
private WritingDeskCatalog() {}
|
||||||
|
|
||||||
|
public static List<SymbolDisplayMetadata> available(WritingDeskBlockEntity desk) {
|
||||||
|
Map<ResourceLocation, SymbolDisplayMetadata> unique = new TreeMap<>();
|
||||||
|
for (int slot = 0; slot < WritingDeskBlockEntity.COLLECTIONS; slot++) {
|
||||||
|
ItemStack collection = desk.getItem(slot);
|
||||||
|
if (collection.is(ModItems.PAGE.get())) add(unique, collection);
|
||||||
|
if (collection.is(ModItems.NOTEBOOK.get())) {
|
||||||
|
List<ItemStack> pages = collection.getOrDefault(
|
||||||
|
ModDataComponents.NOTEBOOK_CONTENTS.get(), NotebookContents.EMPTY).pages();
|
||||||
|
pages.forEach(page -> add(unique, page));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return unique.values().stream()
|
||||||
|
.sorted(Comparator.comparing((SymbolDisplayMetadata symbol) -> symbol.category().toString())
|
||||||
|
.thenComparing(symbol -> symbol.id().toString()))
|
||||||
|
.toList();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void add(Map<ResourceLocation, SymbolDisplayMetadata> unique, ItemStack page) {
|
||||||
|
if (!page.is(ModItems.PAGE.get())) return;
|
||||||
|
PageContent content = PageItem.content(page).resolve();
|
||||||
|
if (content.kind() != PageContent.Kind.SYMBOL) return;
|
||||||
|
SymbolReference reference = content.symbol().orElseThrow();
|
||||||
|
SymbolCatalog.find(reference).ifPresent(definition ->
|
||||||
|
unique.put(reference.id(), definition.display(reference.id())));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void write(RegistryFriendlyByteBuf buffer, List<SymbolDisplayMetadata> entries) {
|
||||||
|
if (entries.size() > MAX_ENTRIES) throw new IllegalArgumentException("Desk symbol catalog exceeds limit");
|
||||||
|
buffer.writeVarInt(entries.size());
|
||||||
|
entries.forEach(entry -> SymbolDisplayMetadata.STREAM_CODEC.encode(buffer, entry));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static List<SymbolDisplayMetadata> read(RegistryFriendlyByteBuf buffer) {
|
||||||
|
int count = buffer.readVarInt();
|
||||||
|
if (count < 0 || count > MAX_ENTRIES) throw new IllegalArgumentException("Invalid desk symbol count " + count);
|
||||||
|
List<SymbolDisplayMetadata> entries = new ArrayList<>(count);
|
||||||
|
for (int index = 0; index < count; index++) {
|
||||||
|
entries.add(SymbolDisplayMetadata.STREAM_CODEC.decode(buffer));
|
||||||
|
}
|
||||||
|
return List.copyOf(entries);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,82 @@
|
|||||||
|
package net.dnorberg.rivencraft.writing;
|
||||||
|
|
||||||
|
import com.mojang.serialization.Codec;
|
||||||
|
import com.mojang.serialization.DataResult;
|
||||||
|
import com.mojang.serialization.codecs.RecordCodecBuilder;
|
||||||
|
import io.netty.buffer.ByteBuf;
|
||||||
|
import java.util.Locale;
|
||||||
|
import java.util.Objects;
|
||||||
|
import java.util.Optional;
|
||||||
|
import net.minecraft.network.codec.ByteBufCodecs;
|
||||||
|
import net.minecraft.network.codec.StreamCodec;
|
||||||
|
|
||||||
|
/** One ordered unit of book writing. Interpretation belongs to Milestone 5. */
|
||||||
|
public record WritingEntry(Kind kind, Optional<SymbolReference> symbol) {
|
||||||
|
private static final Codec<Kind> KIND_CODEC = Codec.STRING.comapFlatMap(
|
||||||
|
value -> {
|
||||||
|
try {
|
||||||
|
return DataResult.success(Kind.valueOf(value.toUpperCase(Locale.ROOT)));
|
||||||
|
} catch (IllegalArgumentException exception) {
|
||||||
|
return DataResult.error(() -> "Unknown writing entry kind: " + value);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
value -> value.name().toLowerCase(Locale.ROOT)
|
||||||
|
);
|
||||||
|
private static final Codec<WritingEntry> RECORD_CODEC = RecordCodecBuilder.create(instance -> instance.group(
|
||||||
|
KIND_CODEC.fieldOf("kind").forGetter(WritingEntry::kind),
|
||||||
|
SymbolReference.CODEC.optionalFieldOf("symbol").forGetter(WritingEntry::symbol)
|
||||||
|
).apply(instance, WritingEntry::new));
|
||||||
|
public static final Codec<WritingEntry> CODEC = RECORD_CODEC.flatXmap(
|
||||||
|
WritingEntry::validate, WritingEntry::validate);
|
||||||
|
public static final StreamCodec<ByteBuf, WritingEntry> STREAM_CODEC = StreamCodec.of(
|
||||||
|
WritingEntry::encode, WritingEntry::decode);
|
||||||
|
|
||||||
|
public WritingEntry {
|
||||||
|
Objects.requireNonNull(kind, "kind");
|
||||||
|
symbol = Objects.requireNonNull(symbol, "symbol");
|
||||||
|
if (kind == Kind.SYMBOL && symbol.isEmpty()) {
|
||||||
|
throw new IllegalArgumentException("Symbol writing entries require a symbol reference");
|
||||||
|
}
|
||||||
|
if (kind == Kind.LINK_PANEL && symbol.isPresent()) {
|
||||||
|
throw new IllegalArgumentException("Link-panel writing entries cannot contain a symbol reference");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static WritingEntry symbol(SymbolReference symbol) {
|
||||||
|
return new WritingEntry(Kind.SYMBOL, Optional.of(symbol));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static WritingEntry linkPanel() {
|
||||||
|
return new WritingEntry(Kind.LINK_PANEL, Optional.empty());
|
||||||
|
}
|
||||||
|
|
||||||
|
private static DataResult<WritingEntry> validate(WritingEntry entry) {
|
||||||
|
return entry.kind == Kind.SYMBOL && entry.symbol.isEmpty()
|
||||||
|
|| entry.kind == Kind.LINK_PANEL && entry.symbol.isPresent()
|
||||||
|
? DataResult.error(() -> "Writing entry contents do not match kind " + entry.kind)
|
||||||
|
: DataResult.success(entry);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void encode(ByteBuf buffer, WritingEntry entry) {
|
||||||
|
ByteBufCodecs.VAR_INT.encode(buffer, entry.kind.ordinal());
|
||||||
|
if (entry.kind == Kind.SYMBOL) {
|
||||||
|
SymbolReference.STREAM_CODEC.encode(buffer, entry.symbol.orElseThrow());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static WritingEntry decode(ByteBuf buffer) {
|
||||||
|
int ordinal = ByteBufCodecs.VAR_INT.decode(buffer);
|
||||||
|
if (ordinal < 0 || ordinal >= Kind.values().length) {
|
||||||
|
throw new IllegalArgumentException("Unknown writing entry kind ordinal " + ordinal);
|
||||||
|
}
|
||||||
|
Kind kind = Kind.values()[ordinal];
|
||||||
|
return kind == Kind.SYMBOL
|
||||||
|
? symbol(SymbolReference.STREAM_CODEC.decode(buffer))
|
||||||
|
: linkPanel();
|
||||||
|
}
|
||||||
|
|
||||||
|
public enum Kind {
|
||||||
|
SYMBOL,
|
||||||
|
LINK_PANEL
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,77 @@
|
|||||||
|
package net.dnorberg.rivencraft.writing;
|
||||||
|
|
||||||
|
import net.dnorberg.rivencraft.config.RivencraftConfig;
|
||||||
|
import net.dnorberg.rivencraft.item.InkVialItem;
|
||||||
|
import net.dnorberg.rivencraft.item.PageItem;
|
||||||
|
import net.dnorberg.rivencraft.registry.ModDataComponents;
|
||||||
|
import net.dnorberg.rivencraft.registry.ModItems;
|
||||||
|
import net.minecraft.world.InteractionHand;
|
||||||
|
import net.minecraft.world.entity.player.Player;
|
||||||
|
import net.minecraft.world.item.ItemStack;
|
||||||
|
import net.minecraft.world.item.Items;
|
||||||
|
|
||||||
|
/** Server-owned costs and the baseline blank-page-to-link-panel transaction. */
|
||||||
|
public final class WritingInkService {
|
||||||
|
private WritingInkService() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int symbolCopyCost() {
|
||||||
|
return RivencraftConfig.symbolInkCost();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int linkPanelCost() {
|
||||||
|
return RivencraftConfig.linkPanelInkCost();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean canPrepareLinkPanel(Player player, InteractionHand vialHand) {
|
||||||
|
ItemStack vial = player.getItemInHand(vialHand);
|
||||||
|
ItemStack page = player.getItemInHand(other(vialHand));
|
||||||
|
int remaining = InkVialItem.remaining(vial);
|
||||||
|
return vial.is(ModItems.INK_VIAL.get()) && remaining >= linkPanelCost()
|
||||||
|
&& remaining <= InkVialItem.CAPACITY
|
||||||
|
&& page.is(Items.PAPER);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean prepareLinkPanel(Player player, InteractionHand vialHand) {
|
||||||
|
if (player.level().isClientSide || !canPrepareLinkPanel(player, vialHand)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
InteractionHand pageHand = other(vialHand);
|
||||||
|
ItemStack page = player.getItemInHand(pageHand);
|
||||||
|
ItemStack vial = player.getItemInHand(vialHand);
|
||||||
|
int newInk = InkVialItem.remaining(vial) - linkPanelCost();
|
||||||
|
ItemStack panel = PageItem.createLinkPanelPage();
|
||||||
|
ItemStack spentVial = newInk == 0
|
||||||
|
? new ItemStack(Items.GLASS_BOTTLE)
|
||||||
|
: new ItemStack(ModItems.INK_VIAL.get());
|
||||||
|
if (newInk > 0) {
|
||||||
|
spentVial.set(ModDataComponents.INK_REMAINING.get(), newInk);
|
||||||
|
}
|
||||||
|
|
||||||
|
// All validation and output construction is complete before changing either input.
|
||||||
|
if (page.getCount() == 1) {
|
||||||
|
player.setItemInHand(pageHand, panel);
|
||||||
|
} else {
|
||||||
|
page.shrink(1);
|
||||||
|
giveOrDrop(player, panel);
|
||||||
|
}
|
||||||
|
if (vial.getCount() == 1) {
|
||||||
|
player.setItemInHand(vialHand, spentVial);
|
||||||
|
} else {
|
||||||
|
vial.shrink(1);
|
||||||
|
giveOrDrop(player, spentVial);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static InteractionHand other(InteractionHand hand) {
|
||||||
|
return hand == InteractionHand.MAIN_HAND ? InteractionHand.OFF_HAND : InteractionHand.MAIN_HAND;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void giveOrDrop(Player player, ItemStack stack) {
|
||||||
|
if (!player.getInventory().add(stack)) {
|
||||||
|
player.drop(stack, false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
{
|
||||||
|
"variants": {
|
||||||
|
"facing=north,extension=false": {"model":"rivencraft:block/writing_desk"},
|
||||||
|
"facing=east,extension=false": {"model":"rivencraft:block/writing_desk","y":90},
|
||||||
|
"facing=south,extension=false": {"model":"rivencraft:block/writing_desk","y":180},
|
||||||
|
"facing=west,extension=false": {"model":"rivencraft:block/writing_desk","y":270},
|
||||||
|
"facing=north,extension=true": {"model":"rivencraft:block/writing_desk_extension"},
|
||||||
|
"facing=east,extension=true": {"model":"rivencraft:block/writing_desk_extension","y":90},
|
||||||
|
"facing=south,extension=true": {"model":"rivencraft:block/writing_desk_extension","y":180},
|
||||||
|
"facing=west,extension=true": {"model":"rivencraft:block/writing_desk_extension","y":270}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -6,6 +6,26 @@
|
|||||||
"item.rivencraft.linking_book.unbound": "Unbound — sneak-use to bind",
|
"item.rivencraft.linking_book.unbound": "Unbound — sneak-use to bind",
|
||||||
"item.rivencraft.linking_book.destination": "%s (%s, %s, %s)",
|
"item.rivencraft.linking_book.destination": "%s (%s, %s, %s)",
|
||||||
"item.rivencraft.linking_book.return": "Return Link",
|
"item.rivencraft.linking_book.return": "Return Link",
|
||||||
|
"item.rivencraft.page": "Page",
|
||||||
|
"item.rivencraft.page.blank": "Blank Page",
|
||||||
|
"item.rivencraft.page.blank.description": "Ready for writing at a Writing Desk.",
|
||||||
|
"item.rivencraft.page.link_panel": "Link Panel Page",
|
||||||
|
"item.rivencraft.page.link_panel.description": "The baseline panel required to assemble a Descriptive Book.",
|
||||||
|
"item.rivencraft.page.unresolved": "Unresolved Symbol Page",
|
||||||
|
"item.rivencraft.notebook": "Notebook",
|
||||||
|
"item.rivencraft.notebook.pages": "Pages: %s/%s",
|
||||||
|
"item.rivencraft.notebook.unresolved": "Unresolved pages: %s",
|
||||||
|
"item.rivencraft.ink_vial": "Ink Vial",
|
||||||
|
"block.rivencraft.writing_desk": "Writing Desk",
|
||||||
|
"container.rivencraft.writing_desk": "Writing Desk",
|
||||||
|
"screen.rivencraft.writing_desk.ink": "Ink: %s/%s",
|
||||||
|
"screen.rivencraft.writing_desk.search": "Search",
|
||||||
|
"screen.rivencraft.writing_desk.no_symbols": "No available symbols",
|
||||||
|
"item.rivencraft.ink_vial.remaining": "Ink: %s/%s",
|
||||||
|
"item.rivencraft.ink_vial.usage": "Use with paper in the other hand to prepare a Link Panel.",
|
||||||
|
"screen.rivencraft.notebook.search": "Search pages",
|
||||||
|
"screen.rivencraft.notebook.move_previous": "Move selected page left",
|
||||||
|
"screen.rivencraft.notebook.move_next": "Move selected page right",
|
||||||
"message.rivencraft.linking_book.bind_hint": "Sneak-use to bind this book to your current location",
|
"message.rivencraft.linking_book.bind_hint": "Sneak-use to bind this book to your current location",
|
||||||
"message.rivencraft.linking_book.unbound": "This Linking Book is unbound",
|
"message.rivencraft.linking_book.unbound": "This Linking Book is unbound",
|
||||||
"message.rivencraft.linking_book.bound": "Linking Book bound as %s",
|
"message.rivencraft.linking_book.bound": "Linking Book bound as %s",
|
||||||
@@ -57,6 +77,20 @@
|
|||||||
"trait.rivencraft.weather.snow": "Snow",
|
"trait.rivencraft.weather.snow": "Snow",
|
||||||
"trait.rivencraft.weather.storm": "Storm",
|
"trait.rivencraft.weather.storm": "Storm",
|
||||||
"trait.rivencraft.day_length.stopped": "Stopped",
|
"trait.rivencraft.day_length.stopped": "Stopped",
|
||||||
|
"symbol.rivencraft.unresolved": "Unresolved Symbol",
|
||||||
|
"symbol.rivencraft.unresolved.description": "Missing symbol: %s",
|
||||||
|
"symbol.rivencraft.terrain.standard": "Standard Terrain",
|
||||||
|
"symbol.rivencraft.terrain.standard.description": "A familiar continental terrain foundation.",
|
||||||
|
"symbol.rivencraft.biome.native": "Native Biomes",
|
||||||
|
"symbol.rivencraft.biome.native.description": "Use the terrain profile's native biome climate.",
|
||||||
|
"symbol.rivencraft.lighting.normal": "Normal Lighting",
|
||||||
|
"symbol.rivencraft.lighting.normal.description": "Use normal skylight and ambient brightness.",
|
||||||
|
"symbol.rivencraft.weather.normal": "Normal Weather",
|
||||||
|
"symbol.rivencraft.weather.normal.description": "Use the normal weather cycle.",
|
||||||
|
"symbol.rivencraft.celestial.normal_time": "Normal Time",
|
||||||
|
"symbol.rivencraft.celestial.normal_time.description": "Use a normal-length celestial cycle.",
|
||||||
|
"symbol.rivencraft.feature.caves": "Caves",
|
||||||
|
"symbol.rivencraft.feature.caves.description": "Describe underground cave features.",
|
||||||
"generator.rivencraft.standard": "Standard",
|
"generator.rivencraft.standard": "Standard",
|
||||||
"generator.rivencraft.amplified": "Amplified",
|
"generator.rivencraft.amplified": "Amplified",
|
||||||
"generator.rivencraft.island": "Island",
|
"generator.rivencraft.island": "Island",
|
||||||
@@ -69,5 +103,6 @@
|
|||||||
"screen.rivencraft.book.explore": "Explore",
|
"screen.rivencraft.book.explore": "Explore",
|
||||||
"screen.rivencraft.book.exploring": "Exploring",
|
"screen.rivencraft.book.exploring": "Exploring",
|
||||||
"screen.rivencraft.book.return_from_explore": "Right-click to return",
|
"screen.rivencraft.book.return_from_explore": "Right-click to return",
|
||||||
"itemGroup.rivencraft": "Rivencraft"
|
"itemGroup.rivencraft": "Rivencraft",
|
||||||
|
"itemGroup.rivencraft.pages": "Rivencraft Pages"
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,62 @@
|
|||||||
|
{
|
||||||
|
"format_version": "26.3",
|
||||||
|
"credit": "Made with Blockbench",
|
||||||
|
"parent": "minecraft:block/block",
|
||||||
|
"textures": {
|
||||||
|
"2": "rivencraft:block/writing_desk",
|
||||||
|
"particle": "rivencraft:block/writing_desk"
|
||||||
|
},
|
||||||
|
"elements": [
|
||||||
|
{
|
||||||
|
"from": [0, 11, 0],
|
||||||
|
"to": [16, 12, 16],
|
||||||
|
"rotation": {"angle": 0, "axis": "y", "origin": [0, 3, 0]},
|
||||||
|
"faces": {
|
||||||
|
"north": {"uv": [1, 2, 2, 2.125], "texture": "#2"},
|
||||||
|
"east": {"uv": [2.82031, 4.01563, 3.82031, 4.125], "texture": "#2"},
|
||||||
|
"south": {"uv": [0, 2, 1, 2.125], "texture": "#2"},
|
||||||
|
"west": {"uv": [2.9375, 0.125, 3, 2.125], "rotation": 90, "texture": "#2"},
|
||||||
|
"up": {"uv": [1, 0, 2, 2], "texture": "#2"},
|
||||||
|
"down": {"uv": [3, 0, 3.9375, 2], "texture": "#2"}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"from": [0, 0, 1],
|
||||||
|
"to": [1, 11, 15],
|
||||||
|
"faces": {
|
||||||
|
"north": {"uv": [7.6875, 2.625, 7.75, 4], "texture": "#2"},
|
||||||
|
"east": {"uv": [7.6875, 2.625, 6.6875, 4], "texture": "#2"},
|
||||||
|
"south": {"uv": [1.42188, 10.78125, 2.4375, 11.85938], "texture": "#2"},
|
||||||
|
"west": {"uv": [5.67969, 2.625, 6.6875, 4], "texture": "#2"},
|
||||||
|
"up": {"uv": [0.08594, 10.36719, 1.14063, 11.83594], "texture": "#2"},
|
||||||
|
"down": {"uv": [5.75, 5.25, 5.8125, 7.10938], "texture": "#2"}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"from": [1, 5, 1],
|
||||||
|
"to": [16, 6, 15],
|
||||||
|
"rotation": {"angle": 0, "axis": "y", "origin": [0, 2, 0]},
|
||||||
|
"faces": {
|
||||||
|
"north": {"uv": [3, 2, 3.9375, 2.125], "texture": "#2"},
|
||||||
|
"east": {"uv": [2.8125, 4, 3.75, 4.125], "texture": "#2"},
|
||||||
|
"south": {"uv": [1.35938, 11.71875, 2.44531, 12.71875], "texture": "#2"},
|
||||||
|
"west": {"uv": [0.03125, 11.66406, 0.99219, 12.66406], "texture": "#2"},
|
||||||
|
"up": {"uv": [1.875, 4, 2.8125, 2.125], "texture": "#2"},
|
||||||
|
"down": {"uv": [0.9375, 2.125, 1.875, 4], "texture": "#2"}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"from": [0, 0, 15],
|
||||||
|
"to": [16, 11, 16],
|
||||||
|
"rotation": {"angle": 0, "axis": "y", "origin": [0, -9, 0]},
|
||||||
|
"faces": {
|
||||||
|
"north": {"uv": [8.0625, 0, 9.0625, 1.375], "texture": "#2"},
|
||||||
|
"east": {"uv": [6.625, 0.125, 6.6875, 1.5], "texture": "#2"},
|
||||||
|
"south": {"uv": [5.625, 2.625, 6.625, 4], "texture": "#2"},
|
||||||
|
"west": {"uv": [7.6875, 2.625, 7.75, 4], "texture": "#2"},
|
||||||
|
"up": {"uv": [0, 15, 16, 16], "texture": "#2"},
|
||||||
|
"down": {"uv": [0, 9.17969, 16, 10.17969], "texture": "#2"}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
@@ -0,0 +1,88 @@
|
|||||||
|
{
|
||||||
|
"format_version": "26.3",
|
||||||
|
"credit": "Made with Blockbench",
|
||||||
|
"parent": "minecraft:block/block",
|
||||||
|
"textures": {
|
||||||
|
"2": "rivencraft:block/writing_desk",
|
||||||
|
"particle": "rivencraft:block/writing_desk"
|
||||||
|
},
|
||||||
|
"elements": [
|
||||||
|
{
|
||||||
|
"from": [1, 0, 1],
|
||||||
|
"to": [15, 1, 15],
|
||||||
|
"rotation": {"angle": 0, "axis": "y", "origin": [1, 0, 0]},
|
||||||
|
"faces": {
|
||||||
|
"north": {"uv": [1.8125, 4.125, 2.8125, 4.25], "texture": "#2"},
|
||||||
|
"east": {"uv": [0.21875, 11.88281, 1.04688, 12.88281], "texture": "#2"},
|
||||||
|
"south": {"uv": [1.53906, 10.5625, 2.63281, 11.5625], "texture": "#2"},
|
||||||
|
"west": {"uv": [0.14063, 10.5625, 1.17969, 11.5625], "texture": "#2"},
|
||||||
|
"up": {"uv": [1.8125, 4.125, 2.8125, 2.125], "texture": "#2"},
|
||||||
|
"down": {"uv": [4, 0, 5, 2], "texture": "#2"}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"from": [0, 11, 0],
|
||||||
|
"to": [16, 12, 16],
|
||||||
|
"rotation": {"angle": 0, "axis": "y", "origin": [0, 3, 0]},
|
||||||
|
"faces": {
|
||||||
|
"north": {"uv": [2, 2, 3, 2.125], "texture": "#2"},
|
||||||
|
"east": {"uv": [1, 0, 1.0625, 2], "rotation": 90, "texture": "#2"},
|
||||||
|
"south": {"uv": [3, 2, 4, 2.125], "texture": "#2"},
|
||||||
|
"west": {"uv": [2.8125, 4, 3.8125, 4.125], "texture": "#2"},
|
||||||
|
"up": {"uv": [2, 0, 3, 2], "texture": "#2"},
|
||||||
|
"down": {"uv": [9, 0, 10, 2], "texture": "#2"}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"from": [15, 0, 1],
|
||||||
|
"to": [16, 11, 15],
|
||||||
|
"faces": {
|
||||||
|
"north": {"uv": [7.6875, 2.625, 7.75, 4], "texture": "#2"},
|
||||||
|
"east": {"uv": [10.00156, 0.625, 11.00156, 2], "texture": "#2"},
|
||||||
|
"south": {"uv": [1.99219, 10.77344, 2.99219, 12.02344], "texture": "#2"},
|
||||||
|
"west": {"uv": [6.6875, 2.625, 7.6875, 4], "texture": "#2"},
|
||||||
|
"up": {"uv": [0.49219, 10.96094, 1.49219, 12.08594], "texture": "#2"},
|
||||||
|
"down": {"uv": [5.75313, 5.36719, 5.8125, 7.125], "texture": "#2"}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"from": [0, 0, 1],
|
||||||
|
"to": [1, 11, 15],
|
||||||
|
"rotation": {"angle": 0, "axis": "y", "origin": [-15, 0, 0]},
|
||||||
|
"faces": {
|
||||||
|
"north": {"uv": [7.68828, 2.625, 7.75078, 4], "texture": "#2"},
|
||||||
|
"east": {"uv": [7.6875, 2.62539, 6.6875, 4.00039], "texture": "#2"},
|
||||||
|
"south": {"uv": [0.05469, 12.22656, 1.05469, 13.32031], "texture": "#2"},
|
||||||
|
"west": {"uv": [3, 0, 4, 1.375], "texture": "#2"},
|
||||||
|
"up": {"uv": [0.15625, 10.83594, 1.15625, 11.97656], "texture": "#2"},
|
||||||
|
"down": {"uv": [7, 4.60156, 7.0625, 6.375], "texture": "#2"}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"from": [1, 5, 1],
|
||||||
|
"to": [15, 6, 15],
|
||||||
|
"rotation": {"angle": 0, "axis": "y", "origin": [1, 2, 0]},
|
||||||
|
"faces": {
|
||||||
|
"north": {"uv": [1.8125, 4.25, 2.8125, 4.125], "texture": "#2"},
|
||||||
|
"east": {"uv": [1.86719, 11.82813, 2.79688, 12.82813], "texture": "#2"},
|
||||||
|
"south": {"uv": [0.32813, 11.80469, 1.28906, 12.80469], "texture": "#2"},
|
||||||
|
"west": {"uv": [0.27344, 10.5625, 1.53125, 11.5625], "texture": "#2"},
|
||||||
|
"up": {"uv": [1.8125, 4.125, 2.8125, 2.125], "texture": "#2"},
|
||||||
|
"down": {"uv": [9, 0, 10, 2], "texture": "#2"}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"from": [0, 0, 15],
|
||||||
|
"to": [16, 11, 16],
|
||||||
|
"rotation": {"angle": 0, "axis": "y", "origin": [0, -9, 0]},
|
||||||
|
"faces": {
|
||||||
|
"north": {"uv": [9, 0.125, 10, 1.5], "texture": "#2"},
|
||||||
|
"east": {"uv": [10.8125, 0.625, 10.875, 2], "texture": "#2"},
|
||||||
|
"south": {"uv": [10.875, 0.625, 11.875, 2], "texture": "#2"},
|
||||||
|
"west": {"uv": [6.6875, 0.125, 6.75, 1.5], "texture": "#2"},
|
||||||
|
"up": {"uv": [0, 15, 16, 16], "texture": "#2"},
|
||||||
|
"down": {"uv": [2.8125, 4, 3.8125, 4.125], "texture": "#2"}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
{
|
||||||
|
"parent": "minecraft:item/generated",
|
||||||
|
"textures": {
|
||||||
|
"layer0": "rivencraft:item/ink_vial"
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,6 +1,14 @@
|
|||||||
{
|
{
|
||||||
"parent": "minecraft:item/generated",
|
"parent": "minecraft:item/generated",
|
||||||
"textures": {
|
"textures": {
|
||||||
"layer0": "rivencraft:item/linking_book"
|
"layer0": "rivencraft:item/linking_book_unwritten"
|
||||||
}
|
},
|
||||||
|
"overrides": [
|
||||||
|
{
|
||||||
|
"predicate": {
|
||||||
|
"rivencraft:bound": 1.0
|
||||||
|
},
|
||||||
|
"model": "rivencraft:item/linking_book_bound"
|
||||||
|
}
|
||||||
|
]
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
{
|
||||||
|
"parent": "minecraft:item/generated",
|
||||||
|
"textures": {
|
||||||
|
"layer0": "rivencraft:item/linking_book"
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
{
|
||||||
|
"parent": "minecraft:item/generated",
|
||||||
|
"textures": {
|
||||||
|
"layer0": "rivencraft:item/notebook"
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
{
|
||||||
|
"parent": "minecraft:item/generated",
|
||||||
|
"textures": {
|
||||||
|
"layer0": "rivencraft:item/page"
|
||||||
|
},
|
||||||
|
"overrides": [
|
||||||
|
{ "predicate": { "custom_model_data": 1 }, "model": "rivencraft:item/page_link_panel" },
|
||||||
|
{ "predicate": { "custom_model_data": 2 }, "model": "rivencraft:item/page_unresolved" },
|
||||||
|
{ "predicate": { "custom_model_data": 3 }, "model": "rivencraft:item/page_symbol" },
|
||||||
|
{ "predicate": { "custom_model_data": 100 }, "model": "rivencraft:item/page_symbol_terrain_standard" },
|
||||||
|
{ "predicate": { "custom_model_data": 101 }, "model": "rivencraft:item/page_symbol_biome_native" },
|
||||||
|
{ "predicate": { "custom_model_data": 102 }, "model": "rivencraft:item/page_symbol_lighting_normal" },
|
||||||
|
{ "predicate": { "custom_model_data": 103 }, "model": "rivencraft:item/page_symbol_weather_normal" },
|
||||||
|
{ "predicate": { "custom_model_data": 104 }, "model": "rivencraft:item/page_symbol_celestial_normal_time" },
|
||||||
|
{ "predicate": { "custom_model_data": 105 }, "model": "rivencraft:item/page_symbol_feature_caves" }
|
||||||
|
]
|
||||||
|
}
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
{
|
||||||
|
"parent": "minecraft:item/generated",
|
||||||
|
"textures": {
|
||||||
|
"layer0": "rivencraft:item/page_link_panel"
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
{
|
||||||
|
"parent": "minecraft:item/generated",
|
||||||
|
"textures": {
|
||||||
|
"layer0": "rivencraft:item/page_symbol"
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
{
|
||||||
|
"parent": "minecraft:item/generated",
|
||||||
|
"textures": { "layer0": "rivencraft:item/page_symbol_biome_native" }
|
||||||
|
}
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
{
|
||||||
|
"parent": "minecraft:item/generated",
|
||||||
|
"textures": { "layer0": "rivencraft:item/page_symbol_celestial_normal_time" }
|
||||||
|
}
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
{
|
||||||
|
"parent": "minecraft:item/generated",
|
||||||
|
"textures": { "layer0": "rivencraft:item/page_symbol_feature_caves" }
|
||||||
|
}
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
{
|
||||||
|
"parent": "minecraft:item/generated",
|
||||||
|
"textures": { "layer0": "rivencraft:item/page_symbol_lighting_normal" }
|
||||||
|
}
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
{
|
||||||
|
"parent": "minecraft:item/generated",
|
||||||
|
"textures": { "layer0": "rivencraft:item/page_symbol_terrain_standard" }
|
||||||
|
}
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
{
|
||||||
|
"parent": "minecraft:item/generated",
|
||||||
|
"textures": { "layer0": "rivencraft:item/page_symbol_weather_normal" }
|
||||||
|
}
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
{
|
||||||
|
"parent": "minecraft:item/generated",
|
||||||
|
"textures": {
|
||||||
|
"layer0": "rivencraft:item/page_unresolved"
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
{
|
||||||
|
"parent": "minecraft:item/generated",
|
||||||
|
"textures": {"layer0": "rivencraft:item/writing_desk"}
|
||||||
|
}
|
||||||
|
After Width: | Height: | Size: 99 KiB |
|
After Width: | Height: | Size: 5.2 KiB |
|
After Width: | Height: | Size: 3.0 KiB |
|
Before Width: | Height: | Size: 546 B After Width: | Height: | Size: 449 B |
|
Before Width: | Height: | Size: 1.0 KiB After Width: | Height: | Size: 507 B |
|
After Width: | Height: | Size: 4.3 KiB |
|
After Width: | Height: | Size: 340 B |
|
After Width: | Height: | Size: 2.1 KiB |
|
After Width: | Height: | Size: 1.7 KiB |
@@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"animation": {}
|
||||||
|
}
|
||||||
|
After Width: | Height: | Size: 405 B |
|
After Width: | Height: | Size: 303 B |
|
After Width: | Height: | Size: 297 B |
|
After Width: | Height: | Size: 941 B |
|
After Width: | Height: | Size: 1.3 KiB |
|
After Width: | Height: | Size: 12 KiB |
|
After Width: | Height: | Size: 12 KiB |
|
After Width: | Height: | Size: 12 KiB |
|
After Width: | Height: | Size: 12 KiB |
|
After Width: | Height: | Size: 12 KiB |
|
After Width: | Height: | Size: 12 KiB |
|
After Width: | Height: | Size: 1.3 KiB |
|
After Width: | Height: | Size: 208 B |
@@ -0,0 +1,4 @@
|
|||||||
|
{
|
||||||
|
"type": "minecraft:block",
|
||||||
|
"pools": [{ "rolls": 1, "entries": [{ "type": "minecraft:item", "name": "rivencraft:writing_desk" }] }]
|
||||||
|
}
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
{
|
||||||
|
"type": "minecraft:crafting_shapeless",
|
||||||
|
"category": "misc",
|
||||||
|
"ingredients": [
|
||||||
|
{ "item": "minecraft:black_dye" },
|
||||||
|
{ "item": "minecraft:black_dye" },
|
||||||
|
{ "item": "minecraft:glass_bottle" },
|
||||||
|
{ "item": "minecraft:water_bucket" }
|
||||||
|
],
|
||||||
|
"result": {
|
||||||
|
"count": 1,
|
||||||
|
"id": "rivencraft:ink_vial"
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
{
|
||||||
|
"type": "minecraft:crafting_shaped",
|
||||||
|
"category": "misc",
|
||||||
|
"key": {
|
||||||
|
"L": {
|
||||||
|
"item": "minecraft:leather"
|
||||||
|
},
|
||||||
|
"S": {
|
||||||
|
"item": "minecraft:string"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"pattern": [
|
||||||
|
" L ",
|
||||||
|
"S ",
|
||||||
|
" L "
|
||||||
|
],
|
||||||
|
"result": {
|
||||||
|
"count": 1,
|
||||||
|
"id": "rivencraft:notebook"
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
{
|
||||||
|
"type": "minecraft:crafting_shaped",
|
||||||
|
"category": "misc",
|
||||||
|
"pattern": ["V F", "PPP", "P P"],
|
||||||
|
"key": {
|
||||||
|
"V": { "item": "minecraft:glass_bottle" },
|
||||||
|
"F": { "item": "minecraft:feather" },
|
||||||
|
"P": { "tag": "minecraft:planks" }
|
||||||
|
},
|
||||||
|
"result": { "id": "rivencraft:writing_desk", "count": 1 }
|
||||||
|
}
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
{
|
||||||
|
"schema_version": 1,
|
||||||
|
"name": "symbol.rivencraft.biome.native",
|
||||||
|
"description": "symbol.rivencraft.biome.native.description",
|
||||||
|
"category": "rivencraft:biome"
|
||||||
|
}
|
||||||