mirror of
https://github.com/GTNewHorizons/CraftTweaker.git
synced 2026-11-25 06:14:25 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ea3b258225 | ||
|
|
a28945f5f1 | ||
|
|
4e3c2c1b79 | ||
|
|
69b28b3bd4 | ||
|
|
60c3c9056d | ||
|
|
bebd499076 | ||
|
|
6376aff61f | ||
|
|
a309488cdf | ||
|
|
6b208b98bc | ||
|
|
e9a6a085b5 | ||
|
|
1afc652dc4 | ||
|
|
356fbdbdcc | ||
|
|
1d76f7db78 | ||
|
|
8abb3efbfb | ||
|
|
b86eeb4cc6 | ||
|
|
a7f9afb6c4 | ||
|
|
236744c74e | ||
|
|
eb2b529dea | ||
|
|
bf291dee77 | ||
|
|
a02cb3eec6 | ||
|
|
38c46d61d9 | ||
|
|
7c4b38e853 | ||
|
|
67ef22c4cc | ||
|
|
5044de32dd | ||
|
|
7b75ffb679 | ||
|
|
4787672b6e | ||
|
|
22502ff016 | ||
|
|
7c060cb624 | ||
|
|
b6a27cb150 | ||
|
|
6ffcca483f | ||
|
|
dc78b2b39e | ||
|
|
436ad039ca | ||
|
|
a348865dda | ||
|
|
86b4108e4f | ||
|
|
4d4fed2482 | ||
|
|
1796484e7c | ||
|
|
8fff244d95 | ||
|
|
e4a0cc8f35 | ||
|
|
7c0eb67215 | ||
|
|
9167cd1f1d | ||
|
|
11c68ce42a | ||
|
|
94705aeacf | ||
|
|
af79e56481 | ||
|
|
449ce974f4 | ||
|
|
6f874e5434 | ||
|
|
1b1d0ce55a | ||
|
|
a385f32680 | ||
|
|
7c5131ffca | ||
|
|
e630cc3f27 |
No files matched your search
@@ -0,0 +1,19 @@
|
|||||||
|
# This is the universal Text Editor Configuration
|
||||||
|
# for all GTNewHorizons projects
|
||||||
|
# See: https://editorconfig.org/
|
||||||
|
|
||||||
|
root = true
|
||||||
|
|
||||||
|
[*]
|
||||||
|
charset = utf-8
|
||||||
|
end_of_line = lf
|
||||||
|
indent_size = 4
|
||||||
|
indent_style = space
|
||||||
|
insert_final_newline = true
|
||||||
|
trim_trailing_whitespace = true
|
||||||
|
|
||||||
|
[*.{bat,ini}]
|
||||||
|
end_of_line = crlf
|
||||||
|
|
||||||
|
[*.{dtd,json,info,mcmeta,md,sh,svg,xml,xsd,xsl,yaml,yml}]
|
||||||
|
indent_size = 2
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
# Ignore spotlessApply reformat
|
||||||
|
a309488cdf7837ae1a27fab25305405ca7fe34e9
|
||||||
@@ -0,0 +1,44 @@
|
|||||||
|
* text eol=lf
|
||||||
|
|
||||||
|
*.[jJ][aA][rR] binary
|
||||||
|
|
||||||
|
*.[pP][nN][gG] binary
|
||||||
|
*.[jJ][pP][gG] binary
|
||||||
|
*.[jJ][pP][eE][gG] binary
|
||||||
|
*.[gG][iI][fF] binary
|
||||||
|
*.[tT][iI][fF] binary
|
||||||
|
*.[tT][iI][fF][fF] binary
|
||||||
|
*.[iI][cC][oO] binary
|
||||||
|
*.[sS][vV][gG] text
|
||||||
|
*.[eE][pP][sS] binary
|
||||||
|
*.[xX][cC][fF] binary
|
||||||
|
|
||||||
|
*.[kK][aA][rR] binary
|
||||||
|
*.[mM]4[aA] binary
|
||||||
|
*.[mM][iI][dD] binary
|
||||||
|
*.[mM][iI][dD][iI] binary
|
||||||
|
*.[mM][pP]3 binary
|
||||||
|
*.[oO][gG][gG] binary
|
||||||
|
*.[rR][aA] binary
|
||||||
|
|
||||||
|
*.7[zZ] binary
|
||||||
|
*.[gG][zZ] binary
|
||||||
|
*.[tT][aA][rR] binary
|
||||||
|
*.[tT][gG][zZ] binary
|
||||||
|
*.[zZ][iI][pP] binary
|
||||||
|
|
||||||
|
*.[tT][cC][nN] binary
|
||||||
|
*.[sS][oO] binary
|
||||||
|
*.[dD][lL][lL] binary
|
||||||
|
*.[dD][yY][lL][iI][bB] binary
|
||||||
|
*.[pP][sS][dD] binary
|
||||||
|
*.[tT][tT][fF] binary
|
||||||
|
*.[oO][tT][fF] binary
|
||||||
|
|
||||||
|
*.[pP][aA][tT][cC][hH] -text
|
||||||
|
|
||||||
|
*.[bB][aA][tT] text eol=crlf
|
||||||
|
*.[cC][mM][dD] text eol=crlf
|
||||||
|
*.[pP][sS]1 text eol=crlf
|
||||||
|
|
||||||
|
*[aA][uU][tT][oO][gG][eE][nN][eE][rR][aA][tT][eE][dD]* binary
|
||||||
Executable
+51
@@ -0,0 +1,51 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
# bashsupport disable=BP5006 # Global environment variables
|
||||||
|
RUNDIR="run" \
|
||||||
|
CRASH="crash-reports" \
|
||||||
|
SERVERLOG="server.log"
|
||||||
|
|
||||||
|
# enable nullglob to get 0 results when no match rather than the pattern
|
||||||
|
shopt -s nullglob
|
||||||
|
|
||||||
|
# store matches in array
|
||||||
|
crash_reports=("$RUNDIR/$CRASH/crash"*.txt)
|
||||||
|
|
||||||
|
# if array not empty there are crash_reports
|
||||||
|
if [ "${#crash_reports[@]}" -gt 0 ]; then
|
||||||
|
# get the latest crash_report from array
|
||||||
|
latest_crash_report="${crash_reports[-1]}"
|
||||||
|
{
|
||||||
|
printf 'Latest crash report detected %s:\n' "${latest_crash_report##*/}"
|
||||||
|
cat "$latest_crash_report"
|
||||||
|
} >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if grep --quiet --fixed-strings 'Fatal errors were detected' "$SERVERLOG"; then
|
||||||
|
{
|
||||||
|
printf 'Fatal errors detected:\n'
|
||||||
|
cat server.log
|
||||||
|
} >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if grep --quiet --fixed-strings 'The state engine was in incorrect state ERRORED and forced into state SERVER_STOPPED' \
|
||||||
|
"$SERVERLOG"; then
|
||||||
|
{
|
||||||
|
printf 'Server force stopped:'
|
||||||
|
cat server.log
|
||||||
|
} >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if ! grep --quiet --perl-regexp --only-matching '.+Done \(.+\)\! For help, type "help" or "\?"' "$SERVERLOG"; then
|
||||||
|
{
|
||||||
|
printf 'Server did not finish startup:'
|
||||||
|
cat server.log
|
||||||
|
} >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
printf 'No crash reports detected'
|
||||||
|
exit 0
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
|
||||||
|
name: Build and test
|
||||||
|
|
||||||
|
on:
|
||||||
|
pull_request:
|
||||||
|
branches: [ master, main ]
|
||||||
|
push:
|
||||||
|
branches: [ master, main ]
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build-and-test:
|
||||||
|
uses: GTNewHorizons/GTNH-Actions-Workflows/.github/workflows/build-and-test.yml@master
|
||||||
|
secrets: inherit
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
|
||||||
|
name: Release tagged build
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
tags: [ '*' ]
|
||||||
|
|
||||||
|
permissions:
|
||||||
|
contents: write
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
release-tags:
|
||||||
|
uses: GTNewHorizons/GTNH-Actions-Workflows/.github/workflows/release-tags.yml@master
|
||||||
|
secrets: inherit
|
||||||
+34
-127
@@ -1,128 +1,35 @@
|
|||||||
# Ignore All
|
.gradle
|
||||||
/*
|
.settings
|
||||||
|
/.idea/
|
||||||
# Except:
|
.shelf
|
||||||
|
/run/
|
||||||
# Source files & libraries
|
/build/
|
||||||
!/buildSrc
|
/eclipse/
|
||||||
/buildSrc/*
|
.vscode
|
||||||
!/buildSrc/src/
|
.classpath
|
||||||
|
.project
|
||||||
!/MineTweaker3-API
|
/bin/
|
||||||
/MineTweaker3-API/*
|
/config/
|
||||||
!/MineTweaker3-API/src
|
/crash-reports/
|
||||||
|
/logs/
|
||||||
!/MineTweaker3-MC1102-Main
|
options.txt
|
||||||
/MineTweaker3-MC1102-Main/*
|
/saves/
|
||||||
!/MineTweaker3-MC1102-Main/src
|
usernamecache.json
|
||||||
!/MineTweaker3-MC1102-Main/build.gradle
|
banned-ips.json
|
||||||
/MineTweaker3-MC1102-Main/bin
|
banned-players.json
|
||||||
|
eula.txt
|
||||||
!/MineTweaker3-MC1102-Mod-JEI
|
ops.json
|
||||||
/MineTweaker3-MC1102-Mod-JEI/*
|
server.properties
|
||||||
!/MineTweaker3-MC1102-Mod-JEI/src
|
servers.dat
|
||||||
!/MineTweaker3-MC1102-Mod-JEI/libs
|
usercache.json
|
||||||
!/MineTweaker3-MC1102-Mod-JEI/build.gradle
|
whitelist.json
|
||||||
|
/out/
|
||||||
!/MineTweaker3-MC19-Main
|
*.iml
|
||||||
/MineTweaker3-MC19-Main/*
|
*.ipr
|
||||||
!/MineTweaker3-MC19-Main/src
|
*.iws
|
||||||
!/MineTweaker3-MC19-Main/build.gradle
|
src/main/resources/mixins.*.json
|
||||||
/MineTweaker3-MC19-Main/bin
|
*.bat
|
||||||
|
/src/main/generated/
|
||||||
!/MineTweaker3-MC19-Mod-JEI
|
/src/test/generated/
|
||||||
/MineTweaker3-MC19-Mod-JEI/*
|
|
||||||
!/MineTweaker3-MC19-Mod-JEI/src
|
|
||||||
!/MineTweaker3-MC19-Mod-JEI/libs
|
|
||||||
!/MineTweaker3-MC19-Mod-JEI/build.gradle
|
|
||||||
|
|
||||||
!/MineTweaker3-MC18-Main
|
|
||||||
/MineTweaker3-MC18-Main/*
|
|
||||||
!/MineTweaker3-MC18-Main/src
|
|
||||||
!/MineTweaker3-MC18-Main/build.gradle
|
|
||||||
/MineTweaker3-MC18-Main/bin
|
|
||||||
|
|
||||||
!/MineTweaker3-MC18-Mod-JEI
|
|
||||||
/MineTweaker3-MC18-Mod-JEI/*
|
|
||||||
!/MineTweaker3-MC18-Mod-JEI/src
|
|
||||||
!/MineTweaker3-MC18-Mod-JEI/libs
|
|
||||||
!/MineTweaker3-MC18-Mod-JEI/build.gradle
|
|
||||||
|
|
||||||
|
|
||||||
!/MineTweaker3-MC1710-Main
|
|
||||||
/MineTweaker3-MC1710-Main/*
|
|
||||||
!/MineTweaker3-MC1710-Main/src
|
|
||||||
/MineTweaker3-MC1710-Main/bin
|
|
||||||
!/MineTweaker3-MC1710-Main/build.gradle
|
|
||||||
|
|
||||||
|
|
||||||
!/MineTweaker3-MC1710-Mod-Buildcraft
|
|
||||||
/MineTweaker3-MC1710-Mod-Buildcraft/*
|
|
||||||
!/MineTweaker3-MC1710-Mod-Buildcraft/src
|
|
||||||
!/MineTweaker3-MC1710-Mod-Buildcraft/libs
|
|
||||||
!/MineTweaker3-MC1710-Mod-Buildcraft/build.gradle
|
|
||||||
|
|
||||||
|
|
||||||
!/MineTweaker3-MC1710-Mod-Buildcraft61
|
|
||||||
/MineTweaker3-MC1710-Mod-Buildcraft61/*
|
|
||||||
!/MineTweaker3-MC1710-Mod-Buildcraft61/src
|
|
||||||
!/MineTweaker3-MC1710-Mod-Buildcraft61/libs
|
|
||||||
!/MineTweaker3-MC1710-Mod-Buildcraft61/build.gradle
|
|
||||||
|
|
||||||
!/MineTweaker3-MC1710-Mod-IC2
|
|
||||||
/MineTweaker3-MC1710-Mod-IC2/*
|
|
||||||
!/MineTweaker3-MC1710-Mod-IC2/src
|
|
||||||
!/MineTweaker3-MC1710-Mod-IC2/libs
|
|
||||||
!/MineTweaker3-MC1710-Mod-IC2/build.gradle
|
|
||||||
|
|
||||||
!/MineTweaker3-MC1102-Mod-IC2
|
|
||||||
/MineTweaker3-MC1102-Mod-IC2/*
|
|
||||||
!/MineTweaker3-MC1102-Mod-IC2/src
|
|
||||||
!/MineTweaker3-MC1102-Mod-IC2/libs
|
|
||||||
!/MineTweaker3-MC1102-Mod-IC2/build.gradle
|
|
||||||
|
|
||||||
!/MineTweaker3-MC1710-Mod-MFR
|
|
||||||
/MineTweaker3-MC1710-Mod-MFR/*
|
|
||||||
!/MineTweaker3-MC1710-Mod-MFR/src
|
|
||||||
!/MineTweaker3-MC1710-Mod-MFR/libs
|
|
||||||
!/MineTweaker3-MC1710-Mod-MFR/build.gradle
|
|
||||||
|
|
||||||
|
|
||||||
!/MineTweaker3-MC1710-Mod-NEI
|
|
||||||
/MineTweaker3-MC1710-Mod-NEI/*
|
|
||||||
!/MineTweaker3-MC1710-Mod-NEI/src
|
|
||||||
!/MineTweaker3-MC1710-Mod-NEI/libs
|
|
||||||
!/MineTweaker3-MC1710-Mod-NEI/build.gradle
|
|
||||||
|
|
||||||
|
|
||||||
!/ZenScript
|
|
||||||
/ZenScript/*
|
|
||||||
!/ZenScript/src
|
|
||||||
|
|
||||||
!/MineTweaker3-Web
|
|
||||||
|
|
||||||
# gradle
|
|
||||||
!/build.gradle
|
|
||||||
!/build.properties
|
|
||||||
!/settings.gradle
|
|
||||||
!/common.gradle
|
|
||||||
!/gradle.properties
|
|
||||||
!/gradlew*
|
|
||||||
!/gradle
|
|
||||||
|
|
||||||
MineTweaker3-Web/doc
|
|
||||||
|
|
||||||
# github
|
|
||||||
!/.gitignore
|
|
||||||
!/README.md
|
|
||||||
|
|
||||||
# unwanted os-generated files
|
|
||||||
nbproject/
|
|
||||||
.DS_Store
|
.DS_Store
|
||||||
.DS_Store?
|
classes
|
||||||
._*
|
|
||||||
.Spotlight-V100
|
|
||||||
.Trashes
|
|
||||||
ehthumbs.db
|
|
||||||
Thumbs.db
|
|
||||||
*~
|
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
[submodule "ZenScript"]
|
|
||||||
path = ZenScript
|
|
||||||
url = https://github.com/CraftTweaker/ZenScript.git
|
|
||||||
@@ -1,37 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
|
||||||
<gradle-project-properties>
|
|
||||||
<!--DO NOT EDIT THIS FILE! - Used by the Gradle plugin of NetBeans.-->
|
|
||||||
<built-in-tasks>
|
|
||||||
<task>
|
|
||||||
<display-name>debug</display-name>
|
|
||||||
<non-blocking>no</non-blocking>
|
|
||||||
<task-names>
|
|
||||||
<name must-exist="no">runClient</name>
|
|
||||||
</task-names>
|
|
||||||
<task-args/>
|
|
||||||
<task-jvm-args>
|
|
||||||
<arg>-Xdebug</arg>
|
|
||||||
</task-jvm-args>
|
|
||||||
</task>
|
|
||||||
<task>
|
|
||||||
<display-name>run</display-name>
|
|
||||||
<non-blocking>no</non-blocking>
|
|
||||||
<task-names>
|
|
||||||
<name must-exist="no">runClient</name>
|
|
||||||
</task-names>
|
|
||||||
<task-args/>
|
|
||||||
<task-jvm-args>
|
|
||||||
<arg>-Dfml.coreMods.load=minetweaker.mc172.transformer.MineTweakerTransformer</arg>
|
|
||||||
</task-jvm-args>
|
|
||||||
</task>
|
|
||||||
<task>
|
|
||||||
<display-name>run.single</display-name>
|
|
||||||
<non-blocking>no</non-blocking>
|
|
||||||
<task-names>
|
|
||||||
<name must-exist="no">${project}:runClient</name>
|
|
||||||
</task-names>
|
|
||||||
<task-args/>
|
|
||||||
<task-jvm-args/>
|
|
||||||
</task>
|
|
||||||
</built-in-tasks>
|
|
||||||
</gradle-project-properties>
|
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
|
||||||
|
# CraftTweaker
|
||||||
|
|
||||||
|
Changelog of CraftTweaker.
|
||||||
|
|
||||||
|
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
# Any Github changes require admin approval
|
||||||
|
/.github/** @GTNewHorizons/admin
|
||||||
|
|
||||||
@@ -1,58 +0,0 @@
|
|||||||
import minetweaker.tasks.RegisterZenClassesTask;
|
|
||||||
|
|
||||||
apply plugin: 'java'
|
|
||||||
apply plugin: 'maven'
|
|
||||||
|
|
||||||
version = ext.mineTweakerVersion
|
|
||||||
|
|
||||||
sourceCompatibility = JavaVersion.VERSION_1_8
|
|
||||||
targetCompatibility = JavaVersion.VERSION_1_8
|
|
||||||
|
|
||||||
task makeRegistry(type: RegisterZenClassesTask) {
|
|
||||||
inputDir = file('build/classes/main')
|
|
||||||
outputDir = file('build/classes/main')
|
|
||||||
className = 'minetweaker.ClassRegistry'
|
|
||||||
}
|
|
||||||
|
|
||||||
tasks.jar.dependsOn(makeRegistry)
|
|
||||||
|
|
||||||
dependencies {
|
|
||||||
dependencies {
|
|
||||||
compile project(':ZenScript')
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
uploadArchives {
|
|
||||||
repositories {
|
|
||||||
mavenDeployer {
|
|
||||||
repository(url: "file://" + System.getenv("local_maven"))
|
|
||||||
pom {
|
|
||||||
groupId = project.group
|
|
||||||
version
|
|
||||||
artifactId = project.archivesBaseName
|
|
||||||
project {
|
|
||||||
name project.archivesBaseName
|
|
||||||
packaging 'jar'
|
|
||||||
description 'CraftTweaker'
|
|
||||||
url 'https://github.com/jaredlll08/CraftTweaker'
|
|
||||||
scm {
|
|
||||||
url 'https://github.com/jaredlll08/CraftTweaker.git'
|
|
||||||
connection 'scm:git:[email protected]:jaredlll08/CraftTweaker.git'
|
|
||||||
developerConnection 'scm:git:[email protected]:jaredlll08/CraftTweaker.git'
|
|
||||||
}
|
|
||||||
issueManagement {
|
|
||||||
system 'github'
|
|
||||||
url 'https://github.com/jaredlll08/CraftTweaker/issues'
|
|
||||||
}
|
|
||||||
developers {
|
|
||||||
developer {
|
|
||||||
id 'Jared'
|
|
||||||
name 'Jared'
|
|
||||||
roles { role 'developer' }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,15 +0,0 @@
|
|||||||
package minetweaker;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The class registry provides the list of annotated classes to the scripting
|
|
||||||
* system.
|
|
||||||
*
|
|
||||||
* @author Stan Hebben
|
|
||||||
*/
|
|
||||||
public class ClassRegistry {
|
|
||||||
public static void getClasses(List<Class> output) {
|
|
||||||
// method stub; contents generated by RegisterZenClassesTask
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,32 +0,0 @@
|
|||||||
package minetweaker;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
import stanhebben.zenscript.compiler.IEnvironmentGlobal;
|
|
||||||
import stanhebben.zenscript.parser.Token;
|
|
||||||
import stanhebben.zenscript.symbols.IZenSymbol;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Bracket handlers enable processing of the bracket syntax.
|
|
||||||
*
|
|
||||||
* Inside brackets, any kind of token is acceptable except the closing bracket.
|
|
||||||
* (>) Bracket handlers (multiple handlers can be registered) will resolve
|
|
||||||
* these tokens into actual values. Values have to be ZenScript symbols and will
|
|
||||||
* resolve at compile-time.
|
|
||||||
*
|
|
||||||
* These may of course return an expression that are executed on run-time, but
|
|
||||||
* the type of the resulting value must be known compile-time.
|
|
||||||
*
|
|
||||||
* @author Stan Hebben
|
|
||||||
*/
|
|
||||||
public interface IBracketHandler {
|
|
||||||
/**
|
|
||||||
* Resolves a set of tokens.
|
|
||||||
*
|
|
||||||
* If the series of tokens is unrecognized, this method should return null.
|
|
||||||
*
|
|
||||||
* @param environment global compilation environment
|
|
||||||
* @param tokens token stream to be detected
|
|
||||||
* @return the resolved symbol, or null
|
|
||||||
*/
|
|
||||||
public IZenSymbol resolve(IEnvironmentGlobal environment, List<Token> tokens);
|
|
||||||
}
|
|
||||||
@@ -1,36 +0,0 @@
|
|||||||
package minetweaker;
|
|
||||||
|
|
||||||
import minetweaker.api.chat.IChatMessage;
|
|
||||||
import minetweaker.api.item.IItemDefinition;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Platform functions are a set of internal functions implemented by the
|
|
||||||
* platform intended to communicate between API and implementation.
|
|
||||||
*
|
|
||||||
* @author Stan Hebben
|
|
||||||
*/
|
|
||||||
public interface IPlatformFunctions {
|
|
||||||
/**
|
|
||||||
* Converts a string into a chat message.
|
|
||||||
*
|
|
||||||
* @param message message string
|
|
||||||
* @return chat message
|
|
||||||
*/
|
|
||||||
public IChatMessage getMessage(String message);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Distributes the given script data to all connected clients. Automatically
|
|
||||||
* reloads the scripts from this data.
|
|
||||||
*
|
|
||||||
* @param data data to be distributed
|
|
||||||
*/
|
|
||||||
public void distributeScripts(byte[] data);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Finds the item definition with the given ID.
|
|
||||||
*
|
|
||||||
* @param id item ID
|
|
||||||
* @return resulting item definition
|
|
||||||
*/
|
|
||||||
public IItemDefinition getItemDefinition(int id);
|
|
||||||
}
|
|
||||||
@@ -1,18 +0,0 @@
|
|||||||
package minetweaker;
|
|
||||||
|
|
||||||
import minetweaker.api.item.IIngredient;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Used to register removable mod recipes for mod machines. Once registered, it
|
|
||||||
* will be called when minetweaker.remove() is called.
|
|
||||||
*
|
|
||||||
* @author Stan Hebben
|
|
||||||
*/
|
|
||||||
public interface IRecipeRemover {
|
|
||||||
/**
|
|
||||||
* Removes all the items matching the given ingredient.
|
|
||||||
*
|
|
||||||
* @param ingredient ingredient
|
|
||||||
*/
|
|
||||||
public void remove(IIngredient ingredient);
|
|
||||||
}
|
|
||||||
@@ -1,84 +0,0 @@
|
|||||||
package minetweaker;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Defines a (possibly) undoable action.
|
|
||||||
*
|
|
||||||
* Every modification made by a command must be registered to the Tweaker with
|
|
||||||
* the Tweaker.apply method. This enables MineTweaker to keep track of actions
|
|
||||||
* that have been performed, and enables them to be rolled back later on.
|
|
||||||
*
|
|
||||||
* Actions exist in two flavors: undoable and permanent. If an action returns
|
|
||||||
* canUndo(), the action is undoable, otherwise it is permanent. Permanent
|
|
||||||
* actions cannot be used in server scripts.
|
|
||||||
*
|
|
||||||
* There also exist semi-permanent actions. Those actions can return an override
|
|
||||||
* key; if a newer action has the same override key as an old action, the new
|
|
||||||
* action is considered to override the old one.
|
|
||||||
*
|
|
||||||
* Likewise, actions can implement hashCode and equals methods to indicate that
|
|
||||||
* they are equal. If an action is equal to a non-undoable stuck action, it will
|
|
||||||
* be omitted from execution.
|
|
||||||
*
|
|
||||||
* @author Stan Hebben
|
|
||||||
*/
|
|
||||||
public interface IUndoableAction {
|
|
||||||
/**
|
|
||||||
* Executes what the action is supposed to do. This method can be called
|
|
||||||
* again if undo() has been called in between.
|
|
||||||
*/
|
|
||||||
public void apply();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Checks if this action can be undone. If this method returns true, it must
|
|
||||||
* implement undo() properly. If this method returns false, the action is
|
|
||||||
* considered permanent, undo() will never be called, and the action cannot
|
|
||||||
* be executed as part of a server script. Additionally, the
|
|
||||||
* minetweaker.clear() function will not work and minetweaker.canClear will
|
|
||||||
* return false.
|
|
||||||
*
|
|
||||||
* @return undoable status
|
|
||||||
*/
|
|
||||||
public boolean canUndo();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Undoes the action. Will only be called after apply() has been executed.
|
|
||||||
* After an undo, apply may be called again. They could be done multiple
|
|
||||||
* times in certain scenarios.
|
|
||||||
*/
|
|
||||||
public void undo();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Describes, in a single human-readable sentence, what this specific action
|
|
||||||
* is doing. Used in logging messages, lists, ...
|
|
||||||
*
|
|
||||||
* Try to be as descriptive as possible without being too verbose.
|
|
||||||
*
|
|
||||||
* Examples: - Adding Peach planks to the woodPlanks ore dictionary entry -
|
|
||||||
* Removing a recipe for Iron Ore
|
|
||||||
*
|
|
||||||
* @return the description of this action
|
|
||||||
*/
|
|
||||||
public String describe();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Describes what this action does if it is undone. Similar to the
|
|
||||||
* describe() method. No implementation is needed if the action cannot be
|
|
||||||
* undone.
|
|
||||||
*
|
|
||||||
* @return the description of this action, when undone
|
|
||||||
*/
|
|
||||||
public String describeUndo();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the override key. Two actions are considered to override each
|
|
||||||
* other if their override key is equal. You can return null to indicate
|
|
||||||
* that an action can never be overridden.
|
|
||||||
*
|
|
||||||
* This value only makes sense for recipes that are not undoable. For
|
|
||||||
* undoable recipes, you should return null.
|
|
||||||
*
|
|
||||||
* @return override key (null for actions that are undoable or which can
|
|
||||||
* never be overridden by another action)
|
|
||||||
*/
|
|
||||||
public Object getOverrideKey();
|
|
||||||
}
|
|
||||||
@@ -1,453 +0,0 @@
|
|||||||
package minetweaker;
|
|
||||||
|
|
||||||
import minetweaker.annotations.BracketHandler;
|
|
||||||
import minetweaker.annotations.ModOnly;
|
|
||||||
import minetweaker.api.client.IClient;
|
|
||||||
import minetweaker.api.compat.*;
|
|
||||||
import minetweaker.api.event.IEventManager;
|
|
||||||
import minetweaker.api.formatting.IFormatter;
|
|
||||||
import minetweaker.api.game.IGame;
|
|
||||||
import minetweaker.api.mods.ILoadedMods;
|
|
||||||
import minetweaker.api.oredict.IOreDict;
|
|
||||||
import minetweaker.api.recipes.IFurnaceManager;
|
|
||||||
import minetweaker.api.recipes.IRecipeManager;
|
|
||||||
import minetweaker.api.server.IServer;
|
|
||||||
import minetweaker.api.vanilla.IVanilla;
|
|
||||||
import minetweaker.runtime.GlobalRegistry;
|
|
||||||
import minetweaker.runtime.ILogger;
|
|
||||||
import minetweaker.runtime.ITweaker;
|
|
||||||
import minetweaker.runtime.MTTweaker;
|
|
||||||
import stanhebben.zenscript.annotations.ZenClass;
|
|
||||||
import stanhebben.zenscript.annotations.ZenExpansion;
|
|
||||||
import stanhebben.zenscript.symbols.IZenSymbol;
|
|
||||||
import stanhebben.zenscript.symbols.SymbolJavaStaticField;
|
|
||||||
import stanhebben.zenscript.symbols.SymbolJavaStaticGetter;
|
|
||||||
import stanhebben.zenscript.symbols.SymbolJavaStaticMethod;
|
|
||||||
import stanhebben.zenscript.type.natives.IJavaMethod;
|
|
||||||
import stanhebben.zenscript.type.natives.JavaMethod;
|
|
||||||
|
|
||||||
import java.lang.annotation.Annotation;
|
|
||||||
import java.lang.reflect.Field;
|
|
||||||
import java.lang.reflect.InvocationTargetException;
|
|
||||||
import java.lang.reflect.Method;
|
|
||||||
import java.lang.reflect.Modifier;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.logging.Level;
|
|
||||||
import java.util.logging.Logger;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Provides access to the MineTweaker API.
|
|
||||||
*
|
|
||||||
* An implementing platform needs to do the following: - Set a logger - Set the
|
|
||||||
* ore dictionary - Set the recipe manager - Set the furnace manager - Set event
|
|
||||||
* manager - Set resource manager
|
|
||||||
*
|
|
||||||
* - Register additional global symbols to the GlobalRegistry (recipes,
|
|
||||||
* minetweaker, oreDict, logger, as well as the official set of functions) -
|
|
||||||
* Register native classes using the GlobalRegistry - Register bracket handlers
|
|
||||||
* to resolve block/item/... references using the bracket syntax
|
|
||||||
*
|
|
||||||
* @author Stan Hebben
|
|
||||||
*/
|
|
||||||
public class MineTweakerAPI {
|
|
||||||
public static final String[] COLOR_NAMES = {
|
|
||||||
"White",
|
|
||||||
"Orange",
|
|
||||||
"Magenta",
|
|
||||||
"Light Blue",
|
|
||||||
"Yellow",
|
|
||||||
"Lime",
|
|
||||||
"Pink",
|
|
||||||
"Gray",
|
|
||||||
"Light Gray",
|
|
||||||
"Cyan",
|
|
||||||
"Purple",
|
|
||||||
"Blue",
|
|
||||||
"Brown",
|
|
||||||
"Green",
|
|
||||||
"Red",
|
|
||||||
"Black"
|
|
||||||
};
|
|
||||||
private static IJEIRecipeRegistry ijeiRecipeRegistry = new DummyJEIRecipeRegistry();
|
|
||||||
|
|
||||||
static {
|
|
||||||
registerClassRegistry(ClassRegistry.class, "MT-API");
|
|
||||||
|
|
||||||
registerGlobalSymbol("logger", getJavaStaticGetterSymbol(MineTweakerAPI.class, "getLogger"));
|
|
||||||
registerGlobalSymbol("recipes", getJavaStaticFieldSymbol(MineTweakerAPI.class, "recipes"));
|
|
||||||
// registerGlobalSymbol("brewing", getJavaStaticFieldSymbol(MineTweakerAPI.class, "brewing"));
|
|
||||||
registerGlobalSymbol("furnace", getJavaStaticFieldSymbol(MineTweakerAPI.class, "furnace"));
|
|
||||||
registerGlobalSymbol("oreDict", getJavaStaticFieldSymbol(MineTweakerAPI.class, "oreDict"));
|
|
||||||
registerGlobalSymbol("events", getJavaStaticFieldSymbol(MineTweakerAPI.class, "events"));
|
|
||||||
registerGlobalSymbol("server", getJavaStaticFieldSymbol(MineTweakerAPI.class, "server"));
|
|
||||||
registerGlobalSymbol("client", getJavaStaticFieldSymbol(MineTweakerAPI.class, "client"));
|
|
||||||
registerGlobalSymbol("game", getJavaStaticFieldSymbol(MineTweakerAPI.class, "game"));
|
|
||||||
registerGlobalSymbol("loadedMods", getJavaStaticFieldSymbol(MineTweakerAPI.class, "loadedMods"));
|
|
||||||
registerGlobalSymbol("format", getJavaStaticFieldSymbol(MineTweakerAPI.class, "format"));
|
|
||||||
registerGlobalSymbol("vanilla", getJavaStaticFieldSymbol(MineTweakerAPI.class, "vanilla"));
|
|
||||||
}
|
|
||||||
|
|
||||||
private MineTweakerAPI() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The Tweaker is where you apply undoable actions. Any kind of action that
|
|
||||||
* reloads with the scripts should always be submitted to the tweaker.
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
public static final ITweaker tweaker = new MTTweaker();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The logger can be used to write logging messages to the client. Error and
|
|
||||||
* warning messages should be relayed to admins for further handling.
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public static final ILogger getLogger() {
|
|
||||||
return MineTweakerImplementationAPI.logger;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Access point to the ore dictionary.
|
|
||||||
*/
|
|
||||||
public static IOreDict oreDict = null;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Access point to the recipe manager.
|
|
||||||
*/
|
|
||||||
public static IRecipeManager recipes = null;
|
|
||||||
|
|
||||||
// /**
|
|
||||||
// * Access point to the brewing manager.
|
|
||||||
// */
|
|
||||||
// public static IBrewingManager brewing = null;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Access point to the furnace manager.
|
|
||||||
*/
|
|
||||||
public static IFurnaceManager furnace = null;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Access point to the events manager.
|
|
||||||
*/
|
|
||||||
public static final IEventManager events = MineTweakerImplementationAPI.events;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Access point to the server, if any.
|
|
||||||
*/
|
|
||||||
public static IServer server = null;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Access point to the client, if any.
|
|
||||||
*/
|
|
||||||
public static IClient client = null;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Access point to general game data, such as items.
|
|
||||||
*/
|
|
||||||
public static IGame game = null;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Access point to mods list.
|
|
||||||
*/
|
|
||||||
public static ILoadedMods loadedMods = null;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Access point to the text formatter.
|
|
||||||
*/
|
|
||||||
public static IFormatter format = null;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Access point to the vanilla functions and data.
|
|
||||||
*/
|
|
||||||
public static IVanilla vanilla = null;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Applies this given action.
|
|
||||||
*
|
|
||||||
* @param action action object
|
|
||||||
*/
|
|
||||||
public static void apply(IUndoableAction action) {
|
|
||||||
tweaker.apply(action);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Logs a command message. Commands messages are those generated as output
|
|
||||||
* in response to a command.
|
|
||||||
*
|
|
||||||
* @param message command message
|
|
||||||
*/
|
|
||||||
public static void logCommand(String message) {
|
|
||||||
getLogger().logCommand(message);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Logs an info message. Info messages have low priority and will only be
|
|
||||||
* displayed in the log files, but not directly to players in-game.
|
|
||||||
*
|
|
||||||
* @param message info message
|
|
||||||
*/
|
|
||||||
public static void logInfo(String message) {
|
|
||||||
getLogger().logInfo(message);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Logs a warning message. Warning messages are displayed to admins and
|
|
||||||
* indicate that there is an issue. However, the issue is not a large
|
|
||||||
* problem, and everything should run fine - besides perhaps a few things
|
|
||||||
* not entirely working as expected.
|
|
||||||
*
|
|
||||||
* @param message warning message
|
|
||||||
*/
|
|
||||||
public static void logWarning(String message) {
|
|
||||||
getLogger().logWarning(message);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Logs an error message. Error messages indicate a real problem and
|
|
||||||
* indicate that things won't run properly. The scripting system will still
|
|
||||||
* make a best-effort attempt at executing the rest of the scripts, but that
|
|
||||||
* might cause additional errors and issues.
|
|
||||||
*
|
|
||||||
* @param message error message
|
|
||||||
*/
|
|
||||||
public static void logError(String message) {
|
|
||||||
getLogger().logError(message);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Logs an error message. Error messages indicate a real problem and
|
|
||||||
* indicate that things won't run properly. The scripting system will still
|
|
||||||
* make a best-effort attempt at executing the rest of the scripts, but that
|
|
||||||
* might cause additional errors and issues.
|
|
||||||
*
|
|
||||||
* @param message error message
|
|
||||||
* @param exception exception that was caught related to the error
|
|
||||||
*/
|
|
||||||
public static void logError(String message, Throwable exception) {
|
|
||||||
getLogger().logError(message, exception);
|
|
||||||
}
|
|
||||||
|
|
||||||
// ###################################
|
|
||||||
// ### Plugin registration methods ###
|
|
||||||
// ###################################
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Register a class registry class. Such class must have (at least) a public
|
|
||||||
* static method called "getClasses" with accepts a List of classes and
|
|
||||||
* which stores its classes into that list.
|
|
||||||
*
|
|
||||||
* @param registryClass
|
|
||||||
*/
|
|
||||||
public static void registerClassRegistry(Class registryClass) {
|
|
||||||
registerClassRegistry(registryClass, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Register a class registry class. Such class must have (at least) a public
|
|
||||||
* static method called "getClasses" with accepts a List of classes and
|
|
||||||
* which stores its classes into that list.
|
|
||||||
*
|
|
||||||
* @param registryClass
|
|
||||||
* @param description
|
|
||||||
*/
|
|
||||||
public static void registerClassRegistry(Class registryClass, String description) {
|
|
||||||
try {
|
|
||||||
Method method = registryClass.getMethod("getClasses", List.class);
|
|
||||||
if ((method.getModifiers() & Modifier.STATIC) == 0) {
|
|
||||||
logError("ERROR: getClasses method in " + registryClass.getName() + " isn't static");
|
|
||||||
} else {
|
|
||||||
List<Class> classes = new ArrayList<Class>();
|
|
||||||
method.invoke(null, classes);
|
|
||||||
|
|
||||||
outer: for (Class cls : classes) {
|
|
||||||
for (Annotation annotation : cls.getAnnotations()) {
|
|
||||||
if (annotation instanceof ModOnly) {
|
|
||||||
String[] value = ((ModOnly) annotation).value();
|
|
||||||
String version = ((ModOnly) annotation).version();
|
|
||||||
|
|
||||||
for (String mod : value) {
|
|
||||||
if (!loadedMods.contains(mod))
|
|
||||||
continue outer;
|
|
||||||
|
|
||||||
if (!loadedMods.get(mod).getVersion().startsWith(version))
|
|
||||||
continue outer;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
MineTweakerAPI.registerClass(cls);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (description != null)
|
|
||||||
logInfo("Loaded class registry: " + description);
|
|
||||||
}
|
|
||||||
} catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException ex) {
|
|
||||||
if(ex.getCause() instanceof NoClassDefFoundError) {
|
|
||||||
logInfo("Classes for registry " + registryClass + " not found, skipping");
|
|
||||||
} else {
|
|
||||||
logError("Error registering class registry", ex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Registers a class registry. Will attempt to resolve the given class name.
|
|
||||||
* Does nothing if the class could not be loaded.
|
|
||||||
*
|
|
||||||
* @param className class name to be loaded
|
|
||||||
* @return true if registration was successful
|
|
||||||
*/
|
|
||||||
public static boolean registerClassRegistry(String className) {
|
|
||||||
return registerClassRegistry(className, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Registers a class registry. Will attempt to resolve the given class name.
|
|
||||||
* Does nothing if the class could not be loaded.
|
|
||||||
*
|
|
||||||
* @param className class name to be loaded
|
|
||||||
* @param description
|
|
||||||
* @return true if registration was successful
|
|
||||||
*/
|
|
||||||
public static boolean registerClassRegistry(String className, String description) {
|
|
||||||
try {
|
|
||||||
registerClassRegistry(Class.forName(className), description);
|
|
||||||
return true;
|
|
||||||
} catch (ClassNotFoundException ex) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Registers an annotated class. A class is annotated with either @ZenClass
|
|
||||||
* or @ZenExpansion. Classes not annotated with either of these will be
|
|
||||||
* ignored.
|
|
||||||
*
|
|
||||||
* @param annotatedClass
|
|
||||||
*/
|
|
||||||
public static void registerClass(Class annotatedClass) {
|
|
||||||
// System.out.println("Registering " + annotatedClass.getName());
|
|
||||||
|
|
||||||
for (Annotation annotation : annotatedClass.getAnnotations()) {
|
|
||||||
if (annotation instanceof ZenExpansion) {
|
|
||||||
GlobalRegistry.registerExpansion(annotatedClass);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (annotation instanceof ZenClass) {
|
|
||||||
GlobalRegistry.registerNativeClass(annotatedClass);
|
|
||||||
}
|
|
||||||
if ((annotation instanceof BracketHandler) && IBracketHandler.class.isAssignableFrom(annotatedClass)) {
|
|
||||||
try {
|
|
||||||
IBracketHandler bracketHandler = (IBracketHandler) annotatedClass.newInstance();
|
|
||||||
registerBracketHandler(bracketHandler);
|
|
||||||
} catch (InstantiationException ex) {
|
|
||||||
Logger.getLogger(MineTweakerAPI.class.getName()).log(Level.SEVERE, null, ex);
|
|
||||||
} catch (IllegalAccessException ex) {
|
|
||||||
Logger.getLogger(MineTweakerAPI.class.getName()).log(Level.SEVERE, null, ex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Registers a global symbol. Global symbols are immediately accessible from
|
|
||||||
* anywhere in the scripts.
|
|
||||||
*
|
|
||||||
* @param name symbol name
|
|
||||||
* @param symbol symbol
|
|
||||||
*/
|
|
||||||
public static void registerGlobalSymbol(String name, IZenSymbol symbol) {
|
|
||||||
GlobalRegistry.registerGlobal(name, symbol);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Registers a recipe remover. Removers are called when the global
|
|
||||||
* minetweaker.remove() function is called.
|
|
||||||
*
|
|
||||||
* @param remover recipe remover
|
|
||||||
*/
|
|
||||||
public static void registerRemover(IRecipeRemover remover) {
|
|
||||||
GlobalRegistry.registerRemover(remover);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Registers a bracket handler. Is capable of converting the bracket syntax
|
|
||||||
* to an actual value. This new handler will be added last - it can thus not
|
|
||||||
* intercept values that are already handled by the system.
|
|
||||||
*
|
|
||||||
* @param handler bracket handler to be added
|
|
||||||
*/
|
|
||||||
public static void registerBracketHandler(IBracketHandler handler) {
|
|
||||||
GlobalRegistry.registerBracketHandler(handler);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a symbol that refers to a java method.
|
|
||||||
*
|
|
||||||
* @param cls class that contains the method
|
|
||||||
* @param name method name
|
|
||||||
* @param arguments method argument types
|
|
||||||
* @return corresponding symbol
|
|
||||||
*/
|
|
||||||
public static IZenSymbol getJavaStaticMethodSymbol(Class cls, String name, Class... arguments) {
|
|
||||||
IJavaMethod method = JavaMethod.get(GlobalRegistry.getTypeRegistry(), cls, name, arguments);
|
|
||||||
return new SymbolJavaStaticMethod(method);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a symbol that refers to a java getter. The getter must be a
|
|
||||||
* method with no arguments. The given symbol will act as a variable of
|
|
||||||
* which the value can be retrieved but not set.
|
|
||||||
*
|
|
||||||
* @param cls class that contains the getter method
|
|
||||||
* @param name name of the method
|
|
||||||
* @return corresponding symbol
|
|
||||||
*/
|
|
||||||
public static IZenSymbol getJavaStaticGetterSymbol(Class cls, String name) {
|
|
||||||
IJavaMethod method = JavaMethod.get(GlobalRegistry.getTypeRegistry(), cls, name);
|
|
||||||
return new SymbolJavaStaticGetter(method);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a symbol that refers to a static field. The field must be an
|
|
||||||
* existing public field in the given class. The field will act as a
|
|
||||||
* variable that can be retrieved but not set.
|
|
||||||
*
|
|
||||||
* @param cls class that contains the field
|
|
||||||
* @param name field name (must be public)
|
|
||||||
* @return corresponding symbol
|
|
||||||
*/
|
|
||||||
public static IZenSymbol getJavaStaticFieldSymbol(Class cls, String name) {
|
|
||||||
try {
|
|
||||||
Field field = cls.getField(name);
|
|
||||||
return new SymbolJavaStaticField(cls, field, GlobalRegistry.getTypeRegistry());
|
|
||||||
} catch (NoSuchFieldException ex) {
|
|
||||||
return null;
|
|
||||||
} catch (SecurityException ex) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Loads a Java method from an existing class.
|
|
||||||
*
|
|
||||||
* @param cls method class
|
|
||||||
* @param name method name
|
|
||||||
* @param arguments argument types
|
|
||||||
* @return java method
|
|
||||||
*/
|
|
||||||
public static IJavaMethod getJavaMethod(Class cls, String name, Class... arguments) {
|
|
||||||
return JavaMethod.get(GlobalRegistry.getTypeRegistry(), cls, name, arguments);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static IJEIRecipeRegistry getIjeiRecipeRegistry() {
|
|
||||||
return ijeiRecipeRegistry;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void setIjeiRecipeRegistry(IJEIRecipeRegistry ijeiRecipeRegistry) {
|
|
||||||
MineTweakerAPI.ijeiRecipeRegistry = ijeiRecipeRegistry;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,846 +0,0 @@
|
|||||||
package minetweaker;
|
|
||||||
|
|
||||||
import minetweaker.api.block.IBlock;
|
|
||||||
import minetweaker.api.block.IBlockDefinition;
|
|
||||||
import minetweaker.api.data.IData;
|
|
||||||
import minetweaker.api.entity.IEntityDefinition;
|
|
||||||
import minetweaker.api.event.*;
|
|
||||||
import minetweaker.api.formatting.IFormatter;
|
|
||||||
import minetweaker.api.game.IGame;
|
|
||||||
import minetweaker.api.item.IItemDefinition;
|
|
||||||
import minetweaker.api.item.IItemStack;
|
|
||||||
import minetweaker.api.item.WeightedItemStack;
|
|
||||||
import minetweaker.api.liquid.ILiquidDefinition;
|
|
||||||
import minetweaker.api.logger.MTLogger;
|
|
||||||
import minetweaker.api.mods.ILoadedMods;
|
|
||||||
import minetweaker.api.mods.IMod;
|
|
||||||
import minetweaker.api.oredict.IOreDict;
|
|
||||||
import minetweaker.api.oredict.IOreDictEntry;
|
|
||||||
import minetweaker.api.player.IPlayer;
|
|
||||||
import minetweaker.api.recipes.*;
|
|
||||||
import minetweaker.api.server.ICommandFunction;
|
|
||||||
import minetweaker.api.server.ICommandValidator;
|
|
||||||
import minetweaker.api.server.IServer;
|
|
||||||
import minetweaker.api.vanilla.IVanilla;
|
|
||||||
import minetweaker.api.vanilla.LootEntry;
|
|
||||||
import minetweaker.api.world.IBiome;
|
|
||||||
import minetweaker.runtime.IScriptProvider;
|
|
||||||
import minetweaker.util.EventList;
|
|
||||||
import minetweaker.util.IEventHandler;
|
|
||||||
import sun.awt.HeadlessToolkit;
|
|
||||||
|
|
||||||
import java.awt.*;
|
|
||||||
import java.awt.datatransfer.Clipboard;
|
|
||||||
import java.awt.datatransfer.StringSelection;
|
|
||||||
import java.util.*;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import static minetweaker.MineTweakerAPI.furnace;
|
|
||||||
import static minetweaker.MineTweakerAPI.server;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The implementation API is used by API implementations for internal
|
|
||||||
* communication and initialization.
|
|
||||||
*
|
|
||||||
* @author Stan Hebben
|
|
||||||
*/
|
|
||||||
public class MineTweakerImplementationAPI {
|
|
||||||
private static Set<IPlayer> blockInfoPlayers = new HashSet<IPlayer>();
|
|
||||||
private static IEventHandle blockEventHandler = null;
|
|
||||||
|
|
||||||
private static final Map<String, MineTweakerCommand> minetweakerCommands;
|
|
||||||
|
|
||||||
private static final Comparator<IItemDefinition> ITEM_COMPARATOR = new ItemComparator();
|
|
||||||
private static final Comparator<ILiquidDefinition> LIQUID_COMPARATOR = new LiquidComparator();
|
|
||||||
private static final Comparator<IBlockDefinition> BLOCK_COMPARATOR = new BlockComparator();
|
|
||||||
private static final Comparator<IEntityDefinition> ENTITY_COMPARATOR = new EntityComparator();
|
|
||||||
|
|
||||||
private static final ListenPlayerLoggedIn LISTEN_LOGIN = new ListenPlayerLoggedIn();
|
|
||||||
private static final ListenPlayerLoggedOut LISTEN_LOGOUT = new ListenPlayerLoggedOut();
|
|
||||||
private static final ListenBlockInfo LISTEN_BLOCK_INFO = new ListenBlockInfo();
|
|
||||||
private static final EventList<ReloadEvent> ONRELOAD = new EventList<ReloadEvent>();
|
|
||||||
private static final EventList<ReloadEvent> ONPOSTRELOAD = new EventList<ReloadEvent>();
|
|
||||||
|
|
||||||
static {
|
|
||||||
minetweakerCommands = new HashMap<String, MineTweakerCommand>();
|
|
||||||
|
|
||||||
minetweakerCommands.put("reload", new MineTweakerCommand(
|
|
||||||
"reload",
|
|
||||||
new String[]{
|
|
||||||
"/minetweaker reload",
|
|
||||||
" Reloads all scripts"
|
|
||||||
}, new ICommandFunction() {
|
|
||||||
@Override
|
|
||||||
public void execute(String[] arguments, IPlayer player) {
|
|
||||||
reload();
|
|
||||||
player.sendChat("Scripts reloaded");
|
|
||||||
}
|
|
||||||
}));
|
|
||||||
|
|
||||||
minetweakerCommands.put("names", new MineTweakerCommand(
|
|
||||||
"names",
|
|
||||||
new String[]{
|
|
||||||
"/minetweaker names",
|
|
||||||
" Outputs a list of all item names in the game to the minetweaker log"
|
|
||||||
}, new ICommandFunction() {
|
|
||||||
@Override
|
|
||||||
public void execute(String[] arguments, IPlayer player) {
|
|
||||||
List<IItemDefinition> items = MineTweakerAPI.game.getItems();
|
|
||||||
Collections.sort(items, ITEM_COMPARATOR);
|
|
||||||
for (IItemDefinition item : items) {
|
|
||||||
String displayName;
|
|
||||||
|
|
||||||
try {
|
|
||||||
displayName = ", " + item.makeStack(0).getDisplayName();
|
|
||||||
} catch (Throwable ex) {
|
|
||||||
// some mods (such as buildcraft) may throw
|
|
||||||
// exceptions when calling
|
|
||||||
// getDisplayName on an item stack that doesn't
|
|
||||||
// contain valid NBT data
|
|
||||||
// also seems to cause errors in some other
|
|
||||||
// cases too
|
|
||||||
displayName = " -- Name could not be retrieved due to an error: " + ex;
|
|
||||||
}
|
|
||||||
|
|
||||||
MineTweakerAPI.logCommand("<" + item.getId() + ">" + displayName);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (player != null) {
|
|
||||||
player.sendChat("List generated; see minetweaker.log in your minecraft dir");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}));
|
|
||||||
|
|
||||||
minetweakerCommands.put("liquids", new MineTweakerCommand(
|
|
||||||
"liquids",
|
|
||||||
new String[]{
|
|
||||||
"/minetweaker liquids",
|
|
||||||
" Outputs a list of all liquid names in the game to the minetweaker log"
|
|
||||||
}, new ICommandFunction() {
|
|
||||||
@Override
|
|
||||||
public void execute(String[] arguments, IPlayer player) {
|
|
||||||
List<ILiquidDefinition> liquids = MineTweakerAPI.game.getLiquids();
|
|
||||||
Collections.sort(liquids, LIQUID_COMPARATOR);
|
|
||||||
|
|
||||||
MineTweakerAPI.logCommand("Liquids:");
|
|
||||||
for (ILiquidDefinition liquid : liquids) {
|
|
||||||
MineTweakerAPI.logCommand("<liquid:" + liquid.getName() + ">, " + liquid.getDisplayName());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (player != null) {
|
|
||||||
player.sendChat("List generated; see minetweaker.log in your minecraft dir");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}));
|
|
||||||
|
|
||||||
minetweakerCommands.put("blocks", new MineTweakerCommand(
|
|
||||||
"blocks",
|
|
||||||
new String[]{
|
|
||||||
"/minetweaker blocks",
|
|
||||||
" Outputs a list of all blocks in the game to the minetweaker log"
|
|
||||||
}, new ICommandFunction() {
|
|
||||||
@Override
|
|
||||||
public void execute(String[] arguments, IPlayer player) {
|
|
||||||
List<IBlockDefinition> blocks = MineTweakerAPI.game.getBlocks();
|
|
||||||
Collections.sort(blocks, BLOCK_COMPARATOR);
|
|
||||||
|
|
||||||
MineTweakerAPI.logCommand("Blocks:");
|
|
||||||
for (IBlockDefinition block : blocks) {
|
|
||||||
MineTweakerAPI.logCommand("<block:" + block.getId() + ">, " + block.getDisplayName());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (player != null) {
|
|
||||||
player.sendChat("List generated; see minetweaker.log in your minecraft dir");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}));
|
|
||||||
|
|
||||||
minetweakerCommands.put("entities", new MineTweakerCommand(
|
|
||||||
"entities",
|
|
||||||
new String[]{
|
|
||||||
"/minetweaker entities",
|
|
||||||
" Outputs a list of all entity definitions in the game to the minetweaker log"
|
|
||||||
}, new ICommandFunction() {
|
|
||||||
@Override
|
|
||||||
public void execute(String[] arguments, IPlayer player) {
|
|
||||||
List<IEntityDefinition> entities = MineTweakerAPI.game.getEntities();
|
|
||||||
Collections.sort(entities, ENTITY_COMPARATOR);
|
|
||||||
|
|
||||||
MineTweakerAPI.logCommand("Entities:");
|
|
||||||
for (IEntityDefinition entity : entities) {
|
|
||||||
MineTweakerAPI.logCommand(entity.getId() + " -- " + entity.getName());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (player != null) {
|
|
||||||
player.sendChat("List generated; see minetweaker.log in your minecraft dir");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}));
|
|
||||||
|
|
||||||
minetweakerCommands.put("recipes", new MineTweakerCommand(
|
|
||||||
"recipes",
|
|
||||||
new String[]{
|
|
||||||
"/minetweaker recipes",
|
|
||||||
" Lists all crafting recipes in the game",
|
|
||||||
"/minetweaker recipes hand",
|
|
||||||
" Lists all crafting recipes for the item in your hand",
|
|
||||||
" Also copies the recipes to clipboard",
|
|
||||||
"/minetweaker recipes furnace",
|
|
||||||
" lists all furnace recipes in the game"
|
|
||||||
}, new ICommandFunction() {
|
|
||||||
@Override
|
|
||||||
public void execute(String[] arguments, IPlayer player) {
|
|
||||||
if (arguments.length == 0) {
|
|
||||||
if (player != null) {
|
|
||||||
player.sendChat("Generating recipe list, this could take a while...");
|
|
||||||
}
|
|
||||||
|
|
||||||
MineTweakerAPI.logCommand("Recipes:");
|
|
||||||
for (ICraftingRecipe recipe : MineTweakerAPI.recipes.getAll()) {
|
|
||||||
try {
|
|
||||||
MineTweakerAPI.logCommand(recipe.toCommandString());
|
|
||||||
} catch (Throwable ex) {
|
|
||||||
// Some recipes can result in an NPE :-(
|
|
||||||
if (recipe instanceof ShapedRecipe) {
|
|
||||||
ShapedRecipe shaped = (ShapedRecipe) recipe;
|
|
||||||
IItemStack out = shaped.getOutput();
|
|
||||||
MineTweakerAPI.logError("Could not dump recipe for " + out, ex);
|
|
||||||
} else if (recipe instanceof ShapelessRecipe) {
|
|
||||||
ShapelessRecipe shapeless = (ShapelessRecipe) recipe;
|
|
||||||
IItemStack out = shapeless.getOutput();
|
|
||||||
MineTweakerAPI.logError("Could not dump recipe for " + out, ex);
|
|
||||||
} else {
|
|
||||||
MineTweakerAPI.logError("Could not dump recipe", ex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (player != null) {
|
|
||||||
player.sendChat("Recipe list generated; see minetweaker.log in your minecraft dir");
|
|
||||||
}
|
|
||||||
} else if (arguments[0].equals("hand") && player != null) {
|
|
||||||
IItemStack item = player.getCurrentItem();
|
|
||||||
if (item != null) {
|
|
||||||
List<ICraftingRecipe> recipes = MineTweakerAPI.recipes.getRecipesFor(item.anyAmount());
|
|
||||||
if (recipes.isEmpty()) {
|
|
||||||
player.sendChat("No crafting recipes found for that item");
|
|
||||||
} else {
|
|
||||||
StringBuilder recipesString = new StringBuilder();
|
|
||||||
|
|
||||||
for (ICraftingRecipe recipe : recipes) {
|
|
||||||
MineTweakerAPI.logCommand(recipe.toCommandString());
|
|
||||||
player.sendChat(recipe.toCommandString());
|
|
||||||
recipesString.append(recipe.toCommandString()).append("\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
copyToClipboard(recipesString.toString());
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
player.sendChat("No item was found");
|
|
||||||
}
|
|
||||||
} else if (arguments[0].equals("furnace") && player != null) {
|
|
||||||
if (player != null) {
|
|
||||||
player.sendChat("Generating furnace list, this could take a while...");
|
|
||||||
}
|
|
||||||
|
|
||||||
MineTweakerAPI.logCommand("Furnace Recipes:");
|
|
||||||
for (IFurnaceRecipe recipe : furnace.getAll()) {
|
|
||||||
try {
|
|
||||||
MineTweakerAPI.logCommand(recipe.toCommandString());
|
|
||||||
} catch (Throwable ex) {
|
|
||||||
MineTweakerAPI.logError("Could not dump furnace recipe", ex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (player != null) {
|
|
||||||
player.sendChat("Furnace Recipe list generated; see minetweaker.log in your minecraft dir");
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (player != null) {
|
|
||||||
player.sendChat("Invalid arguments for recipes command");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}));
|
|
||||||
|
|
||||||
minetweakerCommands.put("inventory", new MineTweakerCommand(
|
|
||||||
"inventory",
|
|
||||||
new String[]{
|
|
||||||
"/minetweaker inventory",
|
|
||||||
" Lists all items in your inventory"
|
|
||||||
}, new ICommandFunction() {
|
|
||||||
@Override
|
|
||||||
public void execute(String[] arguments, IPlayer player) {
|
|
||||||
for (int i = 0; i < player.getInventorySize(); i++) {
|
|
||||||
IItemStack stack = player.getInventoryStack(i);
|
|
||||||
if (stack != null) {
|
|
||||||
player.sendChat(stack.toString());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}));
|
|
||||||
|
|
||||||
minetweakerCommands.put("hand", new MineTweakerCommand(
|
|
||||||
"hand",
|
|
||||||
new String[]{
|
|
||||||
"/minetweaker hand",
|
|
||||||
" Outputs the name of the item in your hand",
|
|
||||||
" Also copies the name to clipboard and prints",
|
|
||||||
" oredict entries"
|
|
||||||
}, new ICommandFunction() {
|
|
||||||
@Override
|
|
||||||
public void execute(String[] arguments, IPlayer player) {
|
|
||||||
IItemStack hand = player.getCurrentItem();
|
|
||||||
if (hand != null) {
|
|
||||||
String value = hand.toString();
|
|
||||||
player.sendChat(value);
|
|
||||||
copyToClipboard(value);
|
|
||||||
|
|
||||||
List<IOreDictEntry> entries = hand.getOres();
|
|
||||||
for (IOreDictEntry entry : entries) {
|
|
||||||
player.sendChat("Is in <ore:" + entry.getName() + ">");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}));
|
|
||||||
|
|
||||||
minetweakerCommands.put("oredict", new MineTweakerCommand(
|
|
||||||
"oredict",
|
|
||||||
new String[]{
|
|
||||||
"/minetweaker oredict",
|
|
||||||
" Outputs all ore dictionary entries in the game to the minetweaker log",
|
|
||||||
"/minetweaker oredict <name>",
|
|
||||||
" Outputs all items in the given ore dictionary entry to the minetweaker log"
|
|
||||||
}, new ICommandFunction() {
|
|
||||||
@Override
|
|
||||||
public void execute(String[] arguments, IPlayer player) {
|
|
||||||
if (arguments.length > 0) {
|
|
||||||
String entryName = arguments[0];
|
|
||||||
IOreDictEntry entry = MineTweakerAPI.oreDict.get(entryName);
|
|
||||||
if (entry.isEmpty()) {
|
|
||||||
player.sendChat("Entry doesn't exist");
|
|
||||||
return;
|
|
||||||
} else {
|
|
||||||
MineTweakerAPI.logCommand("Ore entries for " + entryName + ":");
|
|
||||||
for (IItemStack ore : entry.getItems()) {
|
|
||||||
MineTweakerAPI.logCommand(" " + ore);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
for (IOreDictEntry entry : MineTweakerAPI.oreDict.getEntries()) {
|
|
||||||
if (!entry.isEmpty()) {
|
|
||||||
MineTweakerAPI.logCommand("Ore entries for <ore:" + entry.getName() + "> :");
|
|
||||||
for (IItemStack ore : entry.getItems()) {
|
|
||||||
MineTweakerAPI.logCommand(" " + ore);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
player.sendChat("List generated; see minetweaker.log in your minecraft dir");
|
|
||||||
}
|
|
||||||
}));
|
|
||||||
|
|
||||||
minetweakerCommands.put("mods", new MineTweakerCommand(
|
|
||||||
"mods",
|
|
||||||
new String[]{
|
|
||||||
"/minetweaker mods",
|
|
||||||
" Outputs all active mod IDs and versions in the game"
|
|
||||||
}, new ICommandFunction() {
|
|
||||||
@Override
|
|
||||||
public void execute(String[] arguments, IPlayer player) {
|
|
||||||
MineTweakerAPI.logCommand("Mods list:");
|
|
||||||
for (IMod mod : MineTweakerAPI.loadedMods) {
|
|
||||||
String message = mod.getId() + " - " + mod.getName() + " - " + mod.getVersion();
|
|
||||||
player.sendChat(message);
|
|
||||||
MineTweakerAPI.logCommand("Mod: " + message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}));
|
|
||||||
|
|
||||||
minetweakerCommands.put("name", new MineTweakerCommand(
|
|
||||||
"name",
|
|
||||||
new String[]{
|
|
||||||
"/minetweaker name <id>",
|
|
||||||
" Outputs the name for the given item ID",
|
|
||||||
},
|
|
||||||
new ICommandFunction() {
|
|
||||||
@Override
|
|
||||||
public void execute(String[] arguments, IPlayer player) {
|
|
||||||
if (arguments.length < 1) {
|
|
||||||
player.sendChat("missing id parameter");
|
|
||||||
} else {
|
|
||||||
try {
|
|
||||||
int id = Integer.parseInt(arguments[0]);
|
|
||||||
IItemDefinition definition = platform.getItemDefinition(id);
|
|
||||||
if (definition == null) {
|
|
||||||
player.sendChat("no such item");
|
|
||||||
} else {
|
|
||||||
StringBuilder description = new StringBuilder();
|
|
||||||
description.append('<');
|
|
||||||
description.append(definition.getId());
|
|
||||||
description.append('>');
|
|
||||||
player.sendChat(description.toString());
|
|
||||||
}
|
|
||||||
} catch (NumberFormatException e) {
|
|
||||||
MineTweakerAPI.logCommand("ID must be an integer");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}));
|
|
||||||
|
|
||||||
minetweakerCommands.put("seeds", new MineTweakerCommand(
|
|
||||||
"seeds",
|
|
||||||
new String[]{
|
|
||||||
"/minetweaker seeds",
|
|
||||||
" Prints all seeds registered",
|
|
||||||
" for tall grass"
|
|
||||||
}, new ICommandFunction() {
|
|
||||||
@Override
|
|
||||||
public void execute(String[] arguments, IPlayer player) {
|
|
||||||
MineTweakerAPI.logCommand("Seeds:");
|
|
||||||
for (WeightedItemStack seed : MineTweakerAPI.vanilla.getSeeds().getSeeds()) {
|
|
||||||
String message = seed.getStack() + " - " + (int) seed.getChance();
|
|
||||||
player.sendChat(message);
|
|
||||||
MineTweakerAPI.logCommand("Seed: " + message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}));
|
|
||||||
|
|
||||||
minetweakerCommands.put("loot", new MineTweakerCommand(
|
|
||||||
"seeds",
|
|
||||||
new String[]{
|
|
||||||
"/minetweaker seeds",
|
|
||||||
" Prints all seeds registered",
|
|
||||||
" for tall grass"
|
|
||||||
}, new ICommandFunction() {
|
|
||||||
@Override
|
|
||||||
public void execute(String[] arguments, IPlayer player) {
|
|
||||||
if (arguments.length == 0) {
|
|
||||||
MineTweakerAPI.logCommand("Loot chest contents:");
|
|
||||||
List<String> types = MineTweakerAPI.vanilla.getLoot().getLootTypes();
|
|
||||||
Collections.sort(types);
|
|
||||||
for (String lootType : types) {
|
|
||||||
MineTweakerAPI.logCommand("Loot type: " + lootType);
|
|
||||||
|
|
||||||
List<LootEntry> entries = MineTweakerAPI.vanilla.getLoot().getLoot(lootType);
|
|
||||||
for (LootEntry entry : entries) {
|
|
||||||
MineTweakerAPI.logCommand(" " + entry.toString());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
player.sendChat("List generated; see minetweaker.log in your minecraft dir");
|
|
||||||
} else {
|
|
||||||
MineTweakerAPI.logCommand("Loot for type: " + arguments[0]);
|
|
||||||
|
|
||||||
List<LootEntry> entries = MineTweakerAPI.vanilla.getLoot().getLoot(arguments[0]);
|
|
||||||
for (LootEntry entry : entries) {
|
|
||||||
MineTweakerAPI.logCommand(" " + entry.toString());
|
|
||||||
}
|
|
||||||
|
|
||||||
player.sendChat("List generated; see minetweaker.log in your minecraft dir");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}));
|
|
||||||
|
|
||||||
minetweakerCommands.put("wiki", new MineTweakerCommand(
|
|
||||||
"wiki",
|
|
||||||
new String[]{
|
|
||||||
"/minetweaker wiki",
|
|
||||||
" Opens your browser with the wiki"
|
|
||||||
}, new ICommandFunction() {
|
|
||||||
@Override
|
|
||||||
public void execute(String[] arguments, IPlayer player) {
|
|
||||||
player.openBrowser("http://minetweaker3.powerofbytes.com/wiki/");
|
|
||||||
}
|
|
||||||
}));
|
|
||||||
|
|
||||||
minetweakerCommands.put("bugs", new MineTweakerCommand(
|
|
||||||
"bugs",
|
|
||||||
new String[]{
|
|
||||||
"/minetweaker bugs",
|
|
||||||
" Opens your browser with the GitHub bug tracker"
|
|
||||||
}, new ICommandFunction() {
|
|
||||||
@Override
|
|
||||||
public void execute(String[] arguments, IPlayer player) {
|
|
||||||
player.openBrowser("https://github.com/stanhebben/MineTweaker3/issues");
|
|
||||||
}
|
|
||||||
}));
|
|
||||||
|
|
||||||
minetweakerCommands.put("forum", new MineTweakerCommand(
|
|
||||||
"forum",
|
|
||||||
new String[]{
|
|
||||||
"/minetweaker forum",
|
|
||||||
" Opens your browser with the forum"
|
|
||||||
}, new ICommandFunction() {
|
|
||||||
@Override
|
|
||||||
public void execute(String[] arguments, IPlayer player) {
|
|
||||||
player.openBrowser("http://minetweaker3.powerofbytes.com/forum");
|
|
||||||
}
|
|
||||||
}));
|
|
||||||
|
|
||||||
minetweakerCommands.put("biomes", new MineTweakerCommand(
|
|
||||||
"biomes",
|
|
||||||
new String[]{
|
|
||||||
"/minetweaker biomes",
|
|
||||||
" Lists all the biomes in the game"
|
|
||||||
}, new ICommandFunction() {
|
|
||||||
@Override
|
|
||||||
public void execute(String[] arguments, IPlayer player) {
|
|
||||||
MineTweakerAPI.logCommand("Biomes:");
|
|
||||||
|
|
||||||
for (IBiome biome : MineTweakerAPI.game.getBiomes()) {
|
|
||||||
MineTweakerAPI.logCommand(" " + biome.getName());
|
|
||||||
}
|
|
||||||
|
|
||||||
player.sendChat("Biome list generated; see minetweaker.log in your minecraft dir");
|
|
||||||
}
|
|
||||||
}));
|
|
||||||
|
|
||||||
minetweakerCommands.put("blockinfo", new MineTweakerCommand(
|
|
||||||
"blockinfo",
|
|
||||||
new String[]{
|
|
||||||
"/minetweaker blockinfo",
|
|
||||||
" Activates or deactivates block reader. In block info mode,",
|
|
||||||
" right-click a block to see ID, meta and tile entity data"
|
|
||||||
}, new ICommandFunction() {
|
|
||||||
@Override
|
|
||||||
public void execute(String[] arguments, IPlayer player) {
|
|
||||||
if (blockInfoPlayers.isEmpty()) {
|
|
||||||
blockEventHandler = events.onPlayerInteract(LISTEN_BLOCK_INFO);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (blockInfoPlayers.contains(player)) {
|
|
||||||
blockInfoPlayers.remove(player);
|
|
||||||
player.sendChat("Block info mode deactivated.");
|
|
||||||
} else {
|
|
||||||
blockInfoPlayers.add(player);
|
|
||||||
player.sendChat("Block info mode activated. Right-click a block to see its data.");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (blockInfoPlayers.isEmpty()) {
|
|
||||||
blockEventHandler.close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Access point to the event handler implementation.
|
|
||||||
*/
|
|
||||||
public static final MTEventManager events = new MTEventManager();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Access point to the internal logger instance.
|
|
||||||
*/
|
|
||||||
public static final MTLogger logger = new MTLogger();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Access point to general platform functions.
|
|
||||||
*/
|
|
||||||
public static IPlatformFunctions platform = null;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Initializes the MineTweaker API.
|
|
||||||
*
|
|
||||||
* @param oreDict ore dictionary interface
|
|
||||||
* @param recipes recipe manager interface
|
|
||||||
* @param furnace furnace manager interface
|
|
||||||
* @param game game interface
|
|
||||||
* @param mods mods interface
|
|
||||||
* @param formatter formatter interface
|
|
||||||
* @param vanilla vanilla interface
|
|
||||||
*/
|
|
||||||
public static void init(
|
|
||||||
IOreDict oreDict,
|
|
||||||
IRecipeManager recipes,
|
|
||||||
IFurnaceManager furnace,
|
|
||||||
IGame game,
|
|
||||||
ILoadedMods mods,
|
|
||||||
IFormatter formatter,
|
|
||||||
IVanilla vanilla) {
|
|
||||||
MineTweakerAPI.oreDict = oreDict;
|
|
||||||
MineTweakerAPI.recipes = recipes;
|
|
||||||
MineTweakerAPI.furnace = furnace;
|
|
||||||
MineTweakerAPI.game = game;
|
|
||||||
MineTweakerAPI.loadedMods = mods;
|
|
||||||
MineTweakerAPI.format = formatter;
|
|
||||||
MineTweakerAPI.vanilla = vanilla;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Register an event handler to be fired upon reload.
|
|
||||||
*
|
|
||||||
* @param handler
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public static IEventHandle onReloadEvent(IEventHandler<ReloadEvent> handler) {
|
|
||||||
return ONRELOAD.add(handler);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static IEventHandle onPostReload(IEventHandler<ReloadEvent> handler) {
|
|
||||||
return ONPOSTRELOAD.add(handler);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Must be called upon server start.
|
|
||||||
*
|
|
||||||
* @param server server interface
|
|
||||||
*/
|
|
||||||
public static void onServerStart(IServer server) {
|
|
||||||
MineTweakerAPI.server = server;
|
|
||||||
reload();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Must be called upon server stop.
|
|
||||||
*/
|
|
||||||
public static void onServerStop() {
|
|
||||||
MineTweakerAPI.server = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the script provider.
|
|
||||||
*
|
|
||||||
* @param provider script provider
|
|
||||||
*/
|
|
||||||
public static void setScriptProvider(IScriptProvider provider) {
|
|
||||||
MineTweakerAPI.tweaker.setScriptProvider(provider);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Called to reload scripts. Must be called after setting a new script
|
|
||||||
* provider in order to reload scripts.
|
|
||||||
*/
|
|
||||||
public static void reload() {
|
|
||||||
blockInfoPlayers.clear();
|
|
||||||
|
|
||||||
logger.clear();
|
|
||||||
events.clear();
|
|
||||||
|
|
||||||
if (MineTweakerAPI.server != null) {
|
|
||||||
events.onPlayerLoggedIn(LISTEN_LOGIN);
|
|
||||||
events.onPlayerLoggedOut(LISTEN_LOGOUT);
|
|
||||||
}
|
|
||||||
//
|
|
||||||
// byte[] currentScript = MineTweakerAPI.tweaker.getScriptData();
|
|
||||||
// if (currentScript != null) {
|
|
||||||
// System.out.println("Already loaded a script before");
|
|
||||||
//
|
|
||||||
// // alread loaded a script
|
|
||||||
// byte[] stagedScript = MineTweakerAPI.tweaker.getStagedScriptData();
|
|
||||||
//
|
|
||||||
// if (Arrays.equals(currentScript, stagedScript)) {
|
|
||||||
// System.out.println("No reload needed");
|
|
||||||
// return; // no reload necessary
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// if (MineTweakerAPI.game.isLocked()) {
|
|
||||||
// System.out.println("Reload blocked");
|
|
||||||
// MineTweakerAPI.game.signalLockError();
|
|
||||||
// return;
|
|
||||||
// }
|
|
||||||
// } else {
|
|
||||||
// System.out.println("First time loading a script, go ahead");
|
|
||||||
// }
|
|
||||||
|
|
||||||
MineTweakerAPI.tweaker.rollback();
|
|
||||||
if (MineTweakerAPI.server != null) {
|
|
||||||
if (!MineTweakerAPI.server.isCommandAdded("minetweaker")) {
|
|
||||||
server.addCommand("minetweaker", "", new String[]{"mt", "crafttweaker", "ct"}, new ICommandFunction() {
|
|
||||||
@Override
|
|
||||||
public void execute(String[] arguments, IPlayer player) {
|
|
||||||
if (arguments.length == 0) {
|
|
||||||
player.sendChat("Please provide a command. Use /mt help for more info.");
|
|
||||||
} else if (arguments[0].equals("help")) {
|
|
||||||
String[] keys = minetweakerCommands.keySet().toArray(new String[minetweakerCommands.size()]);
|
|
||||||
Arrays.sort(keys);
|
|
||||||
for (String key : keys) {
|
|
||||||
for (String helpMessage : minetweakerCommands.get(key).description) {
|
|
||||||
player.sendChat(helpMessage);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
MineTweakerCommand command = minetweakerCommands.get(arguments[0]);
|
|
||||||
if (command == null) {
|
|
||||||
player.sendChat("No such minetweaker command available");
|
|
||||||
} else {
|
|
||||||
command.function.execute(Arrays.copyOfRange(arguments, 1, arguments.length), player);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}, new ICommandValidator() {
|
|
||||||
@Override
|
|
||||||
public boolean canExecute(IPlayer player) {
|
|
||||||
return server.isOp(player);
|
|
||||||
}
|
|
||||||
}, null);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
ONRELOAD.publish(new ReloadEvent());
|
|
||||||
|
|
||||||
MineTweakerAPI.tweaker.load();
|
|
||||||
|
|
||||||
if (MineTweakerAPI.server != null) {
|
|
||||||
platform.distributeScripts(MineTweakerAPI.tweaker.getScriptData());
|
|
||||||
}
|
|
||||||
|
|
||||||
ONPOSTRELOAD.publish(new ReloadEvent());
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Adds a new minetweaker command. Can be called with /mt <command&;gt;
|
|
||||||
* <arguments>.
|
|
||||||
*
|
|
||||||
* @param name command name
|
|
||||||
* @param description description strings
|
|
||||||
* @param function command implementation
|
|
||||||
*/
|
|
||||||
public static void addMineTweakerCommand(String name, String[] description, ICommandFunction function) {
|
|
||||||
MineTweakerAPI.apply(new AddMineTweakerCommandAction(new MineTweakerCommand(name, description, function)));
|
|
||||||
}
|
|
||||||
|
|
||||||
// ##############################
|
|
||||||
// ### Private static methods ###
|
|
||||||
// ##############################
|
|
||||||
|
|
||||||
private static void copyToClipboard(String value) {
|
|
||||||
StringSelection stringSelection = new StringSelection(value);
|
|
||||||
if (!(Toolkit.getDefaultToolkit() instanceof HeadlessToolkit)) {
|
|
||||||
Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
|
|
||||||
clipboard.setContents(stringSelection, null);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// ############################
|
|
||||||
// ### Public inner classes ###
|
|
||||||
// ############################
|
|
||||||
|
|
||||||
public static class ReloadEvent {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// ######################
|
|
||||||
// ### Action classes ###
|
|
||||||
// ######################
|
|
||||||
|
|
||||||
private static class AddMineTweakerCommandAction implements IUndoableAction {
|
|
||||||
private final MineTweakerCommand command;
|
|
||||||
|
|
||||||
public AddMineTweakerCommandAction(MineTweakerCommand command) {
|
|
||||||
this.command = command;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void apply() {
|
|
||||||
if (!minetweakerCommands.containsKey(command.name)) {
|
|
||||||
minetweakerCommands.put(command.name, command);
|
|
||||||
} else {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean canUndo() {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void undo() {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String describe() {
|
|
||||||
if (!minetweakerCommands.containsKey(command.name)) {
|
|
||||||
return "Adding minetweaker command " + command.name;
|
|
||||||
}
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String describeUndo() {
|
|
||||||
return "tried to remove command: " + command.name + " failed. THIS IS NOT AN ERROR!";
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Object getOverrideKey() {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// #############################
|
|
||||||
// ### Private inner classes ###
|
|
||||||
// #############################
|
|
||||||
|
|
||||||
private static class MineTweakerCommand {
|
|
||||||
private final String name;
|
|
||||||
private final String[] description;
|
|
||||||
private final ICommandFunction function;
|
|
||||||
|
|
||||||
public MineTweakerCommand(String name, String[] description, ICommandFunction function) {
|
|
||||||
this.name = name;
|
|
||||||
this.description = description;
|
|
||||||
this.function = function;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static class ItemComparator implements Comparator<IItemDefinition> {
|
|
||||||
@Override
|
|
||||||
public int compare(IItemDefinition o1, IItemDefinition o2) {
|
|
||||||
return o1.getId().compareTo(o2.getId());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static class LiquidComparator implements Comparator<ILiquidDefinition> {
|
|
||||||
@Override
|
|
||||||
public int compare(ILiquidDefinition o1, ILiquidDefinition o2) {
|
|
||||||
return o1.getName().compareTo(o2.getName());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static class BlockComparator implements Comparator<IBlockDefinition> {
|
|
||||||
@Override
|
|
||||||
public int compare(IBlockDefinition o1, IBlockDefinition o2) {
|
|
||||||
return o1.getId().compareTo(o2.getId());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static class EntityComparator implements Comparator<IEntityDefinition> {
|
|
||||||
@Override
|
|
||||||
public int compare(IEntityDefinition o1, IEntityDefinition o2) {
|
|
||||||
return o1.getId().compareTo(o2.getId());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static class ListenPlayerLoggedIn implements IEventHandler<PlayerLoggedInEvent> {
|
|
||||||
@Override
|
|
||||||
public void handle(PlayerLoggedInEvent event) {
|
|
||||||
if (MineTweakerAPI.server != null && MineTweakerAPI.server.isOp(event.getPlayer())) {
|
|
||||||
logger.addPlayer(event.getPlayer());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static class ListenPlayerLoggedOut implements IEventHandler<PlayerLoggedOutEvent> {
|
|
||||||
@Override
|
|
||||||
public void handle(PlayerLoggedOutEvent event) {
|
|
||||||
logger.removePlayer(event.getPlayer());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static class ListenBlockInfo implements IEventHandler<PlayerInteractEvent> {
|
|
||||||
@Override
|
|
||||||
public void handle(PlayerInteractEvent event) {
|
|
||||||
if (blockInfoPlayers.contains(event.getPlayer())) {
|
|
||||||
IBlock block = event.getBlock();
|
|
||||||
event.getPlayer().sendChat("Block ID: " + block.getDefinition().getId());
|
|
||||||
event.getPlayer().sendChat("Meta value: " + block.getMeta());
|
|
||||||
IData data = block.getTileData();
|
|
||||||
if (data != null) {
|
|
||||||
event.getPlayer().sendChat("Tile entity data: " + data.asString());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,22 +0,0 @@
|
|||||||
package minetweaker;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Base implementation for a non-undoable action.
|
|
||||||
*
|
|
||||||
* @author Stan Hebben
|
|
||||||
*/
|
|
||||||
public abstract class OneWayAction implements IUndoableAction {
|
|
||||||
@Override
|
|
||||||
public boolean canUndo() {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void undo() {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String describeUndo() {
|
|
||||||
return "impossibru!";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,96 +0,0 @@
|
|||||||
/*
|
|
||||||
* To change this license header, choose License Headers in Project Properties.
|
|
||||||
* To change this template file, choose Tools | Templates
|
|
||||||
* and open the template in the editor.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package minetweaker.expand;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
import minetweaker.MineTweakerAPI;
|
|
||||||
import minetweaker.MineTweakerImplementationAPI;
|
|
||||||
import minetweaker.api.chat.IChatMessage;
|
|
||||||
import minetweaker.api.data.DataString;
|
|
||||||
import minetweaker.api.data.IData;
|
|
||||||
import minetweaker.api.formatting.IFormattedText;
|
|
||||||
import stanhebben.zenscript.annotations.OperatorType;
|
|
||||||
import stanhebben.zenscript.annotations.Optional;
|
|
||||||
import stanhebben.zenscript.annotations.ZenCaster;
|
|
||||||
import stanhebben.zenscript.annotations.ZenExpansion;
|
|
||||||
import stanhebben.zenscript.annotations.ZenMethod;
|
|
||||||
import stanhebben.zenscript.annotations.ZenOperator;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @author Stanneke
|
|
||||||
*/
|
|
||||||
@ZenExpansion("string")
|
|
||||||
public class ExpandString {
|
|
||||||
@ZenOperator(OperatorType.ADD)
|
|
||||||
public static IFormattedText add(String str, IFormattedText formattedText) {
|
|
||||||
return MineTweakerAPI.format.string(str).add(formattedText);
|
|
||||||
}
|
|
||||||
|
|
||||||
@ZenOperator(OperatorType.CAT)
|
|
||||||
public static IFormattedText cat(String str, IFormattedText formattedText) {
|
|
||||||
return add(str, formattedText);
|
|
||||||
}
|
|
||||||
|
|
||||||
@ZenCaster
|
|
||||||
public static IData asData(String value) {
|
|
||||||
return new DataString(value);
|
|
||||||
}
|
|
||||||
|
|
||||||
@ZenCaster
|
|
||||||
public static IChatMessage asChatMessage(String value) {
|
|
||||||
return MineTweakerImplementationAPI.platform.getMessage(value);
|
|
||||||
}
|
|
||||||
|
|
||||||
@ZenCaster
|
|
||||||
public static IFormattedText asFormattedText(String value) {
|
|
||||||
return MineTweakerAPI.format.string(value);
|
|
||||||
}
|
|
||||||
|
|
||||||
@ZenMethod
|
|
||||||
public static List<String> split(String value, String separator, @Optional int maximum) {
|
|
||||||
List<String> result = new ArrayList<String>();
|
|
||||||
int minIndex = 0;
|
|
||||||
int numSplits = 0;
|
|
||||||
|
|
||||||
while (minIndex + separator.length() <= value.length()) {
|
|
||||||
int index = value.indexOf(separator, minIndex);
|
|
||||||
if (index < 0)
|
|
||||||
break;
|
|
||||||
result.add(value.substring(minIndex, index));
|
|
||||||
minIndex = index + separator.length();
|
|
||||||
|
|
||||||
numSplits++;
|
|
||||||
if (maximum > 0 && numSplits >= maximum)
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
result.add(value.substring(minIndex));
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
@ZenMethod
|
|
||||||
public static int indexOf(String value, String needle) {
|
|
||||||
return value.indexOf(needle);
|
|
||||||
}
|
|
||||||
|
|
||||||
@ZenMethod
|
|
||||||
public static int indexOf(String value, String needle, int fromIndex) {
|
|
||||||
return value.indexOf(needle, fromIndex);
|
|
||||||
}
|
|
||||||
|
|
||||||
@ZenMethod
|
|
||||||
public static int lastIndexOf(String value, String needle) {
|
|
||||||
return value.lastIndexOf(needle);
|
|
||||||
}
|
|
||||||
|
|
||||||
@ZenMethod
|
|
||||||
public static int lastIndexOf(String value, String needle, int fromIndex) {
|
|
||||||
return value.lastIndexOf(value, fromIndex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,26 +0,0 @@
|
|||||||
/*
|
|
||||||
* To change this license header, choose License Headers in Project Properties.
|
|
||||||
* To change this template file, choose Tools | Templates
|
|
||||||
* and open the template in the editor.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package minetweaker.runtime;
|
|
||||||
|
|
||||||
import minetweaker.MineTweakerAPI;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @author Stan
|
|
||||||
*/
|
|
||||||
public class GlobalFunctions {
|
|
||||||
private GlobalFunctions() {
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void print(String message) {
|
|
||||||
MineTweakerAPI.logInfo(message);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean isNull(Object any){
|
|
||||||
return any == null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,347 +0,0 @@
|
|||||||
/*
|
|
||||||
* To change this license header, choose License Headers in Project Properties.
|
|
||||||
* To change this template file, choose Tools | Templates
|
|
||||||
* and open the template in the editor.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package minetweaker.runtime;
|
|
||||||
|
|
||||||
import minetweaker.*;
|
|
||||||
import minetweaker.api.item.*;
|
|
||||||
import stanhebben.zenscript.*;
|
|
||||||
import stanhebben.zenscript.annotations.*;
|
|
||||||
import stanhebben.zenscript.compiler.*;
|
|
||||||
import stanhebben.zenscript.expression.partial.*;
|
|
||||||
import stanhebben.zenscript.parser.*;
|
|
||||||
import stanhebben.zenscript.symbols.*;
|
|
||||||
import stanhebben.zenscript.type.*;
|
|
||||||
import stanhebben.zenscript.type.natives.*;
|
|
||||||
import stanhebben.zenscript.util.*;
|
|
||||||
|
|
||||||
import java.lang.annotation.*;
|
|
||||||
import java.lang.reflect.*;
|
|
||||||
import java.util.*;
|
|
||||||
import java.util.logging.*;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @author Stan
|
|
||||||
*/
|
|
||||||
public class GlobalRegistry {
|
|
||||||
private static final Map<String, IZenSymbol> globals = new HashMap<String, IZenSymbol>();
|
|
||||||
private static final List<IRecipeRemover> removers = new ArrayList<IRecipeRemover>();
|
|
||||||
private static final List<IBracketHandler> bracketHandlers = new ArrayList<IBracketHandler>();
|
|
||||||
private static final TypeRegistry types = new TypeRegistry();
|
|
||||||
private static final SymbolPackage root = new SymbolPackage("<root>");
|
|
||||||
private static final IZenErrorLogger errors = new MyErrorLogger();
|
|
||||||
private static final IZenCompileEnvironment environment = new MyCompileEnvironment();
|
|
||||||
private static final Map<String, TypeExpansion> expansions = new HashMap<String, TypeExpansion>();
|
|
||||||
|
|
||||||
static {
|
|
||||||
registerGlobal("print", getStaticFunction(GlobalFunctions.class, "print", String.class));
|
|
||||||
registerGlobal("isNull", getStaticFunction(GlobalFunctions.class, "isNull", Object.class));
|
|
||||||
registerGlobal("max", getStaticFunction(Math.class, "max", int.class, int.class));
|
|
||||||
registerGlobal("min", getStaticFunction(Math.class, "min", int.class, int.class));
|
|
||||||
registerGlobal("pow", getStaticFunction(Math.class, "pow", double.class, double.class));
|
|
||||||
}
|
|
||||||
public static IZenErrorLogger getErrors() {
|
|
||||||
return errors;
|
|
||||||
}
|
|
||||||
|
|
||||||
private GlobalRegistry() {
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void registerGlobal(String name, IZenSymbol symbol) {
|
|
||||||
if (globals.containsKey(name)) {
|
|
||||||
throw new IllegalArgumentException("symbol already exists: " + name);
|
|
||||||
}
|
|
||||||
|
|
||||||
globals.put(name, symbol);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void registerExpansion(Class<?> cls) {
|
|
||||||
try {
|
|
||||||
for (Annotation annotation : cls.getAnnotations()) {
|
|
||||||
if (annotation instanceof ZenExpansion) {
|
|
||||||
ZenExpansion eAnnotation = (ZenExpansion) annotation;
|
|
||||||
if (!expansions.containsKey(eAnnotation.value())) {
|
|
||||||
expansions.put(eAnnotation.value(), new TypeExpansion(eAnnotation.value()));
|
|
||||||
}
|
|
||||||
expansions.get(eAnnotation.value()).expand(cls, types);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (Throwable ex) {
|
|
||||||
errors.error("Error while applying expansion", ex);
|
|
||||||
ex.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void registerRemover(IRecipeRemover remover) {
|
|
||||||
removers.add(remover);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void registerBracketHandler(IBracketHandler handler) {
|
|
||||||
bracketHandlers.add(handler);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void registerNativeClass(Class<?> cls) {
|
|
||||||
//MineTweakerAPI.logInfo("Registering class: " + cls);
|
|
||||||
try {
|
|
||||||
|
|
||||||
ZenTypeNative type = new ZenTypeNative(cls);
|
|
||||||
type.complete(types);
|
|
||||||
|
|
||||||
root.put(type.getName(), new SymbolType(type), errors);
|
|
||||||
} catch (Throwable ex) {
|
|
||||||
MineTweakerAPI.logError("Error for " + cls, ex);
|
|
||||||
ex.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static TypeRegistry getTypeRegistry() {
|
|
||||||
return types;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void remove(IIngredient ingredient) {
|
|
||||||
for (IRecipeRemover remover : removers) {
|
|
||||||
remover.remove(ingredient);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static IZenSymbol resolveBracket(IEnvironmentGlobal environment, List<Token> tokens) {
|
|
||||||
for (IBracketHandler handler : bracketHandlers) {
|
|
||||||
IZenSymbol symbol = handler.resolve(environment, tokens);
|
|
||||||
if (symbol != null) {
|
|
||||||
return symbol;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static IZenSymbol getStaticFunction(Class cls, String name, Class... arguments) {
|
|
||||||
IJavaMethod method = JavaMethod.get(types, cls, name, arguments);
|
|
||||||
if (method == null)
|
|
||||||
return null;
|
|
||||||
return new SymbolJavaStaticMethod(method);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static IZenSymbol getStaticField(Class cls, String name) {
|
|
||||||
try {
|
|
||||||
Field field = cls.getDeclaredField(name);
|
|
||||||
return new SymbolJavaStaticField(cls, field, types);
|
|
||||||
} catch (NoSuchFieldException ex) {
|
|
||||||
Logger.getLogger(GlobalRegistry.class.getName()).log(Level.SEVERE, null, ex);
|
|
||||||
return null;
|
|
||||||
} catch (SecurityException ex) {
|
|
||||||
Logger.getLogger(GlobalRegistry.class.getName()).log(Level.SEVERE, null, ex);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static IEnvironmentGlobal makeGlobalEnvironment(Map<String, byte[]> classes) {
|
|
||||||
return new MyGlobalEnvironment(classes);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static class MyErrorLogger implements IZenErrorLogger {
|
|
||||||
@Override
|
|
||||||
public void error(ZenPosition position, String message) {
|
|
||||||
if (position == null) {
|
|
||||||
MineTweakerAPI.logError("system: " + message);
|
|
||||||
} else {
|
|
||||||
MineTweakerAPI.logError(position + ": " + message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void warning(ZenPosition position, String message) {
|
|
||||||
if (position == null) {
|
|
||||||
MineTweakerAPI.logWarning("system: " + message);
|
|
||||||
} else {
|
|
||||||
MineTweakerAPI.logWarning(position + ": " + message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void info(ZenPosition position, String message) {
|
|
||||||
if (position == null) {
|
|
||||||
MineTweakerAPI.logInfo("system: " + message);
|
|
||||||
} else {
|
|
||||||
MineTweakerAPI.logInfo(position + ": " + message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void error(String message) {
|
|
||||||
error(null, message);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void error(String message, Throwable e) {
|
|
||||||
error(null, message);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void warning(String message) {
|
|
||||||
warning(null, message);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void info(String message) {
|
|
||||||
info(null, message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static class MyCompileEnvironment implements IZenCompileEnvironment {
|
|
||||||
@Override
|
|
||||||
public IZenErrorLogger getErrorLogger() {
|
|
||||||
return errors;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public IZenSymbol getGlobal(String name) {
|
|
||||||
if (globals.containsKey(name)) {
|
|
||||||
return globals.get(name);
|
|
||||||
} else {
|
|
||||||
return root.get(name);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public IZenSymbol getBracketed(IEnvironmentGlobal environment, List<Token> tokens) {
|
|
||||||
return resolveBracket(environment, tokens);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public TypeRegistry getTypeRegistry() {
|
|
||||||
return types;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public TypeExpansion getExpansion(String type) {
|
|
||||||
return expansions.get(type);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setRegistry(IZenRegistry registry) {
|
|
||||||
//NO-OP
|
|
||||||
throw new UnsupportedOperationException("Registry is not local");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static class MyGlobalEnvironment implements IEnvironmentGlobal {
|
|
||||||
private final Map<String, byte[]> classes;
|
|
||||||
private final Map<String, IZenSymbol> symbols;
|
|
||||||
private final ClassNameGenerator generator;
|
|
||||||
|
|
||||||
public MyGlobalEnvironment(Map<String, byte[]> classes) {
|
|
||||||
this.classes = classes;
|
|
||||||
symbols = new HashMap<String, IZenSymbol>();
|
|
||||||
generator = new ClassNameGenerator();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public IZenCompileEnvironment getEnvironment() {
|
|
||||||
return environment;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public TypeExpansion getExpansion(String name) {
|
|
||||||
return expansions.get(name);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String makeClassName() {
|
|
||||||
return generator.generate();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String makeClassNameWithMiddleName(String middleName) {
|
|
||||||
return generator.generateWithMiddleName(middleName);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean containsClass(String name) {
|
|
||||||
return classes.containsKey(name);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void putClass(String name, byte[] data) {
|
|
||||||
classes.put(name, data);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public IPartialExpression getValue(String name, ZenPosition position) {
|
|
||||||
if (symbols.containsKey(name)) {
|
|
||||||
return symbols.get(name).instance(position);
|
|
||||||
} else if (globals.containsKey(name)) {
|
|
||||||
return globals.get(name).instance(position);
|
|
||||||
} else {
|
|
||||||
IZenSymbol pkg = root.get(name);
|
|
||||||
if (pkg == null) {
|
|
||||||
return null;
|
|
||||||
} else {
|
|
||||||
return pkg.instance(position);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void putValue(String name, IZenSymbol value, ZenPosition position) {
|
|
||||||
if (symbols.containsKey(name)) {
|
|
||||||
error(position, "Value already defined in this scope: " + name);
|
|
||||||
} else {
|
|
||||||
symbols.put(name, value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ZenType getType(Type type) {
|
|
||||||
return types.getType(type);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void error(ZenPosition position, String message) {
|
|
||||||
MineTweakerAPI.logError(position.toString() + " > " + message);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void warning(ZenPosition position, String message) {
|
|
||||||
MineTweakerAPI.logWarning(position.toString() + " > " + message);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void info(ZenPosition position, String message) {
|
|
||||||
MineTweakerAPI.logInfo(position.toString() + " > " + message);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void error(String message) {
|
|
||||||
MineTweakerAPI.logError(message);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void error(String message, Throwable e) {
|
|
||||||
MineTweakerAPI.logError(message, e);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void warning(String message) {
|
|
||||||
MineTweakerAPI.logWarning(message);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void info(String message) {
|
|
||||||
MineTweakerAPI.logInfo(message);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Set<String> getClassNames() {
|
|
||||||
return classes.keySet();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public byte[] getClass(String name) {
|
|
||||||
return classes.get(name);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,30 +0,0 @@
|
|||||||
/*
|
|
||||||
* To change this license header, choose License Headers in Project Properties.
|
|
||||||
* To change this template file, choose Tools | Templates
|
|
||||||
* and open the template in the editor.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package minetweaker.runtime;
|
|
||||||
|
|
||||||
import stanhebben.zenscript.annotations.ZenMethod;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @author Stan
|
|
||||||
*/
|
|
||||||
public interface ILogger {
|
|
||||||
@ZenMethod
|
|
||||||
public void logCommand(String message);
|
|
||||||
|
|
||||||
@ZenMethod
|
|
||||||
public void logInfo(String message);
|
|
||||||
|
|
||||||
@ZenMethod
|
|
||||||
public void logWarning(String message);
|
|
||||||
|
|
||||||
@ZenMethod
|
|
||||||
public void logError(String message);
|
|
||||||
|
|
||||||
@ZenMethod
|
|
||||||
public void logError(String message, Throwable exception);
|
|
||||||
}
|
|
||||||
@@ -1,24 +0,0 @@
|
|||||||
/*
|
|
||||||
* To change this license header, choose License Headers in Project Properties.
|
|
||||||
* To change this template file, choose Tools | Templates
|
|
||||||
* and open the template in the editor.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package minetweaker.runtime;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @author Stan
|
|
||||||
*/
|
|
||||||
public interface IScriptIterator {
|
|
||||||
public String getGroupName();
|
|
||||||
|
|
||||||
public boolean next();
|
|
||||||
|
|
||||||
public String getName();
|
|
||||||
|
|
||||||
public InputStream open() throws IOException;
|
|
||||||
}
|
|
||||||
@@ -1,72 +0,0 @@
|
|||||||
/*
|
|
||||||
* To change this license header, choose License Headers in Project Properties.
|
|
||||||
* To change this template file, choose Tools | Templates
|
|
||||||
* and open the template in the editor.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package minetweaker.runtime;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
import minetweaker.IUndoableAction;
|
|
||||||
import minetweaker.api.item.IIngredient;
|
|
||||||
import stanhebben.zenscript.annotations.ZenClass;
|
|
||||||
import stanhebben.zenscript.annotations.ZenMethod;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @author Stan
|
|
||||||
*/
|
|
||||||
@ZenClass("minetweaker.IMineTweaker")
|
|
||||||
public interface ITweaker {
|
|
||||||
/**
|
|
||||||
* Retrieves the script data to be loaded.
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public byte[] getStagedScriptData();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Executes a specified MineTweaker action. Will print a log message and
|
|
||||||
* adds the action to the undo list.
|
|
||||||
*
|
|
||||||
* @param action action to execute
|
|
||||||
*/
|
|
||||||
public void apply(IUndoableAction action);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Removes a specific item from all known recipes handlers.
|
|
||||||
*
|
|
||||||
* @param items items to remove
|
|
||||||
*/
|
|
||||||
@ZenMethod
|
|
||||||
public void remove(IIngredient items);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Rolls back all actions performed by MineTweaker. Returns the list of
|
|
||||||
* actions that could not be rolled back (the "stuck" ones that are not
|
|
||||||
* undoable).
|
|
||||||
*
|
|
||||||
* @return stuck action list
|
|
||||||
*/
|
|
||||||
public List<IUndoableAction> rollback();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the script provider.
|
|
||||||
*
|
|
||||||
* @param provider
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public void setScriptProvider(IScriptProvider provider);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Executes all scripts provided by the script provider.
|
|
||||||
*/
|
|
||||||
public void load();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Retrieves the data from the scripts that were loaded last.
|
|
||||||
*
|
|
||||||
* @return scripts data
|
|
||||||
*/
|
|
||||||
public byte[] getScriptData();
|
|
||||||
}
|
|
||||||
@@ -1,182 +0,0 @@
|
|||||||
/*
|
|
||||||
* To change this license header, choose License Headers in Project Properties.
|
|
||||||
* To change this template file, choose Tools | Templates
|
|
||||||
* and open the template in the editor.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package minetweaker.runtime;
|
|
||||||
|
|
||||||
import minetweaker.IUndoableAction;
|
|
||||||
import minetweaker.MineTweakerAPI;
|
|
||||||
import minetweaker.api.item.IIngredient;
|
|
||||||
import minetweaker.runtime.providers.ScriptProviderMemory;
|
|
||||||
import stanhebben.zenscript.ZenModule;
|
|
||||||
import stanhebben.zenscript.ZenParsedFile;
|
|
||||||
import stanhebben.zenscript.ZenTokener;
|
|
||||||
import stanhebben.zenscript.compiler.IEnvironmentGlobal;
|
|
||||||
import stanhebben.zenscript.parser.ParseException;
|
|
||||||
|
|
||||||
import java.io.BufferedInputStream;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStreamReader;
|
|
||||||
import java.io.Reader;
|
|
||||||
import java.nio.charset.*;
|
|
||||||
import java.util.*;
|
|
||||||
|
|
||||||
import static stanhebben.zenscript.ZenModule.compileScripts;
|
|
||||||
import static stanhebben.zenscript.ZenModule.extractClassName;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @author Stan Hebben
|
|
||||||
*/
|
|
||||||
public class MTTweaker implements ITweaker {
|
|
||||||
private static final boolean DEBUG = false;
|
|
||||||
|
|
||||||
private final List<IUndoableAction> actions = new ArrayList<IUndoableAction>();
|
|
||||||
private final Set<IUndoableAction> wereStuck = new LinkedHashSet<IUndoableAction>();
|
|
||||||
private final Map<Object, IUndoableAction> stuckOverridable = new HashMap<Object, IUndoableAction>();
|
|
||||||
|
|
||||||
private IScriptProvider scriptProvider;
|
|
||||||
private byte[] scriptData;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public byte[] getStagedScriptData() {
|
|
||||||
return ScriptProviderMemory.collect(scriptProvider);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void apply(IUndoableAction action) {
|
|
||||||
MineTweakerAPI.logInfo(action.describe());
|
|
||||||
|
|
||||||
Object overrideKey = action.getOverrideKey();
|
|
||||||
if (wereStuck.contains(action)) {
|
|
||||||
wereStuck.remove(action);
|
|
||||||
|
|
||||||
if (overrideKey != null) {
|
|
||||||
stuckOverridable.remove(overrideKey);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (overrideKey != null && stuckOverridable.containsKey(overrideKey)) {
|
|
||||||
wereStuck.remove(stuckOverridable.get(overrideKey));
|
|
||||||
stuckOverridable.remove(overrideKey);
|
|
||||||
}
|
|
||||||
|
|
||||||
action.apply();
|
|
||||||
}
|
|
||||||
|
|
||||||
actions.add(action);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void remove(IIngredient items) {
|
|
||||||
GlobalRegistry.remove(items);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<IUndoableAction> rollback() {
|
|
||||||
List<IUndoableAction> stuck = new ArrayList<IUndoableAction>();
|
|
||||||
for (int i = actions.size() - 1; i >= 0; i--) {
|
|
||||||
IUndoableAction action = actions.get(i);
|
|
||||||
if (action.canUndo()) {
|
|
||||||
MineTweakerAPI.logInfo(action.describeUndo());
|
|
||||||
action.undo();
|
|
||||||
} else {
|
|
||||||
MineTweakerAPI.logInfo("[Stuck] 1 " + action.describe());
|
|
||||||
MineTweakerAPI.logInfo("[Stuck] 2 " + action.describeUndo());
|
|
||||||
MineTweakerAPI.logInfo("[Stuck] 3 " + action.toString());
|
|
||||||
|
|
||||||
stuck.add(0, action);
|
|
||||||
wereStuck.add(action);
|
|
||||||
|
|
||||||
Object overrideKey = action.getOverrideKey();
|
|
||||||
if (overrideKey != null) {
|
|
||||||
stuckOverridable.put(overrideKey, action);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
actions.clear();
|
|
||||||
return stuck;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setScriptProvider(IScriptProvider provider) {
|
|
||||||
scriptProvider = provider;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void load() {
|
|
||||||
ZenModule.loadedClasses.clear();
|
|
||||||
System.out.println("Loading scripts");
|
|
||||||
|
|
||||||
scriptData = ScriptProviderMemory.collect(scriptProvider);
|
|
||||||
Set<String> executed = new HashSet<String>();
|
|
||||||
|
|
||||||
Iterator<IScriptIterator> scripts = scriptProvider.getScripts();
|
|
||||||
while (scripts.hasNext()) {
|
|
||||||
IScriptIterator script = scripts.next();
|
|
||||||
|
|
||||||
if (!executed.contains(script.getGroupName())) {
|
|
||||||
executed.add(script.getGroupName());
|
|
||||||
|
|
||||||
Map<String, byte[]> classes = new HashMap<String, byte[]>();
|
|
||||||
IEnvironmentGlobal environmentGlobal = GlobalRegistry.makeGlobalEnvironment(classes);
|
|
||||||
|
|
||||||
List<ZenParsedFile> files = new ArrayList<ZenParsedFile>();
|
|
||||||
|
|
||||||
while (script.next()) {
|
|
||||||
Reader reader = null;
|
|
||||||
try {
|
|
||||||
reader = new InputStreamReader(new BufferedInputStream(script.open()), StandardCharsets.UTF_8);
|
|
||||||
|
|
||||||
String filename = script.getName();
|
|
||||||
String className = extractClassName(filename);
|
|
||||||
|
|
||||||
ZenTokener parser = new ZenTokener(reader, environmentGlobal.getEnvironment(), filename, false);
|
|
||||||
ZenParsedFile pfile = new ZenParsedFile(filename, className, parser, environmentGlobal);
|
|
||||||
files.add(pfile);
|
|
||||||
} catch (IOException ex) {
|
|
||||||
MineTweakerAPI.logError("Could not load script " + script.getName() + ": " + ex.getMessage());
|
|
||||||
} catch (ParseException ex) {
|
|
||||||
// ex.printStackTrace();
|
|
||||||
MineTweakerAPI.logError("Error parsing " + ex.getFile().getFileName() + ":" + ex.getLine() + " -- " + ex.getExplanation());
|
|
||||||
} catch (Exception ex) {
|
|
||||||
MineTweakerAPI.logError("Error loading " + script.getName() + ": " + ex.toString(), ex);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (reader != null) {
|
|
||||||
try {
|
|
||||||
reader.close();
|
|
||||||
} catch (IOException ignored) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
String filename = script.getGroupName();
|
|
||||||
System.out.println("MineTweaker: Loading " + filename);
|
|
||||||
compileScripts(filename, files, environmentGlobal, DEBUG);
|
|
||||||
|
|
||||||
// execute scripts
|
|
||||||
ZenModule module = new ZenModule(classes, MineTweakerAPI.class.getClassLoader());
|
|
||||||
module.getMain().run();
|
|
||||||
} catch (Throwable ex) {
|
|
||||||
MineTweakerAPI.logError("Error executing " + script.getGroupName() + ": " + ex.getMessage(), ex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (wereStuck.size() > 0) {
|
|
||||||
MineTweakerAPI.logWarning(Integer.toString(wereStuck.size()) + " modifications were stuck");
|
|
||||||
for (IUndoableAction action : wereStuck) {
|
|
||||||
MineTweakerAPI.logInfo("Stuck: " + action.describe());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public byte[] getScriptData() {
|
|
||||||
return scriptData;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-73
@@ -1,73 +0,0 @@
|
|||||||
/*
|
|
||||||
* To change this license header, choose License Headers in Project Properties.
|
|
||||||
* To change this template file, choose Tools | Templates
|
|
||||||
* and open the template in the editor.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package minetweaker.runtime.providers;
|
|
||||||
|
|
||||||
import java.io.BufferedInputStream;
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.FileInputStream;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.List;
|
|
||||||
import minetweaker.runtime.IScriptIterator;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @author Stan
|
|
||||||
*/
|
|
||||||
public class ScriptIteratorDirectory implements IScriptIterator {
|
|
||||||
private final File directory;
|
|
||||||
private Iterator<File> contents;
|
|
||||||
private File current;
|
|
||||||
|
|
||||||
public ScriptIteratorDirectory(File directory) {
|
|
||||||
this.directory = directory;
|
|
||||||
|
|
||||||
File scriptDir = new File(directory, "scripts");
|
|
||||||
List<File> contentsList = new ArrayList<File>();
|
|
||||||
if (scriptDir.exists()) {
|
|
||||||
iterate(scriptDir, contentsList);
|
|
||||||
}
|
|
||||||
contents = contentsList.iterator();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getGroupName() {
|
|
||||||
return directory.getName();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean next() {
|
|
||||||
if (contents.hasNext()) {
|
|
||||||
current = contents.next();
|
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getName() {
|
|
||||||
return current.getAbsolutePath().substring(directory.getAbsolutePath().length());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public InputStream open() throws IOException {
|
|
||||||
return new BufferedInputStream(new FileInputStream(current));
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void iterate(File directory, List<File> contentsList) {
|
|
||||||
for (File file : directory.listFiles()) {
|
|
||||||
if (file.isDirectory()) {
|
|
||||||
iterate(file, contentsList);
|
|
||||||
} else if (file.isFile() && file.getName().endsWith(".zs")) {
|
|
||||||
contentsList.add(file);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-52
@@ -1,52 +0,0 @@
|
|||||||
/*
|
|
||||||
* To change this license header, choose License Headers in Project Properties.
|
|
||||||
* To change this template file, choose Tools | Templates
|
|
||||||
* and open the template in the editor.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package minetweaker.runtime.providers;
|
|
||||||
|
|
||||||
import java.io.BufferedInputStream;
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.FileInputStream;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
|
||||||
import minetweaker.runtime.IScriptIterator;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @author Stan
|
|
||||||
*/
|
|
||||||
public class ScriptIteratorSingle implements IScriptIterator {
|
|
||||||
private final File file;
|
|
||||||
private boolean first = true;
|
|
||||||
|
|
||||||
public ScriptIteratorSingle(File file) {
|
|
||||||
this.file = file;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getGroupName() {
|
|
||||||
return file.getName();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean next() {
|
|
||||||
if (first) {
|
|
||||||
first = false;
|
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getName() {
|
|
||||||
return file.getName();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public InputStream open() throws IOException {
|
|
||||||
return new BufferedInputStream(new FileInputStream(file));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,70 +0,0 @@
|
|||||||
/*
|
|
||||||
* To change this license header, choose License Headers in Project Properties.
|
|
||||||
* To change this template file, choose Tools | Templates
|
|
||||||
* and open the template in the editor.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package minetweaker.runtime.providers;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Enumeration;
|
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.zip.ZipEntry;
|
|
||||||
import java.util.zip.ZipFile;
|
|
||||||
import minetweaker.runtime.IScriptIterator;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @author Stan
|
|
||||||
*/
|
|
||||||
public class ScriptIteratorZip implements IScriptIterator {
|
|
||||||
private final File file;
|
|
||||||
private final ZipFile zipFile;
|
|
||||||
private final Iterator<ZipEntry> entries;
|
|
||||||
private ZipEntry current;
|
|
||||||
|
|
||||||
public ScriptIteratorZip(File file) throws IOException {
|
|
||||||
this.file = file;
|
|
||||||
|
|
||||||
zipFile = new ZipFile(file);
|
|
||||||
List<ZipEntry> entriesList = new ArrayList<ZipEntry>();
|
|
||||||
Enumeration<? extends ZipEntry> original = zipFile.entries();
|
|
||||||
while (original.hasMoreElements()) {
|
|
||||||
ZipEntry entry = original.nextElement();
|
|
||||||
if (entry.getName().startsWith("scripts/") && entry.getName().endsWith(".zs")) {
|
|
||||||
entriesList.add(entry);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
entries = entriesList.iterator();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getGroupName() {
|
|
||||||
return file.getName().substring(0, file.getName().lastIndexOf('.'));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean next() {
|
|
||||||
if (entries.hasNext()) {
|
|
||||||
current = entries.next();
|
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getName() {
|
|
||||||
return current.getName().substring("scripts/".length());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public InputStream open() throws IOException {
|
|
||||||
return zipFile.getInputStream(current);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-90
@@ -1,90 +0,0 @@
|
|||||||
/*
|
|
||||||
* To change this license header, choose License Headers in Project Properties.
|
|
||||||
* To change this template file, choose Tools | Templates
|
|
||||||
* and open the template in the editor.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package minetweaker.runtime.providers;
|
|
||||||
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.Set;
|
|
||||||
import minetweaker.runtime.IScriptIterator;
|
|
||||||
import minetweaker.runtime.IScriptProvider;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @author Stan Hebben
|
|
||||||
*/
|
|
||||||
public class ScriptProviderCascade implements IScriptProvider {
|
|
||||||
private final IScriptProvider[] providers;
|
|
||||||
|
|
||||||
public ScriptProviderCascade(IScriptProvider... providers) {
|
|
||||||
this.providers = providers;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Iterator<IScriptIterator> getScripts() {
|
|
||||||
return new MyScripterator();
|
|
||||||
}
|
|
||||||
|
|
||||||
private class MyScripterator implements Iterator<IScriptIterator> {
|
|
||||||
private final Set<String> executed = new HashSet<String>();
|
|
||||||
|
|
||||||
private int currentIndex = providers.length - 1;
|
|
||||||
private Iterator<IScriptIterator> current;
|
|
||||||
private IScriptIterator currentValue;
|
|
||||||
|
|
||||||
public MyScripterator() {
|
|
||||||
currentIndex = providers.length - 1;
|
|
||||||
current = providers[currentIndex].getScripts();
|
|
||||||
|
|
||||||
advance();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean hasNext() {
|
|
||||||
return currentIndex >= 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public IScriptIterator next() {
|
|
||||||
IScriptIterator result = currentValue;
|
|
||||||
executed.add(result.getGroupName());
|
|
||||||
|
|
||||||
advance();
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void advance() {
|
|
||||||
do {
|
|
||||||
while (!current.hasNext()) {
|
|
||||||
currentIndex--;
|
|
||||||
if (currentIndex < 0)
|
|
||||||
return;
|
|
||||||
|
|
||||||
current = providers[currentIndex].getScripts();
|
|
||||||
}
|
|
||||||
if (currentIndex < 0)
|
|
||||||
break;
|
|
||||||
|
|
||||||
currentValue = current.next();
|
|
||||||
} while (executed.contains(currentValue.getGroupName()) && hasNext());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void remove() {
|
|
||||||
throw new UnsupportedOperationException("Not supported yet."); // To
|
|
||||||
// change
|
|
||||||
// body
|
|
||||||
// of
|
|
||||||
// generated
|
|
||||||
// methods,
|
|
||||||
// choose
|
|
||||||
// Tools
|
|
||||||
// |
|
|
||||||
// Templates.
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-89
@@ -1,89 +0,0 @@
|
|||||||
/*
|
|
||||||
* To change this license header, choose License Headers in Project Properties.
|
|
||||||
* To change this template file, choose Tools | Templates
|
|
||||||
* and open the template in the editor.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package minetweaker.runtime.providers;
|
|
||||||
|
|
||||||
import minetweaker.runtime.IScriptIterator;
|
|
||||||
import minetweaker.runtime.IScriptProvider;
|
|
||||||
|
|
||||||
import java.io.ByteArrayInputStream;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.nio.charset.Charset;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @author Stan
|
|
||||||
*/
|
|
||||||
public class ScriptProviderCustom implements IScriptProvider {
|
|
||||||
private static final Charset UTF8 = Charset.forName("UTF-8");
|
|
||||||
|
|
||||||
private final String moduleName;
|
|
||||||
private final List<CustomScript> scripts;
|
|
||||||
|
|
||||||
public ScriptProviderCustom(String moduleName) {
|
|
||||||
this.moduleName = moduleName;
|
|
||||||
scripts = new ArrayList<CustomScript>();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void add(String name, byte[] content) {
|
|
||||||
scripts.add(new CustomScript(name, content));
|
|
||||||
}
|
|
||||||
|
|
||||||
public void add(String name, String content) {
|
|
||||||
add(name, content.getBytes(UTF8));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Iterator<IScriptIterator> getScripts() {
|
|
||||||
|
|
||||||
return Collections.<IScriptIterator>singleton(new CustomScriptIterator()).iterator();
|
|
||||||
}
|
|
||||||
|
|
||||||
private class CustomScript {
|
|
||||||
private final String name;
|
|
||||||
private final byte[] content;
|
|
||||||
|
|
||||||
public CustomScript(String name, byte[] content) {
|
|
||||||
this.name = name;
|
|
||||||
this.content = content;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private class CustomScriptIterator implements IScriptIterator {
|
|
||||||
private CustomScript current;
|
|
||||||
private final Iterator<CustomScript> iterator = scripts.iterator();
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getGroupName() {
|
|
||||||
return moduleName;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean next() {
|
|
||||||
if (iterator.hasNext()) {
|
|
||||||
current = iterator.next();
|
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getName() {
|
|
||||||
return current.name;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public InputStream open() throws IOException {
|
|
||||||
return new ByteArrayInputStream(current.content);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-195
@@ -1,195 +0,0 @@
|
|||||||
/*
|
|
||||||
* To change this license header, choose License Headers in Project Properties.
|
|
||||||
* To change this template file, choose Tools | Templates
|
|
||||||
* and open the template in the editor.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package minetweaker.runtime.providers;
|
|
||||||
|
|
||||||
import java.io.ByteArrayInputStream;
|
|
||||||
import java.io.ByteArrayOutputStream;
|
|
||||||
import java.io.DataInputStream;
|
|
||||||
import java.io.DataOutputStream;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Set;
|
|
||||||
import java.util.zip.DeflaterOutputStream;
|
|
||||||
import java.util.zip.InflaterInputStream;
|
|
||||||
import minetweaker.MineTweakerAPI;
|
|
||||||
import minetweaker.util.FileUtil;
|
|
||||||
import minetweaker.runtime.IScriptIterator;
|
|
||||||
import minetweaker.runtime.IScriptProvider;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @author Stan
|
|
||||||
*/
|
|
||||||
public class ScriptProviderMemory implements IScriptProvider {
|
|
||||||
public static byte[] collect(IScriptProvider provider) {
|
|
||||||
ByteArrayOutputStream output = new ByteArrayOutputStream();
|
|
||||||
try {
|
|
||||||
DeflaterOutputStream deflater = new DeflaterOutputStream(output);
|
|
||||||
DataOutputStream deflaterData = new DataOutputStream(deflater);
|
|
||||||
Set<String> executed = new HashSet<String>();
|
|
||||||
|
|
||||||
Iterator<IScriptIterator> scripts = provider.getScripts();
|
|
||||||
while (scripts.hasNext()) {
|
|
||||||
IScriptIterator script = scripts.next();
|
|
||||||
|
|
||||||
if (!executed.contains(script.getGroupName())) {
|
|
||||||
executed.add(script.getGroupName());
|
|
||||||
|
|
||||||
deflaterData.writeUTF(script.getGroupName());
|
|
||||||
|
|
||||||
while (script.next()) {
|
|
||||||
String name = script.getName();
|
|
||||||
byte[] data = FileUtil.read(script.open());
|
|
||||||
if (data.length == 0)
|
|
||||||
continue; // skip empty files
|
|
||||||
|
|
||||||
deflaterData.writeUTF(name);
|
|
||||||
deflaterData.writeInt(data.length);
|
|
||||||
deflaterData.write(data);
|
|
||||||
}
|
|
||||||
|
|
||||||
deflaterData.writeUTF("");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
deflaterData.writeUTF("");
|
|
||||||
|
|
||||||
deflater.close();
|
|
||||||
} catch (IOException ex) {
|
|
||||||
MineTweakerAPI.logError("Could not collect scripts: " + ex.getMessage());
|
|
||||||
}
|
|
||||||
return output.toByteArray();
|
|
||||||
}
|
|
||||||
|
|
||||||
private final Map<String, MemoryModule> modules;
|
|
||||||
|
|
||||||
public ScriptProviderMemory(byte[] scripts) {
|
|
||||||
modules = new HashMap<String, MemoryModule>();
|
|
||||||
|
|
||||||
try {
|
|
||||||
InflaterInputStream inflater = new InflaterInputStream(new ByteArrayInputStream(scripts));
|
|
||||||
DataInputStream inflaterData = new DataInputStream(inflater);
|
|
||||||
|
|
||||||
String moduleName = inflaterData.readUTF();
|
|
||||||
while (moduleName.length() > 0) {
|
|
||||||
List<MemoryFile> files = new ArrayList<MemoryFile>();
|
|
||||||
|
|
||||||
String fileName = inflaterData.readUTF();
|
|
||||||
while (fileName.length() > 0) {
|
|
||||||
byte[] data = new byte[inflaterData.readInt()];
|
|
||||||
inflaterData.readFully(data);
|
|
||||||
files.add(new MemoryFile(fileName, data));
|
|
||||||
|
|
||||||
fileName = inflaterData.readUTF();
|
|
||||||
}
|
|
||||||
modules.put(moduleName, new MemoryModule(moduleName, files));
|
|
||||||
|
|
||||||
moduleName = inflaterData.readUTF();
|
|
||||||
}
|
|
||||||
|
|
||||||
inflaterData.close();
|
|
||||||
} catch (IOException ex) {
|
|
||||||
MineTweakerAPI.logError("Could not load transmitted scripts: " + ex.getMessage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Iterator<IScriptIterator> getScripts() {
|
|
||||||
return new ProviderIterator();
|
|
||||||
}
|
|
||||||
|
|
||||||
private class ProviderIterator implements Iterator<IScriptIterator> {
|
|
||||||
private final Iterator<MemoryModule> baseIterator = modules.values().iterator();
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean hasNext() {
|
|
||||||
return baseIterator.hasNext();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public IScriptIterator next() {
|
|
||||||
return new ScriptIterator(baseIterator.next());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void remove() {
|
|
||||||
throw new UnsupportedOperationException("Not supported yet."); // To
|
|
||||||
// change
|
|
||||||
// body
|
|
||||||
// of
|
|
||||||
// generated
|
|
||||||
// methods,
|
|
||||||
// choose
|
|
||||||
// Tools
|
|
||||||
// |
|
|
||||||
// Templates.
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private class ScriptIterator implements IScriptIterator {
|
|
||||||
private final MemoryModule module;
|
|
||||||
private final Iterator<MemoryFile> files;
|
|
||||||
private MemoryFile current;
|
|
||||||
|
|
||||||
public ScriptIterator(MemoryModule module) {
|
|
||||||
this.module = module;
|
|
||||||
files = module.data.iterator();
|
|
||||||
current = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getGroupName() {
|
|
||||||
return module.name;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean next() {
|
|
||||||
if (files.hasNext()) {
|
|
||||||
current = files.next();
|
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getName() {
|
|
||||||
return current.name;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public InputStream open() throws IOException {
|
|
||||||
return new ByteArrayInputStream(current.data);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private class MemoryModule {
|
|
||||||
private final String name;
|
|
||||||
private final List<MemoryFile> data;
|
|
||||||
|
|
||||||
public MemoryModule(String name, List<MemoryFile> data) {
|
|
||||||
this.name = name;
|
|
||||||
this.data = data;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private class MemoryFile {
|
|
||||||
private final String name;
|
|
||||||
private final byte[] data;
|
|
||||||
|
|
||||||
public MemoryFile(String name, byte[] data) {
|
|
||||||
this.name = name;
|
|
||||||
this.data = data;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,46 +0,0 @@
|
|||||||
/*
|
|
||||||
* To change this license header, choose License Headers in Project Properties.
|
|
||||||
* To change this template file, choose Tools | Templates
|
|
||||||
* and open the template in the editor.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package minetweaker.util;
|
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
import minetweaker.api.block.IBlockPattern;
|
|
||||||
import minetweaker.api.item.IIngredient;
|
|
||||||
import minetweaker.api.item.IItemCondition;
|
|
||||||
import minetweaker.api.item.IItemTransformer;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @author Stan
|
|
||||||
*/
|
|
||||||
public class ArrayUtil {
|
|
||||||
public static final IItemCondition[] EMPTY_CONDITIONS = new IItemCondition[0];
|
|
||||||
public static final IItemTransformer[] EMPTY_TRANSFORMERS = new IItemTransformer[0];
|
|
||||||
|
|
||||||
public static IItemCondition[] append(IItemCondition[] values, IItemCondition value) {
|
|
||||||
IItemCondition[] result = Arrays.copyOf(values, values.length + 1);
|
|
||||||
result[values.length] = value;
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static IItemTransformer[] append(IItemTransformer[] values, IItemTransformer value) {
|
|
||||||
IItemTransformer[] result = Arrays.copyOf(values, values.length + 1);
|
|
||||||
result[values.length] = value;
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static IIngredient[] append(IIngredient[] values, IIngredient value) {
|
|
||||||
IIngredient[] result = Arrays.copyOf(values, values.length + 1);
|
|
||||||
result[values.length] = value;
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static IBlockPattern[] append(IBlockPattern[] values, IBlockPattern value) {
|
|
||||||
IBlockPattern[] result = Arrays.copyOf(values, values.length + 1);
|
|
||||||
result[values.length] = value;
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,91 +0,0 @@
|
|||||||
/*
|
|
||||||
* To change this license header, choose License Headers in Project Properties.
|
|
||||||
* To change this template file, choose Tools | Templates
|
|
||||||
* and open the template in the editor.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package minetweaker.util;
|
|
||||||
|
|
||||||
import minetweaker.api.event.IEventHandle;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @author Stan
|
|
||||||
*/
|
|
||||||
public class EventList<T> {
|
|
||||||
private EventNode first = null;
|
|
||||||
private EventNode last = null;
|
|
||||||
|
|
||||||
public void clear() {
|
|
||||||
first = last = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public IEventHandle add(IEventHandler<T> handler) {
|
|
||||||
EventNode node = new EventNode(handler, last, null);
|
|
||||||
|
|
||||||
synchronized (this) {
|
|
||||||
if (first == null) {
|
|
||||||
first = node;
|
|
||||||
}
|
|
||||||
if (last != null) {
|
|
||||||
last.next = node;
|
|
||||||
}
|
|
||||||
last = node;
|
|
||||||
}
|
|
||||||
|
|
||||||
return node;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean hasHandlers() {
|
|
||||||
return first != null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isEmpty() {
|
|
||||||
return first == null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void publish(T event) {
|
|
||||||
EventNode current = null;
|
|
||||||
|
|
||||||
synchronized (this) {
|
|
||||||
current = first;
|
|
||||||
}
|
|
||||||
|
|
||||||
while (current != null) {
|
|
||||||
current.handler.handle(event);
|
|
||||||
|
|
||||||
synchronized (this) {
|
|
||||||
current = current.next;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private class EventNode implements IEventHandle {
|
|
||||||
private final IEventHandler<T> handler;
|
|
||||||
private EventNode next;
|
|
||||||
private EventNode prev;
|
|
||||||
|
|
||||||
public EventNode(IEventHandler<T> handler, EventNode prev, EventNode next) {
|
|
||||||
this.handler = handler;
|
|
||||||
this.prev = prev;
|
|
||||||
this.next = next;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void close() {
|
|
||||||
synchronized (EventList.this) {
|
|
||||||
if (prev == null) {
|
|
||||||
first = next;
|
|
||||||
} else {
|
|
||||||
prev.next = next;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (next == null) {
|
|
||||||
last = prev;
|
|
||||||
} else {
|
|
||||||
next.prev = prev;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,27 +0,0 @@
|
|||||||
/*
|
|
||||||
* To change this license header, choose License Headers in Project Properties.
|
|
||||||
* To change this template file, choose Tools | Templates
|
|
||||||
* and open the template in the editor.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package minetweaker.util;
|
|
||||||
|
|
||||||
import java.io.ByteArrayOutputStream;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @author Stan
|
|
||||||
*/
|
|
||||||
public class FileUtil {
|
|
||||||
public static final byte[] read(InputStream input) throws IOException {
|
|
||||||
ByteArrayOutputStream output = new ByteArrayOutputStream();
|
|
||||||
byte[] buffer = new byte[65536];
|
|
||||||
while (input.available() > 0) {
|
|
||||||
int bytesRead = input.read(buffer);
|
|
||||||
output.write(buffer, 0, bytesRead);
|
|
||||||
}
|
|
||||||
return output.toByteArray();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,32 +0,0 @@
|
|||||||
/*
|
|
||||||
* To change this license header, choose License Headers in Project Properties.
|
|
||||||
* To change this template file, choose Tools | Templates
|
|
||||||
* and open the template in the editor.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package minetweaker.util;
|
|
||||||
|
|
||||||
import java.nio.ByteBuffer;
|
|
||||||
import java.nio.charset.Charset;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @author Stan
|
|
||||||
*/
|
|
||||||
public class StringUtil
|
|
||||||
{
|
|
||||||
private static final Charset UTF8 = Charset.forName("UTF-8");
|
|
||||||
|
|
||||||
private StringUtil() {
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String decodeUTF8(byte[] data)
|
|
||||||
{
|
|
||||||
return UTF8.decode(ByteBuffer.wrap(data)).toString().trim();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static byte[] encodeUTF8(String data)
|
|
||||||
{
|
|
||||||
return UTF8.encode(data).array();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,93 +0,0 @@
|
|||||||
import minetweaker.tasks.RegisterZenClassesTask;
|
|
||||||
|
|
||||||
buildscript {
|
|
||||||
repositories {
|
|
||||||
jcenter()
|
|
||||||
maven {
|
|
||||||
name = "forge"
|
|
||||||
url = "http://files.minecraftforge.net/maven"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
dependencies {
|
|
||||||
classpath 'net.minecraftforge.gradle:ForgeGradle:2.2-SNAPSHOT'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
apply plugin: 'net.minecraftforge.gradle.forge'
|
|
||||||
apply plugin: 'maven'
|
|
||||||
|
|
||||||
sourceCompatibility = JavaVersion.VERSION_1_8
|
|
||||||
targetCompatibility = JavaVersion.VERSION_1_8
|
|
||||||
|
|
||||||
version = "1.10.2-" + ext.mineTweakerVersion
|
|
||||||
archivesBaseName = project.projectDir.name
|
|
||||||
|
|
||||||
minecraft {
|
|
||||||
version = forgeVersion1102
|
|
||||||
runDir = "eclipse"
|
|
||||||
mappings = "stable_29"
|
|
||||||
}
|
|
||||||
|
|
||||||
dependencies {
|
|
||||||
compile project(':ZenScript')
|
|
||||||
compile project(':MineTweaker3-API')
|
|
||||||
}
|
|
||||||
|
|
||||||
task makeRegistry(type: RegisterZenClassesTask) {
|
|
||||||
inputDir = file('build/classes/main')
|
|
||||||
outputDir = file('build/classes/main')
|
|
||||||
className = 'minetweaker.mc1102.MineTweakerRegistry'
|
|
||||||
}
|
|
||||||
|
|
||||||
tasks.jar.dependsOn(makeRegistry)
|
|
||||||
|
|
||||||
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'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
uploadArchives {
|
|
||||||
repositories {
|
|
||||||
mavenDeployer {
|
|
||||||
repository(url: "file://" + System.getenv("local_maven"))
|
|
||||||
pom {
|
|
||||||
groupId = project.group
|
|
||||||
version
|
|
||||||
artifactId = project.archivesBaseName
|
|
||||||
project {
|
|
||||||
name project.archivesBaseName
|
|
||||||
packaging 'jar'
|
|
||||||
description 'CraftTweaker'
|
|
||||||
url 'https://github.com/jaredlll08/CraftTweaker'
|
|
||||||
scm {
|
|
||||||
url 'https://github.com/jaredlll08/CraftTweaker.git'
|
|
||||||
connection 'scm:git:[email protected]:jaredlll08/CraftTweaker.git'
|
|
||||||
developerConnection 'scm:git:[email protected]:jaredlll08/CraftTweaker.git'
|
|
||||||
}
|
|
||||||
issueManagement {
|
|
||||||
system 'github'
|
|
||||||
url 'https://github.com/jaredlll08/CraftTweaker/issues'
|
|
||||||
}
|
|
||||||
developers {
|
|
||||||
developer {
|
|
||||||
id 'Jared'
|
|
||||||
name 'Jared'
|
|
||||||
roles { role 'developer' }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,37 +0,0 @@
|
|||||||
package com.blamejared.ctgui;
|
|
||||||
|
|
||||||
import com.blamejared.ctgui.api.GuiRegistry;
|
|
||||||
import com.blamejared.ctgui.client.GuiHandlerVanilla;
|
|
||||||
import com.blamejared.ctgui.commands.CommandCTGUI;
|
|
||||||
import com.blamejared.ctgui.proxy.CommonProxy;
|
|
||||||
import net.minecraftforge.fml.common.*;
|
|
||||||
import net.minecraftforge.fml.common.event.*;
|
|
||||||
|
|
||||||
import java.util.*;
|
|
||||||
|
|
||||||
import static com.blamejared.ctgui.reference.Reference.*;
|
|
||||||
|
|
||||||
@Mod(modid = MOD_ID, name = MOD_NAME, version = VERSION, clientSideOnly = true, dependencies = "required-after:MineTweaker3;")
|
|
||||||
public class MTRecipe {
|
|
||||||
|
|
||||||
@Mod.Instance(MOD_ID)
|
|
||||||
public static MTRecipe INSTANCE;
|
|
||||||
|
|
||||||
@SidedProxy(clientSide = "com.blamejared.ctgui.proxy.ClientProxy", serverSide = "com.blamejared.ctgui.proxy.CommonProxy")
|
|
||||||
public static CommonProxy PROXY;
|
|
||||||
|
|
||||||
@Mod.EventHandler
|
|
||||||
public void preInit(FMLPreInitializationEvent event) {
|
|
||||||
List<Integer> idrange = new ArrayList<>();
|
|
||||||
idrange.add(1);
|
|
||||||
idrange.add(2);
|
|
||||||
GuiRegistry.registerGui(idrange, new GuiHandlerVanilla());
|
|
||||||
PROXY.registerGuis();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Mod.EventHandler
|
|
||||||
public void serverStarting(FMLServerStartingEvent e) {
|
|
||||||
e.registerServerCommand(new CommandCTGUI());
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,95 +0,0 @@
|
|||||||
package com.blamejared.ctgui.api;
|
|
||||||
|
|
||||||
import net.minecraft.client.Minecraft;
|
|
||||||
import net.minecraft.client.gui.GuiButton;
|
|
||||||
import net.minecraft.client.renderer.GlStateManager;
|
|
||||||
import net.minecraftforge.fml.client.config.*;
|
|
||||||
import org.lwjgl.opengl.GL11;
|
|
||||||
|
|
||||||
import java.awt.*;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class CheckButton extends GuiCheckBox {
|
|
||||||
|
|
||||||
protected GuiBase parent;
|
|
||||||
protected List<GuiButton> incompatible;
|
|
||||||
|
|
||||||
protected int backgroundSize = 100;
|
|
||||||
|
|
||||||
public CheckButton(GuiBase parent, int id, int xPos, int yPos, String displayString, boolean isChecked) {
|
|
||||||
super(id, xPos, yPos, displayString, isChecked);
|
|
||||||
this.parent = parent;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public int getBackgroundSize() {
|
|
||||||
return backgroundSize;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setBackgroundSize(int backgroundSize) {
|
|
||||||
this.backgroundSize = backgroundSize;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<GuiButton> getIncompatible() {
|
|
||||||
return incompatible;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setIncompatible(List<GuiButton> incompatible) {
|
|
||||||
this.incompatible = incompatible;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Draws this button to the screen.
|
|
||||||
*/
|
|
||||||
public void drawButton(Minecraft mc, int mouseX, int mouseY) {
|
|
||||||
if(this.visible) {
|
|
||||||
this.hovered = mouseX >= this.xPosition && mouseY >= this.yPosition && mouseX < this.xPosition + getButtonWidth() && mouseY < this.yPosition + this.height;
|
|
||||||
GlStateManager.enableAlpha();
|
|
||||||
GL11.glColor4d(1, 1, 1, 0);
|
|
||||||
GuiUtils.drawGradientRect(30, this.xPosition - 2, this.yPosition - 2, this.xPosition + getBackgroundSize(), this.yPosition + height + 2, 0x9F100010, 0x9F100010);
|
|
||||||
GlStateManager.disableAlpha();
|
|
||||||
GuiUtils.drawContinuousTexturedBox(BUTTON_TEXTURES, this.xPosition, this.yPosition, 0, 46, 11, this.height, 200, 20, 2, 3, 2, 2, this.zLevel);
|
|
||||||
this.mouseDragged(mc, mouseX, mouseY);
|
|
||||||
int color = 14737632;
|
|
||||||
|
|
||||||
if(packedFGColour != 0) {
|
|
||||||
color = packedFGColour;
|
|
||||||
} else if(!this.enabled) {
|
|
||||||
color = 10526880;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(this.isChecked()) {
|
|
||||||
this.drawGradientRect(this.xPosition + 2, this.yPosition + 2, this.xPosition + 11 - 2, this.yPosition + height - 2, Color.cyan.darker().getRGB(), Color.cyan.darker().getRGB());
|
|
||||||
}
|
|
||||||
|
|
||||||
this.drawString(mc.fontRendererObj, displayString, xPosition + 11 + 2, yPosition + 2, color);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean mousePressed(Minecraft mc, int mouseX, int mouseY) {
|
|
||||||
if(this.enabled && this.visible && mouseX >= this.xPosition && mouseY >= this.yPosition && mouseX < this.xPosition + this.width && mouseY < this.yPosition + this.height) {
|
|
||||||
setIsChecked(!isChecked());
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public void setIsChecked(boolean isChecked) {
|
|
||||||
super.setIsChecked(isChecked);
|
|
||||||
if(isChecked()) {
|
|
||||||
for(GuiButton but : incompatible) {
|
|
||||||
but.enabled = false;
|
|
||||||
if(but instanceof CheckButton) {
|
|
||||||
((CheckButton) but).setIsChecked(false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
for(GuiButton but : incompatible) {
|
|
||||||
but.enabled = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
-103
@@ -1,103 +0,0 @@
|
|||||||
package com.blamejared.ctgui.api;
|
|
||||||
|
|
||||||
import net.minecraft.block.Block;
|
|
||||||
import net.minecraft.client.Minecraft;
|
|
||||||
import net.minecraft.client.gui.GuiButton;
|
|
||||||
import net.minecraft.creativetab.CreativeTabs;
|
|
||||||
import net.minecraft.item.ItemStack;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
|
|
||||||
public class CheckButtonRecipe extends CheckButton {
|
|
||||||
|
|
||||||
private String propertyKey;
|
|
||||||
|
|
||||||
public CheckButtonRecipe(GuiBase parent, int id, int xPos, int yPos, String displayString, boolean isChecked, String propertyKey) {
|
|
||||||
super(parent, id, xPos, yPos, displayString, isChecked);
|
|
||||||
this.propertyKey = propertyKey;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean mousePressed(Minecraft mc, int mouseX, int mouseY) {
|
|
||||||
if(this.enabled && this.visible && mouseX >= this.xPosition && mouseY >= this.yPosition && mouseX < this.xPosition + this.width && mouseY < this.yPosition + this.height) {
|
|
||||||
setIsChecked(!isChecked());
|
|
||||||
parent.selectedSlot.getPropertyMap().put(getPropertyKey(), isChecked());
|
|
||||||
if(isChecked()) {
|
|
||||||
for(Slider slider : parent.getMenu().getSliders(this)) {
|
|
||||||
if(GuiBase.isBlock(parent.selectedSlot.getStack())) {
|
|
||||||
Block b = Block.getBlockFromItem(parent.selectedSlot.getStack().getItem());
|
|
||||||
ArrayList<ItemStack> list = new ArrayList<>();
|
|
||||||
b.getSubBlocks(parent.selectedSlot.getStack().getItem(), CreativeTabs.SEARCH, list);
|
|
||||||
slider.setValue(parent.selectedSlot.getProperty(slider.getPropertyKey()));
|
|
||||||
slider.maxValue = list.size() - 1;
|
|
||||||
slider.updateSlider();
|
|
||||||
} else {
|
|
||||||
if(parent.selectedSlot.getStack().getItem().getHasSubtypes()) {
|
|
||||||
ArrayList<ItemStack> list = new ArrayList<>();
|
|
||||||
parent.selectedSlot.getStack().getItem().getSubItems(parent.selectedSlot.getStack().getItem(), CreativeTabs.SEARCH, list);
|
|
||||||
slider.setValue(parent.selectedSlot.getProperty(slider.getPropertyKey()));
|
|
||||||
slider.maxValue = list.size() - 1;
|
|
||||||
slider.updateSlider();
|
|
||||||
} else {
|
|
||||||
slider.setValue(parent.selectedSlot.getProperty(slider.getPropertyKey()));
|
|
||||||
slider.maxValue = parent.selectedSlot.getStack().getMaxDamage();
|
|
||||||
slider.updateSlider();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
parent.getButtonList().add(slider);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
for(Slider slider : parent.getMenu().getSliders(this)) {
|
|
||||||
parent.getButtonList().remove(slider);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public void setIsChecked(boolean isChecked) {
|
|
||||||
super.setIsChecked(isChecked);
|
|
||||||
if(isChecked()) {
|
|
||||||
for(Slider slider : parent.getMenu().getSliders(this)) {
|
|
||||||
if(GuiBase.isBlock(parent.selectedSlot.getStack())) {
|
|
||||||
Block b = Block.getBlockFromItem(parent.selectedSlot.getStack().getItem());
|
|
||||||
ArrayList<ItemStack> list = new ArrayList<>();
|
|
||||||
b.getSubBlocks(parent.selectedSlot.getStack().getItem(), CreativeTabs.SEARCH, list);
|
|
||||||
slider.setValue(parent.selectedSlot.getProperty(slider.getPropertyKey()));
|
|
||||||
slider.maxValue = list.size() - 1;
|
|
||||||
slider.updateSlider();
|
|
||||||
} else {
|
|
||||||
if(parent.selectedSlot.getStack().getItem().getHasSubtypes()) {
|
|
||||||
ArrayList<ItemStack> list = new ArrayList<>();
|
|
||||||
parent.selectedSlot.getStack().getItem().getSubItems(parent.selectedSlot.getStack().getItem(), CreativeTabs.SEARCH, list);
|
|
||||||
slider.setValue(parent.selectedSlot.getProperty(slider.getPropertyKey()));
|
|
||||||
slider.maxValue = list.size() - 1;
|
|
||||||
slider.updateSlider();
|
|
||||||
} else {
|
|
||||||
slider.setValue(parent.selectedSlot.getProperty(slider.getPropertyKey()));
|
|
||||||
slider.maxValue = parent.selectedSlot.getStack().getMaxDamage();
|
|
||||||
slider.updateSlider();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
parent.getButtonList().add(slider);
|
|
||||||
}
|
|
||||||
for(GuiButton but : incompatible) {
|
|
||||||
but.enabled = false;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
for(Slider slider : parent.getMenu().getSliders(this)) {
|
|
||||||
parent.getButtonList().remove(slider);
|
|
||||||
}
|
|
||||||
for(GuiButton but : incompatible) {
|
|
||||||
but.enabled = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getPropertyKey() {
|
|
||||||
return propertyKey;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,96 +0,0 @@
|
|||||||
package com.blamejared.ctgui.api;
|
|
||||||
|
|
||||||
import net.minecraft.entity.player.*;
|
|
||||||
import net.minecraft.inventory.*;
|
|
||||||
import net.minecraft.item.ItemStack;
|
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
|
||||||
import java.util.*;
|
|
||||||
|
|
||||||
public class ContainerBase extends Container {
|
|
||||||
|
|
||||||
protected List<SlotRecipe> recipeSlots = new LinkedList<>();
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean canInteractWith(EntityPlayer player) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Nullable
|
|
||||||
@Override
|
|
||||||
public ItemStack slotClick(int i, int mousebtn, ClickType clickTypeIn, EntityPlayer player) {
|
|
||||||
ItemStack stack = null;
|
|
||||||
|
|
||||||
if(i >= 0 && getSlot(i) != null && getSlot(i) instanceof SlotRecipe) // Fake slots
|
|
||||||
{
|
|
||||||
if(mousebtn == 2) {
|
|
||||||
getSlot(i).putStack(null);
|
|
||||||
} else if(mousebtn == 0) {
|
|
||||||
InventoryPlayer playerInv = player.inventory;
|
|
||||||
getSlot(i).onSlotChanged();
|
|
||||||
ItemStack stackSlot = getSlot(i).getStack();
|
|
||||||
ItemStack stackHeld = playerInv.getItemStack();
|
|
||||||
|
|
||||||
if(stackSlot != null)
|
|
||||||
stack = stackSlot.copy();
|
|
||||||
|
|
||||||
if(stackHeld != null) {
|
|
||||||
ItemStack newStack = stackHeld.copy();
|
|
||||||
if(!(getSlot(i) instanceof SlotRecipeOutput))
|
|
||||||
newStack.stackSize = 1;
|
|
||||||
getSlot(i).putStack(newStack);
|
|
||||||
} else
|
|
||||||
getSlot(i).putStack(null);
|
|
||||||
} else if(mousebtn == 1) {
|
|
||||||
InventoryPlayer playerInv = player.inventory;
|
|
||||||
getSlot(i).onSlotChanged();
|
|
||||||
ItemStack stackSlot = getSlot(i).getStack();
|
|
||||||
ItemStack stackHeld = playerInv.getItemStack();
|
|
||||||
|
|
||||||
if(stackSlot != null)
|
|
||||||
stack = stackSlot.copy();
|
|
||||||
|
|
||||||
if(stackHeld != null) {
|
|
||||||
stackHeld = stackHeld.copy();
|
|
||||||
if(stackSlot != null && stackHeld.isItemEqual(stackSlot) && (i == 0 || i == 0)) {
|
|
||||||
int max = stackSlot.getMaxStackSize();
|
|
||||||
if(++stackSlot.stackSize > max)
|
|
||||||
stackSlot.stackSize = max;
|
|
||||||
getSlot(i).putStack(stackSlot);
|
|
||||||
} else {
|
|
||||||
stackHeld.stackSize = 1;
|
|
||||||
getSlot(i).putStack(stackHeld);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if(stackSlot != null) {
|
|
||||||
stackSlot.stackSize--;
|
|
||||||
if(stackSlot.stackSize == 0)
|
|
||||||
getSlot(i).putStack(null);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
stack = super.slotClick(i, mousebtn, clickTypeIn, player);
|
|
||||||
}
|
|
||||||
return stack;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Nullable
|
|
||||||
@Override
|
|
||||||
public ItemStack transferStackInSlot(EntityPlayer playerIn, int index) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<SlotRecipe> getRecipeSlots() {
|
|
||||||
return recipeSlots;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected Slot addSlotToContainer(Slot slotIn) {
|
|
||||||
if(slotIn instanceof SlotRecipe) {
|
|
||||||
getRecipeSlots().add((SlotRecipe) slotIn);
|
|
||||||
}
|
|
||||||
return super.addSlotToContainer(slotIn);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,313 +0,0 @@
|
|||||||
package com.blamejared.ctgui.api;
|
|
||||||
|
|
||||||
import com.blamejared.ctgui.client.gui.GuiMenu;
|
|
||||||
import net.minecraft.block.Block;
|
|
||||||
import net.minecraft.client.Minecraft;
|
|
||||||
import net.minecraft.client.gui.*;
|
|
||||||
import net.minecraft.client.gui.inventory.GuiContainer;
|
|
||||||
import net.minecraft.client.renderer.GlStateManager;
|
|
||||||
import net.minecraft.item.ItemStack;
|
|
||||||
import net.minecraft.util.ResourceLocation;
|
|
||||||
import org.apache.commons.lang3.tuple.Pair;
|
|
||||||
import org.lwjgl.opengl.GL11;
|
|
||||||
|
|
||||||
import java.awt.*;
|
|
||||||
import java.io.*;
|
|
||||||
import java.util.*;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public abstract class GuiBase extends GuiContainer {
|
|
||||||
|
|
||||||
public SlotRecipe selectedSlot;
|
|
||||||
public GuiTextField editingField;
|
|
||||||
public GuiButton add;
|
|
||||||
public GuiButton remove;
|
|
||||||
protected ContainerBase container;
|
|
||||||
protected GuiMenu menu = new GuiMenu();
|
|
||||||
private boolean shouldOpenMenu;
|
|
||||||
|
|
||||||
public GuiBase(ContainerBase container, int xSize, int ySize, boolean shouldOpenMenu) {
|
|
||||||
super(container);
|
|
||||||
this.container = container;
|
|
||||||
this.xSize = xSize;
|
|
||||||
this.ySize = ySize;
|
|
||||||
this.shouldOpenMenu = shouldOpenMenu;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean isBlock(ItemStack stack) {
|
|
||||||
ResourceLocation name = Block.REGISTRY.getNameForObject(Block.getBlockFromItem(stack.getItem()));
|
|
||||||
return !(name != null && name.toString().equals("minecraft:air")) && Block.REGISTRY.containsKey(name);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void initGui() {
|
|
||||||
super.initGui();
|
|
||||||
buttonList.clear();
|
|
||||||
if(shouldOpenMenu)
|
|
||||||
menu.open(this, guiLeft - 102, guiTop + 2);
|
|
||||||
editingField = new GuiTextField(2906, fontRendererObj, guiLeft - 104, guiTop - 26, xSize + 102, 20);
|
|
||||||
editingField.setMaxStringLength(Integer.MAX_VALUE);
|
|
||||||
editingField.setEnabled(true);
|
|
||||||
add = new GuiButton(2906, getGuiLeft() + 86, getGuiTop() + 8, fontRendererObj.getStringWidth("Add") + 4, 20, "Add");
|
|
||||||
getButtonList().add(add);
|
|
||||||
remove = new GuiButton(2907, getGuiLeft() + 86 + 2 + fontRendererObj.getStringWidth("Add") + 4, getGuiTop() + 8, fontRendererObj.getStringWidth("Remove") + 4, 20, "Remove");
|
|
||||||
getButtonList().add(remove);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void drawScreen(int mouseX, int mouseY, float partialTicks) {
|
|
||||||
super.drawScreen(mouseX, mouseY, partialTicks);
|
|
||||||
editingField.drawTextBox();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void updateScreen() {
|
|
||||||
super.updateScreen();
|
|
||||||
if(selectedSlot != null) {
|
|
||||||
if(!selectedSlot.getHasStack()) {
|
|
||||||
selectedSlot = null;
|
|
||||||
editingField.setText("");
|
|
||||||
if(shouldOpenMenu) {
|
|
||||||
menu.setState(false);
|
|
||||||
menu.toggle(false);
|
|
||||||
for(Pair<CheckButtonRecipe, Slider[]> but : menu.getButtons()) {
|
|
||||||
for(Slider slider : but.getValue()) {
|
|
||||||
slider.setValue(0);
|
|
||||||
slider.maxValue = 0;
|
|
||||||
slider.updateSlider();
|
|
||||||
buttonList.remove(slider);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
editingField.setText(selectedSlot.getItemString());
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
editingField.setText("");
|
|
||||||
if(shouldOpenMenu) {
|
|
||||||
menu.setState(false);
|
|
||||||
menu.toggle(false);
|
|
||||||
for(Pair<CheckButtonRecipe, Slider[]> but : menu.getButtons()) {
|
|
||||||
for(Slider slider : but.getValue()) {
|
|
||||||
slider.setValue(0);
|
|
||||||
slider.maxValue = 0;
|
|
||||||
slider.updateSlider();
|
|
||||||
buttonList.remove(slider);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
editingField.updateCursorCounter();
|
|
||||||
final boolean[] canCreate = {true};
|
|
||||||
container.getRecipeSlots().stream().filter(slot -> slot instanceof SlotRecipeOutput).filter(slot -> !slot.getHasStack()).forEach(slot -> canCreate[0] = false);
|
|
||||||
if(!canCreate[0]) {
|
|
||||||
add.enabled = false;
|
|
||||||
remove.enabled = false;
|
|
||||||
} else {
|
|
||||||
add.enabled = true;
|
|
||||||
remove.enabled = true;
|
|
||||||
}
|
|
||||||
if(shouldOpenMenu) {
|
|
||||||
if(selectedSlot != null) {
|
|
||||||
if(selectedSlot.getHasStack() && !selectedSlot.getStack().hasTagCompound()) {
|
|
||||||
menu.nbt.getLeft().enabled = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void mouseClicked(int mouseX, int mouseY, int mouseButton) throws IOException {
|
|
||||||
final boolean[] clickedSlot = new boolean[]{false};
|
|
||||||
for(SlotRecipe slot : container.getRecipeSlots()) {
|
|
||||||
Rectangle rectangle = new Rectangle(guiLeft + slot.xPos, guiTop + slot.yPos, 18, 18);
|
|
||||||
if(rectangle.contains(mouseX, mouseY)) {
|
|
||||||
switch(mouseButton) {
|
|
||||||
case 0:
|
|
||||||
break;
|
|
||||||
case 1:
|
|
||||||
if(slot.getHasStack()) {
|
|
||||||
clickedSlot[0] = true;
|
|
||||||
selectedSlot = slot;
|
|
||||||
editingField.setText(slot.getItemString());
|
|
||||||
if(shouldOpenMenu) {
|
|
||||||
menu.toggle(true);
|
|
||||||
for(Pair<CheckButtonRecipe, Slider[]> but : menu.getButtons()) {
|
|
||||||
for(Slider slider : but.getValue()) {
|
|
||||||
buttonList.remove(slider);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
menu.getFromMap(slot.getPropertyMap(), slot.getProperties());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case 2:
|
|
||||||
clickedSlot[0] = true;
|
|
||||||
selectedSlot = null;
|
|
||||||
if(shouldOpenMenu) {
|
|
||||||
menu.toggle(false);
|
|
||||||
for(Pair<CheckButtonRecipe, Slider[]> but : menu.getButtons()) {
|
|
||||||
for(Slider slider : but.getValue()) {
|
|
||||||
slider.updateSlider();
|
|
||||||
buttonList.remove(slider);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(editingField != null)
|
|
||||||
editingField.setText("");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
if(!clickedSlot[0]) {
|
|
||||||
super.mouseClicked(mouseX, mouseY, mouseButton);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public abstract String getOutputAdd();
|
|
||||||
|
|
||||||
public abstract String getOutputRemove();
|
|
||||||
|
|
||||||
protected void actionPerformed(GuiButton btn) {
|
|
||||||
if(btn.equals(add)) {
|
|
||||||
File scriptFile = new File(new File("scripts"), "/recipes.zs");
|
|
||||||
if(!scriptFile.exists()) {
|
|
||||||
generateFile(scriptFile);
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
List<String> lines = new LinkedList<>();
|
|
||||||
BufferedReader reader = new BufferedReader(new FileReader(scriptFile));
|
|
||||||
String line;
|
|
||||||
while((line = reader.readLine()) != null) {
|
|
||||||
lines.add(line);
|
|
||||||
}
|
|
||||||
if(lines.isEmpty()) {
|
|
||||||
generateFile(scriptFile);
|
|
||||||
while((line = reader.readLine()) != null) {
|
|
||||||
lines.add(line);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
reader.close();
|
|
||||||
PrintWriter writer = new PrintWriter(new FileWriter(scriptFile));
|
|
||||||
for(int i = 0; i < lines.size(); i++) {
|
|
||||||
String beforeLine = "";
|
|
||||||
if(i > 0)
|
|
||||||
beforeLine = lines.get(i - 1);
|
|
||||||
|
|
||||||
String lined = lines.get(i);
|
|
||||||
if(beforeLine.trim().equals("//#Add")) {
|
|
||||||
writer.println(getOutputAdd());
|
|
||||||
}
|
|
||||||
if(!lined.isEmpty()) {
|
|
||||||
writer.println(lined);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
writer.close();
|
|
||||||
} catch(IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(btn.equals(remove)) {
|
|
||||||
File scriptFile = new File(new File("scripts"), "/recipes.zs");
|
|
||||||
if(!scriptFile.exists()) {
|
|
||||||
generateFile(scriptFile);
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
List<String> lines = new LinkedList<>();
|
|
||||||
BufferedReader reader = new BufferedReader(new FileReader(scriptFile));
|
|
||||||
String line;
|
|
||||||
while((line = reader.readLine()) != null) {
|
|
||||||
lines.add(line);
|
|
||||||
}
|
|
||||||
if(lines.isEmpty()) {
|
|
||||||
generateFile(scriptFile);
|
|
||||||
while((line = reader.readLine()) != null) {
|
|
||||||
lines.add(line);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
reader.close();
|
|
||||||
PrintWriter writer = new PrintWriter(new FileWriter(scriptFile));
|
|
||||||
for(int i = 0; i < lines.size(); i++) {
|
|
||||||
String beforeLine = "";
|
|
||||||
if(i > 0)
|
|
||||||
beforeLine = lines.get(i - 1);
|
|
||||||
|
|
||||||
String lined = lines.get(i);
|
|
||||||
if(beforeLine.trim().equals("//#Remove")) {
|
|
||||||
writer.println(getOutputRemove());
|
|
||||||
}
|
|
||||||
if(!lined.isEmpty()) {
|
|
||||||
writer.println(lined);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
writer.close();
|
|
||||||
} catch(IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public abstract ResourceLocation getTexture();
|
|
||||||
|
|
||||||
protected void drawGuiContainerBackgroundLayer(float partialTicks, int mouseX, int mouseY) {
|
|
||||||
GlStateManager.pushAttrib();
|
|
||||||
GL11.glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
|
|
||||||
Minecraft.getMinecraft().renderEngine.bindTexture(getTexture());
|
|
||||||
drawTexturedModalRect(guiLeft, guiTop, 0, 0, xSize, ySize);
|
|
||||||
GlStateManager.popAttrib();
|
|
||||||
if(selectedSlot != null) {
|
|
||||||
GlStateManager.colorMask(true, true, true, false);
|
|
||||||
this.drawGradientRect(guiLeft + selectedSlot.xPos, guiTop + selectedSlot.yPos, guiLeft + selectedSlot.xPos + 16, guiTop + selectedSlot.yPos + 16, Color.cyan.darker().getRGB(), Color.cyan.darker().getRGB());
|
|
||||||
GlStateManager.colorMask(true, true, true, true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<GuiButton> getButtonList() {
|
|
||||||
return this.buttonList;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getGuiLeft() {
|
|
||||||
return guiLeft;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getGuiTop() {
|
|
||||||
return guiTop;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getXSize() {
|
|
||||||
return xSize;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getYSize() {
|
|
||||||
return ySize;
|
|
||||||
}
|
|
||||||
|
|
||||||
public GuiMenu getMenu() {
|
|
||||||
return menu;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public void generateFile(File f) {
|
|
||||||
try {
|
|
||||||
f.createNewFile();
|
|
||||||
PrintWriter writer = new PrintWriter(new FileWriter(f));
|
|
||||||
writer.println("//This file was created via CT-GUI! Editing it is not advised!");
|
|
||||||
writer.println("//Don't touch me!");
|
|
||||||
writer.println("//#Remove");
|
|
||||||
writer.println();
|
|
||||||
writer.println("//Don't touch me!");
|
|
||||||
writer.println("//#Add");
|
|
||||||
writer.println();
|
|
||||||
writer.println("//File End");
|
|
||||||
writer.close();
|
|
||||||
} catch(IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,30 +0,0 @@
|
|||||||
package com.blamejared.ctgui.api;
|
|
||||||
|
|
||||||
import net.minecraftforge.fml.common.network.IGuiHandler;
|
|
||||||
|
|
||||||
import java.util.*;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by Jared.
|
|
||||||
*/
|
|
||||||
public class GuiRegistry {
|
|
||||||
|
|
||||||
public static Map<List<Integer>, IGuiHandler> guiMap = new HashMap<>();
|
|
||||||
|
|
||||||
public static void registerGui(List<Integer> idRange, IGuiHandler handler) {
|
|
||||||
getGuiMap().put(idRange, handler);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static IGuiHandler getHandlerForID(int id) {
|
|
||||||
for(Map.Entry<List<Integer>, IGuiHandler> entry : getGuiMap().entrySet()) {
|
|
||||||
if(entry.getKey().contains(id)) {
|
|
||||||
return entry.getValue();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Map<List<Integer>, IGuiHandler> getGuiMap() {
|
|
||||||
return guiMap;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,26 +0,0 @@
|
|||||||
package com.blamejared.ctgui.api;
|
|
||||||
|
|
||||||
import net.minecraftforge.fml.client.config.GuiSlider;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by Jared.
|
|
||||||
*/
|
|
||||||
public class Slider extends GuiSlider {
|
|
||||||
|
|
||||||
private String propertyKey;
|
|
||||||
|
|
||||||
public Slider(String propertyKey, int id, int xPos, int yPos, int width, int height, String prefix, String suf, double minVal, double maxVal, double currentVal, boolean showDec, boolean drawStr) {
|
|
||||||
super(id, xPos, yPos, width, height, prefix, suf, minVal, maxVal, currentVal, showDec, drawStr);
|
|
||||||
this.propertyKey = propertyKey;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Slider(String propertyKey, int id, int xPos, int yPos, int width, int height, String prefix, String suf, double minVal, double maxVal, double currentVal, boolean showDec, boolean drawStr, ISlider par) {
|
|
||||||
super(id, xPos, yPos, width, height, prefix, suf, minVal, maxVal, currentVal, showDec, drawStr, par);
|
|
||||||
this.propertyKey = propertyKey;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public String getPropertyKey() {
|
|
||||||
return propertyKey;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,112 +0,0 @@
|
|||||||
package com.blamejared.ctgui.api;
|
|
||||||
|
|
||||||
import minetweaker.mc1102.data.NBTConverter;
|
|
||||||
import net.minecraft.entity.player.EntityPlayer;
|
|
||||||
import net.minecraft.inventory.*;
|
|
||||||
import net.minecraft.item.*;
|
|
||||||
import net.minecraftforge.oredict.OreDictionary;
|
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
|
||||||
import java.util.*;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by Jared.
|
|
||||||
*/
|
|
||||||
public class SlotRecipe extends Slot {
|
|
||||||
|
|
||||||
//key is the operation, value is the values, for more than 1 value, seperate using §
|
|
||||||
private Map<String, Boolean> propertyMap = new HashMap<>();
|
|
||||||
private Map<String, Integer> properties = new HashMap<>();
|
|
||||||
|
|
||||||
|
|
||||||
public SlotRecipe(IInventory inventoryIn, int index, int xPosition, int yPosition) {
|
|
||||||
super(inventoryIn, index, xPosition, yPosition);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onPickupFromSlot(EntityPlayer playerIn, ItemStack stack) {
|
|
||||||
super.onPickupFromSlot(playerIn, stack);
|
|
||||||
this.propertyMap.clear();
|
|
||||||
this.properties.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getSlotStackLimit() {
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isItemValid(@Nullable ItemStack stack) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getItemString() {
|
|
||||||
boolean matchAny = getPropertyFromMap("matchNotEmpty");
|
|
||||||
boolean metaWildcard = getPropertyFromMap("anyMetadata");
|
|
||||||
boolean oreDict = getPropertyFromMap("oreDictionary");
|
|
||||||
if(getStack() == null)
|
|
||||||
return "null";
|
|
||||||
String stackName = Item.REGISTRY.getNameForObject(getStack().getItem()).toString();
|
|
||||||
StringBuilder builder = new StringBuilder("<");
|
|
||||||
if(oreDict) {
|
|
||||||
int[] ids = OreDictionary.getOreIDs(getStack());
|
|
||||||
if(ids.length != 0) {
|
|
||||||
stackName = "ore:" + OreDictionary.getOreName(ids[0]);
|
|
||||||
} else
|
|
||||||
oreDict = false;
|
|
||||||
}
|
|
||||||
if(matchAny) {
|
|
||||||
stackName = "*";
|
|
||||||
}
|
|
||||||
builder.append(stackName);
|
|
||||||
if(!oreDict && !matchAny && (metaWildcard || getStack().getItemDamage() != 0))
|
|
||||||
builder.append(':').append(metaWildcard || getStack().getItemDamage() == OreDictionary.WILDCARD_VALUE ? "*" : getStack().getItemDamage());
|
|
||||||
builder.append('>');
|
|
||||||
if(getStack().stackSize > 1)
|
|
||||||
builder.append(" * ").append(getStack().stackSize);
|
|
||||||
if(getPropertyFromMap("anyDamage"))
|
|
||||||
builder.append(".anyDamage()");
|
|
||||||
if(getPropertyFromMap("onlyDamage"))
|
|
||||||
builder.append(".onlyDamaged()");
|
|
||||||
if(getPropertyFromMap("gted"))
|
|
||||||
builder.append(".onlyDamageAtLeast(").append("").append(getProperty("gted")).append(')');
|
|
||||||
if(getPropertyFromMap("ltd"))
|
|
||||||
builder.append(".onlyDamageAtMost(").append("").append(getProperty("ltd")).append(')');
|
|
||||||
if(getPropertyFromMap("betweenDamage")) {
|
|
||||||
builder.append(".onlyDamageBetween(").append("").append(getProperty("betweenDamageX")).append(", ").append("").append(getProperty("betweenDamageY")).append(')');
|
|
||||||
}
|
|
||||||
if(getPropertyFromMap("reuse"))
|
|
||||||
builder.append(".reuse()");
|
|
||||||
if(getPropertyFromMap("noreturn"))
|
|
||||||
builder.append(".noReturn()");
|
|
||||||
if(getPropertyFromMap("nbt")) {
|
|
||||||
if(this instanceof SlotRecipeOutput)
|
|
||||||
builder.append(String.format(".withTag(%s)", NBTConverter.from(getStack().getTagCompound(), false).toString()));
|
|
||||||
else
|
|
||||||
builder.append(String.format(".onlyWithTag(%s)", NBTConverter.from(getStack().getTagCompound(), false).toString()));
|
|
||||||
}
|
|
||||||
return builder.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
boolean getPropertyFromMap(String key) {
|
|
||||||
if(propertyMap.containsKey(key)) {
|
|
||||||
return propertyMap.get(key);
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
int getProperty(String key) {
|
|
||||||
if(properties.containsKey(key)) {
|
|
||||||
return properties.get(key);
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Map<String, Boolean> getPropertyMap() {
|
|
||||||
return propertyMap;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Map<String, Integer> getProperties() {
|
|
||||||
return properties;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,13 +0,0 @@
|
|||||||
package com.blamejared.ctgui.api;
|
|
||||||
|
|
||||||
import net.minecraft.inventory.IInventory;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by Jared.
|
|
||||||
*/
|
|
||||||
public class SlotRecipeOutput extends SlotRecipe {
|
|
||||||
|
|
||||||
public SlotRecipeOutput(IInventory inventoryIn, int index, int xPosition, int yPosition) {
|
|
||||||
super(inventoryIn, index, xPosition, yPosition);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,33 +0,0 @@
|
|||||||
package com.blamejared.ctgui.client;
|
|
||||||
|
|
||||||
import com.blamejared.ctgui.MTRecipe;
|
|
||||||
import com.blamejared.ctgui.api.GuiRegistry;
|
|
||||||
import net.minecraft.entity.player.EntityPlayer;
|
|
||||||
import net.minecraft.world.World;
|
|
||||||
import net.minecraftforge.fml.common.network.*;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by Jared.
|
|
||||||
*/
|
|
||||||
public class GuiHandler implements IGuiHandler {
|
|
||||||
|
|
||||||
public GuiHandler() {
|
|
||||||
NetworkRegistry.INSTANCE.registerGuiHandler(MTRecipe.INSTANCE, this);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Object getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {
|
|
||||||
if(GuiRegistry.getHandlerForID(ID) == null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return GuiRegistry.getHandlerForID(ID).getServerGuiElement(ID, player, world, x, y, z);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {
|
|
||||||
if(GuiRegistry.getHandlerForID(ID) == null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return GuiRegistry.getHandlerForID(ID).getClientGuiElement(ID, player, world, x, y, z);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-35
@@ -1,35 +0,0 @@
|
|||||||
package com.blamejared.ctgui.client;
|
|
||||||
|
|
||||||
import com.blamejared.ctgui.client.gui.craftingtable.*;
|
|
||||||
import com.blamejared.ctgui.client.gui.furnace.*;
|
|
||||||
import net.minecraft.entity.player.EntityPlayer;
|
|
||||||
import net.minecraft.world.World;
|
|
||||||
import net.minecraftforge.fml.common.network.IGuiHandler;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by Jared.
|
|
||||||
*/
|
|
||||||
public class GuiHandlerVanilla implements IGuiHandler {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Object getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {
|
|
||||||
switch(ID) {
|
|
||||||
case 1:
|
|
||||||
return new ContainerCraftingTable(player.inventory);
|
|
||||||
case 2:
|
|
||||||
return new ContainerFurnace(player.inventory);
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {
|
|
||||||
switch(ID) {
|
|
||||||
case 1:
|
|
||||||
return new GuiCraftingTable(new ContainerCraftingTable(player.inventory));
|
|
||||||
case 2:
|
|
||||||
return new GuiFurnace(new ContainerFurnace(player.inventory));
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-118
@@ -1,118 +0,0 @@
|
|||||||
package com.blamejared.ctgui.client;
|
|
||||||
|
|
||||||
import net.minecraft.entity.player.EntityPlayer;
|
|
||||||
import net.minecraft.inventory.*;
|
|
||||||
import net.minecraft.item.ItemStack;
|
|
||||||
import net.minecraft.util.text.ITextComponent;
|
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by Jared.
|
|
||||||
*/
|
|
||||||
public class InventoryFake implements IInventory {
|
|
||||||
|
|
||||||
private final int size;
|
|
||||||
private ItemStack[] items;
|
|
||||||
|
|
||||||
public InventoryFake(int size) {
|
|
||||||
this.size = size;
|
|
||||||
items = new ItemStack[size];
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getSizeInventory() {
|
|
||||||
return items.length;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Nullable
|
|
||||||
@Override
|
|
||||||
public ItemStack getStackInSlot(int index) {
|
|
||||||
return index >= this.getSizeInventory() ? null : items[index];
|
|
||||||
}
|
|
||||||
|
|
||||||
@Nullable
|
|
||||||
@Override
|
|
||||||
public ItemStack decrStackSize(int index, int count) {
|
|
||||||
return ItemStackHelper.getAndSplit(items, index, count);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Nullable
|
|
||||||
@Override
|
|
||||||
public ItemStack removeStackFromSlot(int index) {
|
|
||||||
return ItemStackHelper.getAndRemove(items, index);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setInventorySlotContents(int index, @Nullable ItemStack stack) {
|
|
||||||
this.items[index] = stack;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getInventoryStackLimit() {
|
|
||||||
return 64;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void markDirty() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isUsableByPlayer(EntityPlayer player) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void openInventory(EntityPlayer player) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void closeInventory(EntityPlayer player) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isItemValidForSlot(int index, ItemStack stack) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getField(int id) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setField(int id, int value) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getFieldCount() {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void clear() {
|
|
||||||
for(int i = 0; i < this.items.length; ++i) {
|
|
||||||
this.items[i] = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getName() {
|
|
||||||
return "Fake Inventory";
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean hasCustomName() {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ITextComponent getDisplayName() {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,210 +0,0 @@
|
|||||||
package com.blamejared.ctgui.client.gui;
|
|
||||||
|
|
||||||
import com.blamejared.ctgui.api.*;
|
|
||||||
import net.minecraftforge.fml.relauncher.*;
|
|
||||||
import org.apache.commons.lang3.tuple.*;
|
|
||||||
|
|
||||||
import java.util.*;
|
|
||||||
|
|
||||||
@SideOnly(Side.CLIENT)
|
|
||||||
public class GuiMenu {
|
|
||||||
|
|
||||||
// public Pair<CheckButtonRecipe, Slider[]> matchNotEmpty;
|
|
||||||
public Pair<CheckButtonRecipe, Slider[]> useOreDict;
|
|
||||||
public Pair<CheckButtonRecipe, Slider[]> matchAnyMetadata;
|
|
||||||
public Pair<CheckButtonRecipe, Slider[]> anyDamage;
|
|
||||||
public Pair<CheckButtonRecipe, Slider[]> onlyDamage;
|
|
||||||
// public Pair<CheckButtonRecipe, Slider[]> damage;
|
|
||||||
public Pair<CheckButtonRecipe, Slider[]> greaterThanEqualDamage;
|
|
||||||
public Pair<CheckButtonRecipe, Slider[]> lessThanDamage;
|
|
||||||
public Pair<CheckButtonRecipe, Slider[]> betweenDamage;
|
|
||||||
public Pair<CheckButtonRecipe, Slider[]> nbt;
|
|
||||||
// public Pair<CheckButtonRecipe, Slider[]> transformDamage;
|
|
||||||
// public Pair<CheckButtonRecipe, Slider[]> transformReplace;
|
|
||||||
public Pair<CheckButtonRecipe, Slider[]> reuse;
|
|
||||||
public Pair<CheckButtonRecipe, Slider[]> noReturn;
|
|
||||||
private GuiBase parent;
|
|
||||||
private int x;
|
|
||||||
private int y;
|
|
||||||
private List<Pair<CheckButtonRecipe, Slider[]>> buttons = new ArrayList<>();
|
|
||||||
// public Pair<CheckButtonRecipe, Slider[]> giveBack;
|
|
||||||
|
|
||||||
|
|
||||||
public GuiMenu() {
|
|
||||||
}
|
|
||||||
|
|
||||||
public void open(final GuiBase parent, int x, int y) {
|
|
||||||
this.parent = parent;
|
|
||||||
this.x = x;
|
|
||||||
this.y = y;
|
|
||||||
int buttonCount = 0;
|
|
||||||
// matchNotEmpty = new MutablePair<>(new CheckButtonRecipe(parent, 0, x, y + (15 * buttonCount++), "Match Not Empty", false, "matchNotEmpty"), new Slider[]{});
|
|
||||||
useOreDict = new MutablePair<>(new CheckButtonRecipe(parent, 1, x, y + (15 * buttonCount++), "Ore Dictionary", false, "oreDictionary"), new Slider[]{});
|
|
||||||
matchAnyMetadata = new MutablePair<>(new CheckButtonRecipe(parent, 2, x, y + (15 * buttonCount++), "Any Metadata", false, "anyMetadata"), new Slider[]{});
|
|
||||||
anyDamage = new MutablePair<>(new CheckButtonRecipe(parent, 3, x, y + (15 * buttonCount++), "Any Damage", false, "anyDamage"), new Slider[]{});
|
|
||||||
onlyDamage = new MutablePair<>(new CheckButtonRecipe(parent, 4, x, y + (15 * buttonCount++), "Only Damage", false, "onlyDamage"), new Slider[]{});
|
|
||||||
greaterThanEqualDamage = new MutablePair<>(new CheckButtonRecipe(parent, 6, x, y + (15 * buttonCount++), "X>=Damage", false, "gted"), new Slider[]{new Slider("gted", 10, x - 2, parent.getGuiTop() + parent.getYSize() + 20, parent.getXSize() + 102, 20, "X= ", "", 0, 0, 0, false, true, slider -> {
|
|
||||||
if(parent.selectedSlot != null && parent.selectedSlot.getStack() != null) {
|
|
||||||
parent.selectedSlot.getProperties().put(((Slider) slider).getPropertyKey(), slider.getValueInt());
|
|
||||||
}
|
|
||||||
})});
|
|
||||||
lessThanDamage = new MutablePair<>(new CheckButtonRecipe(parent, 7, x, y + (15 * buttonCount++), "Damage<X", false, "ltd"), new Slider[]{new Slider("ltd", 11, x - 2, parent.getGuiTop() + parent.getYSize() + 20, parent.getXSize() + 102, 20, "X= ", "", 0, 0, 0, false, true, slider -> {
|
|
||||||
if(parent.selectedSlot != null && parent.selectedSlot.getStack() != null) {
|
|
||||||
parent.selectedSlot.getProperties().put(((Slider) slider).getPropertyKey(), slider.getValueInt());
|
|
||||||
}
|
|
||||||
})});
|
|
||||||
betweenDamage = new MutablePair<>(new CheckButtonRecipe(parent, 8, x, y + (15 * buttonCount++), "X<Damage<Y", false, "betweenDamage"), new Slider[]{new Slider("betweenDamageX", 12, x - 2, parent.getGuiTop() + parent.getYSize() + 20, parent.getXSize() + 102, 20, "X= ", "", 0, 0, 0, false, true, slider -> {
|
|
||||||
if(parent.selectedSlot != null && parent.selectedSlot.getStack() != null) {
|
|
||||||
parent.selectedSlot.getProperties().put(((Slider) slider).getPropertyKey(), slider.getValueInt());
|
|
||||||
}
|
|
||||||
}), new Slider("betweenDamageY", 13, x - 2, parent.getGuiTop() + parent.getYSize() + 44, parent.getXSize() + 102, 20, "Y= ", "", 0, 0, 0, false, true, slider -> {
|
|
||||||
if(parent.selectedSlot != null && parent.selectedSlot.getStack() != null) {
|
|
||||||
parent.selectedSlot.getProperties().put(((Slider) slider).getPropertyKey(), slider.getValueInt());
|
|
||||||
}
|
|
||||||
})});
|
|
||||||
|
|
||||||
nbt = new MutablePair<>(new CheckButtonRecipe(parent, 8, x, y + (15 * buttonCount++), "NBT", false, "nbt"), new Slider[]{});
|
|
||||||
|
|
||||||
reuse = new MutablePair<>(new CheckButtonRecipe(parent, 0, x, y + (15 * buttonCount++), "Reuse", false, "reuse"), new Slider[]{});
|
|
||||||
noReturn = new MutablePair<>(new CheckButtonRecipe(parent, 0, x, y + (15 * buttonCount), "No Return", false, "noreturn"), new Slider[]{});
|
|
||||||
|
|
||||||
|
|
||||||
this.buttons.add(useOreDict);
|
|
||||||
this.buttons.add(matchAnyMetadata);
|
|
||||||
this.buttons.add(anyDamage);
|
|
||||||
this.buttons.add(onlyDamage);
|
|
||||||
|
|
||||||
this.buttons.add(greaterThanEqualDamage);
|
|
||||||
this.buttons.add(lessThanDamage);
|
|
||||||
this.buttons.add(betweenDamage);
|
|
||||||
this.buttons.add(nbt);
|
|
||||||
|
|
||||||
|
|
||||||
this.buttons.add(reuse);
|
|
||||||
this.buttons.add(noReturn);
|
|
||||||
|
|
||||||
for(Pair<CheckButtonRecipe, Slider[]> but : this.buttons) {
|
|
||||||
parent.getButtonList().add(but.getLeft());
|
|
||||||
}
|
|
||||||
|
|
||||||
useOreDict.getLeft().setIncompatible(Arrays.asList(new CheckButtonRecipe[]{matchAnyMetadata.getLeft(), anyDamage.getLeft(), onlyDamage.getLeft(), greaterThanEqualDamage.getLeft(), lessThanDamage.getLeft(), betweenDamage.getLeft(), nbt.getLeft()}));
|
|
||||||
matchAnyMetadata.getLeft().setIncompatible(Arrays.asList(new CheckButtonRecipe[]{useOreDict.getLeft(), anyDamage.getLeft(), onlyDamage.getLeft(), greaterThanEqualDamage.getLeft(), lessThanDamage.getLeft(), betweenDamage.getLeft()}));
|
|
||||||
anyDamage.getLeft().setIncompatible(Arrays.asList(new CheckButtonRecipe[]{useOreDict.getLeft(), matchAnyMetadata.getLeft(), onlyDamage.getLeft(), greaterThanEqualDamage.getLeft(), lessThanDamage.getLeft(), betweenDamage.getLeft()}));
|
|
||||||
onlyDamage.getLeft().setIncompatible(Arrays.asList(new CheckButtonRecipe[]{useOreDict.getLeft(), matchAnyMetadata.getLeft(), anyDamage.getLeft(), greaterThanEqualDamage.getLeft(), lessThanDamage.getLeft(), betweenDamage.getLeft()}));
|
|
||||||
|
|
||||||
greaterThanEqualDamage.getLeft().setIncompatible(Arrays.asList(new CheckButtonRecipe[]{useOreDict.getLeft(), matchAnyMetadata.getLeft(), anyDamage.getLeft(), onlyDamage.getLeft(), lessThanDamage.getLeft(), betweenDamage.getLeft()}));
|
|
||||||
lessThanDamage.getLeft().setIncompatible(Arrays.asList(new CheckButtonRecipe[]{useOreDict.getLeft(), matchAnyMetadata.getLeft(), anyDamage.getLeft(), onlyDamage.getLeft(), greaterThanEqualDamage.getLeft(), betweenDamage.getLeft()}));
|
|
||||||
betweenDamage.getLeft().setIncompatible(Arrays.asList(new CheckButtonRecipe[]{useOreDict.getLeft(), matchAnyMetadata.getLeft(), anyDamage.getLeft(), onlyDamage.getLeft(), greaterThanEqualDamage.getLeft(), lessThanDamage.getLeft()}));
|
|
||||||
|
|
||||||
nbt.getLeft().setIncompatible(Arrays.asList(new CheckButtonRecipe[]{useOreDict.getLeft()}));
|
|
||||||
noReturn.getLeft().setIncompatible(Collections.singletonList(reuse.getLeft()));
|
|
||||||
reuse.getLeft().setIncompatible(Collections.singletonList(noReturn.getLeft()));
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public void close(GuiBase parent) {
|
|
||||||
this.parent = parent;
|
|
||||||
if(!parent.getButtonList().isEmpty()) {
|
|
||||||
this.parent.getButtonList().remove(useOreDict.getLeft());
|
|
||||||
this.parent.getButtonList().remove(matchAnyMetadata.getLeft());
|
|
||||||
this.parent.getButtonList().remove(anyDamage.getLeft());
|
|
||||||
this.parent.getButtonList().remove(onlyDamage.getLeft());
|
|
||||||
this.parent.getButtonList().remove(greaterThanEqualDamage.getLeft());
|
|
||||||
this.parent.getButtonList().remove(lessThanDamage.getLeft());
|
|
||||||
this.parent.getButtonList().remove(betweenDamage.getLeft());
|
|
||||||
|
|
||||||
this.parent.getButtonList().remove(reuse.getLeft());
|
|
||||||
this.parent.getButtonList().remove(noReturn.getLeft());
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public void setState(boolean active) {
|
|
||||||
useOreDict.getLeft().setIsChecked(active);
|
|
||||||
matchAnyMetadata.getLeft().setIsChecked(active);
|
|
||||||
anyDamage.getLeft().setIsChecked(active);
|
|
||||||
onlyDamage.getLeft().setIsChecked(active);
|
|
||||||
|
|
||||||
greaterThanEqualDamage.getLeft().setIsChecked(active);
|
|
||||||
lessThanDamage.getLeft().setIsChecked(active);
|
|
||||||
betweenDamage.getLeft().setIsChecked(active);
|
|
||||||
reuse.getLeft().setIsChecked(active);
|
|
||||||
noReturn.getLeft().setIsChecked(active);
|
|
||||||
nbt.getLeft().setIsChecked(active);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public void toggle(boolean active) {
|
|
||||||
useOreDict.getLeft().enabled = active;
|
|
||||||
matchAnyMetadata.getLeft().enabled = active;
|
|
||||||
anyDamage.getLeft().enabled = active;
|
|
||||||
onlyDamage.getLeft().enabled = active;
|
|
||||||
greaterThanEqualDamage.getLeft().enabled = active;
|
|
||||||
lessThanDamage.getLeft().enabled = active;
|
|
||||||
betweenDamage.getLeft().enabled = active;
|
|
||||||
reuse.getLeft().enabled = active;
|
|
||||||
noReturn.getLeft().enabled = active;
|
|
||||||
nbt.getLeft().enabled = active;
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public void getFromMap(Map<String, Boolean> propertyMap, Map<String, Integer> properties) {
|
|
||||||
useOreDict.getLeft().setIsChecked(getPropertyFromMap(propertyMap, useOreDict.getLeft().getPropertyKey()));
|
|
||||||
matchAnyMetadata.getLeft().setIsChecked(getPropertyFromMap(propertyMap, matchAnyMetadata.getLeft().getPropertyKey()));
|
|
||||||
anyDamage.getLeft().setIsChecked(getPropertyFromMap(propertyMap, anyDamage.getLeft().getPropertyKey()));
|
|
||||||
onlyDamage.getLeft().setIsChecked(getPropertyFromMap(propertyMap, onlyDamage.getLeft().getPropertyKey()));
|
|
||||||
greaterThanEqualDamage.getLeft().setIsChecked(getPropertyFromMap(propertyMap, greaterThanEqualDamage.getLeft().getPropertyKey()));
|
|
||||||
lessThanDamage.getLeft().setIsChecked(getPropertyFromMap(propertyMap, lessThanDamage.getLeft().getPropertyKey()));
|
|
||||||
betweenDamage.getLeft().setIsChecked(getPropertyFromMap(propertyMap, betweenDamage.getLeft().getPropertyKey()));
|
|
||||||
reuse.getLeft().setIsChecked(getPropertyFromMap(propertyMap, reuse.getLeft().getPropertyKey()));
|
|
||||||
noReturn.getLeft().setIsChecked(getPropertyFromMap(propertyMap, noReturn.getLeft().getPropertyKey()));
|
|
||||||
nbt.getLeft().setIsChecked(getPropertyFromMap(propertyMap, nbt.getLeft().getPropertyKey()));
|
|
||||||
}
|
|
||||||
|
|
||||||
boolean getPropertyFromMap(Map<String, Boolean> propertyMap, String key) {
|
|
||||||
if(propertyMap.containsKey(key)) {
|
|
||||||
return propertyMap.get(key);
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
Object getProperty(Map<String, Integer> propertyMap, String key) {
|
|
||||||
if(propertyMap.containsKey(key)) {
|
|
||||||
return propertyMap.get(key);
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getX() {
|
|
||||||
return x;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getY() {
|
|
||||||
return y;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getWidth() {
|
|
||||||
return 11;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getHeight() {
|
|
||||||
return 55;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public Slider[] getSliders(CheckButtonRecipe check) {
|
|
||||||
for(Pair<CheckButtonRecipe, Slider[]> pair : this.buttons) {
|
|
||||||
if(pair.getLeft().getPropertyKey().equals(check.getPropertyKey())) {
|
|
||||||
return pair.getValue();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return new Slider[0];
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<Pair<CheckButtonRecipe, Slider[]>> getButtons() {
|
|
||||||
return buttons;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-36
@@ -1,36 +0,0 @@
|
|||||||
package com.blamejared.ctgui.client.gui.craftingtable;
|
|
||||||
|
|
||||||
import com.blamejared.ctgui.api.*;
|
|
||||||
import net.minecraft.entity.player.InventoryPlayer;
|
|
||||||
import net.minecraft.inventory.*;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by Jared.
|
|
||||||
*/
|
|
||||||
public class ContainerCraftingTable extends ContainerBase {
|
|
||||||
|
|
||||||
public InventoryCrafting craftMatrix = new InventoryCrafting(this, 3, 3);
|
|
||||||
public IInventory craftResult = new InventoryCraftResult();
|
|
||||||
|
|
||||||
public ContainerCraftingTable(InventoryPlayer invPlayer) {
|
|
||||||
//output
|
|
||||||
this.addSlotToContainer(new SlotRecipeOutput(craftResult, 0, 124, 35));
|
|
||||||
//Slots
|
|
||||||
for(int i = 0; i < 3; ++i) {
|
|
||||||
for(int j = 0; j < 3; ++j) {
|
|
||||||
this.addSlotToContainer(new SlotRecipe(craftMatrix, j + i * 3, 30 + j * 18, 17 + i * 18));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
//Player
|
|
||||||
for(int x = 0; x < 9; x++) {
|
|
||||||
addSlotToContainer(new Slot(invPlayer, x, 8 + 18 * x, 142));
|
|
||||||
}
|
|
||||||
|
|
||||||
for(int y = 0; y < 3; y++) {
|
|
||||||
for(int x = 0; x < 9; x++) {
|
|
||||||
addSlotToContainer(new Slot(invPlayer, x + y * 9 + 9, 8 + 18 * x, 84 + y * 18));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
-93
@@ -1,93 +0,0 @@
|
|||||||
package com.blamejared.ctgui.client.gui.craftingtable;
|
|
||||||
|
|
||||||
import com.blamejared.ctgui.api.*;
|
|
||||||
import net.minecraft.util.ResourceLocation;
|
|
||||||
|
|
||||||
import java.util.*;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by Jared.
|
|
||||||
*/
|
|
||||||
public class GuiCraftingTable extends GuiBase {
|
|
||||||
|
|
||||||
private CheckButton shaped;
|
|
||||||
private CheckButton shapeless;
|
|
||||||
private CheckButton mirror;
|
|
||||||
public GuiCraftingTable(ContainerBase container) {
|
|
||||||
super(container, 176, 166, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void initGui() {
|
|
||||||
super.initGui();
|
|
||||||
shaped = new CheckButton(this, 2910, getGuiLeft(), getGuiTop() + getYSize() + 4, "Shaped", true);
|
|
||||||
shapeless = new CheckButton(this, 2911, getGuiLeft() + 54, getGuiTop() + getYSize() + 4, "Shapeless", false);
|
|
||||||
mirror = new CheckButton(this, 2912, getGuiLeft() + 54 + 74, getGuiTop() + getYSize() + 4, "Mirror", false);
|
|
||||||
shaped.setBackgroundSize(50);
|
|
||||||
shapeless.setBackgroundSize(70);
|
|
||||||
mirror.setBackgroundSize(50);
|
|
||||||
|
|
||||||
getButtonList().add(shapeless);
|
|
||||||
getButtonList().add(shaped);
|
|
||||||
getButtonList().add(mirror);
|
|
||||||
shaped.setIncompatible(Collections.singletonList(shapeless));
|
|
||||||
shapeless.setIncompatible(Arrays.asList(shaped, mirror));
|
|
||||||
mirror.setIncompatible(Collections.singletonList(remove));
|
|
||||||
shaped.setIsChecked(true);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getOutputAdd() {
|
|
||||||
String type = "add";
|
|
||||||
boolean shapel = false;
|
|
||||||
if(shapeless.isChecked()) {
|
|
||||||
type += "Shapeless";
|
|
||||||
shapel = true;
|
|
||||||
} else if(shaped.isChecked()) {
|
|
||||||
type += "Shaped";
|
|
||||||
}
|
|
||||||
if(mirror.isChecked()) {
|
|
||||||
type += "Mirrored";
|
|
||||||
}
|
|
||||||
if(shapel) {
|
|
||||||
return String.format("recipes.%s(%s, [%s%s%s%s%s%s%s%s%s]);", type, container.getRecipeSlots().get(0).getItemString(), getShapelessItem(container.getRecipeSlots().get(1), true), getShapelessItem(container.getRecipeSlots().get(2), false), getShapelessItem(container.getRecipeSlots().get(3), false), getShapelessItem(container.getRecipeSlots().get(4), false), getShapelessItem(container.getRecipeSlots().get(5), false), getShapelessItem(container.getRecipeSlots().get(6), false), getShapelessItem(container.getRecipeSlots().get(7), false), getShapelessItem(container.getRecipeSlots().get(8), false), getShapelessItem(container.getRecipeSlots().get(9), false));
|
|
||||||
}
|
|
||||||
return String.format("recipes.%s(%s, [[%s, %s, %s],[%s, %s, %s], [%s, %s, %s]]);", type, container.getRecipeSlots().get(0).getItemString(), container.getRecipeSlots().get(1).getItemString(), container.getRecipeSlots().get(2).getItemString(), container.getRecipeSlots().get(3).getItemString(), container.getRecipeSlots().get(4).getItemString(), container.getRecipeSlots().get(5).getItemString(), container.getRecipeSlots().get(6).getItemString(), container.getRecipeSlots().get(7).getItemString(), container.getRecipeSlots().get(8).getItemString(), container.getRecipeSlots().get(9).getItemString());
|
|
||||||
}
|
|
||||||
|
|
||||||
private String getShapelessItem(SlotRecipe slot, boolean first) {
|
|
||||||
String ret = "";
|
|
||||||
if(slot.getHasStack()) {
|
|
||||||
if(!first) {
|
|
||||||
ret += ", ";
|
|
||||||
}
|
|
||||||
ret += slot.getItemString();
|
|
||||||
}
|
|
||||||
return ret.isEmpty() ? ret : ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getOutputRemove() {
|
|
||||||
boolean hasrecipe = false;
|
|
||||||
for(int i = 1; i < container.getRecipeSlots().size(); i++) {
|
|
||||||
SlotRecipe slot = container.getRecipeSlots().get(i);
|
|
||||||
if(slot.getHasStack()) {
|
|
||||||
hasrecipe = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
boolean shapel = shapeless.isChecked();
|
|
||||||
if(shapel) {
|
|
||||||
return String.format("recipes.removeShapeless(%s, [%s%s%s%s%s%s%s%s%s]);", container.getRecipeSlots().get(0).getItemString(), getShapelessItem(container.getRecipeSlots().get(1), true), getShapelessItem(container.getRecipeSlots().get(2), false), getShapelessItem(container.getRecipeSlots().get(3), false), getShapelessItem(container.getRecipeSlots().get(4), false), getShapelessItem(container.getRecipeSlots().get(5), false), getShapelessItem(container.getRecipeSlots().get(6), false), getShapelessItem(container.getRecipeSlots().get(7), false), getShapelessItem(container.getRecipeSlots().get(8), false), getShapelessItem(container.getRecipeSlots().get(9), false));
|
|
||||||
}
|
|
||||||
return hasrecipe ? String.format("recipes.removeShaped(%s, [[%s, %s, %s],[%s, %s, %s], [%s, %s, %s]]);", container.getRecipeSlots().get(0).getItemString(), container.getRecipeSlots().get(1).getItemString(), container.getRecipeSlots().get(2).getItemString(), container.getRecipeSlots().get(3).getItemString(), container.getRecipeSlots().get(4).getItemString(), container.getRecipeSlots().get(5).getItemString(), container.getRecipeSlots().get(6).getItemString(), container.getRecipeSlots().get(7).getItemString(), container.getRecipeSlots().get(8).getItemString(), container.getRecipeSlots().get(9).getItemString()) : String.format("recipes.remove(%s);", container.getRecipeSlots().get(0).getItemString());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ResourceLocation getTexture() {
|
|
||||||
return new ResourceLocation("textures/gui/container/crafting_table.png");
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
-36
@@ -1,36 +0,0 @@
|
|||||||
package com.blamejared.ctgui.client.gui.furnace;
|
|
||||||
|
|
||||||
import com.blamejared.ctgui.api.*;
|
|
||||||
import com.blamejared.ctgui.client.InventoryFake;
|
|
||||||
import net.minecraft.entity.player.InventoryPlayer;
|
|
||||||
import net.minecraft.inventory.*;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by Jared.
|
|
||||||
*/
|
|
||||||
public class ContainerFurnace extends ContainerBase {
|
|
||||||
|
|
||||||
public IInventory inventory = new InventoryFake(1);
|
|
||||||
public IInventory craftResult = new InventoryCraftResult();
|
|
||||||
|
|
||||||
public ContainerFurnace(InventoryPlayer invPlayer) {
|
|
||||||
//output
|
|
||||||
this.addSlotToContainer(new SlotRecipeOutput(craftResult, 0, 116, 35));
|
|
||||||
|
|
||||||
//Slots
|
|
||||||
this.addSlotToContainer(new SlotRecipe(inventory, 0, 56, 17));
|
|
||||||
|
|
||||||
//Player
|
|
||||||
for(int x = 0; x < 9; x++) {
|
|
||||||
addSlotToContainer(new Slot(invPlayer, x, 8 + 18 * x, 142));
|
|
||||||
}
|
|
||||||
|
|
||||||
for(int y = 0; y < 3; y++) {
|
|
||||||
for(int x = 0; x < 9; x++) {
|
|
||||||
addSlotToContainer(new Slot(invPlayer, x + y * 9 + 9, 8 + 18 * x, 84 + y * 18));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
-48
@@ -1,48 +0,0 @@
|
|||||||
package com.blamejared.ctgui.client.gui.furnace;
|
|
||||||
|
|
||||||
import com.blamejared.ctgui.api.*;
|
|
||||||
import net.minecraft.util.ResourceLocation;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by Jared.
|
|
||||||
*/
|
|
||||||
public class GuiFurnace extends GuiBase {
|
|
||||||
|
|
||||||
private Slider xpSlider;
|
|
||||||
|
|
||||||
public GuiFurnace(ContainerBase container) {
|
|
||||||
super(container, 176, 166, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void initGui() {
|
|
||||||
super.initGui();
|
|
||||||
xpSlider = new Slider("slider", 10, getGuiLeft() - 102 - 2, getGuiTop() + getYSize() + 20, getXSize() + 102, 20, "XP= ", "", 0, 50, 0, true, true);
|
|
||||||
getButtonList().add(xpSlider);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void updateScreen() {
|
|
||||||
super.updateScreen();
|
|
||||||
if(!container.getRecipeSlots().get(1).getHasStack()) {
|
|
||||||
add.enabled = false;
|
|
||||||
remove.enabled = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getOutputAdd() {
|
|
||||||
return String.format("furnace.addRecipe(%s, %s, %s);", container.getRecipeSlots().get(0).getItemString(), container.getRecipeSlots().get(1).getItemString(), xpSlider.getValue() + 0f);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getOutputRemove() {
|
|
||||||
return String.format("furnace.remove(%s%s);", container.getRecipeSlots().get(0).getItemString(), container.getRecipeSlots().get(1).getHasStack() ? ", " + container.getRecipeSlots().get(1).getItemString() : "");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ResourceLocation getTexture() {
|
|
||||||
return new ResourceLocation("textures/gui/container/furnace.png");
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
-42
@@ -1,42 +0,0 @@
|
|||||||
package com.blamejared.ctgui.commands;
|
|
||||||
|
|
||||||
import com.blamejared.ctgui.MTRecipe;
|
|
||||||
import com.blamejared.ctgui.api.GuiRegistry;
|
|
||||||
import net.minecraft.command.*;
|
|
||||||
import net.minecraft.entity.player.EntityPlayer;
|
|
||||||
import net.minecraft.server.MinecraftServer;
|
|
||||||
import net.minecraft.util.text.TextComponentString;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by Jared.
|
|
||||||
*/
|
|
||||||
public class CommandCTGUI extends CommandBase {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getName() {
|
|
||||||
return "CTGUI";
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getUsage(ICommandSender sender) {
|
|
||||||
return "CTGUI <id>";
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getRequiredPermissionLevel() {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException {
|
|
||||||
if(args.length == 0 || Integer.parseInt(args[0]) < 1 || GuiRegistry.getHandlerForID(Integer.parseInt(args[0])) == null) {
|
|
||||||
sender.sendMessage(new TextComponentString("Invalid ID!"));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(sender instanceof EntityPlayer) {
|
|
||||||
EntityPlayer player = (EntityPlayer) sender;
|
|
||||||
player.openGui(MTRecipe.INSTANCE, Integer.parseInt(args[0]), sender.getEntityWorld(), 0, 0, 0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,18 +0,0 @@
|
|||||||
package com.blamejared.ctgui.proxy;
|
|
||||||
|
|
||||||
import net.minecraft.client.Minecraft;
|
|
||||||
import net.minecraft.entity.player.EntityPlayer;
|
|
||||||
|
|
||||||
public class ClientProxy extends CommonProxy {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void registerGuis() {
|
|
||||||
super.registerGuis();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public EntityPlayer getPlayer() {
|
|
||||||
return Minecraft.getMinecraft().player;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,17 +0,0 @@
|
|||||||
package com.blamejared.ctgui.proxy;
|
|
||||||
|
|
||||||
import com.blamejared.ctgui.client.GuiHandler;
|
|
||||||
import net.minecraft.entity.player.EntityPlayer;
|
|
||||||
|
|
||||||
public class CommonProxy {
|
|
||||||
|
|
||||||
public void registerGuis() {
|
|
||||||
new GuiHandler();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public EntityPlayer getPlayer() {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
package com.blamejared.ctgui.reference;
|
|
||||||
|
|
||||||
public class Reference {
|
|
||||||
|
|
||||||
public static final String MOD_ID = "ctgui";
|
|
||||||
public static final String MOD_NAME = "CT-GUI";
|
|
||||||
public static final String VERSION = "1.0.0";
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,74 +0,0 @@
|
|||||||
package minetweaker.mc1102;
|
|
||||||
|
|
||||||
import minetweaker.*;
|
|
||||||
import minetweaker.api.event.*;
|
|
||||||
import minetweaker.api.minecraft.MineTweakerMC;
|
|
||||||
import minetweaker.api.player.IPlayer;
|
|
||||||
import minetweaker.api.recipes.*;
|
|
||||||
import minetweaker.mc1102.item.MCItemStack;
|
|
||||||
import minetweaker.mc1102.network.MineTweakerLoadScriptsPacket;
|
|
||||||
import minetweaker.mc1102.player.MCPlayer;
|
|
||||||
import minetweaker.mc1102.recipes.MCCraftingInventory;
|
|
||||||
import minetweaker.mc1102.world.MCDimension;
|
|
||||||
import net.minecraft.entity.player.EntityPlayerMP;
|
|
||||||
import net.minecraft.inventory.InventoryCrafting;
|
|
||||||
import net.minecraft.item.crafting.CraftingManager;
|
|
||||||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
|
||||||
import net.minecraftforge.fml.common.gameevent.PlayerEvent;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Stan
|
|
||||||
*/
|
|
||||||
public class FMLEventHandler {
|
|
||||||
|
|
||||||
@SubscribeEvent
|
|
||||||
public void onPlayerLoggedIn(PlayerEvent.PlayerLoggedInEvent ev) {
|
|
||||||
if(ev.player instanceof EntityPlayerMP) {
|
|
||||||
EntityPlayerMP player = (EntityPlayerMP) ev.player;
|
|
||||||
MineTweakerMod.NETWORK.sendTo(new MineTweakerLoadScriptsPacket(MineTweakerAPI.tweaker.getScriptData()), player);
|
|
||||||
}
|
|
||||||
|
|
||||||
MineTweakerImplementationAPI.events.publishPlayerLoggedIn(new PlayerLoggedInEvent(MineTweakerMC.getIPlayer(ev.player)));
|
|
||||||
}
|
|
||||||
|
|
||||||
@SubscribeEvent
|
|
||||||
public void onPlayerItemCrafted(PlayerEvent.ItemCraftedEvent ev) {
|
|
||||||
IPlayer iPlayer = MineTweakerMC.getIPlayer(ev.player);
|
|
||||||
if(MineTweakerMod.INSTANCE.recipes.hasTransformerRecipes()) {
|
|
||||||
MineTweakerMod.INSTANCE.recipes.applyTransformations(MCCraftingInventory.get(ev.craftMatrix, ev.player), iPlayer);
|
|
||||||
}
|
|
||||||
if(ev.craftMatrix instanceof InventoryCrafting) {
|
|
||||||
|
|
||||||
CraftingManager.getInstance().getRecipeList().stream().filter(i -> i instanceof IMTRecipe && i.getRecipeOutput().isItemEqual(ev.crafting)).forEach(i -> {
|
|
||||||
IMTRecipe rec = (IMTRecipe) i;
|
|
||||||
if(rec.getRecipe() instanceof ShapedRecipe) {
|
|
||||||
ShapedRecipe r = (ShapedRecipe) rec.getRecipe();
|
|
||||||
if(r.getAction() != null) {
|
|
||||||
r.getAction().process(new MCItemStack(ev.crafting), new CraftingInfo(new MCCraftingInventory(ev.craftMatrix, ev.player), new MCDimension(ev.player.world)), new MCPlayer(ev.player));
|
|
||||||
}
|
|
||||||
} else if(rec.getRecipe() instanceof ShapelessRecipe) {
|
|
||||||
ShapelessRecipe r = (ShapelessRecipe) rec.getRecipe();
|
|
||||||
if(r.getAction() != null) {
|
|
||||||
r.getAction().process(new MCItemStack(ev.crafting), new CraftingInfo(new MCCraftingInventory(ev.craftMatrix, ev.player), new MCDimension(ev.player.world)), new MCPlayer(ev.player));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
if(MineTweakerImplementationAPI.events.hasPlayerCrafted()) {
|
|
||||||
MineTweakerImplementationAPI.events.publishPlayerCrafted(new PlayerCraftedEvent(iPlayer, MineTweakerMC.getIItemStack(ev.crafting), MCCraftingInventory.get(ev.craftMatrix, ev.player)));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@SubscribeEvent
|
|
||||||
public void onPlayerItemSmelted(PlayerEvent.ItemSmeltedEvent ev) {
|
|
||||||
if(MineTweakerImplementationAPI.events.hasPlayerSmelted()) {
|
|
||||||
MineTweakerImplementationAPI.events.publishPlayerSmelted(new PlayerSmeltedEvent(MineTweakerMC.getIPlayer(ev.player), MineTweakerMC.getIItemStack(ev.smelting)));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@SubscribeEvent
|
|
||||||
public void onPlayerLoggedOut(PlayerEvent.PlayerLoggedOutEvent ev) {
|
|
||||||
MineTweakerImplementationAPI.events.publishPlayerLoggedOut(new PlayerLoggedOutEvent(MineTweakerMC.getIPlayer(ev.player)));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,94 +0,0 @@
|
|||||||
package minetweaker.mc1102;
|
|
||||||
|
|
||||||
import minetweaker.*;
|
|
||||||
import minetweaker.api.entity.IEntityDefinition;
|
|
||||||
import minetweaker.api.formatting.IFormattedText;
|
|
||||||
import minetweaker.api.item.IItemStack;
|
|
||||||
import minetweaker.api.minecraft.MineTweakerMC;
|
|
||||||
import minetweaker.api.tooltip.IngredientTooltips;
|
|
||||||
import minetweaker.mc1102.formatting.IMCFormattedString;
|
|
||||||
import minetweaker.mc1102.item.MCItemStack;
|
|
||||||
import net.minecraft.entity.*;
|
|
||||||
import net.minecraft.entity.item.EntityItem;
|
|
||||||
import net.minecraft.entity.player.EntityPlayer;
|
|
||||||
import net.minecraft.item.ItemStack;
|
|
||||||
import net.minecraftforge.event.entity.living.LivingDropsEvent;
|
|
||||||
import net.minecraftforge.event.entity.player.*;
|
|
||||||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
|
||||||
import org.lwjgl.input.Keyboard;
|
|
||||||
|
|
||||||
import java.util.*;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Stan
|
|
||||||
*/
|
|
||||||
public class ForgeEventHandler {
|
|
||||||
|
|
||||||
@SubscribeEvent
|
|
||||||
public void onPlayerInteract(PlayerInteractEvent ev) {
|
|
||||||
minetweaker.api.event.PlayerInteractEvent event = new minetweaker.api.event.PlayerInteractEvent(MineTweakerMC.getIPlayer(ev.getEntityPlayer()), MineTweakerMC.getDimension(ev.getWorld()), ev.getPos() == null ? 0 : ev.getPos().getX(), ev.getPos() == null ? 0 : ev.getPos().getY(), ev.getPos() == null ? 0 : ev.getPos().getZ());
|
|
||||||
MineTweakerImplementationAPI.events.publishPlayerInteract(event);
|
|
||||||
}
|
|
||||||
|
|
||||||
@SubscribeEvent
|
|
||||||
public void onItemTooltip(ItemTooltipEvent ev) {
|
|
||||||
if(ev.getItemStack() != null) {
|
|
||||||
IItemStack itemStack = MineTweakerMC.getIItemStack(ev.getItemStack());
|
|
||||||
for(IFormattedText tooltip : IngredientTooltips.getTooltips(itemStack)) {
|
|
||||||
ev.getToolTip().add(((IMCFormattedString) tooltip).getTooltipString());
|
|
||||||
}
|
|
||||||
if(!Keyboard.isCreated()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if(Keyboard.isKeyDown(Keyboard.KEY_LSHIFT) || Keyboard.isKeyDown(Keyboard.KEY_RSHIFT)) {
|
|
||||||
for(IFormattedText tooltip : IngredientTooltips.getShiftTooltips(itemStack)) {
|
|
||||||
ev.getToolTip().add(((IMCFormattedString) tooltip).getTooltipString());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@SubscribeEvent
|
|
||||||
public void mobDrop(LivingDropsEvent ev) {
|
|
||||||
Entity entity = ev.getEntity();
|
|
||||||
IEntityDefinition entityDefinition = MineTweakerAPI.game.getEntity(EntityList.getEntityString(ev.getEntity()));
|
|
||||||
if(entityDefinition != null) {
|
|
||||||
if(!entityDefinition.getDropsToAdd().isEmpty()) {
|
|
||||||
entityDefinition.getDropsToAdd().forEach((key, val) -> {
|
|
||||||
EntityItem item = null;
|
|
||||||
if(val.getMin() == 0 && val.getMax() == 0) {
|
|
||||||
item = new EntityItem(entity.world, entity.posX + 0.5, entity.posY + 0.5, entity.posZ + 0.5, ((ItemStack) key.getInternal()).copy());
|
|
||||||
} else {
|
|
||||||
item = new EntityItem(entity.world, entity.posX + 0.5, entity.posY + 0.5, entity.posZ + 0.5, ((ItemStack) key.withAmount(val.getRandom()).getInternal()).copy());
|
|
||||||
}
|
|
||||||
ev.getDrops().add(item);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
if(ev.getSource().getEntity() instanceof EntityPlayer) {
|
|
||||||
if(!entityDefinition.getDropsToAddPlayerOnly().isEmpty()) {
|
|
||||||
entityDefinition.getDropsToAddPlayerOnly().forEach((key, val) -> {
|
|
||||||
EntityItem item = null;
|
|
||||||
if(val.getMin() == 0 && val.getMax() == 0) {
|
|
||||||
item = new EntityItem(entity.world, entity.posX + 0.5, entity.posY + 0.5, entity.posZ + 0.5, ((ItemStack) key.getInternal()).copy());
|
|
||||||
} else {
|
|
||||||
item = new EntityItem(entity.world, entity.posX + 0.5, entity.posY + 0.5, entity.posZ + 0.5, ((ItemStack) key.withAmount(val.getRandom()).getInternal()).copy());
|
|
||||||
}
|
|
||||||
ev.getDrops().add(item);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(!entityDefinition.getDropsToRemove().isEmpty()) {
|
|
||||||
List<EntityItem> removedDrops = new ArrayList<>();
|
|
||||||
entityDefinition.getDropsToRemove().forEach(drop -> {
|
|
||||||
// if(drop.matches(new MCItemStack()))
|
|
||||||
ev.getDrops().forEach(drops -> {
|
|
||||||
if(drop.matches(new MCItemStack(drops.getEntityItem()))) {
|
|
||||||
removedDrops.add(drops);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
ev.getDrops().removeAll(removedDrops);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,197 +0,0 @@
|
|||||||
package minetweaker.mc1102;
|
|
||||||
|
|
||||||
import minetweaker.*;
|
|
||||||
import minetweaker.annotations.BracketHandler;
|
|
||||||
import minetweaker.api.item.IItemStack;
|
|
||||||
import minetweaker.api.minecraft.MineTweakerMC;
|
|
||||||
import minetweaker.mc1102.brackets.*;
|
|
||||||
import minetweaker.mc1102.client.MCClient;
|
|
||||||
import minetweaker.mc1102.formatting.MCFormatter;
|
|
||||||
import minetweaker.mc1102.furnace.*;
|
|
||||||
import minetweaker.mc1102.game.MCGame;
|
|
||||||
import minetweaker.mc1102.logger.MCLogger;
|
|
||||||
import minetweaker.mc1102.mods.MCLoadedMods;
|
|
||||||
import minetweaker.mc1102.network.*;
|
|
||||||
import minetweaker.mc1102.oredict.MCOreDict;
|
|
||||||
import minetweaker.mc1102.recipes.MCRecipeManager;
|
|
||||||
import minetweaker.mc1102.server.MCServer;
|
|
||||||
import minetweaker.mc1102.util.*;
|
|
||||||
import minetweaker.mc1102.vanilla.MCVanilla;
|
|
||||||
import minetweaker.runtime.*;
|
|
||||||
import minetweaker.runtime.providers.*;
|
|
||||||
import net.minecraft.item.crafting.*;
|
|
||||||
import net.minecraft.nbt.NBTTagCompound;
|
|
||||||
import net.minecraft.server.MinecraftServer;
|
|
||||||
import net.minecraftforge.common.MinecraftForge;
|
|
||||||
import net.minecraftforge.fml.common.*;
|
|
||||||
import net.minecraftforge.fml.common.Mod.EventHandler;
|
|
||||||
import net.minecraftforge.fml.common.event.*;
|
|
||||||
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 stanhebben.zenscript.annotations.*;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.lang.reflect.Field;
|
|
||||||
import java.util.*;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Main mod class. Performs some general logic, initialization of the API and
|
|
||||||
* FML event handling.
|
|
||||||
*
|
|
||||||
* @author Stan Hebben
|
|
||||||
*/
|
|
||||||
@Mod(modid = MineTweakerMod.MODID, version = "3.1.0", name = MineTweakerMod.NAME, dependencies = "after:JEI@[3.14.2.398,)")
|
|
||||||
public class MineTweakerMod {
|
|
||||||
|
|
||||||
public static final String MODID = "MineTweaker3";
|
|
||||||
public static final String NAME = "MineTweaker3";
|
|
||||||
public static final String MCVERSION = "1.10.2";
|
|
||||||
|
|
||||||
public static final SimpleNetworkWrapper NETWORK = NetworkRegistry.INSTANCE.newSimpleChannel(MODID);
|
|
||||||
|
|
||||||
private static final String[] REGISTRIES = {"minetweaker.mods.jei.ClassRegistry", "minetweaker.mods.ic2.ClassRegistry"};
|
|
||||||
private static final String[] REGISTRY_DESCRIPTIONS = {"JEI mod support", "IC2 mod support"};
|
|
||||||
public static MinecraftServer server;
|
|
||||||
@Mod.Instance(MODID)
|
|
||||||
public static MineTweakerMod INSTANCE;
|
|
||||||
|
|
||||||
static {
|
|
||||||
NETWORK.registerMessage(MineTweakerLoadScriptsHandler.class, MineTweakerLoadScriptsPacket.class, 0, Side.CLIENT);
|
|
||||||
NETWORK.registerMessage(MineTweakerOpenBrowserHandler.class, MineTweakerOpenBrowserPacket.class, 1, Side.CLIENT);
|
|
||||||
NETWORK.registerMessage(MineTweakerCopyClipboardHandler.class, MineTweakerCopyClipboardPacket.class, 2, Side.CLIENT);
|
|
||||||
}
|
|
||||||
|
|
||||||
public final MCRecipeManager recipes;
|
|
||||||
private final IScriptProvider scriptsGlobal;
|
|
||||||
private final ScriptProviderCustom scriptsIMC;
|
|
||||||
|
|
||||||
public MineTweakerMod() {
|
|
||||||
MineTweakerImplementationAPI.init(new MCOreDict(), recipes = new MCRecipeManager(), new MCFurnaceManager(), MCGame.INSTANCE, new MCLoadedMods(), new MCFormatter(), new MCVanilla());
|
|
||||||
MineTweakerImplementationAPI.logger.addLogger(new MCLogger(new File("minetweaker.log")));
|
|
||||||
MineTweakerImplementationAPI.platform = MCPlatformFunctions.INSTANCE;
|
|
||||||
File globalDir = new File("scripts");
|
|
||||||
if(!globalDir.exists())
|
|
||||||
globalDir.mkdirs();
|
|
||||||
scriptsIMC = new ScriptProviderCustom("intermod");
|
|
||||||
scriptsGlobal = new ScriptProviderDirectory(globalDir);
|
|
||||||
MineTweakerImplementationAPI.setScriptProvider(scriptsGlobal);
|
|
||||||
}
|
|
||||||
|
|
||||||
// ##########################
|
|
||||||
// ### FML Event Handlers ###
|
|
||||||
// ##########################
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onIMCEvent(FMLInterModComms.IMCEvent event) {
|
|
||||||
event.getMessages().stream().filter(imcMessage -> imcMessage.key.equalsIgnoreCase("addMineTweakerScript")).forEach(imcMessage -> {
|
|
||||||
if(imcMessage.isStringMessage()) {
|
|
||||||
scriptsIMC.add(imcMessage.getSender() + "::imc", imcMessage.getStringValue());
|
|
||||||
} else if(imcMessage.isNBTMessage()) {
|
|
||||||
NBTTagCompound message = imcMessage.getNBTValue();
|
|
||||||
scriptsIMC.add(imcMessage.getSender() + "::" + message.getString("name"), message.getString("content"));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onLoad(FMLPreInitializationEvent ev) {
|
|
||||||
MinecraftForge.EVENT_BUS.register(new ForgeEventHandler());
|
|
||||||
MinecraftForge.EVENT_BUS.register(new FMLEventHandler());
|
|
||||||
// List<Class> apiClasses = new ArrayList<>();
|
|
||||||
// String[] classNames = new String[]{ZenExpansion.class.getCanonicalName(), ZenClass.class.getCanonicalName(), BracketHandler.class.getCanonicalName()};
|
|
||||||
// for(String name : classNames) {
|
|
||||||
// ev.getAsmData().getAll(name).forEach(clazz -> {
|
|
||||||
// boolean valid = true;
|
|
||||||
// try {
|
|
||||||
// for(ModContainer mod : clazz.getCandidate().getContainedMods()) {
|
|
||||||
// if(!mod.getName().equals("MineTweaker 3") || !mod.getName().equals("CT-GUI")) {
|
|
||||||
// valid = false;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// if(valid) {
|
|
||||||
// Class<?> asmClass = Class.forName(clazz.getClassName());
|
|
||||||
// apiClasses.add(asmClass);
|
|
||||||
// }
|
|
||||||
// } catch(ClassNotFoundException e) {
|
|
||||||
// e.printStackTrace();
|
|
||||||
// }
|
|
||||||
// });
|
|
||||||
// }
|
|
||||||
// apiClasses.forEach(i -> {
|
|
||||||
// System.out.println(">>> " + i.getName());
|
|
||||||
// MineTweakerAPI.registerClass(i);
|
|
||||||
// });
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onPostInit(FMLPostInitializationEvent ev) {
|
|
||||||
MineTweakerAPI.registerClassRegistry(MineTweakerRegistry.class);
|
|
||||||
|
|
||||||
for(int i = 0; i < REGISTRIES.length; i++) {
|
|
||||||
MineTweakerAPI.registerClassRegistry(REGISTRIES[i], REGISTRY_DESCRIPTIONS[i]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onComplete(FMLLoadCompleteEvent ev) {
|
|
||||||
MineTweakerAPI.logInfo("MineTweaker: Building registry");
|
|
||||||
ItemBracketHandler.rebuildItemRegistry();
|
|
||||||
LiquidBracketHandler.rebuildLiquidRegistry();
|
|
||||||
EntityBracketHandler.rebuildEntityRegistry();
|
|
||||||
MineTweakerAPI.logInfo("MineTweaker: Sucessfully built item registry");
|
|
||||||
GlobalRegistry.registerBracketHandler(new ItemBracketHandler());
|
|
||||||
GlobalRegistry.registerBracketHandler(new LiquidBracketHandler());
|
|
||||||
GlobalRegistry.registerBracketHandler(new OreBracketHandler());
|
|
||||||
GlobalRegistry.registerBracketHandler(new EntityBracketHandler());
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onServerAboutToStart(FMLServerAboutToStartEvent ev) {
|
|
||||||
server = ev.getServer();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onServerStarting(FMLServerStartingEvent ev) {
|
|
||||||
server = ev.getServer();
|
|
||||||
// starts before loading worlds
|
|
||||||
// perfect place to start MineTweaker!
|
|
||||||
MineTweakerImplementationAPI.addMineTweakerCommand("itemrecipes", new String[]{"Logs items that have a crafting table recipe"}, (arguments, player) -> {
|
|
||||||
List<IItemStack> stacks = new ArrayList<>();
|
|
||||||
for(IRecipe recipe : CraftingManager.getInstance().getRecipeList()) {
|
|
||||||
stacks.add(MineTweakerMC.getIItemStack(recipe.getRecipeOutput()));
|
|
||||||
}
|
|
||||||
for(IItemStack stack : stacks) {
|
|
||||||
if(stack != null)
|
|
||||||
MineTweakerAPI.logCommand(stack.toString());
|
|
||||||
}
|
|
||||||
player.sendChat("Recipe list generated; see minetweaker.log in your minecraft dir");
|
|
||||||
|
|
||||||
});
|
|
||||||
if(MineTweakerPlatformUtils.isClient()) {
|
|
||||||
MineTweakerAPI.client = new MCClient();
|
|
||||||
}
|
|
||||||
|
|
||||||
File scriptsDir = new File(MineTweakerHacks.getWorldDirectory(ev.getServer()), "scripts");
|
|
||||||
if(!scriptsDir.exists()) {
|
|
||||||
scriptsDir.mkdir();
|
|
||||||
}
|
|
||||||
|
|
||||||
IScriptProvider scriptsLocal = new ScriptProviderDirectory(scriptsDir);
|
|
||||||
IScriptProvider cascaded = new ScriptProviderCascade(scriptsIMC, scriptsGlobal, scriptsLocal);
|
|
||||||
|
|
||||||
MineTweakerImplementationAPI.setScriptProvider(cascaded);
|
|
||||||
MineTweakerImplementationAPI.onServerStart(new MCServer(ev.getServer()));
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onServerStopped(FMLServerStoppedEvent ev) {
|
|
||||||
MineTweakerImplementationAPI.onServerStop();
|
|
||||||
MineTweakerImplementationAPI.setScriptProvider(scriptsGlobal);
|
|
||||||
MineTweakerAPI.logInfo("Server stopping, Scripts are being rolled back!");
|
|
||||||
MineTweakerAPI.tweaker.rollback();
|
|
||||||
server = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-76
@@ -1,76 +0,0 @@
|
|||||||
package minetweaker.mc1102.actions;
|
|
||||||
|
|
||||||
import minetweaker.*;
|
|
||||||
import net.minecraft.block.Block;
|
|
||||||
import net.minecraft.item.ItemStack;
|
|
||||||
import net.minecraft.util.ResourceLocation;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Jared
|
|
||||||
*/
|
|
||||||
public class SetBlockHardnessAction implements IUndoableAction {
|
|
||||||
|
|
||||||
private final ItemStack stack;
|
|
||||||
private final float hardness;
|
|
||||||
private final float oldHardness;
|
|
||||||
|
|
||||||
public SetBlockHardnessAction(ItemStack stack, float hardness) {
|
|
||||||
this.stack = stack;
|
|
||||||
this.hardness = hardness;
|
|
||||||
this.oldHardness = Block.getBlockFromItem(stack.getItem()).getBlockHardness(null, null, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void set(ItemStack stack, float hardness) {
|
|
||||||
if(isBlock(stack)) {
|
|
||||||
Block block = Block.getBlockFromItem(stack.getItem());
|
|
||||||
block.setHardness(hardness);
|
|
||||||
} else {
|
|
||||||
MineTweakerAPI.logError("Item is not a block");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean isBlock(ItemStack stack) {
|
|
||||||
ResourceLocation name = Block.REGISTRY.getNameForObject(Block.getBlockFromItem(stack.getItem()));
|
|
||||||
return !name.toString().equals("minecraft:air") && Block.REGISTRY.containsKey(name);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void apply() {
|
|
||||||
if(isBlock(stack)) {
|
|
||||||
set(stack, hardness);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean canUndo() {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void undo() {
|
|
||||||
if(isBlock(stack))
|
|
||||||
set(stack, oldHardness);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String describe() {
|
|
||||||
if(isBlock(stack)) {
|
|
||||||
return "Setting hardness of " + stack.getDisplayName() + " to " + hardness;
|
|
||||||
}
|
|
||||||
return "Unable to set hardness of " + stack.getDisplayName() + " because it is an Item";
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String describeUndo() {
|
|
||||||
if(isBlock(stack)) {
|
|
||||||
return "Reverting hardness of " + stack.getDisplayName() + " to " + oldHardness;
|
|
||||||
}
|
|
||||||
return "Unable to revert hardness of " + stack.getDisplayName() + " because it is an Item";
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Object getOverrideKey() {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,82 +0,0 @@
|
|||||||
package minetweaker.mc1102.block;
|
|
||||||
|
|
||||||
import minetweaker.api.block.*;
|
|
||||||
import minetweaker.api.data.IData;
|
|
||||||
import minetweaker.api.minecraft.MineTweakerMC;
|
|
||||||
import net.minecraft.block.Block;
|
|
||||||
import net.minecraft.item.*;
|
|
||||||
import net.minecraft.nbt.NBTTagCompound;
|
|
||||||
import net.minecraft.tileentity.TileEntity;
|
|
||||||
import net.minecraft.util.math.BlockPos;
|
|
||||||
import net.minecraft.world.IBlockAccess;
|
|
||||||
import net.minecraftforge.oredict.OreDictionary;
|
|
||||||
|
|
||||||
import java.util.*;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Stan
|
|
||||||
*/
|
|
||||||
public class MCWorldBlock implements IBlock {
|
|
||||||
|
|
||||||
private final IBlockAccess blocks;
|
|
||||||
private final int x;
|
|
||||||
private final int y;
|
|
||||||
private final int z;
|
|
||||||
private final BlockPos pos;
|
|
||||||
|
|
||||||
public MCWorldBlock(IBlockAccess blocks, int x, int y, int z) {
|
|
||||||
this.blocks = blocks;
|
|
||||||
this.x = x;
|
|
||||||
this.y = y;
|
|
||||||
this.z = z;
|
|
||||||
this.pos = new BlockPos(x, y, z);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public IBlockDefinition getDefinition() {
|
|
||||||
return MineTweakerMC.getBlockDefinition(blocks.getBlockState(pos).getBlock());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getMeta() {
|
|
||||||
return blocks.getBlockState(pos).getBlock().getMetaFromState(blocks.getBlockState(pos));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public IData getTileData() {
|
|
||||||
TileEntity tileEntity = blocks.getTileEntity(pos);
|
|
||||||
|
|
||||||
if(tileEntity == null)
|
|
||||||
return null;
|
|
||||||
|
|
||||||
NBTTagCompound nbt = new NBTTagCompound();
|
|
||||||
tileEntity.writeToNBT(nbt);
|
|
||||||
return MineTweakerMC.getIData(nbt);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getDisplayName() {
|
|
||||||
Block block = blocks.getBlockState(pos).getBlock();
|
|
||||||
Item item = Item.getItemFromBlock(block);
|
|
||||||
if(item != null) {
|
|
||||||
return (new ItemStack(item, 1, getMeta())).getDisplayName();
|
|
||||||
} else {
|
|
||||||
return block.getLocalizedName();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<IBlock> getBlocks() {
|
|
||||||
return Collections.singletonList(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean matches(IBlock block) {
|
|
||||||
return getDefinition() == block.getDefinition() && (getMeta() == OreDictionary.WILDCARD_VALUE || getMeta() == block.getMeta()) && (getTileData() == null || (block.getTileData() != null && block.getTileData().contains(getTileData())));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public IBlockPattern or(IBlockPattern pattern) {
|
|
||||||
return new BlockPatternOr(this, pattern);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-77
@@ -1,77 +0,0 @@
|
|||||||
package minetweaker.mc1102.brackets;
|
|
||||||
|
|
||||||
import minetweaker.*;
|
|
||||||
import minetweaker.annotations.BracketHandler;
|
|
||||||
import minetweaker.api.entity.IEntityDefinition;
|
|
||||||
import stanhebben.zenscript.compiler.IEnvironmentGlobal;
|
|
||||||
import stanhebben.zenscript.expression.*;
|
|
||||||
import stanhebben.zenscript.expression.partial.IPartialExpression;
|
|
||||||
import stanhebben.zenscript.parser.Token;
|
|
||||||
import stanhebben.zenscript.symbols.IZenSymbol;
|
|
||||||
import stanhebben.zenscript.type.natives.IJavaMethod;
|
|
||||||
import stanhebben.zenscript.util.ZenPosition;
|
|
||||||
|
|
||||||
import java.util.*;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Jared
|
|
||||||
*/
|
|
||||||
@BracketHandler(priority = 100)
|
|
||||||
public class EntityBracketHandler implements IBracketHandler {
|
|
||||||
|
|
||||||
private static final Map<String, IEntityDefinition> entityNames = new HashMap<>();
|
|
||||||
private final IJavaMethod method;
|
|
||||||
|
|
||||||
public EntityBracketHandler() {
|
|
||||||
method = MineTweakerAPI.getJavaMethod(EntityBracketHandler.class, "getEntity", String.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
public static void rebuildEntityRegistry() {
|
|
||||||
entityNames.clear();
|
|
||||||
MineTweakerAPI.game.getEntities().forEach(ent -> {
|
|
||||||
entityNames.put(ent.getName().toLowerCase(), ent);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
public static IEntityDefinition getEntity(String name) {
|
|
||||||
return entityNames.get(name.toLowerCase());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public IZenSymbol resolve(IEnvironmentGlobal environment, List<Token> tokens) {
|
|
||||||
if(tokens.size() > 2) {
|
|
||||||
if(tokens.get(0).getValue().equals("entity") && tokens.get(1).getValue().equals(":")) {
|
|
||||||
return find(environment, tokens, 2, tokens.size());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
private IZenSymbol find(IEnvironmentGlobal environment, List<Token> tokens, int startIndex, int endIndex) {
|
|
||||||
StringBuilder valueBuilder = new StringBuilder();
|
|
||||||
for(int i = startIndex; i < endIndex; i++) {
|
|
||||||
Token token = tokens.get(i);
|
|
||||||
valueBuilder.append(token.getValue());
|
|
||||||
}
|
|
||||||
|
|
||||||
return new EntityReferenceSymbol(environment, valueBuilder.toString());
|
|
||||||
}
|
|
||||||
|
|
||||||
private class EntityReferenceSymbol implements IZenSymbol {
|
|
||||||
|
|
||||||
private final IEnvironmentGlobal environment;
|
|
||||||
private final String name;
|
|
||||||
|
|
||||||
public EntityReferenceSymbol(IEnvironmentGlobal environment, String name) {
|
|
||||||
this.environment = environment;
|
|
||||||
this.name = name;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public IPartialExpression instance(ZenPosition position) {
|
|
||||||
return new ExpressionCallStatic(position, environment, method, new ExpressionString(position, name));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-139
@@ -1,139 +0,0 @@
|
|||||||
package minetweaker.mc1102.brackets;
|
|
||||||
|
|
||||||
import minetweaker.*;
|
|
||||||
import minetweaker.annotations.BracketHandler;
|
|
||||||
import minetweaker.api.item.*;
|
|
||||||
import net.minecraft.block.Block;
|
|
||||||
import net.minecraft.item.*;
|
|
||||||
import net.minecraft.util.ResourceLocation;
|
|
||||||
import net.minecraftforge.oredict.OreDictionary;
|
|
||||||
import stanhebben.zenscript.ZenTokener;
|
|
||||||
import stanhebben.zenscript.compiler.IEnvironmentGlobal;
|
|
||||||
import stanhebben.zenscript.expression.*;
|
|
||||||
import stanhebben.zenscript.expression.partial.IPartialExpression;
|
|
||||||
import stanhebben.zenscript.parser.Token;
|
|
||||||
import stanhebben.zenscript.symbols.IZenSymbol;
|
|
||||||
import stanhebben.zenscript.type.ZenType;
|
|
||||||
import stanhebben.zenscript.type.natives.IJavaMethod;
|
|
||||||
import stanhebben.zenscript.util.ZenPosition;
|
|
||||||
|
|
||||||
import java.util.*;
|
|
||||||
|
|
||||||
import static minetweaker.api.minecraft.MineTweakerMC.getIItemStackWildcardSize;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Stan
|
|
||||||
*/
|
|
||||||
@BracketHandler(priority = 100)
|
|
||||||
public class ItemBracketHandler implements IBracketHandler {
|
|
||||||
|
|
||||||
private static final Map<String, Item> itemNames = new HashMap<>();
|
|
||||||
private static final Map<String, Block> blockNames = new HashMap<>();
|
|
||||||
|
|
||||||
private final IZenSymbol symbolAny;
|
|
||||||
private final IJavaMethod method;
|
|
||||||
|
|
||||||
public ItemBracketHandler() {
|
|
||||||
symbolAny = MineTweakerAPI.getJavaStaticFieldSymbol(IngredientAny.class, "INSTANCE");
|
|
||||||
method = MineTweakerAPI.getJavaMethod(ItemBracketHandler.class, "getItem", String.class, int.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Map<String, Item> getItemNames() {
|
|
||||||
return itemNames;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Map<String, Block> getBlockNames() {
|
|
||||||
return blockNames;
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
public static void rebuildItemRegistry() {
|
|
||||||
itemNames.clear();
|
|
||||||
blockNames.clear();
|
|
||||||
for(ResourceLocation itemName : Item.REGISTRY.getKeys()) {
|
|
||||||
String domain = itemName.toString().replace(" ", "").replace("'", "");
|
|
||||||
itemNames.put(domain, Item.REGISTRY.getObject(itemName));
|
|
||||||
}
|
|
||||||
for(ResourceLocation blockName : Block.REGISTRY.getKeys()) {
|
|
||||||
String domain = blockName.toString().replace(" ", "").replace("'", "");
|
|
||||||
blockNames.put(domain, Block.REGISTRY.getObject(blockName));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static IItemStack getItem(String name, int meta) {
|
|
||||||
// Item item = (Item) Item.itemRegistry.getObject(name);
|
|
||||||
Item item = itemNames.get(name);
|
|
||||||
if(item != null) {
|
|
||||||
return getIItemStackWildcardSize(item, meta);
|
|
||||||
} else if(blockNames.containsKey(name)) {
|
|
||||||
return getIItemStackWildcardSize(new ItemStack(blockNames.get(name), 1, meta));
|
|
||||||
} else {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public IZenSymbol resolve(IEnvironmentGlobal environment, List<Token> tokens) {
|
|
||||||
// any symbol
|
|
||||||
if(tokens.size() == 1 && tokens.get(0).getValue().equals("*")) {
|
|
||||||
return symbolAny;
|
|
||||||
}
|
|
||||||
|
|
||||||
// detect special cases:
|
|
||||||
// item: at the start means item-specific syntax
|
|
||||||
// :xxx with xxx an integer means sub-item syntax
|
|
||||||
// :* means any-subitem-syntax
|
|
||||||
int fromIndex = 0;
|
|
||||||
int toIndex = tokens.size();
|
|
||||||
int meta = 0;
|
|
||||||
|
|
||||||
if(tokens.size() > 2) {
|
|
||||||
if(tokens.get(0).getValue().equals("item") && tokens.get(1).getValue().equals(":")) {
|
|
||||||
fromIndex = 2;
|
|
||||||
}
|
|
||||||
if(tokens.get(tokens.size() - 1).getType() == ZenTokener.T_INTVALUE && tokens.get(tokens.size() - 2).getValue().equals(":")) {
|
|
||||||
toIndex = tokens.size() - 2;
|
|
||||||
meta = Integer.parseInt(tokens.get(tokens.size() - 1).getValue());
|
|
||||||
} else if(tokens.get(tokens.size() - 1).getValue().equals("*") && tokens.get(tokens.size() - 2).getValue().equals(":")) {
|
|
||||||
toIndex = tokens.size() - 2;
|
|
||||||
meta = OreDictionary.WILDCARD_VALUE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return find(environment, tokens, fromIndex, toIndex, meta);
|
|
||||||
}
|
|
||||||
|
|
||||||
private IZenSymbol find(IEnvironmentGlobal environment, List<Token> tokens, int startIndex, int endIndex, int meta) {
|
|
||||||
StringBuilder valueBuilder = new StringBuilder();
|
|
||||||
for(int i = startIndex; i < endIndex; i++) {
|
|
||||||
Token token = tokens.get(i);
|
|
||||||
valueBuilder.append(token.getValue());
|
|
||||||
}
|
|
||||||
|
|
||||||
String itemName = valueBuilder.toString();
|
|
||||||
if(itemNames.containsKey(itemName) || blockNames.containsKey(itemName)) {
|
|
||||||
return new ItemReferenceSymbol(environment, itemName, meta);
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
private class ItemReferenceSymbol implements IZenSymbol {
|
|
||||||
|
|
||||||
private final IEnvironmentGlobal environment;
|
|
||||||
private final String name;
|
|
||||||
private final int meta;
|
|
||||||
|
|
||||||
public ItemReferenceSymbol(IEnvironmentGlobal environment, String name, int meta) {
|
|
||||||
this.environment = environment;
|
|
||||||
this.name = name;
|
|
||||||
this.meta = meta;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public IPartialExpression instance(ZenPosition position) {
|
|
||||||
return new ExpressionCallStatic(position, environment, method, new ExpressionString(position, name), new ExpressionInt(position, meta, ZenType.INT));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-87
@@ -1,87 +0,0 @@
|
|||||||
package minetweaker.mc1102.brackets;
|
|
||||||
|
|
||||||
import minetweaker.IBracketHandler;
|
|
||||||
import minetweaker.annotations.BracketHandler;
|
|
||||||
import minetweaker.api.liquid.ILiquidStack;
|
|
||||||
import minetweaker.mc1102.liquid.MCLiquidStack;
|
|
||||||
import minetweaker.runtime.GlobalRegistry;
|
|
||||||
import net.minecraftforge.fluids.*;
|
|
||||||
import stanhebben.zenscript.compiler.IEnvironmentGlobal;
|
|
||||||
import stanhebben.zenscript.expression.*;
|
|
||||||
import stanhebben.zenscript.expression.partial.IPartialExpression;
|
|
||||||
import stanhebben.zenscript.parser.Token;
|
|
||||||
import stanhebben.zenscript.symbols.IZenSymbol;
|
|
||||||
import stanhebben.zenscript.type.natives.*;
|
|
||||||
import stanhebben.zenscript.util.ZenPosition;
|
|
||||||
|
|
||||||
import java.util.*;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Stan
|
|
||||||
*/
|
|
||||||
@BracketHandler
|
|
||||||
public class LiquidBracketHandler implements IBracketHandler {
|
|
||||||
|
|
||||||
private static final Map<String, Fluid> fluidNames = new HashMap<>();
|
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
public static void rebuildLiquidRegistry() {
|
|
||||||
fluidNames.clear();
|
|
||||||
for(String fluidName : FluidRegistry.getRegisteredFluids().keySet()) {
|
|
||||||
fluidNames.put(fluidName.replace(" ", ""), FluidRegistry.getFluid(fluidName));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static ILiquidStack getLiquid(String name) {
|
|
||||||
Fluid fluid = fluidNames.get(name);
|
|
||||||
if(fluid != null) {
|
|
||||||
return new MCLiquidStack(new FluidStack(fluid, 1));
|
|
||||||
} else {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public IZenSymbol resolve(IEnvironmentGlobal environment, List<Token> tokens) {
|
|
||||||
if(tokens.size() > 2) {
|
|
||||||
if(tokens.get(0).getValue().equals("liquid") && tokens.get(1).getValue().equals(":")) {
|
|
||||||
return find(environment, tokens, 2, tokens.size());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
private IZenSymbol find(IEnvironmentGlobal environment, List<Token> tokens, int startIndex, int endIndex) {
|
|
||||||
StringBuilder valueBuilder = new StringBuilder();
|
|
||||||
for(int i = startIndex; i < endIndex; i++) {
|
|
||||||
Token token = tokens.get(i);
|
|
||||||
valueBuilder.append(token.getValue());
|
|
||||||
}
|
|
||||||
|
|
||||||
Fluid fluid = fluidNames.get(valueBuilder.toString());
|
|
||||||
if(fluid != null) {
|
|
||||||
return new LiquidReferenceSymbol(environment, valueBuilder.toString());
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
private class LiquidReferenceSymbol implements IZenSymbol {
|
|
||||||
|
|
||||||
private final IEnvironmentGlobal environment;
|
|
||||||
private final String name;
|
|
||||||
|
|
||||||
public LiquidReferenceSymbol(IEnvironmentGlobal environment, String name) {
|
|
||||||
this.environment = environment;
|
|
||||||
this.name = name;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public IPartialExpression instance(ZenPosition position) {
|
|
||||||
IJavaMethod method = JavaMethod.get(GlobalRegistry.getTypeRegistry(), LiquidBracketHandler.class, "getLiquid", String.class);
|
|
||||||
|
|
||||||
return new ExpressionCallStatic(position, environment, method, new ExpressionString(position, name));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-81
@@ -1,81 +0,0 @@
|
|||||||
package minetweaker.mc1102.brackets;
|
|
||||||
|
|
||||||
import minetweaker.*;
|
|
||||||
import minetweaker.annotations.BracketHandler;
|
|
||||||
import minetweaker.api.oredict.IOreDictEntry;
|
|
||||||
import minetweaker.mc1102.oredict.MCOreDictEntry;
|
|
||||||
import minetweaker.runtime.GlobalRegistry;
|
|
||||||
import stanhebben.zenscript.compiler.IEnvironmentGlobal;
|
|
||||||
import stanhebben.zenscript.expression.*;
|
|
||||||
import stanhebben.zenscript.expression.partial.IPartialExpression;
|
|
||||||
import stanhebben.zenscript.parser.Token;
|
|
||||||
import stanhebben.zenscript.symbols.IZenSymbol;
|
|
||||||
import stanhebben.zenscript.type.natives.*;
|
|
||||||
import stanhebben.zenscript.util.ZenPosition;
|
|
||||||
|
|
||||||
import java.util.*;
|
|
||||||
import java.util.regex.Pattern;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Stan
|
|
||||||
*/
|
|
||||||
@BracketHandler
|
|
||||||
public class OreBracketHandler implements IBracketHandler {
|
|
||||||
|
|
||||||
public static IOreDictEntry getOre(String name) {
|
|
||||||
return new MCOreDictEntry(name);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static List<IOreDictEntry> getOreList(String wildcardName) {
|
|
||||||
List<IOreDictEntry> result = new ArrayList<>();
|
|
||||||
Pattern wildcardPattern = Pattern.compile(wildcardName.replaceAll("\\*", ".+"));
|
|
||||||
|
|
||||||
for(IOreDictEntry someOreDict : MineTweakerAPI.oreDict.getEntries()) {
|
|
||||||
String oreDictName = someOreDict.getName();
|
|
||||||
if(wildcardPattern.matcher(oreDictName).matches()) {
|
|
||||||
result.add(getOre(oreDictName));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public IZenSymbol resolve(IEnvironmentGlobal environment, List<Token> tokens) {
|
|
||||||
if(tokens.size() > 2) {
|
|
||||||
if(tokens.get(0).getValue().equals("ore") && tokens.get(1).getValue().equals(":")) {
|
|
||||||
return find(environment, tokens, 2, tokens.size());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
private IZenSymbol find(IEnvironmentGlobal environment, List<Token> tokens, int startIndex, int endIndex) {
|
|
||||||
StringBuilder valueBuilder = new StringBuilder();
|
|
||||||
for(int i = startIndex; i < endIndex; i++) {
|
|
||||||
Token token = tokens.get(i);
|
|
||||||
valueBuilder.append(token.getValue());
|
|
||||||
}
|
|
||||||
|
|
||||||
return new OreReferenceSymbol(environment, valueBuilder.toString());
|
|
||||||
}
|
|
||||||
|
|
||||||
private class OreReferenceSymbol implements IZenSymbol {
|
|
||||||
|
|
||||||
private final IEnvironmentGlobal environment;
|
|
||||||
private final String name;
|
|
||||||
|
|
||||||
public OreReferenceSymbol(IEnvironmentGlobal environment, String name) {
|
|
||||||
this.environment = environment;
|
|
||||||
this.name = name;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public IPartialExpression instance(ZenPosition position) {
|
|
||||||
IJavaMethod method = JavaMethod.get(GlobalRegistry.getTypeRegistry(), OreBracketHandler.class, name.contains("*") ? "getOreList" : "getOre", String.class);
|
|
||||||
|
|
||||||
return new ExpressionCallStatic(position, environment, method, new ExpressionString(position, name));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-73
@@ -1,73 +0,0 @@
|
|||||||
package minetweaker.mc1102.brewing;
|
|
||||||
|
|
||||||
import minetweaker.api.item.*;
|
|
||||||
import minetweaker.api.recipes.BrewingRecipe;
|
|
||||||
import minetweaker.api.recipes.*;
|
|
||||||
import minetweaker.api.recipes.IBrewingRecipe;
|
|
||||||
import minetweaker.mc1102.item.MCItemStack;
|
|
||||||
import net.minecraft.item.ItemStack;
|
|
||||||
import net.minecraftforge.common.brewing.*;
|
|
||||||
|
|
||||||
import java.util.*;
|
|
||||||
|
|
||||||
public class MCBrewingManager implements IBrewingManager {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<IBrewingRecipe> getAll() {
|
|
||||||
List<IBrewingRecipe> ret = new ArrayList<>();
|
|
||||||
for(net.minecraftforge.common.brewing.IBrewingRecipe rec : BrewingRecipeRegistry.getRecipes()) {
|
|
||||||
if(rec instanceof net.minecraftforge.common.brewing.AbstractBrewingRecipe) {
|
|
||||||
AbstractBrewingRecipe abs = (AbstractBrewingRecipe) rec;
|
|
||||||
if(abs instanceof BrewingOreRecipe) {
|
|
||||||
BrewingOreRecipe brew = (BrewingOreRecipe) abs;
|
|
||||||
ret.add(new BrewingRecipe(new MCItemStack(brew.getOutput()), new MCItemStack(brew.getInput()), convert(brew.getIngredient())));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void remove(IItemStack output) {
|
|
||||||
// if (output == null)
|
|
||||||
// throw new IllegalArgumentException("output cannot be null");
|
|
||||||
//
|
|
||||||
// for(net.minecraftforge.common.brewing.IBrewingRecipe recipe : BrewingRecipeRegistry.getRecipes()){
|
|
||||||
// if(recipe.is)
|
|
||||||
// }
|
|
||||||
// Map<ItemStack, ItemStack> smeltingList = FurnaceRecipes.instance().getSmeltingList();
|
|
||||||
//
|
|
||||||
// List<ItemStack> toRemove = new ArrayList<ItemStack>();
|
|
||||||
// List<ItemStack> toRemoveValues = new ArrayList<ItemStack>();
|
|
||||||
// for (Map.Entry<ItemStack, ItemStack> entry : smeltingList.entrySet()) {
|
|
||||||
// if (output.matches(new MCItemStack(entry.getValue())) && (input == null || input.matches(new MCItemStack(entry.getKey())))) {
|
|
||||||
// toRemove.add(entry.getKey());
|
|
||||||
// toRemoveValues.add(entry.getValue());
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// if (toRemove.isEmpty()) {
|
|
||||||
// MineTweakerAPI.logWarning("No furnace recipes for " + output.toString());
|
|
||||||
// } else {
|
|
||||||
// MineTweakerAPI.apply(new MCFurnaceManager.RemoveAction(toRemove, toRemoveValues));
|
|
||||||
// }
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void add(IItemStack output, IItemStack ingredient, IItemStack input) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int remove(IItemStack output, IItemStack ingredients) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
private IngredientOr convert(List<ItemStack> ingredients) {
|
|
||||||
IngredientOr ing;
|
|
||||||
|
|
||||||
ing = new IngredientOr((IngredientItem[]) ingredients.toArray());
|
|
||||||
|
|
||||||
return ing;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,30 +0,0 @@
|
|||||||
package minetweaker.mc1102.chat;
|
|
||||||
|
|
||||||
import minetweaker.api.chat.IChatMessage;
|
|
||||||
import net.minecraft.util.text.*;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Stan
|
|
||||||
*/
|
|
||||||
public class MCChatMessage implements IChatMessage {
|
|
||||||
|
|
||||||
private final ITextComponent data;
|
|
||||||
|
|
||||||
public MCChatMessage(String message) {
|
|
||||||
data = new TextComponentString(message);
|
|
||||||
}
|
|
||||||
|
|
||||||
public MCChatMessage(ITextComponent data) {
|
|
||||||
this.data = data;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public IChatMessage add(IChatMessage other) {
|
|
||||||
return new MCChatMessage(data.appendSibling((ITextComponent) other.getInternal()));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Object getInternal() {
|
|
||||||
return data;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,39 +0,0 @@
|
|||||||
package minetweaker.mc1102.data;
|
|
||||||
|
|
||||||
import minetweaker.api.data.*;
|
|
||||||
import net.minecraft.nbt.*;
|
|
||||||
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Stan
|
|
||||||
*/
|
|
||||||
public class NBTUpdater extends NBTConverter implements IDataConverter<NBTBase> {
|
|
||||||
|
|
||||||
private final NBTTagCompound nbt;
|
|
||||||
|
|
||||||
public NBTUpdater(NBTTagCompound compound) {
|
|
||||||
this.nbt = compound;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public NBTBase fromMap(Map<String, IData> map) {
|
|
||||||
for(Map.Entry<String, IData> entry : map.entrySet()) {
|
|
||||||
if(nbt.hasKey(entry.getKey())) {
|
|
||||||
if(entry.getValue() == null) {
|
|
||||||
nbt.removeTag(entry.getKey());
|
|
||||||
} else {
|
|
||||||
if(nbt.getTag(entry.getKey()).getId() == 10) {
|
|
||||||
nbt.setTag(entry.getKey(), entry.getValue().convert(new NBTUpdater(nbt)));
|
|
||||||
} else {
|
|
||||||
nbt.setTag(entry.getKey(), NBTConverter.from(entry.getValue()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else if(entry.getValue() != null) {
|
|
||||||
nbt.setTag(entry.getKey(), from(entry.getValue()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return nbt;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-67
@@ -1,67 +0,0 @@
|
|||||||
package minetweaker.mc1102.entity;
|
|
||||||
|
|
||||||
import minetweaker.api.entity.IEntityDefinition;
|
|
||||||
import minetweaker.api.item.IItemStack;
|
|
||||||
import net.minecraft.entity.Entity;
|
|
||||||
import stanhebben.zenscript.value.*;
|
|
||||||
|
|
||||||
import java.util.*;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Stan
|
|
||||||
*/
|
|
||||||
public class MCEntityDefinition implements IEntityDefinition {
|
|
||||||
|
|
||||||
private final Class<? extends Entity> entityClass;
|
|
||||||
private final String entityName;
|
|
||||||
|
|
||||||
private final Map<IItemStack, IntRange> dropsToAdd = new HashMap<>();
|
|
||||||
private final Map<IItemStack, IntRange> dropsToAddPlayerOnly = new HashMap<>();
|
|
||||||
private final List<IItemStack> dropsToRemove = new ArrayList<>();
|
|
||||||
|
|
||||||
public MCEntityDefinition(Class<? extends Entity> entityClass, String entityName) {
|
|
||||||
this.entityClass = entityClass;
|
|
||||||
this.entityName = entityName;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getId() {
|
|
||||||
return entityClass.getName();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getName() {
|
|
||||||
return entityName;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void addDrop(IItemStack stack, int min, int max) {
|
|
||||||
dropsToAdd.put(stack, new IntRange(min, max));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void addPlayerOnlyDrop(IItemStack stack, int min, int max) {
|
|
||||||
dropsToAddPlayerOnly.put(stack, new IntRange(min, max));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void removeDrop(IItemStack stack) {
|
|
||||||
dropsToRemove.add(stack);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Map<IItemStack, IntRange> getDropsToAdd() {
|
|
||||||
return dropsToAdd;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Map<IItemStack, IntRange> getDropsToAddPlayerOnly() {
|
|
||||||
return dropsToAddPlayerOnly;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<IItemStack> getDropsToRemove() {
|
|
||||||
return dropsToRemove;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-13
@@ -1,13 +0,0 @@
|
|||||||
package minetweaker.mc1102.formatting;
|
|
||||||
|
|
||||||
import minetweaker.api.formatting.IFormattedText;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Stan
|
|
||||||
*/
|
|
||||||
public interface IMCFormattedString extends IFormattedText {
|
|
||||||
|
|
||||||
String getTooltipString();
|
|
||||||
|
|
||||||
String getTooltipString(String context);
|
|
||||||
}
|
|
||||||
-120
@@ -1,120 +0,0 @@
|
|||||||
package minetweaker.mc1102.formatting;
|
|
||||||
|
|
||||||
import minetweaker.api.formatting.*;
|
|
||||||
import net.minecraft.util.text.TextFormatting;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Stan
|
|
||||||
*/
|
|
||||||
public class MCFormatter implements IFormatter {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public IFormattedText string(String text) {
|
|
||||||
return new FormattedString(text);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public IFormattedText black(IFormattedText text) {
|
|
||||||
return new FormattedMarkupString(TextFormatting.BLACK, (IMCFormattedString) text);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public IFormattedText darkBlue(IFormattedText text) {
|
|
||||||
return new FormattedMarkupString(TextFormatting.DARK_BLUE, (IMCFormattedString) text);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public IFormattedText darkGreen(IFormattedText text) {
|
|
||||||
return new FormattedMarkupString(TextFormatting.DARK_GREEN, (IMCFormattedString) text);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public IFormattedText darkAqua(IFormattedText text) {
|
|
||||||
return new FormattedMarkupString(TextFormatting.DARK_AQUA, (IMCFormattedString) text);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public IFormattedText darkRed(IFormattedText text) {
|
|
||||||
return new FormattedMarkupString(TextFormatting.DARK_RED, (IMCFormattedString) text);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public IFormattedText darkPurple(IFormattedText text) {
|
|
||||||
return new FormattedMarkupString(TextFormatting.DARK_PURPLE, (IMCFormattedString) text);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public IFormattedText gold(IFormattedText text) {
|
|
||||||
return new FormattedMarkupString(TextFormatting.GOLD, (IMCFormattedString) text);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public IFormattedText gray(IFormattedText text) {
|
|
||||||
return new FormattedMarkupString(TextFormatting.GRAY, (IMCFormattedString) text);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public IFormattedText darkGray(IFormattedText text) {
|
|
||||||
return new FormattedMarkupString(TextFormatting.DARK_GRAY, (IMCFormattedString) text);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public IFormattedText blue(IFormattedText text) {
|
|
||||||
return new FormattedMarkupString(TextFormatting.BLUE, (IMCFormattedString) text);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public IFormattedText green(IFormattedText text) {
|
|
||||||
return new FormattedMarkupString(TextFormatting.GREEN, (IMCFormattedString) text);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public IFormattedText aqua(IFormattedText text) {
|
|
||||||
return new FormattedMarkupString(TextFormatting.AQUA, (IMCFormattedString) text);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public IFormattedText red(IFormattedText text) {
|
|
||||||
return new FormattedMarkupString(TextFormatting.RED, (IMCFormattedString) text);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public IFormattedText lightPurple(IFormattedText text) {
|
|
||||||
return new FormattedMarkupString(TextFormatting.LIGHT_PURPLE, (IMCFormattedString) text);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public IFormattedText yellow(IFormattedText text) {
|
|
||||||
return new FormattedMarkupString(TextFormatting.YELLOW, (IMCFormattedString) text);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public IFormattedText white(IFormattedText text) {
|
|
||||||
return new FormattedMarkupString(TextFormatting.WHITE, (IMCFormattedString) text);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public IFormattedText obfuscated(IFormattedText text) {
|
|
||||||
return new FormattedMarkupString(TextFormatting.OBFUSCATED, (IMCFormattedString) text);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public IFormattedText bold(IFormattedText text) {
|
|
||||||
return new FormattedMarkupString(TextFormatting.BOLD, (IMCFormattedString) text);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public IFormattedText strikethrough(IFormattedText text) {
|
|
||||||
return new FormattedMarkupString(TextFormatting.STRIKETHROUGH, (IMCFormattedString) text);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public IFormattedText underline(IFormattedText text) {
|
|
||||||
return new FormattedMarkupString(TextFormatting.UNDERLINE, (IMCFormattedString) text);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public IFormattedText italic(IFormattedText text) {
|
|
||||||
return new FormattedMarkupString(TextFormatting.ITALIC, (IMCFormattedString) text);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,88 +0,0 @@
|
|||||||
package minetweaker.mc1102.furnace;
|
|
||||||
|
|
||||||
import minetweaker.MineTweakerAPI;
|
|
||||||
import minetweaker.api.item.IItemStack;
|
|
||||||
import minetweaker.api.minecraft.MineTweakerMC;
|
|
||||||
import net.minecraft.item.*;
|
|
||||||
import net.minecraftforge.fml.common.IFuelHandler;
|
|
||||||
import net.minecraftforge.fml.common.registry.GameRegistry;
|
|
||||||
|
|
||||||
import java.lang.reflect.Field;
|
|
||||||
import java.util.*;
|
|
||||||
|
|
||||||
public class FuelTweaker {
|
|
||||||
|
|
||||||
public static final FuelTweaker INSTANCE = new FuelTweaker();
|
|
||||||
private final HashMap<Item, List<SetFuelPattern>> quickList = new HashMap<>();
|
|
||||||
private List<IFuelHandler> original;
|
|
||||||
|
|
||||||
private FuelTweaker() {
|
|
||||||
}
|
|
||||||
|
|
||||||
public void register() {
|
|
||||||
try {
|
|
||||||
Field fuelHandlers = GameRegistry.class.getDeclaredField("fuelHandlers");
|
|
||||||
fuelHandlers.setAccessible(true);
|
|
||||||
original = (List<IFuelHandler>) fuelHandlers.get(null);
|
|
||||||
List<IFuelHandler> modified = new ArrayList<>();
|
|
||||||
modified.add(new OverridingFuelHandler());
|
|
||||||
fuelHandlers.set(null, modified);
|
|
||||||
} catch(NoSuchFieldException ex) {
|
|
||||||
System.out.println("[MineTweaker] Error: could not get GameRegistry fuel handlers field. Cannot use custom fuel values.");
|
|
||||||
} catch(SecurityException | IllegalAccessException ex) {
|
|
||||||
System.out.println("[MineTweaker] Error: could not alter GameRegistry fuel handlers field. Cannot use custom fuel values.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void addFuelPattern(SetFuelPattern pattern) {
|
|
||||||
List<IItemStack> items = pattern.getPattern().getItems();
|
|
||||||
if(items == null) {
|
|
||||||
MineTweakerAPI.logError("Cannot set fuel for <*>");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
for(IItemStack item : pattern.getPattern().getItems()) {
|
|
||||||
ItemStack itemStack = MineTweakerMC.getItemStack(item);
|
|
||||||
Item mcItem = itemStack.getItem();
|
|
||||||
if(!quickList.containsKey(mcItem)) {
|
|
||||||
quickList.put(mcItem, new ArrayList<>());
|
|
||||||
}
|
|
||||||
quickList.get(mcItem).add(pattern);
|
|
||||||
}
|
|
||||||
|
|
||||||
MineTweakerAPI.getIjeiRecipeRegistry().addFuel(Arrays.asList(MineTweakerMC.getItemStacks(pattern.getPattern().getItems())), pattern.getValue());
|
|
||||||
}
|
|
||||||
|
|
||||||
public void removeFuelPattern(SetFuelPattern pattern) {
|
|
||||||
for(IItemStack item : pattern.getPattern().getItems()) {
|
|
||||||
ItemStack itemStack = MineTweakerMC.getItemStack(item);
|
|
||||||
Item mcItem = itemStack.getItem();
|
|
||||||
if(quickList.containsKey(mcItem)) {
|
|
||||||
quickList.get(mcItem).remove(pattern);
|
|
||||||
}
|
|
||||||
MineTweakerAPI.getIjeiRecipeRegistry().removeFuel(itemStack);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private class OverridingFuelHandler implements IFuelHandler {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getBurnTime(ItemStack fuel) {
|
|
||||||
if(quickList.containsKey(fuel.getItem())) {
|
|
||||||
IItemStack stack = MineTweakerMC.getIItemStack(fuel);
|
|
||||||
|
|
||||||
for(SetFuelPattern override : quickList.get(fuel.getItem())) {
|
|
||||||
if(override.getPattern().matches(stack)) {
|
|
||||||
return override.getValue();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
int max = 0;
|
|
||||||
for(IFuelHandler handler : original) {
|
|
||||||
max = Math.max(max, handler.getBurnTime(fuel));
|
|
||||||
}
|
|
||||||
return max;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-228
@@ -1,228 +0,0 @@
|
|||||||
package minetweaker.mc1102.furnace;
|
|
||||||
|
|
||||||
import minetweaker.*;
|
|
||||||
import minetweaker.api.item.*;
|
|
||||||
import minetweaker.api.recipes.*;
|
|
||||||
import minetweaker.mc1102.item.MCItemStack;
|
|
||||||
import net.minecraft.item.ItemStack;
|
|
||||||
import net.minecraft.item.crafting.FurnaceRecipes;
|
|
||||||
import net.minecraftforge.fml.common.registry.GameRegistry;
|
|
||||||
import stanhebben.zenscript.annotations.Optional;
|
|
||||||
|
|
||||||
import java.util.*;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
import static minetweaker.api.minecraft.MineTweakerMC.*;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Stan
|
|
||||||
*/
|
|
||||||
public class MCFurnaceManager implements IFurnaceManager {
|
|
||||||
|
|
||||||
public MCFurnaceManager() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void remove(IIngredient output, @Optional IIngredient input) {
|
|
||||||
if(output == null)
|
|
||||||
throw new IllegalArgumentException("output cannot be null");
|
|
||||||
|
|
||||||
Map<ItemStack, ItemStack> smeltingList = FurnaceRecipes.instance().getSmeltingList();
|
|
||||||
|
|
||||||
List<ItemStack> toRemove = new ArrayList<>();
|
|
||||||
List<ItemStack> toRemoveValues = new ArrayList<>();
|
|
||||||
|
|
||||||
if(input == null) {
|
|
||||||
for(Map.Entry<ItemStack, ItemStack> entry : smeltingList.entrySet()) {
|
|
||||||
if(output.matches(getIItemStack(entry.getValue()))) {
|
|
||||||
toRemove.add(entry.getKey());
|
|
||||||
toRemoveValues.add(entry.getValue());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
for(Map.Entry<ItemStack, ItemStack> entry : smeltingList.entrySet()) {
|
|
||||||
if(output.matches(getIItemStack(entry.getValue())) && input.matches(getIItemStack(entry.getKey()))) {
|
|
||||||
toRemove.add(entry.getKey());
|
|
||||||
toRemoveValues.add(entry.getValue());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(toRemove.isEmpty()) {
|
|
||||||
MineTweakerAPI.logWarning("No furnace recipes for " + output.toString());
|
|
||||||
} else {
|
|
||||||
MineTweakerAPI.apply(new RemoveAction(toRemove, toRemoveValues));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void addRecipe(IItemStack output, IIngredient input, @Optional double xp) {
|
|
||||||
List<IItemStack> items = input.getItems();
|
|
||||||
if(items == null) {
|
|
||||||
MineTweakerAPI.logError("Cannot turn " + input.toString() + " into a furnace recipe");
|
|
||||||
}
|
|
||||||
|
|
||||||
ItemStack[] items2 = getItemStacks(items);
|
|
||||||
ItemStack output2 = getItemStack(output);
|
|
||||||
MineTweakerAPI.apply(new AddRecipeAction(input, items2, output2, xp));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setFuel(IIngredient item, int fuel) {
|
|
||||||
MineTweakerAPI.apply(new SetFuelAction(new SetFuelPattern(item, fuel)));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getFuel(IItemStack item) {
|
|
||||||
return GameRegistry.getFuelValue(getItemStack(item));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<IFurnaceRecipe> getAll() {
|
|
||||||
return FurnaceRecipes.instance().getSmeltingList().entrySet().stream().map(ent -> new FurnaceRecipe(new MCItemStack(ent.getKey()), new MCItemStack(ent.getValue()), FurnaceRecipes.instance().getSmeltingExperience(ent.getValue()))).collect(Collectors.toList());
|
|
||||||
}
|
|
||||||
|
|
||||||
// ######################
|
|
||||||
// ### Action classes ###
|
|
||||||
// ######################
|
|
||||||
|
|
||||||
private static class RemoveAction implements IUndoableAction {
|
|
||||||
|
|
||||||
private final List<ItemStack> items;
|
|
||||||
private final List<ItemStack> values;
|
|
||||||
|
|
||||||
public RemoveAction(List<ItemStack> items, List<ItemStack> values) {
|
|
||||||
this.items = items;
|
|
||||||
this.values = values;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void apply() {
|
|
||||||
for(ItemStack item : items) {
|
|
||||||
FurnaceRecipes.instance().getSmeltingList().remove(item);
|
|
||||||
MineTweakerAPI.getIjeiRecipeRegistry().removeFurnace(item);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean canUndo() {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void undo() {
|
|
||||||
for(int i = 0; i < items.size(); i++) {
|
|
||||||
FurnaceRecipes.instance().getSmeltingList().put(items.get(i), values.get(i));
|
|
||||||
MineTweakerAPI.getIjeiRecipeRegistry().addFurnace(Arrays.asList(items.toArray()), values.get(i));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String describe() {
|
|
||||||
return "Removing " + items.size() + " furnace recipes";
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String describeUndo() {
|
|
||||||
return "Restoring " + items.size() + " furnace recipes";
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Object getOverrideKey() {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static class AddRecipeAction implements IUndoableAction {
|
|
||||||
|
|
||||||
private final IIngredient ingredient;
|
|
||||||
private final ItemStack[] input;
|
|
||||||
private final ItemStack output;
|
|
||||||
private final double xp;
|
|
||||||
|
|
||||||
public AddRecipeAction(IIngredient ingredient, ItemStack[] input, ItemStack output, double xp) {
|
|
||||||
this.ingredient = ingredient;
|
|
||||||
this.input = input;
|
|
||||||
this.output = output;
|
|
||||||
this.xp = xp;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void apply() {
|
|
||||||
for(ItemStack inputStack : input) {
|
|
||||||
FurnaceRecipes.instance().addSmeltingRecipe(inputStack, output, (float) xp);
|
|
||||||
}
|
|
||||||
MineTweakerAPI.getIjeiRecipeRegistry().addFurnace(Arrays.asList(input), output);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean canUndo() {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void undo() {
|
|
||||||
for(ItemStack inputStack : input) {
|
|
||||||
FurnaceRecipes.instance().getSmeltingList().remove(inputStack);
|
|
||||||
System.out.println(">>>removing");
|
|
||||||
MineTweakerAPI.getIjeiRecipeRegistry().removeFurnace(inputStack);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String describe() {
|
|
||||||
return "Adding furnace recipe for " + ingredient;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String describeUndo() {
|
|
||||||
return "Removing furnace recipe for " + ingredient;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Object getOverrideKey() {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static class SetFuelAction implements IUndoableAction {
|
|
||||||
|
|
||||||
private final SetFuelPattern pattern;
|
|
||||||
|
|
||||||
public SetFuelAction(SetFuelPattern pattern) {
|
|
||||||
this.pattern = pattern;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void apply() {
|
|
||||||
FuelTweaker.INSTANCE.addFuelPattern(pattern);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean canUndo() {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void undo() {
|
|
||||||
FuelTweaker.INSTANCE.removeFuelPattern(pattern);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String describe() {
|
|
||||||
return "Setting fuel for " + pattern.getPattern();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String describeUndo() {
|
|
||||||
return "Removing fuel for " + pattern.getPattern();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Object getOverrideKey() {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,209 +0,0 @@
|
|||||||
package minetweaker.mc1102.game;
|
|
||||||
|
|
||||||
import minetweaker.*;
|
|
||||||
import minetweaker.api.block.IBlockDefinition;
|
|
||||||
import minetweaker.api.entity.IEntityDefinition;
|
|
||||||
import minetweaker.api.game.IGame;
|
|
||||||
import minetweaker.api.item.IItemDefinition;
|
|
||||||
import minetweaker.api.liquid.ILiquidDefinition;
|
|
||||||
import minetweaker.api.minecraft.MineTweakerMC;
|
|
||||||
import minetweaker.api.world.IBiome;
|
|
||||||
import minetweaker.mc1102.entity.MCEntityDefinition;
|
|
||||||
import minetweaker.mc1102.item.MCItemDefinition;
|
|
||||||
import minetweaker.mc1102.liquid.MCLiquidDefinition;
|
|
||||||
import minetweaker.mc1102.util.*;
|
|
||||||
import net.minecraft.block.Block;
|
|
||||||
import net.minecraft.client.Minecraft;
|
|
||||||
import net.minecraft.entity.EntityList;
|
|
||||||
import net.minecraft.item.Item;
|
|
||||||
import net.minecraftforge.fluids.FluidRegistry;
|
|
||||||
|
|
||||||
import java.util.*;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
// TODO Find this
|
|
||||||
// import minetweaker.mc1102.GuiCannotRemodify;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Stan
|
|
||||||
*/
|
|
||||||
public class MCGame implements IGame {
|
|
||||||
|
|
||||||
public static final MCGame INSTANCE = new MCGame();
|
|
||||||
private static final Map<String, String> TRANSLATIONS = MineTweakerHacks.getTranslations();
|
|
||||||
private static final List<IEntityDefinition> ENTITY_DEFINITIONS = new ArrayList<>();
|
|
||||||
private boolean locked = false;
|
|
||||||
|
|
||||||
private MCGame() {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<IItemDefinition> getItems() {
|
|
||||||
return Item.REGISTRY.getKeys().stream().map(item -> new MCItemDefinition(item.toString(), Item.REGISTRY.getObject(item))).collect(Collectors.toList());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<IBlockDefinition> getBlocks() {
|
|
||||||
return Block.REGISTRY.getKeys().stream().map(block -> MineTweakerMC.getBlockDefinition(Block.REGISTRY.getObject(block))).collect(Collectors.toList());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<ILiquidDefinition> getLiquids() {
|
|
||||||
return FluidRegistry.getRegisteredFluids().entrySet().stream().map(entry -> new MCLiquidDefinition(entry.getValue())).collect(Collectors.toList());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<IBiome> getBiomes() {
|
|
||||||
List<IBiome> result = new ArrayList<>();
|
|
||||||
for(IBiome biome : MineTweakerMC.biomes) {
|
|
||||||
if(biome != null) {
|
|
||||||
result.add(biome);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<IEntityDefinition> getEntities() {
|
|
||||||
if(ENTITY_DEFINITIONS.isEmpty()) {
|
|
||||||
EntityList.CLASS_TO_NAME.forEach((key, val) -> {
|
|
||||||
ENTITY_DEFINITIONS.add(new MCEntityDefinition(key, val));
|
|
||||||
});
|
|
||||||
}
|
|
||||||
return ENTITY_DEFINITIONS;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public IEntityDefinition getEntity(String entityName) {
|
|
||||||
for(IEntityDefinition ent : getEntities()) {
|
|
||||||
if(ent.getName().equalsIgnoreCase(entityName)) {
|
|
||||||
return ent;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
boolean needsReloading = false;
|
|
||||||
for(String s : EntityList.NAME_TO_CLASS.keySet()) {
|
|
||||||
if(s.equalsIgnoreCase(entityName)) {
|
|
||||||
needsReloading = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(needsReloading) {
|
|
||||||
ENTITY_DEFINITIONS.clear();
|
|
||||||
EntityList.CLASS_TO_NAME.forEach((key, val) -> {
|
|
||||||
ENTITY_DEFINITIONS.add(new MCEntityDefinition(key, val));
|
|
||||||
});
|
|
||||||
}
|
|
||||||
return getEntities().stream().filter(ent -> ent.getName().equals(entityName)).findFirst().orElse(null);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setLocalization(String key, String value) {
|
|
||||||
MineTweakerAPI.apply(new SetTranslation(null, key, value));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setLocalization(String lang, String key, String value) {
|
|
||||||
MineTweakerAPI.apply(new SetTranslation(lang, key, value));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String localize(String key) {
|
|
||||||
return net.minecraft.util.text.translation.I18n.translateToLocal(key);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String localize(String key, String lang) {
|
|
||||||
return net.minecraft.util.text.translation.I18n.translateToLocal(key);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void lock() {
|
|
||||||
locked = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isLocked() {
|
|
||||||
return locked;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void signalLockError() {
|
|
||||||
MineTweakerAPI.getLogger().logError("Reload of scripts blocked (script lock)");
|
|
||||||
|
|
||||||
if(Minecraft.isGuiEnabled()) {
|
|
||||||
// Commented out due to unresolved import
|
|
||||||
/**
|
|
||||||
* Minecraft.getMinecraft().displayGuiScreen( new GuiCannotRemodify(
|
|
||||||
* "Minecraft has been tweaked for another server",
|
|
||||||
* "with modifications that cannot be rolled back.",
|
|
||||||
* "Please restart your game."));
|
|
||||||
**/
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// ######################
|
|
||||||
// ### Action classes ###
|
|
||||||
// ######################
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Ported from ModTweaker.
|
|
||||||
*
|
|
||||||
* @author Joshiejack
|
|
||||||
*/
|
|
||||||
private static class SetTranslation implements IUndoableAction {
|
|
||||||
|
|
||||||
private final String lang;
|
|
||||||
private final String key;
|
|
||||||
private final String text;
|
|
||||||
private String original;
|
|
||||||
private boolean added;
|
|
||||||
|
|
||||||
public SetTranslation(String lang, String key, String text) {
|
|
||||||
this.lang = lang;
|
|
||||||
this.key = key;
|
|
||||||
this.text = text;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void apply() {
|
|
||||||
if(lang == null || MineTweakerPlatformUtils.isLanguageActive(lang)) {
|
|
||||||
original = TRANSLATIONS.get(key);
|
|
||||||
TRANSLATIONS.put(key, text);
|
|
||||||
added = true;
|
|
||||||
} else {
|
|
||||||
added = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean canUndo() {
|
|
||||||
return TRANSLATIONS != null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void undo() {
|
|
||||||
if(added) {
|
|
||||||
if(original == null) {
|
|
||||||
TRANSLATIONS.remove(key);
|
|
||||||
} else {
|
|
||||||
TRANSLATIONS.put(key, original);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String describe() {
|
|
||||||
return "Setting localization for the key: " + key + " to " + text;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String describeUndo() {
|
|
||||||
return "Setting localization for the key: " + key + " to " + original;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Object getOverrideKey() {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,79 +0,0 @@
|
|||||||
package minetweaker.mc1102.item;
|
|
||||||
|
|
||||||
import minetweaker.MineTweakerAPI;
|
|
||||||
import minetweaker.api.item.*;
|
|
||||||
import minetweaker.api.minecraft.MineTweakerMC;
|
|
||||||
import minetweaker.api.oredict.IOreDictEntry;
|
|
||||||
import net.minecraft.item.*;
|
|
||||||
import net.minecraftforge.oredict.OreDictionary;
|
|
||||||
import stanhebben.zenscript.annotations.Optional;
|
|
||||||
|
|
||||||
import java.util.*;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Stan
|
|
||||||
*/
|
|
||||||
public class MCItemDefinition implements IItemDefinition {
|
|
||||||
|
|
||||||
private final String id;
|
|
||||||
private final Item item;
|
|
||||||
|
|
||||||
public MCItemDefinition(String id, Item item) {
|
|
||||||
this.id = id;
|
|
||||||
this.item = item;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getId() {
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getName() {
|
|
||||||
return item.getUnlocalizedName();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public IItemStack makeStack(@Optional int meta) {
|
|
||||||
return MineTweakerMC.getIItemStackWildcardSize(new ItemStack(item, 1, meta));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<IOreDictEntry> getOres() {
|
|
||||||
List<IOreDictEntry> result = new ArrayList<>();
|
|
||||||
|
|
||||||
for(String key : OreDictionary.getOreNames()) {
|
|
||||||
for(ItemStack is : OreDictionary.getOres(key)) {
|
|
||||||
if(is.getItem() == item) {
|
|
||||||
result.add(MineTweakerAPI.oreDict.get(key));
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
// #############################
|
|
||||||
// ### Object implementation ###
|
|
||||||
// #############################
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int hashCode() {
|
|
||||||
int hash = 7;
|
|
||||||
hash = 37 * hash + (this.item != null ? this.item.hashCode() : 0);
|
|
||||||
return hash;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean equals(Object obj) {
|
|
||||||
if(obj == null) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if(getClass() != obj.getClass()) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
final MCItemDefinition other = (MCItemDefinition) obj;
|
|
||||||
return !(this.item != other.item && (this.item == null || !this.item.equals(other.item)));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,188 +0,0 @@
|
|||||||
package minetweaker.mc1102.liquid;
|
|
||||||
|
|
||||||
import minetweaker.api.data.IData;
|
|
||||||
import minetweaker.api.item.*;
|
|
||||||
import minetweaker.api.liquid.*;
|
|
||||||
import minetweaker.api.player.IPlayer;
|
|
||||||
import minetweaker.mc1102.data.NBTConverter;
|
|
||||||
import net.minecraft.nbt.NBTTagCompound;
|
|
||||||
import net.minecraftforge.fluids.FluidStack;
|
|
||||||
|
|
||||||
import java.util.*;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Stan
|
|
||||||
*/
|
|
||||||
public class MCLiquidStack implements ILiquidStack {
|
|
||||||
|
|
||||||
private final FluidStack stack;
|
|
||||||
private IData tag = null;
|
|
||||||
|
|
||||||
public MCLiquidStack(FluidStack stack) {
|
|
||||||
this.stack = stack;
|
|
||||||
}
|
|
||||||
|
|
||||||
private MCLiquidStack(FluidStack stack, IData tag) {
|
|
||||||
this.stack = stack;
|
|
||||||
this.tag = tag;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ILiquidDefinition getDefinition() {
|
|
||||||
return new MCLiquidDefinition(stack.getFluid());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getName() {
|
|
||||||
return stack.getFluid().getName();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getDisplayName() {
|
|
||||||
return stack.getFluid().getLocalizedName(stack);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getAmount() {
|
|
||||||
return stack.amount;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public IData getTag() {
|
|
||||||
if(tag == null) {
|
|
||||||
if(stack.tag == null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
tag = NBTConverter.from(stack.tag, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
return tag;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ILiquidStack withTag(IData data) {
|
|
||||||
FluidStack result = new FluidStack(stack.getFluid(), stack.amount);
|
|
||||||
result.tag = (NBTTagCompound) NBTConverter.from(data);
|
|
||||||
return new MCLiquidStack(result, data.immutable());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ILiquidStack withAmount(int amount) {
|
|
||||||
FluidStack result = new FluidStack(stack.getFluid(), amount);
|
|
||||||
result.tag = stack.tag;
|
|
||||||
return new MCLiquidStack(result, tag);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getLuminosity() {
|
|
||||||
return stack.getFluid().getLuminosity(stack);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getDensity() {
|
|
||||||
return stack.getFluid().getDensity(stack);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getTemperature() {
|
|
||||||
return stack.getFluid().getTemperature(stack);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getViscosity() {
|
|
||||||
return stack.getFluid().getViscosity(stack);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isGaseous() {
|
|
||||||
return stack.getFluid().isGaseous(stack);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Object getInternal() {
|
|
||||||
return stack;
|
|
||||||
}
|
|
||||||
|
|
||||||
// ##################################
|
|
||||||
// ### IIngredient implementation ###
|
|
||||||
// ##################################
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getMark() {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<IItemStack> getItems() {
|
|
||||||
return Collections.emptyList();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<ILiquidStack> getLiquids() {
|
|
||||||
return Collections.singletonList(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public IIngredient amount(int amount) {
|
|
||||||
return withAmount(amount);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public IIngredient or(IIngredient ingredient) {
|
|
||||||
return new IngredientOr(this, ingredient);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public IIngredient transform(IItemTransformer transformer) {
|
|
||||||
throw new UnsupportedOperationException("Liquid stack can't have transformers");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public IIngredient only(IItemCondition condition) {
|
|
||||||
throw new UnsupportedOperationException("Liquid stack can't have conditions");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public IIngredient marked(String mark) {
|
|
||||||
throw new UnsupportedOperationException("Liquid stack can't be marked");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean matches(IItemStack item) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean matchesExact(IItemStack item) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean matches(ILiquidStack liquid) {
|
|
||||||
return getDefinition().equals(liquid.getDefinition()) && getAmount() <= liquid.getAmount();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean contains(IIngredient ingredient) {
|
|
||||||
if(!ingredient.getItems().isEmpty())
|
|
||||||
return false;
|
|
||||||
|
|
||||||
for(ILiquidStack liquid : ingredient.getLiquids()) {
|
|
||||||
if(!matches(liquid))
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public IItemStack applyTransform(IItemStack item, IPlayer byPlayer) {
|
|
||||||
return item;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean hasTransformers() {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,80 +0,0 @@
|
|||||||
package minetweaker.mc1102.logger;
|
|
||||||
|
|
||||||
import minetweaker.runtime.ILogger;
|
|
||||||
import net.minecraftforge.fml.common.*;
|
|
||||||
|
|
||||||
import java.io.*;
|
|
||||||
import java.util.regex.Pattern;
|
|
||||||
|
|
||||||
public class MCLogger implements ILogger {
|
|
||||||
|
|
||||||
private static final Pattern FORMATTING_CODE_PATTERN = Pattern.compile("(?i)" + String.valueOf('\u00a7') + "[0-9A-FK-OR]");
|
|
||||||
private final Writer writer;
|
|
||||||
private final PrintWriter printWriter;
|
|
||||||
|
|
||||||
public MCLogger(File output) {
|
|
||||||
try {
|
|
||||||
writer = new OutputStreamWriter(new FileOutputStream(output), "utf-8");
|
|
||||||
printWriter = new PrintWriter(writer);
|
|
||||||
} catch(UnsupportedEncodingException ex) {
|
|
||||||
throw new RuntimeException("What the heck?");
|
|
||||||
} catch(FileNotFoundException ex) {
|
|
||||||
throw new RuntimeException("Could not open log file " + output);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void logCommand(String message) {
|
|
||||||
try {
|
|
||||||
writer.write(stripMessage(message) + "\n");
|
|
||||||
writer.flush();
|
|
||||||
} catch(IOException ex) {
|
|
||||||
throw new RuntimeException(ex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void logInfo(String message) {
|
|
||||||
try {
|
|
||||||
writer.write("[" + Loader.instance().getLoaderState() + "][" + FMLCommonHandler.instance().getEffectiveSide() + "][INFO] " + stripMessage(message) + "\n");
|
|
||||||
writer.flush();
|
|
||||||
} catch(IOException ex) {
|
|
||||||
throw new RuntimeException(ex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void logWarning(String message) {
|
|
||||||
try {
|
|
||||||
writer.write("[" + Loader.instance().getLoaderState() + "][" + FMLCommonHandler.instance().getEffectiveSide() + "][WARNING] " + stripMessage(message) + "\n");
|
|
||||||
writer.flush();
|
|
||||||
} catch(IOException ex) {
|
|
||||||
throw new RuntimeException(ex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void logError(String message) {
|
|
||||||
logError(message, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void logError(String message, Throwable exception) {
|
|
||||||
try {
|
|
||||||
writer.write("[" + Loader.instance().getLoaderState() + "][" + FMLCommonHandler.instance().getEffectiveSide() + "][ERROR] " + stripMessage(message) + "\n");
|
|
||||||
if(exception != null) {
|
|
||||||
exception.printStackTrace(printWriter);
|
|
||||||
}
|
|
||||||
writer.flush();
|
|
||||||
} catch(IOException ex) {
|
|
||||||
throw new RuntimeException(ex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns a copy of the given string, with formatting codes stripped away.
|
|
||||||
*/
|
|
||||||
public String stripMessage(String message) {
|
|
||||||
return message == null ? null : FORMATTING_CODE_PATTERN.matcher(message).replaceAll("");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-27
@@ -1,27 +0,0 @@
|
|||||||
package minetweaker.mc1102.network;
|
|
||||||
|
|
||||||
import net.minecraft.client.Minecraft;
|
|
||||||
import net.minecraftforge.fml.common.network.simpleimpl.*;
|
|
||||||
|
|
||||||
import java.awt.*;
|
|
||||||
import java.awt.datatransfer.*;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Stan
|
|
||||||
*/
|
|
||||||
public class MineTweakerCopyClipboardHandler implements IMessageHandler<MineTweakerCopyClipboardPacket, IMessage> {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public IMessage onMessage(MineTweakerCopyClipboardPacket message, MessageContext ctx) {
|
|
||||||
Minecraft.getMinecraft().addScheduledTask(() -> handle(message, ctx));
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void handle(MineTweakerCopyClipboardPacket message, MessageContext ctx) {
|
|
||||||
if(Desktop.isDesktopSupported()) {
|
|
||||||
StringSelection stringSelection = new StringSelection(message.getData());
|
|
||||||
Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
|
|
||||||
clipboard.setContents(stringSelection, null);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-28
@@ -1,28 +0,0 @@
|
|||||||
package minetweaker.mc1102.network;
|
|
||||||
|
|
||||||
import minetweaker.*;
|
|
||||||
import minetweaker.mc1102.client.MCClient;
|
|
||||||
import minetweaker.runtime.providers.ScriptProviderMemory;
|
|
||||||
import net.minecraft.client.Minecraft;
|
|
||||||
import net.minecraftforge.fml.common.network.simpleimpl.*;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Stan
|
|
||||||
*/
|
|
||||||
public class MineTweakerLoadScriptsHandler implements IMessageHandler<MineTweakerLoadScriptsPacket, IMessage> {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public IMessage onMessage(MineTweakerLoadScriptsPacket message, MessageContext ctx) {
|
|
||||||
Minecraft.getMinecraft().addScheduledTask(() -> handle(message, ctx));
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void handle(MineTweakerLoadScriptsPacket message, MessageContext ctx) {
|
|
||||||
if(MineTweakerAPI.server == null) {
|
|
||||||
MineTweakerAPI.client = new MCClient();
|
|
||||||
|
|
||||||
MineTweakerImplementationAPI.setScriptProvider(new ScriptProviderMemory(message.getData()));
|
|
||||||
MineTweakerImplementationAPI.reload();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-32
@@ -1,32 +0,0 @@
|
|||||||
package minetweaker.mc1102.network;
|
|
||||||
|
|
||||||
import net.minecraft.client.Minecraft;
|
|
||||||
import net.minecraftforge.fml.common.network.simpleimpl.*;
|
|
||||||
|
|
||||||
import java.awt.*;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.net.*;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Stan
|
|
||||||
*/
|
|
||||||
public class MineTweakerOpenBrowserHandler implements IMessageHandler<MineTweakerOpenBrowserPacket, IMessage> {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public IMessage onMessage(MineTweakerOpenBrowserPacket message, MessageContext ctx) {
|
|
||||||
Minecraft.getMinecraft().addScheduledTask(() -> handle(message, ctx));
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void handle(MineTweakerOpenBrowserPacket message, MessageContext ctx) {
|
|
||||||
if(Desktop.isDesktopSupported()) {
|
|
||||||
Desktop desktop = Desktop.getDesktop();
|
|
||||||
try {
|
|
||||||
desktop.browse(new URI(message.getUrl()));
|
|
||||||
} catch(IOException | URISyntaxException ignored) {
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
System.out.println("Desktop not supported");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,31 +0,0 @@
|
|||||||
package minetweaker.mc1102.oredict;
|
|
||||||
|
|
||||||
import minetweaker.api.minecraft.MineTweakerMC;
|
|
||||||
import minetweaker.api.oredict.*;
|
|
||||||
import net.minecraftforge.oredict.OreDictionary;
|
|
||||||
|
|
||||||
import java.util.*;
|
|
||||||
|
|
||||||
import static minetweaker.api.minecraft.MineTweakerMC.getOreDict;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Stan
|
|
||||||
*/
|
|
||||||
public class MCOreDict implements IOreDict {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public IOreDictEntry get(String name) {
|
|
||||||
return getOreDict(name);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<IOreDictEntry> getEntries() {
|
|
||||||
List<IOreDictEntry> entries = new ArrayList<>();
|
|
||||||
for(String key : OreDictionary.getOreNames()) {
|
|
||||||
if(!OreDictionary.getOres(key).isEmpty()) {
|
|
||||||
entries.add(MineTweakerMC.getOreDict(key));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return entries;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-426
@@ -1,426 +0,0 @@
|
|||||||
package minetweaker.mc1102.oredict;
|
|
||||||
|
|
||||||
import minetweaker.*;
|
|
||||||
import minetweaker.api.item.*;
|
|
||||||
import minetweaker.api.liquid.ILiquidStack;
|
|
||||||
import minetweaker.api.minecraft.MineTweakerMC;
|
|
||||||
import minetweaker.api.oredict.*;
|
|
||||||
import minetweaker.api.player.IPlayer;
|
|
||||||
import minetweaker.mc1102.util.MineTweakerHacks;
|
|
||||||
import minetweaker.util.ArrayUtil;
|
|
||||||
import net.minecraft.item.ItemStack;
|
|
||||||
import net.minecraftforge.oredict.OreDictionary;
|
|
||||||
|
|
||||||
import java.util.*;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
import static minetweaker.api.minecraft.MineTweakerMC.*;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Stan
|
|
||||||
*/
|
|
||||||
public class MCOreDictEntry implements IOreDictEntry {
|
|
||||||
|
|
||||||
private static final List<ArrayList<ItemStack>> OREDICT_CONTENTS = MineTweakerHacks.getOreIdStacks();
|
|
||||||
private static final List<List<ItemStack>> OREDICT_CONTENTS_UN = MineTweakerHacks.getOreIdStacksUn();
|
|
||||||
|
|
||||||
|
|
||||||
private final String id;
|
|
||||||
|
|
||||||
public MCOreDictEntry(String id) {
|
|
||||||
this.id = id;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// ####################################
|
|
||||||
// ### IOreDictEntry implementation ###
|
|
||||||
// ####################################
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getName() {
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isEmpty() {
|
|
||||||
return OreDictionary.getOres(getName()).isEmpty();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public IItemStack getFirstItem() {
|
|
||||||
return getItems().get(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void add(IItemStack item) {
|
|
||||||
ItemStack stack = getItemStack(item);
|
|
||||||
if(stack != null) {
|
|
||||||
MineTweakerAPI.apply(new ActionAddItem(id, stack));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void addItems(IItemStack[] items) {
|
|
||||||
for(IItemStack item : items) {
|
|
||||||
ItemStack stack = getItemStack(item);
|
|
||||||
if(stack != null) {
|
|
||||||
MineTweakerAPI.apply(new ActionAddItem(id, stack));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void addAll(IOreDictEntry entry) {
|
|
||||||
if(entry instanceof MCOreDictEntry) {
|
|
||||||
MineTweakerAPI.apply(new ActionAddAll(id, ((MCOreDictEntry) entry).id));
|
|
||||||
} else {
|
|
||||||
MineTweakerAPI.logError("not a valid entry");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void remove(IItemStack item) {
|
|
||||||
ItemStack result = null;
|
|
||||||
for(ItemStack itemStack : OreDictionary.getOres(getName())) {
|
|
||||||
if(item.matches(getIItemStackWildcardSize(itemStack))) {
|
|
||||||
result = itemStack;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(result != null) {
|
|
||||||
MineTweakerAPI.apply(new ActionRemoveItem(id, result));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void removeItems(IItemStack[] items) {
|
|
||||||
for(IItemStack item : items) {
|
|
||||||
ItemStack result = null;
|
|
||||||
for(ItemStack itemStack : OreDictionary.getOres(id)) {
|
|
||||||
if(item.matches(getIItemStackWildcardSize(itemStack))) {
|
|
||||||
result = itemStack;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(result != null) {
|
|
||||||
MineTweakerAPI.apply(new ActionRemoveItem(id, result));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean contains(IItemStack item) {
|
|
||||||
for(ItemStack itemStack : OreDictionary.getOres(getName())) {
|
|
||||||
if(getIItemStackWildcardSize(itemStack).matches(item)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void mirror(IOreDictEntry other) {
|
|
||||||
if(other instanceof MCOreDictEntry) {
|
|
||||||
MineTweakerAPI.apply(new ActionMirror(id, ((MCOreDictEntry) other).id));
|
|
||||||
} else {
|
|
||||||
MineTweakerAPI.logError("not a valid oredict entry");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getMark() {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getAmount() {
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<IItemStack> getItems() {
|
|
||||||
return OreDictionary.getOres(getName()).stream().map(MineTweakerMC::getIItemStackWildcardSize).collect(Collectors.toList());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<ILiquidStack> getLiquids() {
|
|
||||||
return Collections.emptyList();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public IIngredient amount(int amount) {
|
|
||||||
return new IngredientStack(this, amount);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public IIngredient transform(IItemTransformer transformer) {
|
|
||||||
return new IngredientOreDict(this, null, ArrayUtil.EMPTY_CONDITIONS, new IItemTransformer[]{transformer});
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public IIngredient only(IItemCondition condition) {
|
|
||||||
return new IngredientOreDict(this, null, new IItemCondition[]{condition}, ArrayUtil.EMPTY_TRANSFORMERS);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public IIngredient marked(String mark) {
|
|
||||||
return new IngredientOreDict(this, mark, ArrayUtil.EMPTY_CONDITIONS, ArrayUtil.EMPTY_TRANSFORMERS);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public IIngredient or(IIngredient ingredient) {
|
|
||||||
return new IngredientOr(this, ingredient);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean matches(IItemStack item) {
|
|
||||||
return contains(item);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean matchesExact(IItemStack item) {
|
|
||||||
return contains(item);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean matches(ILiquidStack liquid) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean contains(IIngredient ingredient) {
|
|
||||||
List<IItemStack> items = ingredient.getItems();
|
|
||||||
for(IItemStack item : items) {
|
|
||||||
if(!matches(item))
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public IItemStack applyTransform(IItemStack item, IPlayer byPlayer) {
|
|
||||||
return item;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean hasTransformers() {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Object getInternal() {
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
|
|
||||||
// #############################
|
|
||||||
// ### Object implementation ###
|
|
||||||
// #############################
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return "<ore:" + id + ">";
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int hashCode() {
|
|
||||||
return id.hashCode();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean equals(Object other) {
|
|
||||||
return other instanceof MCOreDictEntry && Objects.equals(((MCOreDictEntry) other).id, id);
|
|
||||||
}
|
|
||||||
|
|
||||||
// ######################
|
|
||||||
// ### Action classes ###
|
|
||||||
// ######################
|
|
||||||
|
|
||||||
private static class ActionAddItem implements IUndoableAction {
|
|
||||||
|
|
||||||
private final String id;
|
|
||||||
private final ItemStack item;
|
|
||||||
|
|
||||||
public ActionAddItem(String id, ItemStack item) {
|
|
||||||
this.id = id;
|
|
||||||
this.item = item;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void apply() {
|
|
||||||
OreDictionary.registerOre(id, item);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean canUndo() {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void undo() {
|
|
||||||
int oreId = OreDictionary.getOreID(id);
|
|
||||||
OREDICT_CONTENTS.get(oreId).remove(item);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String describe() {
|
|
||||||
return "Adding " + item.getDisplayName() + " to ore dictionary entry " + id;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String describeUndo() {
|
|
||||||
return "Removing " + item.getDisplayName() + " from ore dictionary entry " + id;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Object getOverrideKey() {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private static class ActionMirror implements IUndoableAction {
|
|
||||||
|
|
||||||
private final String idTarget;
|
|
||||||
private final String idSource;
|
|
||||||
|
|
||||||
private final ArrayList<ItemStack> targetCopy;
|
|
||||||
private final List<ItemStack> targetCopyUn;
|
|
||||||
|
|
||||||
public ActionMirror(String idTarget, String idSource) {
|
|
||||||
this.idTarget = idTarget;
|
|
||||||
this.idSource = idSource;
|
|
||||||
|
|
||||||
int targetOreId = OreDictionary.getOreID(idTarget);
|
|
||||||
targetCopy = OREDICT_CONTENTS.get(targetOreId);
|
|
||||||
targetCopyUn = OREDICT_CONTENTS_UN.get(targetOreId);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void apply() {
|
|
||||||
int sourceOreId = OreDictionary.getOreID(idSource);
|
|
||||||
int targetOreId = OreDictionary.getOreID(idTarget);
|
|
||||||
OREDICT_CONTENTS.set(targetOreId, OREDICT_CONTENTS.get(sourceOreId));
|
|
||||||
OREDICT_CONTENTS_UN.set(targetOreId, OREDICT_CONTENTS_UN.get(sourceOreId));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean canUndo() {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void undo() {
|
|
||||||
int targetOreId = OreDictionary.getOreID(idTarget);
|
|
||||||
OREDICT_CONTENTS.set(targetOreId, targetCopy);
|
|
||||||
OREDICT_CONTENTS_UN.set(targetOreId, targetCopyUn);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String describe() {
|
|
||||||
return "Mirroring " + idSource + " to " + idTarget;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String describeUndo() {
|
|
||||||
return "Undoing mirror of " + idSource + " to " + idTarget;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Object getOverrideKey() {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static class ActionRemoveItem implements IUndoableAction {
|
|
||||||
|
|
||||||
private final String id;
|
|
||||||
private final ItemStack item;
|
|
||||||
|
|
||||||
public ActionRemoveItem(String id, ItemStack item) {
|
|
||||||
this.id = id;
|
|
||||||
this.item = item;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void apply() {
|
|
||||||
int oreId = OreDictionary.getOreID(id);
|
|
||||||
OREDICT_CONTENTS.get(oreId).remove(item);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean canUndo() {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void undo() {
|
|
||||||
int oreId = OreDictionary.getOreID(id);
|
|
||||||
OREDICT_CONTENTS.get(oreId).add(item);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String describe() {
|
|
||||||
return "Removing " + item.getDisplayName() + " from ore dictionary entry " + id;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String describeUndo() {
|
|
||||||
return "Restoring " + item.getDisplayName() + " to ore dictionary entry " + id;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Object getOverrideKey() {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static class ActionAddAll implements IUndoableAction {
|
|
||||||
|
|
||||||
private final String idTarget;
|
|
||||||
private final String idSource;
|
|
||||||
|
|
||||||
public ActionAddAll(String idTarget, String idSource) {
|
|
||||||
this.idTarget = idTarget;
|
|
||||||
this.idSource = idSource;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void apply() {
|
|
||||||
for(ItemStack stack : OreDictionary.getOres(idSource)) {
|
|
||||||
OreDictionary.registerOre(idTarget, stack);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean canUndo() {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void undo() {
|
|
||||||
int targetOreId = OreDictionary.getOreID(idTarget);
|
|
||||||
for(ItemStack stack : OreDictionary.getOres(idSource)) {
|
|
||||||
OREDICT_CONTENTS.get(targetOreId).remove(stack);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String describe() {
|
|
||||||
return "Copying contents of ore dictionary entry " + idSource + " to " + idTarget;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String describeUndo() {
|
|
||||||
return "Removing contents of ore dictionary entry " + idSource + " from " + idTarget;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Object getOverrideKey() {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,135 +0,0 @@
|
|||||||
package minetweaker.mc1102.player;
|
|
||||||
|
|
||||||
import minetweaker.MineTweakerAPI;
|
|
||||||
import minetweaker.api.chat.IChatMessage;
|
|
||||||
import minetweaker.api.data.IData;
|
|
||||||
import minetweaker.api.item.IItemStack;
|
|
||||||
import minetweaker.api.player.IPlayer;
|
|
||||||
import net.minecraft.command.ICommandSender;
|
|
||||||
import net.minecraft.util.text.*;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Jared
|
|
||||||
*/
|
|
||||||
public class RconPlayer implements IPlayer {
|
|
||||||
|
|
||||||
private final ICommandSender sender;
|
|
||||||
|
|
||||||
public RconPlayer(ICommandSender sender) {
|
|
||||||
this.sender = sender;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ICommandSender getInternal() {
|
|
||||||
return sender;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getId() {
|
|
||||||
return null; // TODO: we should be having this for MC 1.7.10, right?
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getName() {
|
|
||||||
return sender.getName();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public IData getData() {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getXP() {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setXP(int xp) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void removeXP(int xp) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void update(IData data) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void sendChat(IChatMessage message) {
|
|
||||||
Object internal = message.getInternal();
|
|
||||||
if(!(internal instanceof ITextComponent)) {
|
|
||||||
MineTweakerAPI.logError("not a valid chat message");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
sender.sendMessage((ITextComponent) internal);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void sendChat(String message) {
|
|
||||||
sender.sendMessage(new TextComponentString(message));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getHotbarSize() {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public IItemStack getHotbarStack(int i) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getInventorySize() {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public IItemStack getInventoryStack(int i) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public IItemStack getCurrentItem() {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isCreative() {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isAdventure() {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void openBrowser(String url) {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void copyToClipboard(String value) {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean equals(Object other) {
|
|
||||||
return other.getClass() == this.getClass() && ((RconPlayer) other).sender == sender;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int hashCode() {
|
|
||||||
int hash = 5;
|
|
||||||
hash = 23 * hash + (this.sender != null ? this.sender.hashCode() : 0);
|
|
||||||
return hash;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void give(IItemStack stack) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-430
@@ -1,430 +0,0 @@
|
|||||||
package minetweaker.mc1102.recipes;
|
|
||||||
|
|
||||||
import minetweaker.*;
|
|
||||||
import minetweaker.api.item.*;
|
|
||||||
import minetweaker.api.minecraft.MineTweakerMC;
|
|
||||||
import minetweaker.api.player.IPlayer;
|
|
||||||
import minetweaker.api.recipes.*;
|
|
||||||
import minetweaker.mc1102.util.MineTweakerHacks;
|
|
||||||
import net.minecraft.entity.player.EntityPlayer;
|
|
||||||
import net.minecraft.inventory.*;
|
|
||||||
import net.minecraft.item.ItemStack;
|
|
||||||
import net.minecraft.item.crafting.*;
|
|
||||||
import net.minecraftforge.oredict.*;
|
|
||||||
import stanhebben.zenscript.annotations.Optional;
|
|
||||||
|
|
||||||
import java.util.*;
|
|
||||||
|
|
||||||
import static minetweaker.api.minecraft.MineTweakerMC.*;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Stan
|
|
||||||
*/
|
|
||||||
public class MCRecipeManager implements IRecipeManager {
|
|
||||||
|
|
||||||
private final List<IRecipe> recipes;
|
|
||||||
private final List<ICraftingRecipe> transformerRecipes;
|
|
||||||
|
|
||||||
public MCRecipeManager() {
|
|
||||||
recipes = CraftingManager.getInstance().getRecipeList();
|
|
||||||
transformerRecipes = new ArrayList<>();
|
|
||||||
}
|
|
||||||
|
|
||||||
private static boolean matches(Object input, IIngredient ingredient) {
|
|
||||||
if((input == null) != (ingredient == null)) {
|
|
||||||
return false;
|
|
||||||
} else if(ingredient != null) {
|
|
||||||
if(input instanceof ItemStack) {
|
|
||||||
if(!ingredient.matches(getIItemStack((ItemStack) input))) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
} else if(input instanceof String) {
|
|
||||||
if(!ingredient.contains(getOreDict((String) input))) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean hasTransformerRecipes() {
|
|
||||||
return transformerRecipes.size() > 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void applyTransformations(ICraftingInventory inventory, IPlayer byPlayer) {
|
|
||||||
for(ICraftingRecipe recipe : transformerRecipes) {
|
|
||||||
if(recipe.matches(inventory)) {
|
|
||||||
recipe.applyTransformers(inventory, byPlayer);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<ICraftingRecipe> getRecipesFor(IIngredient ingredient) {
|
|
||||||
List<ICraftingRecipe> results = new ArrayList<>();
|
|
||||||
|
|
||||||
recipes.stream().filter(recipe -> ingredient.matches(MineTweakerMC.getIItemStack(recipe.getRecipeOutput()))).forEach(recipe -> {
|
|
||||||
ICraftingRecipe converted = RecipeConverter.toCraftingRecipe(recipe);
|
|
||||||
results.add(converted);
|
|
||||||
});
|
|
||||||
|
|
||||||
return results;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<ICraftingRecipe> getAll() {
|
|
||||||
List<ICraftingRecipe> results = new ArrayList<>();
|
|
||||||
|
|
||||||
for(IRecipe recipe : recipes) {
|
|
||||||
ICraftingRecipe converted = RecipeConverter.toCraftingRecipe(recipe);
|
|
||||||
results.add(converted);
|
|
||||||
}
|
|
||||||
|
|
||||||
return results;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int remove(IIngredient output, @Optional boolean nbtMatch) {
|
|
||||||
List<IRecipe> toRemove = new ArrayList<>();
|
|
||||||
List<Integer> removeIndex = new ArrayList<>();
|
|
||||||
for(int i = 0; i < recipes.size(); i++) {
|
|
||||||
IRecipe recipe = recipes.get(i);
|
|
||||||
|
|
||||||
// certain special recipes have no predefined output. ignore those
|
|
||||||
// since these cannot be removed with MineTweaker scripts
|
|
||||||
if(recipe.getRecipeOutput() != null) {
|
|
||||||
if(nbtMatch ? output.matchesExact(getIItemStack(recipe.getRecipeOutput())) : output.matches(getIItemStack(recipe.getRecipeOutput()))) {
|
|
||||||
toRemove.add(recipe);
|
|
||||||
removeIndex.add(i);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
MineTweakerAPI.apply(new ActionRemoveRecipes(toRemove, removeIndex));
|
|
||||||
return toRemove.size();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void addShaped(IItemStack output, IIngredient[][] ingredients, @Optional IRecipeFunction function, @Optional IRecipeAction action) {
|
|
||||||
addShaped(output, ingredients, function, action, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void addShapedMirrored(IItemStack output, IIngredient[][] ingredients, @Optional IRecipeFunction function, @Optional IRecipeAction action) {
|
|
||||||
addShaped(output, ingredients, function, action, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void addShapeless(IItemStack output, IIngredient[] ingredients, @Optional IRecipeFunction function, @Optional IRecipeAction action) {
|
|
||||||
ShapelessRecipe recipe = new ShapelessRecipe(output, ingredients, function, action);
|
|
||||||
IRecipe irecipe = RecipeConverter.convert(recipe);
|
|
||||||
MineTweakerAPI.apply(new ActionAddRecipe(irecipe, recipe));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int removeShaped(IIngredient output, IIngredient[][] ingredients) {
|
|
||||||
int ingredientsWidth = 0;
|
|
||||||
int ingredientsHeight = 0;
|
|
||||||
|
|
||||||
if(ingredients != null) {
|
|
||||||
ingredientsHeight = ingredients.length;
|
|
||||||
|
|
||||||
for(int i = 0; i < ingredients.length; i++) {
|
|
||||||
ingredientsWidth = Math.max(ingredientsWidth, ingredients[i].length);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
List<IRecipe> toRemove = new ArrayList<IRecipe>();
|
|
||||||
List<Integer> removeIndex = new ArrayList<Integer>();
|
|
||||||
outer:
|
|
||||||
for(int i = 0; i < recipes.size(); i++) {
|
|
||||||
IRecipe recipe = recipes.get(i);
|
|
||||||
|
|
||||||
if(recipe.getRecipeOutput() == null || !output.matches(getIItemStack(recipe.getRecipeOutput()))) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(ingredients != null) {
|
|
||||||
if(recipe instanceof ShapedRecipes) {
|
|
||||||
ShapedRecipes srecipe = (ShapedRecipes) recipe;
|
|
||||||
if(ingredientsWidth != srecipe.recipeWidth || ingredientsHeight != srecipe.recipeHeight) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
for(int j = 0; j < ingredientsHeight; j++) {
|
|
||||||
IIngredient[] row = ingredients[j];
|
|
||||||
for(int k = 0; k < ingredientsWidth; k++) {
|
|
||||||
IIngredient ingredient = k > row.length ? null : row[k];
|
|
||||||
ItemStack recipeIngredient = srecipe.recipeItems[j * srecipe.recipeWidth + k];
|
|
||||||
|
|
||||||
if(!matches(recipeIngredient, ingredient)) {
|
|
||||||
continue outer;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else if(recipe instanceof ShapedOreRecipe) {
|
|
||||||
ShapedOreRecipe srecipe = (ShapedOreRecipe) recipe;
|
|
||||||
int recipeWidth = MineTweakerHacks.getShapedOreRecipeWidth(srecipe);
|
|
||||||
int recipeHeight = srecipe.getRecipeSize() / recipeWidth;
|
|
||||||
if(ingredientsWidth != recipeWidth || ingredientsHeight != recipeHeight) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
for(int j = 0; j < ingredientsHeight; j++) {
|
|
||||||
IIngredient[] row = ingredients[j];
|
|
||||||
for(int k = 0; k < ingredientsWidth; k++) {
|
|
||||||
IIngredient ingredient = k > row.length ? null : row[k];
|
|
||||||
Object input = srecipe.getInput()[j * recipeWidth + k];
|
|
||||||
if(!matches(input, ingredient)) {
|
|
||||||
continue outer;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if(recipe instanceof ShapelessRecipes) {
|
|
||||||
continue;
|
|
||||||
} else if(recipe instanceof ShapelessOreRecipe) {
|
|
||||||
continue;
|
|
||||||
} else {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if(recipe instanceof ShapelessRecipes) {
|
|
||||||
continue;
|
|
||||||
} else if(recipe instanceof ShapelessOreRecipe) {
|
|
||||||
continue;
|
|
||||||
} else {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
toRemove.add(recipe);
|
|
||||||
removeIndex.add(i);
|
|
||||||
}
|
|
||||||
|
|
||||||
MineTweakerAPI.apply(new ActionRemoveRecipes(toRemove, removeIndex));
|
|
||||||
return toRemove.size();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int removeShapeless(IIngredient output, IIngredient[] ingredients, boolean wildcard) {
|
|
||||||
List<IRecipe> toRemove = new ArrayList<IRecipe>();
|
|
||||||
List<Integer> removeIndex = new ArrayList<Integer>();
|
|
||||||
outer:
|
|
||||||
for(int i = 0; i < recipes.size(); i++) {
|
|
||||||
IRecipe recipe = recipes.get(i);
|
|
||||||
|
|
||||||
if(recipe.getRecipeOutput() == null || !output.matches(getIItemStack(recipe.getRecipeOutput()))) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(ingredients != null) {
|
|
||||||
if(recipe instanceof ShapelessRecipes) {
|
|
||||||
ShapelessRecipes srecipe = (ShapelessRecipes) recipe;
|
|
||||||
|
|
||||||
if(ingredients.length > srecipe.getRecipeSize()) {
|
|
||||||
continue;
|
|
||||||
} else if(!wildcard && ingredients.length < srecipe.getRecipeSize()) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
checkIngredient:
|
|
||||||
for(int j = 0; j < ingredients.length; j++) {
|
|
||||||
for(int k = 0; k < srecipe.getRecipeSize(); k++) {
|
|
||||||
if(matches(srecipe.recipeItems.get(k), ingredients[j])) {
|
|
||||||
continue checkIngredient;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
continue outer;
|
|
||||||
}
|
|
||||||
} else if(recipe instanceof ShapelessOreRecipe) {
|
|
||||||
ShapelessOreRecipe srecipe = (ShapelessOreRecipe) recipe;
|
|
||||||
ArrayList<Object> inputs = srecipe.getInput();
|
|
||||||
|
|
||||||
if(inputs.size() < ingredients.length) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if(!wildcard && inputs.size() > ingredients.length) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
checkIngredient:
|
|
||||||
for(int j = 0; j < ingredients.length; j++) {
|
|
||||||
for(int k = 0; k < srecipe.getRecipeSize(); k++) {
|
|
||||||
if(matches(inputs.get(k), ingredients[j])) {
|
|
||||||
continue checkIngredient;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
continue outer;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(recipe instanceof ShapedRecipes) {
|
|
||||||
continue;
|
|
||||||
} else if(recipe instanceof ShapedOreRecipe) {
|
|
||||||
continue;
|
|
||||||
} else {
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if(recipe instanceof ShapedRecipes) {
|
|
||||||
continue;
|
|
||||||
} else if(recipe instanceof ShapedOreRecipe) {
|
|
||||||
continue;
|
|
||||||
} else {
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
toRemove.add(recipe);
|
|
||||||
removeIndex.add(i);
|
|
||||||
}
|
|
||||||
|
|
||||||
MineTweakerAPI.apply(new ActionRemoveRecipes(toRemove, removeIndex));
|
|
||||||
return toRemove.size();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public IItemStack craft(IItemStack[][] contents) {
|
|
||||||
Container container = new ContainerVirtual();
|
|
||||||
|
|
||||||
int width = 0;
|
|
||||||
int height = contents.length;
|
|
||||||
for(IItemStack[] row : contents) {
|
|
||||||
width = Math.max(width, row.length);
|
|
||||||
}
|
|
||||||
|
|
||||||
ItemStack[] iContents = new ItemStack[width * height];
|
|
||||||
for(int i = 0; i < height; i++) {
|
|
||||||
for(int j = 0; j < contents[i].length; j++) {
|
|
||||||
if(contents[i][j] != null) {
|
|
||||||
iContents[i * width + j] = getItemStack(contents[i][j]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
InventoryCrafting inventory = new InventoryCrafting(container, width, height);
|
|
||||||
for(int i = 0; i < iContents.length; i++) {
|
|
||||||
inventory.setInventorySlotContents(i, iContents[i]);
|
|
||||||
}
|
|
||||||
ItemStack result = CraftingManager.getInstance().findMatchingRecipe(inventory, null);
|
|
||||||
if(result == null) {
|
|
||||||
return null;
|
|
||||||
} else {
|
|
||||||
return getIItemStack(result);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void addShaped(IItemStack output, IIngredient[][] ingredients, IRecipeFunction function, IRecipeAction action, boolean mirrored) {
|
|
||||||
ShapedRecipe recipe = new ShapedRecipe(output, ingredients, function, action, mirrored);
|
|
||||||
IRecipe irecipe = RecipeConverter.convert(recipe);
|
|
||||||
MineTweakerAPI.apply(new ActionAddRecipe(irecipe, recipe));
|
|
||||||
}
|
|
||||||
|
|
||||||
private class ContainerVirtual extends Container {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean canInteractWith(EntityPlayer var1) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private class ActionRemoveRecipes implements IUndoableAction {
|
|
||||||
|
|
||||||
private final List<Integer> removingIndices;
|
|
||||||
private final List<IRecipe> removingRecipes;
|
|
||||||
|
|
||||||
public ActionRemoveRecipes(List<IRecipe> recipes, List<Integer> indices) {
|
|
||||||
this.removingIndices = indices;
|
|
||||||
this.removingRecipes = recipes;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void apply() {
|
|
||||||
for(int i = removingIndices.size() - 1; i >= 0; i--) {
|
|
||||||
recipes.remove((int) removingIndices.get(i));
|
|
||||||
MineTweakerAPI.getIjeiRecipeRegistry().removeRecipe(removingRecipes.get(i));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean canUndo() {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void undo() {
|
|
||||||
for(int i = 0; i < removingIndices.size(); i++) {
|
|
||||||
int index = Math.min(recipes.size(), removingIndices.get(i));
|
|
||||||
recipes.add(index, removingRecipes.get(i));
|
|
||||||
MineTweakerAPI.getIjeiRecipeRegistry().addRecipe(removingRecipes.get(i));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String describe() {
|
|
||||||
return "Removing " + removingIndices.size() + " recipes";
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String describeUndo() {
|
|
||||||
return "Restoring " + removingIndices.size() + " recipes";
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Object getOverrideKey() {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private class ActionAddRecipe implements IUndoableAction {
|
|
||||||
|
|
||||||
private final IRecipe recipe;
|
|
||||||
private final ICraftingRecipe craftingRecipe;
|
|
||||||
|
|
||||||
public ActionAddRecipe(IRecipe recipe, ICraftingRecipe craftingRecipe) {
|
|
||||||
this.recipe = recipe;
|
|
||||||
this.craftingRecipe = craftingRecipe;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void apply() {
|
|
||||||
recipes.add(recipe);
|
|
||||||
if(craftingRecipe.hasTransformers()) {
|
|
||||||
transformerRecipes.add(craftingRecipe);
|
|
||||||
}
|
|
||||||
MineTweakerAPI.getIjeiRecipeRegistry().addRecipe(recipe);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean canUndo() {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void undo() {
|
|
||||||
recipes.remove(recipe);
|
|
||||||
if(craftingRecipe.hasTransformers()) {
|
|
||||||
transformerRecipes.remove(craftingRecipe);
|
|
||||||
}
|
|
||||||
MineTweakerAPI.getIjeiRecipeRegistry().removeRecipe(recipe);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String describe() {
|
|
||||||
return "Adding recipe for " + recipe.getRecipeOutput().getDisplayName();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String describeUndo() {
|
|
||||||
return "Removing recipe for " + recipe.getRecipeOutput().getDisplayName();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Object getOverrideKey() {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-169
@@ -1,169 +0,0 @@
|
|||||||
package minetweaker.mc1102.recipes;
|
|
||||||
|
|
||||||
import minetweaker.api.item.*;
|
|
||||||
import minetweaker.api.minecraft.MineTweakerMC;
|
|
||||||
import minetweaker.api.recipes.*;
|
|
||||||
import net.minecraft.item.ItemStack;
|
|
||||||
import net.minecraft.item.crafting.*;
|
|
||||||
import net.minecraftforge.oredict.*;
|
|
||||||
|
|
||||||
import java.util.*;
|
|
||||||
|
|
||||||
import static minetweaker.api.minecraft.MineTweakerMC.getItemStack;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Stan
|
|
||||||
*/
|
|
||||||
public class RecipeConverter {
|
|
||||||
|
|
||||||
public static final int TYPE_ADVANCED = 0;
|
|
||||||
public static final int TYPE_ORE = 1;
|
|
||||||
public static final int TYPE_BASIC = 2;
|
|
||||||
|
|
||||||
private RecipeConverter() {
|
|
||||||
}
|
|
||||||
|
|
||||||
private static int getIngredientType(IIngredient pattern) {
|
|
||||||
Object internal = pattern.getInternal();
|
|
||||||
if(internal == null) {
|
|
||||||
return TYPE_ADVANCED;
|
|
||||||
} else if(internal instanceof ItemStack) {
|
|
||||||
return TYPE_BASIC;
|
|
||||||
} else {
|
|
||||||
return TYPE_ORE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static int getRecipeType(IIngredient[] ingredients) {
|
|
||||||
int type = TYPE_BASIC;
|
|
||||||
for(IIngredient ingredient : ingredients) {
|
|
||||||
type = Math.min(type, getIngredientType(ingredient));
|
|
||||||
}
|
|
||||||
return type;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static IRecipe convert(ShapelessRecipe recipe) {
|
|
||||||
IIngredient[] ingredients = recipe.getIngredients();
|
|
||||||
int type = getRecipeType(ingredients);
|
|
||||||
|
|
||||||
if(type == TYPE_BASIC) {
|
|
||||||
ItemStack[] items = new ItemStack[ingredients.length];
|
|
||||||
for(int i = 0; i < ingredients.length; i++) {
|
|
||||||
items[i] = getItemStack(ingredients[i]);
|
|
||||||
}
|
|
||||||
return new ShapelessRecipeBasic(items, recipe);
|
|
||||||
} else if(type == TYPE_ORE) {
|
|
||||||
Object[] items = new Object[ingredients.length];
|
|
||||||
for(int i = 0; i < ingredients.length; i++) {
|
|
||||||
items[i] = ingredients[i].getInternal();
|
|
||||||
}
|
|
||||||
return new ShapelessRecipeOre(items, recipe);
|
|
||||||
} else {
|
|
||||||
return new ShapelessRecipeAdvanced(recipe);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static IRecipe convert(ShapedRecipe recipe) {
|
|
||||||
IIngredient[] ingredients = recipe.getIngredients();
|
|
||||||
byte[] posx = recipe.getIngredientsX();
|
|
||||||
byte[] posy = recipe.getIngredientsY();
|
|
||||||
|
|
||||||
// determine recipe type
|
|
||||||
int type = getRecipeType(ingredients);
|
|
||||||
|
|
||||||
// construct recipe
|
|
||||||
if(type == TYPE_BASIC) {
|
|
||||||
ItemStack[] basicIngredients = new ItemStack[recipe.getHeight() * recipe.getWidth()];
|
|
||||||
for(int i = 0; i < ingredients.length; i++) {
|
|
||||||
basicIngredients[posx[i] + posy[i] * recipe.getWidth()] = getItemStack(ingredients[i]);
|
|
||||||
}
|
|
||||||
|
|
||||||
return new ShapedRecipeBasic(basicIngredients, recipe);
|
|
||||||
} else if(type == TYPE_ORE) {
|
|
||||||
Object[] converted = new Object[recipe.getHeight() * recipe.getWidth()];
|
|
||||||
for(int i = 0; i < ingredients.length; i++) {
|
|
||||||
converted[posx[i] + posy[i] * recipe.getWidth()] = ingredients[i].getInternal();
|
|
||||||
}
|
|
||||||
|
|
||||||
// arguments contents:
|
|
||||||
// 1) recipe patterns
|
|
||||||
// 2) characters + ingredients
|
|
||||||
|
|
||||||
int counter = 0;
|
|
||||||
String[] parts = new String[recipe.getHeight()];
|
|
||||||
ArrayList rarguments = new ArrayList();
|
|
||||||
for(int i = 0; i < recipe.getHeight(); i++) {
|
|
||||||
char[] pattern = new char[recipe.getWidth()];
|
|
||||||
for(int j = 0; j < recipe.getWidth(); j++) {
|
|
||||||
int off = i * recipe.getWidth() + j;
|
|
||||||
if(converted[off] == null) {
|
|
||||||
pattern[j] = ' ';
|
|
||||||
} else {
|
|
||||||
pattern[j] = (char) ('A' + counter);
|
|
||||||
rarguments.add(pattern[j]);
|
|
||||||
rarguments.add(converted[off]);
|
|
||||||
counter++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
parts[i] = new String(pattern);
|
|
||||||
}
|
|
||||||
|
|
||||||
rarguments.addAll(0, Arrays.asList(parts));
|
|
||||||
|
|
||||||
return new ShapedRecipeOre(rarguments.toArray(), recipe);
|
|
||||||
} else {
|
|
||||||
return new ShapedRecipeAdvanced(recipe);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static ICraftingRecipe toCraftingRecipe(IRecipe recipe) {
|
|
||||||
IItemStack output = MineTweakerMC.getIItemStack(recipe.getRecipeOutput());
|
|
||||||
|
|
||||||
if(recipe instanceof ShapelessRecipes) {
|
|
||||||
ShapelessRecipes shapeless = (ShapelessRecipes) recipe;
|
|
||||||
|
|
||||||
IIngredient[] ingredients = new IIngredient[shapeless.recipeItems.size()];
|
|
||||||
for(int i = 0; i < ingredients.length; i++) {
|
|
||||||
ingredients[i] = MineTweakerMC.getIIngredient(shapeless.recipeItems.get(i));
|
|
||||||
}
|
|
||||||
|
|
||||||
return new ShapelessRecipe(output, ingredients, null, null);
|
|
||||||
} else if(recipe instanceof ShapedRecipes) {
|
|
||||||
ShapedRecipes shaped = (ShapedRecipes) recipe;
|
|
||||||
|
|
||||||
IIngredient[][] ingredients = new IIngredient[shaped.recipeHeight][shaped.recipeWidth];
|
|
||||||
for(int i = 0; i < shaped.recipeHeight; i++) {
|
|
||||||
for(int j = 0; j < shaped.recipeWidth; j++) {
|
|
||||||
ingredients[i][j] = MineTweakerMC.getIItemStack(shaped.recipeItems[i * shaped.recipeWidth + j]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return new ShapedRecipe(output, ingredients, null, null, false);
|
|
||||||
} else if(recipe instanceof ShapedOreRecipe) {
|
|
||||||
ShapedOreRecipe shaped = (ShapedOreRecipe) recipe;
|
|
||||||
|
|
||||||
int width = (int) Math.sqrt(recipe.getRecipeSize());
|
|
||||||
int height = recipe.getRecipeSize() / width;
|
|
||||||
|
|
||||||
IIngredient[][] recipeIngredients = new IIngredient[height][width];
|
|
||||||
for(int i = 0; i < height; i++) {
|
|
||||||
for(int j = 0; j < width; j++) {
|
|
||||||
recipeIngredients[i][j] = MineTweakerMC.getIIngredient(shaped.getInput()[i * width + j]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return new ShapedRecipe(output, recipeIngredients, null, null, false);
|
|
||||||
} else if(recipe instanceof ShapelessOreRecipe) {
|
|
||||||
ShapelessOreRecipe shapeless = (ShapelessOreRecipe) recipe;
|
|
||||||
|
|
||||||
IIngredient[] ingredients = new IIngredient[shapeless.getRecipeSize()];
|
|
||||||
for(int i = 0; i < ingredients.length; i++) {
|
|
||||||
ingredients[i] = MineTweakerMC.getIIngredient(shapeless.getInput().get(i));
|
|
||||||
}
|
|
||||||
|
|
||||||
return new ShapelessRecipe(output, ingredients, null, null);
|
|
||||||
} else {
|
|
||||||
return new UnknownRecipe(output);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-44
@@ -1,44 +0,0 @@
|
|||||||
package minetweaker.mc1102.recipes;
|
|
||||||
|
|
||||||
import minetweaker.api.item.IItemStack;
|
|
||||||
import minetweaker.api.recipes.*;
|
|
||||||
import net.minecraft.inventory.InventoryCrafting;
|
|
||||||
import net.minecraft.item.ItemStack;
|
|
||||||
import net.minecraft.item.crafting.ShapedRecipes;
|
|
||||||
import net.minecraft.world.World;
|
|
||||||
|
|
||||||
import static minetweaker.api.minecraft.MineTweakerMC.getItemStack;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Stan
|
|
||||||
*/
|
|
||||||
public class ShapedRecipeBasic extends ShapedRecipes implements IMTRecipe {
|
|
||||||
|
|
||||||
private final ShapedRecipe recipe;
|
|
||||||
|
|
||||||
public ShapedRecipeBasic(ItemStack[] basicInputs, ShapedRecipe recipe) {
|
|
||||||
super(recipe.getWidth(), recipe.getHeight(), basicInputs, getItemStack(recipe.getOutput()));
|
|
||||||
|
|
||||||
this.recipe = recipe;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean matches(InventoryCrafting inventory, World world) {
|
|
||||||
return recipe.matches(MCCraftingInventory.get(inventory));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ItemStack getCraftingResult(InventoryCrafting inventory) {
|
|
||||||
IItemStack result = recipe.getCraftingResult(MCCraftingInventory.get(inventory));
|
|
||||||
if(result == null) {
|
|
||||||
return null;
|
|
||||||
} else {
|
|
||||||
return getItemStack(result).copy();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ICraftingRecipe getRecipe() {
|
|
||||||
return recipe;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-43
@@ -1,43 +0,0 @@
|
|||||||
package minetweaker.mc1102.recipes;
|
|
||||||
|
|
||||||
import minetweaker.api.recipes.*;
|
|
||||||
import net.minecraft.inventory.InventoryCrafting;
|
|
||||||
import net.minecraft.item.ItemStack;
|
|
||||||
import net.minecraft.world.World;
|
|
||||||
import net.minecraftforge.oredict.ShapedOreRecipe;
|
|
||||||
|
|
||||||
import static minetweaker.api.minecraft.MineTweakerMC.getItemStack;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Stan
|
|
||||||
*/
|
|
||||||
public class ShapedRecipeOre extends ShapedOreRecipe implements IMTRecipe {
|
|
||||||
|
|
||||||
private final ShapedRecipe recipe;
|
|
||||||
|
|
||||||
public ShapedRecipeOre(Object[] contents, ShapedRecipe recipe) {
|
|
||||||
super(getItemStack(recipe.getOutput()), contents);
|
|
||||||
|
|
||||||
this.recipe = recipe;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean matches(InventoryCrafting inventory, World world) {
|
|
||||||
return recipe.matches(MCCraftingInventory.get(inventory));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ItemStack getCraftingResult(InventoryCrafting inventory) {
|
|
||||||
if(recipe != null) {
|
|
||||||
if(recipe.getCraftingResult(MCCraftingInventory.get(inventory)) != null) {
|
|
||||||
return getItemStack(recipe.getCraftingResult(MCCraftingInventory.get(inventory))).copy();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ICraftingRecipe getRecipe() {
|
|
||||||
return recipe;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-43
@@ -1,43 +0,0 @@
|
|||||||
package minetweaker.mc1102.recipes;
|
|
||||||
|
|
||||||
import minetweaker.api.recipes.*;
|
|
||||||
import net.minecraft.inventory.InventoryCrafting;
|
|
||||||
import net.minecraft.item.ItemStack;
|
|
||||||
import net.minecraft.item.crafting.ShapelessRecipes;
|
|
||||||
import net.minecraft.world.World;
|
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
|
|
||||||
import static minetweaker.api.minecraft.MineTweakerMC.getItemStack;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Stan
|
|
||||||
*/
|
|
||||||
public class ShapelessRecipeBasic extends ShapelessRecipes implements IMTRecipe {
|
|
||||||
|
|
||||||
private final ShapelessRecipe recipe;
|
|
||||||
|
|
||||||
public ShapelessRecipeBasic(ItemStack[] ingredients, ShapelessRecipe recipe) {
|
|
||||||
super(getItemStack(recipe.getOutput()), Arrays.asList(ingredients));
|
|
||||||
|
|
||||||
this.recipe = recipe;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean matches(InventoryCrafting inventory, World world) {
|
|
||||||
return recipe.matches(MCCraftingInventory.get(inventory));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ItemStack getCraftingResult(InventoryCrafting inventory) {
|
|
||||||
if(recipe.getCraftingResult(MCCraftingInventory.get(inventory)) != null) {
|
|
||||||
return getItemStack(recipe.getCraftingResult(MCCraftingInventory.get(inventory))).copy();
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ICraftingRecipe getRecipe() {
|
|
||||||
return recipe;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-38
@@ -1,38 +0,0 @@
|
|||||||
package minetweaker.mc1102.recipes;
|
|
||||||
|
|
||||||
import minetweaker.api.recipes.*;
|
|
||||||
import net.minecraft.inventory.InventoryCrafting;
|
|
||||||
import net.minecraft.item.ItemStack;
|
|
||||||
import net.minecraft.world.World;
|
|
||||||
import net.minecraftforge.oredict.ShapelessOreRecipe;
|
|
||||||
|
|
||||||
import static minetweaker.api.minecraft.MineTweakerMC.getItemStack;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Stan
|
|
||||||
*/
|
|
||||||
public class ShapelessRecipeOre extends ShapelessOreRecipe implements IMTRecipe {
|
|
||||||
|
|
||||||
private final ShapelessRecipe recipe;
|
|
||||||
|
|
||||||
public ShapelessRecipeOre(Object[] ingredients, ShapelessRecipe recipe) {
|
|
||||||
super(getItemStack(recipe.getOutput()), ingredients);
|
|
||||||
|
|
||||||
this.recipe = recipe;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean matches(InventoryCrafting inventory, World world) {
|
|
||||||
return recipe.matches(MCCraftingInventory.get(inventory));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ItemStack getCraftingResult(InventoryCrafting inventory) {
|
|
||||||
return getItemStack(recipe.getCraftingResult(MCCraftingInventory.get(inventory))).copy();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ICraftingRecipe getRecipe() {
|
|
||||||
return recipe;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,186 +0,0 @@
|
|||||||
package minetweaker.mc1102.server;
|
|
||||||
|
|
||||||
import minetweaker.*;
|
|
||||||
import minetweaker.api.minecraft.MineTweakerMC;
|
|
||||||
import minetweaker.api.player.IPlayer;
|
|
||||||
import minetweaker.api.server.*;
|
|
||||||
import minetweaker.mc1102.MineTweakerMod;
|
|
||||||
import minetweaker.mc1102.player.*;
|
|
||||||
import net.minecraft.command.*;
|
|
||||||
import net.minecraft.entity.player.EntityPlayer;
|
|
||||||
import net.minecraft.network.rcon.RConConsoleSource;
|
|
||||||
import net.minecraft.server.MinecraftServer;
|
|
||||||
import net.minecraft.server.management.UserListOps;
|
|
||||||
import net.minecraft.tileentity.CommandBlockBaseLogic;
|
|
||||||
import net.minecraft.util.math.BlockPos;
|
|
||||||
import stanhebben.zenscript.annotations.Optional;
|
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
|
||||||
import java.util.*;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Stan
|
|
||||||
*/
|
|
||||||
public class MCServer extends AbstractServer {
|
|
||||||
|
|
||||||
private final MinecraftServer server;
|
|
||||||
|
|
||||||
public MCServer(MinecraftServer server) {
|
|
||||||
this.server = server;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static IPlayer getPlayer(ICommandSender commandSender) {
|
|
||||||
if(commandSender instanceof EntityPlayer) {
|
|
||||||
return MineTweakerMC.getIPlayer((EntityPlayer) commandSender);
|
|
||||||
} else if(commandSender instanceof RConConsoleSource) {
|
|
||||||
return new RconPlayer(commandSender);
|
|
||||||
} else if(commandSender instanceof CommandBlockBaseLogic) {
|
|
||||||
return new CommandBlockPlayer(commandSender);
|
|
||||||
} else if(commandSender.getName().equals("Server")) {
|
|
||||||
return ServerPlayer.INSTANCE;
|
|
||||||
} else {
|
|
||||||
System.out.println("Unsupported command sender: " + commandSender + " defaulting to server player!");
|
|
||||||
System.out.println("player name: " + commandSender.getName());
|
|
||||||
System.out.println("Please report to mod author if this is incorrect!");
|
|
||||||
return ServerPlayer.INSTANCE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void addCommand(String name, String usage, String[] aliases, ICommandFunction function, @Optional ICommandValidator validator, @Optional ICommandTabCompletion completion) {
|
|
||||||
ICommand command = new MCCommand(name, usage, aliases, function, validator, completion);
|
|
||||||
MineTweakerAPI.apply(new AddCommandAction(command));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isOp(IPlayer player) {
|
|
||||||
if(player == ServerPlayer.INSTANCE)
|
|
||||||
return true;
|
|
||||||
|
|
||||||
UserListOps ops = MineTweakerMod.server.getPlayerList().getOppedPlayers();
|
|
||||||
if(server != null && server.isDedicatedServer() && ops != null) {
|
|
||||||
//TODO figure if this is correct
|
|
||||||
// return ops.func_152690_d() || ops.func_152700_a(player.getName()) != null || player instanceof RconPlayer;
|
|
||||||
return ops.isEmpty() || ops.getGameProfileFromName(player.getName()) != null || player instanceof RconPlayer;
|
|
||||||
} else {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isCommandAdded(String name) {
|
|
||||||
return MineTweakerMod.server.getCommandManager().getCommands().containsKey(name);
|
|
||||||
}
|
|
||||||
|
|
||||||
private class MCCommand implements ICommand {
|
|
||||||
|
|
||||||
private final String name;
|
|
||||||
private final String usage;
|
|
||||||
private final List<String> aliases;
|
|
||||||
private final ICommandFunction function;
|
|
||||||
private final ICommandValidator validator;
|
|
||||||
private final ICommandTabCompletion completion;
|
|
||||||
|
|
||||||
public MCCommand(String name, String usage, String[] aliases, ICommandFunction function, ICommandValidator validator, ICommandTabCompletion completion) {
|
|
||||||
this.name = name;
|
|
||||||
this.usage = usage;
|
|
||||||
this.aliases = Arrays.asList(aliases);
|
|
||||||
this.function = function;
|
|
||||||
this.validator = validator;
|
|
||||||
this.completion = completion;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getName() {
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getUsage(ICommandSender var1) {
|
|
||||||
return usage;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List getAliases() {
|
|
||||||
return aliases;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException {
|
|
||||||
function.execute(args, getPlayer(sender));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean checkPermission(MinecraftServer server, ICommandSender sender) {
|
|
||||||
if(validator == null) {
|
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
return validator.canExecute(getPlayer(sender));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<String> getTabCompletions(MinecraftServer server, ICommandSender sender, String[] args, @Nullable BlockPos pos) {
|
|
||||||
if(completion != null) {
|
|
||||||
return Arrays.asList(completion.getTabCompletionOptions(args, getPlayer(sender)));
|
|
||||||
} else {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isUsernameIndex(String[] var1, int var2) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int compareTo(ICommand o) {
|
|
||||||
return this.getName().compareTo(o.getName());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private class AddCommandAction implements IUndoableAction {
|
|
||||||
|
|
||||||
private final ICommand command;
|
|
||||||
|
|
||||||
public AddCommandAction(ICommand command) {
|
|
||||||
this.command = command;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void apply() {
|
|
||||||
CommandHandler ch = (CommandHandler) MineTweakerMod.server.getCommandManager();
|
|
||||||
if(!ch.getCommands().containsValue(command))
|
|
||||||
ch.registerCommand(command);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean canUndo() {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void undo() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String describe() {
|
|
||||||
CommandHandler ch = (CommandHandler) MineTweakerMod.server.getCommandManager();
|
|
||||||
if(!ch.getCommands().containsValue(command))
|
|
||||||
return "Adding command " + command.getName();
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String describeUndo() {
|
|
||||||
return "tried to remove command: " + command.getName() + " failed. THIS IS NOT AN ERROR!";
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Object getOverrideKey() {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,238 +0,0 @@
|
|||||||
package minetweaker.mc1102.util;
|
|
||||||
|
|
||||||
import minetweaker.MineTweakerAPI;
|
|
||||||
import minetweaker.api.item.WeightedItemStack;
|
|
||||||
import minetweaker.api.minecraft.MineTweakerMC;
|
|
||||||
import net.minecraft.entity.player.EntityPlayer;
|
|
||||||
import net.minecraft.inventory.*;
|
|
||||||
import net.minecraft.item.ItemStack;
|
|
||||||
import net.minecraft.nbt.*;
|
|
||||||
import net.minecraft.server.MinecraftServer;
|
|
||||||
import net.minecraft.util.WeightedRandom;
|
|
||||||
import net.minecraft.util.text.translation.*;
|
|
||||||
import net.minecraftforge.common.ForgeHooks;
|
|
||||||
import net.minecraftforge.oredict.*;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.lang.reflect.*;
|
|
||||||
import java.util.*;
|
|
||||||
import java.util.logging.*;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Common class for all runtime hacks (stuff requiring reflection). It is not
|
|
||||||
* unexpected to have it break with new minecraft versions and may need regular
|
|
||||||
* adjustment - as such, those have been collected here.
|
|
||||||
*
|
|
||||||
* @author Stan Hebben
|
|
||||||
*/
|
|
||||||
public class MineTweakerHacks {
|
|
||||||
|
|
||||||
private static final Field NBTTAGLIST_TAGLIST;
|
|
||||||
private static final Field OREDICTIONARY_IDTOSTACK;
|
|
||||||
private static final Field OREDICTIONARY_IDTOSTACKUN;
|
|
||||||
private static final Field MINECRAFTSERVER_ANVILFILE;
|
|
||||||
private static final Field SHAPEDORERECIPE_WIDTH;
|
|
||||||
private static final Field INVENTORYCRAFTING_EVENTHANDLER;
|
|
||||||
private static final Field SLOTCRAFTING_PLAYER;
|
|
||||||
|
|
||||||
private static final Field SEEDENTRY_SEED;
|
|
||||||
private static final Constructor<? extends WeightedRandom.Item> SEEDENTRY_CONSTRUCTOR;
|
|
||||||
|
|
||||||
static {
|
|
||||||
NBTTAGLIST_TAGLIST = getField(NBTTagList.class, MineTweakerObfuscation.NBTTAGLIST_TAGLIST);
|
|
||||||
OREDICTIONARY_IDTOSTACK = getField(OreDictionary.class, MineTweakerObfuscation.OREDICTIONARY_IDTOSTACK);
|
|
||||||
OREDICTIONARY_IDTOSTACKUN = getField(OreDictionary.class, MineTweakerObfuscation.OREDICTIONARY_IDTOSTACKUN);
|
|
||||||
MINECRAFTSERVER_ANVILFILE = getField(MinecraftServer.class, MineTweakerObfuscation.MINECRAFTSERVER_ANVILFILE);
|
|
||||||
SHAPEDORERECIPE_WIDTH = getField(ShapedOreRecipe.class, "width");
|
|
||||||
INVENTORYCRAFTING_EVENTHANDLER = getField(InventoryCrafting.class, MineTweakerObfuscation.INVENTORYCRAFTING_EVENTHANDLER);
|
|
||||||
SLOTCRAFTING_PLAYER = getField(SlotCrafting.class, MineTweakerObfuscation.SLOTCRAFTING_PLAYER);
|
|
||||||
|
|
||||||
|
|
||||||
Class<? extends WeightedRandom.Item> forgeSeedEntry = null;
|
|
||||||
try {
|
|
||||||
forgeSeedEntry = (Class<? extends WeightedRandom.Item>) Class.forName("net.minecraftforge.common.ForgeHooks$SeedEntry");
|
|
||||||
} catch(ClassNotFoundException ex) {
|
|
||||||
}
|
|
||||||
|
|
||||||
SEEDENTRY_SEED = getField(forgeSeedEntry, "seed");
|
|
||||||
|
|
||||||
Constructor<? extends WeightedRandom.Item> seedEntryConstructor = null;
|
|
||||||
|
|
||||||
try {
|
|
||||||
seedEntryConstructor = forgeSeedEntry.getConstructor(ItemStack.class, int.class);
|
|
||||||
seedEntryConstructor.setAccessible(true);
|
|
||||||
} catch(NoSuchMethodException | SecurityException ex) {
|
|
||||||
Logger.getLogger(MineTweakerHacks.class.getName()).log(Level.SEVERE, null, ex);
|
|
||||||
}
|
|
||||||
|
|
||||||
SEEDENTRY_CONSTRUCTOR = seedEntryConstructor;
|
|
||||||
}
|
|
||||||
|
|
||||||
private MineTweakerHacks() {
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public static List<NBTBase> getTagList(NBTTagList list) {
|
|
||||||
if(NBTTAGLIST_TAGLIST == null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
return (List<NBTBase>) NBTTAGLIST_TAGLIST.get(list);
|
|
||||||
} catch(IllegalArgumentException ex) {
|
|
||||||
return null;
|
|
||||||
} catch(IllegalAccessException ex) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static List getSeeds() {
|
|
||||||
return getPrivateStaticObject(ForgeHooks.class, "seedList");
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public static Map<String, String> getTranslations() {
|
|
||||||
return getPrivateObject(getPrivateStaticObject(I18n.class, "localizedName", "field_74839_a"), "languageList", "field_74816_c");
|
|
||||||
}
|
|
||||||
|
|
||||||
public static List<ArrayList<ItemStack>> getOreIdStacks() {
|
|
||||||
try {
|
|
||||||
return (List<ArrayList<ItemStack>>) OREDICTIONARY_IDTOSTACK.get(null);
|
|
||||||
} catch(IllegalAccessException ex) {
|
|
||||||
MineTweakerAPI.logError("ERROR - could not load ore dictionary stacks!");
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static List<List<ItemStack>> getOreIdStacksUn() {
|
|
||||||
try {
|
|
||||||
return (List<List<ItemStack>>) OREDICTIONARY_IDTOSTACKUN.get(null);
|
|
||||||
} catch(IllegalAccessException ex) {
|
|
||||||
MineTweakerAPI.logError("ERROR - could not load ore dictionary stacks!");
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static File getAnvilFile(MinecraftServer server) {
|
|
||||||
try {
|
|
||||||
return (File) MINECRAFTSERVER_ANVILFILE.get(server);
|
|
||||||
} catch(IllegalAccessException ex) {
|
|
||||||
MineTweakerAPI.logError("could not load anvil file!");
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static File getWorldDirectory(MinecraftServer server) {
|
|
||||||
if(server.isDedicatedServer()) {
|
|
||||||
return server.getFile("world");
|
|
||||||
} else {
|
|
||||||
File worldsDir = getAnvilFile(server);
|
|
||||||
if(worldsDir == null)
|
|
||||||
return null;
|
|
||||||
|
|
||||||
return new File(worldsDir, server.getFolderName());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static int getShapedOreRecipeWidth(ShapedOreRecipe recipe) {
|
|
||||||
try {
|
|
||||||
return SHAPEDORERECIPE_WIDTH.getInt(recipe);
|
|
||||||
} catch(IllegalAccessException ex) {
|
|
||||||
MineTweakerAPI.logError("could not load anvil file!");
|
|
||||||
return 3;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Container getCraftingContainer(InventoryCrafting inventory) {
|
|
||||||
try {
|
|
||||||
return (Container) INVENTORYCRAFTING_EVENTHANDLER.get(inventory);
|
|
||||||
} catch(IllegalAccessException ex) {
|
|
||||||
MineTweakerAPI.logError("could not get inventory eventhandler");
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static EntityPlayer getCraftingSlotPlayer(SlotCrafting slot) {
|
|
||||||
try {
|
|
||||||
return (EntityPlayer) SLOTCRAFTING_PLAYER.get(slot);
|
|
||||||
} catch(IllegalAccessException ex) {
|
|
||||||
MineTweakerAPI.logError("could not get inventory eventhandler");
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static LanguageMap getStringTranslateInstance() {
|
|
||||||
try {
|
|
||||||
Field field = getField(LanguageMap.class, MineTweakerObfuscation.LANGUAGEMAP_INSTANCE);
|
|
||||||
return (LanguageMap) field.get(null);
|
|
||||||
} catch(IllegalAccessException ex) {
|
|
||||||
MineTweakerAPI.logError("could not get LanguageMap");
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static ItemStack getSeedEntrySeed(Object entry) {
|
|
||||||
try {
|
|
||||||
return (ItemStack) SEEDENTRY_SEED.get(entry);
|
|
||||||
} catch(IllegalAccessException ex) {
|
|
||||||
MineTweakerAPI.logError("could not get SeedEntry seed");
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public static WeightedRandom.Item constructSeedEntry(WeightedItemStack stack) {
|
|
||||||
try {
|
|
||||||
return SEEDENTRY_CONSTRUCTOR.newInstance(MineTweakerMC.getItemStack(stack.getStack()), (int) stack.getChance());
|
|
||||||
} catch(InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) {
|
|
||||||
MineTweakerAPI.logError("could not construct SeedEntry");
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static <T> T getPrivateStaticObject(Class<?> cls, String... names) {
|
|
||||||
for(String name : names) {
|
|
||||||
try {
|
|
||||||
Field field = cls.getDeclaredField(name);
|
|
||||||
field.setAccessible(true);
|
|
||||||
return (T) field.get(null);
|
|
||||||
} catch(NoSuchFieldException | SecurityException | IllegalAccessException ignored) {
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static <T> T getPrivateObject(Object object, String... names) {
|
|
||||||
Class<?> cls = object.getClass();
|
|
||||||
for(String name : names) {
|
|
||||||
try {
|
|
||||||
Field field = cls.getDeclaredField(name);
|
|
||||||
field.setAccessible(true);
|
|
||||||
return (T) field.get(object);
|
|
||||||
} catch(NoSuchFieldException | SecurityException | IllegalAccessException ignored) {
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
// #######################
|
|
||||||
// ### Private Methods ###
|
|
||||||
// #######################
|
|
||||||
|
|
||||||
private static Field getField(Class cls, String... names) {
|
|
||||||
for(String name : names) {
|
|
||||||
try {
|
|
||||||
Field field = cls.getDeclaredField(name);
|
|
||||||
field.setAccessible(true);
|
|
||||||
return field;
|
|
||||||
} catch(NoSuchFieldException | SecurityException ignored) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-19
@@ -1,19 +0,0 @@
|
|||||||
package minetweaker.mc1102.util;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Stanneke
|
|
||||||
*/
|
|
||||||
public class MineTweakerObfuscation {
|
|
||||||
|
|
||||||
public static final String[] NBTTAGLIST_TAGLIST = {"tagList", "field_74747_a"};
|
|
||||||
public static final String[] CRAFTINGMANAGER_RECIPES = {"recipes", "field_77597_b"};
|
|
||||||
public static final String[] OREDICTIONARY_IDTOSTACK = {"idToStack"};
|
|
||||||
public static final String[] OREDICTIONARY_IDTOSTACKUN = {"idToStackUn"};
|
|
||||||
public static final String[] MINECRAFTSERVER_ANVILFILE = {"anvilFile", "field_71308_o"};
|
|
||||||
public static final String[] INVENTORYCRAFTING_EVENTHANDLER = {"eventHandler", "field_70465_c"};
|
|
||||||
public static final String[] SLOTCRAFTING_PLAYER = {"player", "field_75238_b"};
|
|
||||||
public static final String[] LANGUAGEMAP_INSTANCE = {"instance", "field_74817_a"};
|
|
||||||
|
|
||||||
private MineTweakerObfuscation() {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-193
@@ -1,193 +0,0 @@
|
|||||||
///*
|
|
||||||
// * To change this license header, choose License Headers in Project Properties.
|
|
||||||
// * To change this template file, choose Tools | Templates
|
|
||||||
// * and open the template in the editor.
|
|
||||||
// */
|
|
||||||
//
|
|
||||||
//package minetweaker.mc1102.vanilla;
|
|
||||||
//
|
|
||||||
//import minetweaker.IUndoableAction;
|
|
||||||
//import minetweaker.MineTweakerAPI;
|
|
||||||
//import minetweaker.api.item.IIngredient;
|
|
||||||
//import minetweaker.api.item.WeightedItemStack;
|
|
||||||
//import minetweaker.api.minecraft.MineTweakerMC;
|
|
||||||
//import minetweaker.api.vanilla.ILootRegistry;
|
|
||||||
//import minetweaker.api.vanilla.LootEntry;
|
|
||||||
//import minetweaker.mc1102.util.MineTweakerHacks;
|
|
||||||
//import net.minecraft.item.ItemStack;
|
|
||||||
//import net.minecraft.world.storage.loot.LootEntryItem;
|
|
||||||
//import net.minecraft.world.storage.loot.functions.LootFunction;
|
|
||||||
//import net.minecraft.world.storage.loot.functions.LootFunctionManager;
|
|
||||||
//
|
|
||||||
//import java.util.*;
|
|
||||||
//
|
|
||||||
///**
|
|
||||||
// * @author Stan
|
|
||||||
// */
|
|
||||||
//public class MCLootRegistry implements ILootRegistry{
|
|
||||||
// private static final Map<String, List<ItemStack>> LOOT = new HashMap<String, List<ItemStack>>();
|
|
||||||
//
|
|
||||||
// @Override
|
|
||||||
// public void addChestLoot(String type, WeightedItemStack item){
|
|
||||||
// LootEntryItem content = new LootEntryItem(MineTweakerMC.getItemStack(item.getStack()).getItem(), 1, 1, (int) item.getChance());
|
|
||||||
// WeightedItemStack sta = new WeightedItemStack();
|
|
||||||
// MineTweakerAPI.apply(new AddLootAction(type, content));
|
|
||||||
// LootFunctionManager.getSerializerFor()
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// //addEntry(new LootEntryItem(ITEM, WEIGHT, QUALITY, FUNCTIONS, CONDITIONS, NAME));
|
|
||||||
// @Override
|
|
||||||
// public void addChestLoot(String type, WeightedItemStack item, int min, int max){
|
|
||||||
// WeightedRandomChestContent content = new WeightedRandomChestContent(MineTweakerMC.getItemStack(item.getStack()), min, max, (int) item.getChance());
|
|
||||||
// MineTweakerAPI.apply(new AddLootAction(type, content));
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// @Override
|
|
||||||
// public void removeChestLoot(String type, IIngredient pattern){
|
|
||||||
// MineTweakerAPI.apply(new RemoveLootAction(type, pattern));
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// @Override
|
|
||||||
// public List<LootEntry> getLoot(String type){
|
|
||||||
// ChestGenHooks recipe = LOOT.get(type);
|
|
||||||
// List<WeightedRandomChestContent> contents = MineTweakerHacks.getPrivateObject(recipe, "contents");
|
|
||||||
//
|
|
||||||
// List<LootEntry> results = new ArrayList<LootEntry>();
|
|
||||||
// for(WeightedRandomChestContent content : contents){
|
|
||||||
// results.add(new LootEntry(new WeightedItemStack(MineTweakerMC.getIItemStack(content.theItemId), content.itemWeight), content.theMinimumChanceToGenerateItem, content.theMaximumChanceToGenerateItem));
|
|
||||||
// }
|
|
||||||
// return results;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// @Override
|
|
||||||
// public List<String> getLootTypes(){
|
|
||||||
// Set<String> keys = LOOT.keySet();
|
|
||||||
// List<String> keyList = new ArrayList<String>();
|
|
||||||
// keyList.addAll(keys);
|
|
||||||
// return keyList;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// // ######################
|
|
||||||
// // ### Action Classes ###
|
|
||||||
// // ######################
|
|
||||||
//
|
|
||||||
// /**
|
|
||||||
// * Ported from ModTweaker.
|
|
||||||
// *
|
|
||||||
// * @author JoshieJack
|
|
||||||
// */
|
|
||||||
// private static class AddLootAction implements IUndoableAction{
|
|
||||||
// private final String chest;
|
|
||||||
// private final WeightedRandomChestContent content;
|
|
||||||
//
|
|
||||||
// public AddLootAction(String chest, WeightedRandomChestContent content){
|
|
||||||
// this.chest = chest;
|
|
||||||
// this.content = content;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// @Override
|
|
||||||
// public void apply(){
|
|
||||||
// ChestGenHooks recipe = LOOT.get(chest);
|
|
||||||
// List<WeightedRandomChestContent> contents = MineTweakerHacks.getPrivateObject(recipe, "contents");
|
|
||||||
//
|
|
||||||
// contents.add(content);
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// @Override
|
|
||||||
// public boolean canUndo(){
|
|
||||||
// return true;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// @Override
|
|
||||||
// public void undo(){
|
|
||||||
// ChestGenHooks recipe = LOOT.get(chest);
|
|
||||||
// List<WeightedRandomChestContent> contents = MineTweakerHacks.getPrivateObject(recipe, "contents");
|
|
||||||
//
|
|
||||||
// contents.remove(content);
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// public String getRecipeInfo(){
|
|
||||||
// return content.theItemId.getDisplayName();
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// @Override
|
|
||||||
// public String describe(){
|
|
||||||
// return "Adding chest loot " + content.theItemId.getDisplayName() + " to loot class " + chest;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// @Override
|
|
||||||
// public String describeUndo(){
|
|
||||||
// return "Removing chest loot " + content.theItemId.getDisplayName() + " from loot class " + chest;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// @Override
|
|
||||||
// public Object getOverrideKey(){
|
|
||||||
// return null;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// /**
|
|
||||||
// * Ported from ModTweaker.
|
|
||||||
// *
|
|
||||||
// * @author JoshieJack
|
|
||||||
// */
|
|
||||||
// private static class RemoveLootAction implements IUndoableAction{
|
|
||||||
// private final String chest;
|
|
||||||
// private final IIngredient pattern;
|
|
||||||
// private final List<WeightedRandomChestContent> removed;
|
|
||||||
//
|
|
||||||
// public RemoveLootAction(String chest, IIngredient pattern){
|
|
||||||
// this.chest = chest;
|
|
||||||
// this.pattern = pattern;
|
|
||||||
// removed = new ArrayList<WeightedRandomChestContent>();
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// @Override
|
|
||||||
// public void apply(){
|
|
||||||
// removed.clear();
|
|
||||||
//
|
|
||||||
// ChestGenHooks recipe = LOOT.get(chest);
|
|
||||||
// List<WeightedRandomChestContent> contents = MineTweakerHacks.getPrivateObject(recipe, "contents");
|
|
||||||
//
|
|
||||||
// for(WeightedRandomChestContent r : contents){
|
|
||||||
// if(pattern.matches(MineTweakerMC.getIItemStack(r.theItemId))){
|
|
||||||
// removed.add(r);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// for(WeightedRandomChestContent r : removed){
|
|
||||||
// contents.remove(r);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// @Override
|
|
||||||
// public boolean canUndo(){
|
|
||||||
// return true;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// @Override
|
|
||||||
// public void undo(){
|
|
||||||
// ChestGenHooks recipe = LOOT.get(chest);
|
|
||||||
// List<WeightedRandomChestContent> contents = MineTweakerHacks.getPrivateObject(recipe, "contents");
|
|
||||||
//
|
|
||||||
// for(WeightedRandomChestContent entry : removed){
|
|
||||||
// contents.add(entry);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// @Override
|
|
||||||
// public String describe(){
|
|
||||||
// return "Removing chest loot " + pattern + " for loot type " + chest;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// @Override
|
|
||||||
// public String describeUndo(){
|
|
||||||
// return "Restoring chest loot " + pattern + " for loot type " + chest + " (" + removed.size() + " entries)";
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// @Override
|
|
||||||
// public Object getOverrideKey(){
|
|
||||||
// return null;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
//}
|
|
||||||
@@ -1,22 +0,0 @@
|
|||||||
package minetweaker.mc1102.vanilla;
|
|
||||||
|
|
||||||
import minetweaker.api.vanilla.*;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Stan
|
|
||||||
*/
|
|
||||||
public class MCVanilla implements IVanilla {
|
|
||||||
|
|
||||||
// private final MCLootRegistry lootRegistry = new MCLootRegistry();
|
|
||||||
private final MCSeedRegistry seedRegistry = new MCSeedRegistry();
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ILootRegistry getLoot() {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ISeedRegistry getSeeds() {
|
|
||||||
return seedRegistry;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,21 +0,0 @@
|
|||||||
package minetweaker.mc1102.world;
|
|
||||||
|
|
||||||
import minetweaker.api.world.IBiome;
|
|
||||||
import net.minecraft.world.biome.Biome;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Stan
|
|
||||||
*/
|
|
||||||
public class MCBiome implements IBiome {
|
|
||||||
|
|
||||||
private final Biome biome;
|
|
||||||
|
|
||||||
public MCBiome(Biome biome) {
|
|
||||||
this.biome = biome;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getName() {
|
|
||||||
return biome.getBiomeName();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,18 +0,0 @@
|
|||||||
[
|
|
||||||
{
|
|
||||||
"modid": "MineTweaker3",
|
|
||||||
"name": "MineTweaker 3",
|
|
||||||
"version": "${version}",
|
|
||||||
"mcversion": "${mcversion}",
|
|
||||||
"description": "Customize your minecraft experience!",
|
|
||||||
"credits": "Created By Stan Hebben",
|
|
||||||
"logoFile": "assets/minetweaker/logo.png",
|
|
||||||
"url": "http://minetweaker3.powerofbytes.com",
|
|
||||||
"authorList": [
|
|
||||||
"Stan Hebben"
|
|
||||||
],
|
|
||||||
"parent": "",
|
|
||||||
"screenshots": [],
|
|
||||||
"dependencies": []
|
|
||||||
}
|
|
||||||
]
|
|
||||||
@@ -1,49 +0,0 @@
|
|||||||
import minetweaker.tasks.RegisterZenClassesTask;
|
|
||||||
|
|
||||||
|
|
||||||
buildscript {
|
|
||||||
repositories {
|
|
||||||
mavenCentral()
|
|
||||||
maven {
|
|
||||||
name = "forge"
|
|
||||||
url = "http://files.minecraftforge.net/maven"
|
|
||||||
}
|
|
||||||
maven {
|
|
||||||
name = "sonatype"
|
|
||||||
url = "https://oss.sonatype.org/content/repositories/snapshots/"
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
dependencies {
|
|
||||||
classpath 'net.minecraftforge.gradle:ForgeGradle:2.2-SNAPSHOT'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
apply plugin: 'net.minecraftforge.gradle.forge'
|
|
||||||
|
|
||||||
sourceCompatibility = JavaVersion.VERSION_1_8
|
|
||||||
targetCompatibility = JavaVersion.VERSION_1_8
|
|
||||||
|
|
||||||
version = "1.10.2-" + ext.mineTweakerVersion
|
|
||||||
archivesBaseName = project.projectDir.name
|
|
||||||
|
|
||||||
minecraft {
|
|
||||||
version = forgeVersion1102
|
|
||||||
runDir = "eclipse"
|
|
||||||
mappings = "stable_29"
|
|
||||||
useDepAts = true
|
|
||||||
}
|
|
||||||
|
|
||||||
dependencies {
|
|
||||||
compile project(':ZenScript')
|
|
||||||
compile project(':MineTweaker3-API')
|
|
||||||
compile project(':MineTweaker3-MC1102-Main')
|
|
||||||
compile files('libs/industrialcraft-2-2.5.63-ex19-dev.jar')
|
|
||||||
}
|
|
||||||
|
|
||||||
task makeRegistry(type: RegisterZenClassesTask) {
|
|
||||||
inputDir = file('build/classes/main')
|
|
||||||
outputDir = file('build/classes/main')
|
|
||||||
className = 'minetweaker.mods.ic2.ClassRegistry'
|
|
||||||
}
|
|
||||||
|
|
||||||
tasks.jar.dependsOn(makeRegistry)
|
|
||||||
Loaded 100 of 607 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user