Initial commit
No files matched your search
@@ -0,0 +1,22 @@
|
||||
# eclipse
|
||||
bin
|
||||
*.launch
|
||||
.settings
|
||||
.metadata
|
||||
.classpath
|
||||
.project
|
||||
|
||||
# idea
|
||||
out
|
||||
*.ipr
|
||||
*.iws
|
||||
*.iml
|
||||
.idea
|
||||
|
||||
# gradle
|
||||
build
|
||||
.gradle
|
||||
|
||||
# other
|
||||
eclipse
|
||||
run
|
||||
@@ -0,0 +1,82 @@
|
||||
|
||||
// For those who want the bleeding edge
|
||||
buildscript {
|
||||
repositories {
|
||||
jcenter()
|
||||
maven {
|
||||
name = "forge"
|
||||
url = "http://files.minecraftforge.net/maven"
|
||||
}
|
||||
}
|
||||
dependencies {
|
||||
classpath 'net.minecraftforge.gradle:ForgeGradle:2.1-SNAPSHOT'
|
||||
}
|
||||
}
|
||||
apply plugin: 'net.minecraftforge.gradle.forge'
|
||||
|
||||
/*
|
||||
// for people who want stable - not yet functional for MC 1.8.8 - we require the forgegradle 2.1 snapshot
|
||||
plugins {
|
||||
id "net.minecraftforge.gradle.forge" version "2.0.2"
|
||||
}
|
||||
*/
|
||||
version = "1.0"
|
||||
group= "com.yourname.modid" // http://maven.apache.org/guides/mini/guide-naming-conventions.html
|
||||
archivesBaseName = "modid"
|
||||
|
||||
minecraft {
|
||||
version = "1.8.9-11.15.1.1722"
|
||||
runDir = "run"
|
||||
|
||||
// the mappings can be changed at any time, and must be in the following format.
|
||||
// snapshot_YYYYMMDD snapshot are built nightly.
|
||||
// stable_# stables are built at the discretion of the MCP team.
|
||||
// Use non-default mappings at your own risk. they may not allways work.
|
||||
// simply re-run your setup task after changing the mappings to update your workspace.
|
||||
mappings = "stable_20"
|
||||
// makeObfSourceJar = false // an Srg named sources jar is made by default. uncomment this to disable.
|
||||
}
|
||||
|
||||
dependencies {
|
||||
// you may put jars on which you depend on in ./libs
|
||||
// or you may define them like so..
|
||||
//compile "some.group:artifact:version:classifier"
|
||||
//compile "some.group:artifact:version"
|
||||
|
||||
// real examples
|
||||
//compile 'com.mod-buildcraft:buildcraft:6.0.8:dev' // adds buildcraft to the dev env
|
||||
//compile 'com.googlecode.efficient-java-matrix-library:ejml:0.24' // adds ejml to the dev env
|
||||
|
||||
// the 'provided' configuration is for optional dependencies that exist at compile-time but might not at runtime.
|
||||
//provided 'com.mod-buildcraft:buildcraft:6.0.8:dev'
|
||||
|
||||
// the deobf configurations: 'deobfCompile' and 'deobfProvided' are the same as the normal compile and provided,
|
||||
// except that these dependencies get remapped to your current MCP mappings
|
||||
//deobfCompile 'com.mod-buildcraft:buildcraft:6.0.8:dev'
|
||||
//deobfProvided 'com.mod-buildcraft:buildcraft:6.0.8:dev'
|
||||
|
||||
// for more info...
|
||||
// http://www.gradle.org/docs/current/userguide/artifact_dependencies_tutorial.html
|
||||
// http://www.gradle.org/docs/current/userguide/dependency_management.html
|
||||
|
||||
}
|
||||
|
||||
processResources
|
||||
{
|
||||
// this will ensure that this task is redone when the versions change.
|
||||
inputs.property "version", project.version
|
||||
inputs.property "mcversion", project.minecraft.version
|
||||
|
||||
// replace stuff in mcmod.info, nothing else
|
||||
from(sourceSets.main.resources.srcDirs) {
|
||||
include 'mcmod.info'
|
||||
|
||||
// replace version and mcversion
|
||||
expand 'version':project.version, 'mcversion':project.minecraft.version
|
||||
}
|
||||
|
||||
// copy everything else, thats not the mcmod.info
|
||||
from(sourceSets.main.resources.srcDirs) {
|
||||
exclude 'mcmod.info'
|
||||
}
|
||||
}
|
||||
@@ -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-2.7-bin.zip
|
||||
@@ -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 "$@"
|
||||
@@ -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
|
||||
@@ -0,0 +1,67 @@
|
||||
package pers.towdium.tudicraft;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.resources.model.ModelResourceLocation;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import net.minecraftforge.fml.common.SidedProxy;
|
||||
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
|
||||
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
|
||||
import net.minecraftforge.fml.common.network.NetworkRegistry;
|
||||
import net.minecraftforge.fml.common.network.simpleimpl.SimpleNetworkWrapper;
|
||||
import net.minecraftforge.fml.common.registry.GameRegistry;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import pers.towdium.tudicraft.event.GuiEventHandler;
|
||||
import pers.towdium.tudicraft.gui.GuiHandler;
|
||||
import pers.towdium.tudicraft.item.ItemCalculator;
|
||||
import pers.towdium.tudicraft.network.IProxy;
|
||||
import pers.towdium.tudicraft.network.packages.PackageCalculatorUpdate;
|
||||
import pers.towdium.tudicraft.network.packages.PackageSlotUpdate;
|
||||
|
||||
/**
|
||||
* @author Towdium
|
||||
*/
|
||||
|
||||
@Mod(modid = Tudicraft.Reference.MODID, name = Tudicraft.Reference.MODNAME, version = Tudicraft.Reference.VERSION)
|
||||
public class Tudicraft {
|
||||
public static Item itemCalculator = new ItemCalculator().setUnlocalizedName("itemCalculator");
|
||||
public static SimpleNetworkWrapper networkWrapper;
|
||||
public static Logger log = LogManager.getLogger(Reference.MODID);
|
||||
|
||||
@SidedProxy(clientSide = "pers.towdium.tudicraft.network.ProxyClient", serverSide = "pers.towdium.tudicraft.network.ProxyServer")
|
||||
public static IProxy proxy;
|
||||
|
||||
@Mod.Instance(Tudicraft.Reference.MODID)
|
||||
public static Tudicraft instance;
|
||||
|
||||
public static class Reference {
|
||||
public static final String MODID = "tudicraft";
|
||||
public static final String MODNAME = "Tudicraft";
|
||||
public static final String VERSION = "0.0.1";
|
||||
}
|
||||
|
||||
@Mod.EventHandler
|
||||
public static void preInit(FMLPreInitializationEvent event){
|
||||
GameRegistry.registerItem(itemCalculator,itemCalculator.getUnlocalizedName().substring(5));
|
||||
networkWrapper = NetworkRegistry.INSTANCE.newSimpleChannel(Reference.MODID);
|
||||
networkWrapper.registerMessage(PackageSlotUpdate.class, PackageSlotUpdate.class, 0, Side.SERVER);
|
||||
networkWrapper.registerMessage(PackageCalculatorUpdate.class, PackageCalculatorUpdate.class, 0, Side.SERVER);
|
||||
|
||||
}
|
||||
|
||||
@Mod.EventHandler
|
||||
public static void init(FMLInitializationEvent event){
|
||||
if(event.getSide().isClient()){
|
||||
Minecraft.getMinecraft().getRenderItem().getItemModelMesher().
|
||||
register(itemCalculator, 0, new ModelResourceLocation(Reference.MODID + ":" + itemCalculator.getUnlocalizedName().substring(5), "inventory"));
|
||||
}
|
||||
NetworkRegistry.INSTANCE.registerGuiHandler(Tudicraft.instance, new GuiHandler());
|
||||
MinecraftForge.EVENT_BUS.register(new GuiEventHandler());
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,263 @@
|
||||
package pers.towdium.tudicraft.core;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import pers.towdium.tudicraft.Tudicraft;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Towdium
|
||||
*/
|
||||
public class Calculator {
|
||||
List<OperateRecord> operateRecords;
|
||||
OperateRecord currentOperate;
|
||||
List<Calculator> calculators;
|
||||
List<ItemRecord> catalystBuffer;
|
||||
ItemRecord itemRecord;
|
||||
|
||||
|
||||
public Calculator (ItemStack itemStack, int amount){
|
||||
this(new ItemRecord(itemStack, amount), new LinkedList<OperateRecord>(), new LinkedList<ItemRecord>(), true);
|
||||
}
|
||||
|
||||
public Calculator (ItemRecord itemRecord, List<OperateRecord> operateRecords, List<ItemRecord> catalystBuffer, boolean exceedMode){
|
||||
this.catalystBuffer = catalystBuffer;
|
||||
this.itemRecord = itemRecord;
|
||||
this.operateRecords = operateRecords;
|
||||
for (Recipe recipe : Tudicraft.proxy.getPlayerHandler().getAllRecipeOf(new ItemStack(itemRecord.item, itemRecord.meta))){
|
||||
if(checkRecipeValid(recipe)){
|
||||
long count = getOperateCount(recipe, exceedMode);
|
||||
this.currentOperate = new OperateRecord(recipe, count);
|
||||
ImmutableList.Builder<OperateRecord> builder = new ImmutableList.Builder<>();
|
||||
builder.addAll(operateRecords);
|
||||
builder.add(currentOperate);
|
||||
ImmutableList<OperateRecord> records = builder.build();
|
||||
ImmutableList.Builder<Calculator> calculatorBuilder = new ImmutableList.Builder<>();
|
||||
for(ItemStack itemStack : recipe.input){
|
||||
if(itemStack != null){
|
||||
calculatorBuilder.add(new Calculator(
|
||||
new ItemRecord(itemStack, count*recipe.getInputAmount(itemStack)), records, catalystBuffer, true
|
||||
));
|
||||
}
|
||||
}
|
||||
this.calculators = calculatorBuilder.build();
|
||||
return;
|
||||
}
|
||||
}
|
||||
catalystBuffer.add(itemRecord);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Calculator:" + itemRecord.item.getUnlocalizedName() + " x " + itemRecord.amount;
|
||||
}
|
||||
|
||||
public CostRecord getCost(){
|
||||
if(currentOperate != null){
|
||||
CostRecord record = getCurrentCost();
|
||||
for(Calculator calculator : calculators){
|
||||
if(calculator.currentOperate != null){
|
||||
CostRecord buffer = calculator.getCost();
|
||||
record.merge(buffer);
|
||||
}
|
||||
}
|
||||
return record;
|
||||
}else {
|
||||
return new CostRecord();
|
||||
}
|
||||
}
|
||||
|
||||
public CostRecord getCurrentCost(){
|
||||
List<ItemRecord> output = new LinkedList<>();
|
||||
List<ItemRecord> input = new LinkedList<>();
|
||||
for(ItemStack itemStack : currentOperate.recipe.output){
|
||||
if(itemStack != null){
|
||||
output.add(new ItemRecord(itemStack, currentOperate.count*itemStack.stackSize));
|
||||
}
|
||||
}
|
||||
for(ItemStack itemStack : currentOperate.recipe.input){
|
||||
if(itemStack != null){
|
||||
input.add(new ItemRecord(itemStack, currentOperate.count*itemStack.stackSize));
|
||||
}
|
||||
}
|
||||
return new Calculator.CostRecord(output, input);
|
||||
}
|
||||
|
||||
protected boolean checkRecipeValid(Recipe recipe){
|
||||
for (OperateRecord record : operateRecords){
|
||||
if(record.recipe.equals(recipe) && record.count == getOperateCount(recipe)){
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
protected long getOperateCount(Recipe recipe){
|
||||
return (int)Math.ceil((float)itemRecord.amount/itemRecord.getOutputAmount(recipe));
|
||||
}
|
||||
|
||||
protected long getOperateCount(Recipe recipe, boolean exceed){
|
||||
if(exceed){
|
||||
return (int)Math.ceil((float)itemRecord.amount/itemRecord.getOutputAmount(recipe));
|
||||
} else {
|
||||
return itemRecord.amount/itemRecord.getOutputAmount(recipe);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
public class CostRecord{
|
||||
List<ItemRecord> output;
|
||||
List<ItemRecord> input;
|
||||
List<ItemRecord> catalyst;
|
||||
|
||||
public CostRecord(){
|
||||
output = new ArrayList<>();
|
||||
input = new ArrayList<>();
|
||||
}
|
||||
|
||||
public CostRecord(List<ItemRecord> output, List<ItemRecord> input) {
|
||||
this.output = output;
|
||||
this.input = input;
|
||||
}
|
||||
|
||||
public void merge(CostRecord costRecord){
|
||||
LOOP1:
|
||||
for(ItemRecord record : costRecord.output){
|
||||
for(ItemRecord record1 : output){
|
||||
if(record1.add(record))
|
||||
continue LOOP1;
|
||||
}
|
||||
output.add(record);
|
||||
}
|
||||
LOOP2:
|
||||
for(ItemRecord record : costRecord.input){
|
||||
for(ItemRecord record1 : input){
|
||||
if(record1.add(record))
|
||||
continue LOOP2;
|
||||
}
|
||||
input.add(record);
|
||||
}
|
||||
}
|
||||
|
||||
public void unify(){
|
||||
cancelIO();
|
||||
for (int i = 0; i < output.size(); i++) {
|
||||
ItemRecord itemRecord = output.get(i);
|
||||
if (!itemRecord.isSameType(Calculator.this.itemRecord)) {
|
||||
CostRecord record = new Calculator(itemRecord, new LinkedList<OperateRecord>(), new LinkedList<ItemRecord>(), true).getCost();
|
||||
record.cancelIO();
|
||||
if (this.canCancelBy(record)) {
|
||||
List<ItemRecord> buffer = record.input;
|
||||
record.input = record.output;
|
||||
record.output = buffer;
|
||||
this.merge(record);
|
||||
this.cancelIO();
|
||||
} else {
|
||||
record = new Calculator(itemRecord, new LinkedList<OperateRecord>(), new LinkedList<ItemRecord>(), false).getCost();
|
||||
record.cancelIO();
|
||||
if(this.canCancelBy(record)) {
|
||||
List<ItemRecord> buffer = record.input;
|
||||
record.input = record.output;
|
||||
record.output = buffer;
|
||||
this.merge(record);
|
||||
this.cancelIO();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
cancelEmpty();
|
||||
}
|
||||
|
||||
protected boolean canCancelBy(CostRecord record){
|
||||
LOOP1:
|
||||
for(ItemRecord itemRecIn : record.output){
|
||||
for(ItemRecord itemRec : output){
|
||||
if(itemRec.isSameType(itemRecIn) && itemRec.amount>=itemRecIn.amount){
|
||||
continue LOOP1;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
LOOP2:
|
||||
for(ItemRecord itemRecIn : record.input){
|
||||
for(ItemRecord itemRec : input){
|
||||
if(itemRec.isSameType(itemRecIn) && itemRec.amount>=itemRecIn.amount){
|
||||
continue LOOP2;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
protected void cancelIO(){
|
||||
ImmutableList.Builder<ItemRecord> catalystBuilder = new ImmutableList.Builder<>();
|
||||
if(catalyst != null){
|
||||
catalystBuilder.addAll(catalyst);
|
||||
}
|
||||
for (ItemRecord inputRec : input) {
|
||||
for (ItemRecord outputRec : output) {
|
||||
if (inputRec.cancel(outputRec) && inputRec.amount == 0) {
|
||||
LOOP:
|
||||
for (ItemRecord itemRecord : Calculator.this.catalystBuffer){
|
||||
if(itemRecord.isSameType(inputRec)){
|
||||
if(catalyst != null){
|
||||
for (ItemRecord exist : catalyst) {
|
||||
if (itemRecord.isSameType(exist)) {
|
||||
continue LOOP;
|
||||
}
|
||||
}
|
||||
}
|
||||
catalystBuilder.add(inputRec.copy());
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catalyst = catalystBuilder.build();
|
||||
}
|
||||
|
||||
protected void cancelEmpty(){
|
||||
ImmutableList.Builder<ItemRecord> builder = new ImmutableList.Builder<>();
|
||||
for(ItemRecord record : output){
|
||||
if(record.amount != 0){
|
||||
builder.add(record);
|
||||
}
|
||||
}
|
||||
output = builder.build();
|
||||
builder = new ImmutableList.Builder<>();
|
||||
for(ItemRecord record : input){
|
||||
if(record.amount != 0){
|
||||
builder.add(record);
|
||||
}
|
||||
}
|
||||
input = builder.build();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class OperateRecord{
|
||||
Recipe recipe;
|
||||
long count;
|
||||
|
||||
public OperateRecord(Recipe recipe, long count) {
|
||||
this.recipe = recipe;
|
||||
this.count = count;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if(!(obj instanceof OperateRecord)){
|
||||
return false;
|
||||
} else {
|
||||
OperateRecord record = (OperateRecord) obj;
|
||||
return record.recipe.equals(recipe) && record.count == count;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
package pers.towdium.tudicraft.core;
|
||||
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
/**
|
||||
* @author Towdium
|
||||
*/
|
||||
public class ItemRecord{
|
||||
Item item;
|
||||
int meta;
|
||||
long amount;
|
||||
|
||||
public ItemRecord(ItemStack itemStack, long amount){
|
||||
item = itemStack.getItem();
|
||||
meta = itemStack.getMetadata();
|
||||
this.amount = amount;
|
||||
}
|
||||
|
||||
public ItemRecord(Item item, int meta, long amount) {
|
||||
this.item = item;
|
||||
this.meta = meta;
|
||||
this.amount = amount;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "itemRecord:" + item.getUnlocalizedName() + " x " + amount;
|
||||
}
|
||||
|
||||
protected int getOutputAmount(Recipe recipe){
|
||||
for(int i = 0; i<4; i++){
|
||||
if(recipe.output[i].getItem() == item && recipe.output[i].getMetadata() == meta){
|
||||
return ItemStackWrapper.getUnifiedAmount(recipe.output[i]);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public boolean isSameType(ItemRecord record){
|
||||
return item == record.item && meta == record.meta;
|
||||
}
|
||||
|
||||
public boolean add(ItemRecord record){
|
||||
if (isSameType(record)){
|
||||
amount += record.amount;
|
||||
return true;
|
||||
}else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean minus(ItemRecord record){
|
||||
if (isSameType(record)){
|
||||
amount -= record.amount;
|
||||
return true;
|
||||
}else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean cancel(ItemRecord record){
|
||||
if (isSameType(record)){
|
||||
long i = amount>record.amount ? record.amount : amount;
|
||||
amount -= i;
|
||||
record.amount -= i;
|
||||
return i!=0;
|
||||
}else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public ItemRecord copy(){
|
||||
return new ItemRecord(item, meta, amount);
|
||||
}
|
||||
|
||||
public ItemStack toItemStack(){
|
||||
return new ItemStack(item, (int) amount, meta);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,104 @@
|
||||
package pers.towdium.tudicraft.core;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraftforge.common.util.Constants;
|
||||
|
||||
/**
|
||||
* @author Towdium
|
||||
*/
|
||||
public class ItemStackWrapper {
|
||||
|
||||
public static boolean isTypeEqual(ItemStack one, ItemStack two){
|
||||
return ItemStack.areItemsEqual(one, two);
|
||||
}
|
||||
|
||||
public static boolean isStackEqual(ItemStack one, ItemStack two){
|
||||
return ItemStack.areItemStacksEqual(one, two);
|
||||
}
|
||||
|
||||
public static boolean isSwapAcceptable(ItemStack in, ItemStack out){
|
||||
return !isTypeEqual(in, out) || getUnifiedAmount(in) < getUnifiedAmount(out);
|
||||
}
|
||||
|
||||
public static ItemStack unify(ItemStack itemStack){
|
||||
if(itemStack == null){
|
||||
return null;
|
||||
}
|
||||
NBTTagCompound nbtTagCompound = new NBTTagCompound();
|
||||
nbtTagCompound.setInteger("count", getNormalAmount(itemStack));
|
||||
nbtTagCompound.setBoolean("approx", false);
|
||||
ItemStack buffer = new ItemStack(itemStack.getItem(), 1, itemStack.getMetadata());
|
||||
buffer.setTagCompound(nbtTagCompound);
|
||||
return buffer;
|
||||
}
|
||||
|
||||
public static ItemStack unify(ItemStack itemStack, int amount){
|
||||
NBTTagCompound nbtTagCompound = new NBTTagCompound();
|
||||
nbtTagCompound.setInteger("count", amount*100);
|
||||
nbtTagCompound.setBoolean("approx", false);
|
||||
ItemStack buffer = new ItemStack(itemStack.getItem(), 1, itemStack.getMetadata());
|
||||
buffer.setTagCompound(nbtTagCompound);
|
||||
return buffer;
|
||||
}
|
||||
|
||||
public static int getUnifiedAmount(ItemStack itemStack){
|
||||
if(itemStack.hasTagCompound()){
|
||||
return itemStack.getTagCompound().getInteger("count");
|
||||
}else {
|
||||
return itemStack.stackSize;
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean getUnifiedApprox(ItemStack itemStack) {
|
||||
return itemStack.hasTagCompound() && itemStack.getTagCompound().getBoolean("approx");
|
||||
}
|
||||
|
||||
public static int getNormalAmount(ItemStack itemStack){
|
||||
return itemStack.stackSize*100;
|
||||
}
|
||||
|
||||
public static class NBT {
|
||||
public static void initNBT(ItemStack itemStack){
|
||||
if(!itemStack.hasTagCompound()){
|
||||
itemStack.setTagCompound(new NBTTagCompound());
|
||||
}
|
||||
}
|
||||
|
||||
public static void setItem(ItemStack dest, String key, ItemStack content){
|
||||
initNBT(dest);
|
||||
NBTTagCompound buffer = new NBTTagCompound();
|
||||
if (content != null){
|
||||
content.writeToNBT(buffer);
|
||||
dest.getTagCompound().setTag(key, buffer);
|
||||
}else {
|
||||
dest.getTagCompound().removeTag(key);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static ItemStack getItem(ItemStack itemStack, String key){
|
||||
NBTTagCompound tagCompound = itemStack.getTagCompound();
|
||||
if(tagCompound == null){
|
||||
return null;
|
||||
}
|
||||
NBTTagCompound itemTagCompound = tagCompound.getCompoundTag(key);
|
||||
if(itemTagCompound == null){
|
||||
return null;
|
||||
}
|
||||
return ItemStack.loadItemStackFromNBT(itemTagCompound);
|
||||
}
|
||||
|
||||
public static void setString(ItemStack dest, String key, String value){
|
||||
initNBT(dest);
|
||||
dest.getTagCompound().setString(key, value);
|
||||
}
|
||||
|
||||
public static String getString(ItemStack dest, String key){
|
||||
if(dest.getTagCompound() != null){
|
||||
return dest.getTagCompound().getString(key);
|
||||
}
|
||||
else return "";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,116 @@
|
||||
package pers.towdium.tudicraft.core;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
/**
|
||||
* @author Towdium
|
||||
*/
|
||||
public class Recipe {
|
||||
ItemStack[] output;
|
||||
ItemStack[] input;
|
||||
|
||||
public Recipe(ItemStack[] output, ItemStack[] input) {
|
||||
if(output.length != 4 || input.length != 12){
|
||||
throw new IllegalArgumentException("Incorrect array size");
|
||||
}
|
||||
this.output = new ItemStack[4];
|
||||
for (int i = 0; i < 4; i++) {
|
||||
ItemStack itemstack = output[i];
|
||||
if(itemstack != null){
|
||||
boolean flag = false;
|
||||
for (int j = 0; j < i; j++) {
|
||||
if (this.output[j] != null && ItemStackWrapper.isTypeEqual(this.output[j], itemstack)) {
|
||||
this.output[j].stackSize += itemstack.stackSize;
|
||||
flag = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!flag) {
|
||||
this.output[i] = itemstack.copy();
|
||||
}
|
||||
}
|
||||
}
|
||||
this.input = new ItemStack[12];
|
||||
for (ItemStack itemstack : input) {
|
||||
if(itemstack != null){
|
||||
for(int i=0; i<12; i++){
|
||||
if(ItemStackWrapper.isTypeEqual(this.input[i], itemstack)){
|
||||
this.input[i].stackSize += itemstack.stackSize;
|
||||
break;
|
||||
} else if (this.input[i] == null){
|
||||
this.input[i] = itemstack.copy();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public ItemStack getOutput(ItemStack itemStack){
|
||||
for(int i = 0; i<4; i++){
|
||||
if(ItemStackWrapper.isTypeEqual(output[i], itemStack)){
|
||||
return output[i];
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public int getOutputIndex(ItemStack itemStack){
|
||||
for(int i = 0; i<4; i++){
|
||||
if(ItemStackWrapper.isTypeEqual(output[i], itemStack)){
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
public int getOutputAmount(ItemStack itemStack){
|
||||
for(int i = 0; i<4; i++){
|
||||
if(ItemStackWrapper.isTypeEqual(output[i], itemStack)){
|
||||
return ItemStackWrapper.getUnifiedAmount(output[i]);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public int getInputAmount(ItemStack itemStack){
|
||||
for(int i = 0; i<12; i++){
|
||||
if(ItemStackWrapper.isTypeEqual(input[i], itemStack)){
|
||||
return ItemStackWrapper.getUnifiedAmount(input[i]);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public boolean getHasOutput(ItemStack itemStack){
|
||||
return getOutputIndex(itemStack) != -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if(obj instanceof Recipe){
|
||||
for(int i=0; i<4; i++){
|
||||
if(!ItemStackWrapper.isStackEqual(output[i], ((Recipe)obj).output[i])){
|
||||
return false;
|
||||
}
|
||||
}
|
||||
for(int i=0; i<12; i++){
|
||||
if(!ItemStackWrapper.isStackEqual(input[i], ((Recipe)obj).input[i])){
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isOutputEqual(Recipe recipe){
|
||||
for(int i=0; i<4; i++){
|
||||
if(!ItemStackWrapper.isStackEqual(output[i], recipe.output[i])){
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
package pers.towdium.tudicraft.event;
|
||||
|
||||
|
||||
import mezz.jei.gui.Focus;
|
||||
import mezz.jei.gui.ItemListOverlay;
|
||||
import mezz.jei.input.InputHandler;
|
||||
import net.minecraft.client.gui.inventory.GuiContainer;
|
||||
import net.minecraft.client.renderer.texture.TextureUtil;
|
||||
import net.minecraft.inventory.Slot;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.client.event.GuiScreenEvent;
|
||||
import net.minecraftforge.fml.common.eventhandler.EventPriority;
|
||||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||
import org.lwjgl.input.Mouse;
|
||||
import pers.towdium.tudicraft.Tudicraft;
|
||||
import pers.towdium.tudicraft.gui.calculator.ContainerCalculator;
|
||||
import pers.towdium.tudicraft.gui.calculator.GuiCalculator;
|
||||
import pers.towdium.tudicraft.gui.recipeEditor.ContainerRecipeEditor;
|
||||
import pers.towdium.tudicraft.gui.recipeEditor.GuiRecipeEditor;
|
||||
import pers.towdium.tudicraft.gui.recipeEditor.InventoryRecipeEditor;
|
||||
import pers.towdium.tudicraft.plugin.JEIPlugin;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* @author Towdium
|
||||
*/
|
||||
public class GuiEventHandler {
|
||||
long time = new Date().getTime();
|
||||
|
||||
@SubscribeEvent(priority = EventPriority.HIGH)
|
||||
public void onMouseClick(GuiScreenEvent.MouseInputEvent.Pre event){
|
||||
if(event.gui instanceof GuiRecipeEditor){
|
||||
if(new Date().getTime() - time < 500){
|
||||
event.setCanceled(true);
|
||||
return;
|
||||
}
|
||||
if (((GuiRecipeEditor) event.gui).getActiveSlot() != -1){
|
||||
GuiRecipeEditor guiContainer = (GuiRecipeEditor) event.gui;
|
||||
ItemStack itemStack = JEIPlugin.runtime.getItemListOverlay().getStackUnderMouse();
|
||||
Slot slot = ((GuiRecipeEditor) event.gui).inventorySlots.getSlot(((GuiRecipeEditor) event.gui).getActiveSlot());
|
||||
slot.inventory.setInventorySlotContents(slot.getSlotIndex(), itemStack);
|
||||
if(Mouse.isButtonDown(0)){
|
||||
time = new Date().getTime();
|
||||
if(guiContainer.getSlotUnderMouse() != null){
|
||||
guiContainer.setActiveSlot(guiContainer.getSlotUnderMouse().getSlotIndex());
|
||||
((ContainerRecipeEditor)((GuiRecipeEditor) event.gui).inventorySlots).getPlayer().playSound("random.click", 1f, 1f );
|
||||
event.setCanceled(true);
|
||||
return;
|
||||
}
|
||||
int y = guiContainer.height - Mouse.getEventY() * guiContainer.height / guiContainer.mc.displayHeight - 1;
|
||||
int x = Mouse.getEventX() * guiContainer.width / guiContainer.mc.displayWidth;
|
||||
boolean over = ((ItemListOverlay)JEIPlugin.runtime.getItemListOverlay()).isMouseOver(x, y);
|
||||
if(!over || (y>25 && y<guiContainer.height-15)){
|
||||
((GuiRecipeEditor) event.gui).setActiveSlot(-1);
|
||||
((ContainerRecipeEditor)((GuiRecipeEditor) event.gui).inventorySlots).getPlayer().playSound("random.click", 1f, 1f );
|
||||
event.setCanceled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}else if(event.gui instanceof GuiCalculator){
|
||||
if (((GuiCalculator) event.gui).getActiveSlot() == 0){
|
||||
Slot slot = ((GuiCalculator) event.gui).inventorySlots.getSlot(((GuiCalculator) event.gui).getActiveSlot());
|
||||
ItemStack itemStack = JEIPlugin.runtime.getItemListOverlay().getStackUnderMouse();
|
||||
if (itemStack != null){
|
||||
slot.inventory.setInventorySlotContents(slot.getSlotIndex(), itemStack);
|
||||
}
|
||||
if (Mouse.isButtonDown(0)){
|
||||
((GuiCalculator) event.gui).setActiveSlot(-1);
|
||||
((ContainerCalculator)((GuiCalculator) event.gui).inventorySlots).getPlayer().playSound("random.click", 1f, 1f );
|
||||
event.setCanceled(true);
|
||||
}
|
||||
} else if(((GuiCalculator) event.gui).getActiveSlot() != -1) {
|
||||
if (Mouse.isButtonDown(0)){
|
||||
((GuiCalculator) event.gui).setActiveSlot(-1);
|
||||
((ContainerCalculator)((GuiCalculator) event.gui).inventorySlots).getPlayer().playSound("random.click", 1f, 1f );
|
||||
event.setCanceled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
package pers.towdium.tudicraft.gui;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.fml.common.network.IGuiHandler;
|
||||
import pers.towdium.tudicraft.Tudicraft;
|
||||
import pers.towdium.tudicraft.gui.calculator.ContainerCalculator;
|
||||
import pers.towdium.tudicraft.gui.calculator.GuiCalculator;
|
||||
import pers.towdium.tudicraft.gui.itemPicker.ContainerItemPicker;
|
||||
import pers.towdium.tudicraft.gui.itemPicker.GuiItemPicker;
|
||||
import pers.towdium.tudicraft.gui.recipeEditor.ContainerRecipeEditor;
|
||||
import pers.towdium.tudicraft.gui.recipeEditor.GuiRecipeEditor;
|
||||
|
||||
/**
|
||||
* @author Towdium
|
||||
*/
|
||||
public class GuiHandler implements IGuiHandler {
|
||||
public static final class GuiId{
|
||||
public static final int CALCULATOR = 0;
|
||||
public static final int ITEM_PICKER = 1;
|
||||
public static final int RECIPE_EDITOR = 2;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {
|
||||
switch (ID) {
|
||||
case GuiId.CALCULATOR: return new GuiCalculator(new ContainerCalculator(player, player.getHeldItem()));
|
||||
case GuiId.ITEM_PICKER: return new GuiItemPicker(new ContainerItemPicker());
|
||||
case GuiId.RECIPE_EDITOR: return new GuiRecipeEditor(new ContainerRecipeEditor(player));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,378 @@
|
||||
package pers.towdium.tudicraft.gui;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
import net.minecraft.client.gui.inventory.GuiContainer;
|
||||
import net.minecraft.inventory.Container;
|
||||
|
||||
/**
|
||||
* CODE IS DONE BY Zyin055
|
||||
* A GuiScreen replacement that supports putting tooltips onto GuiButtons.
|
||||
* SEE HERE: www.minecraftforum.net/forums/mapping-and-modding/minecraft-mods/modification-development/1437428-guide-1-7-2-how-to-make-button-tooltips
|
||||
*/
|
||||
public abstract class GuiTooltipScreen extends GuiContainer
|
||||
{
|
||||
/** Show a white "?" in the top right part of any button with a tooltip assigned to it */
|
||||
public static boolean ShowTooltipButtonEffect = true;
|
||||
|
||||
/** Show an aqua "?" in the top right part of any button with a tooltip assigned to it when mouseovered */
|
||||
public static boolean ShowTooltipButtonMouseoverEffect = true;
|
||||
|
||||
/** Putting this string into a tooltip will cause a line break */
|
||||
public String tooltipNewlineDelimeter = "_p";
|
||||
|
||||
/** The amount of time in milliseconds until a tooltip is rendered */
|
||||
public long tooltipDelay = 900;
|
||||
|
||||
/** The maximum width in pixels a tooltip can occupy before word wrapping occurs */
|
||||
public int tooltipMaxWidth = 150;
|
||||
|
||||
protected int tooltipXOffset = 0;
|
||||
protected int tooltipYOffset = 10;
|
||||
|
||||
private final static int LINE_HEIGHT = 11;
|
||||
|
||||
private long mouseoverTime = 0;
|
||||
private long prevSystemTime = -1;
|
||||
|
||||
public GuiTooltipScreen(Container inventorySlotsIn) {
|
||||
super(inventorySlotsIn);
|
||||
}
|
||||
|
||||
public void drawScreen(int mouseX, int mouseY, float f)
|
||||
{
|
||||
super.drawScreen(mouseX, mouseY, f);
|
||||
|
||||
DrawTooltipScreen(mouseX, mouseY);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method must be overriden. Gets a tooltip String for a specific button.
|
||||
* Recommended to use a switch/case statement for buttonId for easy implementation.
|
||||
* @param buttonId The ID of the button this tooltip corresponds to
|
||||
* @return The tooltip string for the specified buttonId. null if no tooltip exists for this button.
|
||||
*/
|
||||
protected abstract String GetButtonTooltip(int buttonId);
|
||||
|
||||
/**
|
||||
* Renders any special effects applied to tooltip buttons, and renders any tooltips for GuiButtons
|
||||
* that are being mouseovered.
|
||||
* @param mouseX
|
||||
* @param mouseY
|
||||
*/
|
||||
protected void DrawTooltipScreen(int mouseX, int mouseY)
|
||||
{
|
||||
if(ShowTooltipButtonEffect)
|
||||
RenderTooltipButtonEffect();
|
||||
|
||||
int mousedOverButtonId = -1;
|
||||
|
||||
//find out which button is being mouseovered
|
||||
for(int i = 0; i < buttonList.size(); i++)
|
||||
{
|
||||
GuiButton button = (GuiButton)buttonList.get(i);
|
||||
|
||||
if(IsButtonMouseovered(mouseX, mouseY, button))
|
||||
{
|
||||
mousedOverButtonId = button.id;
|
||||
|
||||
if(ShowTooltipButtonMouseoverEffect && GetButtonTooltip(mousedOverButtonId) != null)
|
||||
RenderTooltipButtonMouseoverEffect(button);
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//calculate how long this button has been mouseovered for
|
||||
if(mousedOverButtonId > -1)
|
||||
{
|
||||
long systemTime = System.currentTimeMillis();
|
||||
|
||||
if(prevSystemTime > 0)
|
||||
mouseoverTime += systemTime - prevSystemTime;
|
||||
|
||||
prevSystemTime = systemTime;
|
||||
}
|
||||
else
|
||||
{
|
||||
mouseoverTime = 0;
|
||||
}
|
||||
|
||||
//render the button's tooltip
|
||||
if(mouseoverTime > tooltipDelay)
|
||||
{
|
||||
String tooltip = GetButtonTooltip(mousedOverButtonId);
|
||||
if(tooltip != null)
|
||||
{
|
||||
RenderTooltip(mouseX, mouseY, tooltip);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines if a GuiButton is being mouseovered.
|
||||
* @param mouseX
|
||||
* @param mouseY
|
||||
* @param button
|
||||
* @return true if this button is mouseovered
|
||||
*/
|
||||
protected boolean IsButtonMouseovered(int mouseX, int mouseY, GuiButton button)
|
||||
{
|
||||
return mouseX >= button.xPosition + button.getButtonWidth() - 10 && mouseX <= button.xPosition + button.getButtonWidth() &&
|
||||
mouseY >= button.yPosition && mouseY <= button.yPosition + 10;
|
||||
}
|
||||
|
||||
/**
|
||||
* Render anything special onto all buttons that have tooltips assigned to them.
|
||||
*/
|
||||
protected void RenderTooltipButtonEffect()
|
||||
{
|
||||
for(int i = 0; i < buttonList.size(); i++)
|
||||
{
|
||||
GuiButton button = buttonList.get(i);
|
||||
|
||||
if(GetButtonTooltip(button.id) != null)
|
||||
{
|
||||
boolean flag = mc.fontRendererObj.getUnicodeFlag();
|
||||
mc.fontRendererObj.setUnicodeFlag(true);
|
||||
mc.fontRendererObj.drawStringWithShadow("?", button.xPosition+button.getButtonWidth()-5, button.yPosition, 0x99FFFFFF);
|
||||
mc.fontRendererObj.setUnicodeFlag(flag);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Render anything special onto buttons that have tooltips assigned to them when they are mousevered.
|
||||
* @param button
|
||||
*/
|
||||
protected void RenderTooltipButtonMouseoverEffect(GuiButton button)
|
||||
{
|
||||
boolean flag = mc.fontRendererObj.getUnicodeFlag();
|
||||
mc.fontRendererObj.setUnicodeFlag(true);
|
||||
mc.fontRendererObj.drawStringWithShadow(FontCodes.AQUA + "?", button.xPosition+button.getButtonWidth()-5, button.yPosition, 0xFFFFFF);
|
||||
mc.fontRendererObj.setUnicodeFlag(flag);
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders a tooltip at (x,y).
|
||||
* @param x
|
||||
* @param y
|
||||
* @param tooltip
|
||||
*/
|
||||
protected void RenderTooltip(int x, int y, String tooltip)
|
||||
{
|
||||
String[] tooltipArray = ParseTooltipArrayFromString(tooltip);
|
||||
|
||||
int tooltipWidth = GetTooltipWidth(tooltipArray);
|
||||
int tooltipHeight = GetTooltipHeight(tooltipArray);
|
||||
|
||||
int tooltipX = x + tooltipXOffset;
|
||||
int tooltipY = y + tooltipYOffset;
|
||||
|
||||
if(tooltipX > width - tooltipWidth - 7)
|
||||
tooltipX = width - tooltipWidth - 7;
|
||||
if(tooltipY > height - tooltipHeight - 8)
|
||||
tooltipY = height - tooltipHeight - 8;
|
||||
|
||||
//render the background inside box
|
||||
int innerAlpha = -0xFEFFFF0; //very very dark purple
|
||||
drawGradientRect(tooltipX, tooltipY - 1, tooltipX + tooltipWidth + 6, tooltipY, innerAlpha, innerAlpha);
|
||||
drawGradientRect(tooltipX, tooltipY + tooltipHeight + 6, tooltipX + tooltipWidth + 6, tooltipY + tooltipHeight + 7, innerAlpha, innerAlpha);
|
||||
drawGradientRect(tooltipX, tooltipY, tooltipX + tooltipWidth + 6, tooltipY + tooltipHeight + 6, innerAlpha, innerAlpha);
|
||||
drawGradientRect(tooltipX - 1, tooltipY, tooltipX, tooltipY + tooltipHeight + 6, innerAlpha, innerAlpha);
|
||||
drawGradientRect(tooltipX + tooltipWidth + 6, tooltipY, tooltipX + tooltipWidth + 7, tooltipY + tooltipHeight + 6, innerAlpha, innerAlpha);
|
||||
|
||||
//render the background outside box
|
||||
int outerAlpha1 = 0x505000FF;
|
||||
int outerAlpha2 = (outerAlpha1 & 0xFEFEFE) >> 1 | outerAlpha1 & -0x1000000;
|
||||
drawGradientRect(tooltipX, tooltipY + 1, tooltipX + 1, tooltipY + tooltipHeight + 6 - 1, outerAlpha1, outerAlpha2);
|
||||
drawGradientRect(tooltipX + tooltipWidth + 5, tooltipY + 1, tooltipX + tooltipWidth + 7, tooltipY + tooltipHeight + 6 - 1, outerAlpha1, outerAlpha2);
|
||||
drawGradientRect(tooltipX, tooltipY, tooltipX + tooltipWidth + 3, tooltipY + 1, outerAlpha1, outerAlpha1);
|
||||
drawGradientRect(tooltipX, tooltipY + tooltipHeight + 5, tooltipX + tooltipWidth + 7, tooltipY + tooltipHeight + 6, outerAlpha2, outerAlpha2);
|
||||
|
||||
//render the foreground text
|
||||
int lineCount = 0;
|
||||
for (String s : tooltipArray)
|
||||
{
|
||||
mc.fontRendererObj.drawStringWithShadow(s, tooltipX + 2, tooltipY + 2 + lineCount * LINE_HEIGHT, 0xFFFFFF);
|
||||
lineCount++;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a String representation of a tooltip into a String[], and also decodes any font codes used.
|
||||
* @param s Ex: "Hello,_nI am your _ltooltip_r and you love me."
|
||||
* @return An array of Strings such that each String width does not exceed tooltipMaxWidth
|
||||
*/
|
||||
protected String[] ParseTooltipArrayFromString(String s)
|
||||
{
|
||||
s = DecodeStringCodes(s);
|
||||
String[] tooltipSections = s.split(tooltipNewlineDelimeter);
|
||||
ArrayList<String> tooltipArrayList = new ArrayList<String>();
|
||||
|
||||
for(String section : tooltipSections)
|
||||
{
|
||||
String tooltip = "";
|
||||
String[] tooltipWords = section.split(" ");
|
||||
|
||||
for(int i = 0; i < tooltipWords.length; i++)
|
||||
{
|
||||
int lineWidthWithNextWord = mc.fontRendererObj.getStringWidth(tooltip + tooltipWords[i]);
|
||||
if(lineWidthWithNextWord > tooltipMaxWidth)
|
||||
{
|
||||
tooltipArrayList.add(tooltip.trim());
|
||||
tooltip = tooltipWords[i] + " ";
|
||||
}
|
||||
else
|
||||
{
|
||||
tooltip += tooltipWords[i] + " ";
|
||||
}
|
||||
}
|
||||
|
||||
tooltipArrayList.add(tooltip.trim());
|
||||
}
|
||||
|
||||
String[] tooltipArray = new String[tooltipArrayList.size()];
|
||||
tooltipArrayList.toArray(tooltipArray);
|
||||
|
||||
return tooltipArray;
|
||||
}
|
||||
|
||||
/**
|
||||
* Decodes any font codes into something useable by the fontRendererObj.
|
||||
* @param s E.x.: "Hello,_nI am your _ltooltip_r and you love me."
|
||||
* @return E.x. output (html not included): <br>"Hello,<br>I am your <b>tooltip</b> and you love me."
|
||||
*/
|
||||
private String DecodeStringCodes(String s)
|
||||
{
|
||||
return s.replace("_0", FontCodes.BLACK)
|
||||
.replace("_1", FontCodes.DARK_BLUE)
|
||||
.replace("_2", FontCodes.DARK_GREEN)
|
||||
.replace("_3", FontCodes.DARK_AQUA)
|
||||
.replace("_4", FontCodes.DARK_RED)
|
||||
.replace("_5", FontCodes.DARK_PURPLE)
|
||||
.replace("_6", FontCodes.GOLD)
|
||||
.replace("_7", FontCodes.GRAY)
|
||||
.replace("_8", FontCodes.DARK_GREY)
|
||||
.replace("_9", FontCodes.BLUE)
|
||||
.replace("_a", FontCodes.GREEN)
|
||||
.replace("_b", FontCodes.AQUA)
|
||||
.replace("_c", FontCodes.RED)
|
||||
.replace("_d", FontCodes.LIGHT_PURPLE)
|
||||
.replace("_e", FontCodes.YELLOW)
|
||||
.replace("_f", FontCodes.WHITE)
|
||||
.replace("_k", FontCodes.OBFUSCATED)
|
||||
.replace("_l", FontCodes.BOLD)
|
||||
.replace("_m", FontCodes.STRIKETHROUGH)
|
||||
.replace("_n", FontCodes.UNDERLINE)
|
||||
.replace("_o", FontCodes.ITALICS)
|
||||
.replace("_r", FontCodes.RESET);
|
||||
}
|
||||
|
||||
/***
|
||||
* Gets the width of the tooltip in pixels.
|
||||
* @param tooltipArray
|
||||
* @return
|
||||
*/
|
||||
private int GetTooltipWidth(String[] tooltipArray)
|
||||
{
|
||||
int longestWidth = 0;
|
||||
for(String s : tooltipArray)
|
||||
{
|
||||
int width = mc.fontRendererObj.getStringWidth(s);
|
||||
if(width > longestWidth)
|
||||
longestWidth = width;
|
||||
}
|
||||
return longestWidth;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the height of the tooltip in pixels.
|
||||
* @param tooltipArray
|
||||
* @return
|
||||
*/
|
||||
private int GetTooltipHeight(String[] tooltipArray)
|
||||
{
|
||||
int tooltipHeight = mc.fontRendererObj.FONT_HEIGHT - 2;
|
||||
if (tooltipArray.length > 1)
|
||||
{
|
||||
tooltipHeight += (tooltipArray.length - 1) * LINE_HEIGHT;
|
||||
}
|
||||
return tooltipHeight;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a protected/private field from a class using reflection.
|
||||
* @param <T> The return type of the field you are getting
|
||||
* @param <E> The class the field is in
|
||||
* @param classToAccess The ".class" of the class the field is in
|
||||
* @param instance The instance of the class
|
||||
* @param fieldNames comma seperated names the field may have (i.e. obfuscated, non obfuscated).
|
||||
* Obfustated field names can be found in fml/conf/fields.csv
|
||||
* @return
|
||||
*/
|
||||
public static <T, E> T GetFieldByReflection(Class<? super E> classToAccess, E instance, String... fieldNames)
|
||||
{
|
||||
Field field = null;
|
||||
for(String fieldName : fieldNames)
|
||||
{
|
||||
try
|
||||
{
|
||||
field = classToAccess.getDeclaredField(fieldName);
|
||||
}
|
||||
catch(NoSuchFieldException e){}
|
||||
|
||||
if(field != null)
|
||||
break;
|
||||
}
|
||||
|
||||
if(field != null)
|
||||
{
|
||||
field.setAccessible(true);
|
||||
T fieldT = null;
|
||||
try
|
||||
{
|
||||
fieldT = (T) field.get(instance);
|
||||
}
|
||||
catch (IllegalArgumentException e){}
|
||||
catch (IllegalAccessException e){}
|
||||
|
||||
return fieldT;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public class FontCodes
|
||||
{
|
||||
//color codes for rendered strings
|
||||
public static final String BLACK = "\2470";
|
||||
public static final String DARK_BLUE = "\2471";
|
||||
public static final String DARK_GREEN = "\2472";
|
||||
public static final String DARK_AQUA = "\2473";
|
||||
public static final String DARK_RED = "\2474";
|
||||
public static final String DARK_PURPLE = "\2475";
|
||||
public static final String GOLD = "\2476";
|
||||
public static final String GRAY = "\2477";
|
||||
public static final String DARK_GREY = "\2478";
|
||||
public static final String BLUE = "\2479";
|
||||
public static final String GREEN = "\247a";
|
||||
public static final String AQUA = "\247b";
|
||||
public static final String RED = "\247c";
|
||||
public static final String LIGHT_PURPLE = "\247d";
|
||||
public static final String YELLOW = "\247e";
|
||||
public static final String WHITE = "\247f";
|
||||
|
||||
//font styles
|
||||
public static final String OBFUSCATED = "\247k";
|
||||
public static final String BOLD = "\247l";
|
||||
public static final String STRIKETHROUGH = "\247m";
|
||||
public static final String UNDERLINE = "\247n";
|
||||
public static final String ITALICS = "\247o";
|
||||
|
||||
public static final String RESET = "\247r";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
package pers.towdium.tudicraft.gui.calculator;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.Container;
|
||||
import net.minecraft.inventory.Slot;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
|
||||
/**
|
||||
* @author Towdium
|
||||
*/
|
||||
public class ContainerCalculator extends Container {
|
||||
EntityPlayer player;
|
||||
InventoryCalculator inventoryCalculator;
|
||||
|
||||
public ContainerCalculator(EntityPlayer player, ItemStack itemCalculator){
|
||||
this.player = player;
|
||||
this.inventoryCalculator = new InventoryCalculator(itemCalculator);
|
||||
addSlotToContainer(new Slot(inventoryCalculator, 0,9,9));
|
||||
int i, left, top;
|
||||
i = 1; left = 8; top = 64;
|
||||
for(int a = 0; a < 4; a++){
|
||||
for(int b =0; b < 9; b++){
|
||||
addSlotToContainer(new Slot(inventoryCalculator,i+9*a+b,left+b*18,top+a*18));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canInteractWith(EntityPlayer playerIn) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack transferStackInSlot(EntityPlayer playerIn, int index) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack slotClick(int slotId, int clickedButton, int mode, EntityPlayer playerIn) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public EntityPlayer getPlayer() {
|
||||
return player;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,186 @@
|
||||
package pers.towdium.tudicraft.gui.calculator;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.FontRenderer;
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.client.gui.GuiTextField;
|
||||
import net.minecraft.client.renderer.GlStateManager;
|
||||
import net.minecraft.client.renderer.entity.RenderItem;
|
||||
import net.minecraft.client.renderer.texture.TextureMap;
|
||||
import net.minecraft.client.resources.model.IBakedModel;
|
||||
import net.minecraft.client.resources.model.ModelManager;
|
||||
import net.minecraft.inventory.Slot;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.StatCollector;
|
||||
import pers.towdium.tudicraft.Tudicraft;
|
||||
import pers.towdium.tudicraft.core.Calculator;
|
||||
import pers.towdium.tudicraft.core.ItemStackWrapper;
|
||||
import pers.towdium.tudicraft.gui.GuiTooltipScreen;
|
||||
import pers.towdium.tudicraft.gui.recipeEditor.ContainerRecipeEditor;
|
||||
import pers.towdium.tudicraft.gui.recipeEditor.GuiRecipeEditor;
|
||||
import pers.towdium.tudicraft.network.packages.PackageCalculatorUpdate;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Towdium
|
||||
*/
|
||||
public class GuiCalculator extends GuiTooltipScreen{
|
||||
GuiTextField textFieldAmount;
|
||||
GuiButton edit;
|
||||
Calculator.CostRecord costRecord;
|
||||
int activeSlot = -1;
|
||||
int page = 1;
|
||||
EnumMode mode = EnumMode.input;
|
||||
|
||||
|
||||
public enum EnumMode {input, output, catalyst}
|
||||
|
||||
public GuiCalculator(ContainerCalculator containerCalculator){
|
||||
super(containerCalculator);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initGui() {
|
||||
super.initGui();
|
||||
edit = new GuiButton(3, guiLeft+125, guiTop+31, 44, 20, StatCollector.translateToLocal("gui.calculator.edit"));
|
||||
edit.enabled = false;
|
||||
buttonList.add(new GuiButton(1, guiLeft+7, guiTop+31, 79, 20, StatCollector.translateToLocal("gui.calculator.calculate")));
|
||||
buttonList.add(new GuiButton(2, guiLeft+125, guiTop+7, 44, 20, StatCollector.translateToLocal("gui.calculator.add")));
|
||||
buttonList.add(edit);
|
||||
buttonList.add(new GuiButton(4, guiLeft+7, guiTop+139, 20, 20, "<"));
|
||||
buttonList.add(new GuiButton(5, guiLeft+149, guiTop+139, 20, 20, ">"));
|
||||
textFieldAmount = new GuiTextField(0, fontRendererObj, guiLeft+39, guiTop+8, 44, 18);
|
||||
Slot dest = inventorySlots.getSlot(0);
|
||||
ItemStack itemStack = ((ContainerCalculator)inventorySlots).getPlayer().getHeldItem();
|
||||
dest.inventory.setInventorySlotContents(dest.getSlotIndex(), ItemStackWrapper.NBT.getItem(itemStack, "dest"));
|
||||
textFieldAmount.setText(ItemStackWrapper.NBT.getString(itemStack, "text"));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void drawGuiContainerBackgroundLayer(float partialTicks, int mouseX, int mouseY) {
|
||||
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
|
||||
this.mc.getTextureManager().bindTexture(new ResourceLocation(Tudicraft.Reference.MODID,"textures/gui/guiCalculator.png"));
|
||||
this.drawTexturedModalRect(this.guiLeft, this.guiTop, 0, 0, this.xSize, this.ySize);
|
||||
if(activeSlot == 0){
|
||||
Slot slot = inventorySlots.getSlot(activeSlot);
|
||||
this.drawTexturedModalRect(this.guiLeft+slot.xDisplayPosition-2, this.guiTop+slot.yDisplayPosition-2, 176, 0, 20, 20);
|
||||
}else if(activeSlot > 0){
|
||||
Slot slot = inventorySlots.getSlot(activeSlot);
|
||||
this.drawTexturedModalRect(this.guiLeft+slot.xDisplayPosition-1, this.guiTop+slot.yDisplayPosition-1, 196, 0, 18, 18);
|
||||
}
|
||||
textFieldAmount.drawTextBox();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void drawGuiContainerForegroundLayer(int p_146979_1_, int p_146979_2_) {
|
||||
this.fontRendererObj.drawString("x", 30, 13, 4210752);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String GetButtonTooltip(int buttonId) {
|
||||
switch (buttonId){
|
||||
case 2: return StatCollector.translateToLocal("gui.calculator.addTooltip");
|
||||
case 3: return StatCollector.translateToLocal("gui.calculator.editTooltip");
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void actionPerformed(GuiButton button) throws IOException {
|
||||
switch (button.id){
|
||||
case 1:
|
||||
if(inventorySlots.getSlot(0).getStack() != null){
|
||||
Calculator calculator = new Calculator(inventorySlots.getSlot(0).getStack(), Integer.valueOf(textFieldAmount.getText()));
|
||||
Calculator.CostRecord record = calculator.getCost();
|
||||
record.unify();
|
||||
costRecord = record;
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
mc.displayGuiScreen(new GuiRecipeEditor(new ContainerRecipeEditor(((ContainerCalculator)inventorySlots).getPlayer()), this));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void mouseClicked(int mouseX, int mouseY, int mouseButton) throws IOException {
|
||||
textFieldAmount.mouseClicked(mouseX, mouseY, mouseButton);
|
||||
super.mouseClicked(mouseX, mouseY, mouseButton);
|
||||
Slot slot = getSlotUnderMouse();
|
||||
if(slot != null && mouseButton == 0){
|
||||
activeSlot = slot.getSlotIndex();
|
||||
((ContainerCalculator)inventorySlots).getPlayer().playSound("random.click", 1f, 1f );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawScreen(int mouseX, int mouseY, float f) {
|
||||
super.drawScreen(mouseX, mouseY, f);
|
||||
//Method
|
||||
}
|
||||
|
||||
public int getActiveSlot() {
|
||||
return activeSlot;
|
||||
}
|
||||
|
||||
public void setActiveSlot(int activeSlot) {
|
||||
this.activeSlot = activeSlot;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void keyTyped(char typedChar, int keyCode) throws IOException {
|
||||
if (!this.textFieldAmount.textboxKeyTyped(typedChar, keyCode)){
|
||||
if(keyCode == 1){
|
||||
ItemStack itemStack = ((ContainerCalculator)inventorySlots).getPlayer().getHeldItem();
|
||||
ItemStackWrapper.NBT.setItem(itemStack, "dest", inventorySlots.getSlot(0).inventory.getStackInSlot(inventorySlots.getSlot(0).getSlotIndex()));
|
||||
ItemStackWrapper.NBT.setString(itemStack, "text", textFieldAmount.getText());
|
||||
Tudicraft.networkWrapper.sendToServer(new PackageCalculatorUpdate(((ContainerCalculator)inventorySlots).getPlayer().getHeldItem()));
|
||||
((ContainerCalculator)inventorySlots).getPlayer().closeScreen();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void updateScreen(){
|
||||
|
||||
}
|
||||
|
||||
public void updateSlots(){
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setWorldAndResolution(Minecraft mc, int width, int height) {
|
||||
super.setWorldAndResolution(mc, width, height);
|
||||
ModelManager modelManager = null;
|
||||
Field[] fields = mc.getClass().getDeclaredFields();
|
||||
for(Field field : fields){
|
||||
if(ModelManager.class.equals(field.getType())){
|
||||
field.setAccessible(true);
|
||||
try {
|
||||
modelManager = (ModelManager) field.get(mc);
|
||||
break;
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
if(modelManager != null){
|
||||
itemRender = new RenderItem(mc.renderEngine, modelManager){
|
||||
@Override
|
||||
public void renderItemOverlayIntoGUI(FontRenderer fr, ItemStack stack, int xPosition, int yPosition, String text) {
|
||||
boolean b = fr.getUnicodeFlag();
|
||||
fr.setUnicodeFlag(true);
|
||||
super.renderItemOverlayIntoGUI(fr, stack, xPosition, yPosition, "≈1.23k");
|
||||
fr.setUnicodeFlag(b);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package pers.towdium.tudicraft.gui.calculator;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.inventory.InventoryBasic;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.IChatComponent;
|
||||
|
||||
/**
|
||||
* @author Towdium
|
||||
*/
|
||||
public class InventoryCalculator extends InventoryBasic{
|
||||
|
||||
public InventoryCalculator(ItemStack itemStack) {
|
||||
super("Calculator", false, 37);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
package pers.towdium.tudicraft.gui.itemPicker;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.Container;
|
||||
import net.minecraft.inventory.Slot;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import pers.towdium.tudicraft.Tudicraft;
|
||||
|
||||
|
||||
/**
|
||||
* @author Towdium
|
||||
*/
|
||||
public class ContainerItemPicker extends Container {
|
||||
|
||||
InventoryItemPicker inventoryItemPicker;
|
||||
|
||||
public ContainerItemPicker(){
|
||||
inventoryItemPicker = new InventoryItemPicker();
|
||||
addSlotToContainer(new Slot(inventoryItemPicker ,0,0,0));
|
||||
addSlotToContainer(new Slot(inventoryItemPicker,1,18,0));
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canInteractWith(EntityPlayer playerIn) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack transferStackInSlot(EntityPlayer playerIn, int index) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack slotClick(int slotId, int clickedButton, int mode, EntityPlayer playerIn) {
|
||||
Tudicraft.log.info("Activated");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
package pers.towdium.tudicraft.gui.itemPicker;
|
||||
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.client.gui.GuiTextField;
|
||||
import net.minecraft.client.gui.inventory.GuiContainer;
|
||||
import net.minecraft.client.renderer.GlStateManager;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.StatCollector;
|
||||
import pers.towdium.tudicraft.Tudicraft;
|
||||
import pers.towdium.tudicraft.plugin.JEIPlugin;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* @author Towdium
|
||||
*/
|
||||
public class GuiItemPicker extends GuiContainer{
|
||||
ContainerItemPicker containerItemPicker;
|
||||
GuiTextField searchTextField;
|
||||
|
||||
public GuiItemPicker(ContainerItemPicker containerItemPicker){
|
||||
super(containerItemPicker);
|
||||
this.containerItemPicker = containerItemPicker;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initGui() {
|
||||
super.initGui();
|
||||
buttonList.add(new GuiButton(0, guiLeft+31, guiTop+7, 50, 20, StatCollector.translateToLocal("gui.itemPicker.confirm")));
|
||||
buttonList.add(new GuiButton(0, guiLeft+7, guiTop+137, 20, 20, "<"));
|
||||
buttonList.add(new GuiButton(0, guiLeft+149, guiTop+137, 20, 20, ">"));
|
||||
searchTextField = new GuiTextField(4, fontRendererObj, guiLeft+90, guiTop+7, 79, 20){
|
||||
@Override
|
||||
public boolean textboxKeyTyped(char p_146201_1_, int p_146201_2_) {
|
||||
boolean b = super.textboxKeyTyped(p_146201_1_, p_146201_2_);
|
||||
Tudicraft.log.info("执行了!"+JEIPlugin.runtime.getItemListOverlay().getFilterText());
|
||||
JEIPlugin.runtime.getItemListOverlay().setFilterText("apple");
|
||||
return b;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void drawGuiContainerBackgroundLayer(float partialTicks, int mouseX, int mouseY) {
|
||||
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
|
||||
this.mc.getTextureManager().bindTexture(new ResourceLocation(Tudicraft.Reference.MODID,"textures/gui/guiItemPicker.png"));
|
||||
this.drawTexturedModalRect(this.guiLeft, this.guiTop, 0, 0, this.xSize, this.ySize);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void drawGuiContainerForegroundLayer(int p_146979_1_, int p_146979_2_) {
|
||||
|
||||
this.fontRendererObj.drawString(StatCollector.translateToLocal("container.itemPicker"), 8, 6, 4210752);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawScreen(int mouseX, int mouseY, float partialTicks) {
|
||||
super.drawScreen(mouseX, mouseY, partialTicks);
|
||||
searchTextField.drawTextBox();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onGuiClosed() {
|
||||
super.onGuiClosed();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void actionPerformed(GuiButton button) throws IOException {
|
||||
super.actionPerformed(button);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void mouseClicked(int mouseX, int mouseY, int mouseButton) throws IOException {
|
||||
searchTextField.mouseClicked(mouseX, mouseY, mouseButton);
|
||||
super.mouseClicked(mouseX, mouseY, mouseButton);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void keyTyped(char typedChar, int keyCode) throws IOException {
|
||||
if (!this.searchTextField.textboxKeyTyped(typedChar, keyCode)){
|
||||
super.keyTyped(typedChar, keyCode);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package pers.towdium.tudicraft.gui.itemPicker;
|
||||
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.inventory.InventoryBasic;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
/**
|
||||
* @author Towdium
|
||||
*/
|
||||
public class InventoryItemPicker extends InventoryBasic {
|
||||
public InventoryItemPicker() {
|
||||
super("Item picker", false, 55);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,98 @@
|
||||
package pers.towdium.tudicraft.gui.recipeEditor;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.Container;
|
||||
import net.minecraft.inventory.Slot;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import pers.towdium.tudicraft.core.Recipe;
|
||||
|
||||
|
||||
/**
|
||||
* @author Towdium
|
||||
*/
|
||||
public class ContainerRecipeEditor extends Container {
|
||||
|
||||
InventoryRecipeEditor inventoryRecipeEditor;
|
||||
EntityPlayer player;
|
||||
|
||||
public ContainerRecipeEditor(EntityPlayer player){
|
||||
inventoryRecipeEditor = new InventoryRecipeEditor();
|
||||
int i, left, top;
|
||||
i = 0; left = 9; top = 9;
|
||||
for(int a = 0; a < 2; a++){
|
||||
for(int b =0; b < 2; b++){
|
||||
addSlotToContainer(new Slot(inventoryRecipeEditor,i+2*a+b,left+b*59,top+a*24));
|
||||
}
|
||||
}
|
||||
i = 4; left = 9; top = 69;
|
||||
for(int a = 0; a < 4; a++){
|
||||
for(int b =0; b < 3; b++){
|
||||
addSlotToContainer(new Slot(inventoryRecipeEditor,i+3*a+b,left+b*59,top+a*24));
|
||||
}
|
||||
}
|
||||
this.player = player;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack slotClick(int slotId, int clickedButton, int mode, EntityPlayer playerIn) {
|
||||
if(slotId<0 || slotId>=16){
|
||||
return null;
|
||||
}
|
||||
Slot slot = getSlot(slotId);
|
||||
if(slot != null){
|
||||
ItemStack itemStack = slot.inventory.getStackInSlot(slot.getSlotIndex());
|
||||
if(itemStack != null){
|
||||
if(clickedButton == 0){
|
||||
ItemStack itemStackBuffer = itemStack.copy();
|
||||
itemStackBuffer.stackSize += 1;
|
||||
slot.inventory.setInventorySlotContents(slot.getSlotIndex(), itemStackBuffer);
|
||||
slot.onSlotChanged();
|
||||
}else if(clickedButton == 1){
|
||||
if(itemStack.stackSize == 1){
|
||||
slot.inventory.setInventorySlotContents(slot.getSlotIndex(),null);
|
||||
slot.onSlotChanged();
|
||||
}else {
|
||||
ItemStack itemStackBuffer = itemStack.copy();
|
||||
itemStackBuffer.stackSize -= 1;
|
||||
slot.inventory.setInventorySlotContents(slot.getSlotIndex(), itemStackBuffer);
|
||||
slot.onSlotChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canInteractWith(EntityPlayer playerIn) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack transferStackInSlot(EntityPlayer playerIn, int index) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public EntityPlayer getPlayer() {
|
||||
return player;
|
||||
}
|
||||
|
||||
public Recipe buildRecipe(){
|
||||
ItemStack[] output = new ItemStack[4];
|
||||
boolean flag1 = false, flag2 = false;
|
||||
for(int i=0; i<4; i++){
|
||||
output[i] = getSlot(i).getStack();
|
||||
if(output[i] != null){
|
||||
flag1 = true;
|
||||
}
|
||||
}
|
||||
ItemStack[] input = new ItemStack[12];
|
||||
for(int i=4; i<16; i++){
|
||||
input[i-4] = getSlot(i).getStack();
|
||||
if(input[i-4] != null){
|
||||
flag2 = true;
|
||||
}
|
||||
}
|
||||
return flag1 && flag2 ? new Recipe(output, input) : null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,116 @@
|
||||
package pers.towdium.tudicraft.gui.recipeEditor;
|
||||
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
import net.minecraft.client.gui.inventory.GuiContainer;
|
||||
import net.minecraft.client.renderer.GlStateManager;
|
||||
import net.minecraft.inventory.Slot;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.StatCollector;
|
||||
import pers.towdium.tudicraft.Tudicraft;
|
||||
import pers.towdium.tudicraft.core.Recipe;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.sql.Time;
|
||||
|
||||
/**
|
||||
* @author Towdium
|
||||
*/
|
||||
public class GuiRecipeEditor extends GuiContainer{
|
||||
GuiScreen parent;
|
||||
protected int activeSlot = -1;
|
||||
|
||||
public GuiRecipeEditor(ContainerRecipeEditor containerRecipeEditor, GuiScreen parent){
|
||||
super(containerRecipeEditor);
|
||||
this.parent = parent;
|
||||
}
|
||||
|
||||
public GuiRecipeEditor(ContainerRecipeEditor containerRecipeEditor){
|
||||
super(containerRecipeEditor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initGui() {
|
||||
super.initGui();
|
||||
int i, left, top;
|
||||
i = 0; left = 31 + guiLeft; top = 7 + guiTop;
|
||||
for(int a = 0; a < 2; a++){
|
||||
for(int b =0; b < 2; b++){
|
||||
buttonList.add(new GuiButton(i+2*a+b, left+b*59, top+a*24, 20, 20, "X"));
|
||||
}
|
||||
}
|
||||
i = 4; left = 31 + guiLeft; top = 67 + guiTop;
|
||||
for(int a = 0; a < 4; a++){
|
||||
for(int b =0; b < 3; b++){
|
||||
buttonList.add(new GuiButton(i+3*a+b, left+b*59, top+a*24, 20, 20, "X"));
|
||||
}
|
||||
}
|
||||
buttonList.add(new GuiButton(16, guiLeft+125, guiTop+7, 44, 20, StatCollector.translateToLocal("gui.recipeEditor.save")));
|
||||
buttonList.add(new GuiButton(17, guiLeft+125, guiTop+31, 44, 20, StatCollector.translateToLocal("gui.recipeEditor.clear")));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void drawGuiContainerBackgroundLayer(float partialTicks, int mouseX, int mouseY) {
|
||||
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
|
||||
this.mc.getTextureManager().bindTexture(new ResourceLocation(Tudicraft.Reference.MODID,"textures/gui/guiRecipeEditor.png"));
|
||||
this.drawTexturedModalRect(this.guiLeft, this.guiTop, 0, 0, this.xSize, this.ySize);
|
||||
if(activeSlot != -1){
|
||||
Slot slot = inventorySlots.getSlot(activeSlot);
|
||||
this.drawTexturedModalRect(this.guiLeft+slot.xDisplayPosition-2, this.guiTop+slot.yDisplayPosition-2, 176, 0, 20, 20);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void actionPerformed(GuiButton button) throws IOException {
|
||||
int buttonId = button.id;
|
||||
if(buttonId <= 15){
|
||||
Slot slot = inventorySlots.getSlot(buttonId);
|
||||
slot.inventory.setInventorySlotContents(slot.getSlotIndex(), null);
|
||||
}else if(buttonId == 16) {
|
||||
Tudicraft.proxy.getPlayerHandler().addRecipe(((ContainerRecipeEditor)inventorySlots).buildRecipe());
|
||||
mc.displayGuiScreen(parent);
|
||||
}else if(buttonId == 17) {
|
||||
for(Slot slot : inventorySlots.inventorySlots){
|
||||
slot.inventory.setInventorySlotContents(slot.getSlotIndex(), null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void mouseReleased(int mouseX, int mouseY, int state) {}
|
||||
|
||||
@Override
|
||||
protected void mouseClicked(int mouseX, int mouseY, int mouseButton) throws IOException {
|
||||
super.mouseClicked(mouseX, mouseY, mouseButton);
|
||||
Slot slot = getSlotUnderMouse();
|
||||
if(slot != null && mouseButton == 0 && slot.getStack() == null){
|
||||
activeSlot = slot.getSlotIndex();
|
||||
((ContainerRecipeEditor)inventorySlots).getPlayer().playSound("random.click", 1f, 1f );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void handleMouseClick(Slot slotIn, int slotId, int clickedButton, int clickType) {
|
||||
if (slotIn != null)
|
||||
{
|
||||
slotId = slotIn.slotNumber;
|
||||
}
|
||||
mc.thePlayer.openContainer.slotClick(slotId, clickedButton, clickType, mc.thePlayer);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void keyTyped(char typedChar, int keyCode) throws IOException {
|
||||
if (keyCode == 1) {
|
||||
mc.displayGuiScreen(parent);
|
||||
}
|
||||
}
|
||||
|
||||
public int getActiveSlot() {
|
||||
return activeSlot;
|
||||
}
|
||||
|
||||
public void setActiveSlot(int activeSlot) {
|
||||
this.activeSlot = activeSlot;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package pers.towdium.tudicraft.gui.recipeEditor;
|
||||
|
||||
import net.minecraft.inventory.InventoryBasic;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import pers.towdium.tudicraft.core.Recipe;
|
||||
|
||||
/**
|
||||
* @author Towdium
|
||||
*/
|
||||
public class InventoryRecipeEditor extends InventoryBasic {
|
||||
public InventoryRecipeEditor() {
|
||||
super("Recipe editor", false, 16);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package pers.towdium.tudicraft.item;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.world.World;
|
||||
import pers.towdium.tudicraft.Tudicraft;
|
||||
import pers.towdium.tudicraft.gui.GuiHandler;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Towdium
|
||||
*/
|
||||
public class ItemCalculator extends Item {
|
||||
|
||||
public ItemCalculator() {
|
||||
setMaxStackSize(1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack onItemRightClick(ItemStack itemStackIn, World worldIn, EntityPlayer playerIn) {
|
||||
playerIn.openGui(Tudicraft.instance, GuiHandler.GuiId.CALCULATOR, worldIn, 0, 0, 0);
|
||||
return itemStackIn;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addInformation(ItemStack stack, EntityPlayer playerIn, List<String> tooltip, boolean advanced) {
|
||||
//super.addInformation(stack, playerIn, tooltip, advanced);
|
||||
tooltip.add("sdji");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package pers.towdium.tudicraft.network;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import pers.towdium.tudicraft.core.Recipe;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Towdium
|
||||
*/
|
||||
public interface IPlayerHandler {
|
||||
|
||||
boolean getHasRecipeOf(ItemStack itemStack);
|
||||
|
||||
Recipe getRecipeOf(ItemStack itemStack);
|
||||
|
||||
ImmutableList<Recipe> getAllRecipeOf(ItemStack itemStack);
|
||||
|
||||
int getRecipeIndexOf(ItemStack itemStack);
|
||||
|
||||
ImmutableList<Integer> getAllRecipeIndexOf(ItemStack itemStack);
|
||||
|
||||
void addRecipe(Recipe recipe);
|
||||
|
||||
void removeRecipe(int index);
|
||||
|
||||
void setRecipe(Recipe recipe, int index);
|
||||
|
||||
Recipe getRecipe(int index);
|
||||
|
||||
ImmutableList<ItemStack> getCostOf(ItemStack itemStack, int amount);
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package pers.towdium.tudicraft.network;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import pers.towdium.tudicraft.core.Recipe;
|
||||
|
||||
/**
|
||||
* @author Towdium
|
||||
*/
|
||||
|
||||
|
||||
public interface IProxy {
|
||||
IPlayerHandler getPlayerHandler();
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,127 @@
|
||||
package pers.towdium.tudicraft.network;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import pers.towdium.tudicraft.core.Recipe;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Towdium
|
||||
*/
|
||||
public class PlayerHandlerClient implements IPlayerHandler {
|
||||
List<Recipe> recipes = new ArrayList<>();
|
||||
|
||||
@Override
|
||||
public void addRecipe(Recipe recipe) {
|
||||
for (Recipe oneRecipe : recipes){
|
||||
if(oneRecipe.equals(recipe)){
|
||||
return;
|
||||
}
|
||||
}
|
||||
if(recipe != null){
|
||||
recipes.add(recipe);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getHasRecipeOf(ItemStack itemStack) {
|
||||
for (Recipe recipe : recipes){
|
||||
if(recipe.getHasOutput(itemStack)){
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Recipe getRecipeOf(ItemStack itemStack) {
|
||||
int i = getRecipeIndexOf(itemStack);
|
||||
if(i == -1){
|
||||
return null;
|
||||
}else {
|
||||
return recipes.get(i);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ImmutableList<Recipe> getAllRecipeOf(ItemStack itemStack) {
|
||||
ImmutableList.Builder<Recipe> recipeBuilder = new ImmutableList.Builder<>();
|
||||
for(Integer index : getAllRecipeIndexOf(itemStack)){
|
||||
recipeBuilder.add(recipes.get(index));
|
||||
}
|
||||
return recipeBuilder.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getRecipeIndexOf(ItemStack itemStack) {
|
||||
int[] result = new int[]{-1, -1, -1, -1};
|
||||
for(int[] record : getAllUnsortedRecipeIndexOf(itemStack)){
|
||||
result[record[1]] = record[0];
|
||||
}
|
||||
for (int index : result) {
|
||||
if (index != -1) {
|
||||
return index;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ImmutableList<Integer> getAllRecipeIndexOf(ItemStack itemStack) {
|
||||
ImmutableList.Builder<ImmutableList.Builder<Integer>> builder1 = new ImmutableList.Builder<>();
|
||||
for(int i=0; i<4; i++){
|
||||
builder1.add(new ImmutableList.Builder<Integer>());
|
||||
}
|
||||
ImmutableList<ImmutableList.Builder<Integer>> resultBuffer = builder1.build();
|
||||
for(int[] result : getAllUnsortedRecipeIndexOf(itemStack)){
|
||||
resultBuffer.get(result[1]).add(result[0]);
|
||||
}
|
||||
ImmutableList.Builder<Integer> builder2 = new ImmutableList.Builder<>();
|
||||
for(ImmutableList.Builder<Integer> priority : resultBuffer){
|
||||
builder2.addAll(priority.build().reverse());
|
||||
}
|
||||
return builder2.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeRecipe(int index) {
|
||||
recipes.remove(index);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setRecipe(Recipe recipe, int index) {
|
||||
recipes.set(index, recipe);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Recipe getRecipe(int index) {
|
||||
return recipes.get(index);
|
||||
}
|
||||
|
||||
//TODO
|
||||
@Override
|
||||
public ImmutableList<ItemStack> getCostOf(ItemStack itemStack, int amount) {
|
||||
ImmutableList.Builder<ItemStack> builder = new ImmutableList.Builder<>();
|
||||
//recipes.get(getRecipeIndexOf(itemStack))
|
||||
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
ImmutableList<int[]> getAllUnsortedRecipeIndexOf(ItemStack itemStack){
|
||||
ImmutableList.Builder<int[]> builder = new ImmutableList.Builder<>();
|
||||
int size = recipes.size();
|
||||
int buffer;
|
||||
for(int i = 0; i<size; i++){
|
||||
buffer = recipes.get(i).getOutputIndex(itemStack);
|
||||
if(buffer != -1){
|
||||
builder.add(new int[]{i, buffer});
|
||||
}
|
||||
}
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
package pers.towdium.tudicraft.network;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import pers.towdium.tudicraft.core.Recipe;
|
||||
|
||||
/**
|
||||
* @author Towdium
|
||||
*/
|
||||
public class PlayerHandlerServer implements IPlayerHandler {
|
||||
@Override
|
||||
public void addRecipe(Recipe recipe) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getHasRecipeOf(ItemStack itemStack) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Recipe getRecipeOf(ItemStack itemStack) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ImmutableList<Recipe> getAllRecipeOf(ItemStack itemStack) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getRecipeIndexOf(ItemStack itemStack) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ImmutableList<Integer> getAllRecipeIndexOf(ItemStack itemStack) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeRecipe(int index) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setRecipe(Recipe recipe, int index) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Recipe getRecipe(int index) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ImmutableList<ItemStack> getCostOf(ItemStack itemStack, int amount) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package pers.towdium.tudicraft.network;
|
||||
|
||||
/**
|
||||
* @author Towdium
|
||||
*/
|
||||
public class ProxyClient implements IProxy {
|
||||
PlayerHandlerClient playerHandler = new PlayerHandlerClient();
|
||||
|
||||
@Override
|
||||
public IPlayerHandler getPlayerHandler() {
|
||||
return playerHandler;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package pers.towdium.tudicraft.network;
|
||||
|
||||
/**
|
||||
* @author Towdium
|
||||
*/
|
||||
public class ProxyServer implements IProxy{
|
||||
PlayerHandlerServer playerHandler = new PlayerHandlerServer();
|
||||
|
||||
@Override
|
||||
public IPlayerHandler getPlayerHandler() {
|
||||
return playerHandler;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
package pers.towdium.tudicraft.network.packages;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.fml.common.network.ByteBufUtils;
|
||||
import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
|
||||
import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler;
|
||||
import net.minecraftforge.fml.common.network.simpleimpl.MessageContext;
|
||||
import pers.towdium.tudicraft.item.ItemCalculator;
|
||||
|
||||
/**
|
||||
* @author Towdium
|
||||
*/
|
||||
public class PackageCalculatorUpdate implements IMessage, IMessageHandler<PackageCalculatorUpdate, IMessage> {
|
||||
ItemStack itemStack;
|
||||
|
||||
public PackageCalculatorUpdate(){}
|
||||
|
||||
public PackageCalculatorUpdate(ItemStack itemStack) {
|
||||
this.itemStack = itemStack;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromBytes(ByteBuf buf) {
|
||||
itemStack = ByteBufUtils.readItemStack(buf);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toBytes(ByteBuf buf) {
|
||||
ByteBufUtils.writeItemStack(buf, itemStack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IMessage onMessage(PackageCalculatorUpdate message, MessageContext ctx) {
|
||||
if(ctx.getServerHandler().playerEntity.getHeldItem().getItem() instanceof ItemCalculator){
|
||||
ctx.getServerHandler().playerEntity.inventory.setInventorySlotContents(
|
||||
ctx.getServerHandler().playerEntity.inventory.currentItem, message.itemStack);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
package pers.towdium.tudicraft.network.packages;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
|
||||
import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler;
|
||||
import net.minecraftforge.fml.common.network.simpleimpl.MessageContext;
|
||||
import pers.towdium.tudicraft.core.Recipe;
|
||||
|
||||
/**
|
||||
* @author Towdium
|
||||
*/
|
||||
public class PackageRecipeUpdate implements IMessage, IMessageHandler<PackageRecipeUpdate, IMessage> {
|
||||
Recipe recipe;
|
||||
|
||||
public PackageRecipeUpdate(){}
|
||||
|
||||
|
||||
public PackageRecipeUpdate(Recipe recipe){
|
||||
this.recipe = recipe;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toBytes(ByteBuf buffer) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromBytes(ByteBuf buffer) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public IMessage onMessage(PackageRecipeUpdate message, MessageContext context) {
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
package pers.towdium.tudicraft.network.packages;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.fml.common.network.ByteBufUtils;
|
||||
import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
|
||||
import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler;
|
||||
import net.minecraftforge.fml.common.network.simpleimpl.MessageContext;
|
||||
|
||||
/**
|
||||
* @author Towdium
|
||||
*/
|
||||
public class PackageSlotUpdate implements IMessage, IMessageHandler<PackageSlotUpdate, IMessage> {
|
||||
int slot;
|
||||
int playerId;
|
||||
ItemStack itemStack=null;
|
||||
|
||||
public PackageSlotUpdate(){}
|
||||
|
||||
|
||||
public PackageSlotUpdate(EntityPlayer player, int index){
|
||||
playerId = player.getEntityId();
|
||||
slot = index;
|
||||
this.itemStack = player.inventory.getStackInSlot(index);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public void toBytes(ByteBuf buffer) {
|
||||
buffer.writeByte(slot);
|
||||
buffer.writeInt(playerId);
|
||||
ByteBufUtils.writeItemStack(buffer, itemStack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromBytes(ByteBuf buffer) {
|
||||
slot = buffer.readByte();
|
||||
playerId = buffer.readInt();
|
||||
itemStack = ByteBufUtils.readItemStack(buffer);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public IMessage onMessage(PackageSlotUpdate message, MessageContext context) {
|
||||
context.getServerHandler().playerEntity.inventory.setInventorySlotContents(0, message.itemStack);
|
||||
// Entity player = FMLServerHandler.instance().getServer().getEntityWorld().getEntityByID(playerId);
|
||||
// System.out.println("get entity");
|
||||
//
|
||||
// if(player instanceof EntityPlayerMP){
|
||||
// System.out.println("get entityMP!");
|
||||
// ((EntityPlayerMP) player).getInventory()[0] = new ItemStack(new ItemCalculator(),10);
|
||||
// }
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
package pers.towdium.tudicraft.plugin;
|
||||
|
||||
import mezz.jei.JeiRuntime;
|
||||
import mezz.jei.api.*;
|
||||
import pers.towdium.tudicraft.Tudicraft;
|
||||
|
||||
import javax.swing.plaf.TableUI;
|
||||
|
||||
/**
|
||||
* @author Towdium
|
||||
*/
|
||||
@mezz.jei.api.JEIPlugin
|
||||
public class JEIPlugin implements IModPlugin{
|
||||
public static IJeiRuntime runtime;
|
||||
|
||||
|
||||
@Override
|
||||
public void onJeiHelpersAvailable(IJeiHelpers jeiHelpers) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onItemRegistryAvailable(IItemRegistry itemRegistry) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void register(IModRegistry registry) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRecipeRegistryAvailable(IRecipeRegistry recipeRegistry) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRuntimeAvailable(IJeiRuntime jeiRuntime) {
|
||||
Tudicraft.log.info("载入了!");
|
||||
runtime = jeiRuntime;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
gui.calculator.calculate=Calculate!
|
||||
gui.calculator.edit=Edit
|
||||
gui.calculator.add=Add
|
||||
gui.calculator.editTooltip=Edit records of recipes
|
||||
gui.calculator.addTooltip=Add preferred recipe
|
||||
gui.itemPicker.confirm=Confirm
|
||||
gui.itemPicker.search=Search
|
||||
gui.recipeEditor.save=Save
|
||||
gui.recipeEditor.clear=Clear
|
||||
item.itemCalculator.name=Calculator
|
||||
@@ -0,0 +1,18 @@
|
||||
{
|
||||
"parent": "builtin/generated",
|
||||
"textures": {
|
||||
"layer0": "tudicraft:items/itemCalculator"
|
||||
},
|
||||
"display": {
|
||||
"thirdperson": {
|
||||
"rotation": [ -90, 0, 0 ],
|
||||
"translation": [ 0, 1, -3 ],
|
||||
"scale": [ 0.55, 0.55, 0.55 ]
|
||||
},
|
||||
"firstperson": {
|
||||
"rotation": [ 0, -135, 25 ],
|
||||
"translation": [ 0, 4, 2 ],
|
||||
"scale": [ 1.7, 1.7, 1.7 ]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
After Width: | Height: | Size: 16 KiB |
|
After Width: | Height: | Size: 16 KiB |
|
After Width: | Height: | Size: 16 KiB |
|
After Width: | Height: | Size: 16 KiB |
|
After Width: | Height: | Size: 15 KiB |
|
After Width: | Height: | Size: 15 KiB |
|
After Width: | Height: | Size: 16 KiB |
|
After Width: | Height: | Size: 16 KiB |
|
After Width: | Height: | Size: 241 B |
@@ -0,0 +1,16 @@
|
||||
[
|
||||
{
|
||||
"modid": "examplemod",
|
||||
"name": "Example Mod",
|
||||
"description": "Example placeholder mod.",
|
||||
"version": "${version}",
|
||||
"mcversion": "${mcversion}",
|
||||
"url": "",
|
||||
"updateUrl": "",
|
||||
"authorList": ["ExampleDude"],
|
||||
"credits": "The Forge and FML guys, for making this example",
|
||||
"logoFile": "",
|
||||
"screenshots": [],
|
||||
"dependencies": []
|
||||
}
|
||||
]
|
||||