Skip to content

Commit

Permalink
Merge pull request #710 from FTBTeam/1.20.1/dev
Browse files Browse the repository at this point in the history
1.20.1/dev
  • Loading branch information
desht authored Jan 19, 2024
2 parents fbaa087 + e6ce16c commit 36f78d4
Show file tree
Hide file tree
Showing 22 changed files with 182 additions and 93 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Java CI - Build on Push

on:
push:
branches: [ main, dev, "1.*" ]
branches: [ main, dev, "1.**" ]
workflow_dispatch:
inputs:
skip_maven_publish:
Expand Down
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,21 @@ 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).

## [2001.3.1]

### Added
* Added back support for the `{p}` expansion in command rewards
* Although `@p` and `@s` are the recommended ways to get the player name, `{p}` is once more supported as a workaround for mods/plugins which don't properly use vanilla command parsing
* Improved copy/paste keyboard behaviour a little
* Ctrl-C to copy now also works on images
* If no quests/images are selected, Ctrl-C will work to copy the hovered quest/image

### Fixed
* A quest in the first chapter set as Autofocused (feature added in 2001.2.1) wasn't being autofocused on initial opening of the quest book
* Hopefully mitigate a large amount of server lag (only noticeable in very big quest books) when an item is crafted (or manually smelted)
* Fixed the "Always Invisible" chapter property not being correctly observed when not in edit mode
* Fixed toggling editor mode not working in an SSP world which has been opened to LAN to enable cheats

## [2001.3.0]

