mirror of
https://github.com/GTNewHorizons/CodeChickenCore.git
synced 2026-11-11 15:57:42 +00:00
remove @InterfaceDependancyTransformer (#8)
* remove @InterfaceDependancyTransformer This is no longer used, and I want less class transformer in the LaunchClassLoader * apply spotless
This commit is contained in:
1 parent
cef8a9cbc0
commit
818b13551b
63 files changed
+2011
-2354
No files matched your search
@@ -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
|
||||
+347
-117
@@ -1,26 +1,36 @@
|
||||
//version: 1644894948
|
||||
//version: 1661114848
|
||||
/*
|
||||
DO NOT CHANGE THIS FILE!
|
||||
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.
|
||||
*/
|
||||
|
||||
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 org.gradle.internal.logging.text.StyledTextOutput
|
||||
import org.gradle.internal.logging.text.StyledTextOutputFactory
|
||||
import org.gradle.internal.logging.text.StyledTextOutput.Style
|
||||
|
||||
import com.github.jengelman.gradle.plugins.shadow.tasks.ConfigureShadowRelocation
|
||||
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
|
||||
import org.gradle.internal.logging.text.StyledTextOutput.Style
|
||||
import org.gradle.internal.logging.text.StyledTextOutputFactory
|
||||
|
||||
import java.nio.file.Files
|
||||
import java.nio.file.Paths
|
||||
import java.util.concurrent.TimeUnit
|
||||
import java.util.zip.ZipEntry
|
||||
import java.util.zip.ZipInputStream
|
||||
import java.util.zip.ZipOutputStream
|
||||
|
||||
buildscript {
|
||||
repositories {
|
||||
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/'
|
||||
@@ -29,30 +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 '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.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'
|
||||
@@ -78,7 +95,14 @@ idea {
|
||||
}
|
||||
}
|
||||
|
||||
if(JavaVersion.current() != JavaVersion.VERSION_1_8) {
|
||||
boolean disableSpotless = project.hasProperty("disableSpotless") ? project.disableSpotless.toBoolean() : false
|
||||
|
||||
if (!disableSpotless) {
|
||||
apply plugin: 'com.diffplug.spotless'
|
||||
apply from: Blowdryer.file('spotless.gradle')
|
||||
}
|
||||
|
||||
if (JavaVersion.current() != JavaVersion.VERSION_1_8) {
|
||||
throw new GradleException("This project requires Java 8, but it's running on " + JavaVersion.current())
|
||||
}
|
||||
|
||||
@@ -103,8 +127,11 @@ checkPropertyExists("containsMixinsAndOrCoreModOnly")
|
||||
checkPropertyExists("usesShadowedDependencies")
|
||||
checkPropertyExists("developmentEnvironmentUserName")
|
||||
|
||||
boolean noPublishedSources = project.findProperty("noPublishedSources") ? project.noPublishedSources.toBoolean() : false
|
||||
|
||||
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/"
|
||||
@@ -112,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)
|
||||
}
|
||||
}
|
||||
@@ -188,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'
|
||||
@@ -199,28 +226,31 @@ 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"
|
||||
]
|
||||
jvmArguments += [
|
||||
"-Dmixin.debug.countInjections=true", "-Dmixin.debug.verbose=true", "-Dmixin.debug.export=true"
|
||||
"--tweakClass org.spongepowered.asm.launch.MixinTweaker"
|
||||
]
|
||||
if (usesMixinDebug.toBoolean()) {
|
||||
jvmArguments += [
|
||||
"-Dmixin.debug.countInjections=true",
|
||||
"-Dmixin.debug.verbose=true",
|
||||
"-Dmixin.debug.export=true"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
minecraft {
|
||||
@@ -229,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
|
||||
}
|
||||
}
|
||||
@@ -247,7 +277,7 @@ minecraft {
|
||||
args(arguments)
|
||||
jvmArgs(jvmArguments)
|
||||
|
||||
if(developmentEnvironmentUserName) {
|
||||
if (developmentEnvironmentUserName) {
|
||||
args("--username", developmentEnvironmentUserName)
|
||||
}
|
||||
}
|
||||
@@ -258,7 +288,7 @@ minecraft {
|
||||
}
|
||||
}
|
||||
|
||||
if(file('addon.gradle').exists()) {
|
||||
if (file('addon.gradle').exists()) {
|
||||
apply from: 'addon.gradle'
|
||||
}
|
||||
|
||||
@@ -275,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'
|
||||
@@ -287,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
|
||||
@@ -312,18 +344,23 @@ def refMap = "${tasks.compileJava.temporaryDir}" + File.separator + mixingConfig
|
||||
def mixinSrg = "${tasks.reobf.temporaryDir}" + File.separator + "mixins.srg"
|
||||
|
||||
task generateAssets {
|
||||
if(usesMixins.toBoolean()) {
|
||||
getFile("/src/main/resources/mixins." + modId + ".json").text = """{
|
||||
if (usesMixins.toBoolean()) {
|
||||
def mixinConfigFile = getFile("/src/main/resources/mixins." + modId + ".json");
|
||||
if (!mixinConfigFile.exists()) {
|
||||
mixinConfigFile.text = """{
|
||||
"required": true,
|
||||
"minVersion": "0.7.11",
|
||||
"package": "${modGroup}.${mixinsPackage}",
|
||||
"plugin": "${modGroup}.${mixinPlugin}",
|
||||
"refmap": "${mixingConfigRefMap}",
|
||||
"target": "@env(DEFAULT)",
|
||||
"compatibilityLevel": "JAVA_8"
|
||||
"compatibilityLevel": "JAVA_8",
|
||||
"mixins": [],
|
||||
"client": [],
|
||||
"server": []
|
||||
}
|
||||
|
||||
"""
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -344,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)
|
||||
}
|
||||
|
||||
@@ -359,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
|
||||
]
|
||||
}
|
||||
|
||||
@@ -405,9 +445,9 @@ runServer {
|
||||
|
||||
tasks.withType(JavaExec).configureEach {
|
||||
javaLauncher.set(
|
||||
javaToolchains.launcherFor {
|
||||
languageVersion = projectJavaVersion
|
||||
}
|
||||
javaToolchains.launcherFor {
|
||||
languageVersion = projectJavaVersion
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
@@ -415,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) {
|
||||
@@ -427,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.allJava)
|
||||
from (file("$projectDir/LICENSE"))
|
||||
from(sourceSets.main.allSource)
|
||||
from(file("$projectDir/LICENSE"))
|
||||
getArchiveClassifier().set('sources')
|
||||
}
|
||||
|
||||
@@ -482,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) {
|
||||
@@ -510,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.allJava) {
|
||||
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")
|
||||
}
|
||||
|
||||
@@ -533,11 +578,11 @@ task apiJar(type: Jar) {
|
||||
}
|
||||
|
||||
artifacts {
|
||||
if(!noPublishedSources) {
|
||||
if (!noPublishedSources) {
|
||||
archives sourcesJar
|
||||
}
|
||||
archives devJar
|
||||
if(apiPackage) {
|
||||
if (apiPackage) {
|
||||
archives apiJar
|
||||
}
|
||||
}
|
||||
@@ -555,11 +600,11 @@ publishing {
|
||||
publications {
|
||||
maven(MavenPublication) {
|
||||
from components.java
|
||||
if(usesShadowedDependencies.toBoolean()) {
|
||||
if (usesShadowedDependencies.toBoolean()) {
|
||||
artifact source: shadowJar, classifier: ""
|
||||
}
|
||||
if(!noPublishedSources) {
|
||||
artifact source: sourcesJar, classifier: "src"
|
||||
if (!noPublishedSources) {
|
||||
artifact source: sourcesJar, classifier: "sources"
|
||||
}
|
||||
artifact source: usesShadowedDependencies.toBoolean() ? shadowDevJar : devJar, classifier: "dev"
|
||||
if (apiPackage) {
|
||||
@@ -573,8 +618,11 @@ publishing {
|
||||
|
||||
// remove extra garbage from minecraft and minecraftDeps configuration
|
||||
pom.withXml {
|
||||
def badArtifacts = [:].withDefault {[] as Set<String>}
|
||||
for (configuration in [projectConfigs.minecraft, projectConfigs.minecraftDeps]) {
|
||||
def badArtifacts = [:].withDefault { [] as Set<String> }
|
||||
for (configuration in [
|
||||
projectConfigs.minecraft,
|
||||
projectConfigs.minecraftDeps
|
||||
]) {
|
||||
for (dependency in configuration.allDependencies) {
|
||||
badArtifacts[dependency.group == null ? "" : dependency.group] += dependency.name
|
||||
}
|
||||
@@ -612,7 +660,7 @@ task updateBuildScript {
|
||||
}
|
||||
}
|
||||
|
||||
if (isNewBuildScriptVersionAvailable(projectDir.toString())) {
|
||||
if (!project.getGradle().startParameter.isOffline() && isNewBuildScriptVersionAvailable(projectDir.toString())) {
|
||||
if (autoUpdateBuildScript.toBoolean()) {
|
||||
performBuildScriptUpdate(projectDir.toString())
|
||||
} else {
|
||||
@@ -621,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) {
|
||||
@@ -629,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
|
||||
@@ -648,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 ""
|
||||
@@ -659,7 +744,103 @@ configure(updateBuildScript) {
|
||||
description = 'Updates the build script to the latest version'
|
||||
}
|
||||
|
||||
// Deobfuscation
|
||||
// Parameter Deobfuscation
|
||||
|
||||
task deobfParams {
|
||||
doLast {
|
||||
|
||||
String mcpDir = "$project.gradle.gradleUserHomeDir/caches/minecraft/de/oceanlabs/mcp/mcp_$channel/$mappingsVersion"
|
||||
String mcpZIP = "$mcpDir/mcp_$channel-$mappingsVersion-${minecraftVersion}.zip"
|
||||
String paramsCSV = "$mcpDir/params.csv"
|
||||
|
||||
download.run {
|
||||
src "https://maven.minecraftforge.net/de/oceanlabs/mcp/mcp_$channel/$mappingsVersion-$minecraftVersion/mcp_$channel-$mappingsVersion-${minecraftVersion}.zip"
|
||||
dest mcpZIP
|
||||
overwrite false
|
||||
}
|
||||
|
||||
if (!file(paramsCSV).exists()) {
|
||||
println("Extracting MCP archive ...")
|
||||
unzip(mcpZIP, mcpDir)
|
||||
}
|
||||
|
||||
println("Parsing params.csv ...")
|
||||
Map<String, String> params = new HashMap<>()
|
||||
Files.lines(Paths.get(paramsCSV)).forEach { line ->
|
||||
String[] cells = line.split(",")
|
||||
if (cells.length > 2 && cells[0].matches("p_i?\\d+_\\d+_")) {
|
||||
params.put(cells[0], cells[1])
|
||||
}
|
||||
}
|
||||
|
||||
out.style(Style.Success).println("Modified ${replaceParams(file("$projectDir/src/main/java"), params)} files!")
|
||||
out.style(Style.Failure).println("Don't forget to verify that the code still works as before!\n It could be broken due to duplicate variables existing now\n or parameters taking priority over other variables.")
|
||||
}
|
||||
}
|
||||
|
||||
static int replaceParams(File file, Map<String, String> params) {
|
||||
int fileCount = 0
|
||||
|
||||
if (file.isDirectory()) {
|
||||
for (File f : file.listFiles()) {
|
||||
fileCount += replaceParams(f, params)
|
||||
}
|
||||
return fileCount
|
||||
}
|
||||
println("Visiting ${file.getName()} ...")
|
||||
try {
|
||||
String content = new String(Files.readAllBytes(file.toPath()))
|
||||
int hash = content.hashCode()
|
||||
params.forEach { key, value ->
|
||||
content = content.replaceAll(key, value)
|
||||
}
|
||||
if (hash != content.hashCode()) {
|
||||
Files.write(file.toPath(), content.getBytes("UTF-8"))
|
||||
return 1
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
// Credit: bitsnaps (https://gist.github.com/bitsnaps/00947f2dce66f4bbdabc67d7e7b33681)
|
||||
static unzip(String zipFileName, String outputDir) {
|
||||
byte[] buffer = new byte[16384]
|
||||
ZipInputStream zis = new ZipInputStream(new FileInputStream(zipFileName))
|
||||
ZipEntry zipEntry = zis.getNextEntry()
|
||||
while (zipEntry != null) {
|
||||
File newFile = new File(outputDir + File.separator, zipEntry.name)
|
||||
if (zipEntry.isDirectory()) {
|
||||
if (!newFile.isDirectory() && !newFile.mkdirs()) {
|
||||
throw new IOException("Failed to create directory $newFile")
|
||||
}
|
||||
} else {
|
||||
// fix for Windows-created archives
|
||||
File parent = newFile.parentFile
|
||||
if (!parent.isDirectory() && !parent.mkdirs()) {
|
||||
throw new IOException("Failed to create directory $parent")
|
||||
}
|
||||
// write file content
|
||||
FileOutputStream fos = new FileOutputStream(newFile)
|
||||
int len = 0
|
||||
while ((len = zis.read(buffer)) > 0) {
|
||||
fos.write(buffer, 0, len)
|
||||
}
|
||||
fos.close()
|
||||
}
|
||||
zipEntry = zis.getNextEntry()
|
||||
}
|
||||
zis.closeEntry()
|
||||
zis.close()
|
||||
}
|
||||
|
||||
configure(deobfParams) {
|
||||
group = 'forgegradle'
|
||||
description = 'Rename all obfuscated parameter names inherited from Minecraft classes'
|
||||
}
|
||||
|
||||
// Dependency Deobfuscation
|
||||
|
||||
def deobf(String sourceURL) {
|
||||
try {
|
||||
@@ -668,42 +849,57 @@ 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")) {
|
||||
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("\\."))
|
||||
Collections.reverse(parts)
|
||||
hostName = String.join(".", parts)
|
||||
|
||||
return deobf(sourceURL, hostName + "/" + fileName)
|
||||
} catch(Exception e) {
|
||||
return deobf(sourceURL, "deobf/" + String.valueOf(sourceURL.hashCode()))
|
||||
return deobf(sourceURL, "$hostName/$fileName")
|
||||
} catch (Exception e) {
|
||||
return deobf(sourceURL, "deobf/${sourceURL.hashCode()}")
|
||||
}
|
||||
}
|
||||
|
||||
// The method above is to be preferred. Use this method if the filename is not at the end of the URL.
|
||||
def deobf(String sourceURL, String fileName) {
|
||||
String cacheDir = System.getProperty("user.home") + "/.gradle/caches/"
|
||||
String bon2Dir = cacheDir + "forge_gradle/deobf"
|
||||
String bon2File = bon2Dir + "/BON2-2.5.0.jar"
|
||||
String obfFile = cacheDir + "modules-2/files-2.1/" + fileName + ".jar"
|
||||
String deobfFile = cacheDir + "modules-2/files-2.1/" + fileName + "-deobf.jar"
|
||||
def deobf(String sourceURL, String rawFileName) {
|
||||
String bon2Version = "2.5.1"
|
||||
String fileName = URLDecoder.decode(rawFileName, "UTF-8")
|
||||
String cacheDir = "$project.gradle.gradleUserHomeDir/caches"
|
||||
String bon2Dir = "$cacheDir/forge_gradle/deobf"
|
||||
String bon2File = "$bon2Dir/BON2-${bon2Version}.jar"
|
||||
String obfFile = "$cacheDir/modules-2/files-2.1/${fileName}.jar"
|
||||
String deobfFile = "$cacheDir/modules-2/files-2.1/${fileName}-deobf.jar"
|
||||
|
||||
if(file(deobfFile).exists()) {
|
||||
if (file(deobfFile).exists()) {
|
||||
return files(deobfFile)
|
||||
}
|
||||
|
||||
String mappingsVer
|
||||
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"
|
||||
|
||||
zipMappings(mappingsZIP, remoteMappings, bon2Dir)
|
||||
|
||||
mappingsVer = "snapshot_$id"
|
||||
} else {
|
||||
mappingsVer = "${channel}_$mappingsVersion"
|
||||
}
|
||||
|
||||
download.run {
|
||||
src 'https://github.com/GTNewHorizons/BON2/releases/download/2.5.0/BON2-2.5.0.CUSTOM-all.jar'
|
||||
src "http://jenkins.usrv.eu:8081/nexus/content/repositories/releases/com/github/parker8283/BON2/$bon2Version-CUSTOM/BON2-$bon2Version-CUSTOM-all.jar"
|
||||
dest bon2File
|
||||
quiet true
|
||||
overwrite false
|
||||
@@ -717,14 +913,48 @@ def deobf(String sourceURL, String fileName) {
|
||||
}
|
||||
|
||||
exec {
|
||||
commandLine 'java', '-jar', bon2File, '--inputJar', obfFile, '--outputJar', deobfFile, '--mcVer', '1.7.10', '--mappingsVer', 'stable_12', '--notch'
|
||||
commandLine 'java', '-jar', bon2File, '--inputJar', obfFile, '--outputJar', deobfFile, '--mcVer', minecraftVersion, '--mappingsVer', mappingsVer, '--notch'
|
||||
workingDir bon2Dir
|
||||
standardOutput = new ByteArrayOutputStream()
|
||||
standardOutput = new FileOutputStream("${deobfFile}.log")
|
||||
}
|
||||
|
||||
return files(deobfFile)
|
||||
}
|
||||
|
||||
def zipMappings(String zipPath, String url, String bon2Dir) {
|
||||
File zipFile = new File(zipPath)
|
||||
if (zipFile.exists()) {
|
||||
return
|
||||
}
|
||||
|
||||
String fieldsCache = "$bon2Dir/data/fields.csv"
|
||||
String methodsCache = "$bon2Dir/data/methods.csv"
|
||||
|
||||
download.run {
|
||||
src "${url}fields.csv"
|
||||
dest fieldsCache
|
||||
quiet true
|
||||
}
|
||||
download.run {
|
||||
src "${url}methods.csv"
|
||||
dest methodsCache
|
||||
quiet true
|
||||
}
|
||||
|
||||
zipFile.getParentFile().mkdirs()
|
||||
ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(zipFile))
|
||||
|
||||
zos.putNextEntry(new ZipEntry("fields.csv"))
|
||||
Files.copy(Paths.get(fieldsCache), zos)
|
||||
zos.closeEntry()
|
||||
|
||||
zos.putNextEntry(new ZipEntry("methods.csv"))
|
||||
Files.copy(Paths.get(methodsCache), zos)
|
||||
zos.closeEntry()
|
||||
|
||||
zos.close()
|
||||
}
|
||||
|
||||
// Helper methods
|
||||
|
||||
def checkPropertyExists(String propertyName) {
|
||||
|
||||
@@ -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
|
||||
}
|
||||
@@ -1,5 +1,10 @@
|
||||
package codechicken.core;
|
||||
|
||||
import codechicken.core.launch.CodeChickenCorePlugin;
|
||||
import com.google.common.base.Function;
|
||||
import cpw.mods.fml.common.Loader;
|
||||
import cpw.mods.fml.common.versioning.ComparableVersion;
|
||||
import cpw.mods.fml.relauncher.FMLInjectionData;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
@@ -9,23 +14,14 @@ import java.net.SocketTimeoutException;
|
||||
import java.net.URL;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import codechicken.core.launch.CodeChickenCorePlugin;
|
||||
import com.google.common.base.Function;
|
||||
import cpw.mods.fml.common.Loader;
|
||||
import cpw.mods.fml.common.versioning.ComparableVersion;
|
||||
import cpw.mods.fml.relauncher.FMLInjectionData;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.util.ChatComponentText;
|
||||
import net.minecraft.util.StatCollector;
|
||||
|
||||
public class CCUpdateChecker
|
||||
{
|
||||
public class CCUpdateChecker {
|
||||
private static final ArrayList<String> updates = new ArrayList<String>();
|
||||
|
||||
private static class ThreadUpdateCheck extends Thread
|
||||
{
|
||||
private static class ThreadUpdateCheck extends Thread {
|
||||
private final URL url;
|
||||
private final Function<String, Void> handler;
|
||||
|
||||
@@ -46,11 +42,11 @@ public class CCUpdateChecker
|
||||
BufferedReader read = new BufferedReader(new InputStreamReader(conn.getInputStream()));
|
||||
String ret = read.readLine();
|
||||
read.close();
|
||||
if(ret == null) ret = "";
|
||||
if (ret == null) ret = "";
|
||||
handler.apply(ret);
|
||||
} catch (SocketTimeoutException ignored) {}
|
||||
catch (UnknownHostException ignored) {}
|
||||
catch (IOException iox) {
|
||||
} catch (SocketTimeoutException ignored) {
|
||||
} catch (UnknownHostException ignored) {
|
||||
} catch (IOException iox) {
|
||||
iox.printStackTrace();
|
||||
}
|
||||
}
|
||||
@@ -58,12 +54,10 @@ public class CCUpdateChecker
|
||||
|
||||
public static void tick() {
|
||||
Minecraft mc = Minecraft.getMinecraft();
|
||||
if (!mc.inGameHasFocus)
|
||||
return;
|
||||
if (!mc.inGameHasFocus) return;
|
||||
|
||||
synchronized (updates) {
|
||||
for (String s : updates)
|
||||
mc.thePlayer.addChatMessage(new ChatComponentText(s));
|
||||
for (String s : updates) mc.thePlayer.addChatMessage(new ChatComponentText(s));
|
||||
updates.clear();
|
||||
}
|
||||
}
|
||||
@@ -79,19 +73,22 @@ public class CCUpdateChecker
|
||||
}
|
||||
|
||||
public static void updateCheck(final String mod, final String version) {
|
||||
updateCheck("http://www.chickenbones.net/Files/notification/version.php?" +
|
||||
"version=" + mcVersion() + "&" +
|
||||
"file=" + mod,
|
||||
new Function<String, Void>()
|
||||
{
|
||||
@Override public Void apply(String ret) {
|
||||
updateCheck(
|
||||
"http://www.chickenbones.net/Files/notification/version.php?" + "version="
|
||||
+ mcVersion() + "&" + "file="
|
||||
+ mod,
|
||||
new Function<String, Void>() {
|
||||
@Override
|
||||
public Void apply(String ret) {
|
||||
if (!ret.startsWith("Ret: ")) {
|
||||
CodeChickenCorePlugin.logger.error("Failed to check update for " + mod + " returned: " + ret);
|
||||
CodeChickenCorePlugin.logger.error(
|
||||
"Failed to check update for " + mod + " returned: " + ret);
|
||||
return null;
|
||||
}
|
||||
ComparableVersion newversion = new ComparableVersion(ret.substring(5));
|
||||
if (newversion.compareTo(new ComparableVersion(version)) > 0)
|
||||
addUpdateMessage(StatCollector.translateToLocalFormatted("codechickencore.update", newversion, mod));
|
||||
addUpdateMessage(
|
||||
StatCollector.translateToLocalFormatted("codechickencore.update", newversion, mod));
|
||||
return null;
|
||||
}
|
||||
});
|
||||
@@ -105,7 +102,7 @@ public class CCUpdateChecker
|
||||
try {
|
||||
new ThreadUpdateCheck(new URL(url), handler).start();
|
||||
} catch (MalformedURLException e) {
|
||||
CodeChickenCorePlugin.logger.error("Malformed URL: "+url, e);
|
||||
CodeChickenCorePlugin.logger.error("Malformed URL: " + url, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,12 @@
|
||||
package codechicken.core;
|
||||
|
||||
import codechicken.core.launch.CodeChickenCorePlugin;
|
||||
import codechicken.lib.asm.ASMHelper;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import cpw.mods.fml.common.FMLLog;
|
||||
import cpw.mods.fml.common.Loader;
|
||||
import cpw.mods.fml.common.ModClassLoader;
|
||||
import cpw.mods.fml.relauncher.CoreModManager;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
@@ -8,22 +15,10 @@ import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipInputStream;
|
||||
|
||||
import net.minecraft.launchwrapper.Launch;
|
||||
import org.objectweb.asm.tree.ClassNode;
|
||||
|
||||
import codechicken.core.launch.CodeChickenCorePlugin;
|
||||
import codechicken.lib.asm.ASMHelper;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
|
||||
import cpw.mods.fml.common.FMLLog;
|
||||
import cpw.mods.fml.common.Loader;
|
||||
import cpw.mods.fml.common.ModClassLoader;
|
||||
import cpw.mods.fml.relauncher.CoreModManager;
|
||||
|
||||
public class ClassDiscoverer
|
||||
{
|
||||
public class ClassDiscoverer {
|
||||
public IStringMatcher matcher;
|
||||
public String[] superclasses;
|
||||
public ArrayList<Class<?>> classes;
|
||||
@@ -40,10 +35,13 @@ public class ClassDiscoverer
|
||||
}
|
||||
|
||||
public ClassDiscoverer(Class<?>... superclasses) {
|
||||
this(new IStringMatcher()
|
||||
{
|
||||
public boolean matches(String test) {return true;}
|
||||
}, superclasses);
|
||||
this(
|
||||
new IStringMatcher() {
|
||||
public boolean matches(String test) {
|
||||
return true;
|
||||
}
|
||||
},
|
||||
superclasses);
|
||||
}
|
||||
|
||||
public ArrayList<Class<?>> findClasses() {
|
||||
@@ -59,13 +57,11 @@ public class ClassDiscoverer
|
||||
try {
|
||||
String classname = resource.replace(".class", "").replace("\\", ".").replace("/", ".");
|
||||
byte[] bytes = Launch.classLoader.getClassBytes(classname);
|
||||
if (bytes == null)
|
||||
return;
|
||||
if (bytes == null) return;
|
||||
|
||||
ClassNode cnode = ASMHelper.createClassNode(bytes);
|
||||
for (String superclass : superclasses)
|
||||
if (!cnode.interfaces.contains(superclass) && !cnode.superName.equals(superclass))
|
||||
return;
|
||||
if (!cnode.interfaces.contains(superclass) && !cnode.superName.equals(superclass)) return;
|
||||
|
||||
addClass(classname);
|
||||
} catch (IOException e) {
|
||||
@@ -85,25 +81,30 @@ public class ClassDiscoverer
|
||||
private void findClasspathMods() {
|
||||
List<String> knownLibraries = ImmutableList.<String>builder()
|
||||
.addAll(modClassLoader.getDefaultLibraries())
|
||||
.addAll(CoreModManager.getLoadedCoremods()).build();
|
||||
.addAll(CoreModManager.getLoadedCoremods())
|
||||
.build();
|
||||
File[] minecraftSources = modClassLoader.getParentSources();
|
||||
HashSet<String> searchedSources = new HashSet<String>();
|
||||
for (File minecraftSource : minecraftSources) {
|
||||
if (searchedSources.contains(minecraftSource.getAbsolutePath()))
|
||||
continue;
|
||||
if (searchedSources.contains(minecraftSource.getAbsolutePath())) continue;
|
||||
searchedSources.add(minecraftSource.getAbsolutePath());
|
||||
|
||||
if (minecraftSource.isFile()) {
|
||||
if (!knownLibraries.contains(minecraftSource.getName())) {
|
||||
FMLLog.fine("Found a minecraft related file at %s, examining for codechicken classes", minecraftSource.getAbsolutePath());
|
||||
FMLLog.fine(
|
||||
"Found a minecraft related file at %s, examining for codechicken classes",
|
||||
minecraftSource.getAbsolutePath());
|
||||
try {
|
||||
readFromZipFile(minecraftSource);
|
||||
} catch (Exception e) {
|
||||
CodeChickenCorePlugin.logger.error("Failed to scan " + minecraftSource.getAbsolutePath() + ", the zip file is invalid", e);
|
||||
CodeChickenCorePlugin.logger.error(
|
||||
"Failed to scan " + minecraftSource.getAbsolutePath() + ", the zip file is invalid", e);
|
||||
}
|
||||
}
|
||||
} else if (minecraftSource.isDirectory()) {
|
||||
FMLLog.fine("Found a minecraft related directory at %s, examining for codechicken classes", minecraftSource.getAbsolutePath());
|
||||
FMLLog.fine(
|
||||
"Found a minecraft related directory at %s, examining for codechicken classes",
|
||||
minecraftSource.getAbsolutePath());
|
||||
readFromDirectory(minecraftSource, minecraftSource);
|
||||
}
|
||||
}
|
||||
@@ -123,8 +124,7 @@ public class ClassDiscoverer
|
||||
if (!zipentry.isDirectory() && matcher.matches(name)) {
|
||||
checkAddClass(fullname);
|
||||
}
|
||||
}
|
||||
while (true);
|
||||
} while (true);
|
||||
fileinputstream.close();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,12 +1,10 @@
|
||||
package codechicken.core;
|
||||
|
||||
import codechicken.core.internal.CCCEventHandler;
|
||||
|
||||
import cpw.mods.fml.common.FMLCommonHandler;
|
||||
import cpw.mods.fml.common.ModContainer;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
import net.minecraft.network.NetworkManager;
|
||||
@@ -14,8 +12,7 @@ import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.util.EnumChatFormatting;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class ClientUtils extends CommonUtils
|
||||
{
|
||||
public class ClientUtils extends CommonUtils {
|
||||
private static Minecraft mc() {
|
||||
return Minecraft.getMinecraft();
|
||||
}
|
||||
@@ -24,15 +21,14 @@ public class ClientUtils extends CommonUtils
|
||||
return mc().theWorld;
|
||||
}
|
||||
|
||||
public static boolean inWorld()//TODO unused
|
||||
{
|
||||
public static boolean inWorld() // TODO unused
|
||||
{
|
||||
return mc().getNetHandler() != null;
|
||||
}
|
||||
|
||||
public static void openSMPGui(int windowId, GuiScreen gui) {
|
||||
mc().displayGuiScreen(gui);
|
||||
if (windowId != 0)
|
||||
mc().thePlayer.openContainer.windowId = windowId;
|
||||
if (windowId != 0) mc().thePlayer.openContainer.windowId = windowId;
|
||||
}
|
||||
|
||||
public static float getRenderFrame() {
|
||||
@@ -63,7 +59,8 @@ public class ClientUtils extends CommonUtils
|
||||
|
||||
public static void enhanceSupportersList(Object mod) {
|
||||
ModContainer mc = FMLCommonHandler.instance().findContainerFor(mod);
|
||||
mc.getMetadata().description = mc.getMetadata().description.replace("Supporters:", EnumChatFormatting.AQUA+"Supporters:");
|
||||
mc.getMetadata().description =
|
||||
mc.getMetadata().description.replace("Supporters:", EnumChatFormatting.AQUA + "Supporters:");
|
||||
GuiModListScroll.register(mod);
|
||||
}
|
||||
}
|
||||
@@ -1,16 +1,14 @@
|
||||
package codechicken.core;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import cpw.mods.fml.common.FMLCommonHandler;
|
||||
import cpw.mods.fml.relauncher.FMLInjectionData;
|
||||
import java.io.File;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.EntityList;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.DimensionManager;
|
||||
|
||||
public class CommonUtils
|
||||
{
|
||||
public class CommonUtils {
|
||||
public static boolean isClient() {
|
||||
return FMLCommonHandler.instance().getSide().isClient();
|
||||
}
|
||||
@@ -37,14 +35,12 @@ public class CommonUtils
|
||||
}
|
||||
|
||||
public static String getRelativePath(File parent, File child) {
|
||||
if (parent.isFile() || !child.getPath().startsWith(parent.getPath()))
|
||||
return null;
|
||||
if (parent.isFile() || !child.getPath().startsWith(parent.getPath())) return null;
|
||||
|
||||
return child.getPath().substring(parent.getPath().length() + 1);
|
||||
}
|
||||
|
||||
public static void registerHandledEntity(Class<? extends Entity> entityClass, String identifier)
|
||||
{
|
||||
public static void registerHandledEntity(Class<? extends Entity> entityClass, String identifier) {
|
||||
EntityList.classToStringMapping.put(entityClass, identifier);
|
||||
EntityList.stringToClassMapping.put(identifier, entityClass);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
package codechicken.core;
|
||||
|
||||
import static org.lwjgl.opengl.GL11.*;
|
||||
import static org.lwjgl.opengl.GL11.glReadPixels;
|
||||
|
||||
import codechicken.core.launch.CodeChickenCorePlugin;
|
||||
import codechicken.lib.gui.GuiDraw;
|
||||
import codechicken.lib.vec.Rectangle4i;
|
||||
@@ -7,17 +10,6 @@ import cpw.mods.fml.client.GuiModList;
|
||||
import cpw.mods.fml.common.FMLCommonHandler;
|
||||
import cpw.mods.fml.common.ModContainer;
|
||||
import cpw.mods.fml.common.ModMetadata;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.client.MinecraftForgeClient;
|
||||
import org.lwjgl.BufferUtils;
|
||||
import org.lwjgl.input.Keyboard;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
|
||||
import static org.lwjgl.opengl.GL11.*;
|
||||
import static org.lwjgl.opengl.GL11.glReadPixels;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.File;
|
||||
@@ -25,9 +17,14 @@ import java.io.IOException;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import javax.imageio.ImageIO;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.client.MinecraftForgeClient;
|
||||
import org.lwjgl.BufferUtils;
|
||||
import org.lwjgl.input.Keyboard;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
public class GuiModListScroll
|
||||
{
|
||||
public class GuiModListScroll {
|
||||
private static List<ModContainer> scrollMods = new LinkedList<ModContainer>();
|
||||
|
||||
public static void register(Object mod) {
|
||||
@@ -37,8 +34,7 @@ public class GuiModListScroll
|
||||
private static void register(ModContainer mod) {
|
||||
if (MinecraftForgeClient.getStencilBits() == 0)
|
||||
CodeChickenCorePlugin.logger.error("Unable to do mod description scrolling due to lack of stencil buffer");
|
||||
else
|
||||
scrollMods.add(mod);
|
||||
else scrollMods.add(mod);
|
||||
}
|
||||
|
||||
private static void screenshotStencil(int x) {
|
||||
@@ -49,11 +45,11 @@ public class GuiModListScroll
|
||||
glPixelStorei(GL_PACK_ALIGNMENT, 1);
|
||||
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
|
||||
glReadPixels(0, 0, d.width, d.height, GL_STENCIL_INDEX, GL_UNSIGNED_BYTE, buf);
|
||||
for(int i = 0; i < d.width; i++)
|
||||
for(int j = 0; j < d.height; j++)
|
||||
img.setRGB(i, d.height-j-1, buf.get(j * d.width + i) == 0 ? 0 : 0xFFFFFF);
|
||||
for (int i = 0; i < d.width; i++)
|
||||
for (int j = 0; j < d.height; j++)
|
||||
img.setRGB(i, d.height - j - 1, buf.get(j * d.width + i) == 0 ? 0 : 0xFFFFFF);
|
||||
try {
|
||||
ImageIO.write(img, "png", new File("stencil"+x+".png"));
|
||||
ImageIO.write(img, "png", new File("stencil" + x + ".png"));
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@@ -63,36 +59,35 @@ public class GuiModListScroll
|
||||
private static double scroll;
|
||||
private static double lastFrameTime;
|
||||
private static double timeStart;
|
||||
|
||||
public static void draw(GuiModList gui, int mouseX, int mouseY) {
|
||||
ModContainer selectedMod = ReflectionManager.getField(GuiModList.class, ModContainer.class, gui, "selectedMod");
|
||||
if(selectedMod != lastMod) {
|
||||
if (selectedMod != lastMod) {
|
||||
lastMod = selectedMod;
|
||||
scroll = 0;
|
||||
timeStart = ClientUtils.getRenderTime();
|
||||
}
|
||||
if(!scrollMods.contains(selectedMod) || selectedMod.getMetadata().autogenerated)
|
||||
return;
|
||||
if (!scrollMods.contains(selectedMod) || selectedMod.getMetadata().autogenerated) return;
|
||||
|
||||
int y1 = calcDescY(gui, selectedMod);
|
||||
int y1draw = y1 + 10;
|
||||
int y2 = gui.height-38;
|
||||
int y2 = gui.height - 38;
|
||||
int x1 = ReflectionManager.getField(GuiModList.class, Integer.class, gui, "listWidth") + 20;
|
||||
int x2 = gui.width - 20;
|
||||
if(x2 - x1 <= 20)
|
||||
return;
|
||||
if (x2 - x1 <= 20) return;
|
||||
|
||||
glEnable(GL_STENCIL_TEST);
|
||||
glStencilFunc(GL_ALWAYS, 1, 1);
|
||||
glColorMask(false, false, false, false);
|
||||
glStencilOp(GL_ZERO, GL_ZERO, GL_ZERO);
|
||||
GuiDraw.drawRect(0, 0, gui.width, gui.height, -1);//clear stencil buffer
|
||||
GuiDraw.drawRect(0, 0, gui.width, gui.height, -1); // clear stencil buffer
|
||||
|
||||
screenshotStencil(1);
|
||||
|
||||
glStencilOp(GL_REPLACE, GL_REPLACE, GL_REPLACE);
|
||||
GuiDraw.drawRect(x1, y1, gui.width - x1, gui.height - y1, -1);//add description area (even below button)
|
||||
GuiDraw.drawRect(x1, y1, gui.width - x1, gui.height - y1, -1); // add description area (even below button)
|
||||
glStencilOp(GL_ZERO, GL_ZERO, GL_ZERO);
|
||||
GuiDraw.drawRect(gui.width / 2 - 75, y2, 200, 20, -1);//subtract done button
|
||||
GuiDraw.drawRect(gui.width / 2 - 75, y2, 200, 20, -1); // subtract done button
|
||||
|
||||
screenshotStencil(2);
|
||||
|
||||
@@ -100,13 +95,13 @@ public class GuiModListScroll
|
||||
glStencilFunc(GL_EQUAL, 1, 1);
|
||||
glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
|
||||
|
||||
gui.drawDefaultBackground();//fill stencil with background
|
||||
gui.drawDefaultBackground(); // fill stencil with background
|
||||
|
||||
glColorMask(false, false, false, false);
|
||||
glStencilOp(GL_ZERO, GL_ZERO, GL_ZERO);
|
||||
GuiDraw.drawRect(0, 0, gui.width, gui.height, -1);
|
||||
glStencilOp(GL_REPLACE, GL_REPLACE, GL_REPLACE);
|
||||
GuiDraw.drawRect(x1, y1draw, x2-x1, y2-y1draw, -1);
|
||||
GuiDraw.drawRect(x1, y1draw, x2 - x1, y2 - y1draw, -1);
|
||||
|
||||
screenshotStencil(3);
|
||||
|
||||
@@ -114,10 +109,13 @@ public class GuiModListScroll
|
||||
glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
|
||||
|
||||
String description = selectedMod.getMetadata().description;
|
||||
int height = GuiDraw.fontRenderer.listFormattedStringToWidth(description, x2-x1).size()*GuiDraw.fontRenderer.FONT_HEIGHT;
|
||||
int height = GuiDraw.fontRenderer
|
||||
.listFormattedStringToWidth(description, x2 - x1)
|
||||
.size()
|
||||
* GuiDraw.fontRenderer.FONT_HEIGHT;
|
||||
|
||||
boolean needsScroll = height > y2-y1draw;
|
||||
if((ClientUtils.getRenderTime() - timeStart) > 40 && needsScroll) {
|
||||
boolean needsScroll = height > y2 - y1draw;
|
||||
if ((ClientUtils.getRenderTime() - timeStart) > 40 && needsScroll) {
|
||||
double dt = ClientUtils.getRenderTime() - lastFrameTime;
|
||||
if (new Rectangle4i(x1, y1draw, x2 - x1, y2 - y1draw).contains(mouseX, mouseY)) {
|
||||
double d = Keyboard.isKeyDown(Keyboard.KEY_UP) ? -1 : Keyboard.isKeyDown(Keyboard.KEY_DOWN) ? 1 : 0;
|
||||
@@ -128,16 +126,16 @@ public class GuiModListScroll
|
||||
}
|
||||
lastFrameTime = ClientUtils.getRenderTime();
|
||||
|
||||
//draw description
|
||||
// draw description
|
||||
|
||||
double dy = scroll % (height + 20);
|
||||
GL11.glPushMatrix();
|
||||
GL11.glTranslated(0, -dy, 0);
|
||||
GuiDraw.fontRenderer.drawSplitString(description, x1, y1draw, x2-x1, 0xDDDDDD);
|
||||
if(needsScroll) {
|
||||
GL11.glTranslated(0, height + 20, 0);
|
||||
GuiDraw.fontRenderer.drawSplitString(description, x1, y1draw, x2 - x1, 0xDDDDDD);
|
||||
}
|
||||
GL11.glTranslated(0, -dy, 0);
|
||||
GuiDraw.fontRenderer.drawSplitString(description, x1, y1draw, x2 - x1, 0xDDDDDD);
|
||||
if (needsScroll) {
|
||||
GL11.glTranslated(0, height + 20, 0);
|
||||
GuiDraw.fontRenderer.drawSplitString(description, x1, y1draw, x2 - x1, 0xDDDDDD);
|
||||
}
|
||||
GL11.glPopMatrix();
|
||||
|
||||
glDisable(GL_STENCIL_TEST);
|
||||
@@ -150,14 +148,13 @@ public class GuiModListScroll
|
||||
private static int calcDescY(GuiModList gui, ModContainer mod) {
|
||||
ModMetadata meta = mod.getMetadata();
|
||||
int y = 35;
|
||||
if(!!meta.logoFile.isEmpty() && ReflectionManager.getField(GuiModList.class, ResourceLocation.class, gui, "cachedLogo") != null)
|
||||
if (!!meta.logoFile.isEmpty()
|
||||
&& ReflectionManager.getField(GuiModList.class, ResourceLocation.class, gui, "cachedLogo") != null)
|
||||
y += 65;
|
||||
y += 12; // title
|
||||
y += 40; // necessary lines
|
||||
if(!meta.credits.isEmpty())
|
||||
y += 10;
|
||||
if(!meta.childMods.isEmpty())
|
||||
y += 10;
|
||||
if (!meta.credits.isEmpty()) y += 10;
|
||||
if (!meta.childMods.isEmpty()) y += 10;
|
||||
return y;
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,6 @@ package codechicken.core;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
|
||||
public interface IGuiPacketSender
|
||||
{
|
||||
public interface IGuiPacketSender {
|
||||
void sendPacket(EntityPlayerMP player, int windowId);
|
||||
}
|
||||
@@ -1,6 +1,5 @@
|
||||
package codechicken.core;
|
||||
|
||||
public interface IStringMatcher
|
||||
{
|
||||
public interface IStringMatcher {
|
||||
public boolean matches(String test);
|
||||
}
|
||||
@@ -2,8 +2,7 @@ package codechicken.core;
|
||||
|
||||
import codechicken.core.launch.CodeChickenCorePlugin;
|
||||
|
||||
public class ProfileTimer
|
||||
{
|
||||
public class ProfileTimer {
|
||||
public double decay;
|
||||
public long startTime;
|
||||
public long nanoTime;
|
||||
@@ -30,11 +29,11 @@ public class ProfileTimer
|
||||
}
|
||||
|
||||
public void end() {
|
||||
long t = System.nanoTime()-startTime;
|
||||
nanoTime = (long)(nanoTime*decay+t*(1-decay));
|
||||
long t = System.nanoTime() - startTime;
|
||||
nanoTime = (long) (nanoTime * decay + t * (1 - decay));
|
||||
|
||||
scanCount++;
|
||||
if(logScans > 0 && scanCount % logScans == 0)
|
||||
if (logScans > 0 && scanCount % logScans == 0)
|
||||
CodeChickenCorePlugin.logger.info("Profiled " + logName + " " + nanoTime + "ns");
|
||||
}
|
||||
}
|
||||
@@ -1,19 +1,16 @@
|
||||
package codechicken.core;
|
||||
|
||||
import codechicken.lib.asm.ObfMapping;
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.HashMap;
|
||||
|
||||
import codechicken.lib.asm.ObfMapping;
|
||||
|
||||
public class ReflectionManager
|
||||
{
|
||||
public class ReflectionManager {
|
||||
public static HashMap<Class<?>, Class<?>> primitiveWrappers = new HashMap<Class<?>, Class<?>>();
|
||||
|
||||
static
|
||||
{
|
||||
|
||||
static {
|
||||
primitiveWrappers.put(Integer.TYPE, Integer.class);
|
||||
primitiveWrappers.put(Short.TYPE, Short.class);
|
||||
primitiveWrappers.put(Byte.TYPE, Byte.class);
|
||||
@@ -23,293 +20,247 @@ public class ReflectionManager
|
||||
primitiveWrappers.put(Boolean.TYPE, Boolean.class);
|
||||
primitiveWrappers.put(Character.TYPE, Character.class);
|
||||
}
|
||||
|
||||
public static boolean isInstance(Class<?> class1, Object obj)
|
||||
{
|
||||
|
||||
public static boolean isInstance(Class<?> class1, Object obj) {
|
||||
Class<?> primitive = primitiveWrappers.get(class1);
|
||||
if(primitive != null)
|
||||
{
|
||||
if(primitive == Long.class && Long.class.isInstance(obj))
|
||||
return true;
|
||||
if((primitive == Long.class || primitive == Integer.class) && Integer.class.isInstance(obj))
|
||||
return true;
|
||||
if((primitive == Long.class || primitive == Integer.class || primitive == Short.class) && Short.class.isInstance(obj))
|
||||
return true;
|
||||
if((primitive == Long.class || primitive == Integer.class || primitive == Short.class || primitive == Byte.class) && Integer.class.isInstance(obj))
|
||||
return true;
|
||||
|
||||
if(primitive == Double.class && Double.class.isInstance(obj))
|
||||
return true;
|
||||
if((primitive == Double.class || primitive == Float.class) && Float.class.isInstance(obj))
|
||||
return true;
|
||||
|
||||
if (primitive != null) {
|
||||
if (primitive == Long.class && Long.class.isInstance(obj)) return true;
|
||||
if ((primitive == Long.class || primitive == Integer.class) && Integer.class.isInstance(obj)) return true;
|
||||
if ((primitive == Long.class || primitive == Integer.class || primitive == Short.class)
|
||||
&& Short.class.isInstance(obj)) return true;
|
||||
if ((primitive == Long.class
|
||||
|| primitive == Integer.class
|
||||
|| primitive == Short.class
|
||||
|| primitive == Byte.class)
|
||||
&& Integer.class.isInstance(obj)) return true;
|
||||
|
||||
if (primitive == Double.class && Double.class.isInstance(obj)) return true;
|
||||
if ((primitive == Double.class || primitive == Float.class) && Float.class.isInstance(obj)) return true;
|
||||
|
||||
return primitive.isInstance(obj);
|
||||
}
|
||||
return class1.isInstance(obj);
|
||||
}
|
||||
|
||||
public static Class<?> findClass(String name)
|
||||
{
|
||||
|
||||
public static Class<?> findClass(String name) {
|
||||
return findClass(name, true);
|
||||
}
|
||||
|
||||
public static boolean classExists(String name)
|
||||
{
|
||||
|
||||
public static boolean classExists(String name) {
|
||||
return findClass(name, false) != null;
|
||||
}
|
||||
|
||||
public static Class<?> findClass(String name, boolean init)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
||||
public static Class<?> findClass(String name, boolean init) {
|
||||
try {
|
||||
return Class.forName(name, init, ReflectionManager.class.getClassLoader());
|
||||
}
|
||||
catch (ClassNotFoundException cnfe)
|
||||
{
|
||||
try
|
||||
{
|
||||
return Class.forName("net.minecraft.src."+name, init, ReflectionManager.class.getClassLoader());
|
||||
}
|
||||
catch (ClassNotFoundException cnfe2)
|
||||
{
|
||||
} catch (ClassNotFoundException cnfe) {
|
||||
try {
|
||||
return Class.forName("net.minecraft.src." + name, init, ReflectionManager.class.getClassLoader());
|
||||
} catch (ClassNotFoundException cnfe2) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void setField(Class<?> class1, Object instance, String name, Object value) throws IllegalArgumentException, IllegalAccessException
|
||||
{
|
||||
setField(class1, instance, new String[]{name}, value);
|
||||
public static void setField(Class<?> class1, Object instance, String name, Object value)
|
||||
throws IllegalArgumentException, IllegalAccessException {
|
||||
setField(class1, instance, new String[] {name}, value);
|
||||
}
|
||||
|
||||
public static void setField(Class<?> class1, Object instance, String[] names, Object value) throws IllegalArgumentException, IllegalAccessException
|
||||
{
|
||||
for(Field field : class1.getDeclaredFields())
|
||||
{
|
||||
|
||||
public static void setField(Class<?> class1, Object instance, String[] names, Object value)
|
||||
throws IllegalArgumentException, IllegalAccessException {
|
||||
for (Field field : class1.getDeclaredFields()) {
|
||||
boolean match = false;
|
||||
for(String name : names)
|
||||
{
|
||||
if(field.getName().equals(name))
|
||||
{
|
||||
for (String name : names) {
|
||||
if (field.getName().equals(name)) {
|
||||
match = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(!match)
|
||||
{
|
||||
if (!match) {
|
||||
continue;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
field.setAccessible(true);
|
||||
field.set(instance, value);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
public static void setField(Class<?> class1, Object instance, int fieldindex, Object value) throws IllegalArgumentException, IllegalAccessException
|
||||
{
|
||||
|
||||
public static void setField(Class<?> class1, Object instance, int fieldindex, Object value)
|
||||
throws IllegalArgumentException, IllegalAccessException {
|
||||
Field field = class1.getDeclaredFields()[fieldindex];
|
||||
field.setAccessible(true);
|
||||
field.set(instance, value);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Static function
|
||||
* void return type
|
||||
* single name
|
||||
*/
|
||||
public static void callMethod(Class<?> class1, String name, Object... params) throws IllegalArgumentException, IllegalAccessException, InvocationTargetException
|
||||
{
|
||||
callMethod(class1, null, new String[]{name}, params);
|
||||
public static void callMethod(Class<?> class1, String name, Object... params)
|
||||
throws IllegalArgumentException, IllegalAccessException, InvocationTargetException {
|
||||
callMethod(class1, null, new String[] {name}, params);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Static function
|
||||
* void return type
|
||||
* single name
|
||||
*/
|
||||
public static void callMethod(Class<?> class1, String[] names, Object... params) throws IllegalArgumentException, IllegalAccessException, InvocationTargetException
|
||||
{
|
||||
public static void callMethod(Class<?> class1, String[] names, Object... params)
|
||||
throws IllegalArgumentException, IllegalAccessException, InvocationTargetException {
|
||||
callMethod(class1, null, names, params);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* void return type
|
||||
* single name
|
||||
*/
|
||||
public static void callMethod(Class<?> class1, Object instance, String name, Object... params) throws IllegalArgumentException, IllegalAccessException, InvocationTargetException
|
||||
{
|
||||
callMethod(class1, null, instance, new String[]{name}, params);
|
||||
public static void callMethod(Class<?> class1, Object instance, String name, Object... params)
|
||||
throws IllegalArgumentException, IllegalAccessException, InvocationTargetException {
|
||||
callMethod(class1, null, instance, new String[] {name}, params);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* void return type
|
||||
*/
|
||||
public static void callMethod(Class<?> class1, Object instance, String[] names, Object... params) throws IllegalArgumentException, IllegalAccessException, InvocationTargetException
|
||||
{
|
||||
public static void callMethod(Class<?> class1, Object instance, String[] names, Object... params)
|
||||
throws IllegalArgumentException, IllegalAccessException, InvocationTargetException {
|
||||
callMethod(class1, null, instance, names, params);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Static method
|
||||
* single name
|
||||
*/
|
||||
public static <R> R callMethod(Class<?> class1, Class<R> returntype, String name, Object... params) throws IllegalArgumentException, IllegalAccessException, InvocationTargetException
|
||||
{
|
||||
return callMethod(class1, returntype, null, new String[]{name}, params);
|
||||
public static <R> R callMethod(Class<?> class1, Class<R> returntype, String name, Object... params)
|
||||
throws IllegalArgumentException, IllegalAccessException, InvocationTargetException {
|
||||
return callMethod(class1, returntype, null, new String[] {name}, params);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Static method
|
||||
*/
|
||||
public static <R> R callMethod(Class<?> class1, Class<R> returntype, String[] names, Object... params) throws IllegalArgumentException, IllegalAccessException, InvocationTargetException
|
||||
{
|
||||
public static <R> R callMethod(Class<?> class1, Class<R> returntype, String[] names, Object... params)
|
||||
throws IllegalArgumentException, IllegalAccessException, InvocationTargetException {
|
||||
return callMethod(class1, returntype, null, names, params);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* sinlge name
|
||||
*/
|
||||
public static <R> R callMethod(Class<?> class1, Class<R> returntype, Object instance, String name, Object... params) throws IllegalArgumentException, IllegalAccessException, InvocationTargetException
|
||||
{
|
||||
return callMethod(class1, returntype, instance, new String[]{name}, params);
|
||||
public static <R> R callMethod(Class<?> class1, Class<R> returntype, Object instance, String name, Object... params)
|
||||
throws IllegalArgumentException, IllegalAccessException, InvocationTargetException {
|
||||
return callMethod(class1, returntype, instance, new String[] {name}, params);
|
||||
}
|
||||
|
||||
public static <R> R callMethod(Class<?> class1, Class<R> returntype, Object instance, String[] names, Object... params) throws IllegalArgumentException, IllegalAccessException, InvocationTargetException
|
||||
{
|
||||
nextMethod: for(Method method : class1.getDeclaredMethods())
|
||||
{
|
||||
|
||||
public static <R> R callMethod(
|
||||
Class<?> class1, Class<R> returntype, Object instance, String[] names, Object... params)
|
||||
throws IllegalArgumentException, IllegalAccessException, InvocationTargetException {
|
||||
nextMethod:
|
||||
for (Method method : class1.getDeclaredMethods()) {
|
||||
boolean match = false;
|
||||
for(String name : names)
|
||||
{
|
||||
if(method.getName().equals(name))
|
||||
{
|
||||
for (String name : names) {
|
||||
if (method.getName().equals(name)) {
|
||||
match = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(!match)
|
||||
{
|
||||
if (!match) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
Class<?>[] paramtypes = method.getParameterTypes();
|
||||
if(paramtypes.length != params.length)
|
||||
continue;
|
||||
|
||||
for(int i = 0; i < params.length; i++)
|
||||
{
|
||||
if(!isInstance(paramtypes[i], params[i]))
|
||||
continue nextMethod;
|
||||
if (paramtypes.length != params.length) continue;
|
||||
|
||||
for (int i = 0; i < params.length; i++) {
|
||||
if (!isInstance(paramtypes[i], params[i])) continue nextMethod;
|
||||
}
|
||||
|
||||
|
||||
method.setAccessible(true);
|
||||
return (R)method.invoke(instance, params);
|
||||
return (R) method.invoke(instance, params);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static <T> T getField(Class<?> class1, Class<T> fieldType, Object instance, int fieldIndex) throws IllegalArgumentException, IllegalAccessException
|
||||
{
|
||||
|
||||
public static <T> T getField(Class<?> class1, Class<T> fieldType, Object instance, int fieldIndex)
|
||||
throws IllegalArgumentException, IllegalAccessException {
|
||||
Field field = class1.getDeclaredFields()[fieldIndex];
|
||||
field.setAccessible(true);
|
||||
return (T) field.get(instance);
|
||||
}
|
||||
|
||||
public static <T> T getField(Class<?> class1, Class<T> fieldType, Object instance, String fieldName)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
||||
public static <T> T getField(Class<?> class1, Class<T> fieldType, Object instance, String fieldName) {
|
||||
try {
|
||||
Field field = class1.getDeclaredField(fieldName);
|
||||
field.setAccessible(true);
|
||||
return (T) field.get(instance);
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public static <T> T newInstance(Class<T> class1, Object... params) throws IllegalArgumentException, InstantiationException, IllegalAccessException, InvocationTargetException
|
||||
{
|
||||
nextMethod: for(Constructor<?> constructor : class1.getDeclaredConstructors())
|
||||
{
|
||||
public static <T> T newInstance(Class<T> class1, Object... params)
|
||||
throws IllegalArgumentException, InstantiationException, IllegalAccessException, InvocationTargetException {
|
||||
nextMethod:
|
||||
for (Constructor<?> constructor : class1.getDeclaredConstructors()) {
|
||||
Class<?>[] paramtypes = constructor.getParameterTypes();
|
||||
if(paramtypes.length != params.length)
|
||||
continue;
|
||||
|
||||
for(int i = 0; i < params.length; i++)
|
||||
{
|
||||
if(!isInstance(paramtypes[i], params[i]))
|
||||
continue nextMethod;
|
||||
if (paramtypes.length != params.length) continue;
|
||||
|
||||
for (int i = 0; i < params.length; i++) {
|
||||
if (!isInstance(paramtypes[i], params[i])) continue nextMethod;
|
||||
}
|
||||
|
||||
|
||||
constructor.setAccessible(true);
|
||||
return (T)constructor.newInstance(params);
|
||||
return (T) constructor.newInstance(params);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static boolean hasField(Class<?> class1, String fieldName)
|
||||
{
|
||||
try
|
||||
{
|
||||
public static boolean hasField(Class<?> class1, String fieldName) {
|
||||
try {
|
||||
class1.getDeclaredField(fieldName);
|
||||
return true;
|
||||
}
|
||||
catch(NoSuchFieldException nfe)
|
||||
{
|
||||
} catch (NoSuchFieldException nfe) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static <T> T get(Field field, Class<T> class1)
|
||||
{
|
||||
|
||||
public static <T> T get(Field field, Class<T> class1) {
|
||||
return get(field, class1, null);
|
||||
}
|
||||
|
||||
public static <T> T get(Field field, Class<T> class1, Object instance)
|
||||
{
|
||||
try
|
||||
{
|
||||
return (T)field.get(instance);
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public static void set(Field field, Object value)
|
||||
{
|
||||
set(field, null, value);
|
||||
}
|
||||
|
||||
public static void set(Field field, Object instance, Object value)
|
||||
{
|
||||
try
|
||||
{
|
||||
field.set(instance, value);
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
public static <T> T get(Field field, Class<T> class1, Object instance) {
|
||||
try {
|
||||
return (T) field.get(instance);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public static Field getField(ObfMapping mapping)
|
||||
{
|
||||
public static void set(Field field, Object value) {
|
||||
set(field, null, value);
|
||||
}
|
||||
|
||||
public static void set(Field field, Object instance, Object value) {
|
||||
try {
|
||||
field.set(instance, value);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public static Field getField(ObfMapping mapping) {
|
||||
mapping.toRuntime();
|
||||
|
||||
try
|
||||
{
|
||||
|
||||
try {
|
||||
Class<?> clazz = ReflectionManager.class.getClassLoader().loadClass(mapping.javaClass());
|
||||
Field field = clazz.getDeclaredField(mapping.s_name);
|
||||
field.setAccessible(true);
|
||||
return field;
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,22 +1,20 @@
|
||||
package codechicken.core;
|
||||
|
||||
import codechicken.lib.asm.ObfMapping;
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
|
||||
import codechicken.lib.asm.ObfMapping;
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.inventory.Container;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.inventory.Container;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.util.IChatComponent;
|
||||
|
||||
public class ServerUtils extends CommonUtils
|
||||
{
|
||||
public class ServerUtils extends CommonUtils {
|
||||
public static MinecraftServer mc() {
|
||||
return MinecraftServer.getServer();
|
||||
}
|
||||
@@ -31,9 +29,7 @@ public class ServerUtils extends CommonUtils
|
||||
|
||||
public static ArrayList<EntityPlayer> getPlayersInDimension(int dimension) {
|
||||
ArrayList<EntityPlayer> players = new ArrayList<EntityPlayer>();
|
||||
for (EntityPlayer p : getPlayers())
|
||||
if(p.dimension == dimension)
|
||||
players.add(p);
|
||||
for (EntityPlayer p : getPlayers()) if (p.dimension == dimension) players.add(p);
|
||||
|
||||
return players;
|
||||
}
|
||||
@@ -50,13 +46,20 @@ public class ServerUtils extends CommonUtils
|
||||
private static Field field_152661_c;
|
||||
private static Class<?> c_ProfileEntry;
|
||||
private static Method func_152668_a;
|
||||
|
||||
static {
|
||||
try {
|
||||
field_152661_c = ReflectionManager.getField(new ObfMapping("net/minecraft/server/management/PlayerProfileCache", "field_152661_c", "[Ljava/util/Map;"));
|
||||
c_ProfileEntry = ServerUtils.class.getClassLoader().loadClass("net.minecraft.server.management.PlayerProfileCache$ProfileEntry");
|
||||
func_152668_a = c_ProfileEntry.getDeclaredMethod(
|
||||
new ObfMapping("net/minecraft/server/management/PlayerProfileCache$ProfileEntry",
|
||||
"func_152668_a", "()Lcom/mojang/authlib/GameProfile;").toRuntime().s_name);
|
||||
field_152661_c = ReflectionManager.getField(new ObfMapping(
|
||||
"net/minecraft/server/management/PlayerProfileCache", "field_152661_c", "[Ljava/util/Map;"));
|
||||
c_ProfileEntry = ServerUtils.class
|
||||
.getClassLoader()
|
||||
.loadClass("net.minecraft.server.management.PlayerProfileCache$ProfileEntry");
|
||||
func_152668_a = c_ProfileEntry.getDeclaredMethod(new ObfMapping(
|
||||
"net/minecraft/server/management/PlayerProfileCache$ProfileEntry",
|
||||
"func_152668_a",
|
||||
"()Lcom/mojang/authlib/GameProfile;")
|
||||
.toRuntime()
|
||||
.s_name);
|
||||
func_152668_a.setAccessible(true);
|
||||
|
||||
} catch (Exception e) {
|
||||
@@ -66,14 +69,12 @@ public class ServerUtils extends CommonUtils
|
||||
|
||||
public static GameProfile getGameProfile(String username) {
|
||||
EntityPlayer player = getPlayer(username);
|
||||
if(player != null)
|
||||
return player.getGameProfile();
|
||||
if (player != null) return player.getGameProfile();
|
||||
|
||||
username = username.toLowerCase(Locale.ROOT);
|
||||
try {//use reflection to bypass saving the game profiles every time we ask the cache for one
|
||||
try { // use reflection to bypass saving the game profiles every time we ask the cache for one
|
||||
Object cacheEntry = ((Map) field_152661_c.get(mc().func_152358_ax())).get(username);
|
||||
if(cacheEntry != null)
|
||||
return (GameProfile) func_152668_a.invoke(cacheEntry);
|
||||
if (cacheEntry != null) return (GameProfile) func_152668_a.invoke(cacheEntry);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
@@ -90,7 +91,6 @@ public class ServerUtils extends CommonUtils
|
||||
}
|
||||
|
||||
public static void sendChatToAll(IChatComponent msg) {
|
||||
for(EntityPlayer p : getPlayers())
|
||||
p.addChatComponentMessage(msg);
|
||||
for (EntityPlayer p : getPlayers()) p.addChatComponentMessage(msg);
|
||||
}
|
||||
}
|
||||
@@ -5,61 +5,51 @@ import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
public class TaskProfiler
|
||||
{
|
||||
public static class ProfilerResult
|
||||
{
|
||||
public class TaskProfiler {
|
||||
public static class ProfilerResult {
|
||||
public final String name;
|
||||
public final long time;
|
||||
public final double fraction;
|
||||
|
||||
public ProfilerResult(String name, long time, long totalTime)
|
||||
{
|
||||
|
||||
public ProfilerResult(String name, long time, long totalTime) {
|
||||
this.name = name;
|
||||
this.time = time;
|
||||
fraction = time/(double)totalTime;
|
||||
fraction = time / (double) totalTime;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public HashMap<String, Long> times = new HashMap<String, Long>();
|
||||
|
||||
|
||||
public String currentSection;
|
||||
private long startTime;
|
||||
private long totalTime;
|
||||
|
||||
public void start(String section)
|
||||
{
|
||||
if(currentSection != null)
|
||||
end();
|
||||
|
||||
|
||||
public void start(String section) {
|
||||
if (currentSection != null) end();
|
||||
|
||||
currentSection = section;
|
||||
startTime = System.nanoTime();
|
||||
}
|
||||
|
||||
public void end()
|
||||
{
|
||||
long time = System.nanoTime()-startTime;
|
||||
totalTime+=time;
|
||||
|
||||
|
||||
public void end() {
|
||||
long time = System.nanoTime() - startTime;
|
||||
totalTime += time;
|
||||
|
||||
Long prev = times.get(currentSection);
|
||||
if(prev == null)
|
||||
prev = 0L;
|
||||
times.put(currentSection, prev+time);
|
||||
if (prev == null) prev = 0L;
|
||||
times.put(currentSection, prev + time);
|
||||
currentSection = null;
|
||||
}
|
||||
|
||||
public List<ProfilerResult> getResults()
|
||||
{
|
||||
|
||||
public List<ProfilerResult> getResults() {
|
||||
ArrayList<ProfilerResult> results = new ArrayList<ProfilerResult>(times.size());
|
||||
for(Entry<String, Long> e : times.entrySet())
|
||||
for (Entry<String, Long> e : times.entrySet())
|
||||
results.add(new ProfilerResult(e.getKey(), e.getValue(), totalTime));
|
||||
return results;
|
||||
}
|
||||
|
||||
public void clear()
|
||||
{
|
||||
if(currentSection != null)
|
||||
end();
|
||||
public void clear() {
|
||||
if (currentSection != null) end();
|
||||
times.clear();
|
||||
totalTime = 0;
|
||||
}
|
||||
|
||||
@@ -1,17 +1,13 @@
|
||||
package codechicken.core.asm;
|
||||
|
||||
import codechicken.lib.asm.ObfMapping;
|
||||
import com.google.common.collect.ImmutableBiMap;
|
||||
import cpw.mods.fml.common.asm.transformers.AccessTransformer;
|
||||
import cpw.mods.fml.common.asm.transformers.deobf.FMLDeobfuscatingRemapper;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
import com.google.common.collect.ImmutableBiMap;
|
||||
|
||||
import codechicken.lib.asm.ObfMapping;
|
||||
|
||||
import cpw.mods.fml.common.asm.transformers.AccessTransformer;
|
||||
import cpw.mods.fml.common.asm.transformers.deobf.FMLDeobfuscatingRemapper;
|
||||
|
||||
public class CodeChickenAccessTransformer extends AccessTransformer
|
||||
{
|
||||
public class CodeChickenAccessTransformer extends AccessTransformer {
|
||||
private static boolean makeAllPublic;
|
||||
private static Field f_classNameBiMap;
|
||||
private static Object emptyMap = ImmutableBiMap.of();
|
||||
@@ -22,17 +18,17 @@ public class CodeChickenAccessTransformer extends AccessTransformer
|
||||
}
|
||||
|
||||
private void loadPublicConfig() {
|
||||
if (ObfMapping.obfuscated)
|
||||
return;
|
||||
if (ObfMapping.obfuscated) return;
|
||||
|
||||
makeAllPublic = CodeChickenCoreModContainer.config.getTag("dev.runtimePublic")
|
||||
.setComment("Enabling this setting will make all minecraft classes public at runtime in MCP just as they are in modloader." +
|
||||
"\nYou should ONLY use this when you are testing with a mod that relies on runtime publicity and doesn't include access transformers." +
|
||||
"\nSuch mods are doing the wrong thing and should be fixed.")
|
||||
makeAllPublic = CodeChickenCoreModContainer.config
|
||||
.getTag("dev.runtimePublic")
|
||||
.setComment(
|
||||
"Enabling this setting will make all minecraft classes public at runtime in MCP just as they are in modloader."
|
||||
+ "\nYou should ONLY use this when you are testing with a mod that relies on runtime publicity and doesn't include access transformers."
|
||||
+ "\nSuch mods are doing the wrong thing and should be fixed.")
|
||||
.getBooleanValue(false);
|
||||
|
||||
if (!makeAllPublic)
|
||||
return;
|
||||
if (!makeAllPublic) return;
|
||||
|
||||
try {
|
||||
f_classNameBiMap = FMLDeobfuscatingRemapper.class.getDeclaredField("classNameBiMap");
|
||||
@@ -45,11 +41,9 @@ public class CodeChickenAccessTransformer extends AccessTransformer
|
||||
@Override
|
||||
public byte[] transform(String name, String transformedName, byte[] bytes) {
|
||||
boolean setPublic = makeAllPublic && name.startsWith("net.minecraft.");
|
||||
if (setPublic)
|
||||
setClassMap(name);
|
||||
if (setPublic) setClassMap(name);
|
||||
bytes = super.transform(name, transformedName, bytes);
|
||||
if (setPublic)
|
||||
restoreClassMap();
|
||||
if (setPublic) restoreClassMap();
|
||||
return bytes;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,34 +1,31 @@
|
||||
package codechicken.core.asm;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import codechicken.core.CCUpdateChecker;
|
||||
import codechicken.core.ClientUtils;
|
||||
import codechicken.core.featurehack.LiquidTextures;
|
||||
import codechicken.core.internal.CCCEventHandler;
|
||||
import codechicken.core.launch.CodeChickenCorePlugin;
|
||||
import codechicken.lib.config.ConfigFile;
|
||||
|
||||
import com.google.common.eventbus.EventBus;
|
||||
import com.google.common.eventbus.Subscribe;
|
||||
|
||||
import cpw.mods.fml.common.*;
|
||||
import cpw.mods.fml.common.event.FMLInitializationEvent;
|
||||
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
|
||||
import cpw.mods.fml.common.versioning.ArtifactVersion;
|
||||
import cpw.mods.fml.common.versioning.VersionParser;
|
||||
import cpw.mods.fml.common.versioning.VersionRange;
|
||||
import java.io.File;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
|
||||
public class CodeChickenCoreModContainer extends DummyModContainer
|
||||
{
|
||||
public class CodeChickenCoreModContainer extends DummyModContainer {
|
||||
public static ConfigFile config;
|
||||
|
||||
public static void loadConfig() {
|
||||
if(config == null)
|
||||
config = new ConfigFile(new File(CodeChickenCorePlugin.minecraftDir, "config/CodeChickenCore.cfg")).setComment("CodeChickenCore configuration file.");
|
||||
if (config == null)
|
||||
config = new ConfigFile(new File(CodeChickenCorePlugin.minecraftDir, "config/CodeChickenCore.cfg"))
|
||||
.setComment("CodeChickenCore configuration file.");
|
||||
}
|
||||
|
||||
public CodeChickenCoreModContainer() {
|
||||
@@ -46,7 +43,7 @@ public class CodeChickenCoreModContainer extends DummyModContainer
|
||||
@Override
|
||||
public List<ArtifactVersion> getDependants() {
|
||||
LinkedList<ArtifactVersion> deps = new LinkedList<ArtifactVersion>();
|
||||
if(!getVersion().contains("$")) {
|
||||
if (!getVersion().contains("$")) {
|
||||
deps.add(VersionParser.parseVersionReference("Forge@[10.13.3,)"));
|
||||
deps.add(VersionParser.parseVersionReference("NotEnoughItems@[1.0.5,)"));
|
||||
deps.add(VersionParser.parseVersionReference("EnderStorage@[1.4.7,)"));
|
||||
@@ -65,15 +62,13 @@ public class CodeChickenCoreModContainer extends DummyModContainer
|
||||
|
||||
@Subscribe
|
||||
public void preInit(FMLPreInitializationEvent event) {
|
||||
if (event.getSide().isClient())
|
||||
LiquidTextures.init();
|
||||
if (event.getSide().isClient()) LiquidTextures.init();
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void init(FMLInitializationEvent event) {
|
||||
if (event.getSide().isClient()) {
|
||||
if (config.getTag("checkUpdates").getBooleanValue(true))
|
||||
CCUpdateChecker.updateCheck(getModId());
|
||||
if (config.getTag("checkUpdates").getBooleanValue(true)) CCUpdateChecker.updateCheck(getModId());
|
||||
|
||||
ClientUtils.enhanceSupportersList("CodeChickenCore");
|
||||
|
||||
|
||||
@@ -1,94 +1,89 @@
|
||||
package codechicken.core.asm;
|
||||
|
||||
import codechicken.lib.asm.ASMHelper;
|
||||
import codechicken.lib.asm.ClassHeirachyManager;
|
||||
import codechicken.lib.asm.ObfMapping;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedList;
|
||||
|
||||
import net.minecraft.launchwrapper.IClassTransformer;
|
||||
import net.minecraft.launchwrapper.LaunchClassLoader;
|
||||
import org.objectweb.asm.tree.ClassNode;
|
||||
import org.objectweb.asm.tree.MethodNode;
|
||||
|
||||
import codechicken.lib.asm.ASMHelper;
|
||||
import codechicken.lib.asm.ClassHeirachyManager;
|
||||
import codechicken.lib.asm.ObfMapping;
|
||||
public class DefaultImplementationTransformer implements IClassTransformer {
|
||||
private static LaunchClassLoader cl = (LaunchClassLoader) ClassHeirachyManager.class.getClassLoader();
|
||||
|
||||
import net.minecraft.launchwrapper.IClassTransformer;
|
||||
import net.minecraft.launchwrapper.LaunchClassLoader;
|
||||
|
||||
public class DefaultImplementationTransformer implements IClassTransformer
|
||||
{
|
||||
private static LaunchClassLoader cl = (LaunchClassLoader)ClassHeirachyManager.class.getClassLoader();
|
||||
private static ClassNode getClassNode(String name) {
|
||||
try {
|
||||
return ASMHelper.createClassNode(cl.getClassBytes(name.replace('/', '.')));
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
try {
|
||||
return ASMHelper.createClassNode(cl.getClassBytes(name.replace('/', '.')));
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
static class InterfaceImpl
|
||||
{
|
||||
public final String iname;
|
||||
public ArrayList<MethodNode> impls = new ArrayList<MethodNode>();
|
||||
|
||||
public InterfaceImpl(String iname, String cname)
|
||||
{
|
||||
this.iname = iname;
|
||||
HashSet<String> names = new HashSet<String>();
|
||||
ClassNode inode = getClassNode(iname);
|
||||
for(MethodNode method : inode.methods)
|
||||
names.add(method.name+method.desc);
|
||||
|
||||
ClassNode cnode = getClassNode(cname);
|
||||
for(MethodNode method : cnode.methods)
|
||||
if(names.contains(method.name+method.desc)) {
|
||||
impls.add(method);
|
||||
method.desc = new ObfMapping(cnode.name, method.name, method.desc).toRuntime().s_desc;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean patch(ClassNode cnode) {
|
||||
LinkedList<String> names = new LinkedList<String>();
|
||||
for(MethodNode method : cnode.methods) {
|
||||
ObfMapping m = new ObfMapping(cnode.name, method.name, method.desc).toRuntime();
|
||||
names.add(m.s_name+m.s_desc);
|
||||
}
|
||||
static class InterfaceImpl {
|
||||
public final String iname;
|
||||
public ArrayList<MethodNode> impls = new ArrayList<MethodNode>();
|
||||
|
||||
boolean changed = false;
|
||||
for(MethodNode impl : impls) {
|
||||
if(names.contains(impl.name+impl.desc))
|
||||
continue;
|
||||
|
||||
MethodNode copy = new MethodNode(impl.access, impl.name, impl.desc,
|
||||
impl.signature, impl.exceptions == null ? null : impl.exceptions.toArray(new String[0]));
|
||||
ASMHelper.copy(impl, copy);
|
||||
cnode.methods.add(impl);
|
||||
changed = true;
|
||||
}
|
||||
return changed;
|
||||
}
|
||||
}
|
||||
|
||||
private static HashMap<String, InterfaceImpl> impls = new HashMap<String, InterfaceImpl>();
|
||||
|
||||
public static void registerDefaultImpl(String iname, String cname) {
|
||||
impls.put(iname.replace('.', '/'), new InterfaceImpl(iname, cname));
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] transform(String name, String transformedName, byte[] bytes) {
|
||||
if(transformedName.startsWith("net.minecraft") || impls.isEmpty())
|
||||
return bytes;
|
||||
|
||||
ClassNode cnode = ASMHelper.createClassNode(bytes);
|
||||
boolean changed = false;
|
||||
for(String iname : cnode.interfaces) {
|
||||
InterfaceImpl impl = impls.get(iname);
|
||||
if(impl != null)
|
||||
changed |= impl.patch(cnode);
|
||||
}
|
||||
|
||||
return changed ? ASMHelper.createBytes(cnode, 0) : bytes;
|
||||
}
|
||||
public InterfaceImpl(String iname, String cname) {
|
||||
this.iname = iname;
|
||||
HashSet<String> names = new HashSet<String>();
|
||||
ClassNode inode = getClassNode(iname);
|
||||
for (MethodNode method : inode.methods) names.add(method.name + method.desc);
|
||||
|
||||
ClassNode cnode = getClassNode(cname);
|
||||
for (MethodNode method : cnode.methods)
|
||||
if (names.contains(method.name + method.desc)) {
|
||||
impls.add(method);
|
||||
method.desc = new ObfMapping(cnode.name, method.name, method.desc).toRuntime().s_desc;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean patch(ClassNode cnode) {
|
||||
LinkedList<String> names = new LinkedList<String>();
|
||||
for (MethodNode method : cnode.methods) {
|
||||
ObfMapping m = new ObfMapping(cnode.name, method.name, method.desc).toRuntime();
|
||||
names.add(m.s_name + m.s_desc);
|
||||
}
|
||||
|
||||
boolean changed = false;
|
||||
for (MethodNode impl : impls) {
|
||||
if (names.contains(impl.name + impl.desc)) continue;
|
||||
|
||||
MethodNode copy = new MethodNode(
|
||||
impl.access,
|
||||
impl.name,
|
||||
impl.desc,
|
||||
impl.signature,
|
||||
impl.exceptions == null ? null : impl.exceptions.toArray(new String[0]));
|
||||
ASMHelper.copy(impl, copy);
|
||||
cnode.methods.add(impl);
|
||||
changed = true;
|
||||
}
|
||||
return changed;
|
||||
}
|
||||
}
|
||||
|
||||
private static HashMap<String, InterfaceImpl> impls = new HashMap<String, InterfaceImpl>();
|
||||
|
||||
public static void registerDefaultImpl(String iname, String cname) {
|
||||
impls.put(iname.replace('.', '/'), new InterfaceImpl(iname, cname));
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] transform(String name, String transformedName, byte[] bytes) {
|
||||
if (transformedName.startsWith("net.minecraft") || impls.isEmpty()) return bytes;
|
||||
|
||||
ClassNode cnode = ASMHelper.createClassNode(bytes);
|
||||
boolean changed = false;
|
||||
for (String iname : cnode.interfaces) {
|
||||
InterfaceImpl impl = impls.get(iname);
|
||||
if (impl != null) changed |= impl.patch(cnode);
|
||||
}
|
||||
|
||||
return changed ? ASMHelper.createBytes(cnode, 0) : bytes;
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,7 @@
|
||||
package codechicken.core.asm;
|
||||
|
||||
import static codechicken.core.launch.CodeChickenCorePlugin.logger;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
@@ -11,141 +13,117 @@ import java.util.Map;
|
||||
import java.util.Stack;
|
||||
import java.util.jar.JarFile;
|
||||
import java.util.zip.ZipEntry;
|
||||
|
||||
import net.minecraft.launchwrapper.IClassTransformer;
|
||||
import net.minecraft.launchwrapper.Launch;
|
||||
import net.minecraft.launchwrapper.LaunchClassLoader;
|
||||
import org.objectweb.asm.ClassReader;
|
||||
import org.objectweb.asm.Opcodes;
|
||||
|
||||
import net.minecraft.launchwrapper.IClassTransformer;
|
||||
import net.minecraft.launchwrapper.LaunchClassLoader;
|
||||
|
||||
import static codechicken.core.launch.CodeChickenCorePlugin.logger;
|
||||
|
||||
public class DelegatedTransformer implements IClassTransformer
|
||||
{
|
||||
public class DelegatedTransformer implements IClassTransformer {
|
||||
private static ArrayList<IClassTransformer> delegatedTransformers;
|
||||
private static Method m_defineClass;
|
||||
private static Field f_cachedClasses;
|
||||
|
||||
public DelegatedTransformer()
|
||||
{
|
||||
|
||||
public DelegatedTransformer() {
|
||||
delegatedTransformers = new ArrayList<IClassTransformer>();
|
||||
try
|
||||
{
|
||||
m_defineClass = ClassLoader.class.getDeclaredMethod("defineClass", String.class, byte[].class, Integer.TYPE, Integer.TYPE);
|
||||
try {
|
||||
m_defineClass = ClassLoader.class.getDeclaredMethod(
|
||||
"defineClass", String.class, byte[].class, Integer.TYPE, Integer.TYPE);
|
||||
m_defineClass.setAccessible(true);
|
||||
f_cachedClasses = LaunchClassLoader.class.getDeclaredField("cachedClasses");
|
||||
f_cachedClasses.setAccessible(true);
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public byte[] transform(String name, String tname, byte[] bytes)
|
||||
{
|
||||
public byte[] transform(String name, String tname, byte[] bytes) {
|
||||
if (bytes == null) return null;
|
||||
for(IClassTransformer trans : delegatedTransformers)
|
||||
bytes = trans.transform(name, tname, bytes);
|
||||
for (IClassTransformer trans : delegatedTransformers) bytes = trans.transform(name, tname, bytes);
|
||||
return bytes;
|
||||
}
|
||||
|
||||
public static void addTransformer(String transformer, JarFile jar, File jarFile)
|
||||
{
|
||||
public static void addTransformer(String transformer, JarFile jar, File jarFile) {
|
||||
logger.debug("Adding CCTransformer: " + transformer);
|
||||
try
|
||||
{
|
||||
try {
|
||||
byte[] bytes;
|
||||
bytes = Launch.classLoader.getClassBytes(transformer);
|
||||
|
||||
if(bytes == null)
|
||||
{
|
||||
String resourceName = transformer.replace('.', '/')+".class";
|
||||
|
||||
if (bytes == null) {
|
||||
String resourceName = transformer.replace('.', '/') + ".class";
|
||||
ZipEntry entry = jar.getEntry(resourceName);
|
||||
if(entry == null)
|
||||
throw new Exception("Failed to add transformer: "+transformer+". Entry not found in jar file "+jarFile.getName());
|
||||
|
||||
if (entry == null)
|
||||
throw new Exception("Failed to add transformer: " + transformer + ". Entry not found in jar file "
|
||||
+ jarFile.getName());
|
||||
|
||||
bytes = readFully(jar.getInputStream(entry));
|
||||
}
|
||||
|
||||
|
||||
defineDependancies(bytes, jar, jarFile);
|
||||
Class<?> clazz = defineClass(transformer, bytes);
|
||||
|
||||
if(!IClassTransformer.class.isAssignableFrom(clazz))
|
||||
throw new Exception("Failed to add transformer: "+transformer+" is not an instance of IClassTransformer");
|
||||
|
||||
|
||||
if (!IClassTransformer.class.isAssignableFrom(clazz))
|
||||
throw new Exception(
|
||||
"Failed to add transformer: " + transformer + " is not an instance of IClassTransformer");
|
||||
|
||||
IClassTransformer classTransformer;
|
||||
try
|
||||
{
|
||||
classTransformer = (IClassTransformer) clazz.getDeclaredConstructor(File.class).newInstance(jarFile);
|
||||
}
|
||||
catch(NoSuchMethodException nsme)
|
||||
{
|
||||
try {
|
||||
classTransformer = (IClassTransformer)
|
||||
clazz.getDeclaredConstructor(File.class).newInstance(jarFile);
|
||||
} catch (NoSuchMethodException nsme) {
|
||||
classTransformer = (IClassTransformer) clazz.newInstance();
|
||||
}
|
||||
delegatedTransformers.add(classTransformer);
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void defineDependancies(byte[] bytes, JarFile jar, File jarFile) throws Exception
|
||||
{
|
||||
|
||||
private static void defineDependancies(byte[] bytes, JarFile jar, File jarFile) throws Exception {
|
||||
defineDependancies(bytes, jar, jarFile, new Stack<String>());
|
||||
}
|
||||
|
||||
private static void defineDependancies(byte[] bytes, JarFile jar, File jarFile, Stack<String> depStack) throws Exception
|
||||
{
|
||||
private static void defineDependancies(byte[] bytes, JarFile jar, File jarFile, Stack<String> depStack)
|
||||
throws Exception {
|
||||
ClassReader reader = new ClassReader(bytes);
|
||||
DependancyLister lister = new DependancyLister(Opcodes.ASM4);
|
||||
reader.accept(lister, 0);
|
||||
|
||||
|
||||
depStack.push(reader.getClassName());
|
||||
|
||||
for(String dependancy : lister.getDependancies())
|
||||
{
|
||||
if(depStack.contains(dependancy))
|
||||
continue;
|
||||
|
||||
try
|
||||
{
|
||||
|
||||
for (String dependancy : lister.getDependancies()) {
|
||||
if (depStack.contains(dependancy)) continue;
|
||||
|
||||
try {
|
||||
Launch.classLoader.loadClass(dependancy.replace('/', '.'));
|
||||
}
|
||||
catch(ClassNotFoundException cnfe)
|
||||
{
|
||||
ZipEntry entry = jar.getEntry(dependancy+".class");
|
||||
if(entry == null)
|
||||
throw new Exception("Dependency "+dependancy+" not found in jar file "+jarFile.getName());
|
||||
|
||||
} catch (ClassNotFoundException cnfe) {
|
||||
ZipEntry entry = jar.getEntry(dependancy + ".class");
|
||||
if (entry == null)
|
||||
throw new Exception("Dependency " + dependancy + " not found in jar file " + jarFile.getName());
|
||||
|
||||
byte[] depbytes = readFully(jar.getInputStream(entry));
|
||||
defineDependancies(depbytes, jar, jarFile, depStack);
|
||||
|
||||
logger.debug("Defining dependancy: "+dependancy);
|
||||
|
||||
logger.debug("Defining dependancy: " + dependancy);
|
||||
|
||||
defineClass(dependancy.replace('/', '.'), depbytes);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
depStack.pop();
|
||||
}
|
||||
|
||||
private static Class<?> defineClass(String classname, byte[] bytes) throws Exception
|
||||
{
|
||||
private static Class<?> defineClass(String classname, byte[] bytes) throws Exception {
|
||||
Class<?> clazz = (Class<?>) m_defineClass.invoke(Launch.classLoader, classname, bytes, 0, bytes.length);
|
||||
((Map<String, Class<?>>)f_cachedClasses.get(Launch.classLoader)).put(classname, clazz);
|
||||
((Map<String, Class<?>>) f_cachedClasses.get(Launch.classLoader)).put(classname, clazz);
|
||||
return clazz;
|
||||
}
|
||||
|
||||
public static byte[] readFully(InputStream stream) throws IOException
|
||||
{
|
||||
public static byte[] readFully(InputStream stream) throws IOException {
|
||||
ByteArrayOutputStream bos = new ByteArrayOutputStream(stream.available());
|
||||
int r;
|
||||
while ((r = stream.read()) != -1)
|
||||
{
|
||||
while ((r = stream.read()) != -1) {
|
||||
bos.write(r);
|
||||
}
|
||||
|
||||
|
||||
@@ -5,91 +5,74 @@ import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.objectweb.asm.ClassVisitor;
|
||||
import org.objectweb.asm.FieldVisitor;
|
||||
import org.objectweb.asm.Label;
|
||||
import org.objectweb.asm.MethodVisitor;
|
||||
import org.objectweb.asm.Opcodes;
|
||||
|
||||
public class DependancyLister extends ClassVisitor
|
||||
{
|
||||
public class DependancyLister extends ClassVisitor {
|
||||
private static Pattern classdesc = Pattern.compile("L(.+?);");
|
||||
|
||||
private class DependancyMethodLister extends MethodVisitor
|
||||
{
|
||||
public DependancyMethodLister(int api)
|
||||
{
|
||||
|
||||
private class DependancyMethodLister extends MethodVisitor {
|
||||
public DependancyMethodLister(int api) {
|
||||
super(api);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void visitFieldInsn(int opcode, String owner, String name, String desc)
|
||||
{
|
||||
public void visitFieldInsn(int opcode, String owner, String name, String desc) {
|
||||
dependDesc(desc);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void visitLocalVariable(String name, String desc, String signature, Label start, Label end, int index)
|
||||
{
|
||||
public void visitLocalVariable(String name, String desc, String signature, Label start, Label end, int index) {
|
||||
dependDesc(desc);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void visitMethodInsn(int opcode, String owner, String name, String desc)
|
||||
{
|
||||
public void visitMethodInsn(int opcode, String owner, String name, String desc) {
|
||||
depend(owner);
|
||||
dependDesc(desc);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private HashSet<String> dependancies = new HashSet<String>();
|
||||
|
||||
public DependancyLister(int api)
|
||||
{
|
||||
public DependancyLister(int api) {
|
||||
super(api);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public FieldVisitor visitField(int access, String name, String desc, String signature, Object value)
|
||||
{
|
||||
public FieldVisitor visitField(int access, String name, String desc, String signature, Object value) {
|
||||
dependDesc(desc);
|
||||
return null;
|
||||
}
|
||||
|
||||
private void dependDesc(String desc)
|
||||
{
|
||||
|
||||
private void dependDesc(String desc) {
|
||||
Matcher match = classdesc.matcher(desc);
|
||||
while(match.find())
|
||||
{
|
||||
while (match.find()) {
|
||||
String s = match.group();
|
||||
depend(s.substring(1, s.length()-1));
|
||||
depend(s.substring(1, s.length() - 1));
|
||||
}
|
||||
}
|
||||
|
||||
private void depend(String classname)
|
||||
{
|
||||
private void depend(String classname) {
|
||||
dependancies.add(classname);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions)
|
||||
{
|
||||
public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) {
|
||||
dependDesc(desc);
|
||||
return new DependancyMethodLister(Opcodes.ASM4);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void visit(int version, int access, String name, String signature, String superName, String[] interfaces)
|
||||
{
|
||||
public void visit(int version, int access, String name, String signature, String superName, String[] interfaces) {
|
||||
depend(superName);
|
||||
if(interfaces != null)
|
||||
for(String interfacename : interfaces)
|
||||
depend(interfacename);
|
||||
if (interfaces != null) for (String interfacename : interfaces) depend(interfacename);
|
||||
}
|
||||
|
||||
public List<String> getDependancies()
|
||||
{
|
||||
|
||||
public List<String> getDependancies() {
|
||||
return new ArrayList<String>(dependancies);
|
||||
}
|
||||
}
|
||||
@@ -5,10 +5,6 @@ import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target({ElementType.TYPE})
|
||||
public @interface InterfaceDependancies
|
||||
{
|
||||
|
||||
}
|
||||
public @interface InterfaceDependancies {}
|
||||
@@ -1,53 +0,0 @@
|
||||
package codechicken.core.asm;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
import codechicken.lib.asm.ASMInit;
|
||||
import net.minecraft.launchwrapper.Launch;
|
||||
import org.objectweb.asm.Type;
|
||||
import org.objectweb.asm.tree.AnnotationNode;
|
||||
import org.objectweb.asm.tree.ClassNode;
|
||||
|
||||
import codechicken.lib.asm.ASMHelper;
|
||||
import codechicken.lib.asm.ObfMapping;
|
||||
|
||||
import net.minecraft.launchwrapper.IClassTransformer;
|
||||
|
||||
public class InterfaceDependancyTransformer implements IClassTransformer
|
||||
{
|
||||
static {
|
||||
ASMInit.init();
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] transform(String name, String tname, byte[] bytes) {
|
||||
if (bytes == null) return null;
|
||||
ClassNode cnode = ASMHelper.createClassNode(bytes);
|
||||
|
||||
boolean hasDependancyInterfaces = false;
|
||||
if (cnode.visibleAnnotations != null)
|
||||
for (AnnotationNode ann : cnode.visibleAnnotations)
|
||||
if (ann.desc.equals(Type.getDescriptor(InterfaceDependancies.class))) {
|
||||
hasDependancyInterfaces = true;
|
||||
break;
|
||||
}
|
||||
|
||||
if (!hasDependancyInterfaces)
|
||||
return bytes;
|
||||
|
||||
hasDependancyInterfaces = false;
|
||||
for (Iterator<String> iterator = cnode.interfaces.iterator(); iterator.hasNext(); ) {
|
||||
try {
|
||||
Launch.classLoader.findClass(new ObfMapping(iterator.next()).toRuntime().javaClass());
|
||||
} catch (ClassNotFoundException cnfe) {
|
||||
iterator.remove();
|
||||
hasDependancyInterfaces = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!hasDependancyInterfaces)
|
||||
return bytes;
|
||||
|
||||
return ASMHelper.createBytes(cnode, 0);
|
||||
}
|
||||
}
|
||||
@@ -1,13 +1,23 @@
|
||||
package codechicken.core.asm;
|
||||
|
||||
import codechicken.lib.asm.ASMHelper;
|
||||
import codechicken.lib.asm.ASMInit;
|
||||
import codechicken.lib.asm.CC_ClassWriter;
|
||||
import codechicken.lib.asm.ObfMapping;
|
||||
import codechicken.obfuscator.IHeirachyEvaluator;
|
||||
import codechicken.obfuscator.ObfuscationMap.ObfuscationEntry;
|
||||
import codechicken.obfuscator.ObfuscationRun;
|
||||
import com.google.common.collect.HashMultimap;
|
||||
import com.google.common.collect.Multimap;
|
||||
import cpw.mods.fml.common.asm.transformers.AccessTransformer;
|
||||
import cpw.mods.fml.relauncher.IFMLLoadingPlugin;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.*;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import codechicken.lib.asm.ASMInit;
|
||||
import cpw.mods.fml.relauncher.IFMLLoadingPlugin;
|
||||
import net.minecraft.launchwrapper.IClassTransformer;
|
||||
import net.minecraft.launchwrapper.Launch;
|
||||
import net.minecraft.launchwrapper.LaunchClassLoader;
|
||||
import org.objectweb.asm.ClassReader;
|
||||
import org.objectweb.asm.ClassWriter;
|
||||
import org.objectweb.asm.Opcodes;
|
||||
@@ -15,28 +25,12 @@ import org.objectweb.asm.tree.ClassNode;
|
||||
import org.objectweb.asm.tree.MethodInsnNode;
|
||||
import org.objectweb.asm.tree.MethodNode;
|
||||
|
||||
import com.google.common.collect.HashMultimap;
|
||||
import com.google.common.collect.Multimap;
|
||||
|
||||
import codechicken.lib.asm.ASMHelper;
|
||||
import codechicken.lib.asm.CC_ClassWriter;
|
||||
import codechicken.lib.asm.ObfMapping;
|
||||
import codechicken.obfuscator.IHeirachyEvaluator;
|
||||
import codechicken.obfuscator.ObfuscationRun;
|
||||
import codechicken.obfuscator.ObfuscationMap.ObfuscationEntry;
|
||||
import cpw.mods.fml.common.asm.transformers.AccessTransformer;
|
||||
|
||||
import net.minecraft.launchwrapper.IClassTransformer;
|
||||
import net.minecraft.launchwrapper.LaunchClassLoader;
|
||||
|
||||
public class MCPDeobfuscationTransformer implements IClassTransformer, Opcodes, IHeirachyEvaluator
|
||||
{
|
||||
public class MCPDeobfuscationTransformer implements IClassTransformer, Opcodes, IHeirachyEvaluator {
|
||||
static {
|
||||
ASMInit.init();
|
||||
}
|
||||
|
||||
public static class LoadPlugin implements IFMLLoadingPlugin
|
||||
{
|
||||
public static class LoadPlugin implements IFMLLoadingPlugin {
|
||||
@Override
|
||||
public String[] getASMTransformerClass() {
|
||||
return new String[0];
|
||||
@@ -78,7 +72,8 @@ public class MCPDeobfuscationTransformer implements IClassTransformer, Opcodes,
|
||||
try {
|
||||
f_transformers = LaunchClassLoader.class.getDeclaredField("transformers");
|
||||
f_modifiers = AccessTransformer.class.getDeclaredField("modifiers");
|
||||
Class<?> c_Modifier = Class.forName(AccessTransformer.class.getName() + "$Modifier", false, Launch.classLoader);
|
||||
Class<?> c_Modifier =
|
||||
Class.forName(AccessTransformer.class.getName() + "$Modifier", false, Launch.classLoader);
|
||||
f_Modifier_name = c_Modifier.getDeclaredField("name");
|
||||
f_Modifier_desc = c_Modifier.getDeclaredField("desc");
|
||||
|
||||
@@ -115,21 +110,25 @@ public class MCPDeobfuscationTransformer implements IClassTransformer, Opcodes,
|
||||
public static void load() {
|
||||
CodeChickenCoreModContainer.loadConfig();
|
||||
|
||||
if (CodeChickenCoreModContainer.config.getTag("dev.deobfuscate")
|
||||
if (CodeChickenCoreModContainer.config
|
||||
.getTag("dev.deobfuscate")
|
||||
.setComment("set to true to completely deobfuscate mcp names")
|
||||
.getBooleanValue(!ObfMapping.obfuscated)) {
|
||||
run = new ObfuscationRun(false, ObfMapping.MCPRemapper.getConfFiles(),
|
||||
run = new ObfuscationRun(
|
||||
false,
|
||||
ObfMapping.MCPRemapper.getConfFiles(),
|
||||
ObfuscationRun.fillDefaults(new HashMap<String, String>()));
|
||||
run.obf.setHeirachyEvaluator(instance);
|
||||
run.setQuiet().parseMappings();
|
||||
Collections.addAll(excludedPackages, run.config.get("excludedPackages").split(";"));
|
||||
Collections.addAll(
|
||||
excludedPackages, run.config.get("excludedPackages").split(";"));
|
||||
|
||||
if (ObfMapping.obfuscated) {
|
||||
ObfMapping.loadMCPRemapper();
|
||||
run.setSeargeConstants();
|
||||
getTransformers().add(instance);
|
||||
} else {
|
||||
getTransformers().add(0, instance);//insert transformer as first.
|
||||
getTransformers().add(0, instance); // insert transformer as first.
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -141,8 +140,7 @@ public class MCPDeobfuscationTransformer implements IClassTransformer, Opcodes,
|
||||
activated = true;
|
||||
}
|
||||
|
||||
if (!activated || bytes == null)
|
||||
return bytes;
|
||||
if (!activated || bytes == null) return bytes;
|
||||
|
||||
ClassNode cnode = ASMHelper.createClassNode(bytes, ClassReader.EXPAND_FRAMES);
|
||||
ClassWriter cw = new CC_ClassWriter(0, true);
|
||||
@@ -153,21 +151,20 @@ public class MCPDeobfuscationTransformer implements IClassTransformer, Opcodes,
|
||||
private byte[] injectCallback(byte[] bytes) {
|
||||
ClassNode cnode = ASMHelper.createClassNode(bytes);
|
||||
MethodNode mnode = ASMHelper.findMethod(new ObfMapping(cnode.name, "<clinit>", "()V"), cnode);
|
||||
mnode.instructions.insert(new MethodInsnNode(INVOKESTATIC, "codechicken/core/asm/MCPDeobfuscationTransformer", "loadCallback", "()V"));
|
||||
mnode.instructions.insert(new MethodInsnNode(
|
||||
INVOKESTATIC, "codechicken/core/asm/MCPDeobfuscationTransformer", "loadCallback", "()V"));
|
||||
return ASMHelper.createBytes(cnode, 0);
|
||||
}
|
||||
|
||||
public static void loadCallback() {
|
||||
if (ObfMapping.obfuscated) {
|
||||
//move ourselves to the end
|
||||
// move ourselves to the end
|
||||
List<IClassTransformer> transformers = getTransformers();
|
||||
transformers.remove(instance);
|
||||
transformers.add(instance);
|
||||
} else {
|
||||
//remap access transformers
|
||||
for (IClassTransformer t : getTransformers())
|
||||
if (t instanceof AccessTransformer)
|
||||
remapAccessTransformer(t);
|
||||
// remap access transformers
|
||||
for (IClassTransformer t : getTransformers()) if (t instanceof AccessTransformer) remapAccessTransformer(t);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -207,10 +204,10 @@ public class MCPDeobfuscationTransformer implements IClassTransformer, Opcodes,
|
||||
name = name.replace('/', '.');
|
||||
try {
|
||||
byte[] bytes = Launch.classLoader.getClassBytes(name);
|
||||
if (bytes != null)
|
||||
return ObfuscationRun.getParents(ASMHelper.createClassNode(bytes));
|
||||
} catch (IOException ignored) {}
|
||||
//clear the miss cache because the library containing it might be loaded later
|
||||
if (bytes != null) return ObfuscationRun.getParents(ASMHelper.createClassNode(bytes));
|
||||
} catch (IOException ignored) {
|
||||
}
|
||||
// clear the miss cache because the library containing it might be loaded later
|
||||
Launch.classLoader.clearNegativeEntries(Collections.singleton(name));
|
||||
return null;
|
||||
}
|
||||
@@ -218,19 +215,15 @@ public class MCPDeobfuscationTransformer implements IClassTransformer, Opcodes,
|
||||
@Override
|
||||
public boolean isLibClass(ObfuscationEntry desc) {
|
||||
String name = desc.srg.s_owner;
|
||||
for (String p : excludedPackages)
|
||||
if (name.startsWith(p))
|
||||
return true;
|
||||
for (String p : excludedPackages) if (name.startsWith(p)) return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static String unmap(String name) {
|
||||
if (run == null)
|
||||
return null;
|
||||
if (run == null) return null;
|
||||
ObfuscationEntry e = run.obf.lookupMcpClass(name);
|
||||
if (e == null)
|
||||
return null;
|
||||
if (e == null) return null;
|
||||
return e.obf.s_owner;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
package codechicken.core.asm;
|
||||
|
||||
import static org.objectweb.asm.Opcodes.*;
|
||||
|
||||
import codechicken.lib.asm.ObfMapping;
|
||||
import java.io.File;
|
||||
import java.io.PrintWriter;
|
||||
|
||||
import net.minecraft.launchwrapper.Launch;
|
||||
import org.objectweb.asm.ClassReader;
|
||||
import org.objectweb.asm.ClassVisitor;
|
||||
@@ -10,13 +12,7 @@ import org.objectweb.asm.MethodVisitor;
|
||||
import org.objectweb.asm.util.Printer;
|
||||
import org.objectweb.asm.util.TraceMethodVisitor;
|
||||
|
||||
import codechicken.core.launch.CodeChickenCorePlugin;
|
||||
import codechicken.lib.asm.ObfMapping;
|
||||
|
||||
import static org.objectweb.asm.Opcodes.*;
|
||||
|
||||
public class MethodASMifier extends ClassVisitor
|
||||
{
|
||||
public class MethodASMifier extends ClassVisitor {
|
||||
PrintWriter printWriter;
|
||||
ObfMapping method;
|
||||
Printer asmifier;
|
||||
@@ -55,10 +51,8 @@ public class MethodASMifier extends ClassVisitor
|
||||
|
||||
public static void printMethod(ObfMapping method, byte[] bytes, Printer printer, File toFile) {
|
||||
try {
|
||||
if (!toFile.getParentFile().exists())
|
||||
toFile.getParentFile().mkdirs();
|
||||
if (!toFile.exists())
|
||||
toFile.createNewFile();
|
||||
if (!toFile.getParentFile().exists()) toFile.getParentFile().mkdirs();
|
||||
if (!toFile.exists()) toFile.createNewFile();
|
||||
|
||||
PrintWriter printWriter = new PrintWriter(toFile);
|
||||
|
||||
|
||||
@@ -1,23 +1,20 @@
|
||||
package codechicken.core.asm;
|
||||
|
||||
import static codechicken.lib.asm.InsnComparator.*;
|
||||
|
||||
import codechicken.lib.asm.*;
|
||||
import codechicken.lib.asm.ModularASMTransformer.MethodReplacer;
|
||||
import codechicken.lib.asm.ModularASMTransformer.MethodTransformer;
|
||||
import codechicken.lib.asm.ModularASMTransformer.MethodWriter;
|
||||
import codechicken.lib.config.ConfigTag;
|
||||
import java.util.Map;
|
||||
import net.minecraft.launchwrapper.IClassTransformer;
|
||||
import org.objectweb.asm.Opcodes;
|
||||
import org.objectweb.asm.tree.JumpInsnNode;
|
||||
import org.objectweb.asm.tree.LabelNode;
|
||||
import org.objectweb.asm.tree.MethodNode;
|
||||
|
||||
import codechicken.lib.config.ConfigTag;
|
||||
import net.minecraft.launchwrapper.IClassTransformer;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import static codechicken.lib.asm.InsnComparator.*;
|
||||
|
||||
public class TweakTransformer implements IClassTransformer, Opcodes
|
||||
{
|
||||
public class TweakTransformer implements IClassTransformer, Opcodes {
|
||||
static {
|
||||
ASMInit.init();
|
||||
}
|
||||
@@ -28,53 +25,71 @@ public class TweakTransformer implements IClassTransformer, Opcodes
|
||||
|
||||
public static void load() {
|
||||
CodeChickenCoreModContainer.loadConfig();
|
||||
tweaks = CodeChickenCoreModContainer.config.getTag("tweaks")
|
||||
.setComment("Various tweaks that can be applied to game mechanics.").useBraces();
|
||||
tweaks = CodeChickenCoreModContainer.config
|
||||
.getTag("tweaks")
|
||||
.setComment("Various tweaks that can be applied to game mechanics.")
|
||||
.useBraces();
|
||||
tweaks.removeTag("persistantLava");
|
||||
|
||||
if (tweaks.getTag("environmentallyFriendlyCreepers")
|
||||
.setComment("If set to true, creepers will not destroy landscape. (A version of mobGriefing setting just for creepers)")
|
||||
.setComment(
|
||||
"If set to true, creepers will not destroy landscape. (A version of mobGriefing setting just for creepers)")
|
||||
.getBooleanValue(false)) {
|
||||
transformer.add(new MethodReplacer(new ObfMapping("net/minecraft/entity/monster/EntityCreeper", "func_146077_cc", "()V"),
|
||||
blocks.get("d_environmentallyFriendlyCreepers"), blocks.get("environmentallyFriendlyCreepers")));
|
||||
transformer.add(new MethodReplacer(
|
||||
new ObfMapping("net/minecraft/entity/monster/EntityCreeper", "func_146077_cc", "()V"),
|
||||
blocks.get("d_environmentallyFriendlyCreepers"),
|
||||
blocks.get("environmentallyFriendlyCreepers")));
|
||||
}
|
||||
|
||||
if (!tweaks.getTag("softLeafReplace")
|
||||
.setComment("If set to false, leaves will only replace air when growing")
|
||||
.getBooleanValue(false)) {
|
||||
transformer.add(new MethodWriter(ACC_PUBLIC, new ObfMapping("net/minecraft/block/Block", "canBeReplacedByLeaves", "(Lnet/minecraft/world/IBlockAccess;III)Z"), blocks.get("softLeafReplace")));
|
||||
transformer.add(new MethodWriter(
|
||||
ACC_PUBLIC,
|
||||
new ObfMapping(
|
||||
"net/minecraft/block/Block",
|
||||
"canBeReplacedByLeaves",
|
||||
"(Lnet/minecraft/world/IBlockAccess;III)Z"),
|
||||
blocks.get("softLeafReplace")));
|
||||
}
|
||||
|
||||
if (tweaks.getTag("doFireTickOut")
|
||||
.setComment("If set to true and doFireTick is disabled in the game rules, fire will still dissipate if it's not over a fire source")
|
||||
.setComment(
|
||||
"If set to true and doFireTick is disabled in the game rules, fire will still dissipate if it's not over a fire source")
|
||||
.getBooleanValue(true)) {
|
||||
transformer.add(new MethodTransformer(new ObfMapping("net/minecraft/block/BlockFire", "func_149674_a", "(Lnet/minecraft/world/World;IIILjava/util/Random;)V"))
|
||||
{
|
||||
@Override
|
||||
public void transform(MethodNode mv) {
|
||||
ASMBlock needle = blocks.get("n_doFireTick");
|
||||
ASMBlock inject = blocks.get("doFireTick");
|
||||
transformer.add(
|
||||
new MethodTransformer(new ObfMapping(
|
||||
"net/minecraft/block/BlockFire",
|
||||
"func_149674_a",
|
||||
"(Lnet/minecraft/world/World;IIILjava/util/Random;)V")) {
|
||||
@Override
|
||||
public void transform(MethodNode mv) {
|
||||
ASMBlock needle = blocks.get("n_doFireTick");
|
||||
ASMBlock inject = blocks.get("doFireTick");
|
||||
|
||||
ASMBlock key = needle.applyLabels(findOnce(mv.instructions, needle.list));
|
||||
LabelNode jlabel = key.get("LRET");
|
||||
mv.instructions.insertBefore(jlabel, new JumpInsnNode(GOTO, inject.get("LSKIP")));
|
||||
mv.instructions.insert(jlabel, inject.list.list);
|
||||
}
|
||||
});
|
||||
ASMBlock key = needle.applyLabels(findOnce(mv.instructions, needle.list));
|
||||
LabelNode jlabel = key.get("LRET");
|
||||
mv.instructions.insertBefore(jlabel, new JumpInsnNode(GOTO, inject.get("LSKIP")));
|
||||
mv.instructions.insert(jlabel, inject.list.list);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (tweaks.getTag("finiteWater")
|
||||
.setComment("If set to true two adjacent water source blocks will not generate a third.")
|
||||
.getBooleanValue(false)) {
|
||||
transformer.add(new MethodTransformer(new ObfMapping("net/minecraft/block/BlockDynamicLiquid", "func_149674_a", "(Lnet/minecraft/world/World;IIILjava/util/Random;)V"))
|
||||
{
|
||||
@Override
|
||||
public void transform(MethodNode mv) {
|
||||
ASMBlock needle = blocks.get("finiteWater");
|
||||
ASMBlock key = needle.applyLabels(findOnce(mv.instructions, needle.list));
|
||||
mv.instructions.insertBefore(key.list.getFirst(), new JumpInsnNode(GOTO, key.get("LEND")));
|
||||
}
|
||||
});
|
||||
transformer.add(
|
||||
new MethodTransformer(new ObfMapping(
|
||||
"net/minecraft/block/BlockDynamicLiquid",
|
||||
"func_149674_a",
|
||||
"(Lnet/minecraft/world/World;IIILjava/util/Random;)V")) {
|
||||
@Override
|
||||
public void transform(MethodNode mv) {
|
||||
ASMBlock needle = blocks.get("finiteWater");
|
||||
ASMBlock key = needle.applyLabels(findOnce(mv.instructions, needle.list));
|
||||
mv.instructions.insertBefore(key.list.getFirst(), new JumpInsnNode(GOTO, key.get("LEND")));
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,25 +1,22 @@
|
||||
package codechicken.core.commands;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import codechicken.core.ServerUtils;
|
||||
import java.util.List;
|
||||
import net.minecraft.command.ICommand;
|
||||
import net.minecraft.command.ICommandSender;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.util.ChatComponentText;
|
||||
import net.minecraft.util.ChatComponentTranslation;
|
||||
import net.minecraft.util.ChunkCoordinates;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.command.ICommand;
|
||||
import net.minecraft.command.ICommandSender;
|
||||
import net.minecraft.util.IChatComponent;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.WorldServer;
|
||||
import net.minecraftforge.common.DimensionManager;
|
||||
|
||||
public abstract class CoreCommand implements ICommand
|
||||
{
|
||||
public class WCommandSender implements ICommandSender
|
||||
{
|
||||
public abstract class CoreCommand implements ICommand {
|
||||
public class WCommandSender implements ICommandSender {
|
||||
public ICommandSender wrapped;
|
||||
|
||||
public WCommandSender(ICommandSender sender) {
|
||||
@@ -78,15 +75,13 @@ public abstract class CoreCommand implements ICommand
|
||||
public void processCommand(ICommandSender listener, String[] args) {
|
||||
WCommandSender wsender = new WCommandSender(listener);
|
||||
|
||||
if (args.length < minimumParameters() ||
|
||||
args.length == 1 && args[0].equals("help")) {
|
||||
if (args.length < minimumParameters() || args.length == 1 && args[0].equals("help")) {
|
||||
printHelp(wsender);
|
||||
return;
|
||||
}
|
||||
|
||||
String command = getCommandName();
|
||||
for (String arg : args)
|
||||
command += " " + arg;
|
||||
for (String arg : args) command += " " + arg;
|
||||
|
||||
handleCommand(command, wsender.getCommandSenderName(), args, wsender);
|
||||
}
|
||||
@@ -131,15 +126,14 @@ public abstract class CoreCommand implements ICommand
|
||||
public boolean canCommandSenderUseCommand(ICommandSender var1) {
|
||||
if (OPOnly()) {
|
||||
if (var1 instanceof EntityPlayer)
|
||||
return MinecraftServer.getServer().getConfigurationManager().func_152596_g(((EntityPlayer) var1).getGameProfile());
|
||||
else if (var1 instanceof MinecraftServer)
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
return MinecraftServer.getServer()
|
||||
.getConfigurationManager()
|
||||
.func_152596_g(((EntityPlayer) var1).getGameProfile());
|
||||
else if (var1 instanceof MinecraftServer) return true;
|
||||
else return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
public abstract int minimumParameters();
|
||||
}
|
||||
@@ -1,60 +1,53 @@
|
||||
package codechicken.core.commands;
|
||||
|
||||
import net.minecraft.util.MovingObjectPosition.MovingObjectType;
|
||||
import net.minecraft.world.ChunkPosition;
|
||||
import net.minecraft.command.ICommandSender;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.command.ICommandSender;
|
||||
import net.minecraft.util.MovingObjectPosition;
|
||||
import net.minecraft.util.MovingObjectPosition.MovingObjectType;
|
||||
import net.minecraft.util.Vec3;
|
||||
import net.minecraft.world.ChunkPosition;
|
||||
import net.minecraft.world.WorldServer;
|
||||
|
||||
public abstract class PlayerCommand extends CoreCommand
|
||||
{
|
||||
public abstract class PlayerCommand extends CoreCommand {
|
||||
@Override
|
||||
public boolean canCommandSenderUseCommand(ICommandSender var1)
|
||||
{
|
||||
if(!super.canCommandSenderUseCommand(var1))
|
||||
return false;
|
||||
public boolean canCommandSenderUseCommand(ICommandSender var1) {
|
||||
if (!super.canCommandSenderUseCommand(var1)) return false;
|
||||
return var1 instanceof EntityPlayer;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public void handleCommand(String command, String playername, String[] args, WCommandSender listener)
|
||||
{
|
||||
EntityPlayerMP player = (EntityPlayerMP)listener.wrapped;
|
||||
public void handleCommand(String command, String playername, String[] args, WCommandSender listener) {
|
||||
EntityPlayerMP player = (EntityPlayerMP) listener.wrapped;
|
||||
handleCommand(getWorld(player), player, args);
|
||||
}
|
||||
|
||||
|
||||
public abstract void handleCommand(WorldServer world, EntityPlayerMP player, String[] args);
|
||||
|
||||
public ChunkPosition getPlayerLookingAtBlock(EntityPlayerMP player, float reach)
|
||||
{
|
||||
Vec3 vec3d = Vec3.createVectorHelper(player.posX, (player.posY + 1.6200000000000001D) - player.yOffset, player.posZ);
|
||||
|
||||
public ChunkPosition getPlayerLookingAtBlock(EntityPlayerMP player, float reach) {
|
||||
Vec3 vec3d =
|
||||
Vec3.createVectorHelper(player.posX, (player.posY + 1.6200000000000001D) - player.yOffset, player.posZ);
|
||||
Vec3 vec3d1 = player.getLook(1.0F);
|
||||
Vec3 vec3d2 = vec3d.addVector(vec3d1.xCoord * reach, vec3d1.yCoord * reach, vec3d1.zCoord * reach);
|
||||
MovingObjectPosition hit = player.worldObj.rayTraceBlocks(vec3d, vec3d2);
|
||||
if(hit == null || hit.typeOfHit != MovingObjectType.BLOCK)
|
||||
{
|
||||
if (hit == null || hit.typeOfHit != MovingObjectType.BLOCK) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
return new ChunkPosition(hit.blockX, hit.blockY, hit.blockZ);
|
||||
}
|
||||
|
||||
public Entity getPlayerLookingAtEntity(EntityPlayerMP player, float reach)
|
||||
{
|
||||
Vec3 vec3d = Vec3.createVectorHelper(player.posX, (player.posY + 1.6200000000000001D) - player.yOffset, player.posZ);
|
||||
|
||||
public Entity getPlayerLookingAtEntity(EntityPlayerMP player, float reach) {
|
||||
Vec3 vec3d =
|
||||
Vec3.createVectorHelper(player.posX, (player.posY + 1.6200000000000001D) - player.yOffset, player.posZ);
|
||||
Vec3 vec3d1 = player.getLook(1.0F);
|
||||
Vec3 vec3d2 = vec3d.addVector(vec3d1.xCoord * reach, vec3d1.yCoord * reach, vec3d1.zCoord * reach);
|
||||
MovingObjectPosition hit = player.worldObj.rayTraceBlocks(vec3d, vec3d2);
|
||||
if(hit == null || hit.typeOfHit != MovingObjectType.ENTITY)
|
||||
{
|
||||
if (hit == null || hit.typeOfHit != MovingObjectType.ENTITY) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
return hit.entityHit;
|
||||
}
|
||||
}
|
||||
@@ -1,28 +1,23 @@
|
||||
package codechicken.core.commands;
|
||||
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.command.ICommandSender;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
|
||||
public abstract class ServerCommand extends CoreCommand
|
||||
{
|
||||
public abstract class ServerCommand extends CoreCommand {
|
||||
@Override
|
||||
public void processCommand(ICommandSender var1, String[] var2)
|
||||
{
|
||||
handleCommand(var2, (MinecraftServer)var1);
|
||||
public void processCommand(ICommandSender var1, String[] var2) {
|
||||
handleCommand(var2, (MinecraftServer) var1);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean canCommandSenderUseCommand(ICommandSender var1)
|
||||
{
|
||||
if(!super.canCommandSenderUseCommand(var1))
|
||||
return false;
|
||||
public boolean canCommandSenderUseCommand(ICommandSender var1) {
|
||||
if (!super.canCommandSenderUseCommand(var1)) return false;
|
||||
return var1 instanceof MinecraftServer;
|
||||
}
|
||||
|
||||
|
||||
public abstract void handleCommand(String[] args, MinecraftServer listener);
|
||||
|
||||
public final boolean OPOnly()
|
||||
{
|
||||
public final boolean OPOnly() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4,10 +4,8 @@ import net.minecraft.entity.Entity;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class EntityRenderHook extends Entity
|
||||
{
|
||||
public static interface IRenderCallback
|
||||
{
|
||||
public class EntityRenderHook extends Entity {
|
||||
public static interface IRenderCallback {
|
||||
public void render(float frame, int pass);
|
||||
|
||||
public boolean shouldRenderInPass(int pass);
|
||||
@@ -26,21 +24,17 @@ public class EntityRenderHook extends Entity
|
||||
|
||||
@Override
|
||||
public void onUpdate() {
|
||||
if (!callback.isValid())
|
||||
setDead();
|
||||
if (!callback.isValid()) setDead();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void entityInit() {
|
||||
}
|
||||
protected void entityInit() {}
|
||||
|
||||
@Override
|
||||
protected void readEntityFromNBT(NBTTagCompound var1) {
|
||||
}
|
||||
protected void readEntityFromNBT(NBTTagCompound var1) {}
|
||||
|
||||
@Override
|
||||
protected void writeEntityToNBT(NBTTagCompound var1) {
|
||||
}
|
||||
protected void writeEntityToNBT(NBTTagCompound var1) {}
|
||||
|
||||
@Override
|
||||
public boolean shouldRenderInPass(int pass) {
|
||||
|
||||
@@ -4,44 +4,33 @@ import net.minecraft.entity.Entity;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class EntityUpdateHook extends Entity
|
||||
{
|
||||
public static interface IUpdateCallback
|
||||
{
|
||||
public class EntityUpdateHook extends Entity {
|
||||
public static interface IUpdateCallback {
|
||||
public void onUpdate();
|
||||
|
||||
public boolean isValid();
|
||||
}
|
||||
|
||||
|
||||
public final IUpdateCallback callback;
|
||||
public EntityUpdateHook(World world, int x, int y, int z, IUpdateCallback callback)
|
||||
{
|
||||
|
||||
public EntityUpdateHook(World world, int x, int y, int z, IUpdateCallback callback) {
|
||||
super(world);
|
||||
setPosition(x, y, z);
|
||||
this.callback = callback;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUpdate()
|
||||
{
|
||||
if(!callback.isValid())
|
||||
setDead();
|
||||
else
|
||||
callback.onUpdate();
|
||||
public void onUpdate() {
|
||||
if (!callback.isValid()) setDead();
|
||||
else callback.onUpdate();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void entityInit()
|
||||
{
|
||||
}
|
||||
protected void entityInit() {}
|
||||
|
||||
@Override
|
||||
protected void readEntityFromNBT(NBTTagCompound var1)
|
||||
{
|
||||
}
|
||||
protected void readEntityFromNBT(NBTTagCompound var1) {}
|
||||
|
||||
@Override
|
||||
protected void writeEntityToNBT(NBTTagCompound var1)
|
||||
{
|
||||
}
|
||||
protected void writeEntityToNBT(NBTTagCompound var1) {}
|
||||
}
|
||||
@@ -5,34 +5,27 @@ import cpw.mods.fml.common.FMLCommonHandler;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
public class FeatureHack
|
||||
{
|
||||
public class FeatureHack {
|
||||
private static boolean updateHookEnabled = false;
|
||||
private static boolean renderHookEnabled = false;
|
||||
|
||||
public static void enableUpdateHook()
|
||||
{
|
||||
if(updateHookEnabled)
|
||||
return;
|
||||
|
||||
|
||||
public static void enableUpdateHook() {
|
||||
if (updateHookEnabled) return;
|
||||
|
||||
updateHookEnabled = true;
|
||||
if(FMLCommonHandler.instance().getSide().isClient())
|
||||
enableClientUpdateHook();
|
||||
if (FMLCommonHandler.instance().getSide().isClient()) enableClientUpdateHook();
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public static void enableRenderHook()
|
||||
{
|
||||
if(renderHookEnabled)
|
||||
return;
|
||||
|
||||
public static void enableRenderHook() {
|
||||
if (renderHookEnabled) return;
|
||||
|
||||
renderHookEnabled = true;
|
||||
RenderingRegistry.registerEntityRenderingHandler(EntityUpdateHook.class, new RenderNull());
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
private static void enableClientUpdateHook()
|
||||
{
|
||||
private static void enableClientUpdateHook() {
|
||||
RenderingRegistry.registerEntityRenderingHandler(EntityRenderHook.class, new RenderEntityRenderHook());
|
||||
}
|
||||
}
|
||||
@@ -1,27 +1,30 @@
|
||||
package codechicken.core.featurehack;
|
||||
|
||||
import codechicken.lib.asm.ObfMapping;
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.Map;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.util.ObjectIntIdentityMap;
|
||||
import net.minecraft.util.RegistryNamespaced;
|
||||
import net.minecraft.util.RegistrySimple;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.Map;
|
||||
|
||||
public class GameDataManipulator
|
||||
{
|
||||
public class GameDataManipulator {
|
||||
public static Field f_registryObjects;
|
||||
public static Field f_underlyingIntegerMap;
|
||||
|
||||
static
|
||||
{
|
||||
static {
|
||||
try {
|
||||
f_registryObjects = RegistrySimple.class.getDeclaredField(
|
||||
new ObfMapping("net/minecraft/util/RegistrySimple", "field_82596_a", "Ljava/util/Map;").toRuntime().s_name);
|
||||
new ObfMapping("net/minecraft/util/RegistrySimple", "field_82596_a", "Ljava/util/Map;")
|
||||
.toRuntime()
|
||||
.s_name);
|
||||
f_registryObjects.setAccessible(true);
|
||||
f_underlyingIntegerMap = RegistryNamespaced.class.getDeclaredField(
|
||||
new ObfMapping("net/minecraft/util/RegistryNamespaced", "field_148759_a", "Lnet/minecraft/util/ObjectIntIdentityMap;").toRuntime().s_name);
|
||||
f_underlyingIntegerMap = RegistryNamespaced.class.getDeclaredField(new ObfMapping(
|
||||
"net/minecraft/util/RegistryNamespaced",
|
||||
"field_148759_a",
|
||||
"Lnet/minecraft/util/ObjectIntIdentityMap;")
|
||||
.toRuntime()
|
||||
.s_name);
|
||||
f_underlyingIntegerMap.setAccessible(true);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
@@ -31,8 +34,8 @@ public class GameDataManipulator
|
||||
public static void replaceItem(int id, Item item) {
|
||||
try {
|
||||
String name = Item.itemRegistry.getNameForObject(Item.getItemById(id));
|
||||
((Map)f_registryObjects.get(Item.itemRegistry)).put(name, item);
|
||||
((ObjectIntIdentityMap)f_underlyingIntegerMap.get(Item.itemRegistry)).func_148746_a(item, id);
|
||||
((Map) f_registryObjects.get(Item.itemRegistry)).put(name, item);
|
||||
((ObjectIntIdentityMap) f_underlyingIntegerMap.get(Item.itemRegistry)).func_148746_a(item, id);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
@@ -1,58 +1,56 @@
|
||||
package codechicken.core.featurehack;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import codechicken.core.ReflectionManager;
|
||||
import codechicken.core.asm.TweakTransformer;
|
||||
import codechicken.core.featurehack.mc.TextureLavaFX;
|
||||
import codechicken.core.featurehack.mc.TextureLavaFlowFX;
|
||||
import codechicken.core.featurehack.mc.TextureWaterFX;
|
||||
import codechicken.core.featurehack.mc.TextureWaterFlowFX;
|
||||
import codechicken.lib.asm.ObfMapping;
|
||||
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
||||
import net.minecraft.block.Block;
|
||||
import java.lang.reflect.Field;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.util.IIcon;
|
||||
import net.minecraftforge.client.event.TextureStitchEvent;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
|
||||
import codechicken.core.asm.TweakTransformer;
|
||||
import codechicken.lib.asm.ObfMapping;
|
||||
|
||||
public class LiquidTextures
|
||||
{
|
||||
public class LiquidTextures {
|
||||
public static IIcon[] newTextures = new IIcon[4];
|
||||
|
||||
|
||||
public static boolean replaceLava;
|
||||
public static boolean replaceWater;
|
||||
|
||||
|
||||
private static Field field_tex;
|
||||
|
||||
public static void init()
|
||||
{
|
||||
replaceWater = TweakTransformer.tweaks.getTag("replaceWaterFX").setComment("Set this to true to use the pre1.5 water textures").getBooleanValue(false);
|
||||
replaceLava = TweakTransformer.tweaks.getTag("replaceLavaFX").setComment("Set this to true to use the pre1.5 lava textures").getBooleanValue(false);
|
||||
if(replaceWater)
|
||||
{
|
||||
|
||||
public static void init() {
|
||||
replaceWater = TweakTransformer.tweaks
|
||||
.getTag("replaceWaterFX")
|
||||
.setComment("Set this to true to use the pre1.5 water textures")
|
||||
.getBooleanValue(false);
|
||||
replaceLava = TweakTransformer.tweaks
|
||||
.getTag("replaceLavaFX")
|
||||
.setComment("Set this to true to use the pre1.5 lava textures")
|
||||
.getBooleanValue(false);
|
||||
if (replaceWater) {
|
||||
newTextures[0] = new TextureWaterFX().texture;
|
||||
newTextures[1] = new TextureWaterFlowFX().texture;
|
||||
}
|
||||
if(replaceLava)
|
||||
{
|
||||
if (replaceLava) {
|
||||
newTextures[2] = new TextureLavaFX().texture;
|
||||
newTextures[3] = new TextureLavaFlowFX().texture;
|
||||
}
|
||||
|
||||
if(replaceWater || replaceLava)
|
||||
{
|
||||
|
||||
if (replaceWater || replaceLava) {
|
||||
MinecraftForge.EVENT_BUS.register(new LiquidTextures());
|
||||
field_tex = ReflectionManager.getField(new ObfMapping("net/minecraft/block/BlockLiquid", "field_149806_a", "[Lnet/minecraft/util/IIcon;"));
|
||||
field_tex = ReflectionManager.getField(
|
||||
new ObfMapping("net/minecraft/block/BlockLiquid", "field_149806_a", "[Lnet/minecraft/util/IIcon;"));
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void postStitch(TextureStitchEvent.Post event)
|
||||
{
|
||||
public void postStitch(TextureStitchEvent.Post event) {
|
||||
IIcon[] icons;
|
||||
if(replaceLava)
|
||||
{
|
||||
if (replaceLava) {
|
||||
icons = ReflectionManager.get(field_tex, IIcon[].class, Blocks.flowing_lava);
|
||||
icons[0] = newTextures[2];
|
||||
icons[1] = newTextures[3];
|
||||
@@ -60,8 +58,7 @@ public class LiquidTextures
|
||||
icons[0] = newTextures[2];
|
||||
icons[1] = newTextures[3];
|
||||
}
|
||||
if(replaceWater)
|
||||
{
|
||||
if (replaceWater) {
|
||||
icons = ReflectionManager.get(field_tex, IIcon[].class, Blocks.flowing_water);
|
||||
icons[0] = newTextures[0];
|
||||
icons[1] = newTextures[1];
|
||||
|
||||
@@ -1,26 +1,22 @@
|
||||
package codechicken.core.featurehack;
|
||||
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import net.minecraft.client.renderer.entity.Render;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.client.renderer.entity.Render;
|
||||
import net.minecraftforge.client.MinecraftForgeClient;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
public class RenderEntityRenderHook extends Render
|
||||
{
|
||||
public class RenderEntityRenderHook extends Render {
|
||||
@Override
|
||||
public void doRender(Entity entity, double x, double y, double z, float f, float frame)
|
||||
{
|
||||
EntityRenderHook hook = (EntityRenderHook)entity;
|
||||
GL11.glTranslated(x-hook.posX, y-hook.posY, z-hook.posZ);
|
||||
((EntityRenderHook)entity).callback.render(frame, MinecraftForgeClient.getRenderPass());
|
||||
GL11.glTranslated(hook.posX-x, hook.posY-y, hook.posZ-z);
|
||||
public void doRender(Entity entity, double x, double y, double z, float f, float frame) {
|
||||
EntityRenderHook hook = (EntityRenderHook) entity;
|
||||
GL11.glTranslated(x - hook.posX, y - hook.posY, z - hook.posZ);
|
||||
((EntityRenderHook) entity).callback.render(frame, MinecraftForgeClient.getRenderPass());
|
||||
GL11.glTranslated(hook.posX - x, hook.posY - y, hook.posZ - z);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ResourceLocation getEntityTexture(Entity entity)
|
||||
{
|
||||
protected ResourceLocation getEntityTexture(Entity entity) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -4,16 +4,12 @@ import net.minecraft.client.renderer.entity.Render;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
|
||||
public class RenderNull extends Render
|
||||
{
|
||||
public class RenderNull extends Render {
|
||||
@Override
|
||||
public void doRender(Entity var1, double var2, double var4, double var6, float var8, float var9)
|
||||
{
|
||||
}
|
||||
|
||||
public void doRender(Entity var1, double var2, double var4, double var6, float var8, float var9) {}
|
||||
|
||||
@Override
|
||||
protected ResourceLocation getEntityTexture(Entity entity)
|
||||
{
|
||||
protected ResourceLocation getEntityTexture(Entity entity) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -1,38 +1,37 @@
|
||||
package codechicken.core.featurehack;
|
||||
|
||||
import java.util.Random;
|
||||
import static net.minecraftforge.common.util.ForgeDirection.UP;
|
||||
|
||||
import java.util.Random;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import static net.minecraftforge.common.util.ForgeDirection.UP;
|
||||
|
||||
public class TweakTransformerHelper
|
||||
{
|
||||
public static void quenchFireTick(World world, int x, int y, int z, Random rand)
|
||||
{
|
||||
public class TweakTransformerHelper {
|
||||
public static void quenchFireTick(World world, int x, int y, int z, Random rand) {
|
||||
Block base = world.getBlock(x, y - 1, z);
|
||||
boolean supported = (base != null && base.isFireSource(world, x, y - 1, z, UP));
|
||||
|
||||
if (!Blocks.fire.canPlaceBlockAt(world, x, y, z) ||
|
||||
!supported && world.isRaining() && (world.canLightningStrikeAt(x, y, z) || world.canLightningStrikeAt(x - 1, y, z) || world.canLightningStrikeAt(x + 1, y, z) || world.canLightningStrikeAt(x, y, z - 1) || world.canLightningStrikeAt(x, y, z + 1)))
|
||||
world.setBlockToAir(x, y, z);
|
||||
else
|
||||
{
|
||||
|
||||
if (!Blocks.fire.canPlaceBlockAt(world, x, y, z)
|
||||
|| !supported
|
||||
&& world.isRaining()
|
||||
&& (world.canLightningStrikeAt(x, y, z)
|
||||
|| world.canLightningStrikeAt(x - 1, y, z)
|
||||
|| world.canLightningStrikeAt(x + 1, y, z)
|
||||
|| world.canLightningStrikeAt(x, y, z - 1)
|
||||
|| world.canLightningStrikeAt(x, y, z + 1))) world.setBlockToAir(x, y, z);
|
||||
else {
|
||||
int meta = world.getBlockMetadata(x, y, z);
|
||||
if(meta < 15)
|
||||
world.setBlockMetadataWithNotify(x, y, z, meta+rand.nextInt(3)/2, 0);
|
||||
|
||||
if (meta < 15) world.setBlockMetadataWithNotify(x, y, z, meta + rand.nextInt(3) / 2, 0);
|
||||
|
||||
world.scheduleBlockUpdate(x, y, z, Blocks.fire, Blocks.fire.tickRate(world) + rand.nextInt(10));
|
||||
|
||||
if(!supported && !Blocks.fire.canCatchFire(world, x, y - 1, z, UP) && meta == 15 && rand.nextInt(4) == 0)
|
||||
|
||||
if (!supported && !Blocks.fire.canCatchFire(world, x, y - 1, z, UP) && meta == 15 && rand.nextInt(4) == 0)
|
||||
world.setBlockToAir(x, y, z);
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean canPlaceBlockAt(World world, int x, int y, int z)
|
||||
{
|
||||
|
||||
public static boolean canPlaceBlockAt(World world, int x, int y, int z) {
|
||||
Block block = world.getBlock(x, y, z);
|
||||
return block.isAir(world, x, y, z) || block.isReplaceable(world, x, y, z);
|
||||
}
|
||||
|
||||
@@ -7,22 +7,19 @@ import cpw.mods.fml.relauncher.SideOnly;
|
||||
import net.minecraft.util.MathHelper;
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public class TextureLavaFX extends TextureFX
|
||||
{
|
||||
public class TextureLavaFX extends TextureFX {
|
||||
protected float[] field_76876_g = new float[256];
|
||||
protected float[] field_76878_h = new float[256];
|
||||
protected float[] field_76879_i = new float[256];
|
||||
protected float[] field_76877_j = new float[256];
|
||||
|
||||
public TextureLavaFX()
|
||||
{
|
||||
public TextureLavaFX() {
|
||||
super(16, "lava_still_fx");
|
||||
setup();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setup()
|
||||
{
|
||||
public void setup() {
|
||||
super.setup();
|
||||
field_76876_g = new float[tileSizeSquare];
|
||||
field_76878_h = new float[tileSizeSquare];
|
||||
@@ -30,8 +27,7 @@ public class TextureLavaFX extends TextureFX
|
||||
field_76877_j = new float[tileSizeSquare];
|
||||
}
|
||||
|
||||
public void onTick()
|
||||
{
|
||||
public void onTick() {
|
||||
int var2;
|
||||
float var3;
|
||||
int var5;
|
||||
@@ -40,36 +36,40 @@ public class TextureLavaFX extends TextureFX
|
||||
int var8;
|
||||
int var9;
|
||||
|
||||
for (int var1 = 0; var1 < tileSizeBase; ++var1)
|
||||
{
|
||||
for (var2 = 0; var2 < tileSizeBase; ++var2)
|
||||
{
|
||||
for (int var1 = 0; var1 < tileSizeBase; ++var1) {
|
||||
for (var2 = 0; var2 < tileSizeBase; ++var2) {
|
||||
var3 = 0.0F;
|
||||
int var4 = (int)(MathHelper.sin(var2 * (float)Math.PI * 2.0F / 16.0F) * 1.2F);
|
||||
var5 = (int)(MathHelper.sin(var1 * (float)Math.PI * 2.0F / 16.0F) * 1.2F);
|
||||
int var4 = (int) (MathHelper.sin(var2 * (float) Math.PI * 2.0F / 16.0F) * 1.2F);
|
||||
var5 = (int) (MathHelper.sin(var1 * (float) Math.PI * 2.0F / 16.0F) * 1.2F);
|
||||
|
||||
for (var6 = var1 - 1; var6 <= var1 + 1; ++var6)
|
||||
{
|
||||
for (var7 = var2 - 1; var7 <= var2 + 1; ++var7)
|
||||
{
|
||||
for (var6 = var1 - 1; var6 <= var1 + 1; ++var6) {
|
||||
for (var7 = var2 - 1; var7 <= var2 + 1; ++var7) {
|
||||
var8 = var6 + var4 & tileSizeMask;
|
||||
var9 = var7 + var5 & tileSizeMask;
|
||||
var3 += this.field_76876_g[var8 + var9 * tileSizeBase];
|
||||
}
|
||||
}
|
||||
|
||||
this.field_76878_h[var1 + var2 * tileSizeBase] = var3 / 10.0F + (this.field_76879_i[(var1 + 0 & tileSizeMask) + (var2 + 0 & tileSizeMask) * tileSizeBase] + this.field_76879_i[(var1 + 1 & tileSizeMask) + (var2 + 0 & tileSizeMask) * tileSizeBase] + this.field_76879_i[(var1 + 1 & tileSizeMask) + (var2 + 1 & tileSizeMask) * tileSizeBase] + this.field_76879_i[(var1 + 0 & tileSizeMask) + (var2 + 1 & tileSizeMask) * tileSizeBase]) / 4.0F * 0.8F;
|
||||
this.field_76879_i[var1 + var2 * tileSizeBase] += this.field_76877_j[var1 + var2 * tileSizeBase] * 0.01F;
|
||||
this.field_76878_h[var1 + var2 * tileSizeBase] = var3 / 10.0F
|
||||
+ (this.field_76879_i[(var1 + 0 & tileSizeMask) + (var2 + 0 & tileSizeMask) * tileSizeBase]
|
||||
+ this.field_76879_i[
|
||||
(var1 + 1 & tileSizeMask) + (var2 + 0 & tileSizeMask) * tileSizeBase]
|
||||
+ this.field_76879_i[
|
||||
(var1 + 1 & tileSizeMask) + (var2 + 1 & tileSizeMask) * tileSizeBase]
|
||||
+ this.field_76879_i[
|
||||
(var1 + 0 & tileSizeMask) + (var2 + 1 & tileSizeMask) * tileSizeBase])
|
||||
/ 4.0F
|
||||
* 0.8F;
|
||||
this.field_76879_i[var1 + var2 * tileSizeBase] +=
|
||||
this.field_76877_j[var1 + var2 * tileSizeBase] * 0.01F;
|
||||
|
||||
if (this.field_76879_i[var1 + var2 * tileSizeBase] < 0.0F)
|
||||
{
|
||||
if (this.field_76879_i[var1 + var2 * tileSizeBase] < 0.0F) {
|
||||
this.field_76879_i[var1 + var2 * tileSizeBase] = 0.0F;
|
||||
}
|
||||
|
||||
this.field_76877_j[var1 + var2 * tileSizeBase] -= 0.06F;
|
||||
|
||||
if (Math.random() < 0.005D)
|
||||
{
|
||||
if (Math.random() < 0.005D) {
|
||||
this.field_76877_j[var1 + var2 * tileSizeBase] = 1.5F;
|
||||
}
|
||||
}
|
||||
@@ -79,26 +79,22 @@ public class TextureLavaFX extends TextureFX
|
||||
this.field_76878_h = this.field_76876_g;
|
||||
this.field_76876_g = var11;
|
||||
|
||||
for (var2 = 0; var2 < tileSizeSquare; ++var2)
|
||||
{
|
||||
for (var2 = 0; var2 < tileSizeSquare; ++var2) {
|
||||
var3 = this.field_76876_g[var2] * 2.0F;
|
||||
|
||||
if (var3 > 1.0F)
|
||||
{
|
||||
if (var3 > 1.0F) {
|
||||
var3 = 1.0F;
|
||||
}
|
||||
|
||||
if (var3 < 0.0F)
|
||||
{
|
||||
if (var3 < 0.0F) {
|
||||
var3 = 0.0F;
|
||||
}
|
||||
|
||||
var5 = (int)(var3 * 100.0F + 155.0F);
|
||||
var6 = (int)(var3 * var3 * 255.0F);
|
||||
var7 = (int)(var3 * var3 * var3 * var3 * 128.0F);
|
||||
var5 = (int) (var3 * 100.0F + 155.0F);
|
||||
var6 = (int) (var3 * var3 * 255.0F);
|
||||
var7 = (int) (var3 * var3 * var3 * var3 * 128.0F);
|
||||
|
||||
if (this.anaglyphEnabled)
|
||||
{
|
||||
if (this.anaglyphEnabled) {
|
||||
var8 = (var5 * 30 + var6 * 59 + var7 * 11) / 100;
|
||||
var9 = (var5 * 30 + var6 * 70) / 100;
|
||||
int var10 = (var5 * 30 + var7 * 70) / 100;
|
||||
|
||||
@@ -7,28 +7,25 @@ import cpw.mods.fml.relauncher.SideOnly;
|
||||
import net.minecraft.util.MathHelper;
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public class TextureLavaFlowFX extends TextureFX
|
||||
{
|
||||
public class TextureLavaFlowFX extends TextureFX {
|
||||
protected float[] field_76871_g = new float[256];
|
||||
protected float[] field_76874_h = new float[256];
|
||||
protected float[] field_76875_i = new float[256];
|
||||
protected float[] field_76872_j = new float[256];
|
||||
int field_76873_k = 0;
|
||||
|
||||
//shadow
|
||||
// shadow
|
||||
public int tileSizeBase = 16;
|
||||
public int tileSizeSquare = 256;
|
||||
public int tileSizeMask = 15;
|
||||
public int tileSizeSquareMask = 255;
|
||||
|
||||
public TextureLavaFlowFX()
|
||||
{
|
||||
public TextureLavaFlowFX() {
|
||||
super(32, "lava_flow_fx");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setup()
|
||||
{
|
||||
public void setup() {
|
||||
super.setup();
|
||||
field_76871_g = new float[tileSizeSquare];
|
||||
field_76874_h = new float[tileSizeSquare];
|
||||
@@ -37,8 +34,7 @@ public class TextureLavaFlowFX extends TextureFX
|
||||
field_76873_k = 0;
|
||||
}
|
||||
|
||||
public void onTick()
|
||||
{
|
||||
public void onTick() {
|
||||
++this.field_76873_k;
|
||||
int var2;
|
||||
float var3;
|
||||
@@ -48,36 +44,40 @@ public class TextureLavaFlowFX extends TextureFX
|
||||
int var8;
|
||||
int var9;
|
||||
|
||||
for (int var1 = 0; var1 < tileSizeBase; ++var1)
|
||||
{
|
||||
for (var2 = 0; var2 < tileSizeBase; ++var2)
|
||||
{
|
||||
for (int var1 = 0; var1 < tileSizeBase; ++var1) {
|
||||
for (var2 = 0; var2 < tileSizeBase; ++var2) {
|
||||
var3 = 0.0F;
|
||||
int var4 = (int)(MathHelper.sin(var2 * (float)Math.PI * 2.0F / 16.0F) * 1.2F);
|
||||
var5 = (int)(MathHelper.sin(var1 * (float)Math.PI * 2.0F / 16.0F) * 1.2F);
|
||||
int var4 = (int) (MathHelper.sin(var2 * (float) Math.PI * 2.0F / 16.0F) * 1.2F);
|
||||
var5 = (int) (MathHelper.sin(var1 * (float) Math.PI * 2.0F / 16.0F) * 1.2F);
|
||||
|
||||
for (var6 = var1 - 1; var6 <= var1 + 1; ++var6)
|
||||
{
|
||||
for (var7 = var2 - 1; var7 <= var2 + 1; ++var7)
|
||||
{
|
||||
for (var6 = var1 - 1; var6 <= var1 + 1; ++var6) {
|
||||
for (var7 = var2 - 1; var7 <= var2 + 1; ++var7) {
|
||||
var8 = var6 + var4 & tileSizeMask;
|
||||
var9 = var7 + var5 & tileSizeMask;
|
||||
var3 += this.field_76871_g[var8 + var9 * tileSizeBase];
|
||||
}
|
||||
}
|
||||
|
||||
this.field_76874_h[var1 + var2 * tileSizeBase] = var3 / 10.0F + (this.field_76875_i[(var1 + 0 & tileSizeMask) + (var2 + 0 & tileSizeMask) * tileSizeBase] + this.field_76875_i[(var1 + 1 & tileSizeMask) + (var2 + 0 & tileSizeMask) * tileSizeBase] + this.field_76875_i[(var1 + 1 & tileSizeMask) + (var2 + 1 & tileSizeMask) * tileSizeBase] + this.field_76875_i[(var1 + 0 & tileSizeMask) + (var2 + 1 & tileSizeMask) * tileSizeBase]) / 4.0F * 0.8F;
|
||||
this.field_76875_i[var1 + var2 * tileSizeBase] += this.field_76872_j[var1 + var2 * tileSizeBase] * 0.01F;
|
||||
this.field_76874_h[var1 + var2 * tileSizeBase] = var3 / 10.0F
|
||||
+ (this.field_76875_i[(var1 + 0 & tileSizeMask) + (var2 + 0 & tileSizeMask) * tileSizeBase]
|
||||
+ this.field_76875_i[
|
||||
(var1 + 1 & tileSizeMask) + (var2 + 0 & tileSizeMask) * tileSizeBase]
|
||||
+ this.field_76875_i[
|
||||
(var1 + 1 & tileSizeMask) + (var2 + 1 & tileSizeMask) * tileSizeBase]
|
||||
+ this.field_76875_i[
|
||||
(var1 + 0 & tileSizeMask) + (var2 + 1 & tileSizeMask) * tileSizeBase])
|
||||
/ 4.0F
|
||||
* 0.8F;
|
||||
this.field_76875_i[var1 + var2 * tileSizeBase] +=
|
||||
this.field_76872_j[var1 + var2 * tileSizeBase] * 0.01F;
|
||||
|
||||
if (this.field_76875_i[var1 + var2 * tileSizeBase] < 0.0F)
|
||||
{
|
||||
if (this.field_76875_i[var1 + var2 * tileSizeBase] < 0.0F) {
|
||||
this.field_76875_i[var1 + var2 * tileSizeBase] = 0.0F;
|
||||
}
|
||||
|
||||
this.field_76872_j[var1 + var2 * tileSizeBase] -= 0.06F;
|
||||
|
||||
if (Math.random() < 0.005D)
|
||||
{
|
||||
if (Math.random() < 0.005D) {
|
||||
this.field_76872_j[var1 + var2 * tileSizeBase] = 1.5F;
|
||||
}
|
||||
}
|
||||
@@ -87,26 +87,22 @@ public class TextureLavaFlowFX extends TextureFX
|
||||
this.field_76874_h = this.field_76871_g;
|
||||
this.field_76871_g = var11;
|
||||
|
||||
for (var2 = 0; var2 < tileSizeSquare; ++var2)
|
||||
{
|
||||
for (var2 = 0; var2 < tileSizeSquare; ++var2) {
|
||||
var3 = this.field_76871_g[(var2 - this.field_76873_k / 3 * tileSizeBase) & tileSizeSquareMask] * 2.0F;
|
||||
|
||||
if (var3 > 1.0F)
|
||||
{
|
||||
if (var3 > 1.0F) {
|
||||
var3 = 1.0F;
|
||||
}
|
||||
|
||||
if (var3 < 0.0F)
|
||||
{
|
||||
if (var3 < 0.0F) {
|
||||
var3 = 0.0F;
|
||||
}
|
||||
|
||||
var5 = (int)(var3 * 100.0F + 155.0F);
|
||||
var6 = (int)(var3 * var3 * 255.0F);
|
||||
var7 = (int)(var3 * var3 * var3 * var3 * 128.0F);
|
||||
var5 = (int) (var3 * 100.0F + 155.0F);
|
||||
var6 = (int) (var3 * var3 * 255.0F);
|
||||
var7 = (int) (var3 * var3 * var3 * var3 * 128.0F);
|
||||
|
||||
if (this.anaglyphEnabled)
|
||||
{
|
||||
if (this.anaglyphEnabled) {
|
||||
var8 = (var5 * 30 + var6 * 59 + var7 * 11) / 100;
|
||||
var9 = (var5 * 30 + var6 * 70) / 100;
|
||||
int var10 = (var5 * 30 + var7 * 70) / 100;
|
||||
@@ -115,17 +111,16 @@ public class TextureLavaFlowFX extends TextureFX
|
||||
var7 = var10;
|
||||
}
|
||||
|
||||
int px = var2&tileSizeMask;
|
||||
int py = var2/tileSizeBase;
|
||||
int px = var2 & tileSizeMask;
|
||||
int py = var2 / tileSizeBase;
|
||||
writeColour(px, py, var5, var6, var7, -1);
|
||||
writeColour(px+16, py, var5, var6, var7, -1);
|
||||
writeColour(px, py+16, var5, var6, var7, -1);
|
||||
writeColour(px+16, py+16, var5, var6, var7, -1);
|
||||
writeColour(px + 16, py, var5, var6, var7, -1);
|
||||
writeColour(px, py + 16, var5, var6, var7, -1);
|
||||
writeColour(px + 16, py + 16, var5, var6, var7, -1);
|
||||
}
|
||||
}
|
||||
|
||||
private void writeColour(int px, int py, int var5, int var6, int var7, int var8)
|
||||
{
|
||||
imageData[py*32+px] = new ColourRGBA(var5, var6, var7, var8).argb();
|
||||
private void writeColour(int px, int py, int var5, int var6, int var7, int var8) {
|
||||
imageData[py * 32 + px] = new ColourRGBA(var5, var6, var7, var8).argb();
|
||||
}
|
||||
}
|
||||
@@ -6,8 +6,7 @@ import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public class TextureWaterFX extends TextureFX
|
||||
{
|
||||
public class TextureWaterFX extends TextureFX {
|
||||
/** red RGB value for water texture */
|
||||
protected float[] red = new float[256];
|
||||
|
||||
@@ -19,15 +18,14 @@ public class TextureWaterFX extends TextureFX
|
||||
|
||||
/** alpha RGB value for water texture */
|
||||
protected float[] alpha = new float[256];
|
||||
public TextureWaterFX()
|
||||
{
|
||||
|
||||
public TextureWaterFX() {
|
||||
super(16, "water_still_fx");
|
||||
setup();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setup()
|
||||
{
|
||||
public void setup() {
|
||||
super.setup();
|
||||
red = new float[tileSizeSquare];
|
||||
green = new float[tileSizeSquare];
|
||||
@@ -35,22 +33,18 @@ public class TextureWaterFX extends TextureFX
|
||||
alpha = new float[tileSizeSquare];
|
||||
}
|
||||
|
||||
public void onTick()
|
||||
{
|
||||
public void onTick() {
|
||||
int var1;
|
||||
int var2;
|
||||
float var3;
|
||||
int var5;
|
||||
int var6;
|
||||
|
||||
for (var1 = 0; var1 < tileSizeBase; ++var1)
|
||||
{
|
||||
for (var2 = 0; var2 < tileSizeBase; ++var2)
|
||||
{
|
||||
for (var1 = 0; var1 < tileSizeBase; ++var1) {
|
||||
for (var2 = 0; var2 < tileSizeBase; ++var2) {
|
||||
var3 = 0.0F;
|
||||
|
||||
for (int var4 = var1 - 1; var4 <= var1 + 1; ++var4)
|
||||
{
|
||||
for (int var4 = var1 - 1; var4 <= var1 + 1; ++var4) {
|
||||
var5 = var4 & tileSizeMask;
|
||||
var6 = var2 & tileSizeMask;
|
||||
var3 += this.red[var5 + var6 * tileSizeBase];
|
||||
@@ -60,21 +54,17 @@ public class TextureWaterFX extends TextureFX
|
||||
}
|
||||
}
|
||||
|
||||
for (var1 = 0; var1 < tileSizeBase; ++var1)
|
||||
{
|
||||
for (var2 = 0; var2 < tileSizeBase; ++var2)
|
||||
{
|
||||
for (var1 = 0; var1 < tileSizeBase; ++var1) {
|
||||
for (var2 = 0; var2 < tileSizeBase; ++var2) {
|
||||
this.blue[var1 + var2 * tileSizeBase] += this.alpha[var1 + var2 * tileSizeBase] * 0.05F;
|
||||
|
||||
if (this.blue[var1 + var2 * tileSizeBase] < 0.0F)
|
||||
{
|
||||
if (this.blue[var1 + var2 * tileSizeBase] < 0.0F) {
|
||||
this.blue[var1 + var2 * tileSizeBase] = 0.0F;
|
||||
}
|
||||
|
||||
this.alpha[var1 + var2 * tileSizeBase] -= 0.1F;
|
||||
|
||||
if (Math.random() < 0.05D)
|
||||
{
|
||||
if (Math.random() < 0.05D) {
|
||||
this.alpha[var1 + var2 * tileSizeBase] = 0.5F;
|
||||
}
|
||||
}
|
||||
@@ -84,28 +74,24 @@ public class TextureWaterFX extends TextureFX
|
||||
this.green = this.red;
|
||||
this.red = var12;
|
||||
|
||||
for (var2 = 0; var2 < tileSizeSquare; ++var2)
|
||||
{
|
||||
for (var2 = 0; var2 < tileSizeSquare; ++var2) {
|
||||
var3 = this.red[var2];
|
||||
|
||||
if (var3 > 1.0F)
|
||||
{
|
||||
if (var3 > 1.0F) {
|
||||
var3 = 1.0F;
|
||||
}
|
||||
|
||||
if (var3 < 0.0F)
|
||||
{
|
||||
if (var3 < 0.0F) {
|
||||
var3 = 0.0F;
|
||||
}
|
||||
|
||||
float var13 = var3 * var3;
|
||||
var5 = (int)(32.0F + var13 * 32.0F);
|
||||
var6 = (int)(50.0F + var13 * 64.0F);
|
||||
var5 = (int) (32.0F + var13 * 32.0F);
|
||||
var6 = (int) (50.0F + var13 * 64.0F);
|
||||
int var7 = 255;
|
||||
int var8 = (int)(146.0F + var13 * 50.0F);
|
||||
int var8 = (int) (146.0F + var13 * 50.0F);
|
||||
|
||||
if (this.anaglyphEnabled)
|
||||
{
|
||||
if (this.anaglyphEnabled) {
|
||||
int var9 = (var5 * 30 + var6 * 59 + var7 * 11) / 100;
|
||||
int var10 = (var5 * 30 + var6 * 70) / 100;
|
||||
int var11 = (var5 * 30 + var7 * 70) / 100;
|
||||
|
||||
@@ -6,28 +6,25 @@ import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public class TextureWaterFlowFX extends TextureFX
|
||||
{
|
||||
public class TextureWaterFlowFX extends TextureFX {
|
||||
protected float[] field_76880_g = new float[256];
|
||||
protected float[] field_76883_h = new float[256];
|
||||
protected float[] field_76884_i = new float[256];
|
||||
protected float[] field_76881_j = new float[256];
|
||||
private int tickCounter = 0;
|
||||
|
||||
//shadow
|
||||
|
||||
// shadow
|
||||
public int tileSizeBase = 16;
|
||||
public int tileSizeSquare = 256;
|
||||
public int tileSizeMask = 15;
|
||||
public int tileSizeSquareMask = 255;
|
||||
|
||||
public TextureWaterFlowFX()
|
||||
{
|
||||
public TextureWaterFlowFX() {
|
||||
super(32, "water_flow_fx");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setup()
|
||||
{
|
||||
public void setup() {
|
||||
super.setup();
|
||||
field_76880_g = new float[tileSizeSquare];
|
||||
field_76883_h = new float[tileSizeSquare];
|
||||
@@ -36,8 +33,7 @@ public class TextureWaterFlowFX extends TextureFX
|
||||
tickCounter = 0;
|
||||
}
|
||||
|
||||
public void onTick()
|
||||
{
|
||||
public void onTick() {
|
||||
++this.tickCounter;
|
||||
int var1;
|
||||
int var2;
|
||||
@@ -45,38 +41,33 @@ public class TextureWaterFlowFX extends TextureFX
|
||||
int var5;
|
||||
int var6;
|
||||
|
||||
for (var1 = 0; var1 < tileSizeBase; ++var1)
|
||||
{
|
||||
for (var2 = 0; var2 < tileSizeBase; ++var2)
|
||||
{
|
||||
for (var1 = 0; var1 < tileSizeBase; ++var1) {
|
||||
for (var2 = 0; var2 < tileSizeBase; ++var2) {
|
||||
var3 = 0.0F;
|
||||
|
||||
for (int var4 = var2 - 2; var4 <= var2; ++var4)
|
||||
{
|
||||
for (int var4 = var2 - 2; var4 <= var2; ++var4) {
|
||||
var5 = var1 & tileSizeMask;
|
||||
var6 = var4 & tileSizeMask;
|
||||
var3 += this.field_76880_g[var5 + var6 * tileSizeBase];
|
||||
}
|
||||
|
||||
this.field_76883_h[var1 + var2 * tileSizeBase] = var3 / 3.2F + this.field_76884_i[var1 + var2 * tileSizeBase] * 0.8F;
|
||||
this.field_76883_h[var1 + var2 * tileSizeBase] =
|
||||
var3 / 3.2F + this.field_76884_i[var1 + var2 * tileSizeBase] * 0.8F;
|
||||
}
|
||||
}
|
||||
|
||||
for (var1 = 0; var1 < tileSizeBase; ++var1)
|
||||
{
|
||||
for (var2 = 0; var2 < tileSizeBase; ++var2)
|
||||
{
|
||||
this.field_76884_i[var1 + var2 * tileSizeBase] += this.field_76881_j[var1 + var2 * tileSizeBase] * 0.05F;
|
||||
for (var1 = 0; var1 < tileSizeBase; ++var1) {
|
||||
for (var2 = 0; var2 < tileSizeBase; ++var2) {
|
||||
this.field_76884_i[var1 + var2 * tileSizeBase] +=
|
||||
this.field_76881_j[var1 + var2 * tileSizeBase] * 0.05F;
|
||||
|
||||
if (this.field_76884_i[var1 + var2 * tileSizeBase] < 0.0F)
|
||||
{
|
||||
if (this.field_76884_i[var1 + var2 * tileSizeBase] < 0.0F) {
|
||||
this.field_76884_i[var1 + var2 * tileSizeBase] = 0.0F;
|
||||
}
|
||||
|
||||
this.field_76881_j[var1 + var2 * tileSizeBase] -= 0.3F;
|
||||
|
||||
if (Math.random() < 0.2D)
|
||||
{
|
||||
if (Math.random() < 0.2D) {
|
||||
this.field_76881_j[var1 + var2 * tileSizeBase] = 0.5F;
|
||||
}
|
||||
}
|
||||
@@ -86,28 +77,24 @@ public class TextureWaterFlowFX extends TextureFX
|
||||
this.field_76883_h = this.field_76880_g;
|
||||
this.field_76880_g = var12;
|
||||
|
||||
for (var2 = 0; var2 < tileSizeSquare; ++var2)
|
||||
{
|
||||
for (var2 = 0; var2 < tileSizeSquare; ++var2) {
|
||||
var3 = this.field_76880_g[var2 - this.tickCounter * tileSizeBase & tileSizeSquareMask];
|
||||
|
||||
if (var3 > 1.0F)
|
||||
{
|
||||
if (var3 > 1.0F) {
|
||||
var3 = 1.0F;
|
||||
}
|
||||
|
||||
if (var3 < 0.0F)
|
||||
{
|
||||
if (var3 < 0.0F) {
|
||||
var3 = 0.0F;
|
||||
}
|
||||
|
||||
float var13 = var3 * var3;
|
||||
var5 = (int)(32.0F + var13 * 32.0F);
|
||||
var6 = (int)(50.0F + var13 * 64.0F);
|
||||
var5 = (int) (32.0F + var13 * 32.0F);
|
||||
var6 = (int) (50.0F + var13 * 64.0F);
|
||||
int var7 = 255;
|
||||
int var8 = (int)(146.0F + var13 * 50.0F);
|
||||
int var8 = (int) (146.0F + var13 * 50.0F);
|
||||
|
||||
if (this.anaglyphEnabled)
|
||||
{
|
||||
if (this.anaglyphEnabled) {
|
||||
int var9 = (var5 * 30 + var6 * 59 + var7 * 11) / 100;
|
||||
int var10 = (var5 * 30 + var6 * 70) / 100;
|
||||
int var11 = (var5 * 30 + var7 * 70) / 100;
|
||||
@@ -116,18 +103,16 @@ public class TextureWaterFlowFX extends TextureFX
|
||||
var7 = var11;
|
||||
}
|
||||
|
||||
|
||||
int px = var2&tileSizeMask;
|
||||
int py = var2/tileSizeBase;
|
||||
int px = var2 & tileSizeMask;
|
||||
int py = var2 / tileSizeBase;
|
||||
writeColour(px, py, var5, var6, var7, var8);
|
||||
writeColour(px+16, py, var5, var6, var7, var8);
|
||||
writeColour(px, py+16, var5, var6, var7, var8);
|
||||
writeColour(px+16, py+16, var5, var6, var7, var8);
|
||||
writeColour(px + 16, py, var5, var6, var7, var8);
|
||||
writeColour(px, py + 16, var5, var6, var7, var8);
|
||||
writeColour(px + 16, py + 16, var5, var6, var7, var8);
|
||||
}
|
||||
}
|
||||
|
||||
private void writeColour(int px, int py, int var5, int var6, int var7, int var8)
|
||||
{
|
||||
imageData[py*32+px] = new ColourRGBA(var5, var6, var7, var8).argb();
|
||||
private void writeColour(int px, int py, int var5, int var6, int var7, int var8) {
|
||||
imageData[py * 32 + px] = new ColourRGBA(var5, var6, var7, var8).argb();
|
||||
}
|
||||
}
|
||||
@@ -5,15 +5,13 @@ import net.minecraftforge.fluids.FluidStack;
|
||||
import net.minecraftforge.fluids.FluidTankInfo;
|
||||
import net.minecraftforge.fluids.IFluidTank;
|
||||
|
||||
public class ExtendedFluidTank implements IFluidTank
|
||||
{
|
||||
public class ExtendedFluidTank implements IFluidTank {
|
||||
private FluidStack fluid;
|
||||
private boolean changeType;
|
||||
private int capacity;
|
||||
|
||||
public ExtendedFluidTank(FluidStack type, int capacity)
|
||||
{
|
||||
if(type == null) {
|
||||
|
||||
public ExtendedFluidTank(FluidStack type, int capacity) {
|
||||
if (type == null) {
|
||||
type = FluidUtils.water;
|
||||
changeType = true;
|
||||
}
|
||||
@@ -21,97 +19,76 @@ public class ExtendedFluidTank implements IFluidTank
|
||||
fluid = FluidUtils.copy(type, 0);
|
||||
this.capacity = capacity;
|
||||
}
|
||||
|
||||
public ExtendedFluidTank(int capacity)
|
||||
{
|
||||
|
||||
public ExtendedFluidTank(int capacity) {
|
||||
this(null, capacity);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public FluidStack getFluid()
|
||||
{
|
||||
public FluidStack getFluid() {
|
||||
return fluid.copy();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCapacity()
|
||||
{
|
||||
public int getCapacity() {
|
||||
return capacity;
|
||||
}
|
||||
|
||||
public boolean canAccept(FluidStack type)
|
||||
{
|
||||
public boolean canAccept(FluidStack type) {
|
||||
return type == null || (fluid.amount == 0 && changeType) || fluid.isFluidEqual(type);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int fill(FluidStack resource, boolean doFill)
|
||||
{
|
||||
if(resource == null)
|
||||
return 0;
|
||||
public int fill(FluidStack resource, boolean doFill) {
|
||||
if (resource == null) return 0;
|
||||
|
||||
if(!canAccept(resource))
|
||||
return 0;
|
||||
|
||||
int tofill = Math.min(getCapacity()-fluid.amount, resource.amount);
|
||||
if(doFill && tofill > 0)
|
||||
{
|
||||
if(!fluid.isFluidEqual(resource))
|
||||
fluid = FluidUtils.copy(resource, fluid.amount+tofill);
|
||||
else
|
||||
fluid.amount+=tofill;
|
||||
if (!canAccept(resource)) return 0;
|
||||
|
||||
int tofill = Math.min(getCapacity() - fluid.amount, resource.amount);
|
||||
if (doFill && tofill > 0) {
|
||||
if (!fluid.isFluidEqual(resource)) fluid = FluidUtils.copy(resource, fluid.amount + tofill);
|
||||
else fluid.amount += tofill;
|
||||
onLiquidChanged();
|
||||
}
|
||||
|
||||
|
||||
return tofill;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FluidStack drain(int maxDrain, boolean doDrain)
|
||||
{
|
||||
if(fluid.amount == 0 || maxDrain <= 0)
|
||||
return null;
|
||||
|
||||
public FluidStack drain(int maxDrain, boolean doDrain) {
|
||||
if (fluid.amount == 0 || maxDrain <= 0) return null;
|
||||
|
||||
int todrain = Math.min(maxDrain, fluid.amount);
|
||||
if(doDrain && todrain > 0)
|
||||
{
|
||||
fluid.amount-=todrain;
|
||||
if (doDrain && todrain > 0) {
|
||||
fluid.amount -= todrain;
|
||||
onLiquidChanged();
|
||||
}
|
||||
return FluidUtils.copy(fluid, todrain);
|
||||
}
|
||||
|
||||
public FluidStack drain(FluidStack resource, boolean doDrain)
|
||||
{
|
||||
if (resource == null || !resource.isFluidEqual(fluid))
|
||||
return null;
|
||||
|
||||
|
||||
public FluidStack drain(FluidStack resource, boolean doDrain) {
|
||||
if (resource == null || !resource.isFluidEqual(fluid)) return null;
|
||||
|
||||
return drain(resource.amount, doDrain);
|
||||
}
|
||||
|
||||
public void onLiquidChanged()
|
||||
{
|
||||
}
|
||||
public void onLiquidChanged() {}
|
||||
|
||||
public void fromTag(NBTTagCompound tag)
|
||||
{
|
||||
public void fromTag(NBTTagCompound tag) {
|
||||
fluid = FluidUtils.read(tag);
|
||||
}
|
||||
|
||||
public NBTTagCompound toTag()
|
||||
{
|
||||
|
||||
public NBTTagCompound toTag() {
|
||||
return FluidUtils.write(fluid, new NBTTagCompound());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getFluidAmount()
|
||||
{
|
||||
public int getFluidAmount() {
|
||||
return fluid.amount;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FluidTankInfo getInfo()
|
||||
{
|
||||
public FluidTankInfo getInfo() {
|
||||
return new FluidTankInfo(this);
|
||||
}
|
||||
}
|
||||
@@ -11,87 +11,73 @@ import net.minecraftforge.fluids.FluidRegistry;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import net.minecraftforge.fluids.IFluidHandler;
|
||||
|
||||
public class FluidUtils
|
||||
{
|
||||
public class FluidUtils {
|
||||
public static int B = FluidContainerRegistry.BUCKET_VOLUME;
|
||||
public static FluidStack water = new FluidStack(FluidRegistry.WATER, 1000);
|
||||
public static FluidStack lava = new FluidStack(FluidRegistry.LAVA, 1000);
|
||||
|
||||
public static boolean fillTankWithContainer(IFluidHandler tank, EntityPlayer player)
|
||||
{
|
||||
public static boolean fillTankWithContainer(IFluidHandler tank, EntityPlayer player) {
|
||||
ItemStack stack = player.getCurrentEquippedItem();
|
||||
FluidStack liquid = FluidContainerRegistry.getFluidForFilledItem(stack);
|
||||
|
||||
if(liquid == null)
|
||||
if (liquid == null) return false;
|
||||
|
||||
if (tank.fill(ForgeDirection.UNKNOWN, liquid, false) != liquid.amount && !player.capabilities.isCreativeMode)
|
||||
return false;
|
||||
|
||||
if(tank.fill(ForgeDirection.UNKNOWN, liquid, false) != liquid.amount && !player.capabilities.isCreativeMode)
|
||||
return false;
|
||||
|
||||
tank.fill(ForgeDirection.UNKNOWN, liquid, true);
|
||||
|
||||
if(!player.capabilities.isCreativeMode)
|
||||
|
||||
if (!player.capabilities.isCreativeMode)
|
||||
InventoryUtils.consumeItem(player.inventory, player.inventory.currentItem);
|
||||
|
||||
player.inventoryContainer.detectAndSendChanges();
|
||||
return true;
|
||||
}
|
||||
|
||||
public static boolean emptyTankIntoContainer(IFluidHandler tank, EntityPlayer player, FluidStack tankLiquid)
|
||||
{
|
||||
public static boolean emptyTankIntoContainer(IFluidHandler tank, EntityPlayer player, FluidStack tankLiquid) {
|
||||
ItemStack stack = player.getCurrentEquippedItem();
|
||||
|
||||
if(!FluidContainerRegistry.isEmptyContainer(stack))
|
||||
return false;
|
||||
|
||||
if (!FluidContainerRegistry.isEmptyContainer(stack)) return false;
|
||||
|
||||
ItemStack filled = FluidContainerRegistry.fillFluidContainer(tankLiquid, stack);
|
||||
FluidStack liquid = FluidContainerRegistry.getFluidForFilledItem(filled);
|
||||
|
||||
if(liquid == null || filled == null)
|
||||
return false;
|
||||
|
||||
if (liquid == null || filled == null) return false;
|
||||
|
||||
tank.drain(ForgeDirection.UNKNOWN, liquid.amount, true);
|
||||
|
||||
if(!player.capabilities.isCreativeMode)
|
||||
{
|
||||
if(stack.stackSize == 1)
|
||||
player.inventory.setInventorySlotContents(player.inventory.currentItem, filled);
|
||||
else if(player.inventory.addItemStackToInventory(filled))
|
||||
stack.stackSize--;
|
||||
else
|
||||
return false;
|
||||
if (!player.capabilities.isCreativeMode) {
|
||||
if (stack.stackSize == 1) player.inventory.setInventorySlotContents(player.inventory.currentItem, filled);
|
||||
else if (player.inventory.addItemStackToInventory(filled)) stack.stackSize--;
|
||||
else return false;
|
||||
}
|
||||
|
||||
player.inventoryContainer.detectAndSendChanges();
|
||||
|
||||
player.inventoryContainer.detectAndSendChanges();
|
||||
return true;
|
||||
}
|
||||
|
||||
public static FluidStack copy(FluidStack liquid, int quantity)
|
||||
{
|
||||
public static FluidStack copy(FluidStack liquid, int quantity) {
|
||||
liquid = liquid.copy();
|
||||
liquid.amount = quantity;
|
||||
return liquid;
|
||||
}
|
||||
|
||||
public static FluidStack read(NBTTagCompound tag)
|
||||
{
|
||||
public static FluidStack read(NBTTagCompound tag) {
|
||||
FluidStack stack = FluidStack.loadFluidStackFromNBT(tag);
|
||||
return stack != null ? stack : FluidUtils.emptyFluid();
|
||||
}
|
||||
|
||||
public static NBTTagCompound write(FluidStack fluid, NBTTagCompound tag)
|
||||
{
|
||||
return fluid == null || fluid.getFluid() == null ? new NBTTagCompound() : fluid.writeToNBT(new NBTTagCompound());
|
||||
|
||||
public static NBTTagCompound write(FluidStack fluid, NBTTagCompound tag) {
|
||||
return fluid == null || fluid.getFluid() == null
|
||||
? new NBTTagCompound()
|
||||
: fluid.writeToNBT(new NBTTagCompound());
|
||||
}
|
||||
|
||||
public static int getLuminosity(FluidStack stack, double density)
|
||||
{
|
||||
public static int getLuminosity(FluidStack stack, double density) {
|
||||
Fluid fluid = stack.getFluid();
|
||||
if(fluid == null)
|
||||
return 0;
|
||||
if (fluid == null) return 0;
|
||||
int light = fluid.getLuminosity(stack);
|
||||
if(fluid.isGaseous())
|
||||
light=(int)(light*density);
|
||||
if (fluid.isGaseous()) light = (int) (light * density);
|
||||
return light;
|
||||
}
|
||||
|
||||
|
||||
@@ -4,29 +4,24 @@ import net.minecraftforge.common.util.ForgeDirection;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import net.minecraftforge.fluids.IFluidHandler;
|
||||
|
||||
public class TankAccess
|
||||
{
|
||||
public class TankAccess {
|
||||
public IFluidHandler tank;
|
||||
public ForgeDirection side;
|
||||
|
||||
public TankAccess(IFluidHandler tank, ForgeDirection side)
|
||||
{
|
||||
|
||||
public TankAccess(IFluidHandler tank, ForgeDirection side) {
|
||||
this.tank = tank;
|
||||
this.side = side;
|
||||
}
|
||||
|
||||
public TankAccess(IFluidHandler tank, int side)
|
||||
{
|
||||
|
||||
public TankAccess(IFluidHandler tank, int side) {
|
||||
this(tank, ForgeDirection.getOrientation(side));
|
||||
}
|
||||
|
||||
public int fill(FluidStack resource, boolean doFill)
|
||||
{
|
||||
public int fill(FluidStack resource, boolean doFill) {
|
||||
return tank.fill(side, resource, doFill);
|
||||
}
|
||||
|
||||
public FluidStack drain(int maxDrain, boolean doDrain)
|
||||
{
|
||||
|
||||
public FluidStack drain(int maxDrain, boolean doDrain) {
|
||||
return tank.drain(side, maxDrain, doDrain);
|
||||
}
|
||||
}
|
||||
@@ -1,20 +1,17 @@
|
||||
package codechicken.core.gui;
|
||||
|
||||
import com.google.common.base.Objects;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
|
||||
public class ClickCounter<T>
|
||||
{
|
||||
public class ClickCount
|
||||
{
|
||||
public class ClickCounter<T> {
|
||||
public class ClickCount {
|
||||
public T clicked;
|
||||
public long time;
|
||||
public int count;
|
||||
|
||||
public boolean update(T clicked) {
|
||||
if(!Objects.equal(this.clicked, clicked)) {
|
||||
if (!Objects.equal(this.clicked, clicked)) {
|
||||
this.clicked = clicked;
|
||||
count = 0;
|
||||
time = Long.MIN_VALUE;
|
||||
@@ -28,8 +25,7 @@ public class ClickCounter<T>
|
||||
|
||||
public ClickCount getCount(int button) {
|
||||
ClickCount c = buttons.get(button);
|
||||
if(c == null)
|
||||
buttons.put(button, c = new ClickCount());
|
||||
if (c == null) buttons.put(button, c = new ClickCount());
|
||||
return c;
|
||||
}
|
||||
|
||||
@@ -40,14 +36,11 @@ public class ClickCounter<T>
|
||||
|
||||
public int mouseUp(T clicked, int button) {
|
||||
ClickCount c = getCount(button);
|
||||
if(!c.update(clicked))
|
||||
return 0;
|
||||
if (!c.update(clicked)) return 0;
|
||||
|
||||
long time = System.currentTimeMillis();
|
||||
if(time-c.time < 500)
|
||||
c.count++;
|
||||
else
|
||||
c.count = 1;
|
||||
if (time - c.time < 500) c.count++;
|
||||
else c.count = 1;
|
||||
c.time = time;
|
||||
return c.count;
|
||||
}
|
||||
|
||||
@@ -1,13 +1,11 @@
|
||||
package codechicken.core.gui;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
|
||||
import net.minecraft.client.audio.PositionedSoundRecord;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
public class GuiCCButton extends GuiWidget
|
||||
{
|
||||
public class GuiCCButton extends GuiWidget {
|
||||
public String text;
|
||||
public String actionCommand;
|
||||
private boolean isEnabled = true;
|
||||
@@ -34,28 +32,35 @@ public class GuiCCButton extends GuiWidget
|
||||
public void mouseClicked(int x, int y, int button) {
|
||||
if (isEnabled && pointInside(x, y) && actionCommand != null) {
|
||||
sendAction(actionCommand, button);
|
||||
Minecraft.getMinecraft().getSoundHandler().playSound(PositionedSoundRecord.func_147674_a(new ResourceLocation("gui.button.press"), 1.0F));
|
||||
Minecraft.getMinecraft()
|
||||
.getSoundHandler()
|
||||
.playSound(PositionedSoundRecord.func_147674_a(new ResourceLocation("gui.button.press"), 1.0F));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(int mousex, int mousey, float frame) {
|
||||
if (!visible)
|
||||
return;
|
||||
if (!visible) return;
|
||||
|
||||
drawButtonTex(mousex, mousey);
|
||||
if(text != null)
|
||||
drawText(mousex, mousey);
|
||||
if (text != null) drawText(mousex, mousey);
|
||||
}
|
||||
|
||||
public void drawButtonTex(int mousex, int mousey) {
|
||||
GL11.glColor4f(1, 1, 1, 1);
|
||||
renderEngine.bindTexture(guiTex);
|
||||
int state = getButtonTex(mousex, mousey);
|
||||
drawTexturedModalRect(x, y, 0, 46 + state * 20, width / 2, height / 2);//top left
|
||||
drawTexturedModalRect(x + width / 2, y, 200 - width / 2, 46 + state * 20, width / 2, height / 2);//top right
|
||||
drawTexturedModalRect(x, y + height / 2, 0, 46 + state * 20 + 20 - height / 2, width / 2, height / 2);//bottom left
|
||||
drawTexturedModalRect(x + width / 2, y + height / 2, 200 - width / 2, 46 + state * 20 + 20 - height / 2, width / 2, height / 2);//bottom right
|
||||
drawTexturedModalRect(x, y, 0, 46 + state * 20, width / 2, height / 2); // top left
|
||||
drawTexturedModalRect(x + width / 2, y, 200 - width / 2, 46 + state * 20, width / 2, height / 2); // top right
|
||||
drawTexturedModalRect(
|
||||
x, y + height / 2, 0, 46 + state * 20 + 20 - height / 2, width / 2, height / 2); // bottom left
|
||||
drawTexturedModalRect(
|
||||
x + width / 2,
|
||||
y + height / 2,
|
||||
200 - width / 2,
|
||||
46 + state * 20 + 20 - height / 2,
|
||||
width / 2,
|
||||
height / 2); // bottom right
|
||||
}
|
||||
|
||||
public int getButtonTex(int mousex, int mousey) {
|
||||
|
||||
@@ -2,187 +2,148 @@ package codechicken.core.gui;
|
||||
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
import net.minecraft.util.ChatAllowedCharacters;
|
||||
|
||||
import org.lwjgl.input.Keyboard;
|
||||
|
||||
public class GuiCCTextField extends GuiWidget
|
||||
{
|
||||
public class GuiCCTextField extends GuiWidget {
|
||||
private String text;
|
||||
private boolean isFocused;
|
||||
private boolean isEnabled;
|
||||
|
||||
|
||||
public int maxStringLength;
|
||||
public int cursorCounter;
|
||||
public String actionCommand;
|
||||
|
||||
|
||||
private String allowedCharacters;
|
||||
|
||||
public GuiCCTextField(int x, int y, int width, int height, String text)
|
||||
{
|
||||
public GuiCCTextField(int x, int y, int width, int height, String text) {
|
||||
super(x, y, width, height);
|
||||
isFocused = false;
|
||||
isEnabled = true;
|
||||
this.text = text;
|
||||
}
|
||||
|
||||
public GuiCCTextField setActionCommand(String s)
|
||||
{
|
||||
public GuiCCTextField setActionCommand(String s) {
|
||||
actionCommand = s;
|
||||
return this;
|
||||
}
|
||||
|
||||
public void setText(String s)
|
||||
{
|
||||
if(s.equals(text))
|
||||
return;
|
||||
public void setText(String s) {
|
||||
if (s.equals(text)) return;
|
||||
|
||||
String oldText = text;
|
||||
text = s;
|
||||
onTextChanged(oldText);
|
||||
}
|
||||
|
||||
public void onTextChanged(String oldText)
|
||||
{
|
||||
}
|
||||
public void onTextChanged(String oldText) {}
|
||||
|
||||
public final String getText()
|
||||
{
|
||||
public final String getText() {
|
||||
return text;
|
||||
}
|
||||
|
||||
public final boolean isEnabled()
|
||||
{
|
||||
|
||||
public final boolean isEnabled() {
|
||||
return isEnabled;
|
||||
}
|
||||
|
||||
public void setEnabled(boolean b)
|
||||
{
|
||||
public void setEnabled(boolean b) {
|
||||
isEnabled = b;
|
||||
if(!isEnabled && isFocused)
|
||||
setFocused(false);
|
||||
if (!isEnabled && isFocused) setFocused(false);
|
||||
}
|
||||
|
||||
public final boolean isFocused()
|
||||
{
|
||||
|
||||
public final boolean isFocused() {
|
||||
return isFocused;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update()
|
||||
{
|
||||
public void update() {
|
||||
cursorCounter++;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void keyTyped(char c, int keycode)
|
||||
{
|
||||
if(!isEnabled || !isFocused)
|
||||
return;
|
||||
public void keyTyped(char c, int keycode) {
|
||||
if (!isEnabled || !isFocused) return;
|
||||
|
||||
/*if(c == '\t')//tab
|
||||
{
|
||||
parentGuiScreen.selectNextField();
|
||||
}*/
|
||||
if(c == '\026')//paste
|
||||
if (c == '\026') // paste
|
||||
{
|
||||
String s = GuiScreen.getClipboardString();
|
||||
if(s == null || s.equals(""))
|
||||
return;
|
||||
if (s == null || s.equals("")) return;
|
||||
|
||||
for(int i = 0; i < s.length(); i++)
|
||||
{
|
||||
if(text.length() == maxStringLength)
|
||||
return;
|
||||
for (int i = 0; i < s.length(); i++) {
|
||||
if (text.length() == maxStringLength) return;
|
||||
|
||||
char tc = s.charAt(i);
|
||||
if(canAddChar(tc))
|
||||
setText(text + tc);
|
||||
if (canAddChar(tc)) setText(text + tc);
|
||||
}
|
||||
}
|
||||
if(keycode == Keyboard.KEY_RETURN)
|
||||
{
|
||||
if (keycode == Keyboard.KEY_RETURN) {
|
||||
setFocused(false);
|
||||
sendAction(actionCommand, getText());
|
||||
}
|
||||
|
||||
if(keycode == Keyboard.KEY_BACK && text.length() > 0)
|
||||
setText(text.substring(0, text.length() - 1));
|
||||
if (keycode == Keyboard.KEY_BACK && text.length() > 0) setText(text.substring(0, text.length() - 1));
|
||||
|
||||
if((text.length() < maxStringLength || maxStringLength == 0) && canAddChar(c))
|
||||
setText(text + c);
|
||||
if ((text.length() < maxStringLength || maxStringLength == 0) && canAddChar(c)) setText(text + c);
|
||||
}
|
||||
|
||||
public boolean canAddChar(char c)
|
||||
{
|
||||
return allowedCharacters == null ? ChatAllowedCharacters.isAllowedCharacter(c) : allowedCharacters.indexOf(c) >= 0;
|
||||
public boolean canAddChar(char c) {
|
||||
return allowedCharacters == null
|
||||
? ChatAllowedCharacters.isAllowedCharacter(c)
|
||||
: allowedCharacters.indexOf(c) >= 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseClicked(int x, int y, int button)
|
||||
{
|
||||
if(isEnabled && pointInside(x, y))
|
||||
{
|
||||
public void mouseClicked(int x, int y, int button) {
|
||||
if (isEnabled && pointInside(x, y)) {
|
||||
setFocused(true);
|
||||
if(button == 1)
|
||||
setText("");
|
||||
}
|
||||
else
|
||||
setFocused(false);
|
||||
if (button == 1) setText("");
|
||||
} else setFocused(false);
|
||||
}
|
||||
|
||||
public void setFocused(boolean focus)
|
||||
{
|
||||
if(focus == isFocused)
|
||||
return;
|
||||
public void setFocused(boolean focus) {
|
||||
if (focus == isFocused) return;
|
||||
isFocused = focus;
|
||||
onFocusChanged();
|
||||
}
|
||||
|
||||
public void onFocusChanged()
|
||||
{
|
||||
if(isFocused)
|
||||
cursorCounter = 0;
|
||||
public void onFocusChanged() {
|
||||
if (isFocused) cursorCounter = 0;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void draw(int i, int j, float f)
|
||||
{
|
||||
public void draw(int i, int j, float f) {
|
||||
drawBackground();
|
||||
drawText();
|
||||
}
|
||||
|
||||
public void drawBackground()
|
||||
{
|
||||
public void drawBackground() {
|
||||
drawRect(x - 1, y - 1, x + width + 1, y + height + 1, 0xffa0a0a0);
|
||||
drawRect(x, y, x + width, y + height, 0xff000000);
|
||||
}
|
||||
|
||||
public String getDrawText()
|
||||
{
|
||||
|
||||
public String getDrawText() {
|
||||
String s = getText();
|
||||
if(isEnabled && isFocused && (cursorCounter / 6) % 2 == 0)
|
||||
s+="_";
|
||||
if (isEnabled && isFocused && (cursorCounter / 6) % 2 == 0) s += "_";
|
||||
return s;
|
||||
}
|
||||
|
||||
public void drawText()
|
||||
{
|
||||
drawString(fontRenderer, getDrawText(), x + 4, y + height/2 - 4, getTextColour());
|
||||
|
||||
public void drawText() {
|
||||
drawString(fontRenderer, getDrawText(), x + 4, y + height / 2 - 4, getTextColour());
|
||||
}
|
||||
|
||||
public int getTextColour()
|
||||
{
|
||||
public int getTextColour() {
|
||||
return isEnabled ? 0xe0e0e0 : 0x707070;
|
||||
}
|
||||
|
||||
public GuiCCTextField setMaxStringLength(int i)
|
||||
{
|
||||
public GuiCCTextField setMaxStringLength(int i) {
|
||||
maxStringLength = i;
|
||||
return this;
|
||||
}
|
||||
|
||||
public GuiCCTextField setAllowedCharacters(String s)
|
||||
{
|
||||
public GuiCCTextField setAllowedCharacters(String s) {
|
||||
allowedCharacters = s;
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -1,43 +1,35 @@
|
||||
package codechicken.core.gui;
|
||||
|
||||
import codechicken.lib.gui.GuiDraw;
|
||||
import java.awt.Point;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import codechicken.lib.gui.GuiDraw;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
import org.lwjgl.input.Mouse;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
|
||||
public class GuiScreenWidget extends GuiScreen implements IGuiActionListener
|
||||
{
|
||||
public class GuiScreenWidget extends GuiScreen implements IGuiActionListener {
|
||||
public ArrayList<GuiWidget> widgets = new ArrayList<GuiWidget>();
|
||||
public int xSize, ySize, guiTop, guiLeft;
|
||||
|
||||
public GuiScreenWidget()
|
||||
{
|
||||
public GuiScreenWidget() {
|
||||
this(176, 166);
|
||||
}
|
||||
|
||||
public GuiScreenWidget(int xSize, int ySize)
|
||||
{
|
||||
public GuiScreenWidget(int xSize, int ySize) {
|
||||
super();
|
||||
this.xSize = xSize;
|
||||
this.ySize = ySize;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initGui()
|
||||
{
|
||||
public void initGui() {
|
||||
guiTop = (height - ySize) / 2;
|
||||
guiLeft = (width - xSize) / 2;
|
||||
if(!widgets.isEmpty())
|
||||
resize();
|
||||
if (!widgets.isEmpty()) resize();
|
||||
}
|
||||
|
||||
public void reset()
|
||||
{
|
||||
public void reset() {
|
||||
widgets.clear();
|
||||
initGui();
|
||||
addWidgets();
|
||||
@@ -45,106 +37,78 @@ public class GuiScreenWidget extends GuiScreen implements IGuiActionListener
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setWorldAndResolution(Minecraft mc, int i, int j)
|
||||
{
|
||||
public void setWorldAndResolution(Minecraft mc, int i, int j) {
|
||||
boolean init = this.mc == null;
|
||||
super.setWorldAndResolution(mc, i, j);
|
||||
if(init) {
|
||||
if (init) {
|
||||
addWidgets();
|
||||
resize();
|
||||
}
|
||||
}
|
||||
|
||||
public void add(GuiWidget widget)
|
||||
{
|
||||
public void add(GuiWidget widget) {
|
||||
widgets.add(widget);
|
||||
widget.onAdded(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawScreen(int mousex, int mousey, float f)
|
||||
{
|
||||
public void drawScreen(int mousex, int mousey, float f) {
|
||||
GL11.glTranslated(guiLeft, guiTop, 0);
|
||||
drawBackground();
|
||||
for(GuiWidget widget : widgets)
|
||||
widget.draw(mousex-guiLeft, mousey-guiTop, f);
|
||||
for (GuiWidget widget : widgets) widget.draw(mousex - guiLeft, mousey - guiTop, f);
|
||||
drawForeground();
|
||||
GL11.glTranslated(-guiLeft, -guiTop, 0);
|
||||
}
|
||||
|
||||
public void drawBackground()
|
||||
{
|
||||
}
|
||||
public void drawBackground() {}
|
||||
|
||||
public void drawForeground()
|
||||
{
|
||||
}
|
||||
public void drawForeground() {}
|
||||
|
||||
@Override
|
||||
protected void mouseClicked(int x, int y, int button)
|
||||
{
|
||||
protected void mouseClicked(int x, int y, int button) {
|
||||
super.mouseClicked(x, y, button);
|
||||
for(GuiWidget widget : widgets)
|
||||
widget.mouseClicked(x-guiLeft, y-guiTop, button);
|
||||
for (GuiWidget widget : widgets) widget.mouseClicked(x - guiLeft, y - guiTop, button);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void mouseMovedOrUp(int x, int y, int button)
|
||||
{
|
||||
protected void mouseMovedOrUp(int x, int y, int button) {
|
||||
super.mouseMovedOrUp(x, y, button);
|
||||
for(GuiWidget widget : widgets)
|
||||
widget.mouseMovedOrUp(x-guiLeft, y-guiTop, button);
|
||||
for (GuiWidget widget : widgets) widget.mouseMovedOrUp(x - guiLeft, y - guiTop, button);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void mouseClickMove(int x, int y, int button, long time)
|
||||
{
|
||||
protected void mouseClickMove(int x, int y, int button, long time) {
|
||||
super.mouseClickMove(x, y, button, time);
|
||||
for(GuiWidget widget : widgets)
|
||||
widget.mouseDragged(x-guiLeft, y-guiTop, button, time);
|
||||
for (GuiWidget widget : widgets) widget.mouseDragged(x - guiLeft, y - guiTop, button, time);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateScreen()
|
||||
{
|
||||
public void updateScreen() {
|
||||
super.updateScreen();
|
||||
if(mc.currentScreen == this)
|
||||
for(GuiWidget widget : widgets)
|
||||
widget.update();
|
||||
if (mc.currentScreen == this) for (GuiWidget widget : widgets) widget.update();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void keyTyped(char c, int keycode)
|
||||
{
|
||||
public void keyTyped(char c, int keycode) {
|
||||
super.keyTyped(c, keycode);
|
||||
for(GuiWidget widget : widgets)
|
||||
widget.keyTyped(c, keycode);
|
||||
for (GuiWidget widget : widgets) widget.keyTyped(c, keycode);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleMouseInput()
|
||||
{
|
||||
public void handleMouseInput() {
|
||||
super.handleMouseInput();
|
||||
int i = Mouse.getEventDWheel();
|
||||
if(i != 0)
|
||||
{
|
||||
if (i != 0) {
|
||||
Point p = GuiDraw.getMousePosition();
|
||||
int scroll = i > 0 ? 1 : -1;
|
||||
for(GuiWidget widget : widgets)
|
||||
widget.mouseScrolled(p.x, p.y, scroll);
|
||||
for (GuiWidget widget : widgets) widget.mouseScrolled(p.x, p.y, scroll);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void actionPerformed(String ident, Object... params)
|
||||
{
|
||||
}
|
||||
public void actionPerformed(String ident, Object... params) {}
|
||||
|
||||
public void resize()
|
||||
{
|
||||
}
|
||||
public void resize() {}
|
||||
|
||||
public void addWidgets()
|
||||
{
|
||||
}
|
||||
public void addWidgets() {}
|
||||
}
|
||||
@@ -2,11 +2,9 @@ package codechicken.core.gui;
|
||||
|
||||
import codechicken.lib.math.MathHelper;
|
||||
import codechicken.lib.vec.Rectangle4i;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
public abstract class GuiScrollPane extends GuiWidget
|
||||
{
|
||||
public abstract class GuiScrollPane extends GuiWidget {
|
||||
protected int scrollclicky = -1;
|
||||
protected float scrollpercent;
|
||||
protected int scrollmousey;
|
||||
@@ -29,7 +27,8 @@ public abstract class GuiScrollPane extends GuiWidget
|
||||
}
|
||||
|
||||
public Rectangle windowBounds() {
|
||||
return new Rectangle(x+marginleft, y+margintop, width-marginleft-marginright, height-margintop-marginbottom);
|
||||
return new Rectangle(
|
||||
x + marginleft, y + margintop, width - marginleft - marginright, height - margintop - marginbottom);
|
||||
}
|
||||
|
||||
public abstract int contentHeight();
|
||||
@@ -42,8 +41,10 @@ public abstract class GuiScrollPane extends GuiWidget
|
||||
public Rectangle scrollbarBounds() {
|
||||
Dimension dim = scrollbarDim();
|
||||
return new Rectangle(
|
||||
x + width - dim.width, y + (int) ((height - dim.height) * percentscrolled + 0.4999),
|
||||
dim.width, dim.height);
|
||||
x + width - dim.width,
|
||||
y + (int) ((height - dim.height) * percentscrolled + 0.4999),
|
||||
dim.width,
|
||||
dim.height);
|
||||
}
|
||||
|
||||
public void scrollUp() {
|
||||
@@ -55,7 +56,7 @@ public abstract class GuiScrollPane extends GuiWidget
|
||||
}
|
||||
|
||||
public void scroll(int i) {
|
||||
percentscrolled += i * height / (float)(2*contentHeight());
|
||||
percentscrolled += i * height / (float) (2 * contentHeight());
|
||||
calculatePercentScrolled();
|
||||
}
|
||||
|
||||
@@ -102,15 +103,18 @@ public abstract class GuiScrollPane extends GuiWidget
|
||||
Rectangle w = windowBounds();
|
||||
int barempty = height - sbar.height;
|
||||
|
||||
if (button == 0 &&
|
||||
sbar.height < height && //the scroll bar can move (not full length)
|
||||
mx >= sbar.x && mx <= sbar.x + sbar.width &&
|
||||
my >= y && my <= y + height)//in the scroll pane
|
||||
if (button == 0
|
||||
&& sbar.height < height
|
||||
&& // the scroll bar can move (not full length)
|
||||
mx >= sbar.x
|
||||
&& mx <= sbar.x + sbar.width
|
||||
&& my >= y
|
||||
&& my <= y + height) // in the scroll pane
|
||||
{
|
||||
if (my < sbar.y) {
|
||||
percentscrolled = (my - y) / (float) barempty;
|
||||
calculatePercentScrolled();
|
||||
} else if (my > sbar.y+sbar.height) {
|
||||
} else if (my > sbar.y + sbar.height) {
|
||||
percentscrolled = (my - y - sbar.height + 1) / (float) barempty;
|
||||
calculatePercentScrolled();
|
||||
} else {
|
||||
@@ -118,8 +122,7 @@ public abstract class GuiScrollPane extends GuiWidget
|
||||
scrollpercent = percentscrolled;
|
||||
scrollmousey = my;
|
||||
}
|
||||
} else if (w.contains(mx, my))
|
||||
slotDown(mx - w.x, my - w.y + scrolledPixels(), button);
|
||||
} else if (w.contains(mx, my)) slotDown(mx - w.x, my - w.y + scrolledPixels(), button);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -137,10 +140,9 @@ public abstract class GuiScrollPane extends GuiWidget
|
||||
@Override
|
||||
public void mouseMovedOrUp(int mx, int my, int button) {
|
||||
Rectangle w = windowBounds();
|
||||
if (isScrolling() && button == 0)//we were scrolling and we released mouse
|
||||
scrollclicky = -1;
|
||||
else if (w.contains(mx, my))
|
||||
slotUp(mx - w.x, my - w.y + scrolledPixels(), button);
|
||||
if (isScrolling() && button == 0) // we were scrolling and we released mouse
|
||||
scrollclicky = -1;
|
||||
else if (w.contains(mx, my)) slotUp(mx - w.x, my - w.y + scrolledPixels(), button);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -151,12 +153,9 @@ public abstract class GuiScrollPane extends GuiWidget
|
||||
int barupallowed = (int) ((height - sbarh) * scrollpercent + 0.5);
|
||||
int bardownallowed = (height - sbarh) - barupallowed;
|
||||
|
||||
if (-scrolldiff > barupallowed)
|
||||
scrollmousey = scrollclicky - barupallowed;
|
||||
else if (scrolldiff > bardownallowed)
|
||||
scrollmousey = scrollclicky + bardownallowed;
|
||||
else
|
||||
scrollmousey = mousey;
|
||||
if (-scrolldiff > barupallowed) scrollmousey = scrollclicky - barupallowed;
|
||||
else if (scrolldiff > bardownallowed) scrollmousey = scrollclicky + bardownallowed;
|
||||
else scrollmousey = mousey;
|
||||
|
||||
calculatePercentScrolled();
|
||||
}
|
||||
@@ -180,7 +179,7 @@ public abstract class GuiScrollPane extends GuiWidget
|
||||
public void draw(int mx, int my, float frame) {
|
||||
Rectangle w = windowBounds();
|
||||
drawBackground(frame);
|
||||
drawContent(mx-w.x, my+scrolledPixels()-w.y, frame);
|
||||
drawContent(mx - w.x, my + scrolledPixels() - w.y, frame);
|
||||
drawOverlay(frame);
|
||||
drawScrollbar(frame);
|
||||
}
|
||||
@@ -192,24 +191,22 @@ public abstract class GuiScrollPane extends GuiWidget
|
||||
public abstract void drawContent(int mx, int my, float frame);
|
||||
|
||||
public void drawOverlay(float frame) {
|
||||
//outlines
|
||||
drawRect(x, y - 1, x + width, y, 0xffa0a0a0);//top
|
||||
drawRect(x, y + height, x + width, y + height + 1, 0xffa0a0a0);//bottom
|
||||
drawRect(x - 1, y - 1, x, y + height + 1, 0xffa0a0a0);//left
|
||||
drawRect(x + width, y - 1, x + width + 1, y + height + 1, 0xffa0a0a0);//right
|
||||
// outlines
|
||||
drawRect(x, y - 1, x + width, y, 0xffa0a0a0); // top
|
||||
drawRect(x, y + height, x + width, y + height + 1, 0xffa0a0a0); // bottom
|
||||
drawRect(x - 1, y - 1, x, y + height + 1, 0xffa0a0a0); // left
|
||||
drawRect(x + width, y - 1, x + width + 1, y + height + 1, 0xffa0a0a0); // right
|
||||
}
|
||||
|
||||
public void drawScrollbar(float frame) {
|
||||
Rectangle r = scrollbarBounds();
|
||||
|
||||
drawRect(r.x, r.y, r.x + r.width, r.y + r.height, 0xFF8B8B8B);//corners
|
||||
drawRect(r.x, r.y, r.x + r.width - 1, r.y + r.height - 1, 0xFFF0F0F0);//topleft up
|
||||
drawRect(r.x + 1, r.y + 1, r.x + r.width, r.y + r.height, 0xFF555555);//bottom right down
|
||||
drawRect(r.x + 1, r.y + 1, r.x + r.width - 1, r.y + r.height - 1, 0xFFC6C6C6);//scrollbar
|
||||
drawRect(r.x, r.y, r.x + r.width, r.y + r.height, 0xFF8B8B8B); // corners
|
||||
drawRect(r.x, r.y, r.x + r.width - 1, r.y + r.height - 1, 0xFFF0F0F0); // topleft up
|
||||
drawRect(r.x + 1, r.y + 1, r.x + r.width, r.y + r.height, 0xFF555555); // bottom right down
|
||||
drawRect(r.x + 1, r.y + 1, r.x + r.width - 1, r.y + r.height - 1, 0xFFC6C6C6); // scrollbar
|
||||
|
||||
int algn = scrollbarGuideAlignment();
|
||||
if (algn != 0)
|
||||
drawRect(algn > 0 ? r.x + r.width : r.x - 1, y, r.x, y + height, 0xFF808080);//lineguide
|
||||
if (algn != 0) drawRect(algn > 0 ? r.x + r.width : r.x - 1, y, r.x, y + height, 0xFF808080); // lineguide
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,11 +1,9 @@
|
||||
package codechicken.core.gui;
|
||||
|
||||
import java.awt.*;
|
||||
import org.lwjgl.input.Keyboard;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
public abstract class GuiScrollSlot extends GuiScrollPane
|
||||
{
|
||||
public abstract class GuiScrollSlot extends GuiScrollPane {
|
||||
protected String actionCommand;
|
||||
public boolean focused;
|
||||
protected ClickCounter<Integer> click = new ClickCounter<Integer>();
|
||||
@@ -40,13 +38,11 @@ public abstract class GuiScrollSlot extends GuiScrollPane
|
||||
|
||||
protected abstract void drawSlot(int slot, int x, int y, int mx, int my, float frame);
|
||||
|
||||
protected void unfocus() {
|
||||
}
|
||||
protected void unfocus() {}
|
||||
|
||||
public void setFocused(boolean focus) {
|
||||
focused = focus;
|
||||
if (!focused)
|
||||
unfocus();
|
||||
if (!focused) unfocus();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -56,37 +52,34 @@ public abstract class GuiScrollSlot extends GuiScrollPane
|
||||
|
||||
public int getSlotY(int slot) {
|
||||
int h = 0;
|
||||
for(int i = 0; i < slot; i++)
|
||||
h+=getSlotHeight(i);
|
||||
for (int i = 0; i < slot; i++) h += getSlotHeight(i);
|
||||
return h;
|
||||
}
|
||||
|
||||
public int getSlot(int my) {
|
||||
if (my < 0)
|
||||
return -1;
|
||||
if (my < 0) return -1;
|
||||
|
||||
int y = 0;
|
||||
for(int i = 0; i < getNumSlots(); i++) {
|
||||
for (int i = 0; i < getNumSlots(); i++) {
|
||||
int h = getSlotHeight(i);
|
||||
if(my >= y && my < y+h)
|
||||
return i;
|
||||
y+=h;
|
||||
if (my >= y && my < y + h) return i;
|
||||
y += h;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
public int getClickedSlot(int my) {
|
||||
return getSlot(my-windowBounds().y+scrolledPixels());
|
||||
return getSlot(my - windowBounds().y + scrolledPixels());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int scrolledPixels() {
|
||||
int scrolled = super.scrolledPixels();
|
||||
if(!smoothScroll) {
|
||||
if (!smoothScroll) {
|
||||
int slot = getSlot(scrolled);
|
||||
int sloty = getSlotY(slot);
|
||||
int sloth = getSlotHeight(slot);
|
||||
scrolled = sloty+(int)((scrolled-sloty)/(double)sloth+0.5)*sloth;
|
||||
scrolled = sloty + (int) ((scrolled - sloty) / (double) sloth + 0.5) * sloth;
|
||||
}
|
||||
return scrolled;
|
||||
}
|
||||
@@ -106,8 +99,7 @@ public abstract class GuiScrollSlot extends GuiScrollPane
|
||||
@Override
|
||||
public Rectangle scrollbarBounds() {
|
||||
Rectangle r = super.scrollbarBounds();
|
||||
if(scrollbarAlignment() == -1)
|
||||
r.x = x;
|
||||
if (scrollbarAlignment() == -1) r.x = x;
|
||||
return r;
|
||||
}
|
||||
|
||||
@@ -125,21 +117,16 @@ public abstract class GuiScrollSlot extends GuiScrollPane
|
||||
public void slotUp(int mx, int my, int button) {
|
||||
int slot = getSlot(my);
|
||||
int c = click.mouseUp(slot >= 0 ? slot : null, button);
|
||||
if(c > 0 && slot >= 0)
|
||||
slotClicked(slot, button, mx, my-getSlotY(slot), c);
|
||||
if (c > 0 && slot >= 0) slotClicked(slot, button, mx, my - getSlotY(slot), c);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void keyTyped(char c, int keycode) {
|
||||
if (!focused)
|
||||
return;
|
||||
if (!focused) return;
|
||||
|
||||
if (keycode == Keyboard.KEY_UP)
|
||||
selectPrev();
|
||||
if (keycode == Keyboard.KEY_DOWN)
|
||||
selectNext();
|
||||
if (keycode == Keyboard.KEY_RETURN && actionCommand != null)
|
||||
sendAction(actionCommand);
|
||||
if (keycode == Keyboard.KEY_UP) selectPrev();
|
||||
if (keycode == Keyboard.KEY_DOWN) selectNext();
|
||||
if (keycode == Keyboard.KEY_RETURN && actionCommand != null) sendAction(actionCommand);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -149,9 +136,9 @@ public abstract class GuiScrollSlot extends GuiScrollPane
|
||||
int y = 0;
|
||||
for (int slot = 0; slot < getNumSlots(); slot++) {
|
||||
int h = getSlotHeight(slot);
|
||||
if (y+h > scrolled && y < scrolled+w.height)
|
||||
drawSlot(slot, w.x, w.y+y-scrolledPixels(), mx, my-y, frame);
|
||||
y+=h;
|
||||
if (y + h > scrolled && y < scrolled + w.height)
|
||||
drawSlot(slot, w.x, w.y + y - scrolledPixels(), mx, my - y, frame);
|
||||
y += h;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -7,78 +7,57 @@ import net.minecraft.client.gui.GuiScreen;
|
||||
import net.minecraft.client.renderer.texture.TextureManager;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
|
||||
public class GuiWidget extends Gui
|
||||
{
|
||||
public class GuiWidget extends Gui {
|
||||
protected static final ResourceLocation guiTex = new ResourceLocation("textures/gui/widgets.png");
|
||||
|
||||
|
||||
public GuiScreen parentScreen;
|
||||
public TextureManager renderEngine;
|
||||
public FontRenderer fontRenderer;
|
||||
|
||||
|
||||
public int x;
|
||||
public int y;
|
||||
public int width;
|
||||
public int height;
|
||||
|
||||
public GuiWidget(int x, int y, int width, int height)
|
||||
{
|
||||
|
||||
public GuiWidget(int x, int y, int width, int height) {
|
||||
setSize(x, y, width, height);
|
||||
}
|
||||
|
||||
public void setSize(int x, int y, int width, int height)
|
||||
{
|
||||
|
||||
public void setSize(int x, int y, int width, int height) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
}
|
||||
|
||||
public boolean pointInside(int px, int py)
|
||||
{
|
||||
public boolean pointInside(int px, int py) {
|
||||
return px >= x && px < x + width && py >= y && py < y + height;
|
||||
}
|
||||
|
||||
public void sendAction(String actionCommand, Object... params)
|
||||
{
|
||||
|
||||
public void sendAction(String actionCommand, Object... params) {
|
||||
sendAction(parentScreen, actionCommand, params);
|
||||
}
|
||||
|
||||
public static void sendAction(GuiScreen screen, String actionCommand, Object... params)
|
||||
{
|
||||
if(actionCommand != null && screen instanceof IGuiActionListener)
|
||||
public static void sendAction(GuiScreen screen, String actionCommand, Object... params) {
|
||||
if (actionCommand != null && screen instanceof IGuiActionListener)
|
||||
((IGuiActionListener) screen).actionPerformed(actionCommand, params);
|
||||
}
|
||||
|
||||
public void mouseClicked(int x, int y, int button)
|
||||
{
|
||||
}
|
||||
public void mouseClicked(int x, int y, int button) {}
|
||||
|
||||
public void mouseMovedOrUp(int x, int y, int button)
|
||||
{
|
||||
}
|
||||
|
||||
public void mouseDragged(int x, int y, int button, long time)
|
||||
{
|
||||
}
|
||||
|
||||
public void update()
|
||||
{
|
||||
}
|
||||
public void mouseMovedOrUp(int x, int y, int button) {}
|
||||
|
||||
public void draw(int mousex, int mousey, float frame)
|
||||
{
|
||||
}
|
||||
public void mouseDragged(int x, int y, int button, long time) {}
|
||||
|
||||
public void keyTyped(char c, int keycode)
|
||||
{
|
||||
}
|
||||
public void update() {}
|
||||
|
||||
public void mouseScrolled(int x, int y, int scroll)
|
||||
{
|
||||
}
|
||||
|
||||
public void onAdded(GuiScreen s)
|
||||
{
|
||||
public void draw(int mousex, int mousey, float frame) {}
|
||||
|
||||
public void keyTyped(char c, int keycode) {}
|
||||
|
||||
public void mouseScrolled(int x, int y, int scroll) {}
|
||||
|
||||
public void onAdded(GuiScreen s) {
|
||||
Minecraft mc = Minecraft.getMinecraft();
|
||||
parentScreen = s;
|
||||
renderEngine = mc.renderEngine;
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package codechicken.core.gui;
|
||||
|
||||
public interface IGuiActionListener
|
||||
{
|
||||
public interface IGuiActionListener {
|
||||
public void actionPerformed(String actionCommand, Object... params);
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,6 @@
|
||||
package codechicken.core.internal;
|
||||
|
||||
import codechicken.core.CCUpdateChecker;
|
||||
|
||||
import codechicken.core.GuiModListScroll;
|
||||
import cpw.mods.fml.client.GuiModList;
|
||||
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
||||
@@ -11,14 +10,13 @@ import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import net.minecraftforge.client.event.GuiScreenEvent;
|
||||
|
||||
public class CCCEventHandler
|
||||
{
|
||||
public class CCCEventHandler {
|
||||
public static int renderTime;
|
||||
public static float renderFrame;
|
||||
|
||||
@SubscribeEvent
|
||||
public void clientTick(TickEvent.ClientTickEvent event) {
|
||||
if(event.phase == Phase.END) {
|
||||
if (event.phase == Phase.END) {
|
||||
CCUpdateChecker.tick();
|
||||
renderTime++;
|
||||
}
|
||||
@@ -26,14 +24,12 @@ public class CCCEventHandler
|
||||
|
||||
@SubscribeEvent
|
||||
public void renderTick(TickEvent.RenderTickEvent event) {
|
||||
if(event.phase == Phase.START)
|
||||
renderFrame = event.renderTickTime;
|
||||
if (event.phase == Phase.START) renderFrame = event.renderTickTime;
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void posGuiRender(GuiScreenEvent.DrawScreenEvent.Post event) {
|
||||
if(event.gui instanceof GuiModList)
|
||||
GuiModListScroll.draw((GuiModList)event.gui, event.mouseX, event.mouseY);
|
||||
if (event.gui instanceof GuiModList) GuiModListScroll.draw((GuiModList) event.gui, event.mouseX, event.mouseY);
|
||||
}
|
||||
}
|
||||
@@ -1,127 +1,96 @@
|
||||
package codechicken.core.inventory;
|
||||
|
||||
import java.awt.Point;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.lwjgl.input.Mouse;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import codechicken.lib.gui.GuiDraw;
|
||||
import codechicken.core.gui.GuiWidget;
|
||||
import codechicken.core.gui.IGuiActionListener;
|
||||
|
||||
import codechicken.lib.gui.GuiDraw;
|
||||
import java.awt.Point;
|
||||
import java.util.ArrayList;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.inventory.GuiContainer;
|
||||
import net.minecraft.inventory.Container;
|
||||
import org.lwjgl.input.Mouse;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
public class GuiContainerWidget extends GuiContainer implements IGuiActionListener
|
||||
{
|
||||
public class GuiContainerWidget extends GuiContainer implements IGuiActionListener {
|
||||
public ArrayList<GuiWidget> widgets = new ArrayList<GuiWidget>();
|
||||
|
||||
public GuiContainerWidget(Container inventorySlots)
|
||||
{
|
||||
|
||||
public GuiContainerWidget(Container inventorySlots) {
|
||||
this(inventorySlots, 176, 166);
|
||||
}
|
||||
|
||||
public GuiContainerWidget(Container inventorySlots, int xSize, int ySize)
|
||||
{
|
||||
|
||||
public GuiContainerWidget(Container inventorySlots, int xSize, int ySize) {
|
||||
super(inventorySlots);
|
||||
this.xSize = xSize;
|
||||
this.ySize = ySize;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void setWorldAndResolution(Minecraft mc, int i, int j)
|
||||
{
|
||||
public void setWorldAndResolution(Minecraft mc, int i, int j) {
|
||||
super.setWorldAndResolution(mc, i, j);
|
||||
if(widgets.isEmpty())
|
||||
addWidgets();
|
||||
if (widgets.isEmpty()) addWidgets();
|
||||
}
|
||||
|
||||
public void add(GuiWidget widget)
|
||||
{
|
||||
|
||||
public void add(GuiWidget widget) {
|
||||
widgets.add(widget);
|
||||
widget.onAdded(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void drawGuiContainerBackgroundLayer(float f, int mousex, int mousey)
|
||||
{
|
||||
protected void drawGuiContainerBackgroundLayer(float f, int mousex, int mousey) {
|
||||
GL11.glTranslated(guiLeft, guiTop, 0);
|
||||
drawBackground();
|
||||
for(GuiWidget widget : widgets)
|
||||
widget.draw(mousex-guiLeft, mousey-guiTop, f);
|
||||
|
||||
for (GuiWidget widget : widgets) widget.draw(mousex - guiLeft, mousey - guiTop, f);
|
||||
|
||||
GL11.glTranslated(-guiLeft, -guiTop, 0);
|
||||
}
|
||||
|
||||
public void drawBackground()
|
||||
{
|
||||
}
|
||||
|
||||
public void drawBackground() {}
|
||||
|
||||
@Override
|
||||
protected void mouseClicked(int x, int y, int button)
|
||||
{
|
||||
protected void mouseClicked(int x, int y, int button) {
|
||||
super.mouseClicked(x, y, button);
|
||||
for(GuiWidget widget : widgets)
|
||||
widget.mouseClicked(x-guiLeft, y-guiTop, button);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void mouseMovedOrUp(int x, int y, int button)
|
||||
{
|
||||
super.mouseMovedOrUp(x, y, button);
|
||||
for(GuiWidget widget : widgets)
|
||||
widget.mouseMovedOrUp(x-guiLeft, y-guiTop, button);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void mouseClickMove(int x, int y, int button, long time)
|
||||
{
|
||||
super.mouseClickMove(x, y, button, time);
|
||||
for(GuiWidget widget : widgets)
|
||||
widget.mouseDragged(x-guiLeft, y-guiTop, button, time);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateScreen()
|
||||
{
|
||||
super.updateScreen();
|
||||
if(mc.currentScreen == this)
|
||||
for(GuiWidget widget : widgets)
|
||||
widget.update();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void keyTyped(char c, int keycode)
|
||||
{
|
||||
super.keyTyped(c, keycode);
|
||||
for(GuiWidget widget : widgets)
|
||||
widget.keyTyped(c, keycode);
|
||||
for (GuiWidget widget : widgets) widget.mouseClicked(x - guiLeft, y - guiTop, button);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleMouseInput()
|
||||
{
|
||||
protected void mouseMovedOrUp(int x, int y, int button) {
|
||||
super.mouseMovedOrUp(x, y, button);
|
||||
for (GuiWidget widget : widgets) widget.mouseMovedOrUp(x - guiLeft, y - guiTop, button);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void mouseClickMove(int x, int y, int button, long time) {
|
||||
super.mouseClickMove(x, y, button, time);
|
||||
for (GuiWidget widget : widgets) widget.mouseDragged(x - guiLeft, y - guiTop, button, time);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateScreen() {
|
||||
super.updateScreen();
|
||||
if (mc.currentScreen == this) for (GuiWidget widget : widgets) widget.update();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void keyTyped(char c, int keycode) {
|
||||
super.keyTyped(c, keycode);
|
||||
for (GuiWidget widget : widgets) widget.keyTyped(c, keycode);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleMouseInput() {
|
||||
super.handleMouseInput();
|
||||
int i = Mouse.getEventDWheel();
|
||||
if(i != 0)
|
||||
{
|
||||
if (i != 0) {
|
||||
Point p = GuiDraw.getMousePosition();
|
||||
int scroll = i > 0 ? 1 : -1;
|
||||
for(GuiWidget widget : widgets)
|
||||
widget.mouseScrolled(p.x, p.y, scroll);
|
||||
for (GuiWidget widget : widgets) widget.mouseScrolled(p.x, p.y, scroll);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void actionPerformed(String ident, Object... params)
|
||||
{
|
||||
}
|
||||
public void actionPerformed(String ident, Object... params) {}
|
||||
|
||||
public void addWidgets()
|
||||
{
|
||||
}
|
||||
public void addWidgets() {}
|
||||
|
||||
@Override
|
||||
public void onGuiClosed() {
|
||||
|
||||
@@ -1,5 +1,16 @@
|
||||
package codechicken.core.launch;
|
||||
|
||||
import codechicken.core.asm.*;
|
||||
import codechicken.lib.config.ConfigTag;
|
||||
import cpw.mods.fml.common.FMLCommonHandler;
|
||||
import cpw.mods.fml.common.versioning.DefaultArtifactVersion;
|
||||
import cpw.mods.fml.common.versioning.VersionParser;
|
||||
import cpw.mods.fml.relauncher.CoreModManager;
|
||||
import cpw.mods.fml.relauncher.FMLInjectionData;
|
||||
import cpw.mods.fml.relauncher.IFMLCallHook;
|
||||
import cpw.mods.fml.relauncher.IFMLLoadingPlugin;
|
||||
import cpw.mods.fml.relauncher.IFMLLoadingPlugin.MCVersion;
|
||||
import cpw.mods.fml.relauncher.IFMLLoadingPlugin.TransformerExclusions;
|
||||
import java.awt.*;
|
||||
import java.io.File;
|
||||
import java.lang.reflect.Constructor;
|
||||
@@ -11,32 +22,18 @@ import java.util.Map;
|
||||
import java.util.jar.Attributes;
|
||||
import java.util.jar.JarFile;
|
||||
import java.util.jar.Manifest;
|
||||
|
||||
import javax.swing.JEditorPane;
|
||||
import javax.swing.JOptionPane;
|
||||
import javax.swing.event.HyperlinkEvent;
|
||||
import javax.swing.event.HyperlinkListener;
|
||||
|
||||
import codechicken.core.asm.*;
|
||||
import codechicken.lib.config.ConfigTag;
|
||||
import cpw.mods.fml.common.FMLCommonHandler;
|
||||
import cpw.mods.fml.relauncher.CoreModManager;
|
||||
|
||||
import cpw.mods.fml.common.versioning.DefaultArtifactVersion;
|
||||
import cpw.mods.fml.common.versioning.VersionParser;
|
||||
import cpw.mods.fml.relauncher.FMLInjectionData;
|
||||
import cpw.mods.fml.relauncher.IFMLCallHook;
|
||||
import cpw.mods.fml.relauncher.IFMLLoadingPlugin;
|
||||
import cpw.mods.fml.relauncher.IFMLLoadingPlugin.MCVersion;
|
||||
import cpw.mods.fml.relauncher.IFMLLoadingPlugin.TransformerExclusions;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
@TransformerExclusions(value = {"codechicken.core.asm", "codechicken.obfuscator"})
|
||||
@MCVersion( "1.7.10" )
|
||||
public class CodeChickenCorePlugin implements IFMLLoadingPlugin, IFMLCallHook
|
||||
{
|
||||
@MCVersion("1.7.10")
|
||||
public class CodeChickenCorePlugin implements IFMLLoadingPlugin, IFMLCallHook {
|
||||
public static final String mcVersion = "[1.7.10]";
|
||||
|
||||
@Deprecated
|
||||
public static final String version = "1.1.3-unused";
|
||||
|
||||
@@ -45,8 +42,7 @@ public class CodeChickenCorePlugin implements IFMLLoadingPlugin, IFMLCallHook
|
||||
public static Logger logger = LogManager.getLogger("CodeChickenCore");
|
||||
|
||||
public CodeChickenCorePlugin() {
|
||||
if (minecraftDir != null)
|
||||
return;//get called twice, once for IFMLCallHook
|
||||
if (minecraftDir != null) return; // get called twice, once for IFMLCallHook
|
||||
|
||||
minecraftDir = (File) FMLInjectionData.data()[6];
|
||||
currentMcVersion = (String) FMLInjectionData.data()[4];
|
||||
@@ -58,11 +54,20 @@ public class CodeChickenCorePlugin implements IFMLLoadingPlugin, IFMLCallHook
|
||||
private void injectDeobfPlugin() {
|
||||
try {
|
||||
Class<?> wrapperClass = Class.forName("cpw.mods.fml.relauncher.CoreModManager$FMLPluginWrapper");
|
||||
Constructor wrapperConstructor = wrapperClass.getConstructor(String.class, IFMLLoadingPlugin.class, File.class, Integer.TYPE, String[].class);
|
||||
Constructor wrapperConstructor = wrapperClass.getConstructor(
|
||||
String.class, IFMLLoadingPlugin.class, File.class, Integer.TYPE, String[].class);
|
||||
Field f_loadPlugins = CoreModManager.class.getDeclaredField("loadPlugins");
|
||||
wrapperConstructor.setAccessible(true);
|
||||
f_loadPlugins.setAccessible(true);
|
||||
((List)f_loadPlugins.get(null)).add(2, wrapperConstructor.newInstance("CCCDeobfPlugin", new MCPDeobfuscationTransformer.LoadPlugin(), null, 0, new String[0]));
|
||||
((List) f_loadPlugins.get(null))
|
||||
.add(
|
||||
2,
|
||||
wrapperConstructor.newInstance(
|
||||
"CCCDeobfPlugin",
|
||||
new MCPDeobfuscationTransformer.LoadPlugin(),
|
||||
null,
|
||||
0,
|
||||
new String[0]));
|
||||
} catch (Exception e) {
|
||||
logger.error("Failed to inject MCPDeobfuscation Transformer", e);
|
||||
}
|
||||
@@ -74,22 +79,22 @@ public class CodeChickenCorePlugin implements IFMLLoadingPlugin, IFMLCallHook
|
||||
String err = "This version of " + mod + " does not support minecraft version " + mcVersion;
|
||||
logger.error(err);
|
||||
|
||||
JEditorPane ep = new JEditorPane("text/html",
|
||||
"<html>" +
|
||||
err +
|
||||
"<br>Remove it from your coremods folder and check <a href=\"http://www.minecraftforum.net/topic/909223-\">here</a> for updates" +
|
||||
"</html>");
|
||||
JEditorPane ep = new JEditorPane(
|
||||
"text/html",
|
||||
"<html>" + err
|
||||
+ "<br>Remove it from your coremods folder and check <a href=\"http://www.minecraftforum.net/topic/909223-\">here</a> for updates"
|
||||
+ "</html>");
|
||||
|
||||
ep.setEditable(false);
|
||||
ep.setOpaque(false);
|
||||
ep.addHyperlinkListener(new HyperlinkListener()
|
||||
{
|
||||
ep.addHyperlinkListener(new HyperlinkListener() {
|
||||
@Override
|
||||
public void hyperlinkUpdate(HyperlinkEvent event) {
|
||||
try {
|
||||
if (event.getEventType().equals(HyperlinkEvent.EventType.ACTIVATED))
|
||||
Desktop.getDesktop().browse(event.getURL().toURI());
|
||||
} catch (Exception ignored) {}
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@@ -101,11 +106,15 @@ public class CodeChickenCorePlugin implements IFMLLoadingPlugin, IFMLCallHook
|
||||
public static long parseSize(String text) {
|
||||
double d = Double.parseDouble(text.replaceAll("[GMK]B?$", ""));
|
||||
long l = Math.round(d * 1024 * 1024 * 1024L);
|
||||
switch (text.replaceAll("\\d?","").toUpperCase().charAt(0)) {
|
||||
default: l /= 1024;
|
||||
case 'K': l /= 1024;
|
||||
case 'M': l /= 1024;
|
||||
case 'G': return l;
|
||||
switch (text.replaceAll("\\d?", "").toUpperCase().charAt(0)) {
|
||||
default:
|
||||
l /= 1024;
|
||||
case 'K':
|
||||
l /= 1024;
|
||||
case 'M':
|
||||
l /= 1024;
|
||||
case 'G':
|
||||
return l;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -125,28 +134,45 @@ public class CodeChickenCorePlugin implements IFMLLoadingPlugin, IFMLCallHook
|
||||
}
|
||||
|
||||
public static void systemCheck(ConfigTag checkRAM) {
|
||||
long minBytes = parseSize(checkRAM.getTag("minRAM").setComment("Amount of RAM minimum this modpack needs to load").getValue("3GB"));
|
||||
long minBytes = parseSize(checkRAM.getTag("minRAM")
|
||||
.setComment("Amount of RAM minimum this modpack needs to load")
|
||||
.getValue("3GB"));
|
||||
if (Runtime.getRuntime().maxMemory() < minBytes) {
|
||||
String err = "You should have at least " + humanReadableByteCountBin(minBytes) + " of RAM but you have only allocated " + humanReadableByteCountBin(Runtime.getRuntime().maxMemory()) + ".";
|
||||
String err = "You should have at least " + humanReadableByteCountBin(minBytes)
|
||||
+ " of RAM but you have only allocated "
|
||||
+ humanReadableByteCountBin(Runtime.getRuntime().maxMemory()) + ".";
|
||||
logger.error(err);
|
||||
|
||||
JEditorPane ep = new JEditorPane("text/html",
|
||||
"<html>" + err + "<br>" + checkRAM.getTag("modPack").setComment("Name of the modpack").getValue("Unidentified ModPack") +
|
||||
" seriously won't run without enough RAM. " + checkRAM.getTag("wiki").setComment("Webpage describing RAM settings").getValue("See <a href=\"https://downloadmoreram.com\">DownloadMoreRam.com</a> for details.") +
|
||||
"<br>Recommended values are between " + checkRAM.getTag("recRAM").setComment("Lower bound of recommended RAM").getValue("4GB") + " and " +
|
||||
checkRAM.getTag("recRAMUpper").setComment("Upper bound of recommended RAM").getValue("6GB") + ". Check your launcher's JVM arguments." +
|
||||
"</html>");
|
||||
JEditorPane ep = new JEditorPane(
|
||||
"text/html",
|
||||
"<html>" + err + "<br>"
|
||||
+ checkRAM.getTag("modPack")
|
||||
.setComment("Name of the modpack")
|
||||
.getValue("Unidentified ModPack")
|
||||
+ " seriously won't run without enough RAM. "
|
||||
+ checkRAM.getTag("wiki")
|
||||
.setComment("Webpage describing RAM settings")
|
||||
.getValue(
|
||||
"See <a href=\"https://downloadmoreram.com\">DownloadMoreRam.com</a> for details.")
|
||||
+ "<br>Recommended values are between "
|
||||
+ checkRAM.getTag("recRAM")
|
||||
.setComment("Lower bound of recommended RAM")
|
||||
.getValue("4GB") + " and "
|
||||
+ checkRAM.getTag("recRAMUpper")
|
||||
.setComment("Upper bound of recommended RAM")
|
||||
.getValue("6GB")
|
||||
+ ". Check your launcher's JVM arguments." + "</html>");
|
||||
|
||||
ep.setEditable(false);
|
||||
ep.setOpaque(false);
|
||||
ep.addHyperlinkListener(new HyperlinkListener()
|
||||
{
|
||||
ep.addHyperlinkListener(new HyperlinkListener() {
|
||||
@Override
|
||||
public void hyperlinkUpdate(HyperlinkEvent event) {
|
||||
try {
|
||||
if (event.getEventType().equals(HyperlinkEvent.EventType.ACTIVATED))
|
||||
Desktop.getDesktop().browse(event.getURL().toURI());
|
||||
} catch (Exception ignored) {}
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@@ -159,12 +185,12 @@ public class CodeChickenCorePlugin implements IFMLLoadingPlugin, IFMLCallHook
|
||||
@Override
|
||||
public String[] getASMTransformerClass() {
|
||||
versionCheck(mcVersion, "CodeChickenCore");
|
||||
return new String[]{
|
||||
"codechicken.lib.asm.ClassHeirachyManager",
|
||||
"codechicken.core.asm.InterfaceDependancyTransformer",
|
||||
"codechicken.core.asm.TweakTransformer",
|
||||
"codechicken.core.asm.DelegatedTransformer",
|
||||
"codechicken.core.asm.DefaultImplementationTransformer"};
|
||||
return new String[] {
|
||||
"codechicken.lib.asm.ClassHeirachyManager",
|
||||
"codechicken.core.asm.TweakTransformer",
|
||||
"codechicken.core.asm.DelegatedTransformer",
|
||||
"codechicken.core.asm.DefaultImplementationTransformer"
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -183,17 +209,19 @@ public class CodeChickenCorePlugin implements IFMLLoadingPlugin, IFMLCallHook
|
||||
}
|
||||
|
||||
@Override
|
||||
public void injectData(Map<String, Object> data) {
|
||||
}
|
||||
public void injectData(Map<String, Object> data) {}
|
||||
|
||||
@Override
|
||||
public Void call() {
|
||||
CodeChickenCoreModContainer.loadConfig();
|
||||
ConfigTag checkRAM;
|
||||
checkRAM = CodeChickenCoreModContainer.config.getTag("checks")
|
||||
.setComment("Configuration options for checking various requirements for a modpack.").useBraces();
|
||||
if(checkRAM.getTag("checkRAM").setComment("If set to true, check RAM available for Minecraft before continuing to load").getBooleanValue(false))
|
||||
systemCheck(checkRAM);
|
||||
checkRAM = CodeChickenCoreModContainer.config
|
||||
.getTag("checks")
|
||||
.setComment("Configuration options for checking various requirements for a modpack.")
|
||||
.useBraces();
|
||||
if (checkRAM.getTag("checkRAM")
|
||||
.setComment("If set to true, check RAM available for Minecraft before continuing to load")
|
||||
.getBooleanValue(false)) systemCheck(checkRAM);
|
||||
TweakTransformer.load();
|
||||
scanCodeChickenMods();
|
||||
|
||||
@@ -202,31 +230,24 @@ public class CodeChickenCorePlugin implements IFMLLoadingPlugin, IFMLCallHook
|
||||
|
||||
private void scanCodeChickenMods() {
|
||||
File modsDir = new File(minecraftDir, "mods");
|
||||
for (File file : modsDir.listFiles())
|
||||
scanMod(file);
|
||||
for (File file : modsDir.listFiles()) scanMod(file);
|
||||
File versionModsDir = new File(minecraftDir, "mods/" + currentMcVersion);
|
||||
if (versionModsDir.exists())
|
||||
for (File file : versionModsDir.listFiles())
|
||||
scanMod(file);
|
||||
if (versionModsDir.exists()) for (File file : versionModsDir.listFiles()) scanMod(file);
|
||||
}
|
||||
|
||||
private void scanMod(File file) {
|
||||
if (!file.getName().endsWith(".jar") && !file.getName().endsWith(".zip"))
|
||||
return;
|
||||
if (!file.getName().endsWith(".jar") && !file.getName().endsWith(".zip")) return;
|
||||
|
||||
try {
|
||||
JarFile jar = new JarFile(file);
|
||||
try {
|
||||
Manifest manifest = jar.getManifest();
|
||||
if (manifest == null)
|
||||
return;
|
||||
if (manifest == null) return;
|
||||
Attributes attr = manifest.getMainAttributes();
|
||||
if (attr == null)
|
||||
return;
|
||||
if (attr == null) return;
|
||||
|
||||
String transformer = attr.getValue("CCTransformer");
|
||||
if (transformer != null)
|
||||
DelegatedTransformer.addTransformer(transformer, jar, file);
|
||||
if (transformer != null) DelegatedTransformer.addTransformer(transformer, jar, file);
|
||||
} finally {
|
||||
jar.close();
|
||||
}
|
||||
|
||||
@@ -9,13 +9,6 @@ import cpw.mods.fml.relauncher.FMLLaunchHandler;
|
||||
import cpw.mods.fml.relauncher.IFMLCallHook;
|
||||
import cpw.mods.fml.relauncher.IFMLLoadingPlugin;
|
||||
import cpw.mods.fml.relauncher.IFMLLoadingPlugin.MCVersion;
|
||||
import net.minecraft.launchwrapper.LaunchClassLoader;
|
||||
import sun.misc.URLClassPath;
|
||||
import sun.net.util.URLUtil;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.event.HyperlinkEvent;
|
||||
import javax.swing.event.HyperlinkListener;
|
||||
import java.awt.*;
|
||||
import java.awt.Dialog.ModalityType;
|
||||
import java.awt.event.WindowAdapter;
|
||||
@@ -29,19 +22,25 @@ import java.net.URL;
|
||||
import java.net.URLClassLoader;
|
||||
import java.net.URLConnection;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.List;
|
||||
import java.util.*;
|
||||
import java.util.List;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.regex.PatternSyntaxException;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipFile;
|
||||
import javax.swing.*;
|
||||
import javax.swing.event.HyperlinkEvent;
|
||||
import javax.swing.event.HyperlinkListener;
|
||||
import net.minecraft.launchwrapper.LaunchClassLoader;
|
||||
import sun.misc.URLClassPath;
|
||||
import sun.net.util.URLUtil;
|
||||
|
||||
/**
|
||||
* For autodownloading stuff.
|
||||
* This is really unoriginal, mostly ripped off FML, credits to cpw.
|
||||
*/
|
||||
@MCVersion( "1.7.10" )
|
||||
@MCVersion("1.7.10")
|
||||
public class DepLoader implements IFMLLoadingPlugin, IFMLCallHook {
|
||||
private static ByteBuffer downloadBuffer = ByteBuffer.allocateDirect(1 << 23);
|
||||
private static final String owner = "CB's DepLoader";
|
||||
@@ -74,10 +73,12 @@ public class DepLoader implements IFMLLoadingPlugin, IFMLCallHook {
|
||||
private Box makeProgressPanel() {
|
||||
Box box = Box.createVerticalBox();
|
||||
box.add(Box.createRigidArea(new Dimension(0, 10)));
|
||||
JLabel welcomeLabel = new JLabel("<html><b><font size='+1'>" + owner + " is setting up your minecraft environment</font></b></html>");
|
||||
JLabel welcomeLabel = new JLabel("<html><b><font size='+1'>" + owner
|
||||
+ " is setting up your minecraft environment</font></b></html>");
|
||||
box.add(welcomeLabel);
|
||||
welcomeLabel.setAlignmentY(LEFT_ALIGNMENT);
|
||||
welcomeLabel = new JLabel("<html>Please wait, " + owner + " has some tasks to do before you can play</html>");
|
||||
welcomeLabel =
|
||||
new JLabel("<html>Please wait, " + owner + " has some tasks to do before you can play</html>");
|
||||
welcomeLabel.setAlignmentY(LEFT_ALIGNMENT);
|
||||
box.add(welcomeLabel);
|
||||
box.add(Box.createRigidArea(new Dimension(0, 10)));
|
||||
@@ -93,12 +94,11 @@ public class DepLoader implements IFMLLoadingPlugin, IFMLCallHook {
|
||||
|
||||
@Override
|
||||
public JDialog makeDialog() {
|
||||
if (container != null)
|
||||
return container;
|
||||
if (container != null) return container;
|
||||
|
||||
setMessageType(JOptionPane.INFORMATION_MESSAGE);
|
||||
setMessage(makeProgressPanel());
|
||||
setOptions(new Object[]{"Stop"});
|
||||
setOptions(new Object[] {"Stop"});
|
||||
addPropertyChangeListener(new PropertyChangeListener() {
|
||||
@Override
|
||||
public void propertyChange(PropertyChangeEvent evt) {
|
||||
@@ -119,39 +119,40 @@ public class DepLoader implements IFMLLoadingPlugin, IFMLCallHook {
|
||||
container.addWindowListener(new WindowAdapter() {
|
||||
@Override
|
||||
public void windowClosing(WindowEvent e) {
|
||||
requestClose("Closing this window will stop minecraft from launching\nAre you sure you wish to do this?");
|
||||
requestClose(
|
||||
"Closing this window will stop minecraft from launching\nAre you sure you wish to do this?");
|
||||
}
|
||||
});
|
||||
return container;
|
||||
}
|
||||
|
||||
protected void requestClose(String message) {
|
||||
int shouldClose = JOptionPane.showConfirmDialog(container, message, "Are you sure you want to stop?", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE);
|
||||
if (shouldClose == JOptionPane.YES_OPTION)
|
||||
container.dispose();
|
||||
int shouldClose = JOptionPane.showConfirmDialog(
|
||||
container,
|
||||
message,
|
||||
"Are you sure you want to stop?",
|
||||
JOptionPane.YES_NO_OPTION,
|
||||
JOptionPane.WARNING_MESSAGE);
|
||||
if (shouldClose == JOptionPane.YES_OPTION) container.dispose();
|
||||
|
||||
stopIt = true;
|
||||
if (pokeThread != null)
|
||||
pokeThread.interrupt();
|
||||
if (pokeThread != null) pokeThread.interrupt();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateProgressString(String progressUpdate, Object... data) {
|
||||
//FMLLog.finest(progressUpdate, data);
|
||||
if (currentActivity != null)
|
||||
currentActivity.setText(String.format(progressUpdate, data));
|
||||
// FMLLog.finest(progressUpdate, data);
|
||||
if (currentActivity != null) currentActivity.setText(String.format(progressUpdate, data));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resetProgress(int sizeGuess) {
|
||||
if (progress != null)
|
||||
progress.getModel().setRangeProperties(0, 0, 0, sizeGuess, false);
|
||||
if (progress != null) progress.getModel().setRangeProperties(0, 0, 0, sizeGuess, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateProgress(int fullLength) {
|
||||
if (progress != null)
|
||||
progress.getModel().setValue(fullLength);
|
||||
if (progress != null) progress.getModel().setValue(fullLength);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -166,12 +167,13 @@ public class DepLoader implements IFMLLoadingPlugin, IFMLCallHook {
|
||||
|
||||
@Override
|
||||
public void showErrorDialog(String name, String url) {
|
||||
JEditorPane ep = new JEditorPane("text/html",
|
||||
"<html>" +
|
||||
owner + " was unable to download required library " + name +
|
||||
"<br>Check your internet connection and try restarting or download it manually from" +
|
||||
"<br><a href=\"" + url + "\">" + url + "</a> and put it in your mods folder" +
|
||||
"</html>");
|
||||
JEditorPane ep = new JEditorPane(
|
||||
"text/html",
|
||||
"<html>" + owner
|
||||
+ " was unable to download required library " + name
|
||||
+ "<br>Check your internet connection and try restarting or download it manually from"
|
||||
+ "<br><a href=\""
|
||||
+ url + "\">" + url + "</a> and put it in your mods folder" + "</html>");
|
||||
|
||||
ep.setEditable(false);
|
||||
ep.setOpaque(false);
|
||||
@@ -192,16 +194,13 @@ public class DepLoader implements IFMLLoadingPlugin, IFMLCallHook {
|
||||
|
||||
public static class DummyDownloader implements IDownloadDisplay {
|
||||
@Override
|
||||
public void resetProgress(int sizeGuess) {
|
||||
}
|
||||
public void resetProgress(int sizeGuess) {}
|
||||
|
||||
@Override
|
||||
public void setPokeThread(Thread currentThread) {
|
||||
}
|
||||
public void setPokeThread(Thread currentThread) {}
|
||||
|
||||
@Override
|
||||
public void updateProgress(int fullLength) {
|
||||
}
|
||||
public void updateProgress(int fullLength) {}
|
||||
|
||||
@Override
|
||||
public boolean shouldStopIt() {
|
||||
@@ -209,8 +208,7 @@ public class DepLoader implements IFMLLoadingPlugin, IFMLCallHook {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateProgressString(String string, Object... data) {
|
||||
}
|
||||
public void updateProgressString(String string, Object... data) {}
|
||||
|
||||
@Override
|
||||
public Object makeDialog() {
|
||||
@@ -218,12 +216,10 @@ public class DepLoader implements IFMLLoadingPlugin, IFMLCallHook {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void showErrorDialog(String name, String url) {
|
||||
}
|
||||
public void showErrorDialog(String name, String url) {}
|
||||
}
|
||||
|
||||
public static class VersionedFile
|
||||
{
|
||||
public static class VersionedFile {
|
||||
public final Pattern pattern;
|
||||
public final String filename;
|
||||
public final ComparableVersion version;
|
||||
@@ -233,11 +229,10 @@ public class DepLoader implements IFMLLoadingPlugin, IFMLCallHook {
|
||||
this.pattern = pattern;
|
||||
this.filename = filename;
|
||||
Matcher m = pattern.matcher(filename);
|
||||
if(m.matches()) {
|
||||
if (m.matches()) {
|
||||
name = m.group(1);
|
||||
version = new ComparableVersion(m.group(2));
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
name = null;
|
||||
version = null;
|
||||
}
|
||||
@@ -248,8 +243,7 @@ public class DepLoader implements IFMLLoadingPlugin, IFMLCallHook {
|
||||
}
|
||||
}
|
||||
|
||||
public static class Dependency
|
||||
{
|
||||
public static class Dependency {
|
||||
public String url;
|
||||
public VersionedFile file;
|
||||
|
||||
@@ -281,21 +275,20 @@ public class DepLoader implements IFMLLoadingPlugin, IFMLCallHook {
|
||||
|
||||
modsDir = new File(mcDir, "mods");
|
||||
v_modsDir = new File(mcDir, "mods/" + mcVer);
|
||||
if (!v_modsDir.exists())
|
||||
v_modsDir.mkdirs();
|
||||
if (!v_modsDir.exists()) v_modsDir.mkdirs();
|
||||
}
|
||||
|
||||
private void addClasspath(String name) {
|
||||
try {
|
||||
((LaunchClassLoader) DepLoader.class.getClassLoader()).addURL(new File(v_modsDir, name).toURI().toURL());
|
||||
((LaunchClassLoader) DepLoader.class.getClassLoader())
|
||||
.addURL(new File(v_modsDir, name).toURI().toURL());
|
||||
} catch (MalformedURLException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
private void deleteMod(File mod) {
|
||||
if (mod.delete())
|
||||
return;
|
||||
if (mod.delete()) return;
|
||||
|
||||
try {
|
||||
ClassLoader cl = DepLoader.class.getClassLoader();
|
||||
@@ -319,7 +312,8 @@ public class DepLoader implements IFMLLoadingPlugin, IFMLCallHook {
|
||||
|
||||
if (!mod.delete()) {
|
||||
mod.deleteOnExit();
|
||||
String msg = owner + " was unable to delete file " + mod.getPath() + " the game will now try to delete it on exit. If this dialog appears again, delete it manually.";
|
||||
String msg = owner + " was unable to delete file " + mod.getPath()
|
||||
+ " the game will now try to delete it on exit. If this dialog appears again, delete it manually.";
|
||||
CodeChickenCorePlugin.logger.error(msg);
|
||||
if (!GraphicsEnvironment.isHeadless())
|
||||
JOptionPane.showMessageDialog(null, msg, "An update error has occurred", JOptionPane.ERROR_MESSAGE);
|
||||
@@ -348,7 +342,8 @@ public class DepLoader implements IFMLLoadingPlugin, IFMLCallHook {
|
||||
} catch (Exception e) {
|
||||
libFile.delete();
|
||||
if (downloadMonitor.shouldStopIt()) {
|
||||
CodeChickenCorePlugin.logger.error("You have stopped the downloading operation before it could complete");
|
||||
CodeChickenCorePlugin.logger.error(
|
||||
"You have stopped the downloading operation before it could complete");
|
||||
System.exit(1);
|
||||
return;
|
||||
}
|
||||
@@ -359,7 +354,9 @@ public class DepLoader implements IFMLLoadingPlugin, IFMLCallHook {
|
||||
|
||||
private void download(InputStream is, int sizeGuess, File target) throws Exception {
|
||||
if (sizeGuess > downloadBuffer.capacity())
|
||||
throw new Exception(String.format("The file %s is too large to be downloaded by " + owner + " - the download is invalid", target.getName()));
|
||||
throw new Exception(String.format(
|
||||
"The file %s is too large to be downloaded by " + owner + " - the download is invalid",
|
||||
target.getName()));
|
||||
|
||||
downloadBuffer.clear();
|
||||
|
||||
@@ -393,9 +390,7 @@ public class DepLoader implements IFMLLoadingPlugin, IFMLCallHook {
|
||||
/*String cksum = generateChecksum(downloadBuffer);
|
||||
if (cksum.equals(validationHash))
|
||||
{*/
|
||||
if (!target.exists())
|
||||
target.createNewFile();
|
||||
|
||||
if (!target.exists()) target.createNewFile();
|
||||
|
||||
downloadBuffer.position(0);
|
||||
FileOutputStream fos = new FileOutputStream(target);
|
||||
@@ -414,19 +409,16 @@ public class DepLoader implements IFMLLoadingPlugin, IFMLCallHook {
|
||||
private String checkExisting(Dependency dep) {
|
||||
for (File f : modsDir.listFiles()) {
|
||||
VersionedFile vfile = new VersionedFile(f.getName(), dep.file.pattern);
|
||||
if (!vfile.matches() || !vfile.name.equals(dep.file.name))
|
||||
continue;
|
||||
if (!vfile.matches() || !vfile.name.equals(dep.file.name)) continue;
|
||||
|
||||
if (f.renameTo(new File(v_modsDir, f.getName())))
|
||||
continue;
|
||||
if (f.renameTo(new File(v_modsDir, f.getName()))) continue;
|
||||
|
||||
deleteMod(f);
|
||||
}
|
||||
|
||||
for (File f : v_modsDir.listFiles()) {
|
||||
VersionedFile vfile = new VersionedFile(f.getName(), dep.file.pattern);
|
||||
if (!vfile.matches() || !vfile.name.equals(dep.file.name))
|
||||
continue;
|
||||
if (!vfile.matches() || !vfile.name.equals(dep.file.name)) continue;
|
||||
|
||||
int cmp = vfile.version.compareTo(dep.file.version);
|
||||
if (cmp < 0) {
|
||||
@@ -435,27 +427,25 @@ public class DepLoader implements IFMLLoadingPlugin, IFMLCallHook {
|
||||
return null;
|
||||
}
|
||||
if (cmp > 0) {
|
||||
CodeChickenCorePlugin.logger.warn("Warning: version of " + dep.file.name + ", " + vfile.version + " is newer than request " + dep.file.version);
|
||||
CodeChickenCorePlugin.logger.warn("Warning: version of " + dep.file.name + ", " + vfile.version
|
||||
+ " is newer than request " + dep.file.version);
|
||||
return f.getName();
|
||||
}
|
||||
return f.getName();//found dependency
|
||||
return f.getName(); // found dependency
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void load() {
|
||||
scanDepInfos();
|
||||
if (depMap.isEmpty())
|
||||
return;
|
||||
if (depMap.isEmpty()) return;
|
||||
|
||||
loadDeps();
|
||||
activateDeps();
|
||||
}
|
||||
|
||||
private void activateDeps() {
|
||||
for (Dependency dep : depMap.values())
|
||||
if (dep.coreLib)
|
||||
addClasspath(dep.existing);
|
||||
for (Dependency dep : depMap.values()) if (dep.coreLib) addClasspath(dep.existing);
|
||||
}
|
||||
|
||||
private void loadDeps() {
|
||||
@@ -477,7 +467,7 @@ public class DepLoader implements IFMLLoadingPlugin, IFMLCallHook {
|
||||
|
||||
private void load(Dependency dep) {
|
||||
dep.existing = checkExisting(dep);
|
||||
if (dep.existing == null)//download dep
|
||||
if (dep.existing == null) // download dep
|
||||
{
|
||||
download(dep);
|
||||
dep.existing = dep.file.filename;
|
||||
@@ -493,8 +483,7 @@ public class DepLoader implements IFMLLoadingPlugin, IFMLCallHook {
|
||||
|
||||
private void scanDepInfos() {
|
||||
for (File file : modFiles()) {
|
||||
if (!file.getName().endsWith(".jar") && !file.getName().endsWith(".zip"))
|
||||
continue;
|
||||
if (!file.getName().endsWith(".jar") && !file.getName().endsWith(".zip")) continue;
|
||||
|
||||
scanDepInfo(file);
|
||||
}
|
||||
@@ -505,11 +494,11 @@ public class DepLoader implements IFMLLoadingPlugin, IFMLCallHook {
|
||||
ZipFile zip = new ZipFile(file);
|
||||
ZipEntry e = zip.getEntry("dependancies.info");
|
||||
if (e == null) e = zip.getEntry("dependencies.info");
|
||||
if (e != null)
|
||||
loadJSon(zip.getInputStream(e));
|
||||
if (e != null) loadJSon(zip.getInputStream(e));
|
||||
zip.close();
|
||||
} catch (Exception e) {
|
||||
CodeChickenCorePlugin.logger.error("Failed to load dependencies.info from " + file.getName() + " as JSON");
|
||||
CodeChickenCorePlugin.logger.error(
|
||||
"Failed to load dependencies.info from " + file.getName() + " as JSON");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
@@ -517,47 +506,41 @@ public class DepLoader implements IFMLLoadingPlugin, IFMLCallHook {
|
||||
private void loadJSon(InputStream input) throws IOException {
|
||||
InputStreamReader reader = new InputStreamReader(input);
|
||||
JsonElement root = new JsonParser().parse(reader);
|
||||
if (root.isJsonArray())
|
||||
loadJSonArr(root);
|
||||
else
|
||||
loadJson(root.getAsJsonObject());
|
||||
if (root.isJsonArray()) loadJSonArr(root);
|
||||
else loadJson(root.getAsJsonObject());
|
||||
reader.close();
|
||||
}
|
||||
|
||||
private void loadJSonArr(JsonElement root) throws IOException {
|
||||
for (JsonElement node : root.getAsJsonArray())
|
||||
loadJson(node.getAsJsonObject());
|
||||
for (JsonElement node : root.getAsJsonArray()) loadJson(node.getAsJsonObject());
|
||||
}
|
||||
|
||||
private void loadJson(JsonObject node) throws IOException {
|
||||
boolean obfuscated = ((LaunchClassLoader) DepLoader.class.getClassLoader())
|
||||
.getClassBytes("net.minecraft.world.World") == null;
|
||||
boolean obfuscated =
|
||||
((LaunchClassLoader) DepLoader.class.getClassLoader()).getClassBytes("net.minecraft.world.World")
|
||||
== null;
|
||||
|
||||
String testClass = node.get("class").getAsString();
|
||||
if (DepLoader.class.getResource("/" + testClass.replace('.', '/') + ".class") != null)
|
||||
return;
|
||||
if (DepLoader.class.getResource("/" + testClass.replace('.', '/') + ".class") != null) return;
|
||||
|
||||
String repo = node.get("repo").getAsString();
|
||||
String filename = node.get("file").getAsString();
|
||||
if (!obfuscated && node.has("dev"))
|
||||
filename = node.get("dev").getAsString();
|
||||
if (!obfuscated && node.has("dev")) filename = node.get("dev").getAsString();
|
||||
|
||||
boolean coreLib = node.has("coreLib") && node.get("coreLib").getAsBoolean();
|
||||
|
||||
Pattern pattern = null;
|
||||
try {
|
||||
if(node.has("pattern"))
|
||||
if (node.has("pattern"))
|
||||
pattern = Pattern.compile(node.get("pattern").getAsString());
|
||||
} catch (PatternSyntaxException e) {
|
||||
CodeChickenCorePlugin.logger.error("Invalid filename pattern: " + node.get("pattern"));
|
||||
e.printStackTrace();
|
||||
}
|
||||
if(pattern == null)
|
||||
pattern = Pattern.compile("(\\w+).*?([\\d\\.]+)[-\\w]*\\.[^\\d]+");
|
||||
if (pattern == null) pattern = Pattern.compile("(\\w+).*?([\\d\\.]+)[-\\w]*\\.[^\\d]+");
|
||||
|
||||
VersionedFile file = new VersionedFile(filename, pattern);
|
||||
if (!file.matches())
|
||||
throw new RuntimeException("Invalid filename format for dependency: " + filename);
|
||||
if (!file.matches()) throw new RuntimeException("Invalid filename format for dependency: " + filename);
|
||||
|
||||
addDep(new Dependency(repo, file, coreLib));
|
||||
}
|
||||
@@ -570,8 +553,7 @@ public class DepLoader implements IFMLLoadingPlugin, IFMLCallHook {
|
||||
}
|
||||
|
||||
private boolean mergeNew(Dependency oldDep, Dependency newDep) {
|
||||
if (oldDep == null)
|
||||
return true;
|
||||
if (oldDep == null) return true;
|
||||
|
||||
Dependency newest = newDep.file.version.compareTo(oldDep.file.version) > 0 ? newDep : oldDep;
|
||||
newest.coreLib = newDep.coreLib || oldDep.coreLib;
|
||||
@@ -603,8 +585,7 @@ public class DepLoader implements IFMLLoadingPlugin, IFMLCallHook {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void injectData(Map<String, Object> data) {
|
||||
}
|
||||
public void injectData(Map<String, Object> data) {}
|
||||
|
||||
@Override
|
||||
public Void call() {
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
package codechicken.obfuscator;
|
||||
|
||||
import static org.objectweb.asm.tree.AbstractInsnNode.*;
|
||||
|
||||
import codechicken.lib.asm.ObfMapping;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import org.objectweb.asm.Opcodes;
|
||||
@@ -9,42 +12,30 @@ import org.objectweb.asm.tree.LdcInsnNode;
|
||||
import org.objectweb.asm.tree.MethodInsnNode;
|
||||
import org.objectweb.asm.tree.MethodNode;
|
||||
|
||||
import codechicken.lib.asm.ObfMapping;
|
||||
|
||||
import static org.objectweb.asm.tree.AbstractInsnNode.*;
|
||||
|
||||
public class ConstantObfuscator implements Opcodes
|
||||
{
|
||||
public class ConstantObfuscator implements Opcodes {
|
||||
public ObfRemapper obf;
|
||||
public List<ObfMapping> descCalls = new LinkedList<ObfMapping>();
|
||||
public List<ObfMapping> classCalls = new LinkedList<ObfMapping>();
|
||||
|
||||
public ConstantObfuscator(ObfRemapper obf, String[] a_classCalls, String[] a_descCalls)
|
||||
{
|
||||
|
||||
public ConstantObfuscator(ObfRemapper obf, String[] a_classCalls, String[] a_descCalls) {
|
||||
this.obf = obf;
|
||||
for(String callDesc : a_classCalls)
|
||||
classCalls.add(ObfMapping.fromDesc(callDesc));
|
||||
|
||||
for(String callDesc : a_descCalls)
|
||||
descCalls.add(ObfMapping.fromDesc(callDesc));
|
||||
for (String callDesc : a_classCalls) classCalls.add(ObfMapping.fromDesc(callDesc));
|
||||
|
||||
for (String callDesc : a_descCalls) descCalls.add(ObfMapping.fromDesc(callDesc));
|
||||
}
|
||||
|
||||
public void transform(ClassNode cnode)
|
||||
{
|
||||
for(MethodNode method : cnode.methods)
|
||||
for(AbstractInsnNode insn = method.instructions.getFirst(); insn != null; insn = insn.getNext())
|
||||
public void transform(ClassNode cnode) {
|
||||
for (MethodNode method : cnode.methods)
|
||||
for (AbstractInsnNode insn = method.instructions.getFirst(); insn != null; insn = insn.getNext())
|
||||
obfuscateInsnSeq(insn);
|
||||
}
|
||||
|
||||
private void obfuscateInsnSeq(AbstractInsnNode insn)
|
||||
{
|
||||
if(matchesClass(insn))
|
||||
{
|
||||
|
||||
private void obfuscateInsnSeq(AbstractInsnNode insn) {
|
||||
if (matchesClass(insn)) {
|
||||
LdcInsnNode node1 = (LdcInsnNode) insn;
|
||||
node1.cst = obf.map((String) node1.cst);
|
||||
}
|
||||
if(matchesDesc(insn))
|
||||
{
|
||||
if (matchesDesc(insn)) {
|
||||
LdcInsnNode node1 = (LdcInsnNode) insn;
|
||||
LdcInsnNode node2 = (LdcInsnNode) node1.getNext();
|
||||
LdcInsnNode node3 = (LdcInsnNode) node2.getNext();
|
||||
@@ -54,30 +45,24 @@ public class ConstantObfuscator implements Opcodes
|
||||
node3.cst = mapping.s_desc;
|
||||
}
|
||||
}
|
||||
|
||||
private boolean matchesClass(AbstractInsnNode insn)
|
||||
{
|
||||
if(insn.getType() != LDC_INSN) return false;
|
||||
|
||||
private boolean matchesClass(AbstractInsnNode insn) {
|
||||
if (insn.getType() != LDC_INSN) return false;
|
||||
insn = insn.getNext();
|
||||
if(insn == null || insn.getType() != METHOD_INSN) return false;
|
||||
for(ObfMapping m : classCalls)
|
||||
if(m.matches((MethodInsnNode) insn))
|
||||
return true;
|
||||
if (insn == null || insn.getType() != METHOD_INSN) return false;
|
||||
for (ObfMapping m : classCalls) if (m.matches((MethodInsnNode) insn)) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean matchesDesc(AbstractInsnNode insn)
|
||||
{
|
||||
if(insn.getType() != LDC_INSN) return false;
|
||||
|
||||
private boolean matchesDesc(AbstractInsnNode insn) {
|
||||
if (insn.getType() != LDC_INSN) return false;
|
||||
insn = insn.getNext();
|
||||
if(insn == null || insn.getType() != LDC_INSN) return false;
|
||||
if (insn == null || insn.getType() != LDC_INSN) return false;
|
||||
insn = insn.getNext();
|
||||
if(insn == null || insn.getType() != LDC_INSN) return false;
|
||||
if (insn == null || insn.getType() != LDC_INSN) return false;
|
||||
insn = insn.getNext();
|
||||
if(insn == null || insn.getType() != METHOD_INSN) return false;
|
||||
for(ObfMapping m : descCalls)
|
||||
if(m.matches((MethodInsnNode) insn))
|
||||
return true;
|
||||
if (insn == null || insn.getType() != METHOD_INSN) return false;
|
||||
for (ObfMapping m : descCalls) if (m.matches((MethodInsnNode) insn)) return true;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -2,12 +2,9 @@ package codechicken.obfuscator;
|
||||
|
||||
import java.io.OutputStream;
|
||||
|
||||
public class DummyOutputStream extends OutputStream
|
||||
{
|
||||
public class DummyOutputStream extends OutputStream {
|
||||
public static DummyOutputStream instance = new DummyOutputStream();
|
||||
|
||||
@Override
|
||||
public void write(int b)
|
||||
{
|
||||
}
|
||||
public void write(int b) {}
|
||||
}
|
||||
@@ -1,11 +1,9 @@
|
||||
package codechicken.obfuscator;
|
||||
|
||||
import codechicken.obfuscator.ObfuscationMap.ObfuscationEntry;
|
||||
import java.util.List;
|
||||
|
||||
import codechicken.obfuscator.ObfuscationMap.ObfuscationEntry;
|
||||
|
||||
public interface IHeirachyEvaluator
|
||||
{
|
||||
public interface IHeirachyEvaluator {
|
||||
/**
|
||||
* @param desc The mapping descriptor of the class to evaluate heirachy for
|
||||
* @return A list of parents (srg or obf names)
|
||||
|
||||
@@ -2,8 +2,8 @@ package codechicken.obfuscator;
|
||||
|
||||
import java.io.PrintStream;
|
||||
|
||||
public interface ILogStreams
|
||||
{
|
||||
public interface ILogStreams {
|
||||
public PrintStream err();
|
||||
|
||||
public PrintStream out();
|
||||
}
|
||||
@@ -3,32 +3,27 @@ package codechicken.obfuscator;
|
||||
import codechicken.lib.asm.ObfMapping;
|
||||
import codechicken.obfuscator.ObfuscationMap.ObfuscationEntry;
|
||||
|
||||
public class ObfDirection
|
||||
{
|
||||
public class ObfDirection {
|
||||
public boolean obfuscate;
|
||||
public boolean srg;
|
||||
public boolean srg_cst;
|
||||
|
||||
public ObfDirection setObfuscate(boolean obfuscate)
|
||||
{
|
||||
|
||||
public ObfDirection setObfuscate(boolean obfuscate) {
|
||||
this.obfuscate = obfuscate;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ObfDirection setSearge(boolean srg)
|
||||
{
|
||||
|
||||
public ObfDirection setSearge(boolean srg) {
|
||||
this.srg = srg;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ObfDirection setSeargeConstants(boolean srg_cst)
|
||||
{
|
||||
public ObfDirection setSeargeConstants(boolean srg_cst) {
|
||||
this.srg_cst = srg_cst;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ObfMapping obfuscate(ObfuscationEntry map)
|
||||
{
|
||||
public ObfMapping obfuscate(ObfuscationEntry map) {
|
||||
return srg ? map.srg : obfuscate ? map.obf : map.mcp;
|
||||
}
|
||||
}
|
||||
@@ -1,91 +1,69 @@
|
||||
package codechicken.obfuscator;
|
||||
|
||||
import codechicken.obfuscator.ObfuscationMap.ObfuscationEntry;
|
||||
import org.objectweb.asm.commons.Remapper;
|
||||
|
||||
import codechicken.obfuscator.ObfuscationMap.ObfuscationEntry;
|
||||
|
||||
public class ObfRemapper extends Remapper
|
||||
{
|
||||
public class ObfRemapper extends Remapper {
|
||||
public final ObfuscationMap obf;
|
||||
public ObfDirection dir;
|
||||
|
||||
public ObfRemapper(ObfuscationMap obf, ObfDirection dir)
|
||||
{
|
||||
|
||||
public ObfRemapper(ObfuscationMap obf, ObfDirection dir) {
|
||||
this.obf = obf;
|
||||
this.dir = dir;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String map(String name)
|
||||
{
|
||||
if(name.indexOf('$') >= 0)
|
||||
return map(name.substring(0, name.indexOf('$')))+name.substring(name.indexOf('$'));
|
||||
|
||||
ObfuscationEntry map;
|
||||
if(dir.obfuscate)
|
||||
map = obf.lookupMcpClass(name);
|
||||
else
|
||||
map = obf.lookupObfClass(name);
|
||||
|
||||
if(map != null)
|
||||
return dir.obfuscate(map).s_owner;
|
||||
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String mapFieldName(String owner, String name, String desc)
|
||||
{
|
||||
public String map(String name) {
|
||||
if (name.indexOf('$') >= 0)
|
||||
return map(name.substring(0, name.indexOf('$'))) + name.substring(name.indexOf('$'));
|
||||
|
||||
ObfuscationEntry map;
|
||||
if(dir.obfuscate)
|
||||
map = obf.lookupMcpField(owner, name);
|
||||
else
|
||||
map = obf.lookupObfField(owner, name);
|
||||
|
||||
if(map == null)
|
||||
map = obf.lookupSrgField(owner, name);
|
||||
|
||||
if(map != null)
|
||||
return dir.obfuscate(map).s_name;
|
||||
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String mapMethodName(String owner, String name, String desc)
|
||||
{
|
||||
if(owner.length() == 0 || owner.charAt(0) == '[')
|
||||
return name;
|
||||
|
||||
ObfuscationEntry map;
|
||||
if(dir.obfuscate)
|
||||
map = obf.lookupMcpMethod(owner, name, desc);
|
||||
else
|
||||
map = obf.lookupObfMethod(owner, name, desc);
|
||||
|
||||
if(map == null)
|
||||
map = obf.lookupSrg(name);
|
||||
|
||||
if(map != null)
|
||||
return dir.obfuscate(map).s_name;
|
||||
|
||||
if (dir.obfuscate) map = obf.lookupMcpClass(name);
|
||||
else map = obf.lookupObfClass(name);
|
||||
|
||||
if (map != null) return dir.obfuscate(map).s_owner;
|
||||
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object mapValue(Object cst)
|
||||
{
|
||||
if(cst instanceof String)
|
||||
{
|
||||
if(dir.srg_cst)
|
||||
{
|
||||
public String mapFieldName(String owner, String name, String desc) {
|
||||
ObfuscationEntry map;
|
||||
if (dir.obfuscate) map = obf.lookupMcpField(owner, name);
|
||||
else map = obf.lookupObfField(owner, name);
|
||||
|
||||
if (map == null) map = obf.lookupSrgField(owner, name);
|
||||
|
||||
if (map != null) return dir.obfuscate(map).s_name;
|
||||
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String mapMethodName(String owner, String name, String desc) {
|
||||
if (owner.length() == 0 || owner.charAt(0) == '[') return name;
|
||||
|
||||
ObfuscationEntry map;
|
||||
if (dir.obfuscate) map = obf.lookupMcpMethod(owner, name, desc);
|
||||
else map = obf.lookupObfMethod(owner, name, desc);
|
||||
|
||||
if (map == null) map = obf.lookupSrg(name);
|
||||
|
||||
if (map != null) return dir.obfuscate(map).s_name;
|
||||
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object mapValue(Object cst) {
|
||||
if (cst instanceof String) {
|
||||
if (dir.srg_cst) {
|
||||
ObfuscationEntry map = obf.lookupSrg((String) cst);
|
||||
if(map != null)
|
||||
return dir.obfuscate(map).s_name;
|
||||
if (map != null) return dir.obfuscate(map).s_name;
|
||||
}
|
||||
return cst;
|
||||
}
|
||||
|
||||
|
||||
return super.mapValue(cst);
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,8 @@
|
||||
package codechicken.obfuscator;
|
||||
|
||||
import codechicken.lib.asm.ObfMapping;
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.collect.ArrayListMultimap;
|
||||
import java.io.File;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
@@ -7,162 +10,127 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.collect.ArrayListMultimap;
|
||||
|
||||
import codechicken.lib.asm.ObfMapping;
|
||||
|
||||
public class ObfuscationMap
|
||||
{
|
||||
public class ObfuscationEntry
|
||||
{
|
||||
public class ObfuscationMap {
|
||||
public class ObfuscationEntry {
|
||||
public final ObfMapping obf;
|
||||
public final ObfMapping srg;
|
||||
public final ObfMapping mcp;
|
||||
|
||||
public ObfuscationEntry(ObfMapping obf, ObfMapping srg, ObfMapping mcp)
|
||||
{
|
||||
|
||||
public ObfuscationEntry(ObfMapping obf, ObfMapping srg, ObfMapping mcp) {
|
||||
this.obf = obf;
|
||||
this.srg = srg;
|
||||
this.mcp = mcp;
|
||||
}
|
||||
}
|
||||
|
||||
private class ClassEntry extends ObfuscationEntry
|
||||
{
|
||||
|
||||
private class ClassEntry extends ObfuscationEntry {
|
||||
public Map<String, ObfuscationEntry> mcpMap = new HashMap<String, ObfuscationEntry>();
|
||||
public Map<String, ObfuscationEntry> srgMap = new HashMap<String, ObfuscationEntry>();
|
||||
public Map<String, ObfuscationEntry> obfMap = new HashMap<String, ObfuscationEntry>();
|
||||
|
||||
public ClassEntry(String obf, String srg)
|
||||
{
|
||||
super(new ObfMapping(obf, "", ""),
|
||||
new ObfMapping(srg, "", ""),
|
||||
new ObfMapping(srg, "", ""));
|
||||
|
||||
public ClassEntry(String obf, String srg) {
|
||||
super(new ObfMapping(obf, "", ""), new ObfMapping(srg, "", ""), new ObfMapping(srg, "", ""));
|
||||
}
|
||||
|
||||
public ObfuscationEntry addEntry(ObfMapping obf_desc, ObfMapping srg_desc)
|
||||
{
|
||||
|
||||
public ObfuscationEntry addEntry(ObfMapping obf_desc, ObfMapping srg_desc) {
|
||||
ObfuscationEntry entry = new ObfuscationEntry(obf_desc, srg_desc, srg_desc.copy());
|
||||
obfMap.put(obf_desc.s_name.concat(obf_desc.s_desc), entry);
|
||||
srgMap.put(srg_desc.s_name, entry);
|
||||
|
||||
if(srg_desc.s_name.startsWith("field_") || srg_desc.s_name.startsWith("func_"))
|
||||
|
||||
if (srg_desc.s_name.startsWith("field_") || srg_desc.s_name.startsWith("func_"))
|
||||
srgMemberMap.put(srg_desc.s_name, entry);
|
||||
|
||||
|
||||
return entry;
|
||||
}
|
||||
|
||||
public void inheritFrom(ClassEntry p)
|
||||
{
|
||||
public void inheritFrom(ClassEntry p) {
|
||||
inherit(obfMap, p.obfMap);
|
||||
inherit(srgMap, p.srgMap);
|
||||
inherit(mcpMap, p.mcpMap);
|
||||
}
|
||||
|
||||
private void inherit(Map<String, ObfuscationEntry> child, Map<String, ObfuscationEntry> parent)
|
||||
{
|
||||
for(Entry<String, ObfuscationEntry> e : parent.entrySet())
|
||||
if(!child.containsKey(e.getKey()))
|
||||
child.put(e.getKey(), e.getValue());
|
||||
|
||||
private void inherit(Map<String, ObfuscationEntry> child, Map<String, ObfuscationEntry> parent) {
|
||||
for (Entry<String, ObfuscationEntry> e : parent.entrySet())
|
||||
if (!child.containsKey(e.getKey())) child.put(e.getKey(), e.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private Map<String, ClassEntry> srgMap = new HashMap<String, ClassEntry>();
|
||||
private Map<String, ClassEntry> obfMap = new HashMap<String, ClassEntry>();
|
||||
private ArrayListMultimap<String, ObfuscationEntry> srgMemberMap = ArrayListMultimap.create();
|
||||
|
||||
|
||||
private IHeirachyEvaluator heirachyEvaluator;
|
||||
private HashSet<String> mappedClasses = new HashSet<String>();
|
||||
public ILogStreams log = SystemLogStreams.inst;
|
||||
|
||||
public ObfuscationMap setHeirachyEvaluator(IHeirachyEvaluator eval)
|
||||
{
|
||||
|
||||
public ObfuscationMap setHeirachyEvaluator(IHeirachyEvaluator eval) {
|
||||
heirachyEvaluator = eval;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ObfuscationMap setLog(ILogStreams log)
|
||||
{
|
||||
|
||||
public ObfuscationMap setLog(ILogStreams log) {
|
||||
this.log = log;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ObfuscationEntry addClass(String obf, String srg)
|
||||
{
|
||||
|
||||
public ObfuscationEntry addClass(String obf, String srg) {
|
||||
return addEntry(new ObfMapping(obf, "", ""), new ObfMapping(srg, "", ""));
|
||||
}
|
||||
|
||||
public ObfuscationEntry addField(String obf_owner, String obf_name, String srg_owner, String srg_name)
|
||||
{
|
||||
return addEntry(new ObfMapping(obf_owner, obf_name, ""),
|
||||
new ObfMapping(srg_owner, srg_name, ""));
|
||||
|
||||
public ObfuscationEntry addField(String obf_owner, String obf_name, String srg_owner, String srg_name) {
|
||||
return addEntry(new ObfMapping(obf_owner, obf_name, ""), new ObfMapping(srg_owner, srg_name, ""));
|
||||
}
|
||||
|
||||
public ObfuscationEntry addMethod(String obf_owner, String obf_name, String obf_desc, String srg_owner, String srg_name, String srg_desc)
|
||||
{
|
||||
return addEntry(new ObfMapping(obf_owner, obf_name, obf_desc),
|
||||
new ObfMapping(srg_owner, srg_name, srg_desc));
|
||||
|
||||
public ObfuscationEntry addMethod(
|
||||
String obf_owner, String obf_name, String obf_desc, String srg_owner, String srg_name, String srg_desc) {
|
||||
return addEntry(new ObfMapping(obf_owner, obf_name, obf_desc), new ObfMapping(srg_owner, srg_name, srg_desc));
|
||||
}
|
||||
|
||||
public ObfuscationEntry addEntry(ObfMapping obf_desc, ObfMapping srg_desc)
|
||||
{
|
||||
|
||||
public ObfuscationEntry addEntry(ObfMapping obf_desc, ObfMapping srg_desc) {
|
||||
ClassEntry e = srgMap.get(srg_desc.s_owner);
|
||||
if(e == null)
|
||||
{
|
||||
if (e == null) {
|
||||
e = new ClassEntry(obf_desc.s_owner, srg_desc.s_owner);
|
||||
obfMap.put(obf_desc.s_owner, e);
|
||||
srgMap.put(srg_desc.s_owner, e);
|
||||
}
|
||||
if(obf_desc.s_name.length() > 0)
|
||||
return e.addEntry(obf_desc, srg_desc);
|
||||
|
||||
if (obf_desc.s_name.length() > 0) return e.addEntry(obf_desc, srg_desc);
|
||||
|
||||
return e;
|
||||
}
|
||||
|
||||
public void addMcpName(String srg_name, String mcp_name)
|
||||
{
|
||||
|
||||
public void addMcpName(String srg_name, String mcp_name) {
|
||||
List<ObfuscationEntry> entries = srgMemberMap.get(srg_name);
|
||||
if(entries.isEmpty())
|
||||
{
|
||||
log.err().println("Tried to add mcp name ("+mcp_name+") for unknown srg key ("+srg_name+")");
|
||||
if (entries.isEmpty()) {
|
||||
log.err().println("Tried to add mcp name (" + mcp_name + ") for unknown srg key (" + srg_name + ")");
|
||||
return;
|
||||
}
|
||||
for(ObfuscationEntry entry : entries)
|
||||
{
|
||||
for (ObfuscationEntry entry : entries) {
|
||||
entry.mcp.s_name = mcp_name;
|
||||
srgMap.get(entry.srg.s_owner).mcpMap.put(entry.mcp.s_name.concat(entry.mcp.s_desc), entry);
|
||||
}
|
||||
}
|
||||
|
||||
public ObfuscationEntry lookupSrg(String srg_key)
|
||||
{
|
||||
|
||||
public ObfuscationEntry lookupSrg(String srg_key) {
|
||||
List<ObfuscationEntry> list = srgMemberMap.get(srg_key);
|
||||
return list.isEmpty() ? null : list.get(0);
|
||||
}
|
||||
|
||||
public ObfuscationEntry lookupMcpClass(String name)
|
||||
{
|
||||
|
||||
public ObfuscationEntry lookupMcpClass(String name) {
|
||||
return srgMap.get(name);
|
||||
}
|
||||
|
||||
public ObfuscationEntry lookupObfClass(String name)
|
||||
{
|
||||
public ObfuscationEntry lookupObfClass(String name) {
|
||||
return obfMap.get(name);
|
||||
}
|
||||
|
||||
public ObfuscationEntry lookupMcpField(String owner, String name)
|
||||
{
|
||||
public ObfuscationEntry lookupMcpField(String owner, String name) {
|
||||
return lookupMcpMethod(owner, name, "");
|
||||
}
|
||||
|
||||
public ObfuscationEntry lookupSrgField(String owner, String name)
|
||||
{
|
||||
if(name.startsWith("field_"))
|
||||
{
|
||||
public ObfuscationEntry lookupSrgField(String owner, String name) {
|
||||
if (name.startsWith("field_")) {
|
||||
ObfuscationEntry e = lookupSrg(name);
|
||||
if(e != null)
|
||||
return e;
|
||||
if (e != null) return e;
|
||||
}
|
||||
|
||||
evaluateHeirachy(owner);
|
||||
@@ -170,174 +138,144 @@ public class ObfuscationMap
|
||||
return e == null ? null : e.srgMap.get(name);
|
||||
}
|
||||
|
||||
public ObfuscationEntry lookupObfField(String owner, String name)
|
||||
{
|
||||
public ObfuscationEntry lookupObfField(String owner, String name) {
|
||||
return lookupObfMethod(owner, name, "");
|
||||
}
|
||||
|
||||
public ObfuscationEntry lookupMcpMethod(String owner, String name, String desc)
|
||||
{
|
||||
public ObfuscationEntry lookupMcpMethod(String owner, String name, String desc) {
|
||||
evaluateHeirachy(owner);
|
||||
ClassEntry e = srgMap.get(owner);
|
||||
return e == null ? null : e.mcpMap.get(name.concat(desc));
|
||||
}
|
||||
|
||||
public ObfuscationEntry lookupObfMethod(String owner, String name, String desc)
|
||||
{
|
||||
public ObfuscationEntry lookupObfMethod(String owner, String name, String desc) {
|
||||
evaluateHeirachy(owner);
|
||||
ClassEntry e = obfMap.get(owner);
|
||||
return e == null ? null : e.obfMap.get(name.concat(desc));
|
||||
}
|
||||
|
||||
private boolean isMapped(ObfuscationEntry desc)
|
||||
{
|
||||
|
||||
private boolean isMapped(ObfuscationEntry desc) {
|
||||
return mappedClasses.contains(desc.srg.s_owner);
|
||||
}
|
||||
|
||||
private ObfuscationEntry getOrCreateClassEntry(String name)
|
||||
{
|
||||
|
||||
private ObfuscationEntry getOrCreateClassEntry(String name) {
|
||||
ObfuscationEntry e = lookupObfClass(name);
|
||||
if(e == null)
|
||||
e = lookupMcpClass(name);
|
||||
if(e == null)
|
||||
e = addClass(name, name);//if the class isn't in obf or srg maps, it must be a custom mod class with no name change.
|
||||
if (e == null) e = lookupMcpClass(name);
|
||||
if (e == null)
|
||||
e = addClass(
|
||||
name,
|
||||
name); // if the class isn't in obf or srg maps, it must be a custom mod class with no name change.
|
||||
return e;
|
||||
}
|
||||
|
||||
public ObfuscationEntry evaluateHeirachy(String name)
|
||||
{
|
||||
public ObfuscationEntry evaluateHeirachy(String name) {
|
||||
ObfuscationEntry desc = getOrCreateClassEntry(name);
|
||||
if(isMapped(desc))
|
||||
return desc;
|
||||
if (isMapped(desc)) return desc;
|
||||
|
||||
mappedClasses.add(desc.srg.s_owner);
|
||||
if(heirachyEvaluator == null)
|
||||
if (heirachyEvaluator == null)
|
||||
throw new IllegalArgumentException("Cannot call method/field mappings if a heirachy evaluator is not set.");
|
||||
|
||||
if(!heirachyEvaluator.isLibClass(desc))
|
||||
{
|
||||
|
||||
if (!heirachyEvaluator.isLibClass(desc)) {
|
||||
List<String> parents = heirachyEvaluator.getParents(desc);
|
||||
if(parents == null)
|
||||
log.err().println("Could not find class: "+desc.srg.s_owner);
|
||||
else
|
||||
for(String parent : parents)
|
||||
inherit(desc, evaluateHeirachy(parent));
|
||||
if (parents == null) log.err().println("Could not find class: " + desc.srg.s_owner);
|
||||
else for (String parent : parents) inherit(desc, evaluateHeirachy(parent));
|
||||
}
|
||||
|
||||
|
||||
return desc;
|
||||
}
|
||||
|
||||
public void inherit(ObfuscationEntry desc, ObfuscationEntry p_desc)
|
||||
{
|
||||
public void inherit(ObfuscationEntry desc, ObfuscationEntry p_desc) {
|
||||
inherit(desc.srg.s_owner, p_desc.srg.s_owner);
|
||||
}
|
||||
|
||||
public void inherit(String name, String parent)
|
||||
{
|
||||
public void inherit(String name, String parent) {
|
||||
ClassEntry e = srgMap.get(name);
|
||||
if(e == null)
|
||||
throw new IllegalStateException("Tried to inerit to an undefined class: "+name+" extends "+parent);
|
||||
if (e == null)
|
||||
throw new IllegalStateException("Tried to inerit to an undefined class: " + name + " extends " + parent);
|
||||
ClassEntry p = srgMap.get(parent);
|
||||
if(p == null)
|
||||
throw new IllegalStateException("Tried to inerit from undefired parent: "+name+" extends "+parent);
|
||||
if (p == null)
|
||||
throw new IllegalStateException("Tried to inerit from undefired parent: " + name + " extends " + parent);
|
||||
e.inheritFrom(p);
|
||||
}
|
||||
|
||||
public void parseMappings(File[] mappings)
|
||||
{
|
||||
|
||||
public void parseMappings(File[] mappings) {
|
||||
parseSRGS(mappings[0]);
|
||||
parseCSV(mappings[1]);
|
||||
parseCSV(mappings[2]);
|
||||
}
|
||||
|
||||
public static String[] splitLast(String s, char c)
|
||||
{
|
||||
|
||||
public static String[] splitLast(String s, char c) {
|
||||
int i = s.lastIndexOf(c);
|
||||
return new String[]{s.substring(0, i), s.substring(i+1)};
|
||||
return new String[] {s.substring(0, i), s.substring(i + 1)};
|
||||
}
|
||||
|
||||
public static String[] split4(String s, char c)
|
||||
{
|
||||
|
||||
public static String[] split4(String s, char c) {
|
||||
String[] split = new String[4];
|
||||
int i2 = s.indexOf(c);
|
||||
split[0] = s.substring(0, i2);
|
||||
int i = i2+1;
|
||||
int i = i2 + 1;
|
||||
i2 = s.indexOf(c, i);
|
||||
split[1] = s.substring(i, i2);
|
||||
i = i2+1;
|
||||
i = i2 + 1;
|
||||
i2 = s.indexOf(c, i);
|
||||
split[2] = s.substring(i, i2);
|
||||
i = i2+1;
|
||||
i = i2 + 1;
|
||||
i2 = s.indexOf(c, i);
|
||||
split[3] = s.substring(i);
|
||||
return split;
|
||||
}
|
||||
|
||||
private void parseSRGS(File srgs)
|
||||
{
|
||||
log.out().println("Parsing "+srgs.getName());
|
||||
|
||||
Function<String, Void> function = new Function<String, Void>()
|
||||
{
|
||||
private void parseSRGS(File srgs) {
|
||||
log.out().println("Parsing " + srgs.getName());
|
||||
|
||||
Function<String, Void> function = new Function<String, Void>() {
|
||||
@Override
|
||||
public Void apply(String line)
|
||||
{
|
||||
public Void apply(String line) {
|
||||
int hpos = line.indexOf('#');
|
||||
if(hpos > 0)
|
||||
line = line.substring(0, hpos).trim();
|
||||
if(line.startsWith("CL: "))
|
||||
{
|
||||
if (hpos > 0) line = line.substring(0, hpos).trim();
|
||||
if (line.startsWith("CL: ")) {
|
||||
String[] params = splitLast(line.substring(4), ' ');
|
||||
addClass(params[0], params[1]);
|
||||
}
|
||||
else if(line.startsWith("FD: "))
|
||||
{
|
||||
} else if (line.startsWith("FD: ")) {
|
||||
String[] params = splitLast(line.substring(4), ' ');
|
||||
String[] p1 = splitLast(params[0], '/');
|
||||
String[] p2 = splitLast(params[1], '/');
|
||||
addField(p1[0], p1[1],
|
||||
p2[0], p2[1]);
|
||||
addField(p1[0], p1[1], p2[0], p2[1]);
|
||||
return null;
|
||||
}
|
||||
else if(line.startsWith("MD: "))
|
||||
{
|
||||
} else if (line.startsWith("MD: ")) {
|
||||
String[] params = split4(line.substring(4), ' ');
|
||||
String[] p1 = splitLast(params[0], '/');
|
||||
String[] p2 = splitLast(params[2], '/');
|
||||
addMethod(p1[0], p1[1], params[1],
|
||||
p2[0], p2[1], params[3]);
|
||||
addMethod(p1[0], p1[1], params[1], p2[0], p2[1], params[3]);
|
||||
return null;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
ObfuscationRun.processLines(srgs, function);
|
||||
}
|
||||
|
||||
private void parseCSV(File csv)
|
||||
{
|
||||
log.out().println("Parsing "+csv.getName());
|
||||
|
||||
Function<String, Void> function = new Function<String, Void>()
|
||||
{
|
||||
private void parseCSV(File csv) {
|
||||
log.out().println("Parsing " + csv.getName());
|
||||
|
||||
Function<String, Void> function = new Function<String, Void>() {
|
||||
@Override
|
||||
public Void apply(String line)
|
||||
{
|
||||
if(line.startsWith("func_") || line.startsWith("field_"))
|
||||
{
|
||||
public Void apply(String line) {
|
||||
if (line.startsWith("func_") || line.startsWith("field_")) {
|
||||
int i = line.indexOf(',');
|
||||
String srg = line.substring(0, i);
|
||||
int i2 = i+1;
|
||||
int i2 = i + 1;
|
||||
i = line.indexOf(',', i2);
|
||||
String mcp = line.substring(i2, i);
|
||||
|
||||
|
||||
addMcpName(srg, mcp);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
ObfuscationRun.processLines(csv, function);
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
package codechicken.obfuscator;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
@@ -12,242 +13,199 @@ import org.objectweb.asm.ClassVisitor;
|
||||
import org.objectweb.asm.commons.RemappingClassAdapter;
|
||||
import org.objectweb.asm.tree.ClassNode;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
|
||||
public class ObfuscationRun implements ILogStreams
|
||||
{
|
||||
public class ObfuscationRun implements ILogStreams {
|
||||
public final ObfDirection obfDir;
|
||||
public final ObfuscationMap obf;
|
||||
public final ObfRemapper obfMapper;
|
||||
public final ConstantObfuscator cstMappper;
|
||||
|
||||
|
||||
public File[] mappings;
|
||||
public Map<String, String> config;
|
||||
|
||||
|
||||
private PrintStream out = System.out;
|
||||
private PrintStream err = System.err;
|
||||
private PrintStream quietStream = new PrintStream(DummyOutputStream.instance);
|
||||
|
||||
|
||||
private boolean verbose;
|
||||
private boolean quiet;
|
||||
|
||||
public boolean clean;
|
||||
private long startTime;
|
||||
private boolean finished;
|
||||
|
||||
public ObfuscationRun(boolean obfuscate, File[] mappings, Map<String, String> config)
|
||||
{
|
||||
|
||||
public ObfuscationRun(boolean obfuscate, File[] mappings, Map<String, String> config) {
|
||||
obfDir = new ObfDirection().setObfuscate(obfuscate);
|
||||
this.mappings = mappings;
|
||||
this.config = config;
|
||||
|
||||
|
||||
obf = new ObfuscationMap().setLog(this);
|
||||
obfMapper = new ObfRemapper(obf, obfDir);
|
||||
cstMappper = new ConstantObfuscator(obfMapper,
|
||||
config.get("classConstantCalls").split(","),
|
||||
cstMappper = new ConstantObfuscator(
|
||||
obfMapper,
|
||||
config.get("classConstantCalls").split(","),
|
||||
config.get("descConstantCalls").split(","));
|
||||
}
|
||||
|
||||
public ObfuscationRun setClean()
|
||||
{
|
||||
|
||||
public ObfuscationRun setClean() {
|
||||
clean = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ObfuscationRun setVerbose()
|
||||
{
|
||||
|
||||
public ObfuscationRun setVerbose() {
|
||||
verbose = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ObfuscationRun setQuiet()
|
||||
{
|
||||
|
||||
public ObfuscationRun setQuiet() {
|
||||
quiet = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ObfuscationRun setOut(PrintStream p)
|
||||
{
|
||||
|
||||
public ObfuscationRun setOut(PrintStream p) {
|
||||
out = p;
|
||||
return this;
|
||||
}
|
||||
|
||||
public PrintStream out()
|
||||
{
|
||||
|
||||
public PrintStream out() {
|
||||
return quiet ? quietStream : out;
|
||||
}
|
||||
|
||||
public PrintStream fine()
|
||||
{
|
||||
|
||||
public PrintStream fine() {
|
||||
return verbose ? out : quietStream;
|
||||
}
|
||||
|
||||
public ObfuscationRun setErr(PrintStream p)
|
||||
{
|
||||
|
||||
public ObfuscationRun setErr(PrintStream p) {
|
||||
err = p;
|
||||
return this;
|
||||
}
|
||||
|
||||
public PrintStream err()
|
||||
{
|
||||
|
||||
public PrintStream err() {
|
||||
return quiet ? quietStream : err;
|
||||
}
|
||||
|
||||
public ObfuscationRun setSearge()
|
||||
{
|
||||
public ObfuscationRun setSearge() {
|
||||
obfDir.setSearge(true);
|
||||
return this;
|
||||
}
|
||||
|
||||
public ObfuscationRun setSeargeConstants()
|
||||
{
|
||||
public ObfuscationRun setSeargeConstants() {
|
||||
obfDir.setSeargeConstants(true);
|
||||
return this;
|
||||
}
|
||||
|
||||
public void start()
|
||||
{
|
||||
|
||||
public void start() {
|
||||
startTime = System.currentTimeMillis();
|
||||
}
|
||||
|
||||
public static Map<String, String> fillDefaults(Map<String, String> config)
|
||||
{
|
||||
if(!config.containsKey("excludedPackages"))
|
||||
config.put("excludedPackages", "java/;sun/;javax/;scala/;" +
|
||||
"argo/;org/lwjgl/;org/objectweb/;org/bouncycastle/;com/google/");
|
||||
if(!config.containsKey("ignore"))
|
||||
config.put("ignore", ".");
|
||||
if(!config.containsKey("classConstantCalls"))
|
||||
config.put("classConstantCalls",
|
||||
"codechicken/lib/asm/ObfMapping.<init>(Ljava/lang/String;)V," +
|
||||
"codechicken/lib/asm/ObfMapping.subclass(Ljava/lang/String;)Lcodechicken/lib/asm/ObfMapping;," +
|
||||
"codechicken/lib/asm/ObfMapping.<init>(Lcodechicken/lib/asm/ObfMapping;Ljava/lang/String;)V");
|
||||
if(!config.containsKey("descConstantCalls"))
|
||||
config.put("descConstantCalls",
|
||||
"codechicken/lib/asm/ObfMapping.<init>(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V," +
|
||||
"org/objectweb/asm/MethodVisitor.visitFieldInsn(ILjava/lang/String;Ljava/lang/String;Ljava/lang/String;)V," +
|
||||
"org/objectweb/asm/tree/MethodNode.visitFieldInsn(ILjava/lang/String;Ljava/lang/String;Ljava/lang/String;)V," +
|
||||
"org/objectweb/asm/MethodVisitor.visitMethodInsn(ILjava/lang/String;Ljava/lang/String;Ljava/lang/String;)V," +
|
||||
"org/objectweb/asm/tree/MethodNode.visitMethodInsn(ILjava/lang/String;Ljava/lang/String;Ljava/lang/String;)V," +
|
||||
"org/objectweb/asm/tree/MethodInsnNode.<init>(ILjava/lang/String;Ljava/lang/String;Ljava/lang/String;)V," +
|
||||
"org/objectweb/asm/tree/FieldInsnNode.<init>(ILjava/lang/String;Ljava/lang/String;Ljava/lang/String;)V");
|
||||
|
||||
|
||||
public static Map<String, String> fillDefaults(Map<String, String> config) {
|
||||
if (!config.containsKey("excludedPackages"))
|
||||
config.put(
|
||||
"excludedPackages",
|
||||
"java/;sun/;javax/;scala/;" + "argo/;org/lwjgl/;org/objectweb/;org/bouncycastle/;com/google/");
|
||||
if (!config.containsKey("ignore")) config.put("ignore", ".");
|
||||
if (!config.containsKey("classConstantCalls"))
|
||||
config.put(
|
||||
"classConstantCalls",
|
||||
"codechicken/lib/asm/ObfMapping.<init>(Ljava/lang/String;)V,"
|
||||
+ "codechicken/lib/asm/ObfMapping.subclass(Ljava/lang/String;)Lcodechicken/lib/asm/ObfMapping;,"
|
||||
+ "codechicken/lib/asm/ObfMapping.<init>(Lcodechicken/lib/asm/ObfMapping;Ljava/lang/String;)V");
|
||||
if (!config.containsKey("descConstantCalls"))
|
||||
config.put(
|
||||
"descConstantCalls",
|
||||
"codechicken/lib/asm/ObfMapping.<init>(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V,"
|
||||
+ "org/objectweb/asm/MethodVisitor.visitFieldInsn(ILjava/lang/String;Ljava/lang/String;Ljava/lang/String;)V,"
|
||||
+ "org/objectweb/asm/tree/MethodNode.visitFieldInsn(ILjava/lang/String;Ljava/lang/String;Ljava/lang/String;)V,"
|
||||
+ "org/objectweb/asm/MethodVisitor.visitMethodInsn(ILjava/lang/String;Ljava/lang/String;Ljava/lang/String;)V,"
|
||||
+ "org/objectweb/asm/tree/MethodNode.visitMethodInsn(ILjava/lang/String;Ljava/lang/String;Ljava/lang/String;)V,"
|
||||
+ "org/objectweb/asm/tree/MethodInsnNode.<init>(ILjava/lang/String;Ljava/lang/String;Ljava/lang/String;)V,"
|
||||
+ "org/objectweb/asm/tree/FieldInsnNode.<init>(ILjava/lang/String;Ljava/lang/String;Ljava/lang/String;)V");
|
||||
|
||||
return config;
|
||||
}
|
||||
|
||||
public static void processLines(File file, Function<String, Void> function)
|
||||
{
|
||||
try
|
||||
{
|
||||
public static void processLines(File file, Function<String, Void> function) {
|
||||
try {
|
||||
BufferedReader reader = new BufferedReader(new FileReader(file));
|
||||
String line;
|
||||
while((line = reader.readLine()) != null)
|
||||
function.apply(line);
|
||||
while ((line = reader.readLine()) != null) function.apply(line);
|
||||
reader.close();
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public static void processFiles(File dir, Function<File, Void> function, boolean recursive)
|
||||
{
|
||||
for(File file : dir.listFiles())
|
||||
if(file.isDirectory() && recursive)
|
||||
processFiles(file, function, recursive);
|
||||
else
|
||||
function.apply(file);
|
||||
|
||||
public static void processFiles(File dir, Function<File, Void> function, boolean recursive) {
|
||||
for (File file : dir.listFiles())
|
||||
if (file.isDirectory() && recursive) processFiles(file, function, recursive);
|
||||
else function.apply(file);
|
||||
}
|
||||
|
||||
public static void deleteDir(File directory, boolean remove)
|
||||
{
|
||||
if(!directory.exists())
|
||||
{
|
||||
if(!remove)directory.mkdirs();
|
||||
|
||||
public static void deleteDir(File directory, boolean remove) {
|
||||
if (!directory.exists()) {
|
||||
if (!remove) directory.mkdirs();
|
||||
return;
|
||||
}
|
||||
for(File file : directory.listFiles())
|
||||
{
|
||||
if(file.isDirectory())
|
||||
{
|
||||
for (File file : directory.listFiles()) {
|
||||
if (file.isDirectory()) {
|
||||
deleteDir(file, true);
|
||||
}
|
||||
else
|
||||
{
|
||||
if(!file.delete())
|
||||
throw new RuntimeException("Delete Failed: "+file);
|
||||
} else {
|
||||
if (!file.delete()) throw new RuntimeException("Delete Failed: " + file);
|
||||
}
|
||||
}
|
||||
if(remove)
|
||||
{
|
||||
if(!directory.delete())
|
||||
throw new RuntimeException("Delete Failed: "+directory);
|
||||
if (remove) {
|
||||
if (!directory.delete()) throw new RuntimeException("Delete Failed: " + directory);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static File[] parseConfDir(File confDir) {
|
||||
File srgDir = new File(confDir, "conf");
|
||||
if(!srgDir.exists())
|
||||
srgDir = confDir;
|
||||
|
||||
if (!srgDir.exists()) srgDir = confDir;
|
||||
|
||||
File srgs = new File(srgDir, "packaged.srg");
|
||||
if(!srgs.exists())
|
||||
srgs = new File(srgDir, "joined.srg");
|
||||
if(!srgs.exists())
|
||||
throw new RuntimeException("Could not find packaged.srg or joined.srg");
|
||||
|
||||
if (!srgs.exists()) srgs = new File(srgDir, "joined.srg");
|
||||
if (!srgs.exists()) throw new RuntimeException("Could not find packaged.srg or joined.srg");
|
||||
|
||||
File mapDir = new File(confDir, "mappings");
|
||||
if(!mapDir.exists())
|
||||
mapDir = confDir;
|
||||
|
||||
if (!mapDir.exists()) mapDir = confDir;
|
||||
|
||||
File methods = new File(mapDir, "methods.csv");
|
||||
if(!methods.exists())
|
||||
throw new RuntimeException("Could not find methods.csv");
|
||||
if (!methods.exists()) throw new RuntimeException("Could not find methods.csv");
|
||||
File fields = new File(mapDir, "fields.csv");
|
||||
if(!fields.exists())
|
||||
throw new RuntimeException("Could not find fields.csv");
|
||||
|
||||
return new File[]{srgs, methods, fields};
|
||||
if (!fields.exists()) throw new RuntimeException("Could not find fields.csv");
|
||||
|
||||
return new File[] {srgs, methods, fields};
|
||||
}
|
||||
|
||||
public long startTime()
|
||||
{
|
||||
|
||||
public long startTime() {
|
||||
return startTime;
|
||||
}
|
||||
|
||||
public void remap(ClassNode cnode, ClassVisitor cv)
|
||||
{
|
||||
public void remap(ClassNode cnode, ClassVisitor cv) {
|
||||
cstMappper.transform(cnode);
|
||||
cnode.accept(new RemappingClassAdapter(cv, obfMapper));
|
||||
}
|
||||
|
||||
public static List<String> getParents(ClassNode cnode)
|
||||
{
|
||||
public static List<String> getParents(ClassNode cnode) {
|
||||
List<String> parents = new LinkedList<String>();
|
||||
if(cnode.superName != null)
|
||||
parents.add(cnode.superName);
|
||||
|
||||
for(String s_interface : cnode.interfaces)
|
||||
parents.add(s_interface);
|
||||
|
||||
if (cnode.superName != null) parents.add(cnode.superName);
|
||||
|
||||
for (String s_interface : cnode.interfaces) parents.add(s_interface);
|
||||
|
||||
return parents;
|
||||
}
|
||||
|
||||
public void finish(boolean errored)
|
||||
{
|
||||
long millis = System.currentTimeMillis()-startTime;
|
||||
out().println((errored ? "Errored after" : "Done in ")+new DecimalFormat("0.00").format(millis/1000D)+"s");
|
||||
public void finish(boolean errored) {
|
||||
long millis = System.currentTimeMillis() - startTime;
|
||||
out().println((errored ? "Errored after" : "Done in ") + new DecimalFormat("0.00").format(millis / 1000D)
|
||||
+ "s");
|
||||
finished = true;
|
||||
}
|
||||
|
||||
public boolean finished()
|
||||
{
|
||||
|
||||
public boolean finished() {
|
||||
return finished;
|
||||
}
|
||||
|
||||
public void parseMappings()
|
||||
{
|
||||
public void parseMappings() {
|
||||
obf.parseMappings(mappings);
|
||||
}
|
||||
}
|
||||
@@ -2,19 +2,16 @@ package codechicken.obfuscator;
|
||||
|
||||
import java.io.PrintStream;
|
||||
|
||||
public class SystemLogStreams implements ILogStreams
|
||||
{
|
||||
public class SystemLogStreams implements ILogStreams {
|
||||
public static SystemLogStreams inst = new SystemLogStreams();
|
||||
|
||||
|
||||
@Override
|
||||
public PrintStream err()
|
||||
{
|
||||
public PrintStream err() {
|
||||
return System.err;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public PrintStream out()
|
||||
{
|
||||
public PrintStream out() {
|
||||
return System.out;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user