diff --git a/HEI_gui.xcf b/HEI_gui.xcf new file mode 100644 index 0000000..9e48a1f Binary files /dev/null and b/HEI_gui.xcf differ diff --git a/build.gradle b/build.gradle index 8dd8c53..7d50d36 100644 --- a/build.gradle +++ b/build.gradle @@ -1,94 +1,59 @@ -buildscript { - repositories { - maven { - name 'MixinGradle' - url 'https://repo.spongepowered.org/repository/maven-public' - } - } - dependencies { - if (project.use_mixins.toBoolean()) { - classpath 'org.spongepowered:mixingradle:0.7.+' - } - } -} +import com.gtnewhorizons.retrofuturagradle.mcp.ReobfuscatedJar +import org.jetbrains.gradle.ext.Gradle plugins { - id 'net.minecraftforge.gradle' version '5.1.+' - id 'wtf.gofancy.fancygradle' version '1.1.+' - id 'io.github.srdjan-v.local-git-dependency' version '0.1' -} - -apply { - plugin 'net.minecraftforge.gradle' - plugin 'org.spongepowered.mixin' - plugin "maven-publish" - plugin 'java' - plugin 'idea' -} - -fancyGradle { - patches { - resources - coremods - asm - codeChickenLib - } + id("java") + id("java-library") + id("maven-publish") + id("org.jetbrains.gradle.plugin.idea-ext") version "1.1.7" + id("eclipse") + id("com.gtnewhorizons.retrofuturagradle") version "1.3.27" + id("com.matthewprenger.cursegradle") version "1.4.0" + id('io.github.srdjan-v.local-git-dependency') version '0.5.2' } +def currentBranch = ("git rev-parse --abbrev-ref HEAD").execute().inputStream.readLines().get(0) version = project.mod_version group = project.maven_group archivesBaseName = project.archives_base_name -java.toolchain.languageVersion = JavaLanguageVersion.of(8) - -idea { - module { - downloadJavadoc = true - downloadSources = true +// Set the toolchain version to decouple the Java we run Gradle with from the Java used to compile and run the mod +java { + toolchain { + languageVersion.set(JavaLanguageVersion.of(8)) + // Azul covers the most platforms for Java 8 toolchains, crucially including MacOS arm64 + vendor.set(JvmVendorSpec.AZUL) } + // Generate sources and javadocs jars when building and publishing + withSourcesJar() + //withJavadocJar() } minecraft { - - mappings channel: 'stable', version: '39-1.12' - - if (project.has_access_transformer.toBoolean()) { - accessTransformer = file('src/main/resources/META-INF/accesstransformer.cfg') + mcVersion = '1.12.2' + def args = ["-ea:${project.group}"] + if (project.use_coremod.toBoolean()) { + args << '-Dfml.coreMods.load=' + coremod_plugin_class_name } - runs { - client { - workingDirectory project.file('run/client') - if (project.use_coremod.toBoolean()) { - jvmArg '-Dfml.coreMods.load=' + coremod_plugin_class_name - } - if (project.use_mixins.toBoolean()) { - jvmArg '-Dmixin.hotSwap=true' - jvmArg '-Dmixin.checks.interfaces=true' - jvmArg '-Dmixin.debug=true' - } - property 'forge.logging.markers', 'REGISTRIES' - property 'forge.logging.console.level', 'debug' - environment 'MC_VERSION', '1.12.2' - } - - server { - workingDirectory project.file('run/server') - if (project.use_coremod.toBoolean()) { - jvmArg '-Dfml.coreMods.load=' + coremod_plugin_class_name - } - if (project.use_mixins.toBoolean()) { - jvmArg '-Dmixin.hotSwap=true' - jvmArg '-Dmixin.checks.interfaces=true' - } - property 'forge.logging.markers', 'REGISTRIES' - property 'forge.logging.console.level', 'debug' - environment 'MC_VERSION', '1.12.2' - } + if (project.use_mixins.toBoolean()) { + args << '-Dmixin.hotSwap=true' + args << '-Dmixin.checks.interfaces=true' + args << '-Dmixin.debug.export=true' } + extraRunJvmArguments.addAll(args) + + useDependencyAccessTransformers = true + injectedTags.put("VERSION", project.version) + injectedTags.put("TWEAKED_LIB_VERSION", tweaked_lib_version) } +// Generate a my.project.Tags class with the version number as a field +tasks.injectTags.configure { + outputClassName.set("${project.group}.${project.archives_base_name}.Tags") +} repositories { + mavenCentral() maven { url = 'https://maven.cleanroommc.com' } @@ -101,6 +66,10 @@ repositories { includeGroup "curse.maven" } } + maven { // TOP + name 'tterrag maven' + url "https://maven.tterrag.com/" + } maven { name 'jared maven' url 'https://maven.blamejared.com/' @@ -113,138 +82,174 @@ repositories { name = "Progwml6 maven" url = "https://dvs1.progwml6.com/files/maven/" } + mavenLocal() +} +configurations { + embed + implementation.extendsFrom(embed) } dependencies { - minecraft 'net.minecraftforge:forge:1.12.2-14.23.5.2860' + compileOnly "org.jetbrains:annotations:24.0.1" + //Hwyla + implementation "curse.maven:hwyla-253449:2568751-sources-2568752-api-2568753" + //compileOnly "curse.maven:hwyla-253449:2568751-sources-2568752-api-2568753" + //implementation "curse.maven:top-245211:2667280" + implementation "mcjty.theoneprobe:TheOneProbe-1.12:1.12-1.4.28-17" implementation 'CraftTweaker2:CraftTweaker2-MC1120-Main:1.12-4.1.20.679' - implementation fg.deobf('curse.maven:ImmersiveEngineering-231951:2974106') - implementation fg.deobf('curse.maven:ImmersivePetroleum-268250:3382321') + implementation ("com.cleanroommc:groovyscript:${project.groovy_script_version}") { + exclude group: 'mezz.jei', module: 'jei_1.12.2' + exclude group: 'curse.maven', module: 'top-245211' + exclude group: 'zone.rong', module: 'mixinbooter' + exclude group: 'codechicken', module:'codechickenlib' + } + + implementation rfg.deobf('curse.maven:ImmersiveEngineering-231951:2974106') + implementation rfg.deobf('curse.maven:ImmersivePetroleum-268250:3382321') //AdvancedRocketry - implementation fg.deobf('curse.maven:AdvancedRocketry-236542:3801020') - implementation fg.deobf('curse.maven:Libvulpes-236541:3801015') + implementation rfg.deobf('curse.maven:AdvancedRocketry-236542:3801020') + implementation rfg.deobf('curse.maven:Libvulpes-236541:3801015') - compileOnly fg.deobf('mezz.jei:jei_1.12.2:4.16.1.302:api') - runtimeOnly fg.deobf('mezz.jei:jei_1.12.2:4.16.1.302') + //compileOnly rfg.deobf('mezz.jei:jei_1.12.2:4.16.1.302:api') + //runtimeOnly rfg.deobf('mezz.jei:jei_1.12.2:4.16.1.302') //implementation fg.deobf('curse.maven:had-enough-items-557549:3862733') - compileOnly('zone.rong:mixinbooter:5.0') - runtimeOnly('zone.rong:mixinbooter:5.0') + //enables java 17 features on java 8 + annotationProcessor 'com.github.bsideup.jabel:jabel-javac-plugin:1.0.0' + annotationProcessor 'net.java.dev.jna:jna-platform:5.13.0' + compileOnly 'com.github.bsideup.jabel:jabel-javac-plugin:1.0.0' + + if (project.use_assetmover.toBoolean()) { + implementation 'com.cleanroommc:assetmover:2.0' + } + + if (project.use_mixins.toBoolean()) { + annotationProcessor 'org.ow2.asm:asm-debug-all:5.2' + annotationProcessor 'com.google.guava:guava:32.1.2-jre' + annotationProcessor 'com.google.code.gson:gson:2.8.9' + String mixinBooter = modUtils.enableMixins('zone.rong:mixinbooter:8.9') + api (mixinBooter) {transitive = false} + annotationProcessor (mixinBooter) {transitive = false} + } + + testImplementation 'org.junit.jupiter:junit-jupiter:5.9.2' } localGitDependency { - add 'https://github.com/Srdjan-V/TweakedLib.git', { - name 'TweakedLib' - tag 'v' + project.tweaked_lib_version - } + add('https://github.com/Srdjan-V/TweakedLib.git', { + buildLauncher { + startup { + mainTasks "setupCIWorkspace" + } + } + configuration("runtimeOnly") + enableIdeSupport true + mapSourceSets({ + map "main", "main" + }) + if (currentBranch == "master") { + keepGitUpdated true + tag 'v' + project.tweaked_lib_version + } else { + keepGitUpdated false + branch 'develop' + } + }) + + add('https://github.com/CleanroomMC/HadEnoughItems.git', { + buildLauncher { + setExecutable(javaToolchains.launcherFor { + languageVersion = JavaLanguageVersion.of(8) + }) + startup { + mainTasks "setupCIWorkspace" + } + } + tag project.hei_version + configuration({ + configuration("compileOnly") + include("mezz.jei:HadEnoughItems_1.12.2:${project.hei_version}-api") + }, { + configuration("runtimeOnly") + include("mezz.jei:HadEnoughItems_1.12.2:${project.hei_version}") + }) + }) } -sourceSets { - main { - if (project.use_mixins.toBoolean()) { - ext.refMap = 'mixins.' + archives_base_name + '.refmap.json' +def mixinConfigRefMap = 'mixins.' + project.archives_base_name + '.refmap.json' +def mixinTmpDir = buildDir.path + File.separator + 'tmp' + File.separator + 'mixins' +def refMap = "${mixinTmpDir}" + File.separator + mixinConfigRefMap +def mixinSrg = "${mixinTmpDir}" + File.separator + "mixins.srg" + +if (project.use_mixins.toBoolean()) { + tasks.named("reobfJar", ReobfuscatedJar).configure { + extraSrgFiles.from(mixinSrg) + } + + tasks.named("compileJava", JavaCompile).configure { + doFirst { + new File(mixinTmpDir).mkdirs() } + options.compilerArgs += [ + "-AreobfSrgFile=${tasks.reobfJar.srg.get().asFile}", + "-AoutSrgFile=${mixinSrg}", + "-AoutRefMapFile=${refMap}", + ] } } +if (project.use_access_transformer.toBoolean()) { + for (File at : sourceSets.getByName("main").resources.files) { + if (at.name.toLowerCase().endsWith("_at.cfg")) { + tasks.deobfuscateMergedJarToSrg.accessTransformerFiles.from(at) + tasks.srgifyBinpatchedJar.accessTransformerFiles.from(at) + } + } +} jar { manifest { - // noinspection GroovyAssignabilityCheck def attribute_map = [:] if (project.use_coremod.toBoolean()) { attribute_map['FMLCorePlugin'] = project.coremod_plugin_class_name if (project.include_mod.toBoolean()) { attribute_map['FMLCorePluginContainsFMLMod'] = true - attribute_map['ForceLoadAsMod'] = project.gradle.startParameter.taskNames[0] == 'build' + attribute_map['ForceLoadAsMod'] = project.gradle.startParameter.taskNames[0] == "build" } } - if (project.use_mixins.toBoolean()) { - attribute_map['TweakClass'] = 'org.spongepowered.asm.launch.MixinTweaker' + if (project.use_access_transformer.toBoolean()) { + attribute_map['FMLAT'] = project.archives_base_name + '_at.cfg' } attributes(attribute_map) } + // Add all embedded dependencies into the jar + from(provider { configurations.embed.collect { it.isDirectory() ? it : zipTree(it) } }) } -jar.finalizedBy('reobfJar') - - -import org.apache.tools.ant.filters.ReplaceTokens - -task filterTokens(type: Sync) { - - inputs.property 'version', version - inputs.property 'tweaked_lib_version', tweaked_lib_version - - from sourceSets.main.java - filter(ReplaceTokens, tokens: [VERSION: version.toString(), TWEAKEDLIB: tweaked_lib_version.toString()]) - into "$buildDir/src/$sourceSets.main.name/$sourceSets.main.java.name" -} - -compileJava.source = filterTokens.outputs - processResources { - // required to allow file expansion later - duplicatesStrategy = 'include' - // this will ensure that this task is redone when the versions change. - inputs.property 'version', version - + inputs.property 'version', project.version + inputs.property 'mcversion', project.minecraft.version // replace stuff in mcmod.info, nothing else - from(sourceSets.main.resources.srcDirs) { - include 'mcmod.info' - - // replace version - expand 'version': version - } - - // copy everything else except the mcmod.info - from(sourceSets.main.resources.srcDirs) { - exclude 'mcmod.info' - } -} - -if (project.build_deobfJar.toBoolean()) { - // Create deobf dev jars - task deobfJar(type: Jar) { - archiveClassifier.set("deobf") - from sourceSets.main.output + filesMatching(['mcmod.info', 'pack.mcmeta']) { fcd -> + // replace version and mcversion + fcd.expand( + 'version': project.version, + //'mcversion': project.minecraft.version + ) } -} -if (project.build_apiJar.toBoolean()) { - // Create API library jar - task apiZip(type: Jar) { - archiveClassifier.set("api") - from(sourceSets.main.java) { - include "name/api/**" - } - from(sourceSets.main.output) { - include "name/api/**" - } + if (project.use_access_transformer.toBoolean()) { + rename '(.+_at.cfg)', 'META-INF/$1' // Access Transformers } -} -if (project.build_sourceJar.toBoolean()) { - // Create source jar - task sourcesJar(type: Jar) { - archiveClassifier.set("sources") - from sourceSets.main.allJava - } -} - -artifacts { - if (project.build_deobfJar.toBoolean()) { - archives deobfJar - } - if (project.build_apiJar.toBoolean()) { - archives apiZip - } - if (project.build_sourceJar.toBoolean()) { - archives sourcesJar + if (project.use_mixins.toBoolean()) { + // Embed mixin refmap + from refMap + dependsOn("compileJava") } } @@ -263,7 +268,7 @@ tasks.register('updateGitVersionTag') { def invalid = true def smallestSizeArray = versionTagArray.size() > gitVersionTagArray.size() ? gitVersionTagArray.size() : versionTagArray.size() - for (i in 0.. gitVersionTagArray.get(i)) { invalid = false break @@ -285,6 +290,66 @@ tasks.register('updateGitVersionTag') { } } +idea { + module { + inheritOutputDirs = true + downloadJavadoc = true + downloadSources = true + } + project { + settings { + runConfigurations { + "1. Run Client"(Gradle) { + taskNames = ["runClient"] + } + "2. Run Server"(Gradle) { + taskNames = ["runServer"] + } + "3. Run Obfuscated Client"(Gradle) { + taskNames = ["runObfClient"] + } + "4. Run Obfuscated Server"(Gradle) { + taskNames = ["runObfServer"] + } + } + compiler.javac { + afterEvaluate { + javacAdditionalOptions = "-encoding utf8" + moduleJavacAdditionalOptions = [ + (project.name + ".main"): tasks.compileJava.options.compilerArgs.collect { '"' + it + '"' }.join(' ') + ] + } + } + } + } +} + +tasks.named("processIdeaSettings").configure { + dependsOn("injectTags") +} + +afterEvaluate { + tasks.withType(JavaCompile.class).configureEach { + options.encoding = "UTF-8" + sourceCompatibility = 17 // for the IDE support + options.release = 8 + + javaCompiler = javaToolchains.compilerFor { + languageVersion = JavaLanguageVersion.of(17) + } + } +} + +configure([tasks.javadoc]) { + javadocTool.set(javaToolchains.javadocToolFor { + languageVersion = JavaLanguageVersion.of(17) + }) +} + +tasks.named('test') { + useJUnitPlatform() +} + publishing { publications { mavenJava(MavenPublication) { diff --git a/examples/examples.zs b/examples/CraftTweaker/Reservoirs.zs similarity index 100% rename from examples/examples.zs rename to examples/CraftTweaker/Reservoirs.zs diff --git a/examples/GroovyScript/Reservoirs.groovy b/examples/GroovyScript/Reservoirs.groovy new file mode 100644 index 0000000..106774d --- /dev/null +++ b/examples/GroovyScript/Reservoirs.groovy @@ -0,0 +1,37 @@ +//Register an power tier +var power = mods.tweakedMods.PowerTier.recipeBuilder() + .capacity(5555555) + .rft(5) + .register() + +/* +This method will register a reservoir with the chance to drain fluid from the chunk. +If drainChance is set to 0.25 it will have a 25% chance to drain from the chunk +If drainChance is set to 0.5 it will have a 50% chance to drain from the chunk +If drainChance is set to 1 it will have a 100% chance to drain from the chunk, its the same as registering it normally +*/ + +//Register an fluid reservoir +mods.tweakedMods.FluidReservoir.recipeBuilder() + .name("GroovyFluidReservoir") + .fluid(fluid("lava")) + .weight(80000) + .powerTier(power) + .minSize(50) + .maxSize(1500) + .pumpSpeed(10) + .replenishRate(5) + .register() + +//Remove the default IE water reservoir +mods.tweakedMods.FluidReservoir.remove("water") + +//Modify the default IP lava reservoir +mods.tweakedMods.FluidReservoir.get("lava").toBuilder() + .drainChance(0.8).maxSize(Integer.MAX_VALUE).register() + +/* +Groovy compat is located in 'io.github.srdjanv.tweakedpetroleum.common.compat.groovy' + +Also see https://cleanroommc.com/groovy-script/ +*/ \ No newline at end of file diff --git a/gradle.properties b/gradle.properties index 5235bed..4be494b 100644 --- a/gradle.properties +++ b/gradle.properties @@ -3,28 +3,26 @@ org.gradle.jvmargs = -Xmx3G org.gradle.daemon = false +hei_version = 4.24.7 + # Mod Information -tweaked_lib_version = 1.0.0 +tweaked_lib_version = 2.0.0 +groovy_script_version = 1.0.1 -mod_version = 1.3.0 -maven_group = srki2k +mod_version = 2.0.0 +maven_group = io.github.srdjanv archives_base_name = tweakedpetroleum - -# Optionial Jar compiling -build_deobfJar = false -build_apiJar = false -build_sourceJar = true - - # If any properties changes below this line, run `gradlew setupDecompWorkspace` and refresh gradle again to ensure everything is working correctly. # Boilerplate Options use_mixins = true use_coremod = true use_assetmover = false -has_access_transformer = false + +# Access Transformer files should be in the root of `resources` folder and with the filename formatted as: `{archives_base_name}_at.cfg` +use_access_transformer = false # Coremod Arguments include_mod = true -coremod_plugin_class_name = srki2k.tweakedpetroleum.core.TweakedPetroleumPlugin \ No newline at end of file +coremod_plugin_class_name = io.github.srdjanv.tweakedpetroleum.core.TweakedPetroleumPlugin \ No newline at end of file diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index 249e583..c1962a7 100644 Binary files a/gradle/wrapper/gradle-wrapper.jar and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 8049c68..37aef8d 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,6 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.1.1-bin.zip +networkTimeout=10000 zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/gradlew b/gradlew index a69d9cb..aeb74cb 100644 --- a/gradlew +++ b/gradlew @@ -55,7 +55,7 @@ # Darwin, MinGW, and NonStop. # # (3) This script is generated from the Groovy template -# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt # within the Gradle project. # # You can find Gradle at https://github.com/gradle/gradle/. @@ -80,13 +80,10 @@ do esac done -APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit - -APP_NAME="Gradle" +# This is normally unused +# shellcheck disable=SC2034 APP_BASE_NAME=${0##*/} - -# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' +APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit # Use the maximum available, or set MAX_FD != -1 to use that value. MAX_FD=maximum @@ -143,12 +140,16 @@ fi if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then case $MAX_FD in #( max*) + # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC3045 MAX_FD=$( ulimit -H -n ) || warn "Could not query maximum file descriptor limit" esac case $MAX_FD in #( '' | soft) :;; #( *) + # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC3045 ulimit -n "$MAX_FD" || warn "Could not set maximum file descriptor limit to $MAX_FD" esac @@ -193,6 +194,10 @@ if "$cygwin" || "$msys" ; then done fi + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + # Collect all arguments for the java command; # * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of # shell script including quotes and variable substitutions, so put them in diff --git a/gradlew.bat b/gradlew.bat index f127cfd..93e3f59 100644 --- a/gradlew.bat +++ b/gradlew.bat @@ -26,6 +26,7 @@ if "%OS%"=="Windows_NT" setlocal set DIRNAME=%~dp0 if "%DIRNAME%"=="" set DIRNAME=. +@rem This is normally unused set APP_BASE_NAME=%~n0 set APP_HOME=%DIRNAME% diff --git a/settings.gradle b/settings.gradle index c27922a..505a59e 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,13 +1,22 @@ pluginManagement { repositories { - gradlePluginPortal() - maven { - name 'FancyGradle' - url 'https://gitlab.com/api/v4/projects/26758973/packages/maven' - } maven { - name 'ForgeGradle 5' - url 'https://maven.minecraftforge.net' + // RetroFuturaGradle + name = "GTNH Maven" + url = uri("http://jenkins.usrv.eu:8081/nexus/content/groups/public/") + allowInsecureProtocol = true + mavenContent { + includeGroup("com.gtnewhorizons") + includeGroup("com.gtnewhorizons.retrofuturagradle") + } } + gradlePluginPortal() + mavenCentral() + mavenLocal() } +} + +plugins { + // Automatic toolchain provisioning + id("org.gradle.toolchains.foojay-resolver-convention") version "0.5.0" } \ No newline at end of file diff --git a/src/main/java/srki2k/tweakedpetroleum/TweakedPetroleum.java b/src/main/java/io/github/srdjanv/tweakedpetroleum/TweakedPetroleum.java similarity index 65% rename from src/main/java/srki2k/tweakedpetroleum/TweakedPetroleum.java rename to src/main/java/io/github/srdjanv/tweakedpetroleum/TweakedPetroleum.java index fd568cb..5196899 100644 --- a/src/main/java/srki2k/tweakedpetroleum/TweakedPetroleum.java +++ b/src/main/java/io/github/srdjanv/tweakedpetroleum/TweakedPetroleum.java @@ -1,16 +1,18 @@ -package srki2k.tweakedpetroleum; +package io.github.srdjanv.tweakedpetroleum; +import io.github.srdjanv.tweakedlib.api.integration.DiscoveryHandler; +import io.github.srdjanv.tweakedpetroleum.util.TweakedPetroleumErrorLogging; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.common.config.ConfigManager; import net.minecraftforge.fml.client.event.ConfigChangedEvent; import net.minecraftforge.fml.common.Mod; +import net.minecraftforge.fml.common.event.FMLConstructionEvent; import net.minecraftforge.fml.common.event.FMLInitializationEvent; +import net.minecraftforge.fml.common.event.FMLPostInitializationEvent; import net.minecraftforge.fml.common.event.FMLPreInitializationEvent; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -import srki2k.tweakedpetroleum.common.DefaultReservoirs; -import srki2k.tweakedpetroleum.util.TweakedPetroleumErrorLogging; @Mod(modid = TweakedPetroleum.MODID, @@ -18,11 +20,11 @@ name = "Tweaked Petroleum", dependencies = "required-after:immersivepetroleum;" + "required-after:crafttweaker;" + - "required-after:tweakedlib@[@TWEAKEDLIB@,)") + "required-after:tweakedlib@[" + Tags.TWEAKED_LIB_VERSION + ",)") public class TweakedPetroleum { public static final String MODID = "tweakedpetroleum"; - public static final String VERSION = "@VERSION@"; + public static final String VERSION = Tags.VERSION; public static final Logger LOGGER = LogManager.getLogger(MODID); @@ -36,12 +38,17 @@ public void onConfigChangedEvent(ConfigChangedEvent.OnConfigChangedEvent event) @Mod.EventHandler public void preInit(FMLPreInitializationEvent event) { MinecraftForge.EVENT_BUS.register(this); + DiscoveryHandler.getInstance().preInit(event); } @Mod.EventHandler public void init(FMLInitializationEvent event) { - DefaultReservoirs.init(); - TweakedPetroleumErrorLogging.register(); + DiscoveryHandler.getInstance().init(event); + } + + @Mod.EventHandler + public void postInit(final FMLPostInitializationEvent event) { + DiscoveryHandler.getInstance().postInit(event); } } \ No newline at end of file diff --git a/src/main/java/srki2k/tweakedpetroleum/api/crafting/TweakedPumpjackHandler.java b/src/main/java/io/github/srdjanv/tweakedpetroleum/api/crafting/TweakedPumpjackHandler.java similarity index 83% rename from src/main/java/srki2k/tweakedpetroleum/api/crafting/TweakedPumpjackHandler.java rename to src/main/java/io/github/srdjanv/tweakedpetroleum/api/crafting/TweakedPumpjackHandler.java index 731650c..58c776d 100644 --- a/src/main/java/srki2k/tweakedpetroleum/api/crafting/TweakedPumpjackHandler.java +++ b/src/main/java/io/github/srdjanv/tweakedpetroleum/api/crafting/TweakedPumpjackHandler.java @@ -1,11 +1,11 @@ -package srki2k.tweakedpetroleum.api.crafting; +package io.github.srdjanv.tweakedpetroleum.api.crafting; import blusunrize.immersiveengineering.api.DimensionChunkCoords; import flaxbeard.immersivepetroleum.api.crafting.PumpjackHandler; +import io.github.srdjanv.tweakedlib.api.powertier.PowerTier; +import io.github.srdjanv.tweakedlib.api.powertier.PowerTierHandler; +import io.github.srdjanv.tweakedpetroleum.api.mixins.ITweakedPetReservoirType; import net.minecraft.world.World; -import srki2k.tweakedlib.api.powertier.PowerTier; -import srki2k.tweakedlib.api.powertier.PowerTierHandler; -import srki2k.tweakedpetroleum.api.ihelpers.IReservoirType; import static flaxbeard.immersivepetroleum.api.crafting.PumpjackHandler.*; @@ -27,7 +27,7 @@ public static PowerTier getPowerTier(World world, int chunkX, int chunkZ) { return PowerTierHandler.getFallbackPowerTier(); } - IReservoirType tweakedReservoirType = (IReservoirType) info.getType(); + ITweakedPetReservoirType tweakedReservoirType = (ITweakedPetReservoirType) info.getType(); return PowerTierHandler.getPowerTier(tweakedReservoirType.getPowerTier()); } @@ -44,11 +44,11 @@ public static PowerTier getPowerTier(World world, int chunkX, int chunkZ) { * @param powerTier The tier of power usage * @return The created TweakedReservoirType */ - public static IReservoirType addTweakedReservoir(String name, String fluid, int minSize, int maxSize, int replenishRate, int pumpSpeed, int weight, int powerTier) { + public static ITweakedPetReservoirType addTweakedReservoir(String name, String fluid, int minSize, int maxSize, int replenishRate, int pumpSpeed, int weight, int powerTier) { ReservoirType mix = new ReservoirType(name, fluid, minSize, maxSize, replenishRate); reservoirList.put(mix, weight); - IReservoirType iMix = (IReservoirType) mix; + ITweakedPetReservoirType iMix = (ITweakedPetReservoirType) mix; iMix.setPumpSpeed(pumpSpeed); iMix.setPowerTier(powerTier); @@ -71,7 +71,7 @@ public static int[] getReplenishRateAndPumpSpeed(World world, int chunkX, int ch return replenishRateAndPumpSpeed; } - IReservoirType tweakedReservoirType = (IReservoirType) info.getType(); + ITweakedPetReservoirType tweakedReservoirType = (ITweakedPetReservoirType) info.getType(); if (tweakedReservoirType.getPumpSpeed() == 0) { return replenishRateAndPumpSpeed; @@ -117,8 +117,9 @@ public static ReservoirContent getReservoirContent(World world, int chunkX, int return ReservoirContent.EMPTY; } - return ((IReservoirType) info.getType()).getReservoirContent(); + return ((ITweakedPetReservoirType) info.getType()).getReservoirContent(); } + public enum ReservoirContent { LIQUID, GAS, EMPTY, DEFAULT } diff --git a/src/main/java/srki2k/tweakedpetroleum/api/ihelpers/IPumpjackAddons.java b/src/main/java/io/github/srdjanv/tweakedpetroleum/api/mixins/ITweakedPetPumpjackAddons.java similarity index 60% rename from src/main/java/srki2k/tweakedpetroleum/api/ihelpers/IPumpjackAddons.java rename to src/main/java/io/github/srdjanv/tweakedpetroleum/api/mixins/ITweakedPetPumpjackAddons.java index 3381cbe..716bb95 100644 --- a/src/main/java/srki2k/tweakedpetroleum/api/ihelpers/IPumpjackAddons.java +++ b/src/main/java/io/github/srdjanv/tweakedpetroleum/api/mixins/ITweakedPetPumpjackAddons.java @@ -1,8 +1,8 @@ -package srki2k.tweakedpetroleum.api.ihelpers; +package io.github.srdjanv.tweakedpetroleum.api.mixins; -import srki2k.tweakedpetroleum.api.crafting.TweakedPumpjackHandler; +import io.github.srdjanv.tweakedpetroleum.api.crafting.TweakedPumpjackHandler; -public interface IPumpjackAddons { +public interface ITweakedPetPumpjackAddons { void initEnergyStorage(); diff --git a/src/main/java/io/github/srdjanv/tweakedpetroleum/api/mixins/ITweakedPetReservoirType.java b/src/main/java/io/github/srdjanv/tweakedpetroleum/api/mixins/ITweakedPetReservoirType.java new file mode 100644 index 0000000..27effe6 --- /dev/null +++ b/src/main/java/io/github/srdjanv/tweakedpetroleum/api/mixins/ITweakedPetReservoirType.java @@ -0,0 +1,7 @@ +package io.github.srdjanv.tweakedpetroleum.api.mixins; + +public interface ITweakedPetReservoirType extends ITweakedPetReservoirTypeGetters, ITweakedPetReservoirTypeSetters { + +} + + diff --git a/src/main/java/io/github/srdjanv/tweakedpetroleum/api/mixins/ITweakedPetReservoirTypeGetters.java b/src/main/java/io/github/srdjanv/tweakedpetroleum/api/mixins/ITweakedPetReservoirTypeGetters.java new file mode 100644 index 0000000..65c2f12 --- /dev/null +++ b/src/main/java/io/github/srdjanv/tweakedpetroleum/api/mixins/ITweakedPetReservoirTypeGetters.java @@ -0,0 +1,31 @@ +package io.github.srdjanv.tweakedpetroleum.api.mixins; + +import io.github.srdjanv.tweakedpetroleum.api.crafting.TweakedPumpjackHandler; + +public interface ITweakedPetReservoirTypeGetters { + String getName(); + + String getStringFluid(); + + int getMinSize(); + + int getMaxSize(); + + int getReplenishRate(); + + int getPowerTier(); + + int getPumpSpeed(); + + float getDrainChance(); + + int[] getDimensionWhitelist(); + + int[] getDimensionBlacklist(); + + String[] getBiomeWhitelist(); + + String[] getBiomeBlacklist(); + + TweakedPumpjackHandler.ReservoirContent getReservoirContent(); +} diff --git a/src/main/java/io/github/srdjanv/tweakedpetroleum/api/mixins/ITweakedPetReservoirTypeSetters.java b/src/main/java/io/github/srdjanv/tweakedpetroleum/api/mixins/ITweakedPetReservoirTypeSetters.java new file mode 100644 index 0000000..b8f4dd8 --- /dev/null +++ b/src/main/java/io/github/srdjanv/tweakedpetroleum/api/mixins/ITweakedPetReservoirTypeSetters.java @@ -0,0 +1,21 @@ +package io.github.srdjanv.tweakedpetroleum.api.mixins; + +import io.github.srdjanv.tweakedpetroleum.api.crafting.TweakedPumpjackHandler; + +public interface ITweakedPetReservoirTypeSetters { + void setDimensionWhitelist(int[] dimWhitelist); + + void setDimensionBlacklist(int[] biomeBlacklistList); + + void setBiomeBlacklist(String[] dimBlacklist); + + void setBiomeWhitelist(String[] biomeWhitelistList); + + void setReservoirContent(TweakedPumpjackHandler.ReservoirContent reservoirContents); + + void setPowerTier(int i); + + void setPumpSpeed(int i); + + void setDrainChance(float f); +} diff --git a/src/main/java/srki2k/tweakedpetroleum/client/hei/HEIPlugin.java b/src/main/java/io/github/srdjanv/tweakedpetroleum/client/hei/HEIPlugin.java similarity index 74% rename from src/main/java/srki2k/tweakedpetroleum/client/hei/HEIPlugin.java rename to src/main/java/io/github/srdjanv/tweakedpetroleum/client/hei/HEIPlugin.java index 3218680..c254b80 100644 --- a/src/main/java/srki2k/tweakedpetroleum/client/hei/HEIPlugin.java +++ b/src/main/java/io/github/srdjanv/tweakedpetroleum/client/hei/HEIPlugin.java @@ -1,17 +1,17 @@ -package srki2k.tweakedpetroleum.client.hei; +package io.github.srdjanv.tweakedpetroleum.client.hei; import flaxbeard.immersivepetroleum.api.crafting.PumpjackHandler; import flaxbeard.immersivepetroleum.common.IPContent; import flaxbeard.immersivepetroleum.common.blocks.metal.BlockTypes_IPMetalMultiblock; +import io.github.srdjanv.tweakedlib.api.hei.BaseHEIUtil; +import io.github.srdjanv.tweakedlib.common.Constants; +import io.github.srdjanv.tweakedpetroleum.TweakedPetroleum; +import io.github.srdjanv.tweakedpetroleum.api.crafting.TweakedPumpjackHandler; +import io.github.srdjanv.tweakedpetroleum.api.mixins.ITweakedPetReservoirType; import mezz.jei.api.IModPlugin; import mezz.jei.api.IModRegistry; import mezz.jei.api.recipe.IRecipeCategoryRegistration; import net.minecraft.item.ItemStack; -import srki2k.tweakedlib.api.hei.BaseHEIUtil; -import srki2k.tweakedlib.common.Constants; -import srki2k.tweakedpetroleum.TweakedPetroleum; -import srki2k.tweakedpetroleum.api.crafting.TweakedPumpjackHandler; -import srki2k.tweakedpetroleum.api.ihelpers.IReservoirType; import java.util.Collection; import java.util.stream.Collectors; @@ -27,7 +27,6 @@ public void registerCategories(IRecipeCategoryRegistration registry) { registry.addRecipeCategories(new PumpjackCategory()); } - @Override public void register(IModRegistry registry) { registry.handleRecipes(PumpjackHandler.ReservoirType.class, PumpjackWrapper::new, PumpjackCategory.UID); @@ -38,7 +37,7 @@ public void register(IModRegistry registry) { private Collection getRecipes() { if (Constants.isTweakedPetroleumGasLoaded()) { return PumpjackHandler.reservoirList.keySet().stream(). - filter(reservoirType -> ((IReservoirType) reservoirType).getReservoirContent() == TweakedPumpjackHandler.ReservoirContent.LIQUID). + filter(reservoirType -> ((ITweakedPetReservoirType) reservoirType).getReservoirContent() == TweakedPumpjackHandler.ReservoirContent.LIQUID). collect(Collectors.toList()); } diff --git a/src/main/java/srki2k/tweakedpetroleum/client/hei/PumpjackCategory.java b/src/main/java/io/github/srdjanv/tweakedpetroleum/client/hei/PumpjackCategory.java similarity index 71% rename from src/main/java/srki2k/tweakedpetroleum/client/hei/PumpjackCategory.java rename to src/main/java/io/github/srdjanv/tweakedpetroleum/client/hei/PumpjackCategory.java index b8fffe4..75c205a 100644 --- a/src/main/java/srki2k/tweakedpetroleum/client/hei/PumpjackCategory.java +++ b/src/main/java/io/github/srdjanv/tweakedpetroleum/client/hei/PumpjackCategory.java @@ -1,12 +1,12 @@ -package srki2k.tweakedpetroleum.client.hei; +package io.github.srdjanv.tweakedpetroleum.client.hei; +import io.github.srdjanv.tweakedpetroleum.TweakedPetroleum; +import io.github.srdjanv.tweakedpetroleum.util.HEIPumpjackUtil; import mezz.jei.api.gui.IDrawable; import mezz.jei.api.gui.IGuiFluidStackGroup; import mezz.jei.api.gui.IRecipeLayout; import mezz.jei.api.ingredients.IIngredients; import mezz.jei.api.recipe.IRecipeCategory; -import srki2k.tweakedlib.api.hei.BaseHEIUtil; -import srki2k.tweakedpetroleum.TweakedPetroleum; @SuppressWarnings("NullableProblems") public class PumpjackCategory implements IRecipeCategory { @@ -19,7 +19,7 @@ public String getUid() { @Override public String getTitle() { - return BaseHEIUtil.translateToLocal("tile.immersivepetroleum.metal_multiblock.pumpjack.name"); + return HEIPumpjackUtil.translateToLocal("tile.immersivepetroleum.metal_multiblock.pumpjack.name"); } @Override @@ -29,7 +29,7 @@ public String getModName() { @Override public IDrawable getBackground() { - return BaseHEIUtil.getPumpjackBackground(); + return HEIPumpjackUtil.getPumpjackBackground(); } @Override @@ -37,10 +37,10 @@ public void setRecipe(IRecipeLayout recipeLayout, PumpjackWrapper recipeWrapper, IGuiFluidStackGroup outputGuiFluids = recipeLayout.getFluidStacks(); outputGuiFluids.addTooltipCallback(recipeWrapper); - outputGuiFluids.init(0, false, 12, 10, 16, 60, recipeWrapper.getMaxFluid(), false, null); + outputGuiFluids.init(0, false, 12, 23, 16, 47, recipeWrapper.getMaxFluid(), false, null); outputGuiFluids.set(0, recipeWrapper.getAverageFluid()); - outputGuiFluids.init(1, false, 36, 10, 16, 60, recipeWrapper.getPumpSpeed(), false, null); + outputGuiFluids.init(1, false, 36, 23, 16, 47, recipeWrapper.getPumpSpeed(), false, null); outputGuiFluids.set(1, recipeWrapper.getReplenishRateFluid()); } diff --git a/src/main/java/io/github/srdjanv/tweakedpetroleum/client/hei/PumpjackWrapper.java b/src/main/java/io/github/srdjanv/tweakedpetroleum/client/hei/PumpjackWrapper.java new file mode 100644 index 0000000..614772d --- /dev/null +++ b/src/main/java/io/github/srdjanv/tweakedpetroleum/client/hei/PumpjackWrapper.java @@ -0,0 +1,108 @@ +package io.github.srdjanv.tweakedpetroleum.client.hei; + +import com.google.common.collect.Lists; +import flaxbeard.immersivepetroleum.api.crafting.PumpjackHandler; +import flaxbeard.immersivepetroleum.common.Config; +import io.github.srdjanv.tweakedpetroleum.api.mixins.ITweakedPetReservoirType; +import io.github.srdjanv.tweakedpetroleum.common.Configs; +import io.github.srdjanv.tweakedpetroleum.util.HEIPumpjackUtil; +import mezz.jei.api.gui.ITooltipCallback; +import mezz.jei.api.ingredients.IIngredients; +import mezz.jei.api.ingredients.VanillaTypes; +import mezz.jei.api.recipe.IRecipeWrapper; +import net.minecraft.client.Minecraft; +import net.minecraftforge.fluids.Fluid; +import net.minecraftforge.fluids.FluidStack; + +import java.util.List; +import java.util.function.Consumer; + +import static flaxbeard.immersivepetroleum.api.crafting.PumpjackHandler.reservoirList; + +public class PumpjackWrapper implements IRecipeWrapper, ITooltipCallback { + private final ITweakedPetReservoirType reservoir; + private final Fluid reservoirFluid; + + public PumpjackWrapper(PumpjackHandler.ReservoirType reservoir) { + this.reservoir = (ITweakedPetReservoirType) reservoir; + reservoirFluid = reservoir.getFluid(); + } + + public FluidStack getReplenishRateFluid() { + return new FluidStack(reservoirFluid, reservoir.getReplenishRate()); + } + + public int getPumpSpeed() { + return reservoir.getPumpSpeed(); + } + + public int getMaxFluid() { + return reservoir.getMaxSize(); + } + + public FluidStack getAverageFluid() { + return new FluidStack(reservoirFluid, getAverage()); + } + + public int getAverage() { + return (int) (((long) reservoir.getMaxSize() + reservoir.getMinSize()) / 2); + } + + @Override + public void getIngredients(IIngredients ingredients) { + ingredients.setOutputs(VanillaTypes.FLUID, Lists.newArrayList(getAverageFluid())); + } + + private int getStringWidth() { + return Math.min(77, Minecraft.getMinecraft().fontRenderer.getStringWidth(reservoir.getName()) + 6); + } + + @Override + public List getTooltipStrings(int mouseX, int mouseY) { + Consumer> customWarnings = null; + if (reservoir.getDrainChance() != 1f) { + customWarnings = list-> list.add(HEIPumpjackUtil.translateToLocal("tweakedpetroleum.jei.reservoir.draw_chance1") + " " + reservoir.getDrainChance() * 100 + + HEIPumpjackUtil.translateToLocal("tweakedpetroleum.jei.reservoir.draw_chance2") + " " + (100f - (reservoir.getDrainChance() * 100)) + + HEIPumpjackUtil.translateToLocal("tweakedpetroleum.jei.reservoir.draw_chance3") + ); + } + if (Config.IPConfig.Extraction.req_pipes) { + customWarnings = list -> list.add(HEIPumpjackUtil.translateToLocal("tweakedpetroleum.jei.reservoir.req_pipes")); + } + + return HEIPumpjackUtil.tooltipStrings(mouseX, mouseY, customWarnings, reservoir, this::getAverage, this::getStringWidth); + } + + @Override + @SuppressWarnings("NullableProblems") + public void drawInfo(Minecraft minecraft, int recipeWidth, int recipeHeight, int mouseX, int mouseY) { + if (Configs.TPConfig.HEIConfig.drawPowerTier) HEIPumpjackUtil.drawPowerTier(minecraft,57, 50, reservoir.getPowerTier()); + if (Configs.TPConfig.HEIConfig.drawSpawnWeight) HEIPumpjackUtil.drawSpawnWeight(minecraft,57, 70, reservoirList.get((PumpjackHandler.ReservoirType) reservoir)); + + int warningCount = 0; + if (Config.IPConfig.Extraction.req_pipes) { + warningCount++; + } + + if (reservoir.getDrainChance() != 1f) { + warningCount++; + } + + if (warningCount > 0) { + HEIPumpjackUtil.getPumpjackWarning().draw(minecraft, 56, 24); + minecraft.fontRenderer.drawString(String.valueOf(warningCount), 56, 22, 16696077); + } + + if (getStringWidth() >= 77) { + minecraft.fontRenderer.drawString(minecraft.fontRenderer.trimStringToWidth( + HEIPumpjackUtil.formatString(reservoir.getName()), 68).concat("..."), 6, 6, 15658734); + return; + } + minecraft.fontRenderer.drawString(HEIPumpjackUtil.formatString(reservoir.getName()), 6, 6, 15658734); + } + + @Override + public void onTooltip(int slotIndex, boolean input, FluidStack ingredient, List tooltip) { + HEIPumpjackUtil.onTooltip(slotIndex, reservoir, ingredient.amount, ingredient.getLocalizedName(), tooltip); + } +} diff --git a/src/main/java/io/github/srdjanv/tweakedpetroleum/common/Configs.java b/src/main/java/io/github/srdjanv/tweakedpetroleum/common/Configs.java new file mode 100644 index 0000000..9473244 --- /dev/null +++ b/src/main/java/io/github/srdjanv/tweakedpetroleum/common/Configs.java @@ -0,0 +1,63 @@ +package io.github.srdjanv.tweakedpetroleum.common; + +import io.github.srdjanv.tweakedpetroleum.TweakedPetroleum; +import net.minecraftforge.common.config.Config; +import net.minecraftforge.common.config.Config.Comment; +import net.minecraftforge.common.config.Config.Name; +import net.minecraftforge.common.config.Config.RangeInt; +import net.minecraftforge.common.config.Config.RequiresMcRestart; + +public class Configs { + + @Config(modid = TweakedPetroleum.MODID) + public static class TPConfig { + + @Name("Default Reservoirs") + public static DefaultReservoirs defaultReservoirs; + + public static class DefaultReservoirs { + @Comment({"This will enable reservoir registration from IP's configs, default=true"}) + @Name("Register Reservoirs From Config") + @RequiresMcRestart + public static boolean enableIPConfigReservoirRegistration = true; + + @Name("Default Pumpjack Power Tiers") + public static DefaultPumpjackPowerTiers defaultPumpjackPowerTiers; + + public static class DefaultPumpjackPowerTiers { + + @Comment({"This will set the capacity of the pumpjack, default=16000"}) + @Name("Default capacity") + @RangeInt(min = 1) + @RequiresMcRestart + public static int capacity = 16000; + + @Comment({"This will set the power consumption of the pumpjack, default=1024"}) + @Name("Default consumption") + @RangeInt(min = 1) + @RequiresMcRestart + public static int rft = 1024; + + @Comment({"This will set the pump speed of the pumpjack, default=25"}) + @Name("Default pump speed") + @RangeInt(min = 1) + @RequiresMcRestart + public static int pump_speed = 25; + } + } + + @Name("JEI Config") + public static HEIConfig heiConfig; + + public static class HEIConfig { + + @Name("Draw PowerTier") + public static boolean drawPowerTier = true; + + @Name("Draw SpawnWeight") + public static boolean drawSpawnWeight = true; + + } + } + +} \ No newline at end of file diff --git a/src/main/java/io/github/srdjanv/tweakedpetroleum/common/DefaultReservoirs.java b/src/main/java/io/github/srdjanv/tweakedpetroleum/common/DefaultReservoirs.java new file mode 100644 index 0000000..88b0f0f --- /dev/null +++ b/src/main/java/io/github/srdjanv/tweakedpetroleum/common/DefaultReservoirs.java @@ -0,0 +1,44 @@ +package io.github.srdjanv.tweakedpetroleum.common; + +import flaxbeard.immersivepetroleum.api.crafting.PumpjackHandler; +import io.github.srdjanv.tweakedlib.api.powertier.PowerTierHandler; +import io.github.srdjanv.tweakedpetroleum.api.crafting.TweakedPumpjackHandler; +import io.github.srdjanv.tweakedpetroleum.api.mixins.ITweakedPetReservoirType; +import io.github.srdjanv.tweakedpetroleum.util.TweakedPetroleumInitializer; +import net.minecraftforge.fml.common.event.FMLPreInitializationEvent; + +import java.util.Objects; + +import static flaxbeard.immersivepetroleum.api.crafting.PumpjackHandler.reservoirList; + +public class DefaultReservoirs implements TweakedPetroleumInitializer { + private static DefaultReservoirs instance; + + public static DefaultReservoirs getInstance() { + return Objects.requireNonNull(instance); + } + + public DefaultReservoirs() { + instance = this; + } + + @Override public boolean shouldRun() { + return Configs.TPConfig.DefaultReservoirs.enableIPConfigReservoirRegistration; + } + + private int powerTier; + + @Override public void preInit(FMLPreInitializationEvent event) { + powerTier = PowerTierHandler.registerPowerTier( + Configs.TPConfig.DefaultReservoirs.DefaultPumpjackPowerTiers.capacity, + Configs.TPConfig.DefaultReservoirs.DefaultPumpjackPowerTiers.rft); + } + + public int defaultPowerTier() { + return powerTier; + } + + public int defaultPumpSpeed() { + return Configs.TPConfig.DefaultReservoirs.DefaultPumpjackPowerTiers.pump_speed; + } +} diff --git a/src/main/java/io/github/srdjanv/tweakedpetroleum/common/compat/crafttweaker/TweakedReservoir.java b/src/main/java/io/github/srdjanv/tweakedpetroleum/common/compat/crafttweaker/TweakedReservoir.java new file mode 100644 index 0000000..4c23ed5 --- /dev/null +++ b/src/main/java/io/github/srdjanv/tweakedpetroleum/common/compat/crafttweaker/TweakedReservoir.java @@ -0,0 +1,78 @@ +package io.github.srdjanv.tweakedpetroleum.common.compat.crafttweaker; + +import crafttweaker.CraftTweakerAPI; +import crafttweaker.annotations.ZenRegister; +import crafttweaker.api.liquid.ILiquidStack; +import io.github.srdjanv.tweakedlib.api.powertier.PowerTierHandler; +import io.github.srdjanv.tweakedpetroleum.api.crafting.TweakedPumpjackHandler; +import io.github.srdjanv.tweakedpetroleum.api.mixins.ITweakedPetReservoirType; +import io.github.srdjanv.tweakedpetroleum.util.ReservoirValidation; +import stanhebben.zenscript.annotations.Optional; +import stanhebben.zenscript.annotations.ZenClass; +import stanhebben.zenscript.annotations.ZenMethod; + +@SuppressWarnings("unused") +@ZenClass("mods.TweakedPetroleum.TweakedReservoir") +@ZenRegister +public class TweakedReservoir { + + @ZenMethod + public static void registerReservoir(String name, ILiquidStack fluid, int minSize, int maxSize, int replenishRate, int pumpSpeed, int weight, int powerTier, + @Optional int[] dimBlacklist, @Optional int[] dimWhitelist, @Optional String[] biomeBlacklist, @Optional String[] biomeWhitelist) { + ITweakedPetReservoirType res; + if (ReservoirValidation.validateReservoir(CraftTweakerAPI::logError, name, fluid, + minSize, maxSize, replenishRate, pumpSpeed, weight, powerTier, + biomeBlacklist, biomeWhitelist)) { + res = TweakedPumpjackHandler.addTweakedReservoir(name, fluid.getName(), minSize, maxSize, replenishRate, pumpSpeed, weight, powerTier); + } else { + if (name != null && !name.isEmpty()) { + CraftTweakerAPI.logError(String.format("Added dummy reservoir: %s", name)); + TweakedPumpjackHandler.addTweakedReservoir(name, "water", 0, 10, 0, 10, 0, PowerTierHandler.getFallbackPowerTier().getId()); + } + return; + } + + res.setReservoirContent(TweakedPumpjackHandler.ReservoirContent.LIQUID); + if (dimBlacklist != null) res.setDimensionBlacklist(dimBlacklist); + if (dimWhitelist != null) res.setDimensionWhitelist(dimWhitelist); + if (biomeBlacklist != null) res.setBiomeBlacklist(biomeBlacklist); + if (biomeWhitelist != null) res.setBiomeWhitelist(biomeWhitelist); + + CraftTweakerAPI.logInfo("Added Reservoir Type: " + name); + } + + @ZenMethod + public static void registerReservoirWithDrainChance(String name, ILiquidStack fluid, int minSize, int maxSize, int replenishRate, int pumpSpeed, float drainChance, int weight, int powerTier, + @Optional int[] dimBlacklist, @Optional int[] dimWhitelist, @Optional String[] biomeBlacklist, @Optional String[] biomeWhitelist) { + + ITweakedPetReservoirType res; + if (ReservoirValidation.validateReservoir(CraftTweakerAPI::logError, name, fluid, + minSize, maxSize, replenishRate, pumpSpeed, weight, powerTier, drainChance, + biomeBlacklist, biomeWhitelist)) { + res = TweakedPumpjackHandler.addTweakedReservoir(name, fluid.getName(), minSize, maxSize, replenishRate, pumpSpeed, weight, powerTier); + } else { + if (name != null && !name.isEmpty()) { + CraftTweakerAPI.logError(String.format("Added dummy reservoir: %s", name)); + TweakedPumpjackHandler.addTweakedReservoir(name, "water", 0, 10, 0, 10, 0, PowerTierHandler.getFallbackPowerTier().getId()); + } + return; + } + + res.setReservoirContent(TweakedPumpjackHandler.ReservoirContent.LIQUID); + res.setDrainChance(drainChance); + if (dimBlacklist != null) res.setDimensionBlacklist(dimBlacklist); + if (dimWhitelist != null) res.setDimensionWhitelist(dimWhitelist); + if (biomeBlacklist != null) res.setBiomeBlacklist(biomeBlacklist); + if (biomeWhitelist != null) res.setBiomeWhitelist(biomeWhitelist); + + CraftTweakerAPI.logInfo("Added Reservoir Type: " + name); + } + + @ZenMethod + @Deprecated + public static void registerPowerUsage(int tier, int capacity, int rft) { + CraftTweakerAPI.logError("This method is deprecated 'mods.TweakedPetroleum.TweakedReservoir.registerPowerUsage()"); + CraftTweakerAPI.logError("Go see https://github.com/Srdjan-V/TweakedPetroleum/blob/master/examples/examples.zs for the new way of adding Powertiers"); + } + +} \ No newline at end of file diff --git a/src/main/java/io/github/srdjanv/tweakedpetroleum/common/compat/groovy/FluidReservoir.java b/src/main/java/io/github/srdjanv/tweakedpetroleum/common/compat/groovy/FluidReservoir.java new file mode 100644 index 0000000..00bdd3f --- /dev/null +++ b/src/main/java/io/github/srdjanv/tweakedpetroleum/common/compat/groovy/FluidReservoir.java @@ -0,0 +1,107 @@ +package io.github.srdjanv.tweakedpetroleum.common.compat.groovy; + +import com.cleanroommc.groovyscript.api.GroovyLog; +import flaxbeard.immersivepetroleum.api.crafting.PumpjackHandler; +import io.github.srdjanv.tweakedpetroleum.api.crafting.TweakedPumpjackHandler; +import io.github.srdjanv.tweakedpetroleum.api.mixins.ITweakedPetReservoirType; +import io.github.srdjanv.tweakedpetroleum.util.ReservoirValidation; +import net.minecraftforge.fluids.Fluid; +import net.minecraftforge.fluids.FluidStack; + +import java.util.Arrays; +import java.util.function.BiFunction; + +public class FluidReservoir extends VirtualizedReservoirRegistry< + ITweakedPetReservoirType, + FluidReservoir.FluidReservoirBuilder, + FluidReservoir.FluidReservoirWrapper> { + + private final BiFunction reservoirTypeWrapperFunction = FluidReservoirWrapper::new; + + @Override protected BiFunction getReservoirTypeWrapperFunction() { + return reservoirTypeWrapperFunction; + } + + public FluidReservoir() { + super("Fluid"); + } + + @Override public FluidReservoirBuilder recipeBuilder() { + return new FluidReservoirBuilder(); + } + + public class FluidReservoirBuilder extends ReservoirBuilder { + protected String fluid; + + public FluidReservoirBuilder fluid(FluidStack fluid) { + fluid(fluid.getFluid()); + return this; + } + + public FluidReservoirBuilder fluid(Fluid fluid) { + fluid(fluid.getName()); + return this; + } + + public FluidReservoirBuilder fluid(String fluid) { + this.fluid = fluid; + return this; + } + + @Override + public boolean validate() { + GroovyLog.Msg msg = GroovyLog.msg("Error adding custom fluid reservoir").error(); + ReservoirValidation.validateReservoir(msg::add, name, fluid, minSize, maxSize, replenishRate, pumpSpeed, weight, powerTier, drainChance.floatValue(), + biomeBlacklist == null ? null : biomeBlacklist.toArray(new String[]{}), biomeWhitelist == null ? null : biomeWhitelist.toArray(new String[]{})); + + return !msg.postIfNotEmpty(); + } + + @SuppressWarnings("UnreachableCode") @Override + public FluidReservoirWrapper register() { + if (!validate()) return null; + ITweakedPetReservoirType res = (ITweakedPetReservoirType) new PumpjackHandler.ReservoirType(name, fluid, minSize, maxSize, replenishRate); + + res.setDrainChance(drainChance.floatValue()); + res.setPumpSpeed(pumpSpeed); + res.setPowerTier(powerTier); + res.setReservoirContent(TweakedPumpjackHandler.ReservoirContent.LIQUID); + if (dimBlacklist != null) res.setDimensionBlacklist(dimBlacklist.toIntArray()); + if (dimWhitelist != null) res.setDimensionWhitelist(dimWhitelist.toIntArray()); + if (biomeBlacklist != null) res.setBiomeBlacklist(biomeBlacklist.toArray(new String[]{})); + if (biomeWhitelist != null) res.setBiomeWhitelist(biomeWhitelist.toArray(new String[]{})); + + FluidReservoirWrapper wrapper = new FluidReservoirWrapper(res, weight); + add(wrapper); + return wrapper; + } + + } + + public class FluidReservoirWrapper extends ReservoirWrapper { + private final ITweakedPetReservoirType reservoirType; + + public FluidReservoirWrapper(ITweakedPetReservoirType reservoirType, int weight) { + this((PumpjackHandler.ReservoirType) reservoirType, weight); + } + + public FluidReservoirWrapper(PumpjackHandler.ReservoirType reservoirType, int weight) { + super(FluidReservoir.this::recipeBuilder, reservoirType, weight); + this.reservoirType = (ITweakedPetReservoirType) reservoirType; + } + + @Override + public ITweakedPetReservoirType getRealReservoirType() { + return reservoirType; + } + + @Override public FluidReservoirBuilder toBuilder() { + remove(this); + FluidReservoirBuilder builder = super.toBuilder(); + builder.fluid(getStringFluid()); + return builder; + } + + } + +} diff --git a/src/main/java/io/github/srdjanv/tweakedpetroleum/common/compat/groovy/GroovyCompat.java b/src/main/java/io/github/srdjanv/tweakedpetroleum/common/compat/groovy/GroovyCompat.java new file mode 100644 index 0000000..74dafed --- /dev/null +++ b/src/main/java/io/github/srdjanv/tweakedpetroleum/common/compat/groovy/GroovyCompat.java @@ -0,0 +1,18 @@ +package io.github.srdjanv.tweakedpetroleum.common.compat.groovy; + +import io.github.srdjanv.tweakedlib.common.Constants; +import io.github.srdjanv.tweakedlib.common.compat.groovyscript.GroovyScriptRegistry; +import io.github.srdjanv.tweakedpetroleum.util.TweakedPetroleumInitializer; +import net.minecraftforge.fml.common.event.FMLPreInitializationEvent; + +public class GroovyCompat implements TweakedPetroleumInitializer { + + @Override public boolean shouldRun() { + return Constants.isGroovyScriptLoaded(); + } + + @Override public void preInit(FMLPreInitializationEvent event) { + GroovyScriptRegistry.getRegistry().addRegistry(new FluidReservoir()); + } + +} diff --git a/src/main/java/io/github/srdjanv/tweakedpetroleum/common/compat/groovy/VirtualizedReservoirRegistry.java b/src/main/java/io/github/srdjanv/tweakedpetroleum/common/compat/groovy/VirtualizedReservoirRegistry.java new file mode 100644 index 0000000..b1be990 --- /dev/null +++ b/src/main/java/io/github/srdjanv/tweakedpetroleum/common/compat/groovy/VirtualizedReservoirRegistry.java @@ -0,0 +1,295 @@ +package io.github.srdjanv.tweakedpetroleum.common.compat.groovy; + +import com.cleanroommc.groovyscript.api.GroovyBlacklist; +import com.cleanroommc.groovyscript.api.GroovyLog; +import com.cleanroommc.groovyscript.helper.Alias; +import com.cleanroommc.groovyscript.helper.recipe.IRecipeBuilder; +import com.cleanroommc.groovyscript.registry.VirtualizedRegistry; +import flaxbeard.immersivepetroleum.api.crafting.PumpjackHandler; +import groovyjarjarantlr4.v4.runtime.misc.IntegerList; +import io.github.srdjanv.tweakedlib.api.powertier.PowerTier; +import io.github.srdjanv.tweakedpetroleum.api.crafting.TweakedPumpjackHandler; +import io.github.srdjanv.tweakedpetroleum.api.mixins.ITweakedPetReservoirType; +import io.github.srdjanv.tweakedpetroleum.api.mixins.ITweakedPetReservoirTypeGetters; +import it.unimi.dsi.fastutil.ints.IntArrayList; +import it.unimi.dsi.fastutil.ints.IntList; +import it.unimi.dsi.fastutil.objects.ObjectArrayList; + +import java.math.BigDecimal; +import java.util.*; +import java.util.function.BiFunction; +import java.util.function.Supplier; +import java.util.stream.Collectors; + +@SuppressWarnings("rawtypes") +public abstract class VirtualizedReservoirRegistry< + T extends ITweakedPetReservoirType, + B extends VirtualizedReservoirRegistry.ReservoirBuilder, + W extends VirtualizedReservoirRegistry.ReservoirWrapper> extends VirtualizedRegistry { + + public VirtualizedReservoirRegistry(String reservoirType) { + super(Alias.generateOf(reservoirType + "Reservoir")); + } + + protected abstract BiFunction getReservoirTypeWrapperFunction(); + + @Override + @GroovyBlacklist + public void onReload() { + removeScripted().forEach((recipe) -> PumpjackHandler.reservoirList.remove(recipe.getReservoirType())); + restoreFromBackup().forEach((recipe) -> PumpjackHandler.reservoirList.put(recipe.getReservoirType(), recipe.getWeight())); + } + + public void removeAll() { + PumpjackHandler.reservoirList.forEach((reservoirType, integer) -> addBackup(getReservoirTypeWrapperFunction().apply(reservoirType, integer))); + PumpjackHandler.reservoirList.clear(); + } + + public void remove(String name) { + var res = get(name); + remove(res); + } + + public void remove(W reservoir) { + if (PumpjackHandler.reservoirList.containsKey(reservoir.getReservoirType())) { + PumpjackHandler.reservoirList.remove(reservoir.getReservoirType()); + addBackup(reservoir); + GroovyLog.msg("Removed reservoir with name: {}", reservoir.getName()).info().post(); + } else GroovyLog.msg("Error removing custom reservoir with name: {}", reservoir.getName()) + .add("That reservoir does not exist").error().post(); + } + + public List getAll() { + List reservoirs = PumpjackHandler.reservoirList.entrySet() + .stream().collect(ArrayList::new, + (list, map) -> list.add(getReservoirTypeWrapperFunction().apply(map.getKey(), map.getValue())), + ArrayList::addAll); + + if (reservoirs.isEmpty()) { + GroovyLog.msg("Error getting all custom reservoirs").error() + .add("No reservoirs exist").post(); + } + + return reservoirs; + } + + public W get(String name) { + for (Map.Entry reservoir : PumpjackHandler.reservoirList.entrySet()) { + if (reservoir.getKey().name.equalsIgnoreCase(name)) + return getReservoirTypeWrapperFunction().apply(reservoir.getKey(), reservoir.getValue()); + } + + GroovyLog.msg("Error getting custom reservoir with name: {}", name).error().post(); + return null; + } + + public void add(W wrapper) { + if (wrapper == null) { + GroovyLog.msg("Reservoir to add is null").error().post(); + return; + } + + if (!PumpjackHandler.reservoirList.containsKey(wrapper.getReservoirType())) { + addScripted(wrapper); + PumpjackHandler.reservoirList.put(wrapper.getReservoirType(), wrapper.getWeight()); + GroovyLog.msg("Added reservoir {}", wrapper.getName()).info().post(); + } else GroovyLog.msg("Reservoir {}, is already registered remove it first", wrapper.getName()).error().post(); + } + + public abstract B recipeBuilder(); + + public abstract static class ReservoirWrapper> implements ITweakedPetReservoirTypeGetters { + private final Supplier builderSupplier; + private final PumpjackHandler.ReservoirType reservoirType; + private final int weight; + + public int getWeight() { + return weight; + } + + public PumpjackHandler.ReservoirType getReservoirType() { + return reservoirType; + } + + public abstract T getRealReservoirType(); + + @GroovyBlacklist + public ReservoirWrapper(Supplier builderSupplier, PumpjackHandler.ReservoirType reservoirType, int weight) { + this.builderSupplier = builderSupplier; + this.reservoirType = reservoirType; + this.weight = weight; + } + + @Override + public String getName() { + return getRealReservoirType().getName(); + } + + @Override public String getStringFluid() { + return getRealReservoirType().getStringFluid(); + } + + @Override public int getMinSize() { + return getRealReservoirType().getMinSize(); + } + + @Override public int getMaxSize() { + return getRealReservoirType().getMaxSize(); + } + + @Override public int getReplenishRate() { + return getRealReservoirType().getReplenishRate(); + } + + @Override public int getPumpSpeed() { + return getRealReservoirType().getPumpSpeed(); + } + + @Override public float getDrainChance() { + return getRealReservoirType().getDrainChance(); + } + + @Override public String[] getBiomeWhitelist() { + return getRealReservoirType().getBiomeWhitelist().clone(); + } + + @Override public String[] getBiomeBlacklist() { + return getRealReservoirType().getBiomeBlacklist().clone(); + } + + @Override public TweakedPumpjackHandler.ReservoirContent getReservoirContent() { + return getRealReservoirType().getReservoirContent(); + } + + @Override + public int[] getDimensionWhitelist() { + return getRealReservoirType().getDimensionWhitelist().clone(); + } + + @Override + public int[] getDimensionBlacklist() { + return getRealReservoirType().getDimensionBlacklist().clone(); + } + + @Override + public int getPowerTier() { + return getRealReservoirType().getPowerTier(); + } + + public B toBuilder() { + var builder = builderSupplier.get(); + builder.name(getRealReservoirType().getName()); + builder.weight(weight); + builder.minSize(getMinSize()); + builder.maxSize(getMaxSize()); + builder.replenishRate(getReplenishRate()); + builder.drainChance(BigDecimal.valueOf(getDrainChance())); + builder.pumpSpeed(getPumpSpeed()); + builder.powerTier(getPowerTier()); + builder.dimBlacklist(Arrays.stream(getDimensionBlacklist()).boxed().collect(Collectors.toList())); + builder.dimWhitelist(Arrays.stream(getDimensionWhitelist()).boxed().collect(Collectors.toList())); + builder.biomeBlacklist(Arrays.stream(getBiomeBlacklist()).collect(Collectors.toList())); + builder.biomeWhitelist(Arrays.stream(getBiomeWhitelist()).collect(Collectors.toList())); + return builder; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + ReservoirWrapper that = (ReservoirWrapper) o; + return Objects.equals(reservoirType, that.getReservoirType()); + } + + @Override + public int hashCode() { + return Objects.hash(reservoirType); + } + } + + public abstract static class ReservoirBuilder implements IRecipeBuilder { + protected String name; + protected int weight; + protected int minSize; + protected int maxSize; + protected int replenishRate; + protected int pumpSpeed; + protected BigDecimal drainChance = BigDecimal.valueOf(1f); + protected Integer powerTier; + protected IntList dimBlacklist; + protected IntList dimWhitelist; + protected List biomeWhitelist; + protected List biomeBlacklist; + + public ReservoirBuilder name(String name) { + this.name = name; + return this; + } + + public ReservoirBuilder weight(int weight) { + this.weight = weight; + return this; + } + + public ReservoirBuilder minSize(int size) { + this.minSize = size; + return this; + } + + public ReservoirBuilder maxSize(int size) { + this.maxSize = size; + return this; + } + + public ReservoirBuilder replenishRate(int rate) { + this.replenishRate = rate; + return this; + } + + public ReservoirBuilder pumpSpeed(int speed) { + this.pumpSpeed = speed; + return this; + } + + public ReservoirBuilder powerTier(int powerTier) { + this.powerTier = powerTier; + return this; + } + + public ReservoirBuilder powerTier(PowerTier powerTier) { + this.powerTier = powerTier.hashCode(); + return this; + } + + public ReservoirBuilder dimBlacklist(List dimBlacklist) { + if (Objects.isNull(this.dimBlacklist)) this.dimBlacklist = new IntArrayList(); + this.dimBlacklist.addAll(dimBlacklist); + return this; + } + + public ReservoirBuilder dimWhitelist(List dimWhitelist) { + if (Objects.isNull(this.dimWhitelist)) this.dimWhitelist = new IntArrayList(); + this.dimWhitelist.addAll(dimWhitelist); + return this; + } + + public ReservoirBuilder drainChance(BigDecimal chance) { + this.drainChance = chance; + return this; + } + + public ReservoirBuilder biomeBlacklist(List blacklist) { + if (Objects.isNull(this.biomeBlacklist)) this.biomeBlacklist = new ObjectArrayList<>(); + this.biomeBlacklist.addAll(blacklist); + return this; + } + + public ReservoirBuilder biomeWhitelist(List whitelist) { + if (Objects.isNull(this.biomeWhitelist)) this.biomeWhitelist = new ObjectArrayList<>(); + this.biomeWhitelist.addAll(whitelist); + return this; + } + + } + +} diff --git a/src/main/java/io/github/srdjanv/tweakedpetroleum/common/compat/top/TopCompat.java b/src/main/java/io/github/srdjanv/tweakedpetroleum/common/compat/top/TopCompat.java new file mode 100644 index 0000000..4253f89 --- /dev/null +++ b/src/main/java/io/github/srdjanv/tweakedpetroleum/common/compat/top/TopCompat.java @@ -0,0 +1,71 @@ +package io.github.srdjanv.tweakedpetroleum.common.compat.top; + +import blusunrize.immersiveengineering.api.energy.immersiveflux.IFluxReceiver; +import flaxbeard.immersivepetroleum.api.crafting.PumpjackHandler; +import flaxbeard.immersivepetroleum.common.Config; +import flaxbeard.immersivepetroleum.common.blocks.metal.TileEntityPumpjack; +import io.github.srdjanv.tweakedlib.api.hei.BaseHEIUtil; +import io.github.srdjanv.tweakedlib.api.powertier.PowerTierHandler; +import io.github.srdjanv.tweakedlib.api.top.IETopOverwriteManager; +import io.github.srdjanv.tweakedlib.common.Constants; +import io.github.srdjanv.tweakedpetroleum.api.mixins.ITweakedPetReservoirType; +import io.github.srdjanv.tweakedpetroleum.util.TweakedPetroleumInitializer; +import mcjty.theoneprobe.api.*; +import net.minecraft.block.state.IBlockState; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.world.World; +import net.minecraftforge.fml.common.event.FMLPreInitializationEvent; + +import static mcjty.theoneprobe.api.IProbeInfo.ENDLOC; +import static mcjty.theoneprobe.api.IProbeInfo.STARTLOC; + +public final class TopCompat implements TweakedPetroleumInitializer { + @Override public boolean shouldRun() { + return Constants.isTheOneProbeLoaded(); + } + + @Override public void preInit(FMLPreInitializationEvent event) { + IETopOverwriteManager manager = IETopOverwriteManager.getInstance(); + manager.registerEnergyInfoOverwrite(TileEntityPumpjack.class, TopCompat::addProbeInfo); + } + + private static void addProbeInfo(TileEntity te, ProbeMode mode, IProbeInfo probeInfo, EntityPlayer player, World world, IBlockState blockState, IProbeHitData data) { + TileEntityPumpjack master = ((TileEntityPumpjack) te).master(); + if (master == null) return; + var info = PumpjackHandler.getOilWorldInfo(master.getWorld(), master.getPos().getX() >> 4, master.getPos().getZ() >> 4); + if (info == null) { + probeInfo.text(STARTLOC + "tweakedpetroleum.hud.reservoir.empty" + ENDLOC); + return; + } + + if (master.wasActive && (info.current == info.capacity)) { + probeInfo.text(TextStyleClass.INFO + STARTLOC + "tweakedpetroleum.hud.reservoir.unknown" + ENDLOC); + } else if (!master.wasActive) { + if (Config.IPConfig.Extraction.req_pipes) { + probeInfo.text(TextStyleClass.ERROR + STARTLOC + "tweakedpetroleum.hud.reservoir.req_pipes" + ENDLOC); + } else probeInfo.text(TextStyleClass.ERROR + STARTLOC + "tweakedpetroleum.hud.reservoir.req_power" + ENDLOC); + } + + ITweakedPetReservoirType reservoir = (ITweakedPetReservoirType) info.getType(); + if (reservoir == null) return; + if (master.wasActive && (info.current != info.capacity)) { + probeInfo.text(TextStyleClass.INFO + STARTLOC + "tweakedpetroleum.hud.reservoir.name" + ENDLOC + " " + reservoir.getName()); + probeInfo.text(" " + TextStyleClass.INFO + STARTLOC + "tweakedpetroleum.jei.reservoir.replenishRate" + ENDLOC + " " + reservoir.getReplenishRate() + " mb/t"); + probeInfo.text(" " + TextStyleClass.INFO + STARTLOC + "tweakedpetroleum.jei.reservoir.speed" + ENDLOC + " " + reservoir.getPumpSpeed() + " mb/t"); + + probeInfo.progress(info.current, info.capacity, probeInfo.defaultProgressStyle().suffix(" mb") + .filledColor(0xff0000ff). alternateFilledColor(0xff000099).borderColor(0xff3333ff).numberFormat(NumberFormat.COMMAS)); + + // probeInfo.text(" " + TextStyleClass.INFO + STARTLOC + "tweakedpetroleum.hud.current_level" + ENDLOC + " " + BaseHEIUtil.numberFormat.format(info.current) +"mb"); + } + + var powerTier = PowerTierHandler.getPowerTier(reservoir.getPowerTier()); + probeInfo.text(TextStyleClass.INFO + STARTLOC + "tweakedlib.jei.power_tier" + ENDLOC + " " + + BaseHEIUtil.numberFormat.format(PowerTierHandler.getTierOfSpecifiedPowerTier(reservoir.getPowerTier()))); + probeInfo.text(TextStyleClass.INFO + STARTLOC + "tweakedlib.jei.power_usage" + ENDLOC + " " + + BaseHEIUtil.numberFormat.format(powerTier.getRft()) + " IF/t"); + probeInfo.progress(((IFluxReceiver) te).getEnergyStored(null), powerTier.getCapacity(), + probeInfo.defaultProgressStyle().suffix(" IF").filledColor(-557004).alternateFilledColor(-6729952).borderColor(-12705779).numberFormat(NumberFormat.COMMAS)); + } +} diff --git a/src/main/java/io/github/srdjanv/tweakedpetroleum/common/compat/waila/WailaCompat.java b/src/main/java/io/github/srdjanv/tweakedpetroleum/common/compat/waila/WailaCompat.java new file mode 100644 index 0000000..6c6cf2e --- /dev/null +++ b/src/main/java/io/github/srdjanv/tweakedpetroleum/common/compat/waila/WailaCompat.java @@ -0,0 +1,117 @@ +package io.github.srdjanv.tweakedpetroleum.common.compat.waila; + +import blusunrize.immersiveengineering.api.energy.immersiveflux.IFluxReceiver; +import flaxbeard.immersivepetroleum.api.crafting.PumpjackHandler; +import flaxbeard.immersivepetroleum.common.Config; +import flaxbeard.immersivepetroleum.common.blocks.metal.TileEntityPumpjack; +import io.github.srdjanv.tweakedlib.api.hei.BaseHEIUtil; +import io.github.srdjanv.tweakedlib.api.powertier.PowerTierHandler; +import io.github.srdjanv.tweakedlib.api.waila.DuplicateFilter; +import io.github.srdjanv.tweakedlib.api.waila.FEFilter; +import io.github.srdjanv.tweakedlib.api.waila.IEWallaOverwriteManager; +import io.github.srdjanv.tweakedlib.api.waila.Styling; +import io.github.srdjanv.tweakedlib.common.Constants; +import io.github.srdjanv.tweakedpetroleum.api.mixins.ITweakedPetReservoirType; +import io.github.srdjanv.tweakedpetroleum.util.TweakedPetroleumInitializer; +import it.unimi.dsi.fastutil.objects.ObjectArrayList; +import mcp.mobius.waila.api.IWailaConfigHandler; +import mcp.mobius.waila.api.IWailaDataAccessor; +import net.minecraft.entity.player.EntityPlayerMP; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTBase; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.nbt.NBTTagList; +import net.minecraft.nbt.NBTTagString; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.World; +import net.minecraftforge.fml.common.event.FMLPreInitializationEvent; + +import java.util.List; + +import static mcjty.theoneprobe.api.IProbeInfo.ENDLOC; +import static mcjty.theoneprobe.api.IProbeInfo.STARTLOC; + +public final class WailaCompat implements TweakedPetroleumInitializer { + + private static final String NBT_TAG = "tweakedPetrTag"; + + @Override public boolean shouldRun() { + return Constants.isWailaLoaded(); + } + + @Override public void preInit(FMLPreInitializationEvent event) { + IEWallaOverwriteManager manager = IEWallaOverwriteManager.getInstance(); + manager.registerIEBodyOverwrite(TileEntityPumpjack.class, WailaCompat::getWailaBody); + manager.registerIENBTDataOverwrite(TileEntityPumpjack.class, WailaCompat::getNBTData); + } + + private static List getWailaBody(ItemStack itemStack, List currenttip, IWailaDataAccessor accessor, IWailaConfigHandler config) { + if (accessor.getNBTData().hasKey(NBT_TAG)) { + final var toolTip = new ObjectArrayList(); + final var nbtList = (NBTTagList) accessor.getNBTData().getTag(NBT_TAG); + + for (NBTBase nbtBase : nbtList) { + if (nbtBase instanceof NBTTagString string) { + toolTip.add(Styling.stylifyString(string.getString())); + } + } + DuplicateFilter.add(currenttip, toolTip); + } + + FEFilter.filter(currenttip); + return currenttip; + } + + private static NBTTagCompound getNBTData(EntityPlayerMP player, TileEntity te, NBTTagCompound tag, World world, BlockPos pos) { + TileEntityPumpjack master = ((TileEntityPumpjack) te).master(); + if (master == null) return tag; + var info = PumpjackHandler.getOilWorldInfo(master.getWorld(), master.getPos().getX() >> 4, master.getPos().getZ() >> 4); + + var tipList = new ObjectArrayList(); + listBuild: + { + if (info == null) { + tipList.add(STARTLOC + "tweakedpetroleum.hud.reservoir.empty" + ENDLOC); + break listBuild; + } + + if (master.wasActive && (info.current == info.capacity)) { + tipList.add(STARTLOC + "tweakedpetroleum.hud.reservoir.unknown" + ENDLOC); + } else if (!master.wasActive) { + if (Config.IPConfig.Extraction.req_pipes) { + tipList.add(STARTLOC + "tweakedpetroleum.hud.reservoir.req_pipes" + ENDLOC); + } else tipList.add(STARTLOC + "tweakedpetroleum.hud.reservoir.req_power" + ENDLOC); + } + + ITweakedPetReservoirType reservoir = (ITweakedPetReservoirType) info.getType(); + if (reservoir == null) break listBuild; + if (master.wasActive && (info.current != info.capacity)) { + tipList.add(STARTLOC + "tweakedpetroleum.hud.reservoir.name" + ENDLOC + " " + reservoir.getName()); + tipList.add(" §7" + STARTLOC + "tweakedpetroleum.jei.reservoir.replenishRate" + ENDLOC + " " + reservoir.getReplenishRate() + " mb/t"); + tipList.add(" §7" + STARTLOC + "tweakedpetroleum.jei.reservoir.speed" + ENDLOC + " " + reservoir.getPumpSpeed() + " mb/t"); + tipList.add(" §7" + STARTLOC + "tweakedpetroleum.jei.reservoir.speed" + ENDLOC + " " + reservoir.getPumpSpeed() + " mb/t"); + } + + var powerTier = PowerTierHandler.getPowerTier(reservoir.getPowerTier()); + tipList.add(STARTLOC + "tweakedlib.jei.power_tier" + ENDLOC + " " + + BaseHEIUtil.numberFormat.format(PowerTierHandler.getTierOfSpecifiedPowerTier(reservoir.getPowerTier()))); + tipList.add(STARTLOC + "tweakedlib.jei.power_usage" + ENDLOC + " " + + BaseHEIUtil.numberFormat.format(powerTier.getRft()) + " IF/t"); + + tipList.add(String.format("§7 %s / %s IF", + BaseHEIUtil.numberFormat.format(((IFluxReceiver) te).getEnergyStored(null)), + BaseHEIUtil.numberFormat.format(powerTier.getCapacity()))); + } + + if (!tipList.isEmpty()) { + var tweakedPetrTag = new NBTTagList(); + for (String tip : tipList) tweakedPetrTag.appendTag(new NBTTagString(tip)); + tag.setTag(NBT_TAG, tweakedPetrTag); + } + + return tag; + } + + +} diff --git a/src/main/java/srki2k/tweakedpetroleum/core/TweakedPetroleumPlugin.java b/src/main/java/io/github/srdjanv/tweakedpetroleum/core/TweakedPetroleumPlugin.java similarity index 94% rename from src/main/java/srki2k/tweakedpetroleum/core/TweakedPetroleumPlugin.java rename to src/main/java/io/github/srdjanv/tweakedpetroleum/core/TweakedPetroleumPlugin.java index 4c9f97a..a644667 100644 --- a/src/main/java/srki2k/tweakedpetroleum/core/TweakedPetroleumPlugin.java +++ b/src/main/java/io/github/srdjanv/tweakedpetroleum/core/TweakedPetroleumPlugin.java @@ -1,4 +1,4 @@ -package srki2k.tweakedpetroleum.core; +package io.github.srdjanv.tweakedpetroleum.core; import net.minecraftforge.fml.relauncher.IFMLLoadingPlugin; import zone.rong.mixinbooter.ILateMixinLoader; diff --git a/src/main/java/io/github/srdjanv/tweakedpetroleum/mixin/MixinConfig.java b/src/main/java/io/github/srdjanv/tweakedpetroleum/mixin/MixinConfig.java new file mode 100644 index 0000000..3ece335 --- /dev/null +++ b/src/main/java/io/github/srdjanv/tweakedpetroleum/mixin/MixinConfig.java @@ -0,0 +1,32 @@ +package io.github.srdjanv.tweakedpetroleum.mixin; + +import flaxbeard.immersivepetroleum.api.crafting.PumpjackHandler; +import io.github.srdjanv.tweakedpetroleum.api.mixins.ITweakedPetReservoirType; +import io.github.srdjanv.tweakedpetroleum.common.Configs; +import io.github.srdjanv.tweakedpetroleum.common.DefaultReservoirs; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.ModifyVariable; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +import org.spongepowered.asm.mixin.injection.callback.LocalCapture; + +@Mixin(value = flaxbeard.immersivepetroleum.common.Config.class, remap = false) +public abstract class MixinConfig { + + @Inject(method = "addConfigReservoirs", at = @At("HEAD"), cancellable = true) + private static void onAddConfigReservoirs(String[] reservoirs, CallbackInfo ci) { + if (!Configs.TPConfig.DefaultReservoirs.enableIPConfigReservoirRegistration) ci.cancel(); + } + + @ModifyVariable(method = "addConfigReservoirs", + at = @At(value = "STORE"), + name = "res") + private static PumpjackHandler.ReservoirType onAddConfigReservoirs(PumpjackHandler.ReservoirType res) { + final ITweakedPetReservoirType tweakedPetReservoirType = (ITweakedPetReservoirType) res; + final DefaultReservoirs instance = DefaultReservoirs.getInstance(); + tweakedPetReservoirType.setPowerTier(instance.defaultPowerTier()); + tweakedPetReservoirType.setPumpSpeed(instance.defaultPumpSpeed()); + return res; + } +} diff --git a/src/main/java/srki2k/tweakedpetroleum/mixin/MixinPumpjackHandler.java b/src/main/java/io/github/srdjanv/tweakedpetroleum/mixin/MixinPumpjackHandler.java similarity index 80% rename from src/main/java/srki2k/tweakedpetroleum/mixin/MixinPumpjackHandler.java rename to src/main/java/io/github/srdjanv/tweakedpetroleum/mixin/MixinPumpjackHandler.java index 63ffaec..c80b3ba 100644 --- a/src/main/java/srki2k/tweakedpetroleum/mixin/MixinPumpjackHandler.java +++ b/src/main/java/io/github/srdjanv/tweakedpetroleum/mixin/MixinPumpjackHandler.java @@ -1,11 +1,11 @@ -package srki2k.tweakedpetroleum.mixin; +package io.github.srdjanv.tweakedpetroleum.mixin; import flaxbeard.immersivepetroleum.api.crafting.PumpjackHandler; import flaxbeard.immersivepetroleum.common.IPSaveData; +import io.github.srdjanv.tweakedpetroleum.api.mixins.ITweakedPetReservoirType; import net.minecraft.world.World; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Overwrite; -import srki2k.tweakedpetroleum.api.ihelpers.IReservoirType; import static flaxbeard.immersivepetroleum.api.crafting.PumpjackHandler.getOilWorldInfo; @@ -23,7 +23,7 @@ public static void depleteFluid(World world, int chunkX, int chunkZ, int amount) if (info.current == 0) { return; } - if (Math.random() < ((IReservoirType) info.getType()).getDrainChance()) { + if (Math.random() < ((ITweakedPetReservoirType) info.getType()).getDrainChance()) { info.current = Math.max(0, info.current - amount); IPSaveData.setDirty(world.provider.getDimension()); } diff --git a/src/main/java/srki2k/tweakedpetroleum/mixin/MixinReservoirTweaker.java b/src/main/java/io/github/srdjanv/tweakedpetroleum/mixin/MixinReservoirTweaker.java similarity index 95% rename from src/main/java/srki2k/tweakedpetroleum/mixin/MixinReservoirTweaker.java rename to src/main/java/io/github/srdjanv/tweakedpetroleum/mixin/MixinReservoirTweaker.java index d72c9c5..75130bf 100644 --- a/src/main/java/srki2k/tweakedpetroleum/mixin/MixinReservoirTweaker.java +++ b/src/main/java/io/github/srdjanv/tweakedpetroleum/mixin/MixinReservoirTweaker.java @@ -1,4 +1,4 @@ -package srki2k.tweakedpetroleum.mixin; +package io.github.srdjanv.tweakedpetroleum.mixin; import crafttweaker.CraftTweakerAPI; import crafttweaker.api.liquid.ILiquidStack; diff --git a/src/main/java/srki2k/tweakedpetroleum/mixin/MixinReservoirTypeAddons.java b/src/main/java/io/github/srdjanv/tweakedpetroleum/mixin/MixinReservoirTypeAddons.java similarity index 86% rename from src/main/java/srki2k/tweakedpetroleum/mixin/MixinReservoirTypeAddons.java rename to src/main/java/io/github/srdjanv/tweakedpetroleum/mixin/MixinReservoirTypeAddons.java index c63288b..7ccc12e 100644 --- a/src/main/java/srki2k/tweakedpetroleum/mixin/MixinReservoirTypeAddons.java +++ b/src/main/java/io/github/srdjanv/tweakedpetroleum/mixin/MixinReservoirTypeAddons.java @@ -1,17 +1,17 @@ -package srki2k.tweakedpetroleum.mixin; +package io.github.srdjanv.tweakedpetroleum.mixin; import flaxbeard.immersivepetroleum.api.crafting.PumpjackHandler; +import io.github.srdjanv.tweakedpetroleum.api.crafting.TweakedPumpjackHandler; +import io.github.srdjanv.tweakedpetroleum.api.mixins.ITweakedPetReservoirType; import net.minecraft.nbt.NBTTagCompound; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Unique; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -import srki2k.tweakedpetroleum.api.crafting.TweakedPumpjackHandler; -import srki2k.tweakedpetroleum.api.ihelpers.IReservoirType; @Mixin(value = PumpjackHandler.ReservoirType.class, remap = false) -public abstract class MixinReservoirTypeAddons implements IReservoirType { +public abstract class MixinReservoirTypeAddons implements ITweakedPetReservoirType { @Unique TweakedPumpjackHandler.ReservoirContent reservoirContent = TweakedPumpjackHandler.ReservoirContent.DEFAULT; @@ -73,7 +73,7 @@ public void setDrainChance(float drainChance) { @Inject(method = "readFromNBT", at = @At("RETURN")) private static void onReadFromNBT(NBTTagCompound tag, CallbackInfoReturnable cir) { - IReservoirType mix = (IReservoirType) cir.getReturnValue(); + ITweakedPetReservoirType mix = (ITweakedPetReservoirType) cir.getReturnValue(); mix.setReservoirContent(TweakedPumpjackHandler.ReservoirContent.values()[tag.getByte("reservoirContent")]); mix.setPumpSpeed(tag.getInteger("pumpSpeed")); mix.setPowerTier(tag.getInteger("powerTier")); diff --git a/src/main/java/srki2k/tweakedpetroleum/mixin/MixinReservoirTypeBase.java b/src/main/java/io/github/srdjanv/tweakedpetroleum/mixin/MixinReservoirTypeBase.java similarity index 89% rename from src/main/java/srki2k/tweakedpetroleum/mixin/MixinReservoirTypeBase.java rename to src/main/java/io/github/srdjanv/tweakedpetroleum/mixin/MixinReservoirTypeBase.java index 726d52b..f7fe3ec 100644 --- a/src/main/java/srki2k/tweakedpetroleum/mixin/MixinReservoirTypeBase.java +++ b/src/main/java/io/github/srdjanv/tweakedpetroleum/mixin/MixinReservoirTypeBase.java @@ -1,16 +1,16 @@ -package srki2k.tweakedpetroleum.mixin; +package io.github.srdjanv.tweakedpetroleum.mixin; import flaxbeard.immersivepetroleum.api.crafting.PumpjackHandler; +import io.github.srdjanv.tweakedpetroleum.api.mixins.ITweakedPetReservoirType; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.Unique; -import srki2k.tweakedpetroleum.api.ihelpers.IReservoirType; import java.util.Objects; @Mixin(value = PumpjackHandler.ReservoirType.class, remap = false) -public abstract class MixinReservoirTypeBase implements IReservoirType { +public abstract class MixinReservoirTypeBase implements ITweakedPetReservoirType { @Shadow public String name; @@ -122,7 +122,7 @@ public void setBiomeBlacklist(String[] biomeBlacklist) { public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; - IReservoirType that = (IReservoirType) o; + ITweakedPetReservoirType that = (ITweakedPetReservoirType) o; return name.equals(that.getName()); } diff --git a/src/main/java/srki2k/tweakedpetroleum/mixin/MixinTileEntityPumpjack.java b/src/main/java/io/github/srdjanv/tweakedpetroleum/mixin/MixinTileEntityPumpjack.java similarity index 74% rename from src/main/java/srki2k/tweakedpetroleum/mixin/MixinTileEntityPumpjack.java rename to src/main/java/io/github/srdjanv/tweakedpetroleum/mixin/MixinTileEntityPumpjack.java index faae670..62c861b 100644 --- a/src/main/java/srki2k/tweakedpetroleum/mixin/MixinTileEntityPumpjack.java +++ b/src/main/java/io/github/srdjanv/tweakedpetroleum/mixin/MixinTileEntityPumpjack.java @@ -1,4 +1,4 @@ -package srki2k.tweakedpetroleum.mixin; +package io.github.srdjanv.tweakedpetroleum.mixin; import blusunrize.immersiveengineering.api.MultiblockHandler; import blusunrize.immersiveengineering.api.crafting.IMultiblockRecipe; @@ -6,6 +6,9 @@ import blusunrize.immersiveengineering.common.util.Utils; import flaxbeard.immersivepetroleum.common.Config; import flaxbeard.immersivepetroleum.common.blocks.metal.TileEntityPumpjack; +import io.github.srdjanv.tweakedlib.api.powertier.PowerTierHandler; +import io.github.srdjanv.tweakedpetroleum.api.crafting.TweakedPumpjackHandler; +import io.github.srdjanv.tweakedpetroleum.api.mixins.ITweakedPetPumpjackAddons; import net.minecraft.block.Block; import net.minecraft.block.state.IBlockState; import net.minecraft.util.EnumFacing; @@ -22,12 +25,11 @@ import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import srki2k.tweakedlib.api.powertier.PowerTierHandler; -import srki2k.tweakedpetroleum.api.crafting.TweakedPumpjackHandler; -import srki2k.tweakedpetroleum.api.ihelpers.IPumpjackAddons; + +import java.util.concurrent.ThreadLocalRandom; @Mixin(value = TileEntityPumpjack.class, remap = false) -public abstract class MixinTileEntityPumpjack extends TileEntityMultiblockMetal implements IPumpjackAddons { +public abstract class MixinTileEntityPumpjack extends TileEntityMultiblockMetal implements ITweakedPetPumpjackAddons { //Shadow Variables @Shadow @@ -60,13 +62,16 @@ public abstract class MixinTileEntityPumpjack extends TileEntityMultiblockMetal< @Shadow public abstract void extractOil(int amount); + @Shadow + public abstract TileEntityPumpjack master(); + public MixinTileEntityPumpjack(MultiblockHandler.IMultiblock mutliblockInstance, int[] structureDimensions, int energyCapacity, boolean redstoneControl) { super(mutliblockInstance, structureDimensions, energyCapacity, redstoneControl); } //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// @Unique - TweakedPumpjackHandler.ReservoirContent chunkContains = TweakedPumpjackHandler.ReservoirContent.DEFAULT; + private TweakedPumpjackHandler.ReservoirContent chunkContains = TweakedPumpjackHandler.ReservoirContent.DEFAULT; @Unique @Override @@ -96,6 +101,7 @@ public TweakedPumpjackHandler.ReservoirContent getChunkContains() { private void onConstructed(CallbackInfo ci) { energyStorage.setCapacity(Integer.MAX_VALUE); energyStorage.setLimitTransfer(0); + pipeTicks = ThreadLocalRandom.current().nextInt(90); } /** @@ -124,48 +130,41 @@ public void update(boolean consumePower) { } //Tile initialization - if (pipeTicks == 0) { - if (energyStorage.getMaxEnergyStored() == Integer.MAX_VALUE) { - initEnergyStorage(); - } - - if (chunkContains == TweakedPumpjackHandler.ReservoirContent.DEFAULT) { - chunkContains = getChunkContains(); - } + if (energyStorage.getMaxEnergyStored() == Integer.MAX_VALUE) { + initEnergyStorage(); } boolean active = false; + int consumed = energyStorage.getLimitExtract(); - if (chunkContains != TweakedPumpjackHandler.ReservoirContent.EMPTY) { - int consumed = energyStorage.getLimitExtract(); + if (energyStorage.extractEnergy(consumed, true) >= consumed && canExtract() && !this.isRSDisabled()) { + if (Config.IPConfig.Extraction.pipe_check_ticks == pipeTicks) lastHadPipes = hasPipes(); + if (lastHadPipes) { + int[] replenishRateAndPumpSpeed = getReplenishRateAndPumpSpeed(); + int availableOil = availableOil(); - if (energyStorage.extractEnergy(consumed, true) >= consumed && canExtract() && !this.isRSDisabled()) { - if ((getPos().getX() + getPos().getZ()) % Config.IPConfig.Extraction.pipe_check_ticks == pipeTicks) { - lastHadPipes = hasPipes(); - } - if (lastHadPipes) { - int[] replenishRateAndPumpSpeed = getReplenishRateAndPumpSpeed(); - int availableOil = availableOil(); - - if (availableOil > 0 || replenishRateAndPumpSpeed[0] > 0) { - int oilAmnt = availableOil <= 0 ? replenishRateAndPumpSpeed[0] : availableOil; - - switch (chunkContains) { - case LIQUID: { - active = caseLiquid(consumed, replenishRateAndPumpSpeed[1], oilAmnt); - break; - } - case GAS: { - active = caseGas(consumed, replenishRateAndPumpSpeed[1], oilAmnt); - } + if (availableOil > 0 || replenishRateAndPumpSpeed[0] > 0) { + int oilAmnt = availableOil <= 0 ? replenishRateAndPumpSpeed[0] : availableOil; + + if (chunkContains == TweakedPumpjackHandler.ReservoirContent.DEFAULT) { + chunkContains = getChunkContains(); + } + switch (chunkContains) { + case LIQUID: { + active = caseLiquid(consumed, replenishRateAndPumpSpeed[1], oilAmnt); + break; + } + case GAS: { + active = caseGas(consumed, replenishRateAndPumpSpeed[1], oilAmnt); } - activeTicks++; } + + activeTicks++; } - pipeTicks = (pipeTicks + 1) % Config.IPConfig.Extraction.pipe_check_ticks; } + pipeTicks = (pipeTicks + 1) % (Config.IPConfig.Extraction.pipe_check_ticks + 1); } if (active != wasActive) { @@ -174,7 +173,6 @@ public void update(boolean consumePower) { } wasActive = active; - } @Unique diff --git a/src/main/java/io/github/srdjanv/tweakedpetroleum/util/HEIPumpjackUtil.java b/src/main/java/io/github/srdjanv/tweakedpetroleum/util/HEIPumpjackUtil.java new file mode 100644 index 0000000..9d74c33 --- /dev/null +++ b/src/main/java/io/github/srdjanv/tweakedpetroleum/util/HEIPumpjackUtil.java @@ -0,0 +1,127 @@ +package io.github.srdjanv.tweakedpetroleum.util; + +import flaxbeard.immersivepetroleum.api.crafting.PumpjackHandler; +import io.github.srdjanv.tweakedlib.api.hei.BaseHEIUtil; +import io.github.srdjanv.tweakedpetroleum.api.mixins.ITweakedPetReservoirType; +import it.unimi.dsi.fastutil.objects.ObjectArrayList; +import org.jetbrains.annotations.Nullable; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.function.Consumer; +import java.util.function.IntSupplier; +import java.util.function.LongSupplier; + +import static flaxbeard.immersivepetroleum.api.crafting.PumpjackHandler.reservoirList; + +public class HEIPumpjackUtil extends BaseHEIUtil { + + public static void onTooltip(int slotIndex, ITweakedPetReservoirType reservoir, long ingredientAmount, String ingredientLocalizedName, List tooltip) { + tooltip.clear(); + tooltip.add("§7" + translateToLocal("tweakedpetroleum.jei.reservoir.contents") + " " +ingredientLocalizedName); + + if (slotIndex == 0) { + sizeData(reservoir, ingredientAmount, tooltip, true); + return; + } + speedData(reservoir, tooltip, true); + } + + public static List tooltipStrings(int mouseX, int mouseY, @Nullable Consumer> customWarnings, ITweakedPetReservoirType reservoir, + LongSupplier ingredientAmountSupplier, IntSupplier getStringWidthSupplier) { + + if (mouseY >= 6 & mouseY <= 12 && mouseX >= 6 && mouseX <= getStringWidthSupplier.getAsInt()) { + var list = new ObjectArrayList(); + list.add(formatString(reservoir.getName())); + return list; + } + + if (mouseX > 60 && mouseX < 71 && mouseY > 55 && mouseY < 70) { + List list = new ObjectArrayList<>(); + powerTierListData(list, reservoir.getPowerTier()); + + return list; + } + + if (mouseX > 60 && mouseX < 72 && mouseY > 72 && mouseY < 86) { + List list = new ObjectArrayList<>(); + + list.add(translateToLocal("tweakedpetroleum.jei.reservoir.weight") + " " + reservoirList.get((PumpjackHandler.ReservoirType) reservoir)); + list.add(""); + + list.add(translateToLocal("tweakedpetroleum.jei.reservoir.biomes")); + list.add(" §7" + translateToLocal("tweakedpetroleum.jei.reservoir.biome_whitelist") + " " + Arrays.toString(reservoir.getBiomeWhitelist())); + list.add(" §7" + translateToLocal("tweakedpetroleum.jei.reservoir.biome_blacklist") + " " + Arrays.toString(reservoir.getBiomeBlacklist())); + + list.add(""); + + dimensionListData(list, reservoir.getDimensionWhitelist(), reservoir.getDimensionBlacklist()); + return list; + } + + if (mouseX >= 10 && mouseX <= 29 && mouseY >= 70 && mouseY <= 86) { + List list = new ObjectArrayList<>(); + sizeData(reservoir, ingredientAmountSupplier.getAsLong(), list, false); + return list; + } + + if (mouseX >= 34 && mouseX <= 53 && mouseY >= 70 && mouseY <= 85) { + List list = new ObjectArrayList<>(); + speedData(reservoir, list, false); + return list; + } + + if (customWarnings != null && mouseX > 56 && mouseX < 73 && mouseY > 23 && mouseY < 39) { + List list = new ObjectArrayList<>(); + customWarnings.accept(list); + return list; + } + return null; + } + + + private static void sizeData(ITweakedPetReservoirType reservoir, long ingredientAmount, List tooltip, boolean nested) { + final String prefix; + if (nested) { + prefix = " §7"; + } else { + prefix = "§7"; + } + + tooltip.add(prefix + translateToLocal("tweakedpetroleum.jei.reservoir.max_size") + " " + numberFormat.format(reservoir.getMaxSize())); + tooltip.add(prefix + translateToLocal("tweakedpetroleum.jei.reservoir.min_size") + " " + numberFormat.format(reservoir.getMinSize())); + + if (reservoir.getDrainChance() != 1f) { + tooltip.add(prefix + translateToLocal("tweakedpetroleum.jei.reservoir.average") + " " + + (numberFormat.format(ingredientAmount) + " * " + (100f + (reservoir.getDrainChance() * 100)) + "%")); + return; + } + + tooltip.add(prefix + translateToLocal("tweakedpetroleum.jei.reservoir.average") + " " + + numberFormat.format(ingredientAmount)); + } + + private static void speedData(ITweakedPetReservoirType reservoir, List tooltip, boolean nested) { + final String prefix; + if (nested) { + prefix = " §7"; + } else { + prefix = "§7"; + } + + tooltip.add(prefix + translateToLocal("tweakedpetroleum.jei.reservoir.replenishRate") + " " + numberFormat.format(reservoir.getReplenishRate())); + tooltip.add(prefix + translateToLocal("tweakedpetroleum.jei.reservoir.speed") + " " + numberFormat.format(reservoir.getPumpSpeed())); + + if (reservoir.getDrainChance() != 1f) { + tooltip.add(prefix + translateToLocal("tweakedpetroleum.jei.reservoir.average.time") + " " + + Math.max(0, ((long) (((long) reservoir.getMaxSize() + reservoir.getMinSize()) * (100f - (reservoir.getDrainChance() * 100))) / 2) + / (reservoir.getPumpSpeed() * 24000L))); + return; + } + + tooltip.add(prefix + translateToLocal("tweakedpetroleum.jei.reservoir.average.time") + " " + + Math.max(0, (((long) reservoir.getMaxSize() + reservoir.getMinSize()) / 2) + / (reservoir.getPumpSpeed() * 24000L))); + } +} diff --git a/src/main/java/io/github/srdjanv/tweakedpetroleum/util/ReservoirValidation.java b/src/main/java/io/github/srdjanv/tweakedpetroleum/util/ReservoirValidation.java new file mode 100644 index 0000000..4b8e109 --- /dev/null +++ b/src/main/java/io/github/srdjanv/tweakedpetroleum/util/ReservoirValidation.java @@ -0,0 +1,73 @@ +package io.github.srdjanv.tweakedpetroleum.util; + +import crafttweaker.CraftTweakerAPI; +import io.github.srdjanv.tweakedpetroleum.api.crafting.TweakedPumpjackHandler; + +import java.util.function.Consumer; + +public class ReservoirValidation { + + public static boolean validateReservoir(Consumer errorMassageBuilder, String name, Object content, int minSize, int maxSize, int replenishRate, int pumpSpeed, int weight, Integer powerTier, float drainChance, + String[] biomeBlacklist, String[] biomeWhitelist) { + + MessageBuilder messageBuilder = new MessageBuilder(errorMassageBuilder); + + messageBuilder.runCheck(drainChance < 0 || 1 < drainChance, "Reservoir drainChance must be between 0 and 1!"); + validateReservoir(messageBuilder, name, content, minSize, maxSize, replenishRate, pumpSpeed, weight, powerTier, + biomeBlacklist, biomeWhitelist); + + return messageBuilder.isValid(); + } + + public static boolean validateReservoir(Consumer errorMassageBuilder, String name, Object content, int minSize, int maxSize, int replenishRate, int pumpSpeed, int weight, Integer powerTier, + String[] biomeBlacklist, String[] biomeWhitelist) { + MessageBuilder messageBuilder = new MessageBuilder(errorMassageBuilder); + validateReservoir(messageBuilder, name, content, minSize, maxSize, replenishRate, pumpSpeed, weight, powerTier, + biomeBlacklist, biomeWhitelist); + return messageBuilder.isValid(); + } + + public static void validateReservoir(MessageBuilder messageBuilder, String name, Object content, int minSize, int maxSize, int replenishRate, int pumpSpeed, int weight, Integer powerTier, + String[] biomeBlacklist, String[] biomeWhitelist) { + + messageBuilder.runCheck(name.isEmpty(), "Reservoir name can not be a empty string!"); + messageBuilder.runCheck(content == null, String.format("Trying to add empty reservoir, name: '%s'", name)); + messageBuilder.runCheck(minSize <= 0, String.format("Reservoir(%s) minSize has to be at least 1mb!", name)); + messageBuilder.runCheck(maxSize < minSize, String.format("Reservoir(%s) maxSize can not be smaller than minSize!", name)); + messageBuilder.runCheck(weight < 1, String.format("Reservoir(%s) weight has to be greater than or equal to 1!", name)); + messageBuilder.runCheck(pumpSpeed <= 0, String.format("Reservoir(%s) Pump Speed has to be at least 1mb/t", name)); + messageBuilder.runCheck(pumpSpeed < replenishRate, String.format("Reservoir(%s) Pump Speed can not be smaller than Replenish Rate!", name)); + messageBuilder.runCheck(powerTier == null, String.format("Reservoir(%s) powerTier is not specified", name)); + + if (biomeBlacklist != null) + for (String string : biomeBlacklist) + messageBuilder.runCheck(string == null || string.isEmpty(), + String.format("Reservoir(%s) String '%s' in biomeBlacklist is either Empty or Null", name, string)); + + if (biomeWhitelist != null) + for (String string : biomeWhitelist) + messageBuilder.runCheck(string == null || string.isEmpty(), + String.format("Reservoir(%s) String '%s' in biomeWhitelist is either Empty or Null", name, string)); + } + + public static class MessageBuilder { + private final Consumer errorMassageBuilder; + private boolean valid = true; + + public MessageBuilder(Consumer errorMassageBuilder) { + this.errorMassageBuilder = errorMassageBuilder; + } + + public void runCheck(boolean expression, String errorMessage) { + if (expression) { + errorMassageBuilder.accept(errorMessage); + valid = false; + } + } + + public boolean isValid() { + return valid; + } + } +} + diff --git a/src/main/java/io/github/srdjanv/tweakedpetroleum/util/TweakedPetroleumErrorLogging.java b/src/main/java/io/github/srdjanv/tweakedpetroleum/util/TweakedPetroleumErrorLogging.java new file mode 100644 index 0000000..f511293 --- /dev/null +++ b/src/main/java/io/github/srdjanv/tweakedpetroleum/util/TweakedPetroleumErrorLogging.java @@ -0,0 +1,58 @@ +package io.github.srdjanv.tweakedpetroleum.util; + +import io.github.srdjanv.tweakedpetroleum.TweakedPetroleum; +import io.github.srdjanv.tweakedpetroleum.common.Configs; +import it.unimi.dsi.fastutil.objects.ObjectArrayList; +import org.apache.logging.log4j.Logger; +import io.github.srdjanv.tweakedlib.api.logging.errorlogginglib.ICustomLogger; +import io.github.srdjanv.tweakedlib.api.powertier.PowerTierHandler; +import io.github.srdjanv.tweakedpetroleum.api.mixins.ITweakedPetReservoirType; + +import java.util.ArrayList; +import java.util.List; + +import static flaxbeard.immersivepetroleum.api.crafting.PumpjackHandler.reservoirList; + +public final class TweakedPetroleumErrorLogging implements ICustomLogger { + private TweakedPetroleumErrorLogging() { + } + + private final List errors = new ObjectArrayList<>(); + + @Override + public boolean startupChecks() { + return reservoirList.isEmpty(); + } + + @Override + public boolean runtimeChecks() { + reservoirList.keySet(). + forEach(tweakedReservoirType -> { + if (!PowerTierHandler.powerTierExists(((ITweakedPetReservoirType) tweakedReservoirType).getPowerTier())) { + errors.add("Reservoir with the ID (name) " + tweakedReservoirType.name + " has no valid Power tier"); + } + }); + + return !errors.isEmpty(); + } + + @Override + public boolean discardLoggerAfterStartup() { + return false; + } + + @Override + public Logger getModLogger() { + return TweakedPetroleum.LOGGER; + } + + @Override + public List getErrors() { + return errors; + } + + @Override + public void clean() { + errors.clear(); + } +} diff --git a/src/main/java/io/github/srdjanv/tweakedpetroleum/util/TweakedPetroleumInitializer.java b/src/main/java/io/github/srdjanv/tweakedpetroleum/util/TweakedPetroleumInitializer.java new file mode 100644 index 0000000..0e5ad75 --- /dev/null +++ b/src/main/java/io/github/srdjanv/tweakedpetroleum/util/TweakedPetroleumInitializer.java @@ -0,0 +1,10 @@ +package io.github.srdjanv.tweakedpetroleum.util; + +import io.github.srdjanv.tweakedlib.api.integration.IInitializer; +import io.github.srdjanv.tweakedpetroleum.TweakedPetroleum; + +public interface TweakedPetroleumInitializer extends IInitializer { + default String getModID() { + return TweakedPetroleum.MODID; + } +} diff --git a/src/main/java/srki2k/tweakedpetroleum/api/ihelpers/IReservoirType.java b/src/main/java/srki2k/tweakedpetroleum/api/ihelpers/IReservoirType.java deleted file mode 100644 index 130e501..0000000 --- a/src/main/java/srki2k/tweakedpetroleum/api/ihelpers/IReservoirType.java +++ /dev/null @@ -1,52 +0,0 @@ -package srki2k.tweakedpetroleum.api.ihelpers; - -import srki2k.tweakedpetroleum.api.crafting.TweakedPumpjackHandler; - -public interface IReservoirType { - - String getName(); - - String getStringFluid(); - - int getMinSize(); - - int getMaxSize(); - - int getReplenishRate(); - - int getPowerTier(); - - int getPumpSpeed(); - - float getDrainChance(); - - int[] getDimensionWhitelist(); - - int[] getDimensionBlacklist(); - - String[] getBiomeWhitelist(); - - String[] getBiomeBlacklist(); - - TweakedPumpjackHandler.ReservoirContent getReservoirContent(); - - - void setDimensionWhitelist(int[] dimWhitelist); - - void setDimensionBlacklist(int[] biomeBlacklistList); - - void setBiomeBlacklist(String[] dimBlacklist); - - void setBiomeWhitelist(String[] biomeWhitelistList); - - void setReservoirContent(TweakedPumpjackHandler.ReservoirContent reservoirContents); - - void setPowerTier(int i); - - void setPumpSpeed(int i); - - void setDrainChance(float f); - -} - - diff --git a/src/main/java/srki2k/tweakedpetroleum/client/hei/PumpjackWrapper.java b/src/main/java/srki2k/tweakedpetroleum/client/hei/PumpjackWrapper.java deleted file mode 100644 index 924aa87..0000000 --- a/src/main/java/srki2k/tweakedpetroleum/client/hei/PumpjackWrapper.java +++ /dev/null @@ -1,89 +0,0 @@ -package srki2k.tweakedpetroleum.client.hei; - -import com.google.common.collect.Lists; -import flaxbeard.immersivepetroleum.api.crafting.PumpjackHandler; -import flaxbeard.immersivepetroleum.common.Config; -import mezz.jei.api.gui.ITooltipCallback; -import mezz.jei.api.ingredients.IIngredients; -import mezz.jei.api.ingredients.VanillaTypes; -import mezz.jei.api.recipe.IRecipeWrapper; -import net.minecraft.client.Minecraft; -import net.minecraftforge.fluids.Fluid; -import net.minecraftforge.fluids.FluidStack; -import srki2k.tweakedlib.api.hei.BaseHEIUtil; -import srki2k.tweakedpetroleum.api.ihelpers.IReservoirType; -import srki2k.tweakedpetroleum.util.HEIPumpjackUtil; - -import java.util.List; - -public class PumpjackWrapper implements IRecipeWrapper, ITooltipCallback { - private final IReservoirType reservoir; - private final Fluid reservoirFluid; - - public PumpjackWrapper(PumpjackHandler.ReservoirType reservoir) { - this.reservoir = (IReservoirType) reservoir; - reservoirFluid = reservoir.getFluid(); - } - - public FluidStack getReplenishRateFluid() { - return new FluidStack(reservoirFluid, reservoir.getReplenishRate()); - } - - public int getPumpSpeed() { - return reservoir.getPumpSpeed(); - } - - public int getMaxFluid() { - return reservoir.getMaxSize(); - } - - public FluidStack getAverageFluid() { - return new FluidStack(reservoirFluid, (int) (((long) reservoir.getMaxSize() + (long) reservoir.getMinSize()) / 2)); - } - - @Override - public void getIngredients(IIngredients ingredients) { - ingredients.setOutputs(VanillaTypes.FLUID, Lists.newArrayList(getAverageFluid())); - } - - @Override - @SuppressWarnings("NullableProblems") - public List getTooltipStrings(int mouseX, int mouseY) { - String[][] strings = new String[2][]; - - if (reservoir.getDrainChance() != 1f) { - strings[0] = new String[]{"tweakedpetroleum.jei.reservoir.draw_chance", - String.valueOf(reservoir.getDrainChance() * 100), - String.valueOf(100f - (reservoir.getDrainChance() * 100))}; - } - if (Config.IPConfig.Extraction.req_pipes) { - strings[1] = new String[]{"tweakedpetroleum.jei.reservoir.req_pipes"}; - } - - return HEIPumpjackUtil.tooltipStrings(mouseX, mouseY, strings, reservoir); - } - - @Override - @SuppressWarnings("NullableProblems") - public void drawInfo(Minecraft minecraft, int recipeWidth, int recipeHeight, int mouseX, int mouseY) { - int warningCount = 0; - - if (Config.IPConfig.Extraction.req_pipes) { - warningCount++; - } - - if (reservoir.getDrainChance() != 1f) { - warningCount++; - } - - if (warningCount > 0) { - BaseHEIUtil.getPumpjackWarning().draw(minecraft, 55, 8); - minecraft.fontRenderer.drawString(String.valueOf(warningCount), 55, 6, 16696077); - } - } - - @Override - public void onTooltip(int slotIndex, boolean input, FluidStack ingredient, List tooltip) { - HEIPumpjackUtil.onTooltip(slotIndex, reservoir, ingredient.amount, ingredient.getLocalizedName(), tooltip); - } -} diff --git a/src/main/java/srki2k/tweakedpetroleum/common/Configs.java b/src/main/java/srki2k/tweakedpetroleum/common/Configs.java deleted file mode 100644 index 59f6800..0000000 --- a/src/main/java/srki2k/tweakedpetroleum/common/Configs.java +++ /dev/null @@ -1,41 +0,0 @@ -package srki2k.tweakedpetroleum.common; - -import net.minecraftforge.common.config.Config; -import srki2k.tweakedpetroleum.TweakedPetroleum; - -public class Configs { - - @Config(modid = TweakedPetroleum.MODID) - public static class TPConfig { - - @Config.Name("Default Reservoirs") - public static DefaultReservoirs defaultReservoirs; - - public static class DefaultReservoirs { - @Config.Comment({"This will Register default IP Reservoirs(Oil, Water, Lava), default=true"}) - @Config.Name("Register Reservoirs") - @Config.RequiresMcRestart - public static boolean defaultReservoirs = true; - - @Config.Name("Default Pumpjack Power Tiers") - public static DefaultPumpjackPowerTiers defaultPumpjackPowerTiers; - - public static class DefaultPumpjackPowerTiers { - - @Config.Comment({"This will set the capacity of the pumpjack, default=16000"}) - @Config.Name("Default capacity") - @Config.RangeInt(min = 1) - @Config.RequiresMcRestart - public static int capacity = 16000; - - @Config.Comment({"This will set the power consumption of the pumpjack, default=1024"}) - @Config.Name("Default consumption") - @Config.RangeInt(min = 1) - @Config.RequiresMcRestart - public static int rft = 1024; - - } - } - } - -} \ No newline at end of file diff --git a/src/main/java/srki2k/tweakedpetroleum/common/DefaultReservoirs.java b/src/main/java/srki2k/tweakedpetroleum/common/DefaultReservoirs.java deleted file mode 100644 index a556b61..0000000 --- a/src/main/java/srki2k/tweakedpetroleum/common/DefaultReservoirs.java +++ /dev/null @@ -1,44 +0,0 @@ -package srki2k.tweakedpetroleum.common; - -import flaxbeard.immersivepetroleum.api.crafting.PumpjackHandler; -import srki2k.tweakedlib.api.powertier.PowerTierHandler; -import srki2k.tweakedpetroleum.api.crafting.TweakedPumpjackHandler; -import srki2k.tweakedpetroleum.api.ihelpers.IReservoirType; - -import static flaxbeard.immersivepetroleum.api.crafting.PumpjackHandler.reservoirList; - -public class DefaultReservoirs { - - public static void init() { - if (Configs.TPConfig.DefaultReservoirs.defaultReservoirs) { - int powerTier = PowerTierHandler.registerPowerTier( - Configs.TPConfig.DefaultReservoirs.DefaultPumpjackPowerTiers.capacity, - Configs.TPConfig.DefaultReservoirs.DefaultPumpjackPowerTiers.rft); - - makeReservoirType("aquifer", "water", 5000000, 10000000, 6, 25, 30, powerTier, new int[]{}, new int[]{0}); - makeReservoirType("oil", "oil", 2500000, 15000000, 6, 25, 40, powerTier, new int[]{1}, new int[]{}); - makeReservoirType("lava", "lava", 250000, 1000000, 0, 25, 30, powerTier, new int[]{1}, new int[]{}); - - } - - } - - private static void makeReservoirType(String name, String fluid, int minSize, int maxSize, int replenishRate, int pumpSpeed, int weight, int powerTier, int[] dimBlacklist, int[] dimWhitelist) { - PumpjackHandler.ReservoirType mix = new PumpjackHandler.ReservoirType(name, fluid, minSize, maxSize, replenishRate); - - if (reservoirList.containsKey(mix)) { - return; - } - - reservoirList.put(mix, weight); - - IReservoirType iMix = (IReservoirType) mix; - iMix.setReservoirContent(TweakedPumpjackHandler.ReservoirContent.LIQUID); - iMix.setPumpSpeed(pumpSpeed); - iMix.setPowerTier(powerTier); - iMix.setDimensionBlacklist(dimBlacklist); - iMix.setDimensionWhitelist(dimWhitelist); - - } - -} diff --git a/src/main/java/srki2k/tweakedpetroleum/common/compat/crafttweaker/TweakedReservoir.java b/src/main/java/srki2k/tweakedpetroleum/common/compat/crafttweaker/TweakedReservoir.java deleted file mode 100644 index d214c93..0000000 --- a/src/main/java/srki2k/tweakedpetroleum/common/compat/crafttweaker/TweakedReservoir.java +++ /dev/null @@ -1,85 +0,0 @@ -package srki2k.tweakedpetroleum.common.compat.crafttweaker; - -import crafttweaker.CraftTweakerAPI; -import crafttweaker.annotations.ZenRegister; -import crafttweaker.api.liquid.ILiquidStack; -import srki2k.tweakedpetroleum.api.crafting.TweakedPumpjackHandler; -import srki2k.tweakedpetroleum.api.ihelpers.IReservoirType; -import srki2k.tweakedpetroleum.util.ReservoirValidation; -import stanhebben.zenscript.annotations.Optional; -import stanhebben.zenscript.annotations.ZenClass; -import stanhebben.zenscript.annotations.ZenMethod; - -import java.util.ArrayList; -import java.util.List; - -@SuppressWarnings("unused") -@ZenClass("mods.TweakedPetroleum.TweakedReservoir") -@ZenRegister -public class TweakedReservoir { - - @ZenMethod - public static void registerReservoir(String name, ILiquidStack fluid, int minSize, int maxSize, int replenishRate, int pumpSpeed, int weight, int powerTier, - @Optional int[] dimBlacklist, @Optional int[] dimWhitelist, @Optional String[] biomeBlacklist, @Optional String[] biomeWhitelist) { - - List biomeBlacklistList = new ArrayList<>(); - List biomeWhitelistList = new ArrayList<>(); - - ReservoirValidation.validateReservoir(name, minSize, maxSize, replenishRate, pumpSpeed, weight, powerTier, - biomeBlacklist, biomeWhitelist, - biomeBlacklistList, biomeWhitelistList); - - - IReservoirType res = TweakedPumpjackHandler.addTweakedReservoir(name, fluid.getName(), minSize, maxSize, replenishRate, pumpSpeed, weight, powerTier); - - res.setReservoirContent(TweakedPumpjackHandler.ReservoirContent.LIQUID); - if (dimBlacklist != null) { - res.setDimensionBlacklist(dimBlacklist); - } - if (dimWhitelist != null) { - res.setDimensionWhitelist(dimWhitelist); - } - res.setBiomeBlacklist(biomeBlacklistList.toArray(new String[0])); - res.setBiomeWhitelist(biomeWhitelistList.toArray(new String[0])); - - CraftTweakerAPI.logInfo("Added Reservoir Type: " + name); - - } - - @ZenMethod - public static void registerReservoirWithDrainChance(String name, ILiquidStack fluid, int minSize, int maxSize, int replenishRate, int pumpSpeed, float drainChance, int weight, int powerTier, - @Optional int[] dimBlacklist, @Optional int[] dimWhitelist, @Optional String[] biomeBlacklist, @Optional String[] biomeWhitelist) { - - List biomeBlacklistList = new ArrayList<>(); - List biomeWhitelistList = new ArrayList<>(); - - ReservoirValidation.validateReservoir(name, minSize, maxSize, replenishRate, pumpSpeed, weight, powerTier, drainChance, - biomeBlacklist, biomeWhitelist, - biomeBlacklistList, biomeWhitelistList); - - - IReservoirType res = TweakedPumpjackHandler.addTweakedReservoir(name, fluid.getName(), minSize, maxSize, replenishRate, pumpSpeed, weight, powerTier); - - res.setReservoirContent(TweakedPumpjackHandler.ReservoirContent.LIQUID); - res.setDrainChance(drainChance); - if (dimBlacklist != null) { - res.setDimensionBlacklist(dimBlacklist); - } - if (dimWhitelist != null) { - res.setDimensionWhitelist(dimWhitelist); - } - res.setBiomeBlacklist(biomeBlacklistList.toArray(new String[0])); - res.setBiomeWhitelist(biomeWhitelistList.toArray(new String[0])); - - CraftTweakerAPI.logInfo("Added Reservoir Type: " + name); - - } - - @ZenMethod - @Deprecated - public static void registerPowerUsage(int tier, int capacity, int rft) { - CraftTweakerAPI.logError("This method is deprecated 'mods.TweakedPetroleum.TweakedReservoir.registerPowerUsage()"); - CraftTweakerAPI.logError("Go see https://github.com/Srdjan-V/TweakedPetroleum/blob/master/examples/examples.zs for the new way of adding Powertiers"); - } - -} \ No newline at end of file diff --git a/src/main/java/srki2k/tweakedpetroleum/mixin/MixinConfig.java b/src/main/java/srki2k/tweakedpetroleum/mixin/MixinConfig.java deleted file mode 100644 index 07d86fd..0000000 --- a/src/main/java/srki2k/tweakedpetroleum/mixin/MixinConfig.java +++ /dev/null @@ -1,15 +0,0 @@ -package srki2k.tweakedpetroleum.mixin; - -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; - -@Mixin(value = flaxbeard.immersivepetroleum.common.Config.class, remap = false) -public abstract class MixinConfig { - - @Inject(method = "addConfigReservoirs", at = @At("HEAD"), remap = false, cancellable = true) - private static void onAddConfigReservoirs(String[] reservoirs, CallbackInfo ci) { - ci.cancel(); - } -} diff --git a/src/main/java/srki2k/tweakedpetroleum/util/HEIPumpjackUtil.java b/src/main/java/srki2k/tweakedpetroleum/util/HEIPumpjackUtil.java deleted file mode 100644 index a1c9023..0000000 --- a/src/main/java/srki2k/tweakedpetroleum/util/HEIPumpjackUtil.java +++ /dev/null @@ -1,105 +0,0 @@ -package srki2k.tweakedpetroleum.util; - -import flaxbeard.immersivepetroleum.api.crafting.PumpjackHandler; -import srki2k.tweakedlib.api.hei.BaseHEIUtil; -import srki2k.tweakedpetroleum.api.ihelpers.IReservoirType; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -import static flaxbeard.immersivepetroleum.api.crafting.PumpjackHandler.reservoirList; - -public class HEIPumpjackUtil { - - public static void onTooltip(int slotIndex, IReservoirType reservoir, long ingredientAmount, String ingredientLocalizedName, List tooltip) { - tooltip.clear(); - tooltip.add(BaseHEIUtil.formatString(reservoir.getName())); - tooltip.add(BaseHEIUtil.translateToLocalFormatted("tweakedpetroleum.jei.reservoir.contents", ingredientLocalizedName)); - - if (slotIndex == 0) { - tooltip.add(BaseHEIUtil.translateToLocalFormatted("tweakedpetroleum.jei.reservoir.max_size", BaseHEIUtil.numberFormat.format(reservoir.getMaxSize()))); - tooltip.add(BaseHEIUtil.translateToLocalFormatted("tweakedpetroleum.jei.reservoir.min_size", BaseHEIUtil.numberFormat.format(reservoir.getMinSize()))); - - if (reservoir.getDrainChance() != 1f) { - tooltip.add(BaseHEIUtil.translateToLocalFormatted("tweakedpetroleum.jei.reservoir.average", - (BaseHEIUtil.numberFormat.format(ingredientAmount) + " * " + (100f - (reservoir.getDrainChance() * 100)) + "%"))); - return; - } - - tooltip.add(BaseHEIUtil.translateToLocalFormatted("tweakedpetroleum.jei.reservoir.average", - BaseHEIUtil.numberFormat.format(ingredientAmount))); - return; - } - - tooltip.add(BaseHEIUtil.translateToLocalFormatted("tweakedpetroleum.jei.reservoir.replenishRate", BaseHEIUtil.numberFormat.format(reservoir.getReplenishRate()))); - tooltip.add(BaseHEIUtil.translateToLocalFormatted("tweakedpetroleum.jei.reservoir.speed", BaseHEIUtil.numberFormat.format(reservoir.getPumpSpeed()))); - - if (reservoir.getDrainChance() != 1f) { - tooltip.add(BaseHEIUtil.translateToLocalFormatted("tweakedpetroleum.jei.reservoir.average.time", - Math.max(0, ((long) (((long) reservoir.getMaxSize() + reservoir.getMinSize()) * (100f - (reservoir.getDrainChance() * 100))) / 2) - / (reservoir.getPumpSpeed() * 24000L)))); - return; - } - - tooltip.add(BaseHEIUtil.translateToLocalFormatted("tweakedpetroleum.jei.reservoir.average.time", - Math.max(0, (((long) reservoir.getMaxSize() + reservoir.getMinSize()) / 2) - / (reservoir.getPumpSpeed() * 24000L)))); - } - - - public static List tooltipStrings(int mouseX, int mouseY, String[][] customWarnings, IReservoirType reservoir) { - - if (mouseX > 57 && mouseX < 68 && mouseY > 43 && mouseY < 58) { - List list = new ArrayList<>(); - BaseHEIUtil.powerTierListData(list, reservoir.getPowerTier()); - - return list; - } - - if (mouseX > 56 && mouseX < 69 && mouseY > 58 && mouseY < 72) { - List list = new ArrayList<>(); - - list.add(BaseHEIUtil.translateToLocalFormatted("tweakedpetroleum.jei.reservoir.weight", reservoirList.get((PumpjackHandler.ReservoirType) reservoir))); - list.add(""); - - list.add(BaseHEIUtil.translateToLocalFormatted("tweakedpetroleum.jei.reservoir.biomes")); - list.add(BaseHEIUtil.translateToLocalFormatted("tweakedpetroleum.jei.reservoir.biome_whitelist", Arrays.toString(reservoir.getBiomeWhitelist()))); - list.add(BaseHEIUtil.translateToLocalFormatted("tweakedpetroleum.jei.reservoir.biome_blacklist", Arrays.toString(reservoir.getBiomeBlacklist()))); - - list.add(""); - - BaseHEIUtil.dimensionListData(list, reservoir.getDimensionWhitelist(), reservoir.getDimensionBlacklist()); - - return list; - } - - if (customWarnings != null && mouseX > 54 && mouseX < 71 && mouseY > 7 && mouseY < 23) { - List list = new ArrayList<>(); - - for (String[] s : customWarnings) { - if (s == null) { - continue; - } - - if (s.length == 3) { - list.add(BaseHEIUtil.translateToLocalFormatted(s[0], s[1], s[2])); - continue; - } - - if (s.length == 2) { - list.add(BaseHEIUtil.translateToLocalFormatted(s[0], s[1])); - continue; - } - - list.add(BaseHEIUtil.translateToLocal(s[0])); - - } - - return list; - } - - return null; - } - -} diff --git a/src/main/java/srki2k/tweakedpetroleum/util/ReservoirValidation.java b/src/main/java/srki2k/tweakedpetroleum/util/ReservoirValidation.java deleted file mode 100644 index b238684..0000000 --- a/src/main/java/srki2k/tweakedpetroleum/util/ReservoirValidation.java +++ /dev/null @@ -1,74 +0,0 @@ -package srki2k.tweakedpetroleum.util; - -import crafttweaker.CraftTweakerAPI; - -import java.util.List; - -public class ReservoirValidation { - - public static void validateReservoir(String name, int minSize, int maxSize, int replenishRate, int pumpSpeed, int weight, int powerTier, float drainChance, - String[] biomeBlacklist, String[] biomeWhitelist, - List biomeBlacklistList, List biomeWhitelistList) { - - if (drainChance < 0 || 1 < drainChance) { - CraftTweakerAPI.logError("Reservoir drainChance must be between 0 and 1!"); - } - - validateReservoir(name, minSize, maxSize, replenishRate, pumpSpeed, weight, powerTier, - biomeBlacklist, biomeWhitelist, - biomeBlacklistList, biomeWhitelistList); - - } - - public static void validateReservoir(String name, int minSize, int maxSize, int replenishRate, int pumpSpeed, int weight, int powerTier, - String[] biomeBlacklist, String[] biomeWhitelist, - List biomeBlacklistList, List biomeWhitelistList) { - - if (name.isEmpty()) { - CraftTweakerAPI.logError("Reservoir name can not be a empty string!"); - } - if (minSize <= 0) { - CraftTweakerAPI.logError("Reservoir(" + name + ") minSize has to be at least 1mb!"); - } - if (maxSize < minSize) { - CraftTweakerAPI.logError("Reservoir(" + name + ":) maxSize can not be smaller than minSize!"); - } - if (weight < 1) { - CraftTweakerAPI.logError("Reservoir(" + name + ") weight has to be greater than or equal to 1!"); - } - if (pumpSpeed <= 0) { - CraftTweakerAPI.logError("Reservoir(" + name + ") Pump Speed has to be at least 1mb/t"); - } - if (pumpSpeed < replenishRate) { - CraftTweakerAPI.logError("Reservoir(" + name + ") Pump Speed can not be smaller than Replenish Rate!"); - } - if (powerTier < 0) { - CraftTweakerAPI.logError("Reservoir(" + name + ") powerTier can not be smaller than 0!"); - } - - if (biomeBlacklist != null) { - for (String string : biomeBlacklist) { - if (string == null || string.isEmpty()) { - CraftTweakerAPI.logError("Reservoir(" + name + ") String '" + string + "' in biomeBlacklist is either Empty or Null"); - continue; - } - - biomeBlacklistList.add(string); - } - } - - if (biomeWhitelist != null) { - for (String string : biomeWhitelist) { - if (string == null || string.isEmpty()) { - CraftTweakerAPI.logError("Reservoir(" + name + ") String '" + string + "' in biomeWhitelist is either Empty or Null"); - continue; - } - - biomeWhitelistList.add(string); - } - } - - } - -} - diff --git a/src/main/java/srki2k/tweakedpetroleum/util/TweakedPetroleumErrorLogging.java b/src/main/java/srki2k/tweakedpetroleum/util/TweakedPetroleumErrorLogging.java deleted file mode 100644 index fd634bd..0000000 --- a/src/main/java/srki2k/tweakedpetroleum/util/TweakedPetroleumErrorLogging.java +++ /dev/null @@ -1,77 +0,0 @@ -package srki2k.tweakedpetroleum.util; - -import org.apache.logging.log4j.Logger; -import srki2k.tweakedlib.api.logging.errorlogginglib.ErrorLoggingLib; -import srki2k.tweakedlib.api.logging.errorlogginglib.ICustomLogger; -import srki2k.tweakedlib.api.powertier.PowerTierHandler; -import srki2k.tweakedpetroleum.TweakedPetroleum; -import srki2k.tweakedpetroleum.api.ihelpers.IReservoirType; - -import java.util.ArrayList; -import java.util.List; - -import static flaxbeard.immersivepetroleum.api.crafting.PumpjackHandler.reservoirList; -import static srki2k.tweakedpetroleum.common.Configs.TPConfig.DefaultReservoirs.DefaultPumpjackPowerTiers.capacity; -import static srki2k.tweakedpetroleum.common.Configs.TPConfig.DefaultReservoirs.DefaultPumpjackPowerTiers.rft; -import static srki2k.tweakedpetroleum.common.Configs.TPConfig.DefaultReservoirs.defaultReservoirs; - -public final class TweakedPetroleumErrorLogging implements ICustomLogger { - private TweakedPetroleumErrorLogging() { - } - - public static void register() { - ErrorLoggingLib.addCustomLogger(new TweakedPetroleumErrorLogging()); - } - - List errors = new ArrayList<>(); - - @Override - public boolean startupChecks() { - return reservoirList.isEmpty(); - } - - @Override - public boolean runtimeChecks() { - reservoirList.keySet(). - forEach(tweakedReservoirType -> { - if (!PowerTierHandler.powerTierExists(((IReservoirType) tweakedReservoirType).getPowerTier())) { - errors.add("Reservoir with the ID (name)" + tweakedReservoirType.name + "has no valid Power tier"); - } - }); - - return !errors.isEmpty(); - } - - @Override - public boolean discardLoggerAfterStartup() { - return false; - } - - @Override - public Logger getModLogger() { - return TweakedPetroleum.LOGGER; - } - - @Override - public String[] getConfigs() { - String[] strings = new String[5]; - - strings[0] = "DefaultReservoirs:"; - strings[1] = "Register Reservoirs: " + defaultReservoirs; - strings[2] = "Default Pumpjack Power Tiers:"; - strings[3] = "Default capacity:" + capacity; - strings[4] = "Default consumption:" + rft; - - return strings; - } - - @Override - public List getErrors() { - return errors; - } - - @Override - public void clean() { - errors.clear(); - } -} diff --git a/src/main/resources/assets/tweakedpetroleum/lang/en_us.lang b/src/main/resources/assets/tweakedpetroleum/lang/en_us.lang index 593684c..eb7e5aa 100644 --- a/src/main/resources/assets/tweakedpetroleum/lang/en_us.lang +++ b/src/main/resources/assets/tweakedpetroleum/lang/en_us.lang @@ -1,23 +1,34 @@ -tweakedpetroleum.jei.reservoir.max_size= §7Reservoir Max Size: %d mB -tweakedpetroleum.jei.reservoir.min_size= §7Reservoir Min Size: %d mB -tweakedpetroleum.jei.reservoir.replenishRate= §7Reservoir Replenish Rate: %d mB/t -tweakedpetroleum.jei.reservoir.speed= §7Reservoir Pump Speed: %d mB/t +tweakedpetroleum.jei.reservoir.max_size=Reservoir Max Size: +tweakedpetroleum.jei.reservoir.min_size=Reservoir Min Size: +tweakedpetroleum.jei.reservoir.replenishRate=Reservoir Replenish Rate: +tweakedpetroleum.jei.reservoir.speed=Reservoir Pump Speed: -tweakedpetroleum.jei.reservoir.average= §7Average reservoir yield: %d mB -tweakedpetroleum.jei.reservoir.average.time= §7Average time for the reservoir to deplete in minecraft days: %d -tweakedpetroleum.jei.reservoir.contents= §7This reservoir contains: %d +tweakedpetroleum.jei.reservoir.average=Average reservoir yield: +tweakedpetroleum.jei.reservoir.average.time=Average time for the reservoir to deplete in minecraft days: +tweakedpetroleum.jei.reservoir.contents=This reservoir contains: -tweakedpetroleum.jei.reservoir.weight=Reservoir Spawn Weight %d +tweakedpetroleum.jei.reservoir.weight=Reservoir Spawn Weight: tweakedpetroleum.jei.reservoir.biomes=Biomes -tweakedpetroleum.jei.reservoir.biome_whitelist= §7Biome Whitelist: %d -tweakedpetroleum.jei.reservoir.biome_blacklist= §7Biome Blacklist: %d +tweakedpetroleum.jei.reservoir.biome_whitelist=Biome Whitelist: +tweakedpetroleum.jei.reservoir.biome_blacklist=Biome Blacklist: tweakedpetroleum.jei.reservoir.dimensions=Dimensions -tweakedpetroleum.jei.reservoir.dimension_whitelist= §7Dimension Whitelist: %d -tweakedpetroleum.jei.reservoir.dimension_blacklist= §7Dimension Blacklist: %d +tweakedpetroleum.jei.reservoir.dimension_whitelist=Dimension Whitelist: +tweakedpetroleum.jei.reservoir.dimension_blacklist=Dimension Blacklist: tweakedpetroleum.jei.reservoir.lshift=Hold LShift for more info tweakedpetroleum.jei.reservoir.req_pipes=The pumpjack requires IE pipes built down to Bedrock -tweakedpetroleum.jei.reservoir.draw_chance=This reservoir has a %d percent chance to drain from the chunk, this makes that reservoir effectively %d percent bigger \ No newline at end of file +tweakedpetroleum.jei.reservoir.draw_chance1=This reservoir has an +tweakedpetroleum.jei.reservoir.draw_chance2=chance to drain from the chunk, this makes that reservoir effectively +tweakedpetroleum.jei.reservoir.draw_chance3=bigger + +tweakedpetroleum.hud.reservoir.name=Reservoir name: + +tweakedpetroleum.hud.reservoir.unknown=The contents of this reservoir is unknown +tweakedpetroleum.hud.reservoir.empty=The reservoir is empty +tweakedpetroleum.hud.reservoir.current_level=Current level: + +tweakedpetroleum.hud.reservoir.req_pipes=The pumpjack requires power and, IE pipes built down to Bedrock +tweakedpetroleum.hud.reservoir.req_power=The pumpjack requires power \ No newline at end of file diff --git a/src/main/resources/assets/tweakedpetroleum/lang/zh_cn.lang b/src/main/resources/assets/tweakedpetroleum/lang/zh_cn.lang index d803b66..fa09339 100644 --- a/src/main/resources/assets/tweakedpetroleum/lang/zh_cn.lang +++ b/src/main/resources/assets/tweakedpetroleum/lang/zh_cn.lang @@ -1,21 +1,21 @@ -tweakedpetroleum.jei.reservoir.max_size= §7储层最大储量:%d mB -tweakedpetroleum.jei.reservoir.min_size= §7储层最小储量:%d mB -tweakedpetroleum.jei.reservoir.replenishRate= §7储层补给速率: %d mB/t -tweakedpetroleum.jei.reservoir.speed= §7储层抽取速率: %d mB/t +tweakedpetroleum.jei.reservoir.max_size=储层最大储量:%d mB +tweakedpetroleum.jei.reservoir.min_size=储层最小储量:%d mB +tweakedpetroleum.jei.reservoir.replenishRate=储层补给速率: %d mB/t +tweakedpetroleum.jei.reservoir.speed=储层抽取速率: %d mB/t -tweakedpetroleum.jei.reservoir.average= §7储层平均产量:%d mB -tweakedpetroleum.jei.reservoir.average.time= §7储层将会在平均多少minecraft天耗尽:%d -tweakedpetroleum.jei.reservoir.contents= §7这个储层包含:%d +tweakedpetroleum.jei.reservoir.average=储层平均产量:%d mB +tweakedpetroleum.jei.reservoir.average.time=储层将会在平均多少minecraft天耗尽:%d +tweakedpetroleum.jei.reservoir.contents=这个储层包含:%d tweakedpetroleum.jei.reservoir.weight=储层生成权重 %d tweakedpetroleum.jei.reservoir.biomes=生物群系 -tweakedpetroleum.jei.reservoir.biome_whitelist= §7生物群系白名单:%d -tweakedpetroleum.jei.reservoir.biome_blacklist= §7生物群系黑名单:%d +tweakedpetroleum.jei.reservoir.biome_whitelist=生物群系白名单:%d +tweakedpetroleum.jei.reservoir.biome_blacklist=生物群系黑名单:%d tweakedpetroleum.jei.reservoir.dimensions=维度 -tweakedpetroleum.jei.reservoir.dimension_whitelist= §7维度白名单:%d -tweakedpetroleum.jei.reservoir.dimension_blacklist= §7维度黑名单:%d +tweakedpetroleum.jei.reservoir.dimension_whitelist=维度白名单:%d +tweakedpetroleum.jei.reservoir.dimension_blacklist=维度黑名单:%d tweakedpetroleum.jei.reservoir.lshift=按住LSHIFT查看更多信息 diff --git a/src/main/resources/assets/tweakedpetroleum/textures/gui/pumpjack.png b/src/main/resources/assets/tweakedpetroleum/textures/gui/pumpjack.png index 69c309a..3cfc42f 100644 Binary files a/src/main/resources/assets/tweakedpetroleum/textures/gui/pumpjack.png and b/src/main/resources/assets/tweakedpetroleum/textures/gui/pumpjack.png differ diff --git a/src/main/resources/mixins.tweakedpetroleum.json b/src/main/resources/mixins.tweakedpetroleum.json index 1b45a3d..83a2cf7 100644 --- a/src/main/resources/mixins.tweakedpetroleum.json +++ b/src/main/resources/mixins.tweakedpetroleum.json @@ -1,6 +1,6 @@ { "minVersion": "0.8", - "package": "srki2k.tweakedpetroleum.mixin", + "package": "io.github.srdjanv.tweakedpetroleum.mixin", "compatibilityLevel": "JAVA_8", "mixins": [ "MixinConfig",