From 62d3983eb6aede822a7b251c62b923d68b728a23 Mon Sep 17 00:00:00 2001 From: Raven Szewczyk Date: Wed, 24 Aug 2022 10:09:37 +0100 Subject: [PATCH 01/11] Update dependencies --- dependencies.gradle | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/dependencies.gradle b/dependencies.gradle index 67ff99c..21ba945 100644 --- a/dependencies.gradle +++ b/dependencies.gradle @@ -1,10 +1,10 @@ // Add your dependencies here dependencies { - compile("com.github.GTNewHorizons:Applied-Energistics-2-Unofficial:rv3-beta-91-GTNH:dev") + compile("com.github.GTNewHorizons:Applied-Energistics-2-Unofficial:rv3-beta-98-GTNH:dev") compile("com.github.GTNewHorizons:Baubles:1.0.1.14:dev") compile("curse.maven:cofh-core-69162:2388751") - compile("com.github.GTNewHorizons:NotEnoughItems:2.2.12-GTNH:dev") - compile("com.github.GTNewHorizons:CodeChickenLib:1.1.5.3:dev") - compileOnly("com.github.GTNewHorizons:EnderIO:2.3.1.32:dev") { transitive = false } + compile("com.github.GTNewHorizons:NotEnoughItems:2.2.27-GTNH:dev") + compile("com.github.GTNewHorizons:CodeChickenLib:1.1.5.4:dev") + compileOnly("com.github.GTNewHorizons:EnderIO:2.3.1.43:dev") { transitive = false } } From 166b353332fc6d542c825a06953b66c59beb2b60 Mon Sep 17 00:00:00 2001 From: Raven Szewczyk Date: Wed, 24 Aug 2022 10:10:37 +0100 Subject: [PATCH 02/11] Update buildscript --- .gitattributes | 35 +++++ build.gradle | 352 ++++++++++++++++++++++++++---------------------- settings.gradle | 10 ++ 3 files changed, 239 insertions(+), 158 deletions(-) create mode 100644 .gitattributes create mode 100644 settings.gradle diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..9917fc4 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,35 @@ +* text eol=lf + +*.jar binary + +*.png binary +*.jpg binary +*.jpeg binary +*.gif binary +*.tif binary +*.tiff binary +*.ico binary +*.svg text +*.eps binary + +*.kar binary +*.m4a binary +*.mid binary +*.midi binary +*.mp3 binary +*.ogg binary +*.ra binary + +*.7z binary +*.gz binary +*.tar binary +*.tgz binary +*.zip binary + +*.patch -text + +*.bat text eol=crlf +*.cmd text eol=crlf +*.ps1 text eol=crlf + +*autogenerated binary \ No newline at end of file diff --git a/build.gradle b/build.gradle index 94e9c84..997b94d 100644 --- a/build.gradle +++ b/build.gradle @@ -1,10 +1,9 @@ -//version: 1656003794 +//version: 1661114848 /* -DO NOT CHANGE THIS FILE! - -Also, you may replace this file at any time if there is an update available. -Please check https://github.com/GTNewHorizons/ExampleMod1.7.10/blob/main/build.gradle for updates. -*/ + DO NOT CHANGE THIS FILE! + Also, you may replace this file at any time if there is an update available. + Please check https://github.com/GTNewHorizons/ExampleMod1.7.10/blob/main/build.gradle for updates. + */ import com.github.jengelman.gradle.plugins.shadow.tasks.ConfigureShadowRelocation @@ -21,10 +20,17 @@ import java.util.zip.ZipOutputStream buildscript { repositories { + mavenCentral() + maven { name 'forge' url 'https://maven.minecraftforge.net' } + maven { + // GTNH ForgeGradle Fork + name = "GTNH Maven" + url = "http://jenkins.usrv.eu:8081/nexus/content/groups/public/" + } maven { name 'sonatype' url 'https://oss.sonatype.org/content/repositories/snapshots/' @@ -33,32 +39,37 @@ buildscript { name 'Scala CI dependencies' url 'https://repo1.maven.org/maven2/' } - maven { - name 'jitpack' - url 'https://jitpack.io' - } } dependencies { - classpath 'com.github.GTNewHorizons:ForgeGradle:1.2.7' + classpath 'net.minecraftforge.gradle:ForgeGradle:1.2.9' } } - plugins { id 'java-library' id 'idea' id 'eclipse' id 'scala' id 'maven-publish' - id 'org.jetbrains.kotlin.jvm' version '1.5.30' apply false - id 'org.jetbrains.kotlin.kapt' version '1.5.30' apply false - id 'com.google.devtools.ksp' version '1.5.30-1.0.0' apply false - id 'org.ajoberstar.grgit' version '4.1.1' + id 'org.jetbrains.kotlin.jvm' version '1.5.30' apply false + id 'org.jetbrains.kotlin.kapt' version '1.5.30' apply false + id 'com.google.devtools.ksp' version '1.5.30-1.0.0' apply false + id 'org.ajoberstar.grgit' version '4.1.1' id 'com.github.johnrengelman.shadow' version '4.0.4' - id 'com.palantir.git-version' version '0.13.0' apply false - id 'de.undercouch.download' version '5.0.1' - id 'com.github.gmazzo.buildconfig' version '3.0.3' apply false - id "com.diffplug.spotless" version "6.7.2" + id 'com.palantir.git-version' version '0.13.0' apply false + id 'de.undercouch.download' version '5.0.1' + id 'com.github.gmazzo.buildconfig' version '3.0.3' apply false + id 'com.diffplug.spotless' version '6.7.2' apply false } +boolean settingsupdated = verifySettingsGradle() +settingsupdated = verifyGitAttributes() || settingsupdated +if (settingsupdated) + throw new GradleException("Settings has been updated, please re-run task.") + +dependencies { + implementation 'com.diffplug:blowdryer:1.6.0' +} + +apply plugin: 'com.diffplug.blowdryer' if (project.file('.git/HEAD').isFile()) { apply plugin: 'com.palantir.git-version' @@ -84,38 +95,14 @@ idea { } } -// Spotless autoformatter -// See https://github.com/diffplug/spotless/tree/main/plugin-gradle -// Can be locally toggled via spotless:off/spotless:on comments -spotless { - encoding 'UTF-8' +boolean disableSpotless = project.hasProperty("disableSpotless") ? project.disableSpotless.toBoolean() : false - format 'misc', { - target '*.md', '.gitignore' - - trimTrailingWhitespace() - indentWithSpaces(4) - endWithNewline() - } - java { - toggleOffOn() - importOrder() - removeUnusedImports() - palantirJavaFormat('1.1.0') // last version supporting jvm 8 - } - kotlin { - toggleOffOn() - ktfmt('0.39') - } - groovyGradle { - toggleOffOn() - importOrder() - target '*.gradle' - greclipse('4.19.0') // last version supporting jvm 8 - } +if (!disableSpotless) { + apply plugin: 'com.diffplug.spotless' + apply from: Blowdryer.file('spotless.gradle') } -if(JavaVersion.current() != JavaVersion.VERSION_1_8) { +if (JavaVersion.current() != JavaVersion.VERSION_1_8) { throw new GradleException("This project requires Java 8, but it's running on " + JavaVersion.current()) } @@ -140,12 +127,11 @@ checkPropertyExists("containsMixinsAndOrCoreModOnly") checkPropertyExists("usesShadowedDependencies") checkPropertyExists("developmentEnvironmentUserName") -boolean noPublishedSources = project.findProperty("noPublishedSources") ? project.noPublishedSources.toBoolean() : false -boolean usesMixinDebug = project.findProperty('usesMixinDebug') ?: project.usesMixins.toBoolean() -String channel = project.findProperty('channel') ? project.channel : 'stable' -String mappingsVersion = project.findProperty('mappingsVersion') ? project.mappingsVersion : '12' -String remoteMappings = project.findProperty('remoteMappings') ? project.remoteMappings : 'https://raw.githubusercontent.com/MinecraftForge/FML/1.7.10/conf/' - +boolean noPublishedSources = project.hasProperty("noPublishedSources") ? project.noPublishedSources.toBoolean() : false +boolean usesMixinDebug = project.hasProperty('usesMixinDebug') ?: project.usesMixins.toBoolean() +boolean forceEnableMixins = project.hasProperty('forceEnableMixins') ? project.forceEnableMixins.toBoolean() : false +String channel = project.hasProperty('channel') ? project.channel : 'stable' +String mappingsVersion = project.hasProperty('mappingsVersion') ? project.mappingsVersion : '12' String javaSourceDir = "src/main/java/" String scalaSourceDir = "src/main/scala/" String kotlinSourceDir = "src/main/kotlin/" @@ -153,53 +139,53 @@ String kotlinSourceDir = "src/main/kotlin/" String targetPackageJava = javaSourceDir + modGroup.toString().replaceAll("\\.", "/") String targetPackageScala = scalaSourceDir + modGroup.toString().replaceAll("\\.", "/") String targetPackageKotlin = kotlinSourceDir + modGroup.toString().replaceAll("\\.", "/") -if(!(getFile(targetPackageJava).exists() || getFile(targetPackageScala).exists() || getFile(targetPackageKotlin).exists())) { +if (!(getFile(targetPackageJava).exists() || getFile(targetPackageScala).exists() || getFile(targetPackageKotlin).exists())) { throw new GradleException("Could not resolve \"modGroup\"! Could not find " + targetPackageJava + " or " + targetPackageScala + " or " + targetPackageKotlin) } -if(apiPackage) { +if (apiPackage) { targetPackageJava = javaSourceDir + modGroup.toString().replaceAll("\\.", "/") + "/" + apiPackage.toString().replaceAll("\\.", "/") targetPackageScala = scalaSourceDir + modGroup.toString().replaceAll("\\.", "/") + "/" + apiPackage.toString().replaceAll("\\.", "/") targetPackageKotlin = kotlinSourceDir + modGroup.toString().replaceAll("\\.", "/") + "/" + apiPackage.toString().replaceAll("\\.", "/") - if(!(getFile(targetPackageJava).exists() || getFile(targetPackageScala).exists() || getFile(targetPackageKotlin).exists())) { + if (!(getFile(targetPackageJava).exists() || getFile(targetPackageScala).exists() || getFile(targetPackageKotlin).exists())) { throw new GradleException("Could not resolve \"apiPackage\"! Could not find " + targetPackageJava + " or " + targetPackageScala + " or " + targetPackageKotlin) } } -if(accessTransformersFile) { +if (accessTransformersFile) { String targetFile = "src/main/resources/META-INF/" + accessTransformersFile - if(!getFile(targetFile).exists()) { + if (!getFile(targetFile).exists()) { throw new GradleException("Could not resolve \"accessTransformersFile\"! Could not find " + targetFile) } } -if(usesMixins.toBoolean()) { - if(mixinsPackage.isEmpty() || mixinPlugin.isEmpty()) { +if (usesMixins.toBoolean()) { + if (mixinsPackage.isEmpty() || mixinPlugin.isEmpty()) { throw new GradleException("\"mixinPlugin\" requires \"mixinsPackage\" and \"mixinPlugin\" to be set!") } targetPackageJava = javaSourceDir + modGroup.toString().replaceAll("\\.", "/") + "/" + mixinsPackage.toString().replaceAll("\\.", "/") targetPackageScala = scalaSourceDir + modGroup.toString().replaceAll("\\.", "/") + "/" + mixinsPackage.toString().replaceAll("\\.", "/") targetPackageKotlin = kotlinSourceDir + modGroup.toString().replaceAll("\\.", "/") + "/" + mixinsPackage.toString().replaceAll("\\.", "/") - if(!(getFile(targetPackageJava).exists() || getFile(targetPackageScala).exists() || getFile(targetPackageKotlin).exists())) { - throw new GradleException("Could not resolve \"mixinsPackage\"! Could not find " + targetPackageJava + " or " + targetPackageScala + " or " + targetPackageKotlin) + if (!(getFile(targetPackageJava).exists() || getFile(targetPackageScala).exists() || getFile(targetPackageKotlin).exists())) { + throw new GradleException("Could not resolve \"mixinsPackage\"! Could not find " + targetPackageJava + " or " + targetPackageScala + " or " + targetPackageKotlin) } String targetFileJava = javaSourceDir + modGroup.toString().replaceAll("\\.", "/") + "/" + mixinPlugin.toString().replaceAll("\\.", "/") + ".java" String targetFileScala = scalaSourceDir + modGroup.toString().replaceAll("\\.", "/") + "/" + mixinPlugin.toString().replaceAll("\\.", "/") + ".scala" String targetFileScalaJava = scalaSourceDir + modGroup.toString().replaceAll("\\.", "/") + "/" + mixinPlugin.toString().replaceAll("\\.", "/") + ".java" String targetFileKotlin = kotlinSourceDir + modGroup.toString().replaceAll("\\.", "/") + "/" + mixinPlugin.toString().replaceAll("\\.", "/") + ".kt" - if(!(getFile(targetFileJava).exists() || getFile(targetFileScala).exists() || getFile(targetFileScalaJava).exists() || getFile(targetFileKotlin).exists())) { + if (!(getFile(targetFileJava).exists() || getFile(targetFileScala).exists() || getFile(targetFileScalaJava).exists() || getFile(targetFileKotlin).exists())) { throw new GradleException("Could not resolve \"mixinPlugin\"! Could not find " + targetFileJava + " or " + targetFileScala + " or " + targetFileScalaJava + " or " + targetFileKotlin) } } -if(coreModClass) { +if (coreModClass) { String targetFileJava = javaSourceDir + modGroup.toString().replaceAll("\\.", "/") + "/" + coreModClass.toString().replaceAll("\\.", "/") + ".java" String targetFileScala = scalaSourceDir + modGroup.toString().replaceAll("\\.", "/") + "/" + coreModClass.toString().replaceAll("\\.", "/") + ".scala" String targetFileScalaJava = scalaSourceDir + modGroup.toString().replaceAll("\\.", "/") + "/" + coreModClass.toString().replaceAll("\\.", "/") + ".java" String targetFileKotlin = kotlinSourceDir + modGroup.toString().replaceAll("\\.", "/") + "/" + coreModClass.toString().replaceAll("\\.", "/") + ".kt" - if(!(getFile(targetFileJava).exists() || getFile(targetFileScala).exists() || getFile(targetFileScalaJava).exists() || getFile(targetFileKotlin).exists())) { + if (!(getFile(targetFileJava).exists() || getFile(targetFileScala).exists() || getFile(targetFileScalaJava).exists() || getFile(targetFileKotlin).exists())) { throw new GradleException("Could not resolve \"coreModClass\"! Could not find " + targetFileJava + " or " + targetFileScala + " or " + targetFileScalaJava + " or " + targetFileKotlin) } } @@ -229,7 +215,7 @@ try { catch (Exception ignored) { out.style(Style.Failure).text( 'This mod must be version controlled by Git AND the repository must provide at least one tag,\n' + - 'or the VERSION override must be set! ').style(Style.SuccessHeader).text('(Do NOT download from GitHub using the ZIP option, instead\n' + + 'or the VERSION override must be set! ').style(Style.SuccessHeader).text('(Do NOT download from GitHub using the ZIP option, instead\n' + 'clone the repository, see ').style(Style.Info).text('https://gtnh.miraheze.org/wiki/Development').style(Style.SuccessHeader).println(' for details.)' ) versionOverride = 'NO-GIT-TAG-SET' @@ -240,22 +226,21 @@ ext { modVersion = identifiedVersion } -if(identifiedVersion == versionOverride) { +if (identifiedVersion == versionOverride) { out.style(Style.Failure).text('Override version to ').style(Style.Identifier).text(modVersion).style(Style.Failure).println('!\7') } group = modGroup -if(project.hasProperty("customArchiveBaseName") && customArchiveBaseName) { +if (project.hasProperty("customArchiveBaseName") && customArchiveBaseName) { archivesBaseName = customArchiveBaseName -} -else { +} else { archivesBaseName = modId } def arguments = [] def jvmArguments = [] -if (usesMixins.toBoolean()) { +if (usesMixins.toBoolean() || forceEnableMixins) { arguments += [ "--tweakClass org.spongepowered.asm.launch.MixinTweaker" ] @@ -274,16 +259,16 @@ minecraft { if (replaceGradleTokenInFile) { replaceIn replaceGradleTokenInFile - if(gradleTokenModId) { + if (gradleTokenModId) { replace gradleTokenModId, modId } - if(gradleTokenModName) { + if (gradleTokenModName) { replace gradleTokenModName, modName } - if(gradleTokenVersion) { + if (gradleTokenVersion) { replace gradleTokenVersion, modVersion } - if(gradleTokenGroupName) { + if (gradleTokenGroupName) { replace gradleTokenGroupName, modGroup } } @@ -292,7 +277,7 @@ minecraft { args(arguments) jvmArgs(jvmArguments) - if(developmentEnvironmentUserName) { + if (developmentEnvironmentUserName) { args("--username", developmentEnvironmentUserName) } } @@ -303,7 +288,7 @@ minecraft { } } -if(file('addon.gradle').exists()) { +if (file('addon.gradle').exists()) { apply from: 'addon.gradle' } @@ -320,7 +305,7 @@ repositories { name 'Overmind forge repo mirror' url 'https://gregtech.overminddl1.com/' } - if(usesMixins.toBoolean()) { + if (usesMixins.toBoolean() || forceEnableMixins) { maven { name 'sponge' url 'https://repo.spongepowered.org/repository/maven-public' @@ -332,11 +317,13 @@ repositories { } dependencies { - if(usesMixins.toBoolean()) { + if (usesMixins.toBoolean()) { annotationProcessor('org.ow2.asm:asm-debug-all:5.0.3') annotationProcessor('com.google.guava:guava:24.1.1-jre') annotationProcessor('com.google.code.gson:gson:2.8.6') annotationProcessor('org.spongepowered:mixin:0.8-SNAPSHOT') + } + if (usesMixins.toBoolean() || forceEnableMixins) { // using 0.8 to workaround a issue in 0.7 which fails mixin application compile('com.github.GTNewHorizons:SpongePoweredMixin:0.7.12-GTNH') { // Mixin includes a lot of dependencies that are too up-to-date @@ -394,7 +381,10 @@ shadowJar { } minimize() // This will only allow shading for actually used classes - configurations = [project.configurations.shadowImplementation, project.configurations.shadowCompile] + configurations = [ + project.configurations.shadowImplementation, + project.configurations.shadowCompile + ] dependsOn(relocateShadowJar) } @@ -409,38 +399,38 @@ jar { attributes(getManifestAttributes()) } - if(usesShadowedDependencies.toBoolean()) { + if (usesShadowedDependencies.toBoolean()) { dependsOn(shadowJar) enabled = false } } reobf { - if(usesMixins.toBoolean()) { + if (usesMixins.toBoolean()) { addExtraSrgFile mixinSrg } } afterEvaluate { - if(usesMixins.toBoolean()) { + if (usesMixins.toBoolean()) { tasks.compileJava { options.compilerArgs += [ - "-AreobfSrgFile=${tasks.reobf.srg}", - "-AoutSrgFile=${mixinSrg}", - "-AoutRefMapFile=${refMap}", - // Elan: from what I understand they are just some linter configs so you get some warning on how to properly code - "-XDenableSunApiLintControl", - "-XDignore.symbol.file" + "-AreobfSrgFile=${tasks.reobf.srg}", + "-AoutSrgFile=${mixinSrg}", + "-AoutRefMapFile=${refMap}", + // Elan: from what I understand they are just some linter configs so you get some warning on how to properly code + "-XDenableSunApiLintControl", + "-XDignore.symbol.file" ] } } } runClient { - if(developmentEnvironmentUserName) { + if (developmentEnvironmentUserName) { arguments += [ - "--username", - developmentEnvironmentUserName + "--username", + developmentEnvironmentUserName ] } @@ -455,9 +445,9 @@ runServer { tasks.withType(JavaExec).configureEach { javaLauncher.set( - javaToolchains.launcherFor { - languageVersion = projectJavaVersion - } + javaToolchains.launcherFor { + languageVersion = projectJavaVersion + } ) } @@ -465,6 +455,7 @@ processResources { // this will ensure that this task is redone when the versions change. inputs.property "version", project.version inputs.property "mcversion", project.minecraft.version + exclude("spotless.gradle") // replace stuff in mcmod.info, nothing else from(sourceSets.main.resources.srcDirs) { @@ -477,43 +468,44 @@ processResources { "modName": modName } - if(usesMixins.toBoolean()) { + if (usesMixins.toBoolean()) { from refMap } // copy everything else that's not the mcmod.info from(sourceSets.main.resources.srcDirs) { exclude 'mcmod.info' + exclude 'spotless.gradle' } } def getManifestAttributes() { def manifestAttributes = [:] - if(!containsMixinsAndOrCoreModOnly.toBoolean() && (usesMixins.toBoolean() || coreModClass)) { + if (!containsMixinsAndOrCoreModOnly.toBoolean() && (usesMixins.toBoolean() || coreModClass)) { manifestAttributes += ["FMLCorePluginContainsFMLMod": true] } - if(accessTransformersFile) { - manifestAttributes += ["FMLAT" : accessTransformersFile.toString()] + if (accessTransformersFile) { + manifestAttributes += ["FMLAT": accessTransformersFile.toString()] } - if(coreModClass) { + if (coreModClass) { manifestAttributes += ["FMLCorePlugin": modGroup + "." + coreModClass] } - if(usesMixins.toBoolean()) { + if (usesMixins.toBoolean()) { manifestAttributes += [ - "TweakClass" : "org.spongepowered.asm.launch.MixinTweaker", - "MixinConfigs" : "mixins." + modId + ".json", - "ForceLoadAsMod" : !containsMixinsAndOrCoreModOnly.toBoolean() + "TweakClass" : "org.spongepowered.asm.launch.MixinTweaker", + "MixinConfigs" : "mixins." + modId + ".json", + "ForceLoadAsMod": !containsMixinsAndOrCoreModOnly.toBoolean() ] } return manifestAttributes } task sourcesJar(type: Jar) { - from (sourceSets.main.allSource) - from (file("$projectDir/LICENSE")) + from(sourceSets.main.allSource) + from(file("$projectDir/LICENSE")) getArchiveClassifier().set('sources') } @@ -532,7 +524,10 @@ task shadowDevJar(type: ShadowJar) { } minimize() // This will only allow shading for actually used classes - configurations = [project.configurations.shadowImplementation, project.configurations.shadowCompile] + configurations = [ + project.configurations.shadowImplementation, + project.configurations.shadowCompile + ] } task relocateShadowDevJar(type: ConfigureShadowRelocation) { @@ -560,22 +555,22 @@ task devJar(type: Jar) { attributes(getManifestAttributes()) } - if(usesShadowedDependencies.toBoolean()) { + if (usesShadowedDependencies.toBoolean()) { dependsOn(circularResolverJar) enabled = false } } task apiJar(type: Jar) { - from (sourceSets.main.allSource) { + from(sourceSets.main.allSource) { include modGroup.toString().replaceAll("\\.", "/") + "/" + apiPackage.toString().replaceAll("\\.", "/") + '/**' } - from (sourceSets.main.output) { + from(sourceSets.main.output) { include modGroup.toString().replaceAll("\\.", "/") + "/" + apiPackage.toString().replaceAll("\\.", "/") + '/**' } - from (sourceSets.main.resources.srcDirs) { + from(sourceSets.main.resources.srcDirs) { include("LICENSE") } @@ -583,11 +578,11 @@ task apiJar(type: Jar) { } artifacts { - if(!noPublishedSources) { + if (!noPublishedSources) { archives sourcesJar } archives devJar - if(apiPackage) { + if (apiPackage) { archives apiJar } } @@ -605,10 +600,10 @@ publishing { publications { maven(MavenPublication) { from components.java - if(usesShadowedDependencies.toBoolean()) { + if (usesShadowedDependencies.toBoolean()) { artifact source: shadowJar, classifier: "" } - if(!noPublishedSources) { + if (!noPublishedSources) { artifact source: sourcesJar, classifier: "sources" } artifact source: usesShadowedDependencies.toBoolean() ? shadowDevJar : devJar, classifier: "dev" @@ -623,8 +618,11 @@ publishing { // remove extra garbage from minecraft and minecraftDeps configuration pom.withXml { - def badArtifacts = [:].withDefault {[] as Set} - for (configuration in [projectConfigs.minecraft, projectConfigs.minecraftDeps]) { + def badArtifacts = [:].withDefault { [] as Set } + for (configuration in [ + projectConfigs.minecraft, + projectConfigs.minecraftDeps + ]) { for (dependency in configuration.allDependencies) { badArtifacts[dependency.group == null ? "" : dependency.group] += dependency.name } @@ -662,7 +660,7 @@ task updateBuildScript { } } -if (isNewBuildScriptVersionAvailable(projectDir.toString())) { +if (!project.getGradle().startParameter.isOffline() && isNewBuildScriptVersionAvailable(projectDir.toString())) { if (autoUpdateBuildScript.toBoolean()) { performBuildScriptUpdate(projectDir.toString()) } else { @@ -671,7 +669,40 @@ if (isNewBuildScriptVersionAvailable(projectDir.toString())) { } static URL availableBuildScriptUrl() { - new URL("https://raw.githubusercontent.com/GTNewHorizons/ExampleMod1.7.10/main/build.gradle") + new URL("https://raw.githubusercontent.com/GTNewHorizons/ExampleMod1.7.10/master/build.gradle") +} + +static URL exampleSettingsGradleUrl() { + new URL("https://raw.githubusercontent.com/GTNewHorizons/ExampleMod1.7.10/master/settings.gradle.example") +} + +static URL exampleGitAttributesUrl() { + new URL("https://raw.githubusercontent.com/GTNewHorizons/ExampleMod1.7.10/master/.gitattributes") +} + + +boolean verifyGitAttributes() { + def gitattributesFile = getFile(".gitattributes") + if (!gitattributesFile.exists()) { + println("Downloading default .gitattributes") + exampleGitAttributesUrl().withInputStream { i -> gitattributesFile.withOutputStream { it << i } } + exec { + workingDir '.' + commandLine 'git', 'add', '--renormalize', '.' + } + return true + } + return false +} + +boolean verifySettingsGradle() { + def settingsFile = getFile("settings.gradle") + if (!settingsFile.exists()) { + println("Downloading default settings.gradle") + exampleSettingsGradleUrl().withInputStream { i -> settingsFile.withOutputStream { it << i } } + return true + } + return false } boolean performBuildScriptUpdate(String projectDir) { @@ -679,6 +710,10 @@ boolean performBuildScriptUpdate(String projectDir) { def buildscriptFile = getFile("build.gradle") availableBuildScriptUrl().withInputStream { i -> buildscriptFile.withOutputStream { it << i } } out.style(Style.Success).print("Build script updated. Please REIMPORT the project or RESTART your IDE!") + boolean settingsupdated = verifySettingsGradle() + settingsupdated = verifyGitAttributes() || settingsupdated + if (settingsupdated) + throw new GradleException("Settings has been updated, please re-run task.") return true } return false @@ -698,7 +733,7 @@ boolean isNewBuildScriptVersionAvailable(String projectDir) { static String getVersionHash(String buildScriptContent) { String versionLine = buildScriptContent.find("^//version: [a-z0-9]*") - if(versionLine != null) { + if (versionLine != null) { return versionLine.split(": ").last() } return "" @@ -724,16 +759,16 @@ task deobfParams { overwrite false } - if(!file(paramsCSV).exists()) { + if (!file(paramsCSV).exists()) { println("Extracting MCP archive ...") unzip(mcpZIP, mcpDir) } println("Parsing params.csv ...") Map params = new HashMap<>() - Files.lines(Paths.get(paramsCSV)).forEach{line -> + Files.lines(Paths.get(paramsCSV)).forEach { line -> String[] cells = line.split(",") - if(cells.length > 2 && cells[0].matches("p_i?\\d+_\\d+_")) { + if (cells.length > 2 && cells[0].matches("p_i?\\d+_\\d+_")) { params.put(cells[0], cells[1]) } } @@ -746,8 +781,8 @@ task deobfParams { static int replaceParams(File file, Map params) { int fileCount = 0 - if(file.isDirectory()) { - for(File f : file.listFiles()) { + if (file.isDirectory()) { + for (File f : file.listFiles()) { fileCount += replaceParams(f, params) } return fileCount @@ -756,14 +791,14 @@ static int replaceParams(File file, Map params) { try { String content = new String(Files.readAllBytes(file.toPath())) int hash = content.hashCode() - params.forEach{key, value -> + params.forEach { key, value -> content = content.replaceAll(key, value) } - if(hash != content.hashCode()) { + if (hash != content.hashCode()) { Files.write(file.toPath(), content.getBytes("UTF-8")) return 1 } - } catch(Exception e) { + } catch (Exception e) { e.printStackTrace() } return 0 @@ -775,27 +810,27 @@ static unzip(String zipFileName, String outputDir) { ZipInputStream zis = new ZipInputStream(new FileInputStream(zipFileName)) ZipEntry zipEntry = zis.getNextEntry() while (zipEntry != null) { - File newFile = new File(outputDir + File.separator, zipEntry.name) - if (zipEntry.isDirectory()) { - if (!newFile.isDirectory() && !newFile.mkdirs()) { - throw new IOException("Failed to create directory $newFile") - } - } else { - // fix for Windows-created archives - File parent = newFile.parentFile - if (!parent.isDirectory() && !parent.mkdirs()) { - throw new IOException("Failed to create directory $parent") - } - // write file content - FileOutputStream fos = new FileOutputStream(newFile) - int len = 0 - while ((len = zis.read(buffer)) > 0) { - fos.write(buffer, 0, len) - } - fos.close() - } - zipEntry = zis.getNextEntry() - } + File newFile = new File(outputDir + File.separator, zipEntry.name) + if (zipEntry.isDirectory()) { + if (!newFile.isDirectory() && !newFile.mkdirs()) { + throw new IOException("Failed to create directory $newFile") + } + } else { + // fix for Windows-created archives + File parent = newFile.parentFile + if (!parent.isDirectory() && !parent.mkdirs()) { + throw new IOException("Failed to create directory $parent") + } + // write file content + FileOutputStream fos = new FileOutputStream(newFile) + int len = 0 + while ((len = zis.read(buffer)) > 0) { + fos.write(buffer, 0, len) + } + fos.close() + } + zipEntry = zis.getNextEntry() + } zis.closeEntry() zis.close() } @@ -814,16 +849,16 @@ def deobf(String sourceURL) { //get rid of directories: int lastSlash = fileName.lastIndexOf("/") - if(lastSlash > 0) { + if (lastSlash > 0) { fileName = fileName.substring(lastSlash + 1) } //get rid of extension: - if(fileName.endsWith(".jar") || fileName.endsWith(".litemod")) { + if (fileName.endsWith(".jar") || fileName.endsWith(".litemod")) { fileName = fileName.substring(0, fileName.lastIndexOf(".")) } String hostName = url.getHost() - if(hostName.startsWith("www.")) { + if (hostName.startsWith("www.")) { hostName = hostName.substring(4) } List parts = Arrays.asList(hostName.split("\\.")) @@ -831,7 +866,7 @@ def deobf(String sourceURL) { hostName = String.join(".", parts) return deobf(sourceURL, "$hostName/$fileName") - } catch(Exception e) { + } catch (Exception e) { return deobf(sourceURL, "deobf/${sourceURL.hashCode()}") } } @@ -846,12 +881,13 @@ def deobf(String sourceURL, String rawFileName) { String obfFile = "$cacheDir/modules-2/files-2.1/${fileName}.jar" String deobfFile = "$cacheDir/modules-2/files-2.1/${fileName}-deobf.jar" - if(file(deobfFile).exists()) { + if (file(deobfFile).exists()) { return files(deobfFile) } String mappingsVer - if(remoteMappings) { + String remoteMappings = project.hasProperty('remoteMappings') ? project.remoteMappings : 'https://raw.githubusercontent.com/MinecraftForge/FML/1.7.10/conf/' + if (remoteMappings) { String id = "${forgeVersion.split("\\.")[3]}-$minecraftVersion" String mappingsZIP = "$cacheDir/forge_gradle/maven_downloader/de/oceanlabs/mcp/mcp_snapshot_nodoc/$id/mcp_snapshot_nodoc-${id}.zip" @@ -887,7 +923,7 @@ def deobf(String sourceURL, String rawFileName) { def zipMappings(String zipPath, String url, String bon2Dir) { File zipFile = new File(zipPath) - if(zipFile.exists()) { + if (zipFile.exists()) { return } diff --git a/settings.gradle b/settings.gradle new file mode 100644 index 0000000..93c852a --- /dev/null +++ b/settings.gradle @@ -0,0 +1,10 @@ +plugins { + id 'com.diffplug.blowdryerSetup' version '1.6.0' +} + +apply plugin: 'com.diffplug.blowdryerSetup' + +blowdryerSetup { + github('GTNewHorizons/ExampleMod1.7.10', 'tag', '0.1.5') + //devLocal '.' // Use this when testing config updates locally +} From 71c0304f09e41b494130f73184c7685ca4b48e7f Mon Sep 17 00:00:00 2001 From: Raven Szewczyk Date: Wed, 24 Aug 2022 17:10:04 +0100 Subject: [PATCH 03/11] Switch GuiCraft{Amount,Confirm} to the AE2 versions --- .../client/gui/GuiCraftAmount.java | 151 +----- .../client/gui/GuiCraftConfirm.java | 501 +----------------- .../common/WCTGuiHandler.java | 60 ++- .../container/ContainerCraftAmount.java | 66 +-- .../container/ContainerCraftConfirm.java | 413 +-------------- .../core/sync/WCTPacketHandlerBase.java | 8 +- .../core/sync/packets/PacketCraftRequest.java | 6 +- .../sync/packets/PacketInventoryAction.java | 2 +- .../core/sync/packets/PacketSetJobBytes.java | 32 -- .../sync/packets/PacketUpdateCPUInfo.java | 37 -- .../core/sync/packets/PacketValueConfig.java | 7 - 11 files changed, 97 insertions(+), 1186 deletions(-) delete mode 100644 src/main/java/net/p455w0rd/wirelesscraftingterminal/core/sync/packets/PacketSetJobBytes.java delete mode 100644 src/main/java/net/p455w0rd/wirelesscraftingterminal/core/sync/packets/PacketUpdateCPUInfo.java diff --git a/src/main/java/net/p455w0rd/wirelesscraftingterminal/client/gui/GuiCraftAmount.java b/src/main/java/net/p455w0rd/wirelesscraftingterminal/client/gui/GuiCraftAmount.java index ef5064c..0681ecc 100644 --- a/src/main/java/net/p455w0rd/wirelesscraftingterminal/client/gui/GuiCraftAmount.java +++ b/src/main/java/net/p455w0rd/wirelesscraftingterminal/client/gui/GuiCraftAmount.java @@ -4,47 +4,29 @@ import appeng.api.AEApi; import appeng.api.definitions.IDefinitions; import appeng.api.definitions.IParts; import appeng.api.storage.ITerminalHost; -import appeng.core.AEConfig; -import appeng.core.localization.GuiText; +import appeng.container.implementations.ContainerCraftAmount; import appeng.helpers.Reflected; -import appeng.util.calculators.ArithHelper; -import appeng.util.calculators.Calculator; import net.minecraft.client.gui.GuiButton; -import net.minecraft.client.gui.GuiTextField; import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.item.ItemStack; import net.p455w0rd.wirelesscraftingterminal.client.gui.widgets.GuiTabButton; -import net.p455w0rd.wirelesscraftingterminal.common.container.ContainerCraftAmount; import net.p455w0rd.wirelesscraftingterminal.core.sync.network.NetworkHandler; -import net.p455w0rd.wirelesscraftingterminal.core.sync.packets.PacketCraftRequest; import net.p455w0rd.wirelesscraftingterminal.core.sync.packets.PacketSwitchGuis; import net.p455w0rd.wirelesscraftingterminal.helpers.WirelessTerminalGuiObject; import net.p455w0rd.wirelesscraftingterminal.items.ItemEnum; import net.p455w0rd.wirelesscraftingterminal.items.ItemWirelessCraftingTerminal; import net.p455w0rd.wirelesscraftingterminal.reference.Reference; -public class GuiCraftAmount extends WCTBaseGui { - private GuiTextField amountToCraft; +public class GuiCraftAmount extends appeng.client.gui.implementations.GuiCraftAmount { private GuiTabButton originalGuiBtn; - private GuiButton next; - - private GuiButton plus1; - private GuiButton plus10; - private GuiButton plus100; - private GuiButton plus1000; - private GuiButton minus1; - private GuiButton minus10; - private GuiButton minus100; - private GuiButton minus1000; - private ItemStack myIcon; private int originalGui; @Reflected public GuiCraftAmount(final InventoryPlayer inventoryPlayer, final ITerminalHost te) { - super(new ContainerCraftAmount(inventoryPlayer, te)); + super(inventoryPlayer, te); ItemStack is = new ItemStack(ItemEnum.WIRELESS_CRAFTING_TERMINAL.getItem()); ((ItemWirelessCraftingTerminal) is.getItem()).injectAEPower(is, 6400001); myIcon = is; @@ -55,23 +37,6 @@ public class GuiCraftAmount extends WCTBaseGui { public void initGui() { super.initGui(); - final int a = AEConfig.instance.craftItemsByStackAmounts(0); - final int b = AEConfig.instance.craftItemsByStackAmounts(1); - final int c = AEConfig.instance.craftItemsByStackAmounts(2); - final int d = AEConfig.instance.craftItemsByStackAmounts(3); - - this.buttonList.add(this.plus1 = new GuiButton(0, this.guiLeft + 20, this.guiTop + 26, 22, 20, "+" + a)); - this.buttonList.add(this.plus10 = new GuiButton(0, this.guiLeft + 48, this.guiTop + 26, 28, 20, "+" + b)); - this.buttonList.add(this.plus100 = new GuiButton(0, this.guiLeft + 82, this.guiTop + 26, 32, 20, "+" + c)); - this.buttonList.add(this.plus1000 = new GuiButton(0, this.guiLeft + 120, this.guiTop + 26, 38, 20, "+" + d)); - - this.buttonList.add(this.minus1 = new GuiButton(0, this.guiLeft + 20, this.guiTop + 75, 22, 20, "-" + a)); - this.buttonList.add(this.minus10 = new GuiButton(0, this.guiLeft + 48, this.guiTop + 75, 28, 20, "-" + b)); - this.buttonList.add(this.minus100 = new GuiButton(0, this.guiLeft + 82, this.guiTop + 75, 32, 20, "-" + c)); - this.buttonList.add(this.minus1000 = new GuiButton(0, this.guiLeft + 120, this.guiTop + 75, 38, 20, "-" + d)); - - this.buttonList.add( - this.next = new GuiButton(0, this.guiLeft + 128, this.guiTop + 51, 38, 20, GuiText.Next.getLocal())); final Object target = ((ContainerCraftAmount) this.inventorySlots).getTarget(); final IDefinitions definitions = AEApi.instance().definitions(); final IParts parts = definitions.parts(); @@ -85,120 +50,14 @@ public class GuiCraftAmount extends WCTBaseGui { this.originalGuiBtn = new GuiTabButton( this.guiLeft + 154, this.guiTop - 4, myIcon, myIcon.getDisplayName(), itemRender)); } - - this.amountToCraft = new GuiTextField( - this.fontRendererObj, this.guiLeft + 62, this.guiTop + 57, 59, this.fontRendererObj.FONT_HEIGHT); - this.amountToCraft.setEnableBackgroundDrawing(false); - this.amountToCraft.setMaxStringLength(16); - this.amountToCraft.setTextColor(0xFFFFFF); - this.amountToCraft.setVisible(true); - this.amountToCraft.setFocused(true); - this.amountToCraft.setText("1"); - this.amountToCraft.setSelectionPos(0); - } - - @Override - public void drawFG(final int offsetX, final int offsetY, final int mouseX, final int mouseY) { - this.fontRendererObj.drawString(GuiText.SelectAmount.getLocal(), 8, 6, 4210752); - } - - @Override - public void drawBG(final int offsetX, final int offsetY, final int mouseX, final int mouseY) { - this.next.displayString = isShiftKeyDown() ? GuiText.Start.getLocal() : GuiText.Next.getLocal(); - - this.bindTexture("appliedenergistics2", "guis/craftAmt.png"); - this.drawTexturedModalRect(offsetX, offsetY, 0, 0, this.xSize, this.ySize); - - try { - String out = this.amountToCraft.getText(); - - double resultD = Calculator.conversion(out); - - int resultI = roundDouble(resultD); - - this.next.enabled = resultI > 0; - } catch (final NumberFormatException e) { - this.next.enabled = false; - } - - this.amountToCraft.drawTextBox(); - } - - @Override - protected void keyTyped(final char character, final int key) { - if (!this.checkHotbarKeys(key)) { - if (key == 28) { - this.actionPerformed(this.next); - } - this.amountToCraft.textboxKeyTyped(character, key); - super.keyTyped(character, key); - } } @Override protected void actionPerformed(final GuiButton btn) { super.actionPerformed(btn); - try { - - if (btn == this.originalGuiBtn) { - NetworkHandler.instance.sendToServer(new PacketSwitchGuis(this.originalGui)); - } - - if (btn == this.next && btn.enabled) { - double resultD = Calculator.conversion(this.amountToCraft.getText()); - - int resultI = roundDouble(resultD); - - NetworkHandler.instance.sendToServer(new PacketCraftRequest(resultI, isShiftKeyDown())); - } - } catch (final NumberFormatException e) { - // nope.. - this.amountToCraft.setText("1"); - } - - final boolean isPlus = btn == this.plus1 || btn == this.plus10 || btn == this.plus100 || btn == this.plus1000; - final boolean isMinus = - btn == this.minus1 || btn == this.minus10 || btn == this.minus100 || btn == this.minus1000; - - if (isPlus || isMinus) { - this.addQty(this.getQty(btn)); - } - } - - private void addQty(final int i) { - try { - String out = this.amountToCraft.getText(); - - double resultD = Calculator.conversion(out); - - int resultI = roundDouble(resultD); - - if (resultI == 1 && i > 1) { - resultI = 0; - } - - resultI += i; - if (resultI < 1) { - resultI = 1; - } - - out = Integer.toString(resultI); - this.amountToCraft.setText(out); - } catch (final NumberFormatException e) { - // :P - } - } - - protected String getBackground() { - return "guis/craftAmt.png"; - } - - private int roundDouble(double num) { - if (num <= 0 || Double.isNaN(num)) { - return 0; - } else { - return (int) ArithHelper.round(num, 0); + if (btn == this.originalGuiBtn) { + NetworkHandler.instance.sendToServer(new PacketSwitchGuis(this.originalGui)); } } } diff --git a/src/main/java/net/p455w0rd/wirelesscraftingterminal/client/gui/GuiCraftConfirm.java b/src/main/java/net/p455w0rd/wirelesscraftingterminal/client/gui/GuiCraftConfirm.java index 4beacaa..bf91443 100644 --- a/src/main/java/net/p455w0rd/wirelesscraftingterminal/client/gui/GuiCraftConfirm.java +++ b/src/main/java/net/p455w0rd/wirelesscraftingterminal/client/gui/GuiCraftConfirm.java @@ -1,514 +1,21 @@ package net.p455w0rd.wirelesscraftingterminal.client.gui; -import appeng.api.AEApi; import appeng.api.storage.ITerminalHost; -import appeng.api.storage.data.IAEItemStack; -import appeng.api.storage.data.IItemList; import appeng.core.localization.GuiText; -import appeng.util.Platform; -import com.google.common.base.Joiner; -import java.io.IOException; -import java.text.NumberFormat; -import java.util.ArrayList; -import java.util.Iterator; -import java.util.LinkedList; -import java.util.List; import net.minecraft.client.gui.GuiButton; import net.minecraft.entity.player.InventoryPlayer; -import net.minecraft.item.ItemStack; -import net.p455w0rd.wirelesscraftingterminal.client.gui.widgets.GuiScrollbar; -import net.p455w0rd.wirelesscraftingterminal.common.container.ContainerCraftConfirm; -import net.p455w0rd.wirelesscraftingterminal.common.utils.WCTLog; import net.p455w0rd.wirelesscraftingterminal.core.sync.network.NetworkHandler; import net.p455w0rd.wirelesscraftingterminal.core.sync.packets.PacketSwitchGuis; -import net.p455w0rd.wirelesscraftingterminal.core.sync.packets.PacketValueConfig; import net.p455w0rd.wirelesscraftingterminal.helpers.WirelessTerminalGuiObject; import net.p455w0rd.wirelesscraftingterminal.reference.Reference; -import org.lwjgl.input.Mouse; -import org.lwjgl.opengl.GL11; - -public class GuiCraftConfirm extends WCTBaseGui { - - private final ContainerCraftConfirm ccc; - - private final int rows = 5; - - private final IItemList storage = AEApi.instance().storage().createItemList(); - private final IItemList pending = AEApi.instance().storage().createItemList(); - private final IItemList missing = AEApi.instance().storage().createItemList(); - - private final List visual = new ArrayList(); - - private int OriginalGui = 0; - private GuiButton cancel; - private GuiButton start; - private GuiButton selectCPU; - private int tooltip = -1; - InventoryPlayer inventoryPlayer; - private static int jobBytes; - private static int currCPUAvailBytes; - private static int currCPUCoCPUs; +public class GuiCraftConfirm extends appeng.client.gui.implementations.GuiCraftConfirm { public GuiCraftConfirm(final InventoryPlayer inventoryPlayer, final ITerminalHost te) { - super(new ContainerCraftConfirm(inventoryPlayer, te)); - this.xSize = 238; - this.ySize = 206; - - final GuiScrollbar scrollbar = new GuiScrollbar(); - this.setScrollBar(scrollbar); - - this.ccc = (ContainerCraftConfirm) this.inventorySlots; - this.inventoryPlayer = inventoryPlayer; - - if (te instanceof WirelessTerminalGuiObject) { - this.OriginalGui = Reference.GUI_WCT; - } - } - - boolean isAutoStart() { - return ((ContainerCraftConfirm) this.inventorySlots).isAutoStart(); - } - - @SuppressWarnings("unchecked") - @Override - public void initGui() { - super.initGui(); - - this.start = - new GuiButton(0, this.guiLeft + 162, this.guiTop + this.ySize - 25, 50, 20, GuiText.Start.getLocal()); - this.start.enabled = false; - this.buttonList.add(this.start); - - this.selectCPU = new GuiButton( - 0, - this.guiLeft + (219 - 180) / 2, - this.guiTop + this.ySize - 68, - 180, - 20, - GuiText.CraftingCPU.getLocal() + ": " + GuiText.Automatic); - this.selectCPU.enabled = false; - this.buttonList.add(this.selectCPU); - - if (this.OriginalGui > 0) { - this.cancel = new GuiButton( - 0, this.guiLeft + 6, this.guiTop + this.ySize - 25, 50, 20, GuiText.Cancel.getLocal()); - } - - this.buttonList.add(this.cancel); + super(inventoryPlayer, te); } @Override - public void drawScreen(final int mouseX, final int mouseY, final float btn) { - this.updateCPUButtonText(); - - this.start.enabled = !(this.ccc.hasNoCPU() || this.isSimulation()); - this.selectCPU.enabled = !this.isSimulation(); - - final int gx = (this.width - this.xSize) / 2; - final int gy = (this.height - this.ySize) / 2; - - this.tooltip = -1; - - final int offY = 23; - int y = 0; - int x = 0; - for (int z = 0; z <= 4 * 5; z++) { - final int minX = gx + 9 + x * 67; - final int minY = gy + 22 + y * offY; - - if (minX < mouseX && minX + 67 > mouseX) { - if (minY < mouseY && minY + offY - 2 > mouseY) { - this.tooltip = z; - break; - } - } - - x++; - - if (x > 2) { - y++; - x = 0; - } - } - - super.drawScreen(mouseX, mouseY, btn); - } - - private void updateCPUButtonText() { - String btnTextText = GuiText.CraftingCPU.getLocal() + ": " + GuiText.Automatic.getLocal(); - if (this.ccc.getSelectedCpu() >= 0) // && status.selectedCpu < status.cpus.size() ) - { - if (this.ccc.getName().length() > 0) { - final String name = this.ccc - .getName() - .substring(0, Math.min(20, this.ccc.getName().length())); - btnTextText = GuiText.CraftingCPU.getLocal() + ": " + name; - } else { - btnTextText = GuiText.CraftingCPU.getLocal() + ": #" + this.ccc.getSelectedCpu(); - } - } - - if (this.ccc.hasNoCPU()) { - btnTextText = GuiText.NoCraftingCPUs.getLocal(); - } - - this.selectCPU.displayString = btnTextText; - } - - private boolean isSimulation() { - return ((ContainerCraftConfirm) this.inventorySlots).isSimulation(); - } - - public int getJobBytes() { - return GuiCraftConfirm.jobBytes; - } - - public static void setJobBytes(int numBytes) { - jobBytes = numBytes; - } - - public int getCurrentCPUAvailBytes() { - return GuiCraftConfirm.currCPUAvailBytes; - } - - public static void setCurrentCPUAvailBytes(int numBytes) { - currCPUAvailBytes = numBytes; - } - - public int getCurrentCPUCoCPUs() { - return GuiCraftConfirm.currCPUCoCPUs; - } - - public static void setCurrentCPUCoCPUs(int coCPUs) { - currCPUCoCPUs = coCPUs; - } - - @Override - public void drawFG(final int offsetX, final int offsetY, final int mouseX, final int mouseY) { - int bytesUsed = this.getJobBytes(); - int availBytes = this.getCurrentCPUAvailBytes(); - int availCoCPUs = this.getCurrentCPUCoCPUs(); - String byteUsed = NumberFormat.getInstance().format(bytesUsed); - - final String Add = - bytesUsed > 0 ? (byteUsed + ' ' + GuiText.BytesUsed.getLocal()) : GuiText.CalculatingWait.getLocal(); - this.fontRendererObj.drawString(GuiText.CraftingPlan.getLocal() + " -- " + Add, 8, 7, 4210752); - - String dsp = null; - - if (this.isSimulation()) { - dsp = GuiText.Simulation.getLocal(); - } else { - dsp = availBytes > 0 - ? (GuiText.Bytes.getLocal() + ": " + availBytes + " : " + GuiText.CoProcessors.getLocal() + ": " - + availCoCPUs) - : GuiText.Bytes.getLocal() + ": N/A : " + GuiText.CoProcessors.getLocal() + ": N/A"; - } - - final int offset = (219 - this.fontRendererObj.getStringWidth(dsp)) / 2; - this.fontRendererObj.drawString(dsp, offset, 165, 4210752); - - final int sectionLength = 67; - - int x = 0; - int y = 0; - final int xo = 9; - final int yo = 22; - final int viewStart = this.getScrollBar().getCurrentScroll() * 3; - final int viewEnd = viewStart + 3 * this.rows; - - String dspToolTip = ""; - final List lineList = new LinkedList(); - int toolPosX = 0; - int toolPosY = 0; - - final int offY = 23; - - for (int z = viewStart; z < Math.min(viewEnd, this.visual.size()); z++) { - final IAEItemStack refStack = this.visual.get(z); // repo.getReferenceItem( z ); - if (refStack != null) { - GL11.glPushMatrix(); - GL11.glScaled(0.5, 0.5, 0.5); - - final IAEItemStack stored = this.storage.findPrecise(refStack); - final IAEItemStack pendingStack = this.pending.findPrecise(refStack); - final IAEItemStack missingStack = this.missing.findPrecise(refStack); - - int lines = 0; - - if (stored != null && stored.getStackSize() > 0) { - lines++; - } - if (pendingStack != null && pendingStack.getStackSize() > 0) { - lines++; - } - if (pendingStack != null && pendingStack.getStackSize() > 0) { - lines++; - } - - final int negY = ((lines - 1) * 5) / 2; - int downY = 0; - - if (stored != null && stored.getStackSize() > 0) { - String str = Long.toString(stored.getStackSize()); - if (stored.getStackSize() >= 10000) { - str = Long.toString(stored.getStackSize() / 1000) + 'k'; - } - if (stored.getStackSize() >= 10000000) { - str = Long.toString(stored.getStackSize() / 1000000) + 'm'; - } - - str = GuiText.FromStorage.getLocal() + ": " + str; - final int w = 4 + this.fontRendererObj.getStringWidth(str); - this.fontRendererObj.drawString( - str, - (int) ((x * (1 + sectionLength) + xo + sectionLength - 19 - (w * 0.5)) * 2), - (y * offY + yo + 6 - negY + downY) * 2, - 4210752); - - if (this.tooltip == z - viewStart) { - lineList.add(GuiText.FromStorage.getLocal() + ": " + Long.toString(stored.getStackSize())); - } - - downY += 5; - } - - boolean red = false; - if (missingStack != null && missingStack.getStackSize() > 0) { - String str = Long.toString(missingStack.getStackSize()); - if (missingStack.getStackSize() >= 10000) { - str = Long.toString(missingStack.getStackSize() / 1000) + 'k'; - } - if (missingStack.getStackSize() >= 10000000) { - str = Long.toString(missingStack.getStackSize() / 1000000) + 'm'; - } - - str = GuiText.Missing.getLocal() + ": " + str; - final int w = 4 + this.fontRendererObj.getStringWidth(str); - this.fontRendererObj.drawString( - str, - (int) ((x * (1 + sectionLength) + xo + sectionLength - 19 - (w * 0.5)) * 2), - (y * offY + yo + 6 - negY + downY) * 2, - 4210752); - - if (this.tooltip == z - viewStart) { - lineList.add(GuiText.Missing.getLocal() + ": " + Long.toString(missingStack.getStackSize())); - } - - red = true; - downY += 5; - } - - if (pendingStack != null && pendingStack.getStackSize() > 0) { - String str = Long.toString(pendingStack.getStackSize()); - if (pendingStack.getStackSize() >= 10000) { - str = Long.toString(pendingStack.getStackSize() / 1000) + 'k'; - } - if (pendingStack.getStackSize() >= 10000000) { - str = Long.toString(pendingStack.getStackSize() / 1000000) + 'm'; - } - - str = GuiText.ToCraft.getLocal() + ": " + str; - final int w = 4 + this.fontRendererObj.getStringWidth(str); - this.fontRendererObj.drawString( - str, - (int) ((x * (1 + sectionLength) + xo + sectionLength - 19 - (w * 0.5)) * 2), - (y * offY + yo + 6 - negY + downY) * 2, - 4210752); - - if (this.tooltip == z - viewStart) { - lineList.add(GuiText.ToCraft.getLocal() + ": " + Long.toString(pendingStack.getStackSize())); - } - } - - GL11.glPopMatrix(); - final int posX = x * (1 + sectionLength) + xo + sectionLength - 19; - final int posY = y * offY + yo; - - final ItemStack is = refStack.copy().getItemStack(); - - if (this.tooltip == z - viewStart) { - dspToolTip = Platform.getItemDisplayName(is); - - if (lineList.size() > 0) { - addItemTooltip(is, lineList); - dspToolTip = dspToolTip + '\n' + Joiner.on("\n").join(lineList); - } - - toolPosX = x * (1 + sectionLength) + xo + sectionLength - 8; - toolPosY = y * offY + yo; - } - - this.drawItem(posX, posY, is); - - if (red) { - final int startX = x * (1 + sectionLength) + xo; - final int startY = posY - 4; - drawRect(startX, startY, startX + sectionLength, startY + offY, 0x1AFF0000); - } - - x++; - - if (x > 2) { - y++; - x = 0; - } - } - } - - if (this.tooltip >= 0 && dspToolTip.length() > 0) { - this.drawTooltip(toolPosX, toolPosY + 10, 0, dspToolTip); - } - } - - @Override - public void drawBG(final int offsetX, final int offsetY, final int mouseX, final int mouseY) { - this.setScrollBar(); - this.bindTexture("appliedenergistics2", "guis/craftingreport.png"); - this.drawTexturedModalRect(offsetX, offsetY, 0, 0, this.xSize, this.ySize); - } - - private void setScrollBar() { - final int size = this.visual.size(); - - this.getScrollBar().setTop(19).setLeft(218).setHeight(114); - this.getScrollBar().setRange(0, (size + 2) / 3 - this.rows, 1); - } - - public void postUpdate(final List list, final byte ref) { - switch (ref) { - case 0: - for (final IAEItemStack l : list) { - this.handleInput(this.storage, l); - } - break; - - case 1: - for (final IAEItemStack l : list) { - this.handleInput(this.pending, l); - } - break; - - case 2: - for (final IAEItemStack l : list) { - this.handleInput(this.missing, l); - } - break; - } - - for (final IAEItemStack l : list) { - final long amt = this.getTotal(l); - - if (amt <= 0) { - this.deleteVisualStack(l); - } else { - final IAEItemStack is = this.findVisualStack(l); - is.setStackSize(amt); - } - } - - this.setScrollBar(); - } - - private void handleInput(final IItemList s, final IAEItemStack l) { - IAEItemStack a = s.findPrecise(l); - - if (l.getStackSize() <= 0) { - if (a != null) { - a.reset(); - } - } else { - if (a == null) { - s.add(l.copy()); - a = s.findPrecise(l); - } - - if (a != null) { - a.setStackSize(l.getStackSize()); - } - } - } - - private long getTotal(final IAEItemStack is) { - final IAEItemStack a = this.storage.findPrecise(is); - final IAEItemStack c = this.pending.findPrecise(is); - final IAEItemStack m = this.missing.findPrecise(is); - - long total = 0; - - if (a != null) { - total += a.getStackSize(); - } - - if (c != null) { - total += c.getStackSize(); - } - - if (m != null) { - total += m.getStackSize(); - } - - return total; - } - - private void deleteVisualStack(final IAEItemStack l) { - final Iterator i = this.visual.iterator(); - while (i.hasNext()) { - final IAEItemStack o = i.next(); - if (o.equals(l)) { - i.remove(); - return; - } - } - } - - private IAEItemStack findVisualStack(final IAEItemStack l) { - for (final IAEItemStack o : this.visual) { - if (o.equals(l)) { - return o; - } - } - - final IAEItemStack stack = l.copy(); - this.visual.add(stack); - return stack; - } - - @Override - protected void keyTyped(final char character, final int key) { - if (!this.checkHotbarKeys(key)) { - if (key == 28) { - this.actionPerformed(this.start); - } - super.keyTyped(character, key); - } - } - - @Override - protected void actionPerformed(final GuiButton btn) { - super.actionPerformed(btn); - - final boolean backwards = Mouse.isButtonDown(1); - - if (btn == this.selectCPU) { - try { - NetworkHandler.instance.sendToServer( - new PacketValueConfig("Terminal.Cpu", backwards ? "Prev" : "Next")); - } catch (final IOException e) { - WCTLog.debug(e.getMessage()); - } - } - - if (btn == this.cancel) { - NetworkHandler.instance.sendToServer(new PacketSwitchGuis(this.OriginalGui)); - } - - if (btn == this.start) { - try { - NetworkHandler.instance.sendToServer(new PacketValueConfig("Terminal.Start", "Start")); - } catch (final Throwable e) { - WCTLog.debug(e.getMessage()); - } - } + public void switchToOriginalGUI() { + NetworkHandler.instance.sendToServer(new PacketSwitchGuis(Reference.GUI_WCT)); } } diff --git a/src/main/java/net/p455w0rd/wirelesscraftingterminal/common/WCTGuiHandler.java b/src/main/java/net/p455w0rd/wirelesscraftingterminal/common/WCTGuiHandler.java index dd67e72..822e2ca 100644 --- a/src/main/java/net/p455w0rd/wirelesscraftingterminal/common/WCTGuiHandler.java +++ b/src/main/java/net/p455w0rd/wirelesscraftingterminal/common/WCTGuiHandler.java @@ -2,10 +2,13 @@ package net.p455w0rd.wirelesscraftingterminal.common; import appeng.api.AEApi; import appeng.api.implementations.guiobjects.IPortableCell; +import appeng.container.AEBaseContainer; +import appeng.container.ContainerOpenContext; import appeng.container.implementations.ContainerCraftingStatus; import cpw.mods.fml.common.network.IGuiHandler; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.world.World; +import net.minecraftforge.common.util.ForgeDirection; import net.p455w0rd.wirelesscraftingterminal.api.IWirelessCraftingTermHandler; import net.p455w0rd.wirelesscraftingterminal.client.gui.GuiCraftAmount; import net.p455w0rd.wirelesscraftingterminal.client.gui.GuiCraftConfirm; @@ -37,19 +40,47 @@ public class WCTGuiHandler implements IGuiHandler { final IPortableCell terminal = obj; if (guiId == Reference.GUI_WCT) { - return new ContainerWirelessCraftingTerminal(player, player.inventory); + return updateGui( + new ContainerWirelessCraftingTerminal(player, player.inventory), + world, + x, + y, + z, + ForgeDirection.UNKNOWN, + obj); } if (guiId == Reference.GUI_CRAFTING_STATUS) { - return new ContainerCraftingStatus(player.inventory, terminal); + return updateGui( + new ContainerCraftingStatus(player.inventory, terminal), + world, + x, + y, + z, + ForgeDirection.UNKNOWN, + obj); } if (guiId == Reference.GUI_CRAFT_AMOUNT) { - return new ContainerCraftAmount(player.inventory, terminal); + return updateGui( + new ContainerCraftAmount(player, terminal), + world, + x, + y, + z, + ForgeDirection.UNKNOWN, + obj); } if (guiId == Reference.GUI_CRAFT_CONFIRM) { - return new ContainerCraftConfirm(player.inventory, terminal); + return updateGui( + new ContainerCraftConfirm(player, terminal), + world, + x, + y, + z, + ForgeDirection.UNKNOWN, + obj); } } } @@ -101,4 +132,25 @@ public class WCTGuiHandler implements IGuiHandler { final int ID, final EntityPlayer player, final World world, final int x, final int y, final int z) { player.openGui(WirelessCraftingTerminal.INSTANCE, ID, world, x, y, z); } + + private Object updateGui( + final Object newContainer, + final World w, + final int x, + final int y, + final int z, + final ForgeDirection side, + final Object myItem) { + if (newContainer instanceof AEBaseContainer) { + final AEBaseContainer bc = (AEBaseContainer) newContainer; + bc.setOpenContext(new ContainerOpenContext(myItem)); + bc.getOpenContext().setWorld(w); + bc.getOpenContext().setX(x); + bc.getOpenContext().setY(y); + bc.getOpenContext().setZ(z); + bc.getOpenContext().setSide(side); + } + + return newContainer; + } } diff --git a/src/main/java/net/p455w0rd/wirelesscraftingterminal/common/container/ContainerCraftAmount.java b/src/main/java/net/p455w0rd/wirelesscraftingterminal/common/container/ContainerCraftAmount.java index 1e13294..de4ca3f 100644 --- a/src/main/java/net/p455w0rd/wirelesscraftingterminal/common/container/ContainerCraftAmount.java +++ b/src/main/java/net/p455w0rd/wirelesscraftingterminal/common/container/ContainerCraftAmount.java @@ -1,58 +1,24 @@ package net.p455w0rd.wirelesscraftingterminal.common.container; -import appeng.api.config.SecurityPermissions; -import appeng.api.networking.IGrid; -import appeng.api.networking.security.BaseActionSource; -import appeng.api.storage.ITerminalHost; -import appeng.api.storage.data.IAEItemStack; -import appeng.tile.inventory.AppEngInternalInventory; -import javax.annotation.Nonnull; -import net.minecraft.entity.player.InventoryPlayer; -import net.minecraft.inventory.Slot; -import net.minecraft.world.World; -import net.p455w0rd.wirelesscraftingterminal.api.networking.security.WCTIActionHost; -import net.p455w0rd.wirelesscraftingterminal.api.networking.security.WCTPlayerSource; -import net.p455w0rd.wirelesscraftingterminal.common.container.slot.SlotInaccessible; +import appeng.api.implementations.guiobjects.IPortableCell; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.EntityPlayerMP; +import net.minecraft.tileentity.TileEntity; +import net.p455w0rd.wirelesscraftingterminal.common.WCTGuiHandler; +import net.p455w0rd.wirelesscraftingterminal.core.sync.network.NetworkHandler; +import net.p455w0rd.wirelesscraftingterminal.core.sync.packets.PacketSwitchGuis; +import net.p455w0rd.wirelesscraftingterminal.reference.Reference; -public class ContainerCraftAmount extends WCTBaseContainer { - - private final Slot craftingItem; - private IAEItemStack itemToCreate; - - public ContainerCraftAmount(final InventoryPlayer ip, final ITerminalHost te) { - super(ip, te); - - this.craftingItem = new SlotInaccessible(new AppEngInternalInventory(null, 1), 0, 34, 53); - this.addSlotToContainer(this.getCraftingItem()); +public class ContainerCraftAmount extends appeng.container.implementations.ContainerCraftAmount { + public ContainerCraftAmount(EntityPlayer player, IPortableCell terminal) { + super(player.inventory, terminal); } @Override - public void detectAndSendChanges() { - super.detectAndSendChanges(); - this.verifyPermissions(SecurityPermissions.CRAFT, false); - } - - public IGrid getGrid() { - return this.obj2.getTargetGrid(); - } - - public World getWorld() { - return this.getPlayerInv().player.worldObj; - } - - public BaseActionSource getActionSrc() { - return new WCTPlayerSource(this.getPlayerInv().player, (WCTIActionHost) this.getTarget()); - } - - public Slot getCraftingItem() { - return this.craftingItem; - } - - public IAEItemStack getItemToCraft() { - return this.itemToCreate; - } - - public void setItemToCraft(@Nonnull final IAEItemStack itemToCreate) { - this.itemToCreate = itemToCreate; + public void openConfirmationGUI(EntityPlayer player, TileEntity te) { + int x = (int) player.posX; + int y = (int) player.posY; + int z = (int) player.posZ; + WCTGuiHandler.launchGui(Reference.GUI_CRAFT_CONFIRM, player, player.worldObj, x, y, z); } } diff --git a/src/main/java/net/p455w0rd/wirelesscraftingterminal/common/container/ContainerCraftConfirm.java b/src/main/java/net/p455w0rd/wirelesscraftingterminal/common/container/ContainerCraftConfirm.java index 4c7dde1..63b0242 100644 --- a/src/main/java/net/p455w0rd/wirelesscraftingterminal/common/container/ContainerCraftConfirm.java +++ b/src/main/java/net/p455w0rd/wirelesscraftingterminal/common/container/ContainerCraftConfirm.java @@ -1,417 +1,26 @@ package net.p455w0rd.wirelesscraftingterminal.common.container; -import appeng.api.AEApi; -import appeng.api.config.Actionable; -import appeng.api.config.SecurityPermissions; -import appeng.api.networking.IGrid; -import appeng.api.networking.crafting.ICraftingCPU; -import appeng.api.networking.crafting.ICraftingGrid; -import appeng.api.networking.crafting.ICraftingJob; -import appeng.api.networking.crafting.ICraftingLink; -import appeng.api.networking.security.BaseActionSource; -import appeng.api.networking.storage.IStorageGrid; -import appeng.api.storage.IMEInventory; -import appeng.api.storage.ITerminalHost; -import appeng.api.storage.data.IAEItemStack; -import appeng.api.storage.data.IItemList; -import appeng.util.Platform; -import com.google.common.collect.ImmutableSet; -import java.io.IOException; -import java.util.ArrayList; -import java.util.Collections; -import java.util.concurrent.Future; -import javax.annotation.Nonnull; +import appeng.api.implementations.guiobjects.IPortableCell; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; -import net.minecraft.entity.player.InventoryPlayer; -import net.minecraft.inventory.ICrafting; -import net.minecraft.util.ChatComponentText; -import net.minecraft.world.World; -import net.p455w0rd.wirelesscraftingterminal.api.networking.security.WCTIActionHost; -import net.p455w0rd.wirelesscraftingterminal.api.networking.security.WCTPlayerSource; import net.p455w0rd.wirelesscraftingterminal.common.WCTGuiHandler; -import net.p455w0rd.wirelesscraftingterminal.common.container.guisync.GuiSync; -import net.p455w0rd.wirelesscraftingterminal.common.utils.WCTLog; import net.p455w0rd.wirelesscraftingterminal.core.sync.network.NetworkHandler; -import net.p455w0rd.wirelesscraftingterminal.core.sync.packets.PacketMEInventoryUpdate; -import net.p455w0rd.wirelesscraftingterminal.core.sync.packets.PacketSetJobBytes; import net.p455w0rd.wirelesscraftingterminal.core.sync.packets.PacketSwitchGuis; -import net.p455w0rd.wirelesscraftingterminal.core.sync.packets.PacketUpdateCPUInfo; -import net.p455w0rd.wirelesscraftingterminal.helpers.WirelessTerminalGuiObject; import net.p455w0rd.wirelesscraftingterminal.reference.Reference; -public class ContainerCraftConfirm extends WCTBaseContainer { +public class ContainerCraftConfirm extends appeng.container.implementations.ContainerCraftConfirm { + private final EntityPlayer player; - public final ArrayList cpus = new ArrayList(); - private Future job; - private ICraftingJob result; - - @GuiSync(0) - public long bytesUsed; - - @GuiSync(1) - public long cpuBytesAvail; - - @GuiSync(2) - public int cpuCoProcessors; - - @GuiSync(3) - public boolean autoStart = false; - - @GuiSync(4) - public boolean simulation = true; - - @GuiSync(5) - public int selectedCpu = -1; - - @GuiSync(6) - public boolean noCPU = true; - - @GuiSync(7) - public String myName = ""; - - InventoryPlayer inventoryPlayer; - - public ContainerCraftConfirm(final InventoryPlayer ip, final ITerminalHost te) { - super(ip, te); - inventoryPlayer = ip; - } - - public void cycleCpu(final boolean next) { - if (next) { - this.setSelectedCpu(this.getSelectedCpu() + 1); - } else { - this.setSelectedCpu(this.getSelectedCpu() - 1); - } - - if (this.getSelectedCpu() < -1) { - this.setSelectedCpu(this.cpus.size() - 1); - } else if (this.getSelectedCpu() >= this.cpus.size()) { - this.setSelectedCpu(-1); - } - - if (this.getSelectedCpu() == -1) { - this.setCpuAvailableBytes(0); - this.setCpuCoProcessors(0); - this.setName(""); - try { - NetworkHandler.instance.sendTo( - new PacketUpdateCPUInfo(0, 0), (EntityPlayerMP) this.getPlayerInv().player); - } catch (IOException e) { - // - } - } else { - this.setName(this.cpus.get(this.getSelectedCpu()).getName()); - this.setCpuAvailableBytes(this.cpus.get(this.getSelectedCpu()).getSize()); - this.setCpuCoProcessors(this.cpus.get(this.getSelectedCpu()).getProcessors()); - - try { - NetworkHandler.instance.sendTo( - new PacketUpdateCPUInfo((int) this.getCpuAvailableBytes(), (int) this.getCpuCoProcessors()), - (EntityPlayerMP) this.getPlayerInv().player); - } catch (IOException e) { - // - } - } + public ContainerCraftConfirm(EntityPlayer player, IPortableCell terminal) { + super(player.inventory, terminal); + this.player = player; } @Override - public void detectAndSendChanges() { - if (Platform.isClient()) { - return; - } - - final ICraftingGrid cc = this.getGrid().getCache(ICraftingGrid.class); - final ImmutableSet cpuSet = cc.getCpus(); - - int matches = 0; - boolean changed = false; - for (final ICraftingCPU c : cpuSet) { - boolean found = false; - for (final CraftingCPURecord ccr : this.cpus) { - if (ccr.getCpu() == c) { - found = true; - } - } - - final boolean matched = this.cpuMatches(c); - - if (matched) { - matches++; - } - - if (found == !matched) { - changed = true; - } - } - - if (changed || this.cpus.size() != matches) { - this.cpus.clear(); - for (final ICraftingCPU c : cpuSet) { - if (this.cpuMatches(c)) { - this.cpus.add(new CraftingCPURecord(c.getAvailableStorage(), c.getCoProcessors(), c)); - } - } - - this.sendCPUs(); - } - - this.setNoCPU(this.cpus.isEmpty()); - - super.detectAndSendChanges(); - - if (this.getJob() != null && this.getJob().isDone()) { - try { - this.result = this.getJob().get(); - - if (!this.result.isSimulation()) { - this.setSimulation(false); - if (this.isAutoStart()) { - this.startJob(); - return; - } - } else { - this.setSimulation(true); - } - - try { - final PacketMEInventoryUpdate a = new PacketMEInventoryUpdate((byte) 0); - final PacketMEInventoryUpdate b = new PacketMEInventoryUpdate((byte) 1); - final PacketMEInventoryUpdate c = - this.result.isSimulation() ? new PacketMEInventoryUpdate((byte) 2) : null; - - final IItemList plan = - AEApi.instance().storage().createItemList(); - this.result.populatePlan(plan); - - try { - NetworkHandler.instance.sendTo( - new PacketSetJobBytes((int) this.result.getByteTotal()), - (EntityPlayerMP) this.getPlayerInv().player); - } catch (IOException e) { - // - } - - this.setUsedBytes(this.result.getByteTotal()); - - for (final IAEItemStack out : plan) { - - IAEItemStack o = out.copy(); - o.reset(); - o.setStackSize(out.getStackSize()); - - final IAEItemStack p = out.copy(); - p.reset(); - p.setStackSize(out.getCountRequestable()); - - final IStorageGrid sg = this.getGrid().getCache(IStorageGrid.class); - final IMEInventory items = sg.getItemInventory(); - - IAEItemStack m = null; - if (c != null && this.result.isSimulation()) { - m = o.copy(); - o = items.extractItems(o, Actionable.SIMULATE, this.getActionSource()); - - if (o == null) { - o = m.copy(); - o.setStackSize(0); - } - - m.setStackSize(m.getStackSize() - o.getStackSize()); - } - - if (o.getStackSize() > 0) { - a.appendItem(o); - } - - if (p.getStackSize() > 0) { - b.appendItem(p); - } - - if (c != null && m != null && m.getStackSize() > 0) { - c.appendItem(m); - } - } - - for (final Object g : this.crafters) { - if (g instanceof EntityPlayer) { - NetworkHandler.instance.sendTo(a, (EntityPlayerMP) g); - NetworkHandler.instance.sendTo(b, (EntityPlayerMP) g); - if (c != null) { - NetworkHandler.instance.sendTo(c, (EntityPlayerMP) g); - } - } - } - } catch (final IOException e) { - // :P - } - } catch (final Throwable e) { - this.getPlayerInv().player.addChatMessage(new ChatComponentText("Error: " + e.toString())); - WCTLog.debug(e.getMessage()); - this.setValidContainer(false); - this.result = null; - } - - this.setJob(null); - } - this.verifyPermissions(SecurityPermissions.CRAFT, false); - } - - private IGrid getGrid() { - return this.obj2.getTargetGrid(); - } - - private boolean cpuMatches(final ICraftingCPU c) { - return c.getAvailableStorage() >= this.getUsedBytes() && !c.isBusy(); - } - - private void sendCPUs() { - Collections.sort(this.cpus); - - if (this.getSelectedCpu() >= this.cpus.size()) { - this.setSelectedCpu(-1); - this.setCpuAvailableBytes(0); - this.setCpuCoProcessors(0); - this.setName(""); - } else if (this.getSelectedCpu() != -1) { - this.setName(this.cpus.get(this.getSelectedCpu()).getName()); - this.setCpuAvailableBytes(this.cpus.get(this.getSelectedCpu()).getSize()); - this.setCpuCoProcessors(this.cpus.get(this.getSelectedCpu()).getProcessors()); - } - } - - public void startJob() { - int originalGui = 0; - - final WCTIActionHost ah = this.getActionHost(); - if (ah instanceof WirelessTerminalGuiObject) { - originalGui = Reference.GUI_WCT; - } - - if (this.result != null && !this.isSimulation()) { - final ICraftingGrid cc = this.getGrid().getCache(ICraftingGrid.class); - final ICraftingLink g = cc.submitJob( - this.result, - null, - this.getSelectedCpu() == -1 - ? null - : this.cpus.get(this.getSelectedCpu()).getCpu(), - true, - this.getActionSrc()); - this.setAutoStart(false); - if (g != null && originalGui > 0) // && this.getOpenContext() != null ) - { - NetworkHandler.instance.sendTo( - new PacketSwitchGuis(originalGui), (EntityPlayerMP) this.getInventoryPlayer().player); - - // final TileEntity te = this.getOpenContext().getTile(); - // Platform.openGUI( this.getInventoryPlayer().player, te, this.getOpenContext().getSide(), originalGui - // ); - EntityPlayerMP player = (EntityPlayerMP) this.getInventoryPlayer().player; - World world = player.worldObj; - int x = (int) player.posX; - int y = (int) player.posY; - int z = (int) player.posZ; - WCTGuiHandler.launchGui(originalGui, player, world, x, y, z); - } - } - } - - private BaseActionSource getActionSrc() { - return new WCTPlayerSource(this.getPlayerInv().player, (WCTIActionHost) this.getTarget()); - } - - @Override - public void removeCraftingFromCrafters(final ICrafting c) { - super.removeCraftingFromCrafters(c); - if (this.getJob() != null) { - this.getJob().cancel(true); - this.setJob(null); - } - } - - @Override - public void onContainerClosed(final EntityPlayer par1EntityPlayer) { - super.onContainerClosed(par1EntityPlayer); - if (this.getJob() != null) { - this.getJob().cancel(true); - this.setJob(null); - } - } - - public World getWorld() { - return this.getPlayerInv().player.worldObj; - } - - public boolean isAutoStart() { - return this.autoStart; - } - - public void setAutoStart(final boolean autoStart) { - this.autoStart = autoStart; - } - - public long getUsedBytes() { - return this.bytesUsed; - } - - private void setUsedBytes(final long bytesUsed) { - this.bytesUsed = bytesUsed; - } - - public long getCpuAvailableBytes() { - return this.cpuBytesAvail; - } - - private void setCpuAvailableBytes(final long cpuBytesAvail) { - this.cpuBytesAvail = cpuBytesAvail; - } - - public int getCpuCoProcessors() { - return this.cpuCoProcessors; - } - - private void setCpuCoProcessors(final int cpuCoProcessors) { - this.cpuCoProcessors = cpuCoProcessors; - } - - public int getSelectedCpu() { - return this.selectedCpu; - } - - private void setSelectedCpu(final int selectedCpu) { - this.selectedCpu = selectedCpu; - } - - public String getName() { - return this.myName; - } - - private void setName(@Nonnull final String myName) { - this.myName = myName; - } - - public boolean hasNoCPU() { - return this.noCPU; - } - - private void setNoCPU(final boolean noCPU) { - this.noCPU = noCPU; - } - - public boolean isSimulation() { - return this.simulation; - } - - private void setSimulation(final boolean simulation) { - this.simulation = simulation; - } - - public Future getJob() { - return this.job; - } - - public void setJob(final Future job) { - this.job = job; + public void switchToOriginalGUI() { + int x = (int) player.posX; + int y = (int) player.posY; + int z = (int) player.posZ; + WCTGuiHandler.launchGui(Reference.GUI_WCT, player, player.worldObj, x, y, z); } } diff --git a/src/main/java/net/p455w0rd/wirelesscraftingterminal/core/sync/WCTPacketHandlerBase.java b/src/main/java/net/p455w0rd/wirelesscraftingterminal/core/sync/WCTPacketHandlerBase.java index 2bff200..adbf1bc 100644 --- a/src/main/java/net/p455w0rd/wirelesscraftingterminal/core/sync/WCTPacketHandlerBase.java +++ b/src/main/java/net/p455w0rd/wirelesscraftingterminal/core/sync/WCTPacketHandlerBase.java @@ -15,11 +15,9 @@ import net.p455w0rd.wirelesscraftingterminal.core.sync.packets.PacketMagnetFilte import net.p455w0rd.wirelesscraftingterminal.core.sync.packets.PacketNEIRecipe; import net.p455w0rd.wirelesscraftingterminal.core.sync.packets.PacketOpenGui; import net.p455w0rd.wirelesscraftingterminal.core.sync.packets.PacketPartialItem; -import net.p455w0rd.wirelesscraftingterminal.core.sync.packets.PacketSetJobBytes; import net.p455w0rd.wirelesscraftingterminal.core.sync.packets.PacketSetMagnet; import net.p455w0rd.wirelesscraftingterminal.core.sync.packets.PacketSwapSlots; import net.p455w0rd.wirelesscraftingterminal.core.sync.packets.PacketSwitchGuis; -import net.p455w0rd.wirelesscraftingterminal.core.sync.packets.PacketUpdateCPUInfo; import net.p455w0rd.wirelesscraftingterminal.core.sync.packets.PacketValueConfig; public class WCTPacketHandlerBase { @@ -51,11 +49,7 @@ public class WCTPacketHandlerBase { PACKET_EMPTY_TRASH(PacketEmptyTrash.class), - PACKET_SYNC_CONFIGS(PacketConfigSync.class), - - PACKET_SET_JOB(PacketSetJobBytes.class), - - PACKET_UPDATECPUINFO(PacketUpdateCPUInfo.class); + PACKET_SYNC_CONFIGS(PacketConfigSync.class); private final Class packetClass; private final Constructor packetConstructor; diff --git a/src/main/java/net/p455w0rd/wirelesscraftingterminal/core/sync/packets/PacketCraftRequest.java b/src/main/java/net/p455w0rd/wirelesscraftingterminal/core/sync/packets/PacketCraftRequest.java index 6cf16be..1669f34 100644 --- a/src/main/java/net/p455w0rd/wirelesscraftingterminal/core/sync/packets/PacketCraftRequest.java +++ b/src/main/java/net/p455w0rd/wirelesscraftingterminal/core/sync/packets/PacketCraftRequest.java @@ -4,13 +4,13 @@ import appeng.api.networking.IGrid; import appeng.api.networking.IGridHost; import appeng.api.networking.crafting.ICraftingGrid; import appeng.api.networking.crafting.ICraftingJob; +import appeng.container.implementations.ContainerCraftAmount; +import appeng.container.implementations.ContainerCraftConfirm; import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; import java.util.concurrent.Future; import net.minecraft.entity.player.EntityPlayer; import net.p455w0rd.wirelesscraftingterminal.common.WCTGuiHandler; -import net.p455w0rd.wirelesscraftingterminal.common.container.ContainerCraftAmount; -import net.p455w0rd.wirelesscraftingterminal.common.container.ContainerCraftConfirm; import net.p455w0rd.wirelesscraftingterminal.core.sync.WCTPacket; import net.p455w0rd.wirelesscraftingterminal.core.sync.network.INetworkInfo; import net.p455w0rd.wirelesscraftingterminal.reference.Reference; @@ -44,7 +44,7 @@ public class PacketCraftRequest extends WCTPacket { final ContainerCraftAmount cca = (ContainerCraftAmount) player.openContainer; final Object target = cca.getTarget(); if (target instanceof IGridHost) { - final IGrid g = cca.obj2.getTargetGrid(); + final IGrid g = cca.getGrid(); if (g == null || cca.getItemToCraft() == null) { return; } diff --git a/src/main/java/net/p455w0rd/wirelesscraftingterminal/core/sync/packets/PacketInventoryAction.java b/src/main/java/net/p455w0rd/wirelesscraftingterminal/core/sync/packets/PacketInventoryAction.java index 1a645ba..ec013ff 100644 --- a/src/main/java/net/p455w0rd/wirelesscraftingterminal/core/sync/packets/PacketInventoryAction.java +++ b/src/main/java/net/p455w0rd/wirelesscraftingterminal/core/sync/packets/PacketInventoryAction.java @@ -2,6 +2,7 @@ package net.p455w0rd.wirelesscraftingterminal.core.sync.packets; import appeng.api.storage.data.IAEItemStack; import appeng.client.ClientHelper; +import appeng.container.implementations.ContainerCraftAmount; import appeng.helpers.InventoryAction; import appeng.util.Platform; import appeng.util.item.AEItemStack; @@ -12,7 +13,6 @@ import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.inventory.Container; import net.p455w0rd.wirelesscraftingterminal.common.WCTGuiHandler; -import net.p455w0rd.wirelesscraftingterminal.common.container.ContainerCraftAmount; import net.p455w0rd.wirelesscraftingterminal.common.container.ContainerOpenContext; import net.p455w0rd.wirelesscraftingterminal.common.container.ContainerWirelessCraftingTerminal; import net.p455w0rd.wirelesscraftingterminal.common.container.WCTBaseContainer; diff --git a/src/main/java/net/p455w0rd/wirelesscraftingterminal/core/sync/packets/PacketSetJobBytes.java b/src/main/java/net/p455w0rd/wirelesscraftingterminal/core/sync/packets/PacketSetJobBytes.java deleted file mode 100644 index ea05c27..0000000 --- a/src/main/java/net/p455w0rd/wirelesscraftingterminal/core/sync/packets/PacketSetJobBytes.java +++ /dev/null @@ -1,32 +0,0 @@ -package net.p455w0rd.wirelesscraftingterminal.core.sync.packets; - -import io.netty.buffer.ByteBuf; -import io.netty.buffer.Unpooled; -import java.io.IOException; -import net.minecraft.entity.player.EntityPlayer; -import net.p455w0rd.wirelesscraftingterminal.client.gui.GuiCraftConfirm; -import net.p455w0rd.wirelesscraftingterminal.core.sync.WCTPacket; -import net.p455w0rd.wirelesscraftingterminal.core.sync.network.INetworkInfo; - -public class PacketSetJobBytes extends WCTPacket { - - private final int bytez; - - // automatic. - public PacketSetJobBytes(final ByteBuf stream) throws IOException, ClassNotFoundException { - this.bytez = stream.readInt(); - } - - public PacketSetJobBytes(int numBytes) throws IOException { - this.bytez = numBytes; - final ByteBuf data = Unpooled.buffer(); - data.writeInt(this.getPacketID()); - data.writeInt(this.bytez); - this.configureWrite(data); - } - - @Override - public void clientPacketData(final INetworkInfo network, final WCTPacket packet, final EntityPlayer player) { - GuiCraftConfirm.setJobBytes(this.bytez); - } -} diff --git a/src/main/java/net/p455w0rd/wirelesscraftingterminal/core/sync/packets/PacketUpdateCPUInfo.java b/src/main/java/net/p455w0rd/wirelesscraftingterminal/core/sync/packets/PacketUpdateCPUInfo.java deleted file mode 100644 index 8fa480a..0000000 --- a/src/main/java/net/p455w0rd/wirelesscraftingterminal/core/sync/packets/PacketUpdateCPUInfo.java +++ /dev/null @@ -1,37 +0,0 @@ -package net.p455w0rd.wirelesscraftingterminal.core.sync.packets; - -import io.netty.buffer.ByteBuf; -import io.netty.buffer.Unpooled; -import java.io.IOException; -import net.minecraft.entity.player.EntityPlayer; -import net.p455w0rd.wirelesscraftingterminal.client.gui.GuiCraftConfirm; -import net.p455w0rd.wirelesscraftingterminal.core.sync.WCTPacket; -import net.p455w0rd.wirelesscraftingterminal.core.sync.network.INetworkInfo; - -public class PacketUpdateCPUInfo extends WCTPacket { - - private final int bytez; - private final int coCPUz; - - // automatic. - public PacketUpdateCPUInfo(final ByteBuf stream) throws IOException, ClassNotFoundException { - this.bytez = stream.readInt(); - this.coCPUz = stream.readInt(); - } - - public PacketUpdateCPUInfo(int numBytes, int numCoCPUs) throws IOException { - this.bytez = numBytes; - this.coCPUz = numCoCPUs; - final ByteBuf data = Unpooled.buffer(); - data.writeInt(this.getPacketID()); - data.writeInt(this.bytez); - data.writeInt(this.coCPUz); - this.configureWrite(data); - } - - @Override - public void clientPacketData(final INetworkInfo network, final WCTPacket packet, final EntityPlayer player) { - GuiCraftConfirm.setCurrentCPUAvailBytes(this.bytez); - GuiCraftConfirm.setCurrentCPUCoCPUs(this.coCPUz); - } -} diff --git a/src/main/java/net/p455w0rd/wirelesscraftingterminal/core/sync/packets/PacketValueConfig.java b/src/main/java/net/p455w0rd/wirelesscraftingterminal/core/sync/packets/PacketValueConfig.java index 31bc08c..6b6a9ae 100644 --- a/src/main/java/net/p455w0rd/wirelesscraftingterminal/core/sync/packets/PacketValueConfig.java +++ b/src/main/java/net/p455w0rd/wirelesscraftingterminal/core/sync/packets/PacketValueConfig.java @@ -14,7 +14,6 @@ import java.io.IOException; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.Container; import net.minecraft.item.ItemStack; -import net.p455w0rd.wirelesscraftingterminal.common.container.ContainerCraftConfirm; import net.p455w0rd.wirelesscraftingterminal.common.container.ContainerWirelessCraftingTerminal; import net.p455w0rd.wirelesscraftingterminal.common.container.WCTBaseContainer; import net.p455w0rd.wirelesscraftingterminal.common.utils.RandomUtils; @@ -61,12 +60,6 @@ public class PacketValueConfig extends WCTPacket { final ItemStack is = RandomUtils.getWirelessTerm(player.inventory); final IMouseWheelItem si = (IMouseWheelItem) is.getItem(); si.onWheel(is, this.Value.equals("WheelUp")); - } else if (this.Name.equals("Terminal.Cpu") && c instanceof ContainerCraftConfirm) { - final ContainerCraftConfirm qk = (ContainerCraftConfirm) c; - qk.cycleCpu(this.Value.equals("Next")); - } else if (this.Name.equals("Terminal.Start") && c instanceof ContainerCraftConfirm) { - final ContainerCraftConfirm qk = (ContainerCraftConfirm) c; - qk.startJob(); } else if (c instanceof IConfigurableObject) { final IConfigManager cm = ((IConfigurableObject) c).getConfigManager(); From b8a15b7ee4db08c6482c9e5a0f284cc8f789293a Mon Sep 17 00:00:00 2001 From: Raven Szewczyk Date: Wed, 24 Aug 2022 18:38:42 +0100 Subject: [PATCH 04/11] WCTBase->AEBase Gui,Container --- .../gui/GuiWirelessCraftingTerminal.java | 972 ++------------- .../client/gui/WCTBaseGui.java | 820 ------------ .../client/gui/widgets/GuiScrollbar.java | 119 -- .../container/ContainerOpenContext.java | 68 - .../ContainerWirelessCraftingTerminal.java | 676 ++-------- .../common/container/WCTBaseContainer.java | 1098 ----------------- .../common/container/guisync/GuiSync.java | 17 - .../common/container/guisync/SyncData.java | 140 --- .../common/container/slot/AppEngSlot.java | 202 +-- .../container/slot/SlotPlayerHotBar.java | 3 +- .../common/container/slot/SlotPlayerInv.java | 4 +- .../core/sync/WCTPacketHandlerBase.java | 6 - .../sync/packets/PacketInventoryAction.java | 25 +- .../core/sync/packets/PacketNEIRecipe.java | 16 +- .../core/sync/packets/PacketPartialItem.java | 58 - .../core/sync/packets/PacketProgressBar.java | 58 - .../core/sync/packets/PacketSwapSlots.java | 44 - .../core/sync/packets/PacketValueConfig.java | 17 +- .../helpers/WirelessTerminalGuiObject.java | 3 +- .../items/ItemMagnet.java | 13 - .../items/ItemWirelessCraftingTerminal.java | 3 +- .../proxy/CommonProxy.java | 3 +- 22 files changed, 256 insertions(+), 4109 deletions(-) delete mode 100644 src/main/java/net/p455w0rd/wirelesscraftingterminal/client/gui/WCTBaseGui.java delete mode 100644 src/main/java/net/p455w0rd/wirelesscraftingterminal/client/gui/widgets/GuiScrollbar.java delete mode 100644 src/main/java/net/p455w0rd/wirelesscraftingterminal/common/container/ContainerOpenContext.java delete mode 100644 src/main/java/net/p455w0rd/wirelesscraftingterminal/common/container/WCTBaseContainer.java delete mode 100644 src/main/java/net/p455w0rd/wirelesscraftingterminal/common/container/guisync/GuiSync.java delete mode 100644 src/main/java/net/p455w0rd/wirelesscraftingterminal/common/container/guisync/SyncData.java delete mode 100644 src/main/java/net/p455w0rd/wirelesscraftingterminal/core/sync/packets/PacketPartialItem.java delete mode 100644 src/main/java/net/p455w0rd/wirelesscraftingterminal/core/sync/packets/PacketProgressBar.java delete mode 100644 src/main/java/net/p455w0rd/wirelesscraftingterminal/core/sync/packets/PacketSwapSlots.java diff --git a/src/main/java/net/p455w0rd/wirelesscraftingterminal/client/gui/GuiWirelessCraftingTerminal.java b/src/main/java/net/p455w0rd/wirelesscraftingterminal/client/gui/GuiWirelessCraftingTerminal.java index 81e4d9e..d10eb52 100644 --- a/src/main/java/net/p455w0rd/wirelesscraftingterminal/client/gui/GuiWirelessCraftingTerminal.java +++ b/src/main/java/net/p455w0rd/wirelesscraftingterminal/client/gui/GuiWirelessCraftingTerminal.java @@ -1,14 +1,20 @@ package net.p455w0rd.wirelesscraftingterminal.client.gui; -import appeng.api.config.*; +import appeng.api.config.ActionItems; +import appeng.api.config.SearchBoxMode; +import appeng.api.config.Settings; +import appeng.api.config.TerminalStyle; +import appeng.api.config.YesNo; import appeng.api.storage.data.IAEItemStack; import appeng.api.util.IConfigManager; import appeng.api.util.IConfigurableObject; import appeng.client.ActionKey; +import appeng.client.gui.AEBaseGui; import appeng.client.gui.widgets.GuiImgButton; +import appeng.client.gui.widgets.GuiScrollbar; import appeng.client.gui.widgets.ISortSource; -import appeng.client.gui.widgets.ITooltip; -import appeng.container.slot.SlotRestrictedInput; +import appeng.client.me.InternalSlotME; +import appeng.client.me.ItemRepo; import appeng.core.AEConfig; import appeng.core.CommonHelper; import appeng.core.localization.ButtonToolTips; @@ -17,100 +23,64 @@ import appeng.helpers.InventoryAction; import appeng.util.IConfigManagerHost; import appeng.util.Platform; import codechicken.nei.TextField; -import com.google.common.base.Joiner; -import com.google.common.base.Stopwatch; import cpw.mods.fml.common.Loader; -import cpw.mods.fml.common.ObfuscationReflectionHelper; import cpw.mods.fml.relauncher.ReflectionHelper; -import java.io.IOException; -import java.lang.reflect.Field; -import java.text.DecimalFormat; -import java.text.NumberFormat; -import java.text.ParseException; -import java.util.Collection; -import java.util.HashSet; -import java.util.Iterator; -import java.util.LinkedList; -import java.util.List; -import java.util.Locale; -import java.util.Set; -import java.util.concurrent.TimeUnit; -import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiButton; -import net.minecraft.client.gui.inventory.GuiContainer; import net.minecraft.client.gui.inventory.GuiInventory; -import net.minecraft.client.renderer.RenderHelper; -import net.minecraft.client.renderer.Tessellator; -import net.minecraft.client.renderer.entity.RenderItem; import net.minecraft.client.resources.I18n; -import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.Container; import net.minecraft.inventory.Slot; import net.minecraft.item.ItemStack; import net.minecraft.util.ResourceLocation; -import net.p455w0rd.wirelesscraftingterminal.api.WCTApi; -import net.p455w0rd.wirelesscraftingterminal.client.gui.widgets.GuiScrollbar; import net.p455w0rd.wirelesscraftingterminal.client.gui.widgets.GuiTabButton; import net.p455w0rd.wirelesscraftingterminal.client.gui.widgets.GuiTrashButton; import net.p455w0rd.wirelesscraftingterminal.client.gui.widgets.MEGuiTextField; -import net.p455w0rd.wirelesscraftingterminal.client.me.InternalSlotME; -import net.p455w0rd.wirelesscraftingterminal.client.me.ItemRepo; -import net.p455w0rd.wirelesscraftingterminal.client.me.SlotDisconnected; import net.p455w0rd.wirelesscraftingterminal.client.me.SlotME; -import net.p455w0rd.wirelesscraftingterminal.client.me.WCTRenderItem; import net.p455w0rd.wirelesscraftingterminal.common.container.ContainerWirelessCraftingTerminal; -import net.p455w0rd.wirelesscraftingterminal.common.container.slot.AppEngCraftingSlot; import net.p455w0rd.wirelesscraftingterminal.common.container.slot.AppEngSlot; -import net.p455w0rd.wirelesscraftingterminal.common.container.slot.AppEngSlot.hasCalculatedValidness; -import net.p455w0rd.wirelesscraftingterminal.common.container.slot.OptionalSlotFake; import net.p455w0rd.wirelesscraftingterminal.common.container.slot.SlotCraftingMatrix; -import net.p455w0rd.wirelesscraftingterminal.common.container.slot.SlotCraftingTerm; -import net.p455w0rd.wirelesscraftingterminal.common.container.slot.SlotDisabled; -import net.p455w0rd.wirelesscraftingterminal.common.container.slot.SlotFake; import net.p455w0rd.wirelesscraftingterminal.common.container.slot.SlotFakeCraftingMatrix; -import net.p455w0rd.wirelesscraftingterminal.common.container.slot.SlotInaccessible; -import net.p455w0rd.wirelesscraftingterminal.common.container.slot.SlotOutput; import net.p455w0rd.wirelesscraftingterminal.common.container.slot.SlotTrash; import net.p455w0rd.wirelesscraftingterminal.common.utils.WCTLog; import net.p455w0rd.wirelesscraftingterminal.core.sync.network.NetworkHandler; import net.p455w0rd.wirelesscraftingterminal.core.sync.packets.PacketEmptyTrash; import net.p455w0rd.wirelesscraftingterminal.core.sync.packets.PacketInventoryAction; -import net.p455w0rd.wirelesscraftingterminal.core.sync.packets.PacketSwapSlots; import net.p455w0rd.wirelesscraftingterminal.core.sync.packets.PacketSwitchGuis; import net.p455w0rd.wirelesscraftingterminal.core.sync.packets.PacketValueConfig; import net.p455w0rd.wirelesscraftingterminal.handlers.LocaleHandler; -import net.p455w0rd.wirelesscraftingterminal.integration.IntegrationRegistry; -import net.p455w0rd.wirelesscraftingterminal.integration.IntegrationType; -import net.p455w0rd.wirelesscraftingterminal.integration.abstraction.INEI; import net.p455w0rd.wirelesscraftingterminal.reference.Reference; import org.lwjgl.input.Keyboard; import org.lwjgl.input.Mouse; -import org.lwjgl.opengl.GL11; -import org.lwjgl.opengl.GL12; -public class GuiWirelessCraftingTerminal extends GuiContainer implements ISortSource, IConfigManagerHost { +import java.io.IOException; +import java.lang.reflect.Field; +import java.text.NumberFormat; +import java.util.List; +import java.util.Locale; + +public class GuiWirelessCraftingTerminal extends AEBaseGui implements ISortSource, IConfigManagerHost { private float xSize_lo; private float ySize_lo; public static int tick = 0, - GUI_HEIGHT = 240, - GUI_WIDTH = 230, - AE_ROW_HEIGHT = 18, - AE_NUM_ROWS = 0, - GUI_UPPER_HEIGHT = 35, - GUI_SEARCH_ROW = 35, - SEARCH_X = 81, - SEARCH_Y = 5, - SEARCH_WIDTH = 88, - SEARCH_HEIGHT = 12, - SEARCH_MAXCHARS = 15, - GUI_LOWER_HEIGHT, - AE_TOTAL_ROWS_HEIGHT, - BUTTON_SEARCH_MODE_POS_X = -18, - BUTTON_SEARCH_MODE_POS_Y = 68, - BUTTON_SIZE = 16, - NEI_EXTRA_SPACE = 30, - slotYOffset; + GUI_HEIGHT = 240, + GUI_WIDTH = 230, + AE_ROW_HEIGHT = 18, + AE_NUM_ROWS = 0, + GUI_UPPER_HEIGHT = 35, + GUI_SEARCH_ROW = 35, + SEARCH_X = 81, + SEARCH_Y = 5, + SEARCH_WIDTH = 88, + SEARCH_HEIGHT = 12, + SEARCH_MAXCHARS = 15, + GUI_LOWER_HEIGHT, + AE_TOTAL_ROWS_HEIGHT, + BUTTON_SEARCH_MODE_POS_X = -18, + BUTTON_SEARCH_MODE_POS_Y = 68, + BUTTON_SIZE = 16, + NEI_EXTRA_SPACE = 30, + slotYOffset; protected static final int BUTTON_SEARCH_MODE_ID = 5; protected static final long TOOLTIP_UPDATE_INTERVAL = 3000L; private int currScreenWidth, currScreenHeight; @@ -119,15 +89,6 @@ public class GuiWirelessCraftingTerminal extends GuiContainer implements ISortSo private boolean isFullScreen, init = true, reInit, wasResized = false; public static GuiWirelessCraftingTerminal INSTANCE; private static boolean switchingGuis; - private final List meSlots = new LinkedList(); - private final Set drag_click = new HashSet(); - private final WCTRenderItem aeRenderItem = new WCTRenderItem(); - private GuiScrollbar scrollBar = null; - private boolean disableShiftClick = false; - private Stopwatch dbl_clickTimer = Stopwatch.createStarted(); - private ItemStack dbl_whichItem; - private Slot bl_clicked; - private boolean subGui; public static int craftingGridOffsetX = 80; public static int craftingGridOffsetY; private static String memoryText = ""; @@ -168,11 +129,8 @@ public class GuiWirelessCraftingTerminal extends GuiContainer implements ISortSo this.standardSize = this.xSize; this.setReservedSpace(73); this.containerWCT = (ContainerWirelessCraftingTerminal) container; - this.scrollBar = new GuiScrollbar(); - this.subGui = switchingGuis; - switchingGuis = false; - this.setScrollBar(scrollBar); - this.repo = new ItemRepo(scrollBar, this); + this.setScrollBar(new GuiScrollbar()); + this.repo = new ItemRepo(getScrollBar(), this); this.configSrc = ((IConfigurableObject) this.inventorySlots).getConfigManager(); this.devicePowered = containerWCT.isPowered(); ((ContainerWirelessCraftingTerminal) this.inventorySlots).setGui(this); @@ -189,12 +147,8 @@ public class GuiWirelessCraftingTerminal extends GuiContainer implements ISortSo private void setScrollBar() { this.getScrollBar().setTop(18).setLeft(174).setHeight(this.rows * 18 - 2); this.getScrollBar() - .setRange( - 0, (this.repo.size() + this.perRow - 1) / this.perRow - this.rows, Math.max(1, this.rows / 6)); - } - - protected void setScrollBar(final GuiScrollbar myScrollBar) { - this.scrollBar = myScrollBar; + .setRange( + 0, (this.repo.size() + this.perRow - 1) / this.perRow - this.rows, Math.max(1, this.rows / 6)); } @SuppressWarnings("rawtypes") @@ -211,7 +165,7 @@ public class GuiWirelessCraftingTerminal extends GuiContainer implements ISortSo if (iBtn.getSetting() != Settings.ACTIONS) { final Enum cv = iBtn.getCurrentValue(); final Enum next = - Platform.rotateEnum(cv, backwards, iBtn.getSetting().getPossibleValues()); + Platform.rotateEnum(cv, backwards, iBtn.getSetting().getPossibleValues()); if (btn == this.terminalStyleBox) { AEConfig.instance.settings.putSetting(iBtn.getSetting(), next); @@ -223,7 +177,7 @@ public class GuiWirelessCraftingTerminal extends GuiContainer implements ISortSo } else { try { NetworkHandler.instance.sendToServer( - new PacketValueConfig(iBtn.getSetting().name(), next.name())); + new PacketValueConfig(iBtn.getSetting().name(), next.name())); } catch (final IOException e) { WCTLog.debug(e.getMessage()); } @@ -246,7 +200,7 @@ public class GuiWirelessCraftingTerminal extends GuiContainer implements ISortSo if (s != null) { final PacketInventoryAction p = - new PacketInventoryAction(InventoryAction.MOVE_REGION, s.slotNumber, 0); + new PacketInventoryAction(InventoryAction.MOVE_REGION, s.slotNumber, 0); NetworkHandler.instance.sendToServer(p); } } @@ -276,25 +230,6 @@ public class GuiWirelessCraftingTerminal extends GuiContainer implements ISortSo this.initGui(); } - protected static String join(final Collection toolTip, final String delimiter) { - final Joiner joiner = Joiner.on(delimiter); - - return joiner.join(toolTip); - } - - protected int getQty(final GuiButton btn) { - try { - final DecimalFormat df = new DecimalFormat("+#;-#"); - return df.parse(btn.displayString).intValue(); - } catch (final ParseException e) { - return 0; - } - } - - public boolean isSubGui() { - return this.subGui; - } - int getReservedSpace() { return this.reservedSpace; } @@ -317,15 +252,17 @@ public class GuiWirelessCraftingTerminal extends GuiContainer implements ISortSo @SuppressWarnings({"unchecked", "rawtypes"}) @Override public void initGui() { + super.initGui(); + Keyboard.enableRepeatEvents(true); this.maxRows = this.getMaxRows(); this.perRow = AEConfig.instance.getConfigManager().getSetting(Settings.TERMINAL_STYLE) != TerminalStyle.FULL - ? 9 - : 9 + ((this.width - this.standardSize) / 18); + ? 9 + : 9 + ((this.width - this.standardSize) / 18); this.isNEIEnabled = Loader.isModLoaded("NotEnoughItems"); int top = isNEIEnabled ? 22 : 0; final int magicNumber = 114 + 1; - final int extraSpace = this.height - magicNumber - 0 - top - this.reservedSpace; + final int extraSpace = this.height - magicNumber - top - this.reservedSpace; this.rows = (int) Math.floor(extraSpace / 18); if (this.rows > this.maxRows) { top += (this.rows - this.maxRows) * 18 / 2; @@ -344,7 +281,7 @@ public class GuiWirelessCraftingTerminal extends GuiContainer implements ISortSo for (int y = 0; y < this.rows; y++) { for (int x = 0; x < this.perRow; x++) { this.getMeSlots() - .add(new InternalSlotME(this.repo, x + y * this.perRow, this.offsetX + x * 18, 18 + y * 18)); + .add(new InternalSlotME(this.repo, x + y * this.perRow, this.offsetX + x * 18, 18 + y * 18)); } } if (AEConfig.instance.getConfigManager().getSetting(Settings.TERMINAL_STYLE) != TerminalStyle.FULL) { @@ -359,66 +296,54 @@ public class GuiWirelessCraftingTerminal extends GuiContainer implements ISortSo this.guiTop = (int) Math.floor(unusedSpace / (unusedSpace < 0 ? 3.8f : 2.0f)); int offset = this.guiTop + 8; - final List slots = this.getInventorySlots(); - final Iterator i = slots.iterator(); - while (i.hasNext()) { - if (i.next() instanceof SlotME) { - i.remove(); - } - } - - for (final InternalSlotME me : this.meSlots) { - slots.add(new SlotME(me)); - } - this.buttonList.clear(); this.buttonList.add( - this.clearBtn = new GuiImgButton( - this.guiLeft + 134, this.guiTop + this.ySize - 160, Settings.ACTIONS, ActionItems.STASH)); + this.clearBtn = new GuiImgButton( + this.guiLeft + 134, this.guiTop + this.ySize - 160, Settings.ACTIONS, ActionItems.STASH)); this.buttonList.add(this.trashBtn = new GuiTrashButton(this.guiLeft + 98, this.guiTop + this.ySize - 104)); this.clearBtn.setHalfSize(true); if (this.customSortOrder) { this.buttonList.add( - this.SortByBox = new GuiImgButton( - this.guiLeft - 18, offset, Settings.SORT_BY, this.configSrc.getSetting(Settings.SORT_BY))); + this.SortByBox = new GuiImgButton( + this.guiLeft - 18, offset, Settings.SORT_BY, this.configSrc.getSetting(Settings.SORT_BY))); offset += 20; } this.buttonList.add( - this.ViewBox = new GuiImgButton( - this.guiLeft - 18, offset, Settings.VIEW_MODE, this.configSrc.getSetting(Settings.VIEW_MODE))); + this.ViewBox = new GuiImgButton( + this.guiLeft - 18, offset, Settings.VIEW_MODE, this.configSrc.getSetting(Settings.VIEW_MODE))); offset += 20; this.buttonList.add( - this.SortDirBox = new GuiImgButton( - this.guiLeft - 18, - offset, - Settings.SORT_DIRECTION, - this.configSrc.getSetting(Settings.SORT_DIRECTION))); + this.SortDirBox = new GuiImgButton( + this.guiLeft - 18, + offset, + Settings.SORT_DIRECTION, + this.configSrc.getSetting(Settings.SORT_DIRECTION))); offset += 20; this.buttonList.add( - this.searchBoxSettings = new GuiImgButton( - this.guiLeft - 18, - offset, - Settings.SEARCH_MODE, - AEConfig.instance.settings.getSetting(Settings.SEARCH_MODE))); + this.searchBoxSettings = new GuiImgButton( + this.guiLeft - 18, + offset, + Settings.SEARCH_MODE, + AEConfig.instance.settings.getSetting(Settings.SEARCH_MODE))); offset += 20; this.buttonList.add( - this.searchStringSave = new GuiImgButton( - this.guiLeft - 18, - offset, - Settings.SAVE_SEARCH, - AEConfig.instance.preserveSearchBar ? YesNo.YES : YesNo.NO)); + this.searchStringSave = new GuiImgButton( + this.guiLeft - 18, + offset, + Settings.SAVE_SEARCH, + AEConfig.instance.preserveSearchBar ? YesNo.YES : YesNo.NO)); offset += 20; this.buttonList.add( - this.terminalStyleBox = new GuiImgButton( - this.guiLeft - 18, - offset, - Settings.TERMINAL_STYLE, - AEConfig.instance.settings.getSetting(Settings.TERMINAL_STYLE))); + this.terminalStyleBox = new GuiImgButton( + this.guiLeft - 18, + offset, + Settings.TERMINAL_STYLE, + AEConfig.instance.settings.getSetting(Settings.TERMINAL_STYLE))); this.searchField = new MEGuiTextField(this.fontRendererObj, SEARCH_X, SEARCH_Y, SEARCH_WIDTH, SEARCH_HEIGHT); @@ -429,12 +354,12 @@ public class GuiWirelessCraftingTerminal extends GuiContainer implements ISortSo this.searchField.setEnabled(true); this.buttonList.add( - this.craftingStatusBtn = new GuiTabButton( - this.guiLeft + 169, - this.guiTop - 4, - 2 + 11 * 16, - GuiText.CraftingStatus.getLocal(), - itemRender)); + this.craftingStatusBtn = new GuiTabButton( + this.guiLeft + 169, + this.guiTop - 4, + 2 + 11 * 16, + GuiText.CraftingStatus.getLocal(), + itemRender)); this.craftingStatusBtn.setHideEdge(13); final Enum searchMode = AEConfig.instance.settings.getSetting(Settings.SEARCH_MODE); @@ -471,15 +396,10 @@ public class GuiWirelessCraftingTerminal extends GuiContainer implements ISortSo } } - @SuppressWarnings("unchecked") - private List getInventorySlots() { - return this.inventorySlots.inventorySlots; - } - int getMaxRows() { return AEConfig.instance.getConfigManager().getSetting(Settings.TERMINAL_STYLE) == TerminalStyle.SMALL - ? 6 - : Integer.MAX_VALUE; + ? 6 + : Integer.MAX_VALUE; } protected void repositionSlot(final AppEngSlot s) { @@ -489,7 +409,7 @@ public class GuiWirelessCraftingTerminal extends GuiContainer implements ISortSo /** * Called every tick. It is used in this instance to detect screen size * changes to automatically update the gui height. - * + *

* reInit variable is used to call initGui() on the next tick. It has to be * called this way to update correctly. * @@ -519,7 +439,7 @@ public class GuiWirelessCraftingTerminal extends GuiContainer implements ISortSo } else { this.initGui(); this.setScrollBar(); - if (this.wasResized == true) { + if (this.wasResized) { this.searchField.setFocused(this.wasTextboxFocused); this.searchField.setText(this.repo.getSearchString()); this.wasTextboxFocused = false; @@ -546,8 +466,8 @@ public class GuiWirelessCraftingTerminal extends GuiContainer implements ISortSo */ private boolean hasScreenResChanged() { if ((this.currScreenWidth != this.mc.displayWidth) - || (this.currScreenHeight != this.mc.displayHeight) - || (this.isFullScreen != this.mc.isFullScreen())) { + || (this.currScreenHeight != this.mc.displayHeight) + || (this.isFullScreen != this.mc.isFullScreen())) { this.currScreenWidth = this.mc.displayWidth; this.currScreenHeight = this.mc.displayHeight; this.isFullScreen = this.mc.isFullScreen(); @@ -559,132 +479,11 @@ public class GuiWirelessCraftingTerminal extends GuiContainer implements ISortSo /** * Draws the screen and tooltips. */ + @Override public void drawScreen(int mouseX, int mouseY, float btn) { super.drawScreen(mouseX, mouseY, btn); this.xSize_lo = (float) mouseX; this.ySize_lo = (float) mouseY; - - final boolean hasClicked = Mouse.isButtonDown(0); - if (hasClicked && this.scrollBar != null) { - this.scrollBar.click(this, mouseX - this.guiLeft, mouseY - this.guiTop); - } - - for (final Object c : this.buttonList) { - if (c instanceof ITooltip) { - final ITooltip tooltip = (ITooltip) c; - final int x = tooltip.xPos(); - int y = tooltip.yPos(); - - if (x < mouseX && x + tooltip.getWidth() > mouseX && tooltip.isVisible()) { - if (y < mouseY && y + tooltip.getHeight() > mouseY) { - if (y < 15) { - y = 15; - } - - final String msg = tooltip.getMessage(); - if (msg != null) { - this.drawTooltip(x + 11, y + 4, 0, msg); - } - } - } - } - } - } - - public void drawTooltip(final int par2, final int par3, final int forceWidth, final String message) { - GL11.glPushAttrib(GL11.GL_ALL_ATTRIB_BITS); - GL11.glDisable(GL12.GL_RESCALE_NORMAL); - RenderHelper.disableStandardItemLighting(); - GL11.glDisable(GL11.GL_LIGHTING); - GL11.glDisable(GL11.GL_DEPTH_TEST); - final String[] var4 = message.split("\n"); - - if (var4.length > 0) { - int var5 = 0; - int var6; - int var7; - - for (var6 = 0; var6 < var4.length; ++var6) { - var7 = this.fontRendererObj.getStringWidth(var4[var6]); - - if (var7 > var5) { - var5 = var7; - } - } - - var6 = par2 + 12; - var7 = par3 - 12; - int var9 = 8; - - if (var4.length > 1) { - var9 += 2 + (var4.length - 1) * 10; - } - - if (this.guiTop + var7 + var9 + 6 > this.height) { - var7 = this.height - var9 - this.guiTop - 6; - } - - if (forceWidth > 0) { - var5 = forceWidth; - } - - this.zLevel = 300.0F; - itemRender.zLevel = 300.0F; - final int var10 = -267386864; - this.drawGradientRect(var6 - 3, var7 - 4, var6 + var5 + 3, var7 - 3, var10, var10); - this.drawGradientRect(var6 - 3, var7 + var9 + 3, var6 + var5 + 3, var7 + var9 + 4, var10, var10); - this.drawGradientRect(var6 - 3, var7 - 3, var6 + var5 + 3, var7 + var9 + 3, var10, var10); - this.drawGradientRect(var6 - 4, var7 - 3, var6 - 3, var7 + var9 + 3, var10, var10); - this.drawGradientRect(var6 + var5 + 3, var7 - 3, var6 + var5 + 4, var7 + var9 + 3, var10, var10); - final int var11 = 1347420415; - final int var12 = (var11 & 16711422) >> 1 | var11 & -16777216; - this.drawGradientRect(var6 - 3, var7 - 3 + 1, var6 - 3 + 1, var7 + var9 + 3 - 1, var11, var12); - this.drawGradientRect(var6 + var5 + 2, var7 - 3 + 1, var6 + var5 + 3, var7 + var9 + 3 - 1, var11, var12); - this.drawGradientRect(var6 - 3, var7 - 3, var6 + var5 + 3, var7 - 3 + 1, var11, var11); - this.drawGradientRect(var6 - 3, var7 + var9 + 2, var6 + var5 + 3, var7 + var9 + 3, var12, var12); - - for (int var13 = 0; var13 < var4.length; ++var13) { - String var14 = var4[var13]; - - if (var13 == 0) { - var14 = '\u00a7' + Integer.toHexString(15) + var14; - } else { - var14 = "\u00a77" + var14; - } - - this.fontRendererObj.drawStringWithShadow(var14, var6, var7, -1); - - if (var13 == 0) { - var7 += 2; - } - - var7 += 10; - } - - this.zLevel = 0.0F; - itemRender.zLevel = 0.0F; - } - GL11.glPopAttrib(); - } - - public void bindTexture(final String base, final String file) { - final ResourceLocation loc = new ResourceLocation(base, "textures/" + file); - this.mc.getTextureManager().bindTexture(loc); - } - - /** - * Draw GUI Labels and item tooltips - */ - @Override - protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY) { - final int ox = this.guiLeft; // (width - xSize) / 2; - final int oy = this.guiTop; // (height - ySize) / 2; - GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); - - if (this.scrollBar != null) { - this.scrollBar.draw(this); - } - this.drawFG(ox, oy, mouseX, mouseY); } public void drawFG(int offsetX, int offsetY, int mouseX, int mouseY) { @@ -699,48 +498,6 @@ public class GuiWirelessCraftingTerminal extends GuiContainer implements ISortSo this.currentMouseY = mouseY; } - /** - * Draw and piece together the background texture - */ - @Override - protected void drawGuiContainerBackgroundLayer(final float f, final int x, final int y) { - final int ox = this.guiLeft; // (width - xSize) / 2; - final int oy = this.guiTop; // (height - ySize) / 2; - GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); - this.drawBG(ox, oy, x, y); - - final List slots = this.getInventorySlots(); - for (final Slot slot : slots) { - if (slot instanceof OptionalSlotFake) { - final OptionalSlotFake fs = (OptionalSlotFake) slot; - if (fs.renderDisabled()) { - if (fs.isEnabled()) { - this.drawTexturedModalRect( - ox + fs.xDisplayPosition - 1, - oy + fs.yDisplayPosition - 1, - fs.getSourceX() - 1, - fs.getSourceY() - 1, - 18, - 18); - } else { - GL11.glPushAttrib(GL11.GL_ALL_ATTRIB_BITS); - GL11.glColor4f(1.0F, 1.0F, 1.0F, 0.4F); - GL11.glEnable(GL11.GL_BLEND); - this.drawTexturedModalRect( - ox + fs.xDisplayPosition - 1, - oy + fs.yDisplayPosition - 1, - fs.getSourceX() - 1, - fs.getSourceY() - 1, - 18, - 18); - GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); - GL11.glPopAttrib(); - } - } - } - } - } - public void drawBG(final int offsetX, final int offsetY, final int mouseX, final int mouseY) { this.bindTexture(bgTexturePath); final int x_width = 199; @@ -754,12 +511,12 @@ public class GuiWirelessCraftingTerminal extends GuiContainer implements ISortSo // draw player inv this.drawTexturedModalRect( - offsetX, - offsetY + 16 + this.rows * 18 + this.lowerTextureOffset, - 0, - 106 - 18 - 18, - x_width, - 99 + this.reservedSpace - this.lowerTextureOffset); + offsetX, + offsetY + 16 + this.rows * 18 + this.lowerTextureOffset, + 0, + 106 - 18 - 18, + x_width, + 99 + this.reservedSpace - this.lowerTextureOffset); // draw view cells this.drawTexturedModalRect(offsetX + x_width, offsetY, x_width, 0, 32, 104); @@ -768,12 +525,12 @@ public class GuiWirelessCraftingTerminal extends GuiContainer implements ISortSo this.drawTexturedModalRect(this.guiLeft + 132, (this.guiTop + this.rows * 18) + 83, 237, 237, 19, 19); } GuiInventory.func_147046_a( - this.guiLeft + 51, - (this.guiTop + this.rows * 18) + 94, - 32, - (float) (this.guiLeft + 51) - this.xSize_lo, - (float) ((this.guiTop + this.rows * 18) + 50) - this.ySize_lo, - this.mc.thePlayer); + this.guiLeft + 51, + (this.guiTop + this.rows * 18) + 94, + 32, + (float) (this.guiLeft + 51) - this.xSize_lo, + (float) ((this.guiTop + this.rows * 18) + 50) - this.ySize_lo, + this.mc.thePlayer); boolean update = false; for (int i = 0; i < 5; i++) { @@ -803,500 +560,22 @@ public class GuiWirelessCraftingTerminal extends GuiContainer implements ISortSo this.setScrollBar(); } - this.drag_click.clear(); - - if (btn == 1) { - for (final Object o : this.buttonList) { - final GuiButton guibutton = (GuiButton) o; - if (guibutton.mousePressed(this.mc, xCoord, yCoord)) { - super.mouseClicked(xCoord, yCoord, 0); - return; - } - } - } - super.mouseClicked(xCoord, yCoord, btn); } - @Override - protected void mouseClickMove(final int x, final int y, final int c, final long d) { - final Slot slot = this.getSlot(x, y); - final ItemStack itemstack = this.mc.thePlayer.inventory.getItemStack(); - - if (slot instanceof SlotFake && itemstack != null) { - this.drag_click.add(slot); - if (this.drag_click.size() > 1) { - for (final Slot dr : this.drag_click) { - final PacketInventoryAction p = new PacketInventoryAction( - c == 0 ? InventoryAction.PICKUP_OR_SET_DOWN : InventoryAction.PLACE_SINGLE, - dr.slotNumber, - 0); - NetworkHandler.instance.sendToServer(p); - } - } - } else { - super.mouseClickMove(x, y, c, d); - } - } - - @Override - protected void handleMouseClick(final Slot slot, final int slotIdx, final int ctrlDown, final int key) { - final EntityPlayer player = Minecraft.getMinecraft().thePlayer; - - if (slot instanceof SlotFake) { - final InventoryAction action = - ctrlDown == 1 ? InventoryAction.SPLIT_OR_PLACE_SINGLE : InventoryAction.PICKUP_OR_SET_DOWN; - - if (this.drag_click.size() > 1) { - return; - } - - final PacketInventoryAction p = new PacketInventoryAction(action, slotIdx, 0); - NetworkHandler.instance.sendToServer(p); - - return; - } else if (slot instanceof SlotCraftingTerm) { - if (key == 6) { - return; // prevent weird double clicks.. - } - - InventoryAction action = null; - if (key == 1) { - action = InventoryAction.CRAFT_SHIFT; - } else { - action = ctrlDown == 1 ? InventoryAction.CRAFT_STACK : InventoryAction.CRAFT_ITEM; - } - - final PacketInventoryAction p = new PacketInventoryAction(action, slotIdx, 0); - NetworkHandler.instance.sendToServer(p); - - return; - } - - if (Keyboard.isKeyDown(Keyboard.KEY_SPACE)) { - if (this.enableSpaceClicking()) { - IAEItemStack stack = null; - if (slot instanceof SlotME) { - stack = ((SlotME) slot).getAEStack(); - } - - int slotNum = this.getInventorySlots().size(); - - if (!(slot instanceof SlotME) && slot != null) { - slotNum = slot.slotNumber; - } - - ((ContainerWirelessCraftingTerminal) this.inventorySlots).setTargetStack(stack); - final PacketInventoryAction p = new PacketInventoryAction(InventoryAction.MOVE_REGION, slotNum, 0); - NetworkHandler.instance.sendToServer(p); - return; - } - } - - if (slot instanceof SlotDisconnected) { - InventoryAction action = null; - - switch (key) { - case 0: // pickup / set-down. - action = ctrlDown == 1 ? InventoryAction.SPLIT_OR_PLACE_SINGLE : InventoryAction.PICKUP_OR_SET_DOWN; - break; - case 1: - action = ctrlDown == 1 ? InventoryAction.PICKUP_SINGLE : InventoryAction.SHIFT_CLICK; - break; - - case 3: // creative dupe: - if (player.capabilities.isCreativeMode) { - action = InventoryAction.CREATIVE_DUPLICATE; - } - - break; - - default: - case 4: // drop item: - case 6: - } - - if (action != null) { - final PacketInventoryAction p = new PacketInventoryAction( - action, - slot.getSlotIndex(), - ((SlotDisconnected) slot).getSlot().getId()); - NetworkHandler.instance.sendToServer(p); - } - - return; - } - - if (slot instanceof SlotME) { - InventoryAction action = null; - IAEItemStack stack = null; - - switch (key) { - case 0: // pickup / set-down. - action = ctrlDown == 1 ? InventoryAction.SPLIT_OR_PLACE_SINGLE : InventoryAction.PICKUP_OR_SET_DOWN; - stack = ((SlotME) slot).getAEStack(); - - if (stack != null - && action == InventoryAction.PICKUP_OR_SET_DOWN - && stack.getStackSize() == 0 - && player.inventory.getItemStack() == null) { - action = InventoryAction.AUTO_CRAFT; - } - - break; - case 1: - action = ctrlDown == 1 ? InventoryAction.PICKUP_SINGLE : InventoryAction.SHIFT_CLICK; - stack = ((SlotME) slot).getAEStack(); - break; - - case 3: // creative dupe: - stack = ((SlotME) slot).getAEStack(); - if (stack != null && stack.isCraftable()) { - action = InventoryAction.AUTO_CRAFT; - } else if (player.capabilities.isCreativeMode) { - final IAEItemStack slotItem = ((SlotME) slot).getAEStack(); - if (slotItem != null) { - action = InventoryAction.CREATIVE_DUPLICATE; - } - } - break; - - default: - case 4: // drop item: - case 6: - } - - if (action != null) { - ((ContainerWirelessCraftingTerminal) this.inventorySlots).setTargetStack(stack); - final PacketInventoryAction p = new PacketInventoryAction( - action, this.getInventorySlots().size(), 0); - NetworkHandler.instance.sendToServer(p); - } - - return; - } - - if (!this.disableShiftClick && isShiftKeyDown()) { - this.disableShiftClick = true; - - if (this.dbl_whichItem == null - || this.bl_clicked != slot - || this.dbl_clickTimer.elapsed(TimeUnit.MILLISECONDS) > 150) { - // some simple double click logic. - this.bl_clicked = slot; - this.dbl_clickTimer = Stopwatch.createStarted(); - if (slot != null) { - this.dbl_whichItem = slot.getHasStack() ? slot.getStack().copy() : null; - } else { - this.dbl_whichItem = null; - } - } else if (this.dbl_whichItem != null) { - // a replica of the weird broken vanilla feature. - - final List slots = this.getInventorySlots(); - for (final Slot inventorySlot : slots) { - if (inventorySlot != null - && inventorySlot.canTakeStack(this.mc.thePlayer) - && inventorySlot.getHasStack() - && inventorySlot.inventory == slot.inventory - && Container.func_94527_a(inventorySlot, this.dbl_whichItem, true)) { - this.handleMouseClick(inventorySlot, inventorySlot.slotNumber, ctrlDown, 1); - } - } - } - - this.disableShiftClick = false; - } - - super.handleMouseClick(slot, slotIdx, ctrlDown, key); - } - - @Override - protected boolean checkHotbarKeys(final int keyCode) { - final Slot theSlot; - - try { - theSlot = ObfuscationReflectionHelper.getPrivateValue( - GuiContainer.class, this, "theSlot", "field_147006_u", "f"); - } catch (final Throwable t) { - return false; - } - - if (this.mc.thePlayer.inventory.getItemStack() == null && theSlot != null) { - for (int j = 0; j < 9; ++j) { - if (keyCode == this.mc.gameSettings.keyBindsHotbar[j].getKeyCode()) { - final List slots = this.getInventorySlots(); - for (final Slot s : slots) { - if (s.getSlotIndex() == j - && s.inventory - == ((ContainerWirelessCraftingTerminal) this.inventorySlots).getPlayerInv()) { - if (s.getStack() != null - && s.getStack().getItem() - == WCTApi.instance() - .items() - .WirelessCraftingTerminal - .getItem()) return false; - if (!s.canTakeStack( - ((ContainerWirelessCraftingTerminal) this.inventorySlots).getPlayerInv().player)) - return false; - else break; - } - } - - if (theSlot.getSlotStackLimit() == 64) { - this.handleMouseClick(theSlot, theSlot.slotNumber, j, 2); - return true; - } else { - for (final Slot s : slots) { - if (s.getSlotIndex() == j - && s.inventory - == ((ContainerWirelessCraftingTerminal) this.inventorySlots) - .getPlayerInv()) { - NetworkHandler.instance.sendToServer( - new PacketSwapSlots(s.slotNumber, theSlot.slotNumber)); - return true; - } - } - } - } - } - } - - return false; - } - @Override public void onGuiClosed() { super.onGuiClosed(); - this.subGui = true; // in case the gui is reopened later ( i'm looking - // at you NEI ) Keyboard.enableRepeatEvents(false); if (this.searchField.getText() != null) { memoryText = this.searchField.getText(); } } - protected Slot getSlot(final int mouseX, final int mouseY) { - final List slots = this.getInventorySlots(); - for (final Slot slot : slots) { - // isPointInRegion - if (this.func_146978_c(slot.xDisplayPosition, slot.yDisplayPosition, 16, 16, mouseX, mouseY)) { - return slot; - } - } - - return null; - } - - @Override - public void handleMouseInput() { - super.handleMouseInput(); - - final int i = Mouse.getEventDWheel(); - if (i != 0 && isShiftKeyDown()) { - final int x = Mouse.getEventX() * this.width / this.mc.displayWidth; - final int y = this.height - Mouse.getEventY() * this.height / this.mc.displayHeight - 1; - this.mouseWheelEvent(x, y, i / Math.abs(i)); - } else if (i != 0 && this.scrollBar != null) { - this.scrollBar.wheel(i); - } - } - - private void mouseWheelEvent(final int x, final int y, final int wheel) { - final Slot slot = this.getSlot(x, y); - if (slot instanceof SlotME) { - final IAEItemStack item = ((SlotME) slot).getAEStack(); - if (item != null) { - ((ContainerWirelessCraftingTerminal) this.inventorySlots).setTargetStack(item); - final InventoryAction direction = wheel > 0 ? InventoryAction.ROLL_DOWN : InventoryAction.ROLL_UP; - final int times = Math.abs(wheel); - final int inventorySize = this.getInventorySlots().size(); - for (int h = 0; h < times; h++) { - final PacketInventoryAction p = new PacketInventoryAction(direction, inventorySize, 0); - NetworkHandler.instance.sendToServer(p); - } - } - } - } - protected boolean enableSpaceClicking() { return true; } - protected void drawItem(final int x, final int y, final ItemStack is) { - this.zLevel = 100.0F; - itemRender.zLevel = 100.0F; - - GL11.glPushAttrib(GL11.GL_ALL_ATTRIB_BITS); - GL11.glEnable(GL11.GL_LIGHTING); - GL11.glEnable(GL12.GL_RESCALE_NORMAL); - GL11.glEnable(GL11.GL_DEPTH_TEST); - RenderHelper.enableGUIStandardItemLighting(); - itemRender.renderItemAndEffectIntoGUI(this.fontRendererObj, this.mc.renderEngine, is, x, y); - GL11.glPopAttrib(); - - itemRender.zLevel = 0.0F; - this.zLevel = 0.0F; - } - - protected String getGuiDisplayName(final String in) { - return this.hasCustomInventoryName() ? this.getInventoryName() : in; - } - - private boolean hasCustomInventoryName() { - if (this.inventorySlots instanceof ContainerWirelessCraftingTerminal) { - return ((ContainerWirelessCraftingTerminal) this.inventorySlots).getCustomName() != null; - } - return false; - } - - private String getInventoryName() { - return ((ContainerWirelessCraftingTerminal) this.inventorySlots).getCustomName(); - } - - private void drawSlot(final Slot s) { - if (s instanceof SlotME) { - final RenderItem pIR = this.setItemRender(this.aeRenderItem); - try { - this.zLevel = 100.0F; - itemRender.zLevel = 100.0F; - - if (!this.isPowered()) { - GL11.glDisable(GL11.GL_LIGHTING); - drawRect( - s.xDisplayPosition, - s.yDisplayPosition, - 16 + s.xDisplayPosition, - 16 + s.yDisplayPosition, - 0x66111111); - GL11.glEnable(GL11.GL_LIGHTING); - } - - this.zLevel = 0.0F; - itemRender.zLevel = 0.0F; - - this.aeRenderItem.setAeStack(((SlotME) s).getAEStack()); - - this.safeDrawSlot(s); - } catch (final Exception err) { - WCTLog.warning("WCT prevented crash while drawing slot: " + err.toString()); - } - this.setItemRender(pIR); - return; - } else { - GuiWirelessCraftingTerminal.itemRender = new RenderItem(); - try { - final ItemStack is = s.getStack(); - if (s instanceof AppEngSlot - && (((AppEngSlot) s).renderIconWithItem() || is == null) - && (((AppEngSlot) s).shouldDisplay())) { - final AppEngSlot aes = (AppEngSlot) s; - if (aes.getIcon() >= 0) { - this.bindTexture("appliedenergistics2", "guis/states.png"); - - GL11.glPushAttrib(GL11.GL_ALL_ATTRIB_BITS); - final Tessellator tessellator = Tessellator.instance; - try { - final int uv_y = (int) Math.floor(aes.getIcon() / 16); - final int uv_x = aes.getIcon() - uv_y * 16; - - GL11.glEnable(GL11.GL_BLEND); - GL11.glDisable(GL11.GL_LIGHTING); - GL11.glEnable(GL11.GL_TEXTURE_2D); - GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); - GL11.glColor4f(1.0f, 1.0f, 1.0f, 1.0f); - final float par1 = aes.xDisplayPosition; - final float par2 = aes.yDisplayPosition; - final float par3 = uv_x * 16; - final float par4 = uv_y * 16; - - tessellator.startDrawingQuads(); - tessellator.setColorRGBA_F(1.0f, 1.0f, 1.0f, aes.getOpacityOfIcon()); - final float f1 = 0.00390625F; - final float f = 0.00390625F; - final float par6 = 16; - tessellator.addVertexWithUV( - par1 + 0, par2 + par6, this.zLevel, (par3 + 0) * f, (par4 + par6) * f1); - final float par5 = 16; - tessellator.addVertexWithUV( - par1 + par5, par2 + par6, this.zLevel, (par3 + par5) * f, (par4 + par6) * f1); - tessellator.addVertexWithUV( - par1 + par5, par2 + 0, this.zLevel, (par3 + par5) * f, (par4 + 0) * f1); - tessellator.addVertexWithUV( - par1 + 0, par2 + 0, this.zLevel, (par3 + 0) * f, (par4 + 0) * f1); - tessellator.setColorRGBA_F(1.0f, 1.0f, 1.0f, 1.0f); - tessellator.draw(); - } catch (final Exception err) { - } - GL11.glPopAttrib(); - } - } - - if (is != null && s instanceof AppEngSlot) { - if (((AppEngSlot) s).getIsValid() == hasCalculatedValidness.NotAvailable) { - boolean isValid = s.isItemValid(is) - || s instanceof SlotOutput - || s instanceof AppEngCraftingSlot - || s instanceof SlotDisabled - || s instanceof SlotInaccessible - || s instanceof SlotFake - || s instanceof SlotRestrictedInput - || s instanceof SlotDisconnected; - if (isValid && s instanceof SlotRestrictedInput) { - try { - isValid = ((SlotRestrictedInput) s).isValid(is, this.mc.theWorld); - } catch (final Exception err) { - WCTLog.debug(err.getMessage()); - } - } - ((AppEngSlot) s) - .setIsValid(isValid ? hasCalculatedValidness.Valid : hasCalculatedValidness.Invalid); - } - - if (((AppEngSlot) s).getIsValid() == hasCalculatedValidness.Invalid) { - this.zLevel = 100.0F; - itemRender.zLevel = 100.0F; - - GL11.glDisable(GL11.GL_LIGHTING); - drawRect( - s.xDisplayPosition, - s.yDisplayPosition, - 16 + s.xDisplayPosition, - 16 + s.yDisplayPosition, - 0x66ff6666); - GL11.glEnable(GL11.GL_LIGHTING); - - this.zLevel = 0.0F; - itemRender.zLevel = 0.0F; - } - } - - if (s instanceof AppEngSlot) { - ((AppEngSlot) s).setDisplay(true); - this.safeDrawSlot(s); - } else { - this.safeDrawSlot(s); - } - - return; - } catch (final Exception err) { - WCTLog.warning("WCT prevented crash while drawing slot: " + err.toString()); - } - } - // do the usual for non-ME Slots. - this.safeDrawSlot(s); - } - - private RenderItem setItemRender(final RenderItem item) { - if (isNEIEnabled) { - return ((INEI) IntegrationRegistry.INSTANCE.getInstance(IntegrationType.NEI)).setItemRender(item); - } else { - final RenderItem ri = itemRender; - itemRender = item; - return ri; - } - } - @Override protected void keyTyped(final char character, final int key) { if (!this.checkHotbarKeys(key)) { @@ -1319,7 +598,7 @@ public class GuiWirelessCraftingTerminal extends GuiContainer implements ISortSo } final boolean mouseInGui = - this.isPointInRegion(0, 0, this.xSize, this.ySize, this.currentMouseX, this.currentMouseY); + this.isPointInRegion(0, 0, this.xSize, this.ySize, this.currentMouseX, this.currentMouseY); if (this.isAutoFocus && !this.searchField.isFocused() && mouseInGui) { this.searchField.setFocused(true); } @@ -1338,42 +617,13 @@ public class GuiWirelessCraftingTerminal extends GuiContainer implements ISortSo return this.repo.hasPower(); } - private void safeDrawSlot(final Slot s) { - try { - GuiContainer.class - .getDeclaredMethod("func_146977_a_original", Slot.class) - .invoke(this, s); - } catch (final Exception err) { - } - } - public void bindTexture(final String file) { final ResourceLocation loc = new ResourceLocation(Reference.MODID, "textures/" + file); this.mc.getTextureManager().bindTexture(loc); } - public void func_146977_a(final Slot s) { - this.drawSlot(s); - } - - protected GuiScrollbar getScrollBar() { - return this.scrollBar; - } - - protected List getMeSlots() { - return this.meSlots; - } - - public static final synchronized boolean isSwitchingGuis() { - return switchingGuis; - } - - public static final synchronized void setSwitchingGuis(final boolean switchingGuis) { - GuiWirelessCraftingTerminal.switchingGuis = switchingGuis; - } - public List handleItemTooltip( - final ItemStack stack, final int mouseX, final int mouseY, final List currentToolTip) { + final ItemStack stack, final int mouseX, final int mouseY, final List currentToolTip) { if (stack != null) { final Slot s = this.getSlot(mouseX, mouseY); if (s instanceof SlotME) { @@ -1391,7 +641,7 @@ public class GuiWirelessCraftingTerminal extends GuiContainer implements ISortSo if (myStack.getStackSize() > BigNumber || (myStack.getStackSize() > 1 && stack.isItemDamaged())) { final String local = ButtonToolTips.ItemsStored.getLocal(); final String formattedAmount = - NumberFormat.getNumberInstance(Locale.US).format(myStack.getStackSize()); + NumberFormat.getNumberInstance(Locale.US).format(myStack.getStackSize()); final String format = String.format(local, formattedAmount); currentToolTip.add("\u00a77" + format); @@ -1400,7 +650,7 @@ public class GuiWirelessCraftingTerminal extends GuiContainer implements ISortSo if (myStack.getCountRequestable() > 0) { final String local = ButtonToolTips.ItemsRequestable.getLocal(); final String formattedAmount = - NumberFormat.getNumberInstance(Locale.US).format(myStack.getCountRequestable()); + NumberFormat.getNumberInstance(Locale.US).format(myStack.getCountRequestable()); final String format = String.format(local, formattedAmount); currentToolTip.add("\u00a77" + format); @@ -1408,7 +658,7 @@ public class GuiWirelessCraftingTerminal extends GuiContainer implements ISortSo } else if (stack.stackSize > BigNumber || (stack.stackSize > 1 && stack.isItemDamaged())) { final String local = ButtonToolTips.ItemsStored.getLocal(); final String formattedAmount = - NumberFormat.getNumberInstance(Locale.US).format(stack.stackSize); + NumberFormat.getNumberInstance(Locale.US).format(stack.stackSize); final String format = String.format(local, formattedAmount); currentToolTip.add("\u00a77" + format); @@ -1435,23 +685,23 @@ public class GuiWirelessCraftingTerminal extends GuiContainer implements ISortSo if (myStack != null) { final List currentToolTip = - stack.getTooltip(this.mc.thePlayer, this.mc.gameSettings.advancedItemTooltips); + stack.getTooltip(this.mc.thePlayer, this.mc.gameSettings.advancedItemTooltips); if (myStack.getStackSize() > BigNumber || (myStack.getStackSize() > 1 && stack.isItemDamaged())) { currentToolTip.add("Items Stored: " - + NumberFormat.getNumberInstance(Locale.US).format(myStack.getStackSize())); + + NumberFormat.getNumberInstance(Locale.US).format(myStack.getStackSize())); } if (myStack.getCountRequestable() > 0) { currentToolTip.add("Items Requestable: " - + NumberFormat.getNumberInstance(Locale.US).format(myStack.getCountRequestable())); + + NumberFormat.getNumberInstance(Locale.US).format(myStack.getCountRequestable())); } this.drawTooltip(x, y, 0, join(currentToolTip, "\n")); } else if (stack.stackSize > BigNumber) { final List var4 = stack.getTooltip(this.mc.thePlayer, this.mc.gameSettings.advancedItemTooltips); var4.add("Items Stored: " - + NumberFormat.getNumberInstance(Locale.US).format(stack.stackSize)); + + NumberFormat.getNumberInstance(Locale.US).format(stack.stackSize)); this.drawTooltip(x, y, 0, join(var4, "\n")); return; } @@ -1522,9 +772,9 @@ public class GuiWirelessCraftingTerminal extends GuiContainer implements ISortSo pointX -= i; pointY -= j; return pointX >= rectX - 1 - && pointX < rectX + rectWidth + 1 - && pointY >= rectY - 1 - && pointY < rectY + rectHeight + 1; + && pointX < rectX + rectWidth + 1 + && pointY >= rectY - 1 + && pointY < rectY + rectHeight + 1; } private boolean isNEIFocused() { @@ -1533,7 +783,7 @@ public class GuiWirelessCraftingTerminal extends GuiContainer implements ISortSo } try { final Class c = - ReflectionHelper.getClass(this.getClass().getClassLoader(), "codechicken.nei.LayoutManager"); + ReflectionHelper.getClass(this.getClass().getClassLoader(), "codechicken.nei.LayoutManager"); final Field fldSearchField = c.getField("searchField"); final TextField searchField = (TextField) fldSearchField.get(c); return searchField.focused(); diff --git a/src/main/java/net/p455w0rd/wirelesscraftingterminal/client/gui/WCTBaseGui.java b/src/main/java/net/p455w0rd/wirelesscraftingterminal/client/gui/WCTBaseGui.java deleted file mode 100644 index fd8d97b..0000000 --- a/src/main/java/net/p455w0rd/wirelesscraftingterminal/client/gui/WCTBaseGui.java +++ /dev/null @@ -1,820 +0,0 @@ -package net.p455w0rd.wirelesscraftingterminal.client.gui; - -import appeng.api.storage.data.IAEItemStack; -import appeng.client.gui.widgets.ITooltip; -import appeng.container.slot.SlotRestrictedInput; -import appeng.helpers.InventoryAction; -import com.google.common.base.Joiner; -import com.google.common.base.Stopwatch; -import cpw.mods.fml.common.Loader; -import cpw.mods.fml.common.ObfuscationReflectionHelper; -import java.text.DecimalFormat; -import java.text.ParseException; -import java.util.Collection; -import java.util.HashSet; -import java.util.Iterator; -import java.util.LinkedList; -import java.util.List; -import java.util.Set; -import java.util.concurrent.TimeUnit; -import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.GuiButton; -import net.minecraft.client.gui.inventory.GuiContainer; -import net.minecraft.client.renderer.RenderHelper; -import net.minecraft.client.renderer.Tessellator; -import net.minecraft.client.renderer.entity.RenderItem; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.inventory.Container; -import net.minecraft.inventory.Slot; -import net.minecraft.item.ItemStack; -import net.minecraft.util.ResourceLocation; -import net.p455w0rd.wirelesscraftingterminal.client.gui.widgets.GuiScrollbar; -import net.p455w0rd.wirelesscraftingterminal.client.me.InternalSlotME; -import net.p455w0rd.wirelesscraftingterminal.client.me.SlotDisconnected; -import net.p455w0rd.wirelesscraftingterminal.client.me.SlotME; -import net.p455w0rd.wirelesscraftingterminal.client.me.WCTRenderItem; -import net.p455w0rd.wirelesscraftingterminal.common.container.WCTBaseContainer; -import net.p455w0rd.wirelesscraftingterminal.common.container.slot.AppEngCraftingSlot; -import net.p455w0rd.wirelesscraftingterminal.common.container.slot.AppEngSlot; -import net.p455w0rd.wirelesscraftingterminal.common.container.slot.AppEngSlot.hasCalculatedValidness; -import net.p455w0rd.wirelesscraftingterminal.common.container.slot.OptionalSlotFake; -import net.p455w0rd.wirelesscraftingterminal.common.container.slot.SlotCraftingTerm; -import net.p455w0rd.wirelesscraftingterminal.common.container.slot.SlotDisabled; -import net.p455w0rd.wirelesscraftingterminal.common.container.slot.SlotFake; -import net.p455w0rd.wirelesscraftingterminal.common.container.slot.SlotInaccessible; -import net.p455w0rd.wirelesscraftingterminal.common.container.slot.SlotOutput; -import net.p455w0rd.wirelesscraftingterminal.common.utils.WCTLog; -import net.p455w0rd.wirelesscraftingterminal.core.sync.network.NetworkHandler; -import net.p455w0rd.wirelesscraftingterminal.core.sync.packets.PacketInventoryAction; -import net.p455w0rd.wirelesscraftingterminal.core.sync.packets.PacketSwapSlots; -import net.p455w0rd.wirelesscraftingterminal.integration.IntegrationRegistry; -import net.p455w0rd.wirelesscraftingterminal.integration.IntegrationType; -import net.p455w0rd.wirelesscraftingterminal.integration.abstraction.INEI; -import org.lwjgl.input.Keyboard; -import org.lwjgl.input.Mouse; -import org.lwjgl.opengl.GL11; -import org.lwjgl.opengl.GL12; - -public abstract class WCTBaseGui extends GuiContainer { - private static boolean switchingGuis; - private final List meSlots = new LinkedList(); - // drag y - private final Set drag_click = new HashSet(); - private final WCTRenderItem aeRenderItem = new WCTRenderItem(); - private GuiScrollbar scrollBar = null; - private boolean disableShiftClick = false; - private Stopwatch dbl_clickTimer = Stopwatch.createStarted(); - private ItemStack dbl_whichItem; - private Slot bl_clicked; - private boolean subGui; - - public WCTBaseGui(final Container container) { - super(container); - this.subGui = switchingGuis; - switchingGuis = false; - } - - protected static String join(final Collection toolTip, final String delimiter) { - final Joiner joiner = Joiner.on(delimiter); - - return joiner.join(toolTip); - } - - protected int getQty(final GuiButton btn) { - try { - final DecimalFormat df = new DecimalFormat("+#;-#"); - return df.parse(btn.displayString).intValue(); - } catch (final ParseException e) { - return 0; - } - } - - public boolean isSubGui() { - return this.subGui; - } - - @Override - public void initGui() { - super.initGui(); - - final List slots = this.getInventorySlots(); - final Iterator i = slots.iterator(); - while (i.hasNext()) { - if (i.next() instanceof SlotME) { - i.remove(); - } - } - - for (final InternalSlotME me : this.meSlots) { - slots.add(new SlotME(me)); - } - } - - @SuppressWarnings("unchecked") - private List getInventorySlots() { - return this.inventorySlots.inventorySlots; - } - - @Override - public void drawScreen(final int mouseX, final int mouseY, final float btn) { - super.drawScreen(mouseX, mouseY, btn); - - final boolean hasClicked = Mouse.isButtonDown(0); - if (hasClicked && this.scrollBar != null) { - this.scrollBar.click(this, mouseX - this.guiLeft, mouseY - this.guiTop); - } - - for (final Object c : this.buttonList) { - if (c instanceof ITooltip) { - final ITooltip tooltip = (ITooltip) c; - final int x = tooltip.xPos(); // ((GuiImgButton) c).xPosition; - int y = tooltip.yPos(); // ((GuiImgButton) c).yPosition; - - if (x < mouseX && x + tooltip.getWidth() > mouseX && tooltip.isVisible()) { - if (y < mouseY && y + tooltip.getHeight() > mouseY) { - if (y < 15) { - y = 15; - } - - final String msg = tooltip.getMessage(); - if (msg != null) { - this.drawTooltip(x + 11, y + 4, 0, msg); - } - } - } - } - } - } - - public void drawTooltip(final int par2, final int par3, final int forceWidth, final String message) { - GL11.glPushAttrib(GL11.GL_ALL_ATTRIB_BITS); - GL11.glDisable(GL12.GL_RESCALE_NORMAL); - RenderHelper.disableStandardItemLighting(); - GL11.glDisable(GL11.GL_LIGHTING); - GL11.glDisable(GL11.GL_DEPTH_TEST); - final String[] var4 = message.split("\n"); - - if (var4.length > 0) { - int var5 = 0; - int var6; - int var7; - - for (var6 = 0; var6 < var4.length; ++var6) { - var7 = this.fontRendererObj.getStringWidth(var4[var6]); - - if (var7 > var5) { - var5 = var7; - } - } - - var6 = par2 + 12; - var7 = par3 - 12; - int var9 = 8; - - if (var4.length > 1) { - var9 += 2 + (var4.length - 1) * 10; - } - - if (this.guiTop + var7 + var9 + 6 > this.height) { - var7 = this.height - var9 - this.guiTop - 6; - } - - if (forceWidth > 0) { - var5 = forceWidth; - } - - this.zLevel = 300.0F; - itemRender.zLevel = 300.0F; - final int var10 = -267386864; - this.drawGradientRect(var6 - 3, var7 - 4, var6 + var5 + 3, var7 - 3, var10, var10); - this.drawGradientRect(var6 - 3, var7 + var9 + 3, var6 + var5 + 3, var7 + var9 + 4, var10, var10); - this.drawGradientRect(var6 - 3, var7 - 3, var6 + var5 + 3, var7 + var9 + 3, var10, var10); - this.drawGradientRect(var6 - 4, var7 - 3, var6 - 3, var7 + var9 + 3, var10, var10); - this.drawGradientRect(var6 + var5 + 3, var7 - 3, var6 + var5 + 4, var7 + var9 + 3, var10, var10); - final int var11 = 1347420415; - final int var12 = (var11 & 16711422) >> 1 | var11 & -16777216; - this.drawGradientRect(var6 - 3, var7 - 3 + 1, var6 - 3 + 1, var7 + var9 + 3 - 1, var11, var12); - this.drawGradientRect(var6 + var5 + 2, var7 - 3 + 1, var6 + var5 + 3, var7 + var9 + 3 - 1, var11, var12); - this.drawGradientRect(var6 - 3, var7 - 3, var6 + var5 + 3, var7 - 3 + 1, var11, var11); - this.drawGradientRect(var6 - 3, var7 + var9 + 2, var6 + var5 + 3, var7 + var9 + 3, var12, var12); - - for (int var13 = 0; var13 < var4.length; ++var13) { - String var14 = var4[var13]; - - if (var13 == 0) { - var14 = '\u00a7' + Integer.toHexString(15) + var14; - } else { - var14 = "\u00a77" + var14; - } - - this.fontRendererObj.drawStringWithShadow(var14, var6, var7, -1); - - if (var13 == 0) { - var7 += 2; - } - - var7 += 10; - } - - this.zLevel = 0.0F; - itemRender.zLevel = 0.0F; - } - GL11.glPopAttrib(); - } - - @Override - protected final void drawGuiContainerForegroundLayer(final int x, final int y) { - final int ox = this.guiLeft; // (width - xSize) / 2; - final int oy = this.guiTop; // (height - ySize) / 2; - GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); - - if (this.scrollBar != null) { - this.scrollBar.draw(this); - } - - this.drawFG(ox, oy, x, y); - } - - public abstract void drawFG(int offsetX, int offsetY, int mouseX, int mouseY); - - @Override - protected final void drawGuiContainerBackgroundLayer(final float f, final int x, final int y) { - final int ox = this.guiLeft; // (width - xSize) / 2; - final int oy = this.guiTop; // (height - ySize) / 2; - GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); - this.drawBG(ox, oy, x, y); - - final List slots = this.getInventorySlots(); - for (final Slot slot : slots) { - if (slot instanceof OptionalSlotFake) { - final OptionalSlotFake fs = (OptionalSlotFake) slot; - if (fs.renderDisabled()) { - if (fs.isEnabled()) { - this.drawTexturedModalRect( - ox + fs.xDisplayPosition - 1, - oy + fs.yDisplayPosition - 1, - fs.getSourceX() - 1, - fs.getSourceY() - 1, - 18, - 18); - } else { - GL11.glPushAttrib(GL11.GL_ALL_ATTRIB_BITS); - GL11.glColor4f(1.0F, 1.0F, 1.0F, 0.4F); - GL11.glEnable(GL11.GL_BLEND); - this.drawTexturedModalRect( - ox + fs.xDisplayPosition - 1, - oy + fs.yDisplayPosition - 1, - fs.getSourceX() - 1, - fs.getSourceY() - 1, - 18, - 18); - GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); - GL11.glPopAttrib(); - } - } - } - } - } - - @Override - protected void mouseClicked(final int xCoord, final int yCoord, final int btn) { - this.drag_click.clear(); - - if (btn == 1) { - for (final Object o : this.buttonList) { - final GuiButton guibutton = (GuiButton) o; - if (guibutton.mousePressed(this.mc, xCoord, yCoord)) { - super.mouseClicked(xCoord, yCoord, 0); - return; - } - } - } - - super.mouseClicked(xCoord, yCoord, btn); - } - - @Override - protected void mouseClickMove(final int x, final int y, final int c, final long d) { - final Slot slot = this.getSlot(x, y); - final ItemStack itemstack = this.mc.thePlayer.inventory.getItemStack(); - - if (slot instanceof SlotFake && itemstack != null) { - this.drag_click.add(slot); - if (this.drag_click.size() > 1) { - for (final Slot dr : this.drag_click) { - final PacketInventoryAction p = new PacketInventoryAction( - c == 0 ? InventoryAction.PICKUP_OR_SET_DOWN : InventoryAction.PLACE_SINGLE, - dr.slotNumber, - 0); - NetworkHandler.instance.sendToServer(p); - } - } - } else { - super.mouseClickMove(x, y, c, d); - } - } - - @Override - protected void handleMouseClick(final Slot slot, final int slotIdx, final int ctrlDown, final int key) { - final EntityPlayer player = Minecraft.getMinecraft().thePlayer; - - if (slot instanceof SlotFake) { - final InventoryAction action = - ctrlDown == 1 ? InventoryAction.SPLIT_OR_PLACE_SINGLE : InventoryAction.PICKUP_OR_SET_DOWN; - - if (this.drag_click.size() > 1) { - return; - } - - final PacketInventoryAction p = new PacketInventoryAction(action, slotIdx, 0); - NetworkHandler.instance.sendToServer(p); - - return; - } - - if (slot instanceof SlotCraftingTerm) { - if (key == 6) { - return; // prevent weird double clicks.. - } - - InventoryAction action = null; - if (key == 1) { - action = InventoryAction.CRAFT_SHIFT; - } else { - action = ctrlDown == 1 ? InventoryAction.CRAFT_STACK : InventoryAction.CRAFT_ITEM; - } - - final PacketInventoryAction p = new PacketInventoryAction(action, slotIdx, 0); - NetworkHandler.instance.sendToServer(p); - - return; - } - - if (Keyboard.isKeyDown(Keyboard.KEY_SPACE)) { - if (this.enableSpaceClicking()) { - IAEItemStack stack = null; - if (slot instanceof SlotME) { - stack = ((SlotME) slot).getAEStack(); - } - - int slotNum = this.getInventorySlots().size(); - - if (!(slot instanceof SlotME) && slot != null) { - slotNum = slot.slotNumber; - } - - ((WCTBaseContainer) this.inventorySlots).setTargetStack(stack); - final PacketInventoryAction p = new PacketInventoryAction(InventoryAction.MOVE_REGION, slotNum, 0); - NetworkHandler.instance.sendToServer(p); - return; - } - } - - if (slot instanceof SlotDisconnected) { - InventoryAction action = null; - - switch (key) { - case 0: // pickup / set-down. - action = ctrlDown == 1 ? InventoryAction.SPLIT_OR_PLACE_SINGLE : InventoryAction.PICKUP_OR_SET_DOWN; - break; - case 1: - action = ctrlDown == 1 ? InventoryAction.PICKUP_SINGLE : InventoryAction.SHIFT_CLICK; - break; - - case 3: // creative dupe: - if (player.capabilities.isCreativeMode) { - action = InventoryAction.CREATIVE_DUPLICATE; - } - - break; - - default: - case 4: // drop item: - case 6: - } - - if (action != null) { - final PacketInventoryAction p = new PacketInventoryAction( - action, - slot.getSlotIndex(), - ((SlotDisconnected) slot).getSlot().getId()); - NetworkHandler.instance.sendToServer(p); - } - - return; - } - - if (slot instanceof SlotME) { - InventoryAction action = null; - IAEItemStack stack = null; - - switch (key) { - case 0: // pickup / set-down. - action = ctrlDown == 1 ? InventoryAction.SPLIT_OR_PLACE_SINGLE : InventoryAction.PICKUP_OR_SET_DOWN; - stack = ((SlotME) slot).getAEStack(); - - if (stack != null - && action == InventoryAction.PICKUP_OR_SET_DOWN - && stack.getStackSize() == 0 - && player.inventory.getItemStack() == null) { - action = InventoryAction.AUTO_CRAFT; - } - - break; - case 1: - action = ctrlDown == 1 ? InventoryAction.PICKUP_SINGLE : InventoryAction.SHIFT_CLICK; - stack = ((SlotME) slot).getAEStack(); - break; - - case 3: // creative dupe: - stack = ((SlotME) slot).getAEStack(); - if (stack != null && stack.isCraftable()) { - action = InventoryAction.AUTO_CRAFT; - } else if (player.capabilities.isCreativeMode) { - final IAEItemStack slotItem = ((SlotME) slot).getAEStack(); - if (slotItem != null) { - action = InventoryAction.CREATIVE_DUPLICATE; - } - } - break; - - default: - case 4: // drop item: - case 6: - } - - if (action != null) { - ((WCTBaseContainer) this.inventorySlots).setTargetStack(stack); - final PacketInventoryAction p = new PacketInventoryAction( - action, this.getInventorySlots().size(), 0); - NetworkHandler.instance.sendToServer(p); - } - - return; - } - - if (!this.disableShiftClick && isShiftKeyDown()) { - this.disableShiftClick = true; - - if (this.dbl_whichItem == null - || this.bl_clicked != slot - || this.dbl_clickTimer.elapsed(TimeUnit.MILLISECONDS) > 150) { - // some simple double click logic. - this.bl_clicked = slot; - this.dbl_clickTimer = Stopwatch.createStarted(); - if (slot != null) { - this.dbl_whichItem = slot.getHasStack() ? slot.getStack().copy() : null; - } else { - this.dbl_whichItem = null; - } - } else if (this.dbl_whichItem != null) { - // a replica of the weird broken vanilla feature. - - final List slots = this.getInventorySlots(); - for (final Slot inventorySlot : slots) { - if (inventorySlot != null - && inventorySlot.canTakeStack(this.mc.thePlayer) - && inventorySlot.getHasStack() - && inventorySlot.inventory == slot.inventory - && Container.func_94527_a(inventorySlot, this.dbl_whichItem, true)) { - this.handleMouseClick(inventorySlot, inventorySlot.slotNumber, ctrlDown, 1); - } - } - } - - this.disableShiftClick = false; - } - - super.handleMouseClick(slot, slotIdx, ctrlDown, key); - } - - @Override - protected boolean checkHotbarKeys(final int keyCode) { - final Slot theSlot; - - try { - theSlot = ObfuscationReflectionHelper.getPrivateValue( - GuiContainer.class, this, "theSlot", "field_147006_u", "f"); - } catch (final Throwable t) { - return false; - } - - if (this.mc.thePlayer.inventory.getItemStack() == null && theSlot != null) { - for (int j = 0; j < 9; ++j) { - if (keyCode == this.mc.gameSettings.keyBindsHotbar[j].getKeyCode()) { - final List slots = this.getInventorySlots(); - for (final Slot s : slots) { - if (s.getSlotIndex() == j - && s.inventory == ((WCTBaseContainer) this.inventorySlots).getPlayerInv()) { - if (!s.canTakeStack(((WCTBaseContainer) this.inventorySlots).getPlayerInv().player)) { - return false; - } - } - } - - if (theSlot.getSlotStackLimit() == 64) { - this.handleMouseClick(theSlot, theSlot.slotNumber, j, 2); - return true; - } else { - for (final Slot s : slots) { - if (s.getSlotIndex() == j - && s.inventory == ((WCTBaseContainer) this.inventorySlots).getPlayerInv()) { - NetworkHandler.instance.sendToServer( - new PacketSwapSlots(s.slotNumber, theSlot.slotNumber)); - return true; - } - } - } - } - } - } - - return false; - } - - @Override - public void onGuiClosed() { - super.onGuiClosed(); - this.subGui = true; // in case the gui is reopened later ( i'm looking at you NEI ) - } - - protected Slot getSlot(final int mouseX, final int mouseY) { - final List slots = this.getInventorySlots(); - for (final Slot slot : slots) { - // isPointInRegion - if (this.func_146978_c(slot.xDisplayPosition, slot.yDisplayPosition, 16, 16, mouseX, mouseY)) { - return slot; - } - } - - return null; - } - - public abstract void drawBG(int offsetX, int offsetY, int mouseX, int mouseY); - - @Override - public void handleMouseInput() { - super.handleMouseInput(); - - final int i = Mouse.getEventDWheel(); - if (i != 0 && isShiftKeyDown()) { - final int x = Mouse.getEventX() * this.width / this.mc.displayWidth; - final int y = this.height - Mouse.getEventY() * this.height / this.mc.displayHeight - 1; - this.mouseWheelEvent(x, y, i / Math.abs(i)); - } else if (i != 0 && this.scrollBar != null) { - this.scrollBar.wheel(i); - } - } - - private void mouseWheelEvent(final int x, final int y, final int wheel) { - final Slot slot = this.getSlot(x, y); - if (slot instanceof SlotME) { - final IAEItemStack item = ((SlotME) slot).getAEStack(); - if (item != null) { - ((WCTBaseContainer) this.inventorySlots).setTargetStack(item); - final InventoryAction direction = wheel > 0 ? InventoryAction.ROLL_DOWN : InventoryAction.ROLL_UP; - final int times = Math.abs(wheel); - final int inventorySize = this.getInventorySlots().size(); - for (int h = 0; h < times; h++) { - final PacketInventoryAction p = new PacketInventoryAction(direction, inventorySize, 0); - NetworkHandler.instance.sendToServer(p); - } - } - } - } - - protected boolean enableSpaceClicking() { - return true; - } - - public void bindTexture(final String base, final String file) { - final ResourceLocation loc = new ResourceLocation(base, "textures/" + file); - this.mc.getTextureManager().bindTexture(loc); - } - - protected void drawItem(final int x, final int y, final ItemStack is) { - this.zLevel = 100.0F; - itemRender.zLevel = 100.0F; - - GL11.glPushAttrib(GL11.GL_ALL_ATTRIB_BITS); - GL11.glEnable(GL11.GL_LIGHTING); - GL11.glEnable(GL12.GL_RESCALE_NORMAL); - GL11.glEnable(GL11.GL_DEPTH_TEST); - RenderHelper.enableGUIStandardItemLighting(); - itemRender.renderItemAndEffectIntoGUI(this.fontRendererObj, this.mc.renderEngine, is, x, y); - GL11.glPopAttrib(); - - itemRender.zLevel = 0.0F; - this.zLevel = 0.0F; - } - - protected String getGuiDisplayName(final String in) { - return this.hasCustomInventoryName() ? this.getInventoryName() : in; - } - - private boolean hasCustomInventoryName() { - if (this.inventorySlots instanceof WCTBaseContainer) { - return ((WCTBaseContainer) this.inventorySlots).getCustomName() != null; - } - return false; - } - - private String getInventoryName() { - return ((WCTBaseContainer) this.inventorySlots).getCustomName(); - } - - private void drawSlot(final Slot s) { - if (s instanceof SlotME) { - final RenderItem pIR = this.setItemRender(this.aeRenderItem); - try { - this.zLevel = 100.0F; - itemRender.zLevel = 100.0F; - - if (!this.isPowered()) { - GL11.glDisable(GL11.GL_LIGHTING); - drawRect( - s.xDisplayPosition, - s.yDisplayPosition, - 16 + s.xDisplayPosition, - 16 + s.yDisplayPosition, - 0x66111111); - GL11.glEnable(GL11.GL_LIGHTING); - } - - this.zLevel = 0.0F; - itemRender.zLevel = 0.0F; - - this.aeRenderItem.setAeStack(((SlotME) s).getAEStack()); - - this.safeDrawSlot(s); - } catch (final Exception err) { - WCTLog.warning("WCT prevented crash while drawing slot: " + err.toString()); - } - this.setItemRender(pIR); - return; - } else { - try { - final ItemStack is = s.getStack(); - if (s instanceof AppEngSlot - && (((AppEngSlot) s).renderIconWithItem() || is == null) - && (((AppEngSlot) s).shouldDisplay())) { - final AppEngSlot aes = (AppEngSlot) s; - if (aes.getIcon() >= 0) { - this.bindTexture("guis/states.png"); - - GL11.glPushAttrib(GL11.GL_ALL_ATTRIB_BITS); - final Tessellator tessellator = Tessellator.instance; - try { - final int uv_y = (int) Math.floor(aes.getIcon() / 16); - final int uv_x = aes.getIcon() - uv_y * 16; - - GL11.glEnable(GL11.GL_BLEND); - GL11.glDisable(GL11.GL_LIGHTING); - GL11.glEnable(GL11.GL_TEXTURE_2D); - GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); - GL11.glColor4f(1.0f, 1.0f, 1.0f, 1.0f); - final float par1 = aes.xDisplayPosition; - final float par2 = aes.yDisplayPosition; - final float par3 = uv_x * 16; - final float par4 = uv_y * 16; - - tessellator.startDrawingQuads(); - tessellator.setColorRGBA_F(1.0f, 1.0f, 1.0f, aes.getOpacityOfIcon()); - final float f1 = 0.00390625F; - final float f = 0.00390625F; - final float par6 = 16; - tessellator.addVertexWithUV( - par1 + 0, par2 + par6, this.zLevel, (par3 + 0) * f, (par4 + par6) * f1); - final float par5 = 16; - tessellator.addVertexWithUV( - par1 + par5, par2 + par6, this.zLevel, (par3 + par5) * f, (par4 + par6) * f1); - tessellator.addVertexWithUV( - par1 + par5, par2 + 0, this.zLevel, (par3 + par5) * f, (par4 + 0) * f1); - tessellator.addVertexWithUV( - par1 + 0, par2 + 0, this.zLevel, (par3 + 0) * f, (par4 + 0) * f1); - tessellator.setColorRGBA_F(1.0f, 1.0f, 1.0f, 1.0f); - tessellator.draw(); - } catch (final Exception err) { - } - GL11.glPopAttrib(); - } - } - - if (is != null && s instanceof AppEngSlot) { - if (((AppEngSlot) s).getIsValid() == hasCalculatedValidness.NotAvailable) { - boolean isValid = s.isItemValid(is) - || s instanceof SlotOutput - || s instanceof AppEngCraftingSlot - || s instanceof SlotDisabled - || s instanceof SlotInaccessible - || s instanceof SlotFake - || s instanceof SlotRestrictedInput - || s instanceof SlotDisconnected; - if (isValid && s instanceof SlotRestrictedInput) { - try { - isValid = ((SlotRestrictedInput) s).isValid(is, this.mc.theWorld); - } catch (final Exception err) { - WCTLog.debug(err.getMessage()); - } - } - ((AppEngSlot) s) - .setIsValid(isValid ? hasCalculatedValidness.Valid : hasCalculatedValidness.Invalid); - } - - if (((AppEngSlot) s).getIsValid() == hasCalculatedValidness.Invalid) { - this.zLevel = 100.0F; - itemRender.zLevel = 100.0F; - - GL11.glDisable(GL11.GL_LIGHTING); - drawRect( - s.xDisplayPosition, - s.yDisplayPosition, - 16 + s.xDisplayPosition, - 16 + s.yDisplayPosition, - 0x66ff6666); - GL11.glEnable(GL11.GL_LIGHTING); - - this.zLevel = 0.0F; - itemRender.zLevel = 0.0F; - } - } - - if (s instanceof AppEngSlot) { - ((AppEngSlot) s).setDisplay(true); - this.safeDrawSlot(s); - } else { - this.safeDrawSlot(s); - } - - return; - } catch (final Exception err) { - WCTLog.warning("WCT prevented crash while drawing slot: " + err.toString()); - } - } - // do the usual for non-ME Slots. - this.safeDrawSlot(s); - } - - private RenderItem setItemRender(final RenderItem item) { - if (Loader.isModLoaded("NotEnoughItems")) { - return ((INEI) IntegrationRegistry.INSTANCE.getInstance(IntegrationType.NEI)).setItemRender(item); - } else { - final RenderItem ri = itemRender; - itemRender = item; - return ri; - } - } - - protected boolean isPowered() { - return true; - } - - private void safeDrawSlot(final Slot s) { - try { - GuiContainer.class - .getDeclaredMethod("func_146977_a_original", Slot.class) - .invoke(this, s); - } catch (final Exception err) { - } - } - - public void bindTexture(final String file) { - final ResourceLocation loc = new ResourceLocation("appliedenergistics2", "textures/" + file); - this.mc.getTextureManager().bindTexture(loc); - } - - public void func_146977_a(final Slot s) { - this.drawSlot(s); - } - - protected GuiScrollbar getScrollBar() { - return this.scrollBar; - } - - protected void setScrollBar(final GuiScrollbar myScrollBar) { - this.scrollBar = myScrollBar; - } - - protected List getMeSlots() { - return this.meSlots; - } - - public static final synchronized boolean isSwitchingGuis() { - return switchingGuis; - } - - public static final synchronized void setSwitchingGuis(final boolean switchingGuis) { - WCTBaseGui.switchingGuis = switchingGuis; - } - - protected void addItemTooltip(ItemStack is, List lineList) { - if (isShiftKeyDown()) { - List l = is.getTooltip(this.mc.thePlayer, this.mc.gameSettings.advancedItemTooltips); - if (!l.isEmpty()) l.remove(0); - lineList.addAll(l); - } else { - // TODO: update AE2 on maven and dependency in build gradle - // lineList.add(GuiText.HoldShiftForTooltip.getLocal()); - } - } -} diff --git a/src/main/java/net/p455w0rd/wirelesscraftingterminal/client/gui/widgets/GuiScrollbar.java b/src/main/java/net/p455w0rd/wirelesscraftingterminal/client/gui/widgets/GuiScrollbar.java deleted file mode 100644 index bc28939..0000000 --- a/src/main/java/net/p455w0rd/wirelesscraftingterminal/client/gui/widgets/GuiScrollbar.java +++ /dev/null @@ -1,119 +0,0 @@ -package net.p455w0rd.wirelesscraftingterminal.client.gui.widgets; - -import appeng.client.gui.widgets.IScrollSource; -import net.minecraft.client.gui.inventory.GuiContainer; -import net.p455w0rd.wirelesscraftingterminal.client.gui.GuiWirelessCraftingTerminal; -import net.p455w0rd.wirelesscraftingterminal.client.gui.WCTBaseGui; -import org.lwjgl.opengl.GL11; - -public class GuiScrollbar implements IScrollSource { - - private int displayX = 0; - private int displayY = 0; - private int width = 12; - private int height = 16; - private int pageSize = 1; - - private int maxScroll = 0; - private int minScroll = 0; - private int currentScroll = 0; - - public void draw(final GuiContainer g) { - if (g instanceof GuiWirelessCraftingTerminal) { - ((GuiWirelessCraftingTerminal) g).bindTexture("minecraft", "gui/container/creative_inventory/tabs.png"); - - } else if (g instanceof WCTBaseGui) { - ((WCTBaseGui) g).bindTexture("minecraft", "gui/container/creative_inventory/tabs.png"); - } - - GL11.glColor4f(1.0f, 1.0f, 1.0f, 1.0f); - if (this.getRange() == 0) { - g.drawTexturedModalRect(this.displayX, this.displayY, 232 + this.width, 0, this.width, 15); - } else { - final int offset = (this.currentScroll - this.minScroll) * (this.height - 15) / this.getRange(); - g.drawTexturedModalRect(this.displayX, offset + this.displayY, 232, 0, this.width, 15); - } - } - - private int getRange() { - return this.maxScroll - this.minScroll; - } - - public int getLeft() { - return this.displayX; - } - - public GuiScrollbar setLeft(final int v) { - this.displayX = v; - return this; - } - - public int getTop() { - return this.displayY; - } - - public GuiScrollbar setTop(final int v) { - this.displayY = v; - return this; - } - - public int getWidth() { - return this.width; - } - - public GuiScrollbar setWidth(final int v) { - this.width = v; - return this; - } - - public int getHeight() { - return this.height; - } - - public GuiScrollbar setHeight(final int v) { - this.height = v; - return this; - } - - public void setRange(final int min, final int max, final int pageSize) { - this.minScroll = min; - this.maxScroll = max; - this.pageSize = pageSize; - - if (this.minScroll > this.maxScroll) { - this.maxScroll = this.minScroll; - } - - this.applyRange(); - } - - private void applyRange() { - this.currentScroll = Math.max(Math.min(this.currentScroll, this.maxScroll), this.minScroll); - } - - @Override - public int getCurrentScroll() { - return this.currentScroll; - } - - public void click(final GuiContainer aeBaseGui, final int x, final int y) { - if (this.getRange() == 0) { - return; - } - - if (x > this.displayX && x <= this.displayX + this.width) { - if (y > this.displayY && y <= this.displayY + this.height) { - this.currentScroll = (y - this.displayY); - this.currentScroll = this.minScroll + ((this.currentScroll * 2 * this.getRange() / this.height)); - this.currentScroll = (this.currentScroll + 1) >> 1; - this.applyRange(); - } - } - } - - public void wheel(int delta) { - delta = Math.max(Math.min(-delta, 1), -1); - this.currentScroll += delta * this.pageSize; - this.applyRange(); - } -} diff --git a/src/main/java/net/p455w0rd/wirelesscraftingterminal/common/container/ContainerOpenContext.java b/src/main/java/net/p455w0rd/wirelesscraftingterminal/common/container/ContainerOpenContext.java deleted file mode 100644 index 221c9a8..0000000 --- a/src/main/java/net/p455w0rd/wirelesscraftingterminal/common/container/ContainerOpenContext.java +++ /dev/null @@ -1,68 +0,0 @@ -package net.p455w0rd.wirelesscraftingterminal.common.container; - -import appeng.api.parts.IPart; -import net.minecraft.tileentity.TileEntity; -import net.minecraft.world.World; -import net.minecraftforge.common.util.ForgeDirection; - -public class ContainerOpenContext { - - private final boolean isItem; - private World w; - private int x; - private int y; - private int z; - private ForgeDirection side; - - public ContainerOpenContext(final Object myItem) { - final boolean isWorld = myItem instanceof IPart || myItem instanceof TileEntity; - this.isItem = !isWorld; - } - - public TileEntity getTile() { - if (this.isItem) { - return null; - } - return this.getWorld().getTileEntity(this.getX(), this.getY(), this.getZ()); - } - - public ForgeDirection getSide() { - return this.side; - } - - public void setSide(final ForgeDirection side) { - this.side = side; - } - - private int getZ() { - return this.z; - } - - public void setZ(final int z) { - this.z = z; - } - - private int getY() { - return this.y; - } - - public void setY(final int y) { - this.y = y; - } - - private int getX() { - return this.x; - } - - public void setX(final int x) { - this.x = x; - } - - private World getWorld() { - return this.w; - } - - public void setWorld(final World w) { - this.w = w; - } -} diff --git a/src/main/java/net/p455w0rd/wirelesscraftingterminal/common/container/ContainerWirelessCraftingTerminal.java b/src/main/java/net/p455w0rd/wirelesscraftingterminal/common/container/ContainerWirelessCraftingTerminal.java index 8bc7da0..0fb14f5 100644 --- a/src/main/java/net/p455w0rd/wirelesscraftingterminal/common/container/ContainerWirelessCraftingTerminal.java +++ b/src/main/java/net/p455w0rd/wirelesscraftingterminal/common/container/ContainerWirelessCraftingTerminal.java @@ -14,11 +14,9 @@ import appeng.api.networking.IGrid; import appeng.api.networking.IGridHost; import appeng.api.networking.IGridNode; import appeng.api.networking.energy.IEnergyGrid; -import appeng.api.networking.energy.IEnergySource; import appeng.api.networking.security.BaseActionSource; -import appeng.api.networking.security.ISecurityGrid; +import appeng.api.networking.security.IActionHost; import appeng.api.networking.storage.IBaseMonitor; -import appeng.api.storage.IMEInventoryHandler; import appeng.api.storage.IMEMonitor; import appeng.api.storage.IMEMonitorHandlerReceiver; import appeng.api.storage.data.IAEItemStack; @@ -27,11 +25,12 @@ import appeng.api.util.IConfigManager; import appeng.api.util.IConfigurableObject; import appeng.client.me.InternalSlotME; import appeng.client.me.SlotME; +import appeng.container.AEBaseContainer; import appeng.container.ContainerNull; +import appeng.container.slot.AppEngSlot; import appeng.core.AEConfig; import appeng.core.localization.PlayerMessages; import appeng.helpers.IContainerCraftingPacket; -import appeng.helpers.ICustomNameObject; import appeng.helpers.InventoryAction; import appeng.tile.inventory.AppEngInternalInventory; import appeng.tile.inventory.IAEAppEngInventory; @@ -41,22 +40,9 @@ import appeng.util.IConfigManagerHost; import appeng.util.InventoryAdaptor; import appeng.util.Platform; import appeng.util.inv.AdaptorPlayerHand; -import appeng.util.item.AEItemStack; -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.lang.reflect.Field; -import java.nio.BufferOverflowException; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.HashSet; -import java.util.LinkedList; -import java.util.List; -import javax.annotation.Nonnull; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.entity.player.InventoryPlayer; -import net.minecraft.inventory.Container; import net.minecraft.inventory.ICrafting; import net.minecraft.inventory.IInventory; import net.minecraft.inventory.InventoryCrafting; @@ -66,7 +52,6 @@ import net.minecraft.item.ItemArmor; import net.minecraft.item.ItemStack; import net.minecraft.item.crafting.CraftingManager; import net.minecraft.item.crafting.IRecipe; -import net.minecraft.nbt.CompressedStreamTools; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; import net.minecraft.util.ChatComponentText; @@ -74,12 +59,7 @@ import net.minecraft.world.World; import net.minecraftforge.common.util.ForgeDirection; import net.p455w0rd.wirelesscraftingterminal.api.IWirelessCraftingTermHandler; import net.p455w0rd.wirelesscraftingterminal.api.IWirelessCraftingTerminalItem; -import net.p455w0rd.wirelesscraftingterminal.api.networking.security.WCTIActionHost; -import net.p455w0rd.wirelesscraftingterminal.api.networking.security.WCTPlayerSource; -import net.p455w0rd.wirelesscraftingterminal.common.container.guisync.GuiSync; -import net.p455w0rd.wirelesscraftingterminal.common.container.guisync.SyncData; import net.p455w0rd.wirelesscraftingterminal.common.container.slot.AppEngCraftingSlot; -import net.p455w0rd.wirelesscraftingterminal.common.container.slot.AppEngSlot; import net.p455w0rd.wirelesscraftingterminal.common.container.slot.NullSlot; import net.p455w0rd.wirelesscraftingterminal.common.container.slot.SlotArmor; import net.p455w0rd.wirelesscraftingterminal.common.container.slot.SlotBooster; @@ -101,9 +81,7 @@ import net.p455w0rd.wirelesscraftingterminal.common.inventory.WCTInventoryViewCe import net.p455w0rd.wirelesscraftingterminal.common.utils.RandomUtils; import net.p455w0rd.wirelesscraftingterminal.common.utils.WCTLog; import net.p455w0rd.wirelesscraftingterminal.core.sync.network.NetworkHandler; -import net.p455w0rd.wirelesscraftingterminal.core.sync.packets.PacketInventoryAction; import net.p455w0rd.wirelesscraftingterminal.core.sync.packets.PacketMEInventoryUpdate; -import net.p455w0rd.wirelesscraftingterminal.core.sync.packets.PacketPartialItem; import net.p455w0rd.wirelesscraftingterminal.core.sync.packets.PacketValueConfig; import net.p455w0rd.wirelesscraftingterminal.handlers.LocaleHandler; import net.p455w0rd.wirelesscraftingterminal.helpers.WirelessTerminalGuiObject; @@ -111,13 +89,20 @@ import net.p455w0rd.wirelesscraftingterminal.items.ItemInfinityBooster; import net.p455w0rd.wirelesscraftingterminal.items.ItemMagnet; import net.p455w0rd.wirelesscraftingterminal.reference.Reference; -public class ContainerWirelessCraftingTerminal extends Container - implements IConfigManagerHost, - IConfigurableObject, - IMEMonitorHandlerReceiver, - IAEAppEngInventory, - IContainerCraftingPacket, - IViewCellStorage { +import javax.annotation.Nonnull; +import java.io.IOException; +import java.nio.BufferOverflowException; +import java.util.ArrayList; +import java.util.LinkedList; +import java.util.List; + +public class ContainerWirelessCraftingTerminal extends AEBaseContainer + implements IConfigManagerHost, + IConfigurableObject, + IMEMonitorHandlerReceiver, + IAEAppEngInventory, + IContainerCraftingPacket, + IViewCellStorage { private final ItemStack containerstack; public final WCTInventoryCrafting craftingGrid; @@ -127,37 +112,35 @@ public class ContainerWirelessCraftingTerminal extends Container public final WCTInventoryTrash trashInventory; public final InventoryPlayer inventoryPlayer; public ItemStack[] craftMatrixInventory; - public ItemStack craftItem; - private World worldObj; - private EntityPlayer player; + private final World worldObj; + private final EntityPlayer player; private static final int HOTBAR_START = 1, - HOTBAR_END = HOTBAR_START + 8, - INV_START = HOTBAR_END + 1, - INV_END = INV_START + 26, - ARMOR_START = INV_END + 1, - ARMOR_END = ARMOR_START + 3, - CRAFT_GRID_START = ARMOR_END + 1, - CRAFT_GRID_END = CRAFT_GRID_START + 8, - CRAFT_RESULT = CRAFT_GRID_END + 1, - VIEW_CELL_START = CRAFT_RESULT + 1, - VIEW_CELL_END = VIEW_CELL_START + 4, - BOOSTER_INDEX = 0, - MAGNET_INDEX = VIEW_CELL_END + 1; + HOTBAR_END = HOTBAR_START + 8, + INV_START = HOTBAR_END + 1, + INV_END = INV_START + 26, + ARMOR_START = INV_END + 1, + ARMOR_END = ARMOR_START + 3, + CRAFT_GRID_START = ARMOR_END + 1, + CRAFT_GRID_END = CRAFT_GRID_START + 8, + CRAFT_RESULT = CRAFT_GRID_END + 1, + VIEW_CELL_START = CRAFT_RESULT + 1, + VIEW_CELL_END = VIEW_CELL_START + 4, + BOOSTER_INDEX = 0, + MAGNET_INDEX = VIEW_CELL_END + 1; public static int CRAFTING_SLOT_X_POS = 80, CRAFTING_SLOT_Y_POS = 83; private SlotBooster boosterSlot; - private SlotMagnet magnetSlot; + private final SlotMagnet magnetSlot; private NullSlot nullSlot; - private Slot[] hotbarSlot; - private Slot[] inventorySlot; - private SlotArmor[] armorSlot; - private SlotCraftingMatrix[] craftMatrixSlot; - private SlotCraftingTerm craftingSlot; - private SlotViewCell[] viewCellSlot; + private final Slot[] hotbarSlot; + private final Slot[] inventorySlot; + private final SlotArmor[] armorSlot; + private final SlotCraftingMatrix[] craftMatrixSlot; + private final SlotCraftingTerm craftingSlot; + private final SlotViewCell[] viewCellSlot; public SlotTrash trashSlot; private int firstCraftingSlotNumber = -1, lastCraftingSlotNumber = -1; private final WirelessTerminalGuiObject obj; - private boolean isContainerValid = true; private double powerMultiplier = 0.5; private final IPortableCell civ; private int ticks = 0; @@ -165,25 +148,11 @@ public class ContainerWirelessCraftingTerminal extends Container private final IItemList items = AEApi.instance().storage().createItemList(); private final IConfigManager clientCM; private IConfigManager serverCM; - private IEnergySource powerSrc; - - @GuiSync(98) - public static boolean hasPower = false; private IConfigManagerHost gui; - private final BaseActionSource mySrc; - private final HashMap syncData = new HashMap(); - private final List dataChunks = new LinkedList(); - private IAEItemStack clientRequestedTargetItem = null; - private int ticksSinceCheck = 900; - private String customName; - private boolean sentCustomName; - private ContainerOpenContext openContext; private final AppEngInternalInventory output = new AppEngInternalInventory(this, 1); - private final HashSet locked = new HashSet(); - private IWirelessCraftingTerminalItem thisItem; - private IGridNode networkNode; - private IMEInventoryHandler cellInv; + private final IWirelessCraftingTerminalItem thisItem; + private final IGridNode networkNode; private IRecipe currentRecipe; /** @@ -192,13 +161,12 @@ public class ContainerWirelessCraftingTerminal extends Container * @author p455w0rd */ public ContainerWirelessCraftingTerminal(EntityPlayer player, InventoryPlayer inventoryPlayer) { - + super(inventoryPlayer, getGuiObject(RandomUtils.getWirelessTerm(inventoryPlayer), player, player.worldObj, (int) player.posX, (int) player.posY, (int) player.posZ)); this.clientCM = new ConfigManager(this); this.clientCM.registerSetting(Settings.SORT_BY, SortOrder.NAME); this.clientCM.registerSetting(Settings.VIEW_MODE, ViewItems.ALL); this.clientCM.registerSetting(Settings.SORT_DIRECTION, SortDir.ASCENDING); - this.mySrc = new WCTPlayerSource(inventoryPlayer.player, this.getActionHost()); - this.customName = "WCTContainer"; + this.setCustomName("WCTContainer"); this.boosterInventory = new WCTInventoryBooster(RandomUtils.getWirelessTerm(inventoryPlayer)); this.magnetInventory = new WCTInventoryMagnet(RandomUtils.getWirelessTerm(inventoryPlayer)); @@ -218,13 +186,11 @@ public class ContainerWirelessCraftingTerminal extends Container viewCellSlot = new SlotViewCell[5]; this.obj = - getGuiObject(containerstack, player, worldObj, (int) player.posX, (int) player.posY, (int) player.posZ); - this.civ = (IPortableCell) this.obj; + getGuiObject(containerstack, player, worldObj, (int) player.posX, (int) player.posY, (int) player.posZ); + this.civ = this.obj; final IGridNode node = ((IGridHost) this.obj).getGridNode(ForgeDirection.UNKNOWN); this.networkNode = node; - this.prepareSync(); - if (Platform.isServer()) { this.serverCM = civ.getConfigManager(); this.monitor = civ.getItemInventory(); @@ -232,7 +198,7 @@ public class ContainerWirelessCraftingTerminal extends Container this.monitor.addListener(this, null); setCellInventory(this.monitor); if (civ instanceof IPortableCell) { - setPowerSource((IEnergySource) this.civ); + setPowerSource(this.civ); } } else { this.setValidContainer(false); @@ -260,7 +226,7 @@ public class ContainerWirelessCraftingTerminal extends Container // Add player inventory slots for (int i = 0; i < 3; ++i) { for (int j = 0; j < 9; ++j) { - inventorySlot[k] = new SlotPlayerInv(this.inventoryPlayer, j + i * 9 + 9, j * 18 + 8, 0 + i * 18); + inventorySlot[k] = new SlotPlayerInv(this.inventoryPlayer, j + i * 9 + 9, j * 18 + 8, i * 18); this.addSlotToContainer(inventorySlot[k]); k++; } @@ -276,7 +242,7 @@ public class ContainerWirelessCraftingTerminal extends Container for (int i = 0; i < 3; ++i) { for (int j = 0; j < 3; ++j) { craftMatrixSlot[k] = - new SlotCraftingMatrix(this, this.craftingGrid, j + i * 3, 80 + j * 18, (i * 18) - 76); + new SlotCraftingMatrix(this, this.craftingGrid, j + i * 3, 80 + j * 18, (i * 18) - 76); this.addSlotToContainer(craftMatrixSlot[k]); if (k == 0) { this.firstCraftingSlotNumber = craftMatrixSlot[k].slotNumber; @@ -287,16 +253,16 @@ public class ContainerWirelessCraftingTerminal extends Container this.lastCraftingSlotNumber = craftMatrixSlot[8].slotNumber; craftingSlot = new SlotCraftingTerm( - this.getPlayerInv().player, - this.mySrc, - this.getPowerSource(), - this.obj, - this.craftingGrid, - this.craftingGrid, - this.output, - 174, - -58, - this); + this.getPlayerInv().player, + this.getActionSource(), + this.getPowerSource(), + this.obj, + this.craftingGrid, + this.craftingGrid, + this.output, + 174, + -58, + this); // Add crafting result slot this.addSlotToContainer(craftingSlot); @@ -319,12 +285,6 @@ public class ContainerWirelessCraftingTerminal extends Container thisItem.checkForBooster(containerstack); } - public void setCellInventory(final IMEInventoryHandler cellInv) { - this.cellInv = cellInv; - } - - public void onSlotChange(final Slot s) {} - @Override protected Slot addSlotToContainer(final Slot newSlot) { if (newSlot instanceof AppEngSlot) { @@ -333,7 +293,7 @@ public class ContainerWirelessCraftingTerminal extends Container return super.addSlotToContainer(newSlot); } else { throw new IllegalArgumentException( - "Invalid Slot [" + newSlot + "] for WCT Container instead of AppEngSlot."); + "Invalid Slot [" + newSlot + "] for WCT Container instead of AppEngSlot."); } } @@ -453,7 +413,7 @@ public class ContainerWirelessCraftingTerminal extends Container } // get target item. - final IAEItemStack slotItem = this.clientRequestedTargetItem; + final IAEItemStack slotItem = getTargetStack(); switch (action) { case SHIFT_CLICK: @@ -476,7 +436,7 @@ public class ContainerWirelessCraftingTerminal extends Container } ais = Platform.poweredExtraction( - this.getPowerSource(), this.getCellInventory(), ais, this.getActionSource()); + this.getPowerSource(), this.getCellInventory(), ais, this.getActionSource()); if (ais != null) { adp.addItems(ais.getItemStack()); } @@ -496,14 +456,14 @@ public class ContainerWirelessCraftingTerminal extends Container final IAEItemStack extracted = ais.copy(); ais = Platform.poweredInsert( - this.getPowerSource(), this.getCellInventory(), ais, this.getActionSource()); + this.getPowerSource(), this.getCellInventory(), ais, this.getActionSource()); if (ais == null) { final InventoryAdaptor ia = new AdaptorPlayerHand(player); final ItemStack fail = ia.removeItems(1, extracted.getItemStack(), null); if (fail == null) { this.getCellInventory() - .extractItems(extracted, Actionable.MODULATE, this.getActionSource()); + .extractItems(extracted, Actionable.MODULATE, this.getActionSource()); } this.updateHeld(player); @@ -534,7 +494,7 @@ public class ContainerWirelessCraftingTerminal extends Container IAEItemStack ais = slotItem.copy(); ais.setStackSize(1); ais = Platform.poweredExtraction( - this.getPowerSource(), this.getCellInventory(), ais, this.getActionSource()); + this.getPowerSource(), this.getCellInventory(), ais, this.getActionSource()); if (ais != null) { final InventoryAdaptor ia = new AdaptorPlayerHand(player); @@ -558,7 +518,7 @@ public class ContainerWirelessCraftingTerminal extends Container IAEItemStack ais = slotItem.copy(); ais.setStackSize(ais.getItemStack().getMaxStackSize()); ais = Platform.poweredExtraction( - this.getPowerSource(), this.getCellInventory(), ais, this.getActionSource()); + this.getPowerSource(), this.getCellInventory(), ais, this.getActionSource()); if (ais != null) { player.inventory.setItemStack(ais.getItemStack()); } else { @@ -569,7 +529,7 @@ public class ContainerWirelessCraftingTerminal extends Container } else { IAEItemStack ais = AEApi.instance().storage().createItemStack(player.inventory.getItemStack()); ais = Platform.poweredInsert( - this.getPowerSource(), this.getCellInventory(), ais, this.getActionSource()); + this.getPowerSource(), this.getCellInventory(), ais, this.getActionSource()); if (ais != null) { player.inventory.setItemStack(ais.getItemStack()); } else { @@ -595,7 +555,7 @@ public class ContainerWirelessCraftingTerminal extends Container final long stackSize = Math.min(maxSize, ais.getStackSize()); ais.setStackSize((stackSize + 1) >> 1); ais = Platform.poweredExtraction( - this.getPowerSource(), this.getCellInventory(), ais, this.getActionSource()); + this.getPowerSource(), this.getCellInventory(), ais, this.getActionSource()); } if (ais != null) { @@ -609,7 +569,7 @@ public class ContainerWirelessCraftingTerminal extends Container IAEItemStack ais = AEApi.instance().storage().createItemStack(player.inventory.getItemStack()); ais.setStackSize(1); ais = Platform.poweredInsert( - this.getPowerSource(), this.getCellInventory(), ais, this.getActionSource()); + this.getPowerSource(), this.getCellInventory(), ais, this.getActionSource()); if (ais == null) { final ItemStack is = player.inventory.getItemStack(); is.stackSize--; @@ -651,7 +611,7 @@ public class ContainerWirelessCraftingTerminal extends Container } ais = Platform.poweredExtraction( - this.getPowerSource(), this.getCellInventory(), ais, this.getActionSource()); + this.getPowerSource(), this.getCellInventory(), ais, this.getActionSource()); if (ais != null) { adp.addItems(ais.getItemStack()); } else { @@ -666,23 +626,6 @@ public class ContainerWirelessCraftingTerminal extends Container } } - public IMEInventoryHandler getCellInventory() { - return this.cellInv; - } - - protected void updateHeld(final EntityPlayerMP p) { - if (Platform.isServer()) { - try { - NetworkHandler.instance.sendTo( - new PacketInventoryAction( - InventoryAction.UPDATE_HAND, 0, AEItemStack.create(p.inventory.getItemStack())), - p); - } catch (final IOException e) { - WCTLog.debug(e.getMessage()); - } - } - } - private void updateCraftingMatrix() { if (!this.containerstack.hasTagCompound()) { this.containerstack.setTagCompound(new NBTTagCompound()); @@ -701,11 +644,11 @@ public class ContainerWirelessCraftingTerminal extends Container @Override public void onChangeInventory( - final IInventory inv, - final int slot, - final InvOperation mc, - final ItemStack removedStack, - final ItemStack newStack) { + final IInventory inv, + final int slot, + final InvOperation mc, + final ItemStack removedStack, + final ItemStack newStack) { // <3 } @@ -750,11 +693,11 @@ public class ContainerWirelessCraftingTerminal extends Container return viewCellSlot[index]; } - private WirelessTerminalGuiObject getGuiObject( - final ItemStack it, final EntityPlayer player, final World w, final int x, final int y, final int z) { + public static WirelessTerminalGuiObject getGuiObject( + final ItemStack it, final EntityPlayer player, final World w, final int x, final int y, final int z) { if (it != null) { final IWirelessCraftingTermHandler wh = (IWirelessCraftingTermHandler) - AEApi.instance().registries().wireless().getWirelessTerminalHandler(it); + AEApi.instance().registries().wireless().getWirelessTerminalHandler(it); if (wh != null) { return new WirelessTerminalGuiObject(wh, it, player, w, x, y, z); } @@ -765,22 +708,12 @@ public class ContainerWirelessCraftingTerminal extends Container @Override public void detectAndSendChanges() { - - this.sendCustomName(); - - // if (Platform.isSameItem(this.civ.getItemStack(), this.getPlayerInv().getCurrentItem())) { - // this.getPlayerInv().setInventorySlotContents(this.getPlayerInv().currentItem, this.civ.getItemStack()); - // } - // else { - // this.setValidContainer(false); - // } - // drain 1 ae t this.ticks++; if (this.ticks > 10) { if (!isBoosterInstalled() || !Reference.WCT_BOOSTER_ENABLED) { this.civ.extractAEPower( - this.getPowerMultiplier() * this.ticks, Actionable.MODULATE, PowerMultiplier.CONFIG); + this.getPowerMultiplier() * this.ticks, Actionable.MODULATE, PowerMultiplier.CONFIG); } else { this.civ.extractAEPower((int) (0.5 * this.ticks), Actionable.MODULATE, PowerMultiplier.CONFIG); } @@ -801,7 +734,7 @@ public class ContainerWirelessCraftingTerminal extends Container for (final Object crafter : this.crafters) { try { NetworkHandler.instance.sendTo( - new PacketValueConfig(set.name(), sideLocal.name()), (EntityPlayerMP) crafter); + new PacketValueConfig(set.name(), sideLocal.name()), (EntityPlayerMP) crafter); } catch (final IOException e) { WCTLog.debug(e.getMessage()); } @@ -838,18 +771,7 @@ public class ContainerWirelessCraftingTerminal extends Container WCTLog.debug(e.getMessage()); } } - - this.sendCustomName(); - if (Platform.isServer()) { - for (final Object crafter : this.crafters) { - final ICrafting icrafting = (ICrafting) crafter; - for (final SyncData sd : this.syncData.values()) { - sd.tick(icrafting); - } - } - } } - // if (FMLCommonHandler.instance().getSide() == Side.CLIENT) { if (!isInRange()) { if (!isBoosterInstalled() || !Reference.WCT_BOOSTER_ENABLED) { if (this.isValidContainer()) { @@ -860,14 +782,14 @@ public class ContainerWirelessCraftingTerminal extends Container if (!networkIsPowered()) { if (this.isValidContainer()) { this.getPlayerInv() - .player - .addChatMessage(new ChatComponentText(LocaleHandler.NoNetworkPower.getLocal())); + .player + .addChatMessage(new ChatComponentText(LocaleHandler.NoNetworkPower.getLocal())); } this.setValidContainer(false); } } else if (!hasAccess(SecurityPermissions.CRAFT, true) - || !hasAccess(SecurityPermissions.EXTRACT, true) - || !hasAccess(SecurityPermissions.INJECT, true)) { + || !hasAccess(SecurityPermissions.EXTRACT, true) + || !hasAccess(SecurityPermissions.INJECT, true)) { if (this.isValidContainer()) { this.getPlayerInv().player.addChatMessage(PlayerMessages.CommunicationError.get()); } @@ -875,7 +797,7 @@ public class ContainerWirelessCraftingTerminal extends Container } else { this.setPowerMultiplier(AEConfig.instance.wireless_getDrainRate(this.obj.getRange())); } - // } + super.detectAndSendChanges(); } @@ -885,14 +807,12 @@ public class ContainerWirelessCraftingTerminal extends Container return false; } boolean hasStack = - getSlotFromInventory(this.boosterInventory, BOOSTER_INDEX).getHasStack(); + getSlotFromInventory(this.boosterInventory, BOOSTER_INDEX).getHasStack(); if (hasStack) { Item boosterSlotContents = getSlotFromInventory(this.boosterInventory, BOOSTER_INDEX) - .getStack() - .getItem(); - if (boosterSlotContents instanceof ItemInfinityBooster) { - return true; - } + .getStack() + .getItem(); + return boosterSlotContents instanceof ItemInfinityBooster; } return false; } @@ -903,265 +823,32 @@ public class ContainerWirelessCraftingTerminal extends Container return false; } boolean hasStack = - getSlotFromInventory(this.magnetInventory, MAGNET_INDEX).getHasStack(); + getSlotFromInventory(this.magnetInventory, MAGNET_INDEX).getHasStack(); if (hasStack) { Item magnetSlotContents = getSlotFromInventory(this.magnetInventory, MAGNET_INDEX) - .getStack() - .getItem(); - if (magnetSlotContents instanceof ItemMagnet) { - return true; - } + .getStack() + .getItem(); + return magnetSlotContents instanceof ItemMagnet; } return false; } - public BaseActionSource getActionSource() { - return this.mySrc; - } - - @Override - public boolean canInteractWith(final EntityPlayer entityplayer) { - if (this.isValidContainer()) { - return true; - } - return false; - } - - private void sendCustomName() { - if (!this.sentCustomName) { - this.sentCustomName = true; - if (Platform.isServer()) { - ICustomNameObject name = null; - if (this.obj instanceof ICustomNameObject) { - name = (ICustomNameObject) this.obj; - } - - if (this instanceof ICustomNameObject) { - name = (ICustomNameObject) this; - } - - if (name != null) { - if (name.hasCustomName()) { - this.setCustomName(name.getCustomName()); - } - - if (this.getCustomName() != null) { - try { - NetworkHandler.instance.sendTo( - new PacketValueConfig("CustomName", this.getCustomName()), - (EntityPlayerMP) this.getInventoryPlayer().player); - } catch (final IOException e) { - WCTLog.debug(e.getMessage()); - } - } - } - } - } - } - - public void setCustomName(final String customName) { - this.customName = customName; - } - - public String getCustomName() { - return this.customName; - } - - public void stringSync(final int idx, final String value) { - if (this.syncData.containsKey(idx)) { - this.syncData.get(idx).update(value); - } - } - - public void verifyPermissions(final SecurityPermissions security, final boolean requirePower) { - if (Platform.isClient()) { - return; - } - - this.ticksSinceCheck++; - if (this.ticksSinceCheck < 20) { - return; - } - - this.ticksSinceCheck = 0; - this.setValidContainer(this.isValidContainer() && this.hasAccess(security, requirePower)); - } - protected boolean isInRange() { return this.obj.rangeCheck(Reference.WCT_BOOSTER_ENABLED && this.isBoosterInstalled()); } protected boolean networkIsPowered() { - final WCTIActionHost host = this.getActionHost(); + final IActionHost host = this.getActionHost(); if (host != null) { final IGrid grid = this.obj.getTargetGrid(); if (grid != null) { final IEnergyGrid eg = grid.getCache(IEnergyGrid.class); - if (eg.isNetworkPowered()) { - return true; - } + return eg.isNetworkPowered(); } } return false; } - protected boolean hasAccess(final SecurityPermissions perm, final boolean requirePower) { - final IGrid grid = this.obj.getTargetGrid(); - if (grid != null) { - final IEnergyGrid eg = grid.getCache(IEnergyGrid.class); - if (!eg.isNetworkPowered()) { - return false; - } - } - final ISecurityGrid sg = grid.getCache(ISecurityGrid.class); - if (sg.hasPermission(this.getInventoryPlayer().player, perm)) { - return true; - } - return false; - } - - /* - protected boolean hasAccess(final SecurityPermissions perm, final boolean requirePower) { - final WCTIActionHost host = this.getActionHost(); - - if (host != null) { - final IGridNode gn = host.getActionableNode(); - if (gn != null) { - final IGrid g = gn.getGrid(); - if (g != null) { - if (requirePower) { - final IEnergyGrid eg = g.getCache(IEnergyGrid.class); - if (!eg.isNetworkPowered() && Platform.isServer()) { - return false; - } - } - - final ISecurityGrid sg = g.getCache(ISecurityGrid.class); - if (sg.hasPermission(this.player, perm) && Platform.isServer()) { - return true; - } - } - } - } - return false; - } - */ - public void lockPlayerInventorySlot(final int idx) { - this.locked.add(idx); - } - - public boolean isValidForSlot(final Slot s, final ItemStack i) { - return true; - } - - public void postPartial(final PacketPartialItem packetPartialItem) { - this.dataChunks.add(packetPartialItem); - if (packetPartialItem.getPageCount() == this.dataChunks.size()) { - this.parsePartials(); - } - } - - private void parsePartials() { - int total = 0; - for (final PacketPartialItem ppi : this.dataChunks) { - total += ppi.getSize(); - } - - final byte[] buffer = new byte[total]; - int cursor = 0; - - for (final PacketPartialItem ppi : this.dataChunks) { - cursor = ppi.write(buffer, cursor); - } - - try { - final NBTTagCompound data = CompressedStreamTools.readCompressed(new ByteArrayInputStream(buffer)); - if (data != null) { - this.setTargetStack(AEApi.instance().storage().createItemStack(ItemStack.loadItemStackFromNBT(data))); - } - } catch (final IOException e) { - WCTLog.debug(e.getMessage()); - } - - this.dataChunks.clear(); - } - - public IAEItemStack getTargetStack() { - return this.clientRequestedTargetItem; - } - - public void setTargetStack(final IAEItemStack stack) { - // client doesn't need to re-send, makes for lower overhead rapid - // packets. - if (Platform.isClient()) { - final ItemStack a = stack == null ? null : stack.getItemStack(); - final ItemStack b = - this.clientRequestedTargetItem == null ? null : this.clientRequestedTargetItem.getItemStack(); - - if (Platform.isSameItemPrecise(a, b)) { - return; - } - - final ByteArrayOutputStream stream = new ByteArrayOutputStream(); - final NBTTagCompound item = new NBTTagCompound(); - - if (stack != null) { - stack.writeToNBT(item); - } - - try { - CompressedStreamTools.writeCompressed(item, stream); - - final int maxChunkSize = 30000; - final List miniPackets = new LinkedList(); - - final byte[] data = stream.toByteArray(); - - final ByteArrayInputStream bis = new ByteArrayInputStream(data, 0, stream.size()); - while (bis.available() > 0) { - final int nextBLock = bis.available() > maxChunkSize ? maxChunkSize : bis.available(); - final byte[] nextSegment = new byte[nextBLock]; - bis.read(nextSegment); - miniPackets.add(nextSegment); - } - bis.close(); - stream.close(); - - int page = 0; - for (final byte[] packet : miniPackets) { - final PacketPartialItem ppi = new PacketPartialItem(page, miniPackets.size(), packet); - page++; - NetworkHandler.instance.sendToServer(ppi); - } - } catch (final IOException e) { - WCTLog.debug(e.getMessage()); - return; - } - } - - this.clientRequestedTargetItem = stack == null ? null : stack.copy(); - } - - private void prepareSync() { - for (final Field f : this.getClass().getFields()) { - if (f.isAnnotationPresent(GuiSync.class)) { - final GuiSync annotation = f.getAnnotation(GuiSync.class); - if (this.syncData.containsKey(annotation.value())) { - WCTLog.warning("Channel already in use: " + annotation.value() + " for " + f.getName()); - } else { - this.syncData.put(annotation.value(), new SyncData(this, f, annotation)); - } - } - } - } - - protected WCTIActionHost getActionHost() { - if (this.obj instanceof WCTIActionHost) { - return (WCTIActionHost) this.obj; - } - return null; - } - @Override public IConfigManager getConfigManager() { if (Platform.isServer()) { @@ -1198,9 +885,9 @@ public class ContainerWirelessCraftingTerminal extends Container @Override public void postChange( - final IBaseMonitor monitor, - final Iterable change, - final BaseActionSource source) { + final IBaseMonitor monitor, + final Iterable change, + final BaseActionSource source) { for (final IAEItemStack is : change) { this.items.add(is); } @@ -1258,23 +945,11 @@ public class ContainerWirelessCraftingTerminal extends Container } } - public void onUpdate(final String field, final Object oldValue, final Object newValue) { - // =] - } - - public IEnergySource getPowerSource() { - return this.powerSrc; - } - public boolean isPowered() { double pwr = this.thisItem.getAECurrentPower(this.containerstack); return (pwr > 0.0); } - public void setPowerSource(final IEnergySource powerSrc) { - this.powerSrc = powerSrc; - } - private double getPowerMultiplier() { return this.powerMultiplier; } @@ -1283,37 +958,6 @@ public class ContainerWirelessCraftingTerminal extends Container this.powerMultiplier = powerMultiplier; } - public InventoryPlayer getPlayerInv() { - return this.getInventoryPlayer(); - } - - public InventoryPlayer getInventoryPlayer() { - return this.inventoryPlayer; - } - - public boolean isValidContainer() { - return this.isContainerValid; - } - - public void setValidContainer(final boolean isContainerValid) { - this.isContainerValid = isContainerValid; - } - - public Object getTarget() { - if (this.obj != null) { - return this.obj; - } - return null; - } - - public ContainerOpenContext getOpenContext() { - return this.openContext; - } - - public void setOpenContext(final ContainerOpenContext openContext) { - this.openContext = openContext; - } - /** * Fetches crafting matrix ItemStacks * @@ -1325,7 +969,7 @@ public class ContainerWirelessCraftingTerminal extends Container NBTTagList tagList = nbtTagCompound.getTagList("CraftingMatrix", 10); craftMatrixInventory = new ItemStack[9]; for (int i = 0; i < tagList.tagCount(); ++i) { - NBTTagCompound tagCompound = (NBTTagCompound) tagList.getCompoundTagAt(i); + NBTTagCompound tagCompound = tagList.getCompoundTagAt(i); int slot = tagCompound.getByte("Slot"); if (slot >= 0 && slot < craftMatrixInventory.length) { craftMatrixInventory[slot] = ItemStack.loadItemStackFromNBT(tagCompound); @@ -1342,27 +986,27 @@ public class ContainerWirelessCraftingTerminal extends Container } switch (which) { case "booster": - ((WCTInventoryBooster) boosterInventory).writeNBT(this.containerstack.getTagCompound()); + boosterInventory.writeNBT(this.containerstack.getTagCompound()); break; case "crafting": - ((WCTInventoryCrafting) craftingGrid).writeNBT(this.containerstack.getTagCompound()); + craftingGrid.writeNBT(this.containerstack.getTagCompound()); break; case "viewCell": - ((WCTInventoryViewCell) viewCellInventory).writeNBT(this.containerstack.getTagCompound()); + viewCellInventory.writeNBT(this.containerstack.getTagCompound()); break; case "magnet": - ((WCTInventoryMagnet) magnetInventory).writeNBT(this.containerstack.getTagCompound()); + magnetInventory.writeNBT(this.containerstack.getTagCompound()); break; case "trash": - ((WCTInventoryTrash) trashInventory).writeNBT(this.containerstack.getTagCompound()); + trashInventory.writeNBT(this.containerstack.getTagCompound()); break; case "all": default: - ((WCTInventoryBooster) boosterInventory).writeNBT(this.containerstack.getTagCompound()); - ((WCTInventoryCrafting) craftingGrid).writeNBT(this.containerstack.getTagCompound()); - ((WCTInventoryViewCell) viewCellInventory).writeNBT(this.containerstack.getTagCompound()); - ((WCTInventoryMagnet) magnetInventory).writeNBT(this.containerstack.getTagCompound()); - ((WCTInventoryTrash) trashInventory).writeNBT(this.containerstack.getTagCompound()); + boosterInventory.writeNBT(this.containerstack.getTagCompound()); + craftingGrid.writeNBT(this.containerstack.getTagCompound()); + viewCellInventory.writeNBT(this.containerstack.getTagCompound()); + magnetInventory.writeNBT(this.containerstack.getTagCompound()); + trashInventory.writeNBT(this.containerstack.getTagCompound()); break; } } @@ -1604,79 +1248,10 @@ public class ContainerWirelessCraftingTerminal extends Container return null; } - public void swapSlotContents(final int slotA, final int slotB) { - final Slot a = this.getSlot(slotA); - final Slot b = this.getSlot(slotB); - - // NPE protection... - if (a == null || b == null) { - return; - } - - final ItemStack isA = a.getStack(); - final ItemStack isB = b.getStack(); - - // something to do? - if (isA == null && isB == null) { - return; - } - - // can take? - - if (isA != null && !a.canTakeStack(this.getInventoryPlayer().player)) { - return; - } - - if (isB != null && !b.canTakeStack(this.getInventoryPlayer().player)) { - return; - } - - // swap valid? - - if (isB != null && !a.isItemValid(isB)) { - return; - } - - if (isA != null && !b.isItemValid(isA)) { - return; - } - - ItemStack testA = isB == null ? null : isB.copy(); - ItemStack testB = isA == null ? null : isA.copy(); - - // can put some back? - if (testA != null && testA.stackSize > a.getSlotStackLimit()) { - if (testB != null) { - return; - } - - final int totalA = testA.stackSize; - testA.stackSize = a.getSlotStackLimit(); - testB = testA.copy(); - - testB.stackSize = totalA - testA.stackSize; - } - - if (testB != null && testB.stackSize > b.getSlotStackLimit()) { - if (testA != null) { - return; - } - - final int totalB = testB.stackSize; - testB.stackSize = b.getSlotStackLimit(); - testA = testB.copy(); - - testA.stackSize = totalB - testA.stackSize; - } - - a.putStack(testA); - b.putStack(testB); - } - @SuppressWarnings("unused") private boolean isCraftMatrixSlot(AppEngSlot cs) { return (cs.getSlotIndex() >= this.firstCraftingSlotNumber) - && !(cs.getSlotIndex() <= this.lastCraftingSlotNumber); + && !(cs.getSlotIndex() <= this.lastCraftingSlotNumber); } private void updateSlot(final Slot clickSlot) { @@ -1688,10 +1263,10 @@ public class ContainerWirelessCraftingTerminal extends Container return input; } final IAEItemStack ais = Platform.poweredInsert( - this.getPowerSource(), - this.civ, - AEApi.instance().storage().createItemStack(input), - this.getActionSource()); + this.getPowerSource(), + this.civ, + AEApi.instance().storage().createItemStack(input), + this.getActionSource()); if (ais == null) { return null; } @@ -1728,19 +1303,15 @@ public class ContainerWirelessCraftingTerminal extends Container @SuppressWarnings("unused") private boolean notArmorOrBooster(ItemStack is) { - if ((is.getItem() instanceof ItemInfinityBooster) || (is.getItem() instanceof ItemArmor)) { - return false; - } else { - return true; - } + return (!(is.getItem() instanceof ItemInfinityBooster)) && (!(is.getItem() instanceof ItemArmor)); } @Override public ItemStack slotClick(int slot, int button, int flag, EntityPlayer player) { try { if (slot >= 0 - && getSlot(slot) != null - && getSlot(slot).getStack() == RandomUtils.getWirelessTerm(player.inventory)) { + && getSlot(slot) != null + && getSlot(slot).getStack() == RandomUtils.getWirelessTerm(player.inventory)) { return null; } return super.slotClick(slot, button, flag, player); @@ -1750,15 +1321,6 @@ public class ContainerWirelessCraftingTerminal extends Container return null; } - public final void updateFullProgressBar(final int idx, final long value) { - if (this.syncData.containsKey(idx)) { - this.syncData.get(idx).update(value); - return; - } - - this.updateProgressBar(idx, (int) value); - } - /** * Handles shift-clicking of items whose maxStackSize is 1 */ @@ -1780,9 +1342,9 @@ public class ContainerWirelessCraftingTerminal extends Container } if (itemstack1 != null - && itemstack1.getItem() == stack.getItem() - && (!stack.getHasSubtypes() || stack.getItemDamage() == itemstack1.getItemDamage()) - && ItemStack.areItemStackTagsEqual(stack, itemstack1)) { + && itemstack1.getItem() == stack.getItem() + && (!stack.getHasSubtypes() || stack.getItemDamage() == itemstack1.getItemDamage()) + && ItemStack.areItemStackTagsEqual(stack, itemstack1)) { int l = itemstack1.stackSize + stack.stackSize; if (l <= stack.getMaxStackSize() && l <= slot.getSlotStackLimit()) { @@ -1822,7 +1384,7 @@ public class ContainerWirelessCraftingTerminal extends Container break; } else { putStackInSlot( - k, new ItemStack(stack.getItem(), slot.getSlotStackLimit(), stack.getItemDamage())); + k, new ItemStack(stack.getItem(), slot.getSlotStackLimit(), stack.getItemDamage())); stack.stackSize -= slot.getSlotStackLimit(); boosterInventory.markDirty(); flag1 = true; diff --git a/src/main/java/net/p455w0rd/wirelesscraftingterminal/common/container/WCTBaseContainer.java b/src/main/java/net/p455w0rd/wirelesscraftingterminal/common/container/WCTBaseContainer.java deleted file mode 100644 index f039e7b..0000000 --- a/src/main/java/net/p455w0rd/wirelesscraftingterminal/common/container/WCTBaseContainer.java +++ /dev/null @@ -1,1098 +0,0 @@ -package net.p455w0rd.wirelesscraftingterminal.common.container; - -import appeng.api.AEApi; -import appeng.api.config.Actionable; -import appeng.api.config.SecurityPermissions; -import appeng.api.implementations.guiobjects.IGuiItemObject; -import appeng.api.networking.IGrid; -import appeng.api.networking.energy.IEnergyGrid; -import appeng.api.networking.energy.IEnergySource; -import appeng.api.networking.security.BaseActionSource; -import appeng.api.networking.security.ISecurityGrid; -import appeng.api.parts.IPart; -import appeng.api.storage.IMEInventoryHandler; -import appeng.api.storage.data.IAEItemStack; -import appeng.client.me.InternalSlotME; -import appeng.client.me.SlotME; -import appeng.helpers.ICustomNameObject; -import appeng.helpers.InventoryAction; -import appeng.util.InventoryAdaptor; -import appeng.util.Platform; -import appeng.util.inv.AdaptorPlayerHand; -import appeng.util.item.AEItemStack; -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.lang.reflect.Field; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.HashSet; -import java.util.LinkedList; -import java.util.List; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.entity.player.EntityPlayerMP; -import net.minecraft.entity.player.InventoryPlayer; -import net.minecraft.inventory.Container; -import net.minecraft.inventory.ICrafting; -import net.minecraft.inventory.IInventory; -import net.minecraft.inventory.Slot; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.CompressedStreamTools; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.tileentity.TileEntity; -import net.minecraft.world.World; -import net.minecraftforge.common.util.ForgeDirection; -import net.p455w0rd.wirelesscraftingterminal.api.IWirelessCraftingTermHandler; -import net.p455w0rd.wirelesscraftingterminal.api.networking.security.WCTIActionHost; -import net.p455w0rd.wirelesscraftingterminal.api.networking.security.WCTPlayerSource; -import net.p455w0rd.wirelesscraftingterminal.common.container.guisync.GuiSync; -import net.p455w0rd.wirelesscraftingterminal.common.container.guisync.SyncData; -import net.p455w0rd.wirelesscraftingterminal.common.container.slot.AppEngSlot; -import net.p455w0rd.wirelesscraftingterminal.common.container.slot.SlotCraftingMatrix; -import net.p455w0rd.wirelesscraftingterminal.common.container.slot.SlotCraftingTerm; -import net.p455w0rd.wirelesscraftingterminal.common.container.slot.SlotDisabled; -import net.p455w0rd.wirelesscraftingterminal.common.container.slot.SlotFake; -import net.p455w0rd.wirelesscraftingterminal.common.container.slot.SlotInaccessible; -import net.p455w0rd.wirelesscraftingterminal.common.container.slot.SlotPlayerHotBar; -import net.p455w0rd.wirelesscraftingterminal.common.container.slot.SlotPlayerInv; -import net.p455w0rd.wirelesscraftingterminal.common.utils.RandomUtils; -import net.p455w0rd.wirelesscraftingterminal.common.utils.WCTLog; -import net.p455w0rd.wirelesscraftingterminal.core.sync.network.NetworkHandler; -import net.p455w0rd.wirelesscraftingterminal.core.sync.packets.PacketInventoryAction; -import net.p455w0rd.wirelesscraftingterminal.core.sync.packets.PacketPartialItem; -import net.p455w0rd.wirelesscraftingterminal.core.sync.packets.PacketValueConfig; -import net.p455w0rd.wirelesscraftingterminal.helpers.WirelessTerminalGuiObject; - -public abstract class WCTBaseContainer extends Container { - - private final InventoryPlayer invPlayer; - private final BaseActionSource mySrc; - private final HashSet locked = new HashSet(); - private final TileEntity tileEntity; - private final IPart part; - public final IGuiItemObject obj; - public final WirelessTerminalGuiObject obj2; - private final List dataChunks = new LinkedList(); - private final HashMap syncData = new HashMap(); - private boolean isContainerValid = true; - private String customName; - private ContainerOpenContext openContext; - private IMEInventoryHandler cellInv; - private IEnergySource powerSrc; - private boolean sentCustomName; - private int ticksSinceCheck = 900; - private IAEItemStack clientRequestedTargetItem = null; - - public WCTBaseContainer(final InventoryPlayer ip, final TileEntity myTile, final IPart myPart) { - this(ip, myTile, myPart, null); - } - - public WCTBaseContainer( - final InventoryPlayer ip, final TileEntity myTile, final IPart myPart, final IGuiItemObject gio) { - this.invPlayer = ip; - this.tileEntity = myTile; - this.part = myPart; - this.obj = gio; - EntityPlayer player = ip.player; - this.obj2 = getGuiObject( - RandomUtils.getWirelessTerm(ip), player, player.worldObj, (int) player.posX, (int) player.posY, (int) - player.posZ); - this.mySrc = new WCTPlayerSource(ip.player, this.getActionHost()); - this.prepareSync(); - } - - protected WirelessTerminalGuiObject getGuiObject( - final ItemStack it, final EntityPlayer player, final World w, final int x, final int y, final int z) { - if (it != null) { - final IWirelessCraftingTermHandler wh = (IWirelessCraftingTermHandler) - AEApi.instance().registries().wireless().getWirelessTerminalHandler(it); - if (wh != null) { - return new WirelessTerminalGuiObject(wh, it, player, w, x, y, z); - } - } - - return null; - } - - protected WCTIActionHost getActionHost() { - if (this.obj instanceof WCTIActionHost) { - return (WCTIActionHost) this.obj; - } - - if (this.tileEntity instanceof WCTIActionHost) { - return (WCTIActionHost) this.tileEntity; - } - - if (this.part instanceof WCTIActionHost) { - return (WCTIActionHost) this.part; - } - - return null; - } - - private void prepareSync() { - for (final Field f : this.getClass().getFields()) { - if (f.isAnnotationPresent(GuiSync.class)) { - final GuiSync annotation = f.getAnnotation(GuiSync.class); - if (this.syncData.containsKey(annotation.value())) { - WCTLog.warning("Channel already in use: " + annotation.value() + " for " + f.getName()); - } else { - this.syncData.put(annotation.value(), new SyncData(this, f, annotation)); - } - } - } - } - - public WCTBaseContainer(final InventoryPlayer ip, final Object anchor) { - this.invPlayer = ip; - this.tileEntity = anchor instanceof TileEntity ? (TileEntity) anchor : null; - this.part = anchor instanceof IPart ? (IPart) anchor : null; - this.obj = anchor instanceof IGuiItemObject ? (IGuiItemObject) anchor : null; - - EntityPlayer player = ip.player; - this.obj2 = getGuiObject( - RandomUtils.getWirelessTerm(ip), player, player.worldObj, (int) player.posX, (int) player.posY, (int) - player.posZ); - - if (this.tileEntity == null && this.part == null && this.obj == null) { - throw new IllegalArgumentException("Must have a valid anchor, instead " + anchor + " in " + ip); - } - - this.mySrc = new WCTPlayerSource(ip.player, this.getActionHost()); - - this.prepareSync(); - } - - public void postPartial(final PacketPartialItem packetPartialItem) { - this.dataChunks.add(packetPartialItem); - if (packetPartialItem.getPageCount() == this.dataChunks.size()) { - this.parsePartials(); - } - } - - private void parsePartials() { - int total = 0; - for (final PacketPartialItem ppi : this.dataChunks) { - total += ppi.getSize(); - } - - final byte[] buffer = new byte[total]; - int cursor = 0; - - for (final PacketPartialItem ppi : this.dataChunks) { - cursor = ppi.write(buffer, cursor); - } - - try { - final NBTTagCompound data = CompressedStreamTools.readCompressed(new ByteArrayInputStream(buffer)); - if (data != null) { - this.setTargetStack(AEApi.instance().storage().createItemStack(ItemStack.loadItemStackFromNBT(data))); - } - } catch (final IOException e) { - WCTLog.debug(e.getMessage()); - } - - this.dataChunks.clear(); - } - - public IAEItemStack getTargetStack() { - return this.clientRequestedTargetItem; - } - - public void setTargetStack(final IAEItemStack stack) { - // client doesn't need to re-send, makes for lower overhead rapid packets. - if (Platform.isClient()) { - final ItemStack a = stack == null ? null : stack.getItemStack(); - final ItemStack b = - this.clientRequestedTargetItem == null ? null : this.clientRequestedTargetItem.getItemStack(); - - if (Platform.isSameItemPrecise(a, b)) { - return; - } - - final ByteArrayOutputStream stream = new ByteArrayOutputStream(); - final NBTTagCompound item = new NBTTagCompound(); - - if (stack != null) { - stack.writeToNBT(item); - } - - try { - CompressedStreamTools.writeCompressed(item, stream); - - final int maxChunkSize = 30000; - final List miniPackets = new LinkedList(); - - final byte[] data = stream.toByteArray(); - - final ByteArrayInputStream bis = new ByteArrayInputStream(data, 0, stream.size()); - while (bis.available() > 0) { - final int nextBLock = bis.available() > maxChunkSize ? maxChunkSize : bis.available(); - final byte[] nextSegment = new byte[nextBLock]; - bis.read(nextSegment); - miniPackets.add(nextSegment); - } - bis.close(); - stream.close(); - - int page = 0; - for (final byte[] packet : miniPackets) { - final PacketPartialItem ppi = new PacketPartialItem(page, miniPackets.size(), packet); - page++; - NetworkHandler.instance.sendToServer(ppi); - } - } catch (final IOException e) { - WCTLog.debug(e.getMessage()); - return; - } - } - - this.clientRequestedTargetItem = stack == null ? null : stack.copy(); - } - - public BaseActionSource getActionSource() { - return this.mySrc; - } - - public void verifyPermissions(final SecurityPermissions security, final boolean requirePower) { - if (Platform.isClient()) { - return; - } - - this.ticksSinceCheck++; - if (this.ticksSinceCheck < 20) { - return; - } - - this.ticksSinceCheck = 0; - this.setValidContainer(this.isValidContainer() && this.hasAccess(security, requirePower)); - } - - protected boolean hasAccess(final SecurityPermissions perm, final boolean requirePower) { - final IGrid grid = this.obj2.getTargetGrid(); - if (grid != null) { - final IEnergyGrid eg = grid.getCache(IEnergyGrid.class); - if (!eg.isNetworkPowered()) { - return false; - } - } - final ISecurityGrid sg = grid.getCache(ISecurityGrid.class); - if (sg.hasPermission(this.getInventoryPlayer().player, perm)) { - return true; - } - return false; - } - - public void lockPlayerInventorySlot(final int idx) { - this.locked.add(idx); - } - - public Object getTarget() { - if (this.tileEntity != null) { - return this.tileEntity; - } - if (this.part != null) { - return this.part; - } - if (this.obj2 != null) { - return this.obj2; - } - return null; - } - - public InventoryPlayer getPlayerInv() { - return this.getInventoryPlayer(); - } - - public TileEntity getTileEntity() { - return this.tileEntity; - } - - public final void updateFullProgressBar(final int idx, final long value) { - if (this.syncData.containsKey(idx)) { - this.syncData.get(idx).update(value); - return; - } - - this.updateProgressBar(idx, (int) value); - } - - public void stringSync(final int idx, final String value) { - if (this.syncData.containsKey(idx)) { - this.syncData.get(idx).update(value); - } - } - - protected void bindPlayerInventory(final InventoryPlayer inventoryPlayer, final int offsetX, final int offsetY) { - // bind player inventory - for (int i = 0; i < 3; i++) { - for (int j = 0; j < 9; j++) { - if (this.locked.contains(j + i * 9 + 9)) { - this.addSlotToContainer( - new SlotDisabled(inventoryPlayer, j + i * 9 + 9, 8 + j * 18 + offsetX, offsetY + i * 18)); - } else { - this.addSlotToContainer( - new SlotPlayerInv(inventoryPlayer, j + i * 9 + 9, 8 + j * 18 + offsetX, offsetY + i * 18)); - } - } - } - - // bind player hotbar - for (int i = 0; i < 9; i++) { - if (this.locked.contains(i)) { - this.addSlotToContainer(new SlotDisabled(inventoryPlayer, i, 8 + i * 18 + offsetX, 58 + offsetY)); - } else { - this.addSlotToContainer(new SlotPlayerHotBar(inventoryPlayer, i, 8 + i * 18 + offsetX, 58 + offsetY)); - } - } - } - - @Override - protected Slot addSlotToContainer(final Slot newSlot) { - if (newSlot instanceof AppEngSlot) { - final AppEngSlot s = (AppEngSlot) newSlot; - s.setContainer(this); - return super.addSlotToContainer(newSlot); - } else { - throw new IllegalArgumentException("Invalid Slot [" + newSlot + "]for AE Container instead of AppEngSlot."); - } - } - - @Override - public void detectAndSendChanges() { - this.sendCustomName(); - - if (Platform.isServer()) { - for (final Object crafter : this.crafters) { - final ICrafting icrafting = (ICrafting) crafter; - - for (final SyncData sd : this.syncData.values()) { - sd.tick(icrafting); - } - } - } - - super.detectAndSendChanges(); - } - - @Override - public ItemStack transferStackInSlot(final EntityPlayer p, final int idx) { - if (Platform.isClient()) { - return null; - } - - boolean hasMETiles = false; - for (final Object is : this.inventorySlots) { - if (is instanceof InternalSlotME) { - hasMETiles = true; - break; - } - } - - if (hasMETiles && Platform.isClient()) { - return null; - } - - final AppEngSlot clickSlot = (AppEngSlot) this.inventorySlots.get(idx); // require AE SLots! - - if (clickSlot instanceof SlotDisabled || clickSlot instanceof SlotInaccessible) { - return null; - } - if (clickSlot != null && clickSlot.getHasStack()) { - ItemStack tis = clickSlot.getStack(); - - if (tis == null) { - return null; - } - - final List selectedSlots = new ArrayList(); - - /** - * Gather a list of valid destinations. - */ - if (clickSlot.isPlayerSide()) { - tis = this.shiftStoreItem(tis); - - // target slots in the container... - for (final Object inventorySlot : this.inventorySlots) { - final AppEngSlot cs = (AppEngSlot) inventorySlot; - - if (!(cs.isPlayerSide()) && !(cs instanceof SlotFake) && !(cs instanceof SlotCraftingMatrix)) { - if (cs.isItemValid(tis)) { - selectedSlots.add(cs); - } - } - } - } else { - // target slots in the container... - for (final Object inventorySlot : this.inventorySlots) { - final AppEngSlot cs = (AppEngSlot) inventorySlot; - - if ((cs.isPlayerSide()) && !(cs instanceof SlotFake) && !(cs instanceof SlotCraftingMatrix)) { - if (cs.isItemValid(tis)) { - selectedSlots.add(cs); - } - } - } - } - - /** - * Handle Fake Slot Shift clicking. - */ - if (selectedSlots.isEmpty() && clickSlot.isPlayerSide()) { - if (tis != null) { - // target slots in the container... - for (final Object inventorySlot : this.inventorySlots) { - final AppEngSlot cs = (AppEngSlot) inventorySlot; - final ItemStack destination = cs.getStack(); - - if (!(cs.isPlayerSide()) && cs instanceof SlotFake) { - if (Platform.isSameItemPrecise(destination, tis)) { - return null; - } else if (destination == null) { - cs.putStack(tis.copy()); - cs.onSlotChanged(); - this.updateSlot(cs); - return null; - } - } - } - } - } - - if (tis != null) { - // find partials.. - for (final Slot d : selectedSlots) { - if (d instanceof SlotDisabled || d instanceof SlotME) { - continue; - } - - if (d.isItemValid(tis)) { - if (d.getHasStack()) { - final ItemStack t = d.getStack(); - - if (Platform.isSameItemPrecise(tis, t)) // t.isItemEqual(tis)) - { - int maxSize = t.getMaxStackSize(); - if (maxSize > d.getSlotStackLimit()) { - maxSize = d.getSlotStackLimit(); - } - - int placeAble = maxSize - t.stackSize; - - if (tis.stackSize < placeAble) { - placeAble = tis.stackSize; - } - - t.stackSize += placeAble; - tis.stackSize -= placeAble; - - if (tis.stackSize <= 0) { - clickSlot.putStack(null); - d.onSlotChanged(); - - // if ( hasMETiles ) updateClient(); - - this.updateSlot(clickSlot); - this.updateSlot(d); - return null; - } else { - this.updateSlot(d); - } - } - } - } - } - - // any match.. - for (final Slot d : selectedSlots) { - if (d instanceof SlotDisabled || d instanceof SlotME) { - continue; - } - - if (d.isItemValid(tis)) { - if (d.getHasStack()) { - final ItemStack t = d.getStack(); - - if (Platform.isSameItemPrecise(t, tis)) { - int maxSize = t.getMaxStackSize(); - if (d.getSlotStackLimit() < maxSize) { - maxSize = d.getSlotStackLimit(); - } - - int placeAble = maxSize - t.stackSize; - - if (tis.stackSize < placeAble) { - placeAble = tis.stackSize; - } - - t.stackSize += placeAble; - tis.stackSize -= placeAble; - - if (tis.stackSize <= 0) { - clickSlot.putStack(null); - d.onSlotChanged(); - - // if ( worldEntity != null ) - // worldEntity.markDirty(); - // if ( hasMETiles ) updateClient(); - - this.updateSlot(clickSlot); - this.updateSlot(d); - return null; - } else { - this.updateSlot(d); - } - } - } else { - int maxSize = tis.getMaxStackSize(); - if (maxSize > d.getSlotStackLimit()) { - maxSize = d.getSlotStackLimit(); - } - - final ItemStack tmp = tis.copy(); - if (tmp.stackSize > maxSize) { - tmp.stackSize = maxSize; - } - - tis.stackSize -= tmp.stackSize; - d.putStack(tmp); - - if (tis.stackSize <= 0) { - clickSlot.putStack(null); - d.onSlotChanged(); - - // if ( worldEntity != null ) - // worldEntity.markDirty(); - // if ( hasMETiles ) updateClient(); - - this.updateSlot(clickSlot); - this.updateSlot(d); - return null; - } else { - this.updateSlot(d); - } - } - } - } - } - - clickSlot.putStack(tis != null ? tis.copy() : null); - } - - this.updateSlot(clickSlot); - return null; - } - - @Override - public final void updateProgressBar(final int idx, final int value) { - if (this.syncData.containsKey(idx)) { - this.syncData.get(idx).update((long) value); - } - } - - @Override - public boolean canInteractWith(final EntityPlayer entityplayer) { - if (this.isValidContainer()) { - if (this.tileEntity instanceof IInventory) { - return ((IInventory) this.tileEntity).isUseableByPlayer(entityplayer); - } - return true; - } - return false; - } - - @Override - public boolean canDragIntoSlot(final Slot s) { - return ((AppEngSlot) s).isDraggable(); - } - - public void doAction(final EntityPlayerMP player, final InventoryAction action, final int slot, final long id) { - if (slot >= 0 && slot < this.inventorySlots.size()) { - final Slot s = this.getSlot(slot); - - if (s instanceof SlotCraftingTerm) { - switch (action) { - case CRAFT_SHIFT: - case CRAFT_ITEM: - case CRAFT_STACK: - ((SlotCraftingTerm) s).doClick(action, player); - this.updateHeld(player); - default: - } - } - - if (s instanceof SlotFake) { - final ItemStack hand = player.inventory.getItemStack(); - - switch (action) { - case PICKUP_OR_SET_DOWN: - if (hand == null) { - s.putStack(null); - } else { - s.putStack(hand.copy()); - } - - break; - case PLACE_SINGLE: - if (hand != null) { - final ItemStack is = hand.copy(); - is.stackSize = 1; - s.putStack(is); - } - - break; - case SPLIT_OR_PLACE_SINGLE: - ItemStack is = s.getStack(); - if (is != null) { - if (hand == null) { - is.stackSize--; - } else if (hand.isItemEqual(is)) { - is.stackSize = Math.min(is.getMaxStackSize(), is.stackSize + 1); - } else { - is = hand.copy(); - is.stackSize = 1; - } - - s.putStack(is); - } else if (hand != null) { - is = hand.copy(); - is.stackSize = 1; - s.putStack(is); - } - - break; - case CREATIVE_DUPLICATE: - case MOVE_REGION: - case SHIFT_CLICK: - default: - break; - } - } - - if (action == InventoryAction.MOVE_REGION) { - final List from = new LinkedList(); - - for (final Object j : this.inventorySlots) { - if (j instanceof Slot && j.getClass() == s.getClass()) { - from.add((Slot) j); - } - } - - for (final Slot fr : from) { - this.transferStackInSlot(player, fr.slotNumber); - } - } - - return; - } - - // get target item. - final IAEItemStack slotItem = this.clientRequestedTargetItem; - - switch (action) { - case SHIFT_CLICK: - if (this.getPowerSource() == null || this.getCellInventory() == null) { - return; - } - - if (slotItem != null) { - IAEItemStack ais = slotItem.copy(); - ItemStack myItem = ais.getItemStack(); - - ais.setStackSize(myItem.getMaxStackSize()); - - final InventoryAdaptor adp = InventoryAdaptor.getAdaptor(player, ForgeDirection.UNKNOWN); - myItem.stackSize = (int) ais.getStackSize(); - myItem = adp.simulateAdd(myItem); - - if (myItem != null) { - ais.setStackSize(ais.getStackSize() - myItem.stackSize); - } - - ais = Platform.poweredExtraction( - this.getPowerSource(), this.getCellInventory(), ais, this.getActionSource()); - if (ais != null) { - adp.addItems(ais.getItemStack()); - } - } - break; - case ROLL_DOWN: - if (this.getPowerSource() == null || this.getCellInventory() == null) { - return; - } - - final int releaseQty = 1; - final ItemStack isg = player.inventory.getItemStack(); - - if (isg != null && releaseQty > 0) { - IAEItemStack ais = AEApi.instance().storage().createItemStack(isg); - ais.setStackSize(1); - final IAEItemStack extracted = ais.copy(); - - ais = Platform.poweredInsert( - this.getPowerSource(), this.getCellInventory(), ais, this.getActionSource()); - if (ais == null) { - final InventoryAdaptor ia = new AdaptorPlayerHand(player); - - final ItemStack fail = ia.removeItems(1, extracted.getItemStack(), null); - if (fail == null) { - this.getCellInventory() - .extractItems(extracted, Actionable.MODULATE, this.getActionSource()); - } - - this.updateHeld(player); - } - } - - break; - case ROLL_UP: - case PICKUP_SINGLE: - if (this.getPowerSource() == null || this.getCellInventory() == null) { - return; - } - - if (slotItem != null) { - int liftQty = 1; - final ItemStack item = player.inventory.getItemStack(); - - if (item != null) { - if (item.stackSize >= item.getMaxStackSize()) { - liftQty = 0; - } - if (!Platform.isSameItemPrecise(slotItem.getItemStack(), item)) { - liftQty = 0; - } - } - - if (liftQty > 0) { - IAEItemStack ais = slotItem.copy(); - ais.setStackSize(1); - ais = Platform.poweredExtraction( - this.getPowerSource(), this.getCellInventory(), ais, this.getActionSource()); - if (ais != null) { - final InventoryAdaptor ia = new AdaptorPlayerHand(player); - - final ItemStack fail = ia.addItems(ais.getItemStack()); - if (fail != null) { - this.getCellInventory().injectItems(ais, Actionable.MODULATE, this.getActionSource()); - } - - this.updateHeld(player); - } - } - } - break; - case PICKUP_OR_SET_DOWN: - if (this.getPowerSource() == null || this.getCellInventory() == null) { - return; - } - - if (player.inventory.getItemStack() == null) { - if (slotItem != null) { - IAEItemStack ais = slotItem.copy(); - ais.setStackSize(ais.getItemStack().getMaxStackSize()); - ais = Platform.poweredExtraction( - this.getPowerSource(), this.getCellInventory(), ais, this.getActionSource()); - if (ais != null) { - player.inventory.setItemStack(ais.getItemStack()); - } else { - player.inventory.setItemStack(null); - } - this.updateHeld(player); - } - } else { - IAEItemStack ais = AEApi.instance().storage().createItemStack(player.inventory.getItemStack()); - ais = Platform.poweredInsert( - this.getPowerSource(), this.getCellInventory(), ais, this.getActionSource()); - if (ais != null) { - player.inventory.setItemStack(ais.getItemStack()); - } else { - player.inventory.setItemStack(null); - } - this.updateHeld(player); - } - - break; - case SPLIT_OR_PLACE_SINGLE: - if (this.getPowerSource() == null || this.getCellInventory() == null) { - return; - } - - if (player.inventory.getItemStack() == null) { - if (slotItem != null) { - IAEItemStack ais = slotItem.copy(); - final long maxSize = ais.getItemStack().getMaxStackSize(); - ais.setStackSize(maxSize); - ais = this.getCellInventory().extractItems(ais, Actionable.SIMULATE, this.getActionSource()); - - if (ais != null) { - final long stackSize = Math.min(maxSize, ais.getStackSize()); - ais.setStackSize((stackSize + 1) >> 1); - ais = Platform.poweredExtraction( - this.getPowerSource(), this.getCellInventory(), ais, this.getActionSource()); - } - - if (ais != null) { - player.inventory.setItemStack(ais.getItemStack()); - } else { - player.inventory.setItemStack(null); - } - this.updateHeld(player); - } - } else { - IAEItemStack ais = AEApi.instance().storage().createItemStack(player.inventory.getItemStack()); - ais.setStackSize(1); - ais = Platform.poweredInsert( - this.getPowerSource(), this.getCellInventory(), ais, this.getActionSource()); - if (ais == null) { - final ItemStack is = player.inventory.getItemStack(); - is.stackSize--; - if (is.stackSize <= 0) { - player.inventory.setItemStack(null); - } - this.updateHeld(player); - } - } - - break; - case CREATIVE_DUPLICATE: - if (player.capabilities.isCreativeMode && slotItem != null) { - final ItemStack is = slotItem.getItemStack(); - is.stackSize = is.getMaxStackSize(); - player.inventory.setItemStack(is); - this.updateHeld(player); - } - break; - case MOVE_REGION: - if (this.getPowerSource() == null || this.getCellInventory() == null) { - return; - } - - if (slotItem != null) { - final int playerInv = 9 * 4; - for (int slotNum = 0; slotNum < playerInv; slotNum++) { - IAEItemStack ais = slotItem.copy(); - ItemStack myItem = ais.getItemStack(); - - ais.setStackSize(myItem.getMaxStackSize()); - - final InventoryAdaptor adp = InventoryAdaptor.getAdaptor(player, ForgeDirection.UNKNOWN); - myItem.stackSize = (int) ais.getStackSize(); - myItem = adp.simulateAdd(myItem); - - if (myItem != null) { - ais.setStackSize(ais.getStackSize() - myItem.stackSize); - } - - ais = Platform.poweredExtraction( - this.getPowerSource(), this.getCellInventory(), ais, this.getActionSource()); - if (ais != null) { - adp.addItems(ais.getItemStack()); - } else { - return; - } - } - } - - break; - default: - break; - } - } - - protected void updateHeld(final EntityPlayerMP p) { - if (Platform.isServer()) { - try { - NetworkHandler.instance.sendTo( - new PacketInventoryAction( - InventoryAction.UPDATE_HAND, 0, AEItemStack.create(p.inventory.getItemStack())), - p); - } catch (final IOException e) { - WCTLog.debug(e.getMessage()); - } - } - } - - private ItemStack shiftStoreItem(final ItemStack input) { - if (this.getPowerSource() == null || this.getCellInventory() == null) { - return input; - } - final IAEItemStack ais = Platform.poweredInsert( - this.getPowerSource(), - this.getCellInventory(), - AEApi.instance().storage().createItemStack(input), - this.getActionSource()); - if (ais == null) { - return null; - } - return ais.getItemStack(); - } - - private void updateSlot(final Slot clickSlot) { - // ??? - this.detectAndSendChanges(); - } - - private void sendCustomName() { - if (!this.sentCustomName) { - this.sentCustomName = true; - if (Platform.isServer()) { - ICustomNameObject name = null; - - if (this.part instanceof ICustomNameObject) { - name = (ICustomNameObject) this.part; - } - - if (this.tileEntity instanceof ICustomNameObject) { - name = (ICustomNameObject) this.tileEntity; - } - - if (this.obj instanceof ICustomNameObject) { - name = (ICustomNameObject) this.obj; - } - - if (this instanceof ICustomNameObject) { - name = (ICustomNameObject) this; - } - - if (name != null) { - if (name.hasCustomName()) { - this.setCustomName(name.getCustomName()); - } - - if (this.getCustomName() != null) { - try { - NetworkHandler.instance.sendTo( - new PacketValueConfig("CustomName", this.getCustomName()), - (EntityPlayerMP) this.getInventoryPlayer().player); - } catch (final IOException e) { - WCTLog.debug(e.getMessage()); - } - } - } - } - } - } - - public void swapSlotContents(final int slotA, final int slotB) { - final Slot a = this.getSlot(slotA); - final Slot b = this.getSlot(slotB); - - // NPE protection... - if (a == null || b == null) { - return; - } - - final ItemStack isA = a.getStack(); - final ItemStack isB = b.getStack(); - - // something to do? - if (isA == null && isB == null) { - return; - } - - // can take? - - if (isA != null && !a.canTakeStack(this.getInventoryPlayer().player)) { - return; - } - - if (isB != null && !b.canTakeStack(this.getInventoryPlayer().player)) { - return; - } - - // swap valid? - - if (isB != null && !a.isItemValid(isB)) { - return; - } - - if (isA != null && !b.isItemValid(isA)) { - return; - } - - ItemStack testA = isB == null ? null : isB.copy(); - ItemStack testB = isA == null ? null : isA.copy(); - - // can put some back? - if (testA != null && testA.stackSize > a.getSlotStackLimit()) { - if (testB != null) { - return; - } - - final int totalA = testA.stackSize; - testA.stackSize = a.getSlotStackLimit(); - testB = testA.copy(); - - testB.stackSize = totalA - testA.stackSize; - } - - if (testB != null && testB.stackSize > b.getSlotStackLimit()) { - if (testA != null) { - return; - } - - final int totalB = testB.stackSize; - testB.stackSize = b.getSlotStackLimit(); - testA = testB.copy(); - - testA.stackSize = totalB - testA.stackSize; - } - - a.putStack(testA); - b.putStack(testB); - } - - public void onUpdate(final String field, final Object oldValue, final Object newValue) {} - - public void onSlotChange(final Slot s) {} - - public boolean isValidForSlot(final Slot s, final ItemStack i) { - return true; - } - - public IMEInventoryHandler getCellInventory() { - return this.cellInv; - } - - public void setCellInventory(final IMEInventoryHandler cellInv) { - this.cellInv = cellInv; - } - - public String getCustomName() { - return this.customName; - } - - public void setCustomName(final String customName) { - this.customName = customName; - } - - public InventoryPlayer getInventoryPlayer() { - return this.invPlayer; - } - - public boolean isValidContainer() { - return this.isContainerValid; - } - - public void setValidContainer(final boolean isContainerValid) { - this.isContainerValid = isContainerValid; - } - - public ContainerOpenContext getOpenContext() { - return this.openContext; - } - - public void setOpenContext(final ContainerOpenContext openContext) { - this.openContext = openContext; - } - - public IEnergySource getPowerSource() { - return this.powerSrc; - } - - public void setPowerSource(final IEnergySource powerSrc) { - this.powerSrc = powerSrc; - } -} diff --git a/src/main/java/net/p455w0rd/wirelesscraftingterminal/common/container/guisync/GuiSync.java b/src/main/java/net/p455w0rd/wirelesscraftingterminal/common/container/guisync/GuiSync.java deleted file mode 100644 index 8a4d922..0000000 --- a/src/main/java/net/p455w0rd/wirelesscraftingterminal/common/container/guisync/GuiSync.java +++ /dev/null @@ -1,17 +0,0 @@ -package net.p455w0rd.wirelesscraftingterminal.common.container.guisync; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * Annotates that this field should be synchronized between the server and client. - * Requires the field to be public. - */ -@Retention(RetentionPolicy.RUNTIME) -@Target(ElementType.FIELD) -public @interface GuiSync { - - int value(); -} diff --git a/src/main/java/net/p455w0rd/wirelesscraftingterminal/common/container/guisync/SyncData.java b/src/main/java/net/p455w0rd/wirelesscraftingterminal/common/container/guisync/SyncData.java deleted file mode 100644 index af5f191..0000000 --- a/src/main/java/net/p455w0rd/wirelesscraftingterminal/common/container/guisync/SyncData.java +++ /dev/null @@ -1,140 +0,0 @@ -package net.p455w0rd.wirelesscraftingterminal.common.container.guisync; - -import java.io.IOException; -import java.lang.reflect.Field; -import java.util.EnumSet; -import net.minecraft.entity.player.EntityPlayerMP; -import net.minecraft.inventory.Container; -import net.minecraft.inventory.ICrafting; -import net.p455w0rd.wirelesscraftingterminal.common.container.ContainerWirelessCraftingTerminal; -import net.p455w0rd.wirelesscraftingterminal.common.container.WCTBaseContainer; -import net.p455w0rd.wirelesscraftingterminal.common.utils.WCTLog; -import net.p455w0rd.wirelesscraftingterminal.core.sync.network.NetworkHandler; -import net.p455w0rd.wirelesscraftingterminal.core.sync.packets.PacketValueConfig; - -public class SyncData { - private final Container source; - private final Field field; - private final int channel; - private Object clientVersion; - - public SyncData(final Container container, final Field field, final GuiSync annotation) { - if (container instanceof ContainerWirelessCraftingTerminal) { - this.source = (ContainerWirelessCraftingTerminal) container; - } else if (container instanceof WCTBaseContainer) { - this.source = (WCTBaseContainer) container; - } else { - this.source = container; - } - this.clientVersion = null; - this.field = field; - this.channel = annotation.value(); - } - - public int getChannel() { - return this.channel; - } - - public void tick(final ICrafting c) { - try { - final Object val = this.field.get(this.source); - if (val != null && this.clientVersion == null) { - this.send(c, val); - } else if (!val.equals(this.clientVersion)) { - this.send(c, val); - } - } catch (final IllegalArgumentException e) { - WCTLog.debug(e.getMessage()); - } catch (final IllegalAccessException e) { - WCTLog.debug(e.getMessage()); - } catch (final IOException e) { - WCTLog.debug(e.getMessage()); - } - } - - @SuppressWarnings("rawtypes") - private void send(final ICrafting o, final Object val) throws IOException { - if (val instanceof String) { - if (o instanceof EntityPlayerMP) { - NetworkHandler.instance.sendTo( - new PacketValueConfig("SyncDat." + this.channel, (String) val), (EntityPlayerMP) o); - } - } else if (this.field.getType().isEnum()) { - o.sendProgressBarUpdate(this.source, this.channel, ((Enum) val).ordinal()); - } else if (val instanceof Long || val.getClass() == long.class) { - // NetworkHandler.instance.sendTo( new PacketProgressBar( this.channel, (Long) val ), (EntityPlayerMP) o ); - } else if (val instanceof Boolean || val.getClass() == boolean.class) { - o.sendProgressBarUpdate(this.source, this.channel, ((Boolean) val) ? 1 : 0); - } else { - o.sendProgressBarUpdate(this.source, this.channel, (Integer) val); - } - - this.clientVersion = val; - } - - public void update(final Object val) { - try { - final Object oldValue = this.field.get(this.source); - if (val instanceof String) { - this.updateString(oldValue, (String) val); - } else { - this.updateValue(oldValue, (Long) val); - } - } catch (final IllegalArgumentException e) { - WCTLog.debug(e.getMessage()); - } catch (final IllegalAccessException e) { - WCTLog.debug(e.getMessage()); - } - } - - private void updateString(final Object oldValue, final String val) { - try { - this.field.set(this.source, val); - } catch (final IllegalArgumentException e) { - WCTLog.debug(e.getMessage()); - } catch (final IllegalAccessException e) { - WCTLog.debug(e.getMessage()); - } - } - - @SuppressWarnings({"unchecked", "rawtypes"}) - private void updateValue(final Object oldValue, final long val) { - try { - if (this.field.getType().isEnum()) { - final EnumSet valList = EnumSet.allOf((Class) this.field.getType()); - for (final Enum e : valList) { - if (e.ordinal() == val) { - this.field.set(this.source, e); - break; - } - } - } else { - if (this.field.getType().equals(int.class)) { - this.field.set(this.source, (int) val); - } else if (this.field.getType().equals(long.class)) { - this.field.set(this.source, val); - } else if (this.field.getType().equals(boolean.class)) { - this.field.set(this.source, val == 1); - } else if (this.field.getType().equals(Integer.class)) { - this.field.set(this.source, (int) val); - } else if (this.field.getType().equals(Long.class)) { - this.field.set(this.source, val); - } else if (this.field.getType().equals(Boolean.class)) { - this.field.set(this.source, val == 1); - } - } - - if (this.source instanceof ContainerWirelessCraftingTerminal) { - ((ContainerWirelessCraftingTerminal) this.source) - .onUpdate(this.field.getName(), oldValue, this.field.get(this.source)); - } - if (this.source instanceof WCTBaseContainer) { - ((WCTBaseContainer) this.source).onUpdate(this.field.getName(), oldValue, this.field.get(this.source)); - } - } catch (final IllegalArgumentException e) { - WCTLog.debug(e.getMessage()); - } catch (final IllegalAccessException e) { - WCTLog.debug(e.getMessage()); - } - } -} diff --git a/src/main/java/net/p455w0rd/wirelesscraftingterminal/common/container/slot/AppEngSlot.java b/src/main/java/net/p455w0rd/wirelesscraftingterminal/common/container/slot/AppEngSlot.java index 17516b6..0c0dccf 100644 --- a/src/main/java/net/p455w0rd/wirelesscraftingterminal/common/container/slot/AppEngSlot.java +++ b/src/main/java/net/p455w0rd/wirelesscraftingterminal/common/container/slot/AppEngSlot.java @@ -1,210 +1,10 @@ package net.p455w0rd.wirelesscraftingterminal.common.container.slot; -import appeng.tile.inventory.AppEngInternalInventory; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.inventory.Container; import net.minecraft.inventory.IInventory; -import net.minecraft.inventory.Slot; -import net.minecraft.item.ItemStack; -import net.p455w0rd.wirelesscraftingterminal.common.container.ContainerWirelessCraftingTerminal; -import net.p455w0rd.wirelesscraftingterminal.common.container.WCTBaseContainer; -public class AppEngSlot extends Slot { - - private final int defX; - private final int defY; - private boolean isDraggable = true; - private boolean isPlayerSide = false; - private Container myContainer = null; - private int IIcon = -1; - private hasCalculatedValidness isValid; - private boolean isDisplay = false; +public class AppEngSlot extends appeng.container.slot.AppEngSlot { public AppEngSlot(final IInventory inv, final int idx, final int x, final int y) { super(inv, idx, x, y); - this.defX = x; - this.defY = y; - this.setIsValid(hasCalculatedValidness.NotAvailable); - } - - public Slot setNotDraggable() { - this.setDraggable(false); - return this; - } - - public Slot setPlayerSide() { - this.isPlayerSide = true; - return this; - } - - public String getTooltip() { - return null; - } - - public void clearStack() { - super.putStack(null); - } - - @Override - public boolean isItemValid(final ItemStack par1ItemStack) { - if (this.isEnabled()) { - return super.isItemValid(par1ItemStack); - } - return false; - } - - @Override - public ItemStack getStack() { - if (!this.isEnabled()) { - return null; - } - - if (this.inventory.getSizeInventory() <= this.getSlotIndex()) { - return null; - } - - if (this.isDisplay()) { - this.setDisplay(false); - return this.getDisplayStack(); - } - return super.getStack(); - } - - @Override - public void putStack(final ItemStack par1ItemStack) { - if (this.isEnabled()) { - super.putStack(par1ItemStack); - - if (this.getContainer() != null) { - if (this.getContainer() instanceof ContainerWirelessCraftingTerminal) { - ((ContainerWirelessCraftingTerminal) this.getContainer()).onSlotChange(this); - } - if (this.getContainer() instanceof WCTBaseContainer) { - ((WCTBaseContainer) this.getContainer()).onSlotChange(this); - } - } - } - } - - @Override - public void onSlotChanged() { - if (this.inventory instanceof AppEngInternalInventory) { - ((AppEngInternalInventory) this.inventory).markDirty(this.getSlotIndex()); - } else { - super.onSlotChanged(); - } - - this.setIsValid(hasCalculatedValidness.NotAvailable); - } - - @Override - public boolean canTakeStack(final EntityPlayer par1EntityPlayer) { - if (this.isEnabled()) { - return super.canTakeStack(par1EntityPlayer); - } - return false; - } - - @Override - public boolean func_111238_b() { - return this.isEnabled(); - } - - public ItemStack getDisplayStack() { - return super.getStack(); - } - - public boolean isEnabled() { - return true; - } - - public float getOpacityOfIcon() { - return 0.4f; - } - - public boolean renderIconWithItem() { - return false; - } - - public int getIcon() { - return this.getIIcon(); - } - - public boolean isPlayerSide() { - return this.isPlayerSide; - } - - public boolean shouldDisplay() { - return this.isEnabled(); - } - - public int getX() { - return this.defX; - } - - public int getY() { - return this.defY; - } - - private int getIIcon() { - return this.IIcon; - } - - public void setIIcon(final int iIcon) { - this.IIcon = iIcon; - } - - private boolean isDisplay() { - return this.isDisplay; - } - - public void setDisplay(final boolean isDisplay) { - this.isDisplay = isDisplay; - } - - public boolean isDraggable() { - return this.isDraggable; - } - - private void setDraggable(final boolean isDraggable) { - this.isDraggable = isDraggable; - } - - void setPlayerSide(final boolean isPlayerSide) { - this.isPlayerSide = isPlayerSide; - } - - public hasCalculatedValidness getIsValid() { - return this.isValid; - } - - public void setIsValid(final hasCalculatedValidness isValid) { - this.isValid = isValid; - } - - Container getContainer() { - if (this.myContainer instanceof ContainerWirelessCraftingTerminal) { - return (ContainerWirelessCraftingTerminal) this.myContainer; - } - if (this.myContainer instanceof WCTBaseContainer) { - return (WCTBaseContainer) this.myContainer; - } - return this.myContainer; - } - - public void setContainer(final Container myContainer) { - if (this.myContainer instanceof ContainerWirelessCraftingTerminal) { - this.myContainer = (ContainerWirelessCraftingTerminal) myContainer; - } else if (this.myContainer instanceof WCTBaseContainer) { - this.myContainer = (WCTBaseContainer) myContainer; - } else { - this.myContainer = myContainer; - } - } - - public enum hasCalculatedValidness { - NotAvailable, - Valid, - Invalid } } diff --git a/src/main/java/net/p455w0rd/wirelesscraftingterminal/common/container/slot/SlotPlayerHotBar.java b/src/main/java/net/p455w0rd/wirelesscraftingterminal/common/container/slot/SlotPlayerHotBar.java index 3ce44fc..81e7f56 100644 --- a/src/main/java/net/p455w0rd/wirelesscraftingterminal/common/container/slot/SlotPlayerHotBar.java +++ b/src/main/java/net/p455w0rd/wirelesscraftingterminal/common/container/slot/SlotPlayerHotBar.java @@ -2,10 +2,9 @@ package net.p455w0rd.wirelesscraftingterminal.common.container.slot; import net.minecraft.inventory.IInventory; -public class SlotPlayerHotBar extends AppEngSlot { +public class SlotPlayerHotBar extends appeng.container.slot.SlotPlayerHotBar { public SlotPlayerHotBar(final IInventory par1iInventory, final int par2, final int par3, final int par4) { super(par1iInventory, par2, par3, par4); - this.setPlayerSide(true); } } diff --git a/src/main/java/net/p455w0rd/wirelesscraftingterminal/common/container/slot/SlotPlayerInv.java b/src/main/java/net/p455w0rd/wirelesscraftingterminal/common/container/slot/SlotPlayerInv.java index cfcfe20..9ed4abd 100644 --- a/src/main/java/net/p455w0rd/wirelesscraftingterminal/common/container/slot/SlotPlayerInv.java +++ b/src/main/java/net/p455w0rd/wirelesscraftingterminal/common/container/slot/SlotPlayerInv.java @@ -4,11 +4,9 @@ import net.minecraft.inventory.IInventory; // there is nothing special about this slot, its simply used to represent the players inventory, vs a container slot. -public class SlotPlayerInv extends AppEngSlot { +public class SlotPlayerInv extends appeng.container.slot.SlotPlayerInv { public SlotPlayerInv(final IInventory par1iInventory, final int par2, final int par3, final int par4) { super(par1iInventory, par2, par3, par4); - - this.setPlayerSide(true); } } diff --git a/src/main/java/net/p455w0rd/wirelesscraftingterminal/core/sync/WCTPacketHandlerBase.java b/src/main/java/net/p455w0rd/wirelesscraftingterminal/core/sync/WCTPacketHandlerBase.java index adbf1bc..65dbada 100644 --- a/src/main/java/net/p455w0rd/wirelesscraftingterminal/core/sync/WCTPacketHandlerBase.java +++ b/src/main/java/net/p455w0rd/wirelesscraftingterminal/core/sync/WCTPacketHandlerBase.java @@ -14,9 +14,7 @@ import net.p455w0rd.wirelesscraftingterminal.core.sync.packets.PacketMEInventory import net.p455w0rd.wirelesscraftingterminal.core.sync.packets.PacketMagnetFilter; import net.p455w0rd.wirelesscraftingterminal.core.sync.packets.PacketNEIRecipe; import net.p455w0rd.wirelesscraftingterminal.core.sync.packets.PacketOpenGui; -import net.p455w0rd.wirelesscraftingterminal.core.sync.packets.PacketPartialItem; import net.p455w0rd.wirelesscraftingterminal.core.sync.packets.PacketSetMagnet; -import net.p455w0rd.wirelesscraftingterminal.core.sync.packets.PacketSwapSlots; import net.p455w0rd.wirelesscraftingterminal.core.sync.packets.PacketSwitchGuis; import net.p455w0rd.wirelesscraftingterminal.core.sync.packets.PacketValueConfig; @@ -33,12 +31,8 @@ public class WCTPacketHandlerBase { PACKET_SWITCH_GUIS(PacketSwitchGuis.class), - PACKET_SWAP_SLOTS(PacketSwapSlots.class), - PACKET_RECIPE_NEI(PacketNEIRecipe.class), - PACKET_PARTIAL_ITEM(PacketPartialItem.class), - PACKET_CRAFTING_REQUEST(PacketCraftRequest.class), PACKET_MAGNETFILTER_MODE(PacketMagnetFilter.class), diff --git a/src/main/java/net/p455w0rd/wirelesscraftingterminal/core/sync/packets/PacketInventoryAction.java b/src/main/java/net/p455w0rd/wirelesscraftingterminal/core/sync/packets/PacketInventoryAction.java index ec013ff..c1b0ca0 100644 --- a/src/main/java/net/p455w0rd/wirelesscraftingterminal/core/sync/packets/PacketInventoryAction.java +++ b/src/main/java/net/p455w0rd/wirelesscraftingterminal/core/sync/packets/PacketInventoryAction.java @@ -2,6 +2,8 @@ package net.p455w0rd.wirelesscraftingterminal.core.sync.packets; import appeng.api.storage.data.IAEItemStack; import appeng.client.ClientHelper; +import appeng.container.AEBaseContainer; +import appeng.container.ContainerOpenContext; import appeng.container.implementations.ContainerCraftAmount; import appeng.helpers.InventoryAction; import appeng.util.Platform; @@ -13,9 +15,7 @@ import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.inventory.Container; import net.p455w0rd.wirelesscraftingterminal.common.WCTGuiHandler; -import net.p455w0rd.wirelesscraftingterminal.common.container.ContainerOpenContext; import net.p455w0rd.wirelesscraftingterminal.common.container.ContainerWirelessCraftingTerminal; -import net.p455w0rd.wirelesscraftingterminal.common.container.WCTBaseContainer; import net.p455w0rd.wirelesscraftingterminal.common.utils.RandomUtils; import net.p455w0rd.wirelesscraftingterminal.core.sync.WCTPacket; import net.p455w0rd.wirelesscraftingterminal.core.sync.network.INetworkInfo; @@ -95,15 +95,10 @@ public class PacketInventoryAction extends WCTPacket { final EntityPlayerMP sender = (EntityPlayerMP) player; Container baseContainer = sender.openContainer; ContainerOpenContext context = null; - if (sender.openContainer instanceof ContainerWirelessCraftingTerminal) { - baseContainer = (ContainerWirelessCraftingTerminal) sender.openContainer; - context = ((ContainerWirelessCraftingTerminal) baseContainer).getOpenContext(); + if (baseContainer instanceof AEBaseContainer) { + context = ((AEBaseContainer) baseContainer).getOpenContext(); } - if (sender.openContainer instanceof WCTBaseContainer) { - baseContainer = (WCTBaseContainer) sender.openContainer; - context = ((WCTBaseContainer) baseContainer).getOpenContext(); - } if (this.action == InventoryAction.AUTO_CRAFT) { // if( context != null ) @@ -129,13 +124,13 @@ public class PacketInventoryAction extends WCTPacket { } } - if (baseContainer instanceof WCTBaseContainer) { - if (((WCTBaseContainer) baseContainer).getTargetStack() != null) { + if (baseContainer instanceof AEBaseContainer) { + if (((AEBaseContainer) baseContainer).getTargetStack() != null) { cca.getCraftingItem() - .putStack(((WCTBaseContainer) baseContainer) + .putStack(((AEBaseContainer) baseContainer) .getTargetStack() .getItemStack()); - cca.setItemToCraft(((WCTBaseContainer) baseContainer).getTargetStack()); + cca.setItemToCraft(((AEBaseContainer) baseContainer).getTargetStack()); } } @@ -150,8 +145,8 @@ public class PacketInventoryAction extends WCTPacket { ((ContainerWirelessCraftingTerminal) baseContainer) .doAction(sender, this.action, this.slot, this.id); } - if (baseContainer instanceof WCTBaseContainer) { - ((WCTBaseContainer) baseContainer).doAction(sender, this.action, this.slot, this.id); + if (baseContainer instanceof AEBaseContainer) { + ((AEBaseContainer) baseContainer).doAction(sender, this.action, this.slot, this.id); } } } diff --git a/src/main/java/net/p455w0rd/wirelesscraftingterminal/core/sync/packets/PacketNEIRecipe.java b/src/main/java/net/p455w0rd/wirelesscraftingterminal/core/sync/packets/PacketNEIRecipe.java index d542e08..3c27778 100644 --- a/src/main/java/net/p455w0rd/wirelesscraftingterminal/core/sync/packets/PacketNEIRecipe.java +++ b/src/main/java/net/p455w0rd/wirelesscraftingterminal/core/sync/packets/PacketNEIRecipe.java @@ -39,6 +39,7 @@ import net.minecraft.world.World; import net.minecraftforge.common.util.ForgeDirection; import net.minecraftforge.oredict.OreDictionary; import net.p455w0rd.wirelesscraftingterminal.api.IWirelessCraftingTermHandler; +import net.p455w0rd.wirelesscraftingterminal.common.container.ContainerWirelessCraftingTerminal; import net.p455w0rd.wirelesscraftingterminal.common.utils.RandomUtils; import net.p455w0rd.wirelesscraftingterminal.core.sync.WCTPacket; import net.p455w0rd.wirelesscraftingterminal.core.sync.network.INetworkInfo; @@ -82,19 +83,6 @@ public class PacketNEIRecipe extends WCTPacket { configureWrite(data); } - private WirelessTerminalGuiObject getGuiObject( - final ItemStack it, final EntityPlayer player, final World w, final int x, final int y, final int z) { - if (it != null) { - final IWirelessCraftingTermHandler wh = (IWirelessCraftingTermHandler) - AEApi.instance().registries().wireless().getWirelessTerminalHandler(it); - if (wh != null) { - return new WirelessTerminalGuiObject(wh, it, player, w, x, y, z); - } - } - - return null; - } - @SuppressWarnings({"rawtypes", "unchecked"}) @Override public void serverPacketData(final INetworkInfo manager, final WCTPacket packet, final EntityPlayer player) { @@ -106,7 +94,7 @@ public class PacketNEIRecipe extends WCTPacket { IGridNode node = cct.getNetworkNode(); if (node == null) { - WirelessTerminalGuiObject obj = getGuiObject( + WirelessTerminalGuiObject obj = ContainerWirelessCraftingTerminal.getGuiObject( RandomUtils.getWirelessTerm(player.inventory), player, player.worldObj, diff --git a/src/main/java/net/p455w0rd/wirelesscraftingterminal/core/sync/packets/PacketPartialItem.java b/src/main/java/net/p455w0rd/wirelesscraftingterminal/core/sync/packets/PacketPartialItem.java deleted file mode 100644 index e4d94fe..0000000 --- a/src/main/java/net/p455w0rd/wirelesscraftingterminal/core/sync/packets/PacketPartialItem.java +++ /dev/null @@ -1,58 +0,0 @@ -package net.p455w0rd.wirelesscraftingterminal.core.sync.packets; - -import io.netty.buffer.ByteBuf; -import io.netty.buffer.Unpooled; -import net.minecraft.entity.player.EntityPlayer; -import net.p455w0rd.wirelesscraftingterminal.common.container.ContainerWirelessCraftingTerminal; -import net.p455w0rd.wirelesscraftingterminal.common.container.WCTBaseContainer; -import net.p455w0rd.wirelesscraftingterminal.core.sync.WCTPacket; -import net.p455w0rd.wirelesscraftingterminal.core.sync.network.INetworkInfo; - -public class PacketPartialItem extends WCTPacket { - - private final short pageNum; - private final byte[] data; - - // automatic. - public PacketPartialItem(final ByteBuf stream) { - this.pageNum = stream.readShort(); - stream.readBytes(this.data = new byte[stream.readableBytes()]); - } - - // api - public PacketPartialItem(final int page, final int maxPages, final byte[] buf) { - - final ByteBuf data = Unpooled.buffer(); - - this.pageNum = (short) (page | (maxPages << 8)); - this.data = buf; - data.writeInt(this.getPacketID()); - data.writeShort(this.pageNum); - data.writeBytes(buf); - - this.configureWrite(data); - } - - @Override - public void serverPacketData(final INetworkInfo manager, final WCTPacket packet, final EntityPlayer player) { - if (player.openContainer instanceof ContainerWirelessCraftingTerminal) { - ((ContainerWirelessCraftingTerminal) player.openContainer).postPartial(this); - } - if (player.openContainer instanceof WCTBaseContainer) { - ((WCTBaseContainer) player.openContainer).postPartial(this); - } - } - - public int getPageCount() { - return this.pageNum >> 8; - } - - public int getSize() { - return this.data.length; - } - - public int write(final byte[] buffer, final int cursor) { - System.arraycopy(this.data, 0, buffer, cursor, this.data.length); - return cursor + this.data.length; - } -} diff --git a/src/main/java/net/p455w0rd/wirelesscraftingterminal/core/sync/packets/PacketProgressBar.java b/src/main/java/net/p455w0rd/wirelesscraftingterminal/core/sync/packets/PacketProgressBar.java deleted file mode 100644 index fc489ad..0000000 --- a/src/main/java/net/p455w0rd/wirelesscraftingterminal/core/sync/packets/PacketProgressBar.java +++ /dev/null @@ -1,58 +0,0 @@ -package net.p455w0rd.wirelesscraftingterminal.core.sync.packets; - -import io.netty.buffer.ByteBuf; -import io.netty.buffer.Unpooled; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.inventory.Container; -import net.p455w0rd.wirelesscraftingterminal.common.container.ContainerWirelessCraftingTerminal; -import net.p455w0rd.wirelesscraftingterminal.common.container.WCTBaseContainer; -import net.p455w0rd.wirelesscraftingterminal.core.sync.WCTPacket; -import net.p455w0rd.wirelesscraftingterminal.core.sync.network.INetworkInfo; - -public class PacketProgressBar extends WCTPacket { - - private final short id; - private final long value; - - // automatic. - public PacketProgressBar(final ByteBuf stream) { - this.id = stream.readShort(); - this.value = stream.readLong(); - } - - // api - public PacketProgressBar(final int shortID, final long value) { - this.id = (short) shortID; - this.value = value; - - final ByteBuf data = Unpooled.buffer(); - - data.writeInt(this.getPacketID()); - data.writeShort(shortID); - data.writeLong(value); - - this.configureWrite(data); - } - - @Override - public void serverPacketData(final INetworkInfo manager, final WCTPacket packet, final EntityPlayer player) { - final Container c = player.openContainer; - if (c instanceof ContainerWirelessCraftingTerminal) { - ((ContainerWirelessCraftingTerminal) c).updateFullProgressBar(this.id, this.value); - } - if (c instanceof WCTBaseContainer) { - ((WCTBaseContainer) c).updateFullProgressBar(this.id, this.value); - } - } - - @Override - public void clientPacketData(final INetworkInfo network, final WCTPacket packet, final EntityPlayer player) { - final Container c = player.openContainer; - if (c instanceof ContainerWirelessCraftingTerminal) { - ((ContainerWirelessCraftingTerminal) c).updateFullProgressBar(this.id, this.value); - } - if (c instanceof WCTBaseContainer) { - ((WCTBaseContainer) c).updateFullProgressBar(this.id, this.value); - } - } -} diff --git a/src/main/java/net/p455w0rd/wirelesscraftingterminal/core/sync/packets/PacketSwapSlots.java b/src/main/java/net/p455w0rd/wirelesscraftingterminal/core/sync/packets/PacketSwapSlots.java deleted file mode 100644 index 8f74f18..0000000 --- a/src/main/java/net/p455w0rd/wirelesscraftingterminal/core/sync/packets/PacketSwapSlots.java +++ /dev/null @@ -1,44 +0,0 @@ -package net.p455w0rd.wirelesscraftingterminal.core.sync.packets; - -import io.netty.buffer.ByteBuf; -import io.netty.buffer.Unpooled; -import net.minecraft.entity.player.EntityPlayer; -import net.p455w0rd.wirelesscraftingterminal.common.container.ContainerWirelessCraftingTerminal; -import net.p455w0rd.wirelesscraftingterminal.common.container.WCTBaseContainer; -import net.p455w0rd.wirelesscraftingterminal.core.sync.WCTPacket; -import net.p455w0rd.wirelesscraftingterminal.core.sync.network.INetworkInfo; - -public class PacketSwapSlots extends WCTPacket { - - private final int slotA; - private final int slotB; - - // automatic. - public PacketSwapSlots(final ByteBuf stream) { - this.slotA = stream.readInt(); - this.slotB = stream.readInt(); - } - - // api - public PacketSwapSlots(final int slotA, final int slotB) { - final ByteBuf data = Unpooled.buffer(); - - data.writeInt(this.getPacketID()); - data.writeInt(this.slotA = slotA); - data.writeInt(this.slotB = slotB); - - this.configureWrite(data); - } - - @Override - public void serverPacketData(final INetworkInfo manager, final WCTPacket packet, final EntityPlayer player) { - if (player != null) { - if (player.openContainer instanceof ContainerWirelessCraftingTerminal) { - ((ContainerWirelessCraftingTerminal) player.openContainer).swapSlotContents(this.slotA, this.slotB); - } - if (player.openContainer instanceof WCTBaseContainer) { - ((WCTBaseContainer) player.openContainer).swapSlotContents(this.slotA, this.slotB); - } - } - } -} diff --git a/src/main/java/net/p455w0rd/wirelesscraftingterminal/core/sync/packets/PacketValueConfig.java b/src/main/java/net/p455w0rd/wirelesscraftingterminal/core/sync/packets/PacketValueConfig.java index 6b6a9ae..e09728a 100644 --- a/src/main/java/net/p455w0rd/wirelesscraftingterminal/core/sync/packets/PacketValueConfig.java +++ b/src/main/java/net/p455w0rd/wirelesscraftingterminal/core/sync/packets/PacketValueConfig.java @@ -3,6 +3,7 @@ package net.p455w0rd.wirelesscraftingterminal.core.sync.packets; import appeng.api.config.Settings; import appeng.api.util.IConfigManager; import appeng.api.util.IConfigurableObject; +import appeng.container.AEBaseContainer; import appeng.helpers.IMouseWheelItem; import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; @@ -15,7 +16,6 @@ import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.Container; import net.minecraft.item.ItemStack; import net.p455w0rd.wirelesscraftingterminal.common.container.ContainerWirelessCraftingTerminal; -import net.p455w0rd.wirelesscraftingterminal.common.container.WCTBaseContainer; import net.p455w0rd.wirelesscraftingterminal.common.utils.RandomUtils; import net.p455w0rd.wirelesscraftingterminal.core.sync.WCTPacket; import net.p455w0rd.wirelesscraftingterminal.core.sync.network.INetworkInfo; @@ -85,19 +85,12 @@ public class PacketValueConfig extends WCTPacket { final Container c = player.openContainer; if (this.Name.equals("CustomName")) { - if (c instanceof ContainerWirelessCraftingTerminal) { - ((ContainerWirelessCraftingTerminal) c).setCustomName(this.Value); - } - if (c instanceof WCTBaseContainer) { - ((WCTBaseContainer) c).setCustomName(this.Value); + if (c instanceof AEBaseContainer) { + ((AEBaseContainer) c).setCustomName(this.Value); } } else if (this.Name.startsWith("SyncDat.")) { - if (c instanceof ContainerWirelessCraftingTerminal) { - ((ContainerWirelessCraftingTerminal) c) - .stringSync(Integer.parseInt(this.Name.substring(8)), this.Value); - } - if (c instanceof WCTBaseContainer) { - ((WCTBaseContainer) c).stringSync(Integer.parseInt(this.Name.substring(8)), this.Value); + if (c instanceof AEBaseContainer) { + ((AEBaseContainer) c).stringSync(Integer.parseInt(this.Name.substring(8)), this.Value); } } else if (c instanceof IConfigurableObject) { final IConfigManager cm = ((IConfigurableObject) c).getConfigManager(); diff --git a/src/main/java/net/p455w0rd/wirelesscraftingterminal/helpers/WirelessTerminalGuiObject.java b/src/main/java/net/p455w0rd/wirelesscraftingterminal/helpers/WirelessTerminalGuiObject.java index 4a3d07d..9f7c68d 100644 --- a/src/main/java/net/p455w0rd/wirelesscraftingterminal/helpers/WirelessTerminalGuiObject.java +++ b/src/main/java/net/p455w0rd/wirelesscraftingterminal/helpers/WirelessTerminalGuiObject.java @@ -6,6 +6,7 @@ import appeng.api.config.Actionable; import appeng.api.config.PowerMultiplier; import appeng.api.features.ILocatable; import appeng.api.features.IWirelessTermHandler; +import appeng.api.implementations.guiobjects.IGuiItemObject; import appeng.api.implementations.guiobjects.IPortableCell; import appeng.api.implementations.tiles.IWirelessAccessPoint; import appeng.api.networking.IGrid; @@ -33,7 +34,7 @@ import net.minecraftforge.common.util.ForgeDirection; import net.p455w0rd.wirelesscraftingterminal.api.IWirelessCraftingTerminalItem; import net.p455w0rd.wirelesscraftingterminal.api.networking.security.WCTIActionHost; -public class WirelessTerminalGuiObject implements IActionHost, IPortableCell, IInventorySlotAware, WCTIActionHost { +public class WirelessTerminalGuiObject implements IActionHost, IPortableCell, IInventorySlotAware, WCTIActionHost, IGuiItemObject { private final ItemStack effectiveItem; private final IWirelessTermHandler wth; diff --git a/src/main/java/net/p455w0rd/wirelesscraftingterminal/items/ItemMagnet.java b/src/main/java/net/p455w0rd/wirelesscraftingterminal/items/ItemMagnet.java index 653108f..626c350 100644 --- a/src/main/java/net/p455w0rd/wirelesscraftingterminal/items/ItemMagnet.java +++ b/src/main/java/net/p455w0rd/wirelesscraftingterminal/items/ItemMagnet.java @@ -477,19 +477,6 @@ public class ItemMagnet extends Item { return true; } - public WirelessTerminalGuiObject getGuiObject( - final ItemStack it, final EntityPlayer player, final World w, final int x, final int y, final int z) { - if (it != null) { - final IWirelessCraftingTermHandler wh = (IWirelessCraftingTermHandler) - AEApi.instance().registries().wireless().getWirelessTerminalHandler(it); - if (wh != null) { - return new WirelessTerminalGuiObject(wh, it, player, w, x, y, z); - } - } - - return null; - } - public static List getEntitiesInRange( Class entityType, World world, int x, int y, int z, int distance) { return world.getEntitiesWithinAABB( diff --git a/src/main/java/net/p455w0rd/wirelesscraftingterminal/items/ItemWirelessCraftingTerminal.java b/src/main/java/net/p455w0rd/wirelesscraftingterminal/items/ItemWirelessCraftingTerminal.java index df3d467..e8a2159 100644 --- a/src/main/java/net/p455w0rd/wirelesscraftingterminal/items/ItemWirelessCraftingTerminal.java +++ b/src/main/java/net/p455w0rd/wirelesscraftingterminal/items/ItemWirelessCraftingTerminal.java @@ -1,6 +1,7 @@ package net.p455w0rd.wirelesscraftingterminal.items; import appeng.api.config.*; +import appeng.api.features.IWirelessTermHandler; import appeng.api.util.IConfigManager; import appeng.items.tools.powered.powersink.AERootPoweredItem; import appeng.util.ConfigManager; @@ -32,7 +33,7 @@ import net.p455w0rd.wirelesscraftingterminal.integration.EnderIO; import net.p455w0rd.wirelesscraftingterminal.reference.Reference; import org.lwjgl.input.Keyboard; -public class ItemWirelessCraftingTerminal extends AERootPoweredItem implements IWirelessCraftingTerminalItem, IBauble { +public class ItemWirelessCraftingTerminal extends AERootPoweredItem implements IWirelessCraftingTerminalItem, IWirelessTermHandler, IBauble { public static final String LINK_KEY_STRING = "key"; public static double GLOBAL_POWER_MULTIPLIER = PowerMultiplier.CONFIG.multiplier; diff --git a/src/main/java/net/p455w0rd/wirelesscraftingterminal/proxy/CommonProxy.java b/src/main/java/net/p455w0rd/wirelesscraftingterminal/proxy/CommonProxy.java index 8f7eb5b..da1dcb7 100644 --- a/src/main/java/net/p455w0rd/wirelesscraftingterminal/proxy/CommonProxy.java +++ b/src/main/java/net/p455w0rd/wirelesscraftingterminal/proxy/CommonProxy.java @@ -31,6 +31,7 @@ import net.minecraftforge.event.entity.living.LivingDropsEvent; import net.minecraftforge.event.entity.player.EntityItemPickupEvent; import net.p455w0rd.wirelesscraftingterminal.api.IWirelessCraftingTerminalItem; import net.p455w0rd.wirelesscraftingterminal.api.networking.security.WCTPlayerSource; +import net.p455w0rd.wirelesscraftingterminal.common.container.ContainerWirelessCraftingTerminal; import net.p455w0rd.wirelesscraftingterminal.common.utils.RandomUtils; import net.p455w0rd.wirelesscraftingterminal.core.sync.WCTPacket; import net.p455w0rd.wirelesscraftingterminal.core.sync.network.NetworkHandler; @@ -225,7 +226,7 @@ public class CommonProxy { if (magnetStack.getItem() instanceof ItemMagnet) { ItemMagnet magnet = (ItemMagnet) magnetStack.getItem(); - magnet.obj = magnet.getGuiObject( + magnet.obj = ContainerWirelessCraftingTerminal.getGuiObject( WCTStack, player, world, (int) player.posX, (int) player.posY, (int) player.posZ); magnet.civ = magnet.obj; magnet.powerSrc = magnet.civ; From 2d1851c88fba0a8e1504966e6ba5600d5bf92b19 Mon Sep 17 00:00:00 2001 From: Raven Szewczyk Date: Wed, 24 Aug 2022 18:42:02 +0100 Subject: [PATCH 05/11] Update to ae2 with the new APIs --- dependencies.gradle | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/dependencies.gradle b/dependencies.gradle index 21ba945..5581154 100644 --- a/dependencies.gradle +++ b/dependencies.gradle @@ -1,10 +1,10 @@ // Add your dependencies here dependencies { - compile("com.github.GTNewHorizons:Applied-Energistics-2-Unofficial:rv3-beta-98-GTNH:dev") - compile("com.github.GTNewHorizons:Baubles:1.0.1.14:dev") - compile("curse.maven:cofh-core-69162:2388751") - compile("com.github.GTNewHorizons:NotEnoughItems:2.2.27-GTNH:dev") - compile("com.github.GTNewHorizons:CodeChickenLib:1.1.5.4:dev") - compileOnly("com.github.GTNewHorizons:EnderIO:2.3.1.43:dev") { transitive = false } + compile("com.github.GTNewHorizons:Applied-Energistics-2-Unofficial:rv3-beta-99-GTNH:dev") + compile("com.github.GTNewHorizons:Baubles:1.0.1.14:dev") + compile("curse.maven:cofh-core-69162:2388751") + compile("com.github.GTNewHorizons:NotEnoughItems:2.2.27-GTNH:dev") + compile("com.github.GTNewHorizons:CodeChickenLib:1.1.5.4:dev") + compileOnly("com.github.GTNewHorizons:EnderIO:2.3.1.43:dev") { transitive = false } } From c5bcb1841b3b3dc5e69870bffd52d86d08484b09 Mon Sep 17 00:00:00 2001 From: Raven Szewczyk Date: Wed, 24 Aug 2022 19:24:12 +0100 Subject: [PATCH 06/11] Migrate to AE slot types where possible, everything is working again now --- .../client/gui/GuiCraftConfirm.java | 3 - .../client/gui/GuiCraftingStatus.java | 2 + .../gui/GuiWirelessCraftingTerminal.java | 237 ++++++++++------- .../client/me/ClientDCInternalInv.java | 43 ---- .../client/me/InternalSlotME.java | 39 --- .../client/me/ItemRepo.java | 240 ----------------- .../client/me/SlotDisconnected.java | 73 ------ .../client/me/SlotME.java | 71 ----- .../client/me/WCTRenderItem.java | 147 ----------- .../client/textures/IStateIconTexture.java | 48 ---- .../client/textures/WCTStateIconsEnum.java | 150 ----------- .../common/WCTGuiHandler.java | 16 +- .../container/ContainerCraftAmount.java | 3 - .../container/ContainerCraftConfirm.java | 3 - .../ContainerWirelessCraftingTerminal.java | 189 +++++++------- .../container/slot/AppEngCraftingSlot.java | 161 ------------ .../common/container/slot/AppEngSlot.java | 10 - .../common/container/slot/NullSlot.java | 59 ----- .../container/slot/OptionalSlotFake.java | 1 + .../common/container/slot/SlotArmor.java | 2 +- .../common/container/slot/SlotBooster.java | 2 +- .../container/slot/SlotCraftingMatrix.java | 40 --- .../container/slot/SlotCraftingTerm.java | 243 ------------------ .../common/container/slot/SlotDisabled.java | 22 -- .../common/container/slot/SlotFake.java | 39 --- .../slot/SlotFakeCraftingMatrix.java | 10 - .../container/slot/SlotInaccessible.java | 41 --- .../common/container/slot/SlotMagnet.java | 2 +- .../common/container/slot/SlotOutput.java | 17 -- .../container/slot/SlotPlayerHotBar.java | 10 - .../common/container/slot/SlotPlayerInv.java | 12 - .../common/container/slot/SlotTrash.java | 2 +- .../common/container/slot/SlotViewCell.java | 18 +- .../common/registries/EnumCache.java | 22 -- .../common/utils/ReflectionUtils.java | 61 ----- .../sync/packets/PacketInventoryAction.java | 1 - .../core/sync/packets/PacketNEIRecipe.java | 3 - .../core/sync/packets/PacketValueConfig.java | 1 - .../helpers/WirelessTerminalGuiObject.java | 3 +- .../integration/modules/NEI.java | 4 +- .../NEIHelpers/NEICraftingHandler.java | 4 +- .../items/ItemMagnet.java | 2 - .../items/ItemWirelessCraftingTerminal.java | 3 +- 43 files changed, 260 insertions(+), 1799 deletions(-) delete mode 100644 src/main/java/net/p455w0rd/wirelesscraftingterminal/client/me/ClientDCInternalInv.java delete mode 100644 src/main/java/net/p455w0rd/wirelesscraftingterminal/client/me/InternalSlotME.java delete mode 100644 src/main/java/net/p455w0rd/wirelesscraftingterminal/client/me/ItemRepo.java delete mode 100644 src/main/java/net/p455w0rd/wirelesscraftingterminal/client/me/SlotDisconnected.java delete mode 100644 src/main/java/net/p455w0rd/wirelesscraftingterminal/client/me/SlotME.java delete mode 100644 src/main/java/net/p455w0rd/wirelesscraftingterminal/client/me/WCTRenderItem.java delete mode 100644 src/main/java/net/p455w0rd/wirelesscraftingterminal/client/textures/IStateIconTexture.java delete mode 100644 src/main/java/net/p455w0rd/wirelesscraftingterminal/client/textures/WCTStateIconsEnum.java delete mode 100644 src/main/java/net/p455w0rd/wirelesscraftingterminal/common/container/slot/AppEngCraftingSlot.java delete mode 100644 src/main/java/net/p455w0rd/wirelesscraftingterminal/common/container/slot/AppEngSlot.java delete mode 100644 src/main/java/net/p455w0rd/wirelesscraftingterminal/common/container/slot/NullSlot.java delete mode 100644 src/main/java/net/p455w0rd/wirelesscraftingterminal/common/container/slot/SlotCraftingMatrix.java delete mode 100644 src/main/java/net/p455w0rd/wirelesscraftingterminal/common/container/slot/SlotCraftingTerm.java delete mode 100644 src/main/java/net/p455w0rd/wirelesscraftingterminal/common/container/slot/SlotDisabled.java delete mode 100644 src/main/java/net/p455w0rd/wirelesscraftingterminal/common/container/slot/SlotFake.java delete mode 100644 src/main/java/net/p455w0rd/wirelesscraftingterminal/common/container/slot/SlotFakeCraftingMatrix.java delete mode 100644 src/main/java/net/p455w0rd/wirelesscraftingterminal/common/container/slot/SlotInaccessible.java delete mode 100644 src/main/java/net/p455w0rd/wirelesscraftingterminal/common/container/slot/SlotOutput.java delete mode 100644 src/main/java/net/p455w0rd/wirelesscraftingterminal/common/container/slot/SlotPlayerHotBar.java delete mode 100644 src/main/java/net/p455w0rd/wirelesscraftingterminal/common/container/slot/SlotPlayerInv.java delete mode 100644 src/main/java/net/p455w0rd/wirelesscraftingterminal/common/registries/EnumCache.java delete mode 100644 src/main/java/net/p455w0rd/wirelesscraftingterminal/common/utils/ReflectionUtils.java diff --git a/src/main/java/net/p455w0rd/wirelesscraftingterminal/client/gui/GuiCraftConfirm.java b/src/main/java/net/p455w0rd/wirelesscraftingterminal/client/gui/GuiCraftConfirm.java index bf91443..975382f 100644 --- a/src/main/java/net/p455w0rd/wirelesscraftingterminal/client/gui/GuiCraftConfirm.java +++ b/src/main/java/net/p455w0rd/wirelesscraftingterminal/client/gui/GuiCraftConfirm.java @@ -1,12 +1,9 @@ package net.p455w0rd.wirelesscraftingterminal.client.gui; import appeng.api.storage.ITerminalHost; -import appeng.core.localization.GuiText; -import net.minecraft.client.gui.GuiButton; import net.minecraft.entity.player.InventoryPlayer; import net.p455w0rd.wirelesscraftingterminal.core.sync.network.NetworkHandler; import net.p455w0rd.wirelesscraftingterminal.core.sync.packets.PacketSwitchGuis; -import net.p455w0rd.wirelesscraftingterminal.helpers.WirelessTerminalGuiObject; import net.p455w0rd.wirelesscraftingterminal.reference.Reference; public class GuiCraftConfirm extends appeng.client.gui.implementations.GuiCraftConfirm { diff --git a/src/main/java/net/p455w0rd/wirelesscraftingterminal/client/gui/GuiCraftingStatus.java b/src/main/java/net/p455w0rd/wirelesscraftingterminal/client/gui/GuiCraftingStatus.java index 1c56db6..41661ed 100644 --- a/src/main/java/net/p455w0rd/wirelesscraftingterminal/client/gui/GuiCraftingStatus.java +++ b/src/main/java/net/p455w0rd/wirelesscraftingterminal/client/gui/GuiCraftingStatus.java @@ -57,6 +57,8 @@ public class GuiCraftingStatus extends appeng.client.gui.implementations.GuiCraf @Override public void initGui() { super.initGui(); + // Hide "go back to wireless terminal" button as it opens the wrong GUI + this.buttonList.remove(this.buttonList.size() - 1); if (this.myIcon != null) { this.buttonList.add( diff --git a/src/main/java/net/p455w0rd/wirelesscraftingterminal/client/gui/GuiWirelessCraftingTerminal.java b/src/main/java/net/p455w0rd/wirelesscraftingterminal/client/gui/GuiWirelessCraftingTerminal.java index d10eb52..13abe91 100644 --- a/src/main/java/net/p455w0rd/wirelesscraftingterminal/client/gui/GuiWirelessCraftingTerminal.java +++ b/src/main/java/net/p455w0rd/wirelesscraftingterminal/client/gui/GuiWirelessCraftingTerminal.java @@ -15,6 +15,11 @@ import appeng.client.gui.widgets.GuiScrollbar; import appeng.client.gui.widgets.ISortSource; import appeng.client.me.InternalSlotME; import appeng.client.me.ItemRepo; +import appeng.client.me.SlotME; +import appeng.container.AEBaseContainer; +import appeng.container.slot.AppEngSlot; +import appeng.container.slot.SlotCraftingMatrix; +import appeng.container.slot.SlotFakeCraftingMatrix; import appeng.core.AEConfig; import appeng.core.CommonHelper; import appeng.core.localization.ButtonToolTips; @@ -25,9 +30,16 @@ import appeng.util.Platform; import codechicken.nei.TextField; import cpw.mods.fml.common.Loader; import cpw.mods.fml.relauncher.ReflectionHelper; +import java.io.IOException; +import java.lang.reflect.Field; +import java.text.NumberFormat; +import java.util.List; +import java.util.Locale; +import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiButton; import net.minecraft.client.gui.inventory.GuiInventory; import net.minecraft.client.resources.I18n; +import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.Container; import net.minecraft.inventory.Slot; import net.minecraft.item.ItemStack; @@ -35,11 +47,7 @@ import net.minecraft.util.ResourceLocation; import net.p455w0rd.wirelesscraftingterminal.client.gui.widgets.GuiTabButton; import net.p455w0rd.wirelesscraftingterminal.client.gui.widgets.GuiTrashButton; import net.p455w0rd.wirelesscraftingterminal.client.gui.widgets.MEGuiTextField; -import net.p455w0rd.wirelesscraftingterminal.client.me.SlotME; import net.p455w0rd.wirelesscraftingterminal.common.container.ContainerWirelessCraftingTerminal; -import net.p455w0rd.wirelesscraftingterminal.common.container.slot.AppEngSlot; -import net.p455w0rd.wirelesscraftingterminal.common.container.slot.SlotCraftingMatrix; -import net.p455w0rd.wirelesscraftingterminal.common.container.slot.SlotFakeCraftingMatrix; import net.p455w0rd.wirelesscraftingterminal.common.container.slot.SlotTrash; import net.p455w0rd.wirelesscraftingterminal.common.utils.WCTLog; import net.p455w0rd.wirelesscraftingterminal.core.sync.network.NetworkHandler; @@ -52,35 +60,29 @@ import net.p455w0rd.wirelesscraftingterminal.reference.Reference; import org.lwjgl.input.Keyboard; import org.lwjgl.input.Mouse; -import java.io.IOException; -import java.lang.reflect.Field; -import java.text.NumberFormat; -import java.util.List; -import java.util.Locale; - public class GuiWirelessCraftingTerminal extends AEBaseGui implements ISortSource, IConfigManagerHost { private float xSize_lo; private float ySize_lo; public static int tick = 0, - GUI_HEIGHT = 240, - GUI_WIDTH = 230, - AE_ROW_HEIGHT = 18, - AE_NUM_ROWS = 0, - GUI_UPPER_HEIGHT = 35, - GUI_SEARCH_ROW = 35, - SEARCH_X = 81, - SEARCH_Y = 5, - SEARCH_WIDTH = 88, - SEARCH_HEIGHT = 12, - SEARCH_MAXCHARS = 15, - GUI_LOWER_HEIGHT, - AE_TOTAL_ROWS_HEIGHT, - BUTTON_SEARCH_MODE_POS_X = -18, - BUTTON_SEARCH_MODE_POS_Y = 68, - BUTTON_SIZE = 16, - NEI_EXTRA_SPACE = 30, - slotYOffset; + GUI_HEIGHT = 240, + GUI_WIDTH = 230, + AE_ROW_HEIGHT = 18, + AE_NUM_ROWS = 0, + GUI_UPPER_HEIGHT = 35, + GUI_SEARCH_ROW = 35, + SEARCH_X = 81, + SEARCH_Y = 5, + SEARCH_WIDTH = 88, + SEARCH_HEIGHT = 12, + SEARCH_MAXCHARS = 15, + GUI_LOWER_HEIGHT, + AE_TOTAL_ROWS_HEIGHT, + BUTTON_SEARCH_MODE_POS_X = -18, + BUTTON_SEARCH_MODE_POS_Y = 68, + BUTTON_SIZE = 16, + NEI_EXTRA_SPACE = 30, + slotYOffset; protected static final int BUTTON_SEARCH_MODE_ID = 5; protected static final long TOOLTIP_UPDATE_INTERVAL = 3000L; private int currScreenWidth, currScreenHeight; @@ -147,8 +149,8 @@ public class GuiWirelessCraftingTerminal extends AEBaseGui implements ISortSourc private void setScrollBar() { this.getScrollBar().setTop(18).setLeft(174).setHeight(this.rows * 18 - 2); this.getScrollBar() - .setRange( - 0, (this.repo.size() + this.perRow - 1) / this.perRow - this.rows, Math.max(1, this.rows / 6)); + .setRange( + 0, (this.repo.size() + this.perRow - 1) / this.perRow - this.rows, Math.max(1, this.rows / 6)); } @SuppressWarnings("rawtypes") @@ -165,7 +167,7 @@ public class GuiWirelessCraftingTerminal extends AEBaseGui implements ISortSourc if (iBtn.getSetting() != Settings.ACTIONS) { final Enum cv = iBtn.getCurrentValue(); final Enum next = - Platform.rotateEnum(cv, backwards, iBtn.getSetting().getPossibleValues()); + Platform.rotateEnum(cv, backwards, iBtn.getSetting().getPossibleValues()); if (btn == this.terminalStyleBox) { AEConfig.instance.settings.putSetting(iBtn.getSetting(), next); @@ -177,7 +179,7 @@ public class GuiWirelessCraftingTerminal extends AEBaseGui implements ISortSourc } else { try { NetworkHandler.instance.sendToServer( - new PacketValueConfig(iBtn.getSetting().name(), next.name())); + new PacketValueConfig(iBtn.getSetting().name(), next.name())); } catch (final IOException e) { WCTLog.debug(e.getMessage()); } @@ -200,7 +202,7 @@ public class GuiWirelessCraftingTerminal extends AEBaseGui implements ISortSourc if (s != null) { final PacketInventoryAction p = - new PacketInventoryAction(InventoryAction.MOVE_REGION, s.slotNumber, 0); + new PacketInventoryAction(InventoryAction.MOVE_REGION, s.slotNumber, 0); NetworkHandler.instance.sendToServer(p); } } @@ -225,6 +227,47 @@ public class GuiWirelessCraftingTerminal extends AEBaseGui implements ISortSourc } } + @Override + protected void handleMouseClick(Slot slot, int slotIdx, int ctrlDown, int mouseButton) { + // Handle autocraft requests ourselves to spawn the right GUI classes + final EntityPlayer player = Minecraft.getMinecraft().thePlayer; + + if (slot instanceof SlotME) { + InventoryAction action = null; + IAEItemStack stack = null; + + switch (mouseButton) { + case 0: // pickup / set-down. + action = ctrlDown == 1 ? InventoryAction.SPLIT_OR_PLACE_SINGLE : InventoryAction.PICKUP_OR_SET_DOWN; + stack = ((SlotME) slot).getAEStack(); + + if (stack != null + && action == InventoryAction.PICKUP_OR_SET_DOWN + && stack.getStackSize() == 0 + && player.inventory.getItemStack() == null) { + action = InventoryAction.AUTO_CRAFT; + } + + break; + case 3: // creative dupe: + stack = ((SlotME) slot).getAEStack(); + if (stack != null && stack.isCraftable()) { + action = InventoryAction.AUTO_CRAFT; + } + break; + default: + } + if (action == InventoryAction.AUTO_CRAFT) { + ((AEBaseContainer) this.inventorySlots).setTargetStack(stack); + final PacketInventoryAction p = + new PacketInventoryAction(action, this.inventorySlots.inventorySlots.size(), 0); + NetworkHandler.instance.sendToServer(p); + } + return; + } + super.handleMouseClick(slot, slotIdx, ctrlDown, mouseButton); + } + private void reinitalize() { this.buttonList.clear(); this.initGui(); @@ -257,8 +300,8 @@ public class GuiWirelessCraftingTerminal extends AEBaseGui implements ISortSourc Keyboard.enableRepeatEvents(true); this.maxRows = this.getMaxRows(); this.perRow = AEConfig.instance.getConfigManager().getSetting(Settings.TERMINAL_STYLE) != TerminalStyle.FULL - ? 9 - : 9 + ((this.width - this.standardSize) / 18); + ? 9 + : 9 + ((this.width - this.standardSize) / 18); this.isNEIEnabled = Loader.isModLoaded("NotEnoughItems"); int top = isNEIEnabled ? 22 : 0; final int magicNumber = 114 + 1; @@ -281,7 +324,7 @@ public class GuiWirelessCraftingTerminal extends AEBaseGui implements ISortSourc for (int y = 0; y < this.rows; y++) { for (int x = 0; x < this.perRow; x++) { this.getMeSlots() - .add(new InternalSlotME(this.repo, x + y * this.perRow, this.offsetX + x * 18, 18 + y * 18)); + .add(new InternalSlotME(this.repo, x + y * this.perRow, this.offsetX + x * 18, 18 + y * 18)); } } if (AEConfig.instance.getConfigManager().getSetting(Settings.TERMINAL_STYLE) != TerminalStyle.FULL) { @@ -298,52 +341,52 @@ public class GuiWirelessCraftingTerminal extends AEBaseGui implements ISortSourc this.buttonList.clear(); this.buttonList.add( - this.clearBtn = new GuiImgButton( - this.guiLeft + 134, this.guiTop + this.ySize - 160, Settings.ACTIONS, ActionItems.STASH)); + this.clearBtn = new GuiImgButton( + this.guiLeft + 134, this.guiTop + this.ySize - 160, Settings.ACTIONS, ActionItems.STASH)); this.buttonList.add(this.trashBtn = new GuiTrashButton(this.guiLeft + 98, this.guiTop + this.ySize - 104)); this.clearBtn.setHalfSize(true); if (this.customSortOrder) { this.buttonList.add( - this.SortByBox = new GuiImgButton( - this.guiLeft - 18, offset, Settings.SORT_BY, this.configSrc.getSetting(Settings.SORT_BY))); + this.SortByBox = new GuiImgButton( + this.guiLeft - 18, offset, Settings.SORT_BY, this.configSrc.getSetting(Settings.SORT_BY))); offset += 20; } this.buttonList.add( - this.ViewBox = new GuiImgButton( - this.guiLeft - 18, offset, Settings.VIEW_MODE, this.configSrc.getSetting(Settings.VIEW_MODE))); + this.ViewBox = new GuiImgButton( + this.guiLeft - 18, offset, Settings.VIEW_MODE, this.configSrc.getSetting(Settings.VIEW_MODE))); offset += 20; this.buttonList.add( - this.SortDirBox = new GuiImgButton( - this.guiLeft - 18, - offset, - Settings.SORT_DIRECTION, - this.configSrc.getSetting(Settings.SORT_DIRECTION))); + this.SortDirBox = new GuiImgButton( + this.guiLeft - 18, + offset, + Settings.SORT_DIRECTION, + this.configSrc.getSetting(Settings.SORT_DIRECTION))); offset += 20; this.buttonList.add( - this.searchBoxSettings = new GuiImgButton( - this.guiLeft - 18, - offset, - Settings.SEARCH_MODE, - AEConfig.instance.settings.getSetting(Settings.SEARCH_MODE))); + this.searchBoxSettings = new GuiImgButton( + this.guiLeft - 18, + offset, + Settings.SEARCH_MODE, + AEConfig.instance.settings.getSetting(Settings.SEARCH_MODE))); offset += 20; this.buttonList.add( - this.searchStringSave = new GuiImgButton( - this.guiLeft - 18, - offset, - Settings.SAVE_SEARCH, - AEConfig.instance.preserveSearchBar ? YesNo.YES : YesNo.NO)); + this.searchStringSave = new GuiImgButton( + this.guiLeft - 18, + offset, + Settings.SAVE_SEARCH, + AEConfig.instance.preserveSearchBar ? YesNo.YES : YesNo.NO)); offset += 20; this.buttonList.add( - this.terminalStyleBox = new GuiImgButton( - this.guiLeft - 18, - offset, - Settings.TERMINAL_STYLE, - AEConfig.instance.settings.getSetting(Settings.TERMINAL_STYLE))); + this.terminalStyleBox = new GuiImgButton( + this.guiLeft - 18, + offset, + Settings.TERMINAL_STYLE, + AEConfig.instance.settings.getSetting(Settings.TERMINAL_STYLE))); this.searchField = new MEGuiTextField(this.fontRendererObj, SEARCH_X, SEARCH_Y, SEARCH_WIDTH, SEARCH_HEIGHT); @@ -354,12 +397,12 @@ public class GuiWirelessCraftingTerminal extends AEBaseGui implements ISortSourc this.searchField.setEnabled(true); this.buttonList.add( - this.craftingStatusBtn = new GuiTabButton( - this.guiLeft + 169, - this.guiTop - 4, - 2 + 11 * 16, - GuiText.CraftingStatus.getLocal(), - itemRender)); + this.craftingStatusBtn = new GuiTabButton( + this.guiLeft + 169, + this.guiTop - 4, + 2 + 11 * 16, + GuiText.CraftingStatus.getLocal(), + itemRender)); this.craftingStatusBtn.setHideEdge(13); final Enum searchMode = AEConfig.instance.settings.getSetting(Settings.SEARCH_MODE); @@ -398,8 +441,8 @@ public class GuiWirelessCraftingTerminal extends AEBaseGui implements ISortSourc int getMaxRows() { return AEConfig.instance.getConfigManager().getSetting(Settings.TERMINAL_STYLE) == TerminalStyle.SMALL - ? 6 - : Integer.MAX_VALUE; + ? 6 + : Integer.MAX_VALUE; } protected void repositionSlot(final AppEngSlot s) { @@ -466,8 +509,8 @@ public class GuiWirelessCraftingTerminal extends AEBaseGui implements ISortSourc */ private boolean hasScreenResChanged() { if ((this.currScreenWidth != this.mc.displayWidth) - || (this.currScreenHeight != this.mc.displayHeight) - || (this.isFullScreen != this.mc.isFullScreen())) { + || (this.currScreenHeight != this.mc.displayHeight) + || (this.isFullScreen != this.mc.isFullScreen())) { this.currScreenWidth = this.mc.displayWidth; this.currScreenHeight = this.mc.displayHeight; this.isFullScreen = this.mc.isFullScreen(); @@ -511,12 +554,12 @@ public class GuiWirelessCraftingTerminal extends AEBaseGui implements ISortSourc // draw player inv this.drawTexturedModalRect( - offsetX, - offsetY + 16 + this.rows * 18 + this.lowerTextureOffset, - 0, - 106 - 18 - 18, - x_width, - 99 + this.reservedSpace - this.lowerTextureOffset); + offsetX, + offsetY + 16 + this.rows * 18 + this.lowerTextureOffset, + 0, + 106 - 18 - 18, + x_width, + 99 + this.reservedSpace - this.lowerTextureOffset); // draw view cells this.drawTexturedModalRect(offsetX + x_width, offsetY, x_width, 0, 32, 104); @@ -525,12 +568,12 @@ public class GuiWirelessCraftingTerminal extends AEBaseGui implements ISortSourc this.drawTexturedModalRect(this.guiLeft + 132, (this.guiTop + this.rows * 18) + 83, 237, 237, 19, 19); } GuiInventory.func_147046_a( - this.guiLeft + 51, - (this.guiTop + this.rows * 18) + 94, - 32, - (float) (this.guiLeft + 51) - this.xSize_lo, - (float) ((this.guiTop + this.rows * 18) + 50) - this.ySize_lo, - this.mc.thePlayer); + this.guiLeft + 51, + (this.guiTop + this.rows * 18) + 94, + 32, + (float) (this.guiLeft + 51) - this.xSize_lo, + (float) ((this.guiTop + this.rows * 18) + 50) - this.ySize_lo, + this.mc.thePlayer); boolean update = false; for (int i = 0; i < 5; i++) { @@ -598,7 +641,7 @@ public class GuiWirelessCraftingTerminal extends AEBaseGui implements ISortSourc } final boolean mouseInGui = - this.isPointInRegion(0, 0, this.xSize, this.ySize, this.currentMouseX, this.currentMouseY); + this.isPointInRegion(0, 0, this.xSize, this.ySize, this.currentMouseX, this.currentMouseY); if (this.isAutoFocus && !this.searchField.isFocused() && mouseInGui) { this.searchField.setFocused(true); } @@ -623,7 +666,7 @@ public class GuiWirelessCraftingTerminal extends AEBaseGui implements ISortSourc } public List handleItemTooltip( - final ItemStack stack, final int mouseX, final int mouseY, final List currentToolTip) { + final ItemStack stack, final int mouseX, final int mouseY, final List currentToolTip) { if (stack != null) { final Slot s = this.getSlot(mouseX, mouseY); if (s instanceof SlotME) { @@ -641,7 +684,7 @@ public class GuiWirelessCraftingTerminal extends AEBaseGui implements ISortSourc if (myStack.getStackSize() > BigNumber || (myStack.getStackSize() > 1 && stack.isItemDamaged())) { final String local = ButtonToolTips.ItemsStored.getLocal(); final String formattedAmount = - NumberFormat.getNumberInstance(Locale.US).format(myStack.getStackSize()); + NumberFormat.getNumberInstance(Locale.US).format(myStack.getStackSize()); final String format = String.format(local, formattedAmount); currentToolTip.add("\u00a77" + format); @@ -650,7 +693,7 @@ public class GuiWirelessCraftingTerminal extends AEBaseGui implements ISortSourc if (myStack.getCountRequestable() > 0) { final String local = ButtonToolTips.ItemsRequestable.getLocal(); final String formattedAmount = - NumberFormat.getNumberInstance(Locale.US).format(myStack.getCountRequestable()); + NumberFormat.getNumberInstance(Locale.US).format(myStack.getCountRequestable()); final String format = String.format(local, formattedAmount); currentToolTip.add("\u00a77" + format); @@ -658,7 +701,7 @@ public class GuiWirelessCraftingTerminal extends AEBaseGui implements ISortSourc } else if (stack.stackSize > BigNumber || (stack.stackSize > 1 && stack.isItemDamaged())) { final String local = ButtonToolTips.ItemsStored.getLocal(); final String formattedAmount = - NumberFormat.getNumberInstance(Locale.US).format(stack.stackSize); + NumberFormat.getNumberInstance(Locale.US).format(stack.stackSize); final String format = String.format(local, formattedAmount); currentToolTip.add("\u00a77" + format); @@ -685,23 +728,23 @@ public class GuiWirelessCraftingTerminal extends AEBaseGui implements ISortSourc if (myStack != null) { final List currentToolTip = - stack.getTooltip(this.mc.thePlayer, this.mc.gameSettings.advancedItemTooltips); + stack.getTooltip(this.mc.thePlayer, this.mc.gameSettings.advancedItemTooltips); if (myStack.getStackSize() > BigNumber || (myStack.getStackSize() > 1 && stack.isItemDamaged())) { currentToolTip.add("Items Stored: " - + NumberFormat.getNumberInstance(Locale.US).format(myStack.getStackSize())); + + NumberFormat.getNumberInstance(Locale.US).format(myStack.getStackSize())); } if (myStack.getCountRequestable() > 0) { currentToolTip.add("Items Requestable: " - + NumberFormat.getNumberInstance(Locale.US).format(myStack.getCountRequestable())); + + NumberFormat.getNumberInstance(Locale.US).format(myStack.getCountRequestable())); } this.drawTooltip(x, y, 0, join(currentToolTip, "\n")); } else if (stack.stackSize > BigNumber) { final List var4 = stack.getTooltip(this.mc.thePlayer, this.mc.gameSettings.advancedItemTooltips); var4.add("Items Stored: " - + NumberFormat.getNumberInstance(Locale.US).format(stack.stackSize)); + + NumberFormat.getNumberInstance(Locale.US).format(stack.stackSize)); this.drawTooltip(x, y, 0, join(var4, "\n")); return; } @@ -772,9 +815,9 @@ public class GuiWirelessCraftingTerminal extends AEBaseGui implements ISortSourc pointX -= i; pointY -= j; return pointX >= rectX - 1 - && pointX < rectX + rectWidth + 1 - && pointY >= rectY - 1 - && pointY < rectY + rectHeight + 1; + && pointX < rectX + rectWidth + 1 + && pointY >= rectY - 1 + && pointY < rectY + rectHeight + 1; } private boolean isNEIFocused() { @@ -783,7 +826,7 @@ public class GuiWirelessCraftingTerminal extends AEBaseGui implements ISortSourc } try { final Class c = - ReflectionHelper.getClass(this.getClass().getClassLoader(), "codechicken.nei.LayoutManager"); + ReflectionHelper.getClass(this.getClass().getClassLoader(), "codechicken.nei.LayoutManager"); final Field fldSearchField = c.getField("searchField"); final TextField searchField = (TextField) fldSearchField.get(c); return searchField.focused(); diff --git a/src/main/java/net/p455w0rd/wirelesscraftingterminal/client/me/ClientDCInternalInv.java b/src/main/java/net/p455w0rd/wirelesscraftingterminal/client/me/ClientDCInternalInv.java deleted file mode 100644 index dfc6634..0000000 --- a/src/main/java/net/p455w0rd/wirelesscraftingterminal/client/me/ClientDCInternalInv.java +++ /dev/null @@ -1,43 +0,0 @@ -package net.p455w0rd.wirelesscraftingterminal.client.me; - -import appeng.tile.inventory.AppEngInternalInventory; -import appeng.util.ItemSorters; -import javax.annotation.Nonnull; -import net.minecraft.util.StatCollector; - -public class ClientDCInternalInv implements Comparable { - - private final String unlocalizedName; - private final AppEngInternalInventory inventory; - - private final long id; - private final long sortBy; - - public ClientDCInternalInv(final int size, final long id, final long sortBy, final String unlocalizedName) { - this.inventory = new AppEngInternalInventory(null, size); - this.unlocalizedName = unlocalizedName; - this.id = id; - this.sortBy = sortBy; - } - - public String getName() { - final String s = StatCollector.translateToLocal(this.unlocalizedName + ".name"); - if (s.equals(this.unlocalizedName + ".name")) { - return StatCollector.translateToLocal(this.unlocalizedName); - } - return s; - } - - @Override - public int compareTo(@Nonnull final ClientDCInternalInv o) { - return ItemSorters.compareLong(this.sortBy, o.sortBy); - } - - public AppEngInternalInventory getInventory() { - return this.inventory; - } - - public long getId() { - return this.id; - } -} diff --git a/src/main/java/net/p455w0rd/wirelesscraftingterminal/client/me/InternalSlotME.java b/src/main/java/net/p455w0rd/wirelesscraftingterminal/client/me/InternalSlotME.java deleted file mode 100644 index ef8e492..0000000 --- a/src/main/java/net/p455w0rd/wirelesscraftingterminal/client/me/InternalSlotME.java +++ /dev/null @@ -1,39 +0,0 @@ -package net.p455w0rd.wirelesscraftingterminal.client.me; - -import appeng.api.storage.data.IAEItemStack; -import net.minecraft.item.ItemStack; - -public class InternalSlotME { - - private final int offset; - private final int xPos; - private final int yPos; - private final ItemRepo repo; - - public InternalSlotME(final ItemRepo def, final int offset, final int displayX, final int displayY) { - this.repo = def; - this.offset = offset; - this.xPos = displayX; - this.yPos = displayY; - } - - ItemStack getStack() { - return this.repo.getItem(this.offset); - } - - IAEItemStack getAEStack() { - return this.repo.getReferenceItem(this.offset); - } - - boolean hasPower() { - return this.repo.hasPower(); - } - - int getxPosition() { - return this.xPos; - } - - int getyPosition() { - return this.yPos; - } -} diff --git a/src/main/java/net/p455w0rd/wirelesscraftingterminal/client/me/ItemRepo.java b/src/main/java/net/p455w0rd/wirelesscraftingterminal/client/me/ItemRepo.java deleted file mode 100644 index 8bf0a1e..0000000 --- a/src/main/java/net/p455w0rd/wirelesscraftingterminal/client/me/ItemRepo.java +++ /dev/null @@ -1,240 +0,0 @@ -package net.p455w0rd.wirelesscraftingterminal.client.me; - -import appeng.api.AEApi; -import appeng.api.config.SearchBoxMode; -import appeng.api.config.Settings; -import appeng.api.config.SortOrder; -import appeng.api.config.ViewItems; -import appeng.api.config.YesNo; -import appeng.api.storage.data.IAEItemStack; -import appeng.api.storage.data.IItemList; -import appeng.client.gui.widgets.IScrollSource; -import appeng.client.gui.widgets.ISortSource; -import appeng.core.AEConfig; -import appeng.items.storage.ItemViewCell; -import appeng.util.ItemSorters; -import appeng.util.Platform; -import appeng.util.prioitylist.IPartitionList; -import cpw.mods.fml.relauncher.ReflectionHelper; -import java.lang.reflect.Field; -import java.lang.reflect.Method; -import java.util.ArrayList; -import java.util.Collections; -import java.util.regex.Pattern; -import javax.annotation.Nonnull; -import net.minecraft.item.ItemStack; - -public class ItemRepo { - - private final IItemList list = AEApi.instance().storage().createItemList(); - private final ArrayList view = new ArrayList(); - private final ArrayList dsp = new ArrayList(); - private final IScrollSource src; - private final ISortSource sortSrc; - - private int rowSize = 9; - - private String searchString = ""; - private IPartitionList myPartitionList; - private String innerSearch = ""; - private String NEIWord = null; - private boolean hasPower; - - public ItemRepo(final IScrollSource src, final ISortSource sortSrc) { - this.src = src; - this.sortSrc = sortSrc; - } - - public IAEItemStack getReferenceItem(int idx) { - idx += this.src.getCurrentScroll() * this.rowSize; - - if (idx >= this.view.size()) { - return null; - } - return this.view.get(idx); - } - - public ItemStack getItem(int idx) { - idx += this.src.getCurrentScroll() * this.rowSize; - - if (idx >= this.dsp.size()) { - return null; - } - return this.dsp.get(idx); - } - - void setSearch(final String search) { - this.searchString = search == null ? "" : search; - } - - public void postUpdate(final IAEItemStack is) { - final IAEItemStack st = this.list.findPrecise(is); - - if (st != null) { - st.reset(); - st.add(is); - } else { - this.list.add(is); - } - } - - public void setViewCell(final ItemStack[] list) { - this.myPartitionList = ItemViewCell.createFilter(list); - this.updateView(); - } - - @SuppressWarnings("rawtypes") - public void updateView() { - this.view.clear(); - this.dsp.clear(); - - this.view.ensureCapacity(this.list.size()); - this.dsp.ensureCapacity(this.list.size()); - - final Enum viewMode = this.sortSrc.getSortDisplay(); - final Enum searchMode = AEConfig.instance.settings.getSetting(Settings.SEARCH_MODE); - if (searchMode == SearchBoxMode.NEI_AUTOSEARCH || searchMode == SearchBoxMode.NEI_MANUAL_SEARCH) { - this.updateNEI(this.searchString); - } - - this.innerSearch = this.searchString; - final boolean terminalSearchToolTips = - AEConfig.instance.settings.getSetting(Settings.SEARCH_TOOLTIPS) != YesNo.NO; - // boolean terminalSearchMods = Configuration.INSTANCE.settings.getSetting( Settings.SEARCH_MODS ) != YesNo.NO; - - boolean searchMod = false; - if (this.innerSearch.startsWith("@")) { - searchMod = true; - this.innerSearch = this.innerSearch.substring(1); - } - - Pattern m = null; - try { - m = Pattern.compile(this.innerSearch.toLowerCase(), Pattern.CASE_INSENSITIVE); - } catch (final Throwable ignore) { - try { - m = Pattern.compile(Pattern.quote(this.innerSearch.toLowerCase()), Pattern.CASE_INSENSITIVE); - } catch (final Throwable __) { - return; - } - } - - boolean notDone = false; - for (IAEItemStack is : this.list) { - if (this.myPartitionList != null) { - if (!this.myPartitionList.isListed(is)) { - continue; - } - } - - if (viewMode == ViewItems.CRAFTABLE && !is.isCraftable()) { - continue; - } - - if (viewMode == ViewItems.CRAFTABLE) { - is = is.copy(); - is.setStackSize(0); - } - - if (viewMode == ViewItems.STORED && is.getStackSize() == 0) { - continue; - } - - final String dspName = searchMod ? Platform.getModId(is) : Platform.getItemDisplayName(is); - notDone = true; - - if (m.matcher(dspName.toLowerCase()).find()) { - this.view.add(is); - notDone = false; - } - - if (terminalSearchToolTips && notDone) { - for (final Object lp : Platform.getTooltip(is)) { - if (lp instanceof String && m.matcher((CharSequence) lp).find()) { - this.view.add(is); - notDone = false; - break; - } - } - } - - /* - * if ( terminalSearchMods && notDone ) { if ( m.matcher( Platform.getMod( is.getItemStack() ) ).find() ) { - * view.add( is ); notDone = false; } } - */ - } - - final Enum SortBy = this.sortSrc.getSortBy(); - final Enum SortDir = this.sortSrc.getSortDir(); - - ItemSorters.setDirection((appeng.api.config.SortDir) SortDir); - ItemSorters.init(); - - if (SortBy == SortOrder.MOD) { - Collections.sort(this.view, ItemSorters.CONFIG_BASED_SORT_BY_MOD); - } else if (SortBy == SortOrder.AMOUNT) { - Collections.sort(this.view, ItemSorters.CONFIG_BASED_SORT_BY_SIZE); - } else if (SortBy == SortOrder.INVTWEAKS) { - Collections.sort(this.view, ItemSorters.CONFIG_BASED_SORT_BY_INV_TWEAKS); - } else { - Collections.sort(this.view, ItemSorters.CONFIG_BASED_SORT_BY_NAME); - } - - for (final IAEItemStack is : this.view) { - this.dsp.add(is.getItemStack()); - } - } - - @SuppressWarnings("rawtypes") - private void updateNEI(final String filter) { - try { - if (this.NEIWord == null || !this.NEIWord.equals(filter)) { - final Class c = - ReflectionHelper.getClass(this.getClass().getClassLoader(), "codechicken.nei.LayoutManager"); - final Field fldSearchField = c.getField("searchField"); - final Object searchField = fldSearchField.get(c); - - final Method a = searchField.getClass().getMethod("setText", String.class); - final Method b = searchField.getClass().getMethod("onTextChange", String.class); - - this.NEIWord = filter; - a.invoke(searchField, filter); - b.invoke(searchField, ""); - } - } catch (final Throwable ignore) { - - } - } - - public int size() { - return this.view.size(); - } - - public void clear() { - this.list.resetStatus(); - } - - public boolean hasPower() { - return this.hasPower; - } - - public void setPower(final boolean hasPower) { - this.hasPower = hasPower; - } - - public int getRowSize() { - return this.rowSize; - } - - public void setRowSize(final int rowSize) { - this.rowSize = rowSize; - } - - public String getSearchString() { - return this.searchString; - } - - public void setSearchString(@Nonnull final String searchString) { - this.searchString = searchString; - } -} diff --git a/src/main/java/net/p455w0rd/wirelesscraftingterminal/client/me/SlotDisconnected.java b/src/main/java/net/p455w0rd/wirelesscraftingterminal/client/me/SlotDisconnected.java deleted file mode 100644 index 46059fc..0000000 --- a/src/main/java/net/p455w0rd/wirelesscraftingterminal/client/me/SlotDisconnected.java +++ /dev/null @@ -1,73 +0,0 @@ -package net.p455w0rd.wirelesscraftingterminal.client.me; - -import appeng.items.misc.ItemEncodedPattern; -import appeng.util.Platform; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.inventory.IInventory; -import net.minecraft.item.ItemStack; -import net.p455w0rd.wirelesscraftingterminal.common.container.slot.AppEngSlot; - -public class SlotDisconnected extends AppEngSlot { - - private final ClientDCInternalInv mySlot; - - public SlotDisconnected(final ClientDCInternalInv me, final int which, final int x, final int y) { - super(me.getInventory(), which, x, y); - this.mySlot = me; - } - - @Override - public boolean isItemValid(final ItemStack par1ItemStack) { - return false; - } - - @Override - public void putStack(final ItemStack par1ItemStack) {} - - @Override - public boolean canTakeStack(final EntityPlayer par1EntityPlayer) { - return false; - } - - @Override - public ItemStack getDisplayStack() { - if (Platform.isClient()) { - final ItemStack is = super.getStack(); - if (is != null && is.getItem() instanceof ItemEncodedPattern) { - final ItemEncodedPattern iep = (ItemEncodedPattern) is.getItem(); - final ItemStack out = iep.getOutput(is); - if (out != null) { - return out; - } - } - } - return super.getStack(); - } - - @Override - public void onPickupFromSlot(final EntityPlayer par1EntityPlayer, final ItemStack par2ItemStack) {} - - @Override - public boolean getHasStack() { - return this.getStack() != null; - } - - @Override - public int getSlotStackLimit() { - return 0; - } - - @Override - public ItemStack decrStackSize(final int par1) { - return null; - } - - @Override - public boolean isSlotInInventory(final IInventory par1iInventory, final int par2) { - return false; - } - - public ClientDCInternalInv getSlot() { - return this.mySlot; - } -} diff --git a/src/main/java/net/p455w0rd/wirelesscraftingterminal/client/me/SlotME.java b/src/main/java/net/p455w0rd/wirelesscraftingterminal/client/me/SlotME.java deleted file mode 100644 index d12e1ca..0000000 --- a/src/main/java/net/p455w0rd/wirelesscraftingterminal/client/me/SlotME.java +++ /dev/null @@ -1,71 +0,0 @@ -package net.p455w0rd.wirelesscraftingterminal.client.me; - -import appeng.api.storage.data.IAEItemStack; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.inventory.IInventory; -import net.minecraft.inventory.Slot; -import net.minecraft.item.ItemStack; - -public class SlotME extends Slot { - - private final InternalSlotME mySlot; - - public SlotME(final InternalSlotME me) { - super(null, 0, me.getxPosition(), me.getyPosition()); - this.mySlot = me; - } - - public IAEItemStack getAEStack() { - if (this.mySlot.hasPower()) { - return this.mySlot.getAEStack(); - } - return null; - } - - @Override - public void onPickupFromSlot(final EntityPlayer par1EntityPlayer, final ItemStack par2ItemStack) {} - - @Override - public boolean isItemValid(final ItemStack par1ItemStack) { - return false; - } - - @Override - public ItemStack getStack() { - if (this.mySlot.hasPower()) { - return this.mySlot.getStack(); - } - return null; - } - - @Override - public boolean getHasStack() { - if (this.mySlot.hasPower()) { - return this.getStack() != null; - } - return false; - } - - @Override - public void putStack(final ItemStack par1ItemStack) {} - - @Override - public int getSlotStackLimit() { - return 0; - } - - @Override - public ItemStack decrStackSize(final int par1) { - return null; - } - - @Override - public boolean isSlotInInventory(final IInventory par1iInventory, final int par2) { - return false; - } - - @Override - public boolean canTakeStack(final EntityPlayer par1EntityPlayer) { - return false; - } -} diff --git a/src/main/java/net/p455w0rd/wirelesscraftingterminal/client/me/WCTRenderItem.java b/src/main/java/net/p455w0rd/wirelesscraftingterminal/client/me/WCTRenderItem.java deleted file mode 100644 index b7dd950..0000000 --- a/src/main/java/net/p455w0rd/wirelesscraftingterminal/client/me/WCTRenderItem.java +++ /dev/null @@ -1,147 +0,0 @@ -package net.p455w0rd.wirelesscraftingterminal.client.me; - -import appeng.api.storage.data.IAEItemStack; -import appeng.core.AEConfig; -import appeng.core.localization.GuiText; -import appeng.util.ISlimReadableNumberConverter; -import appeng.util.IWideReadableNumberConverter; -import appeng.util.ReadableNumberConverter; -import javax.annotation.Nonnull; -import net.minecraft.client.gui.FontRenderer; -import net.minecraft.client.renderer.Tessellator; -import net.minecraft.client.renderer.entity.RenderItem; -import net.minecraft.client.renderer.texture.TextureManager; -import net.minecraft.item.ItemStack; -import org.lwjgl.opengl.GL11; - -/** - * @author AlgorithmX2 - * @author thatsIch - * @version rv2 - * @since rv0 - */ -public class WCTRenderItem extends RenderItem { - private static final ISlimReadableNumberConverter SLIM_CONVERTER = ReadableNumberConverter.INSTANCE; - private static final IWideReadableNumberConverter WIDE_CONVERTER = ReadableNumberConverter.INSTANCE; - boolean useLg = AEConfig.instance.useTerminalUseLargeFont(); - private IAEItemStack aeStack = null; - - @Override - public void renderItemOverlayIntoGUI( - final FontRenderer fontRenderer, - final TextureManager textureManager, - final ItemStack is, - final int par4, - final int par5, - final String par6Str) { - if (is != null) { - final float scaleFactor = useLg ? 0.85f : 0.5f; - final float inverseScaleFactor = 1.0f / scaleFactor; - final int offset = useLg ? 0 : -1; - - final boolean unicodeFlag = fontRenderer.getUnicodeFlag(); - fontRenderer.setUnicodeFlag(false); - - if (is.getItem().showDurabilityBar(is)) { - final double health = is.getItem().getDurabilityForDisplay(is); - final int j1 = (int) Math.round(13.0D - health * 13.0D); - final int k = (int) Math.round(255.0D - health * 255.0D); - - GL11.glDisable(GL11.GL_LIGHTING); - GL11.glDisable(GL11.GL_DEPTH_TEST); - GL11.glDisable(GL11.GL_TEXTURE_2D); - GL11.glDisable(GL11.GL_ALPHA_TEST); - GL11.glDisable(GL11.GL_BLEND); - - final Tessellator tessellator = Tessellator.instance; - final int l = 255 - k << 16 | k << 8; - final int i1 = (255 - k) / 4 << 16 | 16128; - - this.renderQuad(tessellator, par4 + 2, par5 + 13, 13, 2, 0); - this.renderQuad(tessellator, par4 + 2, par5 + 13, 12, 1, i1); - this.renderQuad(tessellator, par4 + 2, par5 + 13, j1, 1, l); - - GL11.glEnable(GL11.GL_ALPHA_TEST); - GL11.glEnable(GL11.GL_TEXTURE_2D); - GL11.glEnable(GL11.GL_LIGHTING); - GL11.glEnable(GL11.GL_DEPTH_TEST); - GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); - } - - if (is.stackSize == 0) { - final String craftLabelText = - useLg ? GuiText.LargeFontCraft.getLocal() : GuiText.SmallFontCraft.getLocal(); - - GL11.glDisable(GL11.GL_LIGHTING); - GL11.glDisable(GL11.GL_DEPTH_TEST); - GL11.glPushMatrix(); - GL11.glScaled(scaleFactor, scaleFactor, scaleFactor); - - final int X = (int) - (((float) par4 + offset + 16.0f - fontRenderer.getStringWidth(craftLabelText) * scaleFactor) - * inverseScaleFactor); - final int Y = (int) (((float) par5 + offset + 16.0f - 7.0f * scaleFactor) * inverseScaleFactor); - fontRenderer.drawStringWithShadow(craftLabelText, X, Y, 16777215); - - GL11.glPopMatrix(); - GL11.glEnable(GL11.GL_LIGHTING); - GL11.glEnable(GL11.GL_DEPTH_TEST); - } - - final long amount = this.aeStack != null ? this.aeStack.getStackSize() : is.stackSize; - - if (amount != 0) { - final String stackSize = this.getToBeRenderedStackSize(amount); - - GL11.glDisable(GL11.GL_LIGHTING); - GL11.glDisable(GL11.GL_DEPTH_TEST); - GL11.glPushMatrix(); - GL11.glScaled(scaleFactor, scaleFactor, scaleFactor); - - final int X = - (int) (((float) par4 + offset + 16.0f - fontRenderer.getStringWidth(stackSize) * scaleFactor) - * inverseScaleFactor); - final int Y = (int) (((float) par5 + offset + 16.0f - 7.0f * scaleFactor) * inverseScaleFactor); - fontRenderer.drawStringWithShadow(stackSize, X, Y, 16777215); - - GL11.glPopMatrix(); - GL11.glEnable(GL11.GL_LIGHTING); - GL11.glEnable(GL11.GL_DEPTH_TEST); - } - - fontRenderer.setUnicodeFlag(unicodeFlag); - } - } - - private void renderQuad( - final Tessellator par1Tessellator, - final int par2, - final int par3, - final int par4, - final int par5, - final int par6) { - par1Tessellator.startDrawingQuads(); - par1Tessellator.setColorOpaque_I(par6); - par1Tessellator.addVertex(par2, par3, 0.0D); - par1Tessellator.addVertex(par2, par3 + par5, 0.0D); - par1Tessellator.addVertex(par2 + par4, par3 + par5, 0.0D); - par1Tessellator.addVertex(par2 + par4, par3, 0.0D); - par1Tessellator.draw(); - } - - private String getToBeRenderedStackSize(final long originalSize) { - if (AEConfig.instance.useTerminalUseLargeFont()) { - return SLIM_CONVERTER.toSlimReadableForm(originalSize); - } else { - return WIDE_CONVERTER.toWideReadableForm(originalSize); - } - } - - public IAEItemStack getAeStack() { - return this.aeStack; - } - - public void setAeStack(@Nonnull final IAEItemStack aeStack) { - this.aeStack = aeStack; - } -} diff --git a/src/main/java/net/p455w0rd/wirelesscraftingterminal/client/textures/IStateIconTexture.java b/src/main/java/net/p455w0rd/wirelesscraftingterminal/client/textures/IStateIconTexture.java deleted file mode 100644 index 6d24ee8..0000000 --- a/src/main/java/net/p455w0rd/wirelesscraftingterminal/client/textures/IStateIconTexture.java +++ /dev/null @@ -1,48 +0,0 @@ -package net.p455w0rd.wirelesscraftingterminal.client.textures; - -import javax.annotation.Nonnull; -import net.minecraft.util.ResourceLocation; - -/** - * Icon from a state texture. - * - * @author Nividica - * - */ -public interface IStateIconTexture { - /** - * Height of the icon. - * - * @return - */ - int getHeight(); - - /** - * Texture the icon is in. - * - * @return - */ - @Nonnull - ResourceLocation getTexture(); - - /** - * U coordinate of the icon. - * - * @return - */ - int getU(); - - /** - * V coordinate of the icon. - * - * @return - */ - int getV(); - - /** - * Width of the icon. - * - * @return - */ - int getWidth(); -} diff --git a/src/main/java/net/p455w0rd/wirelesscraftingterminal/client/textures/WCTStateIconsEnum.java b/src/main/java/net/p455w0rd/wirelesscraftingterminal/client/textures/WCTStateIconsEnum.java deleted file mode 100644 index 2272b03..0000000 --- a/src/main/java/net/p455w0rd/wirelesscraftingterminal/client/textures/WCTStateIconsEnum.java +++ /dev/null @@ -1,150 +0,0 @@ -package net.p455w0rd.wirelesscraftingterminal.client.textures; - -import net.minecraft.util.ResourceLocation; - -/** - * Icons stored in the AE2's "states" texture. - * - * @author Nividica - * - */ -public enum WCTStateIconsEnum implements IStateIconTexture { - - // Redstone modes - REDSTONE_LOW(0, 0), - REDSTONE_HIGH(16, 0), - REDSTONE_PULSE(32, 0), - REDSTONE_IGNORE(48, 0), - - // Slot backgrounds - VIEW_CELL_BACKGROUND(224, 64), - UPGRADE_CARD_BACKGROUND(240, 208), - ME_CELL_BACKGROUND(240, 0), - PATTERN_CELL_BACKGROUND(240, 128), - - // Buttons - REGULAR_BUTTON(240, 240), - TAB_BUTTON(208, 0, 22, 22), - - // Sorting modes - SORT_MODE_ALPHABETIC(0, 64), - SORT_MODE_AMOUNT(16, 64), - SORT_MODE_MOD(80, 64), - SORT_MODE_INVTWEAK(64, 64), - - // Sorting directions - SORT_DIR_ASC(0, 48), - SORT_DIR_DEC(16, 48), - - // View types - VIEW_TYPE_STORED(0, 16), - VIEW_TYPE_ALL(32, 16), - VIEW_TYPE_CRAFT(48, 16), - - // Terminal styles - TERM_STYLE_TALL(0, 208), - TERM_STYLE_SMALL(16, 208), - - // Search modes - SEARCH_MODE_AUTO(48, 32), - SEARCH_MODE_MANUAL(64, 32), - SEARCH_MODE_NEI_AUTO(80, 32), - SEARCH_MODE_NEI_MANUAL(96, 32), - - // Misc - WRENCH(32, 64), - DISABLED(0, 128), - ENABLED(16, 128), - SAVE(0, 176), - DELETE(0, 192), - CLEAR_GRID(96, 0), - ARROW_DOWN(128, 0); - - /** - * Location of the AE states texture - */ - public static final ResourceLocation AE_STATES_TEXTURE = - new ResourceLocation("appliedenergistics2", "textures/guis/states.png"); - - /** - * Width and height of standard icons. - */ - public static final int STANDARD_ICON_SIZE = 16; - - /** - * X position in the texture this icon is located at. - */ - private int minU; - - /** - * Y position in the texture this icon is located at. - */ - private int minV; - - /** - * Width of the icon - */ - private int width; - - /** - * Height of the icon - */ - private int height; - - /** - * Standard icon constructor - * - * @param u - * @param v - */ - private WCTStateIconsEnum(final int u, final int v) { - this(u, v, STANDARD_ICON_SIZE, STANDARD_ICON_SIZE); - } - - /** - * Icon constructor - * - * @param u - * @param v - * @param width - * @param height - */ - private WCTStateIconsEnum(final int u, final int v, final int width, final int height) { - // Set the u - this.minU = u; - - // Set the v - this.minV = v; - - // Set width - this.width = width; - - // Set height - this.height = height; - } - - @Override - public int getHeight() { - return this.height; - } - - @Override - public ResourceLocation getTexture() { - return WCTStateIconsEnum.AE_STATES_TEXTURE; - } - - @Override - public int getU() { - return this.minU; - } - - @Override - public int getV() { - return this.minV; - } - - @Override - public int getWidth() { - return this.width; - } -} diff --git a/src/main/java/net/p455w0rd/wirelesscraftingterminal/common/WCTGuiHandler.java b/src/main/java/net/p455w0rd/wirelesscraftingterminal/common/WCTGuiHandler.java index 822e2ca..7550361 100644 --- a/src/main/java/net/p455w0rd/wirelesscraftingterminal/common/WCTGuiHandler.java +++ b/src/main/java/net/p455w0rd/wirelesscraftingterminal/common/WCTGuiHandler.java @@ -63,24 +63,12 @@ public class WCTGuiHandler implements IGuiHandler { if (guiId == Reference.GUI_CRAFT_AMOUNT) { return updateGui( - new ContainerCraftAmount(player, terminal), - world, - x, - y, - z, - ForgeDirection.UNKNOWN, - obj); + new ContainerCraftAmount(player, terminal), world, x, y, z, ForgeDirection.UNKNOWN, obj); } if (guiId == Reference.GUI_CRAFT_CONFIRM) { return updateGui( - new ContainerCraftConfirm(player, terminal), - world, - x, - y, - z, - ForgeDirection.UNKNOWN, - obj); + new ContainerCraftConfirm(player, terminal), world, x, y, z, ForgeDirection.UNKNOWN, obj); } } } diff --git a/src/main/java/net/p455w0rd/wirelesscraftingterminal/common/container/ContainerCraftAmount.java b/src/main/java/net/p455w0rd/wirelesscraftingterminal/common/container/ContainerCraftAmount.java index de4ca3f..4d41719 100644 --- a/src/main/java/net/p455w0rd/wirelesscraftingterminal/common/container/ContainerCraftAmount.java +++ b/src/main/java/net/p455w0rd/wirelesscraftingterminal/common/container/ContainerCraftAmount.java @@ -2,11 +2,8 @@ package net.p455w0rd.wirelesscraftingterminal.common.container; import appeng.api.implementations.guiobjects.IPortableCell; import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.tileentity.TileEntity; import net.p455w0rd.wirelesscraftingterminal.common.WCTGuiHandler; -import net.p455w0rd.wirelesscraftingterminal.core.sync.network.NetworkHandler; -import net.p455w0rd.wirelesscraftingterminal.core.sync.packets.PacketSwitchGuis; import net.p455w0rd.wirelesscraftingterminal.reference.Reference; public class ContainerCraftAmount extends appeng.container.implementations.ContainerCraftAmount { diff --git a/src/main/java/net/p455w0rd/wirelesscraftingterminal/common/container/ContainerCraftConfirm.java b/src/main/java/net/p455w0rd/wirelesscraftingterminal/common/container/ContainerCraftConfirm.java index 63b0242..59522c3 100644 --- a/src/main/java/net/p455w0rd/wirelesscraftingterminal/common/container/ContainerCraftConfirm.java +++ b/src/main/java/net/p455w0rd/wirelesscraftingterminal/common/container/ContainerCraftConfirm.java @@ -2,10 +2,7 @@ package net.p455w0rd.wirelesscraftingterminal.common.container; import appeng.api.implementations.guiobjects.IPortableCell; import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.entity.player.EntityPlayerMP; import net.p455w0rd.wirelesscraftingterminal.common.WCTGuiHandler; -import net.p455w0rd.wirelesscraftingterminal.core.sync.network.NetworkHandler; -import net.p455w0rd.wirelesscraftingterminal.core.sync.packets.PacketSwitchGuis; import net.p455w0rd.wirelesscraftingterminal.reference.Reference; public class ContainerCraftConfirm extends appeng.container.implementations.ContainerCraftConfirm { diff --git a/src/main/java/net/p455w0rd/wirelesscraftingterminal/common/container/ContainerWirelessCraftingTerminal.java b/src/main/java/net/p455w0rd/wirelesscraftingterminal/common/container/ContainerWirelessCraftingTerminal.java index 0fb14f5..f6d8e20 100644 --- a/src/main/java/net/p455w0rd/wirelesscraftingterminal/common/container/ContainerWirelessCraftingTerminal.java +++ b/src/main/java/net/p455w0rd/wirelesscraftingterminal/common/container/ContainerWirelessCraftingTerminal.java @@ -27,7 +27,16 @@ import appeng.client.me.InternalSlotME; import appeng.client.me.SlotME; import appeng.container.AEBaseContainer; import appeng.container.ContainerNull; +import appeng.container.slot.AppEngCraftingSlot; import appeng.container.slot.AppEngSlot; +import appeng.container.slot.NullSlot; +import appeng.container.slot.SlotCraftingMatrix; +import appeng.container.slot.SlotCraftingTerm; +import appeng.container.slot.SlotDisabled; +import appeng.container.slot.SlotFake; +import appeng.container.slot.SlotInaccessible; +import appeng.container.slot.SlotPlayerHotBar; +import appeng.container.slot.SlotPlayerInv; import appeng.core.AEConfig; import appeng.core.localization.PlayerMessages; import appeng.helpers.IContainerCraftingPacket; @@ -40,6 +49,12 @@ import appeng.util.IConfigManagerHost; import appeng.util.InventoryAdaptor; import appeng.util.Platform; import appeng.util.inv.AdaptorPlayerHand; +import java.io.IOException; +import java.nio.BufferOverflowException; +import java.util.ArrayList; +import java.util.LinkedList; +import java.util.List; +import javax.annotation.Nonnull; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.entity.player.InventoryPlayer; @@ -59,18 +74,9 @@ import net.minecraft.world.World; import net.minecraftforge.common.util.ForgeDirection; import net.p455w0rd.wirelesscraftingterminal.api.IWirelessCraftingTermHandler; import net.p455w0rd.wirelesscraftingterminal.api.IWirelessCraftingTerminalItem; -import net.p455w0rd.wirelesscraftingterminal.common.container.slot.AppEngCraftingSlot; -import net.p455w0rd.wirelesscraftingterminal.common.container.slot.NullSlot; import net.p455w0rd.wirelesscraftingterminal.common.container.slot.SlotArmor; import net.p455w0rd.wirelesscraftingterminal.common.container.slot.SlotBooster; -import net.p455w0rd.wirelesscraftingterminal.common.container.slot.SlotCraftingMatrix; -import net.p455w0rd.wirelesscraftingterminal.common.container.slot.SlotCraftingTerm; -import net.p455w0rd.wirelesscraftingterminal.common.container.slot.SlotDisabled; -import net.p455w0rd.wirelesscraftingterminal.common.container.slot.SlotFake; -import net.p455w0rd.wirelesscraftingterminal.common.container.slot.SlotInaccessible; import net.p455w0rd.wirelesscraftingterminal.common.container.slot.SlotMagnet; -import net.p455w0rd.wirelesscraftingterminal.common.container.slot.SlotPlayerHotBar; -import net.p455w0rd.wirelesscraftingterminal.common.container.slot.SlotPlayerInv; import net.p455w0rd.wirelesscraftingterminal.common.container.slot.SlotTrash; import net.p455w0rd.wirelesscraftingterminal.common.container.slot.SlotViewCell; import net.p455w0rd.wirelesscraftingterminal.common.inventory.WCTInventoryBooster; @@ -89,20 +95,13 @@ import net.p455w0rd.wirelesscraftingterminal.items.ItemInfinityBooster; import net.p455w0rd.wirelesscraftingterminal.items.ItemMagnet; import net.p455w0rd.wirelesscraftingterminal.reference.Reference; -import javax.annotation.Nonnull; -import java.io.IOException; -import java.nio.BufferOverflowException; -import java.util.ArrayList; -import java.util.LinkedList; -import java.util.List; - public class ContainerWirelessCraftingTerminal extends AEBaseContainer - implements IConfigManagerHost, - IConfigurableObject, - IMEMonitorHandlerReceiver, - IAEAppEngInventory, - IContainerCraftingPacket, - IViewCellStorage { + implements IConfigManagerHost, + IConfigurableObject, + IMEMonitorHandlerReceiver, + IAEAppEngInventory, + IContainerCraftingPacket, + IViewCellStorage { private final ItemStack containerstack; public final WCTInventoryCrafting craftingGrid; @@ -115,18 +114,18 @@ public class ContainerWirelessCraftingTerminal extends AEBaseContainer private final World worldObj; private final EntityPlayer player; private static final int HOTBAR_START = 1, - HOTBAR_END = HOTBAR_START + 8, - INV_START = HOTBAR_END + 1, - INV_END = INV_START + 26, - ARMOR_START = INV_END + 1, - ARMOR_END = ARMOR_START + 3, - CRAFT_GRID_START = ARMOR_END + 1, - CRAFT_GRID_END = CRAFT_GRID_START + 8, - CRAFT_RESULT = CRAFT_GRID_END + 1, - VIEW_CELL_START = CRAFT_RESULT + 1, - VIEW_CELL_END = VIEW_CELL_START + 4, - BOOSTER_INDEX = 0, - MAGNET_INDEX = VIEW_CELL_END + 1; + HOTBAR_END = HOTBAR_START + 8, + INV_START = HOTBAR_END + 1, + INV_END = INV_START + 26, + ARMOR_START = INV_END + 1, + ARMOR_END = ARMOR_START + 3, + CRAFT_GRID_START = ARMOR_END + 1, + CRAFT_GRID_END = CRAFT_GRID_START + 8, + CRAFT_RESULT = CRAFT_GRID_END + 1, + VIEW_CELL_START = CRAFT_RESULT + 1, + VIEW_CELL_END = VIEW_CELL_START + 4, + BOOSTER_INDEX = 0, + MAGNET_INDEX = VIEW_CELL_END + 1; public static int CRAFTING_SLOT_X_POS = 80, CRAFTING_SLOT_Y_POS = 83; private SlotBooster boosterSlot; private final SlotMagnet magnetSlot; @@ -161,7 +160,15 @@ public class ContainerWirelessCraftingTerminal extends AEBaseContainer * @author p455w0rd */ public ContainerWirelessCraftingTerminal(EntityPlayer player, InventoryPlayer inventoryPlayer) { - super(inventoryPlayer, getGuiObject(RandomUtils.getWirelessTerm(inventoryPlayer), player, player.worldObj, (int) player.posX, (int) player.posY, (int) player.posZ)); + super( + inventoryPlayer, + getGuiObject( + RandomUtils.getWirelessTerm(inventoryPlayer), + player, + player.worldObj, + (int) player.posX, + (int) player.posY, + (int) player.posZ)); this.clientCM = new ConfigManager(this); this.clientCM.registerSetting(Settings.SORT_BY, SortOrder.NAME); this.clientCM.registerSetting(Settings.VIEW_MODE, ViewItems.ALL); @@ -186,7 +193,7 @@ public class ContainerWirelessCraftingTerminal extends AEBaseContainer viewCellSlot = new SlotViewCell[5]; this.obj = - getGuiObject(containerstack, player, worldObj, (int) player.posX, (int) player.posY, (int) player.posZ); + getGuiObject(containerstack, player, worldObj, (int) player.posX, (int) player.posY, (int) player.posZ); this.civ = this.obj; final IGridNode node = ((IGridHost) this.obj).getGridNode(ForgeDirection.UNKNOWN); this.networkNode = node; @@ -242,7 +249,7 @@ public class ContainerWirelessCraftingTerminal extends AEBaseContainer for (int i = 0; i < 3; ++i) { for (int j = 0; j < 3; ++j) { craftMatrixSlot[k] = - new SlotCraftingMatrix(this, this.craftingGrid, j + i * 3, 80 + j * 18, (i * 18) - 76); + new SlotCraftingMatrix(this, this.craftingGrid, j + i * 3, 80 + j * 18, (i * 18) - 76); this.addSlotToContainer(craftMatrixSlot[k]); if (k == 0) { this.firstCraftingSlotNumber = craftMatrixSlot[k].slotNumber; @@ -253,22 +260,22 @@ public class ContainerWirelessCraftingTerminal extends AEBaseContainer this.lastCraftingSlotNumber = craftMatrixSlot[8].slotNumber; craftingSlot = new SlotCraftingTerm( - this.getPlayerInv().player, - this.getActionSource(), - this.getPowerSource(), - this.obj, - this.craftingGrid, - this.craftingGrid, - this.output, - 174, - -58, - this); + this.getPlayerInv().player, + this.getActionSource(), + this.getPowerSource(), + this.obj, + this.craftingGrid, + this.craftingGrid, + this.output, + 174, + -58, + this); // Add crafting result slot this.addSlotToContainer(craftingSlot); // Add view cell slots for (int i = 0; i < 5; i++) { - viewCellSlot[i] = new SlotViewCell(getViewCellStorage(), i, 207, (i * 18) + 8); + viewCellSlot[i] = new SlotViewCell(getViewCellStorage(), i, 207, (i * 18) + 8, inventoryPlayer); addSlotToContainer(viewCellSlot[i]); } @@ -293,7 +300,7 @@ public class ContainerWirelessCraftingTerminal extends AEBaseContainer return super.addSlotToContainer(newSlot); } else { throw new IllegalArgumentException( - "Invalid Slot [" + newSlot + "] for WCT Container instead of AppEngSlot."); + "Invalid Slot [" + newSlot + "] for WCT Container instead of AppEngSlot."); } } @@ -436,7 +443,7 @@ public class ContainerWirelessCraftingTerminal extends AEBaseContainer } ais = Platform.poweredExtraction( - this.getPowerSource(), this.getCellInventory(), ais, this.getActionSource()); + this.getPowerSource(), this.getCellInventory(), ais, this.getActionSource()); if (ais != null) { adp.addItems(ais.getItemStack()); } @@ -456,14 +463,14 @@ public class ContainerWirelessCraftingTerminal extends AEBaseContainer final IAEItemStack extracted = ais.copy(); ais = Platform.poweredInsert( - this.getPowerSource(), this.getCellInventory(), ais, this.getActionSource()); + this.getPowerSource(), this.getCellInventory(), ais, this.getActionSource()); if (ais == null) { final InventoryAdaptor ia = new AdaptorPlayerHand(player); final ItemStack fail = ia.removeItems(1, extracted.getItemStack(), null); if (fail == null) { this.getCellInventory() - .extractItems(extracted, Actionable.MODULATE, this.getActionSource()); + .extractItems(extracted, Actionable.MODULATE, this.getActionSource()); } this.updateHeld(player); @@ -494,7 +501,7 @@ public class ContainerWirelessCraftingTerminal extends AEBaseContainer IAEItemStack ais = slotItem.copy(); ais.setStackSize(1); ais = Platform.poweredExtraction( - this.getPowerSource(), this.getCellInventory(), ais, this.getActionSource()); + this.getPowerSource(), this.getCellInventory(), ais, this.getActionSource()); if (ais != null) { final InventoryAdaptor ia = new AdaptorPlayerHand(player); @@ -518,7 +525,7 @@ public class ContainerWirelessCraftingTerminal extends AEBaseContainer IAEItemStack ais = slotItem.copy(); ais.setStackSize(ais.getItemStack().getMaxStackSize()); ais = Platform.poweredExtraction( - this.getPowerSource(), this.getCellInventory(), ais, this.getActionSource()); + this.getPowerSource(), this.getCellInventory(), ais, this.getActionSource()); if (ais != null) { player.inventory.setItemStack(ais.getItemStack()); } else { @@ -529,7 +536,7 @@ public class ContainerWirelessCraftingTerminal extends AEBaseContainer } else { IAEItemStack ais = AEApi.instance().storage().createItemStack(player.inventory.getItemStack()); ais = Platform.poweredInsert( - this.getPowerSource(), this.getCellInventory(), ais, this.getActionSource()); + this.getPowerSource(), this.getCellInventory(), ais, this.getActionSource()); if (ais != null) { player.inventory.setItemStack(ais.getItemStack()); } else { @@ -555,7 +562,7 @@ public class ContainerWirelessCraftingTerminal extends AEBaseContainer final long stackSize = Math.min(maxSize, ais.getStackSize()); ais.setStackSize((stackSize + 1) >> 1); ais = Platform.poweredExtraction( - this.getPowerSource(), this.getCellInventory(), ais, this.getActionSource()); + this.getPowerSource(), this.getCellInventory(), ais, this.getActionSource()); } if (ais != null) { @@ -569,7 +576,7 @@ public class ContainerWirelessCraftingTerminal extends AEBaseContainer IAEItemStack ais = AEApi.instance().storage().createItemStack(player.inventory.getItemStack()); ais.setStackSize(1); ais = Platform.poweredInsert( - this.getPowerSource(), this.getCellInventory(), ais, this.getActionSource()); + this.getPowerSource(), this.getCellInventory(), ais, this.getActionSource()); if (ais == null) { final ItemStack is = player.inventory.getItemStack(); is.stackSize--; @@ -611,7 +618,7 @@ public class ContainerWirelessCraftingTerminal extends AEBaseContainer } ais = Platform.poweredExtraction( - this.getPowerSource(), this.getCellInventory(), ais, this.getActionSource()); + this.getPowerSource(), this.getCellInventory(), ais, this.getActionSource()); if (ais != null) { adp.addItems(ais.getItemStack()); } else { @@ -644,11 +651,11 @@ public class ContainerWirelessCraftingTerminal extends AEBaseContainer @Override public void onChangeInventory( - final IInventory inv, - final int slot, - final InvOperation mc, - final ItemStack removedStack, - final ItemStack newStack) { + final IInventory inv, + final int slot, + final InvOperation mc, + final ItemStack removedStack, + final ItemStack newStack) { // <3 } @@ -694,10 +701,10 @@ public class ContainerWirelessCraftingTerminal extends AEBaseContainer } public static WirelessTerminalGuiObject getGuiObject( - final ItemStack it, final EntityPlayer player, final World w, final int x, final int y, final int z) { + final ItemStack it, final EntityPlayer player, final World w, final int x, final int y, final int z) { if (it != null) { final IWirelessCraftingTermHandler wh = (IWirelessCraftingTermHandler) - AEApi.instance().registries().wireless().getWirelessTerminalHandler(it); + AEApi.instance().registries().wireless().getWirelessTerminalHandler(it); if (wh != null) { return new WirelessTerminalGuiObject(wh, it, player, w, x, y, z); } @@ -713,7 +720,7 @@ public class ContainerWirelessCraftingTerminal extends AEBaseContainer if (this.ticks > 10) { if (!isBoosterInstalled() || !Reference.WCT_BOOSTER_ENABLED) { this.civ.extractAEPower( - this.getPowerMultiplier() * this.ticks, Actionable.MODULATE, PowerMultiplier.CONFIG); + this.getPowerMultiplier() * this.ticks, Actionable.MODULATE, PowerMultiplier.CONFIG); } else { this.civ.extractAEPower((int) (0.5 * this.ticks), Actionable.MODULATE, PowerMultiplier.CONFIG); } @@ -734,7 +741,7 @@ public class ContainerWirelessCraftingTerminal extends AEBaseContainer for (final Object crafter : this.crafters) { try { NetworkHandler.instance.sendTo( - new PacketValueConfig(set.name(), sideLocal.name()), (EntityPlayerMP) crafter); + new PacketValueConfig(set.name(), sideLocal.name()), (EntityPlayerMP) crafter); } catch (final IOException e) { WCTLog.debug(e.getMessage()); } @@ -782,14 +789,14 @@ public class ContainerWirelessCraftingTerminal extends AEBaseContainer if (!networkIsPowered()) { if (this.isValidContainer()) { this.getPlayerInv() - .player - .addChatMessage(new ChatComponentText(LocaleHandler.NoNetworkPower.getLocal())); + .player + .addChatMessage(new ChatComponentText(LocaleHandler.NoNetworkPower.getLocal())); } this.setValidContainer(false); } } else if (!hasAccess(SecurityPermissions.CRAFT, true) - || !hasAccess(SecurityPermissions.EXTRACT, true) - || !hasAccess(SecurityPermissions.INJECT, true)) { + || !hasAccess(SecurityPermissions.EXTRACT, true) + || !hasAccess(SecurityPermissions.INJECT, true)) { if (this.isValidContainer()) { this.getPlayerInv().player.addChatMessage(PlayerMessages.CommunicationError.get()); } @@ -807,11 +814,11 @@ public class ContainerWirelessCraftingTerminal extends AEBaseContainer return false; } boolean hasStack = - getSlotFromInventory(this.boosterInventory, BOOSTER_INDEX).getHasStack(); + getSlotFromInventory(this.boosterInventory, BOOSTER_INDEX).getHasStack(); if (hasStack) { Item boosterSlotContents = getSlotFromInventory(this.boosterInventory, BOOSTER_INDEX) - .getStack() - .getItem(); + .getStack() + .getItem(); return boosterSlotContents instanceof ItemInfinityBooster; } return false; @@ -823,11 +830,11 @@ public class ContainerWirelessCraftingTerminal extends AEBaseContainer return false; } boolean hasStack = - getSlotFromInventory(this.magnetInventory, MAGNET_INDEX).getHasStack(); + getSlotFromInventory(this.magnetInventory, MAGNET_INDEX).getHasStack(); if (hasStack) { Item magnetSlotContents = getSlotFromInventory(this.magnetInventory, MAGNET_INDEX) - .getStack() - .getItem(); + .getStack() + .getItem(); return magnetSlotContents instanceof ItemMagnet; } return false; @@ -885,9 +892,9 @@ public class ContainerWirelessCraftingTerminal extends AEBaseContainer @Override public void postChange( - final IBaseMonitor monitor, - final Iterable change, - final BaseActionSource source) { + final IBaseMonitor monitor, + final Iterable change, + final BaseActionSource source) { for (final IAEItemStack is : change) { this.items.add(is); } @@ -1251,7 +1258,7 @@ public class ContainerWirelessCraftingTerminal extends AEBaseContainer @SuppressWarnings("unused") private boolean isCraftMatrixSlot(AppEngSlot cs) { return (cs.getSlotIndex() >= this.firstCraftingSlotNumber) - && !(cs.getSlotIndex() <= this.lastCraftingSlotNumber); + && !(cs.getSlotIndex() <= this.lastCraftingSlotNumber); } private void updateSlot(final Slot clickSlot) { @@ -1263,10 +1270,10 @@ public class ContainerWirelessCraftingTerminal extends AEBaseContainer return input; } final IAEItemStack ais = Platform.poweredInsert( - this.getPowerSource(), - this.civ, - AEApi.instance().storage().createItemStack(input), - this.getActionSource()); + this.getPowerSource(), + this.civ, + AEApi.instance().storage().createItemStack(input), + this.getActionSource()); if (ais == null) { return null; } @@ -1310,8 +1317,8 @@ public class ContainerWirelessCraftingTerminal extends AEBaseContainer public ItemStack slotClick(int slot, int button, int flag, EntityPlayer player) { try { if (slot >= 0 - && getSlot(slot) != null - && getSlot(slot).getStack() == RandomUtils.getWirelessTerm(player.inventory)) { + && getSlot(slot) != null + && getSlot(slot).getStack() == RandomUtils.getWirelessTerm(player.inventory)) { return null; } return super.slotClick(slot, button, flag, player); @@ -1342,9 +1349,9 @@ public class ContainerWirelessCraftingTerminal extends AEBaseContainer } if (itemstack1 != null - && itemstack1.getItem() == stack.getItem() - && (!stack.getHasSubtypes() || stack.getItemDamage() == itemstack1.getItemDamage()) - && ItemStack.areItemStackTagsEqual(stack, itemstack1)) { + && itemstack1.getItem() == stack.getItem() + && (!stack.getHasSubtypes() || stack.getItemDamage() == itemstack1.getItemDamage()) + && ItemStack.areItemStackTagsEqual(stack, itemstack1)) { int l = itemstack1.stackSize + stack.stackSize; if (l <= stack.getMaxStackSize() && l <= slot.getSlotStackLimit()) { @@ -1384,7 +1391,7 @@ public class ContainerWirelessCraftingTerminal extends AEBaseContainer break; } else { putStackInSlot( - k, new ItemStack(stack.getItem(), slot.getSlotStackLimit(), stack.getItemDamage())); + k, new ItemStack(stack.getItem(), slot.getSlotStackLimit(), stack.getItemDamage())); stack.stackSize -= slot.getSlotStackLimit(); boosterInventory.markDirty(); flag1 = true; diff --git a/src/main/java/net/p455w0rd/wirelesscraftingterminal/common/container/slot/AppEngCraftingSlot.java b/src/main/java/net/p455w0rd/wirelesscraftingterminal/common/container/slot/AppEngCraftingSlot.java deleted file mode 100644 index 95b990d..0000000 --- a/src/main/java/net/p455w0rd/wirelesscraftingterminal/common/container/slot/AppEngCraftingSlot.java +++ /dev/null @@ -1,161 +0,0 @@ -package net.p455w0rd.wirelesscraftingterminal.common.container.slot; - -import cpw.mods.fml.common.FMLCommonHandler; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.init.Blocks; -import net.minecraft.init.Items; -import net.minecraft.inventory.IInventory; -import net.minecraft.item.Item; -import net.minecraft.item.ItemHoe; -import net.minecraft.item.ItemPickaxe; -import net.minecraft.item.ItemStack; -import net.minecraft.item.ItemSword; -import net.minecraft.item.ItemTool; -import net.minecraft.stats.AchievementList; -import net.minecraftforge.common.MinecraftForge; -import net.minecraftforge.event.entity.player.PlayerDestroyItemEvent; - -public class AppEngCraftingSlot extends AppEngSlot { - - /** - * The craft matrix inventory linked to this result slot. - */ - private final IInventory craftMatrix; - - /** - * The player that is using the GUI where this slot resides. - */ - private final EntityPlayer thePlayer; - - /** - * The number of items that have been crafted so far. Gets passed to ItemStack.onCrafting before being reset. - */ - private int amountCrafted; - - public AppEngCraftingSlot( - final EntityPlayer par1EntityPlayer, - final IInventory par2IInventory, - final IInventory par3IInventory, - final int par4, - final int par5, - final int par6) { - super(par3IInventory, par4, par5, par6); - this.thePlayer = par1EntityPlayer; - this.craftMatrix = par2IInventory; - } - - /** - * Check if the stack is a valid item for this slot. Always true beside for the armor slots. - */ - @Override - public boolean isItemValid(final ItemStack par1ItemStack) { - return false; - } - - /** - * the itemStack passed in is the output - ie, iron ingots, and pickaxes, not ore and wood. Typically increases an - * internal count then calls onCrafting(item). - */ - @Override - protected void onCrafting(final ItemStack par1ItemStack, final int par2) { - this.amountCrafted += par2; - this.onCrafting(par1ItemStack); - } - - /** - * the itemStack passed in is the output - ie, iron ingots, and pickaxes, not ore and wood. - */ - @Override - protected void onCrafting(final ItemStack par1ItemStack) { - par1ItemStack.onCrafting(this.thePlayer.worldObj, this.thePlayer, this.amountCrafted); - this.amountCrafted = 0; - - if (par1ItemStack.getItem() == Item.getItemFromBlock(Blocks.crafting_table)) { - this.thePlayer.addStat(AchievementList.buildWorkBench, 1); - } - - if (par1ItemStack.getItem() instanceof ItemPickaxe) { - this.thePlayer.addStat(AchievementList.buildPickaxe, 1); - } - - if (par1ItemStack.getItem() == Item.getItemFromBlock(Blocks.furnace)) { - this.thePlayer.addStat(AchievementList.buildFurnace, 1); - } - - if (par1ItemStack.getItem() instanceof ItemHoe) { - this.thePlayer.addStat(AchievementList.buildHoe, 1); - } - - if (par1ItemStack.getItem() == Items.bread) { - this.thePlayer.addStat(AchievementList.makeBread, 1); - } - - if (par1ItemStack.getItem() == Items.cake) { - this.thePlayer.addStat(AchievementList.bakeCake, 1); - } - - if (par1ItemStack.getItem() instanceof ItemPickaxe - && ((ItemTool) par1ItemStack.getItem()).func_150913_i() != Item.ToolMaterial.WOOD) { - this.thePlayer.addStat(AchievementList.buildBetterPickaxe, 1); - } - - if (par1ItemStack.getItem() instanceof ItemSword) { - this.thePlayer.addStat(AchievementList.buildSword, 1); - } - - if (par1ItemStack.getItem() == Item.getItemFromBlock(Blocks.enchanting_table)) { - this.thePlayer.addStat(AchievementList.enchantments, 1); - } - - if (par1ItemStack.getItem() == Item.getItemFromBlock(Blocks.bookshelf)) { - this.thePlayer.addStat(AchievementList.bookcase, 1); - } - } - - @Override - public void onPickupFromSlot(final EntityPlayer par1EntityPlayer, final ItemStack par2ItemStack) { - FMLCommonHandler.instance().firePlayerCraftingEvent(par1EntityPlayer, par2ItemStack, this.craftMatrix); - this.onCrafting(par2ItemStack); - - for (int i = 0; i < this.craftMatrix.getSizeInventory(); ++i) { - final ItemStack itemstack1 = this.craftMatrix.getStackInSlot(i); - - if (itemstack1 != null) { - this.craftMatrix.decrStackSize(i, 1); - - if (itemstack1.getItem().hasContainerItem(itemstack1)) { - final ItemStack itemstack2 = itemstack1.getItem().getContainerItem(itemstack1); - - if (itemstack2 != null - && itemstack2.isItemStackDamageable() - && itemstack2.getItemDamage() > itemstack2.getMaxDamage()) { - MinecraftForge.EVENT_BUS.post(new PlayerDestroyItemEvent(this.thePlayer, itemstack2)); - continue; - } - - if (!itemstack1.getItem().doesContainerItemLeaveCraftingGrid(itemstack1) - || !this.thePlayer.inventory.addItemStackToInventory(itemstack2)) { - if (this.craftMatrix.getStackInSlot(i) == null) { - this.craftMatrix.setInventorySlotContents(i, itemstack2); - } else { - this.thePlayer.dropPlayerItemWithRandomChoice(itemstack2, false); - } - } - } - } - } - } - - /** - * Decrease the size of the stack in slot (first int arg) by the amount of the second int arg. Returns the new - * stack. - */ - @Override - public ItemStack decrStackSize(final int par1) { - if (this.getHasStack()) { - this.amountCrafted += Math.min(par1, this.getStack().stackSize); - } - - return super.decrStackSize(par1); - } -} diff --git a/src/main/java/net/p455w0rd/wirelesscraftingterminal/common/container/slot/AppEngSlot.java b/src/main/java/net/p455w0rd/wirelesscraftingterminal/common/container/slot/AppEngSlot.java deleted file mode 100644 index 0c0dccf..0000000 --- a/src/main/java/net/p455w0rd/wirelesscraftingterminal/common/container/slot/AppEngSlot.java +++ /dev/null @@ -1,10 +0,0 @@ -package net.p455w0rd.wirelesscraftingterminal.common.container.slot; - -import net.minecraft.inventory.IInventory; - -public class AppEngSlot extends appeng.container.slot.AppEngSlot { - - public AppEngSlot(final IInventory inv, final int idx, final int x, final int y) { - super(inv, idx, x, y); - } -} diff --git a/src/main/java/net/p455w0rd/wirelesscraftingterminal/common/container/slot/NullSlot.java b/src/main/java/net/p455w0rd/wirelesscraftingterminal/common/container/slot/NullSlot.java deleted file mode 100644 index 0c1c8aa..0000000 --- a/src/main/java/net/p455w0rd/wirelesscraftingterminal/common/container/slot/NullSlot.java +++ /dev/null @@ -1,59 +0,0 @@ -package net.p455w0rd.wirelesscraftingterminal.common.container.slot; - -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.inventory.IInventory; -import net.minecraft.item.ItemStack; - -public class NullSlot extends AppEngSlot { - - public NullSlot() { - super(null, 0, 0, 0); - } - - @Override - public void onSlotChange(final ItemStack par1ItemStack, final ItemStack par2ItemStack) {} - - @Override - public void onPickupFromSlot(final EntityPlayer par1EntityPlayer, final ItemStack par2ItemStack) {} - - @Override - public boolean isItemValid(final ItemStack par1ItemStack) { - return false; - } - - @Override - public ItemStack getStack() { - return null; - } - - @Override - public void putStack(final ItemStack par1ItemStack) {} - - @Override - public void onSlotChanged() {} - - @Override - public int getSlotStackLimit() { - return 0; - } - - @Override - public ItemStack decrStackSize(final int par1) { - return null; - } - - @Override - public boolean isSlotInInventory(final IInventory par1IInventory, final int par2) { - return false; - } - - @Override - public boolean canTakeStack(final EntityPlayer par1EntityPlayer) { - return false; - } - - @Override - public int getSlotIndex() { - return 0; - } -} diff --git a/src/main/java/net/p455w0rd/wirelesscraftingterminal/common/container/slot/OptionalSlotFake.java b/src/main/java/net/p455w0rd/wirelesscraftingterminal/common/container/slot/OptionalSlotFake.java index d095c35..31d3ef2 100644 --- a/src/main/java/net/p455w0rd/wirelesscraftingterminal/common/container/slot/OptionalSlotFake.java +++ b/src/main/java/net/p455w0rd/wirelesscraftingterminal/common/container/slot/OptionalSlotFake.java @@ -1,5 +1,6 @@ package net.p455w0rd.wirelesscraftingterminal.common.container.slot; +import appeng.container.slot.SlotFake; import net.minecraft.inventory.IInventory; import net.minecraft.item.ItemStack; diff --git a/src/main/java/net/p455w0rd/wirelesscraftingterminal/common/container/slot/SlotArmor.java b/src/main/java/net/p455w0rd/wirelesscraftingterminal/common/container/slot/SlotArmor.java index 2ba394f..4706b52 100644 --- a/src/main/java/net/p455w0rd/wirelesscraftingterminal/common/container/slot/SlotArmor.java +++ b/src/main/java/net/p455w0rd/wirelesscraftingterminal/common/container/slot/SlotArmor.java @@ -9,7 +9,7 @@ import net.minecraft.item.ItemArmor; import net.minecraft.item.ItemStack; import net.minecraft.util.IIcon; -public class SlotArmor extends AppEngSlot { +public class SlotArmor extends appeng.container.slot.AppEngSlot { /* * The armor type that can be placed on that slot, it uses the same values diff --git a/src/main/java/net/p455w0rd/wirelesscraftingterminal/common/container/slot/SlotBooster.java b/src/main/java/net/p455w0rd/wirelesscraftingterminal/common/container/slot/SlotBooster.java index 6860223..8c90c94 100644 --- a/src/main/java/net/p455w0rd/wirelesscraftingterminal/common/container/slot/SlotBooster.java +++ b/src/main/java/net/p455w0rd/wirelesscraftingterminal/common/container/slot/SlotBooster.java @@ -9,7 +9,7 @@ import net.minecraft.util.IIcon; import net.p455w0rd.wirelesscraftingterminal.items.ItemBoosterBGIcon; import net.p455w0rd.wirelesscraftingterminal.items.ItemInfinityBooster; -public class SlotBooster extends AppEngSlot { +public class SlotBooster extends appeng.container.slot.AppEngSlot { /** * Custom slot for infinity booster card diff --git a/src/main/java/net/p455w0rd/wirelesscraftingterminal/common/container/slot/SlotCraftingMatrix.java b/src/main/java/net/p455w0rd/wirelesscraftingterminal/common/container/slot/SlotCraftingMatrix.java deleted file mode 100644 index a95827d..0000000 --- a/src/main/java/net/p455w0rd/wirelesscraftingterminal/common/container/slot/SlotCraftingMatrix.java +++ /dev/null @@ -1,40 +0,0 @@ -package net.p455w0rd.wirelesscraftingterminal.common.container.slot; - -import net.minecraft.inventory.Container; -import net.minecraft.inventory.IInventory; -import net.minecraft.item.ItemStack; - -public class SlotCraftingMatrix extends AppEngSlot { - - private final Container c; - - public SlotCraftingMatrix( - final Container c, final IInventory par1iInventory, final int par2, final int par3, final int par4) { - super(par1iInventory, par2, par3, par4); - this.c = c; - } - - @Override - public void clearStack() { - super.clearStack(); - this.c.onCraftMatrixChanged(this.inventory); - } - - @Override - public void putStack(final ItemStack par1ItemStack) { - super.putStack(par1ItemStack); - this.c.onCraftMatrixChanged(this.inventory); - } - - @Override - public boolean isPlayerSide() { - return true; - } - - @Override - public ItemStack decrStackSize(final int par1) { - final ItemStack is = super.decrStackSize(par1); - this.c.onCraftMatrixChanged(this.inventory); - return is; - } -} diff --git a/src/main/java/net/p455w0rd/wirelesscraftingterminal/common/container/slot/SlotCraftingTerm.java b/src/main/java/net/p455w0rd/wirelesscraftingterminal/common/container/slot/SlotCraftingTerm.java deleted file mode 100644 index 8dd1cf8..0000000 --- a/src/main/java/net/p455w0rd/wirelesscraftingterminal/common/container/slot/SlotCraftingTerm.java +++ /dev/null @@ -1,243 +0,0 @@ -package net.p455w0rd.wirelesscraftingterminal.common.container.slot; - -import appeng.api.config.Actionable; -import appeng.api.networking.energy.IEnergySource; -import appeng.api.networking.security.BaseActionSource; -import appeng.api.storage.IMEMonitor; -import appeng.api.storage.IStorageMonitorable; -import appeng.api.storage.data.IAEItemStack; -import appeng.api.storage.data.IItemList; -import appeng.container.ContainerNull; -import appeng.helpers.IContainerCraftingPacket; -import appeng.helpers.InventoryAction; -import appeng.util.InventoryAdaptor; -import appeng.util.Platform; -import appeng.util.inv.AdaptorPlayerHand; -import appeng.util.item.AEItemStack; -import java.util.ArrayList; -import java.util.List; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.inventory.IInventory; -import net.minecraft.inventory.InventoryCrafting; -import net.minecraft.item.Item; -import net.minecraft.item.ItemStack; -import net.minecraft.item.crafting.IRecipe; - -public class SlotCraftingTerm extends AppEngCraftingSlot { - - private final IInventory craftInv; - private final IInventory pattern; - - private final BaseActionSource mySrc; - private final IEnergySource energySrc; - private final IStorageMonitorable storage; - - public SlotCraftingTerm( - final EntityPlayer player, - final BaseActionSource mySrc, - final IEnergySource energySrc, - final IStorageMonitorable storage, - final IInventory cMatrix, - final IInventory secondMatrix, - final IInventory output, - final int x, - final int y, - final IContainerCraftingPacket ccp) { - super(player, cMatrix, output, 0, x, y); - this.energySrc = energySrc; - this.storage = storage; - this.mySrc = mySrc; - this.pattern = cMatrix; - this.craftInv = secondMatrix; - } - - public IInventory getCraftingMatrix() { - return this.craftInv; - } - - @Override - public boolean canTakeStack(final EntityPlayer par1EntityPlayer) { - return false; - } - - @Override - public void onPickupFromSlot(final EntityPlayer p, final ItemStack is) {} - - public void doClick(final InventoryAction action, final EntityPlayer who) { - if (this.getStack() == null) { - return; - } - if (Platform.isClient()) { - return; - } - - final IMEMonitor inv = this.storage.getItemInventory(); - final int howManyPerCraft = this.getStack().stackSize; - int maxTimesToCraft = 0; - - InventoryAdaptor ia = null; - if (action == InventoryAction.CRAFT_SHIFT) // craft into player - // inventory... - { - ia = InventoryAdaptor.getAdaptor(who, null); - maxTimesToCraft = (int) Math.floor((double) this.getStack().getMaxStackSize() / (double) howManyPerCraft); - } else if (action == InventoryAction.CRAFT_STACK) // craft into hand, - // full stack - { - ia = new AdaptorPlayerHand(who); - maxTimesToCraft = (int) Math.floor((double) this.getStack().getMaxStackSize() / (double) howManyPerCraft); - } else - // pick up what was crafted... - { - ia = new AdaptorPlayerHand(who); - maxTimesToCraft = 1; - } - - maxTimesToCraft = this.capCraftingAttempts(maxTimesToCraft); - - if (ia == null) { - return; - } - - final ItemStack rs = Platform.cloneItemStack(this.getStack()); - if (rs == null) { - return; - } - - for (int x = 0; x < maxTimesToCraft; x++) { - if (ia.simulateAdd(rs) == null) { - final IItemList all = inv.getStorageList(); - final ItemStack extra = ia.addItems(this.craftItem(who, rs, inv, all)); - if (extra != null) { - final List drops = new ArrayList(); - drops.add(extra); - Platform.spawnDrops(who.worldObj, (int) who.posX, (int) who.posY, (int) who.posZ, drops); - return; - } - } - } - } - - private int capCraftingAttempts(final int maxTimesToCraft) { - return maxTimesToCraft; - } - - @SuppressWarnings({"rawtypes", "unchecked"}) - private ItemStack craftItem( - final EntityPlayer p, final ItemStack request, final IMEMonitor inv, final IItemList all) { - // update crafting matrix... - ItemStack is = this.getStack(); - - if (is != null && Platform.isSameItem(request, is)) { - final ItemStack[] set = new ItemStack[this.getPattern().getSizeInventory()]; - - // add one of each item to the items on the board... - if (Platform.isServer()) { - final InventoryCrafting ic = new InventoryCrafting(new ContainerNull(), 3, 3); - for (int x = 0; x < 9; x++) { - ic.setInventorySlotContents(x, this.getPattern().getStackInSlot(x)); - } - - final IRecipe r = Platform.findMatchingRecipe(ic, p.worldObj); - - if (r == null) { - final Item target = request.getItem(); - if (target.isDamageable() && target.isRepairable()) { - boolean isBad = false; - for (int x = 0; x < ic.getSizeInventory(); x++) { - final ItemStack pis = ic.getStackInSlot(x); - if (pis == null) { - continue; - } - if (pis.getItem() != target) { - isBad = true; - } - } - if (!isBad) { - super.onPickupFromSlot(p, is); - // actually necessary to cleanup this case... - p.openContainer.onCraftMatrixChanged(this.craftInv); - return request; - } - } - return null; - } - - is = r.getCraftingResult(ic); - - if (inv != null) { - for (int x = 0; x < this.getPattern().getSizeInventory(); x++) { - if (this.getPattern().getStackInSlot(x) != null) { - set[x] = Platform.extractItemsByRecipe( - this.energySrc, - this.mySrc, - inv, - p.worldObj, - r, - is, - ic, - this.getPattern().getStackInSlot(x), - x, - all, - Actionable.MODULATE, - null); - ic.setInventorySlotContents(x, set[x]); - } - } - } - } - - if (this.preCraft(p, inv, set, is)) { - this.makeItem(p, is); - - this.postCraft(p, inv, set, is); - } - - // shouldn't be necessary... - p.openContainer.onCraftMatrixChanged(this.craftInv); - - return is; - } - - return null; - } - - private boolean preCraft( - final EntityPlayer p, final IMEMonitor inv, final ItemStack[] set, final ItemStack result) { - return true; - } - - private void makeItem(final EntityPlayer p, final ItemStack is) { - super.onPickupFromSlot(p, is); - } - - private void postCraft( - final EntityPlayer p, final IMEMonitor inv, final ItemStack[] set, final ItemStack result) { - final List drops = new ArrayList(); - - // add one of each item to the items on the board... - if (Platform.isServer()) { - // set new items onto the crafting table... - for (int x = 0; x < this.craftInv.getSizeInventory(); x++) { - if (this.craftInv.getStackInSlot(x) == null) { - this.craftInv.setInventorySlotContents(x, set[x]); - } else if (set[x] != null) { - // eek! put it back! - final IAEItemStack fail = - inv.injectItems(AEItemStack.create(set[x]), Actionable.MODULATE, this.mySrc); - if (fail != null) { - drops.add(fail.getItemStack()); - } - } - } - } - - if (drops.size() > 0) { - Platform.spawnDrops(p.worldObj, (int) p.posX, (int) p.posY, (int) p.posZ, drops); - } - } - - IInventory getPattern() { - return this.pattern; - } -} diff --git a/src/main/java/net/p455w0rd/wirelesscraftingterminal/common/container/slot/SlotDisabled.java b/src/main/java/net/p455w0rd/wirelesscraftingterminal/common/container/slot/SlotDisabled.java deleted file mode 100644 index b021815..0000000 --- a/src/main/java/net/p455w0rd/wirelesscraftingterminal/common/container/slot/SlotDisabled.java +++ /dev/null @@ -1,22 +0,0 @@ -package net.p455w0rd.wirelesscraftingterminal.common.container.slot; - -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.inventory.IInventory; -import net.minecraft.item.ItemStack; - -public class SlotDisabled extends AppEngSlot { - - public SlotDisabled(final IInventory par1iInventory, final int slotIndex, final int x, final int y) { - super(par1iInventory, slotIndex, x, y); - } - - @Override - public boolean isItemValid(final ItemStack par1ItemStack) { - return false; - } - - @Override - public boolean canTakeStack(final EntityPlayer par1EntityPlayer) { - return false; - } -} diff --git a/src/main/java/net/p455w0rd/wirelesscraftingterminal/common/container/slot/SlotFake.java b/src/main/java/net/p455w0rd/wirelesscraftingterminal/common/container/slot/SlotFake.java deleted file mode 100644 index c4dbc8d..0000000 --- a/src/main/java/net/p455w0rd/wirelesscraftingterminal/common/container/slot/SlotFake.java +++ /dev/null @@ -1,39 +0,0 @@ -package net.p455w0rd.wirelesscraftingterminal.common.container.slot; - -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.inventory.IInventory; -import net.minecraft.item.ItemStack; - -public class SlotFake extends AppEngSlot { - - public SlotFake(final IInventory inv, final int idx, final int x, final int y) { - super(inv, idx, x, y); - } - - @Override - public void onPickupFromSlot(final EntityPlayer par1EntityPlayer, final ItemStack par2ItemStack) {} - - @Override - public ItemStack decrStackSize(final int par1) { - return null; - } - - @Override - public boolean isItemValid(final ItemStack par1ItemStack) { - return false; - } - - @Override - public void putStack(ItemStack is) { - if (is != null) { - is = is.copy(); - } - - super.putStack(is); - } - - @Override - public boolean canTakeStack(final EntityPlayer par1EntityPlayer) { - return false; - } -} diff --git a/src/main/java/net/p455w0rd/wirelesscraftingterminal/common/container/slot/SlotFakeCraftingMatrix.java b/src/main/java/net/p455w0rd/wirelesscraftingterminal/common/container/slot/SlotFakeCraftingMatrix.java deleted file mode 100644 index 66b648e..0000000 --- a/src/main/java/net/p455w0rd/wirelesscraftingterminal/common/container/slot/SlotFakeCraftingMatrix.java +++ /dev/null @@ -1,10 +0,0 @@ -package net.p455w0rd.wirelesscraftingterminal.common.container.slot; - -import net.minecraft.inventory.IInventory; - -public class SlotFakeCraftingMatrix extends SlotFake { - - public SlotFakeCraftingMatrix(final IInventory inv, final int idx, final int x, final int y) { - super(inv, idx, x, y); - } -} diff --git a/src/main/java/net/p455w0rd/wirelesscraftingterminal/common/container/slot/SlotInaccessible.java b/src/main/java/net/p455w0rd/wirelesscraftingterminal/common/container/slot/SlotInaccessible.java deleted file mode 100644 index 3a53579..0000000 --- a/src/main/java/net/p455w0rd/wirelesscraftingterminal/common/container/slot/SlotInaccessible.java +++ /dev/null @@ -1,41 +0,0 @@ -package net.p455w0rd.wirelesscraftingterminal.common.container.slot; - -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.inventory.IInventory; -import net.minecraft.item.ItemStack; - -public class SlotInaccessible extends AppEngSlot { - - private ItemStack dspStack = null; - - public SlotInaccessible(final IInventory i, final int slotIdx, final int x, final int y) { - super(i, slotIdx, x, y); - } - - @Override - public boolean isItemValid(final ItemStack i) { - return false; - } - - @Override - public void onSlotChanged() { - super.onSlotChanged(); - this.dspStack = null; - } - - @Override - public boolean canTakeStack(final EntityPlayer par1EntityPlayer) { - return false; - } - - @Override - public ItemStack getDisplayStack() { - if (this.dspStack == null) { - final ItemStack dsp = super.getDisplayStack(); - if (dsp != null) { - this.dspStack = dsp.copy(); - } - } - return this.dspStack; - } -} diff --git a/src/main/java/net/p455w0rd/wirelesscraftingterminal/common/container/slot/SlotMagnet.java b/src/main/java/net/p455w0rd/wirelesscraftingterminal/common/container/slot/SlotMagnet.java index c047a91..40d381b 100644 --- a/src/main/java/net/p455w0rd/wirelesscraftingterminal/common/container/slot/SlotMagnet.java +++ b/src/main/java/net/p455w0rd/wirelesscraftingterminal/common/container/slot/SlotMagnet.java @@ -4,7 +4,7 @@ import net.minecraft.inventory.IInventory; import net.minecraft.item.ItemStack; import net.p455w0rd.wirelesscraftingterminal.items.ItemMagnet; -public class SlotMagnet extends AppEngSlot { +public class SlotMagnet extends appeng.container.slot.AppEngSlot { public SlotMagnet(IInventory inv, int xPos, int yPos) { super(inv, 0, xPos, yPos); diff --git a/src/main/java/net/p455w0rd/wirelesscraftingterminal/common/container/slot/SlotOutput.java b/src/main/java/net/p455w0rd/wirelesscraftingterminal/common/container/slot/SlotOutput.java deleted file mode 100644 index bc744af..0000000 --- a/src/main/java/net/p455w0rd/wirelesscraftingterminal/common/container/slot/SlotOutput.java +++ /dev/null @@ -1,17 +0,0 @@ -package net.p455w0rd.wirelesscraftingterminal.common.container.slot; - -import net.minecraft.inventory.IInventory; -import net.minecraft.item.ItemStack; - -public class SlotOutput extends AppEngSlot { - - public SlotOutput(final IInventory a, final int b, final int c, final int d, final int i) { - super(a, b, c, d); - this.setIIcon(i); - } - - @Override - public boolean isItemValid(final ItemStack i) { - return false; - } -} diff --git a/src/main/java/net/p455w0rd/wirelesscraftingterminal/common/container/slot/SlotPlayerHotBar.java b/src/main/java/net/p455w0rd/wirelesscraftingterminal/common/container/slot/SlotPlayerHotBar.java deleted file mode 100644 index 81e7f56..0000000 --- a/src/main/java/net/p455w0rd/wirelesscraftingterminal/common/container/slot/SlotPlayerHotBar.java +++ /dev/null @@ -1,10 +0,0 @@ -package net.p455w0rd.wirelesscraftingterminal.common.container.slot; - -import net.minecraft.inventory.IInventory; - -public class SlotPlayerHotBar extends appeng.container.slot.SlotPlayerHotBar { - - public SlotPlayerHotBar(final IInventory par1iInventory, final int par2, final int par3, final int par4) { - super(par1iInventory, par2, par3, par4); - } -} diff --git a/src/main/java/net/p455w0rd/wirelesscraftingterminal/common/container/slot/SlotPlayerInv.java b/src/main/java/net/p455w0rd/wirelesscraftingterminal/common/container/slot/SlotPlayerInv.java deleted file mode 100644 index 9ed4abd..0000000 --- a/src/main/java/net/p455w0rd/wirelesscraftingterminal/common/container/slot/SlotPlayerInv.java +++ /dev/null @@ -1,12 +0,0 @@ -package net.p455w0rd.wirelesscraftingterminal.common.container.slot; - -import net.minecraft.inventory.IInventory; - -// there is nothing special about this slot, its simply used to represent the players inventory, vs a container slot. - -public class SlotPlayerInv extends appeng.container.slot.SlotPlayerInv { - - public SlotPlayerInv(final IInventory par1iInventory, final int par2, final int par3, final int par4) { - super(par1iInventory, par2, par3, par4); - } -} diff --git a/src/main/java/net/p455w0rd/wirelesscraftingterminal/common/container/slot/SlotTrash.java b/src/main/java/net/p455w0rd/wirelesscraftingterminal/common/container/slot/SlotTrash.java index ae33744..3cbbff3 100644 --- a/src/main/java/net/p455w0rd/wirelesscraftingterminal/common/container/slot/SlotTrash.java +++ b/src/main/java/net/p455w0rd/wirelesscraftingterminal/common/container/slot/SlotTrash.java @@ -7,7 +7,7 @@ import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; import net.p455w0rd.wirelesscraftingterminal.common.utils.RandomUtils; -public class SlotTrash extends AppEngSlot { +public class SlotTrash extends appeng.container.slot.AppEngSlot { private final EntityPlayer entityPlayer; private ItemStack itemStack; diff --git a/src/main/java/net/p455w0rd/wirelesscraftingterminal/common/container/slot/SlotViewCell.java b/src/main/java/net/p455w0rd/wirelesscraftingterminal/common/container/slot/SlotViewCell.java index a481e8a..52b821e 100644 --- a/src/main/java/net/p455w0rd/wirelesscraftingterminal/common/container/slot/SlotViewCell.java +++ b/src/main/java/net/p455w0rd/wirelesscraftingterminal/common/container/slot/SlotViewCell.java @@ -1,20 +1,12 @@ package net.p455w0rd.wirelesscraftingterminal.common.container.slot; -import appeng.api.AEApi; +import appeng.container.slot.SlotRestrictedInput; +import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.inventory.IInventory; -import net.minecraft.item.ItemStack; -public class SlotViewCell extends AppEngSlot { +public class SlotViewCell extends SlotRestrictedInput { - public SlotViewCell(IInventory inv, int index, int xPos, int yPos) { - super(inv, index, xPos, yPos); - } - - @Override - public boolean isItemValid(ItemStack is) { - if (is == null || is.getItem() == null) { - return false; - } - return AEApi.instance().definitions().items().viewCell().isSameAs(is); + public SlotViewCell(IInventory inv, int index, int xPos, int yPos, InventoryPlayer playerInv) { + super(PlacableItemType.VIEW_CELL, inv, index, xPos, yPos, playerInv); } } diff --git a/src/main/java/net/p455w0rd/wirelesscraftingterminal/common/registries/EnumCache.java b/src/main/java/net/p455w0rd/wirelesscraftingterminal/common/registries/EnumCache.java deleted file mode 100644 index de0a755..0000000 --- a/src/main/java/net/p455w0rd/wirelesscraftingterminal/common/registries/EnumCache.java +++ /dev/null @@ -1,22 +0,0 @@ -package net.p455w0rd.wirelesscraftingterminal.common.registries; - -import appeng.api.config.SortDir; -import appeng.api.config.SortOrder; -import appeng.api.config.ViewItems; - -public class EnumCache { - /** - * SortDir - */ - public static final SortDir[] AE_SORT_DIRECTIONS = SortDir.values(); - - /** - * SortOrder - */ - public static final SortOrder[] AE_SORT_ORDERS = SortOrder.values(); - - /** - * ViewItems - */ - public static final ViewItems[] AE_VIEW_ITEMS = ViewItems.values(); -} diff --git a/src/main/java/net/p455w0rd/wirelesscraftingterminal/common/utils/ReflectionUtils.java b/src/main/java/net/p455w0rd/wirelesscraftingterminal/common/utils/ReflectionUtils.java deleted file mode 100644 index 666b1b6..0000000 --- a/src/main/java/net/p455w0rd/wirelesscraftingterminal/common/utils/ReflectionUtils.java +++ /dev/null @@ -1,61 +0,0 @@ -package net.p455w0rd.wirelesscraftingterminal.common.utils; - -import cpw.mods.fml.relauncher.ReflectionHelper; -import java.lang.invoke.MethodHandle; -import java.lang.invoke.MethodHandles; -import java.lang.reflect.Field; -import java.lang.reflect.Method; - -public class ReflectionUtils { - /** - * Get a {@link MethodHandle} for a method. - * - * @param clazz The class - * @param methodNames The possible names of the method - * @param methodTypes The argument types of the method - * @param The class - * @return The MethodHandle - */ - public static MethodHandle findMethod(Class clazz, String[] methodNames, Class... methodTypes) { - final Method method = ReflectionHelper.findMethod(clazz, null, methodNames, methodTypes); - try { - return MethodHandles.lookup().unreflect(method); - } catch (IllegalAccessException e) { - throw new ReflectionHelper.UnableToFindMethodException(methodNames, e); - } - } - - /** - * Get a {@link MethodHandle} for a field's getter. - * - * @param clazz The class - * @param fieldNames The possible names of the field - * @return The MethodHandle - */ - public static MethodHandle findFieldGetter(Class clazz, String... fieldNames) { - final Field field = ReflectionHelper.findField(clazz, fieldNames); - - try { - return MethodHandles.lookup().unreflectGetter(field); - } catch (IllegalAccessException e) { - throw new ReflectionHelper.UnableToAccessFieldException(fieldNames, e); - } - } - - /** - * Get a {@link MethodHandle} for a field's setter. - * - * @param clazz The class - * @param fieldNames The possible names of the field - * @return The MethodHandle - */ - public static MethodHandle findFieldSetter(Class clazz, String... fieldNames) { - final Field field = ReflectionHelper.findField(clazz, fieldNames); - - try { - return MethodHandles.lookup().unreflectSetter(field); - } catch (IllegalAccessException e) { - throw new ReflectionHelper.UnableToAccessFieldException(fieldNames, e); - } - } -} diff --git a/src/main/java/net/p455w0rd/wirelesscraftingterminal/core/sync/packets/PacketInventoryAction.java b/src/main/java/net/p455w0rd/wirelesscraftingterminal/core/sync/packets/PacketInventoryAction.java index c1b0ca0..aca26fc 100644 --- a/src/main/java/net/p455w0rd/wirelesscraftingterminal/core/sync/packets/PacketInventoryAction.java +++ b/src/main/java/net/p455w0rd/wirelesscraftingterminal/core/sync/packets/PacketInventoryAction.java @@ -99,7 +99,6 @@ public class PacketInventoryAction extends WCTPacket { context = ((AEBaseContainer) baseContainer).getOpenContext(); } - if (this.action == InventoryAction.AUTO_CRAFT) { // if( context != null ) // { diff --git a/src/main/java/net/p455w0rd/wirelesscraftingterminal/core/sync/packets/PacketNEIRecipe.java b/src/main/java/net/p455w0rd/wirelesscraftingterminal/core/sync/packets/PacketNEIRecipe.java index 3c27778..ed49e5a 100644 --- a/src/main/java/net/p455w0rd/wirelesscraftingterminal/core/sync/packets/PacketNEIRecipe.java +++ b/src/main/java/net/p455w0rd/wirelesscraftingterminal/core/sync/packets/PacketNEIRecipe.java @@ -1,6 +1,5 @@ package net.p455w0rd.wirelesscraftingterminal.core.sync.packets; -import appeng.api.AEApi; import appeng.api.config.Actionable; import appeng.api.config.FuzzyMode; import appeng.api.config.SecurityPermissions; @@ -35,10 +34,8 @@ import net.minecraft.item.crafting.IRecipe; import net.minecraft.nbt.CompressedStreamTools; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; -import net.minecraft.world.World; import net.minecraftforge.common.util.ForgeDirection; import net.minecraftforge.oredict.OreDictionary; -import net.p455w0rd.wirelesscraftingterminal.api.IWirelessCraftingTermHandler; import net.p455w0rd.wirelesscraftingterminal.common.container.ContainerWirelessCraftingTerminal; import net.p455w0rd.wirelesscraftingterminal.common.utils.RandomUtils; import net.p455w0rd.wirelesscraftingterminal.core.sync.WCTPacket; diff --git a/src/main/java/net/p455w0rd/wirelesscraftingterminal/core/sync/packets/PacketValueConfig.java b/src/main/java/net/p455w0rd/wirelesscraftingterminal/core/sync/packets/PacketValueConfig.java index e09728a..f4a7641 100644 --- a/src/main/java/net/p455w0rd/wirelesscraftingterminal/core/sync/packets/PacketValueConfig.java +++ b/src/main/java/net/p455w0rd/wirelesscraftingterminal/core/sync/packets/PacketValueConfig.java @@ -15,7 +15,6 @@ import java.io.IOException; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.Container; import net.minecraft.item.ItemStack; -import net.p455w0rd.wirelesscraftingterminal.common.container.ContainerWirelessCraftingTerminal; import net.p455w0rd.wirelesscraftingterminal.common.utils.RandomUtils; import net.p455w0rd.wirelesscraftingterminal.core.sync.WCTPacket; import net.p455w0rd.wirelesscraftingterminal.core.sync.network.INetworkInfo; diff --git a/src/main/java/net/p455w0rd/wirelesscraftingterminal/helpers/WirelessTerminalGuiObject.java b/src/main/java/net/p455w0rd/wirelesscraftingterminal/helpers/WirelessTerminalGuiObject.java index 9f7c68d..779a8a5 100644 --- a/src/main/java/net/p455w0rd/wirelesscraftingterminal/helpers/WirelessTerminalGuiObject.java +++ b/src/main/java/net/p455w0rd/wirelesscraftingterminal/helpers/WirelessTerminalGuiObject.java @@ -34,7 +34,8 @@ import net.minecraftforge.common.util.ForgeDirection; import net.p455w0rd.wirelesscraftingterminal.api.IWirelessCraftingTerminalItem; import net.p455w0rd.wirelesscraftingterminal.api.networking.security.WCTIActionHost; -public class WirelessTerminalGuiObject implements IActionHost, IPortableCell, IInventorySlotAware, WCTIActionHost, IGuiItemObject { +public class WirelessTerminalGuiObject + implements IActionHost, IPortableCell, IInventorySlotAware, WCTIActionHost, IGuiItemObject { private final ItemStack effectiveItem; private final IWirelessTermHandler wth; diff --git a/src/main/java/net/p455w0rd/wirelesscraftingterminal/integration/modules/NEI.java b/src/main/java/net/p455w0rd/wirelesscraftingterminal/integration/modules/NEI.java index bcaed4e..32e7048 100644 --- a/src/main/java/net/p455w0rd/wirelesscraftingterminal/integration/modules/NEI.java +++ b/src/main/java/net/p455w0rd/wirelesscraftingterminal/integration/modules/NEI.java @@ -2,6 +2,8 @@ package net.p455w0rd.wirelesscraftingterminal.integration.modules; import appeng.api.AEApi; import appeng.api.storage.data.IAEItemStack; +import appeng.container.slot.SlotCraftingMatrix; +import appeng.container.slot.SlotFakeCraftingMatrix; import appeng.integration.modules.NEIHelpers.NEIAEShapelessRecipeHandler; import appeng.util.Platform; import codechicken.nei.PositionedStack; @@ -24,8 +26,6 @@ import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; import net.p455w0rd.wirelesscraftingterminal.client.gui.GuiWirelessCraftingTerminal; import net.p455w0rd.wirelesscraftingterminal.common.container.ContainerWirelessCraftingTerminal; -import net.p455w0rd.wirelesscraftingterminal.common.container.slot.SlotCraftingMatrix; -import net.p455w0rd.wirelesscraftingterminal.common.container.slot.SlotFakeCraftingMatrix; import net.p455w0rd.wirelesscraftingterminal.core.sync.network.NetworkHandler; import net.p455w0rd.wirelesscraftingterminal.core.sync.packets.PacketNEIRecipe; import net.p455w0rd.wirelesscraftingterminal.helpers.Reflected; diff --git a/src/main/java/net/p455w0rd/wirelesscraftingterminal/integration/modules/NEIHelpers/NEICraftingHandler.java b/src/main/java/net/p455w0rd/wirelesscraftingterminal/integration/modules/NEIHelpers/NEICraftingHandler.java index ec278bf..444246e 100644 --- a/src/main/java/net/p455w0rd/wirelesscraftingterminal/integration/modules/NEIHelpers/NEICraftingHandler.java +++ b/src/main/java/net/p455w0rd/wirelesscraftingterminal/integration/modules/NEIHelpers/NEICraftingHandler.java @@ -1,5 +1,7 @@ package net.p455w0rd.wirelesscraftingterminal.integration.modules.NEIHelpers; +import appeng.container.slot.SlotCraftingMatrix; +import appeng.container.slot.SlotFakeCraftingMatrix; import appeng.util.Platform; import codechicken.nei.PositionedStack; import codechicken.nei.api.IOverlayHandler; @@ -12,8 +14,6 @@ import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; import net.p455w0rd.wirelesscraftingterminal.client.gui.GuiWirelessCraftingTerminal; -import net.p455w0rd.wirelesscraftingterminal.common.container.slot.SlotCraftingMatrix; -import net.p455w0rd.wirelesscraftingterminal.common.container.slot.SlotFakeCraftingMatrix; import net.p455w0rd.wirelesscraftingterminal.core.sync.network.NetworkHandler; import net.p455w0rd.wirelesscraftingterminal.core.sync.packets.PacketNEIRecipe; diff --git a/src/main/java/net/p455w0rd/wirelesscraftingterminal/items/ItemMagnet.java b/src/main/java/net/p455w0rd/wirelesscraftingterminal/items/ItemMagnet.java index 626c350..339a9c1 100644 --- a/src/main/java/net/p455w0rd/wirelesscraftingterminal/items/ItemMagnet.java +++ b/src/main/java/net/p455w0rd/wirelesscraftingterminal/items/ItemMagnet.java @@ -1,6 +1,5 @@ package net.p455w0rd.wirelesscraftingterminal.items; -import appeng.api.AEApi; import appeng.api.config.SecurityPermissions; import appeng.api.implementations.guiobjects.IPortableCell; import appeng.api.networking.IGrid; @@ -30,7 +29,6 @@ import net.minecraft.util.AxisAlignedBB; import net.minecraft.util.ChatComponentText; import net.minecraft.world.World; import net.minecraftforge.oredict.OreDictionary; -import net.p455w0rd.wirelesscraftingterminal.api.IWirelessCraftingTermHandler; import net.p455w0rd.wirelesscraftingterminal.api.IWirelessCraftingTerminalItem; import net.p455w0rd.wirelesscraftingterminal.common.WCTGuiHandler; import net.p455w0rd.wirelesscraftingterminal.common.utils.RandomUtils; diff --git a/src/main/java/net/p455w0rd/wirelesscraftingterminal/items/ItemWirelessCraftingTerminal.java b/src/main/java/net/p455w0rd/wirelesscraftingterminal/items/ItemWirelessCraftingTerminal.java index e8a2159..c3b71d8 100644 --- a/src/main/java/net/p455w0rd/wirelesscraftingterminal/items/ItemWirelessCraftingTerminal.java +++ b/src/main/java/net/p455w0rd/wirelesscraftingterminal/items/ItemWirelessCraftingTerminal.java @@ -33,7 +33,8 @@ import net.p455w0rd.wirelesscraftingterminal.integration.EnderIO; import net.p455w0rd.wirelesscraftingterminal.reference.Reference; import org.lwjgl.input.Keyboard; -public class ItemWirelessCraftingTerminal extends AERootPoweredItem implements IWirelessCraftingTerminalItem, IWirelessTermHandler, IBauble { +public class ItemWirelessCraftingTerminal extends AERootPoweredItem + implements IWirelessCraftingTerminalItem, IWirelessTermHandler, IBauble { public static final String LINK_KEY_STRING = "key"; public static double GLOBAL_POWER_MULTIPLIER = PowerMultiplier.CONFIG.multiplier; From 104d89c0c854cca680ed3caadb2b530d23fa720e Mon Sep 17 00:00:00 2001 From: Raven Szewczyk Date: Wed, 24 Aug 2022 19:32:06 +0100 Subject: [PATCH 07/11] Switch to AE2 tab button, text field --- .../client/gui/GuiCraftAmount.java | 2 +- .../client/gui/GuiCraftingStatus.java | 4 +- .../gui/GuiWirelessCraftingTerminal.java | 14 +- .../client/gui/widgets/GuiTabButton.java | 141 ------------------ .../client/gui/widgets/MEGuiTextField.java | 87 ----------- .../common/container/CraftingCPURecord.java | 45 ------ 6 files changed, 7 insertions(+), 286 deletions(-) delete mode 100644 src/main/java/net/p455w0rd/wirelesscraftingterminal/client/gui/widgets/GuiTabButton.java delete mode 100644 src/main/java/net/p455w0rd/wirelesscraftingterminal/client/gui/widgets/MEGuiTextField.java delete mode 100644 src/main/java/net/p455w0rd/wirelesscraftingterminal/common/container/CraftingCPURecord.java diff --git a/src/main/java/net/p455w0rd/wirelesscraftingterminal/client/gui/GuiCraftAmount.java b/src/main/java/net/p455w0rd/wirelesscraftingterminal/client/gui/GuiCraftAmount.java index 0681ecc..5c47d59 100644 --- a/src/main/java/net/p455w0rd/wirelesscraftingterminal/client/gui/GuiCraftAmount.java +++ b/src/main/java/net/p455w0rd/wirelesscraftingterminal/client/gui/GuiCraftAmount.java @@ -4,12 +4,12 @@ import appeng.api.AEApi; import appeng.api.definitions.IDefinitions; import appeng.api.definitions.IParts; import appeng.api.storage.ITerminalHost; +import appeng.client.gui.widgets.GuiTabButton; import appeng.container.implementations.ContainerCraftAmount; import appeng.helpers.Reflected; import net.minecraft.client.gui.GuiButton; import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.item.ItemStack; -import net.p455w0rd.wirelesscraftingterminal.client.gui.widgets.GuiTabButton; import net.p455w0rd.wirelesscraftingterminal.core.sync.network.NetworkHandler; import net.p455w0rd.wirelesscraftingterminal.core.sync.packets.PacketSwitchGuis; import net.p455w0rd.wirelesscraftingterminal.helpers.WirelessTerminalGuiObject; diff --git a/src/main/java/net/p455w0rd/wirelesscraftingterminal/client/gui/GuiCraftingStatus.java b/src/main/java/net/p455w0rd/wirelesscraftingterminal/client/gui/GuiCraftingStatus.java index 41661ed..71bb887 100644 --- a/src/main/java/net/p455w0rd/wirelesscraftingterminal/client/gui/GuiCraftingStatus.java +++ b/src/main/java/net/p455w0rd/wirelesscraftingterminal/client/gui/GuiCraftingStatus.java @@ -4,11 +4,11 @@ import appeng.api.AEApi; import appeng.api.definitions.IDefinitions; import appeng.api.definitions.IParts; import appeng.api.storage.ITerminalHost; +import appeng.client.gui.widgets.GuiTabButton; import appeng.container.implementations.ContainerCraftingStatus; import net.minecraft.client.gui.GuiButton; import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.item.ItemStack; -import net.p455w0rd.wirelesscraftingterminal.client.gui.widgets.GuiTabButton; import net.p455w0rd.wirelesscraftingterminal.core.sync.network.NetworkHandler; import net.p455w0rd.wirelesscraftingterminal.core.sync.packets.PacketSwitchGuis; import net.p455w0rd.wirelesscraftingterminal.helpers.WirelessTerminalGuiObject; @@ -57,8 +57,6 @@ public class GuiCraftingStatus extends appeng.client.gui.implementations.GuiCraf @Override public void initGui() { super.initGui(); - // Hide "go back to wireless terminal" button as it opens the wrong GUI - this.buttonList.remove(this.buttonList.size() - 1); if (this.myIcon != null) { this.buttonList.add( diff --git a/src/main/java/net/p455w0rd/wirelesscraftingterminal/client/gui/GuiWirelessCraftingTerminal.java b/src/main/java/net/p455w0rd/wirelesscraftingterminal/client/gui/GuiWirelessCraftingTerminal.java index 13abe91..daa5c0b 100644 --- a/src/main/java/net/p455w0rd/wirelesscraftingterminal/client/gui/GuiWirelessCraftingTerminal.java +++ b/src/main/java/net/p455w0rd/wirelesscraftingterminal/client/gui/GuiWirelessCraftingTerminal.java @@ -12,7 +12,9 @@ import appeng.client.ActionKey; import appeng.client.gui.AEBaseGui; import appeng.client.gui.widgets.GuiImgButton; import appeng.client.gui.widgets.GuiScrollbar; +import appeng.client.gui.widgets.GuiTabButton; import appeng.client.gui.widgets.ISortSource; +import appeng.client.gui.widgets.MEGuiTextField; import appeng.client.me.InternalSlotME; import appeng.client.me.ItemRepo; import appeng.client.me.SlotME; @@ -44,9 +46,7 @@ import net.minecraft.inventory.Container; import net.minecraft.inventory.Slot; import net.minecraft.item.ItemStack; import net.minecraft.util.ResourceLocation; -import net.p455w0rd.wirelesscraftingterminal.client.gui.widgets.GuiTabButton; import net.p455w0rd.wirelesscraftingterminal.client.gui.widgets.GuiTrashButton; -import net.p455w0rd.wirelesscraftingterminal.client.gui.widgets.MEGuiTextField; import net.p455w0rd.wirelesscraftingterminal.common.container.ContainerWirelessCraftingTerminal; import net.p455w0rd.wirelesscraftingterminal.common.container.slot.SlotTrash; import net.p455w0rd.wirelesscraftingterminal.common.utils.WCTLog; @@ -388,13 +388,9 @@ public class GuiWirelessCraftingTerminal extends AEBaseGui implements ISortSourc Settings.TERMINAL_STYLE, AEConfig.instance.settings.getSetting(Settings.TERMINAL_STYLE))); - this.searchField = new MEGuiTextField(this.fontRendererObj, SEARCH_X, SEARCH_Y, SEARCH_WIDTH, SEARCH_HEIGHT); - - this.searchField.setEnableBackgroundDrawing(false); - this.searchField.setMaxStringLength(25); - this.searchField.setTextColor(0xFFFFFF); - this.searchField.setVisible(true); - this.searchField.setEnabled(true); + this.searchField = new MEGuiTextField(SEARCH_WIDTH, SEARCH_HEIGHT); + this.searchField.x = SEARCH_X; + this.searchField.y = SEARCH_Y; this.buttonList.add( this.craftingStatusBtn = new GuiTabButton( diff --git a/src/main/java/net/p455w0rd/wirelesscraftingterminal/client/gui/widgets/GuiTabButton.java b/src/main/java/net/p455w0rd/wirelesscraftingterminal/client/gui/widgets/GuiTabButton.java deleted file mode 100644 index c4109fa..0000000 --- a/src/main/java/net/p455w0rd/wirelesscraftingterminal/client/gui/widgets/GuiTabButton.java +++ /dev/null @@ -1,141 +0,0 @@ -package net.p455w0rd.wirelesscraftingterminal.client.gui.widgets; - -import appeng.client.gui.widgets.ITooltip; -import appeng.client.texture.ExtraBlockTextures; -import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.FontRenderer; -import net.minecraft.client.gui.GuiButton; -import net.minecraft.client.renderer.RenderHelper; -import net.minecraft.client.renderer.entity.RenderItem; -import net.minecraft.item.ItemStack; -import org.lwjgl.opengl.GL11; -import org.lwjgl.opengl.GL12; - -public class GuiTabButton extends GuiButton implements ITooltip { - private final RenderItem itemRenderer; - private final String message; - private int hideEdge = 0; - private int myIcon = -1; - private ItemStack myItem; - - public GuiTabButton(final int x, final int y, final int ico, final String message, final RenderItem ir) { - super(0, 0, 16, ""); - - this.xPosition = x; - this.yPosition = y; - this.width = 22; - this.height = 22; - this.myIcon = ico; - this.message = message; - this.itemRenderer = ir; - } - - /** - * Using itemstack as an icon - * - * @param x x pos of button - * @param y y pos of button - * @param ico used icon - * @param message mouse over message - * @param ir renderer - */ - public GuiTabButton(final int x, final int y, final ItemStack ico, final String message, final RenderItem ir) { - super(0, 0, 16, ""); - this.xPosition = x; - this.yPosition = y; - this.width = 22; - this.height = 22; - this.myItem = ico; - this.message = message; - this.itemRenderer = ir; - } - - @Override - public void drawButton(final Minecraft minecraft, final int x, final int y) { - if (this.visible) { - GL11.glColor4f(1.0f, 1.0f, 1.0f, 1.0f); - minecraft.renderEngine.bindTexture(ExtraBlockTextures.GuiTexture("guis/states.png")); - this.field_146123_n = x >= this.xPosition - && y >= this.yPosition - && x < this.xPosition + this.width - && y < this.yPosition + this.height; - - int uv_x = (this.hideEdge > 0 ? 11 : 13); - - final int offsetX = this.hideEdge > 0 ? 1 : 0; - - // this.drawTexturedModalRect( this.xPosition, this.yPosition, uv_x * 16, 0, 25, 22 ); - - if (this.myIcon >= 0) { - final int uv_y = (int) Math.floor(this.myIcon / 16); - uv_x = this.myIcon - uv_y * 16; - - this.drawTexturedModalRect( - offsetX + this.xPosition + 3, this.yPosition + 6, uv_x * 16, uv_y * 16, 16, 16); - } - - this.mouseDragged(minecraft, x, y); - - if (this.myItem != null) { - this.zLevel = 100.0F; - this.itemRenderer.zLevel = 100.0F; - - GL11.glEnable(GL11.GL_LIGHTING); - GL11.glEnable(GL12.GL_RESCALE_NORMAL); - RenderHelper.enableGUIStandardItemLighting(); - final FontRenderer fontrenderer = minecraft.fontRenderer; - // this.itemRenderer.renderItemAndEffectIntoGUI( fontrenderer, minecraft.renderEngine, this.myItem, - // offsetX + this.xPosition + 3, this.yPosition + 6 ); - this.itemRenderer.renderItemIntoGUI( - fontrenderer, - minecraft.renderEngine, - this.myItem, - offsetX + this.xPosition + 3, - this.yPosition + 6, - false); - GL11.glDisable(GL11.GL_LIGHTING); - - this.itemRenderer.zLevel = 0.0F; - this.zLevel = 0.0F; - } - } - } - - @Override - public String getMessage() { - return this.message; - } - - @Override - public int xPos() { - return this.xPosition; - } - - @Override - public int yPos() { - return this.yPosition; - } - - @Override - public int getWidth() { - return 22; - } - - @Override - public int getHeight() { - return 22; - } - - @Override - public boolean isVisible() { - return this.visible; - } - - public int getHideEdge() { - return this.hideEdge; - } - - public void setHideEdge(final int hideEdge) { - this.hideEdge = hideEdge; - } -} diff --git a/src/main/java/net/p455w0rd/wirelesscraftingterminal/client/gui/widgets/MEGuiTextField.java b/src/main/java/net/p455w0rd/wirelesscraftingterminal/client/gui/widgets/MEGuiTextField.java deleted file mode 100644 index 72f1f7b..0000000 --- a/src/main/java/net/p455w0rd/wirelesscraftingterminal/client/gui/widgets/MEGuiTextField.java +++ /dev/null @@ -1,87 +0,0 @@ -package net.p455w0rd.wirelesscraftingterminal.client.gui.widgets; - -import net.minecraft.client.gui.FontRenderer; -import net.minecraft.client.gui.GuiTextField; - -/** - * A modified version of the Minecraft text field. - * You can initialize it over the full element span. - * The mouse click area is increased to the full element - * subtracted with the defined padding. - * - * The rendering does pay attention to the size of the '_' caret. - */ -public class MEGuiTextField extends GuiTextField { - private static final int PADDING = 2; - - private final int _xPos; - private final int _yPos; - private final int _width; - private final int _height; - - /** - * Uses the values to instantiate a padded version of a text field. - * Pays attention to the '_' caret. - * - * @param fontRenderer renderer for the strings - * @param xPos absolute left position - * @param yPos absolute top position - * @param width absolute width - * @param height absolute height - */ - public MEGuiTextField( - final FontRenderer fontRenderer, final int xPos, final int yPos, final int width, final int height) { - super(fontRenderer, xPos, yPos, width, height - 2 * PADDING); - - this._xPos = xPos; - this._yPos = yPos; - this._width = width; - this._height = height; - } - - @Override - public void mouseClicked(final int xPos, final int yPos, final int button) { - super.mouseClicked(xPos, yPos, button); - - final boolean requiresFocus = this.isMouseIn(xPos, yPos); - - this.setFocused(requiresFocus); - } - - /** - * Checks if the mouse is within the element - * - * @param xCoord current x coord of the mouse - * @param yCoord current y coord of the mouse - * - * @return true if mouse position is within the text field area - */ - public boolean isMouseIn(final int xCoord, final int yCoord) { - final boolean withinXRange = xCoord >= this._xPos && xCoord <= this._xPos + this._width; - final boolean withinYRange = this._yPos <= yCoord && yCoord < this._yPos + this._height; - - return withinXRange && withinYRange; - } - - @Override - public void drawTextBox() { - if (this.getVisible()) { - if (this.isFocused()) { - drawRect( - this.xPosition - 1, - this.yPosition, - this.xPosition + this.width - 1, - this.yPosition + this.height + 2, - 0xFF606060); - } else { - drawRect( - this.xPosition - 1, - this.yPosition, - this.xPosition + this.width - 1, - this.yPosition + this.height + 2, - 0xFFA8A8A8); - } - super.drawTextBox(); - } - } -} diff --git a/src/main/java/net/p455w0rd/wirelesscraftingterminal/common/container/CraftingCPURecord.java b/src/main/java/net/p455w0rd/wirelesscraftingterminal/common/container/CraftingCPURecord.java deleted file mode 100644 index b4c126c..0000000 --- a/src/main/java/net/p455w0rd/wirelesscraftingterminal/common/container/CraftingCPURecord.java +++ /dev/null @@ -1,45 +0,0 @@ -package net.p455w0rd.wirelesscraftingterminal.common.container; - -import appeng.api.networking.crafting.ICraftingCPU; -import appeng.util.ItemSorters; -import javax.annotation.Nonnull; - -public class CraftingCPURecord implements Comparable { - - private final String myName; - private final ICraftingCPU cpu; - private final long size; - private final int processors; - - public CraftingCPURecord(final long size, final int coProcessors, final ICraftingCPU server) { - this.size = size; - this.processors = coProcessors; - this.cpu = server; - this.myName = server.getName(); - } - - @Override - public int compareTo(@Nonnull final CraftingCPURecord o) { - final int a = ItemSorters.compareLong(o.getProcessors(), this.getProcessors()); - if (a != 0) { - return a; - } - return ItemSorters.compareLong(o.getSize(), this.getSize()); - } - - public ICraftingCPU getCpu() { - return this.cpu; - } - - String getName() { - return this.myName; - } - - int getProcessors() { - return this.processors; - } - - long getSize() { - return this.size; - } -} From 1a22788e4fea08894f62c662e52d4e5d830c7009 Mon Sep 17 00:00:00 2001 From: Raven Szewczyk Date: Wed, 24 Aug 2022 21:13:02 +0100 Subject: [PATCH 08/11] Fix texture errors --- .../client/gui/GuiWirelessCraftingTerminal.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/net/p455w0rd/wirelesscraftingterminal/client/gui/GuiWirelessCraftingTerminal.java b/src/main/java/net/p455w0rd/wirelesscraftingterminal/client/gui/GuiWirelessCraftingTerminal.java index daa5c0b..c77a491 100644 --- a/src/main/java/net/p455w0rd/wirelesscraftingterminal/client/gui/GuiWirelessCraftingTerminal.java +++ b/src/main/java/net/p455w0rd/wirelesscraftingterminal/client/gui/GuiWirelessCraftingTerminal.java @@ -538,7 +538,7 @@ public class GuiWirelessCraftingTerminal extends AEBaseGui implements ISortSourc } public void drawBG(final int offsetX, final int offsetY, final int mouseX, final int mouseY) { - this.bindTexture(bgTexturePath); + this.bindMyTexture(bgTexturePath); final int x_width = 199; // draw "over inventory area" @@ -656,7 +656,7 @@ public class GuiWirelessCraftingTerminal extends AEBaseGui implements ISortSourc return this.repo.hasPower(); } - public void bindTexture(final String file) { + public void bindMyTexture(final String file) { final ResourceLocation loc = new ResourceLocation(Reference.MODID, "textures/" + file); this.mc.getTextureManager().bindTexture(loc); } From a10debce279166b8e59ad38d448e13cf9c21d26d Mon Sep 17 00:00:00 2001 From: Raven Szewczyk Date: Fri, 26 Aug 2022 16:08:21 +0100 Subject: [PATCH 09/11] Fix derps --- .../client/gui/GuiCraftAmount.java | 4 ++++ .../client/gui/GuiWirelessCraftingTerminal.java | 7 ++++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/main/java/net/p455w0rd/wirelesscraftingterminal/client/gui/GuiCraftAmount.java b/src/main/java/net/p455w0rd/wirelesscraftingterminal/client/gui/GuiCraftAmount.java index 5c47d59..64420d8 100644 --- a/src/main/java/net/p455w0rd/wirelesscraftingterminal/client/gui/GuiCraftAmount.java +++ b/src/main/java/net/p455w0rd/wirelesscraftingterminal/client/gui/GuiCraftAmount.java @@ -36,6 +36,10 @@ public class GuiCraftAmount extends appeng.client.gui.implementations.GuiCraftAm @Override public void initGui() { super.initGui(); + // Remove the autogenerated button which takes you to the AE2 wireless terminal GUI + if (this.buttonList.get(this.buttonList.size() - 1) instanceof GuiTabButton) { + this.buttonList.remove(this.buttonList.size() - 1); + } final Object target = ((ContainerCraftAmount) this.inventorySlots).getTarget(); final IDefinitions definitions = AEApi.instance().definitions(); diff --git a/src/main/java/net/p455w0rd/wirelesscraftingterminal/client/gui/GuiWirelessCraftingTerminal.java b/src/main/java/net/p455w0rd/wirelesscraftingterminal/client/gui/GuiWirelessCraftingTerminal.java index c77a491..f437253 100644 --- a/src/main/java/net/p455w0rd/wirelesscraftingterminal/client/gui/GuiWirelessCraftingTerminal.java +++ b/src/main/java/net/p455w0rd/wirelesscraftingterminal/client/gui/GuiWirelessCraftingTerminal.java @@ -71,8 +71,8 @@ public class GuiWirelessCraftingTerminal extends AEBaseGui implements ISortSourc AE_NUM_ROWS = 0, GUI_UPPER_HEIGHT = 35, GUI_SEARCH_ROW = 35, - SEARCH_X = 81, - SEARCH_Y = 5, + SEARCH_X = 80, + SEARCH_Y = 4, SEARCH_WIDTH = 88, SEARCH_HEIGHT = 12, SEARCH_MAXCHARS = 15, @@ -262,8 +262,8 @@ public class GuiWirelessCraftingTerminal extends AEBaseGui implements ISortSourc final PacketInventoryAction p = new PacketInventoryAction(action, this.inventorySlots.inventorySlots.size(), 0); NetworkHandler.instance.sendToServer(p); + return; } - return; } super.handleMouseClick(slot, slotIdx, ctrlDown, mouseButton); } @@ -765,6 +765,7 @@ public class GuiWirelessCraftingTerminal extends AEBaseGui implements ISortSourc } this.repo.updateView(); + this.setScrollBar(); } public boolean isCustomSortOrder() { From a6cbdc4b5d7064db4dc9a1523e354953156a1215 Mon Sep 17 00:00:00 2001 From: Raven Szewczyk Date: Fri, 26 Aug 2022 16:27:43 +0100 Subject: [PATCH 10/11] Fix some warnings, remove broken cape code --- .../ContainerWirelessCraftingTerminal.java | 9 +- .../handlers/NEIRecipeHandler.java | 47 ---- .../implementation/WirelessAELink.java | 263 ------------------ .../proxy/ClientProxy.java | 75 +---- .../proxy/CommonProxy.java | 39 +-- 5 files changed, 5 insertions(+), 428 deletions(-) delete mode 100644 src/main/java/net/p455w0rd/wirelesscraftingterminal/handlers/NEIRecipeHandler.java delete mode 100644 src/main/java/net/p455w0rd/wirelesscraftingterminal/implementation/WirelessAELink.java diff --git a/src/main/java/net/p455w0rd/wirelesscraftingterminal/common/container/ContainerWirelessCraftingTerminal.java b/src/main/java/net/p455w0rd/wirelesscraftingterminal/common/container/ContainerWirelessCraftingTerminal.java index f6d8e20..83318c9 100644 --- a/src/main/java/net/p455w0rd/wirelesscraftingterminal/common/container/ContainerWirelessCraftingTerminal.java +++ b/src/main/java/net/p455w0rd/wirelesscraftingterminal/common/container/ContainerWirelessCraftingTerminal.java @@ -339,6 +339,7 @@ public class ContainerWirelessCraftingTerminal extends AEBaseContainer writeToNBT("crafting"); } + @Override public void doAction(final EntityPlayerMP player, final InventoryAction action, final int slot, final long id) { if (slot >= 0 && slot < this.inventorySlots.size()) { final Slot s = this.getSlot(slot); @@ -350,7 +351,9 @@ public class ContainerWirelessCraftingTerminal extends AEBaseContainer case CRAFT_STACK: ((SlotCraftingTerm) s).doClick(action, player); this.updateHeld(player); + break; default: + break; } } @@ -1255,12 +1258,6 @@ public class ContainerWirelessCraftingTerminal extends AEBaseContainer return null; } - @SuppressWarnings("unused") - private boolean isCraftMatrixSlot(AppEngSlot cs) { - return (cs.getSlotIndex() >= this.firstCraftingSlotNumber) - && !(cs.getSlotIndex() <= this.lastCraftingSlotNumber); - } - private void updateSlot(final Slot clickSlot) { this.detectAndSendChanges(); } diff --git a/src/main/java/net/p455w0rd/wirelesscraftingterminal/handlers/NEIRecipeHandler.java b/src/main/java/net/p455w0rd/wirelesscraftingterminal/handlers/NEIRecipeHandler.java deleted file mode 100644 index 5be3342..0000000 --- a/src/main/java/net/p455w0rd/wirelesscraftingterminal/handlers/NEIRecipeHandler.java +++ /dev/null @@ -1,47 +0,0 @@ -package net.p455w0rd.wirelesscraftingterminal.handlers; - -import codechicken.nei.PositionedStack; -import codechicken.nei.recipe.TemplateRecipeHandler; -import net.minecraft.item.ItemStack; -import net.minecraft.item.crafting.IRecipe; -import net.minecraftforge.oredict.ShapedOreRecipe; - -public class NEIRecipeHandler extends TemplateRecipeHandler { - - public static NEIRecipeHandler INSTANCE; - - public NEIRecipeHandler() { - INSTANCE = this; - } - - @Override - public String getRecipeName() { - // TODO Auto-generated method stub - return null; - } - - @Override - public String getGuiTexture() { - // TODO Auto-generated method stub - return null; - } - - public void removeCachedRecipe(IRecipe r) { - ItemStack recipeOutput = null; - if (r instanceof ShapedOreRecipe) { - ShapedOreRecipe recipe = (ShapedOreRecipe) r; - recipeOutput = recipe.getRecipeOutput(); - } - System.out.println("test"); - if (recipeOutput == null) { - return; - } - for (int i = 0; i < arecipes.size(); i++) { - PositionedStack cachedResult = getResultStack(i); - PositionedStack recipeResult = new PositionedStack(recipeOutput, 119, 24); - if (cachedResult == recipeResult) { - System.out.println("match!"); - } - } - } -} diff --git a/src/main/java/net/p455w0rd/wirelesscraftingterminal/implementation/WirelessAELink.java b/src/main/java/net/p455w0rd/wirelesscraftingterminal/implementation/WirelessAELink.java deleted file mode 100644 index 5aa3156..0000000 --- a/src/main/java/net/p455w0rd/wirelesscraftingterminal/implementation/WirelessAELink.java +++ /dev/null @@ -1,263 +0,0 @@ -package net.p455w0rd.wirelesscraftingterminal.implementation; - -import appeng.api.AEApi; -import appeng.api.implementations.tiles.IWirelessAccessPoint; -import appeng.api.networking.IGrid; -import appeng.api.networking.IGridNode; -import appeng.api.networking.IMachineSet; -import appeng.api.networking.energy.IEnergyGrid; -import appeng.api.networking.security.BaseActionSource; -import appeng.api.networking.storage.IStorageGrid; -import appeng.api.storage.IMEMonitor; -import appeng.api.storage.IStorageMonitorable; -import appeng.api.storage.data.IAEFluidStack; -import appeng.api.storage.data.IAEItemStack; -import appeng.api.util.DimensionalCoord; -import appeng.tile.misc.TileSecurity; -import appeng.tile.networking.TileWireless; -import java.util.ArrayList; -import javax.annotation.Nonnull; -import javax.annotation.Nullable; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.world.World; -import net.minecraftforge.common.util.ForgeDirection; -import net.p455w0rd.wirelesscraftingterminal.api.networking.security.MachineSource; -import net.p455w0rd.wirelesscraftingterminal.api.networking.security.WCTIActionHost; -import net.p455w0rd.wirelesscraftingterminal.api.networking.security.WCTPlayerSource; - -/** - * Provides wireless access to a ME network. - * - * @author Nividica - * - */ -public abstract class WirelessAELink implements IStorageMonitorable { - - protected final EntityPlayer player; - - protected final String encryptionKey; - - protected IWirelessAccessPoint accessPoint; - - protected DimensionalCoord apLocation = null; - - protected BaseActionSource actionSource; - - public WirelessAELink(final @Nullable EntityPlayer player, @Nonnull final String encryptionKey) { - this.player = player; - this.encryptionKey = encryptionKey; - this.linkWithNewAP(); - } - - private static boolean isAPInRange( - final DimensionalCoord APLocation, - final double APRange, - final World world, - final int x, - final int y, - final int z) { - if (!APLocation.isInWorld(world)) { - return false; - } - double squareDistance = getSquaredDistanceFromAP(APLocation, x, y, z); - return squareDistance <= (APRange * APRange); - } - - private static ArrayList locateAPsInRange( - final World world, final int x, final int y, final int z, final IGrid grid) { - IMachineSet accessPoints = grid.getMachines(TileWireless.class); - if (accessPoints.isEmpty()) { - return null; - } - ArrayList aps = new ArrayList(); - for (IGridNode APNode : accessPoints) { - IWirelessAccessPoint AP = (IWirelessAccessPoint) APNode.getMachine(); - if (AP.isActive()) { - if (isAPInRange(AP.getLocation(), AP.getRange(), world, x, y, z)) { - aps.add(AP); - } - } - } - - return aps; - } - - protected static double getSquaredDistanceFromAP( - final DimensionalCoord locationAP, final int x, final int y, final int z) { - if (locationAP == null) { - return Double.MAX_VALUE; - } - int dX = locationAP.x - x, dY = locationAP.y - y, dZ = locationAP.z - z; - return ((dX * dX) + (dY * dY) + (dZ * dZ)); - } - - public static ArrayList locateAPsInRange( - final World world, final int x, final int y, final int z, final String encryptionKey) { - long encryptionValue; - try { - encryptionValue = Long.parseLong(encryptionKey); - } catch (NumberFormatException e) { - return null; - } - - Object source = AEApi.instance().registries().locatable().getLocatableBy(encryptionValue); - - if (!(source instanceof TileSecurity)) { - return null; - } - TileSecurity securityHost = (TileSecurity) source; - IGrid grid; - try { - grid = securityHost.getGridNode(ForgeDirection.UNKNOWN).getGrid(); - } catch (Exception e) { - return null; - } - - return locateAPsInRange(world, x, y, z, grid); - } - - public static ArrayList locateAPsInRangeOfPlayer( - final EntityPlayer player, final String encryptionKey) { - return locateAPsInRange( - player.worldObj, - (int) Math.floor(player.posX), - (int) Math.floor(player.posY), - (int) Math.floor(player.posZ), - encryptionKey); - } - - private boolean isAPInRangeAndActive() { - if (this.accessPoint != null) { - if (this.accessPoint.isActive()) { - return isAPInRange( - this.apLocation, - this.accessPoint.getRange(), - this.getUserWorld(), - this.getUserPositionX(), - this.getUserPositionY(), - this.getUserPositionZ()); - } - } - return false; - } - - private boolean linkWithNewAP() { - World w = this.getUserWorld(); - int x = this.getUserPositionX(); - int y = this.getUserPositionY(); - int z = this.getUserPositionZ(); - - IGrid grid = null; - if (this.accessPoint != null) { - try { - grid = this.accessPoint.getGrid(); - } catch (Exception e) { - } - } - - ArrayList apList; - if (grid != null) { - apList = locateAPsInRange(w, x, y, z, grid); - } else { - apList = locateAPsInRange(w, x, y, z, this.encryptionKey); - } - - if ((apList == null) || (apList.isEmpty())) { - this.accessPoint = null; - return false; - } - - IWirelessAccessPoint closest = null; - double closestDistance = Double.MAX_VALUE; - for (IWirelessAccessPoint ap : apList) { - double dist = getSquaredDistanceFromAP(ap.getLocation(), x, y, z); - if (dist < closestDistance) { - closestDistance = dist; - closest = ap; - } - } - this.setAP(closest); - - return true; - } - - private void setAP(final IWirelessAccessPoint accessPoint) { - this.accessPoint = accessPoint; - this.apLocation = this.accessPoint.getLocation(); - if (this.player != null) { - this.actionSource = new WCTPlayerSource(this.player, (WCTIActionHost) this.accessPoint); - } else { - this.actionSource = new MachineSource((WCTIActionHost) this.accessPoint); - } - } - - protected abstract int getUserPositionX(); - - protected abstract int getUserPositionY(); - - protected abstract int getUserPositionZ(); - - protected abstract World getUserWorld(); - - protected abstract boolean hasPowerToCommunicate(); - - public IEnergyGrid getEnergyGrid() { - if (this.accessPoint == null) { - return null; - } - - try { - return this.accessPoint.getActionableNode().getGrid().getCache(IEnergyGrid.class); - } catch (Exception e) { - // Ignored - } - - return null; - } - - @Override - public IMEMonitor getFluidInventory() { - if ((this.accessPoint == null) || !this.isConnected()) { - return null; - } - - try { - IStorageGrid storageGrid = - this.accessPoint.getActionableNode().getGrid().getCache(IStorageGrid.class); - return storageGrid.getFluidInventory(); - } catch (Exception e) { - // Ignored - } - - return null; - } - - @Override - public IMEMonitor getItemInventory() { - if ((this.accessPoint == null) || !this.isConnected()) { - return null; - } - - try { - IStorageGrid storageGrid = - this.accessPoint.getActionableNode().getGrid().getCache(IStorageGrid.class); - return storageGrid.getItemInventory(); - } catch (Exception e) { - // Ignored - } - - return null; - } - - public boolean isConnected() { - if (!this.hasPowerToCommunicate()) { - return false; - } - - if (this.isAPInRangeAndActive()) { - return true; - } - - return this.linkWithNewAP(); - } -} diff --git a/src/main/java/net/p455w0rd/wirelesscraftingterminal/proxy/ClientProxy.java b/src/main/java/net/p455w0rd/wirelesscraftingterminal/proxy/ClientProxy.java index d7192e0..5e83618 100644 --- a/src/main/java/net/p455w0rd/wirelesscraftingterminal/proxy/ClientProxy.java +++ b/src/main/java/net/p455w0rd/wirelesscraftingterminal/proxy/ClientProxy.java @@ -1,30 +1,17 @@ package net.p455w0rd.wirelesscraftingterminal.proxy; -import com.mojang.authlib.minecraft.MinecraftProfileTexture; import cpw.mods.fml.common.FMLCommonHandler; import cpw.mods.fml.common.Loader; -import cpw.mods.fml.common.eventhandler.SubscribeEvent; -import java.io.IOException; -import java.io.InputStream; -import java.net.MalformedURLException; -import java.net.URL; -import java.util.List; -import javax.xml.bind.DatatypeConverter; -import net.minecraft.client.entity.AbstractClientPlayer; import net.minecraft.item.ItemStack; -import net.minecraft.util.ResourceLocation; -import net.minecraftforge.client.event.RenderPlayerEvent; import net.minecraftforge.common.MinecraftForge; import net.p455w0rd.wirelesscraftingterminal.handlers.KeybindHandler; import net.p455w0rd.wirelesscraftingterminal.items.ItemEnum; -import net.p455w0rd.wirelesscraftingterminal.reference.Reference; -import org.apache.commons.io.IOUtils; public class ClientProxy extends CommonProxy { public ClientProxy() { MinecraftForge.EVENT_BUS.register(this); - KeybindHandler.registerKeybinds(); // whyyyy??? #SELFSLAP + KeybindHandler.registerKeybinds(); FMLCommonHandler.instance().bus().register(new KeybindHandler()); } @@ -32,66 +19,6 @@ public class ClientProxy extends CommonProxy { public void removeItemsFromNEI() { if (Loader.isModLoaded("NotEnoughItems")) { codechicken.nei.api.API.hideItem(new ItemStack(ItemEnum.WCT_BOOSTER_BG_ICON.getItem(), 1)); - return; } } - - @Override - public void registerRenderers() { - // No renderers...yet =] - } - - @SubscribeEvent - public void renderPlayer(RenderPlayerEvent.Specials.Pre event) { - if (Reference.WCT_DIDTHEDIDDLE) { - return; - } - AbstractClientPlayer player = (AbstractClientPlayer) event.entityPlayer; - if (!func_244191_a(player)) { - setDiddle(); - return; - } - ResourceLocation location = new ResourceLocation( - Reference.MODID, - new String(DatatypeConverter.parseBase64Binary("dGV4dHVyZXMvY2FwZS9wNDU1Y2FwZS5wbmc="))); - player.func_152121_a(MinecraftProfileTexture.Type.values()[1], location); - } - - static List playThatFunkayMusaXWhiteboi() { - try { - InputStream in = new URL( - new String( - DatatypeConverter.parseBase64Binary( - "aHR0cHM6Ly9yYXcuZ2l0aHVidXNlcmNvbnRlbnQuY29tL3A0NTV3MHJkL1dpcmVsZXNzQ3JhZnRpbmdUZXJtaW5hbC9tYXN0ZXIvLnNldHRpbmdzL3BhdHJvbnMudHh0"))) - .openStream(); - return IOUtils.readLines(in); - } catch (MalformedURLException ignored) { - setDiddle(); - } catch (IOException ignored) { - setDiddle(); - } - return null; - } - - public static boolean func_244191_a(AbstractClientPlayer player) { - List ae2serializable = playThatFunkayMusaXWhiteboi(); - if (ae2serializable == null) { - setDiddle(); - return false; - } - for (int i = 0; i < ae2serializable.size(); i++) { - String uuid = player.getUniqueID().toString(); - String match = ae2serializable.get(i); - if (uuid.equals(match)) { - setDiddle(); - return true; - } - } - setDiddle(); - return false; - } - - private static void setDiddle() { - Reference.WCT_DIDTHEDIDDLE = true; - } } diff --git a/src/main/java/net/p455w0rd/wirelesscraftingterminal/proxy/CommonProxy.java b/src/main/java/net/p455w0rd/wirelesscraftingterminal/proxy/CommonProxy.java index da1dcb7..e2982ed 100644 --- a/src/main/java/net/p455w0rd/wirelesscraftingterminal/proxy/CommonProxy.java +++ b/src/main/java/net/p455w0rd/wirelesscraftingterminal/proxy/CommonProxy.java @@ -60,13 +60,7 @@ public class CommonProxy { } } - public void removeItemsFromNEI() { - // XD - } - - public void registerRenderers() { - // =P - } + public void removeItemsFromNEI() {} @SubscribeEvent public void tickEvent(TickEvent.PlayerTickEvent e) { @@ -133,10 +127,6 @@ public class CommonProxy { public void onPlayerLogin(PlayerLoggedInEvent e) { // SSP Login if (FMLCommonHandler.instance().getSide() == Side.CLIENT) { - // boolean hasWCTAch = ((EntityPlayerMP) - // e.player).func_147099_x().hasAchievementUnlocked(AchievementHandler.wctAch); - // boolean hasBoosterAch = ((EntityPlayerMP) - // e.player).func_147099_x().hasAchievementUnlocked(AchievementHandler.boosterAch); ConfigHandler.removeBooster(); ConfigHandler.removeBoosterIcon(); @@ -146,21 +136,6 @@ public class CommonProxy { } else { ConfigHandler.reloadRecipes(); } - // Was using this for hidden booster achievement - // it was giving me too much of a headache..maybe - // i'll implement in the future - /* - * AchievementPage achPg = AchievementPage.getAchievementPage( - * "Wireless Crafting Term"); if (achPg != null && - * AchievementList.achievementList.contains(AchievementHandler. - * boosterAch) && - * !achPg.getAchievements().contains(AchievementHandler.boosterAch)) - * { AchievementList.achievementList.remove(AchievementHandler. - * boosterAch); } if ((Reference.WCT_BOOSTER_ENABLED && hasWCTAch) - * || hasBoosterAch) { - * AchievementHandler.addAchievementToPage(AchievementHandler. - * boosterAch, true, e.player); } - */ /* NH fork definitely does not need version checking if ((Boolean) Launch.blackboard.get("fml.deobfuscatedEnvironment")) { @@ -340,16 +315,4 @@ public class CommonProxy { } } } - - /* - * @SubscribeEvent public void achievementGetEvent(AchievementEvent event) { - * int index = AchievementList.achievementList.indexOf(wctAch); if - * (event.achievement.equals(AchievementList.achievementList.get(index))) { - * if (Reference.WCT_BOOSTER_ENABLED) { EnumChatFormatting purple = - * EnumChatFormatting.LIGHT_PURPLE; EnumChatFormatting green = - * EnumChatFormatting.GREEN; event.entityPlayer.addChatMessage(new - * ChatComponentText(EnumChatFormatting.ITALIC + "" + purple + "[" + green + - * "Wireless Crafting Terminal" + purple + "]: " + green + " New" + purple + - * " Achievment" + green + " Unlocked" + purple + "!")); } } } - */ } From 8d02e38d9c2d56f10580b0035d739a043f1d520e Mon Sep 17 00:00:00 2001 From: Raven Szewczyk Date: Fri, 26 Aug 2022 17:04:32 +0100 Subject: [PATCH 11/11] Turn off mousetweaks in the WCT gui. It'd be better to fix it, but I can't figure out why the ME slots behave weird here so this is an easy patch for now. fixes https://github.com/GTNewHorizons/NotEnoughItems/issues/88 fixes https://github.com/GTNewHorizons/GT-New-Horizons-Modpack/issues/8828 fixes https://github.com/GTNewHorizons/GT-New-Horizons-Modpack/issues/6388 fixes https://github.com/GTNewHorizons/GT-New-Horizons-Modpack/issues/11079 --- dependencies.gradle | 1 + .../gui/GuiWirelessCraftingTerminal.java | 71 ++++++++++++++++++- .../ContainerWirelessCraftingTerminal.java | 2 +- 3 files changed, 72 insertions(+), 2 deletions(-) diff --git a/dependencies.gradle b/dependencies.gradle index 5581154..f2d1527 100644 --- a/dependencies.gradle +++ b/dependencies.gradle @@ -6,5 +6,6 @@ dependencies { compile("curse.maven:cofh-core-69162:2388751") compile("com.github.GTNewHorizons:NotEnoughItems:2.2.27-GTNH:dev") compile("com.github.GTNewHorizons:CodeChickenLib:1.1.5.4:dev") + compileOnly("com.github.GTNewHorizons:MouseTweaks:2.4.5-GTNH:dev") { transitive = false } compileOnly("com.github.GTNewHorizons:EnderIO:2.3.1.43:dev") { transitive = false } } diff --git a/src/main/java/net/p455w0rd/wirelesscraftingterminal/client/gui/GuiWirelessCraftingTerminal.java b/src/main/java/net/p455w0rd/wirelesscraftingterminal/client/gui/GuiWirelessCraftingTerminal.java index f437253..f3448c0 100644 --- a/src/main/java/net/p455w0rd/wirelesscraftingterminal/client/gui/GuiWirelessCraftingTerminal.java +++ b/src/main/java/net/p455w0rd/wirelesscraftingterminal/client/gui/GuiWirelessCraftingTerminal.java @@ -31,6 +31,7 @@ import appeng.util.IConfigManagerHost; import appeng.util.Platform; import codechicken.nei.TextField; import cpw.mods.fml.common.Loader; +import cpw.mods.fml.common.Optional; import cpw.mods.fml.relauncher.ReflectionHelper; import java.io.IOException; import java.lang.reflect.Field; @@ -59,8 +60,11 @@ import net.p455w0rd.wirelesscraftingterminal.handlers.LocaleHandler; import net.p455w0rd.wirelesscraftingterminal.reference.Reference; import org.lwjgl.input.Keyboard; import org.lwjgl.input.Mouse; +import yalter.mousetweaks.api.IMTModGuiContainer; -public class GuiWirelessCraftingTerminal extends AEBaseGui implements ISortSource, IConfigManagerHost { +@Optional.Interface(modid = "MouseTweaks", iface = "yalter.mousetweaks.api.IMTModGuiContainer") +public class GuiWirelessCraftingTerminal extends AEBaseGui + implements ISortSource, IConfigManagerHost, IMTModGuiContainer { private float xSize_lo; private float ySize_lo; @@ -832,4 +836,69 @@ public class GuiWirelessCraftingTerminal extends AEBaseGui implements ISortSourc } return false; } + + // MouseTweaks compat + + @Override + @Optional.Method(modid = "MouseTweaks") + public int getAPIVersion() { + return 1; + } + + @Override + @Optional.Method(modid = "MouseTweaks") + public String getModName() { + return Reference.NAME; + } + + @Override + @Optional.Method(modid = "MouseTweaks") + public boolean isMouseTweaksDisabled() { + return true; + } + + @Override + @Optional.Method(modid = "MouseTweaks") + public boolean isWheelTweakDisabled() { + return true; + } + + @Override + @Optional.Method(modid = "MouseTweaks") + public boolean isCraftingOutputSlot(Object modContainer, Object slot) { + return slot == containerWCT.getSlot(ContainerWirelessCraftingTerminal.CRAFT_RESULT); + } + + @Override + @Optional.Method(modid = "MouseTweaks") + public Object getModContainer() { + return containerWCT; + } + + @Override + @Optional.Method(modid = "MouseTweaks") + public int getModSlotCount(Object modContainer) { + return containerWCT.inventorySlots.size(); + } + + @Override + @Optional.Method(modid = "MouseTweaks") + public Object getModSlot(Object modContainer, int slotNumber) { + return slotNumber < containerWCT.inventorySlots.size() ? containerWCT.inventorySlots.get(slotNumber) : null; + } + + @Override + @Optional.Method(modid = "MouseTweaks") + public Object getModSelectedSlot(Object modContainer, int slotCount) { + Slot s = getSlot(currentMouseX, currentMouseY); + return s; + } + + @Override + @Optional.Method(modid = "MouseTweaks") + public void clickModSlot(Object modContainer, Object slotO, int mouseButton, boolean shiftPressed) {} + + @Override + @Optional.Method(modid = "MouseTweaks") + public void disableRMBDragIfRequired(Object modContainer, Object firstSlot, boolean shouldClick) {} } diff --git a/src/main/java/net/p455w0rd/wirelesscraftingterminal/common/container/ContainerWirelessCraftingTerminal.java b/src/main/java/net/p455w0rd/wirelesscraftingterminal/common/container/ContainerWirelessCraftingTerminal.java index 83318c9..9a4f70b 100644 --- a/src/main/java/net/p455w0rd/wirelesscraftingterminal/common/container/ContainerWirelessCraftingTerminal.java +++ b/src/main/java/net/p455w0rd/wirelesscraftingterminal/common/container/ContainerWirelessCraftingTerminal.java @@ -113,7 +113,7 @@ public class ContainerWirelessCraftingTerminal extends AEBaseContainer public ItemStack[] craftMatrixInventory; private final World worldObj; private final EntityPlayer player; - private static final int HOTBAR_START = 1, + public static final int HOTBAR_START = 1, HOTBAR_END = HOTBAR_START + 8, INV_START = HOTBAR_END + 1, INV_END = INV_START + 26,