Compare commits

..
2 Commits
Author SHA1 Message Date
dnorberg 27abebe3aa Validate ordered Age writing and highlight Binder errors (#30)
Build / build (push) Canceled after 0s
2026-09-30 15:39:53 -04:00
dnorberg 5538ca6aa6 Render Legacy glyph pages and base-25 desk numerals
Build / build (push) Canceled after 0s
2026-09-30 13:20:56 -04:00
47 changed files with 949 additions and 127 deletions

No files matched your search

+1 -1
View File
@@ -17,7 +17,7 @@ tasks.named('wrapper', Wrapper).configure {
version = mod_version
group = mod_group_id
List<String> archivedGameTestSuites = ['linking', 'writing', 'desk', 'binder', 'mixer', 'recipe']
List<String> archivedGameTestSuites = ['linking', 'writing', 'grammar', 'desk', 'binder', 'mixer', 'recipe']
List<String> selectedArchivedGameTestSuites = providers.gradleProperty('withArchivedGameTests')
.map { it.toBoolean() }.orElse(false).get() ? archivedGameTestSuites
: providers.gradleProperty('archivedGameTestSuites').orElse('').get()
+2 -1
View File
@@ -23,7 +23,8 @@ project's GNU LGPL v3 license. Rivencraft itself uses the same license.
| `assets/rivencraft/textures/block/ink_mixer_top.png`, `ink_mixer_side.png`, `ink_mixer_bottom.png` | `assets/mystcraft/textures/blocks/inkmixer_top.png`, `inkmixer_side.png`, `inkmixer_bottom.png` | `9bc8ddc061845df0cd5ea47f4fdef773cff786ae` | Namespace/path rename only; Rivencraft supplies its own block model |
| `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 |
| `assets/rivencraft/textures/gui/symbolcomponents.png` | `assets/mystcraft/textures/symbolcomponents.png` | `9bc8ddc061845df0cd5ea47f4fdef773cff786ae` | Byte-identical shared 512×512 component sheet for client-side page composition |
| Runtime-composed symbol pages (`SymbolPageTextures`) | `page_background.png`, `textures/symbolcomponents.png`, `WordData`, `ModSymbols`, and `PageBuilder.PageSprite` | `9bc8ddc061845df0cd5ea47f4fdef773cff786ae` | Replaces the six pre-generated symbol PNGs; layers four poem words on the shared page background and caches bounded client textures |
Mystcraft Legacy identifies XCompWiz as its project developer and includes the
full LGPL v3 text in its root `LICENSE` file. Rivencraft's root `LICENSE`
+6 -6
View File
@@ -1,15 +1,15 @@
# GameTest suites
The default dedicated-server run is a small smoke suite: 17 Rivencraft tests
The default dedicated-server run is a small smoke suite: 19 Rivencraft tests
cover core linking, deterministic Age definition, writing persistence, legacy
data migration, workstation transactions, and forged/replayed menu actions.
NeoForge currently adds two of its own tests, so the runner reports 19.
NeoForge currently adds two of its own tests, so the runner reports 21.
```shell
./gradlew runGameTestServer
```
The remaining 47 Rivencraft tests are archived, not deleted. They cover
The remaining 49 Rivencraft tests are archived, not deleted. They cover
completed milestone details such as every Age terrain profile, Notebook and
Desk surface interactions, refill edge cases, book assembly controls, and
workstation break/drop behavior. Run only the relevant archive alongside the
@@ -17,11 +17,11 @@ core tests when investigating an issue:
```shell
./gradlew runGameTestServer -ParchivedGameTestSuites=desk
./gradlew runGameTestServer -ParchivedGameTestSuites=linking,binder
./gradlew runGameTestServer -ParchivedGameTestSuites=grammar,binder
```
Available suite names are `linking`, `writing`, `desk`, `binder`, `mixer`, and
`recipe`. Run all 64 Rivencraft tests (66 including NeoForge's two) before a
Available suite names are `linking`, `writing`, `grammar`, `desk`, `binder`, `mixer`, and
`recipe`. Run all 68 Rivencraft tests (70 including NeoForge's two) before a
release or after broad cross-system changes:
```shell
+7 -2
View File
@@ -11,12 +11,17 @@ Milestone 5 issue #29 adds typed meaning to the existing data-pack symbol catalo
"semantics": {
"role": "terrain",
"value": "example:highlands"
}
},
"poem": "Terrain Form Tradition Flow"
}
```
`name` and `description` are translation keys. `category` is for display and sorting; it does not determine grammar. `semantics.role` and its typed `value` are server-owned. The terrain value above names an Age runtime profile that a later compiler must resolve and validate. A syntactically valid resource ID alone does not guarantee the profile or feature exists.
`poem` is optional, client-safe artwork metadata: exactly four alphabetic words, ordered top, right, bottom, left. The client layers their glyphs from the shared Legacy component sheet at runtime. GUI thumbnails use the full transparent artwork over their page backgrounds; item icons use the same artwork reduced from 16 to 13 pixels across, over the page texture. Unregistered words use a stable generated component combination; when a symbol has no poem, the six original built-in IDs retain their Legacy poems and other IDs produce four stable fallback words. This affects appearance only, never Age generation. Generated images are cached up to 256 entries and discarded on resource reload.
The Writing Desk's 88 collection tabs use Legacy's number components, chiefly the bottom row of `symbolcomponents.png`, rather than word sigils. Legacy's `ModWords.constructNumber` combines four unit marks (1–4) with four five-step marks (5–20) to form 1–24 and uses a separate zero mark. Rivencraft extends these marks positionally in base 25 for tabs 25–88 (for example, 25 is 1 followed by 0). Hovering still reveals the decimal number for accessibility. The former arbitrary-word glyph generator remains useful for rendering text: on page-free Descriptive Books, the generated Age description now appears as a sequence of layered word glyphs instead of Minecraft's enchantment font. The Age name stays readable.
| Role | Value type and allowed values |
| --- | --- |
| `terrain` | Canonical namespaced Age profile ID. |
@@ -34,6 +39,6 @@ These are schema bounds, not claims that Legacy shipped numeric config ranges. S
The server rejects a v2 definition with an unknown top-level or semantics field, missing/incorrectly typed field, unknown role or choice, malformed/non-canonical resource ID, or out-of-range/non-finite number. An invalid definition is logged with its file ID and excluded from the active catalog. Saved pages and books still retain that ID, allowing the player to recover them if the data pack is corrected. A reload atomically replaces the catalog rather than mutating saved writing.
Schema v1 definitions remain readable as **display-only** symbols; existing packs need not be rewritten merely to show or copy pages. A v1 definition cannot add a `semantics` field. To make one eligible for future Age compilation, publish a v2 definition with the **same file path and ID**, adding a valid role and value. Do not rename the page ID or reorder a book's `OrderedWriting`. The client receives only `SymbolDisplayMetadata` (ID, translation keys, category, resolved flag); semantic definitions are not serialized to it. This slice defines and validates meaning but does **not yet apply** written symbols to Age generation; issues #30 and #31 implement parsing and compilation.
Schema v1 definitions remain readable as **display-only** symbols; existing packs need not be rewritten merely to show or copy pages. A v1 definition cannot add a `semantics` field. To make one eligible for Age grammar parsing, publish a v2 definition with the **same file path and ID**, adding a valid role and value. Do not rename the page ID or reorder a book's `OrderedWriting`. The client receives only `SymbolDisplayMetadata` (ID, translation keys, category, resolved flag); semantic definitions are not serialized to it. The [ordered-writing parser](WRITING_GRAMMAR.md) validates new books, but does **not yet apply** written symbols to Age generation; issue #31 adds compilation.
The six built-in definitions demonstrate terrain, biome-controller, lighting, weather, celestial, and feature roles. A third-party pack may add its own definitions under its namespace. Use an explicit semantic role even when the display category has the same name; the two fields serve different purposes.
+11
View File
@@ -0,0 +1,11 @@
# Ordered Descriptive Book grammar (Milestone 5, issue #30)
`WritingGrammar` interprets the saved `OrderedWriting` on the server using only `SymbolCatalog`'s schema-v2 semantics. Client display metadata, page names, and supplied translations never determine an Age's meaning. The parser is pure: it returns immutable parsed entries and indexed diagnostics without changing a book or its pages.
New Binder writing has at most one Link Panel plus 27 symbol pages. The Link Panel must be first. A Link-Panel-only book, or an older book with no writing component, keeps the existing random Age path. Any authored supported symbol makes the book a partial or complete grammar, even though **0.4.2.0 still generates a random Age**; issue #31 will compile it into a persistent plan before chunk generation.
The supported order follows the representable subset of the [Legacy grammar audit](LEGACY_AGE_GRAMMAR_AUDIT.md): terrain; zero or more biome pages; biome controller; weather; lighting; zero or more period, angle, or phase modifiers; one celestial page; then zero or more distinct features. Biome pages precede the controller that consumes them, and celestial modifiers precede the celestial page. Terrain, controller, weather, lighting, and celestial are single-choice categories; identical repeats are duplicates and differing values conflict. Repeated modifiers are intentional. Biome pages may repeat, preserving author order and any future weighting; feature IDs may not repeat.
Missing terrain, controller, weather, lighting, celestial, or the controller's minimum biome count is an **incomplete** warning, not an error: issue #31 will fill those branches deterministically from the Age seed. The minimum is zero for Native, one for Single, two for Tiled/Grid, and three for Tiny–Huge. Native cannot consume authored biome pages; Single accepts only one. Unknown IDs, schema-v1 display-only symbols, wrong ordering, misplaced modifiers, duplicates, conflicts, missing/extra Link Panels, and oversized writing are errors. The Binder disables output and exposes the first error on the result-slot tooltip. When that error belongs to a page, its thumbnail is tinted and outlined red, the strip scrolls to it, and hovering it shows the diagnostic. This maps the parser's compact entry position back through any empty page positions. Rejected inputs remain removable. Binding an unwritten Descriptive Book rechecks its server-owned writing and reports the first error without creating an Age.
This slice does not score instability, synthesize missing symbols, or apply symbol effects. Those responsibilities belong to issues #31–#35 and Milestone 6. Existing bound books are not revalidated or migrated merely because a data pack changes.
+1 -1
View File
@@ -36,7 +36,7 @@ mod_name=Rivencraft
# 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
# The mod version. Rivencraft uses the x.y.z.b policy documented in README.md.
mod_version=0.4.1.0
mod_version=0.4.2.1
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.
# This should match the base package used for the mod sources.
@@ -12,6 +12,7 @@ import net.dnorberg.rivencraft.registry.ModItems;
import net.dnorberg.rivencraft.writing.NotebookContents;
import net.dnorberg.rivencraft.writing.OrderedWriting;
import net.dnorberg.rivencraft.writing.PageContent;
import net.dnorberg.rivencraft.writing.WritingGrammar;
import net.dnorberg.rivencraft.writing.WritingEntry;
import net.minecraft.core.BlockPos;
import net.minecraft.core.HolderLookup;
@@ -108,7 +109,40 @@ public final class BookBinderBlockEntity extends BlockEntity implements Containe
if (!page.isEmpty() && (!validPage(page) || !PageItem.isUsableWriting(page) || page.getCount() != 1
|| PageItem.content(page).kind() == PageContent.Kind.BLANK)) return false;
}
return true;
return WritingGrammar.parse(currentWriting()).canCreate();
}
public WritingGrammar.Result writingGrammar() {
return WritingGrammar.parse(currentWriting());
}
/** Map the parser's compact entry index back to the visible strip, including empty page positions. */
public int writingStripIndex(int grammarIndex) {
if (grammarIndex < 0) return -1;
int entryIndex = 0;
if (canPlaceItem(LINK_PANEL, items.get(LINK_PANEL))) {
if (grammarIndex == 0) return 0;
entryIndex++;
}
for (int slot = FIRST_PAGE; slot < SIZE; slot++) {
ItemStack page = items.get(slot);
if (!page.isEmpty() && PageItem.content(page).symbol().isPresent()) {
if (entryIndex == grammarIndex) return slot - FIRST_PAGE + 1;
entryIndex++;
}
}
return -1;
}
private OrderedWriting currentWriting() {
List<WritingEntry> entries = new ArrayList<>();
if (canPlaceItem(LINK_PANEL, items.get(LINK_PANEL))) entries.add(WritingEntry.linkPanel());
for (int slot = FIRST_PAGE; slot < SIZE; slot++) {
ItemStack page = items.get(slot);
if (!page.isEmpty()) PageItem.content(page).symbol().ifPresent(reference ->
entries.add(WritingEntry.symbol(reference)));
}
return new OrderedWriting(entries);
}
public ItemStack previewBook() {
@@ -117,15 +151,9 @@ public final class BookBinderBlockEntity extends BlockEntity implements Containe
pendingAgeId = UUID.randomUUID();
setChanged();
}
List<WritingEntry> entries = new ArrayList<>();
entries.add(WritingEntry.linkPanel());
for (int slot = FIRST_PAGE; slot < SIZE; slot++) {
ItemStack page = items.get(slot);
if (!page.isEmpty()) entries.add(WritingEntry.symbol(PageItem.content(page).symbol().orElseThrow()));
}
ItemStack book = new ItemStack(ModItems.DESCRIPTIVE_BOOK.get());
book.set(ModDataComponents.AGE_REFERENCE.get(), new AgeReference(pendingAgeId, title));
book.set(ModDataComponents.BOOK_WRITING.get(), new OrderedWriting(entries));
book.set(ModDataComponents.BOOK_WRITING.get(), currentWriting());
book.set(DataComponents.CUSTOM_NAME, Component.literal(title));
return book;
}
@@ -13,6 +13,10 @@ import net.neoforged.fml.event.lifecycle.FMLClientSetupEvent;
import net.neoforged.neoforge.common.NeoForge;
import net.neoforged.neoforge.client.event.EntityRenderersEvent;
import net.neoforged.neoforge.client.event.RegisterMenuScreensEvent;
import net.neoforged.neoforge.client.event.RegisterClientReloadListenersEvent;
import net.neoforged.neoforge.client.extensions.common.IClientItemExtensions;
import net.neoforged.neoforge.client.extensions.common.RegisterClientExtensionsEvent;
import net.minecraft.client.renderer.BlockEntityWithoutLevelRenderer;
import net.dnorberg.rivencraft.client.screen.NotebookScreen;
import net.dnorberg.rivencraft.client.screen.WritingDeskScreen;
import net.dnorberg.rivencraft.client.screen.BookBinderScreen;
@@ -38,6 +42,24 @@ public final class ClientEvents {
event.register(ModMenus.INK_MIXER.get(), InkMixerScreen::new);
}
@SubscribeEvent
public static void registerPageItemRenderer(RegisterClientExtensionsEvent event) {
event.registerItem(new IClientItemExtensions() {
private final SymbolPageItemRenderer renderer = new SymbolPageItemRenderer();
@Override
public BlockEntityWithoutLevelRenderer getCustomRenderer() {
return renderer;
}
}, ModItems.PAGE.get());
}
@SubscribeEvent
public static void registerPageTextureReload(RegisterClientReloadListenersEvent event) {
event.registerReloadListener((net.minecraft.server.packs.resources.ResourceManagerReloadListener)
manager -> SymbolPageTextures.clear());
}
@SubscribeEvent
public static void clientSetup(FMLClientSetupEvent event) {
event.enqueueWork(() -> ItemProperties.register(
@@ -0,0 +1,47 @@
package net.dnorberg.rivencraft.client;
import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.blaze3d.vertex.VertexConsumer;
import net.dnorberg.rivencraft.Rivencraft;
import net.dnorberg.rivencraft.item.PageItem;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.BlockEntityWithoutLevelRenderer;
import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.ItemDisplayContext;
import net.minecraft.world.item.ItemStack;
/** Flat page model whose symbol artwork is resolved from the stack at render time. */
public final class SymbolPageItemRenderer extends BlockEntityWithoutLevelRenderer {
public SymbolPageItemRenderer() {
super(Minecraft.getInstance().getBlockEntityRenderDispatcher(), Minecraft.getInstance().getEntityModels());
}
@Override
public void renderByItem(ItemStack stack, ItemDisplayContext context, PoseStack pose,
MultiBufferSource buffers, int light, int overlay) {
ResourceLocation texture = switch (PageItem.content(stack).kind()) {
case BLANK -> texture("page");
case LINK_PANEL -> texture("page_link_panel");
case UNRESOLVED_SYMBOL -> texture("page_unresolved");
case SYMBOL -> SymbolPageTextures.forItem(stack);
};
VertexConsumer vertices = buffers.getBuffer(RenderType.entityCutoutNoCull(texture));
var matrix = pose.last().pose();
vertex(vertices, matrix, 0, 0, 0, 1, light, overlay);
vertex(vertices, matrix, 1, 0, 1, 1, light, overlay);
vertex(vertices, matrix, 1, 1, 1, 0, light, overlay);
vertex(vertices, matrix, 0, 1, 0, 0, light, overlay);
}
private static void vertex(VertexConsumer vertices, org.joml.Matrix4f matrix,
float x, float y, float u, float v, int light, int overlay) {
vertices.addVertex(matrix, x, y, 0.5F).setColor(255, 255, 255, 255)
.setUv(u, v).setOverlay(overlay).setLight(light).setNormal(0, 0, 1);
}
private static ResourceLocation texture(String name) {
return ResourceLocation.fromNamespaceAndPath(Rivencraft.MOD_ID, "textures/item/" + name + ".png");
}
}
@@ -0,0 +1,240 @@
package net.dnorberg.rivencraft.client;
import com.mojang.blaze3d.platform.NativeImage;
import java.io.IOException;
import java.io.InputStream;
import java.util.LinkedHashMap;
import java.util.Locale;
import java.util.Map;
import java.util.Random;
import net.dnorberg.rivencraft.Rivencraft;
import net.dnorberg.rivencraft.item.PageItem;
import net.dnorberg.rivencraft.registry.ModDataComponents;
import net.dnorberg.rivencraft.writing.PageContent;
import net.dnorberg.rivencraft.writing.SymbolDisplayMetadata;
import net.dnorberg.rivencraft.writing.SymbolPoems;
import net.dnorberg.rivencraft.writing.SymbolNumerals;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.renderer.texture.DynamicTexture;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.packs.resources.ResourceManager;
import net.minecraft.world.item.ItemStack;
/** Client-only, bounded cache of Legacy-style page compositions; no per-symbol PNGs. */
public final class SymbolPageTextures {
private static final int SIZE = 128;
private static final int GLYPH = 51;
// A 16 px item icon displays a 13 px symbol: three pixels narrower overall.
private static final int ITEM_SYMBOL_SIZE = 13;
private static final int ICON_SIZE = 16;
private static final int CACHE_LIMIT = 256;
private static final ResourceLocation BASE = texture("item/page");
private static final ResourceLocation COMPONENTS = texture("gui/symbolcomponents");
private static final ResourceLocation FALLBACK = texture("item/page_symbol");
private static final Map<String, ResourceLocation> CACHE = new LinkedHashMap<>(16, .75F, true);
private static final Map<String, int[]> WORD_CACHE = new LinkedHashMap<>(16, .75F, true);
private static NativeImage base;
private static NativeImage components;
private static int nextId;
// WordData from Mystcraft Legacy 0.13.7.06. Other words get a stable generated glyph.
private static final Map<String, int[]> WORDS = Map.ofEntries(
Map.entry("Terrain", new int[] {6,10,12,13,16,19,24,25,27}),
Map.entry("Form", new int[] {4,6,8,9,10,11,13,14,16,23}),
Map.entry("Tradition", new int[] {4,6,7,8,9,14,17,18,20}),
Map.entry("Flow", new int[] {4,7,12,13,17,18}),
Map.entry("Constraint", new int[] {5,6,9,11,13,20,22,23}),
Map.entry("Nature", new int[] {5,6,8,10,11,12,15,16,17,22}),
Map.entry("Sustain", new int[] {6,16,19,20,21,23}),
Map.entry("Ethereal", new int[] {4,6,8,13,14,16,18,21,23}),
Map.entry("Dynamic", new int[] {4,5,6,12,13,17,18,22,23}),
Map.entry("Cycle", new int[] {4,5,7,16,17,18}),
Map.entry("Balance", new int[] {4,6,9,10,16,19}),
Map.entry("Transform", new int[] {4,5,6,8,11,14,18,20,21}),
Map.entry("Time", new int[] {4,5,7,12,13,19,20,21,22,23}),
Map.entry("System", new int[] {10,12,14,15,16,20,21,22}),
Map.entry("Void", new int[] {4,5,6,16,17,18,23})
);
private SymbolPageTextures() {}
/** Transparent full-size artwork for GUI thumbnails drawn over their own page background. */
public static ResourceLocation forPage(ItemStack stack) {
return forPage(stack, false);
}
/** Full page texture with artwork reduced by three pixels at 16 px item-icon scale. */
public static ResourceLocation forItem(ItemStack stack) {
return forPage(stack, true);
}
private static ResourceLocation forPage(ItemStack stack, boolean item) {
PageContent content = PageItem.content(stack);
if (content.kind() == PageContent.Kind.UNRESOLVED_SYMBOL) return texture("item/page_unresolved");
if (content.kind() != PageContent.Kind.SYMBOL) return FALLBACK;
SymbolDisplayMetadata metadata = stack.get(ModDataComponents.PAGE_SYMBOL_DISPLAY.get());
ResourceLocation id = content.symbol().orElseThrow().id();
return forSymbol(id, metadata == null ? "" : metadata.poem(), item);
}
private static ResourceLocation forSymbol(ResourceLocation id, String poem, boolean item) {
if (poem.length() > 96 || !poem.matches("[A-Za-z]+(?: [A-Za-z]+){3}")) poem = "";
if (poem.isEmpty()) poem = SymbolPoems.builtIn(id);
String key = id + "|" + poem + (item ? "|item" : "|thumbnail");
ResourceLocation cached = CACHE.get(key);
if (cached != null) return cached;
try {
loadSources(Minecraft.getInstance().getResourceManager());
NativeImage image = compose(id, poem, item);
ResourceLocation location = ResourceLocation.fromNamespaceAndPath(
Rivencraft.MOD_ID, "generated/page_" + nextId++);
Minecraft.getInstance().getTextureManager().register(location, new DynamicTexture(image));
CACHE.put(key, location);
if (CACHE.size() > CACHE_LIMIT) {
String eldest = CACHE.keySet().iterator().next();
Minecraft.getInstance().getTextureManager().release(CACHE.remove(eldest));
}
return location;
} catch (IOException exception) {
Rivencraft.LOGGER.error("Could not compose symbol page {}", id, exception);
return FALLBACK;
}
}
public static void clear() {
var textures = Minecraft.getInstance().getTextureManager();
CACHE.values().forEach(textures::release);
CACHE.clear();
WORD_CACHE.clear();
if (base != null) base.close();
if (components != null) components.close();
base = null;
components = null;
}
private static void loadSources(ResourceManager manager) throws IOException {
if (base != null && components != null) return;
try (InputStream page = manager.getResourceOrThrow(BASE).open();
InputStream sheet = manager.getResourceOrThrow(COMPONENTS).open()) {
base = NativeImage.read(page);
components = NativeImage.read(sheet);
}
}
private static NativeImage compose(ResourceLocation id, String poem, boolean item) {
// GUI variants have no parchment layer, so their untouched pixels must be transparent.
NativeImage image = new NativeImage(SIZE, SIZE, true);
if (item) {
for (int y = 0; y < SIZE; y++) for (int x = 0; x < SIZE; x++) {
image.setPixelRGBA(x, y, base.getPixelRGBA(x * base.getWidth() / SIZE,
y * base.getHeight() / SIZE));
}
}
String[] words = poem.isBlank() ? generatedWords(id) : poem.split(" ");
int[] offsetsX = {38, 77, 38, 0};
int[] offsetsY = {0, 38, 77, 38};
int glyphSize = item ? GLYPH * ITEM_SYMBOL_SIZE / ICON_SIZE : GLYPH;
for (int word = 0; word < 4; word++) {
int originX = item ? scaleForItem(offsetsX[word]) : offsetsX[word];
int originY = item ? scaleForItem(offsetsY[word]) : offsetsY[word];
for (int component : glyphs(words[word])) {
for (int y = 0; y < glyphSize; y++) for (int x = 0; x < glyphSize; x++) {
int pixel = components.getPixelRGBA((component % 8) * 64 + x * 64 / glyphSize,
(component / 8) * 64 + y * 64 / glyphSize);
int alpha = pixel >>> 24;
if (alpha != 0) image.blendPixel(originX + x, originY + y,
(alpha << 24) | 0x001A212B);
}
}
}
return image;
}
private static int scaleForItem(int coordinate) {
return SIZE / 2 + Math.round((coordinate - SIZE / 2F) * ITEM_SYMBOL_SIZE / ICON_SIZE);
}
private static String[] generatedWords(ResourceLocation id) {
String stem = id.toString();
return new String[] {stem + 'a', stem + 'b', stem + 'c', stem + 'd'};
}
private static int[] glyphs(String word) {
int[] known = WORDS.get(word);
if (known != null) return known;
String key = word.toLowerCase(Locale.ROOT);
int[] cached = WORD_CACHE.get(key);
if (cached != null) return cached;
Random random = new Random(key.hashCode());
int[] components = new int[random.nextInt(10) + 3];
for (int index = 0; index < components.length; index++) components[index] = random.nextInt(20) + 4;
WORD_CACHE.put(key, components);
if (WORD_CACHE.size() > CACHE_LIMIT) WORD_CACHE.remove(WORD_CACHE.keySet().iterator().next());
return components;
}
/** Draw a word as a layered Legacy glyph, or a number with Legacy's number components. */
public static void drawWordGlyph(GuiGraphics graphics, String word, int x, int y, int size) {
if (word.matches("[0-9]+")) {
try {
drawNumeral(graphics, Integer.parseInt(word), x, y, size);
return;
} catch (NumberFormatException ignored) {
// Oversized numerals still receive a stable word glyph.
}
}
graphics.setColor(0.13F, 0.10F, 0.08F, 1F);
for (int component : glyphs(word)) drawComponent(graphics, component, x, y, size);
graphics.setColor(1F, 1F, 1F, 1F);
}
/** Legacy's single-number marks; numbers above 24 use positional base 25. */
public static void drawNumeral(GuiGraphics graphics, int number, int x, int y, int size) {
int[] digits = SymbolNumerals.digitsFor(number);
int digitSize = digits.length == 1 ? size : Math.max(8, size * 3 / 4);
graphics.setColor(0.13F, 0.10F, 0.08F, 1F);
for (int digit : digits) {
for (int component : SymbolNumerals.componentsForDigit(digit))
drawComponent(graphics, component, x, y + (size - digitSize) / 2, digitSize);
x += digitSize + 1;
}
graphics.setColor(1F, 1F, 1F, 1F);
}
/** Render translated prose as a sequence of word glyphs within a fixed-width book page. */
public static int drawGlyphText(GuiGraphics graphics, String text, int x, int y, int maxWidth) {
int cursor = x;
boolean drew = false;
for (String word : text.split("[^\\p{L}\\p{N}]+")) {
if (word.isEmpty()) continue;
int width = word.matches("[0-9]+") ? numeralWidth(word, 12) : 12;
if (cursor != x && cursor + width > x + maxWidth) {
cursor = x;
y += 13;
}
drawWordGlyph(graphics, word, cursor, y, 12);
cursor += width + 3;
drew = true;
}
return y + (drew ? 13 : 0);
}
private static int numeralWidth(String word, int size) {
try {
int count = SymbolNumerals.digitsFor(Integer.parseInt(word)).length;
return count == 1 ? size : count * (size * 3 / 4 + 1) - 1;
} catch (NumberFormatException ignored) {
return size;
}
}
private static void drawComponent(GuiGraphics graphics, int component, int x, int y, int size) {
graphics.blit(COMPONENTS, x, y, size, size,
(component % 8) * 64, (component / 8) * 64, 64, 64, 512, 512);
}
private static ResourceLocation texture(String path) {
return ResourceLocation.fromNamespaceAndPath(Rivencraft.MOD_ID, "textures/" + path + ".png");
}
}
@@ -1,5 +1,6 @@
package net.dnorberg.rivencraft.client.screen;
import java.util.Locale;
import net.dnorberg.rivencraft.Rivencraft;
import net.dnorberg.rivencraft.block.entity.BookBinderBlockEntity;
import net.dnorberg.rivencraft.item.PageItem;
@@ -32,6 +33,7 @@ public final class BookBinderScreen extends AbstractContainerScreen<BookBinderMe
private EditBox titleInput;
private int firstVisible;
private int lastGrammarErrorStripIndex = -1;
private boolean stripClickPendingRelease;
public BookBinderScreen(BookBinderMenu menu, Inventory inventory, Component title) {
@@ -86,6 +88,13 @@ public final class BookBinderScreen extends AbstractContainerScreen<BookBinderMe
@Override public void render(GuiGraphics graphics, int mouseX, int mouseY, float partialTick) {
super.render(graphics, mouseX, mouseY, partialTick);
firstVisible = Math.min(firstVisible, maxFirstVisible());
int errorStripIndex = menu.grammarErrorStripIndex();
if (errorStripIndex != lastGrammarErrorStripIndex) {
if (errorStripIndex >= 0
&& (errorStripIndex < firstVisible || errorStripIndex >= firstVisible + VISIBLE_PAGES))
firstVisible = Math.clamp(errorStripIndex - VISIBLE_PAGES + 1, 0, maxFirstVisible());
lastGrammarErrorStripIndex = errorStripIndex;
}
graphics.enableScissor(leftPos + STRIP_X + 8, topPos + STRIP_Y,
leftPos + STRIP_X + STRIP_WIDTH - 8, topPos + STRIP_Y + STRIP_HEIGHT);
int count = visiblePageCount();
@@ -97,6 +106,16 @@ public final class BookBinderScreen extends AbstractContainerScreen<BookBinderMe
}
graphics.disableScissor();
drawScrollEnds(graphics);
Component grammarTooltip = menu.grammarError().map(code -> Component.translatable(
"screen.rivencraft.book_binder.grammar." + code.name().toLowerCase(Locale.ROOT),
errorStripIndex + 1)).orElse(null);
if (menu.getSlot(BookBinderMenu.RESULT).getItem().isEmpty()
&& mouseX >= leftPos + 152 && mouseX < leftPos + 168
&& mouseY >= topPos + 27 && mouseY < topPos + 43
&& grammarTooltip != null) {
graphics.renderTooltip(font, grammarTooltip, mouseX, mouseY);
return;
}
if (mouseY >= topPos + STRIP_Y && mouseY < topPos + STRIP_Y + STRIP_HEIGHT) {
if (firstVisible > 0 && mouseX >= leftPos + STRIP_X && mouseX < leftPos + STRIP_X + 8)
graphics.renderTooltip(font, Component.translatable("screen.rivencraft.book_binder.previous_pages"), mouseX, mouseY);
@@ -111,7 +130,9 @@ public final class BookBinderScreen extends AbstractContainerScreen<BookBinderMe
return;
}
int hovered = pageIndexAt(mouseX, mouseY);
if (hovered >= 0 && hovered < displayedPages() && !pageAtIndex(hovered).isEmpty())
if (hovered >= 0 && hovered == errorStripIndex && grammarTooltip != null)
graphics.renderTooltip(font, grammarTooltip, mouseX, mouseY);
else if (hovered >= 0 && hovered < displayedPages() && !pageAtIndex(hovered).isEmpty())
graphics.renderTooltip(font, pageAtIndex(hovered), mouseX, mouseY);
else renderTooltip(graphics, mouseX, mouseY);
}
@@ -146,7 +167,11 @@ public final class BookBinderScreen extends AbstractContainerScreen<BookBinderMe
case BLANK -> { }
case LINK_PANEL -> graphics.fill(x + 5, y + 6, x + 22, y + 17, 0xFF000000);
case SYMBOL, UNRESOLVED_SYMBOL -> graphics.blit(NotebookScreen.symbolTexture(page),
x + 1, y + 5, 24, 24, 16, 16, 96, 96, 128, 128);
x + 1, y + 5, 24, 24, 0, 0, 128, 128, 128, 128);
}
if (index == menu.grammarErrorStripIndex() && menu.grammarError().isPresent()) {
graphics.fill(x, y, x + PAGE_WIDTH, y + PAGE_HEIGHT, 0x55FF2020);
graphics.renderOutline(x, y, PAGE_WIDTH, PAGE_HEIGHT, 0xFFFF3030);
}
}
@@ -5,6 +5,7 @@ import java.util.Locale;
import net.dnorberg.rivencraft.book.AgeReference;
import net.dnorberg.rivencraft.book.AgeTraits;
import net.dnorberg.rivencraft.client.ClientBookExploreOverlay;
import net.dnorberg.rivencraft.client.SymbolPageTextures;
import net.dnorberg.rivencraft.network.UseDescriptiveBookPayload;
import net.dnorberg.rivencraft.network.BindDescriptiveBookPayload;
import net.dnorberg.rivencraft.network.ModNetworking;
@@ -37,7 +38,6 @@ import org.jetbrains.annotations.Nullable;
public final class DescriptiveBookScreen extends Screen implements ExplorableBookScreen {
private static final int BOOK_TEXT_COLOR = 0xFF3B281B;
private static final int UNRESOLVED_TEXT_COLOR = 0xFF9B302C;
private static final ResourceLocation ENCHANTMENT_FONT = ResourceLocation.withDefaultNamespace("alt");
private static final int BOOK_WIDTH = 327;
private static final int BOOK_HEIGHT = 199;
private static final int LINK_PANEL_X = 173;
@@ -211,7 +211,7 @@ public final class DescriptiveBookScreen extends Screen implements ExplorableBoo
Component profileName = generationProfile.getNamespace().equals("rivencraft")
? Component.translatable("generator.rivencraft." + generationProfile.getPath())
: Component.literal(generationProfile.toString());
detailsY = drawWrappedWithoutShadow(graphics,
detailsY = drawDescription(graphics,
Component.translatable("screen.rivencraft.age.generator", profileName),
x, detailsY, 110) + 2;
}
@@ -415,10 +415,16 @@ public final class DescriptiveBookScreen extends Screen implements ExplorableBoo
}
private int drawTrait(GuiGraphics graphics, String key, Component value, int x, int y) {
return drawWrappedWithoutShadow(graphics,
return drawDescription(graphics,
Component.translatable("screen.rivencraft.age.trait." + key, value), x, y, 110) + 2;
}
private int drawDescription(GuiGraphics graphics, Component text, int x, int y, int maxWidth) {
return pageFree && age != null
? SymbolPageTextures.drawGlyphText(graphics, text.getString(), x, y, maxWidth)
: drawWrappedWithoutShadow(graphics, text, x, y, maxWidth);
}
private static Component traitName(String group, Enum<?> value) {
return Component.translatable("trait.rivencraft." + group + "."
+ value.name().toLowerCase(Locale.ROOT));
@@ -429,9 +435,7 @@ public final class DescriptiveBookScreen extends Screen implements ExplorableBoo
}
private int drawWrappedWithoutShadow(GuiGraphics graphics, Component text, int x, int y, int maxWidth, int color) {
Component displayed = pageFree && age != null && pageIndex == 0
? text.copy().withStyle(style -> style.withFont(ENCHANTMENT_FONT)) : text;
for (FormattedCharSequence line : font.split(displayed, maxWidth)) {
for (FormattedCharSequence line : font.split(text, maxWidth)) {
graphics.drawString(font, line, x, y, color, false);
y += font.lineHeight;
}
@@ -3,6 +3,7 @@ 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.client.SymbolPageTextures;
import net.dnorberg.rivencraft.menu.NotebookMenu;
import net.dnorberg.rivencraft.registry.ModItems;
import net.minecraft.client.gui.GuiGraphics;
@@ -26,14 +27,6 @@ public final class NotebookScreen extends AbstractContainerScreen<NotebookMenu>
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;
@@ -262,7 +255,7 @@ public final class NotebookScreen extends AbstractContainerScreen<NotebookMenu>
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);
28, 28, 0, 0, 128, 128, 128, 128);
}
}
if (dimmed) {
@@ -274,23 +267,7 @@ public final class NotebookScreen extends AbstractContainerScreen<NotebookMenu>
}
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;
};
return SymbolPageTextures.forPage(page);
}
private static ResourceLocation texture(String path) {
@@ -5,6 +5,7 @@ import java.util.Locale;
import java.util.ArrayList;
import java.util.Comparator;
import net.dnorberg.rivencraft.Rivencraft;
import net.dnorberg.rivencraft.client.SymbolPageTextures;
import net.dnorberg.rivencraft.item.PageItem;
import net.dnorberg.rivencraft.menu.WritingDeskMenu;
import net.dnorberg.rivencraft.block.entity.WritingDeskBlockEntity;
@@ -148,7 +149,8 @@ public final class WritingDeskScreen extends AbstractContainerScreen<WritingDesk
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);
// Encode the visible one-based tab number with Legacy's numeric word glyph.
SymbolPageTextures.drawNumeral(graphics, tab + 1, x + 8, tabY + 3, 19);
ItemStack collection = menu.getSlot(tab).getItem();
if (!collection.isEmpty()) {
String name = collection.getHoverName().getString();
@@ -220,6 +222,11 @@ public final class WritingDeskScreen extends AbstractContainerScreen<WritingDesk
graphics.renderTooltip(font, Component.translatable("screen.rivencraft.writing_desk.previous_tabs"), mouseX, mouseY);
else if (localY >= 177 && localY < 186)
graphics.renderTooltip(font, Component.translatable("screen.rivencraft.writing_desk.next_tabs"), mouseX, mouseY);
else if (mouseX < leftPos + 34 && localY >= 29 && localY < 177) {
int tab = menu.firstVisibleTab() + (localY - 29) / 37;
graphics.renderTooltip(font, Component.translatable("screen.rivencraft.writing_desk.tab_symbol",
tab + 1), mouseX, mouseY);
}
}
}
@@ -270,7 +277,7 @@ public final class WritingDeskScreen extends AbstractContainerScreen<WritingDesk
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);
28, 28, 0, 0, 128, 128, 128, 128);
}
}
@@ -14,6 +14,7 @@ import net.dnorberg.rivencraft.registry.ModItems;
import net.dnorberg.rivencraft.writing.NotebookContents;
import net.dnorberg.rivencraft.writing.OrderedWriting;
import net.dnorberg.rivencraft.writing.SymbolReference;
import net.dnorberg.rivencraft.writing.SymbolCatalog;
import net.dnorberg.rivencraft.writing.WritingEntry;
import net.minecraft.core.BlockPos;
import net.minecraft.gametest.framework.GameTest;
@@ -86,12 +87,41 @@ public final class BookBinderGameTests {
restored.loadWithComponents(saved, helper.getLevel().registryAccess());
helper.assertValueEqual(PageItem.content(restored.getItem(BookBinderBlockEntity.FIRST_PAGE))
.symbol().orElseThrow(), missing, "Reload must preserve the removed data-pack symbol ID");
helper.assertFalse(restored.canAssemble(), "Missing symbol cannot create a new written Age");
restored.getItem(BookBinderBlockEntity.FIRST_PAGE).set(ModDataComponents.PAGE_SYMBOL_DISPLAY.get(),
SymbolCatalog.display(new SymbolReference(ResourceLocation.parse("rivencraft:terrain/standard"))));
helper.assertFalse(restored.canAssemble(),
"Forged display metadata cannot make a missing symbol valid for a new Age");
helper.assertTrue(restored.getItem(BookBinderBlockEntity.FIRST_PAGE).is(ModItems.PAGE.get()),
"Rejected writing must remain recoverable as a Page");
helper.succeed();
}
@GameTest(template = "empty")
public static void conflictingGrammarKeepsBinderInputsRecoverable(GameTestHelper helper) {
BookBinderBlockEntity binder = place(helper);
binder.setTitle("Recoverable Duplicate");
binder.setItem(BookBinderBlockEntity.COVER, new ItemStack(Items.LEATHER));
binder.setItem(BookBinderBlockEntity.LINK_PANEL, PageItem.createLinkPanelPage());
binder.setItem(BookBinderBlockEntity.FIRST_PAGE, terrainPage());
binder.setItem(BookBinderBlockEntity.FIRST_PAGE + 5, terrainPage());
helper.assertFalse(binder.canAssemble(), "Duplicate terrain must not assemble a new Age");
int errorEntry = binder.writingGrammar().firstError().orElseThrow().index();
helper.assertValueEqual(errorEntry, 2, "Parser must identify the second authored symbol");
helper.assertValueEqual(binder.writingStripIndex(errorEntry), 6,
"A grammar error must highlight the correct strip page despite empty positions");
helper.assertFalse(binder.consumeAssembly(), "Rejected grammar must not consume binder inputs");
helper.assertTrue(binder.getItem(BookBinderBlockEntity.COVER).is(Items.LEATHER),
"Rejected grammar must leave the cover recoverable");
helper.assertTrue(binder.getItem(BookBinderBlockEntity.LINK_PANEL).is(ModItems.PAGE.get()),
"Rejected grammar must leave the Link Panel recoverable");
helper.assertTrue(binder.getItem(BookBinderBlockEntity.FIRST_PAGE + 5).is(ModItems.PAGE.get()),
"Rejected grammar must leave the duplicate page removable");
ItemStack removed = binder.takePage(5);
helper.assertTrue(removed.is(ModItems.PAGE.get()), "Player must be able to correct the duplicate page");
helper.assertTrue(binder.canAssemble(), "Corrected partial writing must become assemblable");
helper.succeed();
}
public static void assemblyIsAtomicAndRetainsPageOrder(GameTestHelper helper) {
BookBinderBlockEntity binder = place(helper);
binder.setTitle("A New Age");
@@ -47,6 +47,11 @@ public final class CoreGameTests {
WritingDataGameTests.semanticSchemaIsServerOnlyBoundedAndV1Compatible(helper);
}
@GameTest(template = "empty")
public static void orderedWritingGrammar(GameTestHelper helper) {
WritingGrammarGameTests.orderedGrammarAcceptsPartialWritingAndDiagnosesInvalidSequences(helper);
}
@GameTest(template = "empty")
public static void notebookPersistence(GameTestHelper helper) {
WritingDataGameTests.notebookContentsPreserveOrderGapsNamesAndUnknownPages(helper);
@@ -82,6 +87,11 @@ public final class CoreGameTests {
BookBinderGameTests.assemblyIsAtomicAndRetainsPageOrder(helper);
}
@GameTest(template = "empty")
public static void binderRejectsConflictingGrammar(GameTestHelper helper) {
BookBinderGameTests.conflictingGrammarKeepsBinderInputsRecoverable(helper);
}
@GameTest(template = "empty")
public static void binderRejectsForgedAndReplayedActions(GameTestHelper helper) {
BookBinderGameTests.forgedBinderActionsAndReplayedOutputCannotDuplicateBook(helper);
@@ -3,6 +3,7 @@ package net.dnorberg.rivencraft.gametest;
import com.google.gson.JsonParser;
import com.mojang.serialization.JsonOps;
import io.netty.buffer.Unpooled;
import java.util.Arrays;
import java.util.List;
import java.util.UUID;
import net.dnorberg.rivencraft.book.AgeReference;
@@ -11,6 +12,8 @@ import net.dnorberg.rivencraft.writing.PageContent;
import net.dnorberg.rivencraft.writing.SymbolCatalog;
import net.dnorberg.rivencraft.writing.SymbolDefinition;
import net.dnorberg.rivencraft.writing.SymbolSemantics;
import net.dnorberg.rivencraft.writing.SymbolPoems;
import net.dnorberg.rivencraft.writing.SymbolNumerals;
import net.dnorberg.rivencraft.writing.SymbolReference;
import net.dnorberg.rivencraft.writing.WritingEntry;
import net.dnorberg.rivencraft.writing.NotebookContents;
@@ -109,6 +112,20 @@ public final class WritingDataGameTests {
helper.assertValueEqual(builtIn.schemaVersion(), 2, "Built-in symbol must use semantic schema v2");
helper.assertValueEqual(builtIn.semantics().orElseThrow().role(), SymbolSemantics.Role.TERRAIN,
"Built-in terrain symbol must declare its grammar role");
helper.assertValueEqual(builtIn.poem(), "Terrain Form Tradition Flow",
"Built-in page artwork must carry its four-word Legacy poem");
helper.assertValueEqual(SymbolPoems.builtIn(reference("rivencraft:terrain/standard").id()), builtIn.poem(),
"Pre-artwork saved starter pages must retain their original poem");
helper.assertTrue(Arrays.equals(SymbolNumerals.componentsForDigit(0), new int[] {1}),
"Zero must use Legacy's dedicated number mark");
helper.assertTrue(Arrays.equals(SymbolNumerals.componentsForDigit(1), new int[] {56}),
"One must use Legacy's first bottom-row mark");
helper.assertTrue(Arrays.equals(SymbolNumerals.componentsForDigit(24), new int[] {63, 59}),
"Twenty-four must combine Legacy's five and unit marks");
helper.assertTrue(Arrays.equals(SymbolNumerals.digitsFor(25), new int[] {1, 0}),
"Twenty-five must start a second base-25 place");
helper.assertTrue(Arrays.equals(SymbolNumerals.digitsFor(88), new int[] {3, 13}),
"Last writing-desk tab must retain its numeric value");
String display = "\"name\":\"symbol.example.test\","
+ "\"description\":\"symbol.example.test.description\","
@@ -146,6 +163,10 @@ public final class WritingDataGameTests {
.encodeStart(JsonOps.INSTANCE, clientJson).result().orElseThrow();
helper.assertFalse(encoded.getAsJsonObject().has("semantics"),
"Client display payload must never contain generation semantics");
helper.assertValueEqual(encoded.getAsJsonObject().get("poem").getAsString(), builtIn.poem(),
"Client display payload must carry page artwork metadata");
rejectDefinition(helper, "{\"schema_version\":2," + display
+ ",\"semantics\":{\"role\":\"weather\",\"value\":\"normal\"},\"poem\":\"only two\"}", "poem");
helper.succeed();
}
@@ -0,0 +1,143 @@
package net.dnorberg.rivencraft.gametest;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import net.dnorberg.rivencraft.writing.OrderedWriting;
import net.dnorberg.rivencraft.writing.SymbolCatalog;
import net.dnorberg.rivencraft.writing.SymbolDefinition;
import net.dnorberg.rivencraft.writing.SymbolReference;
import net.dnorberg.rivencraft.writing.SymbolSemantics;
import net.dnorberg.rivencraft.writing.WritingEntry;
import net.dnorberg.rivencraft.writing.WritingGrammar;
import net.minecraft.gametest.framework.GameTest;
import net.minecraft.gametest.framework.GameTestHelper;
import net.minecraft.resources.ResourceLocation;
import net.neoforged.neoforge.gametest.GameTestHolder;
import net.neoforged.neoforge.gametest.PrefixGameTestTemplate;
/** Issue #30: parsing must not mutate writing or trust client display metadata. */
@GameTestHolder("rivencraft_archive_grammar")
@PrefixGameTestTemplate(false)
public final class WritingGrammarGameTests {
private WritingGrammarGameTests() {}
@GameTest(template = "empty")
public static void orderedGrammarAcceptsPartialWritingAndDiagnosesInvalidSequences(GameTestHelper helper) {
SymbolReference terrain = ref("rivencraft:terrain/standard");
SymbolReference nativeBiomes = ref("rivencraft:biome/native");
SymbolReference weather = ref("rivencraft:weather/normal");
SymbolReference lighting = ref("rivencraft:lighting/normal");
SymbolReference celestial = ref("rivencraft:celestial/normal_time");
SymbolReference caves = ref("rivencraft:feature/caves");
SymbolReference plains = ref("test:biome/plains");
SymbolReference forest = ref("test:biome/forest");
SymbolReference single = ref("test:controller/single");
SymbolReference alternateTerrain = ref("test:terrain/alternate");
SymbolReference periodHalf = ref("test:period/half");
SymbolReference periodFull = ref("test:period/full");
SymbolReference displayOnly = ref("test:display_only");
Map<SymbolReference, SymbolDefinition> definitions = Map.of(
plains, definition(SymbolSemantics.Role.BIOME,
new SymbolSemantics.ResourceValue(ResourceLocation.parse("minecraft:plains"))),
forest, definition(SymbolSemantics.Role.BIOME,
new SymbolSemantics.ResourceValue(ResourceLocation.parse("minecraft:forest"))),
single, definition(SymbolSemantics.Role.BIOME_CONTROLLER,
new SymbolSemantics.ChoiceValue("single")),
alternateTerrain, definition(SymbolSemantics.Role.TERRAIN,
new SymbolSemantics.ResourceValue(ResourceLocation.parse("test:alternate"))),
periodHalf, definition(SymbolSemantics.Role.PERIOD_MODIFIER,
new SymbolSemantics.NumberValue(0.5)),
periodFull, definition(SymbolSemantics.Role.PERIOD_MODIFIER,
new SymbolSemantics.NumberValue(1.0)),
displayOnly, new SymbolDefinition(1, "symbol.test", "symbol.test.description",
ResourceLocation.parse("test:display"), Optional.empty(), ""));
java.util.function.Function<SymbolReference, Optional<SymbolDefinition>> resolver = reference ->
Optional.ofNullable(definitions.get(reference)).or(() -> SymbolCatalog.find(reference));
helper.assertTrue(parse(resolver, WritingEntry.linkPanel()).randomFallback(),
"Link-Panel-only writing must retain the random Age path");
helper.assertTrue(WritingGrammar.parse(OrderedWriting.EMPTY, resolver).randomFallback(),
"Old page-free books must retain the random Age path");
OrderedWriting partial = writing(WritingEntry.linkPanel(), WritingEntry.symbol(terrain));
WritingGrammar.Result incomplete = WritingGrammar.parse(partial, resolver);
helper.assertTrue(incomplete.canCreate() && !incomplete.randomFallback(),
"Partial authored writing must remain valid, without pretending it is page-free");
helper.assertTrue(incomplete.diagnostics().stream().anyMatch(d -> d.code() == WritingGrammar.Code.INCOMPLETE),
"Missing branches must be reported for deterministic completion");
helper.assertValueEqual(partial.entries().size(), 2, "Parsing must not rewrite saved page order");
WritingGrammar.Result complete = parse(resolver, WritingEntry.linkPanel(), WritingEntry.symbol(terrain),
WritingEntry.symbol(plains), WritingEntry.symbol(single), WritingEntry.symbol(weather),
WritingEntry.symbol(lighting), WritingEntry.symbol(periodHalf), WritingEntry.symbol(celestial),
WritingEntry.symbol(caves));
helper.assertTrue(complete.canCreate(), "Legacy-ordered categories and prefix modifiers must parse");
helper.assertValueEqual(complete.symbols().size(), 8, "Parsed symbols must preserve every authored page");
helper.assertValueEqual(complete.symbols().get(1).reference(), plains,
"A biome page must precede the controller that consumes it");
helper.assertValueEqual(WritingGrammar.parse(writing(WritingEntry.linkPanel(), WritingEntry.symbol(terrain),
WritingEntry.symbol(plains), WritingEntry.symbol(single), WritingEntry.symbol(weather),
WritingEntry.symbol(lighting), WritingEntry.symbol(periodHalf), WritingEntry.symbol(celestial),
WritingEntry.symbol(caves)), resolver), complete,
"Identical ordered writing and server definitions must parse deterministically");
WritingGrammar.Result repeatedModifiers = parse(resolver, WritingEntry.linkPanel(),
WritingEntry.symbol(periodHalf), WritingEntry.symbol(periodFull), WritingEntry.symbol(celestial));
helper.assertTrue(repeatedModifiers.canCreate(), "Repeated period modifiers must remain legal");
assertCode(helper, parse(resolver, WritingEntry.linkPanel(), WritingEntry.symbol(terrain),
WritingEntry.symbol(terrain)), WritingGrammar.Code.DUPLICATE);
assertCode(helper, parse(resolver, WritingEntry.linkPanel(), WritingEntry.symbol(terrain),
WritingEntry.symbol(alternateTerrain)), WritingGrammar.Code.CONFLICT);
assertCode(helper, parse(resolver, WritingEntry.linkPanel(), WritingEntry.symbol(weather),
WritingEntry.symbol(terrain)), WritingGrammar.Code.OUT_OF_ORDER);
assertCode(helper, parse(resolver, WritingEntry.linkPanel(), WritingEntry.symbol(celestial),
WritingEntry.symbol(periodHalf)), WritingGrammar.Code.MISPLACED_MODIFIER);
assertCode(helper, parse(resolver, WritingEntry.linkPanel(), WritingEntry.symbol(nativeBiomes),
WritingEntry.symbol(plains)), WritingGrammar.Code.OUT_OF_ORDER);
assertCode(helper, parse(resolver, WritingEntry.linkPanel(), WritingEntry.symbol(plains),
WritingEntry.symbol(nativeBiomes)), WritingGrammar.Code.CONFLICT);
assertCode(helper, parse(resolver, WritingEntry.linkPanel(), WritingEntry.symbol(plains),
WritingEntry.symbol(forest), WritingEntry.symbol(single)), WritingGrammar.Code.CONFLICT);
assertCode(helper, parse(resolver, WritingEntry.linkPanel(), WritingEntry.symbol(caves),
WritingEntry.symbol(caves)), WritingGrammar.Code.DUPLICATE);
assertCode(helper, parse(resolver, WritingEntry.linkPanel(), WritingEntry.symbol(ref("test:missing"))),
WritingGrammar.Code.UNRESOLVED);
assertCode(helper, parse(resolver, WritingEntry.linkPanel(), WritingEntry.symbol(displayOnly)),
WritingGrammar.Code.UNSUPPORTED);
assertCode(helper, parse(resolver, WritingEntry.symbol(terrain)), WritingGrammar.Code.MISSING_PANEL);
assertCode(helper, parse(resolver, WritingEntry.linkPanel(), WritingEntry.linkPanel()),
WritingGrammar.Code.DUPLICATE_PANEL);
List<WritingEntry> oversized = new ArrayList<>();
for (int index = 0; index <= WritingGrammar.MAX_NEW_ENTRIES; index++)
oversized.add(WritingEntry.linkPanel());
assertCode(helper, WritingGrammar.parse(new OrderedWriting(oversized), resolver), WritingGrammar.Code.TOO_MANY);
helper.succeed();
}
private static SymbolReference ref(String id) {
return new SymbolReference(ResourceLocation.parse(id));
}
private static SymbolDefinition definition(SymbolSemantics.Role role, SymbolSemantics.Value value) {
return new SymbolDefinition(2, "symbol.test", "symbol.test.description",
ResourceLocation.parse("test:" + role.id()), Optional.of(new SymbolSemantics(role, value)), "");
}
private static OrderedWriting writing(WritingEntry... entries) {
return new OrderedWriting(List.of(entries));
}
private static WritingGrammar.Result parse(
java.util.function.Function<SymbolReference, Optional<SymbolDefinition>> resolver,
WritingEntry... entries) {
return WritingGrammar.parse(writing(entries), resolver);
}
private static void assertCode(GameTestHelper helper, WritingGrammar.Result result, WritingGrammar.Code code) {
helper.assertFalse(result.canCreate(), "Writing with " + code + " must not create a new Age");
helper.assertTrue(result.diagnostics().stream().anyMatch(diagnostic -> diagnostic.code() == code),
"Writing must report " + code + " rather than silently dropping a page");
}
}
@@ -8,10 +8,10 @@ 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.SymbolPoems;
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;
@@ -42,7 +42,7 @@ public final class PageItem extends Item {
page.set(ModDataComponents.PAGE_SYMBOL_DISPLAY.get(), new SymbolDisplayMetadata(
reference.id(), key, key + ".description",
net.minecraft.resources.ResourceLocation.fromNamespaceAndPath(Rivencraft.MOD_ID, path.split("/")[0]),
true));
true, SymbolPoems.builtIn(reference.id())));
return page;
}
@@ -118,7 +118,6 @@ public final class PageItem extends Item {
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()));
@@ -134,20 +133,4 @@ public final class PageItem extends Item {
: 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;
};
};
}
}
@@ -1,10 +1,12 @@
package net.dnorberg.rivencraft.menu;
import java.util.Optional;
import net.dnorberg.rivencraft.block.entity.BookBinderBlockEntity;
import net.dnorberg.rivencraft.item.PageItem;
import net.dnorberg.rivencraft.registry.ModItems;
import net.dnorberg.rivencraft.registry.ModMenus;
import net.dnorberg.rivencraft.writing.PageContent;
import net.dnorberg.rivencraft.writing.WritingGrammar;
import net.minecraft.network.RegistryFriendlyByteBuf;
import net.minecraft.world.Container;
import net.minecraft.world.SimpleContainer;
@@ -32,6 +34,8 @@ public final class BookBinderMenu extends AbstractContainerMenu {
private final SimpleContainer result = new SimpleContainer(1);
private final boolean clientSide;
private int selectedPage = -1;
private int grammarErrorCode = -1;
private int grammarErrorStripIndex = -1;
public BookBinderMenu(int id, Inventory inventory, RegistryFriendlyByteBuf data) {
this(id, inventory, inventory.player.level().getBlockEntity(data.readBlockPos())
@@ -47,6 +51,20 @@ public final class BookBinderMenu extends AbstractContainerMenu {
@Override public int get() { return selectedPage; }
@Override public void set(int value) { selectedPage = value; }
});
addDataSlot(new DataSlot() {
@Override public int get() {
return clientSide || binder == null ? grammarErrorCode : binder.writingGrammar().firstError()
.map(error -> error.code().ordinal()).orElse(-1);
}
@Override public void set(int value) { grammarErrorCode = value; }
});
addDataSlot(new DataSlot() {
@Override public int get() {
return clientSide || binder == null ? grammarErrorStripIndex : binder.writingGrammar().firstError()
.map(error -> binder.writingStripIndex(error.index())).orElse(-1);
}
@Override public void set(int value) { grammarErrorStripIndex = value; }
});
addSlot(new BinderSlot(BookBinderBlockEntity.COVER, 8, 27, 64));
addSlot(new BinderSlot(BookBinderBlockEntity.LINK_PANEL, -1000, -1000, 1));
addSlot(new BinderSlot(BookBinderBlockEntity.NOTEBOOK, -1000, -1000, 1));
@@ -66,6 +84,12 @@ public final class BookBinderMenu extends AbstractContainerMenu {
}
public int selectedPage() { return selectedPage; }
public Optional<WritingGrammar.Code> grammarError() {
WritingGrammar.Code[] codes = WritingGrammar.Code.values();
return grammarErrorCode >= 0 && grammarErrorCode < codes.length
? Optional.of(codes[grammarErrorCode]) : Optional.empty();
}
public int grammarErrorStripIndex() { return grammarErrorStripIndex; }
public String title() { return binder == null ? "" : binder.title(); }
public boolean setTitle(Player player, String title) {
if (clientSide || !stillValid(player) || title == null
@@ -20,6 +20,7 @@ import net.dnorberg.rivencraft.writing.OrderedWriting;
import net.dnorberg.rivencraft.writing.SymbolCatalog;
import net.dnorberg.rivencraft.writing.SymbolDisplayMetadata;
import net.dnorberg.rivencraft.writing.WritingEntry;
import net.dnorberg.rivencraft.writing.WritingGrammar;
import net.minecraft.core.component.DataComponents;
import net.minecraft.core.BlockPos;
import net.minecraft.core.GlobalPos;
@@ -133,6 +134,14 @@ public final class ModNetworking {
return;
}
var grammar = WritingGrammar.parse(access.stack()
.getOrDefault(ModDataComponents.BOOK_WRITING.get(), OrderedWriting.EMPTY));
if (!grammar.canCreate()) {
player.displayClientMessage(Component.translatable("message.rivencraft.descriptive_book.invalid_writing",
grammar.firstError().orElseThrow().message()), true);
return;
}
WRITING_BOOKS.add(access.stack());
try {
AgeReference reference = new AgeReference(UUID.randomUUID(), title);
@@ -15,18 +15,20 @@ public record SymbolDefinition(
String nameTranslationKey,
String descriptionTranslationKey,
ResourceLocation category,
Optional<SymbolSemantics> semantics
Optional<SymbolSemantics> semantics,
String poem
) {
public static final int CURRENT_SCHEMA_VERSION = 2;
private static final Pattern TRANSLATION_KEY = Pattern.compile("[a-z0-9_.-]+");
private static final Set<String> V2_FIELDS = Set.of(
"schema_version", "name", "description", "category", "semantics");
"schema_version", "name", "description", "category", "semantics", "poem");
public SymbolDefinition {
Objects.requireNonNull(nameTranslationKey, "nameTranslationKey");
Objects.requireNonNull(descriptionTranslationKey, "descriptionTranslationKey");
Objects.requireNonNull(category, "category");
semantics = Objects.requireNonNull(semantics, "semantics");
poem = Objects.requireNonNull(poem, "poem");
if (schemaVersion != 1 && schemaVersion != CURRENT_SCHEMA_VERSION) {
throw new IllegalArgumentException("Unsupported schema_version " + schemaVersion);
}
@@ -38,6 +40,10 @@ public record SymbolDefinition(
}
validateTranslationKey(nameTranslationKey, "name");
validateTranslationKey(descriptionTranslationKey, "description");
if (!poem.isEmpty() && (poem.length() > 96
|| !poem.matches("[A-Za-z]+(?: [A-Za-z]+){3}"))) {
throw new IllegalArgumentException("'poem' must contain exactly four alphabetic words");
}
}
/** v1 remains display-only; v2 has an exact field set and typed semantics. */
@@ -66,11 +72,12 @@ public record SymbolDefinition(
Optional<SymbolSemantics> semantics = version == CURRENT_SCHEMA_VERSION
? Optional.of(SymbolSemantics.parse(object.get("semantics")))
: Optional.empty();
return new SymbolDefinition(version, name, description, category, semantics);
String poem = object.has("poem") ? requiredString(object, "poem") : "";
return new SymbolDefinition(version, name, description, category, semantics, poem);
}
public SymbolDisplayMetadata display(ResourceLocation id) {
return new SymbolDisplayMetadata(id, nameTranslationKey, descriptionTranslationKey, category, true);
return new SymbolDisplayMetadata(id, nameTranslationKey, descriptionTranslationKey, category, true, poem);
}
static String requiredString(JsonObject object, String field) {
@@ -14,14 +14,16 @@ public record SymbolDisplayMetadata(
String nameTranslationKey,
String descriptionTranslationKey,
ResourceLocation category,
boolean resolved
boolean resolved,
String poem
) {
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)
Codec.BOOL.fieldOf("resolved").forGetter(SymbolDisplayMetadata::resolved),
Codec.STRING.optionalFieldOf("poem", "").forGetter(SymbolDisplayMetadata::poem)
).apply(instance, SymbolDisplayMetadata::new));
public static final StreamCodec<ByteBuf, SymbolDisplayMetadata> STREAM_CODEC = StreamCodec.composite(
ResourceLocation.STREAM_CODEC, SymbolDisplayMetadata::id,
@@ -29,6 +31,7 @@ public record SymbolDisplayMetadata(
ByteBufCodecs.STRING_UTF8, SymbolDisplayMetadata::descriptionTranslationKey,
ResourceLocation.STREAM_CODEC, SymbolDisplayMetadata::category,
ByteBufCodecs.BOOL, SymbolDisplayMetadata::resolved,
ByteBufCodecs.STRING_UTF8, SymbolDisplayMetadata::poem,
SymbolDisplayMetadata::new
);
@@ -38,7 +41,8 @@ public record SymbolDisplayMetadata(
"symbol.rivencraft.unresolved",
"symbol.rivencraft.unresolved.description",
ResourceLocation.fromNamespaceAndPath(Rivencraft.MOD_ID, "unresolved"),
false
false,
""
);
}
}
@@ -0,0 +1,30 @@
package net.dnorberg.rivencraft.writing;
/**
* Number components from Mystcraft Legacy's ModWords#constructNumber.
* Legacy registers 0–25; larger Rivencraft tab numbers use positional base 25.
*/
public final class SymbolNumerals {
private SymbolNumerals() {}
public static int[] digitsFor(int number) {
if (number < 0) throw new IllegalArgumentException("Numeral must be non-negative");
if (number < 25) return new int[] {number};
int count = 0;
for (int remaining = number; remaining > 0; remaining /= 25) count++;
int[] digits = new int[count];
for (int remaining = number, index = count - 1; index >= 0; index--, remaining /= 25)
digits[index] = remaining % 25;
return digits;
}
public static int[] componentsForDigit(int digit) {
if (digit < 0 || digit >= 25) throw new IllegalArgumentException("Numeral digit must be in [0, 24]");
if (digit == 0) return new int[] {1};
int fifths = digit / 5;
int remainder = digit % 5;
if (fifths == 0) return new int[] {55 + remainder};
if (remainder == 0) return new int[] {59 + fifths};
return new int[] {59 + fifths, 55 + remainder};
}
}
@@ -0,0 +1,21 @@
package net.dnorberg.rivencraft.writing;
import net.minecraft.resources.ResourceLocation;
/** Legacy poems for existing starter pages, including stacks saved before poem metadata existed. */
public final class SymbolPoems {
private SymbolPoems() {}
public static String builtIn(ResourceLocation id) {
if (!id.getNamespace().equals("rivencraft")) return "";
return switch (id.getPath()) {
case "terrain/standard" -> "Terrain Form Tradition Flow";
case "biome/native" -> "Constraint Nature Tradition Sustain";
case "lighting/normal" -> "Ethereal Dynamic Cycle Balance";
case "weather/normal" -> "Sustain Dynamic Tradition Balance";
case "celestial/normal_time" -> "Transform Time System Balance";
case "feature/caves" -> "Terrain Transform Void Flow";
default -> "";
};
}
}
@@ -0,0 +1,183 @@
package net.dnorberg.rivencraft.writing;
import java.util.ArrayList;
import java.util.EnumMap;
import java.util.HashSet;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import java.util.function.Function;
import net.dnorberg.rivencraft.writing.SymbolSemantics.ChoiceValue;
import net.dnorberg.rivencraft.writing.SymbolSemantics.Role;
import net.minecraft.resources.ResourceLocation;
/** Server-owned interpretation of ordered writing; compilation belongs to the next release slice. */
public final class WritingGrammar {
// A newly assembled book has one Link Panel plus at most 27 page positions.
public static final int MAX_NEW_ENTRIES = NotebookContents.MAX_PAGES + 1;
private WritingGrammar() {}
public static Result parse(OrderedWriting writing) {
return parse(writing, SymbolCatalog::find);
}
/** The resolver must be the authoritative server catalog, never page display metadata. */
public static Result parse(OrderedWriting writing,
Function<SymbolReference, Optional<SymbolDefinition>> resolver) {
Objects.requireNonNull(writing, "writing");
Objects.requireNonNull(resolver, "resolver");
List<ParsedSymbol> symbols = new ArrayList<>();
List<Diagnostic> diagnostics = new ArrayList<>();
if (writing.entries().size() > MAX_NEW_ENTRIES) {
diagnostics.add(new Diagnostic(Code.TOO_MANY, -1, "At most " + MAX_NEW_ENTRIES + " entries are allowed"));
return new Result(symbols, diagnostics);
}
if (writing.entries().isEmpty()) return new Result(symbols, diagnostics);
EnumMap<Role, ParsedSymbol> singular = new EnumMap<>(Role.class);
Set<ResourceLocation> features = new HashSet<>();
int panels = 0;
int lastStage = -1;
int biomeCount = 0;
for (int index = 0; index < writing.entries().size(); index++) {
WritingEntry entry = writing.entries().get(index);
if (entry.kind() == WritingEntry.Kind.LINK_PANEL) {
panels++;
if (panels > 1) diagnostics.add(new Diagnostic(Code.DUPLICATE_PANEL, index,
"Use exactly one Link Panel"));
else if (index != 0) diagnostics.add(new Diagnostic(Code.PANEL_ORDER, index,
"Move the Link Panel to the first position"));
continue;
}
SymbolReference reference = entry.symbol().orElseThrow();
Optional<SymbolDefinition> definition = resolver.apply(reference);
if (definition.isEmpty()) {
diagnostics.add(new Diagnostic(Code.UNRESOLVED, index,
"Restore the data pack for " + reference.id() + " or remove this page"));
continue;
}
Optional<SymbolSemantics> semantics = definition.orElseThrow().semantics();
if (semantics.isEmpty()) {
diagnostics.add(new Diagnostic(Code.UNSUPPORTED, index,
"Update " + reference.id() + " to semantic schema v2 or remove this page"));
continue;
}
Role role = semantics.orElseThrow().role();
ParsedSymbol parsed = new ParsedSymbol(index, reference, semantics.orElseThrow());
symbols.add(parsed);
if (singular(role)) {
ParsedSymbol previous = singular.putIfAbsent(role, parsed);
if (previous != null) {
Code code = previous.semantics().value().equals(parsed.semantics().value())
? Code.DUPLICATE : Code.CONFLICT;
diagnostics.add(new Diagnostic(code, index,
"Remove this " + role.id() + " page; position " + (previous.index() + 1)
+ " already supplies that category"));
continue;
}
} else if (role == Role.FEATURE && !features.add(reference.id())) {
diagnostics.add(new Diagnostic(Code.DUPLICATE, index,
"Remove the repeated feature page " + reference.id()));
continue;
}
if (role == Role.BIOME) biomeCount++;
int stage = stage(role);
if (stage < lastStage) {
diagnostics.add(new Diagnostic(modifier(role) ? Code.MISPLACED_MODIFIER : Code.OUT_OF_ORDER,
index, "Move this " + role.id() + " page before later grammar categories"));
} else {
lastStage = stage;
}
}
if (panels == 0) diagnostics.add(new Diagnostic(Code.MISSING_PANEL, -1,
"Add a Link Panel as the first page"));
if (symbols.isEmpty()) return new Result(symbols, diagnostics);
ParsedSymbol controller = singular.get(Role.BIOME_CONTROLLER);
if (controller != null && controller.semantics().value() instanceof ChoiceValue choice
&& choice.id().equals("native") && biomeCount > 0) {
diagnostics.add(new Diagnostic(Code.CONFLICT, controller.index(),
"Native biome distribution cannot use authored biome pages"));
} else if (controller != null && controller.semantics().value() instanceof ChoiceValue choice
&& choice.id().equals("single") && biomeCount > 1) {
diagnostics.add(new Diagnostic(Code.CONFLICT, controller.index(),
"Single-biome distribution accepts only one authored biome page"));
}
for (Role required : List.of(Role.TERRAIN, Role.BIOME_CONTROLLER, Role.WEATHER,
Role.LIGHTING, Role.CELESTIAL)) {
if (!singular.containsKey(required)) diagnostics.add(new Diagnostic(Code.INCOMPLETE, -1,
"The Age compiler will fill the missing " + required.id() + " branch from the Age seed"));
}
if (controller != null && controller.semantics().value() instanceof ChoiceValue choice) {
int minimum = switch (choice.id()) {
case "single" -> 1;
case "tiled", "grid" -> 2;
case "native" -> 0;
default -> 3;
};
if (biomeCount < minimum) diagnostics.add(new Diagnostic(Code.INCOMPLETE, -1,
"The Age compiler will fill " + (minimum - biomeCount) + " missing biome page(s)"));
}
return new Result(symbols, diagnostics);
}
private static boolean singular(Role role) {
return switch (role) {
case TERRAIN, BIOME_CONTROLLER, WEATHER, LIGHTING, CELESTIAL -> true;
default -> false;
};
}
private static boolean modifier(Role role) {
return role == Role.PERIOD_MODIFIER || role == Role.ANGLE_MODIFIER || role == Role.PHASE_MODIFIER;
}
private static int stage(Role role) {
return switch (role) {
case TERRAIN -> 0;
case BIOME -> 1;
case BIOME_CONTROLLER -> 2;
case WEATHER -> 3;
case LIGHTING -> 4;
case PERIOD_MODIFIER, ANGLE_MODIFIER, PHASE_MODIFIER -> 5;
case CELESTIAL -> 6;
case FEATURE -> 7;
};
}
public enum Code {
TOO_MANY, MISSING_PANEL, PANEL_ORDER, DUPLICATE_PANEL, UNRESOLVED, UNSUPPORTED,
DUPLICATE, CONFLICT, OUT_OF_ORDER, MISPLACED_MODIFIER, INCOMPLETE
}
public record Diagnostic(Code code, int index, String message) {
public Diagnostic {
Objects.requireNonNull(code, "code");
Objects.requireNonNull(message, "message");
}
public boolean error() { return code != Code.INCOMPLETE; }
}
public record ParsedSymbol(int index, SymbolReference reference, SymbolSemantics semantics) {
public ParsedSymbol {
Objects.requireNonNull(reference, "reference");
Objects.requireNonNull(semantics, "semantics");
}
}
public record Result(List<ParsedSymbol> symbols, List<Diagnostic> diagnostics) {
public Result {
symbols = List.copyOf(symbols);
diagnostics = List.copyOf(diagnostics);
}
public boolean randomFallback() { return symbols.isEmpty() && diagnostics.isEmpty(); }
public boolean canCreate() { return diagnostics.stream().noneMatch(Diagnostic::error); }
public Optional<Diagnostic> firstError() { return diagnostics.stream().filter(Diagnostic::error).findFirst(); }
}
}
@@ -34,6 +34,16 @@
"screen.rivencraft.book_binder.previous_pages": "Scroll pages left (Left Arrow)",
"screen.rivencraft.book_binder.next_pages": "Scroll pages right (Right Arrow)",
"screen.rivencraft.book_binder.select_hint": "Right-click page to select",
"screen.rivencraft.book_binder.grammar.too_many": "Too many pages for a new Age; remove excess pages",
"screen.rivencraft.book_binder.grammar.missing_panel": "Add a Link Panel as the first page",
"screen.rivencraft.book_binder.grammar.panel_order": "Page %s: move the Link Panel to the first position",
"screen.rivencraft.book_binder.grammar.duplicate_panel": "Page %s: remove the extra Link Panel",
"screen.rivencraft.book_binder.grammar.unresolved": "Page %s: missing symbol definition; restore its data pack or remove it",
"screen.rivencraft.book_binder.grammar.unsupported": "Page %s: this symbol needs semantic schema v2; update its data pack or remove it",
"screen.rivencraft.book_binder.grammar.duplicate": "Page %s: remove the duplicate symbol",
"screen.rivencraft.book_binder.grammar.conflict": "Page %s: replace the conflicting symbol",
"screen.rivencraft.book_binder.grammar.out_of_order": "Page %s: move this symbol before later categories",
"screen.rivencraft.book_binder.grammar.misplaced_modifier": "Page %s: move this modifier before its celestial page",
"screen.rivencraft.writing_desk.ink": "Ink: %s/%s",
"screen.rivencraft.writing_desk.search": "Search",
"screen.rivencraft.writing_desk.sort": "Sort pages by name (A–Z)",
@@ -42,6 +52,7 @@
"screen.rivencraft.writing_desk.all_categories": "All categories",
"screen.rivencraft.writing_desk.previous_tabs": "Previous four tabs (Page Up)",
"screen.rivencraft.writing_desk.next_tabs": "Next four tabs (Page Down)",
"screen.rivencraft.writing_desk.tab_symbol": "Tab %s",
"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.",
@@ -57,6 +68,7 @@
"message.rivencraft.descriptive_book.unwritten": "This Descriptive Book is unwritten",
"message.rivencraft.descriptive_book.created": "Created Age: %s",
"message.rivencraft.descriptive_book.unavailable": "That Age is unavailable",
"message.rivencraft.descriptive_book.invalid_writing": "Writing cannot create an Age: %s",
"message.rivencraft.descriptive_book.unsafe": "No safe destination was found in that Age",
"message.rivencraft.descriptive_book.linked_first": "Linked to %s — a Return Link was created",
"message.rivencraft.descriptive_book.linked": "Linked to %s",
@@ -1,17 +1,13 @@
{
"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" }
]
"parent": "builtin/entity",
"gui_light": "front",
"display": {
"ground": { "translation": [0, 2, 0], "scale": [0.5, 0.5, 0.5] },
"head": { "rotation": [0, 180, 0], "translation": [0, 13, 7] },
"thirdperson_righthand": { "translation": [0, 3, 1], "scale": [0.55, 0.55, 0.55] },
"thirdperson_lefthand": { "translation": [0, 3, 1], "scale": [0.55, 0.55, 0.55] },
"firstperson_righthand": { "rotation": [0, -90, 25], "translation": [1.13, 3.2, 1.13], "scale": [0.68, 0.68, 0.68] },
"firstperson_lefthand": { "rotation": [0, 90, -25], "translation": [1.13, 3.2, 1.13], "scale": [0.68, 0.68, 0.68] },
"fixed": { "rotation": [0, 180, 0] }
}
}
@@ -1,4 +0,0 @@
{
"parent": "minecraft:item/generated",
"textures": { "layer0": "rivencraft:item/page_symbol_biome_native" }
}
@@ -1,4 +0,0 @@
{
"parent": "minecraft:item/generated",
"textures": { "layer0": "rivencraft:item/page_symbol_celestial_normal_time" }
}
@@ -1,4 +0,0 @@
{
"parent": "minecraft:item/generated",
"textures": { "layer0": "rivencraft:item/page_symbol_feature_caves" }
}
@@ -1,4 +0,0 @@
{
"parent": "minecraft:item/generated",
"textures": { "layer0": "rivencraft:item/page_symbol_lighting_normal" }
}
@@ -1,4 +0,0 @@
{
"parent": "minecraft:item/generated",
"textures": { "layer0": "rivencraft:item/page_symbol_terrain_standard" }
}
@@ -1,4 +0,0 @@
{
"parent": "minecraft:item/generated",
"textures": { "layer0": "rivencraft:item/page_symbol_weather_normal" }
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 12 KiB

@@ -3,5 +3,6 @@
"name": "symbol.rivencraft.biome.native",
"description": "symbol.rivencraft.biome.native.description",
"category": "rivencraft:biome",
"semantics": { "role": "biome_controller", "value": "native" }
"semantics": { "role": "biome_controller", "value": "native" },
"poem": "Constraint Nature Tradition Sustain"
}
@@ -3,5 +3,6 @@
"name": "symbol.rivencraft.celestial.normal_time",
"description": "symbol.rivencraft.celestial.normal_time.description",
"category": "rivencraft:celestial",
"semantics": { "role": "celestial", "value": "normal_time" }
"semantics": { "role": "celestial", "value": "normal_time" },
"poem": "Transform Time System Balance"
}
@@ -3,5 +3,6 @@
"name": "symbol.rivencraft.feature.caves",
"description": "symbol.rivencraft.feature.caves.description",
"category": "rivencraft:feature",
"semantics": { "role": "feature", "value": "rivencraft:caves" }
"semantics": { "role": "feature", "value": "rivencraft:caves" },
"poem": "Terrain Transform Void Flow"
}
@@ -3,5 +3,6 @@
"name": "symbol.rivencraft.lighting.normal",
"description": "symbol.rivencraft.lighting.normal.description",
"category": "rivencraft:lighting",
"semantics": { "role": "lighting", "value": "normal" }
"semantics": { "role": "lighting", "value": "normal" },
"poem": "Ethereal Dynamic Cycle Balance"
}
@@ -3,5 +3,6 @@
"name": "symbol.rivencraft.terrain.standard",
"description": "symbol.rivencraft.terrain.standard.description",
"category": "rivencraft:terrain",
"semantics": { "role": "terrain", "value": "rivencraft:standard" }
"semantics": { "role": "terrain", "value": "rivencraft:standard" },
"poem": "Terrain Form Tradition Flow"
}
@@ -3,5 +3,6 @@
"name": "symbol.rivencraft.weather.normal",
"description": "symbol.rivencraft.weather.normal.description",
"category": "rivencraft:weather",
"semantics": { "role": "weather", "value": "normal" }
"semantics": { "role": "weather", "value": "normal" },
"poem": "Sustain Dynamic Tradition Balance"
}