Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,20 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* Stage Reward now grants a team stage if "Team Reward" is true
* The text color for not-started chapters in the left-hand chapter panel is now themable
* It uses the `quest_not_started_color` value from `ftb_quests_theme.txt` (default is white as before)
* Added a "Copy ID" menu item to the context menu in the Reward Table editor screen

### Changed
* FTB XMod Compat 21.1.7+ is now required, if that mod is in your instance
* The entity selector screen for the Kill task now shows entity ID's as well as the display name
* It's entirely possible for two mods to use the same display name for two different entities, leading to confusion
* The `/ftbquests generate_chapter_with_all_items_in_game` command has been overhauled and improved:
* `/ftbquests generate_chapter from_entire_creative_list` - replaces the above command. Beware: this command can cause a lot of server lag!
* `/ftbquests generate_chapter from_inventory` - creates a new chapter with an item task & quest for each item in the inventory a player is looking at
* `/ftbquests generate_chapter from_player_inventory` - creates a new chapter with an item task & quest for each item in the player's inventory/hotbar (not armor slots)

### Fixed
* Fixed some logic errors related to quest exclusion and flexible mode
* Fixed UI bug causing multiline text boxes to sometimes go blank
* Fixed UI bug causing the multiline text box editor to occasionally go blank

## [2101.1.19]

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package dev.ftb.mods.ftbquests.api;

