Skip to content

Commit

Permalink
feat: add showWhenAnyParentUnlocked to entry
Browse files Browse the repository at this point in the history
  • Loading branch information
klikli-dev committed Jan 11, 2024
1 parent 33835b5 commit 96efa61
Show file tree
Hide file tree
Showing 53 changed files with 270 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public class BookEntryModel {
protected int entryBackgroundVIndex = 0;

protected boolean hideWhileLocked;
protected boolean showWhenAnyParentUnlocked;
protected List<BookPageModel> pages = new ArrayList<>();
protected BookConditionModel condition;
protected ResourceLocation categoryToOpen;
Expand Down Expand Up @@ -62,6 +63,7 @@ public JsonObject toJson() {
json.addProperty("background_u_index", this.entryBackgroundUIndex);
json.addProperty("background_v_index", this.entryBackgroundVIndex);
json.addProperty("hide_while_locked", this.hideWhileLocked);
json.addProperty("show_when_any_parent_unlocked", this.showWhenAnyParentUnlocked);

if (!this.parents.isEmpty()) {
var parentsArray = new JsonArray();
Expand Down Expand Up @@ -150,10 +152,14 @@ public int getY() {
return this.y;
}

public boolean isHideWhileLocked() {
public boolean hideWhileLocked() {
return this.hideWhileLocked;
}

public boolean showWhenAnyParentUnlocked() {
return this.showWhenAnyParentUnlocked;
}

public List<BookPageModel> getPages() {
return this.pages;
}
Expand Down Expand Up @@ -330,6 +336,15 @@ public BookEntryModel hideWhileLocked(boolean hideWhileLocked) {
return this;
}

/**
* If true, the entry will show (locked) as soon as any parent is unlocked.
* If false, the entry will only show (locked) as soon as all parents are unlocked.
*/
public BookEntryModel showWhenAnyParentUnlocked(boolean showWhenAnyParentUnlocked) {
this.showWhenAnyParentUnlocked = showWhenAnyParentUnlocked;
return this;
}

/**
* Replaces the entry's pages with the given list.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ public class BookEntry {
protected int entryBackgroundVIndex;

protected boolean hideWhileLocked;
/**
* If true, the entry will show (locked) as soon as any parent is unlocked.
* If false, the entry will only show (locked) as soon as all parents are unlocked.
*/
protected boolean showWhenAnyParentUnlocked;
protected List<BookPage> pages;
protected BookCondition condition;

Expand All @@ -62,7 +67,7 @@ public class BookEntry {
protected ResourceLocation commandToRunOnFirstReadId;
protected BookCommand commandToRunOnFirstRead;

public BookEntry(ResourceLocation id, ResourceLocation categoryId, String name, String description, BookIcon icon, int x, int y, int entryBackgroundUIndex, int entryBackgroundVIndex, boolean hideWhileLocked, BookCondition condition, List<BookEntryParent> parents, List<BookPage> pages, ResourceLocation categoryToOpenId, ResourceLocation commandToRunOnFirstReadId) {
public BookEntry(ResourceLocation id, ResourceLocation categoryId, String name, String description, BookIcon icon, int x, int y, int entryBackgroundUIndex, int entryBackgroundVIndex, boolean hideWhileLocked, boolean showWhenAnyParentUnlocked, BookCondition condition, List<BookEntryParent> parents, List<BookPage> pages, ResourceLocation categoryToOpenId, ResourceLocation commandToRunOnFirstReadId) {
this.id = id;
this.categoryId = categoryId;
this.name = name;
Expand All @@ -76,6 +81,7 @@ public BookEntry(ResourceLocation id, ResourceLocation categoryId, String name,
this.pages = pages;
this.condition = condition;
this.hideWhileLocked = hideWhileLocked;
this.showWhenAnyParentUnlocked = showWhenAnyParentUnlocked;

this.categoryToOpenId = categoryToOpenId;
this.commandToRunOnFirstReadId = commandToRunOnFirstReadId;
Expand All @@ -91,6 +97,7 @@ public static BookEntry fromJson(ResourceLocation id, JsonObject json) {
var entryBackgroundUIndex = GsonHelper.getAsInt(json, "background_u_index", 0);
var entryBackgroundVIndex = GsonHelper.getAsInt(json, "background_v_index", 0);
var hideWhileLocked = GsonHelper.getAsBoolean(json, "hide_while_locked", false);
var showWhenAnyParentUnlocked = GsonHelper.getAsBoolean(json, "show_when_any_parent_unlocked", false);

var parentEntries = new ArrayList<BookEntryParent>();

Expand Down Expand Up @@ -130,7 +137,7 @@ public static BookEntry fromJson(ResourceLocation id, JsonObject json) {
}

return new BookEntry(id, categoryId, name, description, icon, x, y, entryBackgroundUIndex,
entryBackgroundVIndex, hideWhileLocked, condition, parentEntries, pages, categoryToOpen, commandToRunOnFirstRead);
entryBackgroundVIndex, hideWhileLocked, showWhenAnyParentUnlocked, condition, parentEntries, pages, categoryToOpen, commandToRunOnFirstRead);
}

public static BookEntry fromNetwork(ResourceLocation id, FriendlyByteBuf buffer) {
Expand All @@ -143,6 +150,7 @@ public static BookEntry fromNetwork(ResourceLocation id, FriendlyByteBuf buffer)
var entryBackgroundUIndex = buffer.readVarInt();
var entryBackgroundVIndex = buffer.readVarInt();
var hideWhileLocked = buffer.readBoolean();
var showWhenAnyParentUnlocked = buffer.readBoolean();

var parentEntries = new ArrayList<BookEntryParent>();

Expand All @@ -166,7 +174,7 @@ public static BookEntry fromNetwork(ResourceLocation id, FriendlyByteBuf buffer)
ResourceLocation commandToRunOnFirstRead = buffer.readNullable(FriendlyByteBuf::readResourceLocation);

return new BookEntry(id, categoryId, name, description, icon, x, y, entryBackgroundUIndex,
entryBackgroundVIndex, hideWhileLocked, condition, parentEntries, pages, categoryToOpen, commandToRunOnFirstRead);
entryBackgroundVIndex, hideWhileLocked, showWhenAnyParentUnlocked, condition, parentEntries, pages, categoryToOpen, commandToRunOnFirstRead);
}

public BookCategory getCategoryToOpen() {
Expand Down Expand Up @@ -241,6 +249,7 @@ public void toNetwork(FriendlyByteBuf buffer) {
buffer.writeVarInt(this.entryBackgroundUIndex);
buffer.writeVarInt(this.entryBackgroundVIndex);
buffer.writeBoolean(this.hideWhileLocked);
buffer.writeBoolean(this.showWhenAnyParentUnlocked);

buffer.writeVarInt(this.parents.size());
for (var parent : this.parents) {
Expand Down Expand Up @@ -271,6 +280,10 @@ public boolean hideWhileLocked() {
return this.hideWhileLocked;
}

public boolean showWhenAnyParentUnlocked() {
return this.showWhenAnyParentUnlocked;
}

public ResourceLocation getId() {
return this.id;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,15 +217,20 @@ private EntryDisplayState getEntryDisplayState(BookEntry entry) {

var isEntryUnlocked = BookUnlockStateManager.get().isUnlockedFor(player, entry);

var anyParentsUnlocked = false;
var allParentsUnlocked = true;
for (var parent : entry.getParents()) {
if (!BookUnlockStateManager.get().isUnlockedFor(player, parent.getEntry())) {
allParentsUnlocked = false;
break;
} else {
anyParentsUnlocked = true;
}
}

if (!allParentsUnlocked)
if(entry.showWhenAnyParentUnlocked() && !anyParentsUnlocked)
return EntryDisplayState.HIDDEN;

if (!entry.showWhenAnyParentUnlocked() && !allParentsUnlocked)
return EntryDisplayState.HIDDEN;

if (!isEntryUnlocked)
Expand Down Expand Up @@ -373,6 +378,9 @@ private void renderConnections(GuiGraphics guiGraphics, BookEntry entry, float x
RenderSystem.enableBlend();

for (var parent : entry.getParents()) {
var parentDisplayState = this.getEntryDisplayState(parent.getEntry());
if(parentDisplayState == EntryDisplayState.HIDDEN)
continue;

int blitOffset = 0; //note: any negative blit offset will move it behind our category background
this.connectionRenderer.setBlitOffset(blitOffset);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ protected String[] generateEntryMap() {
"___ _____5____________",
"__(multiblock)______________d___",
"___ _______r__a_______",
"__c __________________",
"__c ____t_____________",
"___ _______2___3___i__",
"__s _____e____________",
"___ _______________g__",
Expand All @@ -47,6 +47,16 @@ protected void generateEntries() {

var conditionEntries = this.add(this.makeConditionEntries('r', 'a', '1', '2'));

var twoParentsEntry = this.add(this.makeEntryWithTwoParents('t'));
twoParentsEntry.showWhenAnyParentUnlocked(true);
var parent1 = conditionEntries.stream().filter(e -> e.getId().getPath().contains("condition_root")).findFirst().get();
var parent2 = conditionEntries.stream().filter(e -> e.getId().getPath().contains("condition_level_2")).findFirst().get();
twoParentsEntry.withParents(this.parent(parent1), this.parent(parent2));
twoParentsEntry.withCondition(this.condition().and(
this.condition().entryRead(parent1),
this.condition().entryRead(parent2)
));

var recipeEntry = this.add(this.makeRecipeEntry('c'));

var spotlightEntry = this.add(this.makeSpotlightEntry('s'));
Expand Down Expand Up @@ -124,6 +134,26 @@ private BookEntryModel makeMultiblockEntry(String location) {
.withLocation(this.entryMap().get(location));
}

private BookEntryModel makeEntryWithTwoParents(char location) {
this.context().entry("two_parents");
this.add(this.context().entryName(), "Entry with two parents");
this.add(this.context().entryDescription(), "Yup, two parents!");

this.context().page("intro");
this.page(BookTextPageModel.builder()
.withText(this.context().pageText())
.withTitle(this.context().pageTitle())
.build());

this.add(this.context().pageTitle(), "Entry with two parents");
this.add(this.context().pageText(), "It has two parents ..");

return this.entry(location)
.withIcon(Items.AMETHYST_CLUSTER)
.withLocation(this.entryMap().get(location));
}


private List<BookEntryModel> makeConditionEntries(char rootLocation, char advancementLocation, char level1Location, char level2Location) {
var result = new ArrayList<BookEntryModel>();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,27 +1,28 @@
// 1.20.4 2024-01-10T06:21:47.111948 Modonomicon/Books: modonomicon
044d7ef2e45f6f80006d0846f8377680243b8658 data\modonomicon\modonomicon\books\demo\entries\features\spotlight.json
// 1.20.4 2024-01-11T12:51:58.1315442 Modonomicon/Books: modonomicon
1ddba68d78ad9d5a43598e837c23d1a57ceb4b3a data\modonomicon\modonomicon\books\demo\entries\features\spotlight.json
4a0f243b77e13c86c07e8a81ccdac5d62ae54605 data\modonomicon\modonomicon\books\demo\entries\hidden\always_locked.json
2a6c1fb1e2536858796d47d5b4e6de64526e3466 data\modonomicon\modonomicon\books\demo\categories\hidden.json
ab976dcd9540d1cad065333ac2d345b04a5d4154 data\modonomicon\modonomicon\books\demo\entries\hidden\always_locked.json
b82c0b99b596152481f8281592d77c822fd7590e data\modonomicon\modonomicon\books\demo\categories\conditional.json
da6b6a832a9392085f982ba05f34e606d64fa13b data\modonomicon\modonomicon\books\demo\entries\formatting\always_locked.json
617239ac329c0692a471ef875b27df2acad3e362 data\modonomicon\modonomicon\books\demo\entries\features\condition_advancement.json
7cb4c581142b83471177183ec136e5db0f8a1540 data\modonomicon\modonomicon\books\demo\entries\features\multiblock.json
f1ba65555419d482978f2eaef7ef5958084e49da data\modonomicon\modonomicon\books\demo\entries\features\empty.json
81d4cefc726d32ff034207bbadbc0d877b23aa05 data\modonomicon\modonomicon\books\demo\entries\features\condition_root.json
820e09ba5a917e1b5b0ceb1806572b0801cfa52f data\modonomicon\modonomicon\books\demo\entries\formatting\always_locked.json
9efe734dd6980e4e7945babb3595dbc3381cee46 data\modonomicon\modonomicon\books\demo\entries\features\multiblock.json
f363cda4775931649950ee67ebbfaf32f1c4db1a data\modonomicon\modonomicon\books\demo\entries\features\condition_advancement.json
bf51c62090628f3c7f0a236c14e4f316001f3bc3 data\modonomicon\modonomicon\books\demo\entries\features\empty.json
1fcaa7ad5be1754143a21d4491c78b8a675c20b0 data\modonomicon\modonomicon\books\demo\entries\features\condition_root.json
91921129e14250f4f9403e2ee1b4614da61f702a data\modonomicon\modonomicon\books\demo\commands\test_command.json
19124bcb01e4586e51c43a6b9b1dd4c91b6520d4 data\modonomicon\modonomicon\books\demo\categories\formatting.json
149f724b78931be9fa643e1c9288933cc73a75c4 data\modonomicon\modonomicon\books\demo\entries\formatting\basic.json
09d31cc11836a50dad4c92daa1695475a6c4fc1f data\modonomicon\modonomicon\books\demo\entries\conditional\always_locked.json
d477e6f7c2a83fd07e3ab7bbf0f9afac38d2905f data\modonomicon\modonomicon\books\demo\entries\formatting\link.json
1bb271b49b5b3c53d95e25bef2a0425582bbb7f1 data\modonomicon\modonomicon\books\demo\entries\features\command.json
89a3853474ced303a7a4409c7420b830bf940f6c data\modonomicon\modonomicon\books\demo\entries\features\image.json
a86fa14f1daf5f2b39f04afaf7560f59da57a5cd data\modonomicon\modonomicon\books\demo\entries\features\condition_level_2.json
b7bfa2595759a97ccd065468113590c65ad4a7c0 data\modonomicon\modonomicon\books\demo\entries\features\redirect.json
fb90975dbea8b6afb74a66a792295233fd462bf8 data\modonomicon\modonomicon\books\demo\entries\features\condition_level_1.json
ff4da4a6ae75e5e430a24f938260001d74110df0 data\modonomicon\modonomicon\books\demo\entries\formatting\advanced.json
a0b01243aa86122c9894a419e5f6998e2d1a2ca3 data\modonomicon\modonomicon\books\demo\entries\features\recipe.json
401f4f3f00ce4efb15c111371ba089b47498aaab data\modonomicon\modonomicon\books\demo\entries\formatting\basic.json
927643166c4e76606aa33bf3576453ca33418400 data\modonomicon\modonomicon\books\demo\entries\conditional\always_locked.json
55dade7a22bb2786dce2ea67704dea28ea10050f data\modonomicon\modonomicon\books\demo\entries\formatting\link.json
d7d3faee6f41006093d5bbd10e199689459d9ba1 data\modonomicon\modonomicon\books\demo\entries\features\command.json
9a9bc631d5a569b7d737594215bfe083460090a6 data\modonomicon\modonomicon\books\demo\entries\features\image.json
01b6c8a20707f8a8208ed867e9848ac404d337cc data\modonomicon\modonomicon\books\demo\entries\features\condition_level_2.json
0d835b4f641b0e49444a03bb6738e8002a985b9e data\modonomicon\modonomicon\books\demo\entries\features\redirect.json
1c3312590ae13c8ff947bdf25318dab807f06b15 data\modonomicon\modonomicon\books\demo\entries\features\condition_level_1.json
e31c574dcfc0d471cf5f24e056b5b8d7de730882 data\modonomicon\modonomicon\books\demo\entries\formatting\advanced.json
9fa8a927180fa94ecf97338806c83fe4e9e343f3 data\modonomicon\modonomicon\books\demo\entries\features\recipe.json
b9ad32b76e2efc9f44c8b76d56670f9dc63f2a94 data\modonomicon\modonomicon\books\demo\commands\test_command2.json
f5a6ea38b482add4c451e398f054e22fa1684ba4 data\modonomicon\modonomicon\books\demo\categories\features.json
ed0e320abb2ebd6750a96b173ef1f7aeedd87f05 data\modonomicon\modonomicon\books\demo\entries\features\custom_icon.json
b79b2b58f9f86b3efa0d5ad4a2813f092cb9b816 data\modonomicon\modonomicon\books\demo\entries\features\entity.json
27358d5850a49182d8cc4728e994dce12fc3bd92 data\modonomicon\modonomicon\books\demo\entries\features\custom_icon.json
8668b99145a94ec0674238178701ec78185e5e45 data\modonomicon\modonomicon\books\demo\entries\features\entity.json
a30aec89de938ebb9f5e704d5262ad6f43865afd data\modonomicon\modonomicon\books\demo\book.json
6b4396b3899104ee4ecbb49d0eb3833564f81971 data\modonomicon\modonomicon\books\demo\entries\features\two_parents.json
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
// 1.20.4 2024-01-10T06:21:47.1164668 Modonomicon/Languages: en_us
a4ac13d2e5bb6ec1b2501bc9d158fde464336e82 assets\modonomicon\lang\en_us.json
// 1.20.4 2024-01-11T12:51:58.1345437 Modonomicon/Languages: en_us
3fcf20dd9d80f88ce542cd912e2ac2bba62946e5 assets\modonomicon\lang\en_us.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// 1.20.4 2024-01-10T06:21:47.1164668 Modonomicon/Model Definitions
// 1.20.4 2024-01-11T12:51:58.1345437 Modonomicon/Model Definitions
a4a605637998b2d6d6b7cd9c002d5ba0163622c0 assets\modonomicon\models\item\modonomicon_red.json
4b35646623b74487675fa8ec1bb375535100c336 assets\modonomicon\models\item\modonomicon_purple.json
83adea7fd65acd9581797454e1a6dc6122d8a826 assets\modonomicon\models\item\modonomicon_green.json
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// 1.20.4 2024-01-10T06:21:47.1164668 Modonomicon/Multiblocks: modonomicon
// 1.20.4 2024-01-11T12:51:58.1335417 Modonomicon/Multiblocks: modonomicon
89b499dd4f3850c8099ad26ae3c286e95ac8cf99 data\modonomicon\modonomicon\multiblocks\demo_fluid.json
9dc306d79a39ee2085be7e1384d8e39640d79e49 data\modonomicon\modonomicon\multiblocks\demo_dense.json
fc1e7363336d456dd0d1583fcfdaa27a8c4bf23e data\modonomicon\modonomicon\multiblocks\demo_predicate.json
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@
"book.modonomicon.demo.features.spotlight.spotlight1.text": "A sample spotlight page with custom title.",
"book.modonomicon.demo.features.spotlight.spotlight1.title": "Custom Title",
"book.modonomicon.demo.features.spotlight.spotlight2.text": "A sample spotlight page with automatic title.",
"book.modonomicon.demo.features.two_parents.description": "Yup, two parents!",
"book.modonomicon.demo.features.two_parents.intro.text": "It has two parents ..",
"book.modonomicon.demo.features.two_parents.intro.title": "Entry with two parents",
"book.modonomicon.demo.features.two_parents.name": "Entry with two parents",
"book.modonomicon.demo.formatting.advanced.description": "An entry showcasing advanced formatting.",
"book.modonomicon.demo.formatting.advanced.name": "Advanced Formatting Entry",
"book.modonomicon.demo.formatting.advanced.page1.text": "<t>this.could.be.a.translation.key<t> \n***This is bold italics*** \n*++This is italics underlined++*\n[](item://minecraft:diamond)\n[TestText](item://minecraft:emerald)\n",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"item": "minecraft:nether_star"
},
"name": "book.modonomicon.demo.conditional.always_locked.name",
"show_when_any_parent_unlocked": false,
"x": 0,
"y": 0
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"line_reversed": false
}
],
"show_when_any_parent_unlocked": false,
"x": -8,
"y": 3
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"use_markdown_in_title": false
}
],
"show_when_any_parent_unlocked": false,
"x": -3,
"y": -2
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"line_reversed": false
}
],
"show_when_any_parent_unlocked": false,
"x": 0,
"y": 0
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"line_reversed": false
}
],
"show_when_any_parent_unlocked": false,
"x": -6,
"y": 0
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"use_markdown_in_title": false
}
],
"show_when_any_parent_unlocked": false,
"x": -6,
"y": -2
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"line_reversed": false
}
],
"show_when_any_parent_unlocked": false,
"x": 2,
"y": 2
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"line_reversed": false
}
],
"show_when_any_parent_unlocked": false,
"x": -8,
"y": 1
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"text": "book.modonomicon.demo.features.entity.entity2.text"
}
],
"show_when_any_parent_unlocked": false,
"x": 1,
"y": -3
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
"line_reversed": false
}
],
"show_when_any_parent_unlocked": false,
"x": 2,
"y": 0
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
"text": ""
}
],
"show_when_any_parent_unlocked": false,
"x": -14,
"y": -3
}
Loading

0 comments on commit 96efa61

Please sign in to comment.