diff --git a/build.gradle b/build.gradle index 5d17cfb..5cd730d 100644 --- a/build.gradle +++ b/build.gradle @@ -63,7 +63,7 @@ minecraft { repositories { maven { url "http://dvs1.progwml6.com/files/maven" } - maven { url = "http://maven.ic2.player.to/" } + maven { url = "https://modmaven.dev/" } maven { url = "http://maven.covers1624.net" } } @@ -144,4 +144,4 @@ idea { module { outputDir = file('build/classes/main') } -} +} \ No newline at end of file diff --git a/src/main/java/li/cil/scannable/client/ScanManager.java b/src/main/java/li/cil/scannable/client/ScanManager.java index 36de57a..6d1a3fd 100644 --- a/src/main/java/li/cil/scannable/client/ScanManager.java +++ b/src/main/java/li/cil/scannable/client/ScanManager.java @@ -6,6 +6,7 @@ import li.cil.scannable.common.capabilities.CapabilityScanResultProvider; import li.cil.scannable.common.config.Constants; import li.cil.scannable.common.config.Settings; +import li.cil.scannable.common.config.ClientSettings; import li.cil.scannable.common.init.Items; import li.cil.scannable.integration.optifine.ProxyOptiFine; import net.minecraft.client.Minecraft; @@ -36,21 +37,23 @@ public enum ScanManager { // --------------------------------------------------------------------- // private static int computeTargetRadius() { - return Minecraft.getMinecraft().gameSettings.renderDistanceChunks * Constants.CHUNK_SIZE - Constants.SCAN_INITIAL_RADIUS; + return Minecraft.getMinecraft().gameSettings.renderDistanceChunks * Constants.CHUNK_SIZE + - Constants.SCAN_INITIAL_RADIUS; } public static int computeScanGrowthDuration() { - return Constants.SCAN_GROWTH_DURATION * Minecraft.getMinecraft().gameSettings.renderDistanceChunks / Constants.REFERENCE_RENDER_DISTANCE; + return Constants.SCAN_GROWTH_DURATION * Minecraft.getMinecraft().gameSettings.renderDistanceChunks + / Constants.REFERENCE_RENDER_DISTANCE; } public static float computeRadius(final long start, final float duration) { // Scan wave speeds up exponentially. To avoid the initial speed being // near zero due to that we offset the time and adjust the remaining // parameters accordingly. Base equation is: - // r = a + (t + b)^2 * c + // r = a + (t + b)^2 * c // with r := 0 and target radius and t := 0 and target time this yields: - // c = r1/((t1 + b)^2 - b*b) - // a = -r1*b*b/((t1 + b)^2 - b*b) + // c = r1/((t1 + b)^2 - b*b) + // a = -r1*b*b/((t1 + b)^2 - b*b) final float r1 = (float) computeTargetRadius(); final float t1 = duration; @@ -91,13 +94,14 @@ public void beginScan(final EntityPlayer player, final List modules) float scanRadius = Settings.getBaseScanRadius(); for (final ItemStack module : modules) { - final ScanResultProvider provider = module.getCapability(CapabilityScanResultProvider.SCAN_RESULT_PROVIDER_CAPABILITY, null); + final ScanResultProvider provider = module + .getCapability(CapabilityScanResultProvider.SCAN_RESULT_PROVIDER_CAPABILITY, null); if (provider != null) { collectingProviders.add(provider); } if (Items.isModuleRange(module)) { - scanRadius += MathHelper.ceil(Settings.getBaseScanRadius() / 2f); + scanRadius += MathHelper.ceil(Settings.getBaseScanRadius() / 2f) * module.getCount(); } } @@ -120,7 +124,8 @@ public void updateScan(final Entity entity, final boolean finish) { } for (final ScanResultProvider provider : collectingProviders) { - provider.computeScanResults(result -> collectingResults.computeIfAbsent(provider, p -> new ArrayList<>()).add(result)); + provider.computeScanResults( + result -> collectingResults.computeIfAbsent(provider, p -> new ArrayList<>()).add(result)); } ++scanningTicks; @@ -130,7 +135,8 @@ public void updateScan(final Entity entity, final boolean finish) { for (int i = 0; i < remaining; i++) { for (final ScanResultProvider provider : collectingProviders) { - provider.computeScanResults(result -> collectingResults.computeIfAbsent(provider, p -> new ArrayList<>()).add(result)); + provider.computeScanResults( + result -> collectingResults.computeIfAbsent(provider, p -> new ArrayList<>()).add(result)); } } @@ -144,7 +150,8 @@ public void updateScan(final Entity entity, final boolean finish) { currentStart = System.currentTimeMillis(); pendingResults.putAll(collectingResults); - pendingResults.values().forEach(list -> list.sort(Comparator.comparing(result -> -lastScanCenter.distanceTo(result.getPosition())))); + pendingResults.values().forEach( + list -> list.sort(Comparator.comparing(result -> -lastScanCenter.distanceTo(result.getPosition())))); ScannerRenderer.INSTANCE.ping(lastScanCenter); @@ -166,12 +173,13 @@ public void onClientTick(final TickEvent.ClientTickEvent event) { if (lastScanCenter == null || currentStart < 0) { return; } - - if (Constants.SCAN_STAY_DURATION < (int) (System.currentTimeMillis() - currentStart)) { + final int duration = ClientSettings.scanStayDuration; + if (duration < (int) (System.currentTimeMillis() - currentStart) && duration != -1) { pendingResults.clear(); synchronized (renderingResults) { if (!renderingResults.isEmpty()) { - for (Iterator>> iterator = renderingResults.entrySet().iterator(); iterator.hasNext(); ) { + for (Iterator>> iterator = renderingResults + .entrySet().iterator(); iterator.hasNext();) { final Map.Entry> entry = iterator.next(); final List list = entry.getValue(); for (int i = MathHelper.ceil(list.size() / 2f); i > 0; i--) { @@ -257,7 +265,8 @@ public void onPreRenderGameOverlay(final RenderGameOverlayEvent.Pre event) { return; } - // Using shaders so we render as game overlay; restore matrices as used for world rendering. + // Using shaders so we render as game overlay; restore matrices as used for + // world rendering. GlStateManager.matrixMode(GL11.GL_PROJECTION); GlStateManager.pushMatrix(); GlStateManager.matrixMode(GL11.GL_MODELVIEW); diff --git a/src/main/java/li/cil/scannable/client/gui/GuiScanner.java b/src/main/java/li/cil/scannable/client/gui/GuiScanner.java index 43a0737..608aae1 100644 --- a/src/main/java/li/cil/scannable/client/gui/GuiScanner.java +++ b/src/main/java/li/cil/scannable/client/gui/GuiScanner.java @@ -13,7 +13,8 @@ import net.minecraft.util.ResourceLocation; public class GuiScanner extends GuiContainer { - private static final ResourceLocation BACKGROUND = new ResourceLocation(API.MOD_ID, "textures/gui/container/scanner.png"); + private static final ResourceLocation BACKGROUND = new ResourceLocation(API.MOD_ID, + "textures/gui/container/scanner.png"); // --------------------------------------------------------------------- // @@ -34,13 +35,17 @@ public GuiScanner(final ContainerScanner container) { public void drawScreen(final int mouseX, final int mouseY, final float partialTicks) { super.drawScreen(mouseX, mouseY, partialTicks); - if (isPointInRegion(8, 23, fontRenderer.getStringWidth(I18n.format(Constants.GUI_SCANNER_MODULES)), fontRenderer.FONT_HEIGHT, mouseX, mouseY)) { + if (isPointInRegion(8, 23, fontRenderer.getStringWidth(I18n.format(Constants.GUI_SCANNER_MODULES)), + fontRenderer.FONT_HEIGHT, mouseX, mouseY)) { drawHoveringText(I18n.format(Constants.GUI_SCANNER_MODULES_TOOLTIP), mouseX, mouseY); } - if (isPointInRegion(8, 49, fontRenderer.getStringWidth(I18n.format(Constants.GUI_SCANNER_MODULES_INACTIVE)), fontRenderer.FONT_HEIGHT, mouseX, mouseY)) { + if (isPointInRegion(8, 49, fontRenderer.getStringWidth(I18n.format(Constants.GUI_SCANNER_MODULES_INACTIVE)), + fontRenderer.FONT_HEIGHT, mouseX, mouseY)) { drawHoveringText(I18n.format(Constants.GUI_SCANNER_MODULES_INACTIVE_TOOLTIP), mouseX, mouseY); } - + if (isPointInRegion(44 + 6 * 18, 20, 18, 18, mouseX, mouseY)) { + drawHoveringText(I18n.format(Constants.GUI_SCANNER_MODULES_RANGE_TOOLTIP), mouseX, mouseY); + } this.renderHoveredToolTip(mouseX, mouseY); } diff --git a/src/main/java/li/cil/scannable/common/config/ClientSettings.java b/src/main/java/li/cil/scannable/common/config/ClientSettings.java new file mode 100644 index 0000000..77a4157 --- /dev/null +++ b/src/main/java/li/cil/scannable/common/config/ClientSettings.java @@ -0,0 +1,31 @@ +package li.cil.scannable.common.config; + +import li.cil.scannable.api.API; +import li.cil.scannable.client.scanning.ScanResultProviderBlock; +import net.minecraft.block.Block; +import net.minecraft.init.Blocks; +import net.minecraft.util.ResourceLocation; +import net.minecraftforge.common.config.Config; +import net.minecraftforge.fml.common.registry.ForgeRegistries; + +import javax.annotation.Nullable; +import java.util.HashSet; +import java.util.Set; + +@Config(modid = API.MOD_ID, category = "client", name = "scannable-Client") +public final class ClientSettings { + @Config.LangKey(Constants.CONFIG_SCAN_STAY_DURATION) + @Config.Comment("How long the results from a scan should remain visible (in milliseconds).") + @Config.RangeInt(min = -1) + public static int scanStayDuration = 10000; + + /* + * public static int getScanStayDuration() { + * return serverSettings != null ? serverSettings.scanStayDuration : + * scanStayDuration; + * } + */ + + private ClientSettings() { + } +} \ No newline at end of file diff --git a/src/main/java/li/cil/scannable/common/config/Constants.java b/src/main/java/li/cil/scannable/common/config/Constants.java index bcb482e..5d8b30d 100644 --- a/src/main/java/li/cil/scannable/common/config/Constants.java +++ b/src/main/java/li/cil/scannable/common/config/Constants.java @@ -52,6 +52,7 @@ public final class Constants { public static final String CONFIG_FLUID_BLACKLIST = "config.scannable.fluidBlacklist"; public static final String CONFIG_FLUID_COLORS = "config.scannable.fluidColors"; public static final String CONFIG_LOG_BLOCK_DROP_LOOKUP_FAILURES = "config.scannable.logBlockDropLookupFailures"; + public static final String CONFIG_SCAN_STAY_DURATION = "config.scannable.scanStayDuration"; // --------------------------------------------------------------------- // // GUI labels @@ -61,6 +62,8 @@ public final class Constants { public static final String GUI_SCANNER_MODULES_TOOLTIP = "gui.scannable.scanner.modules.tooltip"; public static final String GUI_SCANNER_MODULES_INACTIVE = "gui.scannable.scanner.modules_inactive"; public static final String GUI_SCANNER_MODULES_INACTIVE_TOOLTIP = "gui.scannable.scanner.modules_inactive.tooltip"; + public static final String GUI_SCANNER_MODULES_RANGE = "gui.scannable.scanner.modules_range"; + public static final String GUI_SCANNER_MODULES_RANGE_TOOLTIP = "gui.scannable.scanner.modules_range.tooltip"; public static final String GUI_SCANNER_PROGRESS = "gui.scannable.scanner.progress"; public static final String GUI_OVERLAY_LABEL_DISTANCE = "gui.scannable.overlay.entity_details"; @@ -116,8 +119,10 @@ public final class Constants { public static final int SCANNER_ACTIVE_MODULE_COUNT = 3; // Number of additional modules that can be stored in a scanner. public static final int SCANNER_INACTIVE_MODULE_COUNT = 6; + // Number of range modules that can be stored in a scanner. + public static final int SCANNER_RANGE_MODULE_COUNT = 1; // Total number of modules that can be placed in a scanner. - public static final int SCANNER_TOTAL_MODULE_COUNT = SCANNER_ACTIVE_MODULE_COUNT + SCANNER_INACTIVE_MODULE_COUNT; + public static final int SCANNER_TOTAL_MODULE_COUNT = SCANNER_ACTIVE_MODULE_COUNT + SCANNER_INACTIVE_MODULE_COUNT + SCANNER_RANGE_MODULE_COUNT; // By how much to scale the base scan range when scanning for ores. public static final float MODULE_ORE_RADIUS_MULTIPLIER = 0.25f; // By how much to scale the base scan range when scanning for specific blocks. diff --git a/src/main/java/li/cil/scannable/common/config/Settings.java b/src/main/java/li/cil/scannable/common/config/Settings.java index fe69e1d..18131a2 100644 --- a/src/main/java/li/cil/scannable/common/config/Settings.java +++ b/src/main/java/li/cil/scannable/common/config/Settings.java @@ -12,11 +12,11 @@ import java.util.HashSet; import java.util.Set; -@Config(modid = API.MOD_ID) +@Config(modid = API.MOD_ID, name = "scannable-Common") public final class Settings { @Config.LangKey(Constants.CONFIG_USE_ENERGY) @Config.Comment("Whether to consume energy when performing a scan.\n" + - "Will make the scanner a chargeable item.") + "Will make the scanner a chargeable item.") @Config.RequiresWorldRestart public static boolean useEnergy = true; @@ -82,10 +82,11 @@ public final class Settings { @Config.LangKey(Constants.CONFIG_BASE_SCAN_RADIUS) @Config.Comment("The basic scan radius without range modules.\n" + - "IMPORTANT: some modules such as the block and ore scanner modules will already use\n" + - "a reduced radius based on this value. Specifically, the ore scanners multiply this\n" + - "value by " + Constants.MODULE_ORE_RADIUS_MULTIPLIER + ", and the block scanner multiplies it by " + Constants.MODULE_BLOCK_RADIUS_MULTIPLIER + ".\n" + - "Range modules will boost the range by half this value.") + "IMPORTANT: some modules such as the block and ore scanner modules will already use\n" + + "a reduced radius based on this value. Specifically, the ore scanners multiply this\n" + + "value by " + Constants.MODULE_ORE_RADIUS_MULTIPLIER + ", and the block scanner multiplies it by " + + Constants.MODULE_BLOCK_RADIUS_MULTIPLIER + ".\n" + + "Range modules will boost the range by half this value.") @Config.RangeInt(min = 16, max = 128) @Config.RequiresWorldRestart public static int baseScanRadius = 64; @@ -105,7 +106,7 @@ public final class Settings { @Config.LangKey(Constants.CONFIG_ORES_COMMON) @Config.Comment("Ore dictionary entries considered common ores, requiring the common ore scanner module.\n" + - "Use this to mark ores as common, as opposed to rare (see oresRare).") + "Use this to mark ores as common, as opposed to rare (see oresRare).") @Config.RequiresWorldRestart public static String[] oresCommon = { // Minecraft @@ -129,43 +130,43 @@ public final class Settings { @Config.LangKey(Constants.CONFIG_ORES_RARE) @Config.Comment("Ore dictionary names of ores considered 'rare', requiring the rare ore scanner module.\n" + - "Anything matching /ore[A-Z].*/ that isn't in the common ore list is\n" + - "automatically considered a rare ore (as opposed to the other way around,\n" + - "to make missing entries less likely be a problem). Use this to add rare\n" + - "ores that do follow this pattern.") + "Anything matching /ore[A-Z].*/ that isn't in the common ore list is\n" + + "automatically considered a rare ore (as opposed to the other way around,\n" + + "to make missing entries less likely be a problem). Use this to add rare\n" + + "ores that do follow this pattern.") @Config.RequiresWorldRestart public static String[] oresRare = { }; @Config.LangKey(Constants.CONFIG_STATES_COMMON) @Config.Comment("Block states considered common ores, requiring the common ore scanner module.\n" + - "Use this to mark arbitrary block states as common ores. Format is as follows:\n" + - " mod_id:block_name\n" + - "or with block properties:\n" + - " mod_id:block_name[property1=value1,property2=value2]\n" + - "You can look up the properties (as well as name and mod id) in the F3 debug overlay\n" + - "in the bottom right.") + "Use this to mark arbitrary block states as common ores. Format is as follows:\n" + + " mod_id:block_name\n" + + "or with block properties:\n" + + " mod_id:block_name[property1=value1,property2=value2]\n" + + "You can look up the properties (as well as name and mod id) in the F3 debug overlay\n" + + "in the bottom right.") @Config.RequiresWorldRestart public static String[] statesCommon = { }; @Config.LangKey(Constants.CONFIG_STATES_RARE) @Config.Comment("Block states considered rare ores, requiring the rare ore scanner module.\n" + - "Use this to mark arbitrary block states as rare ores. Format is as follows:\n" + - " mod_id:block_name\n" + - "or with block properties:\n" + - " mod_id:block_name[property1=value1,property2=value2]\n" + - "You can look up the properties (as well as name and mod id) in the F3 debug overlay\n" + - "in the bottom right.") + "Use this to mark arbitrary block states as rare ores. Format is as follows:\n" + + " mod_id:block_name\n" + + "or with block properties:\n" + + " mod_id:block_name[property1=value1,property2=value2]\n" + + "You can look up the properties (as well as name and mod id) in the F3 debug overlay\n" + + "in the bottom right.") @Config.RequiresWorldRestart public static String[] statesRare = { }; @Config.LangKey(Constants.CONFIG_ORE_COLORS) @Config.Comment("The colors for ores used when rendering their result bounding box.\n" + - "Each entry must be a key-value pair separated by a `=`, with the.\n" + - "key being the ore dictionary name and the value being the hexadecimal\n" + - "RGB value of the color.") + "Each entry must be a key-value pair separated by a `=`, with the.\n" + + "key being the ore dictionary name and the value being the hexadecimal\n" + + "RGB value of the color.") @Config.RequiresWorldRestart public static String[] oreColors = { // Minecraft @@ -231,7 +232,7 @@ public final class Settings { @Config.LangKey(Constants.CONFIG_FLUID_COLORS) @Config.Comment("The colors for fluids used when rendering their result bounding box.\n" + - "See `oreColors` for format entries have to be in.") + "See `oreColors` for format entries have to be in.") @Config.RequiresWorldRestart public static String[] fluidColors = { "water=0x4275DC", @@ -240,25 +241,25 @@ public final class Settings { @Config.LangKey(Constants.CONFIG_INJECT_DEPTH_TEXTURE) @Config.Comment("Whether to try to inject a depth texture into Minecraft's FBO when rendering the\n" + - "scan wave effect. This is much faster as it will not have to re-render the world\n" + - "geometry to retrieve the depth information required for the effect. However, it\n" + - "appears that on some systems this doesn't work. The mod tries to detect that and\n" + - "will fall back to re-rendering automatically, but you can force re-rendering by\n" + - "setting this to false, e.g. for debugging or just to avoid the one logged warning.") + "scan wave effect. This is much faster as it will not have to re-render the world\n" + + "geometry to retrieve the depth information required for the effect. However, it\n" + + "appears that on some systems this doesn't work. The mod tries to detect that and\n" + + "will fall back to re-rendering automatically, but you can force re-rendering by\n" + + "setting this to false, e.g. for debugging or just to avoid the one logged warning.") public static boolean injectDepthTexture = true; @Config.LangKey(Constants.CONFIG_LOG_BLOCK_DROP_LOOKUP_FAILURES) @Config.Comment("Whether to log out failure to determine the item stack dropped by a block.\n" + - "Scannable needs to find the item stack representation of a block to get the\n" + - "ore dictionary name(s) of blocks, as well as to show a more accurate tooltip\n" + - "of the currently bound block in the block module. Scannable attempts to find\n" + - "the item stack representation by calling Block.getPickBlock (which is allowed\n" + - "to fail, as some blocks require a valid world state) and alternatively by using\n " + - "Item.getItemFromBlock+Block.damageDropped, the latter being verified using the\n" + - "roundtrip through Block.damageDropped/Item.getMetadata/Block.getStateFromMeta.\n" + - "Sadly this fails for a lot of modded blocks because people rarely implement\n" + - "Block.damageDropped. As a workaround you can add blocks for which this fails to\n" + - "the `statesCommon` and `statesRare` lists.") + "Scannable needs to find the item stack representation of a block to get the\n" + + "ore dictionary name(s) of blocks, as well as to show a more accurate tooltip\n" + + "of the currently bound block in the block module. Scannable attempts to find\n" + + "the item stack representation by calling Block.getPickBlock (which is allowed\n" + + "to fail, as some blocks require a valid world state) and alternatively by using\n " + + "Item.getItemFromBlock+Block.damageDropped, the latter being verified using the\n" + + "roundtrip through Block.damageDropped/Item.getMetadata/Block.getStateFromMeta.\n" + + "Sadly this fails for a lot of modded blocks because people rarely implement\n" + + "Block.damageDropped. As a workaround you can add blocks for which this fails to\n" + + "the `statesCommon` and `statesRare` lists.") public static boolean logBlockDropLookupFailures = false; // --------------------------------------------------------------------- // diff --git a/src/main/java/li/cil/scannable/common/container/ContainerScanner.java b/src/main/java/li/cil/scannable/common/container/ContainerScanner.java index 03acc1a..7982c77 100644 --- a/src/main/java/li/cil/scannable/common/container/ContainerScanner.java +++ b/src/main/java/li/cil/scannable/common/container/ContainerScanner.java @@ -35,6 +35,11 @@ public ContainerScanner(final EntityPlayer player, final EnumHand hand) { addSlotToContainer(new SlotItemHandler(storedModules, slot, 62 + slot * 18, 46)); } + final IItemHandler rangeModules = ((ItemHandlerScanner) itemHandler).getRangeModules(); + for (int slot = 0; slot < rangeModules.getSlots(); ++slot) { + addSlotToContainer(new SlotItemHandler(rangeModules, slot, 44 + 6 * 18, 20)); + } + for (int row = 0; row < 3; ++row) { for (int col = 0; col < 9; ++col) { addSlotToContainer(new Slot(player.inventory, col + row * 9 + 9, 8 + col * 18, row * 18 + 77)); diff --git a/src/main/java/li/cil/scannable/common/inventory/ItemHandlerScanner.java b/src/main/java/li/cil/scannable/common/inventory/ItemHandlerScanner.java index 3b7fa40..a854e1a 100644 --- a/src/main/java/li/cil/scannable/common/inventory/ItemHandlerScanner.java +++ b/src/main/java/li/cil/scannable/common/inventory/ItemHandlerScanner.java @@ -44,7 +44,11 @@ public IItemHandler getActiveModules() { } public IItemHandler getInactiveModules() { - return new RangedWrapper(this, Constants.SCANNER_ACTIVE_MODULE_COUNT, Constants.SCANNER_TOTAL_MODULE_COUNT); + return new RangedWrapper(this, Constants.SCANNER_ACTIVE_MODULE_COUNT, Constants.SCANNER_ACTIVE_MODULE_COUNT + Constants.SCANNER_INACTIVE_MODULE_COUNT); + } + + public IItemHandler getRangeModules() { + return new RangedWrapper(this, Constants.SCANNER_ACTIVE_MODULE_COUNT + Constants.SCANNER_INACTIVE_MODULE_COUNT, Constants.SCANNER_TOTAL_MODULE_COUNT); } // --------------------------------------------------------------------- // @@ -56,7 +60,17 @@ protected int getStackLimit(final int slot, @Nonnull final ItemStack stack) { return 0; } if (stack.getItem() instanceof AbstractItemScannerModule) { - return 64; + // Check if this is a range module and if it's in the range module slot + if (stack.getItem().getRegistryName().toString().endsWith(Constants.NAME_MODULE_RANGE) && + slot >= Constants.SCANNER_ACTIVE_MODULE_COUNT + Constants.SCANNER_INACTIVE_MODULE_COUNT) { + return 64; + } + // For non-range modules, only allow them in non-range slots + if (!stack.getItem().getRegistryName().toString().endsWith(Constants.NAME_MODULE_RANGE) && + slot < Constants.SCANNER_ACTIVE_MODULE_COUNT + Constants.SCANNER_INACTIVE_MODULE_COUNT) { + return 64; + } + return 0; } if (stack.hasCapability(CapabilityScanResultProvider.SCAN_RESULT_PROVIDER_CAPABILITY, null)) { return 64; diff --git a/src/main/java/li/cil/scannable/common/item/ItemScanner.java b/src/main/java/li/cil/scannable/common/item/ItemScanner.java index 67c4a86..da97f88 100644 --- a/src/main/java/li/cil/scannable/common/item/ItemScanner.java +++ b/src/main/java/li/cil/scannable/common/item/ItemScanner.java @@ -38,12 +38,13 @@ import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; import net.minecraftforge.items.CapabilityItemHandler; import net.minecraftforge.items.IItemHandler; +import net.minecraftforge.items.IItemHandlerModifiable; +import net.minecraftforge.items.wrapper.CombinedInvWrapper; import javax.annotation.Nullable; import java.util.ArrayList; import java.util.List; - @Optional.Interface(iface = "cofh.redstoneflux.api.IEnergyContainerItem", modid = ModIDs.RedstoneFlux) public final class ItemScanner extends Item implements IEnergyContainerItem { public ItemScanner() { @@ -77,7 +78,8 @@ public void getSubItems(final CreativeTabs tab, final NonNullList ite } @Override - public void addInformation(final ItemStack stack, @Nullable final World world, final List tooltip, final ITooltipFlag flag) { + public void addInformation(final ItemStack stack, @Nullable final World world, final List tooltip, + final ITooltipFlag flag) { super.addInformation(stack, world, tooltip, flag); tooltip.add(I18n.format(Constants.TOOLTIP_SCANNER)); @@ -91,7 +93,8 @@ public void addInformation(final ItemStack stack, @Nullable final World world, f return; } - tooltip.add(I18n.format(Constants.TOOLTIP_SCANNER_ENERGY, energyStorage.getEnergyStored(), energyStorage.getMaxEnergyStored())); + tooltip.add(I18n.format(Constants.TOOLTIP_SCANNER_ENERGY, energyStorage.getEnergyStored(), + energyStorage.getMaxEnergyStored())); } @Override @@ -122,7 +125,8 @@ public ActionResult onItemRightClick(final World world, final EntityP final List modules = new ArrayList<>(); if (!collectModules(stack, modules)) { if (world.isRemote) { - Minecraft.getMinecraft().ingameGUI.getChatGUI().printChatMessageWithOptionalDeletion(new TextComponentTranslation(Constants.MESSAGE_NO_SCAN_MODULES), Constants.CHAT_LINE_ID); + Minecraft.getMinecraft().ingameGUI.getChatGUI().printChatMessageWithOptionalDeletion( + new TextComponentTranslation(Constants.MESSAGE_NO_SCAN_MODULES), Constants.CHAT_LINE_ID); } player.getCooldownTracker().setCooldown(this, 10); return new ActionResult<>(EnumActionResult.FAIL, stack); @@ -130,7 +134,8 @@ public ActionResult onItemRightClick(final World world, final EntityP if (!tryConsumeEnergy(player, stack, modules, true)) { if (world.isRemote) { - Minecraft.getMinecraft().ingameGUI.getChatGUI().printChatMessageWithOptionalDeletion(new TextComponentTranslation(Constants.MESSAGE_NOT_ENOUGH_ENERGY), Constants.CHAT_LINE_ID); + Minecraft.getMinecraft().ingameGUI.getChatGUI().printChatMessageWithOptionalDeletion( + new TextComponentTranslation(Constants.MESSAGE_NOT_ENOUGH_ENERGY), Constants.CHAT_LINE_ID); } player.getCooldownTracker().setCooldown(this, 10); return new ActionResult<>(EnumActionResult.FAIL, stack); @@ -146,7 +151,8 @@ public ActionResult onItemRightClick(final World world, final EntityP } @Override - public boolean shouldCauseReequipAnimation(final ItemStack oldStack, final ItemStack newStack, final boolean slotChanged) { + public boolean shouldCauseReequipAnimation(final ItemStack oldStack, final ItemStack newStack, + final boolean slotChanged) { return oldStack.getItem() != newStack.getItem() || slotChanged; } @@ -163,7 +169,8 @@ public void onUsingTick(final ItemStack stack, final EntityLivingBase entity, fi } @Override - public void onPlayerStoppedUsing(final ItemStack stack, final World world, final EntityLivingBase entity, final int timeLeft) { + public void onPlayerStoppedUsing(final ItemStack stack, final World world, final EntityLivingBase entity, + final int timeLeft) { if (world.isRemote) { ScanManager.INSTANCE.cancelScan(); SoundManager.INSTANCE.stopChargingSound(); @@ -207,19 +214,21 @@ public ItemStack onItemUseFinish(final ItemStack stack, final World world, final // --------------------------------------------------------------------- // static int getModuleEnergyCost(final EntityPlayer player, final ItemStack module) { - final ScanResultProvider provider = module.getCapability(CapabilityScanResultProvider.SCAN_RESULT_PROVIDER_CAPABILITY, null); + final ScanResultProvider provider = module + .getCapability(CapabilityScanResultProvider.SCAN_RESULT_PROVIDER_CAPABILITY, null); if (provider != null) { return provider.getEnergyCost(player, module); } if (Items.isModuleRange(module)) { - return Settings.getEnergyCostModuleRange(); + return Settings.getEnergyCostModuleRange() * module.getCount(); } return 0; } - private static boolean tryConsumeEnergy(final EntityPlayer player, final ItemStack stack, final List modules, final boolean simulate) { + private static boolean tryConsumeEnergy(final EntityPlayer player, final ItemStack stack, + final List modules, final boolean simulate) { if (!Settings.useEnergy()) { return true; } @@ -251,8 +260,12 @@ private static boolean collectModules(final ItemStack stack, final List