aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYannickMG <yannickmg@gmail.com>2022-07-06 15:35:36 -0400
committerGitHub <noreply@github.com>2022-07-06 20:35:36 +0100
commit7836eea57a199661e1ac4b41d9ae678e62588ee2 (patch)
treeed9c71b33553fcdc58b52664b1efb3dbe4e3cb45
parent1cb11f470f296eb4db63174f7e58b17c7af7000d (diff)
downloadGT5-Unofficial-7836eea57a199661e1ac4b41d9ae678e62588ee2.tar.gz
GT5-Unofficial-7836eea57a199661e1ac4b41d9ae678e62588ee2.tar.bz2
GT5-Unofficial-7836eea57a199661e1ac4b41d9ae678e62588ee2.zip
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
-rw-r--r--build.gradle223
-rw-r--r--dependencies.gradle8
-rw-r--r--repositories.gradle36
-rw-r--r--src/main/java/pers/gwyog/gtneioreplugin/Config.java7
-rw-r--r--src/main/java/pers/gwyog/gtneioreplugin/GTNEIOrePlugin.java34
-rw-r--r--src/main/java/pers/gwyog/gtneioreplugin/plugin/PluginBase.java7
-rw-r--r--src/main/java/pers/gwyog/gtneioreplugin/plugin/gregtech5/PluginGT5Base.java76
-rw-r--r--src/main/java/pers/gwyog/gtneioreplugin/plugin/gregtech5/PluginGT5SmallOreStat.java143
-rw-r--r--src/main/java/pers/gwyog/gtneioreplugin/plugin/gregtech5/PluginGT5VeinStat.java257
-rw-r--r--src/main/java/pers/gwyog/gtneioreplugin/util/CSVMaker.java38
-rw-r--r--src/main/java/pers/gwyog/gtneioreplugin/util/DimensionHelper.java206
-rw-r--r--src/main/java/pers/gwyog/gtneioreplugin/util/GT5CFGHelper.java109
-rw-r--r--src/main/java/pers/gwyog/gtneioreplugin/util/GT5OreLayerHelper.java47
-rw-r--r--src/main/java/pers/gwyog/gtneioreplugin/util/GT5OreSmallHelper.java83
-rw-r--r--src/main/java/pers/gwyog/gtneioreplugin/util/GuiRecipeHelper.java31
-rw-r--r--src/main/java/pers/gwyog/gtneioreplugin/util/OreVeinLayer.java21
-rw-r--r--src/main/java/pers/gwyog/gtneioreplugin/util/Oremix.java49
-rw-r--r--src/main/java/pers/gwyog/gtneioreplugin/util/StringPaddingHack.java38
-rw-r--r--src/main/java/pers/gwyog/gtneioreplugin/util/Veinrenamer.java4
-rw-r--r--src/main/java/pers/gwyog/gtneioreplugin/util/XtoBool.java12
20 files changed, 838 insertions, 591 deletions
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<String, String> 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<String, String> 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<String> handleTooltip(GuiRecipe gui, List<String> 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<String> 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) {