mirror of
https://github.com/GTNewHorizons/FindIt.git
synced 2026-11-19 16:09:34 +00:00
feat: add configuration option to disable empty item stack highlighting (#21)
* feat: add configuration option to disable empty item stack highlighting * refactor: rename config field to match existing ones * chore: applied review suggestions * chore: change default value to true
This commit is contained in:
3 files changed
+32
-1
No files matched your search
@@ -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.
|
||||
//runtimeOnlyNonPublishable('com.github.GTNewHorizons:StorageDrawers:1.13.5-GTNH')
|
||||
//runtimeOnlyNonPublishable("com.github.GTNewHorizons:waila:1.8.1")
|
||||
}
|
||||
@@ -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 = true;
|
||||
|
||||
public static void setup(final File file) {
|
||||
final Configuration config = new Configuration(file);
|
||||
@@ -82,6 +83,14 @@ public class FindItConfig {
|
||||
"FFFF8726",
|
||||
"Item highlighting color as a hexadecimal color code. For example 0xFFFF8726").getString(),
|
||||
16);
|
||||
|
||||
ITEM_HIGHLIGHTING_EMPTY_ITEMSTACKS = config.get(
|
||||
Configuration.CATEGORY_GENERAL,
|
||||
"ItemHighlightingEmptyItemStacks",
|
||||
"true",
|
||||
"If true, the item stack size is ignored. If false, items are only highlighted if their stack size is greater than zero.\n"
|
||||
+ "This is useful when working with barrels or storage drawers.")
|
||||
.getBoolean();
|
||||
} catch (Exception ignore) {} finally {
|
||||
if (config.hasChanged()) config.save();
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import net.minecraft.item.ItemStack;
|
||||
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;
|
||||
@@ -82,7 +83,24 @@ public class FindItemRequest implements IMessage {
|
||||
}
|
||||
}
|
||||
|
||||
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> {
|
||||
|
||||
Reference in new issue
Block a user