diff --git a/.editorconfig b/.editorconfig
new file mode 100644
index 0000000..4ffbd90
--- /dev/null
+++ b/.editorconfig
@@ -0,0 +1,22 @@
+# 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
+
+[*.lang]
+trim_trailing_whitespace = false
diff --git a/.gitattributes b/.gitattributes
new file mode 100644
index 0000000..6f227db
--- /dev/null
+++ b/.gitattributes
@@ -0,0 +1,41 @@
+* 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
+
+*.[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
+
+*.[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
\ No newline at end of file
diff --git a/.github/scripts/test_no_error_reports b/.github/scripts/test_no_error_reports
new file mode 100644
index 0000000..1fcc739
--- /dev/null
+++ b/.github/scripts/test_no_error_reports
@@ -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
diff --git a/.github/scripts/update_version b/.github/scripts/update_version
new file mode 100644
index 0000000..3e5f752
--- /dev/null
+++ b/.github/scripts/update_version
@@ -0,0 +1,12 @@
+#!/usr/bin/env bash
+
+if ! git diff --name-only HEAD HEAD~1 | grep -qF 'build.gradle'; then
+ new_version="$(date +%s)"
+ sed --in-place "s!^//version:.*!//version: $new_version!g" build.gradle
+ git add build.gradle
+ git commit -m "[ci skip] update build script version to $new_version"
+ git push
+ printf 'Updated buildscript version to %s\n' "$new_version"
+else
+ printf 'Ignored buildscript version update: no changes detected\n'
+fi
diff --git a/.github/workflows/build-and-test.yml b/.github/workflows/build-and-test.yml
new file mode 100644
index 0000000..56a1ad5
--- /dev/null
+++ b/.github/workflows/build-and-test.yml
@@ -0,0 +1,45 @@
+# 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
+
+on:
+ pull_request:
+ branches: [ master, main ]
+ push:
+ branches: [ master, main ]
+
+jobs:
+ build-and-test:
+ runs-on: ubuntu-latest
+ steps:
+ - 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.5 minutes
+ run: |
+ mkdir run
+ echo "eula=true" > run/eula.txt
+ timeout 90 ./gradlew runServer 2>&1 | tee -a server.log || true
+
+ - name: Test no errors reported during server run
+ run: |
+ chmod +x .github/scripts/test_no_error_reports
+ .github/scripts/test_no_error_reports
diff --git a/.github/workflows/release-tags.yml b/.github/workflows/release-tags.yml
new file mode 100644
index 0000000..c86d888
--- /dev/null
+++ b/.github/workflows/release-tags.yml
@@ -0,0 +1,51 @@
+# 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
+
+on:
+ push:
+ tags:
+ - '*'
+
+jobs:
+ build:
+ runs-on: ubuntu-latest
+ steps:
+ - 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
+
+ - name: Publish to Maven
+ run: ./gradlew publish
+ env:
+ MAVEN_USER: ${{ secrets.MAVEN_USER }}
+ MAVEN_PASSWORD: ${{ secrets.MAVEN_PASSWORD }}
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..48c525b
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,32 @@
+.gradle
+.settings
+/.idea/
+/.vscode/
+/run/
+/build/
+/eclipse/
+.classpath
+.project
+/bin/
+/config/
+/crash-reports/
+/logs/
+options.txt
+/saves/
+usernamecache.json
+banned-ips.json
+banned-players.json
+eula.txt
+ops.json
+server.properties
+servers.dat
+usercache.json
+whitelist.json
+/out/
+*.iml
+*.ipr
+*.iws
+src/main/resources/mixins.*.json
+*.bat
+*.DS_Store
+!gradlew.bat
diff --git a/CODEOWNERS b/CODEOWNERS
new file mode 100644
index 0000000..a6b5f68
--- /dev/null
+++ b/CODEOWNERS
@@ -0,0 +1,3 @@
+# Any Github changes require admin approval
+/.github/** @GTNewHorizons/admin
+
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000..0a04128
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,165 @@
+ GNU LESSER GENERAL PUBLIC LICENSE
+ Version 3, 29 June 2007
+
+ Copyright (C) 2007 Free Software Foundation, Inc.
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+
+ This version of the GNU Lesser General Public License incorporates
+the terms and conditions of version 3 of the GNU General Public
+License, supplemented by the additional permissions listed below.
+
+ 0. Additional Definitions.
+
+ As used herein, "this License" refers to version 3 of the GNU Lesser
+General Public License, and the "GNU GPL" refers to version 3 of the GNU
+General Public License.
+
+ "The Library" refers to a covered work governed by this License,
+other than an Application or a Combined Work as defined below.
+
+ An "Application" is any work that makes use of an interface provided
+by the Library, but which is not otherwise based on the Library.
+Defining a subclass of a class defined by the Library is deemed a mode
+of using an interface provided by the Library.
+
+ A "Combined Work" is a work produced by combining or linking an
+Application with the Library. The particular version of the Library
+with which the Combined Work was made is also called the "Linked
+Version".
+
+ The "Minimal Corresponding Source" for a Combined Work means the
+Corresponding Source for the Combined Work, excluding any source code
+for portions of the Combined Work that, considered in isolation, are
+based on the Application, and not on the Linked Version.
+
+ The "Corresponding Application Code" for a Combined Work means the
+object code and/or source code for the Application, including any data
+and utility programs needed for reproducing the Combined Work from the
+Application, but excluding the System Libraries of the Combined Work.
+
+ 1. Exception to Section 3 of the GNU GPL.
+
+ You may convey a covered work under sections 3 and 4 of this License
+without being bound by section 3 of the GNU GPL.
+
+ 2. Conveying Modified Versions.
+
+ If you modify a copy of the Library, and, in your modifications, a
+facility refers to a function or data to be supplied by an Application
+that uses the facility (other than as an argument passed when the
+facility is invoked), then you may convey a copy of the modified
+version:
+
+ a) under this License, provided that you make a good faith effort to
+ ensure that, in the event an Application does not supply the
+ function or data, the facility still operates, and performs
+ whatever part of its purpose remains meaningful, or
+
+ b) under the GNU GPL, with none of the additional permissions of
+ this License applicable to that copy.
+
+ 3. Object Code Incorporating Material from Library Header Files.
+
+ The object code form of an Application may incorporate material from
+a header file that is part of the Library. You may convey such object
+code under terms of your choice, provided that, if the incorporated
+material is not limited to numerical parameters, data structure
+layouts and accessors, or small macros, inline functions and templates
+(ten or fewer lines in length), you do both of the following:
+
+ a) Give prominent notice with each copy of the object code that the
+ Library is used in it and that the Library and its use are
+ covered by this License.
+
+ b) Accompany the object code with a copy of the GNU GPL and this license
+ document.
+
+ 4. Combined Works.
+
+ You may convey a Combined Work under terms of your choice that,
+taken together, effectively do not restrict modification of the
+portions of the Library contained in the Combined Work and reverse
+engineering for debugging such modifications, if you also do each of
+the following:
+
+ a) Give prominent notice with each copy of the Combined Work that
+ the Library is used in it and that the Library and its use are
+ covered by this License.
+
+ b) Accompany the Combined Work with a copy of the GNU GPL and this license
+ document.
+
+ c) For a Combined Work that displays copyright notices during
+ execution, include the copyright notice for the Library among
+ these notices, as well as a reference directing the user to the
+ copies of the GNU GPL and this license document.
+
+ d) Do one of the following:
+
+ 0) Convey the Minimal Corresponding Source under the terms of this
+ License, and the Corresponding Application Code in a form
+ suitable for, and under terms that permit, the user to
+ recombine or relink the Application with a modified version of
+ the Linked Version to produce a modified Combined Work, in the
+ manner specified by section 6 of the GNU GPL for conveying
+ Corresponding Source.
+
+ 1) Use a suitable shared library mechanism for linking with the
+ Library. A suitable mechanism is one that (a) uses at run time
+ a copy of the Library already present on the user's computer
+ system, and (b) will operate properly with a modified version
+ of the Library that is interface-compatible with the Linked
+ Version.
+
+ e) Provide Installation Information, but only if you would otherwise
+ be required to provide such information under section 6 of the
+ GNU GPL, and only to the extent that such information is
+ necessary to install and execute a modified version of the
+ Combined Work produced by recombining or relinking the
+ Application with a modified version of the Linked Version. (If
+ you use option 4d0, the Installation Information must accompany
+ the Minimal Corresponding Source and Corresponding Application
+ Code. If you use option 4d1, you must provide the Installation
+ Information in the manner specified by section 6 of the GNU GPL
+ for conveying Corresponding Source.)
+
+ 5. Combined Libraries.
+
+ You may place library facilities that are a work based on the
+Library side by side in a single library together with other library
+facilities that are not Applications and are not covered by this
+License, and convey such a combined library under terms of your
+choice, if you do both of the following:
+
+ a) Accompany the combined library with a copy of the same work based
+ on the Library, uncombined with any other library facilities,
+ conveyed under the terms of this License.
+
+ b) Give prominent notice with the combined library that part of it
+ is a work based on the Library, and explaining where to find the
+ accompanying uncombined form of the same work.
+
+ 6. Revised Versions of the GNU Lesser General Public License.
+
+ The Free Software Foundation may publish revised and/or new versions
+of the GNU Lesser General Public License from time to time. Such new
+versions will be similar in spirit to the present version, but may
+differ in detail to address new problems or concerns.
+
+ Each version is given a distinguishing version number. If the
+Library as you received it specifies that a certain numbered version
+of the GNU Lesser General Public License "or any later version"
+applies to it, you have the option of following the terms and
+conditions either of that published version or of any later version
+published by the Free Software Foundation. If the Library as you
+received it does not specify a version number of the GNU Lesser
+General Public License, you may choose any version of the GNU Lesser
+General Public License ever published by the Free Software Foundation.
+
+ If the Library as you received it specifies that a proxy can decide
+whether future versions of the GNU Lesser General Public License shall
+apply, that proxy's public statement of acceptance of any version is
+permanent authorization for you to choose that version for the
+Library.
diff --git a/README.MD b/README.MD
new file mode 100644
index 0000000..4e0477b
--- /dev/null
+++ b/README.MD
@@ -0,0 +1,5 @@
+# Modular UI - Rendering mod for Minecraft 1.7.10
+
+This is a WIP project for backporting [Modular UI](https://github.com/CleanroomMC/ModularUI) mod from 1.12.2
+
+This mod is under LGPL-3 license
diff --git a/build.gradle b/build.gradle
new file mode 100644
index 0000000..997b94d
--- /dev/null
+++ b/build.gradle
@@ -0,0 +1,968 @@
+//version: 1661114848
+/*
+ DO NOT CHANGE THIS FILE!
+ Also, you may replace this file at any time if there is an update available.
+ Please check https://github.com/GTNewHorizons/ExampleMod1.7.10/blob/main/build.gradle for updates.
+ */
+
+
+import com.github.jengelman.gradle.plugins.shadow.tasks.ConfigureShadowRelocation
+import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
+import org.gradle.internal.logging.text.StyledTextOutput.Style
+import org.gradle.internal.logging.text.StyledTextOutputFactory
+
+import java.nio.file.Files
+import java.nio.file.Paths
+import java.util.concurrent.TimeUnit
+import java.util.zip.ZipEntry
+import java.util.zip.ZipInputStream
+import java.util.zip.ZipOutputStream
+
+buildscript {
+ repositories {
+ mavenCentral()
+
+ maven {
+ name 'forge'
+ url 'https://maven.minecraftforge.net'
+ }
+ maven {
+ // GTNH ForgeGradle Fork
+ name = "GTNH Maven"
+ url = "http://jenkins.usrv.eu:8081/nexus/content/groups/public/"
+ }
+ maven {
+ name 'sonatype'
+ url 'https://oss.sonatype.org/content/repositories/snapshots/'
+ }
+ maven {
+ name 'Scala CI dependencies'
+ url 'https://repo1.maven.org/maven2/'
+ }
+ }
+ dependencies {
+ classpath 'net.minecraftforge.gradle:ForgeGradle:1.2.9'
+ }
+}
+plugins {
+ id 'java-library'
+ id 'idea'
+ id 'eclipse'
+ id 'scala'
+ id 'maven-publish'
+ id 'org.jetbrains.kotlin.jvm' version '1.5.30' apply false
+ id 'org.jetbrains.kotlin.kapt' version '1.5.30' apply false
+ id 'com.google.devtools.ksp' version '1.5.30-1.0.0' apply false
+ id 'org.ajoberstar.grgit' version '4.1.1'
+ id 'com.github.johnrengelman.shadow' version '4.0.4'
+ id 'com.palantir.git-version' version '0.13.0' apply false
+ id 'de.undercouch.download' version '5.0.1'
+ id 'com.github.gmazzo.buildconfig' version '3.0.3' apply false
+ id 'com.diffplug.spotless' version '6.7.2' apply false
+}
+boolean settingsupdated = verifySettingsGradle()
+settingsupdated = verifyGitAttributes() || settingsupdated
+if (settingsupdated)
+ throw new GradleException("Settings has been updated, please re-run task.")
+
+dependencies {
+ implementation 'com.diffplug:blowdryer:1.6.0'
+}
+
+apply plugin: 'com.diffplug.blowdryer'
+
+if (project.file('.git/HEAD').isFile()) {
+ apply plugin: 'com.palantir.git-version'
+}
+
+def out = services.get(StyledTextOutputFactory).create('an-output')
+
+apply plugin: 'forge'
+
+def projectJavaVersion = JavaLanguageVersion.of(8)
+
+java {
+ toolchain {
+ languageVersion.set(projectJavaVersion)
+ }
+}
+
+idea {
+ module {
+ inheritOutputDirs = true
+ downloadJavadoc = true
+ downloadSources = true
+ }
+}
+
+boolean disableSpotless = project.hasProperty("disableSpotless") ? project.disableSpotless.toBoolean() : false
+
+if (!disableSpotless) {
+ apply plugin: 'com.diffplug.spotless'
+ apply from: Blowdryer.file('spotless.gradle')
+}
+
+if (JavaVersion.current() != JavaVersion.VERSION_1_8) {
+ throw new GradleException("This project requires Java 8, but it's running on " + JavaVersion.current())
+}
+
+checkPropertyExists("modName")
+checkPropertyExists("modId")
+checkPropertyExists("modGroup")
+checkPropertyExists("autoUpdateBuildScript")
+checkPropertyExists("minecraftVersion")
+checkPropertyExists("forgeVersion")
+checkPropertyExists("replaceGradleTokenInFile")
+checkPropertyExists("gradleTokenModId")
+checkPropertyExists("gradleTokenModName")
+checkPropertyExists("gradleTokenVersion")
+checkPropertyExists("gradleTokenGroupName")
+checkPropertyExists("apiPackage")
+checkPropertyExists("accessTransformersFile")
+checkPropertyExists("usesMixins")
+checkPropertyExists("mixinPlugin")
+checkPropertyExists("mixinsPackage")
+checkPropertyExists("coreModClass")
+checkPropertyExists("containsMixinsAndOrCoreModOnly")
+checkPropertyExists("usesShadowedDependencies")
+checkPropertyExists("developmentEnvironmentUserName")
+
+boolean noPublishedSources = project.hasProperty("noPublishedSources") ? project.noPublishedSources.toBoolean() : false
+boolean usesMixinDebug = project.hasProperty('usesMixinDebug') ?: project.usesMixins.toBoolean()
+boolean forceEnableMixins = project.hasProperty('forceEnableMixins') ? project.forceEnableMixins.toBoolean() : false
+String channel = project.hasProperty('channel') ? project.channel : 'stable'
+String mappingsVersion = project.hasProperty('mappingsVersion') ? project.mappingsVersion : '12'
+String javaSourceDir = "src/main/java/"
+String scalaSourceDir = "src/main/scala/"
+String kotlinSourceDir = "src/main/kotlin/"
+
+String targetPackageJava = javaSourceDir + modGroup.toString().replaceAll("\\.", "/")
+String targetPackageScala = scalaSourceDir + modGroup.toString().replaceAll("\\.", "/")
+String targetPackageKotlin = kotlinSourceDir + modGroup.toString().replaceAll("\\.", "/")
+if (!(getFile(targetPackageJava).exists() || getFile(targetPackageScala).exists() || getFile(targetPackageKotlin).exists())) {
+ throw new GradleException("Could not resolve \"modGroup\"! Could not find " + targetPackageJava + " or " + targetPackageScala + " or " + targetPackageKotlin)
+}
+
+if (apiPackage) {
+ targetPackageJava = javaSourceDir + modGroup.toString().replaceAll("\\.", "/") + "/" + apiPackage.toString().replaceAll("\\.", "/")
+ targetPackageScala = scalaSourceDir + modGroup.toString().replaceAll("\\.", "/") + "/" + apiPackage.toString().replaceAll("\\.", "/")
+ targetPackageKotlin = kotlinSourceDir + modGroup.toString().replaceAll("\\.", "/") + "/" + apiPackage.toString().replaceAll("\\.", "/")
+ if (!(getFile(targetPackageJava).exists() || getFile(targetPackageScala).exists() || getFile(targetPackageKotlin).exists())) {
+ throw new GradleException("Could not resolve \"apiPackage\"! Could not find " + targetPackageJava + " or " + targetPackageScala + " or " + targetPackageKotlin)
+ }
+}
+
+if (accessTransformersFile) {
+ String targetFile = "src/main/resources/META-INF/" + accessTransformersFile
+ if (!getFile(targetFile).exists()) {
+ throw new GradleException("Could not resolve \"accessTransformersFile\"! Could not find " + targetFile)
+ }
+}
+
+if (usesMixins.toBoolean()) {
+ if (mixinsPackage.isEmpty() || mixinPlugin.isEmpty()) {
+ throw new GradleException("\"mixinPlugin\" requires \"mixinsPackage\" and \"mixinPlugin\" to be set!")
+ }
+
+ targetPackageJava = javaSourceDir + modGroup.toString().replaceAll("\\.", "/") + "/" + mixinsPackage.toString().replaceAll("\\.", "/")
+ targetPackageScala = scalaSourceDir + modGroup.toString().replaceAll("\\.", "/") + "/" + mixinsPackage.toString().replaceAll("\\.", "/")
+ targetPackageKotlin = kotlinSourceDir + modGroup.toString().replaceAll("\\.", "/") + "/" + mixinsPackage.toString().replaceAll("\\.", "/")
+ if (!(getFile(targetPackageJava).exists() || getFile(targetPackageScala).exists() || getFile(targetPackageKotlin).exists())) {
+ throw new GradleException("Could not resolve \"mixinsPackage\"! Could not find " + targetPackageJava + " or " + targetPackageScala + " or " + targetPackageKotlin)
+ }
+
+ String targetFileJava = javaSourceDir + modGroup.toString().replaceAll("\\.", "/") + "/" + mixinPlugin.toString().replaceAll("\\.", "/") + ".java"
+ String targetFileScala = scalaSourceDir + modGroup.toString().replaceAll("\\.", "/") + "/" + mixinPlugin.toString().replaceAll("\\.", "/") + ".scala"
+ String targetFileScalaJava = scalaSourceDir + modGroup.toString().replaceAll("\\.", "/") + "/" + mixinPlugin.toString().replaceAll("\\.", "/") + ".java"
+ String targetFileKotlin = kotlinSourceDir + modGroup.toString().replaceAll("\\.", "/") + "/" + mixinPlugin.toString().replaceAll("\\.", "/") + ".kt"
+ if (!(getFile(targetFileJava).exists() || getFile(targetFileScala).exists() || getFile(targetFileScalaJava).exists() || getFile(targetFileKotlin).exists())) {
+ throw new GradleException("Could not resolve \"mixinPlugin\"! Could not find " + targetFileJava + " or " + targetFileScala + " or " + targetFileScalaJava + " or " + targetFileKotlin)
+ }
+}
+
+if (coreModClass) {
+ String targetFileJava = javaSourceDir + modGroup.toString().replaceAll("\\.", "/") + "/" + coreModClass.toString().replaceAll("\\.", "/") + ".java"
+ String targetFileScala = scalaSourceDir + modGroup.toString().replaceAll("\\.", "/") + "/" + coreModClass.toString().replaceAll("\\.", "/") + ".scala"
+ String targetFileScalaJava = scalaSourceDir + modGroup.toString().replaceAll("\\.", "/") + "/" + coreModClass.toString().replaceAll("\\.", "/") + ".java"
+ String targetFileKotlin = kotlinSourceDir + modGroup.toString().replaceAll("\\.", "/") + "/" + coreModClass.toString().replaceAll("\\.", "/") + ".kt"
+ if (!(getFile(targetFileJava).exists() || getFile(targetFileScala).exists() || getFile(targetFileScalaJava).exists() || getFile(targetFileKotlin).exists())) {
+ throw new GradleException("Could not resolve \"coreModClass\"! Could not find " + targetFileJava + " or " + targetFileScala + " or " + targetFileScalaJava + " or " + targetFileKotlin)
+ }
+}
+
+configurations.all {
+ resolutionStrategy.cacheChangingModulesFor(0, TimeUnit.SECONDS)
+
+ // Make sure GregTech build won't time out
+ System.setProperty("org.gradle.internal.http.connectionTimeout", 120000 as String)
+ System.setProperty("org.gradle.internal.http.socketTimeout", 120000 as String)
+}
+
+// Fix Jenkins' Git: chmod a file should not be detected as a change and append a '.dirty' to the version
+try {
+ 'git config core.fileMode false'.execute()
+}
+catch (Exception ignored) {
+ out.style(Style.Failure).println("git isn't installed at all")
+}
+
+// Pulls version first from the VERSION env and then git tag
+String identifiedVersion
+String versionOverride = System.getenv("VERSION") ?: null
+try {
+ identifiedVersion = versionOverride == null ? gitVersion() : versionOverride
+}
+catch (Exception ignored) {
+ out.style(Style.Failure).text(
+ 'This mod must be version controlled by Git AND the repository must provide at least one tag,\n' +
+ 'or the VERSION override must be set! ').style(Style.SuccessHeader).text('(Do NOT download from GitHub using the ZIP option, instead\n' +
+ 'clone the repository, see ').style(Style.Info).text('https://gtnh.miraheze.org/wiki/Development').style(Style.SuccessHeader).println(' for details.)'
+ )
+ versionOverride = 'NO-GIT-TAG-SET'
+ identifiedVersion = versionOverride
+}
+version = minecraftVersion + '-' + identifiedVersion
+ext {
+ modVersion = identifiedVersion
+}
+
+if (identifiedVersion == versionOverride) {
+ out.style(Style.Failure).text('Override version to ').style(Style.Identifier).text(modVersion).style(Style.Failure).println('!\7')
+}
+
+group = modGroup
+if (project.hasProperty("customArchiveBaseName") && customArchiveBaseName) {
+ archivesBaseName = customArchiveBaseName
+} else {
+ archivesBaseName = modId
+}
+
+def arguments = []
+def jvmArguments = []
+
+if (usesMixins.toBoolean() || forceEnableMixins) {
+ arguments += [
+ "--tweakClass org.spongepowered.asm.launch.MixinTweaker"
+ ]
+ if (usesMixinDebug.toBoolean()) {
+ jvmArguments += [
+ "-Dmixin.debug.countInjections=true",
+ "-Dmixin.debug.verbose=true",
+ "-Dmixin.debug.export=true"
+ ]
+ }
+}
+
+minecraft {
+ version = minecraftVersion + '-' + forgeVersion + '-' + minecraftVersion
+ runDir = 'run'
+
+ if (replaceGradleTokenInFile) {
+ replaceIn replaceGradleTokenInFile
+ if (gradleTokenModId) {
+ replace gradleTokenModId, modId
+ }
+ if (gradleTokenModName) {
+ replace gradleTokenModName, modName
+ }
+ if (gradleTokenVersion) {
+ replace gradleTokenVersion, modVersion
+ }
+ if (gradleTokenGroupName) {
+ replace gradleTokenGroupName, modGroup
+ }
+ }
+
+ clientIntellijRun {
+ args(arguments)
+ jvmArgs(jvmArguments)
+
+ if (developmentEnvironmentUserName) {
+ args("--username", developmentEnvironmentUserName)
+ }
+ }
+
+ serverIntellijRun {
+ args(arguments)
+ jvmArgs(jvmArguments)
+ }
+}
+
+if (file('addon.gradle').exists()) {
+ apply from: 'addon.gradle'
+}
+
+apply from: 'repositories.gradle'
+
+configurations {
+ implementation.extendsFrom(shadowImplementation) // TODO: remove after all uses are refactored
+ implementation.extendsFrom(shadowCompile)
+ implementation.extendsFrom(shadeCompile)
+}
+
+repositories {
+ maven {
+ name 'Overmind forge repo mirror'
+ url 'https://gregtech.overminddl1.com/'
+ }
+ if (usesMixins.toBoolean() || forceEnableMixins) {
+ maven {
+ name 'sponge'
+ url 'https://repo.spongepowered.org/repository/maven-public'
+ }
+ maven {
+ url 'https://jitpack.io'
+ }
+ }
+}
+
+dependencies {
+ if (usesMixins.toBoolean()) {
+ annotationProcessor('org.ow2.asm:asm-debug-all:5.0.3')
+ annotationProcessor('com.google.guava:guava:24.1.1-jre')
+ annotationProcessor('com.google.code.gson:gson:2.8.6')
+ annotationProcessor('org.spongepowered:mixin:0.8-SNAPSHOT')
+ }
+ if (usesMixins.toBoolean() || forceEnableMixins) {
+ // using 0.8 to workaround a issue in 0.7 which fails mixin application
+ compile('com.github.GTNewHorizons:SpongePoweredMixin:0.7.12-GTNH') {
+ // Mixin includes a lot of dependencies that are too up-to-date
+ exclude module: 'launchwrapper'
+ exclude module: 'guava'
+ exclude module: 'gson'
+ exclude module: 'commons-io'
+ exclude module: 'log4j-core'
+ }
+ compile('com.github.GTNewHorizons:SpongeMixins:1.5.0')
+ }
+}
+
+apply from: 'dependencies.gradle'
+
+def mixingConfigRefMap = 'mixins.' + modId + '.refmap.json'
+def refMap = "${tasks.compileJava.temporaryDir}" + File.separator + mixingConfigRefMap
+def mixinSrg = "${tasks.reobf.temporaryDir}" + File.separator + "mixins.srg"
+
+task generateAssets {
+ if (usesMixins.toBoolean()) {
+ def mixinConfigFile = getFile("/src/main/resources/mixins." + modId + ".json");
+ if (!mixinConfigFile.exists()) {
+ mixinConfigFile.text = """{
+ "required": true,
+ "minVersion": "0.7.11",
+ "package": "${modGroup}.${mixinsPackage}",
+ "plugin": "${modGroup}.${mixinPlugin}",
+ "refmap": "${mixingConfigRefMap}",
+ "target": "@env(DEFAULT)",
+ "compatibilityLevel": "JAVA_8",
+ "mixins": [],
+ "client": [],
+ "server": []
+}
+"""
+ }
+ }
+}
+
+task relocateShadowJar(type: ConfigureShadowRelocation) {
+ target = tasks.shadowJar
+ prefix = modGroup + ".shadow"
+}
+
+shadowJar {
+ project.configurations.shadeCompile.each { dep ->
+ from(project.zipTree(dep)) {
+ exclude 'META-INF', 'META-INF/**'
+ }
+ }
+
+ manifest {
+ attributes(getManifestAttributes())
+ }
+
+ minimize() // This will only allow shading for actually used classes
+ configurations = [
+ project.configurations.shadowImplementation,
+ project.configurations.shadowCompile
+ ]
+ dependsOn(relocateShadowJar)
+}
+
+jar {
+ project.configurations.shadeCompile.each { dep ->
+ from(project.zipTree(dep)) {
+ exclude 'META-INF', 'META-INF/**'
+ }
+ }
+
+ manifest {
+ attributes(getManifestAttributes())
+ }
+
+ if (usesShadowedDependencies.toBoolean()) {
+ dependsOn(shadowJar)
+ enabled = false
+ }
+}
+
+reobf {
+ if (usesMixins.toBoolean()) {
+ addExtraSrgFile mixinSrg
+ }
+}
+
+afterEvaluate {
+ if (usesMixins.toBoolean()) {
+ tasks.compileJava {
+ options.compilerArgs += [
+ "-AreobfSrgFile=${tasks.reobf.srg}",
+ "-AoutSrgFile=${mixinSrg}",
+ "-AoutRefMapFile=${refMap}",
+ // Elan: from what I understand they are just some linter configs so you get some warning on how to properly code
+ "-XDenableSunApiLintControl",
+ "-XDignore.symbol.file"
+ ]
+ }
+ }
+}
+
+runClient {
+ if (developmentEnvironmentUserName) {
+ arguments += [
+ "--username",
+ developmentEnvironmentUserName
+ ]
+ }
+
+ args(arguments)
+ jvmArgs(jvmArguments)
+}
+
+runServer {
+ args(arguments)
+ jvmArgs(jvmArguments)
+}
+
+tasks.withType(JavaExec).configureEach {
+ javaLauncher.set(
+ javaToolchains.launcherFor {
+ languageVersion = projectJavaVersion
+ }
+ )
+}
+
+processResources {
+ // this will ensure that this task is redone when the versions change.
+ inputs.property "version", project.version
+ inputs.property "mcversion", project.minecraft.version
+ exclude("spotless.gradle")
+
+ // replace stuff in mcmod.info, nothing else
+ from(sourceSets.main.resources.srcDirs) {
+ include 'mcmod.info'
+
+ // replace modVersion and minecraftVersion
+ expand "minecraftVersion": project.minecraft.version,
+ "modVersion": modVersion,
+ "modId": modId,
+ "modName": modName
+ }
+
+ if (usesMixins.toBoolean()) {
+ from refMap
+ }
+
+ // copy everything else that's not the mcmod.info
+ from(sourceSets.main.resources.srcDirs) {
+ exclude 'mcmod.info'
+ exclude 'spotless.gradle'
+ }
+}
+
+def getManifestAttributes() {
+ def manifestAttributes = [:]
+ if (!containsMixinsAndOrCoreModOnly.toBoolean() && (usesMixins.toBoolean() || coreModClass)) {
+ manifestAttributes += ["FMLCorePluginContainsFMLMod": true]
+ }
+
+ if (accessTransformersFile) {
+ manifestAttributes += ["FMLAT": accessTransformersFile.toString()]
+ }
+
+ if (coreModClass) {
+ manifestAttributes += ["FMLCorePlugin": modGroup + "." + coreModClass]
+ }
+
+ if (usesMixins.toBoolean()) {
+ manifestAttributes += [
+ "TweakClass" : "org.spongepowered.asm.launch.MixinTweaker",
+ "MixinConfigs" : "mixins." + modId + ".json",
+ "ForceLoadAsMod": !containsMixinsAndOrCoreModOnly.toBoolean()
+ ]
+ }
+ return manifestAttributes
+}
+
+task sourcesJar(type: Jar) {
+ from(sourceSets.main.allSource)
+ from(file("$projectDir/LICENSE"))
+ getArchiveClassifier().set('sources')
+}
+
+task shadowDevJar(type: ShadowJar) {
+ project.configurations.shadeCompile.each { dep ->
+ from(project.zipTree(dep)) {
+ exclude 'META-INF', 'META-INF/**'
+ }
+ }
+
+ from sourceSets.main.output
+ getArchiveClassifier().set("dev")
+
+ manifest {
+ attributes(getManifestAttributes())
+ }
+
+ minimize() // This will only allow shading for actually used classes
+ configurations = [
+ project.configurations.shadowImplementation,
+ project.configurations.shadowCompile
+ ]
+}
+
+task relocateShadowDevJar(type: ConfigureShadowRelocation) {
+ target = tasks.shadowDevJar
+ prefix = modGroup + ".shadow"
+}
+
+task circularResolverJar(type: Jar) {
+ dependsOn(relocateShadowDevJar)
+ dependsOn(shadowDevJar)
+ enabled = false
+}
+
+task devJar(type: Jar) {
+ project.configurations.shadeCompile.each { dep ->
+ from(project.zipTree(dep)) {
+ exclude 'META-INF', 'META-INF/**'
+ }
+ }
+
+ from sourceSets.main.output
+ getArchiveClassifier().set("dev")
+
+ manifest {
+ attributes(getManifestAttributes())
+ }
+
+ if (usesShadowedDependencies.toBoolean()) {
+ dependsOn(circularResolverJar)
+ enabled = false
+ }
+}
+
+task apiJar(type: Jar) {
+ from(sourceSets.main.allSource) {
+ include modGroup.toString().replaceAll("\\.", "/") + "/" + apiPackage.toString().replaceAll("\\.", "/") + '/**'
+ }
+
+ from(sourceSets.main.output) {
+ include modGroup.toString().replaceAll("\\.", "/") + "/" + apiPackage.toString().replaceAll("\\.", "/") + '/**'
+ }
+
+ from(sourceSets.main.resources.srcDirs) {
+ include("LICENSE")
+ }
+
+ getArchiveClassifier().set('api')
+}
+
+artifacts {
+ if (!noPublishedSources) {
+ archives sourcesJar
+ }
+ archives devJar
+ if (apiPackage) {
+ archives apiJar
+ }
+}
+
+// The gradle metadata includes all of the additional deps that we disabled from POM generation (including forgeBin with no groupID),
+// and isn't strictly needed with the POM so just disable it.
+tasks.withType(GenerateModuleMetadata) {
+ enabled = false
+}
+
+// workaround variable hiding in pom processing
+def projectConfigs = project.configurations
+
+publishing {
+ publications {
+ maven(MavenPublication) {
+ from components.java
+ if (usesShadowedDependencies.toBoolean()) {
+ artifact source: shadowJar, classifier: ""
+ }
+ if (!noPublishedSources) {
+ artifact source: sourcesJar, classifier: "sources"
+ }
+ artifact source: usesShadowedDependencies.toBoolean() ? shadowDevJar : devJar, classifier: "dev"
+ if (apiPackage) {
+ artifact source: apiJar, classifier: "api"
+ }
+
+ groupId = System.getenv("ARTIFACT_GROUP_ID") ?: "com.github.GTNewHorizons"
+ artifactId = System.getenv("ARTIFACT_ID") ?: project.name
+ // Using the identified version, not project.version as it has the prepended 1.7.10
+ version = System.getenv("RELEASE_VERSION") ?: identifiedVersion
+
+ // remove extra garbage from minecraft and minecraftDeps configuration
+ pom.withXml {
+ def badArtifacts = [:].withDefault { [] as Set }
+ for (configuration in [
+ projectConfigs.minecraft,
+ projectConfigs.minecraftDeps
+ ]) {
+ for (dependency in configuration.allDependencies) {
+ badArtifacts[dependency.group == null ? "" : dependency.group] += dependency.name
+ }
+ }
+ // example for specifying extra stuff to ignore
+ // badArtifacts["org.example.group"] += "artifactName"
+
+ Node pomNode = asNode()
+ pomNode.dependencies.'*'.findAll() {
+ badArtifacts[it.groupId.text()].contains(it.artifactId.text())
+ }.each() {
+ it.parent().remove(it)
+ }
+ }
+ }
+ }
+
+ repositories {
+ maven {
+ url = "http://jenkins.usrv.eu:8081/nexus/content/repositories/releases"
+ credentials {
+ username = System.getenv("MAVEN_USER") ?: "NONE"
+ password = System.getenv("MAVEN_PASSWORD") ?: "NONE"
+ }
+ }
+ }
+}
+
+// Updating
+task updateBuildScript {
+ doLast {
+ if (performBuildScriptUpdate(projectDir.toString())) return
+
+ print("Build script already up-to-date!")
+ }
+}
+
+if (!project.getGradle().startParameter.isOffline() && isNewBuildScriptVersionAvailable(projectDir.toString())) {
+ if (autoUpdateBuildScript.toBoolean()) {
+ performBuildScriptUpdate(projectDir.toString())
+ } else {
+ out.style(Style.SuccessHeader).println("Build script update available! Run 'gradle updateBuildScript'")
+ }
+}
+
+static URL availableBuildScriptUrl() {
+ new URL("https://raw.githubusercontent.com/GTNewHorizons/ExampleMod1.7.10/master/build.gradle")
+}
+
+static URL exampleSettingsGradleUrl() {
+ new URL("https://raw.githubusercontent.com/GTNewHorizons/ExampleMod1.7.10/master/settings.gradle.example")
+}
+
+static URL exampleGitAttributesUrl() {
+ new URL("https://raw.githubusercontent.com/GTNewHorizons/ExampleMod1.7.10/master/.gitattributes")
+}
+
+
+boolean verifyGitAttributes() {
+ def gitattributesFile = getFile(".gitattributes")
+ if (!gitattributesFile.exists()) {
+ println("Downloading default .gitattributes")
+ exampleGitAttributesUrl().withInputStream { i -> gitattributesFile.withOutputStream { it << i } }
+ exec {
+ workingDir '.'
+ commandLine 'git', 'add', '--renormalize', '.'
+ }
+ return true
+ }
+ return false
+}
+
+boolean verifySettingsGradle() {
+ def settingsFile = getFile("settings.gradle")
+ if (!settingsFile.exists()) {
+ println("Downloading default settings.gradle")
+ exampleSettingsGradleUrl().withInputStream { i -> settingsFile.withOutputStream { it << i } }
+ return true
+ }
+ return false
+}
+
+boolean performBuildScriptUpdate(String projectDir) {
+ if (isNewBuildScriptVersionAvailable(projectDir)) {
+ def buildscriptFile = getFile("build.gradle")
+ availableBuildScriptUrl().withInputStream { i -> buildscriptFile.withOutputStream { it << i } }
+ out.style(Style.Success).print("Build script updated. Please REIMPORT the project or RESTART your IDE!")
+ boolean settingsupdated = verifySettingsGradle()
+ settingsupdated = verifyGitAttributes() || settingsupdated
+ if (settingsupdated)
+ throw new GradleException("Settings has been updated, please re-run task.")
+ return true
+ }
+ return false
+}
+
+boolean isNewBuildScriptVersionAvailable(String projectDir) {
+ Map parameters = ["connectTimeout": 2000, "readTimeout": 2000]
+
+ String currentBuildScript = getFile("build.gradle").getText()
+ String currentBuildScriptHash = getVersionHash(currentBuildScript)
+ String availableBuildScript = availableBuildScriptUrl().newInputStream(parameters).getText()
+ String availableBuildScriptHash = getVersionHash(availableBuildScript)
+
+ boolean isUpToDate = currentBuildScriptHash.empty || availableBuildScriptHash.empty || currentBuildScriptHash == availableBuildScriptHash
+ return !isUpToDate
+}
+
+static String getVersionHash(String buildScriptContent) {
+ String versionLine = buildScriptContent.find("^//version: [a-z0-9]*")
+ if (versionLine != null) {
+ return versionLine.split(": ").last()
+ }
+ return ""
+}
+
+configure(updateBuildScript) {
+ group = 'forgegradle'
+ description = 'Updates the build script to the latest version'
+}
+
+// Parameter Deobfuscation
+
+task deobfParams {
+ doLast {
+
+ String mcpDir = "$project.gradle.gradleUserHomeDir/caches/minecraft/de/oceanlabs/mcp/mcp_$channel/$mappingsVersion"
+ String mcpZIP = "$mcpDir/mcp_$channel-$mappingsVersion-${minecraftVersion}.zip"
+ String paramsCSV = "$mcpDir/params.csv"
+
+ download.run {
+ src "https://maven.minecraftforge.net/de/oceanlabs/mcp/mcp_$channel/$mappingsVersion-$minecraftVersion/mcp_$channel-$mappingsVersion-${minecraftVersion}.zip"
+ dest mcpZIP
+ overwrite false
+ }
+
+ if (!file(paramsCSV).exists()) {
+ println("Extracting MCP archive ...")
+ unzip(mcpZIP, mcpDir)
+ }
+
+ println("Parsing params.csv ...")
+ Map params = new HashMap<>()
+ Files.lines(Paths.get(paramsCSV)).forEach { line ->
+ String[] cells = line.split(",")
+ if (cells.length > 2 && cells[0].matches("p_i?\\d+_\\d+_")) {
+ params.put(cells[0], cells[1])
+ }
+ }
+
+ out.style(Style.Success).println("Modified ${replaceParams(file("$projectDir/src/main/java"), params)} files!")
+ out.style(Style.Failure).println("Don't forget to verify that the code still works as before!\n It could be broken due to duplicate variables existing now\n or parameters taking priority over other variables.")
+ }
+}
+
+static int replaceParams(File file, Map params) {
+ int fileCount = 0
+
+ if (file.isDirectory()) {
+ for (File f : file.listFiles()) {
+ fileCount += replaceParams(f, params)
+ }
+ return fileCount
+ }
+ println("Visiting ${file.getName()} ...")
+ try {
+ String content = new String(Files.readAllBytes(file.toPath()))
+ int hash = content.hashCode()
+ params.forEach { key, value ->
+ content = content.replaceAll(key, value)
+ }
+ if (hash != content.hashCode()) {
+ Files.write(file.toPath(), content.getBytes("UTF-8"))
+ return 1
+ }
+ } catch (Exception e) {
+ e.printStackTrace()
+ }
+ return 0
+}
+
+// Credit: bitsnaps (https://gist.github.com/bitsnaps/00947f2dce66f4bbdabc67d7e7b33681)
+static unzip(String zipFileName, String outputDir) {
+ byte[] buffer = new byte[16384]
+ ZipInputStream zis = new ZipInputStream(new FileInputStream(zipFileName))
+ ZipEntry zipEntry = zis.getNextEntry()
+ while (zipEntry != null) {
+ File newFile = new File(outputDir + File.separator, zipEntry.name)
+ if (zipEntry.isDirectory()) {
+ if (!newFile.isDirectory() && !newFile.mkdirs()) {
+ throw new IOException("Failed to create directory $newFile")
+ }
+ } else {
+ // fix for Windows-created archives
+ File parent = newFile.parentFile
+ if (!parent.isDirectory() && !parent.mkdirs()) {
+ throw new IOException("Failed to create directory $parent")
+ }
+ // write file content
+ FileOutputStream fos = new FileOutputStream(newFile)
+ int len = 0
+ while ((len = zis.read(buffer)) > 0) {
+ fos.write(buffer, 0, len)
+ }
+ fos.close()
+ }
+ zipEntry = zis.getNextEntry()
+ }
+ zis.closeEntry()
+ zis.close()
+}
+
+configure(deobfParams) {
+ group = 'forgegradle'
+ description = 'Rename all obfuscated parameter names inherited from Minecraft classes'
+}
+
+// Dependency Deobfuscation
+
+def deobf(String sourceURL) {
+ try {
+ URL url = new URL(sourceURL)
+ String fileName = url.getFile()
+
+ //get rid of directories:
+ int lastSlash = fileName.lastIndexOf("/")
+ if (lastSlash > 0) {
+ fileName = fileName.substring(lastSlash + 1)
+ }
+ //get rid of extension:
+ if (fileName.endsWith(".jar") || fileName.endsWith(".litemod")) {
+ fileName = fileName.substring(0, fileName.lastIndexOf("."))
+ }
+
+ String hostName = url.getHost()
+ if (hostName.startsWith("www.")) {
+ hostName = hostName.substring(4)
+ }
+ List parts = Arrays.asList(hostName.split("\\."))
+ Collections.reverse(parts)
+ hostName = String.join(".", parts)
+
+ return deobf(sourceURL, "$hostName/$fileName")
+ } catch (Exception e) {
+ return deobf(sourceURL, "deobf/${sourceURL.hashCode()}")
+ }
+}
+
+// The method above is to be preferred. Use this method if the filename is not at the end of the URL.
+def deobf(String sourceURL, String rawFileName) {
+ String bon2Version = "2.5.1"
+ String fileName = URLDecoder.decode(rawFileName, "UTF-8")
+ String cacheDir = "$project.gradle.gradleUserHomeDir/caches"
+ String bon2Dir = "$cacheDir/forge_gradle/deobf"
+ String bon2File = "$bon2Dir/BON2-${bon2Version}.jar"
+ String obfFile = "$cacheDir/modules-2/files-2.1/${fileName}.jar"
+ String deobfFile = "$cacheDir/modules-2/files-2.1/${fileName}-deobf.jar"
+
+ if (file(deobfFile).exists()) {
+ return files(deobfFile)
+ }
+
+ String mappingsVer
+ String remoteMappings = project.hasProperty('remoteMappings') ? project.remoteMappings : 'https://raw.githubusercontent.com/MinecraftForge/FML/1.7.10/conf/'
+ if (remoteMappings) {
+ String id = "${forgeVersion.split("\\.")[3]}-$minecraftVersion"
+ String mappingsZIP = "$cacheDir/forge_gradle/maven_downloader/de/oceanlabs/mcp/mcp_snapshot_nodoc/$id/mcp_snapshot_nodoc-${id}.zip"
+
+ zipMappings(mappingsZIP, remoteMappings, bon2Dir)
+
+ mappingsVer = "snapshot_$id"
+ } else {
+ mappingsVer = "${channel}_$mappingsVersion"
+ }
+
+ download.run {
+ src "http://jenkins.usrv.eu:8081/nexus/content/repositories/releases/com/github/parker8283/BON2/$bon2Version-CUSTOM/BON2-$bon2Version-CUSTOM-all.jar"
+ dest bon2File
+ quiet true
+ overwrite false
+ }
+
+ download.run {
+ src sourceURL
+ dest obfFile
+ quiet true
+ overwrite false
+ }
+
+ exec {
+ commandLine 'java', '-jar', bon2File, '--inputJar', obfFile, '--outputJar', deobfFile, '--mcVer', minecraftVersion, '--mappingsVer', mappingsVer, '--notch'
+ workingDir bon2Dir
+ standardOutput = new FileOutputStream("${deobfFile}.log")
+ }
+
+ return files(deobfFile)
+}
+
+def zipMappings(String zipPath, String url, String bon2Dir) {
+ File zipFile = new File(zipPath)
+ if (zipFile.exists()) {
+ return
+ }
+
+ String fieldsCache = "$bon2Dir/data/fields.csv"
+ String methodsCache = "$bon2Dir/data/methods.csv"
+
+ download.run {
+ src "${url}fields.csv"
+ dest fieldsCache
+ quiet true
+ }
+ download.run {
+ src "${url}methods.csv"
+ dest methodsCache
+ quiet true
+ }
+
+ zipFile.getParentFile().mkdirs()
+ ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(zipFile))
+
+ zos.putNextEntry(new ZipEntry("fields.csv"))
+ Files.copy(Paths.get(fieldsCache), zos)
+ zos.closeEntry()
+
+ zos.putNextEntry(new ZipEntry("methods.csv"))
+ Files.copy(Paths.get(methodsCache), zos)
+ zos.closeEntry()
+
+ zos.close()
+}
+
+// Helper methods
+
+def checkPropertyExists(String propertyName) {
+ if (!project.hasProperty(propertyName)) {
+ throw new GradleException("This project requires a property \"" + propertyName + "\"! Please add it your \"gradle.properties\". You can find all properties and their description here: https://github.com/GTNewHorizons/ExampleMod1.7.10/blob/main/gradle.properties")
+ }
+}
+
+def getFile(String relativePath) {
+ return new File(projectDir, relativePath)
+}
diff --git a/dependencies.gradle b/dependencies.gradle
new file mode 100644
index 0000000..3a0f62b
--- /dev/null
+++ b/dependencies.gradle
@@ -0,0 +1,8 @@
+// Add your dependencies here
+
+dependencies {
+ compile 'org.jetbrains:annotations:23.0.0'
+
+ compile("com.github.GTNewHorizons:CodeChickenLib:1.1.5.3:dev")
+ compile("com.github.GTNewHorizons:NotEnoughItems:2.3.1-GTNH:dev")
+}
diff --git a/gradle.properties b/gradle.properties
new file mode 100644
index 0000000..9e048bb
--- /dev/null
+++ b/gradle.properties
@@ -0,0 +1,84 @@
+modName = Modular UI
+
+# This is a case-sensitive string to identify your mod. Convention is to use lower case.
+modId = modularui
+
+modGroup = com.gtnewhorizons.modularui
+
+# WHY is there no version field?
+# The build script relies on git to provide a version via tags. It is super easy and will enable you to always know the
+# code base or your binary. Check out this tutorial: https://blog.mattclemente.com/2017/10/13/versioning-with-git-tags/
+
+# Will update your build.gradle automatically whenever an update is available
+autoUpdateBuildScript = false
+
+minecraftVersion = 1.7.10
+forgeVersion = 10.13.4.1614
+
+# Specify a MCP channel and mappings version for dependency deobfuscation and the deobfParams task.
+channel = stable
+mappingsVersion = 12
+
+# Define other MCP mappings for dependency deobfuscation
+remoteMappings = https://raw.githubusercontent.com/MinecraftForge/FML/1.7.10/conf/
+
+# Select a username for testing your mod with breakpoints. You may leave this empty for a random username each time you
+# restart Minecraft in development. Choose this dependent on your mod:
+# Do you need consistent player progressing (for example Thaumcraft)? -> Select a name
+# Do you need to test how your custom blocks interacts with a player that is not the owner? -> leave name empty
+developmentEnvironmentUserName = Developer
+
+# Define a source file of your project with:
+# 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
+# version in @Mod([...], version = VERSION, [...])
+# Leave these properties empty to skip individual token replacements
+replaceGradleTokenInFile = Tags.java
+gradleTokenModId = GRADLETOKEN_MODID
+gradleTokenModName = GRADLETOKEN_MODNAME
+gradleTokenVersion = GRADLETOKEN_VERSION
+gradleTokenGroupName = GRADLETOKEN_GROUPNAME
+
+# 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.
+# Example value: apiPackage = api + modGroup = com.myname.mymodid -> com.myname.mymodid.api
+apiPackage =
+
+# 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
+accessTransformersFile =
+
+# Provides setup for Mixins if enabled. If you don't know what mixins are: Keep it disabled!
+usesMixins = true
+# Adds some debug arguments like verbose output and export
+usesMixinDebug = false
+# Specify the location of your implementation of IMixinConfigPlugin. Leave it empty otherwise.
+mixinPlugin = mixinplugin.MixinPlugin
+# Specify the package that contains all of your Mixins. You may only place Mixins in this package or the build will fail!
+mixinsPackage = mixins
+# Specify the core mod entry class if you use a core mod. This class must implement IFMLLoadingPlugin!
+# This parameter is for legacy compatibility only
+# Example value: coreModClass = asm.FMLPlugin + modGroup = com.myname.mymodid -> com.myname.mymodid.asm.FMLPlugin
+coreModClass =
+# If your project is only a consolidation of mixins or a core mod and does NOT contain a 'normal' mod ( = some class
+# that is annotated with @Mod) you want this to be true. When in doubt: leave it on false!
+containsMixinsAndOrCoreModOnly = false
+
+# Enables Mixins even if this mod doesn't use them, useful if one of the dependencies uses mixins.
+forceEnableMixins = false
+
+# If enabled, you may use 'shadowCompile' for dependencies. They will be integrated in your jar. It is your
+# responsibility check the licence and request permission for distribution, if required.
+usesShadowedDependencies = false
+
+# Optional parameter to customize the produced artifacts. Use this to preserver artifact naming when migrating older
+# projects. New projects should not use this parameter.
+#customArchiveBaseName =
+
+# Optional parameter to prevent the source code from being published
+# noPublishedSources =
+
+# Uncomment this to disable spotless checks
+# This should only be uncommented to keep it easier to sync with upstream/other forks.
+# That is, if there is no other active fork/upstream, NEVER change this.
+disableSpotless = true
diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar
new file mode 100644
index 0000000..5c2d1cf
Binary files /dev/null and b/gradle/wrapper/gradle-wrapper.jar differ
diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties
new file mode 100644
index 0000000..3ab0b72
--- /dev/null
+++ b/gradle/wrapper/gradle-wrapper.properties
@@ -0,0 +1,5 @@
+distributionBase=GRADLE_USER_HOME
+distributionPath=wrapper/dists
+distributionUrl=https\://services.gradle.org/distributions/gradle-6.9.1-bin.zip
+zipStoreBase=GRADLE_USER_HOME
+zipStorePath=wrapper/dists
diff --git a/gradlew b/gradlew
new file mode 100644
index 0000000..83f2acf
--- /dev/null
+++ b/gradlew
@@ -0,0 +1,188 @@
+#!/usr/bin/env sh
+
+#
+# Copyright 2015 the original author or authors.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# https://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+##############################################################################
+##
+## Gradle start up script for UN*X
+##
+##############################################################################
+
+# Attempt to set APP_HOME
+# Resolve links: $0 may be a link
+PRG="$0"
+# Need this for relative symlinks.
+while [ -h "$PRG" ] ; do
+ ls=`ls -ld "$PRG"`
+ link=`expr "$ls" : '.*-> \(.*\)$'`
+ if expr "$link" : '/.*' > /dev/null; then
+ PRG="$link"
+ else
+ PRG=`dirname "$PRG"`"/$link"
+ fi
+done
+SAVED="`pwd`"
+cd "`dirname \"$PRG\"`/" >/dev/null
+APP_HOME="`pwd -P`"
+cd "$SAVED" >/dev/null
+
+APP_NAME="Gradle"
+APP_BASE_NAME=`basename "$0"`
+
+# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
+DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
+
+# Use the maximum available, or set MAX_FD != -1 to use that value.
+MAX_FD="maximum"
+
+warn () {
+ echo "$*"
+}
+
+die () {
+ echo
+ echo "$*"
+ echo
+ exit 1
+}
+
+# OS specific support (must be 'true' or 'false').
+cygwin=false
+msys=false
+darwin=false
+nonstop=false
+case "`uname`" in
+ CYGWIN* )
+ cygwin=true
+ ;;
+ Darwin* )
+ darwin=true
+ ;;
+ MINGW* )
+ msys=true
+ ;;
+ NONSTOP* )
+ nonstop=true
+ ;;
+esac
+
+CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
+
+# Determine the Java command to use to start the JVM.
+if [ -n "$JAVA_HOME" ] ; then
+ if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
+ # IBM's JDK on AIX uses strange locations for the executables
+ JAVACMD="$JAVA_HOME/jre/sh/java"
+ else
+ JAVACMD="$JAVA_HOME/bin/java"
+ fi
+ if [ ! -x "$JAVACMD" ] ; then
+ die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
+
+Please set the JAVA_HOME variable in your environment to match the
+location of your Java installation."
+ fi
+else
+ 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.
+
+Please set the JAVA_HOME variable in your environment to match the
+location of your Java installation."
+fi
+
+# Increase the maximum file descriptors if we can.
+if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
+ MAX_FD_LIMIT=`ulimit -H -n`
+ if [ $? -eq 0 ] ; then
+ if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
+ MAX_FD="$MAX_FD_LIMIT"
+ fi
+ ulimit -n $MAX_FD
+ if [ $? -ne 0 ] ; then
+ warn "Could not set maximum file descriptor limit: $MAX_FD"
+ fi
+ else
+ warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
+ fi
+fi
+
+# 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
+fi
+
+# Escape application args
+save () {
+ for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
+ echo " "
+}
+APP_ARGS=$(save "$@")
+
+# Collect all arguments for the java command, following the shell quoting and substitution rules
+eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
+
+# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
+if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
+ cd "$(dirname "$0")"
+fi
+
+exec "$JAVACMD" "$@"
diff --git a/gradlew.bat b/gradlew.bat
new file mode 100644
index 0000000..9618d8d
--- /dev/null
+++ b/gradlew.bat
@@ -0,0 +1,100 @@
+@rem
+@rem Copyright 2015 the original author or authors.
+@rem
+@rem Licensed under the Apache License, Version 2.0 (the "License");
+@rem you may not use this file except in compliance with the License.
+@rem You may obtain a copy of the License at
+@rem
+@rem https://www.apache.org/licenses/LICENSE-2.0
+@rem
+@rem Unless required by applicable law or agreed to in writing, software
+@rem distributed under the License is distributed on an "AS IS" BASIS,
+@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+@rem See the License for the specific language governing permissions and
+@rem limitations under the License.
+@rem
+
+@if "%DEBUG%" == "" @echo off
+@rem ##########################################################################
+@rem
+@rem Gradle startup script for Windows
+@rem
+@rem ##########################################################################
+
+@rem Set local scope for the variables with windows NT shell
+if "%OS%"=="Windows_NT" setlocal
+
+set DIRNAME=%~dp0
+if "%DIRNAME%" == "" set DIRNAME=.
+set APP_BASE_NAME=%~n0
+set APP_HOME=%DIRNAME%
+
+@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"
+
+@rem Find java.exe
+if defined JAVA_HOME goto findJavaFromJavaHome
+
+set JAVA_EXE=java.exe
+%JAVA_EXE% -version >NUL 2>&1
+if "%ERRORLEVEL%" == "0" goto init
+
+echo.
+echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
+echo.
+echo Please set the JAVA_HOME variable in your environment to match the
+echo location of your Java installation.
+
+goto fail
+
+:findJavaFromJavaHome
+set JAVA_HOME=%JAVA_HOME:"=%
+set JAVA_EXE=%JAVA_HOME%/bin/java.exe
+
+if exist "%JAVA_EXE%" goto init
+
+echo.
+echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
+echo.
+echo Please set the JAVA_HOME variable in your environment to match the
+echo location of your Java installation.
+
+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
+@rem Setup the command line
+
+set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
+
+@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%
+
+:end
+@rem End local scope for the variables with windows NT shell
+if "%ERRORLEVEL%"=="0" goto mainEnd
+
+:fail
+rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
+rem the _cmd.exe /c_ return code!
+if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
+exit /b 1
+
+:mainEnd
+if "%OS%"=="Windows_NT" endlocal
+
+:omega
diff --git a/jitpack.yml b/jitpack.yml
new file mode 100644
index 0000000..09bbb51
--- /dev/null
+++ b/jitpack.yml
@@ -0,0 +1,2 @@
+before_install:
+ - ./gradlew setupCIWorkspace
\ No newline at end of file
diff --git a/repositories.gradle b/repositories.gradle
new file mode 100644
index 0000000..c884390
--- /dev/null
+++ b/repositories.gradle
@@ -0,0 +1,5 @@
+// Add any additional repositories for your dependencies here
+
+repositories {
+
+}
diff --git a/settings.gradle b/settings.gradle
new file mode 100644
index 0000000..93c852a
--- /dev/null
+++ b/settings.gradle
@@ -0,0 +1,10 @@
+plugins {
+ id 'com.diffplug.blowdryerSetup' version '1.6.0'
+}
+
+apply plugin: 'com.diffplug.blowdryerSetup'
+
+blowdryerSetup {
+ github('GTNewHorizons/ExampleMod1.7.10', 'tag', '0.1.5')
+ //devLocal '.' // Use this when testing config updates locally
+}
diff --git a/src/main/java/com/gtnewhorizons/modularui/ClientProxy.java b/src/main/java/com/gtnewhorizons/modularui/ClientProxy.java
new file mode 100644
index 0000000..220c68e
--- /dev/null
+++ b/src/main/java/com/gtnewhorizons/modularui/ClientProxy.java
@@ -0,0 +1,46 @@
+package com.gtnewhorizons.modularui;
+
+
+import codechicken.lib.math.MathHelper;
+import com.gtnewhorizons.modularui.common.internal.JsonLoader;
+import com.gtnewhorizons.modularui.common.internal.wrapper.ModularGui;
+import cpw.mods.fml.common.event.FMLPreInitializationEvent;
+import cpw.mods.fml.common.eventhandler.SubscribeEvent;
+import cpw.mods.fml.relauncher.Side;
+import cpw.mods.fml.relauncher.SideOnly;
+import net.minecraft.client.Minecraft;
+import net.minecraft.client.resources.IResourceManager;
+import net.minecraft.client.resources.SimpleReloadableResourceManager;
+import net.minecraftforge.client.event.GuiScreenEvent;
+import org.lwjgl.input.Mouse;
+
+@SuppressWarnings("unused")
+@SideOnly(Side.CLIENT)
+public class ClientProxy extends CommonProxy {
+
+ @Override
+ public void preInit(FMLPreInitializationEvent event) {
+ super.preInit(event);
+ }
+
+ public void postInit() {
+ super.postInit();
+ ((SimpleReloadableResourceManager) Minecraft.getMinecraft().getResourceManager()).registerReloadListener(this::onReload);
+ }
+
+ public void onReload(IResourceManager manager) {
+ ModularUI.logger.info("Reloading GUIs");
+ JsonLoader.loadJson();
+ }
+
+ @SubscribeEvent
+ public void mouseScreenInput(GuiScreenEvent event) {
+ if (event.gui instanceof ModularGui) {
+ int w = Mouse.getEventDWheel();
+ int wheel = (int)MathHelper.clip(w, -1, 1);
+ if (wheel != 0) {
+ ((ModularGui) event.gui).mouseScroll(wheel);
+ }
+ }
+ }
+}
diff --git a/src/main/java/com/gtnewhorizons/modularui/CommonProxy.java b/src/main/java/com/gtnewhorizons/modularui/CommonProxy.java
new file mode 100644
index 0000000..72a6084
--- /dev/null
+++ b/src/main/java/com/gtnewhorizons/modularui/CommonProxy.java
@@ -0,0 +1,56 @@
+package com.gtnewhorizons.modularui;
+
+import com.gtnewhorizons.modularui.config.Config;
+import com.gtnewhorizons.modularui.test.TestBlock;
+import com.gtnewhorizons.modularui.test.TestTile;
+import cpw.mods.fml.client.event.ConfigChangedEvent;
+import cpw.mods.fml.common.FMLCommonHandler;
+import cpw.mods.fml.common.event.FMLPreInitializationEvent;
+import cpw.mods.fml.common.eventhandler.SubscribeEvent;
+import cpw.mods.fml.common.registry.GameRegistry;
+import net.minecraft.block.Block;
+import net.minecraft.block.material.Material;
+import net.minecraft.creativetab.CreativeTabs;
+import net.minecraftforge.common.MinecraftForge;
+
+public class CommonProxy {
+
+ public static Block testBlock;
+
+ public void preInit(FMLPreInitializationEvent event) {
+
+ testBlock = new TestBlock(Material.rock)
+ .setBlockName("testBlock")
+ .setCreativeTab(CreativeTabs.tabBlock)
+ .setBlockTextureName("stone");
+ GameRegistry.registerBlock(testBlock, "testBlock");
+ GameRegistry.registerTileEntity(TestTile.class, "TestTileEntity");
+
+ Config.init(event.getSuggestedConfigurationFile());
+
+ FMLCommonHandler.instance().bus().register(this);
+ MinecraftForge.EVENT_BUS.register(this);
+ }
+
+ public void postInit() {
+ }
+
+// @SubscribeEvent
+// public static void registerBlocks(RegistryEvent.Register event) {
+// IForgeRegistry registry = event.getRegistry();
+// registry.register(testBlock);
+// }
+//
+// @SubscribeEvent
+// public static void registerItems(RegistryEvent.Register- event) {
+// IForgeRegistry
- registry = event.getRegistry();
+// registry.register(testItemBlock);
+// }
+
+ @SubscribeEvent
+ public void onConfigChange(ConfigChangedEvent.OnConfigChangedEvent event) {
+ if (event.modID.equals(ModularUI.MODID)) {
+ Config.syncConfig();
+ }
+ }
+}
diff --git a/src/main/java/com/gtnewhorizons/modularui/ModularUI.java b/src/main/java/com/gtnewhorizons/modularui/ModularUI.java
new file mode 100644
index 0000000..a696f26
--- /dev/null
+++ b/src/main/java/com/gtnewhorizons/modularui/ModularUI.java
@@ -0,0 +1,78 @@
+package com.gtnewhorizons.modularui;
+
+import com.gtnewhorizons.modularui.common.internal.JsonLoader;
+import com.gtnewhorizons.modularui.common.internal.network.NetworkHandler;
+import com.gtnewhorizons.modularui.common.internal.wrapper.ModularGui;
+import com.gtnewhorizons.modularui.common.internal.wrapper.ModularUIContainer;
+import com.gtnewhorizons.modularui.api.UIInfos;
+import com.gtnewhorizons.modularui.api.screen.ModularUIContext;
+import com.gtnewhorizons.modularui.api.screen.ModularWindow;
+import com.gtnewhorizons.modularui.api.screen.UIBuildContext;
+import com.gtnewhorizons.modularui.common.widget.WidgetJsonRegistry;
+import cpw.mods.fml.common.FMLCommonHandler;
+import cpw.mods.fml.common.Mod;
+import cpw.mods.fml.common.SidedProxy;
+import cpw.mods.fml.common.event.FMLInitializationEvent;
+import cpw.mods.fml.common.event.FMLPostInitializationEvent;
+import cpw.mods.fml.common.event.FMLPreInitializationEvent;
+import cpw.mods.fml.relauncher.Side;
+import cpw.mods.fml.relauncher.SideOnly;
+import net.minecraft.entity.player.EntityPlayer;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+
+import java.util.function.Function;
+
+@Mod(
+ modid = ModularUI.MODID,
+ version = Tags.VERSION,
+ name = Tags.MODNAME,
+ acceptedMinecraftVersions = "[1.7.10]",
+ dependencies = ModularUI.DEPENDENCIES,
+ guiFactory = ModularUI.GUI_FACTORY
+)
+public class ModularUI {
+
+ public static final String MODID = "modularui";
+ public static final String DEPENDENCIES = "required-after:CodeChickenLib; required-after:NotEnoughItems;";
+ public static final String GUI_FACTORY = Tags.GROUPNAME + ".config.GuiFactory";
+
+ public static final Logger logger = LogManager.getLogger(Tags.MODID);
+
+ @Mod.Instance(ModularUI.MODID)
+ public static ModularUI INSTANCE;
+
+ @SidedProxy(modId = MODID, clientSide = Tags.GROUPNAME + ".ClientProxy", serverSide = Tags.GROUPNAME + ".CommonProxy")
+ public static CommonProxy proxy;
+
+ @Mod.EventHandler
+ public void preInit(FMLPreInitializationEvent event) {
+ proxy.preInit(event);
+ NetworkHandler.init();
+ UIInfos.init();
+ WidgetJsonRegistry.init();
+ }
+
+ @Mod.EventHandler
+ public void init(FMLInitializationEvent event) {
+ if (FMLCommonHandler.instance().getSide() == Side.SERVER) {
+ JsonLoader.loadJson();
+ }
+ }
+
+ @Mod.EventHandler
+ public void onPostInit(FMLPostInitializationEvent event) {
+ proxy.postInit();
+ }
+
+ public static ModularUIContainer createContainer(EntityPlayer player, Function windowCreator) {
+ UIBuildContext buildContext = new UIBuildContext(player);
+ ModularWindow window = windowCreator.apply(buildContext);
+ return new ModularUIContainer(new ModularUIContext(buildContext), window);
+ }
+
+ @SideOnly(Side.CLIENT)
+ public static ModularGui createGuiScreen(EntityPlayer player, Function windowCreator) {
+ return new ModularGui(createContainer(player, windowCreator));
+ }
+}
diff --git a/src/main/java/com/gtnewhorizons/modularui/Tags.java b/src/main/java/com/gtnewhorizons/modularui/Tags.java
new file mode 100644
index 0000000..07daa8d
--- /dev/null
+++ b/src/main/java/com/gtnewhorizons/modularui/Tags.java
@@ -0,0 +1,12 @@
+package com.gtnewhorizons.modularui;
+
+// Use this class for Strings only. Do not import any classes here. It will lead to issues with Mixins if in use!
+
+public class Tags {
+
+ // GRADLETOKEN_* will be replaced by your configuration values at build time
+ public static final String MODID = "GRADLETOKEN_MODID";
+ public static final String MODNAME = "GRADLETOKEN_MODNAME";
+ public static final String VERSION = "GRADLETOKEN_VERSION";
+ public static final String GROUPNAME = "GRADLETOKEN_GROUPNAME";
+}
diff --git a/src/main/java/com/gtnewhorizons/modularui/api/GlStateManager.java b/src/main/java/com/gtnewhorizons/modularui/api/GlStateManager.java
new file mode 100644
index 0000000..3d96de6
--- /dev/null
+++ b/src/main/java/com/gtnewhorizons/modularui/api/GlStateManager.java
@@ -0,0 +1,1278 @@
+package com.gtnewhorizons.modularui.api;
+
+import cpw.mods.fml.relauncher.Side;
+import cpw.mods.fml.relauncher.SideOnly;
+import net.minecraft.client.renderer.OpenGlHelper;
+import org.lwjgl.BufferUtils;
+import org.lwjgl.opengl.GL11;
+import org.lwjgl.opengl.GL14;
+import org.lwjgl.util.vector.Quaternion;
+
+import javax.annotation.Nullable;
+import java.nio.ByteBuffer;
+import java.nio.FloatBuffer;
+import java.nio.IntBuffer;
+
+/**
+ * Copied from forge 1.12.2-14.23.5.2847 net.minecraft.client.renderer.GlStateManager
+ */
+@SideOnly(Side.CLIENT)
+public class GlStateManager {
+ private static final FloatBuffer BUF_FLOAT_16 = BufferUtils.createFloatBuffer(16);
+ private static final FloatBuffer BUF_FLOAT_4 = BufferUtils.createFloatBuffer(4);
+ private static final AlphaState alphaState = new AlphaState();
+ private static final BooleanState lightingState = new BooleanState(2896);
+ private static final BooleanState[] lightState = new BooleanState[8];
+ private static final ColorMaterialState colorMaterialState;
+ private static final BlendState blendState;
+ private static final DepthState depthState;
+ private static final FogState fogState;
+ private static final CullState cullState;
+ private static final PolygonOffsetState polygonOffsetState;
+ private static final ColorLogicState colorLogicState;
+ private static final TexGenState texGenState;
+ private static final ClearState clearState;
+ private static final StencilState stencilState;
+ private static final BooleanState normalizeState;
+ private static int activeTextureUnit;
+ private static final TextureState[] textureState;
+ private static int activeShadeModel;
+ private static final BooleanState rescaleNormalState;
+ private static final ColorMask colorMaskState;
+ private static final Color colorState;
+
+ /**
+ * Do not use (see MinecraftForge issue #1637)
+ */
+ public static void pushAttrib()
+ {
+ GL11.glPushAttrib(8256);
+ }
+
+ /**
+ * Do not use (see MinecraftForge issue #1637)
+ */
+ public static void popAttrib()
+ {
+ GL11.glPopAttrib();
+ }
+
+ public static void disableAlpha()
+ {
+ alphaState.alphaTest.setDisabled();
+ }
+
+ public static void enableAlpha()
+ {
+ alphaState.alphaTest.setEnabled();
+ }
+
+ public static void alphaFunc(int func, float ref)
+ {
+ if (func != alphaState.func || ref != alphaState.ref)
+ {
+ alphaState.func = func;
+ alphaState.ref = ref;
+ GL11.glAlphaFunc(func, ref);
+ }
+ }
+
+ public static void enableLighting()
+ {
+ lightingState.setEnabled();
+ }
+
+ public static void disableLighting()
+ {
+ lightingState.setDisabled();
+ }
+
+ public static void enableLight(int light)
+ {
+ lightState[light].setEnabled();
+ }
+
+ public static void disableLight(int light)
+ {
+ lightState[light].setDisabled();
+ }
+
+ public static void enableColorMaterial()
+ {
+ colorMaterialState.colorMaterial.setEnabled();
+ }
+
+ public static void disableColorMaterial()
+ {
+ colorMaterialState.colorMaterial.setDisabled();
+ }
+
+ public static void colorMaterial(int face, int mode)
+ {
+ if (face != colorMaterialState.face || mode != colorMaterialState.mode)
+ {
+ colorMaterialState.face = face;
+ colorMaterialState.mode = mode;
+ GL11.glColorMaterial(face, mode);
+ }
+ }
+
+ public static void glLight(int light, int pname, FloatBuffer params)
+ {
+ GL11.glLight(light, pname, params);
+ }
+
+ public static void glLightModel(int pname, FloatBuffer params)
+ {
+ GL11.glLightModel(pname, params);
+ }
+
+ public static void glNormal3f(float nx, float ny, float nz)
+ {
+ GL11.glNormal3f(nx, ny, nz);
+ }
+
+ public static void disableDepth()
+ {
+ depthState.depthTest.setDisabled();
+ }
+
+ public static void enableDepth()
+ {
+ depthState.depthTest.setEnabled();
+ }
+
+ public static void depthFunc(int depthFunc)
+ {
+ if (depthFunc != depthState.depthFunc)
+ {
+ depthState.depthFunc = depthFunc;
+ GL11.glDepthFunc(depthFunc);
+ }
+ }
+
+ public static void depthMask(boolean flagIn)
+ {
+ if (flagIn != depthState.maskEnabled)
+ {
+ depthState.maskEnabled = flagIn;
+ GL11.glDepthMask(flagIn);
+ }
+ }
+
+ public static void disableBlend()
+ {
+ blendState.blend.setDisabled();
+ }
+
+ public static void enableBlend()
+ {
+ blendState.blend.setEnabled();
+ }
+
+ public static void blendFunc(SourceFactor srcFactor, DestFactor dstFactor)
+ {
+ blendFunc(srcFactor.factor, dstFactor.factor);
+ }
+
+ public static void blendFunc(int srcFactor, int dstFactor)
+ {
+ if (srcFactor != blendState.srcFactor || dstFactor != blendState.dstFactor)
+ {
+ blendState.srcFactor = srcFactor;
+ blendState.dstFactor = dstFactor;
+ GL11.glBlendFunc(srcFactor, dstFactor);
+ }
+ }
+
+ public static void tryBlendFuncSeparate(SourceFactor srcFactor, DestFactor dstFactor, SourceFactor srcFactorAlpha, DestFactor dstFactorAlpha)
+ {
+ tryBlendFuncSeparate(srcFactor.factor, dstFactor.factor, srcFactorAlpha.factor, dstFactorAlpha.factor);
+ }
+
+ public static void tryBlendFuncSeparate(int srcFactor, int dstFactor, int srcFactorAlpha, int dstFactorAlpha)
+ {
+ if (srcFactor != blendState.srcFactor || dstFactor != blendState.dstFactor || srcFactorAlpha != blendState.srcFactorAlpha || dstFactorAlpha != blendState.dstFactorAlpha)
+ {
+ blendState.srcFactor = srcFactor;
+ blendState.dstFactor = dstFactor;
+ blendState.srcFactorAlpha = srcFactorAlpha;
+ blendState.dstFactorAlpha = dstFactorAlpha;
+ OpenGlHelper.glBlendFunc(srcFactor, dstFactor, srcFactorAlpha, dstFactorAlpha);
+ }
+ }
+
+ public static void glBlendEquation(int blendEquation)
+ {
+ GL14.glBlendEquation(blendEquation);
+ }
+
+ public static void enableOutlineMode(int color)
+ {
+ BUF_FLOAT_4.put(0, (float)(color >> 16 & 255) / 255.0F);
+ BUF_FLOAT_4.put(1, (float)(color >> 8 & 255) / 255.0F);
+ BUF_FLOAT_4.put(2, (float)(color >> 0 & 255) / 255.0F);
+ BUF_FLOAT_4.put(3, (float)(color >> 24 & 255) / 255.0F);
+ glTexEnv(8960, 8705, BUF_FLOAT_4);
+ glTexEnvi(8960, 8704, 34160);
+ glTexEnvi(8960, 34161, 7681);
+ glTexEnvi(8960, 34176, 34166);
+ glTexEnvi(8960, 34192, 768);
+ glTexEnvi(8960, 34162, 7681);
+ glTexEnvi(8960, 34184, 5890);
+ glTexEnvi(8960, 34200, 770);
+ }
+
+ public static void disableOutlineMode()
+ {
+ glTexEnvi(8960, 8704, 8448);
+ glTexEnvi(8960, 34161, 8448);
+ glTexEnvi(8960, 34162, 8448);
+ glTexEnvi(8960, 34176, 5890);
+ glTexEnvi(8960, 34184, 5890);
+ glTexEnvi(8960, 34192, 768);
+ glTexEnvi(8960, 34200, 770);
+ }
+
+ public static void enableFog()
+ {
+ fogState.fog.setEnabled();
+ }
+
+ public static void disableFog()
+ {
+ fogState.fog.setDisabled();
+ }
+
+ public static void setFog(FogMode fogMode)
+ {
+ setFog(fogMode.capabilityId);
+ }
+
+ private static void setFog(int param)
+ {
+ if (param != fogState.mode)
+ {
+ fogState.mode = param;
+ GL11.glFogi(GL11.GL_FOG_MODE, param);
+ }
+ }
+
+ public static void setFogDensity(float param)
+ {
+ if (param != fogState.density)
+ {
+ fogState.density = param;
+ GL11.glFogf(GL11.GL_FOG_DENSITY, param);
+ }
+ }
+
+ public static void setFogStart(float param)
+ {
+ if (param != fogState.start)
+ {
+ fogState.start = param;
+ GL11.glFogf(GL11.GL_FOG_START, param);
+ }
+ }
+
+ public static void setFogEnd(float param)
+ {
+ if (param != fogState.end)
+ {
+ fogState.end = param;
+ GL11.glFogf(GL11.GL_FOG_END, param);
+ }
+ }
+
+ public static void glFog(int pname, FloatBuffer param)
+ {
+ GL11.glFog(pname, param);
+ }
+
+ public static void glFogi(int pname, int param)
+ {
+ GL11.glFogi(pname, param);
+ }
+
+ public static void enableCull()
+ {
+ cullState.cullFace.setEnabled();
+ }
+
+ public static void disableCull()
+ {
+ cullState.cullFace.setDisabled();
+ }
+
+ public static void cullFace(CullFace cullFace)
+ {
+ cullFace(cullFace.mode);
+ }
+
+ private static void cullFace(int mode)
+ {
+ if (mode != cullState.mode)
+ {
+ cullState.mode = mode;
+ GL11.glCullFace(mode);
+ }
+ }
+
+ public static void glPolygonMode(int face, int mode)
+ {
+ GL11.glPolygonMode(face, mode);
+ }
+
+ public static void enablePolygonOffset()
+ {
+ polygonOffsetState.polygonOffsetFill.setEnabled();
+ }
+
+ public static void disablePolygonOffset()
+ {
+ polygonOffsetState.polygonOffsetFill.setDisabled();
+ }
+
+ public static void doPolygonOffset(float factor, float units)
+ {
+ if (factor != polygonOffsetState.factor || units != polygonOffsetState.units)
+ {
+ polygonOffsetState.factor = factor;
+ polygonOffsetState.units = units;
+ GL11.glPolygonOffset(factor, units);
+ }
+ }
+
+ public static void enableColorLogic()
+ {
+ colorLogicState.colorLogicOp.setEnabled();
+ }
+
+ public static void disableColorLogic()
+ {
+ colorLogicState.colorLogicOp.setDisabled();
+ }
+
+ public static void colorLogicOp(LogicOp logicOperation)
+ {
+ colorLogicOp(logicOperation.opcode);
+ }
+
+ public static void colorLogicOp(int opcode)
+ {
+ if (opcode != colorLogicState.opcode)
+ {
+ colorLogicState.opcode = opcode;
+ GL11.glLogicOp(opcode);
+ }
+ }
+
+ public static void enableTexGenCoord(TexGen texGen)
+ {
+ texGenCoord(texGen).textureGen.setEnabled();
+ }
+
+ public static void disableTexGenCoord(TexGen texGen)
+ {
+ texGenCoord(texGen).textureGen.setDisabled();
+ }
+
+ public static void texGen(TexGen texGen, int param)
+ {
+ TexGenCoord glstatemanager$texgencoord = texGenCoord(texGen);
+
+ if (param != glstatemanager$texgencoord.param)
+ {
+ glstatemanager$texgencoord.param = param;
+ GL11.glTexGeni(glstatemanager$texgencoord.coord, GL11.GL_TEXTURE_GEN_MODE, param);
+ }
+ }
+
+ public static void texGen(TexGen texGen, int pname, FloatBuffer params)
+ {
+ GL11.glTexGen(texGenCoord(texGen).coord, pname, params);
+ }
+
+ private static TexGenCoord texGenCoord(TexGen texGen)
+ {
+ switch (texGen)
+ {
+ case S:
+ return texGenState.s;
+ case T:
+ return texGenState.t;
+ case R:
+ return texGenState.r;
+ case Q:
+ return texGenState.q;
+ default:
+ return texGenState.s;
+ }
+ }
+
+ public static void setActiveTexture(int texture)
+ {
+ if (activeTextureUnit != texture - OpenGlHelper.defaultTexUnit)
+ {
+ activeTextureUnit = texture - OpenGlHelper.defaultTexUnit;
+ OpenGlHelper.setActiveTexture(texture);
+ }
+ }
+
+ public static void enableTexture2D()
+ {
+ textureState[activeTextureUnit].texture2DState.setEnabled();
+ }
+
+ public static void disableTexture2D()
+ {
+ textureState[activeTextureUnit].texture2DState.setDisabled();
+ }
+
+ public static void glTexEnv(int target, int parameterName, FloatBuffer parameters)
+ {
+ GL11.glTexEnv(target, parameterName, parameters);
+ }
+
+ public static void glTexEnvi(int target, int parameterName, int parameter)
+ {
+ GL11.glTexEnvi(target, parameterName, parameter);
+ }
+
+ public static void glTexEnvf(int target, int parameterName, float parameter)
+ {
+ GL11.glTexEnvf(target, parameterName, parameter);
+ }
+
+ public static void glTexParameterf(int target, int parameterName, float parameter)
+ {
+ GL11.glTexParameterf(target, parameterName, parameter);
+ }
+
+ public static void glTexParameteri(int target, int parameterName, int parameter)
+ {
+ GL11.glTexParameteri(target, parameterName, parameter);
+ }
+
+ public static int glGetTexLevelParameteri(int target, int level, int parameterName)
+ {
+ return GL11.glGetTexLevelParameteri(target, level, parameterName);
+ }
+
+ public static int generateTexture()
+ {
+ return GL11.glGenTextures();
+ }
+
+ public static void deleteTexture(int texture)
+ {
+ GL11.glDeleteTextures(texture);
+
+ for (TextureState glstatemanager$texturestate : textureState)
+ {
+ if (glstatemanager$texturestate.textureName == texture)
+ {
+ glstatemanager$texturestate.textureName = -1;
+ }
+ }
+ }
+
+ public static void bindTexture(int texture)
+ {
+ if (texture != textureState[activeTextureUnit].textureName)
+ {
+ textureState[activeTextureUnit].textureName = texture;
+ GL11.glBindTexture(GL11.GL_TEXTURE_2D, texture);
+ }
+ }
+
+ public static void glTexImage2D(int target, int level, int internalFormat, int width, int height, int border, int format, int type, @Nullable IntBuffer pixels)
+ {
+ GL11.glTexImage2D(target, level, internalFormat, width, height, border, format, type, pixels);
+ }
+
+ public static void glTexSubImage2D(int target, int level, int xOffset, int yOffset, int width, int height, int format, int type, IntBuffer pixels)
+ {
+ GL11.glTexSubImage2D(target, level, xOffset, yOffset, width, height, format, type, pixels);
+ }
+
+ public static void glCopyTexSubImage2D(int target, int level, int xOffset, int yOffset, int x, int y, int width, int height)
+ {
+ GL11.glCopyTexSubImage2D(target, level, xOffset, yOffset, x, y, width, height);
+ }
+
+ public static void glGetTexImage(int target, int level, int format, int type, IntBuffer pixels)
+ {
+ GL11.glGetTexImage(target, level, format, type, pixels);
+ }
+
+ public static void enableNormalize()
+ {
+ normalizeState.setEnabled();
+ }
+
+ public static void disableNormalize()
+ {
+ normalizeState.setDisabled();
+ }
+
+ public static void shadeModel(int mode)
+ {
+ if (mode != activeShadeModel)
+ {
+ activeShadeModel = mode;
+ GL11.glShadeModel(mode);
+ }
+ }
+
+ public static void enableRescaleNormal()
+ {
+ rescaleNormalState.setEnabled();
+ }
+
+ public static void disableRescaleNormal()
+ {
+ rescaleNormalState.setDisabled();
+ }
+
+ public static void viewport(int x, int y, int width, int height)
+ {
+ GL11.glViewport(x, y, width, height);
+ }
+
+ public static void colorMask(boolean red, boolean green, boolean blue, boolean alpha)
+ {
+ if (red != colorMaskState.red || green != colorMaskState.green || blue != colorMaskState.blue || alpha != colorMaskState.alpha)
+ {
+ colorMaskState.red = red;
+ colorMaskState.green = green;
+ colorMaskState.blue = blue;
+ colorMaskState.alpha = alpha;
+ GL11.glColorMask(red, green, blue, alpha);
+ }
+ }
+
+ public static void clearDepth(double depth)
+ {
+ if (depth != clearState.depth)
+ {
+ clearState.depth = depth;
+ GL11.glClearDepth(depth);
+ }
+ }
+
+ public static void clearColor(float red, float green, float blue, float alpha)
+ {
+ if (red != clearState.color.red || green != clearState.color.green || blue != clearState.color.blue || alpha != clearState.color.alpha)
+ {
+ clearState.color.red = red;
+ clearState.color.green = green;
+ clearState.color.blue = blue;
+ clearState.color.alpha = alpha;
+ GL11.glClearColor(red, green, blue, alpha);
+ }
+ }
+
+ public static void clear(int mask)
+ {
+ GL11.glClear(mask);
+ }
+
+ public static void matrixMode(int mode)
+ {
+ GL11.glMatrixMode(mode);
+ }
+
+ public static void loadIdentity()
+ {
+ GL11.glLoadIdentity();
+ }
+
+ public static void pushMatrix()
+ {
+ GL11.glPushMatrix();
+ }
+
+ public static void popMatrix()
+ {
+ GL11.glPopMatrix();
+ }
+
+ public static void getFloat(int pname, FloatBuffer params)
+ {
+ GL11.glGetFloat(pname, params);
+ }
+
+ public static void ortho(double left, double right, double bottom, double top, double zNear, double zFar)
+ {
+ GL11.glOrtho(left, right, bottom, top, zNear, zFar);
+ }
+
+ public static void rotate(float angle, float x, float y, float z)
+ {
+ GL11.glRotatef(angle, x, y, z);
+ }
+
+ public static void scale(float x, float y, float z)
+ {
+ GL11.glScalef(x, y, z);
+ }
+
+ public static void scale(double x, double y, double z)
+ {
+ GL11.glScaled(x, y, z);
+ }
+
+ public static void translate(float x, float y, float z)
+ {
+ GL11.glTranslatef(x, y, z);
+ }
+
+ public static void translate(double x, double y, double z)
+ {
+ GL11.glTranslated(x, y, z);
+ }
+
+ public static void multMatrix(FloatBuffer matrix)
+ {
+ GL11.glMultMatrix(matrix);
+ }
+
+ public static void rotate(Quaternion quaternionIn)
+ {
+ multMatrix(quatToGlMatrix(BUF_FLOAT_16, quaternionIn));
+ }
+
+ public static FloatBuffer quatToGlMatrix(FloatBuffer buffer, Quaternion quaternionIn)
+ {
+ buffer.clear();
+ float f = quaternionIn.x * quaternionIn.x;
+ float f1 = quaternionIn.x * quaternionIn.y;
+ float f2 = quaternionIn.x * quaternionIn.z;
+ float f3 = quaternionIn.x * quaternionIn.w;
+ float f4 = quaternionIn.y * quaternionIn.y;
+ float f5 = quaternionIn.y * quaternionIn.z;
+ float f6 = quaternionIn.y * quaternionIn.w;
+ float f7 = quaternionIn.z * quaternionIn.z;
+ float f8 = quaternionIn.z * quaternionIn.w;
+ buffer.put(1.0F - 2.0F * (f4 + f7));
+ buffer.put(2.0F * (f1 + f8));
+ buffer.put(2.0F * (f2 - f6));
+ buffer.put(0.0F);
+ buffer.put(2.0F * (f1 - f8));
+ buffer.put(1.0F - 2.0F * (f + f7));
+ buffer.put(2.0F * (f5 + f3));
+ buffer.put(0.0F);
+ buffer.put(2.0F * (f2 + f6));
+ buffer.put(2.0F * (f5 - f3));
+ buffer.put(1.0F - 2.0F * (f + f4));
+ buffer.put(0.0F);
+ buffer.put(0.0F);
+ buffer.put(0.0F);
+ buffer.put(0.0F);
+ buffer.put(1.0F);
+ buffer.rewind();
+ return buffer;
+ }
+
+ public static void color(float colorRed, float colorGreen, float colorBlue, float colorAlpha)
+ {
+ if (colorRed != colorState.red || colorGreen != colorState.green || colorBlue != colorState.blue || colorAlpha != colorState.alpha)
+ {
+ colorState.red = colorRed;
+ colorState.green = colorGreen;
+ colorState.blue = colorBlue;
+ colorState.alpha = colorAlpha;
+ GL11.glColor4f(colorRed, colorGreen, colorBlue, colorAlpha);
+ }
+ }
+
+ public static void color(float colorRed, float colorGreen, float colorBlue)
+ {
+ color(colorRed, colorGreen, colorBlue, 1.0F);
+ }
+
+ public static void glTexCoord2f(float sCoord, float tCoord)
+ {
+ GL11.glTexCoord2f(sCoord, tCoord);
+ }
+
+ public static void glVertex3f(float x, float y, float z)
+ {
+ GL11.glVertex3f(x, y, z);
+ }
+
+ public static void resetColor()
+ {
+ colorState.red = -1.0F;
+ colorState.green = -1.0F;
+ colorState.blue = -1.0F;
+ colorState.alpha = -1.0F;
+ }
+
+ public static void glNormalPointer(int type, int stride, ByteBuffer buffer)
+ {
+ GL11.glNormalPointer(type, stride, buffer);
+ }
+
+ public static void glTexCoordPointer(int size, int type, int stride, int buffer_offset)
+ {
+ GL11.glTexCoordPointer(size, type, stride, (long)buffer_offset);
+ }
+
+ public static void glTexCoordPointer(int size, int type, int stride, ByteBuffer buffer)
+ {
+ GL11.glTexCoordPointer(size, type, stride, buffer);
+ }
+
+ public static void glVertexPointer(int size, int type, int stride, int buffer_offset)
+ {
+ GL11.glVertexPointer(size, type, stride, (long)buffer_offset);
+ }
+
+ public static void glVertexPointer(int size, int type, int stride, ByteBuffer buffer)
+ {
+ GL11.glVertexPointer(size, type, stride, buffer);
+ }
+
+ public static void glColorPointer(int size, int type, int stride, int buffer_offset)
+ {
+ GL11.glColorPointer(size, type, stride, (long)buffer_offset);
+ }
+
+ public static void glColorPointer(int size, int type, int stride, ByteBuffer buffer)
+ {
+ GL11.glColorPointer(size, type, stride, buffer);
+ }
+
+ public static void glDisableClientState(int cap)
+ {
+ GL11.glDisableClientState(cap);
+ }
+
+ public static void glEnableClientState(int cap)
+ {
+ GL11.glEnableClientState(cap);
+ }
+
+ public static void glBegin(int mode)
+ {
+ GL11.glBegin(mode);
+ }
+
+ public static void glEnd()
+ {
+ GL11.glEnd();
+ }
+
+ public static void glDrawArrays(int mode, int first, int count)
+ {
+ GL11.glDrawArrays(mode, first, count);
+ }
+
+ public static void glLineWidth(float width)
+ {
+ GL11.glLineWidth(width);
+ }
+
+ public static void callList(int list)
+ {
+ GL11.glCallList(list);
+ }
+
+ public static void glDeleteLists(int list, int range)
+ {
+ GL11.glDeleteLists(list, range);
+ }
+
+ public static void glNewList(int list, int mode)
+ {
+ GL11.glNewList(list, mode);
+ }
+
+ public static void glEndList()
+ {
+ GL11.glEndList();
+ }
+
+ public static int glGenLists(int range)
+ {
+ return GL11.glGenLists(range);
+ }
+
+ public static void glPixelStorei(int parameterName, int param)
+ {
+ GL11.glPixelStorei(parameterName, param);
+ }
+
+ public static void glReadPixels(int x, int y, int width, int height, int format, int type, IntBuffer pixels)
+ {
+ GL11.glReadPixels(x, y, width, height, format, type, pixels);
+ }
+
+ public static int glGetError()
+ {
+ return GL11.glGetError();
+ }
+
+ public static String glGetString(int name)
+ {
+ return GL11.glGetString(name);
+ }
+
+ public static void glGetInteger(int parameterName, IntBuffer parameters)
+ {
+ GL11.glGetInteger(parameterName, parameters);
+ }
+
+ public static int glGetInteger(int parameterName)
+ {
+ return GL11.glGetInteger(parameterName);
+ }
+
+ static
+ {
+ for (int i = 0; i < 8; ++i)
+ {
+ lightState[i] = new BooleanState(16384 + i);
+ }
+
+ colorMaterialState = new ColorMaterialState();
+ blendState = new BlendState();
+ depthState = new DepthState();
+ fogState = new FogState();
+ cullState = new CullState();
+ polygonOffsetState = new PolygonOffsetState();
+ colorLogicState = new ColorLogicState();
+ texGenState = new TexGenState();
+ clearState = new ClearState();
+ stencilState = new StencilState();
+ normalizeState = new BooleanState(2977);
+ textureState = new TextureState[8];
+
+ for (int j = 0; j < 8; ++j)
+ {
+ textureState[j] = new TextureState();
+ }
+
+ activeShadeModel = 7425;
+ rescaleNormalState = new BooleanState(32826);
+ colorMaskState = new ColorMask();
+ colorState = new Color();
+ }
+
+ @SideOnly(Side.CLIENT)
+ static class AlphaState
+ {
+ public BooleanState alphaTest;
+ public int func;
+ public float ref;
+
+ private AlphaState()
+ {
+ this.alphaTest = new BooleanState(3008);
+ this.func = 519;
+ this.ref = -1.0F;
+ }
+ }
+
+ @SideOnly(Side.CLIENT)
+ static class BlendState
+ {
+ public BooleanState blend;
+ public int srcFactor;
+ public int dstFactor;
+ public int srcFactorAlpha;
+ public int dstFactorAlpha;
+
+ private BlendState()
+ {
+ this.blend = new BooleanState(3042);
+ this.srcFactor = 1;
+ this.dstFactor = 0;
+ this.srcFactorAlpha = 1;
+ this.dstFactorAlpha = 0;
+ }
+ }
+
+ @SideOnly(Side.CLIENT)
+ static class BooleanState
+ {
+ private final int capability;
+ private boolean currentState;
+
+ public BooleanState(int capabilityIn)
+ {
+ this.capability = capabilityIn;
+ }
+
+ public void setDisabled()
+ {
+ this.setState(false);
+ }
+
+ public void setEnabled()
+ {
+ this.setState(true);
+ }
+
+ public void setState(boolean state)
+ {
+ if (state != this.currentState)
+ {
+ this.currentState = state;
+
+ if (state)
+ {
+ GL11.glEnable(this.capability);
+ }
+ else
+ {
+ GL11.glDisable(this.capability);
+ }
+ }
+ }
+ }
+
+ @SideOnly(Side.CLIENT)
+ static class ClearState
+ {
+ public double depth;
+ public Color color;
+
+ private ClearState()
+ {
+ this.depth = 1.0D;
+ this.color = new Color(0.0F, 0.0F, 0.0F, 0.0F);
+ }
+ }
+
+ @SideOnly(Side.CLIENT)
+ static class Color
+ {
+ public float red;
+ public float green;
+ public float blue;
+ public float alpha;
+
+ public Color()
+ {
+ this(1.0F, 1.0F, 1.0F, 1.0F);
+ }
+
+ public Color(float redIn, float greenIn, float blueIn, float alphaIn)
+ {
+ this.red = 1.0F;
+ this.green = 1.0F;
+ this.blue = 1.0F;
+ this.alpha = 1.0F;
+ this.red = redIn;
+ this.green = greenIn;
+ this.blue = blueIn;
+ this.alpha = alphaIn;
+ }
+ }
+
+ @SideOnly(Side.CLIENT)
+ static class ColorLogicState
+ {
+ public BooleanState colorLogicOp;
+ public int opcode;
+
+ private ColorLogicState()
+ {
+ this.colorLogicOp = new BooleanState(3058);
+ this.opcode = 5379;
+ }
+ }
+
+ @SideOnly(Side.CLIENT)
+ static class ColorMask
+ {
+ public boolean red;
+ public boolean green;
+ public boolean blue;
+ public boolean alpha;
+
+ private ColorMask()
+ {
+ this.red = true;
+ this.green = true;
+ this.blue = true;
+ this.alpha = true;
+ }
+ }
+
+ @SideOnly(Side.CLIENT)
+ static class ColorMaterialState
+ {
+ public BooleanState colorMaterial;
+ public int face;
+ public int mode;
+
+ private ColorMaterialState()
+ {
+ this.colorMaterial = new BooleanState(2903);
+ this.face = 1032;
+ this.mode = 5634;
+ }
+ }
+
+ @SideOnly(Side.CLIENT)
+ public static enum CullFace
+ {
+ FRONT(1028),
+ BACK(1029),
+ FRONT_AND_BACK(1032);
+
+ public final int mode;
+
+ private CullFace(int modeIn)
+ {
+ this.mode = modeIn;
+ }
+ }
+
+ @SideOnly(Side.CLIENT)
+ static class CullState
+ {
+ public BooleanState cullFace;
+ public int mode;
+
+ private CullState()
+ {
+ this.cullFace = new BooleanState(2884);
+ this.mode = 1029;
+ }
+ }
+
+ @SideOnly(Side.CLIENT)
+ static class DepthState
+ {
+ public BooleanState depthTest;
+ public boolean maskEnabled;
+ public int depthFunc;
+
+ private DepthState()
+ {
+ this.depthTest = new BooleanState(2929);
+ this.maskEnabled = true;
+ this.depthFunc = 513;
+ }
+ }
+
+ @SideOnly(Side.CLIENT)
+ public static enum DestFactor
+ {
+ CONSTANT_ALPHA(32771),
+ CONSTANT_COLOR(32769),
+ DST_ALPHA(772),
+ DST_COLOR(774),
+ ONE(1),
+ ONE_MINUS_CONSTANT_ALPHA(32772),
+ ONE_MINUS_CONSTANT_COLOR(32770),
+ ONE_MINUS_DST_ALPHA(773),
+ ONE_MINUS_DST_COLOR(775),
+ ONE_MINUS_SRC_ALPHA(771),
+ ONE_MINUS_SRC_COLOR(769),
+ SRC_ALPHA(770),
+ SRC_COLOR(768),
+ ZERO(0);
+
+ public final int factor;
+
+ private DestFactor(int factorIn)
+ {
+ this.factor = factorIn;
+ }
+ }
+
+ @SideOnly(Side.CLIENT)
+ public static enum FogMode
+ {
+ LINEAR(9729),
+ EXP(2048),
+ EXP2(2049);
+
+ /** The capability ID of this {@link FogMode} */
+ public final int capabilityId;
+
+ private FogMode(int capabilityIn)
+ {
+ this.capabilityId = capabilityIn;
+ }
+ }
+
+ @SideOnly(Side.CLIENT)
+ static class FogState
+ {
+ public BooleanState fog;
+ public int mode;
+ public float density;
+ public float start;
+ public float end;
+
+ private FogState()
+ {
+ this.fog = new BooleanState(2912);
+ this.mode = 2048;
+ this.density = 1.0F;
+ this.end = 1.0F;
+ }
+ }
+
+ @SideOnly(Side.CLIENT)
+ public static enum LogicOp
+ {
+ AND(5377),
+ AND_INVERTED(5380),
+ AND_REVERSE(5378),
+ CLEAR(5376),
+ COPY(5379),
+ COPY_INVERTED(5388),
+ EQUIV(5385),
+ INVERT(5386),
+ NAND(5390),
+ NOOP(5381),
+ NOR(5384),
+ OR(5383),
+ OR_INVERTED(5389),
+ OR_REVERSE(5387),
+ SET(5391),
+ XOR(5382);
+
+ public final int opcode;
+
+ private LogicOp(int opcodeIn)
+ {
+ this.opcode = opcodeIn;
+ }
+ }
+
+ @SideOnly(Side.CLIENT)
+ static class PolygonOffsetState
+ {
+ public BooleanState polygonOffsetFill;
+ public BooleanState polygonOffsetLine;
+ public float factor;
+ public float units;
+
+ private PolygonOffsetState()
+ {
+ this.polygonOffsetFill = new BooleanState(32823);
+ this.polygonOffsetLine = new BooleanState(10754);
+ }
+ }
+
+ @SideOnly(Side.CLIENT)
+ public static enum SourceFactor
+ {
+ CONSTANT_ALPHA(32771),
+ CONSTANT_COLOR(32769),
+ DST_ALPHA(772),
+ DST_COLOR(774),
+ ONE(1),
+ ONE_MINUS_CONSTANT_ALPHA(32772),
+ ONE_MINUS_CONSTANT_COLOR(32770),
+ ONE_MINUS_DST_ALPHA(773),
+ ONE_MINUS_DST_COLOR(775),
+ ONE_MINUS_SRC_ALPHA(771),
+ ONE_MINUS_SRC_COLOR(769),
+ SRC_ALPHA(770),
+ SRC_ALPHA_SATURATE(776),
+ SRC_COLOR(768),
+ ZERO(0);
+
+ public final int factor;
+
+ private SourceFactor(int factorIn)
+ {
+ this.factor = factorIn;
+ }
+ }
+
+ @SideOnly(Side.CLIENT)
+ static class StencilFunc
+ {
+ public int func;
+ public int mask;
+
+ private StencilFunc()
+ {
+ this.func = 519;
+ this.mask = -1;
+ }
+ }
+
+ @SideOnly(Side.CLIENT)
+ static class StencilState
+ {
+ public StencilFunc func;
+ public int mask;
+ public int fail;
+ public int zfail;
+ public int zpass;
+
+ private StencilState()
+ {
+ this.func = new StencilFunc();
+ this.mask = -1;
+ this.fail = 7680;
+ this.zfail = 7680;
+ this.zpass = 7680;
+ }
+ }
+
+ @SideOnly(Side.CLIENT)
+ public static enum TexGen
+ {
+ S,
+ T,
+ R,
+ Q;
+ }
+
+ @SideOnly(Side.CLIENT)
+ static class TexGenCoord
+ {
+ public BooleanState textureGen;
+ public int coord;
+ public int param = -1;
+
+ public TexGenCoord(int coordIn, int capabilityIn)
+ {
+ this.coord = coordIn;
+ this.textureGen = new BooleanState(capabilityIn);
+ }
+ }
+
+ @SideOnly(Side.CLIENT)
+ static class TexGenState
+ {
+ public TexGenCoord s;
+ public TexGenCoord t;
+ public TexGenCoord r;
+ public TexGenCoord q;
+
+ private TexGenState()
+ {
+ this.s = new TexGenCoord(8192, 3168);
+ this.t = new TexGenCoord(8193, 3169);
+ this.r = new TexGenCoord(8194, 3170);
+ this.q = new TexGenCoord(8195, 3171);
+ }
+ }
+
+ @SideOnly(Side.CLIENT)
+ static class TextureState
+ {
+ public BooleanState texture2DState;
+ public int textureName;
+
+ private TextureState()
+ {
+ this.texture2DState = new BooleanState(3553);
+ }
+ }
+}
diff --git a/src/main/java/com/gtnewhorizons/modularui/api/KeyBindAPI.java b/src/main/java/com/gtnewhorizons/modularui/api/KeyBindAPI.java
new file mode 100644
index 0000000..5c0c978
--- /dev/null
+++ b/src/main/java/com/gtnewhorizons/modularui/api/KeyBindAPI.java
@@ -0,0 +1,60 @@
+package com.gtnewhorizons.modularui.api;
+
+import net.minecraft.client.settings.KeyBinding;
+
+import java.util.*;
+
+public class KeyBindAPI {
+
+ private static final Set forceCheckKey = new HashSet<>();
+ private static final Map> compatibiliyMap = new HashMap<>();
+
+ /**
+ * By default key binds can only used in specific GUIs. This forces the key bond to trigger regardless of that restriction.
+ *
+ * @param keyBinding key bind to force always to trigger
+ */
+ public static void forceCheckKeyBind(KeyBinding keyBinding) {
+ if (keyBinding == null) {
+ throw new NullPointerException();
+ }
+ forceCheckKey.add(keyBinding);
+ }
+
+ /**
+ * Returns if the key bind should be forced to trigger
+ *
+ * @param keyBinding key bind to check
+ * @return if the key bind should be forced to trigger
+ */
+ public static boolean doForceCheckKeyBind(KeyBinding keyBinding) {
+ return keyBinding != null && forceCheckKey.contains(keyBinding);
+ }
+
+ /**
+ * This forces 2 key binds to always be compatible even if they have assigned the same key.
+ * Conflicts must be handled manually!
+ */
+ public static void setCompatible(KeyBinding keyBinding1, KeyBinding keyBinding2) {
+ if (keyBinding1 == keyBinding2 || keyBinding1 == null || keyBinding2 == null) {
+ throw new IllegalArgumentException();
+ }
+ compatibiliyMap.computeIfAbsent(keyBinding1, key -> new HashSet<>()).add(keyBinding2);
+ compatibiliyMap.computeIfAbsent(keyBinding2, key -> new HashSet<>()).add(keyBinding1);
+ }
+
+ /**
+ * @return if the given key binds are forced to be compatible
+ */
+ public static boolean areCompatible(KeyBinding keyBinding1, KeyBinding keyBinding2) {
+ return compatibiliyMap.getOrDefault(keyBinding1, Collections.emptySet()).contains(keyBinding2);
+ }
+
+ /**
+ * @return all forced compatible key binds for the given key bind
+ */
+ public static Collection getCompatibles(KeyBinding keyBinding) {
+ return compatibiliyMap.getOrDefault(keyBinding, Collections.emptySet());
+ }
+
+}
diff --git a/src/main/java/com/gtnewhorizons/modularui/api/ModularUITextures.java b/src/main/java/com/gtnewhorizons/modularui/api/ModularUITextures.java
new file mode 100644
index 0000000..9402e23
--- /dev/null
+++ b/src/main/java/com/gtnewhorizons/modularui/api/ModularUITextures.java
@@ -0,0 +1,29 @@
+package com.gtnewhorizons.modularui.api;
+
+import com.gtnewhorizons.modularui.ModularUI;
+import com.gtnewhorizons.modularui.api.drawable.AdaptableUITexture;
+import com.gtnewhorizons.modularui.api.drawable.UITexture;
+
+public class ModularUITextures {
+
+ public static final UITexture ICON_INFO = UITexture.fullImage(ModularUI.MODID, "gui/widgets/information");
+ public static final UITexture VANILLA_BACKGROUND = AdaptableUITexture.of(ModularUI.MODID, "gui/background/vanilla_background", 195, 136, 4);
+ public static final AdaptableUITexture BASE_BUTTON = AdaptableUITexture.of(ModularUI.MODID, "gui/widgets/base_button", 18, 18, 1);
+ public static final AdaptableUITexture ITEM_SLOT = AdaptableUITexture.of(ModularUI.MODID, "gui/slot/item", 18, 18, 1);
+ public static final AdaptableUITexture FLUID_SLOT = AdaptableUITexture.of(ModularUI.MODID, "gui/slot/fluid", 18, 18, 1);
+
+ public static final UITexture ARROW_LEFT = UITexture.fullImage(ModularUI.MODID, "gui/icons/arrow_left");
+ public static final UITexture ARROW_RIGHT = UITexture.fullImage(ModularUI.MODID, "gui/icons/arrow_right");
+ public static final UITexture ARROW_UP = UITexture.fullImage(ModularUI.MODID, "gui/icons/arrow_up");
+ public static final UITexture ARROW_DOWN = UITexture.fullImage(ModularUI.MODID, "gui/icons/arrow_down");
+ public static final UITexture CROSS = UITexture.fullImage(ModularUI.MODID, "gui/icons/cross");
+
+ public static final UITexture VANILLA_TAB_TOP = UITexture.fullImage(ModularUI.MODID, "gui/tab/tabs_top");
+ public static final UITexture VANILLA_TAB_BOTTOM = UITexture.fullImage(ModularUI.MODID, "gui/tab/tabs_bottom");
+ public static final UITexture VANILLA_TAB_LEFT = UITexture.fullImage(ModularUI.MODID, "gui/tab/tabs_left");
+ public static final UITexture VANILLA_TAB_RIGHT = UITexture.fullImage(ModularUI.MODID, "gui/tab/tabs_right");
+
+ public static final UITexture VANILLA_TAB_TOP_START = VANILLA_TAB_TOP.getSubArea(0f, 0f, 1 / 3f, 1f);
+ public static final UITexture VANILLA_TAB_TOP_MIDDLE = VANILLA_TAB_TOP.getSubArea(1 / 3f, 0f, 2 / 3f, 1f);
+ public static final UITexture VANILLA_TAB_TOP_END = VANILLA_TAB_TOP.getSubArea(2 / 3f, 0f, 1f, 1f);
+}
diff --git a/src/main/java/com/gtnewhorizons/modularui/api/NumberFormat.java b/src/main/java/com/gtnewhorizons/modularui/api/NumberFormat.java
new file mode 100644
index 0000000..97423cc
--- /dev/null
+++ b/src/main/java/com/gtnewhorizons/modularui/api/NumberFormat.java
@@ -0,0 +1,75 @@
+package com.gtnewhorizons.modularui.api;
+
+import org.jetbrains.annotations.NotNull;
+
+import java.text.DecimalFormat;
+import java.util.Map;
+import java.util.NavigableMap;
+import java.util.TreeMap;
+
+public class NumberFormat {
+
+ private static final NavigableMap suffixesByPower = new TreeMap<>();
+ private static final java.text.NumberFormat[] NUMBER_FORMAT = {
+ new DecimalFormat("0."),
+ new DecimalFormat("0.#"),
+ new DecimalFormat("0.##"),
+ new DecimalFormat("0.###"),
+ new DecimalFormat("0.####"),
+ new DecimalFormat("0.#####"),
+ new DecimalFormat("0.######"),
+ new DecimalFormat("0.#######"),
+ new DecimalFormat("0.########"),
+ new DecimalFormat("0.#########"),
+ };
+
+ static {
+ suffixesByPower.put(0.000_000_000_000_000_001D, "a");
+ suffixesByPower.put(0.000_000_000_000_001D, "f");
+ suffixesByPower.put(0.000_000_000_001D, "p");
+ suffixesByPower.put(0.000_000_001D, "n");
+ suffixesByPower.put(0.000_001D, "u");
+ suffixesByPower.put(0.001D, "m");
+ suffixesByPower.put(1_000D, "k");
+ suffixesByPower.put(1_000_000D, "M");
+ suffixesByPower.put(1_000_000_000D, "G");
+ suffixesByPower.put(1_000_000000_000D, "T");
+ suffixesByPower.put(1_000_000000_000_000D, "P");
+ suffixesByPower.put(1_000_000000_000_000_000D, "E");
+ }
+
+ @NotNull
+ public static String format(double value, int precision) {
+ //Double.MIN_VALUE == -Double.MIN_VALUE so we need an adjustment here
+ if (value == Double.MIN_VALUE) return format(Double.MIN_VALUE + 1, precision);
+ if (value == 0) return "0";
+ if (value < 0) return '-' + format(-value, precision);
+ double divideBy;
+ String suffix;
+ if (value < pow(10, precision)) {
+ divideBy = 1;
+ suffix = "";
+ } else {
+ Map.Entry e = suffixesByPower.floorEntry(value);
+ divideBy = e.getKey();
+ suffix = e.getValue();
+ }
+
+ double truncated = value / (divideBy / 10); //the number part of the output times 10
+ boolean hasDecimal = truncated < 100 && (truncated / 10D) != (truncated / 10);
+ return hasDecimal ? NUMBER_FORMAT[precision].format(truncated / 10D) + suffix : NUMBER_FORMAT[precision].format(truncated / 10) + suffix;
+ }
+
+ @NotNull
+ public static String format(double value) {
+ return format(value, 3);
+ }
+
+ private static int pow(int num, int e) {
+ int result = num;
+ for (int i = 0; i < e; i++) {
+ result *= num;
+ }
+ return result;
+ }
+}
diff --git a/src/main/java/com/gtnewhorizons/modularui/api/UIInfos.java b/src/main/java/com/gtnewhorizons/modularui/api/UIInfos.java
new file mode 100644
index 0000000..ec7229d
--- /dev/null
+++ b/src/main/java/com/gtnewhorizons/modularui/api/UIInfos.java
@@ -0,0 +1,57 @@
+package com.gtnewhorizons.modularui.api;
+
+import com.gtnewhorizons.modularui.ModularUI;
+import com.gtnewhorizons.modularui.common.builder.UIBuilder;
+import com.gtnewhorizons.modularui.common.builder.UIInfo;
+import com.gtnewhorizons.modularui.common.internal.network.NetworkUtils;
+import com.gtnewhorizons.modularui.common.internal.wrapper.ModularGui;
+import com.gtnewhorizons.modularui.common.internal.wrapper.ModularUIContainer;
+
+import com.gtnewhorizons.modularui.api.screen.ITileWithModularUI;
+import com.gtnewhorizons.modularui.api.screen.ModularUIContext;
+import com.gtnewhorizons.modularui.api.screen.ModularWindow;
+import com.gtnewhorizons.modularui.api.screen.UIBuildContext;
+import cpw.mods.fml.common.FMLCommonHandler;
+import cpw.mods.fml.relauncher.Side;
+import cpw.mods.fml.relauncher.SideOnly;
+import net.minecraft.client.gui.GuiScreen;
+import net.minecraft.entity.player.EntityPlayer;
+import net.minecraft.tileentity.TileEntity;
+
+import java.util.function.Function;
+
+public class UIInfos {
+
+ public static void init() {
+ }
+
+ public static final UIInfo, ?> TILE_MODULAR_UI = UIBuilder.of()
+ .gui(((player, world, x, y, z) -> {
+ if (!world.isRemote) return null;
+ TileEntity te = world.getTileEntity(x, y, z);
+ if (te instanceof ITileWithModularUI) {
+ return ModularUI.createGuiScreen(player, ((ITileWithModularUI) te)::createWindow);
+ }
+ return null;
+ }))
+ .container((player, world, x, y, z) -> {
+ TileEntity te = world.getTileEntity(x, y, z);
+ if (te instanceof ITileWithModularUI) {
+ return ModularUI.createContainer(player, ((ITileWithModularUI) te)::createWindow);
+ }
+ return null;
+ })
+ .build();
+
+ @SideOnly(Side.CLIENT)
+ public static void openClientUI(EntityPlayer player, Function uiCreator) {
+ if (!NetworkUtils.isClient(player)) {
+ ModularUI.logger.info("Tried opening client ui on server!");
+ return;
+ }
+ UIBuildContext buildContext = new UIBuildContext(player);
+ ModularWindow window = uiCreator.apply(buildContext);
+ GuiScreen screen = new ModularGui(new ModularUIContainer(new ModularUIContext(buildContext, true), window));
+ FMLCommonHandler.instance().showGuiScreen(screen);
+ }
+}
diff --git a/src/main/java/com/gtnewhorizons/modularui/api/Widget.java b/src/main/java/com/gtnewhorizons/modularui/api/Widget.java
new file mode 100644
index 0000000..6ea5f6d
--- /dev/null
+++ b/src/main/java/com/gtnewhorizons/modularui/api/Widget.java
@@ -0,0 +1,15 @@
+package com.gtnewhorizons.modularui.api;
+
+import net.minecraft.client.gui.FontRenderer;
+import net.minecraft.client.renderer.texture.TextureManager;
+
+public class Widget {
+
+ public void drawForeGround(int mouseX, int mouseY, FontRenderer fontRenderer){
+
+ }
+
+ public void drawBackGround(int mouseX, int mouseY, TextureManager textureManager, int WindowStartX, int windwStartY){
+
+ }
+}
diff --git a/src/main/java/com/gtnewhorizons/modularui/api/animation/Eases.java b/src/main/java/com/gtnewhorizons/modularui/api/animation/Eases.java
new file mode 100644
index 0000000..674fbf2
--- /dev/null
+++ b/src/main/java/com/gtnewhorizons/modularui/api/animation/Eases.java
@@ -0,0 +1,25 @@
+package com.gtnewhorizons.modularui.api.animation;
+
+public enum Eases implements IEase {
+ EaseLinear(input -> input),
+ EaseQuadIn(input -> input * input),
+ EaseQuadInOut(input -> {
+ if ((input /= 0.5f) < 1) {
+ return 0.5f * input * input;
+ }
+ return -0.5f * ((--input) * (input - 2) - 1);
+ }),
+ EaseQuadOut(input -> -input * (input - 2));
+
+
+ IEase ease;
+
+ Eases(IEase ease) {
+ this.ease = ease;
+ }
+
+ @Override
+ public float interpolate(float t) {
+ return ease.interpolate(t);
+ }
+}
diff --git a/src/main/java/com/gtnewhorizons/modularui/api/animation/IEase.java b/src/main/java/com/gtnewhorizons/modularui/api/animation/IEase.java
new file mode 100644
index 0000000..d1edcf6
--- /dev/null
+++ b/src/main/java/com/gtnewhorizons/modularui/api/animation/IEase.java
@@ -0,0 +1,6 @@
+package com.gtnewhorizons.modularui.api.animation;
+
+@FunctionalInterface
+public interface IEase {
+ float interpolate(float t);
+}
diff --git a/src/main/java/com/gtnewhorizons/modularui/api/animation/Interpolator.java b/src/main/java/com/gtnewhorizons/modularui/api/animation/Interpolator.java
new file mode 100644
index 0000000..4751729
--- /dev/null
+++ b/src/main/java/com/gtnewhorizons/modularui/api/animation/Interpolator.java
@@ -0,0 +1,87 @@
+package com.gtnewhorizons.modularui.api.animation;
+
+import java.util.function.Consumer;
+
+public class Interpolator {
+
+ private final float from;
+ private final float to;
+ private final int duration;
+ private final IEase ease;
+ private final Consumer interpolate;
+ private Consumer callback;
+
+ private int runs = 0;
+ private int progress = 0;
+
+ public Interpolator(float from, float to, int duration, IEase ease, Consumer interpolate) {
+ this(from, to, duration, ease, interpolate, null);
+ }
+
+ public Interpolator(float from, float to, int duration, IEase ease, Consumer interpolate, Consumer callback) {
+ this.from = from;
+ this.to = to;
+ this.duration = duration;
+ this.ease = ease;
+ this.interpolate = interpolate;
+ this.callback = callback;
+ }
+
+ public Interpolator getReversed(int duration, IEase ease) {
+ return new Interpolator(to, from, duration, ease, interpolate, callback);
+ }
+
+ public void setCallback(Consumer callback) {
+ this.callback = callback;
+ }
+
+ public void stop() {
+ runs = 0;
+ }
+
+ public Interpolator forward() {
+ progress = 0;
+ runs = 1;
+ return this;
+ }
+
+ public void backwards() {
+ progress = duration;
+ runs = -1;
+ }
+
+ public boolean isAtStart() {
+ return progress == 0;
+ }
+
+ public boolean isAtEnd() {
+ return progress >= duration;
+ }
+
+ public boolean isRunning() {
+ return runs != 0 && progress > 0 && progress < duration;
+ }
+
+ public void update(float partialTicks) {
+ if (runs != 0) {
+ if (runs == -1 && progress <= 0) {
+ progress = 0;
+ if (callback != null) {
+ callback.accept(ease.interpolate(progress * 1.0f / duration) * (to - from) + from);
+ }
+ stop();
+ return;
+ } else if (runs == 1 && progress >= duration) {
+ progress = duration;
+ if (callback != null) {
+ callback.accept(ease.interpolate(progress * 1.0f / duration) * (to - from) + from);
+ }
+ stop();
+ return;
+ } else {
+ interpolate.accept(ease.interpolate(progress * 1.0f / duration) * (to - from) + from);
+ }
+ progress += partialTicks * 50 * runs;
+ }
+ }
+}
diff --git a/src/main/java/com/gtnewhorizons/modularui/api/drawable/AdaptableUITexture.java b/src/main/java/com/gtnewhorizons/modularui/api/drawable/AdaptableUITexture.java
new file mode 100644
index 0000000..e8aa4ca
--- /dev/null
+++ b/src/main/java/com/gtnewhorizons/modularui/api/drawable/AdaptableUITexture.java
@@ -0,0 +1,68 @@
+package com.gtnewhorizons.modularui.api.drawable;
+
+import net.minecraft.util.ResourceLocation;
+
+public class AdaptableUITexture extends UITexture {
+
+ private final int imageWidth, imageHeight, borderWidthU, borderWidthV;
+
+ public AdaptableUITexture(ResourceLocation location, float u0, float v0, float u1, float v1, int imageWidth, int imageHeight, int borderWidthU, int borderWidthV) {
+ super(location, u0, v0, u1, v1);
+ this.imageWidth = imageWidth;
+ this.imageHeight = imageHeight;
+ this.borderWidthU = borderWidthU;
+ this.borderWidthV = borderWidthV;
+ }
+
+ public AdaptableUITexture(ResourceLocation location, int imageWidth, int imageHeight, int borderWidthU, int borderWidthV) {
+ this(location, 0, 0, 1, 1, imageWidth, imageHeight, borderWidthU, borderWidthV);
+ }
+
+ public static AdaptableUITexture of(ResourceLocation location, int imageWidth, int imageHeight, int borderWidthU, int borderWidthV) {
+ return new AdaptableUITexture(location, imageWidth, imageHeight, borderWidthU, borderWidthV);
+ }
+
+ public static AdaptableUITexture of(ResourceLocation location, int imageWidth, int imageHeight, int borderWidthPixel) {
+ return new AdaptableUITexture(location, imageWidth, imageHeight, borderWidthPixel, borderWidthPixel);
+ }
+
+ public static AdaptableUITexture of(String location, int imageWidth, int imageHeight, int borderWidthPixel) {
+ return new AdaptableUITexture(new ResourceLocation(location), imageWidth, imageHeight, borderWidthPixel, borderWidthPixel);
+ }
+
+ public static AdaptableUITexture of(String mod, String location, int imageWidth, int imageHeight, int borderWidthPixel) {
+ return new AdaptableUITexture(new ResourceLocation(mod, location), imageWidth, imageHeight, borderWidthPixel, borderWidthPixel);
+ }
+
+ @Override
+ public AdaptableUITexture getSubArea(float uStart, float vStart, float uEnd, float vEnd) {
+ return new AdaptableUITexture(location, calcU(uStart), calcV(vStart), calcU(uEnd), calcV(vEnd), imageWidth, imageHeight, borderWidthU, borderWidthV);
+ }
+
+ @Override
+ public AdaptableUITexture exposeToJson() {
+ return (AdaptableUITexture) super.exposeToJson();
+ }
+
+ @Override
+ public void draw(float x, float y, float width, float height) {
+ if (width == imageWidth && height == imageHeight) {
+ super.draw(x, y, width, height);
+ return;
+ }
+ float borderU = borderWidthU * 1f / imageWidth;
+ float borderV = borderWidthV * 1f / imageHeight;
+ // draw corners
+ draw(location, x, y, borderWidthU, borderWidthV, u0, v0, borderU, borderV); // x0 y0
+ draw(location, x + width - borderWidthU, y, borderWidthU, borderWidthV, u1 - borderU, v0, u1, borderV); // x1 y0
+ draw(location, x, y + height - borderWidthV, borderWidthU, borderWidthV, u0, v1 - borderV, borderU, v1); // x0 y1
+ draw(location, x + width - borderWidthU, y + height - borderWidthV, borderWidthU, borderWidthV, u1 - borderU, v1 - borderV, u1, v1); // x1 y1
+ // draw edges
+ draw(location, x + borderWidthU, y, width - borderWidthU * 2, borderWidthV, borderU, v0, u1 - borderU, borderV); // top
+ draw(location, x + borderWidthU, y + height - borderWidthV, width - borderWidthU * 2, borderWidthV, borderU, v1 - borderV, u1 - borderU, v1); // bottom
+ draw(location, x, y + borderWidthV, borderWidthU, height - borderWidthV * 2, u0, borderV, borderU, v1 - borderV); // left
+ draw(location, x + width - borderWidthU, y + borderWidthV, borderWidthU, height - borderWidthV * 2, u1 - borderU, borderV, u1, v1 - borderV); // left
+ // draw body
+ draw(location, x + borderWidthU, y + borderWidthV, width - borderWidthU * 2, height - borderWidthV * 2, borderU, borderV, u1 - borderU, v1 - borderV);
+ }
+}
diff --git a/src/main/java/com/gtnewhorizons/modularui/api/drawable/GuiHelper.java b/src/main/java/com/gtnewhorizons/modularui/api/drawable/GuiHelper.java
new file mode 100644
index 0000000..50758e2
--- /dev/null
+++ b/src/main/java/com/gtnewhorizons/modularui/api/drawable/GuiHelper.java
@@ -0,0 +1,318 @@
+package com.gtnewhorizons.modularui.api.drawable;
+
+import com.gtnewhorizons.modularui.api.GlStateManager;
+import com.gtnewhorizons.modularui.api.math.Alignment;
+import com.gtnewhorizons.modularui.api.math.Color;
+import com.gtnewhorizons.modularui.api.math.Pos2d;
+import com.gtnewhorizons.modularui.api.math.Size;
+import cpw.mods.fml.relauncher.Side;
+import cpw.mods.fml.relauncher.SideOnly;
+import net.minecraft.client.Minecraft;
+import net.minecraft.client.gui.GuiScreen;
+import net.minecraft.client.gui.ScaledResolution;
+import net.minecraft.client.renderer.RenderHelper;
+import net.minecraft.client.renderer.Tessellator;
+import net.minecraft.client.renderer.texture.TextureMap;
+import net.minecraft.util.IIcon;
+import net.minecraftforge.client.GuiIngameForge;
+import net.minecraftforge.fluids.Fluid;
+import net.minecraftforge.fluids.FluidStack;
+import org.apache.commons.lang3.tuple.Pair;
+import org.lwjgl.input.Mouse;
+import org.lwjgl.opengl.GL11;
+
+import java.util.List;
+import java.util.Stack;
+import java.util.stream.Collectors;
+
+@SideOnly(Side.CLIENT)
+public class GuiHelper {
+
+ //==== Screen helpers ====
+
+ public static boolean hasScreen() {
+ return Minecraft.getMinecraft().currentScreen != null;
+ }
+
+ public static GuiScreen getActiveScreen() {
+ return Minecraft.getMinecraft().currentScreen;
+ }
+
+ /**
+ * @return the scaled screen size. (0;0) if no screen is open.
+ */
+ public static Size getScreenSize() {
+ GuiScreen screen = Minecraft.getMinecraft().currentScreen;
+ if (screen != null) {
+ return new Size(screen.width, screen.height);
+ }
+ return Size.ZERO;
+ }
+
+ /**
+ * @return the current mouse pos. (0;0) if no screen is open.
+ */
+ public static Pos2d getCurrentMousePos() {
+ GuiScreen screen = Minecraft.getMinecraft().currentScreen;
+ if (screen != null) {
+ int x = Mouse.getEventX() * screen.width / Minecraft.getMinecraft().displayWidth;
+ int y = screen.height - Mouse.getEventY() * screen.height / Minecraft.getMinecraft().displayHeight - 1;
+ return new Pos2d(x, y);
+ }
+ return Pos2d.ZERO;
+ }
+
+
+ //==== Tooltip helpers ====
+
+ public static void drawHoveringText(List textLines, Pos2d mousePos, Size screenSize, int maxWidth, float scale, boolean forceShadow, Alignment alignment) {
+ if (textLines.isEmpty()) {
+ return;
+ }
+ List lines = textLines.stream().map(line -> line.getFormatted()).collect(Collectors.toList());
+ drawHoveringTextFormatted(lines, mousePos, screenSize, maxWidth, scale, forceShadow, alignment);
+ }
+
+ public static void drawHoveringTextFormatted(List lines, Pos2d mousePos, Size screenSize, int maxWidth) {
+ drawHoveringTextFormatted(lines, mousePos, screenSize, maxWidth, 1f, false, Alignment.TopLeft);
+ }
+
+ public static void drawHoveringTextFormatted(List lines, Pos2d mousePos, Size screenSize, int maxWidth, float scale, boolean forceShadow, Alignment alignment) {
+ if (lines.isEmpty()) {
+ return;
+ }
+ if (maxWidth < 0) {
+ maxWidth = Integer.MAX_VALUE;
+ }
+// RenderTooltipEvent.Pre event = new RenderTooltipEvent.Pre(ItemStack.EMPTY, lines, mousePos.x, mousePos.y, screenSize.width, screenSize.height, maxWidth, TextRenderer.getFontRenderer());
+// if (MinecraftForge.EVENT_BUS.post(event)) {
+// return;
+// }
+// lines = event.getLines();
+// mousePos = new Pos2d(event.x(), event.getY());
+// screenSize = new Size(event.getScreenWidth(), event.getScreenHeight());
+// maxWidth = event.getMaxWidth();
+
+ int maxTextWidth = maxWidth;
+
+ boolean mouseOnRightSide = false;
+ int screenSpaceRight = screenSize.width - mousePos.x - 16;
+ if (mousePos.x > screenSize.width / 2f) {
+ mouseOnRightSide = true;
+ }
+ if (maxTextWidth > screenSpaceRight) {
+ maxTextWidth = screenSpaceRight;
+ }
+ boolean putOnLeft = false;
+ int tooltipY = mousePos.y - 12;
+ int tooltipX = mousePos.x + 12;
+ TextRenderer renderer = new TextRenderer();
+ renderer.setPos(mousePos);
+ renderer.setAlignment(Alignment.TopLeft, maxTextWidth);
+ renderer.setScale(scale);
+ renderer.setShadow(forceShadow);
+ renderer.setSimulate(true);
+ List> measuredLines = renderer.measureLines(lines);
+ if (mouseOnRightSide && measuredLines.size() > lines.size()) {
+ putOnLeft = true;
+ maxTextWidth = Math.min(maxWidth, mousePos.x - 16);
+ }
+
+ renderer.setAlignment(Alignment.TopLeft, maxTextWidth);
+ measuredLines = renderer.measureLines(lines);
+ renderer.drawMeasuredLines(measuredLines);
+ int tooltipTextWidth = (int) renderer.lastWidth;
+ int tooltipHeight = (int) renderer.lastHeight;
+
+ if (mouseOnRightSide && putOnLeft) {
+ tooltipX += -24 - tooltipTextWidth;
+ }
+
+ GlStateManager.disableRescaleNormal();
+ RenderHelper.disableStandardItemLighting();
+ GlStateManager.disableLighting();
+ GlStateManager.disableDepth();
+
+ int color = 0xFFFFFF;
+
+ final int zLevel = 300;
+ int backgroundColor = 0xF0100010;
+ int borderColorStart = 0x505000FF;
+ int borderColorEnd = (borderColorStart & 0xFEFEFE) >> 1 | borderColorStart & 0xFF000000;
+// RenderTooltipEvent.Color colorEvent = new RenderTooltipEvent.Color(ItemStack.EMPTY, lines, tooltipX, tooltipY, TextRenderer.getFontRenderer(), backgroundColor, borderColorStart, borderColorEnd);
+// MinecraftForge.EVENT_BUS.post(colorEvent);
+// backgroundColor = colorEvent.getBackground();
+// borderColorStart = colorEvent.getBorderStart();
+// borderColorEnd = colorEvent.getBorderEnd();
+ drawGradientRect(zLevel, tooltipX - 3, tooltipY - 4, tooltipX + tooltipTextWidth + 3, tooltipY - 3, backgroundColor, backgroundColor);
+ drawGradientRect(zLevel, tooltipX - 3, tooltipY + tooltipHeight + 3, tooltipX + tooltipTextWidth + 3, tooltipY + tooltipHeight + 4, backgroundColor, backgroundColor);
+ drawGradientRect(zLevel, tooltipX - 3, tooltipY - 3, tooltipX + tooltipTextWidth + 3, tooltipY + tooltipHeight + 3, backgroundColor, backgroundColor);
+ drawGradientRect(zLevel, tooltipX - 4, tooltipY - 3, tooltipX - 3, tooltipY + tooltipHeight + 3, backgroundColor, backgroundColor);
+ drawGradientRect(zLevel, tooltipX + tooltipTextWidth + 3, tooltipY - 3, tooltipX + tooltipTextWidth + 4, tooltipY + tooltipHeight + 3, backgroundColor, backgroundColor);
+ drawGradientRect(zLevel, tooltipX - 3, tooltipY - 3 + 1, tooltipX - 3 + 1, tooltipY + tooltipHeight + 3 - 1, borderColorStart, borderColorEnd);
+ drawGradientRect(zLevel, tooltipX + tooltipTextWidth + 2, tooltipY - 3 + 1, tooltipX + tooltipTextWidth + 3, tooltipY + tooltipHeight + 3 - 1, borderColorStart, borderColorEnd);
+ drawGradientRect(zLevel, tooltipX - 3, tooltipY - 3, tooltipX + tooltipTextWidth + 3, tooltipY - 3 + 1, borderColorStart, borderColorStart);
+ drawGradientRect(zLevel, tooltipX - 3, tooltipY + tooltipHeight + 2, tooltipX + tooltipTextWidth + 3, tooltipY + tooltipHeight + 3, borderColorEnd, borderColorEnd);
+
+// MinecraftForge.EVENT_BUS.post(new RenderTooltipEvent.PostBackground(ItemStack.EMPTY, lines, tooltipX, tooltipY, TextRenderer.getFontRenderer(), tooltipTextWidth, tooltipHeight));
+
+ renderer.setSimulate(false);
+ renderer.setPos(tooltipX, tooltipY);
+ renderer.setAlignment(alignment, maxTextWidth);
+ renderer.setColor(color);
+ renderer.drawMeasuredLines(measuredLines);
+
+// MinecraftForge.EVENT_BUS.post(new RenderTooltipEvent.PostText(ItemStack.EMPTY, lines, tooltipX, tooltipY, TextRenderer.getFontRenderer(), tooltipTextWidth, tooltipHeight));
+
+ GlStateManager.enableLighting();
+ GlStateManager.enableDepth();
+ RenderHelper.enableStandardItemLighting();
+ GlStateManager.enableRescaleNormal();
+ }
+
+ //==== Draw helpers ====
+
+ public static void drawGradientRect(float zLevel, float left, float top, float right, float bottom, int startColor, int endColor) {
+ float startAlpha = (float) (startColor >> 24 & 255) / 255.0F;
+ float startRed = (float) (startColor >> 16 & 255) / 255.0F;
+ float startGreen = (float) (startColor >> 8 & 255) / 255.0F;
+ float startBlue = (float) (startColor & 255) / 255.0F;
+ float endAlpha = (float) (endColor >> 24 & 255) / 255.0F;
+ float endRed = (float) (endColor >> 16 & 255) / 255.0F;
+ float endGreen = (float) (endColor >> 8 & 255) / 255.0F;
+ float endBlue = (float) (endColor & 255) / 255.0F;
+
+ GlStateManager.disableTexture2D();
+ GlStateManager.enableBlend();
+ GlStateManager.disableAlpha();
+ GlStateManager.tryBlendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ZERO);
+ GlStateManager.shadeModel(GL11.GL_SMOOTH);
+
+ Tessellator tessellator = Tessellator.instance;
+ tessellator.startDrawing(GL11.GL_QUADS);
+ tessellator.setColorRGBA_F(startRed, startGreen, startBlue, startAlpha);
+ tessellator.addVertex(right, top, zLevel);
+ tessellator.setColorRGBA_F(startRed, startGreen, startBlue, startAlpha);
+ tessellator.addVertex(left, top, zLevel);
+ tessellator.setColorRGBA_F(endRed, endGreen, endBlue, endAlpha);
+ tessellator.addVertex(left, bottom, zLevel);
+ tessellator.setColorRGBA_F(endRed, endGreen, endBlue, endAlpha);
+ tessellator.addVertex(right, bottom, zLevel);
+ tessellator.draw();
+
+ GlStateManager.shadeModel(GL11.GL_FLAT);
+ GlStateManager.disableBlend();
+ GlStateManager.enableAlpha();
+ GlStateManager.enableTexture2D();
+ }
+
+ public static void drawFluidTexture(FluidStack content, float x0, float y0, float width, float height, float z) {
+ if (content == null) {
+ return;
+ }
+ Fluid fluid = content.getFluid();
+ IIcon fluidStill = fluid.getIcon(content);
+ int fluidColor = fluid.getColor(content);
+ GlStateManager.enableBlend();
+ Minecraft.getMinecraft().renderEngine.bindTexture(TextureMap.locationBlocksTexture);
+
+ float u0 = fluidStill.getMinU(), u1 = fluidStill.getMaxU(), v0 = fluidStill.getMinV(), v1 = fluidStill.getMaxV();
+ float x1 = x0 + width, y1 = y0 + height;
+ float r = Color.getRedF(fluidColor), g = Color.getGreenF(fluidColor), b = Color.getBlueF(fluidColor), a = Color.getAlphaF(fluidColor);
+
+ Tessellator tessellator = Tessellator.instance;
+// tessellator.startDrawing(7, DefaultVertexFormats.POSITION_TEX_COLOR);
+ tessellator.startDrawingQuads();
+ tessellator.setColorRGBA_F(r, g, b, a);
+ tessellator.setTextureUV(u0, v1);
+ tessellator.addVertex(x0, y1, z);
+ tessellator.setTextureUV(u1, v1);
+ tessellator.addVertex(x1, y1, z);
+ tessellator.setTextureUV(u1, v0);
+ tessellator.addVertex(x1, y0, z);
+ tessellator.setTextureUV(u0, v0);
+ tessellator.addVertex(x0, y0, z);
+ tessellator.draw();
+ GlStateManager.disableBlend();
+ }
+
+
+ //==== Scissor helpers ====
+
+ private static final Stack scissorFrameStack = new Stack<>();
+
+ public static void useScissor(int x, int y, int width, int height, Runnable codeBlock) {
+ pushScissorFrame(x, y, width, height);
+ try {
+ codeBlock.run();
+ } finally {
+ popScissorFrame();
+ }
+ }
+
+ private static int[] peekFirstScissorOrFullScreen() {
+ int[] currentTopFrame = scissorFrameStack.isEmpty() ? null : scissorFrameStack.peek();
+ if (currentTopFrame == null) {
+ Minecraft minecraft = Minecraft.getMinecraft();
+ return new int[]{0, 0, minecraft.displayWidth, minecraft.displayHeight};
+ }
+ return currentTopFrame;
+ }
+
+ public static void pushScissorFrame(int x, int y, int width, int height) {
+ int[] parentScissor = peekFirstScissorOrFullScreen();
+ int parentX = parentScissor[0];
+ int parentY = parentScissor[1];
+ int parentWidth = parentScissor[2];
+ int parentHeight = parentScissor[3];
+
+ boolean pushedFrame = false;
+ if (x <= parentX + parentWidth && y <= parentY + parentHeight) {
+ int newX = Math.max(x, parentX);
+ int newY = Math.max(y, parentY);
+ int newWidth = width - (newX - x);
+ int newHeight = height - (newY - y);
+ if (newWidth > 0 && newHeight > 0) {
+ int maxWidth = parentWidth - (x - parentX);
+ int maxHeight = parentHeight - (y - parentY);
+ newWidth = Math.min(maxWidth, newWidth);
+ newHeight = Math.min(maxHeight, newHeight);
+ applyScissor(newX, newY, newWidth, newHeight);
+ //finally, push applied scissor on top of scissor stack
+ if (scissorFrameStack.isEmpty()) {
+ GL11.glEnable(GL11.GL_SCISSOR_TEST);
+ }
+ scissorFrameStack.push(new int[]{newX, newY, newWidth, newHeight});
+ pushedFrame = true;
+ }
+ }
+ if (!pushedFrame) {
+ if (scissorFrameStack.isEmpty()) {
+ GL11.glEnable(GL11.GL_SCISSOR_TEST);
+ }
+ scissorFrameStack.push(new int[]{parentX, parentY, parentWidth, parentHeight});
+ }
+ }
+
+ public static void popScissorFrame() {
+ scissorFrameStack.pop();
+ int[] parentScissor = peekFirstScissorOrFullScreen();
+ int parentX = parentScissor[0];
+ int parentY = parentScissor[1];
+ int parentWidth = parentScissor[2];
+ int parentHeight = parentScissor[3];
+ applyScissor(parentX, parentY, parentWidth, parentHeight);
+ if (scissorFrameStack.isEmpty()) {
+ GL11.glDisable(GL11.GL_SCISSOR_TEST);
+ }
+ }
+
+ //applies scissor with gui-space coordinates and sizes
+ private static void applyScissor(int x, int y, int w, int h) {
+ //translate upper-left to bottom-left
+ ScaledResolution r = ((GuiIngameForge) Minecraft.getMinecraft().ingameGUI).getResolution();
+ int s = r == null ? 1 : r.getScaleFactor();
+ int translatedY = r == null ? 0 : (r.getScaledHeight() - y - h);
+ GL11.glScissor(x * s, translatedY * s, w * s, h * s);
+ }
+}
diff --git a/src/main/java/com/gtnewhorizons/modularui/api/drawable/IDrawable.java b/src/main/java/com/gtnewhorizons/modularui/api/drawable/IDrawable.java
new file mode 100644
index 0000000..a238415
--- /dev/null
+++ b/src/main/java/com/gtnewhorizons/modularui/api/drawable/IDrawable.java
@@ -0,0 +1,120 @@
+package com.gtnewhorizons.modularui.api.drawable;
+
+import com.google.gson.JsonObject;
+import com.gtnewhorizons.modularui.api.GlStateManager;
+import com.gtnewhorizons.modularui.api.math.Color;
+import com.gtnewhorizons.modularui.api.math.Pos2d;
+import com.gtnewhorizons.modularui.api.math.Size;
+import com.gtnewhorizons.modularui.common.internal.JsonHelper;
+import com.gtnewhorizons.modularui.common.widget.DrawableWidget;
+import cpw.mods.fml.relauncher.Side;
+import cpw.mods.fml.relauncher.SideOnly;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.function.Function;
+
+@FunctionalInterface
+public interface IDrawable {
+
+ /**
+ * Empty drawable
+ */
+ IDrawable EMPTY = (x, y, width, height, partialTicks) -> {
+ };
+
+ /**
+ * Called ever frame
+ *
+ * @param x x position
+ * @param y y position
+ * @param width width of the drawable
+ * @param height height of the drawable
+ * @param partialTicks ticks since last render
+ */
+ @SideOnly(Side.CLIENT)
+ void draw(float x, float y, float width, float height, float partialTicks);
+
+ @SideOnly(Side.CLIENT)
+ default void draw(Pos2d pos, Size size, float partialTicks) {
+ draw(pos.x, pos.y, size.width, size.height, partialTicks);
+ }
+
+ default void tick() {
+ }
+
+ @SideOnly(Side.CLIENT)
+ default void applyThemeColor(int color) {
+ GlStateManager.color(Color.getRedF(color), Color.getGreenF(color), Color.getBlueF(color), Color.getAlphaF(color));
+ }
+
+ @SideOnly(Side.CLIENT)
+ default void applyThemeColor() {
+ applyThemeColor(Color.WHITE.normal);
+ }
+
+ /**
+ * @return a drawable that can be used in guis as a widget
+ */
+ default DrawableWidget asWidget() {
+ return new DrawableWidget().setDrawable(this);
+ }
+
+ /**
+ * This drawable with an offset pos.
+ * Useful if the background of a widget should be larger than the widget itself.
+ *
+ * @param offsetX offset in x
+ * @param offsetY offset in y
+ * @param widthOffset offset width (added to the width passed in {@link #draw(float, float, float, float, float)})
+ * @param heightOffset offset height (added to the height passed in {@link #draw(float, float, float, float, float)})
+ * @return this drawable with offset
+ */
+ default IDrawable withOffset(float offsetX, float offsetY, float widthOffset, float heightOffset) {
+ return new OffsetDrawable(this, offsetX, offsetY, widthOffset, heightOffset);
+ }
+
+ default IDrawable withOffset(float offsetX, float offsetY) {
+ return new OffsetDrawable(this, offsetX, offsetY);
+ }
+
+ /**
+ * This drawable with a fixed size.
+ *
+ * @param fixedHeight fixed width (ignores width passed in {@link #draw(float, float, float, float, float)})
+ * @param fixedWidth fixed height (ignores height passed in {@link #draw(float, float, float, float, float)})
+ * @param offsetX offset in x
+ * @param offsetY offset in y
+ * @return this drawable with offset
+ */
+ default IDrawable withFixedSize(float fixedWidth, float fixedHeight, float offsetX, float offsetY) {
+ return new SizedDrawable(this, fixedWidth, fixedHeight, offsetX, offsetY);
+ }
+
+ default IDrawable withFixedSize(float fixedWidth, float fixedHeight) {
+ return new SizedDrawable(this, fixedWidth, fixedHeight);
+ }
+
+ static final Map> JSON_DRAWABLE_MAP = new HashMap<>();
+
+ static IDrawable ofJson(JsonObject json) {
+ IDrawable drawable = EMPTY;
+ if (json.has("type")) {
+ Function function = JSON_DRAWABLE_MAP.get(json.get("type").getAsString());
+ if (function != null) {
+ drawable = function.apply(json);
+ }
+ }
+ Pos2d offset = JsonHelper.getElement(json, Pos2d.ZERO, Pos2d::ofJson, "offset");
+ Size offsetSize = JsonHelper.getElement(json, Size.ZERO, Size::ofJson, "offsetSize");
+ Size fixedSize = JsonHelper.getElement(json, Size.ZERO, Size::ofJson, "fixedSize");
+ if (!fixedSize.isZero()) {
+ return drawable.withFixedSize(fixedSize.width, fixedSize.height, offset.x, offset.y);
+ }
+ if (!offset.isZero() || !offsetSize.isZero()) {
+ return drawable.withOffset(offset.x, offset.y, offsetSize.width, offsetSize.height);
+ }
+
+ return drawable;
+ }
+}
diff --git a/src/main/java/com/gtnewhorizons/modularui/api/drawable/ItemDrawable.java b/src/main/java/com/gtnewhorizons/modularui/api/drawable/ItemDrawable.java
new file mode 100644
index 0000000..61a523b
--- /dev/null
+++ b/src/main/java/com/gtnewhorizons/modularui/api/drawable/ItemDrawable.java
@@ -0,0 +1,52 @@
+package com.gtnewhorizons.modularui.api.drawable;
+
+import com.gtnewhorizons.modularui.api.GlStateManager;
+import com.gtnewhorizons.modularui.api.Widget;
+import com.gtnewhorizons.modularui.common.widget.DrawableWidget;
+import net.minecraft.client.Minecraft;
+import net.minecraft.client.renderer.RenderHelper;
+import net.minecraft.client.renderer.entity.RenderItem;
+import net.minecraft.item.ItemStack;
+import org.jetbrains.annotations.NotNull;
+
+/**
+ * Draws item. Can also be used for {@link Widget}
+ */
+public class ItemDrawable implements IDrawable {
+
+ private ItemStack item = null;
+
+ private static final RenderItem itemRenderer = new RenderItem();
+
+ public ItemDrawable(@NotNull ItemStack item) {
+ this.item = item;
+ }
+
+ @Override
+ public void applyThemeColor(int color) {
+ }
+
+ @Override
+ public void draw(float x, float y, float width, float height, float partialTicks) {
+ if (item.getItem() == null) return;
+ GlStateManager.pushMatrix();
+ RenderHelper.enableGUIStandardItemLighting();
+ GlStateManager.enableDepth();
+ GlStateManager.scale(width / 16, height / 16, 1);
+ itemRenderer.renderItemAndEffectIntoGUI(item.getItem().getFontRenderer(item), Minecraft.getMinecraft().getTextureManager(), item, (int) x, (int) y);
+ GlStateManager.disableDepth();
+ RenderHelper.enableStandardItemLighting();
+ GlStateManager.disableLighting();
+ GlStateManager.popMatrix();
+ }
+
+ @Override
+ public DrawableWidget asWidget() {
+ return (DrawableWidget) IDrawable.super.asWidget().setSize(16, 16);
+ }
+
+ public ItemDrawable setItem(@NotNull ItemStack item) {
+ this.item = item;
+ return this;
+ }
+}
diff --git a/src/main/java/com/gtnewhorizons/modularui/api/drawable/OffsetDrawable.java b/src/main/java/com/gtnewhorizons/modularui/api/drawable/OffsetDrawable.java
new file mode 100644
index 0000000..3f8e4d6
--- /dev/null
+++ b/src/main/java/com/gtnewhorizons/modularui/api/drawable/OffsetDrawable.java
@@ -0,0 +1,28 @@
+package com.gtnewhorizons.modularui.api.drawable;
+
+/**
+ * Draws a {@link IDrawable} to a offset pos with a offset size
+ */
+public class OffsetDrawable implements IDrawable {
+
+ private final IDrawable drawable;
+ private final float offsetX, offsetY;
+ private final float widthOffset, heightOffset;
+
+ public OffsetDrawable(IDrawable drawable, float offsetX, float offsetY, float widthOffset, float heightOffset) {
+ this.drawable = drawable;
+ this.offsetX = offsetX;
+ this.offsetY = offsetY;
+ this.widthOffset = widthOffset;
+ this.heightOffset = heightOffset;
+ }
+
+ public OffsetDrawable(IDrawable drawable, float offsetX, float offsetY) {
+ this(drawable, offsetX, offsetY, 0, 0);
+ }
+
+ @Override
+ public void draw(float x, float y, float width, float height, float partialTicks) {
+ drawable.draw(x + offsetX, y + offsetY, width + widthOffset, height + heightOffset, partialTicks);
+ }
+}
diff --git a/src/main/java/com/gtnewhorizons/modularui/api/drawable/SizedDrawable.java b/src/main/java/com/gtnewhorizons/modularui/api/drawable/SizedDrawable.java
new file mode 100644
index 0000000..3a9b4a4
--- /dev/null
+++ b/src/main/java/com/gtnewhorizons/modularui/api/drawable/SizedDrawable.java
@@ -0,0 +1,28 @@
+package com.gtnewhorizons.modularui.api.drawable;
+
+/**
+ * Draws a {@link IDrawable} with a fixed size to a offset position
+ */
+public class SizedDrawable implements IDrawable {
+
+ private final IDrawable drawable;
+ private final float fixedWidth, fixedHeight;
+ private final float offsetX, offsetY;
+
+ public SizedDrawable(IDrawable drawable, float fixedWidth, float fixedHeight, float offsetX, float offsetY) {
+ this.drawable = drawable;
+ this.fixedWidth = fixedWidth;
+ this.fixedHeight = fixedHeight;
+ this.offsetX = offsetX;
+ this.offsetY = offsetY;
+ }
+
+ public SizedDrawable(IDrawable drawable, float fixedWidth, float fixedHeight) {
+ this(drawable, fixedWidth, fixedHeight, 0, 0);
+ }
+
+ @Override
+ public void draw(float x, float y, float width, float height, float partialTicks) {
+ drawable.draw(x + offsetX, y + offsetY, fixedWidth, fixedHeight, partialTicks);
+ }
+}
diff --git a/src/main/java/com/gtnewhorizons/modularui/api/drawable/Text.java b/src/main/java/com/gtnewhorizons/modularui/api/drawable/Text.java
new file mode 100644
index 0000000..0a0b8ca
--- /dev/null
+++ b/src/main/java/com/gtnewhorizons/modularui/api/drawable/Text.java
@@ -0,0 +1,139 @@
+package com.gtnewhorizons.modularui.api.drawable;
+
+import com.google.gson.JsonElement;
+import com.google.gson.JsonObject;
+import com.gtnewhorizons.modularui.api.math.Alignment;
+import com.gtnewhorizons.modularui.api.math.Color;
+import com.gtnewhorizons.modularui.common.internal.JsonHelper;
+import com.gtnewhorizons.modularui.common.internal.Theme;
+import cpw.mods.fml.common.FMLCommonHandler;
+import net.minecraft.client.resources.I18n;
+import net.minecraft.util.ChatComponentText;
+import net.minecraft.util.EnumChatFormatting;
+
+import javax.annotation.Nullable;
+import java.util.Objects;
+import java.util.function.Supplier;
+
+public class Text implements IDrawable {
+
+ public static final Text EMPTY = new Text("");
+
+ private static final TextRenderer renderer = new TextRenderer();
+ private final String text;
+ private String formatting = "";
+ @Nullable
+ private Supplier