Skip to content

Commit

Permalink
Merge pull request #744 from FTBTeam/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
desht authored Jul 18, 2024
2 parents 00bd6f2 + 44998fd commit 706940d
Show file tree
Hide file tree
Showing 11 changed files with 46 additions and 26 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,16 @@ 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).

# [2100.1.4]

### Fixed
* Fixed coloured text in quest titles & subtitles not showing in the quest view panel
* Command rewards now support a {team} substitution in the executed command, which is replaced with the player's short team name
* The command setting in the reward properties screen now has a tooltip listing all available substitutions
* Filenames for new chapters are now all named after the chapter title, as intended
* Pre-existing chapter files may be named after the hex chapter id; they will still work fine, but you can rename them if you wish
* If you choose to rename them, also update the `filename` field in the file correspondingly

# [2100.1.3]

### Fixed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ public void onClicked(MouseButton button) {
chapterPanel.questScreen.openGui();

if (accepted && !c.getValue().isEmpty()) {
Chapter chapter = new Chapter(0L, file, file.getDefaultChapterGroup());
Chapter chapter = new Chapter(0L, file, file.getDefaultChapterGroup(), Chapter.titleToID( c.getValue()).orElse(""));
CompoundTag extra = Util.make(new CompoundTag(), t -> t.putLong("group", 0L));
file.getTranslationManager().addInitialTranslation(extra, file.getLocale(), TranslationKey.TITLE, c.getValue());
NetworkManager.sendToServer(CreateObjectMessage.create(chapter, extra));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@
import dev.ftb.mods.ftbquests.quest.reward.RewardType;
import dev.ftb.mods.ftbquests.quest.reward.RewardTypes;
import dev.ftb.mods.ftbquests.quest.theme.property.ThemeProperties;
import dev.ftb.mods.ftbquests.util.TextUtils;
import net.minecraft.ChatFormatting;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.contents.PlainTextContents;
import net.minecraft.world.entity.player.Player;

import java.util.ArrayList;
Expand Down Expand Up @@ -305,8 +305,8 @@ public void addMouseOverText(TooltipList list) {

Component description = quest.getSubtitle();

if (description.getContents() != PlainTextContents.EMPTY) {
list.add(Component.literal("").append(description).withStyle(ChatFormatting.GRAY));
if (!TextUtils.isComponentEmpty(description)) {
list.add(description.copy().withStyle(ChatFormatting.GRAY));
}

if (quest.isOptional()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@
import dev.ftb.mods.ftbquests.quest.task.ItemTask;
import dev.ftb.mods.ftbquests.quest.task.Task;
import dev.ftb.mods.ftbquests.quest.theme.property.ThemeProperties;
import dev.ftb.mods.ftbquests.util.TextUtils;
import net.minecraft.ChatFormatting;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.MutableComponent;
import net.minecraft.network.chat.contents.PlainTextContents;
import net.minecraft.tags.TagKey;
import net.minecraft.world.item.Item;

Expand Down Expand Up @@ -181,14 +181,13 @@ public void draw(GuiGraphics graphics, Theme theme, int x, int y, int w, int h)
ThemeProperties.CHECK_ICON.get().draw(graphics, x + w - 9, y + 1, 8, 8);
poseStack.popPose();
} else {
MutableComponent s = task.getButtonText();

if (s.getContents() != PlainTextContents.EMPTY) {
MutableComponent buttonText = task.getButtonText();
if (!TextUtils.isComponentEmpty(buttonText)) {
poseStack.pushPose();
poseStack.translate(x + 19F - theme.getStringWidth(s) / 2F, y + 15F, 200F);
poseStack.translate(x + 19F - theme.getStringWidth(buttonText) / 2F, y + 15F, 200F);
poseStack.scale(0.5F, 0.5F, 1F);
RenderSystem.enableBlend();
theme.drawString(graphics, s, 0, 0, Color4I.WHITE, Theme.SHADOW);
theme.drawString(graphics, buttonText, 0, 0, Color4I.WHITE, Theme.SHADOW);
poseStack.popPose();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import dev.ftb.mods.ftbquests.quest.theme.QuestTheme;
import dev.ftb.mods.ftbquests.quest.theme.property.ThemeProperties;
import dev.ftb.mods.ftbquests.quest.translation.TranslationKey;
import dev.ftb.mods.ftbquests.util.TextUtils;
import it.unimi.dsi.fastutil.longs.Long2IntMap;
import it.unimi.dsi.fastutil.longs.Long2IntOpenHashMap;
import net.minecraft.ChatFormatting;
Expand All @@ -44,7 +45,6 @@
import net.minecraft.client.gui.screens.ConfirmLinkScreen;
import net.minecraft.client.gui.screens.Screen;
import net.minecraft.network.chat.*;
import net.minecraft.network.chat.contents.PlainTextContents;
import net.minecraft.util.Mth;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.Items;
Expand Down Expand Up @@ -157,7 +157,7 @@ public void addWidgets() {
titleField = new QuestDescriptionField(this, canEdit, TranslationKey.TITLE, (b, clickedW) -> editTitle())
.addFlags(Theme.CENTERED)
.setMinWidth(150).setMaxWidth(500).setSpacing(9)
.setText(quest.getTitle().copy().withStyle(Style.EMPTY.withColor(TextColor.fromRgb(ThemeProperties.QUEST_VIEW_TITLE.get().rgb()))));
.setText(Component.empty().withColor(ThemeProperties.QUEST_VIEW_TITLE.get().rgb()).append(quest.getTitle()));
int w = Math.max(200, titleField.width + 54);

if (quest.getMinWidth() > 0) {
Expand Down Expand Up @@ -342,16 +342,16 @@ public TextField resize(Theme theme) {

Component subtitle = quest.getSubtitle();

if (subtitle.getContents() == PlainTextContents.EMPTY && canEdit) {
if (TextUtils.isComponentEmpty(subtitle) && canEdit) {
subtitle = Component.literal("[No Subtitle]");
}

if (!subtitle.equals(Component.empty())) {
if (!TextUtils.isComponentEmpty(subtitle)) {
panelText.add(new QuestDescriptionField(panelText, canEdit, TranslationKey.QUEST_SUBTITLE, (b, clickedW) -> editSubtitle())
.addFlags(Theme.CENTERED)
.setMinWidth(panelText.width).setMaxWidth(panelText.width)
.setSpacing(9)
.setText(subtitle.copy().withStyle(ChatFormatting.ITALIC, ChatFormatting.GRAY)));
.setText(Component.empty().withStyle(ChatFormatting.ITALIC,ChatFormatting.GRAY).append(subtitle)));
}

boolean showText = !quest.getHideTextUntilComplete().get(false) || questScreen.file.selfTeamData != null && questScreen.file.selfTeamData.isCompleted(quest);
Expand All @@ -363,7 +363,7 @@ public TextField resize(Theme theme) {
addDescriptionText(canEdit, subtitle);
}
if (!quest.getGuidePage().isEmpty()) {
if (subtitle.getContents() != PlainTextContents.EMPTY) {
if (!TextUtils.isComponentEmpty(subtitle)) {
panelText.add(new VerticalSpaceWidget(panelText, 7));
}
panelText.add(new OpenInGuideButton(panelText, quest));
Expand Down Expand Up @@ -397,7 +397,7 @@ public TextField resize(Theme theme) {

private void addDescriptionText(boolean canEdit, Component subtitle) {
Pair<Integer,Integer> pageSpan = pageIndices.get(getCurrentPage());
if (subtitle.getContents() != PlainTextContents.EMPTY) {
if (!TextUtils.isComponentEmpty(subtitle)) {
panelText.add(new VerticalSpaceWidget(panelText, 7));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import dev.ftb.mods.ftblibrary.icon.ItemIcon;
import dev.ftb.mods.ftblibrary.util.KnownServerRegistries;
import dev.ftb.mods.ftbquests.quest.Quest;
import dev.ftb.mods.ftbquests.util.TextUtils;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.ChatFormatting;
Expand All @@ -14,7 +15,6 @@
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.RegistryFriendlyByteBuf;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.contents.PlainTextContents;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.level.ServerPlayer;

Expand Down Expand Up @@ -102,7 +102,7 @@ public Component getAltTitle() {
null :
KnownServerRegistries.client.advancements().get(advancement);

if (info != null && info.name().getContents() != PlainTextContents.EMPTY) {
if (info != null && !TextUtils.isComponentEmpty(info.name())) {
return Component.translatable("ftbquests.reward.ftbquests.advancement").append(": ").append(info.name().copy().withStyle(ChatFormatting.YELLOW));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import dev.ftb.mods.ftblibrary.config.ConfigGroup;
import dev.ftb.mods.ftbquests.quest.Quest;
import dev.ftb.mods.ftbteams.api.FTBTeamsAPI;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.ChatFormatting;
Expand All @@ -18,13 +19,15 @@
import java.util.Map;

public class CommandReward extends Reward {
private static final String DEFAULT_COMMAND = "/say Hi, @p!";

private String command;
private boolean elevatePerms;
private boolean silent;

public CommandReward(long id, Quest quest) {
super(id, quest);
command = "/say Hi, @p!";
command = DEFAULT_COMMAND;
}

@Override
Expand Down Expand Up @@ -70,7 +73,7 @@ public void readNetData(RegistryFriendlyByteBuf buffer) {
@Environment(EnvType.CLIENT)
public void fillConfigGroup(ConfigGroup config) {
super.fillConfigGroup(config);
config.addString("command", command, v -> command = v, "/say Hi, @team!").setNameKey("ftbquests.reward.ftbquests.command");
config.addString("command", command, v -> command = v, DEFAULT_COMMAND).setNameKey("ftbquests.reward.ftbquests.command");
config.addBool("elevate", elevatePerms, v -> elevatePerms = v, false);
config.addBool("silent", silent, v -> silent = v, false);
}
Expand All @@ -90,6 +93,10 @@ 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<String, Object> entry : overrides.entrySet()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import dev.ftb.mods.ftblibrary.util.KnownServerRegistries;
import dev.ftb.mods.ftbquests.quest.Quest;
import dev.ftb.mods.ftbquests.quest.TeamData;
import dev.ftb.mods.ftbquests.util.TextUtils;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.ChatFormatting;
Expand All @@ -17,7 +18,6 @@
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.RegistryFriendlyByteBuf;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.contents.PlainTextContents;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.level.ServerPlayer;

Expand Down Expand Up @@ -89,7 +89,7 @@ public Component getAltTitle() {
null :
KnownServerRegistries.client.advancements().get(advancement);

if (info != null && info.name().getContents() != PlainTextContents.EMPTY) {
if (info != null && !TextUtils.isComponentEmpty(info.name())) {
return Component.translatable("ftbquests.task.ftbquests.advancement").append(": ").append(Component.literal("").append(info.name()).withStyle(ChatFormatting.YELLOW));
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
package dev.ftb.mods.ftbquests.util;

import com.google.gson.JsonParseException;
import com.google.gson.JsonParser;
import dev.ftb.mods.ftblibrary.util.client.ClientTextComponentUtils;
import net.minecraft.ChatFormatting;
import net.minecraft.core.HolderLookup;
import net.minecraft.nbt.ListTag;
import net.minecraft.nbt.Tag;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.MutableComponent;
import net.minecraft.network.chat.contents.PlainTextContents;

import java.util.ArrayList;
import java.util.List;
Expand Down Expand Up @@ -46,4 +45,8 @@ public static List<String> fromListTag(ListTag tag) {
});
return res;
}

public static boolean isComponentEmpty(Component c) {
return c.getSiblings().isEmpty() && c.getContents() == PlainTextContents.EMPTY;
}
}
1 change: 1 addition & 0 deletions common/src/main/resources/assets/ftbquests/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,7 @@
"ftbquests.reward.ftbquests.xp": "XP",
"ftbquests.reward.ftbquests.xp_levels": "XP Levels",
"ftbquests.reward.ftbquests.command": "Command",
"ftbquests.reward.ftbquests.command.tooltip": "Vanilla substitutions, e.g. @p, are supported\nSpecial substitutions:\n{x} / {y} / {z} - player's current X/Y/Z pos\n{quest} - ID of this quest\n{chapter} - ID of this chapter\n{team} - short name of player's team",
"ftbquests.reward.ftbquests.command.elevate": "Run with Elevated Permission",
"ftbquests.reward.ftbquests.command.elevate.tooltip": "Run the command as if the player had permission level 2",
"ftbquests.reward.ftbquests.command.silent": "Silent",
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ maven_group=dev.ftb.mods
mod_author=FTB Team

# Build time
mod_version=2100.1.3
mod_version=2100.1.4
minecraft_version=1.21


Expand Down

0 comments on commit 706940d

Please sign in to comment.