Skip to content

Commit

Permalink
swap to FAPI compile. majorly improve config documentation, fix access
Browse files Browse the repository at this point in the history
  • Loading branch information
sisby-folk committed Dec 14, 2023
1 parent 7b237cc commit 4658d81
Show file tree
Hide file tree
Showing 13 changed files with 76 additions and 69 deletions.
7 changes: 5 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ group = 'folk.sisby'

repositories {
mavenLocal()
maven { url "https://maven.quiltmc.org/repository/release/" }
maven { url 'https://maven.fabricmc.net/'}
maven { url 'https://repo.sleeping.town/'}
maven { url "https://maven.terraformersmc.com/" }
maven { url "https://maven.cafeteria.dev/releases" }
}
Expand All @@ -27,8 +30,8 @@ dependencies {
// // Base // //
minecraft libs.mc
mappings variantOf(libs.qm) { classifier "intermediary-v2" }
modImplementation libs.ql
modImplementation libs.qfapi
modImplementation libs.fl
modImplementation libs.fapi

implementation libs.kaleidoConfig
include libs.kaleidoConfig
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ org.gradle.configureondemand=true
# Enable advanced multi-module optimizations (share tiny-remaper instance between projects)
fabric.loom.multiProjectOptimisation=true
# Mod Properties
baseVersion = 1.1.0
baseVersion = 1.1.1
defaultBranch = 1.20
branch = 1.20
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.3-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
9 changes: 6 additions & 3 deletions libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,23 +1,26 @@
[versions]
loom = "1.2.+"
loom = "1.4.+"
githubRelease = "2.4.1"
minotaur = "2.6.0"

mc = "1.20.1"
fl = "0.15.1"
ql = "0.19.0"
qm = "1.20.1+build.23"
fapi = "0.83.0-1.20"
fapi = "0.83.0+1.20.1"
qfapi = "7.0.2+0.83.0-1.20.1"
kaleidoConfig = "0.1.1+1.1.0-beta.3"

[plugins]
loom = { id = "org.quiltmc.loom", version.ref = "loom" }
loom = { id = "fabric-loom", version.ref = "loom" }
githubRelease = { id = "com.github.breadmoirai.github-release", version.ref = "githubRelease" }
minotaur = { id = "com.modrinth.minotaur", version.ref = "minotaur" }

[libraries]
mc = { group = "mojang", name = "minecraft", version.ref = "mc" }
fl = { group = "net.fabricmc", name = "fabric-loader", version.ref = "fl" }
ql = { group = "org.quiltmc", name = "quilt-loader", version.ref = "ql" }
qm = { group = "org.quiltmc", name = "quilt-mappings", version.ref = "qm" }
fapi = { group = "net.fabricmc.fabric-api", name = "fabric-api", version.ref = "fapi" }
qfapi = { group = "org.quiltmc.quilted-fabric-api", name = "quilted-fabric-api", version.ref = "qfapi" }
kaleidoConfig = { group = "folk.sisby", name = "kaleido-config", version.ref = "kaleidoConfig" }
99 changes: 51 additions & 48 deletions src/main/java/folk/sisby/inventory_tabs/InventoryTabsConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,11 @@

import folk.sisby.kaleido.api.WrappedConfig;
import folk.sisby.kaleido.lib.quiltconfig.api.annotations.Comment;
import folk.sisby.kaleido.lib.quiltconfig.api.values.ValueList;
import folk.sisby.kaleido.lib.quiltconfig.api.values.ValueMap;

import java.util.List;
import java.util.Map;

public class InventoryTabsConfig extends WrappedConfig {
public enum AllowDeny {
ALLOW,
DENY
}

@Comment("Whether to allow interacting with entities through blocks.")
@Comment("More seamless, but may be considered cheating by the server.")
public final Boolean ignoreWalls = true;
Expand All @@ -26,67 +19,77 @@ public enum AllowDeny {
@Comment("If you're seeing stacks in the wrong places (offset up by 1 unit) on modded containers, turn this off.")
public final Boolean consistentContainers = true;

@Comment("Strip nonessential features from 6-row container screens to fit them onto minimum-ratio viewports.")
@Comment("Strip titles from 6-row container screens to fit them onto minimum-ratio viewports.")
public final Boolean compactLargeContainers = false;

@Comment("Logs helpful information for setting up the config for modpackers.")
@Comment("Each reload, logs Screen Handler IDs, Tab Provider IDs, and blocks/items/entities for each Tab Provider.")
@Comment("Emits helpful information for setting up this config when joining a world.")
@Comment("Logs all registered screen handler IDs for use in screen overrides.")
@Comment("Logs all registry tab provider contents (blocks etc) to help find bad tabs.")
public final Boolean configLogging = false;

@Comment("Screens where the tab row should be rendered.")
public final ScreenFilter tabDisplayFilter = new ScreenFilter(AllowDeny.ALLOW, ValueList.create(""
), ValueList.create(""
));

public static class ScreenFilter implements Section {
@Comment("Whether to allow or deny tab display on screens that don't match config or code filters.")
public final AllowDeny fallback;

@Comment("Screen Type IDs to deny rendering tabs on.")
@Comment("Screens allowed through code take precedent over this, e.g. HorseScreen.")
public final List<String> deny;
@Comment("Whether to show tabs on screens that aren't specified below.")
public final Boolean allowScreensByDefault = true;

@Comment("Screen Type IDs to allow rendering tabs on.")
@Comment("Screens denied through code take precedent over this, e.g. CreativeInventoryScreen.")
public final List<String> allow;

public ScreenFilter(AllowDeny fallback, List<String> deny, List<String> allow) {
this.fallback = fallback;
this.deny = deny;
this.allow = allow;
}
}
@Comment("")
@Comment("-------------------------------")
@Comment("")
@Comment("Manually set whether tabs should be shown on a given screen.")
@Comment("")
public final Map<String, Boolean> screenOverrides = ValueMap.builder(true)
.put("minecraft:smoker", true)
.build();

@Comment("")
@Comment("Allows forcing blocks or block tags to be handled by a specific tab provider. '' to disable.")
@Comment("-------------------------------")
@Comment("")
@Comment("Manually set the Tab Provider for a given block or tag")
@Comment("| -Provider ID- | -Tab Behaviour- | -Default Blocks Added-")
@Comment("| block_shulker_box | Checks shulker blocked state | Adds all ShulkerBoxBlocks")
@Comment("| block_ender_chest | Unique, checks chest blocked state | Adds all EnderChestBlocks")
@Comment("| block_chest | L/R Multiblock, checks chest blocked state | Adds all AbstractChestBlocks")
@Comment("| block_unique | Only one tab can exist per block type | Adds all CraftingTableBlocks, AnvilBlocks, CartographyTableBlocks, GrindstoneBlocks, LoomBlocks, and StonecutterBlocks.")
@Comment("| block_simple_storage | Sorted alongside other chest-like tabs | Adds all BarrelBlocks.")
@Comment("| block_simple | No special logic | Adds all BlockWithEntities, except 25 known-bad vanilla block classes - this adds lots of invalid modded blocks!")
@Comment("| \"\" | No tab at all! | Use this to disable bad block tabs in your pack.")
@Comment("")
public final Map<String, String> blockProviderOverrides = ValueMap.builder("")
.put("minecraft:crafting_table", "inventory_tabs:block_unique")
.put("minecraft:fletching_table", "")
.build();

@Comment("")
@Comment("Allows forcing entities or entity tags to be handled by a specific tab provider. '' to disable.")
@Comment("-------------------------------")
@Comment("")
@Comment("Manually set the Tab Provider for a given entity or tag")
@Comment("| -Provider ID- | -Tab Behaviour- | -Default Entities Added-")
@Comment("| entity_sneak | Uses sneak-interact, checks tamed/riding | Adds all RideableOpenableInventory.")
@Comment("| entity_simple | Checks player isn't riding the entity | Adds nothing.")
@Comment("| \"\" | No tab at all! | Use this to disable bad entity tabs in your pack.")
@Comment("")
public final Map<String, String> entityProviderOverrides = ValueMap.builder("")
.put("minecraft:chest_minecart", "inventory_tabs:entity_simple")
.build();

@Comment("")
@Comment("Allows forcing items or item tags to be handled by a specific tab provider. Use NONE to disable.")
@Comment("-------------------------------")
@Comment("")
@Comment("Manually set the Tab Provider for a given item or tag")
@Comment("| -Provider ID- | -Tab Behaviour- | -Default Items Added-")
@Comment("| item_unique | Only one tab can exist per item type | Adds nothing.")
@Comment("| item_simple | No special logic | Adds nothing.")
@Comment("| \"\" | No tab at all! | Use this to disable bad item tabs in your pack.")
@Comment("")
public final Map<String, String> itemProviderOverrides = ValueMap.builder("")
.put("minecraft:dirt", "")
.build();

@Comment("")
@Comment("Whether to enable the default registry-matching logic for each tab provider.")
@Comment("When default logic is disabled, a tab provider will only be used if overridden below!")
@Comment("Simple Block: Blocks with block entities that can be interacted with to open a screen.")
@Comment("-Default logic: All BlockEntityProviders that don't match a list of known-bad types are added.")
@Comment("Chest Block: Must have facing and single/left/right properties, and can be blocked above.")
@Comment("-Default logic: All AbstractChestBlocks are added.")
@Comment("Unique Block: Blocks that open the same screen, regardless of where they are.")
@Comment("-Default logic: Blocks from a list of known-good vanilla types are added.")
@Comment("Simple Entity: Entity that can be interacted with to open a screen.")
@Comment("-Default logic: Nothing is added.")
@Comment("Sneak Entity: Entity that can be interacted with while sneaking to open a screen.")
@Comment("-Default logic: Nothing is added.")
public final Map<String, Boolean> registryProviderDefaults = ValueMap.builder(true).build();
@Comment("-------------------------------")
@Comment("")
@Comment("Enable or disable the default added logic for each tab provider (see above)")
@Comment("Non-registry Tab Providers like player_inventory and vehicle_inventory can't be disabled here.")
@Comment("")
public final Map<String, Boolean> registryProviderDefaults = ValueMap.builder(true)
.put("inventory_tabs:block_simple", true)
.build();
}
7 changes: 4 additions & 3 deletions src/main/java/folk/sisby/inventory_tabs/ScreenSupport.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.function.Predicate;

public class ScreenSupport {
Expand All @@ -21,11 +22,11 @@ public static boolean allowTabs(Screen screen) {
if (ALLOW.values().stream().anyMatch(p -> p.test(hs))) return true;
try {
Identifier handlerId = Registries.SCREEN_HANDLER_TYPE.getId(hs.getScreenHandler().getType());
if (InventoryTabs.CONFIG.tabDisplayFilter.deny.stream().map(Identifier::tryParse).toList().contains(handlerId)) return false;
if (InventoryTabs.CONFIG.tabDisplayFilter.allow.stream().map(Identifier::tryParse).toList().contains(handlerId)) return true;
if (InventoryTabs.CONFIG.screenOverrides.entrySet().stream().filter(e -> !e.getValue()).anyMatch(e -> Objects.equals(e.getKey(), handlerId.toString()))) return false;
if (InventoryTabs.CONFIG.screenOverrides.entrySet().stream().filter(Map.Entry::getValue).anyMatch(e -> Objects.equals(e.getKey(), handlerId.toString()))) return true;
} catch (UnsupportedOperationException ignored) {
}
return InventoryTabs.CONFIG.tabDisplayFilter.fallback == InventoryTabsConfig.AllowDeny.ALLOW;
return InventoryTabs.CONFIG.allowScreensByDefault;
}
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/folk/sisby/inventory_tabs/TabManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ public static void drawButton(GuiGraphics graphics, double mouseX, double mouseY
int u = BUTTON_WIDTH * (left ? 0 : 1);
int v = BUTTON_HEIGHT * (active ? hovered ? 2 : 1 : 0);
graphics.drawTexture(BUTTONS_TEXTURE, rect.getX(), rect.getY(), u, v, rect.getWidth(), rect.getHeight());
if (hovered) graphics.drawTooltip(currentScreen.getTextRenderer(), Text.literal((currentPage + 1) + "/" + (getMaximumPage() + 1)), (int) mouseX, (int) mouseY);
if (hovered) graphics.drawTooltip(currentScreen.textRenderer, Text.literal((currentPage + 1) + "/" + (getMaximumPage() + 1)), (int) mouseX, (int) mouseY);
}

public static void playClick() {
Expand Down
2 changes: 0 additions & 2 deletions src/main/java/folk/sisby/inventory_tabs/TabProviders.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,6 @@ public static void reload(DynamicRegistryManager manager) {
if (InventoryTabs.CONFIG.configLogging) {
InventoryTabs.LOGGER.info("[Inventory Tabs] Registered Screen Handlers:");
manager.get(RegistryKeys.SCREEN_HANDLER_TYPE).getKeys().forEach(id -> InventoryTabs.LOGGER.info("[Inventory Tabs] {}", id.getValue().toString()));
InventoryTabs.LOGGER.info("[Inventory Tabs] Registered Tab Providers Available:");
REGISTRY.keySet().forEach(id -> InventoryTabs.LOGGER.info("[Inventory Tabs] {}", id.toString()));
}
reloadRegistryProviders(manager, RegistryKeys.BLOCK, getProviders(BlockTabProvider.class), InventoryTabs.CONFIG.blockProviderOverrides);
warmEntities = reloadRegistryProviders(manager, RegistryKeys.ENTITY_TYPE, getProviders(EntityTabProvider.class), InventoryTabs.CONFIG.entityProviderOverrides);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
public abstract class BlockTabProvider extends RegistryTabProvider<Block> {
public final Map<Identifier, BiPredicate<World, BlockPos>> preclusions = new HashMap<>();

BlockTabProvider() {
public BlockTabProvider() {
preclusions.put(InventoryTabs.id("player_in_range"), (w, p) -> MinecraftClient.getInstance().player != null && !PlayerUtil.inRange(MinecraftClient.getInstance().player, p));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public abstract class EntityTabProvider extends RegistryTabProvider<EntityType<?
public final Set<EntityType<?>> failedMatches = new HashSet<>();
public final Map<Identifier, Predicate<Entity>> preclusions = new HashMap<>();

EntityTabProvider() {
public EntityTabProvider() {
preclusions.put(InventoryTabs.id("removed"), Entity::isRemoved);
preclusions.put(InventoryTabs.id("player_in_range"), (e) -> MinecraftClient.getInstance().player != null && !PlayerUtil.inRange(MinecraftClient.getInstance().player, e));
preclusions.put(InventoryTabs.id("vehicle"), e -> MinecraftClient.getInstance().player != null && e == MinecraftClient.getInstance().player.getVehicle());
Expand Down
7 changes: 1 addition & 6 deletions src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,5 @@
"fabricloader": ">=0.14.21",
"fabric-api": ">=${fapi}",
"minecraft": ">=${mc}"
},
"jars": [
{
"file": "META-INF/jars/kaleido-config-${kaleidoConfig}.jar"
}
]
}
}
1 change: 1 addition & 0 deletions src/main/resources/inventory_tabs.accesswidener
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
accessWidener v2 named
accessible method net/minecraft/block/ShulkerBoxBlock canOpen (Lnet/minecraft/block/BlockState;Lnet/minecraft/world/World;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/entity/ShulkerBoxBlockEntity;)Z
mutable field net/minecraft/client/gui/screen/Screen title Lnet/minecraft/text/Text;
accessible field net/minecraft/client/gui/screen/Screen textRenderer Lnet/minecraft/client/font/TextRenderer;
accessible field net/minecraft/client/gui/screen/ingame/HandledScreen backgroundWidth I
accessible field net/minecraft/client/gui/screen/ingame/HandledScreen backgroundHeight I
mutable field net/minecraft/client/gui/screen/ingame/HandledScreen playerInventoryTitle Lnet/minecraft/text/Text;
Expand Down
3 changes: 3 additions & 0 deletions src/main/resources/quilt.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@
"id": "quilted_fabric_api",
"versions": ">=${qfapi}"
}
],
"jars": [
"META-INF/jars/kaleido-config-${kaleidoConfig}.jar"
]
},
"mixin": "inventory_tabs.mixins.json",
Expand Down

0 comments on commit 4658d81

Please sign in to comment.