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

feat: add configuration option to disable empty item stack highlighting #21

Merged
Merged
Show file tree
Hide file tree
Changes from 2 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
4 changes: 4 additions & 0 deletions dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,8 @@ dependencies {
compileOnly('com.github.GTNewHorizons:EnderIO:2.8.17:dev')
compileOnly('com.github.GTNewHorizons:Draconic-Evolution:1.3.10-GTNH:dev')
api('com.github.GTNewHorizons:ForestryMC:4.9.16:dev')

// For testing in dev environment.
devOnlyNonPublishable('com.github.GTNewHorizons:StorageDrawers:1.13.5-GTNH')
devOnlyNonPublishable("com.github.GTNewHorizons:waila:1.8.1")
mainrs marked this conversation as resolved.
Show resolved Hide resolved
}
9 changes: 9 additions & 0 deletions src/main/java/com/gtnh/findit/FindItConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public class FindItConfig {
public static int ITEM_HIGHLIGHTING_DURATION = 10;
public static int BLOCK_HIGHLIGHTING_DURATION = 8;
public static int ITEM_HIGHLIGHTING_COLOR = 0xFFFF8726;
public static boolean ITEM_HIGHLIGHTING_EMPTY_ITEMSTACKS = false;
mainrs marked this conversation as resolved.
Show resolved Hide resolved

public static void setup(final File file) {
final Configuration config = new Configuration(file);
Expand Down Expand Up @@ -82,6 +83,14 @@ public static void setup(final File file) {
"FFFF8726",
"Item highlighting color as a hexadecimal color code. For example 0xFFFF8726").getString(),
16);

ITEM_HIGHLIGHTING_EMPTY_ITEMSTACKS = config.get(
Configuration.CATEGORY_GENERAL,
"ItemHighlightingEmptyItemStacks",
"false",
mainrs marked this conversation as resolved.
Show resolved Hide resolved
"If true, the item stack size is ignored. If false, items are only highlighted if their stack size is greater than one.\n"
mainrs marked this conversation as resolved.
Show resolved Hide resolved
+ "This is useful when working with barrels or storage drawers.")
.getBoolean();
} catch (Exception ignore) {} finally {
if (config.hasChanged()) config.save();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import net.minecraftforge.fluids.FluidStack;

import com.gtnh.findit.FindIt;
import com.gtnh.findit.FindItConfig;
import com.gtnh.findit.service.blockfinder.BlockFoundResponse;
import com.gtnh.findit.util.ProtoUtils;
import com.gtnh.findit.util.mods.ForestryUtils;
Expand Down Expand Up @@ -82,7 +83,24 @@ public boolean isStackSatisfies(ItemStack stack) {
}
}

return StackInfo.equalItemAndNBT(targetStack, stack, true);
return StackInfo.equalItemAndNBT(targetStack, stack, true) && shouldHighlightItemStack(stack);
}

/**
* Returns whether an {@code ItemStack} should be highlighted inside inventories. The method explicitly checks for
* empty item stacks and consults the mod's configuration to determine whether empty item stacks should be
* highlighted or not.
*
* @param itemStack The {@code ItemStack} to check.
* @return {@code true} if the {@code ItemStack} should be highlighted, {@code false} otherwise.
*/
private boolean shouldHighlightItemStack(ItemStack itemStack) {
// If the user requested to highlight empty item stacks, we early return to make sure that we do so.
if (FindItConfig.ITEM_HIGHLIGHTING_EMPTY_ITEMSTACKS) {
return true;
}

return itemStack.stackSize > 0;
}

public static class Handler implements IMessageHandler<FindItemRequest, BlockFoundResponse> {
Expand Down