Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev #14

Merged
merged 12 commits into from
Dec 6, 2023
Merged

Dev #14

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
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
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@ 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).

## [2.1.0]

### Added

* Added FTB Quests integration for Item Filters and FTB Filter System mods
* FTB Quests 2001.3.0 now required; it now supports external filtering mods via an abstraction layer
* Item Filter is no longer a hard dependency for FTB Quests; it's supported along with FTB Filter System by FTB XMod Compat

## [2.0.4]

### Fixed
Expand Down
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,18 @@ If either REI or JEI is present:
* FTB Quests will use that mod for displaying the items obtained from any configured loot crates (rewards from the reward table which have loot crates enabled)
* FTB Quests will use that mod to show the recipes for items in item tasks (as viewed in the quest display panel)

### Item Filters and FTB Filter System

As of version 2.1.0, FTB XMod Compat provides FTB Quests integration for the Item Filters and FTB Filter System mods. Item Filters was previously a hard dependency for FTB Quests, but is now an optional dependency, along with the new FTB Filter System mod. Using FTB Filter System will be the recommended path for future modpacks.

With KubeJS installed, FTB Filter System's "Custom" filter fires a KubeJS event allowing pack developers to match items using an external KJS script. See https://github.com/FTBTeam/FTB-Filter-System/blob/main/README.md for more information on this, including examples.

### Fallbacks