### Changed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import dev.ftb.mods.ftblibrary.config.ui.EditConfigScreen;
import dev.ftb.mods.ftblibrary.config.ui.SelectFluidScreen;
import dev.ftb.mods.ftblibrary.config.ui.SelectItemStackScreen;
import dev.ftb.mods.ftblibrary.ui.Widget;
import dev.ftb.mods.ftblibrary.ui.input.MouseButton;
import dev.ftb.mods.ftbquests.FTBQuests;
import dev.ftb.mods.ftbquests.api.FTBQuestsAPI;
Expand All @@ -18,6 +19,8 @@
import dev.ftb.mods.ftbquests.item.FTBQuestsItems;
import dev.ftb.mods.ftbquests.net.SetCustomImageMessage;
import dev.ftb.mods.ftbquests.quest.BaseQuestFile;
import dev.ftb.mods.ftbquests.quest.Quest;
import dev.ftb.mods.ftbquests.quest.QuestObjectBase;
import dev.ftb.mods.ftbquests.quest.TeamData;
import dev.ftb.mods.ftbquests.quest.reward.ItemReward;
import dev.ftb.mods.ftbquests.quest.reward.RewardTypes;
Expand Down Expand Up @@ -293,4 +296,8 @@ public static void rebuildCreativeTabs() {
public static Optional<RegistryAccess> registryAccess() {
return Minecraft.getInstance().level == null ? Optional.empty() : Optional.of(Minecraft.getInstance().level.registryAccess());
}

public static void copyToClipboard(QuestObjectBase qo) {
Widget.setClipboardString(qo.getCodeString());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ public static void moveQuest(long id, long chapter, double x, double y) {

public static void syncEditingMode(UUID teamId, boolean editingMode) {
if (ClientQuestFile.INSTANCE.getOrCreateTeamData(teamId).setCanEdit(Minecraft.getInstance().player, editingMode)) {
setEditorPermission(editingMode);
ClientQuestFile.INSTANCE.refreshGui();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@
import java.util.Optional;

public class ChapterImageButton extends Button implements QuestPositionableButton, Comparable<ChapterImageButton> {
private static WeakReference<ChapterImage> clipboard = new WeakReference<>(null);

private final QuestScreen questScreen;
private final ChapterImage chapterImage;

Expand All @@ -39,13 +37,13 @@ public ChapterImageButton(Panel panel, ChapterImage i) {
chapterImage = i;
}

public static Optional<ChapterImage> getClipboard() {
ChapterImage img = clipboard.get();
public static Optional<ChapterImage> getClipboardImage() {
ChapterImage img = ChapterImage.clipboard.get();
if (img != null) {
if (img.getChapter().isValid()) {
return Optional.of(img);
} else {
clipboard = new WeakReference<>(null);
ChapterImage.clipboard = new WeakReference<>(null);
}
}
return Optional.empty();
Expand Down Expand Up @@ -81,18 +79,15 @@ public void onClicked(MouseButton button) {
new EditConfigScreen(group).openGui();
}));

contextMenu.add(new ContextMenuItem(Component.translatable("gui.move"), ThemeProperties.MOVE_UP_ICON.get(chapterImage.getChapter()), () -> {
questScreen.initiateMoving(chapterImage);
}) {
contextMenu.add(new ContextMenuItem(Component.translatable("gui.move"), ThemeProperties.MOVE_UP_ICON.get(chapterImage.getChapter()),
() -> questScreen.initiateMoving(chapterImage)) {
@Override
public void addMouseOverText(TooltipList list) {
list.add(Component.translatable("ftbquests.gui.move_tooltip").withStyle(ChatFormatting.DARK_GRAY));
}
});

contextMenu.add(new ContextMenuItem(Component.translatable("gui.copy"), Icons.INFO, () -> {
clipboard = new WeakReference<>(chapterImage);
}) {
contextMenu.add(new ContextMenuItem(Component.translatable("gui.copy"), Icons.INFO, chapterImage::copyToClipboard) {
@Override
public void addMouseOverText(TooltipList list) {
list.add(Component.literal(chapterImage.getImage().toString()).withStyle(ChatFormatting.DARK_GRAY));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.chat.Component;
import net.minecraft.util.Mth;
import org.apache.commons.lang3.mutable.MutableBoolean;
import org.jetbrains.annotations.Nullable;
import org.joml.Matrix4f;
import org.lwjgl.glfw.GLFW;
Expand Down Expand Up @@ -484,13 +483,11 @@ public boolean mousePressed(MouseButton button) {
contextMenu.add(new ContextMenuItem(Component.translatable("ftbquests.chapter.image"), Icons.ART, () -> showImageCreationScreen(qx, qy)));

String clip = getClipboardString();
MutableBoolean addedSeparator = new MutableBoolean(false);
if (!clip.isEmpty()) {
if (!ChapterImage.isImageInClipboard()) {
QuestObjectBase.parseHexId(clip).ifPresent(questId -> {
QuestObject qo = questScreen.file.get(questId);
contextMenu.add(ContextMenuItem.SEPARATOR);
if (qo instanceof Quest quest) {
contextMenu.add(ContextMenuItem.SEPARATOR);
addedSeparator.setTrue();
contextMenu.add(new PasteQuestMenuItem(quest, Component.translatable("ftbquests.gui.paste"),
Icons.ADD,
() -> new CopyQuestMessage(quest, questScreen.selectedChapter, qx, qy, true).sendToServer()));
Expand All @@ -507,19 +504,18 @@ public boolean mousePressed(MouseButton button) {
new CreateObjectMessage(link, new CompoundTag()).sendToServer();
}));
} else if (qo instanceof Task task) {
contextMenu.add(ContextMenuItem.SEPARATOR);
addedSeparator.setTrue();
contextMenu.add(new AddTaskButton.PasteTaskMenuItem(task, () -> copyAndCreateTask(task, qx, qy)));
}
});
} else {
ChapterImageButton.getClipboardImage().ifPresent(clipImg -> {
contextMenu.add(ContextMenuItem.SEPARATOR);
contextMenu.add(new TooltipContextMenuItem(Component.translatable("ftbquests.gui.paste_image"),
Icons.ADD,
() -> new CopyChapterImageMessage(clipImg, questScreen.selectedChapter, qx, qy).sendToServer(),
Component.literal(clipImg.getImage().toString()).withStyle(ChatFormatting.GRAY)));
});
}
ChapterImageButton.getClipboard().ifPresent(clipImg -> {
if (!addedSeparator.getValue()) contextMenu.add(ContextMenuItem.SEPARATOR);
contextMenu.add(new TooltipContextMenuItem(Component.translatable("ftbquests.gui.paste_image"),
Icons.ADD,
() -> new CopyChapterImageMessage(clipImg, questScreen.selectedChapter, qx, qy).sendToServer(),
Component.literal(clipImg.getImage().toString()).withStyle(ChatFormatting.GRAY)));
});

questScreen.openContextMenu(contextMenu);
return true;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package dev.ftb.mods.ftbquests.client.gui.quests;

import com.mojang.datafixers.util.Pair;
import dev.ftb.mods.ftblibrary.config.ConfigGroup;
import dev.ftb.mods.ftblibrary.config.ConfigValue;
import dev.ftb.mods.ftblibrary.config.ConfigWithVariants;
Expand All @@ -17,10 +18,7 @@
import dev.ftb.mods.ftbquests.client.gui.CustomToast;
import dev.ftb.mods.ftbquests.client.gui.FTBQuestsTheme;
import dev.ftb.mods.ftbquests.client.gui.SelectQuestObjectScreen;
import dev.ftb.mods.ftbquests.net.ChangeProgressMessage;
import dev.ftb.mods.ftbquests.net.CopyQuestMessage;
import dev.ftb.mods.ftbquests.net.CreateObjectMessage;
import dev.ftb.mods.ftbquests.net.EditObjectMessage;
import dev.ftb.mods.ftbquests.net.*;
import dev.ftb.mods.ftbquests.quest.*;
import dev.ftb.mods.ftbquests.quest.reward.RandomReward;
import dev.ftb.mods.ftbquests.quest.reward.Reward;
Expand Down Expand Up @@ -336,34 +334,51 @@ private boolean moveSelectedQuests(double x, double y) {
return true;
}

private boolean copySelectedQuests() {
Collection<Quest> quests = getSelectedQuests();
private boolean copyObjectsToClipboard() {
Movable toCopy = null;

if (quests.size() > 1) {
Minecraft.getInstance().getToasts().addToast(new CustomToast(Component.translatable("ftbquests.gui.error"), Icons.BARRIER, Component.translatable("ftbquests.quest.cannot_copy_many")));
return false;
}
for (Quest q : quests) {
setClipboardString(q.getCodeString());
Minecraft.getInstance().getToasts().addToast(new CustomToast(Component.translatable("ftbquests.quest.copied"), Icons.INFO, Component.literal(q.getTitle().getString())));
if (selectedObjects.size() > 1) {
displayError(Component.translatable("ftbquests.quest.cannot_copy_many"));
} else if (selectedObjects.isEmpty()) {
// no objects selected: copy hovered object if there is one
toCopy = questPanel.getWidgets().stream()
.filter(w -> w instanceof QuestPositionableButton && w.isMouseOver())
.map(w -> ((QuestPositionableButton) w).moveAndDeleteFocus())
.findFirst()
.orElse(null);
} else {
// one object selected
toCopy = selectedObjects.get(0);
}

return true;
}

private boolean pasteSelectedQuests(boolean withDeps) {
String clip = getClipboardString();
if (clip.isEmpty()) return false;
if (toCopy != null) {
toCopy.copyToClipboard();
Minecraft.getInstance().getToasts().addToast(new CustomToast(Component.translatable("ftbquests.quest.copied"),
Icons.INFO, Component.literal(toCopy.getTitle().getString())));
return true;
}

return QuestObjectBase.parseHexId(clip).map(id -> {
Quest quest = file.getQuest(id);
if (quest == null) return false;
return false;
}

double snap = 1D / file.getGridScale();
double qx = Mth.floor(questPanel.questX * snap + 0.5D) / snap;
double qy = Mth.floor(questPanel.questY * snap + 0.5D) / snap;
private boolean pasteSelectedQuest(boolean withDeps) {
if (ChapterImage.isImageInClipboard()) {
return pasteSelectedImage();
} else {
return QuestObjectBase.parseHexId(getClipboardString()).map(id -> {
Quest quest = file.getQuest(id);
if (quest == null) return false;
Pair<Double, Double> qxy = getSnappedXY();
new CopyQuestMessage(quest, selectedChapter, qxy.getFirst(), qxy.getSecond(), withDeps).sendToServer();
return true;
}).orElse(false);
}
}

new CopyQuestMessage(quest, selectedChapter, qx, qy, withDeps).sendToServer();
private boolean pasteSelectedImage() {
return ChapterImageButton.getClipboardImage().map(clipImg -> {
Pair<Double,Double> qxy = getSnappedXY();
new CopyChapterImageMessage(clipImg, selectedChapter, qxy.getFirst(), qxy.getSecond()).sendToServer();
return true;
}).orElse(false);
}
Expand All @@ -374,18 +389,21 @@ private boolean pasteSelectedQuestLinks() {

return QuestObjectBase.parseHexId(clip).map(id -> {
if (file.getQuest(id) == null) return false;

double snap = 1D / file.getGridScale();
double qx = Mth.floor(questPanel.questX * snap + 0.5D) / snap;
double qy = Mth.floor(questPanel.questY * snap + 0.5D) / snap;

Pair<Double,Double> qxy = getSnappedXY();
QuestLink link = new QuestLink(0L, selectedChapter, id);
link.setPosition(qx, qy);
link.setPosition(qxy.getFirst(), qxy.getSecond());
new CreateObjectMessage(link, new CompoundTag(), false).sendToServer();
return true;
}).orElse(false);
}

private Pair<Double,Double> getSnappedXY() {
double snap = 1D / file.getGridScale();
double qx = Mth.floor(questPanel.questX * snap + 0.5D) / snap;
double qy = Mth.floor(questPanel.questY * snap + 0.5D) / snap;
return Pair.of(qx,qy);
}

void deleteSelectedObjects() {
selectedObjects.forEach(movable -> {
if (movable instanceof Quest q) {
Expand Down Expand Up @@ -507,13 +525,13 @@ public boolean keyPressed(Key key) {
return moveSelectedQuests(step, 0D);
}
case GLFW.GLFW_KEY_C -> {
return copySelectedQuests();
return copyObjectsToClipboard();
}
case GLFW.GLFW_KEY_V -> {
if (key.modifiers.alt()) {
return pasteSelectedQuestLinks();
} else {
return pasteSelectedQuests(!key.modifiers.shift());
return pasteSelectedQuest(!key.modifiers.shift());
}
}
}
Expand Down Expand Up @@ -564,6 +582,7 @@ public void tick() {

if (selectedChapter == null) {
selectChapter(file.getFirstVisibleChapter(file.selfTeamData));
selectedChapter.getAutofocus().ifPresent(this::scrollTo);
}

super.tick();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,7 @@
import dev.ftb.mods.ftbquests.quest.loot.LootCrate;
import dev.ftb.mods.ftbquests.quest.loot.RewardTable;
import dev.ftb.mods.ftbquests.quest.reward.*;
import dev.ftb.mods.ftbquests.quest.task.CustomTask;
import dev.ftb.mods.ftbquests.quest.task.Task;
import dev.ftb.mods.ftbquests.quest.task.TaskType;
import dev.ftb.mods.ftbquests.quest.task.TaskTypes;
import dev.ftb.mods.ftbquests.quest.task.*;
import dev.ftb.mods.ftbquests.quest.theme.property.ThemeProperties;
import dev.ftb.mods.ftbquests.util.FileUtils;
import dev.ftb.mods.ftbquests.util.NetUtils;
Expand Down Expand Up @@ -89,6 +86,7 @@ public abstract class BaseQuestFile extends QuestObject implements QuestFile {

private List<Task> allTasks;
private List<Task> submitTasks;
private List<Task> craftingTasks;

public BaseQuestFile() {
super(1L);
Expand Down Expand Up @@ -1058,6 +1056,7 @@ public void clearCachedData() {

allTasks = null;
submitTasks = null;
craftingTasks = null;

for (ChapterGroup group : chapterGroups) {
group.clearCachedData();
Expand Down Expand Up @@ -1194,6 +1193,13 @@ public List<Task> getSubmitTasks() {
return submitTasks;
}

public List<Task> getCraftingTasks() {
if (craftingTasks == null) {
craftingTasks = getAllTasks().stream().filter(task -> task instanceof ItemTask i && i.isOnlyFromCrafting()).toList();
}
return craftingTasks;
}

public List<Chapter> getVisibleChapters(TeamData data) {
List<Chapter> list = new ArrayList<>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public final class Chapter extends QuestObject {
private final List<Quest> quests;
private final List<QuestLink> questLinks;
private final List<String> rawSubtitle;
boolean alwaysInvisible;
private boolean alwaysInvisible;
private String defaultQuestShape;
private double defaultQuestSize;
private final List<ChapterImage> images;
Expand Down Expand Up @@ -453,8 +453,8 @@ public void fillConfigGroup(ConfigGroup config) {
@Override
public boolean isVisible(TeamData data) {
return !alwaysInvisible
&& quests.isEmpty() || quests.stream().anyMatch(quest -> quest.isVisible(data))
&& questLinks.isEmpty() || questLinks.stream().anyMatch(link -> link.isVisible(data));
&& (quests.isEmpty() || quests.stream().anyMatch(quest -> quest.isVisible(data)))
&& (questLinks.isEmpty() || questLinks.stream().anyMatch(link -> link.isVisible(data)));
}

@Override
Expand Down
Loading

0 comments on commit 36f78d4

Please sign in to comment.