diff --git a/src/main/java/com/minelittlepony/unicopia/client/gui/spellbook/ClientChapters.java b/src/main/java/com/minelittlepony/unicopia/client/gui/spellbook/ClientChapters.java index 59e818e3..331e6962 100644 --- a/src/main/java/com/minelittlepony/unicopia/client/gui/spellbook/ClientChapters.java +++ b/src/main/java/com/minelittlepony/unicopia/client/gui/spellbook/ClientChapters.java @@ -1,6 +1,7 @@ package com.minelittlepony.unicopia.client.gui.spellbook; import java.util.*; + import com.minelittlepony.unicopia.client.gui.spellbook.SpellbookChapterList.*; import com.minelittlepony.unicopia.client.gui.spellbook.element.DynamicContent; import com.minelittlepony.unicopia.container.spellbook.SpellbookChapter; diff --git a/src/main/java/com/minelittlepony/unicopia/client/gui/spellbook/element/DynamicContent.java b/src/main/java/com/minelittlepony/unicopia/client/gui/spellbook/element/DynamicContent.java index a8e4c684..d6895e75 100644 --- a/src/main/java/com/minelittlepony/unicopia/client/gui/spellbook/element/DynamicContent.java +++ b/src/main/java/com/minelittlepony/unicopia/client/gui/spellbook/element/DynamicContent.java @@ -91,7 +91,7 @@ public class DynamicContent implements Content { rightPanel.init(screen, pageIndex + 1); } - class Page implements Drawable { + public class Page implements Drawable { private final Text title; private final int level; private final int color; @@ -197,5 +197,10 @@ public class DynamicContent implements Content { matrices.pop(); } + + @Override + public String toString() { + return "DynamicContents$Page[title=" + title + ",elements=" + elements + "]"; + } } } \ No newline at end of file diff --git a/src/main/java/com/minelittlepony/unicopia/client/gui/spellbook/element/PageElement.java b/src/main/java/com/minelittlepony/unicopia/client/gui/spellbook/element/PageElement.java index 48383c4b..8f3a1af8 100644 --- a/src/main/java/com/minelittlepony/unicopia/client/gui/spellbook/element/PageElement.java +++ b/src/main/java/com/minelittlepony/unicopia/client/gui/spellbook/element/PageElement.java @@ -56,7 +56,7 @@ public interface PageElement extends Drawable { byte t = b.readByte(); return switch (t) { case 1 -> formatLine(capture(b.readIdentifier(), id -> Registries.ITEM.get(id).getDefaultStack().getName()), "item", count); - case 2 -> formatLine(Trait.PACKET_CODEC.decode(b)::getShortName, "trait", count); + case 2 -> formatLine(Trait.fromId(b.readIdentifier()).get()::getShortName, "trait", count); case 3 -> Suppliers.ofInstance(TextCodecs.PACKET_CODEC.decode(b)); case 4 -> formatLine(SpellType.getKey(b.readIdentifier())::getName, "spell", count); default -> throw new IllegalArgumentException("Unexpected value: " + t); diff --git a/src/main/java/com/minelittlepony/unicopia/container/spellbook/Chapter.java b/src/main/java/com/minelittlepony/unicopia/container/spellbook/Chapter.java index e0e9030e..0a689076 100644 --- a/src/main/java/com/minelittlepony/unicopia/container/spellbook/Chapter.java +++ b/src/main/java/com/minelittlepony/unicopia/container/spellbook/Chapter.java @@ -20,7 +20,7 @@ public record Chapter ( TabSide.CODEC.fieldOf("side").forGetter(Chapter::side), Codec.INT.fieldOf("y_position").forGetter(Chapter::tabY), Codec.INT.optionalFieldOf("color", 0).forGetter(Chapter::color), - Contents.CODEC.fieldOf("contents").forGetter(Chapter::contents) + Contents.CODEC.fieldOf("content").forGetter(Chapter::contents) ).apply(instance, Chapter::new)); record Contents(List pages) { @@ -35,10 +35,10 @@ public record Chapter ( List elements ) { public static final Codec CODEC = RecordCodecBuilder.create(instance -> instance.group( - TextCodecs.CODEC.fieldOf("title").forGetter(Page::title), - Codec.INT.fieldOf("level").forGetter(Page::level), - TextColor.CODEC.fieldOf("color").xmap(TextColor::getRgb, TextColor::fromRgb).forGetter(Page::level), - ChapterPageElement.CODEC.listOf().fieldOf("elements").forGetter(Page::elements) + TextCodecs.CODEC.optionalFieldOf("title", Text.empty()).forGetter(Page::title), + Codec.INT.optionalFieldOf("level", 0).forGetter(Page::level), + TextColor.CODEC.xmap(TextColor::getRgb, TextColor::fromRgb).optionalFieldOf("color", 0).forGetter(Page::color), + ChapterPageElement.CODEC.listOf().optionalFieldOf("elements", List.of()).forGetter(Page::elements) ).apply(instance, Page::new)); public void toBuffer(RegistryByteBuf buffer) { diff --git a/src/main/java/com/minelittlepony/unicopia/container/spellbook/SpellbookChapterLoader.java b/src/main/java/com/minelittlepony/unicopia/container/spellbook/SpellbookChapterLoader.java index c763433e..1ad05c11 100644 --- a/src/main/java/com/minelittlepony/unicopia/container/spellbook/SpellbookChapterLoader.java +++ b/src/main/java/com/minelittlepony/unicopia/container/spellbook/SpellbookChapterLoader.java @@ -61,6 +61,7 @@ public class SpellbookChapterLoader extends JsonDataLoader implements Identifiab try { chapters = data.entrySet().stream().map(entry -> { return Chapter.CODEC.decode(JsonOps.INSTANCE, entry.getValue()) + .ifError(error -> LOGGER.error("Could not load spellbook chapters due to exception {}", error)) .result() .map(Pair::getFirst) .map(chapter -> new IdentifiableChapter(entry.getKey(), chapter)) diff --git a/src/main/resources/data/unicopia/spellbook/chapters/air_magic.json b/src/main/resources/data/unicopia/spellbook/chapters/air_magic.json index d552314e..752fdf7d 100644 --- a/src/main/resources/data/unicopia/spellbook/chapters/air_magic.json +++ b/src/main/resources/data/unicopia/spellbook/chapters/air_magic.json @@ -1,5 +1,5 @@ { - "side": "RIGHT", + "side": "right", "y_position": 4, "color": 0, "content": { diff --git a/src/main/resources/data/unicopia/spellbook/chapters/crystal_heart.json b/src/main/resources/data/unicopia/spellbook/chapters/crystal_heart.json index 87bfca53..c5840923 100644 --- a/src/main/resources/data/unicopia/spellbook/chapters/crystal_heart.json +++ b/src/main/resources/data/unicopia/spellbook/chapters/crystal_heart.json @@ -1,5 +1,5 @@ { - "side": "RIGHT", + "side": "right", "y_position": 7, "color": 0, "content": { diff --git a/src/main/resources/data/unicopia/spellbook/chapters/dark_magic.json b/src/main/resources/data/unicopia/spellbook/chapters/dark_magic.json index fb4e0968..23b20685 100644 --- a/src/main/resources/data/unicopia/spellbook/chapters/dark_magic.json +++ b/src/main/resources/data/unicopia/spellbook/chapters/dark_magic.json @@ -1,5 +1,5 @@ { - "side": "RIGHT", + "side": "right", "y_position": 5, "color": 0, "content": { diff --git a/src/main/resources/data/unicopia/spellbook/chapters/fire_magic.json b/src/main/resources/data/unicopia/spellbook/chapters/fire_magic.json index 491cb6de..2229fee3 100644 --- a/src/main/resources/data/unicopia/spellbook/chapters/fire_magic.json +++ b/src/main/resources/data/unicopia/spellbook/chapters/fire_magic.json @@ -1,5 +1,5 @@ { - "side": "RIGHT", + "side": "right", "y_position": 2, "color": 0, "content": { diff --git a/src/main/resources/data/unicopia/spellbook/chapters/ice_magic.json b/src/main/resources/data/unicopia/spellbook/chapters/ice_magic.json index 717c76db..89bd0771 100644 --- a/src/main/resources/data/unicopia/spellbook/chapters/ice_magic.json +++ b/src/main/resources/data/unicopia/spellbook/chapters/ice_magic.json @@ -1,5 +1,5 @@ { - "side": "RIGHT", + "side": "right", "y_position": 3, "color": 0, "content": { diff --git a/src/main/resources/data/unicopia/spellbook/chapters/introduction.json b/src/main/resources/data/unicopia/spellbook/chapters/introduction.json index b2cca4f9..31c08b9d 100644 --- a/src/main/resources/data/unicopia/spellbook/chapters/introduction.json +++ b/src/main/resources/data/unicopia/spellbook/chapters/introduction.json @@ -1,5 +1,5 @@ { - "side": "RIGHT", + "side": "right", "y_position": 0, "color": 0, "content": { diff --git a/src/main/resources/data/unicopia/spellbook/chapters/the_otherworldly.json b/src/main/resources/data/unicopia/spellbook/chapters/the_otherworldly.json index 57a28e5c..b8c93bea 100644 --- a/src/main/resources/data/unicopia/spellbook/chapters/the_otherworldly.json +++ b/src/main/resources/data/unicopia/spellbook/chapters/the_otherworldly.json @@ -1,5 +1,5 @@ { - "side": "RIGHT", + "side": "right", "y_position": 6, "color": 0, "content": {