If neither KubeJS nor Game Stages is loaded, FTB Quests will use an inbuilt stages implementation based on string "tags" which can be added to players. This works but is extremely limited in functionality (either a player has a given tag, or doesn't).

If neither Item Filters nor FTB Filter System is load, only simple item matching will be available for FTB Quests item tasks.

## FTB Chunks

The following cross-mod integrations are added to FTB Chunks 1902.4.0+, if present:
Expand Down
2 changes: 2 additions & 0 deletions common/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,15 @@ dependencies {
modApi("dev.ftb.mods:ftb-ranks:${rootProject.ftb_ranks_version}")
modApi("dev.ftb.mods:ftb-essentials:${rootProject.ftb_essentials_version}")
modApi("dev.ftb.mods:ftb-teams:${rootProject.ftb_teams_version}")
modApi("dev.ftb.mods:ftb-filter-system:${rootProject.ftb_filter_system_version}")

modCompileOnly("me.shedaniel:RoughlyEnoughItems-api:${rootProject.rei_version}")
modCompileOnly("mezz.jei:jei-${rootProject.minecraft_version}-common-api:${rootProject.jei_version}")

compileOnly("net.luckperms:api:${rootProject.luckperms_api_version}")

modCompileOnlyApi "dev.latvian.mods:kubejs:${rootProject.kubejs_version}"
modCompileOnlyApi "dev.latvian.mods:item-filters:${rootProject.itemfilters_version}"
}

publishing {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@ public class FTBXModCompat {
public static boolean isFTBChunksLoaded;
public static boolean isFTBRanksLoaded;
public static boolean isFTBEssentialsLoaded;
public static boolean isFTBFilterSystemLoaded;

public static boolean isKubeJSLoaded;
public static boolean isItemFiltersLoaded;
public static boolean isGameStagesLoaded;
public static boolean isREILoaded;
public static boolean isJEILoaded;
Expand Down Expand Up @@ -48,8 +50,10 @@ private static void detectLoadedMods() {
isFTBChunksLoaded = Platform.isModLoaded("ftbchunks");
isFTBRanksLoaded = Platform.isModLoaded("ftbranks");
isFTBEssentialsLoaded = Platform.isModLoaded("ftbessentials");
isFTBFilterSystemLoaded = Platform.isModLoaded("ftbfiltersystem");

isKubeJSLoaded = Platform.isModLoaded("kubejs");
isItemFiltersLoaded = Platform.isModLoaded("itemfilters");
isGameStagesLoaded = Platform.isModLoaded("gamestages");
isREILoaded = Platform.isModLoaded("roughlyenoughitems");
isJEILoaded = Platform.isModLoaded("jei");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package dev.ftb.mods.ftbxmodcompat.ftbfiltersystem.kubejs;

import dev.latvian.mods.kubejs.event.EventJS;
import net.minecraft.world.item.ItemStack;

public class CustomFilterEventJS extends EventJS {
private final ItemStack stack;
private final String data;

public CustomFilterEventJS(ItemStack stack, String data) {
this.stack = stack;
this.data = data;
}

public ItemStack getStack() {
return stack;
}

public String getData() {
return data;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package dev.ftb.mods.ftbxmodcompat.ftbfiltersystem.kubejs;

import dev.latvian.mods.kubejs.event.EventGroup;
import dev.latvian.mods.kubejs.event.EventHandler;
import dev.latvian.mods.kubejs.event.Extra;

public interface FFSEvents {
EventGroup EVENT_GROUP = EventGroup.of("FTBFilterSystemEvents");

EventHandler CUSTOM_FILTER = EVENT_GROUP.server("customFilter", () -> CustomFilterEventJS.class).extra(Extra.STRING).hasResult();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package dev.ftb.mods.ftbxmodcompat.ftbfiltersystem.kubejs;

import dev.architectury.event.EventResult;
import dev.ftb.mods.ftbfiltersystem.api.event.CustomFilterEvent;
import dev.latvian.mods.kubejs.KubeJSPlugin;
import dev.latvian.mods.kubejs.script.ScriptType;
import net.minecraft.world.item.ItemStack;

public class FFSKubeJSPlugin extends KubeJSPlugin {
@Override
public void init() {
CustomFilterEvent.MATCH_ITEM.register(FFSKubeJSPlugin::onCustomFilter);
}

@Override
public void registerEvents() {
FFSEvents.EVENT_GROUP.register();
}

private static EventResult onCustomFilter(ItemStack stack, String eventId, String extraData) {
return FFSEvents.CUSTOM_FILTER.post(ScriptType.SERVER, eventId, new CustomFilterEventJS(stack, extraData)).arch();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import dev.ftb.mods.ftbquests.FTBQuests;
import dev.ftb.mods.ftbxmodcompat.FTBXModCompat;
import dev.ftb.mods.ftbxmodcompat.ftbquests.filtering.ItemFilteringSetup;
import dev.ftb.mods.ftbxmodcompat.ftbquests.jei.helper.JEIRecipeHelper;
import dev.ftb.mods.ftbxmodcompat.ftbquests.rei.helper.REIRecipeHelper;

Expand All @@ -13,5 +14,7 @@ public static void init() {
FTBQuests.setRecipeModHelper(new REIRecipeHelper());
}
FTBXModCompat.LOGGER.info("[FTB Quests] recipe helper provider is [{}]", FTBQuests.getRecipeModHelper().getHelperName());

ItemFilteringSetup.init();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package dev.ftb.mods.ftbxmodcompat.ftbquests.filtering;

import dev.ftb.mods.ftbfiltersystem.api.FTBFilterSystemAPI;
import dev.ftb.mods.ftbfiltersystem.api.FilterException;
import dev.ftb.mods.ftbfiltersystem.api.filter.SmartFilter;
import dev.ftb.mods.ftbquests.FTBQuests;
import dev.ftb.mods.ftbquests.api.FTBQuestsAPI;
import dev.ftb.mods.ftbquests.api.ItemFilterAdapter;
import dev.ftb.mods.ftbxmodcompat.FTBXModCompat;
import net.minecraft.tags.TagKey;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;

class FFSSetup {
public static void init() {
FTBQuestsAPI.api().registerFilterAdapter(new FFSAdapter());
FTBXModCompat.LOGGER.info("[FTB Quests] Enabled FTB Filter System integration");
}

private static class FFSAdapter implements ItemFilterAdapter {
@Override
public String getName() {
return "FTB Filter System";
}

@Override
public boolean isFilterStack(ItemStack stack) {
return FTBFilterSystemAPI.api().isFilterItem(stack);
}

@Override
public boolean doesItemMatch(ItemStack filterStack, ItemStack toCheck) {
return FTBFilterSystemAPI.api().doesFilterMatch(filterStack, toCheck);
}

@Override
public Matcher getMatcher(ItemStack filterStack) {
try {
return new FFSMatcher(filterStack);
} catch (FilterException e) {
return ItemFilterAdapter.NO_MATCH;
}
}

@Override
public ItemStack makeTagFilterStack(TagKey<Item> tag) {
return FTBFilterSystemAPI.api().makeTagFilter(tag);
}
}

private static class FFSMatcher implements ItemFilterAdapter.Matcher {
private final SmartFilter smartFilter;

public FFSMatcher(ItemStack filterStack) {
smartFilter = FTBFilterSystemAPI.api().parseFilter(filterStack);
}

@Override
public boolean test(ItemStack stack) {
return smartFilter.test(stack);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package dev.ftb.mods.ftbxmodcompat.ftbquests.filtering;

import dev.ftb.mods.ftbxmodcompat.FTBXModCompat;

public class ItemFilteringSetup {
public static void init() {
if (FTBXModCompat.isFTBFilterSystemLoaded) {
FFSSetup.init();
}
if (FTBXModCompat.isItemFiltersLoaded) {
ItemFiltersSetup.init();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package dev.ftb.mods.ftbxmodcompat.ftbquests.filtering;

import dev.ftb.mods.ftbquests.api.FTBQuestsAPI;
import dev.ftb.mods.ftbquests.api.ItemFilterAdapter;
import dev.ftb.mods.ftbxmodcompat.FTBXModCompat;
import dev.latvian.mods.itemfilters.api.IItemFilter;
import dev.latvian.mods.itemfilters.api.IStringValueFilter;
import dev.latvian.mods.itemfilters.api.ItemFiltersAPI;
import dev.latvian.mods.itemfilters.api.ItemFiltersItems;
import net.minecraft.tags.TagKey;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;

class ItemFiltersSetup {
public static void init() {
FTBQuestsAPI.api().registerFilterAdapter(new ItemFiltersAdapter());
FTBXModCompat.LOGGER.info("[FTB Quests] Enabled Item Filters integration");
}

private static class ItemFiltersAdapter implements ItemFilterAdapter {
@Override
public String getName() {
return "Item Filters";
}

@Override
public boolean isFilterStack(ItemStack stack) {
return ItemFiltersAPI.isFilter(stack);
}

@Override
public boolean doesItemMatch(ItemStack filterStack, ItemStack toCheck) {
return ItemFiltersAPI.isFilter(filterStack) && ItemFiltersAPI.filter(filterStack, toCheck);
}

@Override
public Matcher getMatcher(ItemStack filterStack) {
return new IFMatcher(filterStack);
}

@Override
public ItemStack makeTagFilterStack(TagKey<Item> tag) {
ItemStack tagFilter = new ItemStack(ItemFiltersItems.TAG.get());
((IStringValueFilter) tagFilter.getItem()).setValue(tagFilter, tag.location().toString());
return tagFilter;
}
}

private static class IFMatcher implements ItemFilterAdapter.Matcher {
private final ItemStack filterStack;
private final IItemFilter filter;

private IFMatcher(ItemStack filterStack) {
this.filterStack = filterStack;
this.filter = ItemFiltersAPI.getFilter(filterStack);
}

@Override
public boolean test(ItemStack stack) {
return filter != null && filter.filter(filterStack, stack);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package dev.ftb.mods.ftbxmodcompat.ftbquests.kubejs;

import dev.ftb.mods.ftbquests.api.event.CustomFilterDisplayItemsEvent;
import dev.latvian.mods.kubejs.event.EventJS;
import net.minecraft.world.item.ItemStack;

import java.util.Collection;

public class CustomFilterItemEventJS extends EventJS {
private final CustomFilterDisplayItemsEvent event;

public CustomFilterItemEventJS(CustomFilterDisplayItemsEvent event) {
this.event = event;
}

public void addStack(ItemStack stack) {
event.add(stack);
}

public void addStacks(Collection<ItemStack> stacks) {
event.add(stacks);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,6 @@ public interface FTBQuestsKubeJSEvents {
EventHandler CUSTOM_REWARD = EVENT_GROUP.server("customReward", () -> CustomRewardEventJS.class).extra(Extra.STRING).hasResult();
EventHandler OBJECT_COMPLETED = EVENT_GROUP.server("completed", () -> QuestObjectCompletedEventJS.class).extra(Extra.STRING);
EventHandler OBJECT_STARTED = EVENT_GROUP.server("started", () -> QuestObjectStartedEventJS.class).extra(Extra.STRING);

EventHandler CUSTOM_FILTER_ITEM = EVENT_GROUP.client("customFilterItem", () -> CustomFilterItemEventJS.class);
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package dev.ftb.mods.ftbxmodcompat.ftbquests.kubejs;

import dev.architectury.event.EventResult;
import dev.ftb.mods.ftbquests.api.event.CustomFilterDisplayItemsEvent;
import dev.ftb.mods.ftbquests.events.CustomRewardEvent;
import dev.ftb.mods.ftbquests.events.CustomTaskEvent;
import dev.ftb.mods.ftbquests.events.ObjectCompletedEvent;
Expand All @@ -16,11 +17,13 @@
import net.minecraft.world.entity.player.Player;

public class KubeJSIntegration extends KubeJSPlugin {
@Override
public void init() {
CustomTaskEvent.EVENT.register(KubeJSIntegration::onCustomTask);
CustomRewardEvent.EVENT.register(KubeJSIntegration::onCustomReward);
ObjectCompletedEvent.GENERIC.register(KubeJSIntegration::onCompleted);
ObjectStartedEvent.GENERIC.register(KubeJSIntegration::onStarted);
CustomFilterDisplayItemsEvent.ADD_ITEMSTACK.register(KubeJSIntegration::onCustomFilterItem);

Stages.added(event -> {
if (event.getPlayer() instanceof ServerPlayer sp) StageTask.checkStages(sp);
Expand All @@ -29,7 +32,7 @@ public void init() {
if (event.getPlayer() instanceof ServerPlayer sp) StageTask.checkStages(sp);
});

FTBXModCompat.LOGGER.info("FTB Quests: Enabled KubeJS integration");
FTBXModCompat.LOGGER.info("[FTB Quests] Enabled KubeJS integration");
}

@Override
Expand All @@ -47,6 +50,10 @@ public void registerEvents() {
FTBQuestsKubeJSEvents.EVENT_GROUP.register();
}

private static void onCustomFilterItem(CustomFilterDisplayItemsEvent event) {
FTBQuestsKubeJSEvents.CUSTOM_FILTER_ITEM.post(ScriptType.CLIENT, new CustomFilterItemEventJS(event));
}

public static EventResult onCustomTask(CustomTaskEvent event) {
return FTBQuestsKubeJSEvents.CUSTOM_TASK.post(ScriptType.SERVER, event.getTask(), new CustomTaskEventJS(event)).arch();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,23 @@
import dev.ftb.mods.ftbxmodcompat.FTBXModCompat;
import dev.ftb.mods.ftbxmodcompat.ftbquests.recipemod_common.WrappedLootCrate;
import dev.ftb.mods.ftbxmodcompat.ftbquests.recipemod_common.WrappedQuest;
import me.shedaniel.math.Rectangle;
import me.shedaniel.rei.api.client.entry.filtering.base.BasicFilteringRule;
import me.shedaniel.rei.api.client.plugins.REIClientPlugin;
import me.shedaniel.rei.api.client.registry.category.CategoryRegistry;
import me.shedaniel.rei.api.client.registry.display.DisplayRegistry;
import me.shedaniel.rei.api.client.registry.screen.ExclusionZones;
import me.shedaniel.rei.api.client.registry.screen.ExclusionZonesProvider;
import me.shedaniel.rei.api.client.view.ViewSearchBuilder;
import me.shedaniel.rei.api.common.entry.EntryStack;
import me.shedaniel.rei.api.common.entry.type.EntryDefinition;
import me.shedaniel.rei.api.common.entry.type.EntryTypeRegistry;
import me.shedaniel.rei.api.common.entry.type.VanillaEntryTypes;
import net.minecraft.client.gui.screens.Screen;
import net.minecraft.world.item.ItemStack;

import java.util.Collection;

public class FTBQuestsREIIntegration implements REIClientPlugin {
private static BasicFilteringRule.MarkDirty cratesChanged;

Expand Down
Loading