From 4b992a6bf9ac76a50bf80c7ce3e6da6d3b54b323 Mon Sep 17 00:00:00 2001 From: strubium <113206902+strubium@users.noreply.github.com> Date: Fri, 29 Nov 2024 12:39:32 -0600 Subject: [PATCH] Only one showChestContents --- .../apiimpl/providers/ChestInfoTools.java | 41 ++++--------------- 1 file changed, 8 insertions(+), 33 deletions(-) diff --git a/src/main/java/mcjty/theoneprobe/apiimpl/providers/ChestInfoTools.java b/src/main/java/mcjty/theoneprobe/apiimpl/providers/ChestInfoTools.java index 17798145..d94591be 100644 --- a/src/main/java/mcjty/theoneprobe/apiimpl/providers/ChestInfoTools.java +++ b/src/main/java/mcjty/theoneprobe/apiimpl/providers/ChestInfoTools.java @@ -1,6 +1,7 @@ package mcjty.theoneprobe.apiimpl.providers; import mcjty.theoneprobe.Tools; +import mcjty.theoneprobe.Utilities; import mcjty.theoneprobe.api.ElementAlignment; import mcjty.theoneprobe.api.IProbeConfig; import mcjty.theoneprobe.api.IProbeInfo; @@ -26,7 +27,10 @@ public class ChestInfoTools { static void showChestInfo(ProbeMode mode, IProbeInfo probeInfo, World world, BlockPos pos, IProbeConfig config) { List stacks = null; IProbeConfig.ConfigMode chestMode = config.getShowChestContents(); - if (chestMode == IProbeConfig.ConfigMode.EXTENDED && (ConfigSetup.showSmallChestContentsWithoutSneaking > 0 || !ConfigSetup.getInventoriesToShow().isEmpty())) { + + // Determine the chestMode based on configuration and world state + if (chestMode == IProbeConfig.ConfigMode.EXTENDED + && (ConfigSetup.showSmallChestContentsWithoutSneaking > 0 || !ConfigSetup.getInventoriesToShow().isEmpty())) { if (ConfigSetup.getInventoriesToShow().contains(world.getBlockState(pos).getBlock().getRegistryName())) { chestMode = IProbeConfig.ConfigMode.NORMAL; } else if (ConfigSetup.showSmallChestContentsWithoutSneaking > 0) { @@ -42,6 +46,7 @@ static void showChestInfo(ProbeMode mode, IProbeInfo probeInfo, World world, Blo } } + // Check if chest contents should be shown based on the mode and configuration if (Tools.show(mode, chestMode)) { if (stacks == null) { stacks = new ArrayList<>(); @@ -49,8 +54,8 @@ static void showChestInfo(ProbeMode mode, IProbeInfo probeInfo, World world, Blo } if (!stacks.isEmpty()) { - boolean showDetailed = Tools.show(mode, config.getShowChestContentsDetailed()) && stacks.size() <= ConfigSetup.showItemDetailThresshold; - showChestContents(probeInfo, stacks, showDetailed); + // Call the updated showChestContents method with mode, probeInfo, and stacks + Utilities.showChestContents(probeInfo, stacks, mode); } } } @@ -74,36 +79,6 @@ private static void addItemStack(List stacks, Set foundItems, @ } } - private static void showChestContents(IProbeInfo probeInfo, List stacks, boolean detailed) { - IProbeInfo vertical; - IProbeInfo horizontal = null; - - int rows = 0; - int idx = 0; - - vertical = probeInfo.vertical(probeInfo.defaultLayoutStyle().borderColor(ConfigSetup.chestContentsBorderColor).spacing(0)); - - if (detailed) { - for (ItemStack stackInSlot : stacks) { - horizontal = vertical.horizontal(new LayoutStyle().spacing(10).alignment(ElementAlignment.ALIGN_CENTER)); - horizontal.item(stackInSlot, new ItemStyle().width(16).height(16)) - .itemLabel(stackInSlot); //TOPFIX: Chest info doesn't show gregtechCE item local name when player on server. - } - } else { - for (ItemStack stackInSlot : stacks) { - if (idx % 10 == 0) { - horizontal = vertical.horizontal(new LayoutStyle().spacing(0)); - rows++; - if (rows > 4) { - break; - } - } - horizontal.item(stackInSlot); - idx++; - } - } - } - private static int getChestContents(World world, BlockPos pos, List stacks) { TileEntity te = world.getTileEntity(pos);