mirror of
https://github.com/GTNewHorizons/CodeChickenCore.git
synced 2026-11-16 10:44:51 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c5b8594660 | ||
|
|
7b0ab21823 | ||
|
|
dd1abf7ac4 | ||
|
|
20b1e28074 | ||
|
|
cc15e4cec6 | ||
|
|
83f5eac8d8 | ||
|
|
2cf7226306 | ||
|
|
6273a1e71a | ||
|
|
b52d844ed6 | ||
|
|
331a5fcd3f | ||
|
|
955a875d42 | ||
|
|
b45ef7230d | ||
|
|
de334d86f6 | ||
|
|
acdf6d754f | ||
|
|
818b13551b | ||
|
|
cef8a9cbc0 | ||
|
|
cd994ecd27 | ||
|
|
817438ec82 | ||
|
|
1ee3abf0ff | ||
|
|
a37aeac535 | ||
|
|
9adf1b6650 |
No files matched your search
@@ -0,0 +1,19 @@
|
|||||||
|
# This is the universal Text Editor Configuration
|
||||||
|
# for all GTNewHorizons projects
|
||||||
|
# See: https://editorconfig.org/
|
||||||
|
|
||||||
|
root = true
|
||||||
|
|
||||||
|
[*]
|
||||||
|
charset = utf-8
|
||||||
|
end_of_line = lf
|
||||||
|
indent_size = 4
|
||||||
|
indent_style = space
|
||||||
|
insert_final_newline = true
|
||||||
|
trim_trailing_whitespace = true
|
||||||
|
|
||||||
|
[*.{bat,ini}]
|
||||||
|
end_of_line = crlf
|
||||||
|
|
||||||
|
[*.{dtd,json,info,mcmeta,md,sh,svg,xml,xsd,xsl,yaml,yml}]
|
||||||
|
indent_size = 2
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
# Ignore spotlessApply reformat
|
||||||
|
955a875d42bd8f725d389ef8c4f571824f2ae0c8
|
||||||
@@ -0,0 +1,44 @@
|
|||||||
|
* text eol=lf
|
||||||
|
|
||||||
|
*.[jJ][aA][rR] binary
|
||||||
|
|
||||||
|
*.[pP][nN][gG] binary
|
||||||
|
*.[jJ][pP][gG] binary
|
||||||
|
*.[jJ][pP][eE][gG] binary
|
||||||
|
*.[gG][iI][fF] binary
|
||||||
|
*.[tT][iI][fF] binary
|
||||||
|
*.[tT][iI][fF][fF] binary
|
||||||
|
*.[iI][cC][oO] binary
|
||||||
|
*.[sS][vV][gG] text
|
||||||
|
*.[eE][pP][sS] binary
|
||||||
|
*.[xX][cC][fF] binary
|
||||||
|
|
||||||
|
*.[kK][aA][rR] binary
|
||||||
|
*.[mM]4[aA] binary
|
||||||
|
*.[mM][iI][dD] binary
|
||||||
|
*.[mM][iI][dD][iI] binary
|
||||||
|
*.[mM][pP]3 binary
|
||||||
|
*.[oO][gG][gG] binary
|
||||||
|
*.[rR][aA] binary
|
||||||
|
|
||||||
|
*.7[zZ] binary
|
||||||
|
*.[gG][zZ] binary
|
||||||
|
*.[tT][aA][rR] binary
|
||||||
|
*.[tT][gG][zZ] binary
|
||||||
|
*.[zZ][iI][pP] binary
|
||||||
|
|
||||||
|
*.[tT][cC][nN] binary
|
||||||
|
*.[sS][oO] binary
|
||||||
|
*.[dD][lL][lL] binary
|
||||||
|
*.[dD][yY][lL][iI][bB] binary
|
||||||
|
*.[pP][sS][dD] binary
|
||||||
|
*.[tT][tT][fF] binary
|
||||||
|
*.[oO][tT][fF] binary
|
||||||
|
|
||||||
|
*.[pP][aA][tT][cC][hH] -text
|
||||||
|
|
||||||
|
*.[bB][aA][tT] text eol=crlf
|
||||||
|
*.[cC][mM][dD] text eol=crlf
|
||||||
|
*.[pP][sS]1 text eol=crlf
|
||||||
|
|
||||||
|
*[aA][uU][tT][oO][gG][eE][nN][eE][rR][aA][tT][eE][dD]* binary
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
directory="run/crash-reports"
|
|
||||||
if [ -d $directory ]; then
|
|
||||||
echo "Crash reports detected:"
|
|
||||||
cat $directory/*
|
|
||||||
exit 1
|
|
||||||
else
|
|
||||||
echo "No crash reports detected"
|
|
||||||
exit 0
|
|
||||||
fi
|
|
||||||
Executable
+51
@@ -0,0 +1,51 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
# bashsupport disable=BP5006 # Global environment variables
|
||||||
|
RUNDIR="run" \
|
||||||
|
CRASH="crash-reports" \
|
||||||
|
SERVERLOG="server.log"
|
||||||
|
|
||||||
|
# enable nullglob to get 0 results when no match rather than the pattern
|
||||||
|
shopt -s nullglob
|
||||||
|
|
||||||
|
# store matches in array
|
||||||
|
crash_reports=("$RUNDIR/$CRASH/crash"*.txt)
|
||||||
|
|
||||||
|
# if array not empty there are crash_reports
|
||||||
|
if [ "${#crash_reports[@]}" -gt 0 ]; then
|
||||||
|
# get the latest crash_report from array
|
||||||
|
latest_crash_report="${crash_reports[-1]}"
|
||||||
|
{
|
||||||
|
printf 'Latest crash report detected %s:\n' "${latest_crash_report##*/}"
|
||||||
|
cat "$latest_crash_report"
|
||||||
|
} >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if grep --quiet --fixed-strings 'Fatal errors were detected' "$SERVERLOG"; then
|
||||||
|
{
|
||||||
|
printf 'Fatal errors detected:\n'
|
||||||
|
cat server.log
|
||||||
|
} >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if grep --quiet --fixed-strings 'The state engine was in incorrect state ERRORED and forced into state SERVER_STOPPED' \
|
||||||
|
"$SERVERLOG"; then
|
||||||
|
{
|
||||||
|
printf 'Server force stopped:'
|
||||||
|
cat server.log
|
||||||
|
} >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if ! grep --quiet --perl-regexp --only-matching '.+Done \(.+\)\! For help, type "help" or "\?"' "$SERVERLOG"; then
|
||||||
|
{
|
||||||
|
printf 'Server did not finish startup:'
|
||||||
|
cat server.log
|
||||||
|
} >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
printf 'No crash reports detected'
|
||||||
|
exit 0
|
||||||
@@ -1,5 +1,3 @@
|
|||||||
# This workflow will build a Java project with Gradle and cache/restore any dependencies to improve the workflow execution time
|
|
||||||
# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-gradle
|
|
||||||
|
|
||||||
name: Build and test
|
name: Build and test
|
||||||
|
|
||||||
@@ -11,35 +9,5 @@ on:
|
|||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build-and-test:
|
build-and-test:
|
||||||
runs-on: ubuntu-latest
|
uses: GTNewHorizons/GTNH-Actions-Workflows/.github/workflows/build-and-test.yml@master
|
||||||
steps:
|
secrets: inherit
|
||||||
- uses: actions/checkout@v2
|
|
||||||
with:
|
|
||||||
fetch-depth: 0
|
|
||||||
|
|
||||||
- name: Set up JDK 8
|
|
||||||
uses: actions/setup-java@v2
|
|
||||||
with:
|
|
||||||
java-version: '8'
|
|
||||||
distribution: 'adopt'
|
|
||||||
cache: gradle
|
|
||||||
|
|
||||||
- name: Grant execute permission for gradlew
|
|
||||||
run: chmod +x gradlew
|
|
||||||
|
|
||||||
- name: Setup the workspace
|
|
||||||
run: ./gradlew setupCIWorkspace
|
|
||||||
|
|
||||||
- name: Build the mod
|
|
||||||
run: ./gradlew build
|
|
||||||
|
|
||||||
- name: Run server for 1 minute
|
|
||||||
run: |
|
|
||||||
mkdir run
|
|
||||||
echo "eula=true" > run/eula.txt
|
|
||||||
timeout 10 ./gradlew runServer || true
|
|
||||||
|
|
||||||
- name: Test no crashes happend
|
|
||||||
run: |
|
|
||||||
chmod +x .github/scripts/test-no-crash-reports.sh
|
|
||||||
.github/scripts/test-no-crash-reports.sh
|
|
||||||
@@ -1,45 +1,14 @@
|
|||||||
# This workflow will build a Java project with Gradle and cache/restore any dependencies to improve the workflow execution time
|
|
||||||
# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-gradle
|
|
||||||
|
|
||||||
name: Release tagged build
|
name: Release tagged build
|
||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
tags:
|
tags: [ '*' ]
|
||||||
- '*'
|
|
||||||
|
permissions:
|
||||||
|
contents: write
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build:
|
release-tags:
|
||||||
runs-on: ubuntu-latest
|
uses: GTNewHorizons/GTNH-Actions-Workflows/.github/workflows/release-tags.yml@master
|
||||||
steps:
|
secrets: inherit
|
||||||
- uses: actions/checkout@v2
|
|
||||||
with:
|
|
||||||
fetch-depth: 0
|
|
||||||
|
|
||||||
- name: Set release version
|
|
||||||
run: echo "RELEASE_VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV
|
|
||||||
|
|
||||||
- name: Set up JDK 8
|
|
||||||
uses: actions/setup-java@v2
|
|
||||||
with:
|
|
||||||
java-version: '8'
|
|
||||||
distribution: 'adopt'
|
|
||||||
cache: gradle
|
|
||||||
|
|
||||||
- name: Grant execute permission for gradlew
|
|
||||||
run: chmod +x gradlew
|
|
||||||
|
|
||||||
- name: Setup the workspace
|
|
||||||
run: ./gradlew setupCIWorkspace
|
|
||||||
|
|
||||||
- name: Build the mod
|
|
||||||
run: ./gradlew build
|
|
||||||
|
|
||||||
- name: Release under current tag
|
|
||||||
uses: "marvinpinto/action-automatic-releases@latest"
|
|
||||||
with:
|
|
||||||
repo_token: "${{ secrets.GITHUB_TOKEN }}"
|
|
||||||
automatic_release_tag: "${{ env.RELEASE_VERSION }}"
|
|
||||||
prerelease: false
|
|
||||||
title: "${{ env.RELEASE_VERSION }}"
|
|
||||||
files: build/libs/*.jar
|
|
||||||
@@ -26,3 +26,4 @@ whitelist.json
|
|||||||
*.ipr
|
*.ipr
|
||||||
*.iws
|
*.iws
|
||||||
src/main/resources/mixins.*.json
|
src/main/resources/mixins.*.json
|
||||||
|
*.bat
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
# Any Github changes require admin approval
|
||||||
|
/.github/** @GTNewHorizons/admin
|
||||||
|
|
||||||
+3
-3
@@ -1,8 +1,8 @@
|
|||||||
minecraft {
|
minecraft {
|
||||||
if (replaceGradleTokenInFile) {
|
if (replaceGradleTokenInFile) {
|
||||||
replaceIn "CodeChickenCorePlugin.java"
|
tagReplacementFiles.add "CodeChickenCorePlugin.java"
|
||||||
if(gradleTokenVersion) {
|
if(gradleTokenVersion) {
|
||||||
replace gradleTokenVersion, versionDetails().lastTag
|
injectedTags.put gradleTokenVersion, versionDetails().lastTag
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+1368
-351
File diff suppressed because it is too large.
Load diff
+1
-1
@@ -1,5 +1,5 @@
|
|||||||
// Add your dependencies here
|
// Add your dependencies here
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
compile("com.github.GTNewHorizons:CodeChickenLib:master-SNAPSHOT:dev")
|
api('com.github.GTNewHorizons:CodeChickenLib:1.2.0:dev')
|
||||||
}
|
}
|
||||||
+39
-7
@@ -21,23 +21,26 @@ forgeVersion = 10.13.4.1614
|
|||||||
# Do you need to test how your custom blocks interacts with a player that is not the owner? -> leave name empty
|
# Do you need to test how your custom blocks interacts with a player that is not the owner? -> leave name empty
|
||||||
developmentEnvironmentUserName = Developer
|
developmentEnvironmentUserName = Developer
|
||||||
|
|
||||||
# Define a source file of your project with:
|
# Generate a class with String fields for the mod id, name, version and group name named with the fields below
|
||||||
|
generateGradleTokenClass = codechicken.core.asm.Tags
|
||||||
|
gradleTokenModId = MODID
|
||||||
|
gradleTokenModName = MODNAME
|
||||||
|
gradleTokenVersion = VERSION
|
||||||
|
gradleTokenGroupName = GROUPNAME
|
||||||
|
# [DEPRECATED]
|
||||||
|
# Multiple source files can be defined here by providing a comma-seperated list: Class1.java,Class2.java,Class3.java
|
||||||
# public static final String VERSION = "GRADLETOKEN_VERSION";
|
# public static final String VERSION = "GRADLETOKEN_VERSION";
|
||||||
# The string's content will be replaced with your mod's version when compiled. You should use this to specify your mod's
|
# The string's content will be replaced with your mod's version when compiled. You should use this to specify your mod's
|
||||||
# version in @Mod([...], version = VERSION, [...])
|
# version in @Mod([...], version = VERSION, [...])
|
||||||
# Leave these properties empty to skip individual token replacements
|
# Leave these properties empty to skip individual token replacements
|
||||||
replaceGradleTokenInFile = CodeChickenCoreModContainer.java
|
replaceGradleTokenInFile =
|
||||||
gradleTokenModId = GRADLETOKEN_MODID
|
|
||||||
gradleTokenModName = GRADLETOKEN_MODNAME
|
|
||||||
gradleTokenVersion = GRADLETOKEN_VERSION
|
|
||||||
gradleTokenGroupName =
|
|
||||||
|
|
||||||
# In case your mod provides an API for other mods to implement you may declare its package here. Otherwise, you can
|
# In case your mod provides an API for other mods to implement you may declare its package here. Otherwise, you can
|
||||||
# leave this property empty.
|
# leave this property empty.
|
||||||
# Example value: apiPackage = api + modGroup = com.myname.mymodid -> com.myname.mymodid.api
|
# Example value: apiPackage = api + modGroup = com.myname.mymodid -> com.myname.mymodid.api
|
||||||
apiPackage =
|
apiPackage =
|
||||||
|
|
||||||
# Specify the configuration file for Forge's access transformers here. I must be placed into /src/main/resources/META-INF/
|
# Specify the configuration file for Forge's access transformers here. It must be placed into /src/main/resources/META-INF/
|
||||||
# Example value: mymodid_at.cfg
|
# Example value: mymodid_at.cfg
|
||||||
accessTransformersFile =
|
accessTransformersFile =
|
||||||
|
|
||||||
@@ -58,3 +61,32 @@ containsMixinsAndOrCoreModOnly = true
|
|||||||
# If enabled, you may use 'shadowImplementation' for dependencies. They will be integrated in your jar. It is your
|
# If enabled, you may use 'shadowImplementation' for dependencies. They will be integrated in your jar. It is your
|
||||||
# responsibility check the licence and request permission for distribution, if required.
|
# responsibility check the licence and request permission for distribution, if required.
|
||||||
usesShadowedDependencies = false
|
usesShadowedDependencies = false
|
||||||
|
|
||||||
|
# Publishing to CurseForge requires you to set the CURSEFORGE_TOKEN environment variable to one of your CurseForge API tokens.
|
||||||
|
|
||||||
|
# The project's numeric ID on CurseForge. You can find this in the About Project box.
|
||||||
|
# Leave this empty if you don't want to publish on CurseForge.
|
||||||
|
curseForgeProjectId = 746279
|
||||||
|
|
||||||
|
# The project's relations on CurseForge. You can use this to refer to other projects on CurseForge.
|
||||||
|
# Syntax: type1:name1;type2:name2;...
|
||||||
|
# Where type can be one of [requiredDependency, embeddedLibrary, optionalDependency, tool, incompatible],
|
||||||
|
# and the name is the CurseForge project id of the other mod.
|
||||||
|
# curseForgeRelations =
|
||||||
|
|
||||||
|
|
||||||
|
# Publishing to modrinth requires you to set the MODRINTH_TOKEN environment variable to your current modrinth API token.
|
||||||
|
|
||||||
|
# The project's ID on Modrinth. Can be either the slug or the ID.
|
||||||
|
# Leave this empty if you don't want to publish on Modrinth.
|
||||||
|
|
||||||
|
modrinthProjectId = codechickencore-unofficial
|
||||||
|
|
||||||
|
# The project's relations on Modrinth. You can use this to refer to other projects on Modrinth.
|
||||||
|
# Syntax: scope1-type1:name1;scope2-type2:name2;...
|
||||||
|
# Where scope can be one of [required, optional, incompatible, embedded],
|
||||||
|
# type can be one of [project, version],
|
||||||
|
# and the name is the Modrinth project or version slug/id of the other mod.
|
||||||
|
|
||||||
|
# modrinthRelations =
|
||||||
|
|
||||||
Vendored
BIN
Binary file not shown.
+3
-1
@@ -1,5 +1,7 @@
|
|||||||
distributionBase=GRADLE_USER_HOME
|
distributionBase=GRADLE_USER_HOME
|
||||||
distributionPath=wrapper/dists
|
distributionPath=wrapper/dists
|
||||||
distributionUrl=https\://services.gradle.org/distributions/gradle-6.9.1-bin.zip
|
distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip
|
||||||
|
networkTimeout=10000
|
||||||
|
validateDistributionUrl=true
|
||||||
zipStoreBase=GRADLE_USER_HOME
|
zipStoreBase=GRADLE_USER_HOME
|
||||||
zipStorePath=wrapper/dists
|
zipStorePath=wrapper/dists
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
#!/usr/bin/env sh
|
#!/bin/sh
|
||||||
|
|
||||||
#
|
#
|
||||||
# Copyright 2015 the original author or authors.
|
# Copyright © 2015-2021 the original authors.
|
||||||
#
|
#
|
||||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
# you may not use this file except in compliance with the License.
|
# you may not use this file except in compliance with the License.
|
||||||
@@ -17,78 +17,111 @@
|
|||||||
#
|
#
|
||||||
|
|
||||||
##############################################################################
|
##############################################################################
|
||||||
##
|
#
|
||||||
## Gradle start up script for UN*X
|
# Gradle start up script for POSIX generated by Gradle.
|
||||||
##
|
#
|
||||||
|
# Important for running:
|
||||||
|
#
|
||||||
|
# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is
|
||||||
|
# noncompliant, but you have some other compliant shell such as ksh or
|
||||||
|
# bash, then to run this script, type that shell name before the whole
|
||||||
|
# command line, like:
|
||||||
|
#
|
||||||
|
# ksh Gradle
|
||||||
|
#
|
||||||
|
# Busybox and similar reduced shells will NOT work, because this script
|
||||||
|
# requires all of these POSIX shell features:
|
||||||
|
# * functions;
|
||||||
|
# * expansions «$var», «${var}», «${var:-default}», «${var+SET}»,
|
||||||
|
# «${var#prefix}», «${var%suffix}», and «$( cmd )»;
|
||||||
|
# * compound commands having a testable exit status, especially «case»;
|
||||||
|
# * various built-in commands including «command», «set», and «ulimit».
|
||||||
|
#
|
||||||
|
# Important for patching:
|
||||||
|
#
|
||||||
|
# (2) This script targets any POSIX shell, so it avoids extensions provided
|
||||||
|
# by Bash, Ksh, etc; in particular arrays are avoided.
|
||||||
|
#
|
||||||
|
# The "traditional" practice of packing multiple parameters into a
|
||||||
|
# space-separated string is a well documented source of bugs and security
|
||||||
|
# problems, so this is (mostly) avoided, by progressively accumulating
|
||||||
|
# options in "$@", and eventually passing that to Java.
|
||||||
|
#
|
||||||
|
# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS,
|
||||||
|
# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly;
|
||||||
|
# see the in-line comments for details.
|
||||||
|
#
|
||||||
|
# There are tweaks for specific operating systems such as AIX, CygWin,
|
||||||
|
# Darwin, MinGW, and NonStop.
|
||||||
|
#
|
||||||
|
# (3) This script is generated from the Groovy template
|
||||||
|
# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
|
||||||
|
# within the Gradle project.
|
||||||
|
#
|
||||||
|
# You can find Gradle at https://github.com/gradle/gradle/.
|
||||||
|
#
|
||||||
##############################################################################
|
##############################################################################
|
||||||
|
|
||||||
# Attempt to set APP_HOME
|
# Attempt to set APP_HOME
|
||||||
|
|
||||||
# Resolve links: $0 may be a link
|
# Resolve links: $0 may be a link
|
||||||
PRG="$0"
|
app_path=$0
|
||||||
# Need this for relative symlinks.
|
|
||||||
while [ -h "$PRG" ] ; do
|
# Need this for daisy-chained symlinks.
|
||||||
ls=`ls -ld "$PRG"`
|
while
|
||||||
link=`expr "$ls" : '.*-> \(.*\)$'`
|
APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path
|
||||||
if expr "$link" : '/.*' > /dev/null; then
|
[ -h "$app_path" ]
|
||||||
PRG="$link"
|
do
|
||||||
else
|
ls=$( ls -ld "$app_path" )
|
||||||
PRG=`dirname "$PRG"`"/$link"
|
link=${ls#*' -> '}
|
||||||
fi
|
case $link in #(
|
||||||
|
/*) app_path=$link ;; #(
|
||||||
|
*) app_path=$APP_HOME$link ;;
|
||||||
|
esac
|
||||||
done
|
done
|
||||||
SAVED="`pwd`"
|
|
||||||
cd "`dirname \"$PRG\"`/" >/dev/null
|
|
||||||
APP_HOME="`pwd -P`"
|
|
||||||
cd "$SAVED" >/dev/null
|
|
||||||
|
|
||||||
APP_NAME="Gradle"
|
# This is normally unused
|
||||||
APP_BASE_NAME=`basename "$0"`
|
# shellcheck disable=SC2034
|
||||||
|
APP_BASE_NAME=${0##*/}
|
||||||
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
|
||||||
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
|
APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit
|
||||||
|
|
||||||
# Use the maximum available, or set MAX_FD != -1 to use that value.
|
# Use the maximum available, or set MAX_FD != -1 to use that value.
|
||||||
MAX_FD="maximum"
|
MAX_FD=maximum
|
||||||
|
|
||||||
warn () {
|
warn () {
|
||||||
echo "$*"
|
echo "$*"
|
||||||
}
|
} >&2
|
||||||
|
|
||||||
die () {
|
die () {
|
||||||
echo
|
echo
|
||||||
echo "$*"
|
echo "$*"
|
||||||
echo
|
echo
|
||||||
exit 1
|
exit 1
|
||||||
}
|
} >&2
|
||||||
|
|
||||||
# OS specific support (must be 'true' or 'false').
|
# OS specific support (must be 'true' or 'false').
|
||||||
cygwin=false
|
cygwin=false
|
||||||
msys=false
|
msys=false
|
||||||
darwin=false
|
darwin=false
|
||||||
nonstop=false
|
nonstop=false
|
||||||
case "`uname`" in
|
case "$( uname )" in #(
|
||||||
CYGWIN* )
|
CYGWIN* ) cygwin=true ;; #(
|
||||||
cygwin=true
|
Darwin* ) darwin=true ;; #(
|
||||||
;;
|
MSYS* | MINGW* ) msys=true ;; #(
|
||||||
Darwin* )
|
NONSTOP* ) nonstop=true ;;
|
||||||
darwin=true
|
|
||||||
;;
|
|
||||||
MINGW* )
|
|
||||||
msys=true
|
|
||||||
;;
|
|
||||||
NONSTOP* )
|
|
||||||
nonstop=true
|
|
||||||
;;
|
|
||||||
esac
|
esac
|
||||||
|
|
||||||
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
|
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
|
||||||
|
|
||||||
|
|
||||||
# Determine the Java command to use to start the JVM.
|
# Determine the Java command to use to start the JVM.
|
||||||
if [ -n "$JAVA_HOME" ] ; then
|
if [ -n "$JAVA_HOME" ] ; then
|
||||||
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
|
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
|
||||||
# IBM's JDK on AIX uses strange locations for the executables
|
# IBM's JDK on AIX uses strange locations for the executables
|
||||||
JAVACMD="$JAVA_HOME/jre/sh/java"
|
JAVACMD=$JAVA_HOME/jre/sh/java
|
||||||
else
|
else
|
||||||
JAVACMD="$JAVA_HOME/bin/java"
|
JAVACMD=$JAVA_HOME/bin/java
|
||||||
fi
|
fi
|
||||||
if [ ! -x "$JAVACMD" ] ; then
|
if [ ! -x "$JAVACMD" ] ; then
|
||||||
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
|
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
|
||||||
@@ -97,92 +130,120 @@ Please set the JAVA_HOME variable in your environment to match the
|
|||||||
location of your Java installation."
|
location of your Java installation."
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
JAVACMD="java"
|
JAVACMD=java
|
||||||
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
if ! command -v java >/dev/null 2>&1
|
||||||
|
then
|
||||||
|
die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||||
|
|
||||||
Please set the JAVA_HOME variable in your environment to match the
|
Please set the JAVA_HOME variable in your environment to match the
|
||||||
location of your Java installation."
|
location of your Java installation."
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Increase the maximum file descriptors if we can.
|
# Increase the maximum file descriptors if we can.
|
||||||
if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
|
if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
|
||||||
MAX_FD_LIMIT=`ulimit -H -n`
|
case $MAX_FD in #(
|
||||||
if [ $? -eq 0 ] ; then
|
max*)
|
||||||
if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
|
# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
|
||||||
MAX_FD="$MAX_FD_LIMIT"
|
# shellcheck disable=SC2039,SC3045
|
||||||
fi
|
MAX_FD=$( ulimit -H -n ) ||
|
||||||
ulimit -n $MAX_FD
|
warn "Could not query maximum file descriptor limit"
|
||||||
if [ $? -ne 0 ] ; then
|
esac
|
||||||
warn "Could not set maximum file descriptor limit: $MAX_FD"
|
case $MAX_FD in #(
|
||||||
fi
|
'' | soft) :;; #(
|
||||||
else
|
*)
|
||||||
warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
|
# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
|
||||||
fi
|
# shellcheck disable=SC2039,SC3045
|
||||||
fi
|
ulimit -n "$MAX_FD" ||
|
||||||
|
warn "Could not set maximum file descriptor limit to $MAX_FD"
|
||||||
# For Darwin, add options to specify how the application appears in the dock
|
|
||||||
if $darwin; then
|
|
||||||
GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
|
|
||||||
fi
|
|
||||||
|
|
||||||
# For Cygwin or MSYS, switch paths to Windows format before running java
|
|
||||||
if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then
|
|
||||||
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
|
|
||||||
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
|
|
||||||
JAVACMD=`cygpath --unix "$JAVACMD"`
|
|
||||||
|
|
||||||
# We build the pattern for arguments to be converted via cygpath
|
|
||||||
ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
|
|
||||||
SEP=""
|
|
||||||
for dir in $ROOTDIRSRAW ; do
|
|
||||||
ROOTDIRS="$ROOTDIRS$SEP$dir"
|
|
||||||
SEP="|"
|
|
||||||
done
|
|
||||||
OURCYGPATTERN="(^($ROOTDIRS))"
|
|
||||||
# Add a user-defined pattern to the cygpath arguments
|
|
||||||
if [ "$GRADLE_CYGPATTERN" != "" ] ; then
|
|
||||||
OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
|
|
||||||
fi
|
|
||||||
# Now convert the arguments - kludge to limit ourselves to /bin/sh
|
|
||||||
i=0
|
|
||||||
for arg in "$@" ; do
|
|
||||||
CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
|
|
||||||
CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
|
|
||||||
|
|
||||||
if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
|
|
||||||
eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
|
|
||||||
else
|
|
||||||
eval `echo args$i`="\"$arg\""
|
|
||||||
fi
|
|
||||||
i=$((i+1))
|
|
||||||
done
|
|
||||||
case $i in
|
|
||||||
(0) set -- ;;
|
|
||||||
(1) set -- "$args0" ;;
|
|
||||||
(2) set -- "$args0" "$args1" ;;
|
|
||||||
(3) set -- "$args0" "$args1" "$args2" ;;
|
|
||||||
(4) set -- "$args0" "$args1" "$args2" "$args3" ;;
|
|
||||||
(5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
|
|
||||||
(6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
|
|
||||||
(7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
|
|
||||||
(8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
|
|
||||||
(9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
|
|
||||||
esac
|
esac
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Escape application args
|
# Collect all arguments for the java command, stacking in reverse order:
|
||||||
save () {
|
# * args from the command line
|
||||||
for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
|
# * the main class name
|
||||||
echo " "
|
# * -classpath
|
||||||
}
|
# * -D...appname settings
|
||||||
APP_ARGS=$(save "$@")
|
# * --module-path (only if needed)
|
||||||
|
# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables.
|
||||||
|
|
||||||
# Collect all arguments for the java command, following the shell quoting and substitution rules
|
# For Cygwin or MSYS, switch paths to Windows format before running java
|
||||||
eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
|
if "$cygwin" || "$msys" ; then
|
||||||
|
APP_HOME=$( cygpath --path --mixed "$APP_HOME" )
|
||||||
|
CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" )
|
||||||
|
|
||||||
# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
|
JAVACMD=$( cygpath --unix "$JAVACMD" )
|
||||||
if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
|
|
||||||
cd "$(dirname "$0")"
|
# Now convert the arguments - kludge to limit ourselves to /bin/sh
|
||||||
|
for arg do
|
||||||
|
if
|
||||||
|
case $arg in #(
|
||||||
|
-*) false ;; # don't mess with options #(
|
||||||
|
/?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath
|
||||||
|
[ -e "$t" ] ;; #(
|
||||||
|
*) false ;;
|
||||||
|
esac
|
||||||
|
then
|
||||||
|
arg=$( cygpath --path --ignore --mixed "$arg" )
|
||||||
|
fi
|
||||||
|
# Roll the args list around exactly as many times as the number of
|
||||||
|
# args, so each arg winds up back in the position where it started, but
|
||||||
|
# possibly modified.
|
||||||
|
#
|
||||||
|
# NB: a `for` loop captures its iteration list before it begins, so
|
||||||
|
# changing the positional parameters here affects neither the number of
|
||||||
|
# iterations, nor the values presented in `arg`.
|
||||||
|
shift # remove old arg
|
||||||
|
set -- "$@" "$arg" # push replacement arg
|
||||||
|
done
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||||
|
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
|
||||||
|
|
||||||
|
# Collect all arguments for the java command:
|
||||||
|
# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
|
||||||
|
# and any embedded shellness will be escaped.
|
||||||
|
# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be
|
||||||
|
# treated as '${Hostname}' itself on the command line.
|
||||||
|
|
||||||
|
set -- \
|
||||||
|
"-Dorg.gradle.appname=$APP_BASE_NAME" \
|
||||||
|
-classpath "$CLASSPATH" \
|
||||||
|
org.gradle.wrapper.GradleWrapperMain \
|
||||||
|
"$@"
|
||||||
|
|
||||||
|
# Stop when "xargs" is not available.
|
||||||
|
if ! command -v xargs >/dev/null 2>&1
|
||||||
|
then
|
||||||
|
die "xargs is not available"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Use "xargs" to parse quoted args.
|
||||||
|
#
|
||||||
|
# With -n1 it outputs one arg per line, with the quotes and backslashes removed.
|
||||||
|
#
|
||||||
|
# In Bash we could simply go:
|
||||||
|
#
|
||||||
|
# readarray ARGS < <( xargs -n1 <<<"$var" ) &&
|
||||||
|
# set -- "${ARGS[@]}" "$@"
|
||||||
|
#
|
||||||
|
# but POSIX shell has neither arrays nor command substitution, so instead we
|
||||||
|
# post-process each arg (as a line of input to sed) to backslash-escape any
|
||||||
|
# character that might be a shell metacharacter, then use eval to reverse
|
||||||
|
# that process (while maintaining the separation between arguments), and wrap
|
||||||
|
# the whole thing up as a single "set" statement.
|
||||||
|
#
|
||||||
|
# This will of course break if any of these variables contains a newline or
|
||||||
|
# an unmatched quote.
|
||||||
|
#
|
||||||
|
|
||||||
|
eval "set -- $(
|
||||||
|
printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" |
|
||||||
|
xargs -n1 |
|
||||||
|
sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' |
|
||||||
|
tr '\n' ' '
|
||||||
|
)" '"$@"'
|
||||||
|
|
||||||
exec "$JAVACMD" "$@"
|
exec "$JAVACMD" "$@"
|
||||||
Vendored
+15
-23
@@ -14,7 +14,7 @@
|
|||||||
@rem limitations under the License.
|
@rem limitations under the License.
|
||||||
@rem
|
@rem
|
||||||
|
|
||||||
@if "%DEBUG%" == "" @echo off
|
@if "%DEBUG%"=="" @echo off
|
||||||
@rem ##########################################################################
|
@rem ##########################################################################
|
||||||
@rem
|
@rem
|
||||||
@rem Gradle startup script for Windows
|
@rem Gradle startup script for Windows
|
||||||
@@ -25,10 +25,14 @@
|
|||||||
if "%OS%"=="Windows_NT" setlocal
|
if "%OS%"=="Windows_NT" setlocal
|
||||||
|
|
||||||
set DIRNAME=%~dp0
|
set DIRNAME=%~dp0
|
||||||
if "%DIRNAME%" == "" set DIRNAME=.
|
if "%DIRNAME%"=="" set DIRNAME=.
|
||||||
|
@rem This is normally unused
|
||||||
set APP_BASE_NAME=%~n0
|
set APP_BASE_NAME=%~n0
|
||||||
set APP_HOME=%DIRNAME%
|
set APP_HOME=%DIRNAME%
|
||||||
|
|
||||||
|
@rem Resolve any "." and ".." in APP_HOME to make it shorter.
|
||||||
|
for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
|
||||||
|
|
||||||
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||||
set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
|
set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
|
||||||
|
|
||||||
@@ -37,7 +41,7 @@ if defined JAVA_HOME goto findJavaFromJavaHome
|
|||||||
|
|
||||||
set JAVA_EXE=java.exe
|
set JAVA_EXE=java.exe
|
||||||
%JAVA_EXE% -version >NUL 2>&1
|
%JAVA_EXE% -version >NUL 2>&1
|
||||||
if "%ERRORLEVEL%" == "0" goto init
|
if %ERRORLEVEL% equ 0 goto execute
|
||||||
|
|
||||||
echo.
|
echo.
|
||||||
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||||
@@ -51,7 +55,7 @@ goto fail
|
|||||||
set JAVA_HOME=%JAVA_HOME:"=%
|
set JAVA_HOME=%JAVA_HOME:"=%
|
||||||
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
|
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
|
||||||
|
|
||||||
if exist "%JAVA_EXE%" goto init
|
if exist "%JAVA_EXE%" goto execute
|
||||||
|
|
||||||
echo.
|
echo.
|
||||||
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
|
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
|
||||||
@@ -61,38 +65,26 @@ echo location of your Java installation.
|
|||||||
|
|
||||||
goto fail
|
goto fail
|
||||||
|
|
||||||
:init
|
|
||||||
@rem Get command-line arguments, handling Windows variants
|
|
||||||
|
|
||||||
if not "%OS%" == "Windows_NT" goto win9xME_args
|
|
||||||
|
|
||||||
:win9xME_args
|
|
||||||
@rem Slurp the command line arguments.
|
|
||||||
set CMD_LINE_ARGS=
|
|
||||||
set _SKIP=2
|
|
||||||
|
|
||||||
:win9xME_args_slurp
|
|
||||||
if "x%~1" == "x" goto execute
|
|
||||||
|
|
||||||
set CMD_LINE_ARGS=%*
|
|
||||||
|
|
||||||
:execute
|
:execute
|
||||||
@rem Setup the command line
|
@rem Setup the command line
|
||||||
|
|
||||||
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
|
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
|
||||||
|
|
||||||
|
|
||||||
@rem Execute Gradle
|
@rem Execute Gradle
|
||||||
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
|
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
|
||||||
|
|
||||||
:end
|
:end
|
||||||
@rem End local scope for the variables with windows NT shell
|
@rem End local scope for the variables with windows NT shell
|
||||||
if "%ERRORLEVEL%"=="0" goto mainEnd
|
if %ERRORLEVEL% equ 0 goto mainEnd
|
||||||
|
|
||||||
:fail
|
:fail
|
||||||
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
|
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
|
||||||
rem the _cmd.exe /c_ return code!
|
rem the _cmd.exe /c_ return code!
|
||||||
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
|
set EXIT_CODE=%ERRORLEVEL%
|
||||||
exit /b 1
|
if %EXIT_CODE% equ 0 set EXIT_CODE=1
|
||||||
|
if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE%
|
||||||
|
exit /b %EXIT_CODE%
|
||||||
|
|
||||||
:mainEnd
|
:mainEnd
|
||||||
if "%OS%"=="Windows_NT" endlocal
|
if "%OS%"=="Windows_NT" endlocal
|
||||||
|
|||||||
@@ -1,7 +1,4 @@
|
|||||||
// Add any additional repositiroes for your dependencies here
|
// Add any additional repositiroes for your dependencies here
|
||||||
|
|
||||||
repositories {
|
repositories {
|
||||||
maven {
|
|
||||||
url = "https://jitpack.io"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
|
||||||
|
pluginManagement {
|
||||||
|
repositories {
|
||||||
|
maven {
|
||||||
|
// RetroFuturaGradle
|
||||||
|
name "GTNH Maven"
|
||||||
|
url "https://nexus.gtnewhorizons.com/repository/public/"
|
||||||
|
mavenContent {
|
||||||
|
includeGroupByRegex("com\\.gtnewhorizons\\..+")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
gradlePluginPortal()
|
||||||
|
mavenCentral()
|
||||||
|
mavenLocal()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
plugins {
|
||||||
|
id 'com.diffplug.blowdryerSetup' version '1.7.1'
|
||||||
|
id 'org.gradle.toolchains.foojay-resolver-convention' version '0.7.0' // Provides java toolchains
|
||||||
|
}
|
||||||
|
|
||||||
|
blowdryerSetup {
|
||||||
|
repoSubfolder 'gtnhShared'
|
||||||
|
github('GTNewHorizons/ExampleMod1.7.10', 'tag', '0.2.0')
|
||||||
|
//devLocal '.' // Use this when testing config updates locally
|
||||||
|
}
|
||||||
@@ -10,22 +10,23 @@ import java.net.URL;
|
|||||||
import java.net.UnknownHostException;
|
import java.net.UnknownHostException;
|
||||||
import java.util.ArrayList;
|
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.client.Minecraft;
|
||||||
import net.minecraft.util.ChatComponentText;
|
import net.minecraft.util.ChatComponentText;
|
||||||
import net.minecraft.util.StatCollector;
|
import net.minecraft.util.StatCollector;
|
||||||
|
|
||||||
public class CCUpdateChecker
|
import com.google.common.base.Function;
|
||||||
{
|
|
||||||
|
import codechicken.core.launch.CodeChickenCorePlugin;
|
||||||
|
import cpw.mods.fml.common.Loader;
|
||||||
|
import cpw.mods.fml.common.versioning.ComparableVersion;
|
||||||
|
import cpw.mods.fml.relauncher.FMLInjectionData;
|
||||||
|
|
||||||
|
public class CCUpdateChecker {
|
||||||
|
|
||||||
private static final ArrayList<String> updates = new ArrayList<String>();
|
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 URL url;
|
||||||
private final Function<String, Void> handler;
|
private final Function<String, Void> handler;
|
||||||
|
|
||||||
@@ -46,11 +47,9 @@ public class CCUpdateChecker
|
|||||||
BufferedReader read = new BufferedReader(new InputStreamReader(conn.getInputStream()));
|
BufferedReader read = new BufferedReader(new InputStreamReader(conn.getInputStream()));
|
||||||
String ret = read.readLine();
|
String ret = read.readLine();
|
||||||
read.close();
|
read.close();
|
||||||
if(ret == null) ret = "";
|
if (ret == null) ret = "";
|
||||||
handler.apply(ret);
|
handler.apply(ret);
|
||||||
} catch (SocketTimeoutException ignored) {}
|
} catch (SocketTimeoutException ignored) {} catch (UnknownHostException ignored) {} catch (IOException iox) {
|
||||||
catch (UnknownHostException ignored) {}
|
|
||||||
catch (IOException iox) {
|
|
||||||
iox.printStackTrace();
|
iox.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -58,12 +57,10 @@ public class CCUpdateChecker
|
|||||||
|
|
||||||
public static void tick() {
|
public static void tick() {
|
||||||
Minecraft mc = Minecraft.getMinecraft();
|
Minecraft mc = Minecraft.getMinecraft();
|
||||||
if (!mc.inGameHasFocus)
|
if (!mc.inGameHasFocus) return;
|
||||||
return;
|
|
||||||
|
|
||||||
synchronized (updates) {
|
synchronized (updates) {
|
||||||
for (String s : updates)
|
for (String s : updates) mc.thePlayer.addChatMessage(new ChatComponentText(s));
|
||||||
mc.thePlayer.addChatMessage(new ChatComponentText(s));
|
|
||||||
updates.clear();
|
updates.clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -79,19 +76,24 @@ public class CCUpdateChecker
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void updateCheck(final String mod, final String version) {
|
public static void updateCheck(final String mod, final String version) {
|
||||||
updateCheck("http://www.chickenbones.net/Files/notification/version.php?" +
|
updateCheck(
|
||||||
"version=" + mcVersion() + "&" +
|
"http://www.chickenbones.net/Files/notification/version.php?" + "version="
|
||||||
"file=" + mod,
|
+ mcVersion()
|
||||||
new Function<String, Void>()
|
+ "&"
|
||||||
{
|
+ "file="
|
||||||
@Override public Void apply(String ret) {
|
+ mod,
|
||||||
|
new Function<String, Void>() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Void apply(String ret) {
|
||||||
if (!ret.startsWith("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;
|
return null;
|
||||||
}
|
}
|
||||||
ComparableVersion newversion = new ComparableVersion(ret.substring(5));
|
ComparableVersion newversion = new ComparableVersion(ret.substring(5));
|
||||||
if (newversion.compareTo(new ComparableVersion(version)) > 0)
|
if (newversion.compareTo(new ComparableVersion(version)) > 0) addUpdateMessage(
|
||||||
addUpdateMessage(StatCollector.translateToLocalFormatted("codechickencore.update", newversion, mod));
|
StatCollector.translateToLocalFormatted("codechickencore.update", newversion, mod));
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -105,7 +107,7 @@ public class CCUpdateChecker
|
|||||||
try {
|
try {
|
||||||
new ThreadUpdateCheck(new URL(url), handler).start();
|
new ThreadUpdateCheck(new URL(url), handler).start();
|
||||||
} catch (MalformedURLException e) {
|
} catch (MalformedURLException e) {
|
||||||
CodeChickenCorePlugin.logger.error("Malformed URL: "+url, e);
|
CodeChickenCorePlugin.logger.error("Malformed URL: " + url, e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -10,20 +10,20 @@ import java.util.zip.ZipEntry;
|
|||||||
import java.util.zip.ZipInputStream;
|
import java.util.zip.ZipInputStream;
|
||||||
|
|
||||||
import net.minecraft.launchwrapper.Launch;
|
import net.minecraft.launchwrapper.Launch;
|
||||||
import org.objectweb.asm.tree.ClassNode;
|
|
||||||
|
|
||||||
import codechicken.core.launch.CodeChickenCorePlugin;
|
import org.objectweb.asm.tree.ClassNode;
|
||||||
import codechicken.lib.asm.ASMHelper;
|
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
|
|
||||||
|
import codechicken.core.launch.CodeChickenCorePlugin;
|
||||||
|
import codechicken.lib.asm.ASMHelper;
|
||||||
import cpw.mods.fml.common.FMLLog;
|
import cpw.mods.fml.common.FMLLog;
|
||||||
import cpw.mods.fml.common.Loader;
|
import cpw.mods.fml.common.Loader;
|
||||||
import cpw.mods.fml.common.ModClassLoader;
|
import cpw.mods.fml.common.ModClassLoader;
|
||||||
import cpw.mods.fml.relauncher.CoreModManager;
|
import cpw.mods.fml.relauncher.CoreModManager;
|
||||||
|
|
||||||
public class ClassDiscoverer
|
public class ClassDiscoverer {
|
||||||
{
|
|
||||||
public IStringMatcher matcher;
|
public IStringMatcher matcher;
|
||||||
public String[] superclasses;
|
public String[] superclasses;
|
||||||
public ArrayList<Class<?>> classes;
|
public ArrayList<Class<?>> classes;
|
||||||
@@ -40,9 +40,11 @@ public class ClassDiscoverer
|
|||||||
}
|
}
|
||||||
|
|
||||||
public ClassDiscoverer(Class<?>... superclasses) {
|
public ClassDiscoverer(Class<?>... superclasses) {
|
||||||
this(new IStringMatcher()
|
this(new IStringMatcher() {
|
||||||
{
|
|
||||||
public boolean matches(String test) {return true;}
|
public boolean matches(String test) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}, superclasses);
|
}, superclasses);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -59,13 +61,11 @@ public class ClassDiscoverer
|
|||||||
try {
|
try {
|
||||||
String classname = resource.replace(".class", "").replace("\\", ".").replace("/", ".");
|
String classname = resource.replace(".class", "").replace("\\", ".").replace("/", ".");
|
||||||
byte[] bytes = Launch.classLoader.getClassBytes(classname);
|
byte[] bytes = Launch.classLoader.getClassBytes(classname);
|
||||||
if (bytes == null)
|
if (bytes == null) return;
|
||||||
return;
|
|
||||||
|
|
||||||
ClassNode cnode = ASMHelper.createClassNode(bytes);
|
ClassNode cnode = ASMHelper.createClassNode(bytes);
|
||||||
for (String superclass : superclasses)
|
for (String superclass : superclasses)
|
||||||
if (!cnode.interfaces.contains(superclass) && !cnode.superName.equals(superclass))
|
if (!cnode.interfaces.contains(superclass) && !cnode.superName.equals(superclass)) return;
|
||||||
return;
|
|
||||||
|
|
||||||
addClass(classname);
|
addClass(classname);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
@@ -83,27 +83,31 @@ public class ClassDiscoverer
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void findClasspathMods() {
|
private void findClasspathMods() {
|
||||||
List<String> knownLibraries = ImmutableList.<String>builder()
|
List<String> knownLibraries = ImmutableList.<String>builder().addAll(modClassLoader.getDefaultLibraries())
|
||||||
.addAll(modClassLoader.getDefaultLibraries())
|
|
||||||
.addAll(CoreModManager.getLoadedCoremods()).build();
|
.addAll(CoreModManager.getLoadedCoremods()).build();
|
||||||
File[] minecraftSources = modClassLoader.getParentSources();
|
File[] minecraftSources = modClassLoader.getParentSources();
|
||||||
HashSet<String> searchedSources = new HashSet<String>();
|
HashSet<String> searchedSources = new HashSet<String>();
|
||||||
for (File minecraftSource : minecraftSources) {
|
for (File minecraftSource : minecraftSources) {
|
||||||
if (searchedSources.contains(minecraftSource.getAbsolutePath()))
|
if (searchedSources.contains(minecraftSource.getAbsolutePath())) continue;
|
||||||
continue;
|
|
||||||
searchedSources.add(minecraftSource.getAbsolutePath());
|
searchedSources.add(minecraftSource.getAbsolutePath());
|
||||||
|
|
||||||
if (minecraftSource.isFile()) {
|
if (minecraftSource.isFile()) {
|
||||||
if (!knownLibraries.contains(minecraftSource.getName())) {
|
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 {
|
try {
|
||||||
readFromZipFile(minecraftSource);
|
readFromZipFile(minecraftSource);
|
||||||
} catch (Exception e) {
|
} 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()) {
|
} 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);
|
readFromDirectory(minecraftSource, minecraftSource);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -123,8 +127,7 @@ public class ClassDiscoverer
|
|||||||
if (!zipentry.isDirectory() && matcher.matches(name)) {
|
if (!zipentry.isDirectory() && matcher.matches(name)) {
|
||||||
checkAddClass(fullname);
|
checkAddClass(fullname);
|
||||||
}
|
}
|
||||||
}
|
} while (true);
|
||||||
while (true);
|
|
||||||
fileinputstream.close();
|
fileinputstream.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,12 +1,5 @@
|
|||||||
package codechicken.core;
|
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.Minecraft;
|
||||||
import net.minecraft.client.gui.GuiScreen;
|
import net.minecraft.client.gui.GuiScreen;
|
||||||
import net.minecraft.network.NetworkManager;
|
import net.minecraft.network.NetworkManager;
|
||||||
@@ -14,8 +7,14 @@ import net.minecraft.server.MinecraftServer;
|
|||||||
import net.minecraft.util.EnumChatFormatting;
|
import net.minecraft.util.EnumChatFormatting;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
|
|
||||||
public class ClientUtils extends CommonUtils
|
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;
|
||||||
|
|
||||||
|
public class ClientUtils extends CommonUtils {
|
||||||
|
|
||||||
private static Minecraft mc() {
|
private static Minecraft mc() {
|
||||||
return Minecraft.getMinecraft();
|
return Minecraft.getMinecraft();
|
||||||
}
|
}
|
||||||
@@ -24,15 +23,14 @@ public class ClientUtils extends CommonUtils
|
|||||||
return mc().theWorld;
|
return mc().theWorld;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean inWorld()//TODO unused
|
public static boolean inWorld() // TODO unused
|
||||||
{
|
{
|
||||||
return mc().getNetHandler() != null;
|
return mc().getNetHandler() != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void openSMPGui(int windowId, GuiScreen gui) {
|
public static void openSMPGui(int windowId, GuiScreen gui) {
|
||||||
mc().displayGuiScreen(gui);
|
mc().displayGuiScreen(gui);
|
||||||
if (windowId != 0)
|
if (windowId != 0) mc().thePlayer.openContainer.windowId = windowId;
|
||||||
mc().thePlayer.openContainer.windowId = windowId;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static float getRenderFrame() {
|
public static float getRenderFrame() {
|
||||||
@@ -63,7 +61,8 @@ public class ClientUtils extends CommonUtils
|
|||||||
|
|
||||||
public static void enhanceSupportersList(Object mod) {
|
public static void enhanceSupportersList(Object mod) {
|
||||||
ModContainer mc = FMLCommonHandler.instance().findContainerFor(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);
|
GuiModListScroll.register(mod);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2,15 +2,16 @@ package codechicken.core;
|
|||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
|
||||||
import cpw.mods.fml.common.FMLCommonHandler;
|
|
||||||
import cpw.mods.fml.relauncher.FMLInjectionData;
|
|
||||||
import net.minecraft.entity.Entity;
|
import net.minecraft.entity.Entity;
|
||||||
import net.minecraft.entity.EntityList;
|
import net.minecraft.entity.EntityList;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
import net.minecraftforge.common.DimensionManager;
|
import net.minecraftforge.common.DimensionManager;
|
||||||
|
|
||||||
public class CommonUtils
|
import cpw.mods.fml.common.FMLCommonHandler;
|
||||||
{
|
import cpw.mods.fml.relauncher.FMLInjectionData;
|
||||||
|
|
||||||
|
public class CommonUtils {
|
||||||
|
|
||||||
public static boolean isClient() {
|
public static boolean isClient() {
|
||||||
return FMLCommonHandler.instance().getSide().isClient();
|
return FMLCommonHandler.instance().getSide().isClient();
|
||||||
}
|
}
|
||||||
@@ -37,14 +38,12 @@ public class CommonUtils
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static String getRelativePath(File parent, File child) {
|
public static String getRelativePath(File parent, File child) {
|
||||||
if (parent.isFile() || !child.getPath().startsWith(parent.getPath()))
|
if (parent.isFile() || !child.getPath().startsWith(parent.getPath())) return null;
|
||||||
return null;
|
|
||||||
|
|
||||||
return child.getPath().substring(parent.getPath().length() + 1);
|
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.classToStringMapping.put(entityClass, identifier);
|
||||||
EntityList.stringToClassMapping.put(identifier, entityClass);
|
EntityList.stringToClassMapping.put(identifier, entityClass);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,40 @@
|
|||||||
package codechicken.core;
|
package codechicken.core;
|
||||||
|
|
||||||
|
import static org.lwjgl.opengl.GL11.GL_ALWAYS;
|
||||||
|
import static org.lwjgl.opengl.GL11.GL_EQUAL;
|
||||||
|
import static org.lwjgl.opengl.GL11.GL_KEEP;
|
||||||
|
import static org.lwjgl.opengl.GL11.GL_PACK_ALIGNMENT;
|
||||||
|
import static org.lwjgl.opengl.GL11.GL_REPLACE;
|
||||||
|
import static org.lwjgl.opengl.GL11.GL_STENCIL_INDEX;
|
||||||
|
import static org.lwjgl.opengl.GL11.GL_STENCIL_TEST;
|
||||||
|
import static org.lwjgl.opengl.GL11.GL_UNPACK_ALIGNMENT;
|
||||||
|
import static org.lwjgl.opengl.GL11.GL_UNSIGNED_BYTE;
|
||||||
|
import static org.lwjgl.opengl.GL11.GL_ZERO;
|
||||||
|
import static org.lwjgl.opengl.GL11.glColorMask;
|
||||||
|
import static org.lwjgl.opengl.GL11.glDisable;
|
||||||
|
import static org.lwjgl.opengl.GL11.glEnable;
|
||||||
|
import static org.lwjgl.opengl.GL11.glPixelStorei;
|
||||||
|
import static org.lwjgl.opengl.GL11.glReadPixels;
|
||||||
|
import static org.lwjgl.opengl.GL11.glStencilFunc;
|
||||||
|
import static org.lwjgl.opengl.GL11.glStencilOp;
|
||||||
|
|
||||||
|
import java.awt.Dimension;
|
||||||
|
import java.awt.image.BufferedImage;
|
||||||
|
import java.io.File;
|
||||||
|
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;
|
||||||
|
|
||||||
import codechicken.core.launch.CodeChickenCorePlugin;
|
import codechicken.core.launch.CodeChickenCorePlugin;
|
||||||
import codechicken.lib.gui.GuiDraw;
|
import codechicken.lib.gui.GuiDraw;
|
||||||
import codechicken.lib.vec.Rectangle4i;
|
import codechicken.lib.vec.Rectangle4i;
|
||||||
@@ -7,27 +42,9 @@ import cpw.mods.fml.client.GuiModList;
|
|||||||
import cpw.mods.fml.common.FMLCommonHandler;
|
import cpw.mods.fml.common.FMLCommonHandler;
|
||||||
import cpw.mods.fml.common.ModContainer;
|
import cpw.mods.fml.common.ModContainer;
|
||||||
import cpw.mods.fml.common.ModMetadata;
|
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;
|
public class GuiModListScroll {
|
||||||
|
|
||||||
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;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.nio.ByteBuffer;
|
|
||||||
import java.util.LinkedList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class GuiModListScroll
|
|
||||||
{
|
|
||||||
private static List<ModContainer> scrollMods = new LinkedList<ModContainer>();
|
private static List<ModContainer> scrollMods = new LinkedList<ModContainer>();
|
||||||
|
|
||||||
public static void register(Object mod) {
|
public static void register(Object mod) {
|
||||||
@@ -37,8 +54,7 @@ public class GuiModListScroll
|
|||||||
private static void register(ModContainer mod) {
|
private static void register(ModContainer mod) {
|
||||||
if (MinecraftForgeClient.getStencilBits() == 0)
|
if (MinecraftForgeClient.getStencilBits() == 0)
|
||||||
CodeChickenCorePlugin.logger.error("Unable to do mod description scrolling due to lack of stencil buffer");
|
CodeChickenCorePlugin.logger.error("Unable to do mod description scrolling due to lack of stencil buffer");
|
||||||
else
|
else scrollMods.add(mod);
|
||||||
scrollMods.add(mod);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void screenshotStencil(int x) {
|
private static void screenshotStencil(int x) {
|
||||||
@@ -49,11 +65,10 @@ public class GuiModListScroll
|
|||||||
glPixelStorei(GL_PACK_ALIGNMENT, 1);
|
glPixelStorei(GL_PACK_ALIGNMENT, 1);
|
||||||
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
|
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
|
||||||
glReadPixels(0, 0, d.width, d.height, GL_STENCIL_INDEX, GL_UNSIGNED_BYTE, buf);
|
glReadPixels(0, 0, d.width, d.height, GL_STENCIL_INDEX, GL_UNSIGNED_BYTE, buf);
|
||||||
for(int i = 0; i < d.width; i++)
|
for (int i = 0; i < d.width; i++) for (int j = 0; j < d.height; j++)
|
||||||
for(int j = 0; j < d.height; j++)
|
img.setRGB(i, d.height - j - 1, buf.get(j * d.width + i) == 0 ? 0 : 0xFFFFFF);
|
||||||
img.setRGB(i, d.height-j-1, buf.get(j * d.width + i) == 0 ? 0 : 0xFFFFFF);
|
|
||||||
try {
|
try {
|
||||||
ImageIO.write(img, "png", new File("stencil"+x+".png"));
|
ImageIO.write(img, "png", new File("stencil" + x + ".png"));
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
@@ -63,36 +78,35 @@ public class GuiModListScroll
|
|||||||
private static double scroll;
|
private static double scroll;
|
||||||
private static double lastFrameTime;
|
private static double lastFrameTime;
|
||||||
private static double timeStart;
|
private static double timeStart;
|
||||||
|
|
||||||
public static void draw(GuiModList gui, int mouseX, int mouseY) {
|
public static void draw(GuiModList gui, int mouseX, int mouseY) {
|
||||||
ModContainer selectedMod = ReflectionManager.getField(GuiModList.class, ModContainer.class, gui, "selectedMod");
|
ModContainer selectedMod = ReflectionManager.getField(GuiModList.class, ModContainer.class, gui, "selectedMod");
|
||||||
if(selectedMod != lastMod) {
|
if (selectedMod != lastMod) {
|
||||||
lastMod = selectedMod;
|
lastMod = selectedMod;
|
||||||
scroll = 0;
|
scroll = 0;
|
||||||
timeStart = ClientUtils.getRenderTime();
|
timeStart = ClientUtils.getRenderTime();
|
||||||
}
|
}
|
||||||
if(!scrollMods.contains(selectedMod) || selectedMod.getMetadata().autogenerated)
|
if (!scrollMods.contains(selectedMod) || selectedMod.getMetadata().autogenerated) return;
|
||||||
return;
|
|
||||||
|
|
||||||
int y1 = calcDescY(gui, selectedMod);
|
int y1 = calcDescY(gui, selectedMod);
|
||||||
int y1draw = y1 + 10;
|
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 x1 = ReflectionManager.getField(GuiModList.class, Integer.class, gui, "listWidth") + 20;
|
||||||
int x2 = gui.width - 20;
|
int x2 = gui.width - 20;
|
||||||
if(x2 - x1 <= 20)
|
if (x2 - x1 <= 20) return;
|
||||||
return;
|
|
||||||
|
|
||||||
glEnable(GL_STENCIL_TEST);
|
glEnable(GL_STENCIL_TEST);
|
||||||
glStencilFunc(GL_ALWAYS, 1, 1);
|
glStencilFunc(GL_ALWAYS, 1, 1);
|
||||||
glColorMask(false, false, false, false);
|
glColorMask(false, false, false, false);
|
||||||
glStencilOp(GL_ZERO, GL_ZERO, GL_ZERO);
|
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);
|
screenshotStencil(1);
|
||||||
|
|
||||||
glStencilOp(GL_REPLACE, GL_REPLACE, GL_REPLACE);
|
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);
|
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);
|
screenshotStencil(2);
|
||||||
|
|
||||||
@@ -100,13 +114,13 @@ public class GuiModListScroll
|
|||||||
glStencilFunc(GL_EQUAL, 1, 1);
|
glStencilFunc(GL_EQUAL, 1, 1);
|
||||||
glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
|
glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
|
||||||
|
|
||||||
gui.drawDefaultBackground();//fill stencil with background
|
gui.drawDefaultBackground(); // fill stencil with background
|
||||||
|
|
||||||
glColorMask(false, false, false, false);
|
glColorMask(false, false, false, false);
|
||||||
glStencilOp(GL_ZERO, GL_ZERO, GL_ZERO);
|
glStencilOp(GL_ZERO, GL_ZERO, GL_ZERO);
|
||||||
GuiDraw.drawRect(0, 0, gui.width, gui.height, -1);
|
GuiDraw.drawRect(0, 0, gui.width, gui.height, -1);
|
||||||
glStencilOp(GL_REPLACE, GL_REPLACE, GL_REPLACE);
|
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);
|
screenshotStencil(3);
|
||||||
|
|
||||||
@@ -114,10 +128,11 @@ public class GuiModListScroll
|
|||||||
glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
|
glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
|
||||||
|
|
||||||
String description = selectedMod.getMetadata().description;
|
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;
|
boolean needsScroll = height > y2 - y1draw;
|
||||||
if((ClientUtils.getRenderTime() - timeStart) > 40 && needsScroll) {
|
if ((ClientUtils.getRenderTime() - timeStart) > 40 && needsScroll) {
|
||||||
double dt = ClientUtils.getRenderTime() - lastFrameTime;
|
double dt = ClientUtils.getRenderTime() - lastFrameTime;
|
||||||
if (new Rectangle4i(x1, y1draw, x2 - x1, y2 - y1draw).contains(mouseX, mouseY)) {
|
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;
|
double d = Keyboard.isKeyDown(Keyboard.KEY_UP) ? -1 : Keyboard.isKeyDown(Keyboard.KEY_DOWN) ? 1 : 0;
|
||||||
@@ -128,36 +143,35 @@ public class GuiModListScroll
|
|||||||
}
|
}
|
||||||
lastFrameTime = ClientUtils.getRenderTime();
|
lastFrameTime = ClientUtils.getRenderTime();
|
||||||
|
|
||||||
//draw description
|
// draw description
|
||||||
|
|
||||||
double dy = scroll % (height + 20);
|
double dy = scroll % (height + 20);
|
||||||
GL11.glPushMatrix();
|
GL11.glPushMatrix();
|
||||||
GL11.glTranslated(0, -dy, 0);
|
GL11.glTranslated(0, -dy, 0);
|
||||||
GuiDraw.fontRenderer.drawSplitString(description, x1, y1draw, x2-x1, 0xDDDDDD);
|
GuiDraw.fontRenderer.drawSplitString(description, x1, y1draw, x2 - x1, 0xDDDDDD);
|
||||||
if(needsScroll) {
|
if (needsScroll) {
|
||||||
GL11.glTranslated(0, height + 20, 0);
|
GL11.glTranslated(0, height + 20, 0);
|
||||||
GuiDraw.fontRenderer.drawSplitString(description, x1, y1draw, x2 - x1, 0xDDDDDD);
|
GuiDraw.fontRenderer.drawSplitString(description, x1, y1draw, x2 - x1, 0xDDDDDD);
|
||||||
}
|
}
|
||||||
GL11.glPopMatrix();
|
GL11.glPopMatrix();
|
||||||
|
|
||||||
glDisable(GL_STENCIL_TEST);
|
glDisable(GL_STENCIL_TEST);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Does not add the last 10 px space before the description normally starts
|
* Does not add the last 10 px space before the description normally starts Ignores empty child mods expecting a
|
||||||
* Ignores empty child mods expecting a background draw overwrite
|
* background draw overwrite
|
||||||
*/
|
*/
|
||||||
private static int calcDescY(GuiModList gui, ModContainer mod) {
|
private static int calcDescY(GuiModList gui, ModContainer mod) {
|
||||||
ModMetadata meta = mod.getMetadata();
|
ModMetadata meta = mod.getMetadata();
|
||||||
int y = 35;
|
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 += 65;
|
||||||
y += 12; // title
|
y += 12; // title
|
||||||
y += 40; // necessary lines
|
y += 40; // necessary lines
|
||||||
if(!meta.credits.isEmpty())
|
if (!meta.credits.isEmpty()) y += 10;
|
||||||
y += 10;
|
if (!meta.childMods.isEmpty()) y += 10;
|
||||||
if(!meta.childMods.isEmpty())
|
|
||||||
y += 10;
|
|
||||||
return y;
|
return y;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2,7 +2,7 @@ package codechicken.core;
|
|||||||
|
|
||||||
import net.minecraft.entity.player.EntityPlayerMP;
|
import net.minecraft.entity.player.EntityPlayerMP;
|
||||||
|
|
||||||
public interface IGuiPacketSender
|
public interface IGuiPacketSender {
|
||||||
{
|
|
||||||
void sendPacket(EntityPlayerMP player, int windowId);
|
void sendPacket(EntityPlayerMP player, int windowId);
|
||||||
}
|
}
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
package codechicken.core;
|
package codechicken.core;
|
||||||
|
|
||||||
public interface IStringMatcher
|
public interface IStringMatcher {
|
||||||
{
|
|
||||||
public boolean matches(String test);
|
public boolean matches(String test);
|
||||||
}
|
}
|
||||||
@@ -2,8 +2,8 @@ package codechicken.core;
|
|||||||
|
|
||||||
import codechicken.core.launch.CodeChickenCorePlugin;
|
import codechicken.core.launch.CodeChickenCorePlugin;
|
||||||
|
|
||||||
public class ProfileTimer
|
public class ProfileTimer {
|
||||||
{
|
|
||||||
public double decay;
|
public double decay;
|
||||||
public long startTime;
|
public long startTime;
|
||||||
public long nanoTime;
|
public long nanoTime;
|
||||||
@@ -30,11 +30,11 @@ public class ProfileTimer
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void end() {
|
public void end() {
|
||||||
long t = System.nanoTime()-startTime;
|
long t = System.nanoTime() - startTime;
|
||||||
nanoTime = (long)(nanoTime*decay+t*(1-decay));
|
nanoTime = (long) (nanoTime * decay + t * (1 - decay));
|
||||||
|
|
||||||
scanCount++;
|
scanCount++;
|
||||||
if(logScans > 0 && scanCount % logScans == 0)
|
if (logScans > 0 && scanCount % logScans == 0)
|
||||||
CodeChickenCorePlugin.logger.info("Profiled " + logName + " " + nanoTime + "ns");
|
CodeChickenCorePlugin.logger.info("Profiled " + logName + " " + nanoTime + "ns");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -8,12 +8,11 @@ import java.util.HashMap;
|
|||||||
|
|
||||||
import codechicken.lib.asm.ObfMapping;
|
import codechicken.lib.asm.ObfMapping;
|
||||||
|
|
||||||
public class ReflectionManager
|
public class ReflectionManager {
|
||||||
{
|
|
||||||
public static HashMap<Class<?>, Class<?>> primitiveWrappers = new HashMap<Class<?>, Class<?>>();
|
public static HashMap<Class<?>, Class<?>> primitiveWrappers = new HashMap<Class<?>, Class<?>>();
|
||||||
|
|
||||||
static
|
static {
|
||||||
{
|
|
||||||
primitiveWrappers.put(Integer.TYPE, Integer.class);
|
primitiveWrappers.put(Integer.TYPE, Integer.class);
|
||||||
primitiveWrappers.put(Short.TYPE, Short.class);
|
primitiveWrappers.put(Short.TYPE, Short.class);
|
||||||
primitiveWrappers.put(Byte.TYPE, Byte.class);
|
primitiveWrappers.put(Byte.TYPE, Byte.class);
|
||||||
@@ -23,293 +22,238 @@ public class ReflectionManager
|
|||||||
primitiveWrappers.put(Boolean.TYPE, Boolean.class);
|
primitiveWrappers.put(Boolean.TYPE, Boolean.class);
|
||||||
primitiveWrappers.put(Character.TYPE, Character.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);
|
Class<?> primitive = primitiveWrappers.get(class1);
|
||||||
if(primitive != null)
|
if (primitive != null) {
|
||||||
{
|
if (primitive == Long.class && Long.class.isInstance(obj)) return true;
|
||||||
if(primitive == Long.class && Long.class.isInstance(obj))
|
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;
|
return true;
|
||||||
if((primitive == Long.class || primitive == Integer.class) && Integer.class.isInstance(obj))
|
if ((primitive == Long.class || primitive == Integer.class
|
||||||
|
|| primitive == Short.class
|
||||||
|
|| primitive == Byte.class) && Integer.class.isInstance(obj))
|
||||||
return true;
|
return true;
|
||||||
if((primitive == Long.class || primitive == Integer.class || primitive == Short.class) && Short.class.isInstance(obj))
|
|
||||||
return true;
|
if (primitive == Double.class && Double.class.isInstance(obj)) return true;
|
||||||
if((primitive == Long.class || primitive == Integer.class || primitive == Short.class || primitive == Byte.class) && Integer.class.isInstance(obj))
|
if ((primitive == Double.class || primitive == Float.class) && Float.class.isInstance(obj)) return true;
|
||||||
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 primitive.isInstance(obj);
|
||||||
}
|
}
|
||||||
return class1.isInstance(obj);
|
return class1.isInstance(obj);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Class<?> findClass(String name)
|
public static Class<?> findClass(String name) {
|
||||||
{
|
|
||||||
return findClass(name, true);
|
return findClass(name, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean classExists(String name)
|
public static boolean classExists(String name) {
|
||||||
{
|
|
||||||
return findClass(name, false) != null;
|
return findClass(name, false) != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Class<?> findClass(String name, boolean init)
|
public static Class<?> findClass(String name, boolean init) {
|
||||||
{
|
try {
|
||||||
try
|
|
||||||
{
|
|
||||||
return Class.forName(name, init, ReflectionManager.class.getClassLoader());
|
return Class.forName(name, init, ReflectionManager.class.getClassLoader());
|
||||||
}
|
} catch (ClassNotFoundException cnfe) {
|
||||||
catch (ClassNotFoundException cnfe)
|
try {
|
||||||
{
|
return Class.forName("net.minecraft.src." + name, init, ReflectionManager.class.getClassLoader());
|
||||||
try
|
} catch (ClassNotFoundException cnfe2) {
|
||||||
{
|
|
||||||
return Class.forName("net.minecraft.src."+name, init, ReflectionManager.class.getClassLoader());
|
|
||||||
}
|
|
||||||
catch (ClassNotFoundException cnfe2)
|
|
||||||
{
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void setField(Class<?> class1, Object instance, String name, Object value) throws IllegalArgumentException, IllegalAccessException
|
public static void setField(Class<?> class1, Object instance, String name, Object value)
|
||||||
{
|
throws IllegalArgumentException, IllegalAccessException {
|
||||||
setField(class1, instance, new String[]{name}, value);
|
setField(class1, instance, new String[] { name }, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void setField(Class<?> class1, Object instance, String[] names, Object value) throws IllegalArgumentException, IllegalAccessException
|
public static void setField(Class<?> class1, Object instance, String[] names, Object value)
|
||||||
{
|
throws IllegalArgumentException, IllegalAccessException {
|
||||||
for(Field field : class1.getDeclaredFields())
|
for (Field field : class1.getDeclaredFields()) {
|
||||||
{
|
|
||||||
boolean match = false;
|
boolean match = false;
|
||||||
for(String name : names)
|
for (String name : names) {
|
||||||
{
|
if (field.getName().equals(name)) {
|
||||||
if(field.getName().equals(name))
|
|
||||||
{
|
|
||||||
match = true;
|
match = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(!match)
|
if (!match) {
|
||||||
{
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
field.setAccessible(true);
|
field.setAccessible(true);
|
||||||
field.set(instance, value);
|
field.set(instance, value);
|
||||||
return;
|
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 field = class1.getDeclaredFields()[fieldindex];
|
||||||
field.setAccessible(true);
|
field.setAccessible(true);
|
||||||
field.set(instance, value);
|
field.set(instance, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Static function
|
* Static function void return type single name
|
||||||
* void return type
|
|
||||||
* single name
|
|
||||||
*/
|
*/
|
||||||
public static void callMethod(Class<?> class1, String name, Object... params) throws IllegalArgumentException, IllegalAccessException, InvocationTargetException
|
public static void callMethod(Class<?> class1, String name, Object... params)
|
||||||
{
|
throws IllegalArgumentException, IllegalAccessException, InvocationTargetException {
|
||||||
callMethod(class1, null, new String[]{name}, params);
|
callMethod(class1, null, new String[] { name }, params);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Static function
|
* Static function void return type single name
|
||||||
* 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);
|
callMethod(class1, null, names, params);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* void return type
|
* void return type single name
|
||||||
* single name
|
|
||||||
*/
|
*/
|
||||||
public static void callMethod(Class<?> class1, Object instance, String name, Object... params) throws IllegalArgumentException, IllegalAccessException, InvocationTargetException
|
public static void callMethod(Class<?> class1, Object instance, String name, Object... params)
|
||||||
{
|
throws IllegalArgumentException, IllegalAccessException, InvocationTargetException {
|
||||||
callMethod(class1, null, instance, new String[]{name}, params);
|
callMethod(class1, null, instance, new String[] { name }, params);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* void return type
|
* 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);
|
callMethod(class1, null, instance, names, params);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Static method
|
* Static method single name
|
||||||
* single name
|
|
||||||
*/
|
*/
|
||||||
public static <R> R callMethod(Class<?> class1, Class<R> returntype, String name, Object... params) throws IllegalArgumentException, IllegalAccessException, InvocationTargetException
|
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);
|
return callMethod(class1, returntype, null, new String[] { name }, params);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Static method
|
* 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);
|
return callMethod(class1, returntype, null, names, params);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* sinlge name
|
* sinlge name
|
||||||
*/
|
*/
|
||||||
public static <R> R callMethod(Class<?> class1, Class<R> returntype, Object instance, String name, Object... params) throws IllegalArgumentException, IllegalAccessException, InvocationTargetException
|
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);
|
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
|
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())
|
nextMethod: for (Method method : class1.getDeclaredMethods()) {
|
||||||
{
|
|
||||||
boolean match = false;
|
boolean match = false;
|
||||||
for(String name : names)
|
for (String name : names) {
|
||||||
{
|
if (method.getName().equals(name)) {
|
||||||
if(method.getName().equals(name))
|
|
||||||
{
|
|
||||||
match = true;
|
match = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(!match)
|
if (!match) {
|
||||||
{
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
Class<?>[] paramtypes = method.getParameterTypes();
|
Class<?>[] paramtypes = method.getParameterTypes();
|
||||||
if(paramtypes.length != params.length)
|
if (paramtypes.length != params.length) continue;
|
||||||
continue;
|
|
||||||
|
for (int i = 0; i < params.length; i++) {
|
||||||
for(int i = 0; i < params.length; i++)
|
if (!isInstance(paramtypes[i], params[i])) continue nextMethod;
|
||||||
{
|
|
||||||
if(!isInstance(paramtypes[i], params[i]))
|
|
||||||
continue nextMethod;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
method.setAccessible(true);
|
method.setAccessible(true);
|
||||||
return (R)method.invoke(instance, params);
|
return (R) method.invoke(instance, params);
|
||||||
}
|
}
|
||||||
return null;
|
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 field = class1.getDeclaredFields()[fieldIndex];
|
||||||
field.setAccessible(true);
|
field.setAccessible(true);
|
||||||
return (T) field.get(instance);
|
return (T) field.get(instance);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <T> T getField(Class<?> class1, Class<T> fieldType, Object instance, String fieldName)
|
public static <T> T getField(Class<?> class1, Class<T> fieldType, Object instance, String fieldName) {
|
||||||
{
|
try {
|
||||||
try
|
|
||||||
{
|
|
||||||
Field field = class1.getDeclaredField(fieldName);
|
Field field = class1.getDeclaredField(fieldName);
|
||||||
field.setAccessible(true);
|
field.setAccessible(true);
|
||||||
return (T) field.get(instance);
|
return (T) field.get(instance);
|
||||||
}
|
} catch (Exception e) {
|
||||||
catch(Exception e)
|
|
||||||
{
|
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <T> T newInstance(Class<T> class1, Object... params) throws IllegalArgumentException, InstantiationException, IllegalAccessException, InvocationTargetException
|
public static <T> T newInstance(Class<T> class1, Object... params)
|
||||||
{
|
throws IllegalArgumentException, InstantiationException, IllegalAccessException, InvocationTargetException {
|
||||||
nextMethod: for(Constructor<?> constructor : class1.getDeclaredConstructors())
|
nextMethod: for (Constructor<?> constructor : class1.getDeclaredConstructors()) {
|
||||||
{
|
|
||||||
Class<?>[] paramtypes = constructor.getParameterTypes();
|
Class<?>[] paramtypes = constructor.getParameterTypes();
|
||||||
if(paramtypes.length != params.length)
|
if (paramtypes.length != params.length) continue;
|
||||||
continue;
|
|
||||||
|
for (int i = 0; i < params.length; i++) {
|
||||||
for(int i = 0; i < params.length; i++)
|
if (!isInstance(paramtypes[i], params[i])) continue nextMethod;
|
||||||
{
|
|
||||||
if(!isInstance(paramtypes[i], params[i]))
|
|
||||||
continue nextMethod;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
constructor.setAccessible(true);
|
constructor.setAccessible(true);
|
||||||
return (T)constructor.newInstance(params);
|
return (T) constructor.newInstance(params);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean hasField(Class<?> class1, String fieldName)
|
public static boolean hasField(Class<?> class1, String fieldName) {
|
||||||
{
|
try {
|
||||||
try
|
|
||||||
{
|
|
||||||
class1.getDeclaredField(fieldName);
|
class1.getDeclaredField(fieldName);
|
||||||
return true;
|
return true;
|
||||||
}
|
} catch (NoSuchFieldException nfe) {
|
||||||
catch(NoSuchFieldException nfe)
|
|
||||||
{
|
|
||||||
return false;
|
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);
|
return get(field, class1, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <T> T get(Field field, Class<T> class1, Object instance)
|
public static <T> T get(Field field, Class<T> class1, Object instance) {
|
||||||
{
|
try {
|
||||||
try
|
return (T) field.get(instance);
|
||||||
{
|
} catch (Exception e) {
|
||||||
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)
|
|
||||||
{
|
|
||||||
throw new RuntimeException(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();
|
mapping.toRuntime();
|
||||||
|
|
||||||
try
|
try {
|
||||||
{
|
|
||||||
Class<?> clazz = ReflectionManager.class.getClassLoader().loadClass(mapping.javaClass());
|
Class<?> clazz = ReflectionManager.class.getClassLoader().loadClass(mapping.javaClass());
|
||||||
Field field = clazz.getDeclaredField(mapping.s_name);
|
Field field = clazz.getDeclaredField(mapping.s_name);
|
||||||
field.setAccessible(true);
|
field.setAccessible(true);
|
||||||
return field;
|
return field;
|
||||||
}
|
} catch (Exception e) {
|
||||||
catch(Exception e)
|
|
||||||
{
|
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,16 +7,18 @@ import java.util.List;
|
|||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.Map;
|
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.EntityPlayer;
|
||||||
import net.minecraft.entity.player.EntityPlayerMP;
|
import net.minecraft.entity.player.EntityPlayerMP;
|
||||||
|
import net.minecraft.inventory.Container;
|
||||||
|
import net.minecraft.server.MinecraftServer;
|
||||||
import net.minecraft.util.IChatComponent;
|
import net.minecraft.util.IChatComponent;
|
||||||
|
|
||||||
public class ServerUtils extends CommonUtils
|
import com.mojang.authlib.GameProfile;
|
||||||
{
|
|
||||||
|
import codechicken.lib.asm.ObfMapping;
|
||||||
|
|
||||||
|
public class ServerUtils extends CommonUtils {
|
||||||
|
|
||||||
public static MinecraftServer mc() {
|
public static MinecraftServer mc() {
|
||||||
return MinecraftServer.getServer();
|
return MinecraftServer.getServer();
|
||||||
}
|
}
|
||||||
@@ -31,9 +33,7 @@ public class ServerUtils extends CommonUtils
|
|||||||
|
|
||||||
public static ArrayList<EntityPlayer> getPlayersInDimension(int dimension) {
|
public static ArrayList<EntityPlayer> getPlayersInDimension(int dimension) {
|
||||||
ArrayList<EntityPlayer> players = new ArrayList<EntityPlayer>();
|
ArrayList<EntityPlayer> players = new ArrayList<EntityPlayer>();
|
||||||
for (EntityPlayer p : getPlayers())
|
for (EntityPlayer p : getPlayers()) if (p.dimension == dimension) players.add(p);
|
||||||
if(p.dimension == dimension)
|
|
||||||
players.add(p);
|
|
||||||
|
|
||||||
return players;
|
return players;
|
||||||
}
|
}
|
||||||
@@ -50,13 +50,21 @@ public class ServerUtils extends CommonUtils
|
|||||||
private static Field field_152661_c;
|
private static Field field_152661_c;
|
||||||
private static Class<?> c_ProfileEntry;
|
private static Class<?> c_ProfileEntry;
|
||||||
private static Method func_152668_a;
|
private static Method func_152668_a;
|
||||||
|
|
||||||
static {
|
static {
|
||||||
try {
|
try {
|
||||||
field_152661_c = ReflectionManager.getField(new ObfMapping("net/minecraft/server/management/PlayerProfileCache", "field_152661_c", "[Ljava/util/Map;"));
|
field_152661_c = ReflectionManager.getField(
|
||||||
c_ProfileEntry = ServerUtils.class.getClassLoader().loadClass("net.minecraft.server.management.PlayerProfileCache$ProfileEntry");
|
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(
|
func_152668_a = c_ProfileEntry.getDeclaredMethod(
|
||||||
new ObfMapping("net/minecraft/server/management/PlayerProfileCache$ProfileEntry",
|
new ObfMapping(
|
||||||
"func_152668_a", "()Lcom/mojang/authlib/GameProfile;").toRuntime().s_name);
|
"net/minecraft/server/management/PlayerProfileCache$ProfileEntry",
|
||||||
|
"func_152668_a",
|
||||||
|
"()Lcom/mojang/authlib/GameProfile;").toRuntime().s_name);
|
||||||
func_152668_a.setAccessible(true);
|
func_152668_a.setAccessible(true);
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
@@ -66,14 +74,12 @@ public class ServerUtils extends CommonUtils
|
|||||||
|
|
||||||
public static GameProfile getGameProfile(String username) {
|
public static GameProfile getGameProfile(String username) {
|
||||||
EntityPlayer player = getPlayer(username);
|
EntityPlayer player = getPlayer(username);
|
||||||
if(player != null)
|
if (player != null) return player.getGameProfile();
|
||||||
return player.getGameProfile();
|
|
||||||
|
|
||||||
username = username.toLowerCase(Locale.ROOT);
|
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);
|
Object cacheEntry = ((Map) field_152661_c.get(mc().func_152358_ax())).get(username);
|
||||||
if(cacheEntry != null)
|
if (cacheEntry != null) return (GameProfile) func_152668_a.invoke(cacheEntry);
|
||||||
return (GameProfile) func_152668_a.invoke(cacheEntry);
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
@@ -90,7 +96,6 @@ public class ServerUtils extends CommonUtils
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void sendChatToAll(IChatComponent msg) {
|
public static void sendChatToAll(IChatComponent msg) {
|
||||||
for(EntityPlayer p : getPlayers())
|
for (EntityPlayer p : getPlayers()) p.addChatComponentMessage(msg);
|
||||||
p.addChatComponentMessage(msg);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -5,61 +5,53 @@ import java.util.HashMap;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
|
|
||||||
public class TaskProfiler
|
public class TaskProfiler {
|
||||||
{
|
|
||||||
public static class ProfilerResult
|
public static class ProfilerResult {
|
||||||
{
|
|
||||||
public final String name;
|
public final String name;
|
||||||
public final long time;
|
public final long time;
|
||||||
public final double fraction;
|
public final double fraction;
|
||||||
|
|
||||||
public ProfilerResult(String name, long time, long totalTime)
|
public ProfilerResult(String name, long time, long totalTime) {
|
||||||
{
|
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.time = time;
|
this.time = time;
|
||||||
fraction = time/(double)totalTime;
|
fraction = time / (double) totalTime;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public HashMap<String, Long> times = new HashMap<String, Long>();
|
public HashMap<String, Long> times = new HashMap<String, Long>();
|
||||||
|
|
||||||
public String currentSection;
|
public String currentSection;
|
||||||
private long startTime;
|
private long startTime;
|
||||||
private long totalTime;
|
private long totalTime;
|
||||||
|
|
||||||
public void start(String section)
|
public void start(String section) {
|
||||||
{
|
if (currentSection != null) end();
|
||||||
if(currentSection != null)
|
|
||||||
end();
|
|
||||||
|
|
||||||
currentSection = section;
|
currentSection = section;
|
||||||
startTime = System.nanoTime();
|
startTime = System.nanoTime();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void end()
|
public void end() {
|
||||||
{
|
long time = System.nanoTime() - startTime;
|
||||||
long time = System.nanoTime()-startTime;
|
totalTime += time;
|
||||||
totalTime+=time;
|
|
||||||
|
|
||||||
Long prev = times.get(currentSection);
|
Long prev = times.get(currentSection);
|
||||||
if(prev == null)
|
if (prev == null) prev = 0L;
|
||||||
prev = 0L;
|
times.put(currentSection, prev + time);
|
||||||
times.put(currentSection, prev+time);
|
|
||||||
currentSection = null;
|
currentSection = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<ProfilerResult> getResults()
|
public List<ProfilerResult> getResults() {
|
||||||
{
|
|
||||||
ArrayList<ProfilerResult> results = new ArrayList<ProfilerResult>(times.size());
|
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));
|
results.add(new ProfilerResult(e.getKey(), e.getValue(), totalTime));
|
||||||
return results;
|
return results;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void clear()
|
public void clear() {
|
||||||
{
|
if (currentSection != null) end();
|
||||||
if(currentSection != null)
|
|
||||||
end();
|
|
||||||
times.clear();
|
times.clear();
|
||||||
totalTime = 0;
|
totalTime = 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,12 +6,11 @@ import java.lang.reflect.Field;
|
|||||||
import com.google.common.collect.ImmutableBiMap;
|
import com.google.common.collect.ImmutableBiMap;
|
||||||
|
|
||||||
import codechicken.lib.asm.ObfMapping;
|
import codechicken.lib.asm.ObfMapping;
|
||||||
|
|
||||||
import cpw.mods.fml.common.asm.transformers.AccessTransformer;
|
import cpw.mods.fml.common.asm.transformers.AccessTransformer;
|
||||||
import cpw.mods.fml.common.asm.transformers.deobf.FMLDeobfuscatingRemapper;
|
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 boolean makeAllPublic;
|
||||||
private static Field f_classNameBiMap;
|
private static Field f_classNameBiMap;
|
||||||
private static Object emptyMap = ImmutableBiMap.of();
|
private static Object emptyMap = ImmutableBiMap.of();
|
||||||
@@ -22,17 +21,15 @@ public class CodeChickenAccessTransformer extends AccessTransformer
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void loadPublicConfig() {
|
private void loadPublicConfig() {
|
||||||
if (ObfMapping.obfuscated)
|
if (ObfMapping.obfuscated) return;
|
||||||
return;
|
|
||||||
|
|
||||||
makeAllPublic = CodeChickenCoreModContainer.config.getTag("dev.runtimePublic")
|
makeAllPublic = CodeChickenCoreModContainer.config.getTag("dev.runtimePublic").setComment(
|
||||||
.setComment("Enabling this setting will make all minecraft classes public at runtime in MCP just as they are in modloader." +
|
"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." +
|
+ "\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.")
|
+ "\nSuch mods are doing the wrong thing and should be fixed.")
|
||||||
.getBooleanValue(false);
|
.getBooleanValue(false);
|
||||||
|
|
||||||
if (!makeAllPublic)
|
if (!makeAllPublic) return;
|
||||||
return;
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
f_classNameBiMap = FMLDeobfuscatingRemapper.class.getDeclaredField("classNameBiMap");
|
f_classNameBiMap = FMLDeobfuscatingRemapper.class.getDeclaredField("classNameBiMap");
|
||||||
@@ -45,11 +42,9 @@ public class CodeChickenAccessTransformer extends AccessTransformer
|
|||||||
@Override
|
@Override
|
||||||
public byte[] transform(String name, String transformedName, byte[] bytes) {
|
public byte[] transform(String name, String transformedName, byte[] bytes) {
|
||||||
boolean setPublic = makeAllPublic && name.startsWith("net.minecraft.");
|
boolean setPublic = makeAllPublic && name.startsWith("net.minecraft.");
|
||||||
if (setPublic)
|
if (setPublic) setClassMap(name);
|
||||||
setClassMap(name);
|
|
||||||
bytes = super.transform(name, transformedName, bytes);
|
bytes = super.transform(name, transformedName, bytes);
|
||||||
if (setPublic)
|
if (setPublic) restoreClassMap();
|
||||||
restoreClassMap();
|
|
||||||
return bytes;
|
return bytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,31 +4,35 @@ import java.io.File;
|
|||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import net.minecraftforge.common.MinecraftForge;
|
||||||
|
|
||||||
|
import com.google.common.eventbus.EventBus;
|
||||||
|
import com.google.common.eventbus.Subscribe;
|
||||||
|
|
||||||
import codechicken.core.CCUpdateChecker;
|
import codechicken.core.CCUpdateChecker;
|
||||||
import codechicken.core.ClientUtils;
|
import codechicken.core.ClientUtils;
|
||||||
import codechicken.core.featurehack.LiquidTextures;
|
import codechicken.core.featurehack.LiquidTextures;
|
||||||
import codechicken.core.internal.CCCEventHandler;
|
import codechicken.core.internal.CCCEventHandler;
|
||||||
import codechicken.core.launch.CodeChickenCorePlugin;
|
import codechicken.core.launch.CodeChickenCorePlugin;
|
||||||
import codechicken.lib.config.ConfigFile;
|
import codechicken.lib.config.ConfigFile;
|
||||||
|
import cpw.mods.fml.common.DummyModContainer;
|
||||||
import com.google.common.eventbus.EventBus;
|
import cpw.mods.fml.common.FMLCommonHandler;
|
||||||
import com.google.common.eventbus.Subscribe;
|
import cpw.mods.fml.common.LoadController;
|
||||||
|
import cpw.mods.fml.common.ModMetadata;
|
||||||
import cpw.mods.fml.common.*;
|
|
||||||
import cpw.mods.fml.common.event.FMLInitializationEvent;
|
import cpw.mods.fml.common.event.FMLInitializationEvent;
|
||||||
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
|
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
|
||||||
import cpw.mods.fml.common.versioning.ArtifactVersion;
|
import cpw.mods.fml.common.versioning.ArtifactVersion;
|
||||||
import cpw.mods.fml.common.versioning.VersionParser;
|
import cpw.mods.fml.common.versioning.VersionParser;
|
||||||
import cpw.mods.fml.common.versioning.VersionRange;
|
import cpw.mods.fml.common.versioning.VersionRange;
|
||||||
import net.minecraftforge.common.MinecraftForge;
|
|
||||||
|
|
||||||
public class CodeChickenCoreModContainer extends DummyModContainer
|
public class CodeChickenCoreModContainer extends DummyModContainer {
|
||||||
{
|
|
||||||
public static ConfigFile config;
|
public static ConfigFile config;
|
||||||
|
|
||||||
public static void loadConfig() {
|
public static void loadConfig() {
|
||||||
if(config == null)
|
if (config == null)
|
||||||
config = new ConfigFile(new File(CodeChickenCorePlugin.minecraftDir, "config/CodeChickenCore.cfg")).setComment("CodeChickenCore configuration file.");
|
config = new ConfigFile(new File(CodeChickenCorePlugin.minecraftDir, "config/CodeChickenCore.cfg"))
|
||||||
|
.setComment("CodeChickenCore configuration file.");
|
||||||
}
|
}
|
||||||
|
|
||||||
public CodeChickenCoreModContainer() {
|
public CodeChickenCoreModContainer() {
|
||||||
@@ -37,16 +41,16 @@ public class CodeChickenCoreModContainer extends DummyModContainer
|
|||||||
|
|
||||||
private static ModMetadata getModMetadata() {
|
private static ModMetadata getModMetadata() {
|
||||||
final ModMetadata modMetadata = new ModMetadata();
|
final ModMetadata modMetadata = new ModMetadata();
|
||||||
modMetadata.name = "GRADLETOKEN_MODNAME";
|
modMetadata.name = "CodeChicken Core";
|
||||||
modMetadata.modId = "GRADLETOKEN_MODID";
|
modMetadata.modId = "CodeChickenCore";
|
||||||
modMetadata.version = "GRADLETOKEN_VERSION";
|
modMetadata.version = Tags.VERSION;
|
||||||
return modMetadata;
|
return modMetadata;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<ArtifactVersion> getDependants() {
|
public List<ArtifactVersion> getDependants() {
|
||||||
LinkedList<ArtifactVersion> deps = new LinkedList<ArtifactVersion>();
|
LinkedList<ArtifactVersion> deps = new LinkedList<ArtifactVersion>();
|
||||||
if(!getVersion().contains("$")) {
|
if (!getVersion().contains("$")) {
|
||||||
deps.add(VersionParser.parseVersionReference("Forge@[10.13.3,)"));
|
deps.add(VersionParser.parseVersionReference("Forge@[10.13.3,)"));
|
||||||
deps.add(VersionParser.parseVersionReference("NotEnoughItems@[1.0.5,)"));
|
deps.add(VersionParser.parseVersionReference("NotEnoughItems@[1.0.5,)"));
|
||||||
deps.add(VersionParser.parseVersionReference("EnderStorage@[1.4.7,)"));
|
deps.add(VersionParser.parseVersionReference("EnderStorage@[1.4.7,)"));
|
||||||
@@ -65,15 +69,13 @@ public class CodeChickenCoreModContainer extends DummyModContainer
|
|||||||
|
|
||||||
@Subscribe
|
@Subscribe
|
||||||
public void preInit(FMLPreInitializationEvent event) {
|
public void preInit(FMLPreInitializationEvent event) {
|
||||||
if (event.getSide().isClient())
|
if (event.getSide().isClient()) LiquidTextures.init();
|
||||||
LiquidTextures.init();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Subscribe
|
@Subscribe
|
||||||
public void init(FMLInitializationEvent event) {
|
public void init(FMLInitializationEvent event) {
|
||||||
if (event.getSide().isClient()) {
|
if (event.getSide().isClient()) {
|
||||||
if (config.getTag("checkUpdates").getBooleanValue(true))
|
if (config.getTag("checkUpdates").getBooleanValue(true)) CCUpdateChecker.updateCheck(getModId());
|
||||||
CCUpdateChecker.updateCheck(getModId());
|
|
||||||
|
|
||||||
ClientUtils.enhanceSupportersList("CodeChickenCore");
|
ClientUtils.enhanceSupportersList("CodeChickenCore");
|
||||||
|
|
||||||
|
|||||||
@@ -6,6 +6,9 @@ import java.util.HashMap;
|
|||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.LinkedList;
|
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.ClassNode;
|
||||||
import org.objectweb.asm.tree.MethodNode;
|
import org.objectweb.asm.tree.MethodNode;
|
||||||
|
|
||||||
@@ -13,82 +16,78 @@ import codechicken.lib.asm.ASMHelper;
|
|||||||
import codechicken.lib.asm.ClassHeirachyManager;
|
import codechicken.lib.asm.ClassHeirachyManager;
|
||||||
import codechicken.lib.asm.ObfMapping;
|
import codechicken.lib.asm.ObfMapping;
|
||||||
|
|
||||||
import net.minecraft.launchwrapper.IClassTransformer;
|
public class DefaultImplementationTransformer implements IClassTransformer {
|
||||||
import net.minecraft.launchwrapper.LaunchClassLoader;
|
|
||||||
|
private static LaunchClassLoader cl = (LaunchClassLoader) ClassHeirachyManager.class.getClassLoader();
|
||||||
|
|
||||||
public class DefaultImplementationTransformer implements IClassTransformer
|
|
||||||
{
|
|
||||||
private static LaunchClassLoader cl = (LaunchClassLoader)ClassHeirachyManager.class.getClassLoader();
|
|
||||||
private static ClassNode getClassNode(String name) {
|
private static ClassNode getClassNode(String name) {
|
||||||
try {
|
try {
|
||||||
return ASMHelper.createClassNode(cl.getClassBytes(name.replace('/', '.')));
|
return ASMHelper.createClassNode(cl.getClassBytes(name.replace('/', '.')));
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new RuntimeException(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) {
|
static class InterfaceImpl {
|
||||||
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;
|
public final String iname;
|
||||||
for(MethodNode impl : impls) {
|
public ArrayList<MethodNode> impls = new ArrayList<MethodNode>();
|
||||||
if(names.contains(impl.name+impl.desc))
|
|
||||||
continue;
|
public InterfaceImpl(String iname, String cname) {
|
||||||
|
this.iname = iname;
|
||||||
MethodNode copy = new MethodNode(impl.access, impl.name, impl.desc,
|
HashSet<String> names = new HashSet<String>();
|
||||||
impl.signature, impl.exceptions == null ? null : impl.exceptions.toArray(new String[0]));
|
ClassNode inode = getClassNode(iname);
|
||||||
ASMHelper.copy(impl, copy);
|
for (MethodNode method : inode.methods) names.add(method.name + method.desc);
|
||||||
cnode.methods.add(impl);
|
|
||||||
changed = true;
|
ClassNode cnode = getClassNode(cname);
|
||||||
}
|
for (MethodNode method : cnode.methods) if (names.contains(method.name + method.desc)) {
|
||||||
return changed;
|
impls.add(method);
|
||||||
}
|
method.desc = new ObfMapping(cnode.name, method.name, method.desc).toRuntime().s_desc;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
private static HashMap<String, InterfaceImpl> impls = new HashMap<String, InterfaceImpl>();
|
|
||||||
|
public boolean patch(ClassNode cnode) {
|
||||||
public static void registerDefaultImpl(String iname, String cname) {
|
LinkedList<String> names = new LinkedList<String>();
|
||||||
impls.put(iname.replace('.', '/'), new InterfaceImpl(iname, cname));
|
for (MethodNode method : cnode.methods) {
|
||||||
}
|
ObfMapping m = new ObfMapping(cnode.name, method.name, method.desc).toRuntime();
|
||||||
|
names.add(m.s_name + m.s_desc);
|
||||||
@Override
|
}
|
||||||
public byte[] transform(String name, String transformedName, byte[] bytes) {
|
|
||||||
if(transformedName.startsWith("net.minecraft") || impls.isEmpty())
|
boolean changed = false;
|
||||||
return bytes;
|
for (MethodNode impl : impls) {
|
||||||
|
if (names.contains(impl.name + impl.desc)) continue;
|
||||||
ClassNode cnode = ASMHelper.createClassNode(bytes);
|
|
||||||
boolean changed = false;
|
MethodNode copy = new MethodNode(
|
||||||
for(String iname : cnode.interfaces) {
|
impl.access,
|
||||||
InterfaceImpl impl = impls.get(iname);
|
impl.name,
|
||||||
if(impl != null)
|
impl.desc,
|
||||||
changed |= impl.patch(cnode);
|
impl.signature,
|
||||||
}
|
impl.exceptions == null ? null : impl.exceptions.toArray(new String[0]));
|
||||||
|
ASMHelper.copy(impl, copy);
|
||||||
return changed ? ASMHelper.createBytes(cnode, 0) : bytes;
|
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;
|
package codechicken.core.asm;
|
||||||
|
|
||||||
|
import static codechicken.core.launch.CodeChickenCorePlugin.logger;
|
||||||
|
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@@ -12,140 +14,118 @@ import java.util.Stack;
|
|||||||
import java.util.jar.JarFile;
|
import java.util.jar.JarFile;
|
||||||
import java.util.zip.ZipEntry;
|
import java.util.zip.ZipEntry;
|
||||||
|
|
||||||
|
import net.minecraft.launchwrapper.IClassTransformer;
|
||||||
import net.minecraft.launchwrapper.Launch;
|
import net.minecraft.launchwrapper.Launch;
|
||||||
|
import net.minecraft.launchwrapper.LaunchClassLoader;
|
||||||
|
|
||||||
import org.objectweb.asm.ClassReader;
|
import org.objectweb.asm.ClassReader;
|
||||||
import org.objectweb.asm.Opcodes;
|
import org.objectweb.asm.Opcodes;
|
||||||
|
|
||||||
import net.minecraft.launchwrapper.IClassTransformer;
|
public class DelegatedTransformer implements IClassTransformer {
|
||||||
import net.minecraft.launchwrapper.LaunchClassLoader;
|
|
||||||
|
|
||||||
import static codechicken.core.launch.CodeChickenCorePlugin.logger;
|
|
||||||
|
|
||||||
public class DelegatedTransformer implements IClassTransformer
|
|
||||||
{
|
|
||||||
private static ArrayList<IClassTransformer> delegatedTransformers;
|
private static ArrayList<IClassTransformer> delegatedTransformers;
|
||||||
private static Method m_defineClass;
|
private static Method m_defineClass;
|
||||||
private static Field f_cachedClasses;
|
private static Field f_cachedClasses;
|
||||||
|
|
||||||
public DelegatedTransformer()
|
public DelegatedTransformer() {
|
||||||
{
|
|
||||||
delegatedTransformers = new ArrayList<IClassTransformer>();
|
delegatedTransformers = new ArrayList<IClassTransformer>();
|
||||||
try
|
try {
|
||||||
{
|
m_defineClass = ClassLoader.class
|
||||||
m_defineClass = ClassLoader.class.getDeclaredMethod("defineClass", String.class, byte[].class, Integer.TYPE, Integer.TYPE);
|
.getDeclaredMethod("defineClass", String.class, byte[].class, Integer.TYPE, Integer.TYPE);
|
||||||
m_defineClass.setAccessible(true);
|
m_defineClass.setAccessible(true);
|
||||||
f_cachedClasses = LaunchClassLoader.class.getDeclaredField("cachedClasses");
|
f_cachedClasses = LaunchClassLoader.class.getDeclaredField("cachedClasses");
|
||||||
f_cachedClasses.setAccessible(true);
|
f_cachedClasses.setAccessible(true);
|
||||||
}
|
} catch (Exception e) {
|
||||||
catch(Exception e)
|
|
||||||
{
|
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public byte[] transform(String name, String tname, byte[] bytes)
|
public byte[] transform(String name, String tname, byte[] bytes) {
|
||||||
{
|
|
||||||
if (bytes == null) return null;
|
if (bytes == null) return null;
|
||||||
for(IClassTransformer trans : delegatedTransformers)
|
for (IClassTransformer trans : delegatedTransformers) bytes = trans.transform(name, tname, bytes);
|
||||||
bytes = trans.transform(name, tname, bytes);
|
|
||||||
return 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);
|
logger.debug("Adding CCTransformer: " + transformer);
|
||||||
try
|
try {
|
||||||
{
|
|
||||||
byte[] bytes;
|
byte[] bytes;
|
||||||
bytes = Launch.classLoader.getClassBytes(transformer);
|
bytes = Launch.classLoader.getClassBytes(transformer);
|
||||||
|
|
||||||
if(bytes == null)
|
if (bytes == null) {
|
||||||
{
|
String resourceName = transformer.replace('.', '/') + ".class";
|
||||||
String resourceName = transformer.replace('.', '/')+".class";
|
|
||||||
ZipEntry entry = jar.getEntry(resourceName);
|
ZipEntry entry = jar.getEntry(resourceName);
|
||||||
if(entry == null)
|
if (entry == null) throw new Exception(
|
||||||
throw new Exception("Failed to add transformer: "+transformer+". Entry not found in jar file "+jarFile.getName());
|
"Failed to add transformer: " + transformer
|
||||||
|
+ ". Entry not found in jar file "
|
||||||
|
+ jarFile.getName());
|
||||||
|
|
||||||
bytes = readFully(jar.getInputStream(entry));
|
bytes = readFully(jar.getInputStream(entry));
|
||||||
}
|
}
|
||||||
|
|
||||||
defineDependancies(bytes, jar, jarFile);
|
defineDependancies(bytes, jar, jarFile);
|
||||||
Class<?> clazz = defineClass(transformer, bytes);
|
Class<?> clazz = defineClass(transformer, bytes);
|
||||||
|
|
||||||
if(!IClassTransformer.class.isAssignableFrom(clazz))
|
if (!IClassTransformer.class.isAssignableFrom(clazz)) throw new Exception(
|
||||||
throw new Exception("Failed to add transformer: "+transformer+" is not an instance of IClassTransformer");
|
"Failed to add transformer: " + transformer + " is not an instance of IClassTransformer");
|
||||||
|
|
||||||
IClassTransformer classTransformer;
|
IClassTransformer classTransformer;
|
||||||
try
|
try {
|
||||||
{
|
|
||||||
classTransformer = (IClassTransformer) clazz.getDeclaredConstructor(File.class).newInstance(jarFile);
|
classTransformer = (IClassTransformer) clazz.getDeclaredConstructor(File.class).newInstance(jarFile);
|
||||||
}
|
} catch (NoSuchMethodException nsme) {
|
||||||
catch(NoSuchMethodException nsme)
|
|
||||||
{
|
|
||||||
classTransformer = (IClassTransformer) clazz.newInstance();
|
classTransformer = (IClassTransformer) clazz.newInstance();
|
||||||
}
|
}
|
||||||
delegatedTransformers.add(classTransformer);
|
delegatedTransformers.add(classTransformer);
|
||||||
}
|
} catch (Exception e) {
|
||||||
catch(Exception e)
|
|
||||||
{
|
|
||||||
e.printStackTrace();
|
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>());
|
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);
|
ClassReader reader = new ClassReader(bytes);
|
||||||
DependancyLister lister = new DependancyLister(Opcodes.ASM4);
|
DependancyLister lister = new DependancyLister(Opcodes.ASM4);
|
||||||
reader.accept(lister, 0);
|
reader.accept(lister, 0);
|
||||||
|
|
||||||
depStack.push(reader.getClassName());
|
depStack.push(reader.getClassName());
|
||||||
|
|
||||||
for(String dependancy : lister.getDependancies())
|
for (String dependancy : lister.getDependancies()) {
|
||||||
{
|
if (depStack.contains(dependancy)) continue;
|
||||||
if(depStack.contains(dependancy))
|
|
||||||
continue;
|
try {
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
Launch.classLoader.loadClass(dependancy.replace('/', '.'));
|
Launch.classLoader.loadClass(dependancy.replace('/', '.'));
|
||||||
}
|
} catch (ClassNotFoundException cnfe) {
|
||||||
catch(ClassNotFoundException cnfe)
|
ZipEntry entry = jar.getEntry(dependancy + ".class");
|
||||||
{
|
if (entry == null)
|
||||||
ZipEntry entry = jar.getEntry(dependancy+".class");
|
throw new Exception("Dependency " + dependancy + " not found in jar file " + jarFile.getName());
|
||||||
if(entry == null)
|
|
||||||
throw new Exception("Dependency "+dependancy+" not found in jar file "+jarFile.getName());
|
|
||||||
|
|
||||||
byte[] depbytes = readFully(jar.getInputStream(entry));
|
byte[] depbytes = readFully(jar.getInputStream(entry));
|
||||||
defineDependancies(depbytes, jar, jarFile, depStack);
|
defineDependancies(depbytes, jar, jarFile, depStack);
|
||||||
|
|
||||||
logger.debug("Defining dependancy: "+dependancy);
|
logger.debug("Defining dependancy: " + dependancy);
|
||||||
|
|
||||||
defineClass(dependancy.replace('/', '.'), depbytes);
|
defineClass(dependancy.replace('/', '.'), depbytes);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
depStack.pop();
|
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);
|
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;
|
return clazz;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static byte[] readFully(InputStream stream) throws IOException
|
public static byte[] readFully(InputStream stream) throws IOException {
|
||||||
{
|
|
||||||
ByteArrayOutputStream bos = new ByteArrayOutputStream(stream.available());
|
ByteArrayOutputStream bos = new ByteArrayOutputStream(stream.available());
|
||||||
int r;
|
int r;
|
||||||
while ((r = stream.read()) != -1)
|
while ((r = stream.read()) != -1) {
|
||||||
{
|
|
||||||
bos.write(r);
|
bos.write(r);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -12,84 +12,70 @@ import org.objectweb.asm.Label;
|
|||||||
import org.objectweb.asm.MethodVisitor;
|
import org.objectweb.asm.MethodVisitor;
|
||||||
import org.objectweb.asm.Opcodes;
|
import org.objectweb.asm.Opcodes;
|
||||||
|
|
||||||
public class DependancyLister extends ClassVisitor
|
public class DependancyLister extends ClassVisitor {
|
||||||
{
|
|
||||||
private static Pattern classdesc = Pattern.compile("L(.+?);");
|
private static Pattern classdesc = Pattern.compile("L(.+?);");
|
||||||
|
|
||||||
private class DependancyMethodLister extends MethodVisitor
|
private class DependancyMethodLister extends MethodVisitor {
|
||||||
{
|
|
||||||
public DependancyMethodLister(int api)
|
public DependancyMethodLister(int api) {
|
||||||
{
|
|
||||||
super(api);
|
super(api);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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);
|
dependDesc(desc);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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);
|
dependDesc(desc);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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);
|
depend(owner);
|
||||||
dependDesc(desc);
|
dependDesc(desc);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private HashSet<String> dependancies = new HashSet<String>();
|
private HashSet<String> dependancies = new HashSet<String>();
|
||||||
|
|
||||||
public DependancyLister(int api)
|
public DependancyLister(int api) {
|
||||||
{
|
|
||||||
super(api);
|
super(api);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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);
|
dependDesc(desc);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void dependDesc(String desc)
|
private void dependDesc(String desc) {
|
||||||
{
|
|
||||||
Matcher match = classdesc.matcher(desc);
|
Matcher match = classdesc.matcher(desc);
|
||||||
while(match.find())
|
while (match.find()) {
|
||||||
{
|
|
||||||
String s = match.group();
|
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);
|
dependancies.add(classname);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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);
|
dependDesc(desc);
|
||||||
return new DependancyMethodLister(Opcodes.ASM4);
|
return new DependancyMethodLister(Opcodes.ASM4);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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);
|
depend(superName);
|
||||||
if(interfaces != null)
|
if (interfaces != null) for (String interfacename : interfaces) depend(interfacename);
|
||||||
for(String interfacename : interfaces)
|
|
||||||
depend(interfacename);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<String> getDependancies()
|
public List<String> getDependancies() {
|
||||||
{
|
|
||||||
return new ArrayList<String>(dependancies);
|
return new ArrayList<String>(dependancies);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -5,10 +5,6 @@ import java.lang.annotation.Retention;
|
|||||||
import java.lang.annotation.RetentionPolicy;
|
import java.lang.annotation.RetentionPolicy;
|
||||||
import java.lang.annotation.Target;
|
import java.lang.annotation.Target;
|
||||||
|
|
||||||
|
|
||||||
@Retention(RetentionPolicy.RUNTIME)
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
@Target({ElementType.TYPE})
|
@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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -2,12 +2,17 @@ package codechicken.core.asm;
|
|||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.util.*;
|
import java.util.Collections;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.LinkedList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
|
|
||||||
import codechicken.lib.asm.ASMInit;
|
import net.minecraft.launchwrapper.IClassTransformer;
|
||||||
import cpw.mods.fml.relauncher.IFMLLoadingPlugin;
|
|
||||||
import net.minecraft.launchwrapper.Launch;
|
import net.minecraft.launchwrapper.Launch;
|
||||||
|
import net.minecraft.launchwrapper.LaunchClassLoader;
|
||||||
|
|
||||||
import org.objectweb.asm.ClassReader;
|
import org.objectweb.asm.ClassReader;
|
||||||
import org.objectweb.asm.ClassWriter;
|
import org.objectweb.asm.ClassWriter;
|
||||||
import org.objectweb.asm.Opcodes;
|
import org.objectweb.asm.Opcodes;
|
||||||
@@ -19,24 +24,23 @@ import com.google.common.collect.HashMultimap;
|
|||||||
import com.google.common.collect.Multimap;
|
import com.google.common.collect.Multimap;
|
||||||
|
|
||||||
import codechicken.lib.asm.ASMHelper;
|
import codechicken.lib.asm.ASMHelper;
|
||||||
|
import codechicken.lib.asm.ASMInit;
|
||||||
import codechicken.lib.asm.CC_ClassWriter;
|
import codechicken.lib.asm.CC_ClassWriter;
|
||||||
import codechicken.lib.asm.ObfMapping;
|
import codechicken.lib.asm.ObfMapping;
|
||||||
import codechicken.obfuscator.IHeirachyEvaluator;
|
import codechicken.obfuscator.IHeirachyEvaluator;
|
||||||
import codechicken.obfuscator.ObfuscationRun;
|
|
||||||
import codechicken.obfuscator.ObfuscationMap.ObfuscationEntry;
|
import codechicken.obfuscator.ObfuscationMap.ObfuscationEntry;
|
||||||
|
import codechicken.obfuscator.ObfuscationRun;
|
||||||
import cpw.mods.fml.common.asm.transformers.AccessTransformer;
|
import cpw.mods.fml.common.asm.transformers.AccessTransformer;
|
||||||
|
import cpw.mods.fml.relauncher.IFMLLoadingPlugin;
|
||||||
|
|
||||||
import net.minecraft.launchwrapper.IClassTransformer;
|
public class MCPDeobfuscationTransformer implements IClassTransformer, Opcodes, IHeirachyEvaluator {
|
||||||
import net.minecraft.launchwrapper.LaunchClassLoader;
|
|
||||||
|
|
||||||
public class MCPDeobfuscationTransformer implements IClassTransformer, Opcodes, IHeirachyEvaluator
|
|
||||||
{
|
|
||||||
static {
|
static {
|
||||||
ASMInit.init();
|
ASMInit.init();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class LoadPlugin implements IFMLLoadingPlugin
|
public static class LoadPlugin implements IFMLLoadingPlugin {
|
||||||
{
|
|
||||||
@Override
|
@Override
|
||||||
public String[] getASMTransformerClass() {
|
public String[] getASMTransformerClass() {
|
||||||
return new String[0];
|
return new String[0];
|
||||||
@@ -78,7 +82,8 @@ public class MCPDeobfuscationTransformer implements IClassTransformer, Opcodes,
|
|||||||
try {
|
try {
|
||||||
f_transformers = LaunchClassLoader.class.getDeclaredField("transformers");
|
f_transformers = LaunchClassLoader.class.getDeclaredField("transformers");
|
||||||
f_modifiers = AccessTransformer.class.getDeclaredField("modifiers");
|
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_name = c_Modifier.getDeclaredField("name");
|
||||||
f_Modifier_desc = c_Modifier.getDeclaredField("desc");
|
f_Modifier_desc = c_Modifier.getDeclaredField("desc");
|
||||||
|
|
||||||
@@ -118,7 +123,9 @@ public class MCPDeobfuscationTransformer implements IClassTransformer, Opcodes,
|
|||||||
if (CodeChickenCoreModContainer.config.getTag("dev.deobfuscate")
|
if (CodeChickenCoreModContainer.config.getTag("dev.deobfuscate")
|
||||||
.setComment("set to true to completely deobfuscate mcp names")
|
.setComment("set to true to completely deobfuscate mcp names")
|
||||||
.getBooleanValue(!ObfMapping.obfuscated)) {
|
.getBooleanValue(!ObfMapping.obfuscated)) {
|
||||||
run = new ObfuscationRun(false, ObfMapping.MCPRemapper.getConfFiles(),
|
run = new ObfuscationRun(
|
||||||
|
false,
|
||||||
|
ObfMapping.MCPRemapper.getConfFiles(),
|
||||||
ObfuscationRun.fillDefaults(new HashMap<String, String>()));
|
ObfuscationRun.fillDefaults(new HashMap<String, String>()));
|
||||||
run.obf.setHeirachyEvaluator(instance);
|
run.obf.setHeirachyEvaluator(instance);
|
||||||
run.setQuiet().parseMappings();
|
run.setQuiet().parseMappings();
|
||||||
@@ -129,7 +136,7 @@ public class MCPDeobfuscationTransformer implements IClassTransformer, Opcodes,
|
|||||||
run.setSeargeConstants();
|
run.setSeargeConstants();
|
||||||
getTransformers().add(instance);
|
getTransformers().add(instance);
|
||||||
} else {
|
} else {
|
||||||
getTransformers().add(0, instance);//insert transformer as first.
|
getTransformers().add(0, instance); // insert transformer as first.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -141,8 +148,7 @@ public class MCPDeobfuscationTransformer implements IClassTransformer, Opcodes,
|
|||||||
activated = true;
|
activated = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!activated || bytes == null)
|
if (!activated || bytes == null) return bytes;
|
||||||
return bytes;
|
|
||||||
|
|
||||||
ClassNode cnode = ASMHelper.createClassNode(bytes, ClassReader.EXPAND_FRAMES);
|
ClassNode cnode = ASMHelper.createClassNode(bytes, ClassReader.EXPAND_FRAMES);
|
||||||
ClassWriter cw = new CC_ClassWriter(0, true);
|
ClassWriter cw = new CC_ClassWriter(0, true);
|
||||||
@@ -153,21 +159,24 @@ public class MCPDeobfuscationTransformer implements IClassTransformer, Opcodes,
|
|||||||
private byte[] injectCallback(byte[] bytes) {
|
private byte[] injectCallback(byte[] bytes) {
|
||||||
ClassNode cnode = ASMHelper.createClassNode(bytes);
|
ClassNode cnode = ASMHelper.createClassNode(bytes);
|
||||||
MethodNode mnode = ASMHelper.findMethod(new ObfMapping(cnode.name, "<clinit>", "()V"), cnode);
|
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);
|
return ASMHelper.createBytes(cnode, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void loadCallback() {
|
public static void loadCallback() {
|
||||||
if (ObfMapping.obfuscated) {
|
if (ObfMapping.obfuscated) {
|
||||||
//move ourselves to the end
|
// move ourselves to the end
|
||||||
List<IClassTransformer> transformers = getTransformers();
|
List<IClassTransformer> transformers = getTransformers();
|
||||||
transformers.remove(instance);
|
transformers.remove(instance);
|
||||||
transformers.add(instance);
|
transformers.add(instance);
|
||||||
} else {
|
} else {
|
||||||
//remap access transformers
|
// remap access transformers
|
||||||
for (IClassTransformer t : getTransformers())
|
for (IClassTransformer t : getTransformers()) if (t instanceof AccessTransformer) remapAccessTransformer(t);
|
||||||
if (t instanceof AccessTransformer)
|
|
||||||
remapAccessTransformer(t);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -207,10 +216,9 @@ public class MCPDeobfuscationTransformer implements IClassTransformer, Opcodes,
|
|||||||
name = name.replace('/', '.');
|
name = name.replace('/', '.');
|
||||||
try {
|
try {
|
||||||
byte[] bytes = Launch.classLoader.getClassBytes(name);
|
byte[] bytes = Launch.classLoader.getClassBytes(name);
|
||||||
if (bytes != null)
|
if (bytes != null) return ObfuscationRun.getParents(ASMHelper.createClassNode(bytes));
|
||||||
return ObfuscationRun.getParents(ASMHelper.createClassNode(bytes));
|
|
||||||
} catch (IOException ignored) {}
|
} catch (IOException ignored) {}
|
||||||
//clear the miss cache because the library containing it might be loaded later
|
// clear the miss cache because the library containing it might be loaded later
|
||||||
Launch.classLoader.clearNegativeEntries(Collections.singleton(name));
|
Launch.classLoader.clearNegativeEntries(Collections.singleton(name));
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -218,19 +226,15 @@ public class MCPDeobfuscationTransformer implements IClassTransformer, Opcodes,
|
|||||||
@Override
|
@Override
|
||||||
public boolean isLibClass(ObfuscationEntry desc) {
|
public boolean isLibClass(ObfuscationEntry desc) {
|
||||||
String name = desc.srg.s_owner;
|
String name = desc.srg.s_owner;
|
||||||
for (String p : excludedPackages)
|
for (String p : excludedPackages) if (name.startsWith(p)) return true;
|
||||||
if (name.startsWith(p))
|
|
||||||
return true;
|
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String unmap(String name) {
|
public static String unmap(String name) {
|
||||||
if (run == null)
|
if (run == null) return null;
|
||||||
return null;
|
|
||||||
ObfuscationEntry e = run.obf.lookupMcpClass(name);
|
ObfuscationEntry e = run.obf.lookupMcpClass(name);
|
||||||
if (e == null)
|
if (e == null) return null;
|
||||||
return null;
|
|
||||||
return e.obf.s_owner;
|
return e.obf.s_owner;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,22 +1,22 @@
|
|||||||
package codechicken.core.asm;
|
package codechicken.core.asm;
|
||||||
|
|
||||||
|
import static org.objectweb.asm.Opcodes.ASM4;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.PrintWriter;
|
import java.io.PrintWriter;
|
||||||
|
|
||||||
import net.minecraft.launchwrapper.Launch;
|
import net.minecraft.launchwrapper.Launch;
|
||||||
|
|
||||||
import org.objectweb.asm.ClassReader;
|
import org.objectweb.asm.ClassReader;
|
||||||
import org.objectweb.asm.ClassVisitor;
|
import org.objectweb.asm.ClassVisitor;
|
||||||
import org.objectweb.asm.MethodVisitor;
|
import org.objectweb.asm.MethodVisitor;
|
||||||
import org.objectweb.asm.util.Printer;
|
import org.objectweb.asm.util.Printer;
|
||||||
import org.objectweb.asm.util.TraceMethodVisitor;
|
import org.objectweb.asm.util.TraceMethodVisitor;
|
||||||
|
|
||||||
import codechicken.core.launch.CodeChickenCorePlugin;
|
|
||||||
import codechicken.lib.asm.ObfMapping;
|
import codechicken.lib.asm.ObfMapping;
|
||||||
|
|
||||||
import static org.objectweb.asm.Opcodes.*;
|
public class MethodASMifier extends ClassVisitor {
|
||||||
|
|
||||||
public class MethodASMifier extends ClassVisitor
|
|
||||||
{
|
|
||||||
PrintWriter printWriter;
|
PrintWriter printWriter;
|
||||||
ObfMapping method;
|
ObfMapping method;
|
||||||
Printer asmifier;
|
Printer asmifier;
|
||||||
@@ -55,10 +55,8 @@ public class MethodASMifier extends ClassVisitor
|
|||||||
|
|
||||||
public static void printMethod(ObfMapping method, byte[] bytes, Printer printer, File toFile) {
|
public static void printMethod(ObfMapping method, byte[] bytes, Printer printer, File toFile) {
|
||||||
try {
|
try {
|
||||||
if (!toFile.getParentFile().exists())
|
if (!toFile.getParentFile().exists()) toFile.getParentFile().mkdirs();
|
||||||
toFile.getParentFile().mkdirs();
|
if (!toFile.exists()) toFile.createNewFile();
|
||||||
if (!toFile.exists())
|
|
||||||
toFile.createNewFile();
|
|
||||||
|
|
||||||
PrintWriter printWriter = new PrintWriter(toFile);
|
PrintWriter printWriter = new PrintWriter(toFile);
|
||||||
|
|
||||||
|
|||||||
@@ -1,23 +1,28 @@
|
|||||||
package codechicken.core.asm;
|
package codechicken.core.asm;
|
||||||
|
|
||||||
import codechicken.lib.asm.*;
|
import static codechicken.lib.asm.InsnComparator.findOnce;
|
||||||
import codechicken.lib.asm.ModularASMTransformer.MethodReplacer;
|
|
||||||
import codechicken.lib.asm.ModularASMTransformer.MethodTransformer;
|
import java.util.Map;
|
||||||
import codechicken.lib.asm.ModularASMTransformer.MethodWriter;
|
|
||||||
|
import net.minecraft.launchwrapper.IClassTransformer;
|
||||||
|
|
||||||
import org.objectweb.asm.Opcodes;
|
import org.objectweb.asm.Opcodes;
|
||||||
import org.objectweb.asm.tree.JumpInsnNode;
|
import org.objectweb.asm.tree.JumpInsnNode;
|
||||||
import org.objectweb.asm.tree.LabelNode;
|
import org.objectweb.asm.tree.LabelNode;
|
||||||
import org.objectweb.asm.tree.MethodNode;
|
import org.objectweb.asm.tree.MethodNode;
|
||||||
|
|
||||||
|
import codechicken.lib.asm.ASMBlock;
|
||||||
|
import codechicken.lib.asm.ASMInit;
|
||||||
|
import codechicken.lib.asm.ASMReader;
|
||||||
|
import codechicken.lib.asm.ModularASMTransformer;
|
||||||
|
import codechicken.lib.asm.ModularASMTransformer.MethodReplacer;
|
||||||
|
import codechicken.lib.asm.ModularASMTransformer.MethodTransformer;
|
||||||
|
import codechicken.lib.asm.ModularASMTransformer.MethodWriter;
|
||||||
|
import codechicken.lib.asm.ObfMapping;
|
||||||
import codechicken.lib.config.ConfigTag;
|
import codechicken.lib.config.ConfigTag;
|
||||||
import net.minecraft.launchwrapper.IClassTransformer;
|
|
||||||
|
|
||||||
import java.util.Map;
|
public class TweakTransformer implements IClassTransformer, Opcodes {
|
||||||
|
|
||||||
import static codechicken.lib.asm.InsnComparator.*;
|
|
||||||
|
|
||||||
public class TweakTransformer implements IClassTransformer, Opcodes
|
|
||||||
{
|
|
||||||
static {
|
static {
|
||||||
ASMInit.init();
|
ASMInit.init();
|
||||||
}
|
}
|
||||||
@@ -32,49 +37,68 @@ public class TweakTransformer implements IClassTransformer, Opcodes
|
|||||||
.setComment("Various tweaks that can be applied to game mechanics.").useBraces();
|
.setComment("Various tweaks that can be applied to game mechanics.").useBraces();
|
||||||
tweaks.removeTag("persistantLava");
|
tweaks.removeTag("persistantLava");
|
||||||
|
|
||||||
if (tweaks.getTag("environmentallyFriendlyCreepers")
|
if (tweaks.getTag("environmentallyFriendlyCreepers").setComment(
|
||||||
.setComment("If set to true, creepers will not destroy landscape. (A version of mobGriefing setting just for creepers)")
|
"If set to true, creepers will not destroy landscape. (A version of mobGriefing setting just for creepers)")
|
||||||
.getBooleanValue(false)) {
|
.getBooleanValue(false)) {
|
||||||
transformer.add(new MethodReplacer(new ObfMapping("net/minecraft/entity/monster/EntityCreeper", "func_146077_cc", "()V"),
|
transformer.add(
|
||||||
blocks.get("d_environmentallyFriendlyCreepers"), blocks.get("environmentallyFriendlyCreepers")));
|
new MethodReplacer(
|
||||||
|
new ObfMapping("net/minecraft/entity/monster/EntityCreeper", "func_146077_cc", "()V"),
|
||||||
|
blocks.get("d_environmentallyFriendlyCreepers"),
|
||||||
|
blocks.get("environmentallyFriendlyCreepers")));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!tweaks.getTag("softLeafReplace")
|
if (!tweaks.getTag("softLeafReplace").setComment("If set to false, leaves will only replace air when growing")
|
||||||
.setComment("If set to false, leaves will only replace air when growing")
|
|
||||||
.getBooleanValue(false)) {
|
.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")
|
if (tweaks.getTag("doFireTickOut").setComment(
|
||||||
.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")
|
"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)) {
|
.getBooleanValue(true)) {
|
||||||
transformer.add(new MethodTransformer(new ObfMapping("net/minecraft/block/BlockFire", "func_149674_a", "(Lnet/minecraft/world/World;IIILjava/util/Random;)V"))
|
transformer.add(
|
||||||
{
|
new MethodTransformer(
|
||||||
@Override
|
new ObfMapping(
|
||||||
public void transform(MethodNode mv) {
|
"net/minecraft/block/BlockFire",
|
||||||
ASMBlock needle = blocks.get("n_doFireTick");
|
"func_149674_a",
|
||||||
ASMBlock inject = blocks.get("doFireTick");
|
"(Lnet/minecraft/world/World;IIILjava/util/Random;)V")) {
|
||||||
|
|
||||||
ASMBlock key = needle.applyLabels(findOnce(mv.instructions, needle.list));
|
@Override
|
||||||
LabelNode jlabel = key.get("LRET");
|
public void transform(MethodNode mv) {
|
||||||
mv.instructions.insertBefore(jlabel, new JumpInsnNode(GOTO, inject.get("LSKIP")));
|
ASMBlock needle = blocks.get("n_doFireTick");
|
||||||
mv.instructions.insert(jlabel, inject.list.list);
|
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);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tweaks.getTag("finiteWater")
|
if (tweaks.getTag("finiteWater")
|
||||||
.setComment("If set to true two adjacent water source blocks will not generate a third.")
|
.setComment("If set to true two adjacent water source blocks will not generate a third.")
|
||||||
.getBooleanValue(false)) {
|
.getBooleanValue(false)) {
|
||||||
transformer.add(new MethodTransformer(new ObfMapping("net/minecraft/block/BlockDynamicLiquid", "func_149674_a", "(Lnet/minecraft/world/World;IIILjava/util/Random;)V"))
|
transformer.add(
|
||||||
{
|
new MethodTransformer(
|
||||||
@Override
|
new ObfMapping(
|
||||||
public void transform(MethodNode mv) {
|
"net/minecraft/block/BlockDynamicLiquid",
|
||||||
ASMBlock needle = blocks.get("finiteWater");
|
"func_149674_a",
|
||||||
ASMBlock key = needle.applyLabels(findOnce(mv.instructions, needle.list));
|
"(Lnet/minecraft/world/World;IIILjava/util/Random;)V")) {
|
||||||
mv.instructions.insertBefore(key.list.getFirst(), new JumpInsnNode(GOTO, key.get("LEND")));
|
|
||||||
}
|
@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")));
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,24 +2,25 @@ package codechicken.core.commands;
|
|||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import codechicken.core.ServerUtils;
|
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.server.MinecraftServer;
|
||||||
import net.minecraft.util.ChatComponentText;
|
import net.minecraft.util.ChatComponentText;
|
||||||
import net.minecraft.util.ChatComponentTranslation;
|
import net.minecraft.util.ChatComponentTranslation;
|
||||||
import net.minecraft.util.ChunkCoordinates;
|
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.util.IChatComponent;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
import net.minecraft.world.WorldServer;
|
import net.minecraft.world.WorldServer;
|
||||||
import net.minecraftforge.common.DimensionManager;
|
import net.minecraftforge.common.DimensionManager;
|
||||||
|
|
||||||
public abstract class CoreCommand implements ICommand
|
import codechicken.core.ServerUtils;
|
||||||
{
|
|
||||||
public class WCommandSender implements ICommandSender
|
public abstract class CoreCommand implements ICommand {
|
||||||
{
|
|
||||||
|
public class WCommandSender implements ICommandSender {
|
||||||
|
|
||||||
public ICommandSender wrapped;
|
public ICommandSender wrapped;
|
||||||
|
|
||||||
public WCommandSender(ICommandSender sender) {
|
public WCommandSender(ICommandSender sender) {
|
||||||
@@ -78,15 +79,13 @@ public abstract class CoreCommand implements ICommand
|
|||||||
public void processCommand(ICommandSender listener, String[] args) {
|
public void processCommand(ICommandSender listener, String[] args) {
|
||||||
WCommandSender wsender = new WCommandSender(listener);
|
WCommandSender wsender = new WCommandSender(listener);
|
||||||
|
|
||||||
if (args.length < minimumParameters() ||
|
if (args.length < minimumParameters() || args.length == 1 && args[0].equals("help")) {
|
||||||
args.length == 1 && args[0].equals("help")) {
|
|
||||||
printHelp(wsender);
|
printHelp(wsender);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
String command = getCommandName();
|
String command = getCommandName();
|
||||||
for (String arg : args)
|
for (String arg : args) command += " " + arg;
|
||||||
command += " " + arg;
|
|
||||||
|
|
||||||
handleCommand(command, wsender.getCommandSenderName(), args, wsender);
|
handleCommand(command, wsender.getCommandSenderName(), args, wsender);
|
||||||
}
|
}
|
||||||
@@ -130,16 +129,13 @@ public abstract class CoreCommand implements ICommand
|
|||||||
@Override
|
@Override
|
||||||
public boolean canCommandSenderUseCommand(ICommandSender var1) {
|
public boolean canCommandSenderUseCommand(ICommandSender var1) {
|
||||||
if (OPOnly()) {
|
if (OPOnly()) {
|
||||||
if (var1 instanceof EntityPlayer)
|
if (var1 instanceof EntityPlayer) return MinecraftServer.getServer().getConfigurationManager()
|
||||||
return MinecraftServer.getServer().getConfigurationManager().func_152596_g(((EntityPlayer) var1).getGameProfile());
|
.func_152596_g(((EntityPlayer) var1).getGameProfile());
|
||||||
else if (var1 instanceof MinecraftServer)
|
else if (var1 instanceof MinecraftServer) return true;
|
||||||
return true;
|
else return false;
|
||||||
else
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public abstract int minimumParameters();
|
public abstract int minimumParameters();
|
||||||
}
|
}
|
||||||
@@ -1,60 +1,54 @@
|
|||||||
package codechicken.core.commands;
|
package codechicken.core.commands;
|
||||||
|
|
||||||
import net.minecraft.util.MovingObjectPosition.MovingObjectType;
|
import net.minecraft.command.ICommandSender;
|
||||||
import net.minecraft.world.ChunkPosition;
|
|
||||||
import net.minecraft.entity.Entity;
|
import net.minecraft.entity.Entity;
|
||||||
import net.minecraft.entity.player.EntityPlayer;
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
import net.minecraft.entity.player.EntityPlayerMP;
|
import net.minecraft.entity.player.EntityPlayerMP;
|
||||||
import net.minecraft.command.ICommandSender;
|
|
||||||
import net.minecraft.util.MovingObjectPosition;
|
import net.minecraft.util.MovingObjectPosition;
|
||||||
|
import net.minecraft.util.MovingObjectPosition.MovingObjectType;
|
||||||
import net.minecraft.util.Vec3;
|
import net.minecraft.util.Vec3;
|
||||||
|
import net.minecraft.world.ChunkPosition;
|
||||||
import net.minecraft.world.WorldServer;
|
import net.minecraft.world.WorldServer;
|
||||||
|
|
||||||
public abstract class PlayerCommand extends CoreCommand
|
public abstract class PlayerCommand extends CoreCommand {
|
||||||
{
|
|
||||||
@Override
|
@Override
|
||||||
public boolean canCommandSenderUseCommand(ICommandSender var1)
|
public boolean canCommandSenderUseCommand(ICommandSender var1) {
|
||||||
{
|
if (!super.canCommandSenderUseCommand(var1)) return false;
|
||||||
if(!super.canCommandSenderUseCommand(var1))
|
|
||||||
return false;
|
|
||||||
return var1 instanceof EntityPlayer;
|
return var1 instanceof EntityPlayer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handleCommand(String command, String playername, String[] args, WCommandSender listener)
|
public void handleCommand(String command, String playername, String[] args, WCommandSender listener) {
|
||||||
{
|
EntityPlayerMP player = (EntityPlayerMP) listener.wrapped;
|
||||||
EntityPlayerMP player = (EntityPlayerMP)listener.wrapped;
|
|
||||||
handleCommand(getWorld(player), player, args);
|
handleCommand(getWorld(player), player, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract void handleCommand(WorldServer world, EntityPlayerMP player, String[] args);
|
public abstract void handleCommand(WorldServer world, EntityPlayerMP player, String[] args);
|
||||||
|
|
||||||
public ChunkPosition getPlayerLookingAtBlock(EntityPlayerMP player, float reach)
|
public ChunkPosition getPlayerLookingAtBlock(EntityPlayerMP player, float reach) {
|
||||||
{
|
Vec3 vec3d = Vec3
|
||||||
Vec3 vec3d = Vec3.createVectorHelper(player.posX, (player.posY + 1.6200000000000001D) - player.yOffset, player.posZ);
|
.createVectorHelper(player.posX, (player.posY + 1.6200000000000001D) - player.yOffset, player.posZ);
|
||||||
Vec3 vec3d1 = player.getLook(1.0F);
|
Vec3 vec3d1 = player.getLook(1.0F);
|
||||||
Vec3 vec3d2 = vec3d.addVector(vec3d1.xCoord * reach, vec3d1.yCoord * reach, vec3d1.zCoord * reach);
|
Vec3 vec3d2 = vec3d.addVector(vec3d1.xCoord * reach, vec3d1.yCoord * reach, vec3d1.zCoord * reach);
|
||||||
MovingObjectPosition hit = player.worldObj.rayTraceBlocks(vec3d, vec3d2);
|
MovingObjectPosition hit = player.worldObj.rayTraceBlocks(vec3d, vec3d2);
|
||||||
if(hit == null || hit.typeOfHit != MovingObjectType.BLOCK)
|
if (hit == null || hit.typeOfHit != MovingObjectType.BLOCK) {
|
||||||
{
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return new ChunkPosition(hit.blockX, hit.blockY, hit.blockZ);
|
return new ChunkPosition(hit.blockX, hit.blockY, hit.blockZ);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Entity getPlayerLookingAtEntity(EntityPlayerMP player, float reach)
|
public Entity getPlayerLookingAtEntity(EntityPlayerMP player, float reach) {
|
||||||
{
|
Vec3 vec3d = Vec3
|
||||||
Vec3 vec3d = Vec3.createVectorHelper(player.posX, (player.posY + 1.6200000000000001D) - player.yOffset, player.posZ);
|
.createVectorHelper(player.posX, (player.posY + 1.6200000000000001D) - player.yOffset, player.posZ);
|
||||||
Vec3 vec3d1 = player.getLook(1.0F);
|
Vec3 vec3d1 = player.getLook(1.0F);
|
||||||
Vec3 vec3d2 = vec3d.addVector(vec3d1.xCoord * reach, vec3d1.yCoord * reach, vec3d1.zCoord * reach);
|
Vec3 vec3d2 = vec3d.addVector(vec3d1.xCoord * reach, vec3d1.yCoord * reach, vec3d1.zCoord * reach);
|
||||||
MovingObjectPosition hit = player.worldObj.rayTraceBlocks(vec3d, vec3d2);
|
MovingObjectPosition hit = player.worldObj.rayTraceBlocks(vec3d, vec3d2);
|
||||||
if(hit == null || hit.typeOfHit != MovingObjectType.ENTITY)
|
if (hit == null || hit.typeOfHit != MovingObjectType.ENTITY) {
|
||||||
{
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return hit.entityHit;
|
return hit.entityHit;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,28 +1,24 @@
|
|||||||
package codechicken.core.commands;
|
package codechicken.core.commands;
|
||||||
|
|
||||||
import net.minecraft.server.MinecraftServer;
|
|
||||||
import net.minecraft.command.ICommandSender;
|
import net.minecraft.command.ICommandSender;
|
||||||
|
import net.minecraft.server.MinecraftServer;
|
||||||
|
|
||||||
|
public abstract class ServerCommand extends CoreCommand {
|
||||||
|
|
||||||
public abstract class ServerCommand extends CoreCommand
|
|
||||||
{
|
|
||||||
@Override
|
@Override
|
||||||
public void processCommand(ICommandSender var1, String[] var2)
|
public void processCommand(ICommandSender var1, String[] var2) {
|
||||||
{
|
handleCommand(var2, (MinecraftServer) var1);
|
||||||
handleCommand(var2, (MinecraftServer)var1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean canCommandSenderUseCommand(ICommandSender var1)
|
public boolean canCommandSenderUseCommand(ICommandSender var1) {
|
||||||
{
|
if (!super.canCommandSenderUseCommand(var1)) return false;
|
||||||
if(!super.canCommandSenderUseCommand(var1))
|
|
||||||
return false;
|
|
||||||
return var1 instanceof MinecraftServer;
|
return var1 instanceof MinecraftServer;
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract void handleCommand(String[] args, MinecraftServer listener);
|
public abstract void handleCommand(String[] args, MinecraftServer listener);
|
||||||
|
|
||||||
public final boolean OPOnly()
|
public final boolean OPOnly() {
|
||||||
{
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -4,10 +4,10 @@ import net.minecraft.entity.Entity;
|
|||||||
import net.minecraft.nbt.NBTTagCompound;
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
|
|
||||||
public class EntityRenderHook extends Entity
|
public class EntityRenderHook extends Entity {
|
||||||
{
|
|
||||||
public static interface IRenderCallback
|
public static interface IRenderCallback {
|
||||||
{
|
|
||||||
public void render(float frame, int pass);
|
public void render(float frame, int pass);
|
||||||
|
|
||||||
public boolean shouldRenderInPass(int pass);
|
public boolean shouldRenderInPass(int pass);
|
||||||
@@ -26,21 +26,17 @@ public class EntityRenderHook extends Entity
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onUpdate() {
|
public void onUpdate() {
|
||||||
if (!callback.isValid())
|
if (!callback.isValid()) setDead();
|
||||||
setDead();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void entityInit() {
|
protected void entityInit() {}
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void readEntityFromNBT(NBTTagCompound var1) {
|
protected void readEntityFromNBT(NBTTagCompound var1) {}
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void writeEntityToNBT(NBTTagCompound var1) {
|
protected void writeEntityToNBT(NBTTagCompound var1) {}
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean shouldRenderInPass(int pass) {
|
public boolean shouldRenderInPass(int pass) {
|
||||||
|
|||||||
@@ -4,44 +4,35 @@ import net.minecraft.entity.Entity;
|
|||||||
import net.minecraft.nbt.NBTTagCompound;
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
|
|
||||||
public class EntityUpdateHook extends Entity
|
public class EntityUpdateHook extends Entity {
|
||||||
{
|
|
||||||
public static interface IUpdateCallback
|
public static interface IUpdateCallback {
|
||||||
{
|
|
||||||
public void onUpdate();
|
public void onUpdate();
|
||||||
|
|
||||||
public boolean isValid();
|
public boolean isValid();
|
||||||
}
|
}
|
||||||
|
|
||||||
public final IUpdateCallback callback;
|
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);
|
super(world);
|
||||||
setPosition(x, y, z);
|
setPosition(x, y, z);
|
||||||
this.callback = callback;
|
this.callback = callback;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onUpdate()
|
public void onUpdate() {
|
||||||
{
|
if (!callback.isValid()) setDead();
|
||||||
if(!callback.isValid())
|
else callback.onUpdate();
|
||||||
setDead();
|
|
||||||
else
|
|
||||||
callback.onUpdate();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void entityInit()
|
protected void entityInit() {}
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void readEntityFromNBT(NBTTagCompound var1)
|
protected void readEntityFromNBT(NBTTagCompound var1) {}
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void writeEntityToNBT(NBTTagCompound var1)
|
protected void writeEntityToNBT(NBTTagCompound var1) {}
|
||||||
{
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -5,34 +5,28 @@ import cpw.mods.fml.common.FMLCommonHandler;
|
|||||||
import cpw.mods.fml.relauncher.Side;
|
import cpw.mods.fml.relauncher.Side;
|
||||||
import cpw.mods.fml.relauncher.SideOnly;
|
import cpw.mods.fml.relauncher.SideOnly;
|
||||||
|
|
||||||
public class FeatureHack
|
public class FeatureHack {
|
||||||
{
|
|
||||||
private static boolean updateHookEnabled = false;
|
private static boolean updateHookEnabled = false;
|
||||||
private static boolean renderHookEnabled = false;
|
private static boolean renderHookEnabled = false;
|
||||||
|
|
||||||
public static void enableUpdateHook()
|
public static void enableUpdateHook() {
|
||||||
{
|
if (updateHookEnabled) return;
|
||||||
if(updateHookEnabled)
|
|
||||||
return;
|
|
||||||
|
|
||||||
updateHookEnabled = true;
|
updateHookEnabled = true;
|
||||||
if(FMLCommonHandler.instance().getSide().isClient())
|
if (FMLCommonHandler.instance().getSide().isClient()) enableClientUpdateHook();
|
||||||
enableClientUpdateHook();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@SideOnly(Side.CLIENT)
|
@SideOnly(Side.CLIENT)
|
||||||
public static void enableRenderHook()
|
public static void enableRenderHook() {
|
||||||
{
|
if (renderHookEnabled) return;
|
||||||
if(renderHookEnabled)
|
|
||||||
return;
|
|
||||||
|
|
||||||
renderHookEnabled = true;
|
renderHookEnabled = true;
|
||||||
RenderingRegistry.registerEntityRenderingHandler(EntityUpdateHook.class, new RenderNull());
|
RenderingRegistry.registerEntityRenderingHandler(EntityUpdateHook.class, new RenderNull());
|
||||||
}
|
}
|
||||||
|
|
||||||
@SideOnly(Side.CLIENT)
|
@SideOnly(Side.CLIENT)
|
||||||
private static void enableClientUpdateHook()
|
private static void enableClientUpdateHook() {
|
||||||
{
|
|
||||||
RenderingRegistry.registerEntityRenderingHandler(EntityRenderHook.class, new RenderEntityRenderHook());
|
RenderingRegistry.registerEntityRenderingHandler(EntityRenderHook.class, new RenderEntityRenderHook());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,27 +1,31 @@
|
|||||||
package codechicken.core.featurehack;
|
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.item.Item;
|
||||||
import net.minecraft.util.ObjectIntIdentityMap;
|
import net.minecraft.util.ObjectIntIdentityMap;
|
||||||
import net.minecraft.util.RegistryNamespaced;
|
import net.minecraft.util.RegistryNamespaced;
|
||||||
import net.minecraft.util.RegistrySimple;
|
import net.minecraft.util.RegistrySimple;
|
||||||
|
|
||||||
import java.lang.reflect.Field;
|
import codechicken.lib.asm.ObfMapping;
|
||||||
import java.util.Map;
|
|
||||||
|
public class GameDataManipulator {
|
||||||
|
|
||||||
public class GameDataManipulator
|
|
||||||
{
|
|
||||||
public static Field f_registryObjects;
|
public static Field f_registryObjects;
|
||||||
public static Field f_underlyingIntegerMap;
|
public static Field f_underlyingIntegerMap;
|
||||||
|
|
||||||
static
|
static {
|
||||||
{
|
|
||||||
try {
|
try {
|
||||||
f_registryObjects = RegistrySimple.class.getDeclaredField(
|
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_registryObjects.setAccessible(true);
|
||||||
f_underlyingIntegerMap = RegistryNamespaced.class.getDeclaredField(
|
f_underlyingIntegerMap = RegistryNamespaced.class.getDeclaredField(
|
||||||
new ObfMapping("net/minecraft/util/RegistryNamespaced", "field_148759_a", "Lnet/minecraft/util/ObjectIntIdentityMap;").toRuntime().s_name);
|
new ObfMapping(
|
||||||
|
"net/minecraft/util/RegistryNamespaced",
|
||||||
|
"field_148759_a",
|
||||||
|
"Lnet/minecraft/util/ObjectIntIdentityMap;").toRuntime().s_name);
|
||||||
f_underlyingIntegerMap.setAccessible(true);
|
f_underlyingIntegerMap.setAccessible(true);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
@@ -31,8 +35,8 @@ public class GameDataManipulator
|
|||||||
public static void replaceItem(int id, Item item) {
|
public static void replaceItem(int id, Item item) {
|
||||||
try {
|
try {
|
||||||
String name = Item.itemRegistry.getNameForObject(Item.getItemById(id));
|
String name = Item.itemRegistry.getNameForObject(Item.getItemById(id));
|
||||||
((Map)f_registryObjects.get(Item.itemRegistry)).put(name, item);
|
((Map) f_registryObjects.get(Item.itemRegistry)).put(name, item);
|
||||||
((ObjectIntIdentityMap)f_underlyingIntegerMap.get(Item.itemRegistry)).func_148746_a(item, id);
|
((ObjectIntIdentityMap) f_underlyingIntegerMap.get(Item.itemRegistry)).func_148746_a(item, id);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,58 +1,55 @@
|
|||||||
package codechicken.core.featurehack;
|
package codechicken.core.featurehack;
|
||||||
|
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import codechicken.core.ReflectionManager;
|
|
||||||
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 cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
|
||||||
import net.minecraft.block.Block;
|
|
||||||
import net.minecraft.init.Blocks;
|
import net.minecraft.init.Blocks;
|
||||||
import net.minecraft.util.IIcon;
|
import net.minecraft.util.IIcon;
|
||||||
import net.minecraftforge.client.event.TextureStitchEvent;
|
import net.minecraftforge.client.event.TextureStitchEvent;
|
||||||
import net.minecraftforge.common.MinecraftForge;
|
import net.minecraftforge.common.MinecraftForge;
|
||||||
|
|
||||||
|
import codechicken.core.ReflectionManager;
|
||||||
import codechicken.core.asm.TweakTransformer;
|
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 codechicken.lib.asm.ObfMapping;
|
||||||
|
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
||||||
|
|
||||||
|
public class LiquidTextures {
|
||||||
|
|
||||||
public class LiquidTextures
|
|
||||||
{
|
|
||||||
public static IIcon[] newTextures = new IIcon[4];
|
public static IIcon[] newTextures = new IIcon[4];
|
||||||
|
|
||||||
public static boolean replaceLava;
|
public static boolean replaceLava;
|
||||||
public static boolean replaceWater;
|
public static boolean replaceWater;
|
||||||
|
|
||||||
private static Field field_tex;
|
private static Field field_tex;
|
||||||
|
|
||||||
public static void init()
|
public static void init() {
|
||||||
{
|
replaceWater = TweakTransformer.tweaks.getTag("replaceWaterFX")
|
||||||
replaceWater = TweakTransformer.tweaks.getTag("replaceWaterFX").setComment("Set this to true to use the pre1.5 water textures").getBooleanValue(false);
|
.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);
|
replaceLava = TweakTransformer.tweaks.getTag("replaceLavaFX")
|
||||||
if(replaceWater)
|
.setComment("Set this to true to use the pre1.5 lava textures").getBooleanValue(false);
|
||||||
{
|
if (replaceWater) {
|
||||||
newTextures[0] = new TextureWaterFX().texture;
|
newTextures[0] = new TextureWaterFX().texture;
|
||||||
newTextures[1] = new TextureWaterFlowFX().texture;
|
newTextures[1] = new TextureWaterFlowFX().texture;
|
||||||
}
|
}
|
||||||
if(replaceLava)
|
if (replaceLava) {
|
||||||
{
|
|
||||||
newTextures[2] = new TextureLavaFX().texture;
|
newTextures[2] = new TextureLavaFX().texture;
|
||||||
newTextures[3] = new TextureLavaFlowFX().texture;
|
newTextures[3] = new TextureLavaFlowFX().texture;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(replaceWater || replaceLava)
|
if (replaceWater || replaceLava) {
|
||||||
{
|
|
||||||
MinecraftForge.EVENT_BUS.register(new LiquidTextures());
|
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
|
@SubscribeEvent
|
||||||
public void postStitch(TextureStitchEvent.Post event)
|
public void postStitch(TextureStitchEvent.Post event) {
|
||||||
{
|
|
||||||
IIcon[] icons;
|
IIcon[] icons;
|
||||||
if(replaceLava)
|
if (replaceLava) {
|
||||||
{
|
|
||||||
icons = ReflectionManager.get(field_tex, IIcon[].class, Blocks.flowing_lava);
|
icons = ReflectionManager.get(field_tex, IIcon[].class, Blocks.flowing_lava);
|
||||||
icons[0] = newTextures[2];
|
icons[0] = newTextures[2];
|
||||||
icons[1] = newTextures[3];
|
icons[1] = newTextures[3];
|
||||||
@@ -60,8 +57,7 @@ public class LiquidTextures
|
|||||||
icons[0] = newTextures[2];
|
icons[0] = newTextures[2];
|
||||||
icons[1] = newTextures[3];
|
icons[1] = newTextures[3];
|
||||||
}
|
}
|
||||||
if(replaceWater)
|
if (replaceWater) {
|
||||||
{
|
|
||||||
icons = ReflectionManager.get(field_tex, IIcon[].class, Blocks.flowing_water);
|
icons = ReflectionManager.get(field_tex, IIcon[].class, Blocks.flowing_water);
|
||||||
icons[0] = newTextures[0];
|
icons[0] = newTextures[0];
|
||||||
icons[1] = newTextures[1];
|
icons[1] = newTextures[1];
|
||||||
|
|||||||
@@ -1,26 +1,24 @@
|
|||||||
package codechicken.core.featurehack;
|
package codechicken.core.featurehack;
|
||||||
|
|
||||||
|
import net.minecraft.client.renderer.entity.Render;
|
||||||
|
import net.minecraft.entity.Entity;
|
||||||
|
import net.minecraft.util.ResourceLocation;
|
||||||
|
import net.minecraftforge.client.MinecraftForgeClient;
|
||||||
|
|
||||||
import org.lwjgl.opengl.GL11;
|
import org.lwjgl.opengl.GL11;
|
||||||
|
|
||||||
import net.minecraft.entity.Entity;
|
public class RenderEntityRenderHook extends Render {
|
||||||
import net.minecraft.util.ResourceLocation;
|
|
||||||
import net.minecraft.client.renderer.entity.Render;
|
|
||||||
import net.minecraftforge.client.MinecraftForgeClient;
|
|
||||||
|
|
||||||
public class RenderEntityRenderHook extends Render
|
|
||||||
{
|
|
||||||
@Override
|
@Override
|
||||||
public void doRender(Entity entity, double x, double y, double z, float f, float frame)
|
public void doRender(Entity entity, double x, double y, double z, float f, float frame) {
|
||||||
{
|
EntityRenderHook hook = (EntityRenderHook) entity;
|
||||||
EntityRenderHook hook = (EntityRenderHook)entity;
|
GL11.glTranslated(x - hook.posX, y - hook.posY, z - hook.posZ);
|
||||||
GL11.glTranslated(x-hook.posX, y-hook.posY, z-hook.posZ);
|
((EntityRenderHook) entity).callback.render(frame, MinecraftForgeClient.getRenderPass());
|
||||||
((EntityRenderHook)entity).callback.render(frame, MinecraftForgeClient.getRenderPass());
|
GL11.glTranslated(hook.posX - x, hook.posY - y, hook.posZ - z);
|
||||||
GL11.glTranslated(hook.posX-x, hook.posY-y, hook.posZ-z);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected ResourceLocation getEntityTexture(Entity entity)
|
protected ResourceLocation getEntityTexture(Entity entity) {
|
||||||
{
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -4,16 +4,13 @@ import net.minecraft.client.renderer.entity.Render;
|
|||||||
import net.minecraft.entity.Entity;
|
import net.minecraft.entity.Entity;
|
||||||
import net.minecraft.util.ResourceLocation;
|
import net.minecraft.util.ResourceLocation;
|
||||||
|
|
||||||
public class RenderNull extends Render
|
public class RenderNull extends Render {
|
||||||
{
|
|
||||||
@Override
|
@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
|
@Override
|
||||||
protected ResourceLocation getEntityTexture(Entity entity)
|
protected ResourceLocation getEntityTexture(Entity entity) {
|
||||||
{
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,38 +1,37 @@
|
|||||||
package codechicken.core.featurehack;
|
package codechicken.core.featurehack;
|
||||||
|
|
||||||
|
import static net.minecraftforge.common.util.ForgeDirection.UP;
|
||||||
|
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
|
||||||
import net.minecraft.block.Block;
|
import net.minecraft.block.Block;
|
||||||
import net.minecraft.init.Blocks;
|
import net.minecraft.init.Blocks;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
|
|
||||||
import static net.minecraftforge.common.util.ForgeDirection.UP;
|
public class TweakTransformerHelper {
|
||||||
|
|
||||||
public class TweakTransformerHelper
|
public static void quenchFireTick(World world, int x, int y, int z, Random rand) {
|
||||||
{
|
|
||||||
public static void quenchFireTick(World world, int x, int y, int z, Random rand)
|
|
||||||
{
|
|
||||||
Block base = world.getBlock(x, y - 1, z);
|
Block base = world.getBlock(x, y - 1, z);
|
||||||
boolean supported = (base != null && base.isFireSource(world, x, y - 1, z, UP));
|
boolean supported = (base != null && base.isFireSource(world, x, y - 1, z, UP));
|
||||||
|
|
||||||
if (!Blocks.fire.canPlaceBlockAt(world, x, y, z) ||
|
if (!Blocks.fire.canPlaceBlockAt(world, x, y, z) || !supported && world.isRaining()
|
||||||
!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.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);
|
world.setBlockToAir(x, y, z);
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
int meta = world.getBlockMetadata(x, y, z);
|
int meta = world.getBlockMetadata(x, y, z);
|
||||||
if(meta < 15)
|
if (meta < 15) world.setBlockMetadataWithNotify(x, y, z, meta + rand.nextInt(3) / 2, 0);
|
||||||
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));
|
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);
|
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);
|
Block block = world.getBlock(x, y, z);
|
||||||
return block.isAir(world, x, y, z) || block.isReplaceable(world, x, y, z);
|
return block.isAir(world, x, y, z) || block.isReplaceable(world, x, y, z);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,28 +1,27 @@
|
|||||||
package codechicken.core.featurehack.mc;
|
package codechicken.core.featurehack.mc;
|
||||||
|
|
||||||
|
import net.minecraft.util.MathHelper;
|
||||||
|
|
||||||
import codechicken.lib.colour.ColourRGBA;
|
import codechicken.lib.colour.ColourRGBA;
|
||||||
import codechicken.lib.render.TextureFX;
|
import codechicken.lib.render.TextureFX;
|
||||||
import cpw.mods.fml.relauncher.Side;
|
import cpw.mods.fml.relauncher.Side;
|
||||||
import cpw.mods.fml.relauncher.SideOnly;
|
import cpw.mods.fml.relauncher.SideOnly;
|
||||||
import net.minecraft.util.MathHelper;
|
|
||||||
|
|
||||||
@SideOnly(Side.CLIENT)
|
@SideOnly(Side.CLIENT)
|
||||||
public class TextureLavaFX extends TextureFX
|
public class TextureLavaFX extends TextureFX {
|
||||||
{
|
|
||||||
protected float[] field_76876_g = new float[256];
|
protected float[] field_76876_g = new float[256];
|
||||||
protected float[] field_76878_h = new float[256];
|
protected float[] field_76878_h = new float[256];
|
||||||
protected float[] field_76879_i = new float[256];
|
protected float[] field_76879_i = new float[256];
|
||||||
protected float[] field_76877_j = new float[256];
|
protected float[] field_76877_j = new float[256];
|
||||||
|
|
||||||
public TextureLavaFX()
|
public TextureLavaFX() {
|
||||||
{
|
|
||||||
super(16, "lava_still_fx");
|
super(16, "lava_still_fx");
|
||||||
setup();
|
setup();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setup()
|
public void setup() {
|
||||||
{
|
|
||||||
super.setup();
|
super.setup();
|
||||||
field_76876_g = new float[tileSizeSquare];
|
field_76876_g = new float[tileSizeSquare];
|
||||||
field_76878_h = new float[tileSizeSquare];
|
field_76878_h = new float[tileSizeSquare];
|
||||||
@@ -30,8 +29,7 @@ public class TextureLavaFX extends TextureFX
|
|||||||
field_76877_j = new float[tileSizeSquare];
|
field_76877_j = new float[tileSizeSquare];
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onTick()
|
public void onTick() {
|
||||||
{
|
|
||||||
int var2;
|
int var2;
|
||||||
float var3;
|
float var3;
|
||||||
int var5;
|
int var5;
|
||||||
@@ -40,36 +38,40 @@ public class TextureLavaFX extends TextureFX
|
|||||||
int var8;
|
int var8;
|
||||||
int var9;
|
int var9;
|
||||||
|
|
||||||
for (int var1 = 0; var1 < tileSizeBase; ++var1)
|
for (int var1 = 0; var1 < tileSizeBase; ++var1) {
|
||||||
{
|
for (var2 = 0; var2 < tileSizeBase; ++var2) {
|
||||||
for (var2 = 0; var2 < tileSizeBase; ++var2)
|
|
||||||
{
|
|
||||||
var3 = 0.0F;
|
var3 = 0.0F;
|
||||||
int var4 = (int)(MathHelper.sin(var2 * (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);
|
var5 = (int) (MathHelper.sin(var1 * (float) Math.PI * 2.0F / 16.0F) * 1.2F);
|
||||||
|
|
||||||
for (var6 = var1 - 1; var6 <= var1 + 1; ++var6)
|
for (var6 = var1 - 1; var6 <= var1 + 1; ++var6) {
|
||||||
{
|
for (var7 = var2 - 1; var7 <= var2 + 1; ++var7) {
|
||||||
for (var7 = var2 - 1; var7 <= var2 + 1; ++var7)
|
|
||||||
{
|
|
||||||
var8 = var6 + var4 & tileSizeMask;
|
var8 = var6 + var4 & tileSizeMask;
|
||||||
var9 = var7 + var5 & tileSizeMask;
|
var9 = var7 + var5 & tileSizeMask;
|
||||||
var3 += this.field_76876_g[var8 + var9 * tileSizeBase];
|
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_76878_h[var1 + var2 * tileSizeBase] = var3 / 10.0F
|
||||||
this.field_76879_i[var1 + var2 * tileSizeBase] += this.field_76877_j[var1 + var2 * tileSizeBase] * 0.01F;
|
+ (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_76879_i[var1 + var2 * tileSizeBase] = 0.0F;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.field_76877_j[var1 + var2 * tileSizeBase] -= 0.06F;
|
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;
|
this.field_76877_j[var1 + var2 * tileSizeBase] = 1.5F;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -79,26 +81,22 @@ public class TextureLavaFX extends TextureFX
|
|||||||
this.field_76878_h = this.field_76876_g;
|
this.field_76878_h = this.field_76876_g;
|
||||||
this.field_76876_g = var11;
|
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;
|
var3 = this.field_76876_g[var2] * 2.0F;
|
||||||
|
|
||||||
if (var3 > 1.0F)
|
if (var3 > 1.0F) {
|
||||||
{
|
|
||||||
var3 = 1.0F;
|
var3 = 1.0F;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (var3 < 0.0F)
|
if (var3 < 0.0F) {
|
||||||
{
|
|
||||||
var3 = 0.0F;
|
var3 = 0.0F;
|
||||||
}
|
}
|
||||||
|
|
||||||
var5 = (int)(var3 * 100.0F + 155.0F);
|
var5 = (int) (var3 * 100.0F + 155.0F);
|
||||||
var6 = (int)(var3 * var3 * 255.0F);
|
var6 = (int) (var3 * var3 * 255.0F);
|
||||||
var7 = (int)(var3 * var3 * var3 * var3 * 128.0F);
|
var7 = (int) (var3 * var3 * var3 * var3 * 128.0F);
|
||||||
|
|
||||||
if (this.anaglyphEnabled)
|
if (this.anaglyphEnabled) {
|
||||||
{
|
|
||||||
var8 = (var5 * 30 + var6 * 59 + var7 * 11) / 100;
|
var8 = (var5 * 30 + var6 * 59 + var7 * 11) / 100;
|
||||||
var9 = (var5 * 30 + var6 * 70) / 100;
|
var9 = (var5 * 30 + var6 * 70) / 100;
|
||||||
int var10 = (var5 * 30 + var7 * 70) / 100;
|
int var10 = (var5 * 30 + var7 * 70) / 100;
|
||||||
|
|||||||
@@ -1,34 +1,33 @@
|
|||||||
package codechicken.core.featurehack.mc;
|
package codechicken.core.featurehack.mc;
|
||||||
|
|
||||||
|
import net.minecraft.util.MathHelper;
|
||||||
|
|
||||||
import codechicken.lib.colour.ColourRGBA;
|
import codechicken.lib.colour.ColourRGBA;
|
||||||
import codechicken.lib.render.TextureFX;
|
import codechicken.lib.render.TextureFX;
|
||||||
import cpw.mods.fml.relauncher.Side;
|
import cpw.mods.fml.relauncher.Side;
|
||||||
import cpw.mods.fml.relauncher.SideOnly;
|
import cpw.mods.fml.relauncher.SideOnly;
|
||||||
import net.minecraft.util.MathHelper;
|
|
||||||
|
|
||||||
@SideOnly(Side.CLIENT)
|
@SideOnly(Side.CLIENT)
|
||||||
public class TextureLavaFlowFX extends TextureFX
|
public class TextureLavaFlowFX extends TextureFX {
|
||||||
{
|
|
||||||
protected float[] field_76871_g = new float[256];
|
protected float[] field_76871_g = new float[256];
|
||||||
protected float[] field_76874_h = new float[256];
|
protected float[] field_76874_h = new float[256];
|
||||||
protected float[] field_76875_i = new float[256];
|
protected float[] field_76875_i = new float[256];
|
||||||
protected float[] field_76872_j = new float[256];
|
protected float[] field_76872_j = new float[256];
|
||||||
int field_76873_k = 0;
|
int field_76873_k = 0;
|
||||||
|
|
||||||
//shadow
|
// shadow
|
||||||
public int tileSizeBase = 16;
|
public int tileSizeBase = 16;
|
||||||
public int tileSizeSquare = 256;
|
public int tileSizeSquare = 256;
|
||||||
public int tileSizeMask = 15;
|
public int tileSizeMask = 15;
|
||||||
public int tileSizeSquareMask = 255;
|
public int tileSizeSquareMask = 255;
|
||||||
|
|
||||||
public TextureLavaFlowFX()
|
public TextureLavaFlowFX() {
|
||||||
{
|
|
||||||
super(32, "lava_flow_fx");
|
super(32, "lava_flow_fx");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setup()
|
public void setup() {
|
||||||
{
|
|
||||||
super.setup();
|
super.setup();
|
||||||
field_76871_g = new float[tileSizeSquare];
|
field_76871_g = new float[tileSizeSquare];
|
||||||
field_76874_h = new float[tileSizeSquare];
|
field_76874_h = new float[tileSizeSquare];
|
||||||
@@ -37,8 +36,7 @@ public class TextureLavaFlowFX extends TextureFX
|
|||||||
field_76873_k = 0;
|
field_76873_k = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onTick()
|
public void onTick() {
|
||||||
{
|
|
||||||
++this.field_76873_k;
|
++this.field_76873_k;
|
||||||
int var2;
|
int var2;
|
||||||
float var3;
|
float var3;
|
||||||
@@ -48,36 +46,40 @@ public class TextureLavaFlowFX extends TextureFX
|
|||||||
int var8;
|
int var8;
|
||||||
int var9;
|
int var9;
|
||||||
|
|
||||||
for (int var1 = 0; var1 < tileSizeBase; ++var1)
|
for (int var1 = 0; var1 < tileSizeBase; ++var1) {
|
||||||
{
|
for (var2 = 0; var2 < tileSizeBase; ++var2) {
|
||||||
for (var2 = 0; var2 < tileSizeBase; ++var2)
|
|
||||||
{
|
|
||||||
var3 = 0.0F;
|
var3 = 0.0F;
|
||||||
int var4 = (int)(MathHelper.sin(var2 * (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);
|
var5 = (int) (MathHelper.sin(var1 * (float) Math.PI * 2.0F / 16.0F) * 1.2F);
|
||||||
|
|
||||||
for (var6 = var1 - 1; var6 <= var1 + 1; ++var6)
|
for (var6 = var1 - 1; var6 <= var1 + 1; ++var6) {
|
||||||
{
|
for (var7 = var2 - 1; var7 <= var2 + 1; ++var7) {
|
||||||
for (var7 = var2 - 1; var7 <= var2 + 1; ++var7)
|
|
||||||
{
|
|
||||||
var8 = var6 + var4 & tileSizeMask;
|
var8 = var6 + var4 & tileSizeMask;
|
||||||
var9 = var7 + var5 & tileSizeMask;
|
var9 = var7 + var5 & tileSizeMask;
|
||||||
var3 += this.field_76871_g[var8 + var9 * tileSizeBase];
|
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_76874_h[var1 + var2 * tileSizeBase] = var3 / 10.0F
|
||||||
this.field_76875_i[var1 + var2 * tileSizeBase] += this.field_76872_j[var1 + var2 * tileSizeBase] * 0.01F;
|
+ (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_76875_i[var1 + var2 * tileSizeBase] = 0.0F;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.field_76872_j[var1 + var2 * tileSizeBase] -= 0.06F;
|
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;
|
this.field_76872_j[var1 + var2 * tileSizeBase] = 1.5F;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -87,26 +89,22 @@ public class TextureLavaFlowFX extends TextureFX
|
|||||||
this.field_76874_h = this.field_76871_g;
|
this.field_76874_h = this.field_76871_g;
|
||||||
this.field_76871_g = var11;
|
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;
|
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;
|
var3 = 1.0F;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (var3 < 0.0F)
|
if (var3 < 0.0F) {
|
||||||
{
|
|
||||||
var3 = 0.0F;
|
var3 = 0.0F;
|
||||||
}
|
}
|
||||||
|
|
||||||
var5 = (int)(var3 * 100.0F + 155.0F);
|
var5 = (int) (var3 * 100.0F + 155.0F);
|
||||||
var6 = (int)(var3 * var3 * 255.0F);
|
var6 = (int) (var3 * var3 * 255.0F);
|
||||||
var7 = (int)(var3 * var3 * var3 * var3 * 128.0F);
|
var7 = (int) (var3 * var3 * var3 * var3 * 128.0F);
|
||||||
|
|
||||||
if (this.anaglyphEnabled)
|
if (this.anaglyphEnabled) {
|
||||||
{
|
|
||||||
var8 = (var5 * 30 + var6 * 59 + var7 * 11) / 100;
|
var8 = (var5 * 30 + var6 * 59 + var7 * 11) / 100;
|
||||||
var9 = (var5 * 30 + var6 * 70) / 100;
|
var9 = (var5 * 30 + var6 * 70) / 100;
|
||||||
int var10 = (var5 * 30 + var7 * 70) / 100;
|
int var10 = (var5 * 30 + var7 * 70) / 100;
|
||||||
@@ -115,17 +113,16 @@ public class TextureLavaFlowFX extends TextureFX
|
|||||||
var7 = var10;
|
var7 = var10;
|
||||||
}
|
}
|
||||||
|
|
||||||
int px = var2&tileSizeMask;
|
int px = var2 & tileSizeMask;
|
||||||
int py = var2/tileSizeBase;
|
int py = var2 / tileSizeBase;
|
||||||
writeColour(px, py, var5, var6, var7, -1);
|
writeColour(px, py, var5, var6, var7, -1);
|
||||||
writeColour(px+16, py, var5, var6, var7, -1);
|
writeColour(px + 16, py, var5, var6, var7, -1);
|
||||||
writeColour(px, py+16, 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 + 16, var5, var6, var7, -1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void writeColour(int px, int py, int var5, int var6, int var7, int 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();
|
||||||
imageData[py*32+px] = new ColourRGBA(var5, var6, var7, var8).argb();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -6,8 +6,8 @@ import cpw.mods.fml.relauncher.Side;
|
|||||||
import cpw.mods.fml.relauncher.SideOnly;
|
import cpw.mods.fml.relauncher.SideOnly;
|
||||||
|
|
||||||
@SideOnly(Side.CLIENT)
|
@SideOnly(Side.CLIENT)
|
||||||
public class TextureWaterFX extends TextureFX
|
public class TextureWaterFX extends TextureFX {
|
||||||
{
|
|
||||||
/** red RGB value for water texture */
|
/** red RGB value for water texture */
|
||||||
protected float[] red = new float[256];
|
protected float[] red = new float[256];
|
||||||
|
|
||||||
@@ -19,15 +19,14 @@ public class TextureWaterFX extends TextureFX
|
|||||||
|
|
||||||
/** alpha RGB value for water texture */
|
/** alpha RGB value for water texture */
|
||||||
protected float[] alpha = new float[256];
|
protected float[] alpha = new float[256];
|
||||||
public TextureWaterFX()
|
|
||||||
{
|
public TextureWaterFX() {
|
||||||
super(16, "water_still_fx");
|
super(16, "water_still_fx");
|
||||||
setup();
|
setup();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setup()
|
public void setup() {
|
||||||
{
|
|
||||||
super.setup();
|
super.setup();
|
||||||
red = new float[tileSizeSquare];
|
red = new float[tileSizeSquare];
|
||||||
green = new float[tileSizeSquare];
|
green = new float[tileSizeSquare];
|
||||||
@@ -35,22 +34,18 @@ public class TextureWaterFX extends TextureFX
|
|||||||
alpha = new float[tileSizeSquare];
|
alpha = new float[tileSizeSquare];
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onTick()
|
public void onTick() {
|
||||||
{
|
|
||||||
int var1;
|
int var1;
|
||||||
int var2;
|
int var2;
|
||||||
float var3;
|
float var3;
|
||||||
int var5;
|
int var5;
|
||||||
int var6;
|
int var6;
|
||||||
|
|
||||||
for (var1 = 0; var1 < tileSizeBase; ++var1)
|
for (var1 = 0; var1 < tileSizeBase; ++var1) {
|
||||||
{
|
for (var2 = 0; var2 < tileSizeBase; ++var2) {
|
||||||
for (var2 = 0; var2 < tileSizeBase; ++var2)
|
|
||||||
{
|
|
||||||
var3 = 0.0F;
|
var3 = 0.0F;
|
||||||
|
|
||||||
for (int var4 = var1 - 1; var4 <= var1 + 1; ++var4)
|
for (int var4 = var1 - 1; var4 <= var1 + 1; ++var4) {
|
||||||
{
|
|
||||||
var5 = var4 & tileSizeMask;
|
var5 = var4 & tileSizeMask;
|
||||||
var6 = var2 & tileSizeMask;
|
var6 = var2 & tileSizeMask;
|
||||||
var3 += this.red[var5 + var6 * tileSizeBase];
|
var3 += this.red[var5 + var6 * tileSizeBase];
|
||||||
@@ -60,21 +55,17 @@ public class TextureWaterFX extends TextureFX
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (var1 = 0; var1 < tileSizeBase; ++var1)
|
for (var1 = 0; var1 < tileSizeBase; ++var1) {
|
||||||
{
|
for (var2 = 0; var2 < tileSizeBase; ++var2) {
|
||||||
for (var2 = 0; var2 < tileSizeBase; ++var2)
|
|
||||||
{
|
|
||||||
this.blue[var1 + var2 * tileSizeBase] += this.alpha[var1 + var2 * tileSizeBase] * 0.05F;
|
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.blue[var1 + var2 * tileSizeBase] = 0.0F;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.alpha[var1 + var2 * tileSizeBase] -= 0.1F;
|
this.alpha[var1 + var2 * tileSizeBase] -= 0.1F;
|
||||||
|
|
||||||
if (Math.random() < 0.05D)
|
if (Math.random() < 0.05D) {
|
||||||
{
|
|
||||||
this.alpha[var1 + var2 * tileSizeBase] = 0.5F;
|
this.alpha[var1 + var2 * tileSizeBase] = 0.5F;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -84,28 +75,24 @@ public class TextureWaterFX extends TextureFX
|
|||||||
this.green = this.red;
|
this.green = this.red;
|
||||||
this.red = var12;
|
this.red = var12;
|
||||||
|
|
||||||
for (var2 = 0; var2 < tileSizeSquare; ++var2)
|
for (var2 = 0; var2 < tileSizeSquare; ++var2) {
|
||||||
{
|
|
||||||
var3 = this.red[var2];
|
var3 = this.red[var2];
|
||||||
|
|
||||||
if (var3 > 1.0F)
|
if (var3 > 1.0F) {
|
||||||
{
|
|
||||||
var3 = 1.0F;
|
var3 = 1.0F;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (var3 < 0.0F)
|
if (var3 < 0.0F) {
|
||||||
{
|
|
||||||
var3 = 0.0F;
|
var3 = 0.0F;
|
||||||
}
|
}
|
||||||
|
|
||||||
float var13 = var3 * var3;
|
float var13 = var3 * var3;
|
||||||
var5 = (int)(32.0F + var13 * 32.0F);
|
var5 = (int) (32.0F + var13 * 32.0F);
|
||||||
var6 = (int)(50.0F + var13 * 64.0F);
|
var6 = (int) (50.0F + var13 * 64.0F);
|
||||||
int var7 = 255;
|
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 var9 = (var5 * 30 + var6 * 59 + var7 * 11) / 100;
|
||||||
int var10 = (var5 * 30 + var6 * 70) / 100;
|
int var10 = (var5 * 30 + var6 * 70) / 100;
|
||||||
int var11 = (var5 * 30 + var7 * 70) / 100;
|
int var11 = (var5 * 30 + var7 * 70) / 100;
|
||||||
|
|||||||
@@ -6,28 +6,26 @@ import cpw.mods.fml.relauncher.Side;
|
|||||||
import cpw.mods.fml.relauncher.SideOnly;
|
import cpw.mods.fml.relauncher.SideOnly;
|
||||||
|
|
||||||
@SideOnly(Side.CLIENT)
|
@SideOnly(Side.CLIENT)
|
||||||
public class TextureWaterFlowFX extends TextureFX
|
public class TextureWaterFlowFX extends TextureFX {
|
||||||
{
|
|
||||||
protected float[] field_76880_g = new float[256];
|
protected float[] field_76880_g = new float[256];
|
||||||
protected float[] field_76883_h = new float[256];
|
protected float[] field_76883_h = new float[256];
|
||||||
protected float[] field_76884_i = new float[256];
|
protected float[] field_76884_i = new float[256];
|
||||||
protected float[] field_76881_j = new float[256];
|
protected float[] field_76881_j = new float[256];
|
||||||
private int tickCounter = 0;
|
private int tickCounter = 0;
|
||||||
|
|
||||||
//shadow
|
// shadow
|
||||||
public int tileSizeBase = 16;
|
public int tileSizeBase = 16;
|
||||||
public int tileSizeSquare = 256;
|
public int tileSizeSquare = 256;
|
||||||
public int tileSizeMask = 15;
|
public int tileSizeMask = 15;
|
||||||
public int tileSizeSquareMask = 255;
|
public int tileSizeSquareMask = 255;
|
||||||
|
|
||||||
public TextureWaterFlowFX()
|
public TextureWaterFlowFX() {
|
||||||
{
|
|
||||||
super(32, "water_flow_fx");
|
super(32, "water_flow_fx");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setup()
|
public void setup() {
|
||||||
{
|
|
||||||
super.setup();
|
super.setup();
|
||||||
field_76880_g = new float[tileSizeSquare];
|
field_76880_g = new float[tileSizeSquare];
|
||||||
field_76883_h = new float[tileSizeSquare];
|
field_76883_h = new float[tileSizeSquare];
|
||||||
@@ -36,8 +34,7 @@ public class TextureWaterFlowFX extends TextureFX
|
|||||||
tickCounter = 0;
|
tickCounter = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onTick()
|
public void onTick() {
|
||||||
{
|
|
||||||
++this.tickCounter;
|
++this.tickCounter;
|
||||||
int var1;
|
int var1;
|
||||||
int var2;
|
int var2;
|
||||||
@@ -45,38 +42,33 @@ public class TextureWaterFlowFX extends TextureFX
|
|||||||
int var5;
|
int var5;
|
||||||
int var6;
|
int var6;
|
||||||
|
|
||||||
for (var1 = 0; var1 < tileSizeBase; ++var1)
|
for (var1 = 0; var1 < tileSizeBase; ++var1) {
|
||||||
{
|
for (var2 = 0; var2 < tileSizeBase; ++var2) {
|
||||||
for (var2 = 0; var2 < tileSizeBase; ++var2)
|
|
||||||
{
|
|
||||||
var3 = 0.0F;
|
var3 = 0.0F;
|
||||||
|
|
||||||
for (int var4 = var2 - 2; var4 <= var2; ++var4)
|
for (int var4 = var2 - 2; var4 <= var2; ++var4) {
|
||||||
{
|
|
||||||
var5 = var1 & tileSizeMask;
|
var5 = var1 & tileSizeMask;
|
||||||
var6 = var4 & tileSizeMask;
|
var6 = var4 & tileSizeMask;
|
||||||
var3 += this.field_76880_g[var5 + var6 * tileSizeBase];
|
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 (var1 = 0; var1 < tileSizeBase; ++var1) {
|
||||||
{
|
for (var2 = 0; var2 < tileSizeBase; ++var2) {
|
||||||
for (var2 = 0; var2 < tileSizeBase; ++var2)
|
this.field_76884_i[var1 + var2 * tileSizeBase] += this.field_76881_j[var1 + var2 * tileSizeBase]
|
||||||
{
|
* 0.05F;
|
||||||
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_76884_i[var1 + var2 * tileSizeBase] = 0.0F;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.field_76881_j[var1 + var2 * tileSizeBase] -= 0.3F;
|
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;
|
this.field_76881_j[var1 + var2 * tileSizeBase] = 0.5F;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -86,28 +78,24 @@ public class TextureWaterFlowFX extends TextureFX
|
|||||||
this.field_76883_h = this.field_76880_g;
|
this.field_76883_h = this.field_76880_g;
|
||||||
this.field_76880_g = var12;
|
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];
|
var3 = this.field_76880_g[var2 - this.tickCounter * tileSizeBase & tileSizeSquareMask];
|
||||||
|
|
||||||
if (var3 > 1.0F)
|
if (var3 > 1.0F) {
|
||||||
{
|
|
||||||
var3 = 1.0F;
|
var3 = 1.0F;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (var3 < 0.0F)
|
if (var3 < 0.0F) {
|
||||||
{
|
|
||||||
var3 = 0.0F;
|
var3 = 0.0F;
|
||||||
}
|
}
|
||||||
|
|
||||||
float var13 = var3 * var3;
|
float var13 = var3 * var3;
|
||||||
var5 = (int)(32.0F + var13 * 32.0F);
|
var5 = (int) (32.0F + var13 * 32.0F);
|
||||||
var6 = (int)(50.0F + var13 * 64.0F);
|
var6 = (int) (50.0F + var13 * 64.0F);
|
||||||
int var7 = 255;
|
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 var9 = (var5 * 30 + var6 * 59 + var7 * 11) / 100;
|
||||||
int var10 = (var5 * 30 + var6 * 70) / 100;
|
int var10 = (var5 * 30 + var6 * 70) / 100;
|
||||||
int var11 = (var5 * 30 + var7 * 70) / 100;
|
int var11 = (var5 * 30 + var7 * 70) / 100;
|
||||||
@@ -116,18 +104,16 @@ public class TextureWaterFlowFX extends TextureFX
|
|||||||
var7 = var11;
|
var7 = var11;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int px = var2 & tileSizeMask;
|
||||||
int px = var2&tileSizeMask;
|
int py = var2 / tileSizeBase;
|
||||||
int py = var2/tileSizeBase;
|
|
||||||
writeColour(px, py, var5, var6, var7, var8);
|
writeColour(px, py, var5, var6, var7, var8);
|
||||||
writeColour(px+16, py, var5, var6, var7, var8);
|
writeColour(px + 16, py, var5, var6, var7, var8);
|
||||||
writeColour(px, py+16, 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 + 16, var5, var6, var7, var8);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void writeColour(int px, int py, int var5, int var6, int var7, int 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();
|
||||||
imageData[py*32+px] = new ColourRGBA(var5, var6, var7, var8).argb();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -5,15 +5,14 @@ import net.minecraftforge.fluids.FluidStack;
|
|||||||
import net.minecraftforge.fluids.FluidTankInfo;
|
import net.minecraftforge.fluids.FluidTankInfo;
|
||||||
import net.minecraftforge.fluids.IFluidTank;
|
import net.minecraftforge.fluids.IFluidTank;
|
||||||
|
|
||||||
public class ExtendedFluidTank implements IFluidTank
|
public class ExtendedFluidTank implements IFluidTank {
|
||||||
{
|
|
||||||
private FluidStack fluid;
|
private FluidStack fluid;
|
||||||
private boolean changeType;
|
private boolean changeType;
|
||||||
private int capacity;
|
private int capacity;
|
||||||
|
|
||||||
public ExtendedFluidTank(FluidStack type, int capacity)
|
public ExtendedFluidTank(FluidStack type, int capacity) {
|
||||||
{
|
if (type == null) {
|
||||||
if(type == null) {
|
|
||||||
type = FluidUtils.water;
|
type = FluidUtils.water;
|
||||||
changeType = true;
|
changeType = true;
|
||||||
}
|
}
|
||||||
@@ -21,97 +20,76 @@ public class ExtendedFluidTank implements IFluidTank
|
|||||||
fluid = FluidUtils.copy(type, 0);
|
fluid = FluidUtils.copy(type, 0);
|
||||||
this.capacity = capacity;
|
this.capacity = capacity;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ExtendedFluidTank(int capacity)
|
public ExtendedFluidTank(int capacity) {
|
||||||
{
|
|
||||||
this(null, capacity);
|
this(null, capacity);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public FluidStack getFluid()
|
public FluidStack getFluid() {
|
||||||
{
|
|
||||||
return fluid.copy();
|
return fluid.copy();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getCapacity()
|
public int getCapacity() {
|
||||||
{
|
|
||||||
return capacity;
|
return capacity;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean canAccept(FluidStack type)
|
public boolean canAccept(FluidStack type) {
|
||||||
{
|
|
||||||
return type == null || (fluid.amount == 0 && changeType) || fluid.isFluidEqual(type);
|
return type == null || (fluid.amount == 0 && changeType) || fluid.isFluidEqual(type);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int fill(FluidStack resource, boolean doFill)
|
public int fill(FluidStack resource, boolean doFill) {
|
||||||
{
|
if (resource == null) return 0;
|
||||||
if(resource == null)
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
if(!canAccept(resource))
|
if (!canAccept(resource)) return 0;
|
||||||
return 0;
|
|
||||||
|
int tofill = Math.min(getCapacity() - fluid.amount, resource.amount);
|
||||||
int tofill = Math.min(getCapacity()-fluid.amount, resource.amount);
|
if (doFill && tofill > 0) {
|
||||||
if(doFill && tofill > 0)
|
if (!fluid.isFluidEqual(resource)) fluid = FluidUtils.copy(resource, fluid.amount + tofill);
|
||||||
{
|
else fluid.amount += tofill;
|
||||||
if(!fluid.isFluidEqual(resource))
|
|
||||||
fluid = FluidUtils.copy(resource, fluid.amount+tofill);
|
|
||||||
else
|
|
||||||
fluid.amount+=tofill;
|
|
||||||
onLiquidChanged();
|
onLiquidChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
return tofill;
|
return tofill;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public FluidStack drain(int maxDrain, boolean doDrain)
|
public FluidStack drain(int maxDrain, boolean doDrain) {
|
||||||
{
|
if (fluid.amount == 0 || maxDrain <= 0) return null;
|
||||||
if(fluid.amount == 0 || maxDrain <= 0)
|
|
||||||
return null;
|
|
||||||
|
|
||||||
int todrain = Math.min(maxDrain, fluid.amount);
|
int todrain = Math.min(maxDrain, fluid.amount);
|
||||||
if(doDrain && todrain > 0)
|
if (doDrain && todrain > 0) {
|
||||||
{
|
fluid.amount -= todrain;
|
||||||
fluid.amount-=todrain;
|
|
||||||
onLiquidChanged();
|
onLiquidChanged();
|
||||||
}
|
}
|
||||||
return FluidUtils.copy(fluid, todrain);
|
return FluidUtils.copy(fluid, todrain);
|
||||||
}
|
}
|
||||||
|
|
||||||
public FluidStack drain(FluidStack resource, boolean doDrain)
|
public FluidStack drain(FluidStack resource, boolean doDrain) {
|
||||||
{
|
if (resource == null || !resource.isFluidEqual(fluid)) return null;
|
||||||
if (resource == null || !resource.isFluidEqual(fluid))
|
|
||||||
return null;
|
|
||||||
|
|
||||||
return drain(resource.amount, doDrain);
|
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);
|
fluid = FluidUtils.read(tag);
|
||||||
}
|
}
|
||||||
|
|
||||||
public NBTTagCompound toTag()
|
public NBTTagCompound toTag() {
|
||||||
{
|
|
||||||
return FluidUtils.write(fluid, new NBTTagCompound());
|
return FluidUtils.write(fluid, new NBTTagCompound());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getFluidAmount()
|
public int getFluidAmount() {
|
||||||
{
|
|
||||||
return fluid.amount;
|
return fluid.amount;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public FluidTankInfo getInfo()
|
public FluidTankInfo getInfo() {
|
||||||
{
|
|
||||||
return new FluidTankInfo(this);
|
return new FluidTankInfo(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,6 +1,5 @@
|
|||||||
package codechicken.core.fluid;
|
package codechicken.core.fluid;
|
||||||
|
|
||||||
import codechicken.lib.inventory.InventoryUtils;
|
|
||||||
import net.minecraft.entity.player.EntityPlayer;
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.nbt.NBTTagCompound;
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
@@ -11,87 +10,75 @@ import net.minecraftforge.fluids.FluidRegistry;
|
|||||||
import net.minecraftforge.fluids.FluidStack;
|
import net.minecraftforge.fluids.FluidStack;
|
||||||
import net.minecraftforge.fluids.IFluidHandler;
|
import net.minecraftforge.fluids.IFluidHandler;
|
||||||
|
|
||||||
public class FluidUtils
|
import codechicken.lib.inventory.InventoryUtils;
|
||||||
{
|
|
||||||
|
public class FluidUtils {
|
||||||
|
|
||||||
public static int B = FluidContainerRegistry.BUCKET_VOLUME;
|
public static int B = FluidContainerRegistry.BUCKET_VOLUME;
|
||||||
public static FluidStack water = new FluidStack(FluidRegistry.WATER, 1000);
|
public static FluidStack water = new FluidStack(FluidRegistry.WATER, 1000);
|
||||||
public static FluidStack lava = new FluidStack(FluidRegistry.LAVA, 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();
|
ItemStack stack = player.getCurrentEquippedItem();
|
||||||
FluidStack liquid = FluidContainerRegistry.getFluidForFilledItem(stack);
|
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;
|
return false;
|
||||||
|
|
||||||
if(tank.fill(ForgeDirection.UNKNOWN, liquid, false) != liquid.amount && !player.capabilities.isCreativeMode)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
tank.fill(ForgeDirection.UNKNOWN, liquid, true);
|
tank.fill(ForgeDirection.UNKNOWN, liquid, true);
|
||||||
|
|
||||||
if(!player.capabilities.isCreativeMode)
|
if (!player.capabilities.isCreativeMode)
|
||||||
InventoryUtils.consumeItem(player.inventory, player.inventory.currentItem);
|
InventoryUtils.consumeItem(player.inventory, player.inventory.currentItem);
|
||||||
|
|
||||||
player.inventoryContainer.detectAndSendChanges();
|
player.inventoryContainer.detectAndSendChanges();
|
||||||
return true;
|
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();
|
ItemStack stack = player.getCurrentEquippedItem();
|
||||||
|
|
||||||
if(!FluidContainerRegistry.isEmptyContainer(stack))
|
if (!FluidContainerRegistry.isEmptyContainer(stack)) return false;
|
||||||
return false;
|
|
||||||
|
|
||||||
ItemStack filled = FluidContainerRegistry.fillFluidContainer(tankLiquid, stack);
|
ItemStack filled = FluidContainerRegistry.fillFluidContainer(tankLiquid, stack);
|
||||||
FluidStack liquid = FluidContainerRegistry.getFluidForFilledItem(filled);
|
FluidStack liquid = FluidContainerRegistry.getFluidForFilledItem(filled);
|
||||||
|
|
||||||
if(liquid == null || filled == null)
|
if (liquid == null || filled == null) return false;
|
||||||
return false;
|
|
||||||
|
|
||||||
tank.drain(ForgeDirection.UNKNOWN, liquid.amount, true);
|
tank.drain(ForgeDirection.UNKNOWN, liquid.amount, true);
|
||||||
|
|
||||||
if(!player.capabilities.isCreativeMode)
|
if (!player.capabilities.isCreativeMode) {
|
||||||
{
|
if (stack.stackSize == 1) player.inventory.setInventorySlotContents(player.inventory.currentItem, filled);
|
||||||
if(stack.stackSize == 1)
|
else if (player.inventory.addItemStackToInventory(filled)) stack.stackSize--;
|
||||||
player.inventory.setInventorySlotContents(player.inventory.currentItem, filled);
|
else return false;
|
||||||
else if(player.inventory.addItemStackToInventory(filled))
|
|
||||||
stack.stackSize--;
|
|
||||||
else
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
player.inventoryContainer.detectAndSendChanges();
|
player.inventoryContainer.detectAndSendChanges();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static FluidStack copy(FluidStack liquid, int quantity)
|
public static FluidStack copy(FluidStack liquid, int quantity) {
|
||||||
{
|
|
||||||
liquid = liquid.copy();
|
liquid = liquid.copy();
|
||||||
liquid.amount = quantity;
|
liquid.amount = quantity;
|
||||||
return liquid;
|
return liquid;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static FluidStack read(NBTTagCompound tag)
|
public static FluidStack read(NBTTagCompound tag) {
|
||||||
{
|
|
||||||
FluidStack stack = FluidStack.loadFluidStackFromNBT(tag);
|
FluidStack stack = FluidStack.loadFluidStackFromNBT(tag);
|
||||||
return stack != null ? stack : FluidUtils.emptyFluid();
|
return stack != null ? stack : FluidUtils.emptyFluid();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static NBTTagCompound write(FluidStack fluid, NBTTagCompound tag)
|
public static NBTTagCompound write(FluidStack fluid, NBTTagCompound tag) {
|
||||||
{
|
return fluid == null || fluid.getFluid() == null ? new NBTTagCompound()
|
||||||
return fluid == null || fluid.getFluid() == null ? new NBTTagCompound() : fluid.writeToNBT(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();
|
Fluid fluid = stack.getFluid();
|
||||||
if(fluid == null)
|
if (fluid == null) return 0;
|
||||||
return 0;
|
|
||||||
int light = fluid.getLuminosity(stack);
|
int light = fluid.getLuminosity(stack);
|
||||||
if(fluid.isGaseous())
|
if (fluid.isGaseous()) light = (int) (light * density);
|
||||||
light=(int)(light*density);
|
|
||||||
return light;
|
return light;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,29 +4,25 @@ import net.minecraftforge.common.util.ForgeDirection;
|
|||||||
import net.minecraftforge.fluids.FluidStack;
|
import net.minecraftforge.fluids.FluidStack;
|
||||||
import net.minecraftforge.fluids.IFluidHandler;
|
import net.minecraftforge.fluids.IFluidHandler;
|
||||||
|
|
||||||
public class TankAccess
|
public class TankAccess {
|
||||||
{
|
|
||||||
public IFluidHandler tank;
|
public IFluidHandler tank;
|
||||||
public ForgeDirection side;
|
public ForgeDirection side;
|
||||||
|
|
||||||
public TankAccess(IFluidHandler tank, ForgeDirection side)
|
public TankAccess(IFluidHandler tank, ForgeDirection side) {
|
||||||
{
|
|
||||||
this.tank = tank;
|
this.tank = tank;
|
||||||
this.side = side;
|
this.side = side;
|
||||||
}
|
}
|
||||||
|
|
||||||
public TankAccess(IFluidHandler tank, int side)
|
public TankAccess(IFluidHandler tank, int side) {
|
||||||
{
|
|
||||||
this(tank, ForgeDirection.getOrientation(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);
|
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);
|
return tank.drain(side, maxDrain, doDrain);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,20 +1,20 @@
|
|||||||
package codechicken.core.gui;
|
package codechicken.core.gui;
|
||||||
|
|
||||||
import com.google.common.base.Objects;
|
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.TreeMap;
|
import java.util.TreeMap;
|
||||||
|
|
||||||
public class ClickCounter<T>
|
import com.google.common.base.Objects;
|
||||||
{
|
|
||||||
public class ClickCount
|
public class ClickCounter<T> {
|
||||||
{
|
|
||||||
|
public class ClickCount {
|
||||||
|
|
||||||
public T clicked;
|
public T clicked;
|
||||||
public long time;
|
public long time;
|
||||||
public int count;
|
public int count;
|
||||||
|
|
||||||
public boolean update(T clicked) {
|
public boolean update(T clicked) {
|
||||||
if(!Objects.equal(this.clicked, clicked)) {
|
if (!Objects.equal(this.clicked, clicked)) {
|
||||||
this.clicked = clicked;
|
this.clicked = clicked;
|
||||||
count = 0;
|
count = 0;
|
||||||
time = Long.MIN_VALUE;
|
time = Long.MIN_VALUE;
|
||||||
@@ -28,8 +28,7 @@ public class ClickCounter<T>
|
|||||||
|
|
||||||
public ClickCount getCount(int button) {
|
public ClickCount getCount(int button) {
|
||||||
ClickCount c = buttons.get(button);
|
ClickCount c = buttons.get(button);
|
||||||
if(c == null)
|
if (c == null) buttons.put(button, c = new ClickCount());
|
||||||
buttons.put(button, c = new ClickCount());
|
|
||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -40,14 +39,11 @@ public class ClickCounter<T>
|
|||||||
|
|
||||||
public int mouseUp(T clicked, int button) {
|
public int mouseUp(T clicked, int button) {
|
||||||
ClickCount c = getCount(button);
|
ClickCount c = getCount(button);
|
||||||
if(!c.update(clicked))
|
if (!c.update(clicked)) return 0;
|
||||||
return 0;
|
|
||||||
|
|
||||||
long time = System.currentTimeMillis();
|
long time = System.currentTimeMillis();
|
||||||
if(time-c.time < 500)
|
if (time - c.time < 500) c.count++;
|
||||||
c.count++;
|
else c.count = 1;
|
||||||
else
|
|
||||||
c.count = 1;
|
|
||||||
c.time = time;
|
c.time = time;
|
||||||
return c.count;
|
return c.count;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,13 +1,13 @@
|
|||||||
package codechicken.core.gui;
|
package codechicken.core.gui;
|
||||||
|
|
||||||
import net.minecraft.client.Minecraft;
|
import net.minecraft.client.Minecraft;
|
||||||
|
|
||||||
import net.minecraft.client.audio.PositionedSoundRecord;
|
import net.minecraft.client.audio.PositionedSoundRecord;
|
||||||
import net.minecraft.util.ResourceLocation;
|
import net.minecraft.util.ResourceLocation;
|
||||||
|
|
||||||
import org.lwjgl.opengl.GL11;
|
import org.lwjgl.opengl.GL11;
|
||||||
|
|
||||||
public class GuiCCButton extends GuiWidget
|
public class GuiCCButton extends GuiWidget {
|
||||||
{
|
|
||||||
public String text;
|
public String text;
|
||||||
public String actionCommand;
|
public String actionCommand;
|
||||||
private boolean isEnabled = true;
|
private boolean isEnabled = true;
|
||||||
@@ -34,28 +34,34 @@ public class GuiCCButton extends GuiWidget
|
|||||||
public void mouseClicked(int x, int y, int button) {
|
public void mouseClicked(int x, int y, int button) {
|
||||||
if (isEnabled && pointInside(x, y) && actionCommand != null) {
|
if (isEnabled && pointInside(x, y) && actionCommand != null) {
|
||||||
sendAction(actionCommand, button);
|
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
|
@Override
|
||||||
public void draw(int mousex, int mousey, float frame) {
|
public void draw(int mousex, int mousey, float frame) {
|
||||||
if (!visible)
|
if (!visible) return;
|
||||||
return;
|
|
||||||
|
|
||||||
drawButtonTex(mousex, mousey);
|
drawButtonTex(mousex, mousey);
|
||||||
if(text != null)
|
if (text != null) drawText(mousex, mousey);
|
||||||
drawText(mousex, mousey);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void drawButtonTex(int mousex, int mousey) {
|
public void drawButtonTex(int mousex, int mousey) {
|
||||||
GL11.glColor4f(1, 1, 1, 1);
|
GL11.glColor4f(1, 1, 1, 1);
|
||||||
renderEngine.bindTexture(guiTex);
|
renderEngine.bindTexture(guiTex);
|
||||||
int state = getButtonTex(mousex, mousey);
|
int state = getButtonTex(mousex, mousey);
|
||||||
drawTexturedModalRect(x, y, 0, 46 + state * 20, width / 2, height / 2);//top left
|
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 + 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, y + height / 2, 0, 46 + state * 20 + 20 - height / 2, width / 2, height / 2); // bottom
|
||||||
drawTexturedModalRect(x + width / 2, y + height / 2, 200 - width / 2, 46 + state * 20 + 20 - height / 2, width / 2, height / 2);//bottom right
|
// 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) {
|
public int getButtonTex(int mousex, int mousey) {
|
||||||
|
|||||||
@@ -5,184 +5,145 @@ import net.minecraft.util.ChatAllowedCharacters;
|
|||||||
|
|
||||||
import org.lwjgl.input.Keyboard;
|
import org.lwjgl.input.Keyboard;
|
||||||
|
|
||||||
public class GuiCCTextField extends GuiWidget
|
public class GuiCCTextField extends GuiWidget {
|
||||||
{
|
|
||||||
private String text;
|
private String text;
|
||||||
private boolean isFocused;
|
private boolean isFocused;
|
||||||
private boolean isEnabled;
|
private boolean isEnabled;
|
||||||
|
|
||||||
public int maxStringLength;
|
public int maxStringLength;
|
||||||
public int cursorCounter;
|
public int cursorCounter;
|
||||||
public String actionCommand;
|
public String actionCommand;
|
||||||
|
|
||||||
private String allowedCharacters;
|
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);
|
super(x, y, width, height);
|
||||||
isFocused = false;
|
isFocused = false;
|
||||||
isEnabled = true;
|
isEnabled = true;
|
||||||
this.text = text;
|
this.text = text;
|
||||||
}
|
}
|
||||||
|
|
||||||
public GuiCCTextField setActionCommand(String s)
|
public GuiCCTextField setActionCommand(String s) {
|
||||||
{
|
|
||||||
actionCommand = s;
|
actionCommand = s;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setText(String s)
|
public void setText(String s) {
|
||||||
{
|
if (s.equals(text)) return;
|
||||||
if(s.equals(text))
|
|
||||||
return;
|
|
||||||
|
|
||||||
String oldText = text;
|
String oldText = text;
|
||||||
text = s;
|
text = s;
|
||||||
onTextChanged(oldText);
|
onTextChanged(oldText);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onTextChanged(String oldText)
|
public void onTextChanged(String oldText) {}
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
public final String getText()
|
public final String getText() {
|
||||||
{
|
|
||||||
return text;
|
return text;
|
||||||
}
|
}
|
||||||
|
|
||||||
public final boolean isEnabled()
|
public final boolean isEnabled() {
|
||||||
{
|
|
||||||
return isEnabled;
|
return isEnabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setEnabled(boolean b)
|
public void setEnabled(boolean b) {
|
||||||
{
|
|
||||||
isEnabled = b;
|
isEnabled = b;
|
||||||
if(!isEnabled && isFocused)
|
if (!isEnabled && isFocused) setFocused(false);
|
||||||
setFocused(false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public final boolean isFocused()
|
public final boolean isFocused() {
|
||||||
{
|
|
||||||
return isFocused;
|
return isFocused;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void update()
|
public void update() {
|
||||||
{
|
|
||||||
cursorCounter++;
|
cursorCounter++;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void keyTyped(char c, int keycode)
|
public void keyTyped(char c, int keycode) {
|
||||||
{
|
if (!isEnabled || !isFocused) return;
|
||||||
if(!isEnabled || !isFocused)
|
|
||||||
return;
|
|
||||||
|
|
||||||
/*if(c == '\t')//tab
|
/*
|
||||||
{
|
* if(c == '\t')//tab { parentGuiScreen.selectNextField(); }
|
||||||
parentGuiScreen.selectNextField();
|
*/
|
||||||
}*/
|
if (c == '\026') // paste
|
||||||
if(c == '\026')//paste
|
|
||||||
{
|
{
|
||||||
String s = GuiScreen.getClipboardString();
|
String s = GuiScreen.getClipboardString();
|
||||||
if(s == null || s.equals(""))
|
if (s == null || s.equals("")) return;
|
||||||
return;
|
|
||||||
|
|
||||||
for(int i = 0; i < s.length(); i++)
|
for (int i = 0; i < s.length(); i++) {
|
||||||
{
|
if (text.length() == maxStringLength) return;
|
||||||
if(text.length() == maxStringLength)
|
|
||||||
return;
|
|
||||||
|
|
||||||
char tc = s.charAt(i);
|
char tc = s.charAt(i);
|
||||||
if(canAddChar(tc))
|
if (canAddChar(tc)) setText(text + tc);
|
||||||
setText(text + tc);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(keycode == Keyboard.KEY_RETURN)
|
if (keycode == Keyboard.KEY_RETURN) {
|
||||||
{
|
|
||||||
setFocused(false);
|
setFocused(false);
|
||||||
sendAction(actionCommand, getText());
|
sendAction(actionCommand, getText());
|
||||||
}
|
}
|
||||||
|
|
||||||
if(keycode == Keyboard.KEY_BACK && text.length() > 0)
|
if (keycode == Keyboard.KEY_BACK && text.length() > 0) setText(text.substring(0, text.length() - 1));
|
||||||
setText(text.substring(0, text.length() - 1));
|
|
||||||
|
|
||||||
if((text.length() < maxStringLength || maxStringLength == 0) && canAddChar(c))
|
if ((text.length() < maxStringLength || maxStringLength == 0) && canAddChar(c)) setText(text + c);
|
||||||
setText(text + c);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean canAddChar(char c)
|
public boolean canAddChar(char c) {
|
||||||
{
|
return allowedCharacters == null ? ChatAllowedCharacters.isAllowedCharacter(c)
|
||||||
return allowedCharacters == null ? ChatAllowedCharacters.isAllowedCharacter(c) : allowedCharacters.indexOf(c) >= 0;
|
: allowedCharacters.indexOf(c) >= 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void mouseClicked(int x, int y, int button)
|
public void mouseClicked(int x, int y, int button) {
|
||||||
{
|
if (isEnabled && pointInside(x, y)) {
|
||||||
if(isEnabled && pointInside(x, y))
|
|
||||||
{
|
|
||||||
setFocused(true);
|
setFocused(true);
|
||||||
if(button == 1)
|
if (button == 1) setText("");
|
||||||
setText("");
|
} else setFocused(false);
|
||||||
}
|
|
||||||
else
|
|
||||||
setFocused(false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setFocused(boolean focus)
|
public void setFocused(boolean focus) {
|
||||||
{
|
if (focus == isFocused) return;
|
||||||
if(focus == isFocused)
|
|
||||||
return;
|
|
||||||
isFocused = focus;
|
isFocused = focus;
|
||||||
onFocusChanged();
|
onFocusChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onFocusChanged()
|
public void onFocusChanged() {
|
||||||
{
|
if (isFocused) cursorCounter = 0;
|
||||||
if(isFocused)
|
|
||||||
cursorCounter = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void draw(int i, int j, float f)
|
public void draw(int i, int j, float f) {
|
||||||
{
|
|
||||||
drawBackground();
|
drawBackground();
|
||||||
drawText();
|
drawText();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void drawBackground()
|
public void drawBackground() {
|
||||||
{
|
|
||||||
drawRect(x - 1, y - 1, x + width + 1, y + height + 1, 0xffa0a0a0);
|
drawRect(x - 1, y - 1, x + width + 1, y + height + 1, 0xffa0a0a0);
|
||||||
drawRect(x, y, x + width, y + height, 0xff000000);
|
drawRect(x, y, x + width, y + height, 0xff000000);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getDrawText()
|
public String getDrawText() {
|
||||||
{
|
|
||||||
String s = getText();
|
String s = getText();
|
||||||
if(isEnabled && isFocused && (cursorCounter / 6) % 2 == 0)
|
if (isEnabled && isFocused && (cursorCounter / 6) % 2 == 0) s += "_";
|
||||||
s+="_";
|
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void drawText()
|
public void drawText() {
|
||||||
{
|
drawString(fontRenderer, getDrawText(), x + 4, y + height / 2 - 4, getTextColour());
|
||||||
drawString(fontRenderer, getDrawText(), x + 4, y + height/2 - 4, getTextColour());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getTextColour()
|
public int getTextColour() {
|
||||||
{
|
|
||||||
return isEnabled ? 0xe0e0e0 : 0x707070;
|
return isEnabled ? 0xe0e0e0 : 0x707070;
|
||||||
}
|
}
|
||||||
|
|
||||||
public GuiCCTextField setMaxStringLength(int i)
|
public GuiCCTextField setMaxStringLength(int i) {
|
||||||
{
|
|
||||||
maxStringLength = i;
|
maxStringLength = i;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public GuiCCTextField setAllowedCharacters(String s)
|
public GuiCCTextField setAllowedCharacters(String s) {
|
||||||
{
|
|
||||||
allowedCharacters = s;
|
allowedCharacters = s;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,41 +3,37 @@ package codechicken.core.gui;
|
|||||||
import java.awt.Point;
|
import java.awt.Point;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
import codechicken.lib.gui.GuiDraw;
|
|
||||||
import org.lwjgl.input.Mouse;
|
|
||||||
import org.lwjgl.opengl.GL11;
|
|
||||||
|
|
||||||
import net.minecraft.client.Minecraft;
|
import net.minecraft.client.Minecraft;
|
||||||
import net.minecraft.client.gui.GuiScreen;
|
import net.minecraft.client.gui.GuiScreen;
|
||||||
|
|
||||||
public class GuiScreenWidget extends GuiScreen implements IGuiActionListener
|
import org.lwjgl.input.Mouse;
|
||||||
{
|
import org.lwjgl.opengl.GL11;
|
||||||
|
|
||||||
|
import codechicken.lib.gui.GuiDraw;
|
||||||
|
|
||||||
|
public class GuiScreenWidget extends GuiScreen implements IGuiActionListener {
|
||||||
|
|
||||||
public ArrayList<GuiWidget> widgets = new ArrayList<GuiWidget>();
|
public ArrayList<GuiWidget> widgets = new ArrayList<GuiWidget>();
|
||||||
public int xSize, ySize, guiTop, guiLeft;
|
public int xSize, ySize, guiTop, guiLeft;
|
||||||
|
|
||||||
public GuiScreenWidget()
|
public GuiScreenWidget() {
|
||||||
{
|
|
||||||
this(176, 166);
|
this(176, 166);
|
||||||
}
|
}
|
||||||
|
|
||||||
public GuiScreenWidget(int xSize, int ySize)
|
public GuiScreenWidget(int xSize, int ySize) {
|
||||||
{
|
|
||||||
super();
|
super();
|
||||||
this.xSize = xSize;
|
this.xSize = xSize;
|
||||||
this.ySize = ySize;
|
this.ySize = ySize;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void initGui()
|
public void initGui() {
|
||||||
{
|
|
||||||
guiTop = (height - ySize) / 2;
|
guiTop = (height - ySize) / 2;
|
||||||
guiLeft = (width - xSize) / 2;
|
guiLeft = (width - xSize) / 2;
|
||||||
if(!widgets.isEmpty())
|
if (!widgets.isEmpty()) resize();
|
||||||
resize();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void reset()
|
public void reset() {
|
||||||
{
|
|
||||||
widgets.clear();
|
widgets.clear();
|
||||||
initGui();
|
initGui();
|
||||||
addWidgets();
|
addWidgets();
|
||||||
@@ -45,106 +41,78 @@ public class GuiScreenWidget extends GuiScreen implements IGuiActionListener
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setWorldAndResolution(Minecraft mc, int i, int j)
|
public void setWorldAndResolution(Minecraft mc, int i, int j) {
|
||||||
{
|
|
||||||
boolean init = this.mc == null;
|
boolean init = this.mc == null;
|
||||||
super.setWorldAndResolution(mc, i, j);
|
super.setWorldAndResolution(mc, i, j);
|
||||||
if(init) {
|
if (init) {
|
||||||
addWidgets();
|
addWidgets();
|
||||||
resize();
|
resize();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void add(GuiWidget widget)
|
public void add(GuiWidget widget) {
|
||||||
{
|
|
||||||
widgets.add(widget);
|
widgets.add(widget);
|
||||||
widget.onAdded(this);
|
widget.onAdded(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void drawScreen(int mousex, int mousey, float f)
|
public void drawScreen(int mousex, int mousey, float f) {
|
||||||
{
|
|
||||||
GL11.glTranslated(guiLeft, guiTop, 0);
|
GL11.glTranslated(guiLeft, guiTop, 0);
|
||||||
drawBackground();
|
drawBackground();
|
||||||
for(GuiWidget widget : widgets)
|
for (GuiWidget widget : widgets) widget.draw(mousex - guiLeft, mousey - guiTop, f);
|
||||||
widget.draw(mousex-guiLeft, mousey-guiTop, f);
|
|
||||||
drawForeground();
|
drawForeground();
|
||||||
GL11.glTranslated(-guiLeft, -guiTop, 0);
|
GL11.glTranslated(-guiLeft, -guiTop, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void drawBackground()
|
public void drawBackground() {}
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
public void drawForeground()
|
public void drawForeground() {}
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void mouseClicked(int x, int y, int button)
|
protected void mouseClicked(int x, int y, int button) {
|
||||||
{
|
|
||||||
super.mouseClicked(x, y, button);
|
super.mouseClicked(x, y, button);
|
||||||
for(GuiWidget widget : widgets)
|
for (GuiWidget widget : widgets) widget.mouseClicked(x - guiLeft, y - guiTop, button);
|
||||||
widget.mouseClicked(x-guiLeft, y-guiTop, button);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void mouseMovedOrUp(int x, int y, int button)
|
protected void mouseMovedOrUp(int x, int y, int button) {
|
||||||
{
|
|
||||||
super.mouseMovedOrUp(x, y, button);
|
super.mouseMovedOrUp(x, y, button);
|
||||||
for(GuiWidget widget : widgets)
|
for (GuiWidget widget : widgets) widget.mouseMovedOrUp(x - guiLeft, y - guiTop, button);
|
||||||
widget.mouseMovedOrUp(x-guiLeft, y-guiTop, button);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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);
|
super.mouseClickMove(x, y, button, time);
|
||||||
for(GuiWidget widget : widgets)
|
for (GuiWidget widget : widgets) widget.mouseDragged(x - guiLeft, y - guiTop, button, time);
|
||||||
widget.mouseDragged(x-guiLeft, y-guiTop, button, time);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateScreen()
|
public void updateScreen() {
|
||||||
{
|
|
||||||
super.updateScreen();
|
super.updateScreen();
|
||||||
if(mc.currentScreen == this)
|
if (mc.currentScreen == this) for (GuiWidget widget : widgets) widget.update();
|
||||||
for(GuiWidget widget : widgets)
|
|
||||||
widget.update();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void keyTyped(char c, int keycode)
|
public void keyTyped(char c, int keycode) {
|
||||||
{
|
|
||||||
super.keyTyped(c, keycode);
|
super.keyTyped(c, keycode);
|
||||||
for(GuiWidget widget : widgets)
|
for (GuiWidget widget : widgets) widget.keyTyped(c, keycode);
|
||||||
widget.keyTyped(c, keycode);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handleMouseInput()
|
public void handleMouseInput() {
|
||||||
{
|
|
||||||
super.handleMouseInput();
|
super.handleMouseInput();
|
||||||
int i = Mouse.getEventDWheel();
|
int i = Mouse.getEventDWheel();
|
||||||
if(i != 0)
|
if (i != 0) {
|
||||||
{
|
|
||||||
Point p = GuiDraw.getMousePosition();
|
Point p = GuiDraw.getMousePosition();
|
||||||
int scroll = i > 0 ? 1 : -1;
|
int scroll = i > 0 ? 1 : -1;
|
||||||
for(GuiWidget widget : widgets)
|
for (GuiWidget widget : widgets) widget.mouseScrolled(p.x, p.y, scroll);
|
||||||
widget.mouseScrolled(p.x, p.y, scroll);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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() {}
|
||||||
{
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -1,12 +1,13 @@
|
|||||||
package codechicken.core.gui;
|
package codechicken.core.gui;
|
||||||
|
|
||||||
|
import java.awt.Dimension;
|
||||||
|
import java.awt.Rectangle;
|
||||||
|
|
||||||
import codechicken.lib.math.MathHelper;
|
import codechicken.lib.math.MathHelper;
|
||||||
import codechicken.lib.vec.Rectangle4i;
|
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 int scrollclicky = -1;
|
||||||
protected float scrollpercent;
|
protected float scrollpercent;
|
||||||
protected int scrollmousey;
|
protected int scrollmousey;
|
||||||
@@ -29,7 +30,11 @@ public abstract class GuiScrollPane extends GuiWidget
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Rectangle windowBounds() {
|
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();
|
public abstract int contentHeight();
|
||||||
@@ -42,8 +47,10 @@ public abstract class GuiScrollPane extends GuiWidget
|
|||||||
public Rectangle scrollbarBounds() {
|
public Rectangle scrollbarBounds() {
|
||||||
Dimension dim = scrollbarDim();
|
Dimension dim = scrollbarDim();
|
||||||
return new Rectangle(
|
return new Rectangle(
|
||||||
x + width - dim.width, y + (int) ((height - dim.height) * percentscrolled + 0.4999),
|
x + width - dim.width,
|
||||||
dim.width, dim.height);
|
y + (int) ((height - dim.height) * percentscrolled + 0.4999),
|
||||||
|
dim.width,
|
||||||
|
dim.height);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void scrollUp() {
|
public void scrollUp() {
|
||||||
@@ -55,7 +62,7 @@ public abstract class GuiScrollPane extends GuiWidget
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void scroll(int i) {
|
public void scroll(int i) {
|
||||||
percentscrolled += i * height / (float)(2*contentHeight());
|
percentscrolled += i * height / (float) (2 * contentHeight());
|
||||||
calculatePercentScrolled();
|
calculatePercentScrolled();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -102,15 +109,13 @@ public abstract class GuiScrollPane extends GuiWidget
|
|||||||
Rectangle w = windowBounds();
|
Rectangle w = windowBounds();
|
||||||
int barempty = height - sbar.height;
|
int barempty = height - sbar.height;
|
||||||
|
|
||||||
if (button == 0 &&
|
if (button == 0 && sbar.height < height && // the scroll bar can move (not full length)
|
||||||
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
|
||||||
mx >= sbar.x && mx <= sbar.x + sbar.width &&
|
|
||||||
my >= y && my <= y + height)//in the scroll pane
|
|
||||||
{
|
{
|
||||||
if (my < sbar.y) {
|
if (my < sbar.y) {
|
||||||
percentscrolled = (my - y) / (float) barempty;
|
percentscrolled = (my - y) / (float) barempty;
|
||||||
calculatePercentScrolled();
|
calculatePercentScrolled();
|
||||||
} else if (my > sbar.y+sbar.height) {
|
} else if (my > sbar.y + sbar.height) {
|
||||||
percentscrolled = (my - y - sbar.height + 1) / (float) barempty;
|
percentscrolled = (my - y - sbar.height + 1) / (float) barempty;
|
||||||
calculatePercentScrolled();
|
calculatePercentScrolled();
|
||||||
} else {
|
} else {
|
||||||
@@ -118,29 +123,25 @@ public abstract class GuiScrollPane extends GuiWidget
|
|||||||
scrollpercent = percentscrolled;
|
scrollpercent = percentscrolled;
|
||||||
scrollmousey = my;
|
scrollmousey = my;
|
||||||
}
|
}
|
||||||
} else if (w.contains(mx, my))
|
} else if (w.contains(mx, my)) slotDown(mx - w.x, my - w.y + scrolledPixels(), button);
|
||||||
slotDown(mx - w.x, my - w.y + scrolledPixels(), button);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Mouse down on slot area
|
* Mouse down on slot area Coordinates relative to slot content area
|
||||||
* Coordinates relative to slot content area
|
|
||||||
*/
|
*/
|
||||||
public void slotDown(int mx, int my, int button) {}
|
public void slotDown(int mx, int my, int button) {}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Mouse up on slot area
|
* Mouse up on slot area Coordinates relative to slot content area
|
||||||
* Coordinates relative to slot content area
|
|
||||||
*/
|
*/
|
||||||
public void slotUp(int mx, int my, int button) {}
|
public void slotUp(int mx, int my, int button) {}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void mouseMovedOrUp(int mx, int my, int button) {
|
public void mouseMovedOrUp(int mx, int my, int button) {
|
||||||
Rectangle w = windowBounds();
|
Rectangle w = windowBounds();
|
||||||
if (isScrolling() && button == 0)//we were scrolling and we released mouse
|
if (isScrolling() && button == 0) // we were scrolling and we released mouse
|
||||||
scrollclicky = -1;
|
scrollclicky = -1;
|
||||||
else if (w.contains(mx, my))
|
else if (w.contains(mx, my)) slotUp(mx - w.x, my - w.y + scrolledPixels(), button);
|
||||||
slotUp(mx - w.x, my - w.y + scrolledPixels(), button);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -151,12 +152,9 @@ public abstract class GuiScrollPane extends GuiWidget
|
|||||||
int barupallowed = (int) ((height - sbarh) * scrollpercent + 0.5);
|
int barupallowed = (int) ((height - sbarh) * scrollpercent + 0.5);
|
||||||
int bardownallowed = (height - sbarh) - barupallowed;
|
int bardownallowed = (height - sbarh) - barupallowed;
|
||||||
|
|
||||||
if (-scrolldiff > barupallowed)
|
if (-scrolldiff > barupallowed) scrollmousey = scrollclicky - barupallowed;
|
||||||
scrollmousey = scrollclicky - barupallowed;
|
else if (scrolldiff > bardownallowed) scrollmousey = scrollclicky + bardownallowed;
|
||||||
else if (scrolldiff > bardownallowed)
|
else scrollmousey = mousey;
|
||||||
scrollmousey = scrollclicky + bardownallowed;
|
|
||||||
else
|
|
||||||
scrollmousey = mousey;
|
|
||||||
|
|
||||||
calculatePercentScrolled();
|
calculatePercentScrolled();
|
||||||
}
|
}
|
||||||
@@ -180,7 +178,7 @@ public abstract class GuiScrollPane extends GuiWidget
|
|||||||
public void draw(int mx, int my, float frame) {
|
public void draw(int mx, int my, float frame) {
|
||||||
Rectangle w = windowBounds();
|
Rectangle w = windowBounds();
|
||||||
drawBackground(frame);
|
drawBackground(frame);
|
||||||
drawContent(mx-w.x, my+scrolledPixels()-w.y, frame);
|
drawContent(mx - w.x, my + scrolledPixels() - w.y, frame);
|
||||||
drawOverlay(frame);
|
drawOverlay(frame);
|
||||||
drawScrollbar(frame);
|
drawScrollbar(frame);
|
||||||
}
|
}
|
||||||
@@ -192,24 +190,22 @@ public abstract class GuiScrollPane extends GuiWidget
|
|||||||
public abstract void drawContent(int mx, int my, float frame);
|
public abstract void drawContent(int mx, int my, float frame);
|
||||||
|
|
||||||
public void drawOverlay(float frame) {
|
public void drawOverlay(float frame) {
|
||||||
//outlines
|
// outlines
|
||||||
drawRect(x, y - 1, x + width, y, 0xffa0a0a0);//top
|
drawRect(x, y - 1, x + width, y, 0xffa0a0a0); // top
|
||||||
drawRect(x, y + height, x + width, y + height + 1, 0xffa0a0a0);//bottom
|
drawRect(x, y + height, x + width, y + height + 1, 0xffa0a0a0); // bottom
|
||||||
drawRect(x - 1, y - 1, x, y + height + 1, 0xffa0a0a0);//left
|
drawRect(x - 1, y - 1, x, y + height + 1, 0xffa0a0a0); // left
|
||||||
drawRect(x + width, y - 1, x + width + 1, y + height + 1, 0xffa0a0a0);//right
|
drawRect(x + width, y - 1, x + width + 1, y + height + 1, 0xffa0a0a0); // right
|
||||||
}
|
}
|
||||||
|
|
||||||
public void drawScrollbar(float frame) {
|
public void drawScrollbar(float frame) {
|
||||||
Rectangle r = scrollbarBounds();
|
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, 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, 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, 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 + 1, r.y + 1, r.x + r.width - 1, r.y + r.height - 1, 0xFFC6C6C6); // scrollbar
|
||||||
|
|
||||||
int algn = scrollbarGuideAlignment();
|
int algn = scrollbarGuideAlignment();
|
||||||
if (algn != 0)
|
if (algn != 0) drawRect(algn > 0 ? r.x + r.width : r.x - 1, y, r.x, y + height, 0xFF808080); // lineguide
|
||||||
drawRect(algn > 0 ? r.x + r.width : r.x - 1, y, r.x, y + height, 0xFF808080);//lineguide
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -1,11 +1,11 @@
|
|||||||
package codechicken.core.gui;
|
package codechicken.core.gui;
|
||||||
|
|
||||||
|
import java.awt.Rectangle;
|
||||||
|
|
||||||
import org.lwjgl.input.Keyboard;
|
import org.lwjgl.input.Keyboard;
|
||||||
|
|
||||||
import java.awt.*;
|
public abstract class GuiScrollSlot extends GuiScrollPane {
|
||||||
|
|
||||||
public abstract class GuiScrollSlot extends GuiScrollPane
|
|
||||||
{
|
|
||||||
protected String actionCommand;
|
protected String actionCommand;
|
||||||
public boolean focused;
|
public boolean focused;
|
||||||
protected ClickCounter<Integer> click = new ClickCounter<Integer>();
|
protected ClickCounter<Integer> click = new ClickCounter<Integer>();
|
||||||
@@ -40,13 +40,11 @@ public abstract class GuiScrollSlot extends GuiScrollPane
|
|||||||
|
|
||||||
protected abstract void drawSlot(int slot, int x, int y, int mx, int my, float frame);
|
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) {
|
public void setFocused(boolean focus) {
|
||||||
focused = focus;
|
focused = focus;
|
||||||
if (!focused)
|
if (!focused) unfocus();
|
||||||
unfocus();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -56,37 +54,34 @@ public abstract class GuiScrollSlot extends GuiScrollPane
|
|||||||
|
|
||||||
public int getSlotY(int slot) {
|
public int getSlotY(int slot) {
|
||||||
int h = 0;
|
int h = 0;
|
||||||
for(int i = 0; i < slot; i++)
|
for (int i = 0; i < slot; i++) h += getSlotHeight(i);
|
||||||
h+=getSlotHeight(i);
|
|
||||||
return h;
|
return h;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getSlot(int my) {
|
public int getSlot(int my) {
|
||||||
if (my < 0)
|
if (my < 0) return -1;
|
||||||
return -1;
|
|
||||||
|
|
||||||
int y = 0;
|
int y = 0;
|
||||||
for(int i = 0; i < getNumSlots(); i++) {
|
for (int i = 0; i < getNumSlots(); i++) {
|
||||||
int h = getSlotHeight(i);
|
int h = getSlotHeight(i);
|
||||||
if(my >= y && my < y+h)
|
if (my >= y && my < y + h) return i;
|
||||||
return i;
|
y += h;
|
||||||
y+=h;
|
|
||||||
}
|
}
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getClickedSlot(int my) {
|
public int getClickedSlot(int my) {
|
||||||
return getSlot(my-windowBounds().y+scrolledPixels());
|
return getSlot(my - windowBounds().y + scrolledPixels());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int scrolledPixels() {
|
public int scrolledPixels() {
|
||||||
int scrolled = super.scrolledPixels();
|
int scrolled = super.scrolledPixels();
|
||||||
if(!smoothScroll) {
|
if (!smoothScroll) {
|
||||||
int slot = getSlot(scrolled);
|
int slot = getSlot(scrolled);
|
||||||
int sloty = getSlotY(slot);
|
int sloty = getSlotY(slot);
|
||||||
int sloth = getSlotHeight(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;
|
return scrolled;
|
||||||
}
|
}
|
||||||
@@ -106,8 +101,7 @@ public abstract class GuiScrollSlot extends GuiScrollPane
|
|||||||
@Override
|
@Override
|
||||||
public Rectangle scrollbarBounds() {
|
public Rectangle scrollbarBounds() {
|
||||||
Rectangle r = super.scrollbarBounds();
|
Rectangle r = super.scrollbarBounds();
|
||||||
if(scrollbarAlignment() == -1)
|
if (scrollbarAlignment() == -1) r.x = x;
|
||||||
r.x = x;
|
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -125,21 +119,16 @@ public abstract class GuiScrollSlot extends GuiScrollPane
|
|||||||
public void slotUp(int mx, int my, int button) {
|
public void slotUp(int mx, int my, int button) {
|
||||||
int slot = getSlot(my);
|
int slot = getSlot(my);
|
||||||
int c = click.mouseUp(slot >= 0 ? slot : null, button);
|
int c = click.mouseUp(slot >= 0 ? slot : null, button);
|
||||||
if(c > 0 && slot >= 0)
|
if (c > 0 && slot >= 0) slotClicked(slot, button, mx, my - getSlotY(slot), c);
|
||||||
slotClicked(slot, button, mx, my-getSlotY(slot), c);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void keyTyped(char c, int keycode) {
|
public void keyTyped(char c, int keycode) {
|
||||||
if (!focused)
|
if (!focused) return;
|
||||||
return;
|
|
||||||
|
|
||||||
if (keycode == Keyboard.KEY_UP)
|
if (keycode == Keyboard.KEY_UP) selectPrev();
|
||||||
selectPrev();
|
if (keycode == Keyboard.KEY_DOWN) selectNext();
|
||||||
if (keycode == Keyboard.KEY_DOWN)
|
if (keycode == Keyboard.KEY_RETURN && actionCommand != null) sendAction(actionCommand);
|
||||||
selectNext();
|
|
||||||
if (keycode == Keyboard.KEY_RETURN && actionCommand != null)
|
|
||||||
sendAction(actionCommand);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -149,9 +138,9 @@ public abstract class GuiScrollSlot extends GuiScrollPane
|
|||||||
int y = 0;
|
int y = 0;
|
||||||
for (int slot = 0; slot < getNumSlots(); slot++) {
|
for (int slot = 0; slot < getNumSlots(); slot++) {
|
||||||
int h = getSlotHeight(slot);
|
int h = getSlotHeight(slot);
|
||||||
if (y+h > scrolled && y < scrolled+w.height)
|
if (y + h > scrolled && y < scrolled + w.height)
|
||||||
drawSlot(slot, w.x, w.y+y-scrolledPixels(), mx, my-y, frame);
|
drawSlot(slot, w.x, w.y + y - scrolledPixels(), mx, my - y, frame);
|
||||||
y+=h;
|
y += h;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -7,78 +7,58 @@ import net.minecraft.client.gui.GuiScreen;
|
|||||||
import net.minecraft.client.renderer.texture.TextureManager;
|
import net.minecraft.client.renderer.texture.TextureManager;
|
||||||
import net.minecraft.util.ResourceLocation;
|
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");
|
protected static final ResourceLocation guiTex = new ResourceLocation("textures/gui/widgets.png");
|
||||||
|
|
||||||
public GuiScreen parentScreen;
|
public GuiScreen parentScreen;
|
||||||
public TextureManager renderEngine;
|
public TextureManager renderEngine;
|
||||||
public FontRenderer fontRenderer;
|
public FontRenderer fontRenderer;
|
||||||
|
|
||||||
public int x;
|
public int x;
|
||||||
public int y;
|
public int y;
|
||||||
public int width;
|
public int width;
|
||||||
public int height;
|
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);
|
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.x = x;
|
||||||
this.y = y;
|
this.y = y;
|
||||||
this.width = width;
|
this.width = width;
|
||||||
this.height = height;
|
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;
|
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);
|
sendAction(parentScreen, actionCommand, params);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void sendAction(GuiScreen screen, String actionCommand, Object... params)
|
public static void sendAction(GuiScreen screen, String actionCommand, Object... params) {
|
||||||
{
|
if (actionCommand != null && screen instanceof IGuiActionListener)
|
||||||
if(actionCommand != null && screen instanceof IGuiActionListener)
|
|
||||||
((IGuiActionListener) screen).actionPerformed(actionCommand, params);
|
((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 mouseMovedOrUp(int x, int y, int button) {}
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
public void mouseDragged(int x, int y, int button, long time)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
public void update()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
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 draw(int mousex, int mousey, float frame) {}
|
||||||
{
|
|
||||||
}
|
public void keyTyped(char c, int keycode) {}
|
||||||
|
|
||||||
public void onAdded(GuiScreen s)
|
public void mouseScrolled(int x, int y, int scroll) {}
|
||||||
{
|
|
||||||
|
public void onAdded(GuiScreen s) {
|
||||||
Minecraft mc = Minecraft.getMinecraft();
|
Minecraft mc = Minecraft.getMinecraft();
|
||||||
parentScreen = s;
|
parentScreen = s;
|
||||||
renderEngine = mc.renderEngine;
|
renderEngine = mc.renderEngine;
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
package codechicken.core.gui;
|
package codechicken.core.gui;
|
||||||
|
|
||||||
public interface IGuiActionListener
|
public interface IGuiActionListener {
|
||||||
{
|
|
||||||
public void actionPerformed(String actionCommand, Object... params);
|
public void actionPerformed(String actionCommand, Object... params);
|
||||||
}
|
}
|
||||||
@@ -1,7 +1,8 @@
|
|||||||
package codechicken.core.internal;
|
package codechicken.core.internal;
|
||||||
|
|
||||||
import codechicken.core.CCUpdateChecker;
|
import net.minecraftforge.client.event.GuiScreenEvent;
|
||||||
|
|
||||||
|
import codechicken.core.CCUpdateChecker;
|
||||||
import codechicken.core.GuiModListScroll;
|
import codechicken.core.GuiModListScroll;
|
||||||
import cpw.mods.fml.client.GuiModList;
|
import cpw.mods.fml.client.GuiModList;
|
||||||
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
||||||
@@ -9,16 +10,15 @@ import cpw.mods.fml.common.gameevent.TickEvent;
|
|||||||
import cpw.mods.fml.common.gameevent.TickEvent.Phase;
|
import cpw.mods.fml.common.gameevent.TickEvent.Phase;
|
||||||
import cpw.mods.fml.relauncher.Side;
|
import cpw.mods.fml.relauncher.Side;
|
||||||
import cpw.mods.fml.relauncher.SideOnly;
|
import cpw.mods.fml.relauncher.SideOnly;
|
||||||
import net.minecraftforge.client.event.GuiScreenEvent;
|
|
||||||
|
|
||||||
public class CCCEventHandler
|
public class CCCEventHandler {
|
||||||
{
|
|
||||||
public static int renderTime;
|
public static int renderTime;
|
||||||
public static float renderFrame;
|
public static float renderFrame;
|
||||||
|
|
||||||
@SubscribeEvent
|
@SubscribeEvent
|
||||||
public void clientTick(TickEvent.ClientTickEvent event) {
|
public void clientTick(TickEvent.ClientTickEvent event) {
|
||||||
if(event.phase == Phase.END) {
|
if (event.phase == Phase.END) {
|
||||||
CCUpdateChecker.tick();
|
CCUpdateChecker.tick();
|
||||||
renderTime++;
|
renderTime++;
|
||||||
}
|
}
|
||||||
@@ -26,14 +26,12 @@ public class CCCEventHandler
|
|||||||
|
|
||||||
@SubscribeEvent
|
@SubscribeEvent
|
||||||
public void renderTick(TickEvent.RenderTickEvent event) {
|
public void renderTick(TickEvent.RenderTickEvent event) {
|
||||||
if(event.phase == Phase.START)
|
if (event.phase == Phase.START) renderFrame = event.renderTickTime;
|
||||||
renderFrame = event.renderTickTime;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@SubscribeEvent
|
@SubscribeEvent
|
||||||
@SideOnly(Side.CLIENT)
|
@SideOnly(Side.CLIENT)
|
||||||
public void posGuiRender(GuiScreenEvent.DrawScreenEvent.Post event) {
|
public void posGuiRender(GuiScreenEvent.DrawScreenEvent.Post event) {
|
||||||
if(event.gui instanceof GuiModList)
|
if (event.gui instanceof GuiModList) GuiModListScroll.draw((GuiModList) event.gui, event.mouseX, event.mouseY);
|
||||||
GuiModListScroll.draw((GuiModList)event.gui, event.mouseX, event.mouseY);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -3,125 +3,98 @@ package codechicken.core.inventory;
|
|||||||
import java.awt.Point;
|
import java.awt.Point;
|
||||||
import java.util.ArrayList;
|
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 net.minecraft.client.Minecraft;
|
import net.minecraft.client.Minecraft;
|
||||||
import net.minecraft.client.gui.inventory.GuiContainer;
|
import net.minecraft.client.gui.inventory.GuiContainer;
|
||||||
import net.minecraft.inventory.Container;
|
import net.minecraft.inventory.Container;
|
||||||
|
|
||||||
public class GuiContainerWidget extends GuiContainer implements IGuiActionListener
|
import org.lwjgl.input.Mouse;
|
||||||
{
|
import org.lwjgl.opengl.GL11;
|
||||||
|
|
||||||
|
import codechicken.core.gui.GuiWidget;
|
||||||
|
import codechicken.core.gui.IGuiActionListener;
|
||||||
|
import codechicken.lib.gui.GuiDraw;
|
||||||
|
|
||||||
|
public class GuiContainerWidget extends GuiContainer implements IGuiActionListener {
|
||||||
|
|
||||||
public ArrayList<GuiWidget> widgets = new ArrayList<GuiWidget>();
|
public ArrayList<GuiWidget> widgets = new ArrayList<GuiWidget>();
|
||||||
|
|
||||||
public GuiContainerWidget(Container inventorySlots)
|
public GuiContainerWidget(Container inventorySlots) {
|
||||||
{
|
|
||||||
this(inventorySlots, 176, 166);
|
this(inventorySlots, 176, 166);
|
||||||
}
|
}
|
||||||
|
|
||||||
public GuiContainerWidget(Container inventorySlots, int xSize, int ySize)
|
public GuiContainerWidget(Container inventorySlots, int xSize, int ySize) {
|
||||||
{
|
|
||||||
super(inventorySlots);
|
super(inventorySlots);
|
||||||
this.xSize = xSize;
|
this.xSize = xSize;
|
||||||
this.ySize = ySize;
|
this.ySize = ySize;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setWorldAndResolution(Minecraft mc, int i, int j)
|
public void setWorldAndResolution(Minecraft mc, int i, int j) {
|
||||||
{
|
|
||||||
super.setWorldAndResolution(mc, i, j);
|
super.setWorldAndResolution(mc, i, j);
|
||||||
if(widgets.isEmpty())
|
if (widgets.isEmpty()) addWidgets();
|
||||||
addWidgets();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void add(GuiWidget widget)
|
public void add(GuiWidget widget) {
|
||||||
{
|
|
||||||
widgets.add(widget);
|
widgets.add(widget);
|
||||||
widget.onAdded(this);
|
widget.onAdded(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void drawGuiContainerBackgroundLayer(float f, int mousex, int mousey)
|
protected void drawGuiContainerBackgroundLayer(float f, int mousex, int mousey) {
|
||||||
{
|
|
||||||
GL11.glTranslated(guiLeft, guiTop, 0);
|
GL11.glTranslated(guiLeft, guiTop, 0);
|
||||||
drawBackground();
|
drawBackground();
|
||||||
for(GuiWidget widget : widgets)
|
for (GuiWidget widget : widgets) widget.draw(mousex - guiLeft, mousey - guiTop, f);
|
||||||
widget.draw(mousex-guiLeft, mousey-guiTop, f);
|
|
||||||
|
|
||||||
GL11.glTranslated(-guiLeft, -guiTop, 0);
|
GL11.glTranslated(-guiLeft, -guiTop, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void drawBackground()
|
public void drawBackground() {}
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void mouseClicked(int x, int y, int button)
|
protected void mouseClicked(int x, int y, int button) {
|
||||||
{
|
|
||||||
super.mouseClicked(x, y, button);
|
super.mouseClicked(x, y, button);
|
||||||
for(GuiWidget widget : widgets)
|
for (GuiWidget widget : widgets) widget.mouseClicked(x - guiLeft, y - guiTop, button);
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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();
|
super.handleMouseInput();
|
||||||
int i = Mouse.getEventDWheel();
|
int i = Mouse.getEventDWheel();
|
||||||
if(i != 0)
|
if (i != 0) {
|
||||||
{
|
|
||||||
Point p = GuiDraw.getMousePosition();
|
Point p = GuiDraw.getMousePosition();
|
||||||
int scroll = i > 0 ? 1 : -1;
|
int scroll = i > 0 ? 1 : -1;
|
||||||
for(GuiWidget widget : widgets)
|
for (GuiWidget widget : widgets) widget.mouseScrolled(p.x, p.y, scroll);
|
||||||
widget.mouseScrolled(p.x, p.y, scroll);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(String ident, Object... params)
|
public void actionPerformed(String ident, Object... params) {}
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
public void addWidgets()
|
public void addWidgets() {}
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onGuiClosed() {
|
public void onGuiClosed() {
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package codechicken.core.launch;
|
package codechicken.core.launch;
|
||||||
|
|
||||||
import java.awt.*;
|
import java.awt.Desktop;
|
||||||
|
import java.awt.GraphicsEnvironment;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.lang.reflect.Constructor;
|
import java.lang.reflect.Constructor;
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
@@ -17,32 +18,40 @@ import javax.swing.JOptionPane;
|
|||||||
import javax.swing.event.HyperlinkEvent;
|
import javax.swing.event.HyperlinkEvent;
|
||||||
import javax.swing.event.HyperlinkListener;
|
import javax.swing.event.HyperlinkListener;
|
||||||
|
|
||||||
import codechicken.core.asm.*;
|
|
||||||
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.TransformerExclusions;
|
|
||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
|
|
||||||
@TransformerExclusions(value = {"codechicken.core.asm", "codechicken.obfuscator"})
|
import codechicken.core.asm.CodeChickenCoreModContainer;
|
||||||
public class CodeChickenCorePlugin implements IFMLLoadingPlugin, IFMLCallHook
|
import codechicken.core.asm.DelegatedTransformer;
|
||||||
{
|
import codechicken.core.asm.MCPDeobfuscationTransformer;
|
||||||
|
import codechicken.core.asm.Tags;
|
||||||
|
import codechicken.core.asm.TweakTransformer;
|
||||||
|
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;
|
||||||
|
|
||||||
|
@TransformerExclusions(value = { "codechicken.core.asm", "codechicken.obfuscator" })
|
||||||
|
@MCVersion("1.7.10")
|
||||||
|
public class CodeChickenCorePlugin implements IFMLLoadingPlugin, IFMLCallHook {
|
||||||
|
|
||||||
public static final String mcVersion = "[1.7.10]";
|
public static final String mcVersion = "[1.7.10]";
|
||||||
public static final String version = "GRADLETOKEN_VERSION";
|
|
||||||
|
@Deprecated
|
||||||
|
public static final String version = Tags.VERSION;
|
||||||
|
|
||||||
public static File minecraftDir;
|
public static File minecraftDir;
|
||||||
public static String currentMcVersion;
|
public static String currentMcVersion;
|
||||||
public static Logger logger = LogManager.getLogger("CodeChickenCore");
|
public static Logger logger = LogManager.getLogger("CodeChickenCore");
|
||||||
|
|
||||||
public CodeChickenCorePlugin() {
|
public CodeChickenCorePlugin() {
|
||||||
if (minecraftDir != null)
|
if (minecraftDir != null) return; // get called twice, once for IFMLCallHook
|
||||||
return;//get called twice, once for IFMLCallHook
|
|
||||||
|
|
||||||
minecraftDir = (File) FMLInjectionData.data()[6];
|
minecraftDir = (File) FMLInjectionData.data()[6];
|
||||||
currentMcVersion = (String) FMLInjectionData.data()[4];
|
currentMcVersion = (String) FMLInjectionData.data()[4];
|
||||||
@@ -54,11 +63,19 @@ public class CodeChickenCorePlugin implements IFMLLoadingPlugin, IFMLCallHook
|
|||||||
private void injectDeobfPlugin() {
|
private void injectDeobfPlugin() {
|
||||||
try {
|
try {
|
||||||
Class<?> wrapperClass = Class.forName("cpw.mods.fml.relauncher.CoreModManager$FMLPluginWrapper");
|
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");
|
Field f_loadPlugins = CoreModManager.class.getDeclaredField("loadPlugins");
|
||||||
wrapperConstructor.setAccessible(true);
|
wrapperConstructor.setAccessible(true);
|
||||||
f_loadPlugins.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) {
|
} catch (Exception e) {
|
||||||
logger.error("Failed to inject MCPDeobfuscation Transformer", e);
|
logger.error("Failed to inject MCPDeobfuscation Transformer", e);
|
||||||
}
|
}
|
||||||
@@ -70,16 +87,16 @@ public class CodeChickenCorePlugin implements IFMLLoadingPlugin, IFMLCallHook
|
|||||||
String err = "This version of " + mod + " does not support minecraft version " + mcVersion;
|
String err = "This version of " + mod + " does not support minecraft version " + mcVersion;
|
||||||
logger.error(err);
|
logger.error(err);
|
||||||
|
|
||||||
JEditorPane ep = new JEditorPane("text/html",
|
JEditorPane ep = new JEditorPane(
|
||||||
"<html>" +
|
"text/html",
|
||||||
err +
|
"<html>" + err
|
||||||
"<br>Remove it from your coremods folder and check <a href=\"http://www.minecraftforum.net/topic/909223-\">here</a> for updates" +
|
+ "<br>Remove it from your coremods folder and check <a href=\"http://www.minecraftforum.net/topic/909223-\">here</a> for updates"
|
||||||
"</html>");
|
+ "</html>");
|
||||||
|
|
||||||
ep.setEditable(false);
|
ep.setEditable(false);
|
||||||
ep.setOpaque(false);
|
ep.setOpaque(false);
|
||||||
ep.addHyperlinkListener(new HyperlinkListener()
|
ep.addHyperlinkListener(new HyperlinkListener() {
|
||||||
{
|
|
||||||
@Override
|
@Override
|
||||||
public void hyperlinkUpdate(HyperlinkEvent event) {
|
public void hyperlinkUpdate(HyperlinkEvent event) {
|
||||||
try {
|
try {
|
||||||
@@ -97,11 +114,15 @@ public class CodeChickenCorePlugin implements IFMLLoadingPlugin, IFMLCallHook
|
|||||||
public static long parseSize(String text) {
|
public static long parseSize(String text) {
|
||||||
double d = Double.parseDouble(text.replaceAll("[GMK]B?$", ""));
|
double d = Double.parseDouble(text.replaceAll("[GMK]B?$", ""));
|
||||||
long l = Math.round(d * 1024 * 1024 * 1024L);
|
long l = Math.round(d * 1024 * 1024 * 1024L);
|
||||||
switch (text.replaceAll("\\d?","").toUpperCase().charAt(0)) {
|
switch (text.replaceAll("\\d?", "").toUpperCase().charAt(0)) {
|
||||||
default: l /= 1024;
|
default:
|
||||||
case 'K': l /= 1024;
|
l /= 1024;
|
||||||
case 'M': l /= 1024;
|
case 'K':
|
||||||
case 'G': return l;
|
l /= 1024;
|
||||||
|
case 'M':
|
||||||
|
l /= 1024;
|
||||||
|
case 'G':
|
||||||
|
return l;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -120,23 +141,38 @@ public class CodeChickenCorePlugin implements IFMLLoadingPlugin, IFMLCallHook
|
|||||||
return String.format("%.1f %cB", value / 1024.0, ci.current());
|
return String.format("%.1f %cB", value / 1024.0, ci.current());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void systemCheck(String minRAM) {
|
public static void systemCheck(ConfigTag checkRAM) {
|
||||||
long minBytes = parseSize(minRAM);
|
long minBytes = parseSize(
|
||||||
|
checkRAM.getTag("minRAM").setComment("Amount of RAM minimum this modpack needs to load")
|
||||||
|
.getValue("3GB"));
|
||||||
if (Runtime.getRuntime().maxMemory() < minBytes) {
|
if (Runtime.getRuntime().maxMemory() < minBytes) {
|
||||||
String err = "You should have at least " + minRAM + " 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);
|
logger.error(err);
|
||||||
|
|
||||||
JEditorPane ep = new JEditorPane("text/html",
|
JEditorPane ep = new JEditorPane(
|
||||||
"<html>" +
|
"text/html",
|
||||||
err +
|
"<html>" + err
|
||||||
"<br>GTNH seriously won't run without enough RAM. See <a href=\"https://gtnh.miraheze.org/m/3S2\">the Wiki</a> for details." +
|
+ "<br>"
|
||||||
"<br>Recommended values are between 4GB and 6GB. Check your launcher's JVM arguments." +
|
+ checkRAM.getTag("modPack").setComment("Name of the modpack")
|
||||||
"</html>");
|
.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.setEditable(false);
|
||||||
ep.setOpaque(false);
|
ep.setOpaque(false);
|
||||||
ep.addHyperlinkListener(new HyperlinkListener()
|
ep.addHyperlinkListener(new HyperlinkListener() {
|
||||||
{
|
|
||||||
@Override
|
@Override
|
||||||
public void hyperlinkUpdate(HyperlinkEvent event) {
|
public void hyperlinkUpdate(HyperlinkEvent event) {
|
||||||
try {
|
try {
|
||||||
@@ -155,12 +191,9 @@ public class CodeChickenCorePlugin implements IFMLLoadingPlugin, IFMLCallHook
|
|||||||
@Override
|
@Override
|
||||||
public String[] getASMTransformerClass() {
|
public String[] getASMTransformerClass() {
|
||||||
versionCheck(mcVersion, "CodeChickenCore");
|
versionCheck(mcVersion, "CodeChickenCore");
|
||||||
return new String[]{
|
return new String[] { "codechicken.lib.asm.ClassHeirachyManager", "codechicken.core.asm.TweakTransformer",
|
||||||
"codechicken.lib.asm.ClassHeirachyManager",
|
"codechicken.core.asm.DelegatedTransformer", "codechicken.core.asm.DefaultImplementationTransformer",
|
||||||
"codechicken.core.asm.InterfaceDependancyTransformer",
|
"codechicken.lib.asm.RedirectorTransformer" };
|
||||||
"codechicken.core.asm.TweakTransformer",
|
|
||||||
"codechicken.core.asm.DelegatedTransformer",
|
|
||||||
"codechicken.core.asm.DefaultImplementationTransformer"};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -179,13 +212,18 @@ public class CodeChickenCorePlugin implements IFMLLoadingPlugin, IFMLCallHook
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void injectData(Map<String, Object> data) {
|
public void injectData(Map<String, Object> data) {}
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Void call() {
|
public Void call() {
|
||||||
CodeChickenCoreModContainer.loadConfig();
|
CodeChickenCoreModContainer.loadConfig();
|
||||||
systemCheck(CodeChickenCoreModContainer.config.getTag("minRAM").getValue("3GB"));
|
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);
|
||||||
TweakTransformer.load();
|
TweakTransformer.load();
|
||||||
scanCodeChickenMods();
|
scanCodeChickenMods();
|
||||||
|
|
||||||
@@ -194,31 +232,24 @@ public class CodeChickenCorePlugin implements IFMLLoadingPlugin, IFMLCallHook
|
|||||||
|
|
||||||
private void scanCodeChickenMods() {
|
private void scanCodeChickenMods() {
|
||||||
File modsDir = new File(minecraftDir, "mods");
|
File modsDir = new File(minecraftDir, "mods");
|
||||||
for (File file : modsDir.listFiles())
|
for (File file : modsDir.listFiles()) scanMod(file);
|
||||||
scanMod(file);
|
|
||||||
File versionModsDir = new File(minecraftDir, "mods/" + currentMcVersion);
|
File versionModsDir = new File(minecraftDir, "mods/" + currentMcVersion);
|
||||||
if (versionModsDir.exists())
|
if (versionModsDir.exists()) for (File file : versionModsDir.listFiles()) scanMod(file);
|
||||||
for (File file : versionModsDir.listFiles())
|
|
||||||
scanMod(file);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void scanMod(File file) {
|
private void scanMod(File file) {
|
||||||
if (!file.getName().endsWith(".jar") && !file.getName().endsWith(".zip"))
|
if (!file.getName().endsWith(".jar") && !file.getName().endsWith(".zip")) return;
|
||||||
return;
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
JarFile jar = new JarFile(file);
|
JarFile jar = new JarFile(file);
|
||||||
try {
|
try {
|
||||||
Manifest manifest = jar.getManifest();
|
Manifest manifest = jar.getManifest();
|
||||||
if (manifest == null)
|
if (manifest == null) return;
|
||||||
return;
|
|
||||||
Attributes attr = manifest.getMainAttributes();
|
Attributes attr = manifest.getMainAttributes();
|
||||||
if (attr == null)
|
if (attr == null) return;
|
||||||
return;
|
|
||||||
|
|
||||||
String transformer = attr.getValue("CCTransformer");
|
String transformer = attr.getValue("CCTransformer");
|
||||||
if (transformer != null)
|
if (transformer != null) DelegatedTransformer.addTransformer(transformer, jar, file);
|
||||||
DelegatedTransformer.addTransformer(transformer, jar, file);
|
|
||||||
} finally {
|
} finally {
|
||||||
jar.close();
|
jar.close();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,53 +1,76 @@
|
|||||||
package codechicken.core.launch;
|
package codechicken.core.launch;
|
||||||
|
|
||||||
import com.google.gson.JsonElement;
|
import java.awt.Desktop;
|
||||||
import com.google.gson.JsonObject;
|
|
||||||
import com.google.gson.JsonParser;
|
|
||||||
import cpw.mods.fml.common.versioning.ComparableVersion;
|
|
||||||
import cpw.mods.fml.relauncher.FMLInjectionData;
|
|
||||||
import cpw.mods.fml.relauncher.FMLLaunchHandler;
|
|
||||||
import cpw.mods.fml.relauncher.IFMLCallHook;
|
|
||||||
import cpw.mods.fml.relauncher.IFMLLoadingPlugin;
|
|
||||||
import net.minecraft.launchwrapper.LaunchClassLoader;
|
|
||||||
import sun.misc.URLClassPath;
|
|
||||||
import sun.net.util.URLUtil;
|
|
||||||
|
|
||||||
import codechicken.core.launch.CodeChickenCorePlugin;
|
|
||||||
|
|
||||||
import javax.swing.*;
|
|
||||||
import javax.swing.event.HyperlinkEvent;
|
|
||||||
import javax.swing.event.HyperlinkListener;
|
|
||||||
import java.awt.*;
|
|
||||||
import java.awt.Dialog.ModalityType;
|
import java.awt.Dialog.ModalityType;
|
||||||
|
import java.awt.Dimension;
|
||||||
|
import java.awt.GraphicsEnvironment;
|
||||||
import java.awt.event.WindowAdapter;
|
import java.awt.event.WindowAdapter;
|
||||||
import java.awt.event.WindowEvent;
|
import java.awt.event.WindowEvent;
|
||||||
import java.beans.PropertyChangeEvent;
|
import java.beans.PropertyChangeEvent;
|
||||||
import java.beans.PropertyChangeListener;
|
import java.beans.PropertyChangeListener;
|
||||||
import java.io.*;
|
import java.io.Closeable;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileOutputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
|
import java.io.InterruptedIOException;
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.net.MalformedURLException;
|
import java.net.MalformedURLException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.net.URLClassLoader;
|
import java.net.URLClassLoader;
|
||||||
import java.net.URLConnection;
|
import java.net.URLConnection;
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
import java.util.*;
|
import java.util.Arrays;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
import java.util.regex.PatternSyntaxException;
|
import java.util.regex.PatternSyntaxException;
|
||||||
import java.util.zip.ZipEntry;
|
import java.util.zip.ZipEntry;
|
||||||
import java.util.zip.ZipFile;
|
import java.util.zip.ZipFile;
|
||||||
|
|
||||||
|
import javax.swing.Box;
|
||||||
|
import javax.swing.JDialog;
|
||||||
|
import javax.swing.JEditorPane;
|
||||||
|
import javax.swing.JLabel;
|
||||||
|
import javax.swing.JOptionPane;
|
||||||
|
import javax.swing.JProgressBar;
|
||||||
|
import javax.swing.WindowConstants;
|
||||||
|
import javax.swing.event.HyperlinkEvent;
|
||||||
|
import javax.swing.event.HyperlinkListener;
|
||||||
|
|
||||||
|
import net.minecraft.launchwrapper.LaunchClassLoader;
|
||||||
|
|
||||||
|
import com.google.gson.JsonElement;
|
||||||
|
import com.google.gson.JsonObject;
|
||||||
|
import com.google.gson.JsonParser;
|
||||||
|
|
||||||
|
import cpw.mods.fml.common.versioning.ComparableVersion;
|
||||||
|
import cpw.mods.fml.relauncher.FMLInjectionData;
|
||||||
|
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 sun.misc.URLClassPath;
|
||||||
|
import sun.net.util.URLUtil;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* For autodownloading stuff.
|
* For autodownloading stuff. This is really unoriginal, mostly ripped off FML, credits to cpw.
|
||||||
* This is really unoriginal, mostly ripped off FML, credits to cpw.
|
|
||||||
*/
|
*/
|
||||||
|
@MCVersion("1.7.10")
|
||||||
public class DepLoader implements IFMLLoadingPlugin, IFMLCallHook {
|
public class DepLoader implements IFMLLoadingPlugin, IFMLCallHook {
|
||||||
|
|
||||||
private static ByteBuffer downloadBuffer = ByteBuffer.allocateDirect(1 << 23);
|
private static ByteBuffer downloadBuffer = ByteBuffer.allocateDirect(1 << 23);
|
||||||
private static final String owner = "CB's DepLoader";
|
private static final String owner = "CB's DepLoader";
|
||||||
private static DepLoadInst inst;
|
private static DepLoadInst inst;
|
||||||
|
|
||||||
public interface IDownloadDisplay {
|
public interface IDownloadDisplay {
|
||||||
|
|
||||||
void resetProgress(int sizeGuess);
|
void resetProgress(int sizeGuess);
|
||||||
|
|
||||||
void setPokeThread(Thread currentThread);
|
void setPokeThread(Thread currentThread);
|
||||||
@@ -65,6 +88,7 @@ public class DepLoader implements IFMLLoadingPlugin, IFMLCallHook {
|
|||||||
|
|
||||||
@SuppressWarnings("serial")
|
@SuppressWarnings("serial")
|
||||||
public static class Downloader extends JOptionPane implements IDownloadDisplay {
|
public static class Downloader extends JOptionPane implements IDownloadDisplay {
|
||||||
|
|
||||||
private JDialog container;
|
private JDialog container;
|
||||||
private JLabel currentActivity;
|
private JLabel currentActivity;
|
||||||
private JProgressBar progress;
|
private JProgressBar progress;
|
||||||
@@ -74,10 +98,13 @@ public class DepLoader implements IFMLLoadingPlugin, IFMLCallHook {
|
|||||||
private Box makeProgressPanel() {
|
private Box makeProgressPanel() {
|
||||||
Box box = Box.createVerticalBox();
|
Box box = Box.createVerticalBox();
|
||||||
box.add(Box.createRigidArea(new Dimension(0, 10)));
|
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);
|
box.add(welcomeLabel);
|
||||||
welcomeLabel.setAlignmentY(LEFT_ALIGNMENT);
|
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);
|
welcomeLabel.setAlignmentY(LEFT_ALIGNMENT);
|
||||||
box.add(welcomeLabel);
|
box.add(welcomeLabel);
|
||||||
box.add(Box.createRigidArea(new Dimension(0, 10)));
|
box.add(Box.createRigidArea(new Dimension(0, 10)));
|
||||||
@@ -93,13 +120,13 @@ public class DepLoader implements IFMLLoadingPlugin, IFMLCallHook {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public JDialog makeDialog() {
|
public JDialog makeDialog() {
|
||||||
if (container != null)
|
if (container != null) return container;
|
||||||
return container;
|
|
||||||
|
|
||||||
setMessageType(JOptionPane.INFORMATION_MESSAGE);
|
setMessageType(JOptionPane.INFORMATION_MESSAGE);
|
||||||
setMessage(makeProgressPanel());
|
setMessage(makeProgressPanel());
|
||||||
setOptions(new Object[]{"Stop"});
|
setOptions(new Object[] { "Stop" });
|
||||||
addPropertyChangeListener(new PropertyChangeListener() {
|
addPropertyChangeListener(new PropertyChangeListener() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void propertyChange(PropertyChangeEvent evt) {
|
public void propertyChange(PropertyChangeEvent evt) {
|
||||||
if (evt.getSource() == Downloader.this && evt.getPropertyName() == VALUE_PROPERTY) {
|
if (evt.getSource() == Downloader.this && evt.getPropertyName() == VALUE_PROPERTY) {
|
||||||
@@ -117,41 +144,43 @@ public class DepLoader implements IFMLLoadingPlugin, IFMLCallHook {
|
|||||||
container.setVisible(true);
|
container.setVisible(true);
|
||||||
container.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
|
container.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
|
||||||
container.addWindowListener(new WindowAdapter() {
|
container.addWindowListener(new WindowAdapter() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void windowClosing(WindowEvent e) {
|
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;
|
return container;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void requestClose(String message) {
|
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);
|
int shouldClose = JOptionPane.showConfirmDialog(
|
||||||
if (shouldClose == JOptionPane.YES_OPTION)
|
container,
|
||||||
container.dispose();
|
message,
|
||||||
|
"Are you sure you want to stop?",
|
||||||
|
JOptionPane.YES_NO_OPTION,
|
||||||
|
JOptionPane.WARNING_MESSAGE);
|
||||||
|
if (shouldClose == JOptionPane.YES_OPTION) container.dispose();
|
||||||
|
|
||||||
stopIt = true;
|
stopIt = true;
|
||||||
if (pokeThread != null)
|
if (pokeThread != null) pokeThread.interrupt();
|
||||||
pokeThread.interrupt();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateProgressString(String progressUpdate, Object... data) {
|
public void updateProgressString(String progressUpdate, Object... data) {
|
||||||
//FMLLog.finest(progressUpdate, data);
|
// FMLLog.finest(progressUpdate, data);
|
||||||
if (currentActivity != null)
|
if (currentActivity != null) currentActivity.setText(String.format(progressUpdate, data));
|
||||||
currentActivity.setText(String.format(progressUpdate, data));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void resetProgress(int sizeGuess) {
|
public void resetProgress(int sizeGuess) {
|
||||||
if (progress != null)
|
if (progress != null) progress.getModel().setRangeProperties(0, 0, 0, sizeGuess, false);
|
||||||
progress.getModel().setRangeProperties(0, 0, 0, sizeGuess, false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateProgress(int fullLength) {
|
public void updateProgress(int fullLength) {
|
||||||
if (progress != null)
|
if (progress != null) progress.getModel().setValue(fullLength);
|
||||||
progress.getModel().setValue(fullLength);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -166,23 +195,29 @@ public class DepLoader implements IFMLLoadingPlugin, IFMLCallHook {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void showErrorDialog(String name, String url) {
|
public void showErrorDialog(String name, String url) {
|
||||||
JEditorPane ep = new JEditorPane("text/html",
|
JEditorPane ep = new JEditorPane(
|
||||||
"<html>" +
|
"text/html",
|
||||||
owner + " was unable to download required library " + name +
|
"<html>" + owner
|
||||||
"<br>Check your internet connection and try restarting or download it manually from" +
|
+ " was unable to download required library "
|
||||||
"<br><a href=\"" + url + "\">" + url + "</a> and put it in your mods folder" +
|
+ name
|
||||||
"</html>");
|
+ "<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.setEditable(false);
|
||||||
ep.setOpaque(false);
|
ep.setOpaque(false);
|
||||||
ep.addHyperlinkListener(new HyperlinkListener() {
|
ep.addHyperlinkListener(new HyperlinkListener() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void hyperlinkUpdate(HyperlinkEvent event) {
|
public void hyperlinkUpdate(HyperlinkEvent event) {
|
||||||
try {
|
try {
|
||||||
if (event.getEventType().equals(HyperlinkEvent.EventType.ACTIVATED))
|
if (event.getEventType().equals(HyperlinkEvent.EventType.ACTIVATED))
|
||||||
Desktop.getDesktop().browse(event.getURL().toURI());
|
Desktop.getDesktop().browse(event.getURL().toURI());
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -191,17 +226,15 @@ public class DepLoader implements IFMLLoadingPlugin, IFMLCallHook {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static class DummyDownloader implements IDownloadDisplay {
|
public static class DummyDownloader implements IDownloadDisplay {
|
||||||
@Override
|
|
||||||
public void resetProgress(int sizeGuess) {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setPokeThread(Thread currentThread) {
|
public void resetProgress(int sizeGuess) {}
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateProgress(int fullLength) {
|
public void setPokeThread(Thread currentThread) {}
|
||||||
}
|
|
||||||
|
@Override
|
||||||
|
public void updateProgress(int fullLength) {}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean shouldStopIt() {
|
public boolean shouldStopIt() {
|
||||||
@@ -209,8 +242,7 @@ public class DepLoader implements IFMLLoadingPlugin, IFMLCallHook {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateProgressString(String string, Object... data) {
|
public void updateProgressString(String string, Object... data) {}
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object makeDialog() {
|
public Object makeDialog() {
|
||||||
@@ -218,12 +250,11 @@ public class DepLoader implements IFMLLoadingPlugin, IFMLCallHook {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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 Pattern pattern;
|
||||||
public final String filename;
|
public final String filename;
|
||||||
public final ComparableVersion version;
|
public final ComparableVersion version;
|
||||||
@@ -233,11 +264,10 @@ public class DepLoader implements IFMLLoadingPlugin, IFMLCallHook {
|
|||||||
this.pattern = pattern;
|
this.pattern = pattern;
|
||||||
this.filename = filename;
|
this.filename = filename;
|
||||||
Matcher m = pattern.matcher(filename);
|
Matcher m = pattern.matcher(filename);
|
||||||
if(m.matches()) {
|
if (m.matches()) {
|
||||||
name = m.group(1);
|
name = m.group(1);
|
||||||
version = new ComparableVersion(m.group(2));
|
version = new ComparableVersion(m.group(2));
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
name = null;
|
name = null;
|
||||||
version = null;
|
version = null;
|
||||||
}
|
}
|
||||||
@@ -248,8 +278,8 @@ public class DepLoader implements IFMLLoadingPlugin, IFMLCallHook {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class Dependency
|
public static class Dependency {
|
||||||
{
|
|
||||||
public String url;
|
public String url;
|
||||||
public VersionedFile file;
|
public VersionedFile file;
|
||||||
|
|
||||||
@@ -267,6 +297,7 @@ public class DepLoader implements IFMLLoadingPlugin, IFMLCallHook {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static class DepLoadInst {
|
public static class DepLoadInst {
|
||||||
|
|
||||||
private File modsDir;
|
private File modsDir;
|
||||||
private File v_modsDir;
|
private File v_modsDir;
|
||||||
private IDownloadDisplay downloadMonitor;
|
private IDownloadDisplay downloadMonitor;
|
||||||
@@ -281,21 +312,20 @@ public class DepLoader implements IFMLLoadingPlugin, IFMLCallHook {
|
|||||||
|
|
||||||
modsDir = new File(mcDir, "mods");
|
modsDir = new File(mcDir, "mods");
|
||||||
v_modsDir = new File(mcDir, "mods/" + mcVer);
|
v_modsDir = new File(mcDir, "mods/" + mcVer);
|
||||||
if (!v_modsDir.exists())
|
if (!v_modsDir.exists()) v_modsDir.mkdirs();
|
||||||
v_modsDir.mkdirs();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addClasspath(String name) {
|
private void addClasspath(String name) {
|
||||||
try {
|
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) {
|
} catch (MalformedURLException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void deleteMod(File mod) {
|
private void deleteMod(File mod) {
|
||||||
if (mod.delete())
|
if (mod.delete()) return;
|
||||||
return;
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
ClassLoader cl = DepLoader.class.getClassLoader();
|
ClassLoader cl = DepLoader.class.getClassLoader();
|
||||||
@@ -319,7 +349,9 @@ public class DepLoader implements IFMLLoadingPlugin, IFMLCallHook {
|
|||||||
|
|
||||||
if (!mod.delete()) {
|
if (!mod.delete()) {
|
||||||
mod.deleteOnExit();
|
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);
|
CodeChickenCorePlugin.logger.error(msg);
|
||||||
if (!GraphicsEnvironment.isHeadless())
|
if (!GraphicsEnvironment.isHeadless())
|
||||||
JOptionPane.showMessageDialog(null, msg, "An update error has occurred", JOptionPane.ERROR_MESSAGE);
|
JOptionPane.showMessageDialog(null, msg, "An update error has occurred", JOptionPane.ERROR_MESSAGE);
|
||||||
@@ -348,7 +380,8 @@ public class DepLoader implements IFMLLoadingPlugin, IFMLCallHook {
|
|||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
libFile.delete();
|
libFile.delete();
|
||||||
if (downloadMonitor.shouldStopIt()) {
|
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);
|
System.exit(1);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -358,8 +391,10 @@ public class DepLoader implements IFMLLoadingPlugin, IFMLCallHook {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void download(InputStream is, int sizeGuess, File target) throws Exception {
|
private void download(InputStream is, int sizeGuess, File target) throws Exception {
|
||||||
if (sizeGuess > downloadBuffer.capacity())
|
if (sizeGuess > downloadBuffer.capacity()) throw new Exception(
|
||||||
throw new Exception(String.format("The file %s is too large to be downloaded by " + owner + " - the download is invalid", target.getName()));
|
String.format(
|
||||||
|
"The file %s is too large to be downloaded by " + owner + " - the download is invalid",
|
||||||
|
target.getName()));
|
||||||
|
|
||||||
downloadBuffer.clear();
|
downloadBuffer.clear();
|
||||||
|
|
||||||
@@ -390,22 +425,20 @@ public class DepLoader implements IFMLLoadingPlugin, IFMLCallHook {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
/*String cksum = generateChecksum(downloadBuffer);
|
/*
|
||||||
if (cksum.equals(validationHash))
|
* String cksum = generateChecksum(downloadBuffer); if (cksum.equals(validationHash)) {
|
||||||
{*/
|
*/
|
||||||
if (!target.exists())
|
if (!target.exists()) target.createNewFile();
|
||||||
target.createNewFile();
|
|
||||||
|
|
||||||
|
|
||||||
downloadBuffer.position(0);
|
downloadBuffer.position(0);
|
||||||
FileOutputStream fos = new FileOutputStream(target);
|
FileOutputStream fos = new FileOutputStream(target);
|
||||||
fos.getChannel().write(downloadBuffer);
|
fos.getChannel().write(downloadBuffer);
|
||||||
fos.close();
|
fos.close();
|
||||||
/*}
|
/*
|
||||||
else
|
* } else { throw new RuntimeException(String.
|
||||||
{
|
* format("The downloaded file %s has an invalid checksum %s (expecting %s). The download did not succeed correctly and the file has been deleted. Please try launching again."
|
||||||
throw new RuntimeException(String.format("The downloaded file %s has an invalid checksum %s (expecting %s). The download did not succeed correctly and the file has been deleted. Please try launching again.", target.getName(), cksum, validationHash));
|
* , target.getName(), cksum, validationHash)); }
|
||||||
}*/
|
*/
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
@@ -414,19 +447,16 @@ public class DepLoader implements IFMLLoadingPlugin, IFMLCallHook {
|
|||||||
private String checkExisting(Dependency dep) {
|
private String checkExisting(Dependency dep) {
|
||||||
for (File f : modsDir.listFiles()) {
|
for (File f : modsDir.listFiles()) {
|
||||||
VersionedFile vfile = new VersionedFile(f.getName(), dep.file.pattern);
|
VersionedFile vfile = new VersionedFile(f.getName(), dep.file.pattern);
|
||||||
if (!vfile.matches() || !vfile.name.equals(dep.file.name))
|
if (!vfile.matches() || !vfile.name.equals(dep.file.name)) continue;
|
||||||
continue;
|
|
||||||
|
|
||||||
if (f.renameTo(new File(v_modsDir, f.getName())))
|
if (f.renameTo(new File(v_modsDir, f.getName()))) continue;
|
||||||
continue;
|
|
||||||
|
|
||||||
deleteMod(f);
|
deleteMod(f);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (File f : v_modsDir.listFiles()) {
|
for (File f : v_modsDir.listFiles()) {
|
||||||
VersionedFile vfile = new VersionedFile(f.getName(), dep.file.pattern);
|
VersionedFile vfile = new VersionedFile(f.getName(), dep.file.pattern);
|
||||||
if (!vfile.matches() || !vfile.name.equals(dep.file.name))
|
if (!vfile.matches() || !vfile.name.equals(dep.file.name)) continue;
|
||||||
continue;
|
|
||||||
|
|
||||||
int cmp = vfile.version.compareTo(dep.file.version);
|
int cmp = vfile.version.compareTo(dep.file.version);
|
||||||
if (cmp < 0) {
|
if (cmp < 0) {
|
||||||
@@ -435,27 +465,29 @@ public class DepLoader implements IFMLLoadingPlugin, IFMLCallHook {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
if (cmp > 0) {
|
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();
|
||||||
}
|
}
|
||||||
return f.getName();//found dependency
|
return f.getName(); // found dependency
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void load() {
|
public void load() {
|
||||||
scanDepInfos();
|
scanDepInfos();
|
||||||
if (depMap.isEmpty())
|
if (depMap.isEmpty()) return;
|
||||||
return;
|
|
||||||
|
|
||||||
loadDeps();
|
loadDeps();
|
||||||
activateDeps();
|
activateDeps();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void activateDeps() {
|
private void activateDeps() {
|
||||||
for (Dependency dep : depMap.values())
|
for (Dependency dep : depMap.values()) if (dep.coreLib) addClasspath(dep.existing);
|
||||||
if (dep.coreLib)
|
|
||||||
addClasspath(dep.existing);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void loadDeps() {
|
private void loadDeps() {
|
||||||
@@ -477,7 +509,7 @@ public class DepLoader implements IFMLLoadingPlugin, IFMLCallHook {
|
|||||||
|
|
||||||
private void load(Dependency dep) {
|
private void load(Dependency dep) {
|
||||||
dep.existing = checkExisting(dep);
|
dep.existing = checkExisting(dep);
|
||||||
if (dep.existing == null)//download dep
|
if (dep.existing == null) // download dep
|
||||||
{
|
{
|
||||||
download(dep);
|
download(dep);
|
||||||
dep.existing = dep.file.filename;
|
dep.existing = dep.file.filename;
|
||||||
@@ -493,8 +525,7 @@ public class DepLoader implements IFMLLoadingPlugin, IFMLCallHook {
|
|||||||
|
|
||||||
private void scanDepInfos() {
|
private void scanDepInfos() {
|
||||||
for (File file : modFiles()) {
|
for (File file : modFiles()) {
|
||||||
if (!file.getName().endsWith(".jar") && !file.getName().endsWith(".zip"))
|
if (!file.getName().endsWith(".jar") && !file.getName().endsWith(".zip")) continue;
|
||||||
continue;
|
|
||||||
|
|
||||||
scanDepInfo(file);
|
scanDepInfo(file);
|
||||||
}
|
}
|
||||||
@@ -505,11 +536,11 @@ public class DepLoader implements IFMLLoadingPlugin, IFMLCallHook {
|
|||||||
ZipFile zip = new ZipFile(file);
|
ZipFile zip = new ZipFile(file);
|
||||||
ZipEntry e = zip.getEntry("dependancies.info");
|
ZipEntry e = zip.getEntry("dependancies.info");
|
||||||
if (e == null) e = zip.getEntry("dependencies.info");
|
if (e == null) e = zip.getEntry("dependencies.info");
|
||||||
if (e != null)
|
if (e != null) loadJSon(zip.getInputStream(e));
|
||||||
loadJSon(zip.getInputStream(e));
|
|
||||||
zip.close();
|
zip.close();
|
||||||
} catch (Exception e) {
|
} 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();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -517,16 +548,13 @@ public class DepLoader implements IFMLLoadingPlugin, IFMLCallHook {
|
|||||||
private void loadJSon(InputStream input) throws IOException {
|
private void loadJSon(InputStream input) throws IOException {
|
||||||
InputStreamReader reader = new InputStreamReader(input);
|
InputStreamReader reader = new InputStreamReader(input);
|
||||||
JsonElement root = new JsonParser().parse(reader);
|
JsonElement root = new JsonParser().parse(reader);
|
||||||
if (root.isJsonArray())
|
if (root.isJsonArray()) loadJSonArr(root);
|
||||||
loadJSonArr(root);
|
else loadJson(root.getAsJsonObject());
|
||||||
else
|
|
||||||
loadJson(root.getAsJsonObject());
|
|
||||||
reader.close();
|
reader.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void loadJSonArr(JsonElement root) throws IOException {
|
private void loadJSonArr(JsonElement root) throws IOException {
|
||||||
for (JsonElement node : root.getAsJsonArray())
|
for (JsonElement node : root.getAsJsonArray()) loadJson(node.getAsJsonObject());
|
||||||
loadJson(node.getAsJsonObject());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void loadJson(JsonObject node) throws IOException {
|
private void loadJson(JsonObject node) throws IOException {
|
||||||
@@ -534,30 +562,25 @@ public class DepLoader implements IFMLLoadingPlugin, IFMLCallHook {
|
|||||||
.getClassBytes("net.minecraft.world.World") == null;
|
.getClassBytes("net.minecraft.world.World") == null;
|
||||||
|
|
||||||
String testClass = node.get("class").getAsString();
|
String testClass = node.get("class").getAsString();
|
||||||
if (DepLoader.class.getResource("/" + testClass.replace('.', '/') + ".class") != null)
|
if (DepLoader.class.getResource("/" + testClass.replace('.', '/') + ".class") != null) return;
|
||||||
return;
|
|
||||||
|
|
||||||
String repo = node.get("repo").getAsString();
|
String repo = node.get("repo").getAsString();
|
||||||
String filename = node.get("file").getAsString();
|
String filename = node.get("file").getAsString();
|
||||||
if (!obfuscated && node.has("dev"))
|
if (!obfuscated && node.has("dev")) filename = node.get("dev").getAsString();
|
||||||
filename = node.get("dev").getAsString();
|
|
||||||
|
|
||||||
boolean coreLib = node.has("coreLib") && node.get("coreLib").getAsBoolean();
|
boolean coreLib = node.has("coreLib") && node.get("coreLib").getAsBoolean();
|
||||||
|
|
||||||
Pattern pattern = null;
|
Pattern pattern = null;
|
||||||
try {
|
try {
|
||||||
if(node.has("pattern"))
|
if (node.has("pattern")) pattern = Pattern.compile(node.get("pattern").getAsString());
|
||||||
pattern = Pattern.compile(node.get("pattern").getAsString());
|
|
||||||
} catch (PatternSyntaxException e) {
|
} catch (PatternSyntaxException e) {
|
||||||
CodeChickenCorePlugin.logger.error("Invalid filename pattern: " + node.get("pattern"));
|
CodeChickenCorePlugin.logger.error("Invalid filename pattern: " + node.get("pattern"));
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
if(pattern == null)
|
if (pattern == null) pattern = Pattern.compile("(\\w+).*?([\\d\\.]+)[-\\w]*\\.[^\\d]+");
|
||||||
pattern = Pattern.compile("(\\w+).*?([\\d\\.]+)[-\\w]*\\.[^\\d]+");
|
|
||||||
|
|
||||||
VersionedFile file = new VersionedFile(filename, pattern);
|
VersionedFile file = new VersionedFile(filename, pattern);
|
||||||
if (!file.matches())
|
if (!file.matches()) throw new RuntimeException("Invalid filename format for dependency: " + filename);
|
||||||
throw new RuntimeException("Invalid filename format for dependency: " + filename);
|
|
||||||
|
|
||||||
addDep(new Dependency(repo, file, coreLib));
|
addDep(new Dependency(repo, file, coreLib));
|
||||||
}
|
}
|
||||||
@@ -570,8 +593,7 @@ public class DepLoader implements IFMLLoadingPlugin, IFMLCallHook {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private boolean mergeNew(Dependency oldDep, Dependency newDep) {
|
private boolean mergeNew(Dependency oldDep, Dependency newDep) {
|
||||||
if (oldDep == null)
|
if (oldDep == null) return true;
|
||||||
return true;
|
|
||||||
|
|
||||||
Dependency newest = newDep.file.version.compareTo(oldDep.file.version) > 0 ? newDep : oldDep;
|
Dependency newest = newDep.file.version.compareTo(oldDep.file.version) > 0 ? newDep : oldDep;
|
||||||
newest.coreLib = newDep.coreLib || oldDep.coreLib;
|
newest.coreLib = newDep.coreLib || oldDep.coreLib;
|
||||||
@@ -603,8 +625,7 @@ public class DepLoader implements IFMLLoadingPlugin, IFMLCallHook {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void injectData(Map<String, Object> data) {
|
public void injectData(Map<String, Object> data) {}
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Void call() {
|
public Void call() {
|
||||||
|
|||||||
@@ -1,7 +1,11 @@
|
|||||||
package codechicken.obfuscator;
|
package codechicken.obfuscator;
|
||||||
|
|
||||||
|
import static org.objectweb.asm.tree.AbstractInsnNode.LDC_INSN;
|
||||||
|
import static org.objectweb.asm.tree.AbstractInsnNode.METHOD_INSN;
|
||||||
|
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.objectweb.asm.Opcodes;
|
import org.objectweb.asm.Opcodes;
|
||||||
import org.objectweb.asm.tree.AbstractInsnNode;
|
import org.objectweb.asm.tree.AbstractInsnNode;
|
||||||
import org.objectweb.asm.tree.ClassNode;
|
import org.objectweb.asm.tree.ClassNode;
|
||||||
@@ -11,40 +15,31 @@ import org.objectweb.asm.tree.MethodNode;
|
|||||||
|
|
||||||
import codechicken.lib.asm.ObfMapping;
|
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 ObfRemapper obf;
|
||||||
public List<ObfMapping> descCalls = new LinkedList<ObfMapping>();
|
public List<ObfMapping> descCalls = new LinkedList<ObfMapping>();
|
||||||
public List<ObfMapping> classCalls = 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;
|
this.obf = obf;
|
||||||
for(String callDesc : a_classCalls)
|
for (String callDesc : a_classCalls) classCalls.add(ObfMapping.fromDesc(callDesc));
|
||||||
classCalls.add(ObfMapping.fromDesc(callDesc));
|
|
||||||
|
for (String callDesc : a_descCalls) descCalls.add(ObfMapping.fromDesc(callDesc));
|
||||||
for(String callDesc : a_descCalls)
|
|
||||||
descCalls.add(ObfMapping.fromDesc(callDesc));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void transform(ClassNode cnode)
|
public void transform(ClassNode cnode) {
|
||||||
{
|
for (MethodNode method : cnode.methods)
|
||||||
for(MethodNode method : cnode.methods)
|
for (AbstractInsnNode insn = method.instructions.getFirst(); insn != null; insn = insn.getNext())
|
||||||
for(AbstractInsnNode insn = method.instructions.getFirst(); insn != null; insn = insn.getNext())
|
|
||||||
obfuscateInsnSeq(insn);
|
obfuscateInsnSeq(insn);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void obfuscateInsnSeq(AbstractInsnNode insn)
|
private void obfuscateInsnSeq(AbstractInsnNode insn) {
|
||||||
{
|
if (matchesClass(insn)) {
|
||||||
if(matchesClass(insn))
|
|
||||||
{
|
|
||||||
LdcInsnNode node1 = (LdcInsnNode) insn;
|
LdcInsnNode node1 = (LdcInsnNode) insn;
|
||||||
node1.cst = obf.map((String) node1.cst);
|
node1.cst = obf.map((String) node1.cst);
|
||||||
}
|
}
|
||||||
if(matchesDesc(insn))
|
if (matchesDesc(insn)) {
|
||||||
{
|
|
||||||
LdcInsnNode node1 = (LdcInsnNode) insn;
|
LdcInsnNode node1 = (LdcInsnNode) insn;
|
||||||
LdcInsnNode node2 = (LdcInsnNode) node1.getNext();
|
LdcInsnNode node2 = (LdcInsnNode) node1.getNext();
|
||||||
LdcInsnNode node3 = (LdcInsnNode) node2.getNext();
|
LdcInsnNode node3 = (LdcInsnNode) node2.getNext();
|
||||||
@@ -54,30 +49,24 @@ public class ConstantObfuscator implements Opcodes
|
|||||||
node3.cst = mapping.s_desc;
|
node3.cst = mapping.s_desc;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean matchesClass(AbstractInsnNode insn)
|
private boolean matchesClass(AbstractInsnNode insn) {
|
||||||
{
|
if (insn.getType() != LDC_INSN) return false;
|
||||||
if(insn.getType() != LDC_INSN) return false;
|
|
||||||
insn = insn.getNext();
|
insn = insn.getNext();
|
||||||
if(insn == null || insn.getType() != METHOD_INSN) return false;
|
if (insn == null || insn.getType() != METHOD_INSN) return false;
|
||||||
for(ObfMapping m : classCalls)
|
for (ObfMapping m : classCalls) if (m.matches((MethodInsnNode) insn)) return true;
|
||||||
if(m.matches((MethodInsnNode) insn))
|
|
||||||
return true;
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean matchesDesc(AbstractInsnNode insn)
|
private boolean matchesDesc(AbstractInsnNode insn) {
|
||||||
{
|
if (insn.getType() != LDC_INSN) return false;
|
||||||
if(insn.getType() != LDC_INSN) return false;
|
|
||||||
insn = insn.getNext();
|
insn = insn.getNext();
|
||||||
if(insn == null || insn.getType() != LDC_INSN) return false;
|
if (insn == null || insn.getType() != LDC_INSN) return false;
|
||||||
insn = insn.getNext();
|
insn = insn.getNext();
|
||||||
if(insn == null || insn.getType() != LDC_INSN) return false;
|
if (insn == null || insn.getType() != LDC_INSN) return false;
|
||||||
insn = insn.getNext();
|
insn = insn.getNext();
|
||||||
if(insn == null || insn.getType() != METHOD_INSN) return false;
|
if (insn == null || insn.getType() != METHOD_INSN) return false;
|
||||||
for(ObfMapping m : descCalls)
|
for (ObfMapping m : descCalls) if (m.matches((MethodInsnNode) insn)) return true;
|
||||||
if(m.matches((MethodInsnNode) insn))
|
|
||||||
return true;
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2,12 +2,10 @@ package codechicken.obfuscator;
|
|||||||
|
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
|
|
||||||
public class DummyOutputStream extends OutputStream
|
public class DummyOutputStream extends OutputStream {
|
||||||
{
|
|
||||||
public static DummyOutputStream instance = new DummyOutputStream();
|
public static DummyOutputStream instance = new DummyOutputStream();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void write(int b)
|
public void write(int b) {}
|
||||||
{
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -4,8 +4,8 @@ import java.util.List;
|
|||||||
|
|
||||||
import codechicken.obfuscator.ObfuscationMap.ObfuscationEntry;
|
import codechicken.obfuscator.ObfuscationMap.ObfuscationEntry;
|
||||||
|
|
||||||
public interface IHeirachyEvaluator
|
public interface IHeirachyEvaluator {
|
||||||
{
|
|
||||||
/**
|
/**
|
||||||
* @param desc The mapping descriptor of the class to evaluate heirachy for
|
* @param desc The mapping descriptor of the class to evaluate heirachy for
|
||||||
* @return A list of parents (srg or obf names)
|
* @return A list of parents (srg or obf names)
|
||||||
|
|||||||
@@ -2,8 +2,9 @@ package codechicken.obfuscator;
|
|||||||
|
|
||||||
import java.io.PrintStream;
|
import java.io.PrintStream;
|
||||||
|
|
||||||
public interface ILogStreams
|
public interface ILogStreams {
|
||||||
{
|
|
||||||
public PrintStream err();
|
public PrintStream err();
|
||||||
|
|
||||||
public PrintStream out();
|
public PrintStream out();
|
||||||
}
|
}
|
||||||
@@ -3,32 +3,28 @@ package codechicken.obfuscator;
|
|||||||
import codechicken.lib.asm.ObfMapping;
|
import codechicken.lib.asm.ObfMapping;
|
||||||
import codechicken.obfuscator.ObfuscationMap.ObfuscationEntry;
|
import codechicken.obfuscator.ObfuscationMap.ObfuscationEntry;
|
||||||
|
|
||||||
public class ObfDirection
|
public class ObfDirection {
|
||||||
{
|
|
||||||
public boolean obfuscate;
|
public boolean obfuscate;
|
||||||
public boolean srg;
|
public boolean srg;
|
||||||
public boolean srg_cst;
|
public boolean srg_cst;
|
||||||
|
|
||||||
public ObfDirection setObfuscate(boolean obfuscate)
|
public ObfDirection setObfuscate(boolean obfuscate) {
|
||||||
{
|
|
||||||
this.obfuscate = obfuscate;
|
this.obfuscate = obfuscate;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ObfDirection setSearge(boolean srg)
|
public ObfDirection setSearge(boolean srg) {
|
||||||
{
|
|
||||||
this.srg = srg;
|
this.srg = srg;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ObfDirection setSeargeConstants(boolean srg_cst)
|
public ObfDirection setSeargeConstants(boolean srg_cst) {
|
||||||
{
|
|
||||||
this.srg_cst = srg_cst;
|
this.srg_cst = srg_cst;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ObfMapping obfuscate(ObfuscationEntry map)
|
public ObfMapping obfuscate(ObfuscationEntry map) {
|
||||||
{
|
|
||||||
return srg ? map.srg : obfuscate ? map.obf : map.mcp;
|
return srg ? map.srg : obfuscate ? map.obf : map.mcp;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -4,88 +4,68 @@ import org.objectweb.asm.commons.Remapper;
|
|||||||
|
|
||||||
import codechicken.obfuscator.ObfuscationMap.ObfuscationEntry;
|
import codechicken.obfuscator.ObfuscationMap.ObfuscationEntry;
|
||||||
|
|
||||||
public class ObfRemapper extends Remapper
|
public class ObfRemapper extends Remapper {
|
||||||
{
|
|
||||||
public final ObfuscationMap obf;
|
public final ObfuscationMap obf;
|
||||||
public ObfDirection dir;
|
public ObfDirection dir;
|
||||||
|
|
||||||
public ObfRemapper(ObfuscationMap obf, ObfDirection dir)
|
public ObfRemapper(ObfuscationMap obf, ObfDirection dir) {
|
||||||
{
|
|
||||||
this.obf = obf;
|
this.obf = obf;
|
||||||
this.dir = dir;
|
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
|
@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;
|
ObfuscationEntry map;
|
||||||
if(dir.obfuscate)
|
if (dir.obfuscate) map = obf.lookupMcpClass(name);
|
||||||
map = obf.lookupMcpField(owner, name);
|
else map = obf.lookupObfClass(name);
|
||||||
else
|
|
||||||
map = obf.lookupObfField(owner, name);
|
if (map != null) return dir.obfuscate(map).s_owner;
|
||||||
|
|
||||||
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;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object mapValue(Object cst)
|
public String mapFieldName(String owner, String name, String desc) {
|
||||||
{
|
ObfuscationEntry map;
|
||||||
if(cst instanceof String)
|
if (dir.obfuscate) map = obf.lookupMcpField(owner, name);
|
||||||
{
|
else map = obf.lookupObfField(owner, name);
|
||||||
if(dir.srg_cst)
|
|
||||||
{
|
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);
|
ObfuscationEntry map = obf.lookupSrg((String) cst);
|
||||||
if(map != null)
|
if (map != null) return dir.obfuscate(map).s_name;
|
||||||
return dir.obfuscate(map).s_name;
|
|
||||||
}
|
}
|
||||||
return cst;
|
return cst;
|
||||||
}
|
}
|
||||||
|
|
||||||
return super.mapValue(cst);
|
return super.mapValue(cst);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -12,157 +12,130 @@ import com.google.common.collect.ArrayListMultimap;
|
|||||||
|
|
||||||
import codechicken.lib.asm.ObfMapping;
|
import codechicken.lib.asm.ObfMapping;
|
||||||
|
|
||||||
public class ObfuscationMap
|
public class ObfuscationMap {
|
||||||
{
|
|
||||||
public class ObfuscationEntry
|
public class ObfuscationEntry {
|
||||||
{
|
|
||||||
public final ObfMapping obf;
|
public final ObfMapping obf;
|
||||||
public final ObfMapping srg;
|
public final ObfMapping srg;
|
||||||
public final ObfMapping mcp;
|
public final ObfMapping mcp;
|
||||||
|
|
||||||
public ObfuscationEntry(ObfMapping obf, ObfMapping srg, ObfMapping mcp)
|
public ObfuscationEntry(ObfMapping obf, ObfMapping srg, ObfMapping mcp) {
|
||||||
{
|
|
||||||
this.obf = obf;
|
this.obf = obf;
|
||||||
this.srg = srg;
|
this.srg = srg;
|
||||||
this.mcp = mcp;
|
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> mcpMap = new HashMap<String, ObfuscationEntry>();
|
||||||
public Map<String, ObfuscationEntry> srgMap = new HashMap<String, ObfuscationEntry>();
|
public Map<String, ObfuscationEntry> srgMap = new HashMap<String, ObfuscationEntry>();
|
||||||
public Map<String, ObfuscationEntry> obfMap = new HashMap<String, ObfuscationEntry>();
|
public Map<String, ObfuscationEntry> obfMap = new HashMap<String, ObfuscationEntry>();
|
||||||
|
|
||||||
public ClassEntry(String obf, String srg)
|
public ClassEntry(String obf, String srg) {
|
||||||
{
|
super(new ObfMapping(obf, "", ""), new ObfMapping(srg, "", ""), new ObfMapping(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());
|
ObfuscationEntry entry = new ObfuscationEntry(obf_desc, srg_desc, srg_desc.copy());
|
||||||
obfMap.put(obf_desc.s_name.concat(obf_desc.s_desc), entry);
|
obfMap.put(obf_desc.s_name.concat(obf_desc.s_desc), entry);
|
||||||
srgMap.put(srg_desc.s_name, 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);
|
srgMemberMap.put(srg_desc.s_name, entry);
|
||||||
|
|
||||||
return entry;
|
return entry;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void inheritFrom(ClassEntry p)
|
public void inheritFrom(ClassEntry p) {
|
||||||
{
|
|
||||||
inherit(obfMap, p.obfMap);
|
inherit(obfMap, p.obfMap);
|
||||||
inherit(srgMap, p.srgMap);
|
inherit(srgMap, p.srgMap);
|
||||||
inherit(mcpMap, p.mcpMap);
|
inherit(mcpMap, p.mcpMap);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void inherit(Map<String, ObfuscationEntry> child, Map<String, ObfuscationEntry> parent)
|
private void inherit(Map<String, ObfuscationEntry> child, Map<String, ObfuscationEntry> parent) {
|
||||||
{
|
for (Entry<String, ObfuscationEntry> e : parent.entrySet())
|
||||||
for(Entry<String, ObfuscationEntry> e : parent.entrySet())
|
if (!child.containsKey(e.getKey())) child.put(e.getKey(), e.getValue());
|
||||||
if(!child.containsKey(e.getKey()))
|
|
||||||
child.put(e.getKey(), e.getValue());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private Map<String, ClassEntry> srgMap = new HashMap<String, ClassEntry>();
|
private Map<String, ClassEntry> srgMap = new HashMap<String, ClassEntry>();
|
||||||
private Map<String, ClassEntry> obfMap = new HashMap<String, ClassEntry>();
|
private Map<String, ClassEntry> obfMap = new HashMap<String, ClassEntry>();
|
||||||
private ArrayListMultimap<String, ObfuscationEntry> srgMemberMap = ArrayListMultimap.create();
|
private ArrayListMultimap<String, ObfuscationEntry> srgMemberMap = ArrayListMultimap.create();
|
||||||
|
|
||||||
private IHeirachyEvaluator heirachyEvaluator;
|
private IHeirachyEvaluator heirachyEvaluator;
|
||||||
private HashSet<String> mappedClasses = new HashSet<String>();
|
private HashSet<String> mappedClasses = new HashSet<String>();
|
||||||
public ILogStreams log = SystemLogStreams.inst;
|
public ILogStreams log = SystemLogStreams.inst;
|
||||||
|
|
||||||
public ObfuscationMap setHeirachyEvaluator(IHeirachyEvaluator eval)
|
public ObfuscationMap setHeirachyEvaluator(IHeirachyEvaluator eval) {
|
||||||
{
|
|
||||||
heirachyEvaluator = eval;
|
heirachyEvaluator = eval;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ObfuscationMap setLog(ILogStreams log)
|
public ObfuscationMap setLog(ILogStreams log) {
|
||||||
{
|
|
||||||
this.log = log;
|
this.log = log;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ObfuscationEntry addClass(String obf, String srg)
|
public ObfuscationEntry addClass(String obf, String srg) {
|
||||||
{
|
|
||||||
return addEntry(new ObfMapping(obf, "", ""), new ObfMapping(srg, "", ""));
|
return addEntry(new ObfMapping(obf, "", ""), new ObfMapping(srg, "", ""));
|
||||||
}
|
}
|
||||||
|
|
||||||
public ObfuscationEntry addField(String obf_owner, String obf_name, String srg_owner, String 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, ""));
|
||||||
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)
|
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),
|
return addEntry(new ObfMapping(obf_owner, obf_name, obf_desc), new ObfMapping(srg_owner, srg_name, srg_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);
|
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);
|
e = new ClassEntry(obf_desc.s_owner, srg_desc.s_owner);
|
||||||
obfMap.put(obf_desc.s_owner, e);
|
obfMap.put(obf_desc.s_owner, e);
|
||||||
srgMap.put(srg_desc.s_owner, e);
|
srgMap.put(srg_desc.s_owner, e);
|
||||||
}
|
}
|
||||||
if(obf_desc.s_name.length() > 0)
|
if (obf_desc.s_name.length() > 0) return e.addEntry(obf_desc, srg_desc);
|
||||||
return e.addEntry(obf_desc, srg_desc);
|
|
||||||
|
|
||||||
return e;
|
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);
|
List<ObfuscationEntry> entries = srgMemberMap.get(srg_name);
|
||||||
if(entries.isEmpty())
|
if (entries.isEmpty()) {
|
||||||
{
|
log.err().println("Tried to add mcp name (" + mcp_name + ") for unknown srg key (" + srg_name + ")");
|
||||||
log.err().println("Tried to add mcp name ("+mcp_name+") for unknown srg key ("+srg_name+")");
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
for(ObfuscationEntry entry : entries)
|
for (ObfuscationEntry entry : entries) {
|
||||||
{
|
|
||||||
entry.mcp.s_name = mcp_name;
|
entry.mcp.s_name = mcp_name;
|
||||||
srgMap.get(entry.srg.s_owner).mcpMap.put(entry.mcp.s_name.concat(entry.mcp.s_desc), entry);
|
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);
|
List<ObfuscationEntry> list = srgMemberMap.get(srg_key);
|
||||||
return list.isEmpty() ? null : list.get(0);
|
return list.isEmpty() ? null : list.get(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ObfuscationEntry lookupMcpClass(String name)
|
public ObfuscationEntry lookupMcpClass(String name) {
|
||||||
{
|
|
||||||
return srgMap.get(name);
|
return srgMap.get(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ObfuscationEntry lookupObfClass(String name)
|
public ObfuscationEntry lookupObfClass(String name) {
|
||||||
{
|
|
||||||
return obfMap.get(name);
|
return obfMap.get(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ObfuscationEntry lookupMcpField(String owner, String name)
|
public ObfuscationEntry lookupMcpField(String owner, String name) {
|
||||||
{
|
|
||||||
return lookupMcpMethod(owner, name, "");
|
return lookupMcpMethod(owner, name, "");
|
||||||
}
|
}
|
||||||
|
|
||||||
public ObfuscationEntry lookupSrgField(String owner, String name)
|
public ObfuscationEntry lookupSrgField(String owner, String name) {
|
||||||
{
|
if (name.startsWith("field_")) {
|
||||||
if(name.startsWith("field_"))
|
|
||||||
{
|
|
||||||
ObfuscationEntry e = lookupSrg(name);
|
ObfuscationEntry e = lookupSrg(name);
|
||||||
if(e != null)
|
if (e != null) return e;
|
||||||
return e;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
evaluateHeirachy(owner);
|
evaluateHeirachy(owner);
|
||||||
@@ -170,174 +143,144 @@ public class ObfuscationMap
|
|||||||
return e == null ? null : e.srgMap.get(name);
|
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, "");
|
return lookupObfMethod(owner, name, "");
|
||||||
}
|
}
|
||||||
|
|
||||||
public ObfuscationEntry lookupMcpMethod(String owner, String name, String desc)
|
public ObfuscationEntry lookupMcpMethod(String owner, String name, String desc) {
|
||||||
{
|
|
||||||
evaluateHeirachy(owner);
|
evaluateHeirachy(owner);
|
||||||
ClassEntry e = srgMap.get(owner);
|
ClassEntry e = srgMap.get(owner);
|
||||||
return e == null ? null : e.mcpMap.get(name.concat(desc));
|
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);
|
evaluateHeirachy(owner);
|
||||||
ClassEntry e = obfMap.get(owner);
|
ClassEntry e = obfMap.get(owner);
|
||||||
return e == null ? null : e.obfMap.get(name.concat(desc));
|
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);
|
return mappedClasses.contains(desc.srg.s_owner);
|
||||||
}
|
}
|
||||||
|
|
||||||
private ObfuscationEntry getOrCreateClassEntry(String name)
|
private ObfuscationEntry getOrCreateClassEntry(String name) {
|
||||||
{
|
|
||||||
ObfuscationEntry e = lookupObfClass(name);
|
ObfuscationEntry e = lookupObfClass(name);
|
||||||
if(e == null)
|
if (e == null) e = lookupMcpClass(name);
|
||||||
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
|
||||||
if(e == null)
|
// with no name change.
|
||||||
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;
|
return e;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ObfuscationEntry evaluateHeirachy(String name)
|
public ObfuscationEntry evaluateHeirachy(String name) {
|
||||||
{
|
|
||||||
ObfuscationEntry desc = getOrCreateClassEntry(name);
|
ObfuscationEntry desc = getOrCreateClassEntry(name);
|
||||||
if(isMapped(desc))
|
if (isMapped(desc)) return desc;
|
||||||
return desc;
|
|
||||||
|
|
||||||
mappedClasses.add(desc.srg.s_owner);
|
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.");
|
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);
|
List<String> parents = heirachyEvaluator.getParents(desc);
|
||||||
if(parents == null)
|
if (parents == null) log.err().println("Could not find class: " + desc.srg.s_owner);
|
||||||
log.err().println("Could not find class: "+desc.srg.s_owner);
|
else for (String parent : parents) inherit(desc, evaluateHeirachy(parent));
|
||||||
else
|
|
||||||
for(String parent : parents)
|
|
||||||
inherit(desc, evaluateHeirachy(parent));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return desc;
|
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);
|
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);
|
ClassEntry e = srgMap.get(name);
|
||||||
if(e == null)
|
if (e == null)
|
||||||
throw new IllegalStateException("Tried to inerit to an undefined class: "+name+" extends "+parent);
|
throw new IllegalStateException("Tried to inerit to an undefined class: " + name + " extends " + parent);
|
||||||
ClassEntry p = srgMap.get(parent);
|
ClassEntry p = srgMap.get(parent);
|
||||||
if(p == null)
|
if (p == null)
|
||||||
throw new IllegalStateException("Tried to inerit from undefired parent: "+name+" extends "+parent);
|
throw new IllegalStateException("Tried to inerit from undefired parent: " + name + " extends " + parent);
|
||||||
e.inheritFrom(p);
|
e.inheritFrom(p);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void parseMappings(File[] mappings)
|
public void parseMappings(File[] mappings) {
|
||||||
{
|
|
||||||
parseSRGS(mappings[0]);
|
parseSRGS(mappings[0]);
|
||||||
parseCSV(mappings[1]);
|
parseCSV(mappings[1]);
|
||||||
parseCSV(mappings[2]);
|
parseCSV(mappings[2]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String[] splitLast(String s, char c)
|
public static String[] splitLast(String s, char c) {
|
||||||
{
|
|
||||||
int i = s.lastIndexOf(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];
|
String[] split = new String[4];
|
||||||
int i2 = s.indexOf(c);
|
int i2 = s.indexOf(c);
|
||||||
split[0] = s.substring(0, i2);
|
split[0] = s.substring(0, i2);
|
||||||
int i = i2+1;
|
int i = i2 + 1;
|
||||||
i2 = s.indexOf(c, i);
|
i2 = s.indexOf(c, i);
|
||||||
split[1] = s.substring(i, i2);
|
split[1] = s.substring(i, i2);
|
||||||
i = i2+1;
|
i = i2 + 1;
|
||||||
i2 = s.indexOf(c, i);
|
i2 = s.indexOf(c, i);
|
||||||
split[2] = s.substring(i, i2);
|
split[2] = s.substring(i, i2);
|
||||||
i = i2+1;
|
i = i2 + 1;
|
||||||
i2 = s.indexOf(c, i);
|
i2 = s.indexOf(c, i);
|
||||||
split[3] = s.substring(i);
|
split[3] = s.substring(i);
|
||||||
return split;
|
return split;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void parseSRGS(File srgs)
|
private void parseSRGS(File srgs) {
|
||||||
{
|
log.out().println("Parsing " + srgs.getName());
|
||||||
log.out().println("Parsing "+srgs.getName());
|
|
||||||
|
Function<String, Void> function = new Function<String, Void>() {
|
||||||
Function<String, Void> function = new Function<String, Void>()
|
|
||||||
{
|
|
||||||
@Override
|
@Override
|
||||||
public Void apply(String line)
|
public Void apply(String line) {
|
||||||
{
|
|
||||||
int hpos = line.indexOf('#');
|
int hpos = line.indexOf('#');
|
||||||
if(hpos > 0)
|
if (hpos > 0) line = line.substring(0, hpos).trim();
|
||||||
line = line.substring(0, hpos).trim();
|
if (line.startsWith("CL: ")) {
|
||||||
if(line.startsWith("CL: "))
|
|
||||||
{
|
|
||||||
String[] params = splitLast(line.substring(4), ' ');
|
String[] params = splitLast(line.substring(4), ' ');
|
||||||
addClass(params[0], params[1]);
|
addClass(params[0], params[1]);
|
||||||
}
|
} else if (line.startsWith("FD: ")) {
|
||||||
else if(line.startsWith("FD: "))
|
|
||||||
{
|
|
||||||
String[] params = splitLast(line.substring(4), ' ');
|
String[] params = splitLast(line.substring(4), ' ');
|
||||||
String[] p1 = splitLast(params[0], '/');
|
String[] p1 = splitLast(params[0], '/');
|
||||||
String[] p2 = splitLast(params[1], '/');
|
String[] p2 = splitLast(params[1], '/');
|
||||||
addField(p1[0], p1[1],
|
addField(p1[0], p1[1], p2[0], p2[1]);
|
||||||
p2[0], p2[1]);
|
|
||||||
return null;
|
return null;
|
||||||
}
|
} else if (line.startsWith("MD: ")) {
|
||||||
else if(line.startsWith("MD: "))
|
|
||||||
{
|
|
||||||
String[] params = split4(line.substring(4), ' ');
|
String[] params = split4(line.substring(4), ' ');
|
||||||
String[] p1 = splitLast(params[0], '/');
|
String[] p1 = splitLast(params[0], '/');
|
||||||
String[] p2 = splitLast(params[2], '/');
|
String[] p2 = splitLast(params[2], '/');
|
||||||
addMethod(p1[0], p1[1], params[1],
|
addMethod(p1[0], p1[1], params[1], p2[0], p2[1], params[3]);
|
||||||
p2[0], p2[1], params[3]);
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
ObfuscationRun.processLines(srgs, function);
|
ObfuscationRun.processLines(srgs, function);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void parseCSV(File csv)
|
private void parseCSV(File csv) {
|
||||||
{
|
log.out().println("Parsing " + csv.getName());
|
||||||
log.out().println("Parsing "+csv.getName());
|
|
||||||
|
Function<String, Void> function = new Function<String, Void>() {
|
||||||
Function<String, Void> function = new Function<String, Void>()
|
|
||||||
{
|
|
||||||
@Override
|
@Override
|
||||||
public Void apply(String line)
|
public Void apply(String line) {
|
||||||
{
|
if (line.startsWith("func_") || line.startsWith("field_")) {
|
||||||
if(line.startsWith("func_") || line.startsWith("field_"))
|
|
||||||
{
|
|
||||||
int i = line.indexOf(',');
|
int i = line.indexOf(',');
|
||||||
String srg = line.substring(0, i);
|
String srg = line.substring(0, i);
|
||||||
int i2 = i+1;
|
int i2 = i + 1;
|
||||||
i = line.indexOf(',', i2);
|
i = line.indexOf(',', i2);
|
||||||
String mcp = line.substring(i2, i);
|
String mcp = line.substring(i2, i);
|
||||||
|
|
||||||
addMcpName(srg, mcp);
|
addMcpName(srg, mcp);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
ObfuscationRun.processLines(csv, function);
|
ObfuscationRun.processLines(csv, function);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -8,246 +8,203 @@ import java.text.DecimalFormat;
|
|||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.objectweb.asm.ClassVisitor;
|
import org.objectweb.asm.ClassVisitor;
|
||||||
import org.objectweb.asm.commons.RemappingClassAdapter;
|
import org.objectweb.asm.commons.RemappingClassAdapter;
|
||||||
import org.objectweb.asm.tree.ClassNode;
|
import org.objectweb.asm.tree.ClassNode;
|
||||||
|
|
||||||
import com.google.common.base.Function;
|
import com.google.common.base.Function;
|
||||||
|
|
||||||
public class ObfuscationRun implements ILogStreams
|
public class ObfuscationRun implements ILogStreams {
|
||||||
{
|
|
||||||
public final ObfDirection obfDir;
|
public final ObfDirection obfDir;
|
||||||
public final ObfuscationMap obf;
|
public final ObfuscationMap obf;
|
||||||
public final ObfRemapper obfMapper;
|
public final ObfRemapper obfMapper;
|
||||||
public final ConstantObfuscator cstMappper;
|
public final ConstantObfuscator cstMappper;
|
||||||
|
|
||||||
public File[] mappings;
|
public File[] mappings;
|
||||||
public Map<String, String> config;
|
public Map<String, String> config;
|
||||||
|
|
||||||
private PrintStream out = System.out;
|
private PrintStream out = System.out;
|
||||||
private PrintStream err = System.err;
|
private PrintStream err = System.err;
|
||||||
private PrintStream quietStream = new PrintStream(DummyOutputStream.instance);
|
private PrintStream quietStream = new PrintStream(DummyOutputStream.instance);
|
||||||
|
|
||||||
private boolean verbose;
|
private boolean verbose;
|
||||||
private boolean quiet;
|
private boolean quiet;
|
||||||
|
|
||||||
public boolean clean;
|
public boolean clean;
|
||||||
private long startTime;
|
private long startTime;
|
||||||
private boolean finished;
|
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);
|
obfDir = new ObfDirection().setObfuscate(obfuscate);
|
||||||
this.mappings = mappings;
|
this.mappings = mappings;
|
||||||
this.config = config;
|
this.config = config;
|
||||||
|
|
||||||
obf = new ObfuscationMap().setLog(this);
|
obf = new ObfuscationMap().setLog(this);
|
||||||
obfMapper = new ObfRemapper(obf, obfDir);
|
obfMapper = new ObfRemapper(obf, obfDir);
|
||||||
cstMappper = new ConstantObfuscator(obfMapper,
|
cstMappper = new ConstantObfuscator(
|
||||||
config.get("classConstantCalls").split(","),
|
obfMapper,
|
||||||
|
config.get("classConstantCalls").split(","),
|
||||||
config.get("descConstantCalls").split(","));
|
config.get("descConstantCalls").split(","));
|
||||||
}
|
}
|
||||||
|
|
||||||
public ObfuscationRun setClean()
|
public ObfuscationRun setClean() {
|
||||||
{
|
|
||||||
clean = true;
|
clean = true;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ObfuscationRun setVerbose()
|
public ObfuscationRun setVerbose() {
|
||||||
{
|
|
||||||
verbose = true;
|
verbose = true;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ObfuscationRun setQuiet()
|
public ObfuscationRun setQuiet() {
|
||||||
{
|
|
||||||
quiet = true;
|
quiet = true;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ObfuscationRun setOut(PrintStream p)
|
public ObfuscationRun setOut(PrintStream p) {
|
||||||
{
|
|
||||||
out = p;
|
out = p;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public PrintStream out()
|
public PrintStream out() {
|
||||||
{
|
|
||||||
return quiet ? quietStream : out;
|
return quiet ? quietStream : out;
|
||||||
}
|
}
|
||||||
|
|
||||||
public PrintStream fine()
|
public PrintStream fine() {
|
||||||
{
|
|
||||||
return verbose ? out : quietStream;
|
return verbose ? out : quietStream;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ObfuscationRun setErr(PrintStream p)
|
public ObfuscationRun setErr(PrintStream p) {
|
||||||
{
|
|
||||||
err = p;
|
err = p;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public PrintStream err()
|
public PrintStream err() {
|
||||||
{
|
|
||||||
return quiet ? quietStream : err;
|
return quiet ? quietStream : err;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ObfuscationRun setSearge()
|
public ObfuscationRun setSearge() {
|
||||||
{
|
|
||||||
obfDir.setSearge(true);
|
obfDir.setSearge(true);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ObfuscationRun setSeargeConstants()
|
public ObfuscationRun setSeargeConstants() {
|
||||||
{
|
|
||||||
obfDir.setSeargeConstants(true);
|
obfDir.setSeargeConstants(true);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void start()
|
public void start() {
|
||||||
{
|
|
||||||
startTime = System.currentTimeMillis();
|
startTime = System.currentTimeMillis();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Map<String, String> fillDefaults(Map<String, String> config)
|
public static Map<String, String> fillDefaults(Map<String, String> config) {
|
||||||
{
|
if (!config.containsKey("excludedPackages")) config.put(
|
||||||
if(!config.containsKey("excludedPackages"))
|
"excludedPackages",
|
||||||
config.put("excludedPackages", "java/;sun/;javax/;scala/;" +
|
"java/;sun/;javax/;scala/;" + "argo/;org/lwjgl/;org/objectweb/;org/bouncycastle/;com/google/");
|
||||||
"argo/;org/lwjgl/;org/objectweb/;org/bouncycastle/;com/google/");
|
if (!config.containsKey("ignore")) config.put("ignore", ".");
|
||||||
if(!config.containsKey("ignore"))
|
if (!config.containsKey("classConstantCalls")) config.put(
|
||||||
config.put("ignore", ".");
|
"classConstantCalls",
|
||||||
if(!config.containsKey("classConstantCalls"))
|
"codechicken/lib/asm/ObfMapping.<init>(Ljava/lang/String;)V,"
|
||||||
config.put("classConstantCalls",
|
+ "codechicken/lib/asm/ObfMapping.subclass(Ljava/lang/String;)Lcodechicken/lib/asm/ObfMapping;,"
|
||||||
"codechicken/lib/asm/ObfMapping.<init>(Ljava/lang/String;)V," +
|
+ "codechicken/lib/asm/ObfMapping.<init>(Lcodechicken/lib/asm/ObfMapping;Ljava/lang/String;)V");
|
||||||
"codechicken/lib/asm/ObfMapping.subclass(Ljava/lang/String;)Lcodechicken/lib/asm/ObfMapping;," +
|
if (!config.containsKey("descConstantCalls")) config.put(
|
||||||
"codechicken/lib/asm/ObfMapping.<init>(Lcodechicken/lib/asm/ObfMapping;Ljava/lang/String;)V");
|
"descConstantCalls",
|
||||||
if(!config.containsKey("descConstantCalls"))
|
"codechicken/lib/asm/ObfMapping.<init>(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V,"
|
||||||
config.put("descConstantCalls",
|
+ "org/objectweb/asm/MethodVisitor.visitFieldInsn(ILjava/lang/String;Ljava/lang/String;Ljava/lang/String;)V,"
|
||||||
"codechicken/lib/asm/ObfMapping.<init>(Ljava/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.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.visitFieldInsn(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/MethodVisitor.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/MethodNode.visitMethodInsn(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");
|
||||||
"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;
|
return config;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void processLines(File file, Function<String, Void> function)
|
public static void processLines(File file, Function<String, Void> function) {
|
||||||
{
|
try {
|
||||||
try
|
|
||||||
{
|
|
||||||
BufferedReader reader = new BufferedReader(new FileReader(file));
|
BufferedReader reader = new BufferedReader(new FileReader(file));
|
||||||
String line;
|
String line;
|
||||||
while((line = reader.readLine()) != null)
|
while ((line = reader.readLine()) != null) function.apply(line);
|
||||||
function.apply(line);
|
|
||||||
reader.close();
|
reader.close();
|
||||||
}
|
} catch (Exception e) {
|
||||||
catch(Exception e)
|
|
||||||
{
|
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void processFiles(File dir, Function<File, Void> function, boolean recursive)
|
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);
|
||||||
for(File file : dir.listFiles())
|
else function.apply(file);
|
||||||
if(file.isDirectory() && recursive)
|
|
||||||
processFiles(file, function, recursive);
|
|
||||||
else
|
|
||||||
function.apply(file);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void deleteDir(File directory, boolean remove)
|
public static void deleteDir(File directory, boolean remove) {
|
||||||
{
|
if (!directory.exists()) {
|
||||||
if(!directory.exists())
|
if (!remove) directory.mkdirs();
|
||||||
{
|
|
||||||
if(!remove)directory.mkdirs();
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
for(File file : directory.listFiles())
|
for (File file : directory.listFiles()) {
|
||||||
{
|
if (file.isDirectory()) {
|
||||||
if(file.isDirectory())
|
|
||||||
{
|
|
||||||
deleteDir(file, true);
|
deleteDir(file, true);
|
||||||
}
|
} else {
|
||||||
else
|
if (!file.delete()) throw new RuntimeException("Delete Failed: " + file);
|
||||||
{
|
|
||||||
if(!file.delete())
|
|
||||||
throw new RuntimeException("Delete Failed: "+file);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(remove)
|
if (remove) {
|
||||||
{
|
if (!directory.delete()) throw new RuntimeException("Delete Failed: " + directory);
|
||||||
if(!directory.delete())
|
|
||||||
throw new RuntimeException("Delete Failed: "+directory);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static File[] parseConfDir(File confDir) {
|
public static File[] parseConfDir(File confDir) {
|
||||||
File srgDir = new File(confDir, "conf");
|
File srgDir = new File(confDir, "conf");
|
||||||
if(!srgDir.exists())
|
if (!srgDir.exists()) srgDir = confDir;
|
||||||
srgDir = confDir;
|
|
||||||
|
|
||||||
File srgs = new File(srgDir, "packaged.srg");
|
File srgs = new File(srgDir, "packaged.srg");
|
||||||
if(!srgs.exists())
|
if (!srgs.exists()) srgs = new File(srgDir, "joined.srg");
|
||||||
srgs = new File(srgDir, "joined.srg");
|
if (!srgs.exists()) throw new RuntimeException("Could not find packaged.srg or joined.srg");
|
||||||
if(!srgs.exists())
|
|
||||||
throw new RuntimeException("Could not find packaged.srg or joined.srg");
|
|
||||||
|
|
||||||
File mapDir = new File(confDir, "mappings");
|
File mapDir = new File(confDir, "mappings");
|
||||||
if(!mapDir.exists())
|
if (!mapDir.exists()) mapDir = confDir;
|
||||||
mapDir = confDir;
|
|
||||||
|
|
||||||
File methods = new File(mapDir, "methods.csv");
|
File methods = new File(mapDir, "methods.csv");
|
||||||
if(!methods.exists())
|
if (!methods.exists()) throw new RuntimeException("Could not find methods.csv");
|
||||||
throw new RuntimeException("Could not find methods.csv");
|
|
||||||
File fields = new File(mapDir, "fields.csv");
|
File fields = new File(mapDir, "fields.csv");
|
||||||
if(!fields.exists())
|
if (!fields.exists()) throw new RuntimeException("Could not find fields.csv");
|
||||||
throw new RuntimeException("Could not find fields.csv");
|
|
||||||
|
return new File[] { srgs, methods, fields };
|
||||||
return new File[]{srgs, methods, fields};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public long startTime()
|
public long startTime() {
|
||||||
{
|
|
||||||
return startTime;
|
return startTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void remap(ClassNode cnode, ClassVisitor cv)
|
public void remap(ClassNode cnode, ClassVisitor cv) {
|
||||||
{
|
|
||||||
cstMappper.transform(cnode);
|
cstMappper.transform(cnode);
|
||||||
cnode.accept(new RemappingClassAdapter(cv, obfMapper));
|
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>();
|
List<String> parents = new LinkedList<String>();
|
||||||
if(cnode.superName != null)
|
if (cnode.superName != null) parents.add(cnode.superName);
|
||||||
parents.add(cnode.superName);
|
|
||||||
|
for (String s_interface : cnode.interfaces) parents.add(s_interface);
|
||||||
for(String s_interface : cnode.interfaces)
|
|
||||||
parents.add(s_interface);
|
|
||||||
|
|
||||||
return parents;
|
return parents;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void finish(boolean errored)
|
public void finish(boolean errored) {
|
||||||
{
|
long millis = System.currentTimeMillis() - startTime;
|
||||||
long millis = System.currentTimeMillis()-startTime;
|
out().println(
|
||||||
out().println((errored ? "Errored after" : "Done in ")+new DecimalFormat("0.00").format(millis/1000D)+"s");
|
(errored ? "Errored after" : "Done in ") + new DecimalFormat("0.00").format(millis / 1000D) + "s");
|
||||||
finished = true;
|
finished = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean finished()
|
public boolean finished() {
|
||||||
{
|
|
||||||
return finished;
|
return finished;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void parseMappings()
|
public void parseMappings() {
|
||||||
{
|
|
||||||
obf.parseMappings(mappings);
|
obf.parseMappings(mappings);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2,19 +2,17 @@ package codechicken.obfuscator;
|
|||||||
|
|
||||||
import java.io.PrintStream;
|
import java.io.PrintStream;
|
||||||
|
|
||||||
public class SystemLogStreams implements ILogStreams
|
public class SystemLogStreams implements ILogStreams {
|
||||||
{
|
|
||||||
public static SystemLogStreams inst = new SystemLogStreams();
|
public static SystemLogStreams inst = new SystemLogStreams();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PrintStream err()
|
public PrintStream err() {
|
||||||
{
|
|
||||||
return System.err;
|
return System.err;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PrintStream out()
|
public PrintStream out() {
|
||||||
{
|
|
||||||
return System.out;
|
return System.out;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,13 +1,12 @@
|
|||||||
[
|
|
||||||
{
|
{
|
||||||
"modid": "${modId}",
|
"modListVersion": 2,
|
||||||
"name": "${modName}",
|
"modList": [{
|
||||||
"description": "Base common code for all chickenbones mods.
|
"modid": "${modId}",
|
||||||
|
"name": "${modName}",
|
||||||
Supporters: JBoyJr",
|
"description": "Base common code for all chickenbones mods. Supporters: JBoyJr",
|
||||||
"version": "${modVersion}",
|
"version": "${modVersion}",
|
||||||
"mcversion": "${minecraftVersion}",
|
"mcversion": "${minecraftVersion}",
|
||||||
"url": "http://www.minecraftforum.net/topic/909223",
|
"url": "http://www.minecraftforum.net/topic/909223",
|
||||||
"authorList": [ "ChickenBones" ]
|
"authorList": ["ChickenBones", "GTNH Team"]
|
||||||
|
}]
|
||||||
}
|
}
|
||||||
]
|
|
||||||
Reference in new issue
Block a user