Skip to content

Commit

Permalink
Merge pull request #694 from FTBTeam/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
desht authored Sep 20, 2023
2 parents 3f69270 + 8ba5b74 commit 076155f
Show file tree
Hide file tree
Showing 11 changed files with 137 additions and 4 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [2001.1.4]

### Added
* Command rewards now have a "Silent" boolean property; when true, any command output (success or failure) is suppressed
* Added a `/ftbquests open_book <id>` command to open the book to a specific quest, quest link, chapter or task
* When moving images on the quest screen, scaled-up images are always treated as if they were size 1.0
* Otherwise, scaled images have a huge snap jump, making them difficult to position neatly
* Note also that holding Shift while moving images and quests disables grid snap completely
* Added "Pause SSP Game" option to "Edit File" config screen (default false)
* Game will pause when in quest screen in single-player mode (although not while in edit mode config screens)

### Fixed
* Fixed client crash while logging in under certain circumstances (related to tooltip generation for Quest Barrier block item)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import dev.ftb.mods.ftbquests.net.DeleteObjectMessage;
import dev.ftb.mods.ftbquests.quest.BaseQuestFile;
import dev.ftb.mods.ftbquests.quest.Quest;
import dev.ftb.mods.ftbquests.quest.QuestObject;
import dev.ftb.mods.ftbquests.quest.TeamData;
import dev.ftb.mods.ftbquests.quest.task.StructureTask;
import dev.ftb.mods.ftbquests.quest.theme.QuestTheme;
Expand Down Expand Up @@ -194,4 +195,23 @@ public void setEditorPermission(boolean hasPermission) {
public boolean hasEditorPermission() {
return editorPermission;
}

public static void openBookToQuestObject(long id) {
if (exists()) {
ClientQuestFile file = ClientQuestFile.INSTANCE;
if (file.questScreen == null) {
ClientQuestFile.INSTANCE.openQuestGui();
}
if (file.questScreen != null) {
if (id != 0L) {
QuestObject qo = file.get(id);
if (qo != null) {
file.questScreen.open(qo, true);
}
} else {
file.questScreen.openGui();
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -311,8 +311,9 @@ public void draw(GuiGraphics graphics, Theme theme, int x, int y, int w, int h)
questY = qy;
} else {
// grid-snapping size is based on the smallest selected item
// although images always act as if they were size 1
double minSize = questScreen.selectedObjects.stream()
.map(Movable::getWidth)
.map(m -> m instanceof ChapterImage ? 1d : m.getWidth())
.min(Double::compare)
.orElse(1d);
double snap = 1D / (questScreen.file.getGridScale() * minSize);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import dev.ftb.mods.ftblibrary.util.TooltipList;
import dev.ftb.mods.ftblibrary.util.client.PositionedIngredient;
import dev.ftb.mods.ftbquests.FTBQuests;
import dev.ftb.mods.ftbquests.client.ClientQuestFile;
import dev.ftb.mods.ftbquests.client.gui.FTBQuestsTheme;
import dev.ftb.mods.ftbquests.net.SubmitTaskMessage;
import dev.ftb.mods.ftbquests.quest.task.ItemTask;
Expand Down Expand Up @@ -128,6 +129,11 @@ public boolean keyPressed(Key key) {
return false;
}

@Override
public boolean doesGuiPauseGame() {
return ClientQuestFile.exists() && ClientQuestFile.INSTANCE.isPauseGame();
}

@Override
public boolean onClosedByKey(Key key) {
if (super.onClosedByKey(key)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@
import dev.ftb.mods.ftbquests.FTBQuests;
import dev.ftb.mods.ftbquests.integration.PermissionsHelper;
import dev.ftb.mods.ftbquests.net.CreateObjectResponseMessage;
import dev.ftb.mods.ftbquests.net.OpenQuestBookMessage;
import dev.ftb.mods.ftbquests.net.SyncEditorPermissionMessage;
import dev.ftb.mods.ftbquests.net.SyncQuestsMessage;
import dev.ftb.mods.ftbquests.quest.*;
import dev.ftb.mods.ftbquests.quest.loot.RewardTable;
import dev.ftb.mods.ftbquests.quest.loot.WeightedReward;
import dev.ftb.mods.ftbquests.quest.reward.ItemReward;
import dev.ftb.mods.ftbquests.quest.task.ItemTask;
import dev.ftb.mods.ftbquests.quest.task.Task;
import dev.ftb.mods.ftbquests.util.ProgressChange;
import net.minecraft.ChatFormatting;
import net.minecraft.Util;
Expand Down Expand Up @@ -153,6 +155,11 @@ public static void register(CommandDispatcher<CommandSourceStack> dispatcher) {
)
)
)
.then(Commands.literal("open_book")
.executes(c -> openQuest(c.getSource().getPlayerOrException(), null))
.then(Commands.argument("quest_object", QuestObjectArgument.questObject(qob -> qob instanceof QuestObject))
.executes(c -> openQuest(c.getSource().getPlayerOrException(), c.getArgument("quest_object", QuestObjectBase.class))))
)
);
}

Expand All @@ -162,6 +169,34 @@ private static boolean hasEditorPermission(CommandSourceStack stack) {
|| stack.isPlayer() && PermissionsHelper.hasEditorPermission(stack.getPlayer(), false);
}

private static int openQuest(ServerPlayer player, QuestObjectBase qob) {
if (qob == null) {
// just open the book to wherever it last was
new OpenQuestBookMessage(0L).sendTo(player);
} else if (qob instanceof QuestObject quest) {
if (canSeeQuestObject(player, quest)) {
new OpenQuestBookMessage(quest.id).sendTo(player);
}
}
return 1;
}

private static boolean canSeeQuestObject(ServerPlayer player, QuestObject qo) {
if (qo instanceof Chapter) {
return true;
}
TeamData data = TeamData.get(player);
Quest quest = null;
if (qo instanceof QuestLink link) {
quest = link.getQuest().orElse(null);
} else if (qo instanceof Task task) {
quest = task.getQuest();
} else if (qo instanceof Quest q) {
quest = q;
}
return quest != null && (data.getCanEdit(player) || !quest.hideDetailsUntilStartable() || data.canStartTasks(quest));
}

private static int exportRewards(CommandSourceStack source, RewardTable table, BlockPos pos) throws CommandSyntaxException {
ServerPlayer player = source.getPlayerOrException();
ServerLevel level = source.getLevel();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.util.Collection;
import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.function.Predicate;

public class QuestObjectArgument implements ArgumentType<QuestObjectBase> {

Expand All @@ -37,6 +38,16 @@ public class QuestObjectArgument implements ArgumentType<QuestObjectBase> {
public static final DynamicCommandExceptionType INVALID_ID = new DynamicCommandExceptionType(
(id) -> Component.translatable("commands.ftbquests.command.error.invalid_id", id));

private final Predicate<QuestObjectBase> filter;

public QuestObjectArgument() {
this(qo -> true);
}

public QuestObjectArgument(Predicate<QuestObjectBase> filter) {
this.filter = filter;
}

@Override
public QuestObjectBase parse(StringReader reader) throws CommandSyntaxException {
String id = reader.readString();
Expand All @@ -45,7 +56,7 @@ public QuestObjectBase parse(StringReader reader) throws CommandSyntaxException
if (id.startsWith("#")) {
String val = id.substring(1);
for (QuestObjectBase object : file.getAllObjects()) {
if (object.hasTag(val)) {
if (object.hasTag(val) && filter.test(object)) {
return object;
}
}
Expand All @@ -54,7 +65,7 @@ public QuestObjectBase parse(StringReader reader) throws CommandSyntaxException
try {
long num = file.getID(id);
QuestObjectBase object = file.getBase(num);
if (object == null) {
if (object == null || !filter.test(object)) {
throw NO_OBJECT.createWithContext(reader, id);
}
return object;
Expand All @@ -73,6 +84,7 @@ public <S> CompletableFuture<Suggestions> listSuggestions(CommandContext<S> cont
return SharedSuggestionProvider.suggest(
file.getAllObjects()
.stream()
.filter(filter)
.map(BaseQuestFile::getCodeString),
builder
);
Expand All @@ -89,6 +101,10 @@ public static QuestObjectArgument questObject() {
return new QuestObjectArgument();
}

public static QuestObjectArgument questObject(Predicate<QuestObjectBase> filter) {
return new QuestObjectArgument(filter);
}

@Nullable
private static BaseQuestFile findQuestFile() {
if (!QuestObjectBase.isNull(ServerQuestFile.INSTANCE)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ public interface FTBQuestsNetHandler {
MessageType SYNC_STRUCTURES_RESPONSE = NET.registerS2C("sync_structures_response", SyncStructuresResponseMessage::new);
MessageType REQUEST_TEAM_DATA = NET.registerC2S("request_team_data", RequestTeamDataMessage::new);
MessageType SYNC_EDITOR_PERMISSION = NET.registerS2C("sync_editor_permission", SyncEditorPermissionMessage::new);
MessageType OPEN_QUEST_BOOK = NET.registerS2C("open_quest_book", OpenQuestBookMessage::new);

static void init() {
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package dev.ftb.mods.ftbquests.net;

import dev.architectury.networking.NetworkManager;
import dev.architectury.networking.simple.BaseS2CMessage;
import dev.architectury.networking.simple.MessageType;
import dev.ftb.mods.ftbquests.client.ClientQuestFile;
import net.minecraft.network.FriendlyByteBuf;

public class OpenQuestBookMessage extends BaseS2CMessage {
private final long id;

public OpenQuestBookMessage(long id) {
this.id = id;
}

OpenQuestBookMessage(FriendlyByteBuf buf) {
id = buf.readLong();
}

@Override
public MessageType getType() {
return FTBQuestsNetHandler.OPEN_QUEST_BOOK;
}

@Override
public void write(FriendlyByteBuf buf) {
buf.writeLong(id);
}

@Override
public void handle(NetworkManager.PacketContext context) {
ClientQuestFile.openBookToQuestObject(id);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1037,6 +1037,7 @@ public void fillConfigGroup(ConfigGroup config) {
config.addString("lock_message", lockMessage, v -> lockMessage = v, "");
config.addEnum("progression_mode", progressionMode, v -> progressionMode = v, ProgressionMode.NAME_MAP_NO_DEFAULT);
config.addInt("detection_delay", detectionDelay, v -> detectionDelay = v, 20, 0, 200);
config.addBool("pause_game", pauseGame, v -> pauseGame = v, false);

ConfigGroup defaultsGroup = config.getOrCreateSubgroup("defaults");
defaultsGroup.addBool("reward_team", defaultPerTeamReward, v -> defaultPerTeamReward = v, false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
public class CommandReward extends Reward {
private String command;
private boolean elevatePerms;
private boolean silent;

public CommandReward(long id, Quest quest) {
super(id, quest);
Expand All @@ -37,27 +38,31 @@ public void writeData(CompoundTag nbt) {
if (elevatePerms) {
nbt.putBoolean("elevate_perms", true);
}
if (silent) nbt.putBoolean("silent", true);
}

@Override
public void readData(CompoundTag nbt) {
super.readData(nbt);
command = nbt.getString("command");
elevatePerms = nbt.getBoolean("elevate_perms");
silent = nbt.getBoolean("silent");
}

@Override
public void writeNetData(FriendlyByteBuf buffer) {
super.writeNetData(buffer);
buffer.writeUtf(command, Short.MAX_VALUE);
buffer.writeBoolean(elevatePerms);
buffer.writeBoolean(silent);
}

@Override
public void readNetData(FriendlyByteBuf buffer) {
super.readNetData(buffer);
command = buffer.readUtf(Short.MAX_VALUE);
elevatePerms = buffer.readBoolean();
silent = buffer.readBoolean();
}

@Override
Expand All @@ -66,6 +71,7 @@ public void fillConfigGroup(ConfigGroup config) {
super.fillConfigGroup(config);
config.addString("command", command, v -> command = v, "/say Hi, @team!").setNameKey("ftbquests.reward.ftbquests.command");
config.addBool("elevate", elevatePerms, v -> elevatePerms = v, false);
config.addBool("silent", silent, v -> silent = v, false);
}

@Override
Expand Down Expand Up @@ -93,7 +99,8 @@ public void claim(ServerPlayer player, boolean notify) {

CommandSourceStack source = player.createCommandSourceStack();
if (elevatePerms) source = source.withPermission(2);

if (silent) source = source.withSuppressedOutput();

player.server.getCommands().performPrefixedCommand(source, cmd);
}

Expand Down
3 changes: 3 additions & 0 deletions common/src/main/resources/assets/ftbquests/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@
"ftbquests.file.grid_scale": "Grid Scale",
"ftbquests.file.lock_message": "Lock Message",
"ftbquests.file.progression_mode": "Progression Mode",
"ftbquests.file.pause_game": "Quest Screen Pauses SSP Game",
"ftbquests.file.pause_game.tooltip": "Does not apply to multiplayer games",
"ftbquests.file.detection_delay": "Item Auto-Detection Minimum Interval",
"ftbquests.file.detection_delay.tooltip": "Minimum interval (in ticks) between checks of a player's inventory when it changes\nHigher values are kinder on server TPS, especially if players inventories change frequently, but mean longer delays for quest auto-completion messages.",
"ftbquests.chapter.misc.progression_mode": "Default 'Progression Mode'",
Expand Down Expand Up @@ -416,6 +418,7 @@
"ftbquests.reward.ftbquests.command": "Command",
"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",
"ftbquests.reward.ftbquests.advancement": "Advancement",
"ftbquests.reward.ftbquests.advancement.criterion": "Criterion",
"ftbquests.reward.ftbquests.advancement.criterion.tooltip": "Optional, set if you want only one criterion to be granted",
Expand Down

0 comments on commit 076155f

Please sign in to comment.