Browse Source

first commit

master
Adrian Siekierka 1 year ago
commit
b96caf196c

+ 13
- 0
README.md View File

@@ -0,0 +1,13 @@
# Ion Chests

## Compilation Instructions

1. Download Quark and AutoRegLib from CurseForge.
2. Run [BON2](https://ci.tterrag.com/job/BON2/) on them with the matching version of mappings.
3. Move the resulting JARs to libs/.
4. Run "gradle setupDecompWorkspace", etc. as usual.
5. Don't forget to add -Dfml.coreMods.load=pl.asie.ionchests.IonChests to the VM arguments!

## License

To be decided.

+ 94
- 0
build.gradle View File

@@ -0,0 +1,94 @@
buildscript {
repositories {
jcenter()
maven { url = "http://files.minecraftforge.net/maven" }
maven { url "https://plugins.gradle.org/m2/" }
}
dependencies {
classpath 'net.minecraftforge.gradle:ForgeGradle:2.3-SNAPSHOT'
}
}
apply plugin: 'net.minecraftforge.gradle.forge'
version = "1.0.0"
group = "pl.asie.ionchests"
archivesBaseName = "IonChests"
sourceCompatibility = targetCompatibility = '1.8'
compileJava {
sourceCompatibility = targetCompatibility = '1.8'
}
if (System.getenv("BUILD_NUMBER") != null)
version += ".${System.getenv("BUILD_NUMBER")}"
configurations {
deploy
}
dependencies {
deploy 'org.apache.maven.wagon:wagon-ssh:2.10'
}
minecraft {
version = "1.12.2-14.23.4.2739"
runDir = "run"
mappings = "snapshot_20180723"
replace "\${version}", project.version
replace "\${mcversion}", version
}
repositories {
}
sourceSets {
main {
resources {
srcDirs += 'docs'
}
}
}
dependencies {
}
processResources {
inputs.property "version", project.version
inputs.property "mcversion", project.minecraft.version
from(sourceSets.main.resources.srcDirs) {
include 'mcmod.info'
expand 'version':project.version, 'mcversion':project.minecraft.version
}
from(sourceSets.main.resources.srcDirs) {
exclude 'mcmod.info'
}
}
jar {
manifest.attributes "Manifest-Version": "1.0"
manifest.attributes "FMLCorePlugin": "pl.asie.ionchests.IonChests"
}
if (file('private.gradle').exists()) {
apply from: 'private.gradle'
}
task signJar(type: SignJar, dependsOn: reobfJar) {
onlyIf {
project.hasProperty('keyStore')
}
keyStore = project.keyStore
alias = project.keyStoreAlias
storePass = project.keyStorePass
keyPass = project.keyStoreKeyPass
inputFile = jar.archivePath
outputFile = jar.archivePath
}
build.dependsOn(signJar)

+ 3
- 0
gradle.properties View File

@@ -0,0 +1,3 @@
# Sets default memory used for gradle commands. Can be overridden by user or command line properties.
# This is required to provide enough memory for the Minecraft decompilation process.
org.gradle.jvmargs=-Xmx3G

BIN
gradle/wrapper/gradle-wrapper.jar View File


+ 6
- 0
gradle/wrapper/gradle-wrapper.properties View File

@@ -0,0 +1,6 @@
#Mon Sep 14 12:28:28 PDT 2015
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.4.1-bin.zip

+ 164
- 0
gradlew View File

@@ -0,0 +1,164 @@
#!/usr/bin/env bash

##############################################################################
##
## Gradle start up script for UN*X
##
##############################################################################

# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS=""

APP_NAME="Gradle"
APP_BASE_NAME=`basename "$0"`

# 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
case "`uname`" in
CYGWIN* )
cygwin=true
;;
Darwin* )
darwin=true
;;
MINGW* )
msys=true
;;
esac

