Skip to content
Open
Show file tree
Hide file tree
Changes from all 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: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
}

Expand Down Expand Up @@ -144,4 +144,4 @@ idea {
module {
outputDir = file('build/classes/main')
}
}
}
35 changes: 22 additions & 13 deletions src/main/java/li/cil/scannable/client/ScanManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -91,7 +94,8 @@ public void beginScan(final EntityPlayer player, final List<ItemStack> 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);
}
Expand Down Expand Up @@ -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;
Expand All @@ -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));
}
}

Expand All @@ -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);

Expand All @@ -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<Map.Entry<ScanResultProvider, List<ScanResult>>> iterator = renderingResults.entrySet().iterator(); iterator.hasNext(); ) {
for (Iterator<Map.Entry<ScanResultProvider, List<ScanResult>>> iterator = renderingResults
.entrySet().iterator(); iterator.hasNext();) {
final Map.Entry<ScanResultProvider, List<ScanResult>> entry = iterator.next();
final List<ScanResult> list = entry.getValue();
for (int i = MathHelper.ceil(list.size() / 2f); i > 0; i--) {
Expand Down Expand Up @@ -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);
Expand Down
31 changes: 31 additions & 0 deletions src/main/java/li/cil/scannable/common/config/ClientSettings.java
Original file line number Diff line number Diff line change
@@ -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() {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
85 changes: 43 additions & 42 deletions src/main/java/li/cil/scannable/common/config/Settings.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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",
Expand All @@ -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;

// --------------------------------------------------------------------- //
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/assets/scannable/lang/en_US.lang
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,4 @@ config.scannable.injectDepthTexture=Inject Depth Texture
config.scannable.fluidBlacklist=Blacklist: Fluids
config.scannable.fluidColors=Fluid Colors
config.scannable.logBlockDropLookupFailures=Log item lookup failures
config.scannable.scanStayDuration=Scan result retention time
Loading