import net.minecraft.core.HolderLookup;
import net.minecraft.tags.TagKey;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
Expand Down Expand Up @@ -35,7 +36,7 @@ public interface ItemFilterAdapter {
* @param toCheck the itemstack to check
* @return true if the first item is a filter stack AND the second item is matched by it
*/
boolean doesItemMatch(ItemStack filterStack, ItemStack toCheck);
boolean doesItemMatch(ItemStack filterStack, ItemStack toCheck, HolderLookup.Provider registryAccess);

/**
* Retrieve the actual item matcher from this filter implementation, which is basically a predicate that can
Expand All @@ -45,7 +46,7 @@ public interface ItemFilterAdapter {
* @param filterStack the filter item (note: the filter, not the item to be tested!)
* @return a matcher object
*/
Matcher getMatcher(ItemStack filterStack);
Matcher getMatcher(ItemStack filterStack, HolderLookup.Provider registryAccess);

/**
* Does this filter mod provide a way to filter items by item tag?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,9 @@ public void onClicked(MouseButton button) {
new ContextMenuItem(Component.translatable(pendingDeleteIndexes.contains(idx) ? "ftbquests.gui.restore" : "gui.remove"), Icons.BIN,
b -> deleteRewardTable()),
new ContextMenuItem(getLootCrateText(), ItemIcon.getItemIcon(ModItems.LOOTCRATE.get()),
b -> toggleLootCrate())
b -> toggleLootCrate()),
new ContextMenuItem(Component.translatable("ftbquests.gui.copy_id"), Icons.SETTINGS,
b -> QuestScreen.setClipboardString(table.getCodeString()))
);
getGui().openContextMenu(menu);
}
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import dev.ftb.mods.ftbquests.api.event.CustomFilterDisplayItemsEvent;
import dev.ftb.mods.ftbquests.client.FTBQuestsClient;
import it.unimi.dsi.fastutil.ints.Int2ObjectLinkedOpenHashMap;
import net.minecraft.core.HolderLookup;
import net.minecraft.world.item.CreativeModeTabs;
import net.minecraft.world.item.ItemStack;
import org.jetbrains.annotations.NotNull;
Expand All @@ -18,12 +19,12 @@ public class DisplayStacksCache {
private static List<ItemStack> extraCache = null;

@NotNull
public static List<ItemStack> getCachedDisplayStacks(ItemStack filterStack, ItemFilterAdapter adapter) {
public static List<ItemStack> getCachedDisplayStacks(ItemStack filterStack, ItemFilterAdapter adapter, HolderLookup.Provider registryAccess) {
int key = ItemStack.hashItemAndComponents(filterStack);

List<ItemStack> result = cache.getAndMoveToFirst(key);
if (result == null) {
result = computeMatchingStacks(adapter.getMatcher(filterStack));
result = computeMatchingStacks(adapter.getMatcher(filterStack, registryAccess));
cache.put(key, result);
if (cache.size() >= MAX_CACHE_SIZE) {
cache.removeLast();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import dev.ftb.mods.ftblibrary.config.NameMap;
import dev.ftb.mods.ftbquests.api.ItemFilterAdapter;
import net.minecraft.core.HolderLookup;
import net.minecraft.core.component.DataComponentMap;
import net.minecraft.world.item.ItemStack;

Expand All @@ -25,18 +26,18 @@ public Optional<ItemFilterAdapter> getFilterAdapter(ItemStack stack) {
return adapters.stream().filter(adapter -> adapter.isFilterStack(stack)).findFirst();
}

public boolean doesItemMatch(ItemStack filterStack, ItemStack toCheck, ComponentMatchType matchType) {
public boolean doesItemMatch(ItemStack filterStack, ItemStack toCheck, ComponentMatchType matchType, HolderLookup.Provider registryAccess) {
return getFilterAdapter(filterStack)
.map(adapter -> adapter.doesItemMatch(filterStack, toCheck))
.map(adapter -> adapter.doesItemMatch(filterStack, toCheck, registryAccess))
.orElse(areItemStacksEqual(filterStack, toCheck, matchType));
}

public List<ItemStack> getAllMatchingStacks(ItemStack filterStack) {
public List<ItemStack> getAllMatchingStacks(ItemStack filterStack, HolderLookup.Provider registryAccess) {
List<ItemStack> res = new ArrayList<>();

adapters.forEach(adapter -> {
if (adapter.isFilterStack(filterStack)) {
res.addAll(DisplayStacksCache.getCachedDisplayStacks(filterStack, adapter));
res.addAll(DisplayStacksCache.getCachedDisplayStacks(filterStack, adapter, registryAccess));
}
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ public void readNetData(RegistryFriendlyByteBuf buffer) {
}

public List<ItemStack> getValidDisplayItems() {
return ItemMatchingSystem.INSTANCE.getAllMatchingStacks(itemStack);
return ItemMatchingSystem.INSTANCE.getAllMatchingStacks(itemStack, getQuestFile().holderLookup());
}

@Override
Expand Down Expand Up @@ -188,7 +188,7 @@ public boolean test(ItemStack stack) {
return true;
}

return ItemMatchingSystem.INSTANCE.doesItemMatch(itemStack, stack, matchComponents);
return ItemMatchingSystem.INSTANCE.doesItemMatch(itemStack, stack, matchComponents, getQuestFile().holderLookup());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import dev.ftb.mods.ftbquests.quest.TeamData;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.ChatFormatting;
import net.minecraft.core.HolderLookup;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.core.registries.Registries;
Expand Down Expand Up @@ -226,7 +227,9 @@ private boolean nameMatchOK(LivingEntity e) {
return c1.getString().compareTo(c2.getString());
});
return NameMap.of(ZOMBIE, ids)
.nameKey(id -> "entity." + id.toLanguageKey())
.name(id -> Component.translatable("entity." + id.toLanguageKey())
.append(Component.empty().withStyle(ChatFormatting.GRAY).append(" [").append(Component.literal(id.toString())).append("]"))
)
.icon(KillTask::getIconForEntityType)
.create();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package dev.ftb.mods.ftbquests.util;

import dev.architectury.injectables.annotations.ExpectPlatform;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.core.NonNullList;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Level;

import java.util.List;

public class InventoryUtil {
@ExpectPlatform
public static NonNullList<ItemStack> getItemsInInventory(Level level, BlockPos pos, Direction side) {
throw new AssertionError();
}

@ExpectPlatform
public static boolean putItemsInInventory(List<ItemStack> items, Level level, BlockPos pos, Direction side, boolean clearFirst) {
throw new AssertionError();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package dev.ftb.mods.ftbquests.util.fabric;

import net.fabricmc.fabric.api.transfer.v1.item.ItemStorage;
import net.fabricmc.fabric.api.transfer.v1.item.ItemVariant;
import net.fabricmc.fabric.api.transfer.v1.storage.Storage;
import net.fabricmc.fabric.api.transfer.v1.transaction.Transaction;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.core.NonNullList;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Level;

import java.util.List;

public class InventoryUtilImpl {
@SuppressWarnings("UnstableApiUsage")
public static NonNullList<ItemStack> getItemsInInventory(Level level, BlockPos pos, Direction side) {
NonNullList<ItemStack> items = NonNullList.create();

Storage<ItemVariant> storage = ItemStorage.SIDED.find(level, pos, side);
if (storage != null) {
storage.forEach(storageView -> {
if (!storageView.isResourceBlank()) {
items.add(storageView.getResource().toStack((int) storageView.getAmount()));
}
});
}

return items;
}

@SuppressWarnings("UnstableApiUsage")
public static boolean putItemsInInventory(List<ItemStack> items, Level level, BlockPos pos, Direction side, boolean clearFirst) {
Storage<ItemVariant> storage = ItemStorage.SIDED.find(level, pos, side);
if (storage == null || !storage.supportsInsertion()) {
throw new IllegalArgumentException("No item storage found");
}

try (Transaction tx = Transaction.openOuter()) {
if (clearFirst && storage.supportsExtraction()) {
for (var view : storage.nonEmptyViews()) {
view.extract(view.getResource(), view.getAmount(), tx);
}
}
int ok = 0;
for (ItemStack stack : items) {
if (storage.insert(ItemVariant.of(stack), Integer.MAX_VALUE, tx) == stack.getCount()) {
ok++;
} else {
break;
}
}
if (ok == items.size()) {
tx.commit();
return true;
} else {
tx.abort();
return false;
}
}
}
}
1 change: 1 addition & 0 deletions fabric/src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,6 @@
"ftbteams": ">=${ftbteamsversion}"
},
"breaks": {
"ftbxmodcompat": "<21.1.7"
}
}
4 changes: 2 additions & 2 deletions 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=2101.1.20
mod_version=2101.1.21
minecraft_version=1.21.1

# Cross env
Expand All @@ -23,7 +23,7 @@ fabric_api_version=0.102.1+1.21.1
fabric_api_version_range=>=0.102.1+1.21.1
architectury_api_version=13.0.8

ftb_library_version=2101.1.29
ftb_library_version=2101.1.30
ftb_teams_version=2101.1.8

# Optional deps
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package dev.ftb.mods.ftbquests.util.neoforge;

import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.core.NonNullList;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Level;
import net.neoforged.neoforge.capabilities.Capabilities;
import net.neoforged.neoforge.items.IItemHandler;
import net.neoforged.neoforge.items.ItemHandlerHelper;

import java.util.List;

public class InventoryUtilImpl {
public static NonNullList<ItemStack> getItemsInInventory(Level level, BlockPos pos, Direction side) {
IItemHandler handler = level.getCapability(Capabilities.ItemHandler.BLOCK, pos, side);
NonNullList<ItemStack> items = NonNullList.create();

if (handler != null) {
for (int i = 0; i < handler.getSlots(); i++) {
ItemStack stack = handler.getStackInSlot(i);
if (!stack.isEmpty()) {
items.add(stack);
}
}
}

return items;
}

public static boolean putItemsInInventory(List<ItemStack> items, Level level, BlockPos pos, Direction side, boolean clearFirst) {
IItemHandler handler = level.getCapability(Capabilities.ItemHandler.BLOCK, pos, side);
if (handler == null) {
throw new IllegalArgumentException("No item handler at that blockpos & side");
}

if (clearFirst) {
for (int i = 0; i < handler.getSlots(); i++) {
handler.extractItem(i, Integer.MAX_VALUE, false);
}
}
for (ItemStack stack : items) {
ItemStack excess = ItemHandlerHelper.insertItem(handler, stack.copy(), false);
if (!excess.isEmpty()) {
return false;
}
}

return true;
}
}
6 changes: 6 additions & 0 deletions neoforge/src/main/resources/META-INF/neoforge.mods.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,9 @@ type = "required"
versionRange = "[${ftbteamsversion},)"
ordering = "AFTER"
side = "BOTH"

[[dependencies.ftbquests]]
modId = "ftbxmodcompat"
type = "optional"
versionRange = "[21.1.7,)"
side = "BOTH"