# For Cygwin, ensure paths are in UNIX format before anything is touched.
if $cygwin ; then
[ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
fi

# 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\"`/" >&-
APP_HOME="`pwd -P`"
cd "$SAVED" >&-

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" ] ; 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, switch paths to Windows format before running java
if $cygwin ; then
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`

# 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

# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
function splitJvmOpts() {
JVM_OPTS=("$@")
}
eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"

exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"

+ 90
- 0
gradlew.bat View File

@@ -0,0 +1,90 @@
@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
@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=
set DIRNAME=%~dp0
if "%DIRNAME%" == "" set DIRNAME=.
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%
@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 Windowz variants
if not "%OS%" == "Windows_NT" goto win9xME_args
if "%@eval[2+2]" == "4" goto 4NT_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=%*
goto execute
:4NT_args
@rem Get arguments from the 4NT Shell from JP Software
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

+ 59
- 0
src/main/java/pl/asie/ionchests/IonChests.java View File

@@ -0,0 +1,59 @@
package pl.asie.ionchests;


import net.minecraftforge.common.config.Configuration;
import net.minecraftforge.fml.relauncher.IFMLLoadingPlugin;
import scala.actors.threadpool.Arrays;

import javax.annotation.Nullable;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@IFMLLoadingPlugin.Name("IonChests")
@IFMLLoadingPlugin.MCVersion("1.12.2")
@IFMLLoadingPlugin.SortingIndex(1001)
@IFMLLoadingPlugin.TransformerExclusions("pl.asie.ionchests")
public class IonChests implements IFMLLoadingPlugin {
protected static List<String> patchedGuis = new ArrayList<>();

@Override
public String[] getASMTransformerClass() {
return new String[] {
"pl.asie.ionchests.IonChestsTransformer"
};
}

@Override
public String getModContainerClass() {
return null;
}

@Nullable
@Override
public String getSetupClass() {
return null;
}

@Override
public void injectData(Map<String, Object> data) {
Configuration config = new Configuration(new File(new File("config"), "ionchestscompat.cfg"));

String[] patchNames = config.getStringList("additionalGuiClasses", "general", new String[0], "Additional GUI classes, in the form of pa.ck.age.ClassName");
patchedGuis.addAll(Arrays.asList(patchNames));

patchedGuis.add("cpw.mods.ironchest.client.gui.chest.GUIChest");
patchedGuis.add("cpw.mods.ironchest.client.gui.shulker.GUIShulkerChest");
patchedGuis.add("pl.asie.charset.module.storage.chests.GuiChestCharset");

if (config.hasChanged()) {
config.save();
}
}

@Override
public String getAccessTransformerClass() {
return null;
}
}

+ 189
- 0
src/main/java/pl/asie/ionchests/IonChestsTransformer.java View File

@@ -0,0 +1,189 @@
package pl.asie.ionchests;

import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import com.google.common.io.ByteStreams;
import net.minecraft.launchwrapper.IClassTransformer;
import net.minecraft.launchwrapper.LaunchClassLoader;
import net.minecraftforge.fml.common.Loader;
import org.objectweb.asm.ClassReader;
import org.objectweb.asm.ClassWriter;
import org.objectweb.asm.Opcodes;
import org.objectweb.asm.commons.ClassRemapper;
import org.objectweb.asm.commons.Remapper;
import org.objectweb.asm.tree.*;

import java.io.IOException;
import java.io.InputStream;
import java.util.List;
import java.util.ListIterator;
import java.util.Set;

public class IonChestsTransformer implements IClassTransformer {
public boolean hasClass(String s) {
try {
Class.forName(s);
return true;
} catch (ClassNotFoundException e) {
return false;
}
}

@Override
public byte[] transform(String name, String transformedName, byte[] basicClass) {
byte[] data = basicClass;

if (IonChests.patchedGuis.contains(transformedName)) {
if (hasClass("vazkii.quark.api.IChestButtonCallback")) {
data = spliceClasses(
data,
"pl.asie.ionchests.compat.Quark_Gui",
"vazkii/quark/api/IChestButtonCallback",
"vazkii/quark/api/IChestButtonCallback",
"onAddChestButton",
"onAddChestButton"
);
}

if (hasClass("vazkii.quark.api.IItemSearchBar")) {
data = spliceClasses(
data,
"pl.asie.ionchests.compat.Quark_Gui",
"vazkii/quark/api/IItemSearchBar",
"vazkii/quark/api/IItemSearchBar",
"onSearchBarAdded",
"onSearchBarAdded"
);
}
}

if (transformedName.equals("pl.asie.charset.module.storage.barrels.TileEntityDayBarrel")) {
if (hasClass("vazkii.quark.api.IDropoffManager")) {
data = spliceClasses(data,
"pl.asie.ionchests.compat.Quark_BarrelDropoffManager",
"vazkii/quark/api/IDropoffManager",
"vazkii/quark/api/IDropoffManager",
"acceptsDropoff",
"acceptsDropoff",
"getDropoffItemHandler",
"getDropoffItemHandler"
);
}
}

return data;
}

public static byte[] spliceClasses(final byte[] data, final String className, final String... methods) {
ClassReader reader = new ClassReader(data);
ClassNode nodeOrig = new ClassNode();
reader.accept(nodeOrig, 0);
ClassNode nodeNew = spliceClasses(nodeOrig, className, methods);
ClassWriter writer = new ClassWriter(0);
nodeNew.accept(writer);
return writer.toByteArray();
}

public static ClassNode spliceClasses(final ClassNode data, final String className, final String... methods) {
try (InputStream stream = IonChests.class.getClassLoader().getResourceAsStream(className.replace('.', '/') + ".class")) {
return spliceClasses(data, ByteStreams.toByteArray(stream), className, methods);
} catch (IOException e) {
throw new RuntimeException(e);
}
}


public static ClassNode spliceClasses(final ClassNode nodeData, final byte[] dataSplice, final String className, final String... methods) {
// System.out.println("Splicing from " + className + " to " + targetClassName)
if (dataSplice == null) {
throw new RuntimeException("Class " + className + " not found! This is a FoamFix bug!");
}

final Set<String> methodSet = Sets.newHashSet(methods);
final List<String> methodList = Lists.newArrayList(methods);

final ClassReader readerSplice = new ClassReader(dataSplice);
final String className2 = className.replace('.', '/');
final String targetClassName2 = nodeData.name;
final String targetClassName = targetClassName2.replace('/', '.');
final Remapper remapper = new Remapper() {
public String map(final String name) {
return className2.equals(name) ? targetClassName2 : name;
}
};

ClassNode nodeSplice = new ClassNode();
readerSplice.accept(new ClassRemapper(nodeSplice, remapper), ClassReader.EXPAND_FRAMES);
for (String s : nodeSplice.interfaces) {
if (methodSet.contains(s)) {
nodeData.interfaces.add(s);
System.out.println("Added INTERFACE: " + s);
}
}

for (int i = 0; i < nodeSplice.methods.size(); i++) {
if (methodSet.contains(nodeSplice.methods.get(i).name)) {
MethodNode mn = nodeSplice.methods.get(i);
boolean added = false;

for (int j = 0; j < nodeData.methods.size(); j++) {
if (nodeData.methods.get(j).name.equals(mn.name)
&& nodeData.methods.get(j).desc.equals(mn.desc)) {
MethodNode oldMn = nodeData.methods.get(j);
System.out.println("Spliced in METHOD: " + targetClassName + "." + mn.name);
nodeData.methods.set(j, mn);
if (nodeData.superName != null && nodeData.name.equals(nodeSplice.superName)) {
ListIterator<AbstractInsnNode> nodeListIterator = mn.instructions.iterator();
while (nodeListIterator.hasNext()) {
AbstractInsnNode node = nodeListIterator.next();
if (node instanceof MethodInsnNode
&& node.getOpcode() == Opcodes.INVOKESPECIAL) {
MethodInsnNode methodNode = (MethodInsnNode) node;
if (targetClassName2.equals(methodNode.owner)) {
methodNode.owner = nodeData.superName;
}
}
}
}

oldMn.name = methodList.get((methodList.indexOf(oldMn.name)) & (~1)) + "_foamfix_old";
nodeData.methods.add(oldMn);
added = true;
break;
}
}

if (!added) {
System.out.println("Added METHOD: " + targetClassName + "." + mn.name);
nodeData.methods.add(mn);
added = true;
}
}
}

for (int i = 0; i < nodeSplice.fields.size(); i++) {
if (methodSet.contains(nodeSplice.fields.get(i).name)) {
FieldNode mn = nodeSplice.fields.get(i);
boolean added = false;

for (int j = 0; j < nodeData.fields.size(); j++) {
if (nodeData.fields.get(j).name.equals(mn.name)
&& nodeData.fields.get(j).desc.equals(mn.desc)) {
System.out.println("Spliced in FIELD: " + targetClassName + "." + mn.name);
nodeData.fields.set(j, mn);
added = true;
break;
}
}

if (!added) {
System.out.println("Added FIELD: " + targetClassName + "." + mn.name);
nodeData.fields.add(mn);
added = true;
}
}
}

return nodeData;
}
}

+ 50
- 0
src/main/java/pl/asie/ionchests/compat/Quark_BarrelDropoffManager.java View File

@@ -0,0 +1,50 @@
package pl.asie.ionchests.compat;

import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.fml.relauncher.ReflectionHelper;
import net.minecraftforge.items.CapabilityItemHandler;
import net.minecraftforge.items.IItemHandler;
import vazkii.quark.api.IDropoffManager;

import java.lang.invoke.MethodHandle;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.function.Supplier;

public class Quark_BarrelDropoffManager extends TileEntity implements IDropoffManager {
public static class Helper {
private Helper() {

}

private static Field iv_getter;

public static IItemHandler getInsertionView(Object o) {
if (iv_getter == null) {
iv_getter = ReflectionHelper.findField(o.getClass(), "insertionView");
if (iv_getter != null) {
iv_getter.setAccessible(true);
} else {
throw new RuntimeException("Could not find " + o.getClass().getName() + ".insertionView!");
}
}

try {
return (IItemHandler) iv_getter.get(o);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}

@Override
public boolean acceptsDropoff(EntityPlayer entityPlayer) {
return true;
}

@Override
public IItemHandler getDropoffItemHandler(Supplier<IItemHandler> defaultSupplier) {
return Helper.getInsertionView(this);
}
}

+ 41
- 0
src/main/java/pl/asie/ionchests/compat/Quark_Gui.java View File

@@ -0,0 +1,41 @@
package pl.asie.ionchests.compat;

import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.gui.GuiTextField;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.inventory.Container;
import vazkii.quark.api.IChestButtonCallback;
import vazkii.quark.api.IItemSearchBar;

public class Quark_Gui extends GuiContainer implements IChestButtonCallback, IItemSearchBar {
public Quark_Gui(Container inventorySlotsIn) {
super(inventorySlotsIn);
}

@Override
public boolean onAddChestButton(GuiButton guiButton, int i) {
return true;
}

@Override
public void onSearchBarAdded(GuiTextField guiTextField) {
int xOffset = this.getXSize() - 95;
if (getClass().getName().startsWith("cpw.")) {
guiTextField.y = this.getGuiTop() - 4;
xOffset -= 4;
} else if (getClass().getName().startsWith("pl.asie.charset.module.storage.chests")) {
// Work around bug in Charset 0.5.2.x
if (this.getXSize() == 222) {
xOffset -= (222 - 176);
}
}

guiTextField.x = this.getGuiLeft() + xOffset;
}

@Override
protected void drawGuiContainerBackgroundLayer(float partialTicks, int mouseX, int mouseY) {

}
}

Loading…
Cancel
Save