From 7836eea57a199661e1ac4b41d9ae678e62588ee2 Mon Sep 17 00:00:00 2001 From: YannickMG Date: Wed, 6 Jul 2022 15:35:36 -0400 Subject: Enhanced NEI discoverability (#17) * Removed unused code * Addressed IDE warnings * Refactored PluginGT5VeinStat::loadCraftingRecipes for readability * Refactored PluginGT5VeinStat::drawExtras for readability * Added OreVeinLayer class for the concept of ore layer * Updated buildscript * Ran spotlessApply * Addressed some trivial IDE warnings * Load both Small Ores and regular Ores when either is queried. * Refactored PluginGT5SmallOreStat::loadCraftingRecipes for readability * Refactored PluginGT5SmallOreStat::drawExtras for readability --- build.gradle | 223 ++++++++++++++++-- dependencies.gradle | 8 +- repositories.gradle | 36 +-- .../java/pers/gwyog/gtneioreplugin/Config.java | 7 +- .../pers/gwyog/gtneioreplugin/GTNEIOrePlugin.java | 34 ++- .../gwyog/gtneioreplugin/plugin/PluginBase.java | 7 +- .../plugin/gregtech5/PluginGT5Base.java | 76 +++--- .../plugin/gregtech5/PluginGT5SmallOreStat.java | 143 +++++++----- .../plugin/gregtech5/PluginGT5VeinStat.java | 257 +++++++-------------- .../pers/gwyog/gtneioreplugin/util/CSVMaker.java | 38 +-- .../gwyog/gtneioreplugin/util/DimensionHelper.java | 206 +++++++++-------- .../gwyog/gtneioreplugin/util/GT5CFGHelper.java | 109 +++++---- .../gtneioreplugin/util/GT5OreLayerHelper.java | 47 ++-- .../gtneioreplugin/util/GT5OreSmallHelper.java | 83 ++++--- .../gwyog/gtneioreplugin/util/GuiRecipeHelper.java | 31 ++- .../gwyog/gtneioreplugin/util/OreVeinLayer.java | 21 ++ .../pers/gwyog/gtneioreplugin/util/Oremix.java | 49 +++- .../gtneioreplugin/util/StringPaddingHack.java | 38 +-- .../gwyog/gtneioreplugin/util/Veinrenamer.java | 4 +- .../pers/gwyog/gtneioreplugin/util/XtoBool.java | 12 +- 20 files changed, 838 insertions(+), 591 deletions(-) create mode 100644 src/main/java/pers/gwyog/gtneioreplugin/util/OreVeinLayer.java diff --git a/build.gradle b/build.gradle index d90db129d1..e182c451c6 100644 --- a/build.gradle +++ b/build.gradle @@ -1,4 +1,4 @@ -//version: 1646409286 +//version: 1656760175 /* DO NOT CHANGE THIS FILE! @@ -12,7 +12,12 @@ import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar import org.gradle.internal.logging.text.StyledTextOutput.Style import org.gradle.internal.logging.text.StyledTextOutputFactory +import java.nio.file.Files +import java.nio.file.Paths import java.util.concurrent.TimeUnit +import java.util.zip.ZipEntry +import java.util.zip.ZipInputStream +import java.util.zip.ZipOutputStream buildscript { repositories { @@ -44,13 +49,15 @@ plugins { id 'eclipse' id 'scala' id 'maven-publish' - id 'org.jetbrains.kotlin.jvm' version '1.5.30' apply false - id 'org.jetbrains.kotlin.kapt' version '1.5.30' apply false + id 'org.jetbrains.kotlin.jvm' version '1.5.30' apply false + id 'org.jetbrains.kotlin.kapt' version '1.5.30' apply false + id 'com.google.devtools.ksp' version '1.5.30-1.0.0' apply false id 'org.ajoberstar.grgit' version '4.1.1' id 'com.github.johnrengelman.shadow' version '4.0.4' - id 'com.palantir.git-version' version '0.13.0' apply false + id 'com.palantir.git-version' version '0.13.0' apply false id 'de.undercouch.download' version '5.0.1' - id 'com.github.gmazzo.buildconfig' version '3.0.3' apply false + id 'com.github.gmazzo.buildconfig' version '3.0.3' apply false + id "com.diffplug.spotless" version "6.7.2" } if (project.file('.git/HEAD').isFile()) { @@ -77,6 +84,37 @@ idea { } } +// Spotless autoformatter +// See https://github.com/diffplug/spotless/tree/main/plugin-gradle +// Can be locally toggled via spotless:off/spotless:on comments +spotless { + encoding 'UTF-8' + + format 'misc', { + target '.gitignore' + + trimTrailingWhitespace() + indentWithSpaces(4) + endWithNewline() + } + java { + toggleOffOn() + importOrder() + removeUnusedImports() + palantirJavaFormat('1.1.0') // last version supporting jvm 8 + } + kotlin { + toggleOffOn() + ktfmt('0.39') + } + groovyGradle { + toggleOffOn() + importOrder() + target '*.gradle' + greclipse('4.19.0') // last version supporting jvm 8 + } +} + if(JavaVersion.current() != JavaVersion.VERSION_1_8) { throw new GradleException("This project requires Java 8, but it's running on " + JavaVersion.current()) } @@ -104,6 +142,9 @@ checkPropertyExists("developmentEnvironmentUserName") boolean noPublishedSources = project.findProperty("noPublishedSources") ? project.noPublishedSources.toBoolean() : false boolean usesMixinDebug = project.findProperty('usesMixinDebug') ?: project.usesMixins.toBoolean() +String channel = project.findProperty('channel') ? project.channel : 'stable' +String mappingsVersion = project.findProperty('mappingsVersion') ? project.mappingsVersion : '12' +String remoteMappings = project.findProperty('remoteMappings') ? project.remoteMappings : 'https://raw.githubusercontent.com/MinecraftForge/FML/1.7.10/conf/' String javaSourceDir = "src/main/java/" String scalaSourceDir = "src/main/scala/" @@ -568,7 +609,7 @@ publishing { artifact source: shadowJar, classifier: "" } if(!noPublishedSources) { - artifact source: sourcesJar, classifier: "src" + artifact source: sourcesJar, classifier: "sources" } artifact source: usesShadowedDependencies.toBoolean() ? shadowDevJar : devJar, classifier: "dev" if (apiPackage) { @@ -668,7 +709,103 @@ configure(updateBuildScript) { description = 'Updates the build script to the latest version' } -// Deobfuscation +// Parameter Deobfuscation + +task deobfParams { + doLast { + + String mcpDir = "$project.gradle.gradleUserHomeDir/caches/minecraft/de/oceanlabs/mcp/mcp_$channel/$mappingsVersion" + String mcpZIP = "$mcpDir/mcp_$channel-$mappingsVersion-${minecraftVersion}.zip" + String paramsCSV = "$mcpDir/params.csv" + + download.run { + src "https://maven.minecraftforge.net/de/oceanlabs/mcp/mcp_$channel/$mappingsVersion-$minecraftVersion/mcp_$channel-$mappingsVersion-${minecraftVersion}.zip" + dest mcpZIP + overwrite false + } + + if(!file(paramsCSV).exists()) { + println("Extracting MCP archive ...") + unzip(mcpZIP, mcpDir) + } + + println("Parsing params.csv ...") + Map params = new HashMap<>() + Files.lines(Paths.get(paramsCSV)).forEach{line -> + String[] cells = line.split(",") + if(cells.length > 2 && cells[0].matches("p_i?\\d+_\\d+_")) { + params.put(cells[0], cells[1]) + } + } + + out.style(Style.Success).println("Modified ${replaceParams(file("$projectDir/src/main/java"), params)} files!") + out.style(Style.Failure).println("Don't forget to verify that the code still works as before!\n It could be broken due to duplicate variables existing now\n or parameters taking priority over other variables.") + } +} + +static int replaceParams(File file, Map params) { + int fileCount = 0 + + if(file.isDirectory()) { + for(File f : file.listFiles()) { + fileCount += replaceParams(f, params) + } + return fileCount + } + println("Visiting ${file.getName()} ...") + try { + String content = new String(Files.readAllBytes(file.toPath())) + int hash = content.hashCode() + params.forEach{key, value -> + content = content.replaceAll(key, value) + } + if(hash != content.hashCode()) { + Files.write(file.toPath(), content.getBytes("UTF-8")) + return 1 + } + } catch(Exception e) { + e.printStackTrace() + } + return 0 +} + +// Credit: bitsnaps (https://gist.github.com/bitsnaps/00947f2dce66f4bbdabc67d7e7b33681) +static unzip(String zipFileName, String outputDir) { + byte[] buffer = new byte[16384] + ZipInputStream zis = new ZipInputStream(new FileInputStream(zipFileName)) + ZipEntry zipEntry = zis.getNextEntry() + while (zipEntry != null) { + File newFile = new File(outputDir + File.separator, zipEntry.name) + if (zipEntry.isDirectory()) { + if (!newFile.isDirectory() && !newFile.mkdirs()) { + throw new IOException("Failed to create directory $newFile") + } + } else { + // fix for Windows-created archives + File parent = newFile.parentFile + if (!parent.isDirectory() && !parent.mkdirs()) { + throw new IOException("Failed to create directory $parent") + } + // write file content + FileOutputStream fos = new FileOutputStream(newFile) + int len = 0 + while ((len = zis.read(buffer)) > 0) { + fos.write(buffer, 0, len) + } + fos.close() + } + zipEntry = zis.getNextEntry() + } + zis.closeEntry() + zis.close() +} + +configure(deobfParams) { + group = 'forgegradle' + description = 'Rename all obfuscated parameter names inherited from Minecraft classes' +} + +// Dependency Deobfuscation def deobf(String sourceURL) { try { @@ -681,7 +818,7 @@ def deobf(String sourceURL) { fileName = fileName.substring(lastSlash + 1) } //get rid of extension: - if(fileName.endsWith(".jar")) { + if(fileName.endsWith(".jar") || fileName.endsWith(".litemod")) { fileName = fileName.substring(0, fileName.lastIndexOf(".")) } @@ -693,26 +830,40 @@ def deobf(String sourceURL) { Collections.reverse(parts) hostName = String.join(".", parts) - return deobf(sourceURL, hostName + "/" + fileName) + return deobf(sourceURL, "$hostName/$fileName") } catch(Exception e) { - return deobf(sourceURL, "deobf/" + String.valueOf(sourceURL.hashCode())) + return deobf(sourceURL, "deobf/${sourceURL.hashCode()}") } } // The method above is to be preferred. Use this method if the filename is not at the end of the URL. -def deobf(String sourceURL, String fileName) { - String cacheDir = System.getProperty("user.home") + "/.gradle/caches/" - String bon2Dir = cacheDir + "forge_gradle/deobf" - String bon2File = bon2Dir + "/BON2-2.5.0.jar" - String obfFile = cacheDir + "modules-2/files-2.1/" + fileName + ".jar" - String deobfFile = cacheDir + "modules-2/files-2.1/" + fileName + "-deobf.jar" +def deobf(String sourceURL, String rawFileName) { + String bon2Version = "2.5.1" + String fileName = URLDecoder.decode(rawFileName, "UTF-8") + String cacheDir = "$project.gradle.gradleUserHomeDir/caches" + String bon2Dir = "$cacheDir/forge_gradle/deobf" + String bon2File = "$bon2Dir/BON2-${bon2Version}.jar" + String obfFile = "$cacheDir/modules-2/files-2.1/${fileName}.jar" + String deobfFile = "$cacheDir/modules-2/files-2.1/${fileName}-deobf.jar" if(file(deobfFile).exists()) { return files(deobfFile) } + String mappingsVer + if(remoteMappings) { + String id = "${forgeVersion.split("\\.")[3]}-$minecraftVersion" + String mappingsZIP = "$cacheDir/forge_gradle/maven_downloader/de/oceanlabs/mcp/mcp_snapshot_nodoc/$id/mcp_snapshot_nodoc-${id}.zip" + + zipMappings(mappingsZIP, remoteMappings, bon2Dir) + + mappingsVer = "snapshot_$id" + } else { + mappingsVer = "${channel}_$mappingsVersion" + } + download.run { - src 'https://github.com/GTNewHorizons/BON2/releases/download/2.5.0/BON2-2.5.0.CUSTOM-all.jar' + src "http://jenkins.usrv.eu:8081/nexus/content/repositories/releases/com/github/parker8283/BON2/$bon2Version-CUSTOM/BON2-$bon2Version-CUSTOM-all.jar" dest bon2File quiet true overwrite false @@ -726,14 +877,48 @@ def deobf(String sourceURL, String fileName) { } exec { - commandLine 'java', '-jar', bon2File, '--inputJar', obfFile, '--outputJar', deobfFile, '--mcVer', '1.7.10', '--mappingsVer', 'stable_12', '--notch' + commandLine 'java', '-jar', bon2File, '--inputJar', obfFile, '--outputJar', deobfFile, '--mcVer', minecraftVersion, '--mappingsVer', mappingsVer, '--notch' workingDir bon2Dir - standardOutput = new ByteArrayOutputStream() + standardOutput = new FileOutputStream("${deobfFile}.log") } return files(deobfFile) } +def zipMappings(String zipPath, String url, String bon2Dir) { + File zipFile = new File(zipPath) + if(zipFile.exists()) { + return + } + + String fieldsCache = "$bon2Dir/data/fields.csv" + String methodsCache = "$bon2Dir/data/methods.csv" + + download.run { + src "${url}fields.csv" + dest fieldsCache + quiet true + } + download.run { + src "${url}methods.csv" + dest methodsCache + quiet true + } + + zipFile.getParentFile().mkdirs() + ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(zipFile)) + + zos.putNextEntry(new ZipEntry("fields.csv")) + Files.copy(Paths.get(fieldsCache), zos) + zos.closeEntry() + + zos.putNextEntry(new ZipEntry("methods.csv")) + Files.copy(Paths.get(methodsCache), zos) + zos.closeEntry() + + zos.close() +} + // Helper methods def checkPropertyExists(String propertyName) { diff --git a/dependencies.gradle b/dependencies.gradle index d8316c045f..9e3d33e5e2 100644 --- a/dependencies.gradle +++ b/dependencies.gradle @@ -1,10 +1,10 @@ // Add your dependencies here dependencies { - compile('com.github.GTNewHorizons:GT5-Unofficial:5.09.40.39:dev') - compile('com.github.GTNewHorizons:NotEnoughItems:2.2.9-GTNH:dev') + compile('com.github.GTNewHorizons:GT5-Unofficial:5.09.40.39:dev') + compile('com.github.GTNewHorizons:NotEnoughItems:2.2.9-GTNH:dev') - compile('net.industrial-craft:industrialcraft-2:2.2.828-experimental:dev') + compile('net.industrial-craft:industrialcraft-2:2.2.828-experimental:dev') - compileOnly('com.opencsv:opencsv:4.0') + compileOnly('com.opencsv:opencsv:4.0') } diff --git a/repositories.gradle b/repositories.gradle index e850975183..f67e7c627d 100644 --- a/repositories.gradle +++ b/repositories.gradle @@ -1,22 +1,22 @@ // Add any additional repositiroes for your dependencies here repositories { - maven { - name 'GTNH Maven' - url 'http://jenkins.usrv.eu:8081/nexus/content/groups/public/' - } - maven { - name 'ic2' - url 'http://maven.ic2.player.to/' - metadataSources { - mavenPom() - artifact() - } - } - maven { - url 'https://cursemaven.com' - content { - includeGroup 'curse.maven' - } - } + maven { + name 'GTNH Maven' + url 'http://jenkins.usrv.eu:8081/nexus/content/groups/public/' + } + maven { + name 'ic2' + url 'http://maven.ic2.player.to/' + metadataSources { + mavenPom() + artifact() + } + } + maven { + url 'https://cursemaven.com' + content { + includeGroup 'curse.maven' + } + } } diff --git a/src/main/java/pers/gwyog/gtneioreplugin/Config.java b/src/main/java/pers/gwyog/gtneioreplugin/Config.java index c31ebc63a6..eedd953316 100644 --- a/src/main/java/pers/gwyog/gtneioreplugin/Config.java +++ b/src/main/java/pers/gwyog/gtneioreplugin/Config.java @@ -1,9 +1,8 @@ package pers.gwyog.gtneioreplugin; import cpw.mods.fml.common.event.FMLPreInitializationEvent; -import net.minecraftforge.common.config.Configuration; - import java.io.File; +import net.minecraftforge.common.config.Configuration; public class Config { public Configuration tConfig; @@ -15,8 +14,6 @@ public class Config { } public void save() { - if (tConfig.hasChanged()) - tConfig.save(); + if (tConfig.hasChanged()) tConfig.save(); } - } diff --git a/src/main/java/pers/gwyog/gtneioreplugin/GTNEIOrePlugin.java b/src/main/java/pers/gwyog/gtneioreplugin/GTNEIOrePlugin.java index a324621a3b..3c0eb00eb4 100644 --- a/src/main/java/pers/gwyog/gtneioreplugin/GTNEIOrePlugin.java +++ b/src/main/java/pers/gwyog/gtneioreplugin/GTNEIOrePlugin.java @@ -11,7 +11,11 @@ import pers.gwyog.gtneioreplugin.util.GT5OreLayerHelper; import pers.gwyog.gtneioreplugin.util.GT5OreSmallHelper; import pers.gwyog.gtneioreplugin.util.GuiRecipeHelper; -@Mod(modid = GTNEIOrePlugin.MODID, name = GTNEIOrePlugin.NAME, version = GTNEIOrePlugin.VERSION, dependencies = "required-after:gregtech;required-after:NotEnoughItems") +@Mod( + modid = GTNEIOrePlugin.MODID, + name = GTNEIOrePlugin.NAME, + version = GTNEIOrePlugin.VERSION, + dependencies = "required-after:gregtech;required-after:NotEnoughItems") public class GTNEIOrePlugin { public static final String MODID = "GRADLETOKEN_MODID"; public static final String NAME = "GRADLETOKEN_MODNAME"; @@ -22,17 +26,36 @@ public class GTNEIOrePlugin { public static String CSVnameSmall; public static boolean toolTips = true; public static int maxTooltipLines = 11; + @Mod.Instance(MODID) public static GTNEIOrePlugin instance; @EventHandler public void preinit(FMLPreInitializationEvent event) { Config c = new Config(event, MODID + ".cfg"); - csv = c.tConfig.getBoolean("print csv", "ALL", false, "print csv, you need apache commons collections to be injected in the minecraft jar."); - CSVname = c.tConfig.getString("CSV_name", "ALL", event.getModConfigurationDirectory() + "/GTNH-Oresheet.csv", "rename the oresheet here, it will appear in /config"); - CSVnameSmall= c.tConfig.getString("CSV_name_for_Small_Ore_Sheet", "ALL", event.getModConfigurationDirectory() + "/GTNH-Small-Ores-Sheet.csv", "rename the oresheet here, it will appear in /config"); + csv = c.tConfig.getBoolean( + "print csv", + "ALL", + false, + "print csv, you need apache commons collections to be injected in the minecraft jar."); + CSVname = c.tConfig.getString( + "CSV_name", + "ALL", + event.getModConfigurationDirectory() + "/GTNH-Oresheet.csv", + "rename the oresheet here, it will appear in /config"); + CSVnameSmall = c.tConfig.getString( + "CSV_name_for_Small_Ore_Sheet", + "ALL", + event.getModConfigurationDirectory() + "/GTNH-Small-Ores-Sheet.csv", + "rename the oresheet here, it will appear in /config"); toolTips = c.tConfig.getBoolean("DimTooltip", "ALL", true, "Activates Dimension Tooltips"); - maxTooltipLines = c.tConfig.getInt("MaxToolTipLines", "ALL", 11, 1, Integer.MAX_VALUE, "Maximum number of lines the dimension names tooltip can have before it wraps around."); + maxTooltipLines = c.tConfig.getInt( + "MaxToolTipLines", + "ALL", + 11, + 1, + Integer.MAX_VALUE, + "Maximum number of lines the dimension names tooltip can have before it wraps around."); c.save(); } @@ -48,5 +71,4 @@ public class GTNEIOrePlugin { } } } - } diff --git a/src/main/java/pers/gwyog/gtneioreplugin/plugin/PluginBase.java b/src/main/java/pers/gwyog/gtneioreplugin/plugin/PluginBase.java index da3947fee8..de36d22bc9 100644 --- a/src/main/java/pers/gwyog/gtneioreplugin/plugin/PluginBase.java +++ b/src/main/java/pers/gwyog/gtneioreplugin/plugin/PluginBase.java @@ -2,11 +2,10 @@ package pers.gwyog.gtneioreplugin.plugin; import codechicken.lib.gui.GuiDraw; import codechicken.nei.recipe.TemplateRecipeHandler; +import java.awt.*; import net.minecraft.client.resources.I18n; import net.minecraft.util.EnumChatFormatting; -import java.awt.*; - public abstract class PluginBase extends TemplateRecipeHandler { @Override @@ -27,7 +26,8 @@ public abstract class PluginBase extends TemplateRecipeHandler { @Override public void loadTransferRects() { int stringLength = GuiDraw.getStringWidth(EnumChatFormatting.BOLD + I18n.format("gui.nei.seeAll")); - transferRects.add(new RecipeTransferRect(new Rectangle(getGuiWidth() - stringLength - 3, 5, stringLength, 9), getOutputId())); + transferRects.add(new RecipeTransferRect( + new Rectangle(getGuiWidth() - stringLength - 3, 5, stringLength, 9), getOutputId())); } public abstract String getOutputId(); @@ -35,5 +35,4 @@ public abstract class PluginBase extends TemplateRecipeHandler { public int getGuiWidth() { return 166; } - } diff --git a/src/main/java/pers/gwyog/gtneioreplugin/plugin/gregtech5/PluginGT5Base.java b/src/main/java/pers/gwyog/gtneioreplugin/plugin/gregtech5/PluginGT5Base.java index f5bb8a618b..bdcccebe7a 100644 --- a/src/main/java/pers/gwyog/gtneioreplugin/plugin/gregtech5/PluginGT5Base.java +++ b/src/main/java/pers/gwyog/gtneioreplugin/plugin/gregtech5/PluginGT5Base.java @@ -1,27 +1,27 @@ package pers.gwyog.gtneioreplugin.plugin.gregtech5; +import static pers.gwyog.gtneioreplugin.GTNEIOrePlugin.toolTips; + import codechicken.lib.gui.GuiDraw; import codechicken.nei.guihook.GuiContainerManager; import codechicken.nei.recipe.GuiRecipe; import gregtech.api.GregTech_API; import gregtech.api.enums.Materials; import gregtech.api.util.GT_LanguageManager; +import java.awt.Point; +import java.awt.Rectangle; +import java.util.List; import net.minecraft.client.resources.I18n; import net.minecraft.util.EnumChatFormatting; import pers.gwyog.gtneioreplugin.plugin.PluginBase; import pers.gwyog.gtneioreplugin.util.DimensionHelper; import pers.gwyog.gtneioreplugin.util.GuiRecipeHelper; -import java.awt.Point; -import java.awt.Rectangle; -import java.util.List; - -import static pers.gwyog.gtneioreplugin.GTNEIOrePlugin.toolTips; - public abstract class PluginGT5Base extends PluginBase { protected static String getLocalizedNameForItem(Materials aMaterial, String aFormat) { - return String.format(aFormat.replace("%s", "%temp").replace("%material", "%s"), aMaterial.mLocalizedName).replace("%temp", "%s"); + return String.format(aFormat.replace("%s", "%temp").replace("%material", "%s"), aMaterial.mLocalizedName) + .replace("%temp", "%s"); } protected static String getLocalizedNameForItem(String aFormat, int aMaterialID) { @@ -36,19 +36,24 @@ public abstract class PluginGT5Base extends PluginBase { public static String getGTOreLocalizedName(short index) { - if (!getLocalizedNameForItem(GT_LanguageManager.getTranslation(getGTOreUnlocalizedName(index)), index % 1000).contains("Awakened")) - return getLocalizedNameForItem(GT_LanguageManager.getTranslation(getGTOreUnlocalizedName(index)), index % 1000); - else - return "Aw. Draconium Ore"; + if (!getLocalizedNameForItem(GT_LanguageManager.getTranslation(getGTOreUnlocalizedName(index)), index % 1000) + .contains("Awakened")) + return getLocalizedNameForItem( + GT_LanguageManager.getTranslation(getGTOreUnlocalizedName(index)), index % 1000); + else return "Aw. Draconium Ore"; } protected static String getGTOreUnlocalizedName(short index) { return "gt.blockores." + index + ".name"; } + static void drawLine(String lineKey, String value, int x, int y) { + GuiDraw.drawString(I18n.format(lineKey) + ": " + value, x, y, 0x404040, false); + } + /** * Add lines to the current tooltip if appropriate - * + * * @param gui An instance of the currentscreen * @param currenttip The current tooltip, will contain item name and info * @param recipe The recipe index being handled @@ -58,9 +63,8 @@ public abstract class PluginGT5Base extends PluginBase { public List handleTooltip(GuiRecipe gui, List currenttip, int recipe) { if (toolTips && GuiContainerManager.shouldShowTooltip(gui) && currenttip.size() == 0) { String dimNames = getDimensionNames(recipe); - Rectangle dimRect = getDimensionNamesRect(gui, recipe , dimNames); + Rectangle dimRect = getDimensionNamesRect(gui, recipe, dimNames); Point mousePos = GuiDraw.getMousePosition(); - if (dimRect.contains(mousePos.x, mousePos.y)) { List dims = DimensionHelper.convertCondensedStringToToolTip(dimNames); @@ -73,42 +77,42 @@ public abstract class PluginGT5Base extends PluginBase { /** * The dimension names for a given recipe index - * - * @param The recipe index being handled + * + * @param recipe The recipe index being handled * @return A CSV string of dimension name abbreviations */ protected abstract String getDimensionNames(int recipe); /** * Produce a rectangle covering the area of displayed dimension names - * + * * @param gui An instance of the currentscreen * @param recipe The recipe index being handled * @param dimNames Dimension names to produce a rectangle for * @return Rectangle area of dimension names */ protected Rectangle getDimensionNamesRect(GuiRecipe gui, int recipe, String dimNames) { - int dimNamesHeight = dimNames.length() > 70 ? 30 : (dimNames.length() > 36 ? 20 : 10); + int dimNamesHeight = dimNames.length() > 70 ? 30 : (dimNames.length() > 36 ? 20 : 10); Point offset = gui.getRecipePosition(recipe); - return new Rectangle(GuiRecipeHelper.getGuiLeft(gui) + offset.x + 2, - GuiRecipeHelper.getGuiTop(gui) + offset.y + 110, - GuiRecipeHelper.getXSize(gui) - 9, - dimNamesHeight ); + return new Rectangle( + GuiRecipeHelper.getGuiLeft(gui) + offset.x + 2, + GuiRecipeHelper.getGuiTop(gui) + offset.y + 110, + GuiRecipeHelper.getXSize(gui) - 9, + dimNamesHeight); } protected int getMaximumMaterialIndex(short meta, boolean smallOre) { int offset = smallOre ? 16000 : 0; - if (!getGTOreLocalizedName((short) (meta + offset + 5000)).equals(getGTOreUnlocalizedName((short) (meta + offset + 5000)))) - return 7; - else if (!getGTOreLocalizedName((short) (meta + offset + 5000)).equals(getGTOreUnlocalizedName((short) (meta + offset + 5000)))) - return 6; - else - return 5; + if (!getGTOreLocalizedName((short) (meta + offset + 5000)) + .equals(getGTOreUnlocalizedName((short) (meta + offset + 5000)))) return 7; + else if (!getGTOreLocalizedName((short) (meta + offset + 5000)) + .equals(getGTOreUnlocalizedName((short) (meta + offset + 5000)))) return 6; + else return 5; } /** * Draw the dimension header and the dimension names over up to 3 lines - * + * * @param dimNames A CSV string of dimension name abbreviations */ protected void drawDimNames(String dimNames) { @@ -118,12 +122,13 @@ public abstract class PluginGT5Base extends PluginBase { GuiDraw.drawString(I18n.format("") + dimNames.substring(0, 36), 2, 110, 0x404040, false); if (dimNames.length() > 70) { GuiDraw.drawString(I18n.format("") + dimNames.substring(36, 70), 2, 120, 0x404040, false); - GuiDraw.drawString(I18n.format("") + dimNames.substring(70, dimNames.length() - 1), 2, 130, 0x404040, false); - } else - { - GuiDraw.drawString(I18n.format("") + dimNames.substring(36, dimNames.length() - 1), 2, 120, 0x404040, false); + GuiDraw.drawString( + I18n.format("") + dimNames.substring(70, dimNames.length() - 1), 2, 130, 0x404040, false); + } else { + GuiDraw.drawString( + I18n.format("") + dimNames.substring(36, dimNames.length() - 1), 2, 120, 0x404040, false); } - } else{ + } else { GuiDraw.drawString(I18n.format("") + dimNames.substring(0, dimNames.length() - 1), 2, 110, 0x404040, false); } } @@ -132,6 +137,7 @@ public abstract class PluginGT5Base extends PluginBase { * Draw the "see all recipes" transfer label */ protected void drawSeeAllRecipesLabel() { - GuiDraw.drawStringR(EnumChatFormatting.BOLD + I18n.format("gtnop.gui.nei.seeAll"), getGuiWidth() - 3, 5, 0x404040, false); + GuiDraw.drawStringR( + EnumChatFormatting.BOLD + I18n.format("gtnop.gui.nei.seeAll"), getGuiWidth() - 3, 5, 0x404040, false); } } diff --git a/src/main/java/pers/gwyog/gtneioreplugin/plugin/gregtech5/PluginGT5SmallOreStat.java b/src/main/java/pers/gwyog/gtneioreplugin/plugin/gregtech5/PluginGT5SmallOreStat.java index 70346889e9..38f668f05e 100644 --- a/src/main/java/pers/gwyog/gtneioreplugin/plugin/gregtech5/PluginGT5SmallOreStat.java +++ b/src/main/java/pers/gwyog/gtneioreplugin/plugin/gregtech5/PluginGT5SmallOreStat.java @@ -1,37 +1,49 @@ package pers.gwyog.gtneioreplugin.plugin.gregtech5; -import codechicken.lib.gui.GuiDraw; import codechicken.nei.PositionedStack; -import gregtech.api.GregTech_API; import gregtech.api.enums.OrePrefixes; import gregtech.api.util.GT_OreDictUnificator; +import java.util.ArrayList; +import java.util.List; import net.minecraft.client.resources.I18n; import net.minecraft.item.ItemStack; import pers.gwyog.gtneioreplugin.util.GT5OreSmallHelper; import pers.gwyog.gtneioreplugin.util.GT5OreSmallHelper.OreSmallWrapper; -import java.util.ArrayList; -import java.util.List; - public class PluginGT5SmallOreStat extends PluginGT5Base { + private static final int SMALL_ORE_BASE_META = 16000; + @Override public void drawExtras(int recipe) { - CachedOreSmallRecipe crecipe = (CachedOreSmallRecipe) this.arecipes.get(recipe); - OreSmallWrapper oreSmall = GT5OreSmallHelper.mapOreSmallWrapper.get(crecipe.oreGenName); - String sDimNames = GT5OreSmallHelper.bufferedDims.get(oreSmall); - GuiDraw.drawString(I18n.format("gtnop.gui.nei.oreName") + ": " + getGTOreLocalizedName((short) (oreSmall.oreMeta + 16000)), 2, 18, 0x404040, false); + OreSmallWrapper oreSmall = getSmallOre(recipe); - GuiDraw.drawString(I18n.format("gtnop.gui.nei.genHeight") + ": " + oreSmall.worldGenHeightRange, 2, 31, 0x404040, false); - GuiDraw.drawString(I18n.format("gtnop.gui.nei.amount") + ": " + oreSmall.amountPerChunk, 2, 44, 0x404040, false); - // if (GT5OreSmallHelper.restrictBiomeSupport) GuiDraw.drawString(I18n.format("gtnop.gui.nei.restrictBiome") + ": " + getBiomeTranslated(oreSmall.restrictBiome), 2, 70, 0x404040, false); - GuiDraw.drawString(I18n.format("gtnop.gui.nei.chanceDrops") + ": ", 2, 83 + getRestrictBiomeOffset(), 0x404040, false); - GuiDraw.drawString(I18n.format("gtnop.gui.nei.worldNames") + ": ", 2, 100, 0x404040, false); + drawSmallOreName(oreSmall); + drawSmallOreInfo(oreSmall); + String sDimNames = GT5OreSmallHelper.bufferedDims.get(oreSmall); drawDimNames(sDimNames); + drawSeeAllRecipesLabel(); } + private void drawSmallOreName(OreSmallWrapper oreSmall) { + String oreName = getGTOreLocalizedName((short) (oreSmall.oreMeta + SMALL_ORE_BASE_META)); + drawLine("gtnop.gui.nei.oreName", oreName, 2, 18); + } + + private void drawSmallOreInfo(OreSmallWrapper oreSmall) { + drawLine("gtnop.gui.nei.genHeight", oreSmall.worldGenHeightRange, 2, 31); + drawLine("gtnop.gui.nei.amount", String.valueOf(oreSmall.amountPerChunk), 2, 44); + drawLine("gtnop.gui.nei.chanceDrops", "", 2, 83 + getRestrictBiomeOffset()); + drawLine("gtnop.gui.nei.worldNames", "", 2, 100); + } + + private OreSmallWrapper getSmallOre(int recipe) { + CachedOreSmallRecipe crecipe = (CachedOreSmallRecipe) this.arecipes.get(recipe); + return GT5OreSmallHelper.mapOreSmallWrapper.get(crecipe.oreGenName); + } + public int getRestrictBiomeOffset() { return GT5OreSmallHelper.restrictBiomeSupport ? 0 : -13; } @@ -39,48 +51,51 @@ public class PluginGT5SmallOreStat extends PluginGT5Base { @Override public void loadCraftingRecipes(String outputId, Object... results) { if (outputId.equals(getOutputId())) - for (ItemStack stack : GT5OreSmallHelper.oreSmallList) - loadCraftingRecipes(stack); - else - super.loadCraftingRecipes(outputId, results); + for (ItemStack stack : GT5OreSmallHelper.oreSmallList) loadCraftingRecipes(stack); + else super.loadCraftingRecipes(outputId, results); } @Override public void loadCraftingRecipes(ItemStack stack) { if (stack.getUnlocalizedName().startsWith("gt.blockores")) { - if (stack.getItemDamage() < 16000) { - super.loadCraftingRecipes(stack); - return; - } - short baseMeta = (short) (stack.getItemDamage() % 1000); - for (OreSmallWrapper oreSmallWorldGen : GT5OreSmallHelper.mapOreSmallWrapper.values()) { - if (oreSmallWorldGen.oreMeta == baseMeta) { - List stackList = new ArrayList(); - int maximumIndex = getMaximumMaterialIndex(baseMeta, true); - for (int i = 0; i < maximumIndex; i++) - stackList.add(new ItemStack(GregTech_API.sBlockOres1, 1, oreSmallWorldGen.oreMeta + 16000 + i * 1000)); - List materialDustStackList = new ArrayList(); - for (int i = 0; i < maximumIndex; i++) - materialDustStackList.add(GT_OreDictUnificator.get(OrePrefixes.dust, GT5OreSmallHelper.getDroppedDusts()[i], 1L)); - this.arecipes.add(new CachedOreSmallRecipe(oreSmallWorldGen.oreGenName, stackList, materialDustStackList, GT5OreSmallHelper.mapOreMetaToOreDrops.get(baseMeta))); - } - } - } else if (GT5OreSmallHelper.mapOreDropUnlocalizedNameToOreMeta.keySet().contains(stack.getUnlocalizedName())) { - short baseMeta = GT5OreSmallHelper.mapOreDropUnlocalizedNameToOreMeta.get(stack.getUnlocalizedName()); - for (String oreGenName : GT5OreSmallHelper.mapOreSmallWrapper.keySet()) { - OreSmallWrapper oreSmallWrapper = GT5OreSmallHelper.mapOreSmallWrapper.get(oreGenName); - if (oreSmallWrapper.oreMeta == baseMeta) { - List stackList = new ArrayList(); - for (int i = 0; i < 7; i++) - stackList.add(new ItemStack(GregTech_API.sBlockOres1, 1, baseMeta + 16000 + i * 1000)); - List materialDustStackList = new ArrayList(); - for (int i = 0; i < 7; i++) - materialDustStackList.add(GT_OreDictUnificator.get(OrePrefixes.dust, GT5OreSmallHelper.getDroppedDusts()[i], 1L)); - this.arecipes.add(new CachedOreSmallRecipe(GT5OreSmallHelper.mapOreSmallWrapper.get(oreGenName).oreGenName, stackList, materialDustStackList, GT5OreSmallHelper.mapOreMetaToOreDrops.get(baseMeta))); - } + short oreMeta = (short) (stack.getItemDamage() % 1000); + loadSmallOre(oreMeta, getMaximumMaterialIndex(oreMeta, true)); + } else if (GT5OreSmallHelper.mapOreDropUnlocalizedNameToOreMeta.containsKey(stack.getUnlocalizedName())) { + short oreMeta = GT5OreSmallHelper.mapOreDropUnlocalizedNameToOreMeta.get(stack.getUnlocalizedName()); + loadSmallOre(oreMeta, 7); + } else super.loadCraftingRecipes(stack); + } + + private void loadSmallOre(short oreMeta, int maximumIndex) { + OreSmallWrapper smallOre = getSmallOre(oreMeta); + if (smallOre != null) { + addSmallOre(smallOre, maximumIndex); + } + } + + private OreSmallWrapper getSmallOre(short oreMeta) { + for (OreSmallWrapper oreSmallWorldGen : GT5OreSmallHelper.mapOreSmallWrapper.values()) { + if (oreSmallWorldGen.oreMeta == oreMeta) { + return oreSmallWorldGen; } - } else - super.loadCraftingRecipes(stack); + } + return null; + } + + private void addSmallOre(OreSmallWrapper smallOre, int maximumIndex) { + this.arecipes.add(new CachedOreSmallRecipe( + smallOre.oreGenName, + smallOre.getMaterialDrops(maximumIndex), + getStoneDusts(maximumIndex), + GT5OreSmallHelper.mapOreMetaToOreDrops.get(smallOre.oreMeta))); + } + + private List getStoneDusts(int maximumIndex) { + List materialDustStackList = new ArrayList<>(); + for (int i = 0; i < maximumIndex; i++) + materialDustStackList.add( + GT_OreDictUnificator.get(OrePrefixes.dust, GT5OreSmallHelper.getDroppedDusts()[i], 1L)); + return materialDustStackList; } @Override @@ -95,48 +110,52 @@ public class PluginGT5SmallOreStat extends PluginGT5Base { /** * The dimension names for a given recipe identifier - * + * * @param recipe identifier * @return A CSV string of dimension name abbreviations */ @Override - protected String getDimensionNames(int recipe) { - CachedOreSmallRecipe crecipe = (CachedOreSmallRecipe) this.arecipes.get(recipe); - OreSmallWrapper oreSmall = GT5OreSmallHelper.mapOreSmallWrapper.get(crecipe.oreGenName); + protected String getDimensionNames(int recipe) { + OreSmallWrapper oreSmall = getSmallOre(recipe); return GT5OreSmallHelper.bufferedDims.get(oreSmall); } - + public class CachedOreSmallRecipe extends CachedRecipe { public String oreGenName; public PositionedStack positionedStackOreSmall; public PositionedStack positionedStackMaterialDust; public List positionedDropStackList; - public CachedOreSmallRecipe(String oreGenName, List stackList, List materialDustStackList, List dropStackList) { + public CachedOreSmallRecipe( + String oreGenName, + List stackList, + List materialDustStackList, + List dropStackList) { this.oreGenName = oreGenName; this.positionedStackOreSmall = new PositionedStack(stackList, 2, 0); - this.positionedStackMaterialDust = new PositionedStack(materialDustStackList, 43, 79 + getRestrictBiomeOffset()); - List positionedDropStackList = new ArrayList(); + this.positionedStackMaterialDust = + new PositionedStack(materialDustStackList, 43, 79 + getRestrictBiomeOffset()); + List positionedDropStackList = new ArrayList<>(); int i = 1; for (ItemStack stackDrop : dropStackList) - positionedDropStackList.add(new PositionedStack(stackDrop, 43 + 20 * (i % 4), 79 + 16 * ((i++) / 4) + getRestrictBiomeOffset())); + positionedDropStackList.add(new PositionedStack( + stackDrop, 43 + 20 * (i % 4), 79 + 16 * ((i++) / 4) + getRestrictBiomeOffset())); this.positionedDropStackList = positionedDropStackList; } @Override public List getIngredients() { positionedStackOreSmall.setPermutationToRender((cycleticks / 20) % positionedStackOreSmall.items.length); - positionedStackMaterialDust.setPermutationToRender((cycleticks / 20) % positionedStackMaterialDust.items.length); + positionedStackMaterialDust.setPermutationToRender( + (cycleticks / 20) % positionedStackMaterialDust.items.length); positionedDropStackList.add(positionedStackOreSmall); positionedDropStackList.add(positionedStackMaterialDust); return positionedDropStackList; - } @Override public PositionedStack getResult() { return null; } - } } diff --git a/src/main/java/pers/gwyog/gtneioreplugin/plugin/gregtech5/PluginGT5VeinStat.java b/src/main/java/pers/gwyog/gtneioreplugin/plugin/gregtech5/PluginGT5VeinStat.java index 8f8a01ef0a..dc559db34a 100644 --- a/src/main/java/pers/gwyog/gtneioreplugin/plugin/gregtech5/PluginGT5VeinStat.java +++ b/src/main/java/pers/gwyog/gtneioreplugin/plugin/gregtech5/PluginGT5VeinStat.java @@ -1,202 +1,104 @@ package pers.gwyog.gtneioreplugin.plugin.gregtech5; -import codechicken.lib.gui.GuiDraw; +import static pers.gwyog.gtneioreplugin.util.OreVeinLayer.*; + import codechicken.nei.PositionedStack; import cpw.mods.fml.common.Loader; -import gregtech.api.GregTech_API; +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; import net.minecraft.client.resources.I18n; import net.minecraft.item.ItemStack; import pers.gwyog.gtneioreplugin.util.GT5OreLayerHelper; import pers.gwyog.gtneioreplugin.util.GT5OreLayerHelper.OreLayerWrapper; -import java.util.ArrayList; -import java.util.HashSet; -import java.util.List; -import java.util.Set; - public class PluginGT5VeinStat extends PluginGT5Base { - // Unused - public static String[] getLocalizedVeinName(OreLayerWrapper oreLayer) { - String unlocalizedName = oreLayer.veinName; - if (unlocalizedName.startsWith("ore.mix.custom.")) - return get_Cnames(oreLayer);//I18n.format("gtnop.ore.custom.name") + I18n.format("gtnop.ore.vein.name") + unlocalizedName.substring(15); - else - return new String[]{I18n.format("gtnop." + unlocalizedName) + I18n.format("gtnop.ore.vein.name")}; - } - - // Unused - public static String coustomVeinRenamer(OreLayerWrapper oreLayer) { - Set s = new HashSet(); - for (int i = 0; i < 4; i++) - s.add(getGTOreLocalizedName(oreLayer.Meta[i]).replaceAll(" ", "")); - return s.toString() - .replace("[".charAt(0), ",".charAt(0)) - .replace("]".charAt(0), ",".charAt(0)) - .replaceAll(" Ore", ",") - .replaceAll("Ore", ",") - .replaceAll(" Sand", ",") - .replaceAll("Sand", ",") - .replaceAll("Stone", ",") - .replaceAll(" Stone", ",") - .replaceAll("Earth", ",") - .replaceAll(" Earth", ",") - .replaceAll("Infused", ",") - .replaceAll(" Infused", ",") - .replaceAll(",", "") - .trim(); - } - - /*public String getWeightedChance(OreLayerWrapper oreLayer) { - String weightedChance = ""; - for (int i=0; i < oreLayer.alloweddims.size(); i++) { - if (oreLayer.alloweddims.get(i) && (oreLayer.Weight.get(i) != 0)) { - if (!weightedChance.isEmpty()) - weightedChance += ", "; - weightedChance += String.format("%.2f%%", (100.0f*oreLayer.Weight.get(i))/GT5OreLayerHelper.weightPerWorld[i]); - } - } - return weightedChance; - }*/ - - // Unused - public static String[] get_Cnames(OreLayerWrapper oreLayer) { - - String[] splt = coustomVeinRenamer(oreLayer).split("\\s"); - /*HashSet h = new HashSet(); - for (int i=0; i < splt.length;i++) { - h.add(splt[i]); - } - h.toArray(splt);*/ - - String[] ret = {oreLayer.veinName.replace("ore.mix.custom.", "") + " ", " ", " "}; - for (int i = 0; i < ret.length; i++) { - ret[i] = ret[i].trim(); - } - for (int i = 0; i < splt.length; i++) { - //FMLLog.info("Split:"+splt[i]); - //FMLLog.info("I:"+Integer.toString(i)); - if (ret[0].length() + splt[i].length() <= 20) - ret[0] = ret[0] + splt[i] + " "; - if ((ret[0].length() + splt[i].length() > 20) && ret[1].length() + splt[i].length() <= 70 && !ret[0].contains(splt[i])) - ret[1] = ret[1] + splt[i] + " "; - if ((ret[0].length() + splt[i].length() > 20) && (ret[1].length() + splt[i].length() > 70) && ret[2].length() + splt[i].length() <= 70 && !ret[1].contains(splt[i])) - ret[2] = ret[2] + splt[i] + " "; - } - for (int i = 0; i < ret.length; i++) { - ret[i] = ret[i].trim(); - } - - if (ret[2].isEmpty() && !ret[1].isEmpty()) - if (ret[1].length() <= 65) - ret[1] = ret[1] + " Vein"; - else - ret[2] = ret[2] + "Vein"; - else if (ret[1].isEmpty() && ret[2].isEmpty() && !ret[0].isEmpty()) - if (ret[0].length() <= 15) - ret[0] = ret[0] + " Vein"; - else - ret[1] = ret[1] + "Vein"; - else if (!(ret[1].isEmpty() && ret[2].isEmpty())) - ret[2] = ret[2] + "Vein"; - String[] ret2 = new String[2]; - if (ret[2].isEmpty() && !ret[1].isEmpty()) { - ret2[0] = ret[0]; - ret2[1] = ret[1]; - return ret2; - } - String[] ret1 = new String[1]; - if (ret[1].isEmpty() && ret[2].isEmpty() && !ret[0].isEmpty()) { - ret1[0] = ret[0]; - return ret1; - } else - return ret; - } - @Override public void loadCraftingRecipes(String outputId, Object... results) { if (outputId.equals(getOutputId())) { - OreLayerWrapper oreLayerWrapper; - for (String veinName : GT5OreLayerHelper.mapOreLayerWrapper.keySet()) { - oreLayerWrapper = GT5OreLayerHelper.mapOreLayerWrapper.get(veinName); - List stackListPrimary = new ArrayList(); - List stackListSecondary = new ArrayList(); - List stackListBetween = new ArrayList(); - List stackListSporadic = new ArrayList(); - for (int i = 0; i < 7; i++) { - stackListPrimary.add(new ItemStack(GregTech_API.sBlockOres1, 1, oreLayerWrapper.Meta[0] + i * 1000)); - stackListSecondary.add(new ItemStack(GregTech_API.sBlockOres1, 1, oreLayerWrapper.Meta[1] + i * 1000)); - stackListBetween.add(new ItemStack(GregTech_API.sBlockOres1, 1, oreLayerWrapper.Meta[2] + i * 1000)); - stackListSporadic.add(new ItemStack(GregTech_API.sBlockOres1, 1, oreLayerWrapper.Meta[3] + i * 1000)); - } - this.arecipes.add(new CachedVeinStatRecipe(veinName, stackListPrimary, stackListSecondary, stackListBetween, stackListSporadic)); + for (OreLayerWrapper oreVein : getAllVeins()) { + addVeinWithLayers(oreVein, 7); } - } else - super.loadCraftingRecipes(outputId, results); + } else super.loadCraftingRecipes(outputId, results); } @Override public void loadCraftingRecipes(ItemStack stack) { if (stack.getUnlocalizedName().startsWith("gt.blockores")) { - if (stack.getItemDamage() > 16000) { - super.loadCraftingRecipes(stack); - return; - } - short baseMeta = (short) (stack.getItemDamage() % 1000); - for (OreLayerWrapper worldGen : GT5OreLayerHelper.mapOreLayerWrapper.values()) { - if (worldGen.Meta[0] == baseMeta || worldGen.Meta[1] == baseMeta || worldGen.Meta[2] == baseMeta || worldGen.Meta[3] == baseMeta) { - List stackListPrimary = new ArrayList(); - List stackListSecondary = new ArrayList(); - List stackListBetween = new ArrayList(); - List stackListSporadic = new ArrayList(); - for (int i = 0; i < getMaximumMaterialIndex(baseMeta, false); i++) { - stackListPrimary.add(new ItemStack(GregTech_API.sBlockOres1, 1, worldGen.Meta[0] + i * 1000)); - stackListSecondary.add(new ItemStack(GregTech_API.sBlockOres1, 1, worldGen.Meta[1] + i * 1000)); - stackListBetween.add(new ItemStack(GregTech_API.sBlockOres1, 1, worldGen.Meta[2] + i * 1000)); - stackListSporadic.add(new ItemStack(GregTech_API.sBlockOres1, 1, worldGen.Meta[3] + i * 1000)); - } - this.arecipes.add(new CachedVeinStatRecipe(worldGen.veinName, stackListPrimary, stackListSecondary, stackListBetween, stackListSporadic)); - } + loadMatchingVeins((short) (stack.getItemDamage() % 1000)); + } else super.loadCraftingRecipes(stack); + } + + private void loadMatchingVeins(short oreId) { + for (OreLayerWrapper oreVein : getAllVeins()) { + if (oreVein.containsOre(oreId)) { + addVeinWithLayers(oreVein, getMaximumMaterialIndex(oreId, false)); } - } else - super.loadCraftingRecipes(stack); + } + } + + private void addVeinWithLayers(OreLayerWrapper oreVein, int maximumMaterialIndex) { + this.arecipes.add(new CachedVeinStatRecipe( + oreVein.veinName, + oreVein.getVeinLayerOre(maximumMaterialIndex, VEIN_PRIMARY), + oreVein.getVeinLayerOre(maximumMaterialIndex, VEIN_SECONDARY), + oreVein.getVeinLayerOre(maximumMaterialIndex, VEIN_BETWEEN), + oreVein.getVeinLayerOre(maximumMaterialIndex, VEIN_SPORADIC))); + } + + private Collection getAllVeins() { + return GT5OreLayerHelper.mapOreLayerWrapper.values(); } @Override public void drawExtras(int recipe) { - CachedVeinStatRecipe crecipe = (CachedVeinStatRecipe) this.arecipes.get(recipe); - OreLayerWrapper oreLayer = GT5OreLayerHelper.mapOreLayerWrapper.get(crecipe.veinName); + OreLayerWrapper oreLayer = getOreLayer(recipe); - String sDimNames = GT5OreLayerHelper.bufferedDims.get(oreLayer); + drawVeinName(oreLayer); + drawVeinLayerNames(oreLayer); + drawVeinInfo(oreLayer); - if(Loader.isModLoaded("visualprospecting")) { - GuiDraw.drawString(I18n.format("gtnop.gui.nei.veinName") + ": " + I18n.format(oreLayer.veinName) + " " + I18n.format("gtnop.gui.nei.vein"), 2, 20, 0x404040, false); - } - else { - if (getGTOreLocalizedName(oreLayer.Meta[0]).contains("Ore")) - GuiDraw.drawString(I18n.format("gtnop.gui.nei.veinName") + ": " + getGTOreLocalizedName(oreLayer.Meta[0]).split("Ore")[0] + "" + I18n.format("gtnop.gui.nei.vein"), 2, 20, 0x404040, false); - else if (getGTOreLocalizedName(oreLayer.Meta[0]).contains("Sand")) - GuiDraw.drawString(I18n.format("gtnop.gui.nei.veinName") + ": " + getGTOreLocalizedName(oreLayer.Meta[0]).split("Sand")[0] + "" + I18n.format("gtnop.gui.nei.vein"), 2, 20, 0x404040, false); - else - GuiDraw.drawString(I18n.format("gtnop.gui.nei.veinName") + ": " + getGTOreLocalizedName(oreLayer.Meta[0]) + " " + I18n.format("gtnop.gui.nei.vein"), 2, 20, 0x404040, false); - } - - GuiDraw.drawString(I18n.format("gtnop.gui.nei.primaryOre") + ": " + getGTOreLocalizedName(oreLayer.Meta[0]), 2, 50, 0x404040, false); + String sDimNames = GT5OreLayerHelper.bufferedDims.get(oreLayer); + drawDimNames(sDimNames); - GuiDraw.drawString(I18n.format("gtnop.gui.nei.secondaryOre") + ": " + getGTOreLocalizedName(oreLayer.Meta[1]), 2, 60, 0x404040, false); + drawSeeAllRecipesLabel(); + } - GuiDraw.drawString(I18n.format("gtnop.gui.nei.betweenOre") + ": " + getGTOreLocalizedName(oreLayer.Meta[2]), 2, 70, 0x404040, false); + private OreLayerWrapper getOreLayer(int recipe) { + CachedVeinStatRecipe crecipe = (CachedVeinStatRecipe) this.arecipes.get(recipe); + return GT5OreLayerHelper.mapOreLayerWrapper.get(crecipe.veinName); + } - GuiDraw.drawString(I18n.format("gtnop.gui.nei.sporadicOre") + ": " + getGTOreLocalizedName(oreLayer.Meta[3]), 2, 80, 0x404040, false); + private static void drawVeinName(OreLayerWrapper oreLayer) { + if (Loader.isModLoaded("visualprospecting")) { + drawVeinNameLine(I18n.format(oreLayer.veinName) + " "); + } else { + String veinName = getGTOreLocalizedName(oreLayer.Meta[VEIN_PRIMARY]); + if (veinName.contains("Ore")) drawVeinNameLine(veinName.split("Ore")[0]); + else if (veinName.contains("Sand")) drawVeinNameLine(veinName.split("Sand")[0]); + else drawVeinNameLine(veinName + " "); + } + } - GuiDraw.drawString(I18n.format("gtnop.gui.nei.genHeight") + ": " + oreLayer.worldGenHeightRange, 2, 90, 0x404040, false); + private static void drawVeinNameLine(String veinName) { + drawLine("gtnop.gui.nei.veinName", veinName + I18n.format("gtnop.gui" + ".nei.vein"), 2, 20); + } - GuiDraw.drawString(I18n.format("gtnop.gui.nei.weightedChance") + ": " + Integer.toString(oreLayer.randomWeight), 100, 90, 0x404040, false); + private static void drawVeinLayerNames(OreLayerWrapper oreLayer) { + drawVeinLayerNameLine(oreLayer, VEIN_PRIMARY, 50); + drawVeinLayerNameLine(oreLayer, VEIN_SECONDARY, 60); + drawVeinLayerNameLine(oreLayer, VEIN_BETWEEN, 70); + drawVeinLayerNameLine(oreLayer, VEIN_SPORADIC, 80); + } - drawDimNames(sDimNames); + private static void drawVeinLayerNameLine(OreLayerWrapper oreLayer, int veinLayer, int height) { + drawLine(getOreVeinLayerName(veinLayer), getGTOreLocalizedName(oreLayer.Meta[veinLayer]), 2, height); + } - //if (GT5OreLayerHelper.restrictBiomeSupport) GuiDraw.drawString(I18n.format("gtnop.gui.nei.restrictBiome") + ": " + getBiomeTranslated(oreLayer.restrictBiome), 2, 122, 0x404040, false); - drawSeeAllRecipesLabel(); + private static void drawVeinInfo(OreLayerWrapper oreLayer) { + drawLine("gtnop.gui.nei.genHeight", oreLayer.worldGenHeightRange, 2, 90); + drawLine("gtnop.gui.nei.weightedChance", Integer.toString(oreLayer.randomWeight), 100, 90); } @Override @@ -208,17 +110,16 @@ public class PluginGT5VeinStat extends PluginGT5Base { public String getRecipeName() { return I18n.format("gtnop.gui.veinStat.name"); } - + /** * The dimension names for a given recipe identifier - * + * * @param recipe identifier * @return A CSV string of dimension name abbreviations */ @Override - protected String getDimensionNames(int recipe) { - CachedVeinStatRecipe crecipe = (CachedVeinStatRecipe) this.arecipes.get(recipe); - OreLayerWrapper oreLayer = GT5OreLayerHelper.mapOreLayerWrapper.get(crecipe.veinName); + protected String getDimensionNames(int recipe) { + OreLayerWrapper oreLayer = getOreLayer(recipe); return GT5OreLayerHelper.bufferedDims.get(oreLayer); } @@ -229,8 +130,12 @@ public class PluginGT5VeinStat extends PluginGT5Base { public PositionedStack positionedStackBetween; public PositionedStack positionedStackSporadic; - public CachedVeinStatRecipe(String veinName, List stackListPrimary, List stackListSecondary, - List stackListBetween, List stackListSporadic) { + public CachedVeinStatRecipe( + String veinName, + List stackListPrimary, + List stackListSecondary, + List stackListBetween, + List stackListSporadic) { this.veinName = veinName; positionedStackPrimary = new PositionedStack(stackListPrimary, 2, 0); positionedStackSecondary = new PositionedStack(stackListSecondary, 22, 0); @@ -240,15 +145,11 @@ public class PluginGT5VeinStat extends PluginGT5Base { @Override public List getIngredients() { - List ingredientsList = new ArrayList(); + List ingredientsList = new ArrayList<>(); positionedStackPrimary.setPermutationToRender((cycleticks / 20) % positionedStackPrimary.items.length); - ; positionedStackSecondary.setPermutationToRender((cycleticks / 20) % positionedStackPrimary.items.length); - ; positionedStackBetween.setPermutationToRender((cycleticks / 20) % positionedStackPrimary.items.length); - ; positionedStackSporadic.setPermutationToRender((cycleticks / 20) % positionedStackPrimary.items.length); - ; ingredientsList.add(positionedStackPrimary); ingredientsList.add(positionedStackSecondary); ingredientsList.add(positionedStackBetween); @@ -260,7 +161,5 @@ public class PluginGT5VeinStat extends PluginGT5Base { public PositionedStack getResult() { return null; } - } - } diff --git a/src/main/java/pers/gwyog/gtneioreplugin/util/CSVMaker.java b/src/main/java/pers/gwyog/gtneioreplugin/util/CSVMaker.java index f12405a7ae..24cc1dd023 100644 --- a/src/main/java/pers/gwyog/gtneioreplugin/util/CSVMaker.java +++ b/src/main/java/pers/gwyog/gtneioreplugin/util/CSVMaker.java @@ -4,10 +4,6 @@ import com.opencsv.CSVWriter; import com.opencsv.bean.ColumnPositionMappingStrategy; import com.opencsv.bean.StatefulBeanToCsv; import com.opencsv.bean.StatefulBeanToCsvBuilder; -import pers.gwyog.gtneioreplugin.GTNEIOrePlugin; -import pers.gwyog.gtneioreplugin.plugin.gregtech5.PluginGT5VeinStat; -import pers.gwyog.gtneioreplugin.util.GT5OreLayerHelper.OreLayerWrapper; - import java.io.BufferedWriter; import java.nio.file.Files; import java.nio.file.Paths; @@ -15,12 +11,13 @@ import java.util.ArrayList; import java.util.Iterator; import java.util.List; import java.util.Map; +import pers.gwyog.gtneioreplugin.GTNEIOrePlugin; +import pers.gwyog.gtneioreplugin.plugin.gregtech5.PluginGT5VeinStat; +import pers.gwyog.gtneioreplugin.util.GT5OreLayerHelper.OreLayerWrapper; public class CSVMaker implements Runnable { - public CSVMaker() { - - } + public CSVMaker() {} public static List Combsort(List liste) { try { @@ -37,7 +34,13 @@ public class CSVMaker implements Runnable { schritt = (int) (schritt / 1.3); } for (int i = 0; i < liste2.size() - schritt; i++) { - if (liste2.get(i).getOreName().substring(0, 3).compareTo((liste2.get(i + schritt).getOreName().substring(0, 3))) > 0) { + if (liste2.get(i) + .getOreName() + .substring(0, 3) + .compareTo((liste2.get(i + schritt) + .getOreName() + .substring(0, 3))) + > 0) { Oremix tmp = (Oremix) liste2.get(i); liste2.set(i, liste2.get(i + schritt)); liste2.set(i + schritt, (Oremix) tmp); @@ -107,14 +110,17 @@ public class CSVMaker implements Runnable { BufferedWriter one = Files.newBufferedWriter(Paths.get(GTNEIOrePlugin.CSVnameSmall)); ColumnPositionMappingStrategy strat = new ColumnPositionMappingStrategy(); strat.setType(Oremix.class); - String[] columns = "ORENAME,mix,DENSITY,overworld,nether,end,ea,tf,mo,ma,ph,de,as,ce,eu,ga,ca,io,ve,me,en,ti,mi,ob,pr,tr,pl,kb,ha,make,dd,cb,vb,bc,be,bf,tcetie".split("\\,"); + String[] columns = + "ORENAME,mix,DENSITY,overworld,nether,end,ea,tf,mo,ma,ph,de,as,ce,eu,ga,ca,io,ve,me,en,ti,mi,ob,pr,tr,pl,kb,ha,make,dd,cb,vb,bc,be,bf,tcetie" + .split("\\,"); strat.setColumnMapping(columns); StatefulBeanToCsv beanToCsv = new StatefulBeanToCsvBuilder(one) .withQuotechar(CSVWriter.NO_QUOTE_CHARACTER) .withMappingStrategy(strat) .build(); List towrite = Combsort(OreVeins); - one.write("Ore Name,Primary,Secondary,Inbetween,Around,ID,Tier,Height,Density,Size,Weight,Overworld,Nether,End,End Asteroids,Twilight Forest,Moon,Mars,Phobos,Deimos,Asteroids,Ceres,Europa,Ganymede,Callisto,Io,Venus,Mercury,Enceladus,Titan,Miranda,Oberon,Proteus,Triton,Pluto,Kuiper Belt,Haumea,Makemake,Deep Dark,Centauri Bb,Vega B,Barnard C,Barnard E,Barnard F,T Ceti E"); + one.write( + "Ore Name,Primary,Secondary,Inbetween,Around,ID,Tier,Height,Density,Size,Weight,Overworld,Nether,End,End Asteroids,Twilight Forest,Moon,Mars,Phobos,Deimos,Asteroids,Ceres,Europa,Ganymede,Callisto,Io,Venus,Mercury,Enceladus,Titan,Miranda,Oberon,Proteus,Triton,Pluto,Kuiper Belt,Haumea,Makemake,Deep Dark,Centauri Bb,Vega B,Barnard C,Barnard E,Barnard F,T Ceti E"); one.newLine(); beanToCsv.write(towrite); one.flush(); @@ -149,7 +155,8 @@ public class CSVMaker implements Runnable { oremix.setHeight(oreLayer.worldGenHeightRange); oremix.setDensity(oreLayer.density); oremix.setWeight(oreLayer.randomWeight); - oremix.setMix(Integer.toString(oreLayer.Meta[0]) + "|" + Integer.toString(oreLayer.Meta[1]) + "|" + Integer.toString(oreLayer.Meta[2]) + "|" + Integer.toString(oreLayer.Meta[3])); + oremix.setMix(Integer.toString(oreLayer.Meta[0]) + "|" + Integer.toString(oreLayer.Meta[1]) + "|" + + Integer.toString(oreLayer.Meta[2]) + "|" + Integer.toString(oreLayer.Meta[3])); oremix.as = Dims.contains("As"); oremix.bc = Dims.contains("BC"); oremix.be = Dims.contains("BE"); @@ -186,21 +193,23 @@ public class CSVMaker implements Runnable { oremix.setEnd(Dims.contains("EN")); OreVeins.add(oremix); - System.out.println(pair.getKey() + " = " + pair.getValue()); it.remove(); // avoids a ConcurrentModificationException } BufferedWriter one = Files.newBufferedWriter(Paths.get(GTNEIOrePlugin.CSVname)); ColumnPositionMappingStrategy strat = new ColumnPositionMappingStrategy(); strat.setType(Oremix.class); - String[] columns = "ORENAME,PRIMARY,SECONDARY,INBETWEEN,AROUND,mix,TIER,HEIGHT,DENSITY,SIZE,WEIGHT,overworld,nether,end,ea,tf,mo,ma,ph,de,as,ce,eu,ga,ca,io,ve,me,en,ti,mi,ob,pr,tr,pl,kb,ha,make,dd,cb,vb,bc,be,bf,tcetie".split("\\,"); + String[] columns = + "ORENAME,PRIMARY,SECONDARY,INBETWEEN,AROUND,mix,TIER,HEIGHT,DENSITY,SIZE,WEIGHT,overworld,nether,end,ea,tf,mo,ma,ph,de,as,ce,eu,ga,ca,io,ve,me,en,ti,mi,ob,pr,tr,pl,kb,ha,make,dd,cb,vb,bc,be,bf,tcetie" + .split("\\,"); strat.setColumnMapping(columns); StatefulBeanToCsv beanToCsv = new StatefulBeanToCsvBuilder(one) .withQuotechar(CSVWriter.NO_QUOTE_CHARACTER) .withMappingStrategy(strat) .build(); List towrite = Combsort(OreVeins); - one.write("Ore Name,Primary,Secondary,Inbetween,Around,ID,Tier,Height,Density,Size,Weight,Overworld,Nether,End,End Asteroids,Twilight Forest,Moon,Mars,Phobos,Deimos,Asteroids,Ceres,Europa,Ganymede,Callisto,Io,Venus,Mercury,Enceladus,Titan,Miranda,Oberon,Proteus,Triton,Pluto,Kuiper Belt,Haumea,Makemake,Deep Dark,Centauri Bb,Vega B,Barnard C,Barnard E,Barnard F,T Ceti E"); + one.write( + "Ore Name,Primary,Secondary