From 8ceed0ac02c540f963b3d941f6a2589fc8af3c3c Mon Sep 17 00:00:00 2001 From: UnRealDinnerbone Date: Thu, 8 Aug 2024 12:34:22 -0500 Subject: [PATCH 1/9] Update sidebar json and render overlay code --- .../client/FTBQuestsClientEventHandler.java | 5 +++-- .../resources/assets/ftbquests/sidebar_buttons.json | 12 ------------ .../assets/ftbquests/sidebar_buttons/quests.json | 10 ++++++++++ 3 files changed, 13 insertions(+), 14 deletions(-) delete mode 100644 common/src/main/resources/assets/ftbquests/sidebar_buttons.json create mode 100644 common/src/main/resources/assets/ftbquests/sidebar_buttons/quests.json diff --git a/common/src/main/java/dev/ftb/mods/ftbquests/client/FTBQuestsClientEventHandler.java b/common/src/main/java/dev/ftb/mods/ftbquests/client/FTBQuestsClientEventHandler.java index e5ac1ece6..e6992c9ed 100644 --- a/common/src/main/java/dev/ftb/mods/ftbquests/client/FTBQuestsClientEventHandler.java +++ b/common/src/main/java/dev/ftb/mods/ftbquests/client/FTBQuestsClientEventHandler.java @@ -10,6 +10,7 @@ import dev.architectury.networking.NetworkManager; import dev.architectury.registry.client.rendering.BlockEntityRendererRegistry; import dev.architectury.registry.client.rendering.ColorHandlerRegistry; +import dev.ftb.mods.ftblibrary.api.sidebar.ButtonOverlayRender; import dev.ftb.mods.ftblibrary.icon.Color4I; import dev.ftb.mods.ftblibrary.sidebar.SidebarButtonCreatedEvent; import dev.ftb.mods.ftblibrary.ui.CustomClickEvent; @@ -117,7 +118,7 @@ private void registerItemColors(Minecraft minecraft) { private void onSidebarButtonCreated(SidebarButtonCreatedEvent event) { if (event.getButton().getId().equals(QUESTS_BUTTON)) { - event.getButton().setCustomTextHandler(() -> + event.getButton().addOverlayRender(ButtonOverlayRender.ofSimpleString(() -> { if (ClientQuestFile.exists()) { if (ClientQuestFile.INSTANCE.isDisableGui() && !ClientQuestFile.INSTANCE.canEdit()) { @@ -130,7 +131,7 @@ private void onSidebarButtonCreated(SidebarButtonCreatedEvent event) { } return ""; - }); + })); } } diff --git a/common/src/main/resources/assets/ftbquests/sidebar_buttons.json b/common/src/main/resources/assets/ftbquests/sidebar_buttons.json deleted file mode 100644 index 4a24ee380..000000000 --- a/common/src/main/resources/assets/ftbquests/sidebar_buttons.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "quests": { - "group": "ftblibrary:info", - "icon": "ftbquests:item/book", - "x": 610, - "click": "ftbquests:open_gui", - "required_server_mods": [ - "ftbquests" - ], - "custom_text": true - } -} \ No newline at end of file diff --git a/common/src/main/resources/assets/ftbquests/sidebar_buttons/quests.json b/common/src/main/resources/assets/ftbquests/sidebar_buttons/quests.json new file mode 100644 index 000000000..f3cc13f3b --- /dev/null +++ b/common/src/main/resources/assets/ftbquests/sidebar_buttons/quests.json @@ -0,0 +1,10 @@ +{ + "icon": "ftbquests:item/book", + "sort_index": 575, + "click": [ + "ftbquests:open_gui" + ], + "required_server_mods": [ + "ftbquests" + ] +} \ No newline at end of file From 6d05fe6c7a3b81470e41dc93348a41d0e0452460 Mon Sep 17 00:00:00 2001 From: Des Herriott Date: Fri, 9 Aug 2024 15:47:53 +0100 Subject: [PATCH 2/9] build: updated to ftb lib 2100.1.5-SNAPSHOT fix up FTBQuestsClientEventHandler --- .../ftb/mods/ftbquests/client/FTBQuestsClientEventHandler.java | 2 +- gradle.properties | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/common/src/main/java/dev/ftb/mods/ftbquests/client/FTBQuestsClientEventHandler.java b/common/src/main/java/dev/ftb/mods/ftbquests/client/FTBQuestsClientEventHandler.java index e6992c9ed..3948d4b1b 100644 --- a/common/src/main/java/dev/ftb/mods/ftbquests/client/FTBQuestsClientEventHandler.java +++ b/common/src/main/java/dev/ftb/mods/ftbquests/client/FTBQuestsClientEventHandler.java @@ -11,8 +11,8 @@ import dev.architectury.registry.client.rendering.BlockEntityRendererRegistry; import dev.architectury.registry.client.rendering.ColorHandlerRegistry; import dev.ftb.mods.ftblibrary.api.sidebar.ButtonOverlayRender; +import dev.ftb.mods.ftblibrary.api.sidebar.SidebarButtonCreatedEvent; import dev.ftb.mods.ftblibrary.icon.Color4I; -import dev.ftb.mods.ftblibrary.sidebar.SidebarButtonCreatedEvent; import dev.ftb.mods.ftblibrary.ui.CustomClickEvent; import dev.ftb.mods.ftblibrary.ui.GuiHelper; import dev.ftb.mods.ftbquests.api.FTBQuestsAPI; diff --git a/gradle.properties b/gradle.properties index d7f1d5134..cad4d737e 100644 --- a/gradle.properties +++ b/gradle.properties @@ -24,7 +24,7 @@ fabric_api_version=0.100.8+1.21 fabric_api_version_range=>=0.100.1+1.21 architectury_api_version=13.0.6 -ftb_library_version=2100.1.4 +ftb_library_version=2100.1.5-SNAPSHOT ftb_teams_version=2100.1.0 # Optional deps From cfcf1a258122f6ede9723a9eb109eb6cc984f315 Mon Sep 17 00:00:00 2001 From: Des Herriott Date: Tue, 13 Aug 2024 16:30:36 +0100 Subject: [PATCH 3/9] build: updated gradle & arch loom versions --- build.gradle | 2 +- gradle/wrapper/gradle-wrapper.properties | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/build.gradle b/build.gradle index 724df26b8..39317fff7 100644 --- a/build.gradle +++ b/build.gradle @@ -1,6 +1,6 @@ plugins { id "architectury-plugin" version "3.4-SNAPSHOT" - id "dev.architectury.loom" version "1.6-SNAPSHOT" apply false + id "dev.architectury.loom" version "1.7-SNAPSHOT" apply false id "me.modmuss50.mod-publish-plugin" version "0.5.1" } diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 48c0a02ca..0d1842103 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.8-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists From 8d693ecd2c7cf62695b94b09940d2fe13a133d7b Mon Sep 17 00:00:00 2001 From: Des Herriott Date: Wed, 14 Aug 2024 16:41:31 +0100 Subject: [PATCH 4/9] build: updated to MC 1.21.1 --- gradle.properties | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/gradle.properties b/gradle.properties index cad4d737e..ca411d351 100644 --- a/gradle.properties +++ b/gradle.properties @@ -9,23 +9,22 @@ maven_group=dev.ftb.mods mod_author=FTB Team # Build time -mod_version=2100.1.5 -minecraft_version=1.21 - +mod_version=2101.1.0 +minecraft_version=1.21.1 # Cross env #forge_version=50.0.9 #forge_loader_version=49 -neoforge_version=21.0.146 -neoforge_version_range=[21.0.143,) +neoforge_version=21.1.9 +neoforge_version_range=[21.1.0,) neoforge_loader_version=4 fabric_loader_version=0.15.11 fabric_api_version=0.100.8+1.21 fabric_api_version_range=>=0.100.1+1.21 architectury_api_version=13.0.6 -ftb_library_version=2100.1.5-SNAPSHOT -ftb_teams_version=2100.1.0 +ftb_library_version=2101.1.0-SNAPSHOT +ftb_teams_version=2101.1.0-SNAPSHOT # Optional deps teamreborn_energy_version=4.1.0 From f3fee980d43258f12e8f44acefa123b9bf1b7b29 Mon Sep 17 00:00:00 2001 From: Des Herriott Date: Wed, 14 Aug 2024 16:37:11 +0100 Subject: [PATCH 5/9] fix: hide until deps visible/completed behaviour Fixed incorrect current behaviour: "Hide quest until deps visible" actually requires dependency completion, not visibility Added new "Hide quest until deps completed" setting https://github.com/FTBTeam/FTB-Mods-Issues/issues/1306 --- .../dev/ftb/mods/ftbquests/quest/Chapter.java | 17 +++++-- .../dev/ftb/mods/ftbquests/quest/Quest.java | 49 +++++++++++++++---- .../ftb/mods/ftbquests/quest/TeamData.java | 43 ++++++++-------- .../assets/ftbquests/lang/en_us.json | 5 +- 4 files changed, 80 insertions(+), 34 deletions(-) diff --git a/common/src/main/java/dev/ftb/mods/ftbquests/quest/Chapter.java b/common/src/main/java/dev/ftb/mods/ftbquests/quest/Chapter.java index 8d014a587..ffb95156d 100644 --- a/common/src/main/java/dev/ftb/mods/ftbquests/quest/Chapter.java +++ b/common/src/main/java/dev/ftb/mods/ftbquests/quest/Chapter.java @@ -42,6 +42,7 @@ public final class Chapter extends QuestObject { private int defaultMinWidth = 0; private ProgressionMode progressionMode; private boolean hideQuestDetailsUntilStartable; + private boolean hideQuestUntilDepsComplete; private boolean hideQuestUntilDepsVisible; private boolean defaultRepeatable; private Tristate consumeItems; @@ -67,6 +68,7 @@ public Chapter(long id, BaseQuestFile file, ChapterGroup group, String filename) defaultHideDependencyLines = false; progressionMode = ProgressionMode.DEFAULT; hideQuestUntilDepsVisible = false; + hideQuestUntilDepsComplete = false; hideQuestDetailsUntilStartable = false; defaultRepeatable = false; consumeItems = Tristate.DEFAULT; @@ -176,6 +178,7 @@ public void writeData(CompoundTag nbt, HolderLookup.Provider provider) { if (hideQuestDetailsUntilStartable) nbt.putBoolean("hide_quest_details_until_startable", true); if (hideQuestUntilDepsVisible) nbt.putBoolean("hide_quest_until_deps_visible", true); + if (hideQuestUntilDepsComplete) nbt.putBoolean("hide_quest_until_deps_complete", true); if (defaultRepeatable) nbt.putBoolean("default_repeatable_quest", true); if (requireSequentialTasks) nbt.putBoolean("require_sequential_tasks", true); @@ -215,6 +218,7 @@ public void readData(CompoundTag nbt, HolderLookup.Provider provider) { consumeItems = Tristate.read(nbt, "consume_items"); hideQuestDetailsUntilStartable = nbt.getBoolean("hide_quest_details_until_startable"); hideQuestUntilDepsVisible = nbt.getBoolean("hide_quest_until_deps_visible"); + hideQuestUntilDepsComplete = nbt.getBoolean("hide_quest_until_deps_complete"); defaultRepeatable = nbt.getBoolean("default_repeatable_quest"); requireSequentialTasks = nbt.getBoolean("require_sequential_tasks"); autoFocusId = nbt.getString("autofocus_id"); @@ -234,12 +238,13 @@ public void writeNetData(RegistryFriendlyByteBuf buffer) { flags = Bits.setFlag(flags, 0x01, alwaysInvisible); flags = Bits.setFlag(flags, 0x02, defaultHideDependencyLines); flags = Bits.setFlag(flags, 0x04, hideQuestDetailsUntilStartable); - flags = Bits.setFlag(flags, 0x08, hideQuestUntilDepsVisible); + flags = Bits.setFlag(flags, 0x08, hideQuestUntilDepsComplete); flags = Bits.setFlag(flags, 0x10, defaultRepeatable); flags = Bits.setFlag(flags, 0x20, consumeItems != Tristate.DEFAULT); flags = Bits.setFlag(flags, 0x40, consumeItems == Tristate.TRUE); flags = Bits.setFlag(flags, 0x80, requireSequentialTasks); flags = Bits.setFlag(flags, 0x100, !autoFocusId.isEmpty()); + flags = Bits.setFlag(flags, 0x200, hideQuestUntilDepsVisible); buffer.writeVarInt(flags); if (!autoFocusId.isEmpty()) buffer.writeLong(QuestObjectBase.parseHexId(autoFocusId).orElse(0L)); @@ -259,10 +264,11 @@ public void readNetData(RegistryFriendlyByteBuf buffer) { alwaysInvisible = Bits.getFlag(flags, 0x01); defaultHideDependencyLines = Bits.getFlag(flags, 0x02); hideQuestDetailsUntilStartable = Bits.getFlag(flags, 0x04); - hideQuestUntilDepsVisible = Bits.getFlag(flags, 0x08); + hideQuestUntilDepsComplete = Bits.getFlag(flags, 0x08); defaultRepeatable = Bits.getFlag(flags, 0x10); consumeItems = Bits.getFlag(flags, 0x20) ? Bits.getFlag(flags, 0x40) ? Tristate.TRUE : Tristate.FALSE : Tristate.DEFAULT; requireSequentialTasks = Bits.getFlag(flags, 0x80); + hideQuestUntilDepsVisible = Bits.getFlag(flags, 0x200); autoFocusId = Bits.getFlag(flags, 0x100) ? QuestObjectBase.getCodeString(buffer.readLong()) : ""; } @@ -418,6 +424,7 @@ public void fillConfigGroup(ConfigGroup config) { visibility.addBool("default_hide_dependency_lines", defaultHideDependencyLines, v -> defaultHideDependencyLines = v, false); visibility.addBool("hide_quest_details_until_startable", hideQuestDetailsUntilStartable, v -> hideQuestDetailsUntilStartable = v, false); visibility.addBool("hide_quest_until_deps_visible", hideQuestUntilDepsVisible, v -> hideQuestUntilDepsVisible = v, false); + visibility.addBool("hide_quest_until_deps_complete", hideQuestUntilDepsComplete, v -> hideQuestUntilDepsComplete = v, false); ConfigGroup misc = config.getOrCreateSubgroup("misc").setNameKey("ftbquests.quest.misc"); misc.addString("autofocus_id", autoFocusId, v -> autoFocusId = v, "", HEX_STRING); @@ -490,7 +497,11 @@ public boolean hideQuestDetailsUntilStartable() { return hideQuestDetailsUntilStartable; } - public boolean hideQuestUntilDepsVisible() { + public boolean hideQuestUntilDepsComplete() { + return hideQuestUntilDepsComplete; + } + + public boolean isHideQuestUntilDepsVisible() { return hideQuestUntilDepsVisible; } diff --git a/common/src/main/java/dev/ftb/mods/ftbquests/quest/Quest.java b/common/src/main/java/dev/ftb/mods/ftbquests/quest/Quest.java index 69f8836f6..28d37a874 100644 --- a/common/src/main/java/dev/ftb/mods/ftbquests/quest/Quest.java +++ b/common/src/main/java/dev/ftb/mods/ftbquests/quest/Quest.java @@ -50,6 +50,7 @@ public final class Quest extends QuestObject implements Movable { private Chapter chapter; private double x, y; private Tristate hideUntilDepsVisible; + private Tristate hideUntilDepsComplete; private String shape; private final List dependencies; private final List tasks; @@ -92,6 +93,7 @@ public Quest(long id, Chapter chapter) { hideDependencyLines = Tristate.DEFAULT; hideDependentLines = false; hideUntilDepsVisible = Tristate.DEFAULT; + hideUntilDepsComplete = Tristate.DEFAULT; dependencyRequirement = DependencyRequirement.ALL_COMPLETED; minRequiredDependencies = 0; hideTextUntilComplete = Tristate.DEFAULT; @@ -258,7 +260,8 @@ public void writeData(CompoundTag nbt, HolderLookup.Provider provider) { nbt.put("dependencies", deps); } - hideUntilDepsVisible.write(nbt, "hide"); + hideUntilDepsVisible.write(nbt, "hide_until_deps_visible"); + hideUntilDepsComplete.write(nbt, "hide_until_deps_complete"); if (dependencyRequirement != DependencyRequirement.ALL_COMPLETED) { nbt.putString("dependency_requirement", dependencyRequirement.getId()); @@ -342,7 +345,14 @@ public void readData(CompoundTag nbt, HolderLookup.Provider provider) { } } - hideUntilDepsVisible = Tristate.read(nbt, "hide"); + if (nbt.contains("hide", Tag.TAG_BYTE)) { + // TODO legacy; remove in 1.22 + hideUntilDepsVisible = Tristate.read(nbt, "hide"); + } else { + hideUntilDepsVisible = Tristate.read(nbt, "hide_until_deps_visible"); + } + hideUntilDepsComplete = Tristate.read(nbt, "hide_until_deps_complete"); + dependencyRequirement = DependencyRequirement.NAME_MAP.get(nbt.getString("dependency_requirement")); hideTextUntilComplete = Tristate.read(nbt, "hide_text_until_complete"); size = nbt.getDouble("size"); @@ -381,6 +391,7 @@ public void writeNetData(RegistryFriendlyByteBuf buffer) { flags = Bits.setFlag(flags, 0x20000, iconScale != 1f); buffer.writeVarInt(flags); + hideUntilDepsComplete.write(buffer); hideUntilDepsVisible.write(buffer); hideDependencyLines.write(buffer); hideTextUntilComplete.write(buffer); @@ -424,6 +435,7 @@ public void writeNetData(RegistryFriendlyByteBuf buffer) { public void readNetData(RegistryFriendlyByteBuf buffer) { super.readNetData(buffer); int flags = buffer.readVarInt(); + hideUntilDepsComplete = Tristate.read(buffer); hideUntilDepsVisible = Tristate.read(buffer); hideDependencyLines = Tristate.read(buffer); hideTextUntilComplete = Tristate.read(buffer); @@ -633,7 +645,8 @@ public void onClicked(Widget clicked, MouseButton button, ConfigCallback callbac appearance.addDouble("icon_scale", iconScale, v -> iconScale = v, 1f, 0.1, 2.0); ConfigGroup visibility = config.getOrCreateSubgroup("visibility"); - visibility.addTristate("hide", hideUntilDepsVisible, v -> hideUntilDepsVisible = v); + visibility.addTristate("hide_until_deps_complete", hideUntilDepsComplete, v -> hideUntilDepsComplete = v); + visibility.addTristate("hide_until_deps_visible", hideUntilDepsVisible, v -> hideUntilDepsVisible = v); visibility.addBool("invisible", invisible, v -> invisible = v, false); visibility.addInt("invisible_until_tasks", invisibleUntilTasks, v -> invisibleUntilTasks = v, 0, 0, Integer.MAX_VALUE).setCanEdit(invisible); visibility.addTristate("hide_details_until_startable", hideDetailsUntilStartable, v -> hideDetailsUntilStartable = v); @@ -715,8 +728,10 @@ public boolean isVisible(TeamData data) { return true; } - if (hideUntilDepsVisible.get(chapter.hideQuestUntilDepsVisible())) { + if (hideUntilDepsComplete.get(chapter.hideQuestUntilDepsComplete())) { return data.areDependenciesComplete(this); + } else if (hideUntilDepsVisible.get(chapter.isHideQuestUntilDepsVisible())) { + return data.areDependenciesVisible(this); } return streamDependencies().anyMatch(object -> object.isVisible(data)); @@ -1016,21 +1031,35 @@ public void removeReward(Reward reward) { rewards.remove(reward); } - public boolean areDependenciesComplete(TeamData teamData) { + @FunctionalInterface + private interface DependencyChecker { + default boolean check(QuestObject questObject) { + return !questObject.invalid && check0(questObject); + } + boolean check0(QuestObject questObject); + } + + private boolean checkDependencies(DependencyChecker checker) { if (minRequiredDependencies > 0) { return streamDependencies() - .filter(dep -> teamData.isCompleted(dep) && !dep.invalid) + .filter(checker::check) .limit(minRequiredDependencies) .count() == minRequiredDependencies; } else if (dependencyRequirement.needOnlyOne()) { - return streamDependencies() - .anyMatch(dep -> !dep.invalid && (dependencyRequirement.needCompletion() ? teamData.isCompleted(dep) : teamData.isStarted(dep))); + return streamDependencies().anyMatch(checker::check); } else { - return streamDependencies() - .allMatch(dep -> !dep.invalid && (dependencyRequirement.needCompletion() ? teamData.isCompleted(dep) : teamData.isStarted(dep))); + return streamDependencies().allMatch(checker::check); } } + public boolean areDependenciesComplete(TeamData teamData) { + return checkDependencies(dep -> dependencyRequirement.needCompletion() ? teamData.isCompleted(dep) : teamData.isStarted(dep)); + } + + public boolean areDependenciesVisible(TeamData teamData) { + return checkDependencies(dep -> dep.isVisible(teamData)); + } + public List> buildDescriptionIndex() { List> index = new ArrayList<>(); diff --git a/common/src/main/java/dev/ftb/mods/ftbquests/quest/TeamData.java b/common/src/main/java/dev/ftb/mods/ftbquests/quest/TeamData.java index d201d1b38..b212590ec 100644 --- a/common/src/main/java/dev/ftb/mods/ftbquests/quest/TeamData.java +++ b/common/src/main/java/dev/ftb/mods/ftbquests/quest/TeamData.java @@ -32,6 +32,7 @@ import net.minecraft.server.level.ServerPlayer; import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.ItemStack; +import org.apache.commons.lang3.function.ToBooleanBiFunction; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -77,8 +78,9 @@ public void encode(FriendlyByteBuf buf, TeamData data) { private final Long2LongOpenHashMap completed; private final Object2ObjectOpenHashMap perPlayerData; - private Long2ByteOpenHashMap areDependenciesCompleteCache; - private Object2ByteOpenHashMap unclaimedRewardsCache; + private final Long2ByteOpenHashMap areDependenciesCompleteCache; + private final Long2ByteOpenHashMap areDependenciesVisibleCache; + private final Object2ByteOpenHashMap unclaimedRewardsCache; public TeamData(UUID teamId, BaseQuestFile file) { this(teamId, file, ""); @@ -100,6 +102,9 @@ public TeamData(UUID teamId, BaseQuestFile file, String name) { completed = new Long2LongOpenHashMap(); completed.defaultReturnValue(0L); perPlayerData = new Object2ObjectOpenHashMap<>(); + areDependenciesCompleteCache = new Long2ByteOpenHashMap(); + areDependenciesVisibleCache = new Long2ByteOpenHashMap(); + unclaimedRewardsCache = new Object2ByteOpenHashMap<>(); } public UUID getTeamId() { @@ -257,14 +262,8 @@ public boolean isRewardClaimed(UUID player, Reward reward) { } public boolean hasUnclaimedRewards(UUID player, QuestObject object) { - if (unclaimedRewardsCache == null) { - unclaimedRewardsCache = new Object2ByteOpenHashMap<>(); - unclaimedRewardsCache.defaultReturnValue(BOOL_UNKNOWN); - } - QuestKey key = QuestKey.create(player, object.id); - byte b = unclaimedRewardsCache.getByte(key); - + byte b = unclaimedRewardsCache.getOrDefault(key, BOOL_UNKNOWN); if (b == BOOL_UNKNOWN) { b = object.hasUnclaimedRewardsRaw(this, player) ? BOOL_TRUE : BOOL_FALSE; unclaimedRewardsCache.put(key, b); @@ -320,8 +319,9 @@ public boolean resetReward(UUID player, Reward reward) { } public void clearCachedProgress() { - areDependenciesCompleteCache = null; - unclaimedRewardsCache = null; + areDependenciesCompleteCache.clear(); + areDependenciesVisibleCache.clear(); + unclaimedRewardsCache.clear(); } public SNBTCompoundTag serializeNBT() { @@ -524,25 +524,28 @@ public boolean isCompleted(QuestObject object) { return completed.containsKey(object.id); } - public boolean areDependenciesComplete(Quest quest) { + private boolean checkDepsCached(Quest quest, Long2ByteOpenHashMap cache, ToBooleanBiFunction checker) { if (!quest.hasDependencies()) { return true; } - if (areDependenciesCompleteCache == null) { - areDependenciesCompleteCache = new Long2ByteOpenHashMap(); - areDependenciesCompleteCache.defaultReturnValue(BOOL_UNKNOWN); - } - - byte res = areDependenciesCompleteCache.get(quest.id); + byte res = cache.getOrDefault(quest.id, BOOL_UNKNOWN); if (res == BOOL_UNKNOWN) { - res = quest.areDependenciesComplete(this) ? BOOL_TRUE : BOOL_FALSE; - areDependenciesCompleteCache.put(quest.id, res); + res = checker.applyAsBoolean(quest, this) ? BOOL_TRUE : BOOL_FALSE; + cache.put(quest.id, res); } return res == BOOL_TRUE; } + public boolean areDependenciesComplete(Quest quest) { + return checkDepsCached(quest, areDependenciesCompleteCache, Quest::areDependenciesComplete); + } + + public boolean areDependenciesVisible(Quest quest) { + return checkDepsCached(quest, areDependenciesVisibleCache, Quest::areDependenciesVisible); + } + public boolean canStartTasks(Quest quest) { return quest.getProgressionMode() == ProgressionMode.FLEXIBLE || areDependenciesComplete(quest); } diff --git a/common/src/main/resources/assets/ftbquests/lang/en_us.json b/common/src/main/resources/assets/ftbquests/lang/en_us.json index 1b5e779fa..4a18e40f8 100644 --- a/common/src/main/resources/assets/ftbquests/lang/en_us.json +++ b/common/src/main/resources/assets/ftbquests/lang/en_us.json @@ -152,6 +152,7 @@ "ftbquests.chapter.image.corner": "Rotate and offset from corner", "ftbquests.chapter.appearance.default_min_width": "Default Min Opened Quest Window Width", "ftbquests.chapter.visibility.hide_quest_details_until_startable": "Hide Quest Details Until Startable", + "ftbquests.chapter.visibility.hide_quest_until_deps_complete": "Hide Quests Until Dependencies Complete", "ftbquests.chapter.visibility.hide_quest_until_deps_visible": "Hide Quests Until Dependencies Visible", "ftbquests.quest": "Quest", "ftbquests.quests": "Quests", @@ -170,7 +171,8 @@ "ftbquests.quest.appearance.size.tooltip": "0 means to use chapter default", "ftbquests.quest.appearance.icon_scale": "Icon Scaling", "ftbquests.quest.appearance.icon_scale.tooltip": "Independent of the overall button size", - "ftbquests.quest.visibility.hide": "Hide Quest Until Dependencies are Visible", + "ftbquests.quest.visibility.hide_until_deps_complete": "Hide Quest Until Dependencies Complete", + "ftbquests.quest.visibility.hide_until_deps_visible": "Hide Quest Until Dependencies Visible", "ftbquests.quest.appearance.shape": "Shape", "ftbquests.quest_link.shape": "Shape", "ftbquests.quest_link.size": "Size", @@ -203,6 +205,7 @@ "ftbquests.quest.dependencies.min_required_dependencies": "Min Required Dependencies", "ftbquests.quest.min_required_dependencies.tooltip": "If you set this to anything more than 0, it becomes an OR quest, where only certain amount of dependencies is required for it to unlock", "ftbquests.quest.visibility.hide_text_until_complete": "Hide Text Until Quest is Completed", + "ftbquests.quest.visibility.hide_text_until_complete.tooltip": "Quest details can be opened, but no description text is displayed until the quest is completed", "ftbquests.quest.misc.disable_jei": "Disable JEI Recipe", "ftbquests.quest.misc.optional": "Optional Quest", "ftbquests.quest.locked": "Locked: uncompleted dependencies", From b23a74a4f884f7da4d8186f15379e423ad42967d Mon Sep 17 00:00:00 2001 From: Des Herriott Date: Fri, 16 Aug 2024 13:52:20 +0100 Subject: [PATCH 6/9] build: version -> 2101.1.0, changelog updated --- CHANGELOG.md | 13 +++++++++++++ gradle.properties | 4 ++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9d9f5d0e3..20c525cf3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,19 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +# [2101.1.0] + +### Changed +* Minecraft 1.21.1 is now required; this no longer supports Minecraft 1.21 + +### Added +* Sidebar buttons for this and other FTB mods can now be enabled/disabled/rearranged (new functionality in FTB Library 2101.1.0) + +### Fixed +* Fixed "Hide Quests until Dependencies Visible" setting actually checking for dependencies being _complete_ + * Added new "Hide Quests until Dependencies Complete" setting + * So there are now two independent setting for hiding quests based on dependency visibility and/or completion + # [2100.1.5] ### Changed diff --git a/gradle.properties b/gradle.properties index ca411d351..1837b34dd 100644 --- a/gradle.properties +++ b/gradle.properties @@ -23,8 +23,8 @@ fabric_api_version=0.100.8+1.21 fabric_api_version_range=>=0.100.1+1.21 architectury_api_version=13.0.6 -ftb_library_version=2101.1.0-SNAPSHOT -ftb_teams_version=2101.1.0-SNAPSHOT +ftb_library_version=2101.1.1 +ftb_teams_version=2101.1.0 # Optional deps teamreborn_energy_version=4.1.0 From ffd3a447f2526d0de6d21b41f1c6a8e8f96db609 Mon Sep 17 00:00:00 2001 From: Des Herriott Date: Fri, 16 Aug 2024 15:02:56 +0100 Subject: [PATCH 7/9] feat: added a few more command substitutions Also re-did the templating algorithm; should be more performant as the number of overrides increases https://github.com/FTBTeam/FTB-Mods-Issues/issues/1311 --- .../ftbquests/quest/reward/CommandReward.java | 47 ++++++++++++++----- 1 file changed, 36 insertions(+), 11 deletions(-) diff --git a/common/src/main/java/dev/ftb/mods/ftbquests/quest/reward/CommandReward.java b/common/src/main/java/dev/ftb/mods/ftbquests/quest/reward/CommandReward.java index 60ef2ac81..0d8c9eb56 100644 --- a/common/src/main/java/dev/ftb/mods/ftbquests/quest/reward/CommandReward.java +++ b/common/src/main/java/dev/ftb/mods/ftbquests/quest/reward/CommandReward.java @@ -15,11 +15,16 @@ import net.minecraft.network.chat.MutableComponent; import net.minecraft.server.level.ServerPlayer; +import java.util.ArrayList; import java.util.HashMap; +import java.util.List; import java.util.Map; +import java.util.regex.Matcher; +import java.util.regex.Pattern; public class CommandReward extends Reward { private static final String DEFAULT_COMMAND = "/say Hi, @p!"; + public static final Pattern PATTERN = Pattern.compile("[{](\\w+)}"); private String command; private boolean elevatePerms; @@ -93,17 +98,15 @@ public void claim(ServerPlayer player, boolean notify) { } overrides.put("quest", quest); - overrides.put("team", FTBTeamsAPI.api().getManager().getTeamForPlayer(player) - .map(team -> team.getName().getString()) - .orElse(player.getGameProfile().getName()) - ); - - String cmd = command; - for (Map.Entry entry : overrides.entrySet()) { - if (entry.getValue() != null) { - cmd = cmd.replace("{" + entry.getKey() + "}", entry.getValue().toString()); - } - } + FTBTeamsAPI.api().getManager().getTeamForPlayer(player).ifPresent(team -> { + overrides.put("team", team.getName().getString()); + overrides.put("team_id", team.getShortName()); + overrides.put("long_team_id", team.getId().toString()); + overrides.put("member_count", team.getMembers().size()); + overrides.put("online_member_count", team.getOnlineMembers().size()); + }); + + String cmd = format(command, overrides); CommandSourceStack source = player.createCommandSourceStack(); if (elevatePerms) source = source.withPermission(2); @@ -117,4 +120,26 @@ public void claim(ServerPlayer player, boolean notify) { public MutableComponent getAltTitle() { return Component.translatable("ftbquests.reward.ftbquests.command").append(": ").append(Component.literal(command).withStyle(ChatFormatting.RED)); } + + public static String format(String template, Map parameters) { + StringBuilder newTemplate = new StringBuilder(template); + List valueList = new ArrayList<>(); + + Matcher matcher = PATTERN.matcher(template); + + while (matcher.find()) { + String key = matcher.group(1); + + if (parameters.containsKey(key)) { + String paramName = "{" + key + "}"; + int index = newTemplate.indexOf(paramName); + if (index != -1) { + newTemplate.replace(index, index + paramName.length(), "%s"); + valueList.add(parameters.get(key)); + } + } + } + + return String.format(newTemplate.toString(), valueList.toArray()); + } } From 1edcf81ad74fd9611a54b6dc2b53495ce0ee7812 Mon Sep 17 00:00:00 2001 From: Des Herriott Date: Fri, 16 Aug 2024 15:08:30 +0100 Subject: [PATCH 8/9] feat: added a few more command substitutions Also re-did the templating algorithm; should be more performant as the number of overrides increases https://github.com/FTBTeam/FTB-Mods-Issues/issues/1311 --- .../java/dev/ftb/mods/ftbquests/quest/reward/CommandReward.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/src/main/java/dev/ftb/mods/ftbquests/quest/reward/CommandReward.java b/common/src/main/java/dev/ftb/mods/ftbquests/quest/reward/CommandReward.java index 0d8c9eb56..e9db2f621 100644 --- a/common/src/main/java/dev/ftb/mods/ftbquests/quest/reward/CommandReward.java +++ b/common/src/main/java/dev/ftb/mods/ftbquests/quest/reward/CommandReward.java @@ -86,7 +86,7 @@ public void fillConfigGroup(ConfigGroup config) { @Override public void claim(ServerPlayer player, boolean notify) { Map overrides = new HashMap<>(); -// overrides.put("p", player.getGameProfile().getName()); + overrides.put("p", player.getGameProfile().getName()); BlockPos pos = player.blockPosition(); overrides.put("x", pos.getX()); From bbe681e5212a7632803d3e491df0b48232b5c398 Mon Sep 17 00:00:00 2001 From: Des Herriott Date: Fri, 16 Aug 2024 15:08:56 +0100 Subject: [PATCH 9/9] chore: changelog updated --- CHANGELOG.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 20c525cf3..4e93e33c9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added * Sidebar buttons for this and other FTB mods can now be enabled/disabled/rearranged (new functionality in FTB Library 2101.1.0) +* A few new template substitutions are available in command rewards + * `{team_id}` - the short team name, e.g. "Dev#380df991" + * `{long_team_id}` - the full team UUID, e.g. "380df991-f603-344c-a090-369bad2a924a" + * `{member_count}` - the number of players in the team + * `{online_member_count}` - the number of currently-online players in the team ### Fixed * Fixed "Hide Quests until Dependencies Visible" setting actually checking for dependencies being _complete_