diff --git a/.gitignore b/.gitignore index fc5b5b3..2d13044 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,24 @@ +# gradle + +.gradle/ +build/ +out/ +bin/ + + +# idea + +.idea/ +*.iml +*.ipr +*.iws + +#vscode +.vscode/ +.project +.classpath + + # eclipse bin *.launch @@ -7,17 +28,5 @@ bin .project .DS_Store -# idea -out -*.ipr -*.iws -*.iml -.idea - -# gradle -build -.gradle - -# other -eclipse -run +# fabric +run/ \ No newline at end of file diff --git a/LICENSE b/LICENSE index 65c5ca8..0e259d4 100644 --- a/LICENSE +++ b/LICENSE @@ -1,165 +1,121 @@ - GNU LESSER GENERAL PUBLIC LICENSE - Version 3, 29 June 2007 +Creative Commons Legal Code - Copyright (C) 2007 Free Software Foundation, Inc. - Everyone is permitted to copy and distribute verbatim copies - of this license document, but changing it is not allowed. +CC0 1.0 Universal + CREATIVE COMMONS CORPORATION IS NOT A LAW FIRM AND DOES NOT PROVIDE + LEGAL SERVICES. DISTRIBUTION OF THIS DOCUMENT DOES NOT CREATE AN + ATTORNEY-CLIENT RELATIONSHIP. CREATIVE COMMONS PROVIDES THIS + INFORMATION ON AN "AS-IS" BASIS. CREATIVE COMMONS MAKES NO WARRANTIES + REGARDING THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS + PROVIDED HEREUNDER, AND DISCLAIMS LIABILITY FOR DAMAGES RESULTING FROM + THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS PROVIDED + HEREUNDER. - This version of the GNU Lesser General Public License incorporates -the terms and conditions of version 3 of the GNU General Public -License, supplemented by the additional permissions listed below. +Statement of Purpose - 0. Additional Definitions. +The laws of most jurisdictions throughout the world automatically confer +exclusive Copyright and Related Rights (defined below) upon the creator +and subsequent owner(s) (each and all, an "owner") of an original work of +authorship and/or a database (each, a "Work"). - As used herein, "this License" refers to version 3 of the GNU Lesser -General Public License, and the "GNU GPL" refers to version 3 of the GNU -General Public License. +Certain owners wish to permanently relinquish those rights to a Work for +the purpose of contributing to a commons of creative, cultural and +scientific works ("Commons") that the public can reliably and without fear +of later claims of infringement build upon, modify, incorporate in other +works, reuse and redistribute as freely as possible in any form whatsoever +and for any purposes, including without limitation commercial purposes. +These owners may contribute to the Commons to promote the ideal of a free +culture and the further production of creative, cultural and scientific +works, or to gain reputation or greater distribution for their Work in +part through the use and efforts of others. - "The Library" refers to a covered work governed by this License, -other than an Application or a Combined Work as defined below. +For these and/or other purposes and motivations, and without any +expectation of additional consideration or compensation, the person +associating CC0 with a Work (the "Affirmer"), to the extent that he or she +is an owner of Copyright and Related Rights in the Work, voluntarily +elects to apply CC0 to the Work and publicly distribute the Work under its +terms, with knowledge of his or her Copyright and Related Rights in the +Work and the meaning and intended legal effect of CC0 on those rights. - An "Application" is any work that makes use of an interface provided -by the Library, but which is not otherwise based on the Library. -Defining a subclass of a class defined by the Library is deemed a mode -of using an interface provided by the Library. +1. Copyright and Related Rights. A Work made available under CC0 may be +protected by copyright and related or neighboring rights ("Copyright and +Related Rights"). Copyright and Related Rights include, but are not +limited to, the following: - A "Combined Work" is a work produced by combining or linking an -Application with the Library. The particular version of the Library -with which the Combined Work was made is also called the "Linked -Version". + i. the right to reproduce, adapt, distribute, perform, display, + communicate, and translate a Work; + ii. moral rights retained by the original author(s) and/or performer(s); +iii. publicity and privacy rights pertaining to a person's image or + likeness depicted in a Work; + iv. rights protecting against unfair competition in regards to a Work, + subject to the limitations in paragraph 4(a), below; + v. rights protecting the extraction, dissemination, use and reuse of data + in a Work; + vi. database rights (such as those arising under Directive 96/9/EC of the + European Parliament and of the Council of 11 March 1996 on the legal + protection of databases, and under any national implementation + thereof, including any amended or successor version of such + directive); and +vii. other similar, equivalent or corresponding rights throughout the + world based on applicable law or treaty, and any national + implementations thereof. - The "Minimal Corresponding Source" for a Combined Work means the -Corresponding Source for the Combined Work, excluding any source code -for portions of the Combined Work that, considered in isolation, are -based on the Application, and not on the Linked Version. +2. Waiver. To the greatest extent permitted by, but not in contravention +of, applicable law, Affirmer hereby overtly, fully, permanently, +irrevocably and unconditionally waives, abandons, and surrenders all of +Affirmer's Copyright and Related Rights and associated claims and causes +of action, whether now known or unknown (including existing as well as +future claims and causes of action), in the Work (i) in all territories +worldwide, (ii) for the maximum duration provided by applicable law or +treaty (including future time extensions), (iii) in any current or future +medium and for any number of copies, and (iv) for any purpose whatsoever, +including without limitation commercial, advertising or promotional +purposes (the "Waiver"). Affirmer makes the Waiver for the benefit of each +member of the public at large and to the detriment of Affirmer's heirs and +successors, fully intending that such Waiver shall not be subject to +revocation, rescission, cancellation, termination, or any other legal or +equitable action to disrupt the quiet enjoyment of the Work by the public +as contemplated by Affirmer's express Statement of Purpose. - The "Corresponding Application Code" for a Combined Work means the -object code and/or source code for the Application, including any data -and utility programs needed for reproducing the Combined Work from the -Application, but excluding the System Libraries of the Combined Work. +3. Public License Fallback. Should any part of the Waiver for any reason +be judged legally invalid or ineffective under applicable law, then the +Waiver shall be preserved to the maximum extent permitted taking into +account Affirmer's express Statement of Purpose. In addition, to the +extent the Waiver is so judged Affirmer hereby grants to each affected +person a royalty-free, non transferable, non sublicensable, non exclusive, +irrevocable and unconditional license to exercise Affirmer's Copyright and +Related Rights in the Work (i) in all territories worldwide, (ii) for the +maximum duration provided by applicable law or treaty (including future +time extensions), (iii) in any current or future medium and for any number +of copies, and (iv) for any purpose whatsoever, including without +limitation commercial, advertising or promotional purposes (the +"License"). The License shall be deemed effective as of the date CC0 was +applied by Affirmer to the Work. Should any part of the License for any +reason be judged legally invalid or ineffective under applicable law, such +partial invalidity or ineffectiveness shall not invalidate the remainder +of the License, and in such case Affirmer hereby affirms that he or she +will not (i) exercise any of his or her remaining Copyright and Related +Rights in the Work or (ii) assert any associated claims and causes of +action with respect to the Work, in either case contrary to Affirmer's +express Statement of Purpose. - 1. Exception to Section 3 of the GNU GPL. +4. Limitations and Disclaimers. - You may convey a covered work under sections 3 and 4 of this License -without being bound by section 3 of the GNU GPL. - - 2. Conveying Modified Versions. - - If you modify a copy of the Library, and, in your modifications, a -facility refers to a function or data to be supplied by an Application -that uses the facility (other than as an argument passed when the -facility is invoked), then you may convey a copy of the modified -version: - - a) under this License, provided that you make a good faith effort to - ensure that, in the event an Application does not supply the - function or data, the facility still operates, and performs - whatever part of its purpose remains meaningful, or - - b) under the GNU GPL, with none of the additional permissions of - this License applicable to that copy. - - 3. Object Code Incorporating Material from Library Header Files. - - The object code form of an Application may incorporate material from -a header file that is part of the Library. You may convey such object -code under terms of your choice, provided that, if the incorporated -material is not limited to numerical parameters, data structure -layouts and accessors, or small macros, inline functions and templates -(ten or fewer lines in length), you do both of the following: - - a) Give prominent notice with each copy of the object code that the - Library is used in it and that the Library and its use are - covered by this License. - - b) Accompany the object code with a copy of the GNU GPL and this license - document. - - 4. Combined Works. - - You may convey a Combined Work under terms of your choice that, -taken together, effectively do not restrict modification of the -portions of the Library contained in the Combined Work and reverse -engineering for debugging such modifications, if you also do each of -the following: - - a) Give prominent notice with each copy of the Combined Work that - the Library is used in it and that the Library and its use are - covered by this License. - - b) Accompany the Combined Work with a copy of the GNU GPL and this license - document. - - c) For a Combined Work that displays copyright notices during - execution, include the copyright notice for the Library among - these notices, as well as a reference directing the user to the - copies of the GNU GPL and this license document. - - d) Do one of the following: - - 0) Convey the Minimal Corresponding Source under the terms of this - License, and the Corresponding Application Code in a form - suitable for, and under terms that permit, the user to - recombine or relink the Application with a modified version of - the Linked Version to produce a modified Combined Work, in the - manner specified by section 6 of the GNU GPL for conveying - Corresponding Source. - - 1) Use a suitable shared library mechanism for linking with the - Library. A suitable mechanism is one that (a) uses at run time - a copy of the Library already present on the user's computer - system, and (b) will operate properly with a modified version - of the Library that is interface-compatible with the Linked - Version. - - e) Provide Installation Information, but only if you would otherwise - be required to provide such information under section 6 of the - GNU GPL, and only to the extent that such information is - necessary to install and execute a modified version of the - Combined Work produced by recombining or relinking the - Application with a modified version of the Linked Version. (If - you use option 4d0, the Installation Information must accompany - the Minimal Corresponding Source and Corresponding Application - Code. If you use option 4d1, you must provide the Installation - Information in the manner specified by section 6 of the GNU GPL - for conveying Corresponding Source.) - - 5. Combined Libraries. - - You may place library facilities that are a work based on the -Library side by side in a single library together with other library -facilities that are not Applications and are not covered by this -License, and convey such a combined library under terms of your -choice, if you do both of the following: - - a) Accompany the combined library with a copy of the same work based - on the Library, uncombined with any other library facilities, - conveyed under the terms of this License. - - b) Give prominent notice with the combined library that part of it - is a work based on the Library, and explaining where to find the - accompanying uncombined form of the same work. - - 6. Revised Versions of the GNU Lesser General Public License. - - The Free Software Foundation may publish revised and/or new versions -of the GNU Lesser General Public License from time to time. Such new -versions will be similar in spirit to the present version, but may -differ in detail to address new problems or concerns. - - Each version is given a distinguishing version number. If the -Library as you received it specifies that a certain numbered version -of the GNU Lesser General Public License "or any later version" -applies to it, you have the option of following the terms and -conditions either of that published version or of any later version -published by the Free Software Foundation. If the Library as you -received it does not specify a version number of the GNU Lesser -General Public License, you may choose any version of the GNU Lesser -General Public License ever published by the Free Software Foundation. - - If the Library as you received it specifies that a proxy can decide -whether future versions of the GNU Lesser General Public License shall -apply, that proxy's public statement of acceptance of any version is -permanent authorization for you to choose that version for the -Library. + a. No trademark or patent rights held by Affirmer are waived, abandoned, + surrendered, licensed or otherwise affected by this document. + b. Affirmer offers the Work as-is and makes no representations or + warranties of any kind concerning the Work, express, implied, + statutory or otherwise, including without limitation warranties of + title, merchantability, fitness for a particular purpose, non + infringement, or the absence of latent or other defects, accuracy, or + the present or absence of errors, whether or not discoverable, all to + the greatest extent permissible under applicable law. + c. Affirmer disclaims responsibility for clearing rights of other persons + that may apply to the Work or any use thereof, including without + limitation any person's Copyright and Related Rights in the Work. + Further, Affirmer disclaims responsibility for obtaining any necessary + consents, permissions or other rights required for any use of the + Work. + d. Affirmer understands and acknowledges that Creative Commons is not a + party to this document and has no duty or obligation with respect to + this CC0 or use of the Work. diff --git a/README.md b/README.md index aea4cfe..10fc90e 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,16 @@ +# Fabric Example Mod -# Carry On [![](http://cf.way2muchnoise.eu/carry-on.svg)](https://minecraft.curseforge.com/projects/carry-on) [![](http://cf.way2muchnoise.eu/versions/carry-on.svg)](https://minecraft.curseforge.com/projects/carry-on) +## Setup + +1. Edit build.gradle and mod.json to suit your needs. + * The "mixins" object can be removed from mod.json if you do not need to use mixins. + * Please replace all occurences of "modid" with your own mod ID - sometimes, a different string may also suffice. +2. Run the following command: + +``` +./gradlew idea +``` + +## License + +This template is available under the CC0 license. Feel free to learn from it and incorporate it in your own projects. diff --git a/build.bat b/build.bat deleted file mode 100644 index 9691829..0000000 --- a/build.bat +++ /dev/null @@ -1,2 +0,0 @@ -gradlew build -pause \ No newline at end of file diff --git a/build.gradle b/build.gradle index 0dc116a..3af29ad 100644 --- a/build.gradle +++ b/build.gradle @@ -1,70 +1,20 @@ -buildscript { - repositories { - jcenter() - maven { url = "http://files.minecraftforge.net/maven" } - - } - dependencies { - classpath 'net.minecraftforge.gradle:ForgeGradle:2.2-SNAPSHOT' - } +plugins { + id 'fabric-loom' version '0.1.0-SNAPSHOT' } +sourceCompatibility = 1.8 +targetCompatibility = 1.8 - - -apply plugin: 'net.minecraftforge.gradle.forge' - -version = "1.0" -group = "tschipp.carryon" -archivesBaseName = "carryon" - -sourceCompatibility = targetCompatibility = '1.8' -compileJava { - sourceCompatibility = targetCompatibility = '1.8' -} +archivesBaseName = "CarryOn" +version = "1.0.0" minecraft { - version = "1.11.2-13.20.1.2386" - runDir = "run" - - mappings = "snapshot_20161220" - // makeObfSourceJar = false // an Srg named sources jar is made by default. uncomment this to disable. } -repositories { - - maven { url 'http://maven.epoxide.org' } - - ivy { - name "LatMod" - artifactPattern "http://mods.latmod.com/[module]/[revision]/[module]-[revision](-[classifier]).[ext]" - } -} - - - dependencies { - - deobfCompile "net.darkhax.gamestages:GameStages-1.11.2:1.0.11" - - deobfCompile "LatMod:FTBUtilities:1.1x-3.6.5" - deobfCompile "LatMod:FTBLib:1.1x-3.6.5" + minecraft "com.mojang:minecraft:18w50a" + mappings "net.fabricmc:yarn:18w50a.33" + modCompile "net.fabricmc:fabric-loader:0.2.0.70" - -} - -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' - } + modCompile "net.fabricmc:fabric:0.1.1.53" } diff --git a/carryon-scripts b/carryon-scripts deleted file mode 100644 index e69de29..0000000 diff --git a/gradle.properties b/gradle.properties deleted file mode 100644 index e9b9fd5..0000000 --- a/gradle.properties +++ /dev/null @@ -1,3 +0,0 @@ -# Sets default memory used for gradle commands. Can be overridden by user or command line properties. -# This is required to provide enough memory for the Minecraft decompilation process. -org.gradle.jvmargs=-Xmx3G diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index 30d399d..deedc7f 100644 Binary files a/gradle/wrapper/gradle-wrapper.jar and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index e18cba7..b9e1d2c 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Mon Sep 14 12:28:28 PDT 2015 +#Mon Aug 22 17:36:22 EDT 2016 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-2.14-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.2-bin.zip diff --git a/gradlew b/gradlew index 91a7e26..9aa616c 100644 --- a/gradlew +++ b/gradlew @@ -6,12 +6,30 @@ ## ############################################################################## -# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -DEFAULT_JVM_OPTS="" +# Attempt to set APP_HOME +# Resolve links: $0 may be a link +PRG="$0" +# Need this for relative symlinks. +while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG=`dirname "$PRG"`"/$link" + fi +done +SAVED="`pwd`" +cd "`dirname \"$PRG\"`/" >/dev/null +APP_HOME="`pwd -P`" +cd "$SAVED" >/dev/null APP_NAME="Gradle" APP_BASE_NAME=`basename "$0"` +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS="" + # Use the maximum available, or set MAX_FD != -1 to use that value. MAX_FD="maximum" @@ -30,6 +48,7 @@ die ( ) { cygwin=false msys=false darwin=false +nonstop=false case "`uname`" in CYGWIN* ) cygwin=true @@ -40,31 +59,11 @@ case "`uname`" in MINGW* ) msys=true ;; + NONSTOP* ) + nonstop=true + ;; esac -# For Cygwin, ensure paths are in UNIX format before anything is touched. -if $cygwin ; then - [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"` -fi - -# Attempt to set APP_HOME -# Resolve links: $0 may be a link -PRG="$0" -# Need this for relative symlinks. -while [ -h "$PRG" ] ; do - ls=`ls -ld "$PRG"` - link=`expr "$ls" : '.*-> \(.*\)$'` - if expr "$link" : '/.*' > /dev/null; then - PRG="$link" - else - PRG=`dirname "$PRG"`"/$link" - fi -done -SAVED="`pwd`" -cd "`dirname \"$PRG\"`/" >&- -APP_HOME="`pwd -P`" -cd "$SAVED" >&- - CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar # Determine the Java command to use to start the JVM. @@ -90,7 +89,7 @@ location of your Java installation." fi # Increase the maximum file descriptors if we can. -if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then +if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then MAX_FD_LIMIT=`ulimit -H -n` if [ $? -eq 0 ] ; then if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then @@ -114,6 +113,7 @@ fi if $cygwin ; then APP_HOME=`cygpath --path --mixed "$APP_HOME"` CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` + JAVACMD=`cygpath --unix "$JAVACMD"` # We build the pattern for arguments to be converted via cygpath ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` @@ -161,4 +161,9 @@ function splitJvmOpts() { eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" +# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong +if [[ "$(uname)" == "Darwin" ]] && [[ "$HOME" == "$PWD" ]]; then + cd "$(dirname "$0")" +fi + exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" diff --git a/gradlew.bat b/gradlew.bat index 8a0b282..f955316 100644 --- a/gradlew.bat +++ b/gradlew.bat @@ -8,14 +8,14 @@ @rem Set local scope for the variables with windows NT shell if "%OS%"=="Windows_NT" setlocal -@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -set DEFAULT_JVM_OPTS= - set DIRNAME=%~dp0 if "%DIRNAME%" == "" set DIRNAME=. set APP_BASE_NAME=%~n0 set APP_HOME=%DIRNAME% +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS= + @rem Find java.exe if defined JAVA_HOME goto findJavaFromJavaHome @@ -46,10 +46,9 @@ echo location of your Java installation. goto fail :init -@rem Get command-line arguments, handling Windowz variants +@rem Get command-line arguments, handling Windows variants if not "%OS%" == "Windows_NT" goto win9xME_args -if "%@eval[2+2]" == "4" goto 4NT_args :win9xME_args @rem Slurp the command line arguments. @@ -60,11 +59,6 @@ set _SKIP=2 if "x%~1" == "x" goto execute set CMD_LINE_ARGS=%* -goto execute - -:4NT_args -@rem Get arguments from the 4NT Shell from JP Software -set CMD_LINE_ARGS=%$ :execute @rem Setup the command line diff --git a/settings.gradle b/settings.gradle new file mode 100644 index 0000000..683b201 --- /dev/null +++ b/settings.gradle @@ -0,0 +1,10 @@ +pluginManagement { + repositories { + jcenter() + maven { + name = 'Fabric' + url = 'http://maven.fabricmc.net/' + } + gradlePluginPortal() + } +} diff --git a/setup.bat b/setup.bat deleted file mode 100644 index a2b532d..0000000 --- a/setup.bat +++ /dev/null @@ -1,2 +0,0 @@ -gradlew setupDecompWorkspace && gradlew eclipse -pause \ No newline at end of file diff --git a/src/main/java/tschipp/carryon/CarryOn.java b/src/main/java/tschipp/carryon/CarryOn.java index 9636537..fc31415 100644 --- a/src/main/java/tschipp/carryon/CarryOn.java +++ b/src/main/java/tschipp/carryon/CarryOn.java @@ -1,70 +1,24 @@ package tschipp.carryon; - -import java.io.File; - import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -import net.minecraft.client.Minecraft; -import net.minecraftforge.fml.common.FMLCommonHandler; -import net.minecraftforge.fml.common.Mod; -import net.minecraftforge.fml.common.Mod.EventBusSubscriber; -import net.minecraftforge.fml.common.Mod.EventHandler; -import net.minecraftforge.fml.common.Mod.Instance; -import net.minecraftforge.fml.common.SidedProxy; -import net.minecraftforge.fml.common.event.FMLInitializationEvent; -import net.minecraftforge.fml.common.event.FMLPostInitializationEvent; -import net.minecraftforge.fml.common.event.FMLPreInitializationEvent; -import net.minecraftforge.fml.common.event.FMLServerStartingEvent; -import net.minecraftforge.fml.common.network.simpleimpl.SimpleNetworkWrapper; -import tschipp.carryon.common.CommonProxy; -import tschipp.carryon.common.command.CommandCarryOn; -import tschipp.carryon.common.command.CommandCarryOnReload; +import net.fabricmc.api.ModInitializer; +import tschipp.carryon.keybinds.CarryOnKeybinds; -@EventBusSubscriber -@Mod(modid = CarryOn.MODID, name = CarryOn.NAME, version = CarryOn.VERSION, guiFactory = "tschipp.carryon.client.gui.GuiFactoryCarryOn", dependencies = "required-after:forge@[13.20.1.2386,)", updateJSON = CarryOn.UPDATE_JSON, acceptedMinecraftVersions = CarryOn.ACCEPTED_VERSIONS) -public class CarryOn { - @SidedProxy(clientSide = "tschipp.carryon.client.ClientProxy", serverSide = "tschipp.carryon.common.CommonProxy") - public static CommonProxy proxy; +public class CarryOn implements ModInitializer { - // Instance - @Instance(CarryOn.MODID) - public static CarryOn instance; - - public static final String MODID = "carryon"; - public static final String VERSION = "1.9.1"; - public static final String NAME = "Carry On"; - public static final String ACCEPTED_VERSIONS = "[1.11,1.12)"; - public static final String UPDATE_JSON = "https://gist.githubusercontent.com/Tschipp/dccadee7c90d7a34e6e76a35d9d6fa2e/raw/"; + public static String MODID = "carryon"; public static final Logger LOGGER = LogManager.getFormatterLogger("CarryOn"); - public static File CONFIGURATION_FILE; - - public static SimpleNetworkWrapper network; - @EventHandler - public void preInit(FMLPreInitializationEvent event){ - CarryOn.proxy.preInit(event); + + @Override + public void onInitialize() { + RegistryHandler.regItems(); + CarryOnKeybinds.init(); } - @EventHandler - public void init(FMLInitializationEvent event) { - CarryOn.proxy.init(event); - } - @EventHandler - public void postInit(FMLPostInitializationEvent event) { - CarryOn.proxy.postInit(event); - } - @EventHandler - public void serverLoad(FMLServerStartingEvent event) - { - event.registerServerCommand(new CommandCarryOn()); - event.registerServerCommand(new CommandCarryOnReload()); - } - - - -} \ No newline at end of file +} diff --git a/src/main/java/tschipp/carryon/PickupHandler.java b/src/main/java/tschipp/carryon/PickupHandler.java new file mode 100644 index 0000000..147f163 --- /dev/null +++ b/src/main/java/tschipp/carryon/PickupHandler.java @@ -0,0 +1,21 @@ +package tschipp.carryon; + +import net.minecraft.block.entity.BlockEntity; +import net.minecraft.entity.Entity; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.World; + +public class PickupHandler { + + public static boolean canPlayerPickUpBlock(PlayerEntity player, BlockEntity te, World world, BlockPos pos) + { + return true; + } + + public static boolean canPlayerPickUpEntity(PlayerEntity player, Entity entity) + { + return true; + } + +} \ No newline at end of file diff --git a/src/main/java/tschipp/carryon/RegistryHandler.java b/src/main/java/tschipp/carryon/RegistryHandler.java new file mode 100644 index 0000000..93d3389 --- /dev/null +++ b/src/main/java/tschipp/carryon/RegistryHandler.java @@ -0,0 +1,25 @@ +package tschipp.carryon; + +import net.minecraft.item.Item; +import net.minecraft.util.Identifier; +import net.minecraft.util.registry.Registry; +import tschipp.carryon.items.ItemEntity; +import tschipp.carryon.items.ItemTile; + +public class RegistryHandler { + + public static Item TILE_ITEM; + public static Item ENTITY_ITEM; + + public static void regItems() + { + TILE_ITEM = register(new ItemTile(), "tile_item"); + ENTITY_ITEM = register(new ItemEntity(), "entity_item"); + } + + private static Item register(Item item, String name) + { + return Registry.register(Registry.ITEM, new Identifier(CarryOn.MODID, name), item); + } + +} \ No newline at end of file diff --git a/src/main/java/tschipp/carryon/client/ClientProxy.java b/src/main/java/tschipp/carryon/client/ClientProxy.java deleted file mode 100644 index f42de29..0000000 --- a/src/main/java/tschipp/carryon/client/ClientProxy.java +++ /dev/null @@ -1,32 +0,0 @@ -package tschipp.carryon.client; - -import net.minecraftforge.fml.common.event.FMLInitializationEvent; -import net.minecraftforge.fml.common.event.FMLPostInitializationEvent; -import net.minecraftforge.fml.common.event.FMLPreInitializationEvent; -import tschipp.carryon.client.keybinds.CarryOnKeybinds; -import tschipp.carryon.common.CommonProxy; -import tschipp.carryon.common.handler.RegistrationHandler; - -public class ClientProxy extends CommonProxy { - - @Override - public void preInit(FMLPreInitializationEvent event) - { - super.preInit(event); - RegistrationHandler.regItemRenders(); - RegistrationHandler.regClientEvents(); - } - - @Override - public void init(FMLInitializationEvent event) - { - CarryOnKeybinds.init(); - super.init(event); - } - - @Override - public void postInit(FMLPostInitializationEvent e) - { - super.postInit(e); - } -} diff --git a/src/main/java/tschipp/carryon/client/event/RenderEntityEvents.java b/src/main/java/tschipp/carryon/client/event/RenderEntityEvents.java deleted file mode 100644 index 1ab616a..0000000 --- a/src/main/java/tschipp/carryon/client/event/RenderEntityEvents.java +++ /dev/null @@ -1,390 +0,0 @@ -package tschipp.carryon.client.event; - -import java.lang.reflect.Field; -import java.lang.reflect.InvocationTargetException; - -import net.minecraft.client.Minecraft; -import net.minecraft.client.entity.EntityPlayerSP; -import net.minecraft.client.gui.inventory.GuiContainer; -import net.minecraft.client.renderer.GlStateManager; -import net.minecraft.client.renderer.OpenGlHelper; -import net.minecraft.client.renderer.RenderHelper; -import net.minecraft.client.settings.GameSettings; -import net.minecraft.client.settings.KeyBinding; -import net.minecraft.entity.Entity; -import net.minecraft.entity.EntityList; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.util.EnumHand; -import net.minecraft.util.ResourceLocation; -import net.minecraft.util.math.BlockPos; -import net.minecraft.util.math.MathHelper; -import net.minecraft.world.World; -import net.minecraftforge.client.event.GuiOpenEvent; -import net.minecraftforge.client.event.MouseEvent; -import net.minecraftforge.client.event.RenderHandEvent; -import net.minecraftforge.client.event.RenderPlayerEvent; -import net.minecraftforge.client.event.GuiScreenEvent.InitGuiEvent; -import net.minecraftforge.fml.common.Loader; -import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; -import net.minecraftforge.fml.common.gameevent.InputEvent; -import net.minecraftforge.fml.relauncher.Side; -import net.minecraftforge.fml.relauncher.SideOnly; -import tschipp.carryon.common.handler.RegistrationHandler; -import tschipp.carryon.common.helper.ScriptParseHelper; -import tschipp.carryon.common.item.ItemEntity; -import tschipp.carryon.common.item.ItemTile; -import tschipp.carryon.common.scripting.CarryOnOverride; -import tschipp.carryon.common.scripting.ScriptChecker; - -public class RenderEntityEvents -{ - /* - * Prevents the Player from scrolling - */ - @SideOnly(Side.CLIENT) - @SubscribeEvent - public void onScroll(MouseEvent event) throws IllegalArgumentException, IllegalAccessException - { - if (event.getDwheel() > 0 || event.getDwheel() < 0 || Minecraft.getMinecraft().gameSettings.keyBindPickBlock.isPressed()) - { - ItemStack stack = Minecraft.getMinecraft().player.getHeldItemMainhand(); - - if (!stack.isEmpty() && stack.getItem() == RegistrationHandler.itemEntity) - { - if (ItemEntity.hasEntityData(stack)) - { - event.setCanceled(true); - } - } - } - } - - /* - * Prevents the Player from opening Guis - */ - @SideOnly(Side.CLIENT) - @SubscribeEvent - public void onGuiInit(InitGuiEvent.Pre event) - { - if (event.getGui() != null) - { - boolean inventory = event.getGui() instanceof GuiContainer; - EntityPlayer player = Minecraft.getMinecraft().player; - - if (player != null && inventory) - { - ItemStack stack = player.getHeldItem(EnumHand.MAIN_HAND); - - if (!stack.isEmpty() && stack.getItem() == RegistrationHandler.itemEntity && ItemEntity.hasEntityData(stack)) - { - Minecraft.getMinecraft().player.closeScreen(); - Minecraft.getMinecraft().currentScreen = null; - Minecraft.getMinecraft().setIngameFocus(); - - } - } - } - } - - /* - * Prevents the Player from switching Slots - */ - @SideOnly(Side.CLIENT) - @SubscribeEvent - public void inputEvent(InputEvent event) throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException, InvocationTargetException - { - GameSettings settings = Minecraft.getMinecraft().gameSettings; - Field field = KeyBinding.class.getDeclaredFields()[7]; - field.setAccessible(true); - ItemStack stack = Minecraft.getMinecraft().player.getHeldItemMainhand(); - EntityPlayer player = Minecraft.getMinecraft().player; - - if (!stack.isEmpty() && stack.getItem() == RegistrationHandler.itemEntity && ItemEntity.hasEntityData(stack)) - { - if (settings.keyBindDrop.isPressed()) - { - field.set(settings.keyBindDrop, false); - } - if (settings.keyBindSwapHands.isPressed()) - { - field.set(settings.keyBindSwapHands, false); - } - for (KeyBinding keyBind : settings.keyBindsHotbar) - { - if (keyBind.isPressed()) - { - field.set(keyBind, false); - } - } - } - - int current = player.inventory.currentItem; - - if (player.getEntityData().hasKey("carrySlot") ? player.getEntityData().getInteger("carrySlot") != current : false) - { - player.inventory.currentItem = player.getEntityData().getInteger("carrySlot"); - } - } - - /* - * Renders the Entity in First Person - */ - @SideOnly(Side.CLIENT) - @SubscribeEvent - public void renderHand(RenderHandEvent event) - { - World world = Minecraft.getMinecraft().world; - EntityPlayer player = Minecraft.getMinecraft().player; - ItemStack stack = player.getHeldItemMainhand(); - int perspective = Minecraft.getMinecraft().gameSettings.thirdPersonView; - float partialticks = event.getPartialTicks(); - - if (!stack.isEmpty() && stack.getItem() == RegistrationHandler.itemEntity && ItemEntity.hasEntityData(stack)) - { - if(Loader.isModLoaded("realrender") || Loader.isModLoaded("rfpr")) - return; - - - Entity entity = ItemEntity.getEntity(stack, world); - - if (entity != null) - { - double d0 = player.lastTickPosX + (player.posX - player.lastTickPosX) * partialticks; - double d1 = player.lastTickPosY + (player.posY - player.lastTickPosY) * partialticks; - double d2 = player.lastTickPosZ + (player.posZ - player.lastTickPosZ) * partialticks; - - entity.setPosition(d0, d1, d2); - entity.rotationYaw = 0.0f; - entity.prevRotationYaw = 0.0f; - entity.setRotationYawHead(0.0f); - - float height = entity.height; - float width = entity.width; - GlStateManager.pushMatrix(); - GlStateManager.scale(.8, .8, .8); - GlStateManager.rotate(180, 0, 1, 0); - GlStateManager.translate(0.0, -height - .1, width + 0.1); - GlStateManager.enableAlpha(); - - if (perspective == 0) - { - RenderHelper.enableStandardItemLighting(); - Minecraft.getMinecraft().getRenderManager().setRenderShadow(false); - - CarryOnOverride carryOverride = ScriptChecker.getOverride(player); - if (carryOverride != null) - { - double[] translation = ScriptParseHelper.getXYZArray(carryOverride.getRenderTranslation()); - double[] rotation = ScriptParseHelper.getXYZArray(carryOverride.getRenderRotation()); - double[] scale = ScriptParseHelper.getScale(carryOverride.getRenderScale()); - String entityname = carryOverride.getRenderNameEntity(); - if (entityname != null) - { - Entity newEntity = EntityList.createEntityByIDFromName(new ResourceLocation(entityname), world); - if (newEntity != null) - { - NBTTagCompound nbttag = carryOverride.getRenderNBT(); - if (nbttag != null) - newEntity.readFromNBT(nbttag); - entity = newEntity; - entity.setPosition(d0, d1, d2); - entity.rotationYaw = 0.0f; - entity.prevRotationYaw = 0.0f; - entity.setRotationYawHead(0.0f); - } - } - - GlStateManager.translate(translation[0], translation[1], translation[2]); - GlStateManager.rotate((float) rotation[0], 1, 0, 0); - GlStateManager.rotate((float) rotation[1], 0, 1, 0); - GlStateManager.rotate((float) rotation[2], 0, 0, 1); - GlStateManager.scale(scale[0], scale[1], scale[2]); - - } - - this.renderEntityStatic(entity); - Minecraft.getMinecraft().getRenderManager().setRenderShadow(true); - } - - GlStateManager.disableAlpha(); - GlStateManager.scale(1, 1, 1); - GlStateManager.popMatrix(); - - RenderHelper.disableStandardItemLighting(); - GlStateManager.disableRescaleNormal(); - GlStateManager.setActiveTexture(OpenGlHelper.lightmapTexUnit); - GlStateManager.disableTexture2D(); - GlStateManager.setActiveTexture(OpenGlHelper.defaultTexUnit); - - if (perspective == 0) - { - event.setCanceled(true); - } - } - } - } - - @SideOnly(Side.CLIENT) - private void renderEntityStatic(Entity entity) - { - if (entity.ticksExisted == 0) - { - entity.lastTickPosX = entity.posX; - entity.lastTickPosY = entity.posY; - entity.lastTickPosZ = entity.posZ; - } - - float f = entity.prevRotationYaw + (entity.rotationYaw - entity.prevRotationYaw); - int i = this.getBrightnessForRender(entity, Minecraft.getMinecraft().player); - - if (entity.isBurning()) - { - i = 15728880; - } - - int j = i % 65536; - int k = i / 65536; - OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, j, k); - GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F); - - this.setLightmapDisabled(false); - - - - Minecraft.getMinecraft().getRenderManager().doRenderEntity(entity, 0.0D, 0.0D, 0.0D, f, 0.0F, true); - this.setLightmapDisabled(true); - } - - @SideOnly(Side.CLIENT) - private int getBrightnessForRender(Entity entity, EntityPlayer player) - { - BlockPos.MutableBlockPos blockpos$mutableblockpos = new BlockPos.MutableBlockPos(MathHelper.floor(player.posX), 0, MathHelper.floor(player.posZ)); - - if (entity.world.isBlockLoaded(blockpos$mutableblockpos)) - { - blockpos$mutableblockpos.setY(MathHelper.floor(player.posY + entity.getEyeHeight())); - return entity.world.getCombinedLight(blockpos$mutableblockpos, 0); - } - else - { - return 0; - } - } - - @SideOnly(Side.CLIENT) - private void setLightmapDisabled(boolean disabled) - { - GlStateManager.setActiveTexture(OpenGlHelper.lightmapTexUnit); - - if (disabled) - { - GlStateManager.disableTexture2D(); - } - else - { - GlStateManager.enableTexture2D(); - } - - GlStateManager.setActiveTexture(OpenGlHelper.defaultTexUnit); - } - - /* - * Renders the Block in Third Person - */ - @SideOnly(Side.CLIENT) - @SubscribeEvent - public void onPlayerRenderPost(RenderPlayerEvent.Post event) - { - World world = Minecraft.getMinecraft().world; - EntityPlayer player = event.getEntityPlayer(); - event.getRenderer().getMainModel(); - EntityPlayerSP clientPlayer = Minecraft.getMinecraft().player; - ItemStack stack = player.getHeldItemMainhand(); - float partialticks = event.getPartialRenderTick(); - - if (!stack.isEmpty() && stack.getItem() == RegistrationHandler.itemEntity && ItemEntity.hasEntityData(stack)) - { - Entity entity = ItemEntity.getEntity(stack, world); - float rotation = -(player.prevRenderYawOffset + (player.renderYawOffset - player.prevRenderYawOffset) * partialticks); - - if (entity != null) - { - double d0 = player.lastTickPosX + (player.posX - player.lastTickPosX) * partialticks; - double d1 = player.lastTickPosY + (player.posY - player.lastTickPosY) * partialticks; - double d2 = player.lastTickPosZ + (player.posZ - player.lastTickPosZ) * partialticks; - - double c0 = clientPlayer.lastTickPosX + (clientPlayer.posX - clientPlayer.lastTickPosX) * partialticks; - double c1 = clientPlayer.lastTickPosY + (clientPlayer.posY - clientPlayer.lastTickPosY) * partialticks; - double c2 = clientPlayer.lastTickPosZ + (clientPlayer.posZ - clientPlayer.lastTickPosZ) * partialticks; - - double xOffset = d0 - c0; - double yOffset = d1 - c1; - double zOffset = d2 - c2; - - float height = entity.height; - float width = entity.width; - float multiplier = height * width; - - entity.setPosition(c0, c1, c2); - entity.rotationYaw = 0.0f; - entity.prevRotationYaw = 0.0f; - entity.setRotationYawHead(0.0f); - - GlStateManager.pushMatrix(); - GlStateManager.translate(xOffset, yOffset, zOffset); - GlStateManager.scale((10 - multiplier) * 0.08, (10 - multiplier) * 0.08, (10 - multiplier) * 0.08); - GlStateManager.rotate(rotation, 0, 1f, 0); - GlStateManager.translate(0.0, height / 2 + -(height / 2) + 1, width - 0.1 < 0.7 ? width - 0.1 + (0.7 - (width - 0.1)) : width - 0.1); - - if((Loader.isModLoaded("realrender") || Loader.isModLoaded("rfpr")) && Minecraft.getMinecraft().gameSettings.thirdPersonView == 0) - GlStateManager.translate(0, 0, -0.3); - - if (player.isSneaking()) - { - GlStateManager.translate(0, -0.3, 0); - } - - Minecraft.getMinecraft().getRenderManager().setRenderShadow(false); - - CarryOnOverride carryOverride = ScriptChecker.getOverride(player); - if (carryOverride != null) - { - double[] translation = ScriptParseHelper.getXYZArray(carryOverride.getRenderTranslation()); - double[] rot = ScriptParseHelper.getXYZArray(carryOverride.getRenderRotation()); - double[] scale = ScriptParseHelper.getScale(carryOverride.getRenderScale()); - String entityname = carryOverride.getRenderNameEntity(); - if (entityname != null) - { - Entity newEntity = EntityList.createEntityByIDFromName(new ResourceLocation(entityname), world); - if (newEntity != null) - { - NBTTagCompound nbttag = carryOverride.getRenderNBT(); - if (nbttag != null) - newEntity.readFromNBT(nbttag); - entity = newEntity; - entity.setPosition(c0, c1, c2); - entity.rotationYaw = 0.0f; - entity.prevRotationYaw = 0.0f; - entity.setRotationYawHead(0.0f); - } - } - - GlStateManager.translate(translation[0], translation[1], translation[2]); - GlStateManager.rotate((float) rot[0], 1, 0, 0); - GlStateManager.rotate((float) rot[1], 0, 1, 0); - GlStateManager.rotate((float) rot[2], 0, 0, 1); - GlStateManager.scale(scale[0], scale[1], scale[2]); - - } - - Minecraft.getMinecraft().getRenderManager().renderEntityStatic(entity, 0.0f, false); - Minecraft.getMinecraft().getRenderManager().setRenderShadow(true); - - GlStateManager.scale(1, 1, 1); - GlStateManager.popMatrix(); - } - } - } -} diff --git a/src/main/java/tschipp/carryon/client/event/RenderEvents.java b/src/main/java/tschipp/carryon/client/event/RenderEvents.java deleted file mode 100644 index 486d2ed..0000000 --- a/src/main/java/tschipp/carryon/client/event/RenderEvents.java +++ /dev/null @@ -1,827 +0,0 @@ -package tschipp.carryon.client.event; - -import java.lang.reflect.Field; -import java.lang.reflect.InvocationTargetException; - -import net.minecraft.block.Block; -import net.minecraft.block.state.IBlockState; -import net.minecraft.client.Minecraft; -import net.minecraft.client.entity.AbstractClientPlayer; -import net.minecraft.client.entity.EntityPlayerSP; -import net.minecraft.client.gui.inventory.GuiContainer; -import net.minecraft.client.model.ModelPlayer; -import net.minecraft.client.model.ModelRenderer; -import net.minecraft.client.renderer.GlStateManager; -import net.minecraft.client.renderer.OpenGlHelper; -import net.minecraft.client.renderer.block.model.IBakedModel; -import net.minecraft.client.renderer.entity.RenderManager; -import net.minecraft.client.renderer.entity.RenderPlayer; -import net.minecraft.client.renderer.texture.TextureMap; -import net.minecraft.client.resources.DefaultPlayerSkin; -import net.minecraft.client.settings.GameSettings; -import net.minecraft.client.settings.KeyBinding; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.entity.player.EnumPlayerModelParts; -import net.minecraft.init.Blocks; -import net.minecraft.item.Item; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.util.EnumHand; -import net.minecraft.util.ResourceLocation; -import net.minecraft.util.math.BlockPos; -import net.minecraft.util.math.MathHelper; -import net.minecraft.world.World; -import net.minecraftforge.client.event.GuiScreenEvent.InitGuiEvent; -import net.minecraftforge.client.event.MouseEvent; -import net.minecraftforge.client.event.RenderHandEvent; -import net.minecraftforge.client.event.RenderPlayerEvent; -import net.minecraftforge.fml.common.Loader; -import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; -import net.minecraftforge.fml.common.gameevent.InputEvent; -import net.minecraftforge.fml.common.gameevent.TickEvent.PlayerTickEvent; -import net.minecraftforge.fml.relauncher.Side; -import net.minecraftforge.fml.relauncher.SideOnly; -import tschipp.carryon.CarryOn; -import tschipp.carryon.client.keybinds.CarryOnKeybinds; -import tschipp.carryon.common.config.CarryOnConfig; -import tschipp.carryon.common.handler.ModelOverridesHandler; -import tschipp.carryon.common.handler.RegistrationHandler; -import tschipp.carryon.common.helper.ScriptParseHelper; -import tschipp.carryon.common.helper.StringParser; -import tschipp.carryon.common.item.ItemEntity; -import tschipp.carryon.common.item.ItemTile; -import tschipp.carryon.common.scripting.CarryOnOverride; -import tschipp.carryon.common.scripting.ScriptChecker; -import tschipp.carryon.network.server.SyncKeybindPacket; - -public class RenderEvents -{ - private static boolean initModels; - private ModelRenderer fakeLeftArm; - private ModelRenderer fakeRightArm; - private ModelRenderer fakeLeftArmwear; - private ModelRenderer fakeRightArmwear; - - /* - * Prevents the Player from scrolling - */ - @SideOnly(Side.CLIENT) - @SubscribeEvent - public void onScroll(MouseEvent event) - { - if (event.getDwheel() > 0 || event.getDwheel() < 0 || Minecraft.getMinecraft().gameSettings.keyBindPickBlock.isPressed()) - { - ItemStack stack = Minecraft.getMinecraft().player.getHeldItemMainhand(); - - if (!stack.isEmpty() && stack.getItem() == RegistrationHandler.itemTile) - { - if (ItemTile.hasTileData(stack)) - { - event.setCanceled(true); - } - } - } - } - - @SubscribeEvent - @SideOnly(Side.CLIENT) - public void onPlayerTick(PlayerTickEvent event) throws IllegalArgumentException, IllegalAccessException, InvocationTargetException - { - EntityPlayer player = event.player; - - if (player != null && event.side == Side.CLIENT) - { - boolean keyPressed = CarryOnKeybinds.carryKey.isKeyDown(); - boolean playerKeyPressed = CarryOnKeybinds.isKeyPressed(player); - - if (keyPressed && !playerKeyPressed) - { - CarryOnKeybinds.setKeyPressed(player, true); - CarryOn.network.sendToServer(new SyncKeybindPacket(true)); - } - else if (!keyPressed && playerKeyPressed) - { - CarryOnKeybinds.setKeyPressed(player, false); - CarryOn.network.sendToServer(new SyncKeybindPacket(false)); - } - } - } - - /* - * Prevents the Player from opening Guis - */ - @SideOnly(Side.CLIENT) - @SubscribeEvent - public void onGuiInit(InitGuiEvent.Pre event) - { - if (event.getGui() != null) - { - boolean inventory = event.getGui() instanceof GuiContainer; - EntityPlayer player = Minecraft.getMinecraft().player; - - if (player != null && inventory) - { - ItemStack stack = player.getHeldItem(EnumHand.MAIN_HAND); - - if (!stack.isEmpty() && stack.getItem() == RegistrationHandler.itemTile && ItemTile.hasTileData(stack)) - { - Minecraft.getMinecraft().player.closeScreen(); - Minecraft.getMinecraft().currentScreen = null; - Minecraft.getMinecraft().setIngameFocus(); - - } - } - } - } - - /* - * Prevents the Player from switching Slots - */ - @SideOnly(Side.CLIENT) - @SubscribeEvent - public void inputEvent(InputEvent event) throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException - { - GameSettings settings = Minecraft.getMinecraft().gameSettings; - Field field = KeyBinding.class.getDeclaredFields()[7]; - field.setAccessible(true); - ItemStack stack = Minecraft.getMinecraft().player.getHeldItemMainhand(); - EntityPlayer player = Minecraft.getMinecraft().player; - - if (!stack.isEmpty() && stack.getItem() == RegistrationHandler.itemTile && ItemTile.hasTileData(stack)) - { - if (settings.keyBindDrop.isPressed()) - { - field.set(settings.keyBindDrop, false); - } - if (settings.keyBindSwapHands.isPressed()) - { - field.set(settings.keyBindSwapHands, false); - } - for (KeyBinding keyBind : settings.keyBindsHotbar) - { - if (keyBind.isPressed()) - { - field.set(keyBind, false); - } - } - } - - int current = player.inventory.currentItem; - - if (player.getEntityData().hasKey("carrySlot") ? player.getEntityData().getInteger("carrySlot") != current : false) - { - player.inventory.currentItem = player.getEntityData().getInteger("carrySlot"); - } - } - - /* - * Renders the Block in First Person - */ - @SideOnly(Side.CLIENT) - @SubscribeEvent - public void renderHand(RenderHandEvent event) - { - World world = Minecraft.getMinecraft().world; - EntityPlayer player = Minecraft.getMinecraft().player; - AbstractClientPlayer aplayer = (AbstractClientPlayer) player; - ItemStack stack = player.getHeldItemMainhand(); - int perspective = Minecraft.getMinecraft().gameSettings.thirdPersonView; - boolean f1 = Minecraft.getMinecraft().gameSettings.hideGUI; - - if (!stack.isEmpty() && stack.getItem() == RegistrationHandler.itemTile && ItemTile.hasTileData(stack) && perspective == 0 && !f1) - { - if (Loader.isModLoaded("realrender") || Loader.isModLoaded("rfpr")) - return; - - Block block = ItemTile.getBlock(stack); - NBTTagCompound tag = ItemTile.getTileData(stack); - IBlockState state = ItemTile.getBlockState(stack); - ItemStack tileStack = ItemTile.getItemStack(stack); - - GlStateManager.pushMatrix(); - GlStateManager.scale(2.5, 2.5, 2.5); - GlStateManager.translate(0, -0.6, -1); - - if (CarryOnConfig.settings.facePlayer ? !isChest(block) : isChest(block)) - { - GlStateManager.rotate(180, 0, 1f, 0); - GlStateManager.rotate(-8, 1f, 0, 0); - } - else - { - GlStateManager.rotate(8, 1f, 0, 0); - } - - IBakedModel model = ModelOverridesHandler.hasCustomOverrideModel(state, tag) ? ModelOverridesHandler.getCustomOverrideModel(state, tag, world, player) : Minecraft.getMinecraft().getRenderItem().getItemModelWithOverrides(tileStack, world, player); - - CarryOnOverride carryOverride = ScriptChecker.getOverride(player); - if (carryOverride != null) - { - double[] translation = ScriptParseHelper.getXYZArray(carryOverride.getRenderTranslation()); - double[] rotation = ScriptParseHelper.getXYZArray(carryOverride.getRenderRotation()); - double[] scale = ScriptParseHelper.getScale(carryOverride.getRenderScale()); - Block b = StringParser.getBlock(carryOverride.getRenderNameBlock()); - if (b != null) - { - ItemStack s = new ItemStack(b, 1, carryOverride.getRenderMeta()); - s.setTagCompound(carryOverride.getRenderNBT()); - model = Minecraft.getMinecraft().getRenderItem().getItemModelWithOverrides(s, world, player); - } - - GlStateManager.translate(translation[0], translation[1], translation[2]); - GlStateManager.rotate((float) rotation[0], 1, 0, 0); - GlStateManager.rotate((float) rotation[1], 0, 1, 0); - GlStateManager.rotate((float) rotation[2], 0, 0, 1); - GlStateManager.scale(scale[0], scale[1], scale[2]); - - } - - int i = this.getBrightnessForRender(Minecraft.getMinecraft().player); - int j = i % 65536; - int k = i / 65536; - OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, j, k); - GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F); - this.setLightmapDisabled(false); - - Minecraft.getMinecraft().getTextureManager().bindTexture(TextureMap.LOCATION_BLOCKS_TEXTURE); - - if (ModelOverridesHandler.hasCustomOverrideModel(state, tag)) - { - Object override = ModelOverridesHandler.getOverrideObject(state, tag); - - if (override instanceof ItemStack) - { - - Minecraft.getMinecraft().getRenderItem().renderItem((ItemStack) override, model); - } - else - { - Minecraft.getMinecraft().getRenderItem().renderItem(tileStack.isEmpty() ? stack : tileStack, model); - } - } - else - { - Minecraft.getMinecraft().getRenderItem().renderItem(tileStack.isEmpty() ? stack : tileStack, model); - } - - this.setLightmapDisabled(true); - - if (perspective == 0) - { - event.setCanceled(true); - } - - GlStateManager.scale(1, 1, 1); - GlStateManager.popMatrix(); - - } - else - { - if (stack.isEmpty() ? true : stack.getItem() != RegistrationHandler.itemEntity) - { - event.setCanceled(false); - Minecraft mc = Minecraft.getMinecraft(); - RenderManager manager = mc.getRenderManager(); - RenderPlayer renderPlayer = manager.getSkinMap().get(aplayer.getSkinType()); - ModelPlayer modelPlayer = renderPlayer.getMainModel(); - - if (modelPlayer != null) - { - if (modelPlayer.bipedLeftArm != null && modelPlayer.bipedRightArm != null) - { - modelPlayer.bipedLeftArm.isHidden = false; - modelPlayer.bipedRightArm.isHidden = false; - modelPlayer.bipedLeftArmwear.isHidden = false; - modelPlayer.bipedRightArmwear.isHidden = false; - } - } - } - } - } - - @SideOnly(Side.CLIENT) - private int getBrightnessForRender(EntityPlayer player) - { - BlockPos.MutableBlockPos blockpos$mutableblockpos = new BlockPos.MutableBlockPos(MathHelper.floor(player.posX), 0, MathHelper.floor(player.posZ)); - - if (player.world.isBlockLoaded(blockpos$mutableblockpos)) - { - blockpos$mutableblockpos.setY(MathHelper.floor(player.posY + player.getEyeHeight())); - return player.world.getCombinedLight(blockpos$mutableblockpos, 0); - } - else - { - return 0; - } - } - - @SideOnly(Side.CLIENT) - private void setLightmapDisabled(boolean disabled) - { - GlStateManager.setActiveTexture(OpenGlHelper.lightmapTexUnit); - - if (disabled) - { - GlStateManager.disableTexture2D(); - } - else - { - GlStateManager.enableTexture2D(); - } - - GlStateManager.setActiveTexture(OpenGlHelper.defaultTexUnit); - } - - /* - * Renders the Block in Third Person - */ - @SideOnly(Side.CLIENT) - @SubscribeEvent - public void onPlayerRenderPost(RenderPlayerEvent.Post event) - { - World world = Minecraft.getMinecraft().world; - EntityPlayer player = event.getEntityPlayer(); - EntityPlayerSP clientPlayer = Minecraft.getMinecraft().player; - ItemStack stack = player.getHeldItemMainhand(); - float partialticks = event.getPartialRenderTick(); - - if (!stack.isEmpty() && stack.getItem() == RegistrationHandler.itemTile && ItemTile.hasTileData(stack)) - { - Block block = ItemTile.getBlock(stack); - IBlockState state = ItemTile.getBlockState(stack); - NBTTagCompound tag = ItemTile.getTileData(stack); - ItemStack tileItem = ItemTile.getItemStack(stack); - - float rotation = -(player.prevRenderYawOffset + (player.renderYawOffset - player.prevRenderYawOffset) * partialticks); - - double d0 = player.lastTickPosX + (player.posX - player.lastTickPosX) * partialticks; - double d1 = player.lastTickPosY + (player.posY - player.lastTickPosY) * partialticks; - double d2 = player.lastTickPosZ + (player.posZ - player.lastTickPosZ) * partialticks; - - double c0 = clientPlayer.lastTickPosX + (clientPlayer.posX - clientPlayer.lastTickPosX) * partialticks; - double c1 = clientPlayer.lastTickPosY + (clientPlayer.posY - clientPlayer.lastTickPosY) * partialticks; - double c2 = clientPlayer.lastTickPosZ + (clientPlayer.posZ - clientPlayer.lastTickPosZ) * partialticks; - - double xOffset = d0 - c0; - double yOffset = d1 - c1; - double zOffset = d2 - c2; - - GlStateManager.pushMatrix(); - GlStateManager.translate(xOffset, yOffset, zOffset); - GlStateManager.scale(0.6, 0.6, 0.6); - - if (CarryOnConfig.settings.facePlayer ? !isChest(block) : isChest(block)) - { - GlStateManager.rotate(rotation, 0, 1.0f, 0); - GlStateManager.translate(0, 1.6, 0.65); - if ((Loader.isModLoaded("realrender") || Loader.isModLoaded("rfpr")) && Minecraft.getMinecraft().gameSettings.thirdPersonView == 0) - GlStateManager.translate(0, 0, -0.4); - } - else - { - GlStateManager.rotate(rotation + 180, 0, 1.0f, 0); - GlStateManager.translate(0, 1.6, -0.65); - if ((Loader.isModLoaded("realrender") || Loader.isModLoaded("rfpr")) && Minecraft.getMinecraft().gameSettings.thirdPersonView == 0) - GlStateManager.translate(0, 0, 0.4); - } - - if (player.isSneaking()) - { - GlStateManager.translate(0, -0.3, 0); - } - - IBakedModel model = ModelOverridesHandler.hasCustomOverrideModel(state, tag) ? ModelOverridesHandler.getCustomOverrideModel(state, tag, world, player) : Minecraft.getMinecraft().getRenderItem().getItemModelWithOverrides(tileItem, world, player); - - CarryOnOverride carryOverride = ScriptChecker.getOverride(player); - if (carryOverride != null) - { - double[] translation = ScriptParseHelper.getXYZArray(carryOverride.getRenderTranslation()); - double[] rot = ScriptParseHelper.getXYZArray(carryOverride.getRenderRotation()); - double[] scale = ScriptParseHelper.getScale(carryOverride.getRenderScale()); - Block b = StringParser.getBlock(carryOverride.getRenderNameBlock()); - if (b != null) - { - ItemStack s = new ItemStack(b, 1, carryOverride.getRenderMeta()); - s.setTagCompound(carryOverride.getRenderNBT()); - model = Minecraft.getMinecraft().getRenderItem().getItemModelWithOverrides(s, world, player); - } - - GlStateManager.translate(translation[0], translation[1], translation[2]); - GlStateManager.rotate((float) rot[0], 1, 0, 0); - GlStateManager.rotate((float) rot[1], 0, 1, 0); - GlStateManager.rotate((float) rot[2], 0, 0, 1); - GlStateManager.scale(scale[0], scale[1], scale[2]); - - } - - Minecraft.getMinecraft().getTextureManager().bindTexture(TextureMap.LOCATION_BLOCKS_TEXTURE); - - if (ModelOverridesHandler.hasCustomOverrideModel(state, tag)) - { - Object override = ModelOverridesHandler.getOverrideObject(state, tag); - - if (override instanceof ItemStack) - { - Minecraft.getMinecraft().getRenderItem().renderItem((ItemStack) override, model); - } - else - { - Minecraft.getMinecraft().getRenderItem().renderItem(tileItem.isEmpty() ? stack : tileItem, model); - } - } - else - { - Minecraft.getMinecraft().getRenderItem().renderItem(tileItem.isEmpty() ? stack : tileItem, model); - } - - GlStateManager.scale(1, 1, 1); - GlStateManager.popMatrix(); - } - } - - /* - * Renders correct arm rotation - */ - @SideOnly(Side.CLIENT) - @SubscribeEvent - public void onPlayerRenderPre(RenderPlayerEvent.Pre event) - { - if (!Loader.isModLoaded("mobends") && CarryOnConfig.settings.renderArms) - { - EntityPlayer player = event.getEntityPlayer(); - AbstractClientPlayer aplayer = (AbstractClientPlayer) player; - ItemStack stack = player.getHeldItemMainhand(); - ModelPlayer model = event.getRenderer().getMainModel(); - ResourceLocation skinLoc = DefaultPlayerSkin.getDefaultSkin(player.getPersistentID()); - - if (!initModels) - { - this.fakeLeftArm = new ModelRenderer(model, 32, 48); - this.fakeRightArm = new ModelRenderer(model, 40, 16); - this.fakeLeftArmwear = new ModelRenderer(model, 48, 48); - this.fakeRightArmwear = new ModelRenderer(model, 40, 32); - initModels = true; - } - - player.setArrowCountInEntity(0); // TODO Temporary Fix - - if (!stack.isEmpty() && stack.getItem() == RegistrationHandler.itemTile && ItemTile.hasTileData(stack) || stack.getItem() == RegistrationHandler.itemEntity && ItemEntity.hasEntityData(stack)) - { - CarryOnOverride overrider = ScriptChecker.getOverride(player); - if (overrider != null) - { - if (model.bipedBody.childModels != null && !model.bipedBody.childModels.isEmpty()) - { - for (int k = 0; k < model.bipedBody.childModels.size(); k++) - { - double[] rotLeft1 = ScriptParseHelper.getXYZArray(overrider.getRenderRotationLeftArm()); - double[] rotRight1 = ScriptParseHelper.getXYZArray(overrider.getRenderRotationRightArm()); - - float rotX = model.bipedBody.childModels.get(k).rotateAngleX; - float rotY = model.bipedBody.childModels.get(k).rotateAngleY; - float rotZ = model.bipedBody.childModels.get(k).rotateAngleZ; - - if (rotLeft1[0] == rotX || rotLeft1[1] == rotY || rotRight1[2] == rotZ || rotRight1[0] == rotX || rotRight1[1] == rotY || rotRight1[2] == rotZ || rotX == rotLeft1[0] - 0.5f || rotX == rotRight1[0] - 0.5f) - { - model.bipedBody.childModels.remove(k); - k = k - 1; - } - } - } - } - else - { - if (model.bipedBody.childModels != null && !model.bipedBody.childModels.isEmpty()) - { - for (int k = 0; k < model.bipedBody.childModels.size(); k++) - { - float chkRot = model.bipedBody.childModels.get(k).rotateAngleX; - - if (chkRot == -0.9001F || chkRot == -1.2001F || chkRot == -1.4001F || chkRot == -1.7001F) - { - model.bipedBody.childModels.remove(k); - k = k - 1; - } - } - } - } - - Item item = stack.getItem(); - - model.bipedLeftArm.isHidden = true; - model.bipedRightArm.isHidden = true; - model.bipedLeftArmwear.isHidden = true; - model.bipedRightArmwear.isHidden = true; - this.fakeLeftArm.isHidden = false; - this.fakeLeftArmwear.isHidden = false; - this.fakeRightArm.isHidden = false; - this.fakeRightArmwear.isHidden = false; - - Minecraft.getMinecraft().getTextureManager().bindTexture(skinLoc); - - if (aplayer.getSkinType().equals("default")) - { - // left arm - this.fakeLeftArm.addBox(model.bipedLeftArm.offsetX + 4.2F, model.bipedLeftArm.offsetY, model.bipedLeftArm.offsetZ, 4, 12, 4, .08F); - this.fakeLeftArmwear.addBox(model.bipedLeftArm.offsetX + 4.2F, model.bipedLeftArm.offsetY, model.bipedLeftArm.offsetZ, 4, 12, 4, .08F + 0.25F); - - // right arm - this.fakeRightArm.addBox(model.bipedRightArm.offsetX - 7.9F, model.bipedRightArm.offsetY, model.bipedRightArm.offsetZ, 4, 12, 4, .08F); - this.fakeRightArmwear.addBox(model.bipedRightArm.offsetX - 7.9F, model.bipedRightArm.offsetY, model.bipedRightArm.offsetZ, 4, 12, 4, .08F + 0.25F); - } - else - { - // left arm - this.fakeLeftArm.addBox(model.bipedLeftArm.offsetX + 4.2F, model.bipedLeftArm.offsetY, model.bipedLeftArm.offsetZ, 3, 12, 4, .08F); - this.fakeLeftArmwear.addBox(model.bipedLeftArm.offsetX + 4.2F, model.bipedLeftArm.offsetY, model.bipedLeftArm.offsetZ, 3, 12, 4, .08F + 0.25F); - - // right arm - this.fakeRightArm.addBox(model.bipedRightArm.offsetX - 7.2F, model.bipedRightArm.offsetY, model.bipedRightArm.offsetZ, 3, 12, 4, .08F); - this.fakeRightArmwear.addBox(model.bipedRightArm.offsetX - 7.2F, model.bipedRightArm.offsetY, model.bipedRightArm.offsetZ, 3, 12, 4, .08F + 0.25F); - } - - CarryOnOverride override = ScriptChecker.getOverride(player); - if (override != null) - { - double[] rotLeft = null; - double[] rotRight = null; - if (override.getRenderRotationLeftArm() != null) - rotLeft = ScriptParseHelper.getXYZArray(override.getRenderRotationLeftArm()); - if (override.getRenderRotationRightArm() != null) - rotRight = ScriptParseHelper.getXYZArray(override.getRenderRotationRightArm()); - - boolean renderRight = override.isRenderRightArm(); - boolean renderLeft = override.isRenderLeftArm(); - - if (!renderRight) - { - this.fakeRightArm.isHidden = true; - this.fakeRightArmwear.isHidden = true; - model.bipedRightArm.isHidden = false; - model.bipedRightArmwear.isHidden = false; - } - - if (!renderLeft) - { - this.fakeLeftArm.isHidden = true; - this.fakeLeftArmwear.isHidden = true; - model.bipedLeftArm.isHidden = false; - model.bipedLeftArmwear.isHidden = false; - } - - if (rotLeft != null) - { - if (!player.isSneaking()) - { - this.fakeLeftArm.rotateAngleX = (float) rotLeft[0]; - this.fakeLeftArmwear.rotateAngleX = (float) rotLeft[0]; - } - else - { - this.fakeLeftArm.rotateAngleX = (float) rotLeft[0] - 0.5f; - this.fakeLeftArmwear.rotateAngleX = (float) rotLeft[0] - 0.5f; - } - - this.fakeLeftArmwear.rotateAngleY = (float) rotLeft[1]; - this.fakeLeftArmwear.rotateAngleZ = (float) rotLeft[2]; - this.fakeLeftArm.rotateAngleY = (float) rotLeft[1]; - this.fakeLeftArm.rotateAngleZ = (float) rotLeft[2]; - } - else - { - if (item == RegistrationHandler.itemTile) - { - if (!player.isSneaking()) - { - this.fakeLeftArm.rotateAngleX = -.9001F; - this.fakeLeftArmwear.rotateAngleX = -.9001F; - } - else - { - this.fakeLeftArm.rotateAngleX = -1.4001F; - this.fakeLeftArmwear.rotateAngleX = -1.4001F; - } - } - else - { - if (!player.isSneaking()) - { - this.fakeLeftArm.rotateAngleX = -1.2001F; - this.fakeLeftArmwear.rotateAngleX = -1.2001F; - } - else - { - this.fakeLeftArm.rotateAngleX = -1.7001F; - this.fakeLeftArmwear.rotateAngleX = -1.7001F; - } - - this.fakeLeftArm.rotateAngleY = 0.15f; - this.fakeLeftArmwear.rotateAngleY = 0.15f; - } - } - - if (rotRight != null) - { - if (!player.isSneaking()) - { - this.fakeRightArm.rotateAngleX = (float) rotRight[0]; - this.fakeRightArmwear.rotateAngleX = (float) rotRight[0]; - } - else - { - this.fakeRightArm.rotateAngleX = (float) rotRight[0] - 0.5f; - this.fakeRightArmwear.rotateAngleX = (float) rotRight[0] - 0.5f; - } - - this.fakeRightArmwear.rotateAngleY = (float) rotRight[1]; - this.fakeRightArmwear.rotateAngleZ = (float) rotRight[2]; - this.fakeRightArm.rotateAngleY = (float) rotRight[1]; - this.fakeRightArm.rotateAngleZ = (float) rotRight[2]; - } - else - { - if (item == RegistrationHandler.itemTile) - { - if (!player.isSneaking()) - { - this.fakeRightArm.rotateAngleX = -.9001F; - this.fakeRightArmwear.rotateAngleX = -.9001F; - } - else - { - this.fakeRightArm.rotateAngleX = -1.4001F; - this.fakeRightArmwear.rotateAngleX = -1.4001F; - } - } - else - { - if (!player.isSneaking()) - { - this.fakeRightArm.rotateAngleX = -1.2001F; - this.fakeRightArmwear.rotateAngleX = -1.2001F; - } - else - { - this.fakeRightArm.rotateAngleX = -1.7001F; - this.fakeRightArmwear.rotateAngleX = -1.7001F; - } - - this.fakeRightArm.rotateAngleY = -0.15f; - this.fakeRightArmwear.rotateAngleY = -0.15f; - } - } - } - else - { - if (item == RegistrationHandler.itemTile) - { - if (!player.isSneaking()) - { - this.fakeRightArm.rotateAngleX = -.9001F; - this.fakeLeftArm.rotateAngleX = -.9001F; - this.fakeLeftArmwear.rotateAngleX = -.9001F; - this.fakeRightArmwear.rotateAngleX = -.9001F; - } - else - { - this.fakeRightArm.rotateAngleX = -1.4001F; - this.fakeLeftArm.rotateAngleX = -1.4001F; - this.fakeLeftArmwear.rotateAngleX = -1.4001F; - this.fakeRightArmwear.rotateAngleX = -1.4001F; - } - - this.fakeRightArm.rotateAngleY = 0f; - this.fakeLeftArm.rotateAngleY = 0f; - this.fakeLeftArmwear.rotateAngleY = 0f; - this.fakeRightArmwear.rotateAngleY = 0f; - } - else - { - if (!player.isSneaking()) - { - this.fakeRightArm.rotateAngleX = -1.2001F; - this.fakeLeftArm.rotateAngleX = -1.2001F; - this.fakeLeftArmwear.rotateAngleX = -1.2001F; - this.fakeRightArmwear.rotateAngleX = -1.2001F; - } - else - { - this.fakeRightArm.rotateAngleX = -1.7001F; - this.fakeLeftArm.rotateAngleX = -1.7001F; - this.fakeLeftArmwear.rotateAngleX = -1.7001F; - this.fakeRightArmwear.rotateAngleX = -1.7001F; - } - - this.fakeRightArm.rotateAngleY = -0.15f; - this.fakeLeftArm.rotateAngleY = 0.15f; - this.fakeLeftArmwear.rotateAngleY = 0.15f; - this.fakeRightArmwear.rotateAngleY = -0.15f; - } - - this.fakeRightArm.rotateAngleZ = 0F; - this.fakeLeftArm.rotateAngleZ = 0F; - this.fakeLeftArmwear.rotateAngleZ = 0F; - this.fakeRightArmwear.rotateAngleZ = 0F; - } - - model.bipedBody.addChild(this.fakeLeftArm); - model.bipedBody.addChild(this.fakeRightArm); - - if (player.isWearing(EnumPlayerModelParts.LEFT_SLEEVE)) - { - model.bipedBody.addChild(this.fakeLeftArmwear); - } - if (player.isWearing(EnumPlayerModelParts.RIGHT_SLEEVE)) - { - model.bipedBody.addChild(this.fakeRightArmwear); - } - } - else - { - model.bipedLeftArm.isHidden = false; - model.bipedRightArm.isHidden = false; - model.bipedLeftArmwear.isHidden = false; - model.bipedRightArmwear.isHidden = false; - - CarryOnOverride overrider = ScriptChecker.getOverride(player); - if (overrider != null) - { - if (model.bipedBody.childModels != null && !model.bipedBody.childModels.isEmpty()) - { - for (int k = 0; k < model.bipedBody.childModels.size(); k++) - { - double[] rotLeft1 = ScriptParseHelper.getXYZArray(overrider.getRenderRotationLeftArm()); - double[] rotRight1 = ScriptParseHelper.getXYZArray(overrider.getRenderRotationRightArm()); - - float rotX = model.bipedBody.childModels.get(k).rotateAngleX; - float rotY = model.bipedBody.childModels.get(k).rotateAngleY; - float rotZ = model.bipedBody.childModels.get(k).rotateAngleZ; - - if (rotLeft1[0] == rotX || rotLeft1[1] == rotY || rotRight1[2] == rotZ || rotRight1[0] == rotX || rotRight1[1] == rotY || rotRight1[2] == rotZ || rotX == rotLeft1[0] - 0.5f || rotX == rotRight1[0] - 0.5f) - { - model.bipedBody.childModels.remove(k); - k = k - 1; - } - } - } - } - else - { - if (model.bipedBody.childModels != null && !model.bipedBody.childModels.isEmpty()) - { - for (int k = 0; k < model.bipedBody.childModels.size(); k++) - { - float chkRot = model.bipedBody.childModels.get(k).rotateAngleX; - - if (chkRot == -0.9001F || chkRot == -1.2001F || chkRot == -1.4001F || chkRot == -1.7001F) - { - model.bipedBody.childModels.remove(k); - k = k - 1; - } - } - } - } - } - - if (stack.isEmpty() || stack.getItem() != RegistrationHandler.itemTile && stack.getItem() != RegistrationHandler.itemEntity) - { - model.bipedLeftArm.isHidden = false; - model.bipedRightArm.isHidden = false; - model.bipedLeftArmwear.isHidden = false; - model.bipedRightArmwear.isHidden = false; - } - } - } - - public static boolean isChest(Block block) - { - return block == Blocks.CHEST || block == Blocks.ENDER_CHEST || block == Blocks.TRAPPED_CHEST; - } - - @SideOnly(Side.CLIENT) - private static RenderPlayer getRenderPlayer(AbstractClientPlayer player) - { - Minecraft mc = Minecraft.getMinecraft(); - RenderManager manager = mc.getRenderManager(); - return manager.getSkinMap().get(player.getSkinType()); - } - - @SideOnly(Side.CLIENT) - private static ModelPlayer getPlayerModel(AbstractClientPlayer player) - { - return getRenderPlayer(player).getMainModel(); - } - - @SubscribeEvent - @SideOnly(Side.CLIENT) - public void hideItems(RenderPlayerEvent.Specials.Pre event) - { - EntityPlayer player = event.getEntityPlayer(); - ItemStack stack = player.getHeldItemMainhand(); - - if (stack != null && (stack.getItem() == RegistrationHandler.itemTile || stack.getItem() == RegistrationHandler.itemEntity)) - { - event.setRenderItem(false); - } - } -} diff --git a/src/main/java/tschipp/carryon/client/gui/GuiConfigCarryOn.java b/src/main/java/tschipp/carryon/client/gui/GuiConfigCarryOn.java deleted file mode 100644 index d09828c..0000000 --- a/src/main/java/tschipp/carryon/client/gui/GuiConfigCarryOn.java +++ /dev/null @@ -1,48 +0,0 @@ -package tschipp.carryon.client.gui; - -import java.util.List; - -import net.minecraft.client.gui.GuiButton; -import net.minecraft.client.gui.GuiScreen; -import net.minecraftforge.common.config.ConfigCategory; -import net.minecraftforge.common.config.ConfigElement; -import net.minecraftforge.common.config.Configuration; -import net.minecraftforge.fml.client.config.GuiConfig; -import net.minecraftforge.fml.client.config.IConfigElement; -import tschipp.carryon.CarryOn; -import tschipp.carryon.common.config.CarryOnConfig; - -public class GuiConfigCarryOn extends GuiConfig -{ - private static final String LANG_PREFIX = CarryOn.MODID + ".category."; - - public GuiConfigCarryOn(GuiScreen parent) { - super(parent, getConfigElements(), CarryOn.MODID, false, false, "Carry On Configuration"); - } - - private static List getConfigElements() { - - final Configuration configuration = CarryOnConfig.EventHandler.getConfiguration(); - - final ConfigCategory topLevelCategory = configuration.getCategory(Configuration.CATEGORY_GENERAL); - topLevelCategory.getChildren() - .forEach(configCategory -> configCategory.setLanguageKey(GuiConfigCarryOn.LANG_PREFIX + configCategory.getName())); - - return new ConfigElement(topLevelCategory).getChildElements(); - } - - @Override - public void initGui() { - super.initGui(); - } - - @Override - public void drawScreen(int mouseX, int mouseY, float partialTicks) { - super.drawScreen(mouseX, mouseY, partialTicks); - } - - @Override - protected void actionPerformed(GuiButton button) { - super.actionPerformed(button); - } -} diff --git a/src/main/java/tschipp/carryon/client/gui/GuiFactoryCarryOn.java b/src/main/java/tschipp/carryon/client/gui/GuiFactoryCarryOn.java deleted file mode 100644 index dd74b43..0000000 --- a/src/main/java/tschipp/carryon/client/gui/GuiFactoryCarryOn.java +++ /dev/null @@ -1,47 +0,0 @@ -package tschipp.carryon.client.gui; - -import java.util.Set; - -import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.GuiScreen; -import net.minecraftforge.fml.client.IModGuiFactory; - -public class GuiFactoryCarryOn implements IModGuiFactory -{ - @Override - public void initialize(Minecraft minecraftInstance) { - // Do nothing - } - - @Override - public Class mainConfigGuiClass() { - return GuiConfigCarryOn.class; - } - - @Override - public Set runtimeGuiCategories() { - return null; - } - - @Override - public RuntimeOptionGuiHandler getHandlerFor(RuntimeOptionCategoryElement element) { - return null; - } - - - @Override - public boolean hasConfigGui() - { - return true; - } - - @Override - public GuiScreen createConfigGui(GuiScreen parentScreen) - { - - return new GuiConfigCarryOn(parentScreen); - } - - - -} \ No newline at end of file diff --git a/src/main/java/tschipp/carryon/client/keybinds/CarryOnKeybinds.java b/src/main/java/tschipp/carryon/client/keybinds/CarryOnKeybinds.java deleted file mode 100644 index 25eaad2..0000000 --- a/src/main/java/tschipp/carryon/client/keybinds/CarryOnKeybinds.java +++ /dev/null @@ -1,44 +0,0 @@ -package tschipp.carryon.client.keybinds; - -import org.lwjgl.input.Keyboard; - -import net.minecraft.client.settings.KeyBinding; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraftforge.fml.client.registry.ClientRegistry; -import net.minecraftforge.fml.relauncher.Side; -import net.minecraftforge.fml.relauncher.SideOnly; - -public class CarryOnKeybinds -{ - - public static final String KEYBIND_KEY = "carryOnKeyPressed"; - public static KeyBinding carryKey; - - @SideOnly(Side.CLIENT) - public static void init() - { - carryKey = new KeyBinding("key.carry.desc", Keyboard.KEY_LSHIFT, "key.carry.category"); - - ClientRegistry.registerKeyBinding(carryKey); - } - - public static boolean isKeyPressed(EntityPlayer player) - { - NBTTagCompound tag = player.getEntityData(); - if(tag != null && tag.hasKey(KEYBIND_KEY)) - { - return tag.getBoolean(KEYBIND_KEY); - } - return false; - } - - public static void setKeyPressed(EntityPlayer player, boolean pressed) - { - NBTTagCompound tag = player.getEntityData(); - tag.setBoolean(KEYBIND_KEY, pressed); - } - - - -} diff --git a/src/main/java/tschipp/carryon/client/model/ModelPlayerCarrying.java b/src/main/java/tschipp/carryon/client/model/ModelPlayerCarrying.java deleted file mode 100644 index 956366f..0000000 --- a/src/main/java/tschipp/carryon/client/model/ModelPlayerCarrying.java +++ /dev/null @@ -1,23 +0,0 @@ -package tschipp.carryon.client.model; - -import net.minecraft.client.model.ModelPlayer; -import net.minecraft.entity.Entity; - -public class ModelPlayerCarrying extends ModelPlayer -{ - - public ModelPlayerCarrying(float modelSize, boolean smallArmsIn) - { - super(modelSize, smallArmsIn); - } - - @Override - public void setRotationAngles(float limbSwing, float limbSwingAmount, float ageInTicks, float netHeadYaw, float headPitch, float scaleFactor, Entity entityIn) - { - super.setRotationAngles(limbSwing, limbSwingAmount, ageInTicks, netHeadYaw, headPitch, scaleFactor, entityIn); - - - - } - -} diff --git a/src/main/java/tschipp/carryon/common/CommonProxy.java b/src/main/java/tschipp/carryon/common/CommonProxy.java deleted file mode 100644 index 123c13b..0000000 --- a/src/main/java/tschipp/carryon/common/CommonProxy.java +++ /dev/null @@ -1,63 +0,0 @@ -package tschipp.carryon.common; - -import java.io.FileNotFoundException; - -import com.google.gson.JsonIOException; -import com.google.gson.JsonSyntaxException; - -import net.minecraft.nbt.NBTException; -import net.minecraftforge.fml.common.Mod.EventHandler; -import net.minecraftforge.fml.common.event.FMLInitializationEvent; -import net.minecraftforge.fml.common.event.FMLPostInitializationEvent; -import net.minecraftforge.fml.common.event.FMLPreInitializationEvent; -import net.minecraftforge.fml.common.network.NetworkRegistry; -import net.minecraftforge.fml.relauncher.Side; -import tschipp.carryon.CarryOn; -import tschipp.carryon.common.handler.RegistrationHandler; -import tschipp.carryon.common.scripting.ScriptReader; -import tschipp.carryon.network.client.CarrySlotPacket; -import tschipp.carryon.network.client.CarrySlotPacketHandler; -import tschipp.carryon.network.client.ScriptReloadPacket; -import tschipp.carryon.network.client.ScriptReloadPacketHandler; -import tschipp.carryon.network.server.SyncKeybindPacket; -import tschipp.carryon.network.server.SyncKeybindPacketHandler; - -public class CommonProxy -{ - - @EventHandler - public void preInit(FMLPreInitializationEvent event) - { - ScriptReader.preInit(event); - - CarryOn.network = NetworkRegistry.INSTANCE.newSimpleChannel("CarryOn"); - - CarryOn.network.registerMessage(SyncKeybindPacketHandler.class, SyncKeybindPacket.class, 0, Side.SERVER); - CarryOn.network.registerMessage(CarrySlotPacketHandler.class, CarrySlotPacket.class, 1, Side.CLIENT); - CarryOn.network.registerMessage(ScriptReloadPacketHandler.class, ScriptReloadPacket.class, 2, Side.CLIENT); - - RegistrationHandler.regItems(); - RegistrationHandler.regCommonEvents(); - } - - @EventHandler - public void init(FMLInitializationEvent event) - { - try - { - ScriptReader.parseScripts(); - } - catch (JsonIOException | JsonSyntaxException | FileNotFoundException | NBTException e) - { - e.printStackTrace(); - } - RegistrationHandler.regOverrideList(); - RegistrationHandler.regCaps(); - } - - @EventHandler - public void postInit(FMLPostInitializationEvent e) - { - } - -} diff --git a/src/main/java/tschipp/carryon/common/capabilities/IPosition.java b/src/main/java/tschipp/carryon/common/capabilities/IPosition.java deleted file mode 100644 index 35d90e2..0000000 --- a/src/main/java/tschipp/carryon/common/capabilities/IPosition.java +++ /dev/null @@ -1,16 +0,0 @@ -package tschipp.carryon.common.capabilities; - -import net.minecraft.util.math.BlockPos; - -public interface IPosition { - - public BlockPos getPos(); - - public void setPos(BlockPos pos); - - public boolean isBlockActivated(); - - public void setBlockActivated(boolean b); - - -} diff --git a/src/main/java/tschipp/carryon/common/capabilities/PositionProvider.java b/src/main/java/tschipp/carryon/common/capabilities/PositionProvider.java deleted file mode 100644 index 6f46a79..0000000 --- a/src/main/java/tschipp/carryon/common/capabilities/PositionProvider.java +++ /dev/null @@ -1,37 +0,0 @@ -package tschipp.carryon.common.capabilities; - -import net.minecraft.nbt.NBTBase; -import net.minecraft.util.EnumFacing; -import net.minecraftforge.common.capabilities.Capability; -import net.minecraftforge.common.capabilities.CapabilityInject; -import net.minecraftforge.common.capabilities.ICapabilitySerializable; - -public class PositionProvider implements ICapabilitySerializable { - - @CapabilityInject(IPosition.class) - public static final Capability POSITION_CAPABILITY = null; - - private IPosition instance = POSITION_CAPABILITY.getDefaultInstance(); - - - @Override - public boolean hasCapability(Capability capability, EnumFacing facing) { - return capability == POSITION_CAPABILITY; - } - - @Override - public T getCapability(Capability capability, EnumFacing facing) { - return capability == POSITION_CAPABILITY ? POSITION_CAPABILITY.cast(instance) : null; - } - - @Override - public NBTBase serializeNBT() { - return POSITION_CAPABILITY.getStorage().writeNBT(POSITION_CAPABILITY, instance, null); - } - - @Override - public void deserializeNBT(NBTBase nbt) { - POSITION_CAPABILITY.getStorage().readNBT(POSITION_CAPABILITY, instance, null, nbt); - } - -} diff --git a/src/main/java/tschipp/carryon/common/capabilities/PositionStorage.java b/src/main/java/tschipp/carryon/common/capabilities/PositionStorage.java deleted file mode 100644 index d3a4973..0000000 --- a/src/main/java/tschipp/carryon/common/capabilities/PositionStorage.java +++ /dev/null @@ -1,41 +0,0 @@ -package tschipp.carryon.common.capabilities; - -import net.minecraft.nbt.NBTBase; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.util.EnumFacing; -import net.minecraft.util.math.BlockPos; -import net.minecraftforge.common.capabilities.Capability; -import net.minecraftforge.common.capabilities.Capability.IStorage; - -public class PositionStorage implements IStorage { - - @Override - public NBTBase writeNBT(Capability capability, IPosition instance, EnumFacing side) { - - NBTTagCompound tag = new NBTTagCompound(); - - tag.setBoolean("blockActivated", instance.isBlockActivated()); - tag.setInteger("x", instance.getPos().getX()); - tag.setInteger("y", instance.getPos().getY()); - tag.setInteger("z", instance.getPos().getZ()); - - return tag; - - } - - @Override - public void readNBT(Capability capability, IPosition instance, EnumFacing side, NBTBase nbt) { - - NBTTagCompound tag = (NBTTagCompound) nbt; - - int x = tag.getInteger("x"); - int y = tag.getInteger("y"); - int z = tag.getInteger("z"); - - BlockPos pos = new BlockPos(x,y,z); - - instance.setPos(pos); - instance.setBlockActivated(tag.getBoolean("blockActivated")); - } - -} diff --git a/src/main/java/tschipp/carryon/common/capabilities/TEPosition.java b/src/main/java/tschipp/carryon/common/capabilities/TEPosition.java deleted file mode 100644 index 7398fc0..0000000 --- a/src/main/java/tschipp/carryon/common/capabilities/TEPosition.java +++ /dev/null @@ -1,34 +0,0 @@ -package tschipp.carryon.common.capabilities; - -import net.minecraft.util.math.BlockPos; - -public class TEPosition implements IPosition { - - private BlockPos pos = new BlockPos(0, 0, 0); - private boolean blockActivated = false; - - @Override - public BlockPos getPos() - { - return pos; - } - @Override - public void setPos(BlockPos pos) - { - this.pos = pos; - } - @Override - public boolean isBlockActivated() - { - return blockActivated; - } - @Override - public void setBlockActivated(boolean b) - { - this.blockActivated = b; - } - - - - -} diff --git a/src/main/java/tschipp/carryon/common/capabilities/event/PositionClientEvents.java b/src/main/java/tschipp/carryon/common/capabilities/event/PositionClientEvents.java deleted file mode 100644 index 1d6e3e8..0000000 --- a/src/main/java/tschipp/carryon/common/capabilities/event/PositionClientEvents.java +++ /dev/null @@ -1,91 +0,0 @@ -package tschipp.carryon.common.capabilities.event; - -import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.inventory.GuiContainer; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.tileentity.TileEntity; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; -import net.minecraftforge.client.event.GuiScreenEvent; -import net.minecraftforge.event.entity.player.PlayerContainerEvent; -import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; -import net.minecraftforge.fml.common.gameevent.TickEvent.PlayerTickEvent; -import net.minecraftforge.fml.relauncher.Side; -import net.minecraftforge.fml.relauncher.SideOnly; -import tschipp.carryon.common.capabilities.IPosition; -import tschipp.carryon.common.capabilities.PositionProvider; - -public class PositionClientEvents -{ - - @SideOnly(Side.CLIENT) - @SubscribeEvent - public void onGui(GuiScreenEvent.DrawScreenEvent event) - { - if (event.getGui() != null) - { - EntityPlayer player = Minecraft.getMinecraft().player; - boolean inventory = event.getGui() instanceof GuiContainer; - - if (player != null && inventory) - { - if(player.hasCapability(PositionProvider.POSITION_CAPABILITY, null)) - { - IPosition cap = player.getCapability(PositionProvider.POSITION_CAPABILITY, null); - if(cap.isBlockActivated()) - { - World world = player.world; - BlockPos pos = cap.getPos(); - if(world != null) - { - TileEntity te = world.getTileEntity(pos); - if(te == null) - { -// player.openContainer = null; - Minecraft.getMinecraft().currentScreen = null; - Minecraft.getMinecraft().setIngameFocus(); - cap.setBlockActivated(false); - cap.setPos(new BlockPos(0,0,0)); - } - } - } - } - } - } - } - - @SideOnly(Side.CLIENT) - @SubscribeEvent - public void onGuiClose(PlayerContainerEvent.Close event) - { - EntityPlayer player = event.getEntityPlayer(); - if(player.hasCapability(PositionProvider.POSITION_CAPABILITY, null)) - { - IPosition cap = player.getCapability(PositionProvider.POSITION_CAPABILITY, null); - cap.setBlockActivated(false); - cap.setPos(new BlockPos(0,0,0)); - } - } - - - @SideOnly(Side.CLIENT) - @SubscribeEvent - public void onPlayerTick(PlayerTickEvent event) - { - if (event.side == Side.CLIENT) - { - EntityPlayer player = event.player; - if (player.hasCapability(PositionProvider.POSITION_CAPABILITY, null)) - { - IPosition cap = player.getCapability(PositionProvider.POSITION_CAPABILITY, null); - if (cap.isBlockActivated() && Minecraft.getMinecraft().currentScreen == null) - { - cap.setBlockActivated(false); - cap.setPos(new BlockPos(0, 0, 0)); - } - } - } - } - - -} diff --git a/src/main/java/tschipp/carryon/common/capabilities/event/PositionCommonEvents.java b/src/main/java/tschipp/carryon/common/capabilities/event/PositionCommonEvents.java deleted file mode 100644 index ae25abd..0000000 --- a/src/main/java/tschipp/carryon/common/capabilities/event/PositionCommonEvents.java +++ /dev/null @@ -1,60 +0,0 @@ -package tschipp.carryon.common.capabilities.event; - -import net.minecraft.entity.Entity; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.tileentity.TileEntity; -import net.minecraft.util.ResourceLocation; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; -import net.minecraftforge.common.util.FakePlayer; -import net.minecraftforge.event.AttachCapabilitiesEvent; -import net.minecraftforge.event.entity.player.PlayerInteractEvent; -import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; -import tschipp.carryon.CarryOn; -import tschipp.carryon.common.capabilities.IPosition; -import tschipp.carryon.common.capabilities.PositionProvider; - -public class PositionCommonEvents -{ - - @SubscribeEvent - public void onAttachCaps(AttachCapabilitiesEvent event) - { - if (event.getObject() instanceof EntityPlayer) - { - event.addCapability(new ResourceLocation(CarryOn.MODID, "position"), new PositionProvider()); - } - - } - - @SubscribeEvent - public void onBlockRight(PlayerInteractEvent.RightClickBlock event) - { - BlockPos pos = event.getPos(); - World world = event.getWorld(); - EntityPlayer player = event.getEntityPlayer(); - - if (event.isCanceled()) - return; - - if (player == null) - return; - - if (player instanceof FakePlayer) - return; - - TileEntity te = world.getTileEntity(pos); - if (te != null) - { - if (player.hasCapability(PositionProvider.POSITION_CAPABILITY, null)) - { - IPosition cap = player.getCapability(PositionProvider.POSITION_CAPABILITY, null); - cap.setBlockActivated(true); - cap.setPos(pos); - } - } - } - - - -} diff --git a/src/main/java/tschipp/carryon/common/command/CommandCarryOn.java b/src/main/java/tschipp/carryon/common/command/CommandCarryOn.java deleted file mode 100644 index 571a8ff..0000000 --- a/src/main/java/tschipp/carryon/common/command/CommandCarryOn.java +++ /dev/null @@ -1,194 +0,0 @@ -package tschipp.carryon.common.command; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; - -import net.minecraft.command.CommandBase; -import net.minecraft.command.CommandException; -import net.minecraft.command.ICommand; -import net.minecraft.command.ICommandSender; -import net.minecraft.command.WrongUsageException; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.entity.player.EntityPlayerMP; -import net.minecraft.item.ItemStack; -import net.minecraft.server.MinecraftServer; -import net.minecraft.util.math.BlockPos; -import net.minecraft.util.text.TextComponentString; -import net.minecraftforge.fml.common.network.NetworkRegistry.TargetPoint; -import tschipp.carryon.CarryOn; -import tschipp.carryon.common.handler.CustomPickupOverrideHandler; -import tschipp.carryon.common.handler.ModelOverridesHandler; -import tschipp.carryon.common.handler.RegistrationHandler; -import tschipp.carryon.common.item.ItemEntity; -import tschipp.carryon.common.item.ItemTile; -import tschipp.carryon.common.scripting.ScriptReader; -import tschipp.carryon.network.client.CarrySlotPacket; - -public class CommandCarryOn extends CommandBase implements ICommand -{ - - private final List names; - - public CommandCarryOn() - { - names = new ArrayList(); - names.add("carryon"); - } - - @Override - public int compareTo(ICommand o) - { - return this.getName().compareTo(o.getName()); - } - - @Override - public String getName() - { - return "carryon"; - } - - @Override - public String getUsage(ICommandSender sender) - { - - return "/carryon "; - } - - @Override - public List getAliases() - { - return this.names; - } - - @Override - public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException - { - if (args.length > 0) - { - // Handling clear - if (args[0].toLowerCase().equals("clear")) - { - if (sender instanceof EntityPlayer) - { - EntityPlayer player = (EntityPlayer) sender; - - int cleared = 0; - cleared += player.inventory.clearMatchingItems(RegistrationHandler.itemTile, 0, 64, null); - cleared += player.inventory.clearMatchingItems(RegistrationHandler.itemEntity, 0, 64, null); - - CarryOn.network.sendTo(new CarrySlotPacket(9, player.getEntityId()), (EntityPlayerMP) player); - - if (cleared != 1) - player.sendMessage(new TextComponentString("Cleared " + cleared + " Items!")); - else - player.sendMessage(new TextComponentString("Cleared " + cleared + " Item!")); - } - - } - // Handling debug - else if (args[0].toLowerCase().equals("debug")) - { - - if (sender instanceof EntityPlayer) - { - EntityPlayer player = (EntityPlayer) sender; - ItemStack main = player.getHeldItemMainhand(); - if (!main.isEmpty() && main.getItem() == RegistrationHandler.itemTile) - { - player.sendMessage(new TextComponentString("Block: " + ItemTile.getBlock(main))); - player.sendMessage(new TextComponentString("BlockState: " + ItemTile.getBlockState(main))); - player.sendMessage(new TextComponentString("Meta: " + ItemTile.getMeta(main))); - player.sendMessage(new TextComponentString("ItemStack: " + ItemTile.getItemStack(main))); - - if(ModelOverridesHandler.hasCustomOverrideModel(ItemTile.getBlockState(main), ItemTile.getTileData(main))) - player.sendMessage(new TextComponentString("Override Model: " + ModelOverridesHandler.getOverrideObject(ItemTile.getBlockState(main), ItemTile.getTileData(main)))); - - if(CustomPickupOverrideHandler.hasSpecialPickupConditions(ItemTile.getBlockState(main))) - player.sendMessage(new TextComponentString("Custom Pickup Condition: " + CustomPickupOverrideHandler.getPickupCondition(ItemTile.getBlockState(main)))); - - - CarryOn.LOGGER.info("Block: " + ItemTile.getBlock(main)); - CarryOn.LOGGER.info("BlockState: " + ItemTile.getBlockState(main)); - CarryOn.LOGGER.info("Meta: " + ItemTile.getMeta(main)); - CarryOn.LOGGER.info("ItemStack: " + ItemTile.getItemStack(main)); - - if(ModelOverridesHandler.hasCustomOverrideModel(ItemTile.getBlockState(main), ItemTile.getTileData(main))) - CarryOn.LOGGER.info("Override Model: " + ModelOverridesHandler.getOverrideObject(ItemTile.getBlockState(main), ItemTile.getTileData(main))); - - if(CustomPickupOverrideHandler.hasSpecialPickupConditions(ItemTile.getBlockState(main))) - CarryOn.LOGGER.info("Custom Pickup Condition: " + CustomPickupOverrideHandler.getPickupCondition(ItemTile.getBlockState(main))); - - } - else if(!main.isEmpty() && main.getItem() == RegistrationHandler.itemEntity) - { - player.sendMessage(new TextComponentString("Entity: " + ItemEntity.getEntity(main, server.getEntityWorld()))); - player.sendMessage(new TextComponentString("Entity Name: " + ItemEntity.getEntityName(main))); - - if(CustomPickupOverrideHandler.hasSpecialPickupConditions(ItemEntity.getEntity(main, server.getEntityWorld()))) - player.sendMessage(new TextComponentString("Custom Pickup Condition: " + CustomPickupOverrideHandler.getPickupCondition(ItemEntity.getEntity(main, server.getEntityWorld())))); - - CarryOn.LOGGER.info("Entity: " + ItemEntity.getEntity(main, server.getEntityWorld())); - CarryOn.LOGGER.info("Entity Name: " + ItemEntity.getEntityName(main)); - - if(CustomPickupOverrideHandler.hasSpecialPickupConditions(ItemEntity.getEntity(main, server.getEntityWorld()))) - CarryOn.LOGGER.info("Custom Pickup Condition: " + CustomPickupOverrideHandler.getPickupCondition(ItemEntity.getEntity(main, server.getEntityWorld()))); - - } - } - } - else - { - throw new WrongUsageException(this.getUsage(sender)); - } - - } - else - { - throw new WrongUsageException(this.getUsage(sender)); - } - - } - - @Override - public boolean checkPermission(MinecraftServer server, ICommandSender sender) - { - return true; - } - - @Override - public List getTabCompletions(MinecraftServer server, ICommandSender sender, String[] args, BlockPos pos) - { - - if (args.length > 0) - { - if (args.length == 1) - { - return CommandBase.getListOfStringsMatchingLastWord(args, "debug", "clear"); - } - - else - { - return Collections.emptyList(); - } - - } - - return Collections.emptyList(); - - } - - @Override - public boolean isUsernameIndex(String[] args, int index) - { - - return false; - } - - @Override - public int getRequiredPermissionLevel() - { - return 2; - } - -} diff --git a/src/main/java/tschipp/carryon/common/command/CommandCarryOnReload.java b/src/main/java/tschipp/carryon/common/command/CommandCarryOnReload.java deleted file mode 100644 index 9f5c48e..0000000 --- a/src/main/java/tschipp/carryon/common/command/CommandCarryOnReload.java +++ /dev/null @@ -1,80 +0,0 @@ -package tschipp.carryon.common.command; - -import java.util.Collections; -import java.util.List; - -import net.minecraft.command.CommandBase; -import net.minecraft.command.CommandException; -import net.minecraft.command.ICommandSender; -import net.minecraft.server.MinecraftServer; -import net.minecraft.util.math.BlockPos; -import net.minecraft.util.text.TextComponentString; -import tschipp.carryon.CarryOn; -import tschipp.carryon.common.config.CarryOnConfig; -import tschipp.carryon.common.scripting.ScriptReader; -import tschipp.carryon.network.client.ScriptReloadPacket; - -public class CommandCarryOnReload extends CommandBase -{ - - @Override - public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException - { - - if (CarryOnConfig.settings.useScripts) - { - ScriptReader.reloadScripts(); - CarryOn.network.sendToAll(new ScriptReloadPacket()); - sender.sendMessage(new TextComponentString("Successfully reloaded scripts!")); - } - else - sender.sendMessage(new TextComponentString("To use custom Carry On scripts, enable them in the config!")); - - } - - @Override - public boolean checkPermission(MinecraftServer server, ICommandSender sender) - { - return sender.canUseCommand(this.getRequiredPermissionLevel(), this.getName()); - } - - @Override - public int getRequiredPermissionLevel() - { - return 2; - } - - @Override - public List getTabCompletions(MinecraftServer server, ICommandSender sender, String[] args, BlockPos pos) - { - - if (args.length > 0) - { - if (args.length == 1) - { - return CommandBase.getListOfStringsMatchingLastWord(args, "reload"); - } - - else - { - return Collections.emptyList(); - } - - } - - return Collections.emptyList(); - - } - - @Override - public String getName() - { - return "reloadscripts"; - } - - @Override - public String getUsage(ICommandSender sender) - { - return "/reloadscripts"; - } -} diff --git a/src/main/java/tschipp/carryon/common/config/CarryOnConfig.java b/src/main/java/tschipp/carryon/common/config/CarryOnConfig.java deleted file mode 100644 index 5bd4b75..0000000 --- a/src/main/java/tschipp/carryon/common/config/CarryOnConfig.java +++ /dev/null @@ -1,102 +0,0 @@ -package tschipp.carryon.common.config; - -import java.io.File; -import java.lang.invoke.MethodHandle; -import java.util.Map; -import java.util.Optional; - -import net.minecraftforge.common.config.Config; -import net.minecraftforge.common.config.ConfigManager; -import net.minecraftforge.common.config.Configuration; -import net.minecraftforge.fml.client.config.IConfigElement; -import net.minecraftforge.fml.client.event.ConfigChangedEvent; -import net.minecraftforge.fml.common.Mod; -import net.minecraftforge.fml.common.Mod.EventHandler; -import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; -import tschipp.carryon.CarryOn; -import tschipp.carryon.common.helper.ReflectionUtil; - -@Config(modid = CarryOn.MODID) -public class CarryOnConfig { - - @Config.LangKey(CarryOn.MODID) - @Config.Comment("General Mod Settings") - public static Configs.Settings settings = new Configs.Settings(); - - @Config.LangKey(CarryOn.MODID) - @Config.Comment("Blacklist for Blocks and Entities") - public static Configs.Blacklist blacklist = new Configs.Blacklist(); - - @Config.LangKey(CarryOn.MODID) - @Config.Comment("Whitelist for Blocks and Entities (useWhitelist must be true!)") - public static Configs.WhiteList whitelist = new Configs.WhiteList(); - - @Config.LangKey(CarryOn.MODID) - @Config.Comment("Model Overrides based on NBT or on Meta. Advanced Users Only!") - public static Configs.ModelOverrides modelOverrides = new Configs.ModelOverrides(); - - @Config.LangKey(CarryOn.MODID) - @Config.Comment("Custom Pickup Conditions for certain blocks. ONLY WORKS WHEN GAMESTAGES IS INSTALLED! Advanced Users Only!") - public static Configs.CustomPickupConditions customPickupConditions = new Configs.CustomPickupConditions(); - - @Mod.EventBusSubscriber - public static class EventHandler { - - /** - * The {@link ConfigManager#CONFIGS} getter. - */ - private static final MethodHandle CONFIGS_GETTER = ReflectionUtil.findFieldGetter(ConfigManager.class, "CONFIGS"); - - - /** - * The {@link Configuration} instance. - */ - private static Configuration configuration; - - /** - * Get the {@link Configuration} instance from {@link ConfigManager}. - *

- * TODO: Use a less hackish method of getting the - * {@link Configuration}/{@link IConfigElement}s when possible. - * - * @return The Configuration instance - */ - public static Configuration getConfiguration() { - if (EventHandler.configuration == null) - try { - final String fileName = CarryOn.MODID + ".cfg"; - - @SuppressWarnings("unchecked") - final Map configsMap = (Map) EventHandler.CONFIGS_GETTER - .invokeExact(); - - final Optional> entryOptional = configsMap.entrySet().stream() - .filter(entry -> fileName.equals(new File(entry.getKey()).getName())).findFirst(); - - entryOptional - .ifPresent(stringConfigurationEntry -> EventHandler.configuration = stringConfigurationEntry - .getValue()); - } catch (Throwable throwable) { - throwable.printStackTrace(); - } - - return EventHandler.configuration; - } - - /** - * Inject the new values and save to the config file when the config has - * been changed from the GUI. - * - * @param event - * The event - */ - @SubscribeEvent - public static void onConfigChanged(ConfigChangedEvent.OnConfigChangedEvent event) { - if (event.getModID().equals(CarryOn.MODID)) - ConfigManager.load(CarryOn.MODID, Config.Type.INSTANCE); - - } - - } - -} diff --git a/src/main/java/tschipp/carryon/common/config/Configs.java b/src/main/java/tschipp/carryon/common/config/Configs.java deleted file mode 100644 index fe44531..0000000 --- a/src/main/java/tschipp/carryon/common/config/Configs.java +++ /dev/null @@ -1,262 +0,0 @@ -package tschipp.carryon.common.config; - -import net.minecraftforge.common.config.Config; -import net.minecraftforge.common.config.Config.Comment; - -public class Configs { - - public static class Settings - { - @Comment("If the front of the Tile Entities should face the player or should face outward") - public boolean facePlayer = false; - - @Comment("More complex Tile Entities slow down the player more") - public boolean heavyTiles = true; - - @Comment("Allow all blocks to be picked up, not just Tile Entites") - public boolean pickupAllBlocks = false; - - @Comment("Whether Blocks and Entities slow the creative player down when carried") - public boolean slownessInCreative = true; - - @Config.RangeDouble(min = 0) - @Comment("Maximum distance from where Blocks and Entities can be picked up") - public double maxDistance = 2.5; - - @Config.RangeDouble(min = 0, max = 10) - @Comment("Max width of entities that can be picked up in survival mode") - public float maxEntityWidth = 1.5f; - - @Config.RangeDouble(min = 0, max = 10) - @Comment("Max height of entities that can be picked up in survival mode") - public float maxEntityHeight = 1.5f; - - @Comment("Whether hostile mobs should be able to picked up in survival mode") - public boolean pickupHostileMobs = false; - - @Comment("Larger Entities slow down the player more") - public boolean heavyEntities = true; - - @Comment("Slowness multiplier for blocks") - public double blockSlownessMultiplier = 1.0; - - @Comment("Slowness multiplier for entities") - public double entitySlownessMultiplier = 1.0; - - @Comment("Arms should render on sides when carrying") - public boolean renderArms = true; - - @Comment("Allow babies to be carried even when adult mob is blacklisted (or not whitelisted)") - public boolean allowBabies = false; - - @Comment("Use Whitelist instead of Blacklist for Blocks") - public boolean useWhitelistBlocks=false; - - @Comment("Use Whitelist instead of Blacklist for Entities") - public boolean useWhitelistEntities=false; - - @Comment("Whether the player can hit blocks and entities while carrying or not") - public boolean hitWhileCarrying=false; - - @Comment("Whether the player drops the carried object when hit or not") - public boolean dropCarriedWhenHit=false; - - @Config.RequiresMcRestart() - @Comment("Use custom Pickup Scripts. Having this set to false, will not allow you to run scripts, but will increase your performance") - public boolean useScripts=false; - - @Comment("Allows entities to be stacked using Carry On") - public boolean stackableEntities = true; - - @Config.RangeInt(min = 1) - @Comment("Maximum stack limit for entities") - public int maxEntityStackLimit = 10; - - @Comment("Whether entities' size matters when stacking or not") - public boolean entitySizeMattersStacking = true; - } - - public static class WhiteList - { - @Config.RequiresMcRestart() - @Comment("Entities that CAN be picked up") - public String[] allowedEntities=new String[] - { - }; - - @Config.RequiresMcRestart() - @Comment("Blocks that CAN be picked up") - public String[] allowedBlocks=new String[] - { - }; - } - - public static class Blacklist - { - @Config.RequiresMcRestart() - @Comment("Tile Entities that cannot be picked up") - public String[] forbiddenTiles = new String[] - { - "minecraft:end_portal", - "minecraft:end_gateway", - "minecraft:double_plant", - "minecraft:bed", - "minecraft:wooden_door", - "minecraft:iron_door", - "minecraft:spruce_door", - "minecraft:birch_door", - "minecraft:jungle_door", - "minecraft:acacia_door", - "minecraft:dark_oak_door", - "minecraft:waterlily", - "minecraft:cake", - "animania:block_trough", - "animania:block_invisiblock", - "colossalchests:*", - "ic2:*", - "bigreactors:*", - "forestry:*", - "tconstruct:*", - "rustic:*", - "botania:*", - "astralsorcery:*", - "quark:colored_bed_*", - "immersiveengineering:*", - "embers:block_furnace", - "embers:ember_bore", - "embers:ember_activator", - "embers:mixer", - "embers:heat_coil", - "embers:large_tank", - "embers:crystal_cell", - "embers:alchemy_pedestal", - "embers:boiler", - "embers:combustor", - "embers:catalzyer", - "embers:field_chart", - "embers:inferno_forge", - "storagedrawers:framingtable", - "skyresources:*", - "lootbags:*", - "exsartagine:*", - "aquamunda:tank", - "opencomputers:*", - "malisisdoors:*", - "industrialforegoing:*", - "minecolonies:*", - }; - - @Config.RequiresMcRestart() - @Comment("Entities that cannot be picked up") - public String[] forbiddenEntities = new String[] - { - "minecraft:ender_crystal", - "minecraft:ender_dragon", - "minecraft:ghast", - "minecraft:shulker", - "minecraft:leash_knot", - "minecraft:armor_stand", - "minecraft:item_frame", - "minecraft:painting", - "minecraft:shulker_bullet", - "animania:textures/entity/pigs/hamster_tarou.png", - "animania:hamster", - "animania:ferret*", - "animania:hedgehog*", - "animania:cart", - "animania:wagon", - "mynko:*" - }; - } - - public static class ModelOverrides - { - @Config.RequiresMcRestart() - @Comment("Model Overrides based on NBT or on Meta. Advanced Users Only!") - public String[] modelOverrides = new String[] - { - "minecraft:lit_furnace->minecraft:furnace", - "minecraft:hopper->(block)minecraft:hopper", - "minecraft:unpowered_comparator->(block)minecraft:unpowered_comparator", - "minecraft:unpowered_repeater->(block)minecraft:unpowered_repeater", - "minecraft:powered_comparator->(block)minecraft:powered_comparator", - "minecraft:powered_repeater->(block)minecraft:powered_repeater", - "minecraft:cauldron->(block)minecraft:cauldron", - "minecraft:brewing_stand->(item)minecraft:brewing_stand", - "minecraft:tallgrass;1->(item)minecraft:tallgrass;1", - "minecraft:tallgrass;2->(item)minecraft:tallgrass;2", - "minecraft:flower_pot->(block)minecraft:flower_pot", - "minecraft:leaves2->(item)minecraft:leaves2", - "minecraft:reeds->(block)minecraft:reeds", - "minecraft:daylight_detector_inverted->minecraft:daylight_detector", - "quark:custom_chest{type:\"spruce\"}->quark:custom_chest;0", - "quark:custom_chest{type:\"birch\"}->quark:custom_chest;1", - "quark:custom_chest{type:\"jungle\"}->quark:custom_chest;2", - "quark:custom_chest{type:\"acacia\"}->quark:custom_chest;3", - "quark:custom_chest{type:\"dark_oak\"}->quark:custom_chest;4", - "quark:custom_chest_trap{type:\"spruce\"}->quark:custom_chest_trap;0", - "quark:custom_chest_trap{type:\"birch\"}->quark:custom_chest_trap;1", - "quark:custom_chest_trap{type:\"jungle\"}->quark:custom_chest_trap;2", - "quark:custom_chest_trap{type:\"acacia\"}->quark:custom_chest_trap;3", - "quark:custom_chest_trap{type:\"dark_oak\"}->quark:custom_chest_trap;4", - "storagedrawers:basicdrawers;0{Mat:\"spruce\"}->storagedrawers:basicdrawers;0{material:\"spruce\"}", - "storagedrawers:basicdrawers;0{Mat:\"birch\"}->storagedrawers:basicdrawers;0{material:\"birch\"}", - "storagedrawers:basicdrawers;0{Mat:\"jungle\"}->storagedrawers:basicdrawers;0{material:\"jungle\"}", - "storagedrawers:basicdrawers;0{Mat:\"acacia\"}->storagedrawers:basicdrawers;0{material:\"acacia\"}", - "storagedrawers:basicdrawers;0{Mat:\"dark_oak\"}->storagedrawers:basicdrawers;0{material:\"dark_oak\"}", - "storagedrawers:basicdrawers;1{Mat:\"spruce\"}->storagedrawers:basicdrawers;1{material:\"spruce\"}", - "storagedrawers:basicdrawers;1{Mat:\"birch\"}->storagedrawers:basicdrawers;1{material:\"birch\"}", - "storagedrawers:basicdrawers;1{Mat:\"jungle\"}->storagedrawers:basicdrawers;1{material:\"jungle\"}", - "storagedrawers:basicdrawers;1{Mat:\"acacia\"}->storagedrawers:basicdrawers;1{material:\"acacia\"}", - "storagedrawers:basicdrawers;1{Mat:\"dark_oak\"}->storagedrawers:basicdrawers;1{material:\"dark_oak\"}", - "storagedrawers:basicdrawers;2{Mat:\"spruce\"}->storagedrawers:basicdrawers;2{material:\"spruce\"}", - "storagedrawers:basicdrawers;2{Mat:\"birch\"}->storagedrawers:basicdrawers;2{material:\"birch\"}", - "storagedrawers:basicdrawers;2{Mat:\"jungle\"}->storagedrawers:basicdrawers;2{material:\"jungle\"}", - "storagedrawers:basicdrawers;2{Mat:\"acacia\"}->storagedrawers:basicdrawers;2{material:\"acacia\"}", - "storagedrawers:basicdrawers;2{Mat:\"dark_oak\"}->storagedrawers:basicdrawers;2{material:\"dark_oak\"}", - "storagedrawers:basicdrawers;3{Mat:\"spruce\"}->storagedrawers:basicdrawers;3{material:\"spruce\"}", - "storagedrawers:basicdrawers;3{Mat:\"birch\"}->storagedrawers:basicdrawers;3{material:\"birch\"}", - "storagedrawers:basicdrawers;3{Mat:\"jungle\"}->storagedrawers:basicdrawers;3{material:\"jungle\"}", - "storagedrawers:basicdrawers;3{Mat:\"acacia\"}->storagedrawers:basicdrawers;3{material:\"acacia\"}", - "storagedrawers:basicdrawers;3{Mat:\"dark_oak\"}->storagedrawers:basicdrawers;3{material:\"dark_oak\"}", - "storagedrawers:basicdrawers;4{Mat:\"spruce\"}->storagedrawers:basicdrawers;4{material:\"spruce\"}", - "storagedrawers:basicdrawers;4{Mat:\"birch\"}->storagedrawers:basicdrawers;4{material:\"birch\"}", - "storagedrawers:basicdrawers;4{Mat:\"jungle\"}->storagedrawers:basicdrawers;4{material:\"jungle\"}", - "storagedrawers:basicdrawers;4{Mat:\"acacia\"}->storagedrawers:basicdrawers;4{material:\"acacia\"}", - "storagedrawers:basicdrawers;4{Mat:\"dark_oak\"}->storagedrawers:basicdrawers;4{material:\"dark_oak\"}", - "animania:block_nest->(block)animania:block_nest", - "animania:cheese_mold;0->(block)animania:cheese_mold;0", - "animania:cheese_mold;1->(block)animania:cheese_mold;1", - "animania:cheese_mold;2->(block)animania:cheese_mold;2", - "animania:cheese_mold;3->(block)animania:cheese_mold;3", - "animania:cheese_mold;4->(block)animania:cheese_mold;4", - "animania:cheese_mold;5->(block)animania:cheese_mold;5", - "animania:cheese_mold;6->(block)animania:cheese_mold;6", - "animania:cheese_mold;7->(block)animania:cheese_mold;7", - "animania:cheese_mold;8->(block)animania:cheese_mold;8", - "animania:cheese_mold;9->(block)animania:cheese_mold;9", - "animania:cheese_mold;10->(block)animania:cheese_mold;10", - - }; - } - - - - public static class CustomPickupConditions - { - @Config.RequiresMcRestart() - @Comment("Custom Pickup Conditions for Blocks") - public String[] customPickupConditionsBlocks = new String[] - { - - }; - - @Config.RequiresMcRestart() - @Comment("Custom Pickup Conditions for Entities") - public String[] customPickupConditionsEntities = new String[] - { - - }; - } - -} diff --git a/src/main/java/tschipp/carryon/common/event/ItemEntityEvents.java b/src/main/java/tschipp/carryon/common/event/ItemEntityEvents.java deleted file mode 100644 index f844549..0000000 --- a/src/main/java/tschipp/carryon/common/event/ItemEntityEvents.java +++ /dev/null @@ -1,259 +0,0 @@ -package tschipp.carryon.common.event; - -import java.util.List; - -import com.google.common.collect.Lists; - -import net.minecraft.block.material.Material; -import net.minecraft.entity.Entity; -import net.minecraft.entity.EntityLivingBase; -import net.minecraft.entity.item.EntityItem; -import net.minecraft.entity.passive.EntityAnimal; -import net.minecraft.entity.passive.EntityHorse; -import net.minecraft.entity.passive.EntityVillager; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.entity.player.EntityPlayerMP; -import net.minecraft.init.SoundEvents; -import net.minecraft.item.Item; -import net.minecraft.item.ItemStack; -import net.minecraft.util.EnumFacing; -import net.minecraft.util.EnumHand; -import net.minecraft.util.SoundCategory; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; -import net.minecraftforge.event.entity.EntityJoinWorldEvent; -import net.minecraftforge.event.entity.living.LivingEvent.LivingUpdateEvent; -import net.minecraftforge.event.entity.player.PlayerInteractEvent; -import net.minecraftforge.fml.common.eventhandler.Event.Result; -import net.minecraftforge.fml.common.eventhandler.EventPriority; -import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; -import net.minecraftforge.fml.common.network.NetworkRegistry.TargetPoint; -import net.minecraftforge.items.CapabilityItemHandler; -import net.minecraftforge.items.IItemHandler; -import tschipp.carryon.CarryOn; -import tschipp.carryon.client.keybinds.CarryOnKeybinds; -import tschipp.carryon.common.config.CarryOnConfig; -import tschipp.carryon.common.handler.PickupHandler; -import tschipp.carryon.common.handler.RegistrationHandler; -import tschipp.carryon.common.item.ItemEntity; -import tschipp.carryon.common.scripting.CarryOnOverride; -import tschipp.carryon.common.scripting.ScriptChecker; -import tschipp.carryon.network.client.CarrySlotPacket; - -public class ItemEntityEvents -{ - - @SubscribeEvent(priority = EventPriority.HIGH) - public void onBlockClick(PlayerInteractEvent.RightClickBlock event) - { - EntityPlayer player = event.getEntityPlayer(); - ItemStack stack = player.getHeldItemMainhand(); - if (!stack.isEmpty() && stack.getItem() == RegistrationHandler.itemEntity && ItemEntity.hasEntityData(stack)) - { - player.getEntityData().removeTag("carrySlot"); - event.setUseBlock(Result.DENY); - } - - } - - @SubscribeEvent(priority = EventPriority.HIGH) - public void onItemDropped(EntityJoinWorldEvent event) - { - Entity e = event.getEntity(); - World world = event.getWorld(); - if (e instanceof EntityItem) - { - EntityItem eitem = (EntityItem) e; - ItemStack stack = eitem.getEntityItem(); - Item item = stack.getItem(); - if (item == RegistrationHandler.itemEntity && ItemEntity.hasEntityData(stack)) - { - BlockPos pos = eitem.getPosition(); - Entity entity = ItemEntity.getEntity(stack, world); - entity.setPosition(pos.getX() + 0.5, pos.getY(), pos.getZ() + 0.5); - world.spawnEntity(entity); - - ItemEntity.clearEntityData(stack); - eitem.setEntityItemStack(ItemStack.EMPTY); - } - } - } - - @SubscribeEvent(priority = EventPriority.HIGH) - public void onEntityRightClick(PlayerInteractEvent.EntityInteract event) - { - EntityPlayer player = event.getEntityPlayer(); - - if (player instanceof EntityPlayerMP) - { - ItemStack main = player.getHeldItemMainhand(); - ItemStack off = player.getHeldItemOffhand(); - World world = event.getWorld(); - Entity entity = event.getTarget(); - BlockPos pos = entity.getPosition(); - - if (main.isEmpty() && off.isEmpty() && CarryOnKeybinds.isKeyPressed(player)) - { - ItemStack stack = new ItemStack(RegistrationHandler.itemEntity); - - if (entity.hurtResistantTime == 0) - { - if (entity instanceof EntityAnimal) - ((EntityAnimal) entity).clearLeashed(true, true); - - if (PickupHandler.canPlayerPickUpEntity(player, entity)) - { - if (ItemEntity.storeEntityData(entity, world, stack)) - { - if (entity.hasCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null)) - { - IItemHandler handler = entity.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null); - for (int i = 0; i < handler.getSlots(); i++) - { - handler.extractItem(i, 64, false); - } - } - - CarryOnOverride override = ScriptChecker.inspectEntity(entity); - int overrideHash = 0; - if (override != null) - overrideHash = override.hashCode(); - - CarryOn.network.sendToAllAround(new CarrySlotPacket(player.inventory.currentItem, player.getEntityId(), overrideHash), new TargetPoint(world.provider.getDimension(), player.posX, player.posY, player.posZ, 256)); - entity.setDead(); - player.setHeldItem(EnumHand.MAIN_HAND, stack); - event.setCanceled(true); - } - } - } - - } - else if (!main.isEmpty() && main.getItem() == RegistrationHandler.itemEntity && ItemEntity.hasEntityData(main) && !CarryOnKeybinds.isKeyPressed(player) && CarryOnConfig.settings.stackableEntities) - { - Entity entityHeld = ItemEntity.getEntity(main, world); - - if (entity.hurtResistantTime == 0 && entityHeld instanceof EntityLivingBase) - { - - if (!world.isRemote && entityHeld.getUniqueID() != entity.getUniqueID() && !entityHeld.isDead && !entity.isDead) - { - - double sizeHeldEntity = entityHeld.height * entityHeld.width; - double distance = pos.distanceSqToCenter(player.posX, player.posY + 0.5, player.posZ); - Entity lowestEntity = entity.getLowestRidingEntity(); - int numPassengers = getAllPassengers(lowestEntity); - if (numPassengers < CarryOnConfig.settings.maxEntityStackLimit - 1) - { - Entity topEntity = getTopPassenger(lowestEntity); - - double sizeEntity = topEntity.height * topEntity.width; - if ((CarryOnConfig.settings.entitySizeMattersStacking && sizeHeldEntity <= sizeEntity) || !CarryOnConfig.settings.entitySizeMattersStacking) - { - if (topEntity instanceof EntityHorse) - { - EntityHorse horse = (EntityHorse) topEntity; - horse.setHorseTamed(true); - } - - if (distance < 6) - { - double tempX = entity.posX; - double tempY = entity.posY; - double tempZ = entity.posZ; - entityHeld.setPosition(tempX, tempY + 2.6, tempZ); - world.spawnEntity(entityHeld); - entityHeld.startRiding(topEntity, false); - entityHeld.setPositionAndUpdate(tempX, tempY, tempZ); - } - else - { - entityHeld.setPosition(entity.posX, entity.posY, entity.posZ); - world.spawnEntity(entityHeld); - entityHeld.startRiding(topEntity, false); - } - - - ItemEntity.clearEntityData(main); - player.setHeldItem(EnumHand.MAIN_HAND, ItemStack.EMPTY); - CarryOn.network.sendToAllAround(new CarrySlotPacket(9, player.getEntityId()), new TargetPoint(world.provider.getDimension(), player.posX, player.posY, player.posZ, 256)); - event.setCanceled(true); - world.playSound(null, player.posX, player.posY, player.posZ, SoundEvents.ENTITY_HORSE_SADDLE, SoundCategory.PLAYERS, 0.5F, 1.5F); - } - else - { - world.playSound(null, player.posX, player.posY, player.posZ, SoundEvents.BLOCK_NOTE_BASS, SoundCategory.PLAYERS, 0.5F, 1.5F); - return; - } - } - else - { - world.playSound(null, player.posX, player.posY, player.posZ, SoundEvents.BLOCK_NOTE_BASS, SoundCategory.PLAYERS, 0.5F, 1.5F); - return; - } - } - - } - - } - } - - } - - public static int getAllPassengers(Entity entity) - { - int passengers = 0; - while (entity.isBeingRidden()) - { - List pass = entity.getPassengers(); - if (!pass.isEmpty()) - { - entity = pass.get(0); - passengers++; - } - } - - return passengers; - } - - public static Entity getTopPassenger(Entity entity) - { - Entity top = entity; - while (entity.isBeingRidden()) - { - List pass = entity.getPassengers(); - if (!pass.isEmpty()) - { - entity = pass.get(0); - top = entity; - } - } - - return top; - } - - @SubscribeEvent - public void onLivingUpdate(LivingUpdateEvent event) - { - EntityLivingBase entity = event.getEntityLiving(); - World world = entity.world; - ItemStack main = entity.getHeldItemMainhand(); - if (!main.isEmpty() && main.getItem() == RegistrationHandler.itemEntity && ItemEntity.hasEntityData(main)) - { - BlockPos pos = entity.getPosition(); - BlockPos below = pos.offset(EnumFacing.DOWN); - - if (world.getBlockState(pos).getMaterial() == Material.WATER || world.getBlockState(below).getMaterial() == Material.WATER) - { - Entity contained = ItemEntity.getEntity(main, world); - if (contained != null) - { - float height = contained.height; - float width = contained.width; - - entity.addVelocity(0, -0.01 * height * width, 0); - } - } - } - } - -} diff --git a/src/main/java/tschipp/carryon/common/event/ItemEvents.java b/src/main/java/tschipp/carryon/common/event/ItemEvents.java deleted file mode 100644 index 7c79c71..0000000 --- a/src/main/java/tschipp/carryon/common/event/ItemEvents.java +++ /dev/null @@ -1,375 +0,0 @@ -package tschipp.carryon.common.event; - -import net.minecraft.block.Block; -import net.minecraft.block.state.IBlockState; -import net.minecraft.entity.Entity; -import net.minecraft.entity.EntityLivingBase; -import net.minecraft.entity.item.EntityItem; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.entity.player.EntityPlayerMP; -import net.minecraft.inventory.IInventory; -import net.minecraft.item.Item; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.tileentity.TileEntity; -import net.minecraft.util.EnumFacing; -import net.minecraft.util.EnumHand; -import net.minecraft.util.math.BlockPos; -import net.minecraft.util.text.TextComponentString; -import net.minecraft.util.text.TextFormatting; -import net.minecraft.util.text.event.ClickEvent; -import net.minecraft.util.text.event.ClickEvent.Action; -import net.minecraft.world.GameRules; -import net.minecraft.world.World; -import net.minecraftforge.event.entity.EntityJoinWorldEvent; -import net.minecraftforge.event.entity.living.LivingAttackEvent; -import net.minecraftforge.event.entity.player.AttackEntityEvent; -import net.minecraftforge.event.entity.player.PlayerEvent; -import net.minecraftforge.event.entity.player.PlayerEvent.BreakSpeed; -import net.minecraftforge.event.entity.player.PlayerEvent.StartTracking; -import net.minecraftforge.event.entity.player.PlayerInteractEvent; -import net.minecraftforge.event.world.BlockEvent.BreakEvent; -import net.minecraftforge.fml.common.eventhandler.Event.Result; -import net.minecraftforge.fml.common.eventhandler.EventPriority; -import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; -import net.minecraftforge.fml.common.gameevent.PlayerEvent.PlayerLoggedInEvent; -import net.minecraftforge.fml.common.network.NetworkRegistry.TargetPoint; -import net.minecraftforge.items.CapabilityItemHandler; -import net.minecraftforge.items.IItemHandler; -import tschipp.carryon.CarryOn; -import tschipp.carryon.client.keybinds.CarryOnKeybinds; -import tschipp.carryon.common.config.CarryOnConfig; -import tschipp.carryon.common.handler.PickupHandler; -import tschipp.carryon.common.handler.RegistrationHandler; -import tschipp.carryon.common.item.ItemEntity; -import tschipp.carryon.common.item.ItemTile; -import tschipp.carryon.common.scripting.CarryOnOverride; -import tschipp.carryon.common.scripting.ScriptChecker; -import tschipp.carryon.network.client.CarrySlotPacket; - -public class ItemEvents -{ - - @SubscribeEvent(priority = EventPriority.HIGH) - public void onBlockClick(PlayerInteractEvent.RightClickBlock event) - { - EntityPlayer player = event.getEntityPlayer(); - ItemStack stack = player.getHeldItemMainhand(); - if (!stack.isEmpty() && stack.getItem() == RegistrationHandler.itemTile && ItemTile.hasTileData(stack)) - { - player.getEntityData().removeTag("carrySlot"); - event.setUseBlock(Result.DENY); - } - - } - - @SubscribeEvent(priority = EventPriority.HIGH) - public void onItemDropped(EntityJoinWorldEvent event) - { - Entity e = event.getEntity(); - World world = event.getWorld(); - if (e instanceof EntityItem) - { - EntityItem eitem = (EntityItem) e; - ItemStack stack = eitem.getEntityItem(); - Item item = stack.getItem(); - if (item == RegistrationHandler.itemTile && ItemTile.hasTileData(stack)) - { - BlockPos pos = eitem.getPosition(); - BlockPos finalPos = pos; - Block block = ItemTile.getBlock(stack); - if (!world.getBlockState(pos).getBlock().isReplaceable(world, pos) || !block.canPlaceBlockAt(world, pos)) - { - for (EnumFacing facing : EnumFacing.VALUES) - { - BlockPos offsetPos = pos.offset(facing); - if (world.getBlockState(offsetPos).getBlock().isReplaceable(world, offsetPos) && block.canPlaceBlockAt(world, offsetPos)) - { - finalPos = offsetPos; - break; - } - } - } - world.setBlockState(finalPos, ItemTile.getBlockState(stack)); - TileEntity tile = world.getTileEntity(finalPos); - if (tile != null) - { - tile.readFromNBT(ItemTile.getTileData(stack)); - tile.setPos(finalPos); - } - ItemTile.clearTileData(stack); - eitem.setEntityItemStack(ItemStack.EMPTY); - } - } - - } - - @SubscribeEvent - public void onPlayerLogin(PlayerLoggedInEvent event) - { - if (event.player instanceof EntityPlayer) - { - EntityPlayer player = (EntityPlayer) event.player; - World world = player.getEntityWorld(); - - ItemStack carried = player.getHeldItemMainhand(); - if (!carried.isEmpty() && carried.getItem() == RegistrationHandler.itemTile || carried.getItem() == RegistrationHandler.itemEntity) - { - if (carried.getItem() == RegistrationHandler.itemTile) - { - CarryOnOverride override = ScriptChecker.inspectBlock(((ItemTile) carried.getItem()).getBlockState(carried), world, player.getPosition(), ((ItemTile) carried.getItem()).getTileData(carried)); - if (override != null) - CarryOn.network.sendTo(new CarrySlotPacket(player.inventory.currentItem, player.getEntityId(), override.hashCode()), (EntityPlayerMP) player); - else - CarryOn.network.sendTo(new CarrySlotPacket(player.inventory.currentItem, player.getEntityId()), (EntityPlayerMP) player); - } - else - { - CarryOnOverride override = ScriptChecker.inspectEntity(((ItemEntity) carried.getItem()).getEntity(carried, world)); - if (override != null) - CarryOn.network.sendTo(new CarrySlotPacket(player.inventory.currentItem, player.getEntityId(), override.hashCode()), (EntityPlayerMP) player); - else - CarryOn.network.sendTo(new CarrySlotPacket(player.inventory.currentItem, player.getEntityId()), (EntityPlayerMP) player); - } - } - - } - } - - @SubscribeEvent - public void onEntityStartTracking(StartTracking event) - { - Entity e = event.getTarget(); - EntityPlayer tracker = event.getEntityPlayer(); - - if (e instanceof EntityPlayer && tracker instanceof EntityPlayerMP) - { - EntityPlayer player = (EntityPlayer) e; - World world = player.getEntityWorld(); - - ItemStack carried = player.getHeldItemMainhand(); - if (!carried.isEmpty() && carried.getItem() == RegistrationHandler.itemTile || carried.getItem() == RegistrationHandler.itemEntity) - { - if (carried.getItem() == RegistrationHandler.itemTile) - { - CarryOnOverride override = ScriptChecker.inspectBlock(((ItemTile) carried.getItem()).getBlockState(carried), world, player.getPosition(), ((ItemTile) carried.getItem()).getTileData(carried)); - if (override != null) - CarryOn.network.sendTo(new CarrySlotPacket(player.inventory.currentItem, player.getEntityId(), override.hashCode()), (EntityPlayerMP) tracker); - else - CarryOn.network.sendTo(new CarrySlotPacket(player.inventory.currentItem, player.getEntityId()), (EntityPlayerMP) tracker); - } - else - { - CarryOnOverride override = ScriptChecker.inspectEntity(((ItemEntity) carried.getItem()).getEntity(carried, world)); - if (override != null) - CarryOn.network.sendTo(new CarrySlotPacket(player.inventory.currentItem, player.getEntityId(), override.hashCode()), (EntityPlayerMP) tracker); - else - CarryOn.network.sendTo(new CarrySlotPacket(player.inventory.currentItem, player.getEntityId()), (EntityPlayerMP) tracker); - } - } - - } - } - - @SubscribeEvent - public void harvestSpeed(BreakSpeed event) - { - EntityPlayer player = event.getEntityPlayer(); - if (player != null && !CarryOnConfig.settings.hitWhileCarrying) - { - ItemStack stack = player.getHeldItemMainhand(); - if (!stack.isEmpty() && (stack.getItem() == RegistrationHandler.itemTile || stack.getItem() == RegistrationHandler.itemEntity)) - event.setNewSpeed(0); - } - } - - @SubscribeEvent - public void attackEntity(AttackEntityEvent event) - { - EntityPlayer player = event.getEntityPlayer(); - ItemStack stack = player.getHeldItemMainhand(); - if (!stack.isEmpty() && !CarryOnConfig.settings.hitWhileCarrying && (stack.getItem() == RegistrationHandler.itemTile || stack.getItem() == RegistrationHandler.itemEntity)) - { - event.setCanceled(true); - } - } - - @SubscribeEvent - public void harvestSpeed(BreakEvent event) - { - EntityPlayer player = event.getPlayer(); - if (player != null && !CarryOnConfig.settings.hitWhileCarrying) - { - ItemStack stack = player.getHeldItemMainhand(); - if (!stack.isEmpty() && (stack.getItem() == RegistrationHandler.itemTile || stack.getItem() == RegistrationHandler.itemEntity)) - event.setCanceled(true); - } - } - - - @SubscribeEvent - public void playerAttack(LivingAttackEvent event) - { - EntityLivingBase eliving = event.getEntityLiving(); - if (eliving instanceof EntityPlayer && CarryOnConfig.settings.dropCarriedWhenHit) - { - EntityPlayer player = (EntityPlayer) eliving; - ItemStack stack = player.getHeldItemMainhand(); - if (!stack.isEmpty() && (stack.getItem() == RegistrationHandler.itemTile || stack.getItem() == RegistrationHandler.itemEntity)) - { - if (!player.world.isRemote) - { - player.setHeldItem(EnumHand.MAIN_HAND, ItemStack.EMPTY); - EntityItem item = new EntityItem(player.world, player.posX, player.posY, player.posZ, stack); - CarryOn.network.sendToAllAround(new CarrySlotPacket(9, player.getEntityId()), new TargetPoint(player.world.provider.getDimension(), player.posX, player.posY, player.posZ, 256)); - player.world.spawnEntity(item); - } - } - - } - } - - @SubscribeEvent - public void onBlockRightClick(PlayerInteractEvent.RightClickBlock event) throws InstantiationException, IllegalAccessException - { - EntityPlayer player = event.getEntityPlayer(); - - if (player instanceof EntityPlayerMP) - { - - ItemStack main = player.getHeldItemMainhand(); - ItemStack off = player.getHeldItemOffhand(); - World world = event.getWorld(); - BlockPos pos = event.getPos(); - Block block = world.getBlockState(pos).getBlock(); - IBlockState state = world.getBlockState(pos); - - if (main.isEmpty() && off.isEmpty() && CarryOnKeybinds.isKeyPressed(player)) - { - ItemStack stack = new ItemStack(RegistrationHandler.itemTile); - - TileEntity te = world.getTileEntity(pos); - if (PickupHandler.canPlayerPickUpBlock(player, te, world, pos)) - { - if (ItemTile.storeTileData(te, world, pos, state.getActualState(world, pos), stack)) - { - IBlockState statee = world.getBlockState(pos); - NBTTagCompound tag = new NBTTagCompound(); - tag = world.getTileEntity(pos) != null ? world.getTileEntity(pos).writeToNBT(tag) : new NBTTagCompound(); - CarryOnOverride override = ScriptChecker.inspectBlock(state, world, pos, tag); - int overrideHash = 0; - if (override != null) - overrideHash = override.hashCode(); - - try - { - CarryOn.network.sendToAllAround(new CarrySlotPacket(player.inventory.currentItem, player.getEntityId(), overrideHash), new TargetPoint(world.provider.getDimension(), player.posX, player.posY, player.posZ, 256)); - world.removeTileEntity(pos); - world.setBlockToAir(pos); - player.setHeldItem(EnumHand.MAIN_HAND, stack); - event.setUseBlock(Result.DENY); - event.setCanceled(true); - } - catch (Exception e) - { - try - { - CarryOn.network.sendToAllAround(new CarrySlotPacket(player.inventory.currentItem, player.getEntityId(), overrideHash), new TargetPoint(world.provider.getDimension(), player.posX, player.posY, player.posZ, 256)); - emptyTileEntity(te); - world.setBlockToAir(pos); - player.setHeldItem(EnumHand.MAIN_HAND, stack); - event.setUseBlock(Result.DENY); - event.setCanceled(true); - } - catch (Exception ex) - { - CarryOn.network.sendToAllAround(new CarrySlotPacket(9, player.getEntityId()), new TargetPoint(world.provider.getDimension(), player.posX, player.posY, player.posZ, 256)); - world.setBlockState(pos, statee); - if (!tag.hasNoTags()) - TileEntity.create(world, tag); - - player.sendMessage(new TextComponentString(TextFormatting.RED + "Error detected. Cannot pick up block.")); - TextComponentString s = new TextComponentString(TextFormatting.GOLD + "here"); - s.getStyle().setClickEvent(new ClickEvent(Action.OPEN_URL, "https://github.com/Tschipp/CarryOn/issues")); - player.sendMessage(new TextComponentString(TextFormatting.RED + "Please report this error ").appendSibling(s)); - } - } - - } - - } - - } - } - } - - public static void emptyTileEntity(TileEntity te) - { - if (te != null && !te.isInvalid()) - { - for (EnumFacing facing : EnumFacing.VALUES) - { - if (te.hasCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, facing)) - { - IItemHandler itemHandler = te.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, facing); - for (int i = 0; i < itemHandler.getSlots(); i++) - { - itemHandler.extractItem(i, 64, false); - } - } - } - - if (te.hasCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null)) - { - IItemHandler itemHandler = te.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null); - for (int i = 0; i < itemHandler.getSlots(); i++) - { - itemHandler.extractItem(i, 64, false); - } - } - - if (te instanceof IInventory) - { - IInventory inv = (IInventory) te; - inv.clear(); - } - - if (te instanceof IItemHandler) - { - IItemHandler itemHandler = (IItemHandler) te; - for (int i = 0; i < itemHandler.getSlots(); i++) - { - itemHandler.extractItem(i, 64, false); - } - } - } - } - - @SubscribeEvent - public void onRespawn(PlayerEvent.Clone event) - { - EntityPlayer original = event.getOriginal(); - EntityPlayer player = event.getEntityPlayer(); - boolean wasDead = event.isWasDeath(); - GameRules rules = player.world.getGameRules(); - boolean keepInv = rules.getBoolean("keepInventory"); - boolean wasCarrying = player.inventory.hasItemStack(new ItemStack(RegistrationHandler.itemTile)) || player.inventory.hasItemStack(new ItemStack(RegistrationHandler.itemEntity)); - - if ((wasDead ? keepInv : true) && wasCarrying) - { - int carrySlot = original.inventory.currentItem; - - ItemStack stack = player.inventory.removeStackFromSlot(carrySlot); - World world = player.world; - - EntityItem item = new EntityItem(world); - item.setEntityItemStack(stack); - BlockPos pos = original.getBedLocation(); - if (pos == null) - pos = player.getPosition(); - item.setPosition(pos.getX(), pos.getY(), pos.getZ()); - world.spawnEntity(item); - } - } - -} diff --git a/src/main/java/tschipp/carryon/common/handler/CustomPickupOverrideHandler.java b/src/main/java/tschipp/carryon/common/handler/CustomPickupOverrideHandler.java deleted file mode 100644 index 38ce4ac..0000000 --- a/src/main/java/tschipp/carryon/common/handler/CustomPickupOverrideHandler.java +++ /dev/null @@ -1,125 +0,0 @@ -package tschipp.carryon.common.handler; - -import java.util.HashMap; - -import net.minecraft.block.Block; -import net.minecraft.block.state.IBlockState; -import net.minecraft.entity.Entity; -import net.minecraft.entity.EntityList; -import net.minecraftforge.fml.common.Loader; -import tschipp.carryon.common.config.CarryOnConfig; -import tschipp.carryon.common.helper.InvalidConfigException; - -public class CustomPickupOverrideHandler -{ - - public static HashMap PICKUP_CONDITIONS = new HashMap(); - public static HashMap PICKUP_CONDITIONS_ENTITIES = new HashMap(); - - public static void initPickupOverrides() - { - if (Loader.isModLoaded("gamestages")) - { - - String[] conditions = CarryOnConfig.customPickupConditions.customPickupConditionsBlocks; - - for (int i = 0; i < conditions.length; i++) - { - String line = conditions[i]; - - if (!line.contains("(") || !line.contains(")")) - new InvalidConfigException("Invalid Condition at line " + i + ": " + line).printException(); - - String condition = line.substring(line.indexOf("(")); - String blockname = line.replace(condition, ""); - condition = condition.replace("(", ""); - condition = condition.replace(")", ""); - - if (blockname.contains("*")) - { - String modid = blockname.replace("*", ""); - for (int k = 0; k < Block.REGISTRY.getKeys().size(); k++) - { - if (Block.REGISTRY.getKeys().toArray()[k].toString().contains(modid)) - { - PICKUP_CONDITIONS.put(Block.REGISTRY.getKeys().toArray()[k].toString() + ";any", condition); - } - } - } - else - { - if (!blockname.contains(";")) - blockname = blockname + ";any"; - - PICKUP_CONDITIONS.put(blockname, condition); - } - } - - String[] entityConditions = CarryOnConfig.customPickupConditions.customPickupConditionsEntities; - - for (int i = 0; i < entityConditions.length; i++) - { - String line = entityConditions[i]; - - if (!line.contains("(") || !line.contains(")")) - new InvalidConfigException("Invalid Condition at line " + i + ": " + line).printException(); - - String condition = line.substring(line.indexOf("(")); - String entityname = line.replace(condition, ""); - condition = condition.replace("(", ""); - condition = condition.replace(")", ""); - - PICKUP_CONDITIONS_ENTITIES.put(entityname, condition); - - } - } - } - - public static boolean hasSpecialPickupConditions(IBlockState state) - { - if (!Loader.isModLoaded("gamestages")) - return false; - - String block = state.getBlock().getRegistryName().toString(); - String meta = "" + state.getBlock().getMetaFromState(state); - - boolean absolute = PICKUP_CONDITIONS.containsKey(block + ";" + meta); - boolean any = PICKUP_CONDITIONS.containsKey(block + ";any"); - - return absolute || any; - } - - public static String getPickupCondition(IBlockState state) - { - String block = state.getBlock().getRegistryName().toString(); - String meta = "" + state.getBlock().getMetaFromState(state); - - String absolute = PICKUP_CONDITIONS.get(block + ";" + meta); - String any = PICKUP_CONDITIONS.get(block + ";any"); - - if (absolute != null) - return absolute; - else - return any; - } - - public static boolean hasSpecialPickupConditions(Entity entity) - { - if (!Loader.isModLoaded("gamestages")) - return false; - - String entityname = EntityList.getKey(entity).toString(); - boolean condition = PICKUP_CONDITIONS_ENTITIES.containsKey(entityname); - - return condition; - } - - public static String getPickupCondition(Entity entity) - { - String entityname = EntityList.getKey(entity).toString(); - String condition = PICKUP_CONDITIONS_ENTITIES.get(entityname); - - return condition; - } - -} diff --git a/src/main/java/tschipp/carryon/common/handler/ListHandler.java b/src/main/java/tschipp/carryon/common/handler/ListHandler.java deleted file mode 100644 index 83a23bc..0000000 --- a/src/main/java/tschipp/carryon/common/handler/ListHandler.java +++ /dev/null @@ -1,138 +0,0 @@ -package tschipp.carryon.common.handler; - -import java.util.ArrayList; -import java.util.List; - -import net.minecraft.block.Block; -import net.minecraft.entity.Entity; -import net.minecraft.entity.EntityList; -import net.minecraftforge.fml.common.registry.ForgeRegistries; -import tschipp.carryon.common.config.CarryOnConfig; - -public class ListHandler -{ - public static List FORBIDDEN_TILES; - public static List FORBIDDEN_ENTITIES; - public static List ALLOWED_ENTITIES; - public static List ALLOWED_TILES; - - public static boolean isForbidden(Block block) - { - String name = block.getRegistryName().toString(); - if (FORBIDDEN_TILES.contains(name)) - return true; - else - { - boolean contains = false; - for (String s : FORBIDDEN_TILES) - { - if (s.contains("*")) - { - if(name.contains(s.replace("*", ""))) - contains = true; - } - } - - return contains; - } - } - - public static boolean isForbidden(Entity entity) - { - if (EntityList.getKey(entity) != null) - { - String name = EntityList.getKey(entity).toString(); - boolean contains = FORBIDDEN_ENTITIES.contains(name); - return contains; - } - return true; - } - - public static boolean isAllowed(Entity entity) - { - if (EntityList.getKey(entity) != null) - { - String name = EntityList.getKey(entity).toString(); - boolean contains = ALLOWED_ENTITIES.contains(name); - return contains; - } - return true; - } - - public static boolean isAllowed(Block block) - { - String name = block.getRegistryName().toString(); - if (ALLOWED_TILES.contains(name)) - return true; - else - { - boolean contains = false; - for (String s : ALLOWED_TILES) - { - if (s.contains("*")) - { - if(name.contains(s.replace("*", ""))) - contains = true; - } - } - return contains; - } - - } - - public static void initForbiddenTiles() - { - String[] forbidden = CarryOnConfig.blacklist.forbiddenTiles; - FORBIDDEN_TILES = new ArrayList(); - - for (int i = 0; i < forbidden.length; i++) - { - FORBIDDEN_TILES.add(forbidden[i]); - } - - String[] forbiddenEntity = CarryOnConfig.blacklist.forbiddenEntities; - FORBIDDEN_ENTITIES = new ArrayList(); - - for (int i = 0; i < forbiddenEntity.length; i++) - { - if (forbiddenEntity[i].contains("*")) - { - String modid = forbiddenEntity[i].replace("*", ""); - for (int k = 0; k < ForgeRegistries.ENTITIES.getKeys().size(); k++) - { - if (ForgeRegistries.ENTITIES.getKeys().toArray()[k].toString().contains(modid)) - { - FORBIDDEN_ENTITIES.add(ForgeRegistries.ENTITIES.getKeys().toArray()[k].toString()); - } - } - } - FORBIDDEN_ENTITIES.add(forbiddenEntity[i]); - } - - String[] allowedEntities = CarryOnConfig.whitelist.allowedEntities; - ALLOWED_ENTITIES = new ArrayList(); - for (int i = 0; i < allowedEntities.length; i++) - { - if (allowedEntities[i].contains("*")) - { - String modid = allowedEntities[i].replace("*", ""); - for (int k = 0; k < ForgeRegistries.ENTITIES.getKeys().size(); k++) - { - if (ForgeRegistries.ENTITIES.getKeys().toArray()[k].toString().contains(modid)) - { - ALLOWED_ENTITIES.add(ForgeRegistries.ENTITIES.getKeys().toArray()[k].toString()); - } - } - } - ALLOWED_ENTITIES.add(allowedEntities[i]); - } - - String[] allowedBlocks = CarryOnConfig.whitelist.allowedBlocks; - ALLOWED_TILES = new ArrayList(); - for (int i = 0; i < allowedBlocks.length; i++) - { - ALLOWED_TILES.add(allowedBlocks[i]); - } - } - -} diff --git a/src/main/java/tschipp/carryon/common/handler/ModelOverridesHandler.java b/src/main/java/tschipp/carryon/common/handler/ModelOverridesHandler.java deleted file mode 100644 index 2d8885c..0000000 --- a/src/main/java/tschipp/carryon/common/handler/ModelOverridesHandler.java +++ /dev/null @@ -1,269 +0,0 @@ -package tschipp.carryon.common.handler; - -import java.util.HashMap; -import java.util.Set; - -import org.apache.commons.lang3.StringUtils; - -import net.minecraft.block.Block; -import net.minecraft.block.state.IBlockState; -import net.minecraft.client.Minecraft; -import net.minecraft.client.renderer.block.model.IBakedModel; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.JsonToNBT; -import net.minecraft.nbt.NBTException; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.nbt.NBTUtil; -import net.minecraft.world.World; -import net.minecraftforge.fml.common.Loader; -import net.minecraftforge.fml.relauncher.Side; -import net.minecraftforge.fml.relauncher.SideOnly; -import tschipp.carryon.common.config.CarryOnConfig; -import tschipp.carryon.common.helper.InvalidConfigException; -import tschipp.carryon.common.helper.StringParser; - -public class ModelOverridesHandler -{ - public static HashMap OVERRIDE_OBJECTS = new HashMap(); - - /* - * This class is really ugly, will probably be replaced by something else - - * Tschipp - */ - public static void initOverrides() - { - String[] overrides = CarryOnConfig.modelOverrides.modelOverrides; - - for (int i = 0; i < overrides.length; i++) - { - boolean errored = false; - - Object toOverrideObject; - Object overrideObject; - NBTTagCompound tag = new NBTTagCompound(); - - String currentline = overrides[i]; - if (StringUtils.isEmpty(currentline) || !StringUtils.contains(currentline, "->")) - new InvalidConfigException("Missing Override Model at line " + i + " : " + currentline).printException(); - - String[] sa = currentline.split("->"); - String toOverride = ""; - String override = ""; - try - { - toOverride = sa[0]; - override = sa[1]; - } - catch (ArrayIndexOutOfBoundsException e) - { - errored = true; - new InvalidConfigException("Missing Override Model at line " + i + " : " + currentline).printException(); - } - - if (toOverride.contains("{")) - { - if (!toOverride.contains("}")) - { - errored = true; - new InvalidConfigException("Missing } at line " + i + " : " + currentline).printException(); - } - - String nbt = toOverride.substring(toOverride.indexOf("{")); - toOverride = toOverride.replace(nbt, ""); - try - { - tag = JsonToNBT.getTagFromJson(nbt); - } - catch (NBTException e) - { - errored = true; - new InvalidConfigException("Error while parsing NBT at line " + i + " : " + e.getMessage()).printException(); - } - - } - else if (toOverride.contains("}")) - { - errored = true; - new InvalidConfigException("Missing { at line " + i + " : " + currentline).printException(); - } - - String overridetype = "item"; - if (override.contains("(")) - { - if (!override.contains(")")) - { - errored = true; - new InvalidConfigException("Missing ) at line " + i + " : " + currentline).printException(); - } - - overridetype = override.substring(0, override.indexOf(")") + 1); - override =override.replace(overridetype, ""); - overridetype = overridetype.replace("(", ""); - overridetype = overridetype.replace(")", ""); - - } - else if (override.contains(")")) - { - errored = true; - new InvalidConfigException("Missing ( at line " + i + " : " + currentline).printException(); - } - - String modidToOverride = "minecraft"; - String modidOverride = "minecraft"; - - if (toOverride.contains(":")) - modidToOverride = toOverride.replace(toOverride.substring(toOverride.indexOf(":")), ""); - - if (override.contains(":")) - modidOverride = override.replace(override.substring(override.indexOf(":")), ""); - - if (Loader.isModLoaded(modidOverride) && Loader.isModLoaded(modidToOverride) && !errored) - { - - int meta = StringParser.getMeta(toOverride); - if (meta == 0) - toOverrideObject = StringParser.getBlock(toOverride); - else - toOverrideObject = StringParser.getBlockState(toOverride); - - if (toOverrideObject != null) - { - if (overridetype.equals("block")) - overrideObject = StringParser.getBlockState(override); - else - overrideObject = StringParser.getItemStack(override); - - if (overrideObject != null) - { - NBTTagCompound keyComp = new NBTTagCompound(); - keyComp.setTag("nbttag", tag); - if (toOverrideObject instanceof Block) - { - keyComp.setString("block", ((Block) toOverrideObject).getRegistryName().toString()); - } - else - { - keyComp.setInteger("stateid", Block.getStateId((IBlockState) toOverrideObject)); - keyComp.setString("block", ((IBlockState) toOverrideObject).getBlock().getRegistryName().toString()); - } - OVERRIDE_OBJECTS.put(keyComp, overrideObject); - } - } - } - } - } - - public static boolean hasCustomOverrideModel(IBlockState state, NBTTagCompound tag) - { - if (OVERRIDE_OBJECTS.isEmpty()) - return false; - - int stateid = Block.getStateId(state); - NBTTagCompound[] keys = new NBTTagCompound[OVERRIDE_OBJECTS.size()]; - OVERRIDE_OBJECTS.keySet().toArray(keys); - for (NBTTagCompound key : keys) - { - int id = key.getInteger("stateid"); - Block block = StringParser.getBlock(key.getString("block")); - if (id == 0 ? block == state.getBlock() : id == stateid) - { - NBTTagCompound toCheckForCompound = key.getCompoundTag("nbttag"); - Set kSetToCheck = toCheckForCompound.getKeySet(); - Set kSetTile = tag.getKeySet(); - - boolean flag = true; - if (kSetTile.containsAll(kSetToCheck)) - { - for (String skey : kSetToCheck) - { - if (!NBTUtil.areNBTEquals(tag.getTag(skey), toCheckForCompound.getTag(skey), true)) - flag = false; - } - if (flag) - return true; - } - } - } - - return false; - } - - @SideOnly(Side.CLIENT) - public static IBakedModel getCustomOverrideModel(IBlockState state, NBTTagCompound tag, World world, EntityPlayer player) - { - int stateid = Block.getStateId(state); - NBTTagCompound[] keys = new NBTTagCompound[OVERRIDE_OBJECTS.size()]; - OVERRIDE_OBJECTS.keySet().toArray(keys); - for (NBTTagCompound key : keys) - { - int id = key.getInteger("stateid"); - Block block = StringParser.getBlock(key.getString("block")); - if (id == 0 ? block == state.getBlock() : id == stateid) - { - NBTTagCompound toCheckForCompound = key.getCompoundTag("nbttag"); - Set kSetToCheck = toCheckForCompound.getKeySet(); - Set kSetTile = tag.getKeySet(); - - boolean flag = true; - if (kSetTile.containsAll(kSetToCheck)) - { - for (String skey : kSetToCheck) - { - if (!NBTUtil.areNBTEquals(tag.getTag(skey), toCheckForCompound.getTag(skey), true)) - flag = false; - } - if (flag) - { - Object override = OVERRIDE_OBJECTS.get(key); - - if (override == null) - return null; - - if (override instanceof IBlockState) - return Minecraft.getMinecraft().getBlockRendererDispatcher().getModelForState((IBlockState) override); - else - return Minecraft.getMinecraft().getRenderItem().getItemModelWithOverrides((ItemStack) override, world, player); - } - } - } - } - return null; - - } - - public static Object getOverrideObject(IBlockState state, NBTTagCompound tag) - { - int stateid = Block.getStateId(state); - NBTTagCompound[] keys = new NBTTagCompound[OVERRIDE_OBJECTS.size()]; - OVERRIDE_OBJECTS.keySet().toArray(keys); - for (NBTTagCompound key : keys) - { - int id = key.getInteger("stateid"); - Block block = StringParser.getBlock(key.getString("block")); - if (id == 0 ? block == state.getBlock() : id == stateid) - { - NBTTagCompound toCheckForCompound = key.getCompoundTag("nbttag"); - Set kSetToCheck = toCheckForCompound.getKeySet(); - Set kSetTile = tag.getKeySet(); - - boolean flag = true; - if (kSetTile.containsAll(kSetToCheck)) - { - for (String skey : kSetToCheck) - { - if (!NBTUtil.areNBTEquals(tag.getTag(skey), toCheckForCompound.getTag(skey), true)) - flag = false; - } - if (flag) - { - Object override = OVERRIDE_OBJECTS.get(key); - return override; - } - } - } - } - return null; - } - -} diff --git a/src/main/java/tschipp/carryon/common/handler/PickupHandler.java b/src/main/java/tschipp/carryon/common/handler/PickupHandler.java deleted file mode 100644 index 31502f3..0000000 --- a/src/main/java/tschipp/carryon/common/handler/PickupHandler.java +++ /dev/null @@ -1,222 +0,0 @@ -package tschipp.carryon.common.handler; - -import java.util.UUID; - -import javax.annotation.Nullable; - -import net.darkhax.gamestages.capabilities.PlayerDataHandler; -import net.darkhax.gamestages.capabilities.PlayerDataHandler.IStageData; -import net.minecraft.block.Block; -import net.minecraft.block.state.IBlockState; -import net.minecraft.entity.Entity; -import net.minecraft.entity.EntityAgeable; -import net.minecraft.entity.EnumCreatureType; -import net.minecraft.entity.passive.EntityTameable; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.entity.player.EntityPlayerMP; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.tileentity.TileEntity; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; -import net.minecraftforge.common.MinecraftForge; -import net.minecraftforge.event.entity.player.AttackEntityEvent; -import net.minecraftforge.event.world.BlockEvent; -import tschipp.carryon.CarryOn; -import tschipp.carryon.common.config.CarryOnConfig; -import tschipp.carryon.common.item.ItemTile; -import tschipp.carryon.common.scripting.CarryOnOverride; -import tschipp.carryon.common.scripting.ScriptChecker; - -public class PickupHandler -{ - - public static boolean canPlayerPickUpBlock(EntityPlayer player, @Nullable TileEntity tile, World world, BlockPos pos) - { - IBlockState state = world.getBlockState(pos); - Block block = state.getBlock(); - - player.closeScreen(); - - NBTTagCompound tag = new NBTTagCompound(); - if (tile != null) - tile.writeToNBT(tag); - - CarryOnOverride override = ScriptChecker.inspectBlock(world.getBlockState(pos), world, pos, tag); - if (override != null) - { - return (ScriptChecker.fulfillsConditions(override, player)) && handleProtections((EntityPlayerMP) player, world, pos, state); - } - else - { - if (CarryOnConfig.settings.useWhitelistBlocks) - { - if (!ListHandler.isAllowed(world.getBlockState(pos).getBlock())) - { - return false; - } - CarryOn.LOGGER.info("Block is allowed"); - } - else - { - if (ListHandler.isForbidden(world.getBlockState(pos).getBlock())) - { - return false; - } - } - - if ((block.getBlockHardness(state, world, pos) != -1 || player.isCreative())) - { - double distance = pos.distanceSqToCenter(player.posX, player.posY + 0.5, player.posZ); - - if (distance < Math.pow(CarryOnConfig.settings.maxDistance, 2)) - { - - if (!ItemTile.isLocked(pos, world)) - { - - if (CustomPickupOverrideHandler.hasSpecialPickupConditions(state)) - { - IStageData stageData = PlayerDataHandler.getStageData(player); - String condition = CustomPickupOverrideHandler.getPickupCondition(state); - if (stageData.hasUnlockedStage(condition)) - return true && handleProtections((EntityPlayerMP) player, world, pos, state); - - } - else if (CarryOnConfig.settings.pickupAllBlocks ? true : tile != null) - { - - return true && handleProtections((EntityPlayerMP) player, world, pos, state); - } - - } - } - } - } - - return false; - } - - public static boolean canPlayerPickUpEntity(EntityPlayer player, Entity toPickUp) - { - BlockPos pos = toPickUp.getPosition(); - - if (toPickUp instanceof EntityPlayer) - return false; - - CarryOnOverride override = ScriptChecker.inspectEntity(toPickUp); - if (override != null) - { - return (ScriptChecker.fulfillsConditions(override, player)) && handleProtections((EntityPlayerMP) player, toPickUp); - } - else - { - - // check for allow babies to be picked up - if (toPickUp instanceof EntityAgeable && CarryOnConfig.settings.allowBabies) - { - EntityAgeable living = (EntityAgeable) toPickUp; - if (living.getGrowingAge() < 0 || living.isChild()) - { - - double distance = pos.distanceSqToCenter(player.posX, player.posY + 0.5, player.posZ); - if (distance < Math.pow(CarryOnConfig.settings.maxDistance, 2)) - { - if (toPickUp instanceof EntityTameable) - { - EntityTameable tame = (EntityTameable) toPickUp; - if (tame.getOwnerId() != null && tame.getOwnerId() != player.getUUID(player.getGameProfile())) - return false; - } - } - - if (CustomPickupOverrideHandler.hasSpecialPickupConditions(toPickUp)) - { - IStageData stageData = PlayerDataHandler.getStageData(player); - String condition = CustomPickupOverrideHandler.getPickupCondition(toPickUp); - if (stageData.hasUnlockedStage(condition)) - return true && handleProtections((EntityPlayerMP) player, toPickUp); - } - else - return true && handleProtections((EntityPlayerMP) player, toPickUp); - } - } - - if (CarryOnConfig.settings.useWhitelistEntities) - { - if (!ListHandler.isAllowed(toPickUp)) - { - return false; - } - } - else - { - if (ListHandler.isForbidden(toPickUp)) - { - return false; - } - } - - if ((CarryOnConfig.settings.pickupHostileMobs ? true : !toPickUp.isCreatureType(EnumCreatureType.MONSTER, false) || player.isCreative())) - { - if ((CarryOnConfig.settings.pickupHostileMobs ? true : !toPickUp.isCreatureType(EnumCreatureType.MONSTER, false) || player.isCreative())) - { - if ((toPickUp.height <= CarryOnConfig.settings.maxEntityHeight && toPickUp.width <= CarryOnConfig.settings.maxEntityWidth || player.isCreative())) - { - double distance = pos.distanceSqToCenter(player.posX, player.posY + 0.5, player.posZ); - if (distance < Math.pow(CarryOnConfig.settings.maxDistance, 2)) - { - if (toPickUp instanceof EntityTameable) - { - EntityTameable tame = (EntityTameable) toPickUp; - UUID owner = tame.getOwnerId(); - UUID playerID = player.getUUID(player.getGameProfile()); - if (owner != null && !owner.equals(playerID)) - return false; - } - - if (CustomPickupOverrideHandler.hasSpecialPickupConditions(toPickUp)) - { - IStageData stageData = PlayerDataHandler.getStageData(player); - String condition = CustomPickupOverrideHandler.getPickupCondition(toPickUp); - if (stageData.hasUnlockedStage(condition)) - return true && handleProtections((EntityPlayerMP) player, toPickUp); - } - else - return true && handleProtections((EntityPlayerMP) player, toPickUp); - } - } - } - - } - } - - return false; - } - - private static boolean handleProtections(EntityPlayerMP player, World world, BlockPos pos, IBlockState state) - { - boolean breakable = true; - - BlockEvent.BreakEvent event = new BlockEvent.BreakEvent(world, pos, state, player); - MinecraftForge.EVENT_BUS.post(event); - - if(event.isCanceled()) - breakable = false; - - return breakable; - } - - private static boolean handleProtections(EntityPlayerMP player, Entity entity) - { - boolean canPickup = true; - - AttackEntityEvent event = new AttackEntityEvent(player, entity); - MinecraftForge.EVENT_BUS.post(event); - - if(event.isCanceled()) - canPickup = false; - - return canPickup; - } - -} diff --git a/src/main/java/tschipp/carryon/common/handler/RegistrationHandler.java b/src/main/java/tschipp/carryon/common/handler/RegistrationHandler.java deleted file mode 100644 index 35fa825..0000000 --- a/src/main/java/tschipp/carryon/common/handler/RegistrationHandler.java +++ /dev/null @@ -1,64 +0,0 @@ -package tschipp.carryon.common.handler; - -import net.minecraft.client.renderer.block.model.ModelResourceLocation; -import net.minecraft.item.Item; -import net.minecraftforge.client.model.ModelLoader; -import net.minecraftforge.common.MinecraftForge; -import net.minecraftforge.common.capabilities.CapabilityManager; -import tschipp.carryon.CarryOn; -import tschipp.carryon.client.event.RenderEntityEvents; -import tschipp.carryon.client.event.RenderEvents; -import tschipp.carryon.common.capabilities.IPosition; -import tschipp.carryon.common.capabilities.PositionStorage; -import tschipp.carryon.common.capabilities.TEPosition; -import tschipp.carryon.common.capabilities.event.PositionClientEvents; -import tschipp.carryon.common.capabilities.event.PositionCommonEvents; -import tschipp.carryon.common.event.ItemEntityEvents; -import tschipp.carryon.common.event.ItemEvents; -import tschipp.carryon.common.item.ItemEntity; -import tschipp.carryon.common.item.ItemTile; - -public class RegistrationHandler -{ - public static Item itemTile; - public static Item itemEntity; - - public static void regItems() - { - itemTile = new ItemTile(); - itemEntity = new ItemEntity(); - } - - public static void regItemRenders() - { - ModelLoader.setCustomModelResourceLocation(itemTile, 0, new ModelResourceLocation(CarryOn.MODID + ":" + "tile", "inventory")); - ModelLoader.setCustomModelResourceLocation(itemEntity, 0, new ModelResourceLocation(CarryOn.MODID + ":" + "tile", "inventory")); - } - - public static void regCommonEvents() - { - MinecraftForge.EVENT_BUS.register(new ItemEvents()); - MinecraftForge.EVENT_BUS.register(new ItemEntityEvents()); - MinecraftForge.EVENT_BUS.register(new PositionCommonEvents()); - } - - public static void regClientEvents() - { - MinecraftForge.EVENT_BUS.register(new RenderEvents()); - MinecraftForge.EVENT_BUS.register(new RenderEntityEvents()); - MinecraftForge.EVENT_BUS.register(new PositionClientEvents()); - } - - public static void regOverrideList() - { - ModelOverridesHandler.initOverrides(); - CustomPickupOverrideHandler.initPickupOverrides(); - ListHandler.initForbiddenTiles(); - } - - public static void regCaps() - { - CapabilityManager.INSTANCE.register(IPosition.class, new PositionStorage(), TEPosition::new); - } - -} diff --git a/src/main/java/tschipp/carryon/common/helper/InvalidConfigException.java b/src/main/java/tschipp/carryon/common/helper/InvalidConfigException.java deleted file mode 100644 index fdabc9c..0000000 --- a/src/main/java/tschipp/carryon/common/helper/InvalidConfigException.java +++ /dev/null @@ -1,31 +0,0 @@ -package tschipp.carryon.common.helper; - -import tschipp.carryon.CarryOn; - -public class InvalidConfigException extends Exception -{ - - public InvalidConfigException(String cause) - { - super(cause); - } - - public void printException() - { - CarryOn.LOGGER.error(this.getMessage()); - for (int i = 0; i < this.getStackTrace().length; i++) - { - StackTraceElement element = this.getStackTrace()[i]; - CarryOn.LOGGER.error(element.toString()); - - if(i >= 10) - { - CarryOn.LOGGER.error((this.getStackTrace().length - 10) + " more..."); - break; - } - } - - CarryOn.LOGGER.info(""); - } - -} diff --git a/src/main/java/tschipp/carryon/common/helper/ReflectionUtil.java b/src/main/java/tschipp/carryon/common/helper/ReflectionUtil.java deleted file mode 100644 index 6f7f376..0000000 --- a/src/main/java/tschipp/carryon/common/helper/ReflectionUtil.java +++ /dev/null @@ -1,76 +0,0 @@ -package tschipp.carryon.common.helper; - -import java.lang.invoke.MethodHandle; -import java.lang.invoke.MethodHandles; -import java.lang.reflect.Field; -import java.lang.reflect.Method; - -import net.minecraftforge.fml.relauncher.ReflectionHelper; - -/** - * Utility methods for reflection. - * - * @author Choonster - */ -public class ReflectionUtil -{ - /** - * Get a {@link MethodHandle} for a method. - * - * @param clazz - * The class - * @param methodNames - * The possible names of the method - * @param methodTypes - * The argument types of the method - * @param - * The class - * @return The MethodHandle - */ - public static MethodHandle findMethod(Class clazz, String[] methodNames, Class... methodTypes) { - final Method method = ReflectionHelper.findMethod(clazz, null, methodNames, methodTypes); - try { - return MethodHandles.lookup().unreflect(method); - } catch (IllegalAccessException e) { - throw new ReflectionHelper.UnableToFindMethodException(methodNames, e); - } - } - - /** - * Get a {@link MethodHandle} for a field's getter. - * - * @param clazz - * The class - * @param fieldNames - * The possible names of the field - * @return The MethodHandle - */ - public static MethodHandle findFieldGetter(Class clazz, String... fieldNames) { - final Field field = ReflectionHelper.findField(clazz, fieldNames); - - try { - return MethodHandles.lookup().unreflectGetter(field); - } catch (IllegalAccessException e) { - throw new ReflectionHelper.UnableToAccessFieldException(fieldNames, e); - } - } - - /** - * Get a {@link MethodHandle} for a field's setter. - * - * @param clazz - * The class - * @param fieldNames - * The possible names of the field - * @return The MethodHandle - */ - public static MethodHandle findFieldSetter(Class clazz, String... fieldNames) { - final Field field = ReflectionHelper.findField(clazz, fieldNames); - - try { - return MethodHandles.lookup().unreflectSetter(field); - } catch (IllegalAccessException e) { - throw new ReflectionHelper.UnableToAccessFieldException(fieldNames, e); - } - } -} \ No newline at end of file diff --git a/src/main/java/tschipp/carryon/common/helper/ScriptParseHelper.java b/src/main/java/tschipp/carryon/common/helper/ScriptParseHelper.java deleted file mode 100644 index 0163a55..0000000 --- a/src/main/java/tschipp/carryon/common/helper/ScriptParseHelper.java +++ /dev/null @@ -1,372 +0,0 @@ -package tschipp.carryon.common.helper; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; -import java.util.Map; - -import net.minecraft.block.Block; -import net.minecraft.block.material.Material; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.nbt.NBTBase; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.potion.PotionEffect; -import net.minecraft.scoreboard.Score; -import net.minecraft.scoreboard.ScoreObjective; -import net.minecraft.scoreboard.Scoreboard; -import net.minecraft.stats.Achievement; -import net.minecraft.stats.AchievementList; -import net.minecraft.util.math.BlockPos; - -public class ScriptParseHelper -{ - - public static boolean matches(double number, String cond) - { - if (cond == null) - return true; - - try - { - if (cond.contains("<=")) - { - return number <= Double.parseDouble(cond.replace("<=", "")); - } - if (cond.contains(">=")) - { - return number >= Double.parseDouble(cond.replace(">=", "")); - } - if (cond.contains("<")) - { - return number < Double.parseDouble(cond.replace("<", "")); - } - if (cond.contains(">")) - { - return number > Double.parseDouble(cond.replace(">", "")); - } - if (cond.contains("=")) - { - return number == Double.parseDouble(cond.replace("=", "")); - } - else - return number == Double.parseDouble(cond); - - } - catch (Exception e) - { - new InvalidConfigException(e.getMessage()).printException(); - } - - return false; - } - - public static boolean matches(Block block, String cond) - { - if (cond == null) - return true; - - Block toCheck = StringParser.getBlock(cond); - if (toCheck != null) - return block == toCheck; - - return false; - } - - public static boolean matches(NBTTagCompound toCheck, NBTTagCompound toMatch) - { - if (toCheck == null || toMatch == null) - return true; - - boolean matching = true; - for (String key : toMatch.getKeySet()) - { - NBTBase tag = toMatch.getTag(key); - key = key.replace("\"", ""); - NBTBase tagToCheck = toCheck.getTag(key); - if (!tag.equals(tagToCheck)) - matching = false; - } - - return matching; - } - - public static double[] getXYZArray(String s) - { - double[] d = new double[3]; - d[0] = getValueFromString(s, "x"); - d[1] = getValueFromString(s, "y"); - d[2] = getValueFromString(s, "z"); - - return d; - } - - - public static double[] getScale(String s) - { - double[] d = new double[3]; - d[0] = getScaleValueFromString(s, "x"); - d[1] = getScaleValueFromString(s, "y"); - d[2] = getScaleValueFromString(s, "z"); - - return d; - } - - public static double getScaleValueFromString(String toGetFrom, String key) - { - if(toGetFrom == null) - return 1; - - String[] s = toGetFrom.split(","); - for (String string : s) - { - if (string.contains(key) && string.contains("=")) - { - double numb = 1; - string = string.replace(key + "=", ""); - - try - { - numb = Double.parseDouble(string); - } - catch (Exception e) - { - } - - return numb; - } - } - - return 1; - } - - public static Achievement getAchievementFromString(String s) - { - if (s == null) - return null; - - for (Achievement a : AchievementList.ACHIEVEMENTS) - { - if (a.statId.equals(s)) - return a; - } - - return null; - } - - public static boolean matchesScore(EntityPlayer player, String cond) - { - if (cond == null) - return true; - - Scoreboard score = player.getWorldScoreboard(); - String numb; - String scorename; - int iE = cond.indexOf("="); - int iG = cond.indexOf(">"); - int iL = cond.indexOf("<"); - - if (iG == -1 ? true : iE < iG && iL == -1 ? true : iE < iL && iE != -1) - numb = cond.substring(iE); - else if (iE == -1 ? true : iG < iE && iL == -1 ? true : iG < iL && iG != -1) - numb = cond.substring(iG); - else - numb = cond.substring(iL); - - scorename = cond.replace(numb, ""); - Map o = score.getObjectivesForEntity(player.getGameProfile().getName()); - if (o != null) - { - Score sc = o.get(score.getObjective(scorename)); - if (sc != null) - { - int points = sc.getScorePoints(); - - return matches(points, numb); - } - } - - return false; - } - - public static boolean matches(BlockPos pos, String cond) - { - if (cond == null) - return true; - - BlockPos blockpos = new BlockPos(getValueFromString(cond, "x"), getValueFromString(cond, "y"), getValueFromString(cond, "z")); - BlockPos expand = new BlockPos(getValueFromString(cond, "dx"), getValueFromString(cond, "dy"), getValueFromString(cond, "dz")); - BlockPos expanded = blockpos.add(expand); - - boolean x = (pos.getX() >= blockpos.getX() && pos.getX() <= expanded.getX()) || blockpos.getX() == 0; - boolean y = (pos.getY() >= blockpos.getY() && pos.getY() <= expanded.getY()) || blockpos.getY() == 0; - boolean z = (pos.getZ() >= blockpos.getZ() && pos.getZ() <= expanded.getZ()) || blockpos.getZ() == 0; - - return x && y && z; - } - - public static double getValueFromString(String toGetFrom, String key) - { - if(toGetFrom == null) - return 0; - - String[] s = toGetFrom.split(","); - for (String string : s) - { - if (string.contains(key) && string.contains("=")) - { - double numb = 0; - string = string.replace(key + "=", ""); - - try - { - numb = Double.parseDouble(string); - } - catch (Exception e) - { - } - - return numb; - } - } - - return 0; - } - - public static boolean hasEffects(EntityPlayer player, String cond) - { - if(cond == null) - return true; - - Collection effects = player.getActivePotionEffects(); - String[] potions = cond.split(","); - - List names = new ArrayList(); - List levels = new ArrayList(); - - for(int i = 0; i < potions.length; i++) - { - String pot = potions[i]; - if(pot.contains("#")) - { - String level = pot.substring(pot.indexOf("#")); - String name = pot.substring(0, pot.indexOf("#")); - level = level.replace("#", ""); - int lev = 0; - try - { - lev = Integer.parseInt(level); - } - catch(Exception e) - {} - - levels.add(lev); - names.add(name); - } - else - { - levels.add(0); - names.add(pot); - } - } - - int matches = 0; - for(PotionEffect effect : effects) - { - int amp = effect.getAmplifier(); - String name = effect.getPotion().getRegistryName().toString(); - - if(names.contains(name)) - { - int idx = names.indexOf(name); - int lev = levels.get(idx); - - if(lev == amp) - matches++; - } - } - - return matches == potions.length; - } - - public static boolean matches(Material material, String cond) - { - if (cond == null) - return true; - - switch (cond) - { - case "air": - return material == Material.AIR; - case "anvil": - return material == Material.ANVIL; - case "barrier": - return material == Material.BARRIER; - case "cactus": - return material == Material.CACTUS; - case "cake": - return material == Material.CAKE; - case "carpet": - return material == Material.CARPET; - case "circuits": - return material == Material.CIRCUITS; - case "clay": - return material == Material.CLAY; - case "cloth": - return material == Material.CLOTH; - case "coral": - return material == Material.CORAL; - case "dragon_egg": - return material == Material.DRAGON_EGG; - case "fire": - return material == Material.FIRE; - case "glass": - return material == Material.GLASS; - case "gourd": - return material == Material.GOURD; - case "grass": - return material == Material.GRASS; - case "ground": - return material == Material.GROUND; - case "ice": - return material == Material.ICE; - case "iron": - return material == Material.IRON; - case "lava": - return material == Material.LAVA; - case "leaves": - return material == Material.LEAVES; - case "packed_ice": - return material == Material.PACKED_ICE; - case "piston": - return material == Material.PISTON; - case "plants": - return material == Material.PLANTS; - case "portal": - return material == Material.PORTAL; - case "redstone_light": - return material == Material.REDSTONE_LIGHT; - case "rock": - return material == Material.ROCK; - case "sand": - return material == Material.SAND; - case "snow": - return material == Material.SNOW; - case "sponge": - return material == Material.SPONGE; - case "structure_void": - return material == Material.STRUCTURE_VOID; - case "tnt": - return material == Material.TNT; - case "vine": - return material == Material.VINE; - case "water": - return material == Material.WATER; - case "web": - return material == Material.WEB; - case "wood": - return material == Material.WOOD; - } - - return false; - } -} diff --git a/src/main/java/tschipp/carryon/common/helper/StringParser.java b/src/main/java/tschipp/carryon/common/helper/StringParser.java deleted file mode 100644 index edd9184..0000000 --- a/src/main/java/tschipp/carryon/common/helper/StringParser.java +++ /dev/null @@ -1,158 +0,0 @@ -package tschipp.carryon.common.helper; - -import javax.annotation.Nullable; - -import org.apache.logging.log4j.Level; - -import net.minecraft.block.Block; -import net.minecraft.block.state.IBlockState; -import net.minecraft.item.Item; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.JsonToNBT; -import net.minecraft.nbt.NBTException; -import net.minecraft.nbt.NBTTagCompound; -import tschipp.carryon.CarryOn; - -public class StringParser -{ - - @Nullable - public static Block getBlock(String string) - { - if(string == null) - return null; - - NBTTagCompound tag = getTagCompound(string); - if (tag != null) - string = string.replace(tag.toString(), ""); - - if (string.contains(";")) - string = string.replace(string.substring(string.indexOf(";")), ""); - - Block block = Block.getBlockFromName(string); - if (block == null) - new InvalidConfigException("Block Parsing Error. Invalid Name: " + string).printException(); - - return block; - } - - public static int getMeta(String string) - { - if(string == null) - return 0; - - NBTTagCompound tag = getTagCompound(string); - if (tag != null) - string = string.replace(tag.toString(), ""); - - if (string.contains(";")) - { - int meta = 0; - try - { - meta = Integer.parseInt(string.substring(string.indexOf(";")).replace(";", "")); - } - catch (Exception e) - { - new InvalidConfigException("Meta Parsing Error at: " + string + " : " + e.getMessage()).printException(); - } - - return meta; - } - return 0; - } - - @Nullable - public static IBlockState getBlockState(String string) - { - if(string == null) - return null; - - NBTTagCompound tag = getTagCompound(string); - if (tag != null) - string = string.replace(tag.toString(), ""); - - int meta = getMeta(string); - if (meta == 0) - { - Block block = getBlock(string); - if(block != null) - return block.getDefaultState(); - } - try - { - return getBlock(string).getStateFromMeta(meta); - } - catch (Exception e) - { - new InvalidConfigException("Blockstate parsing Exception at: " + string + " : " + e.getMessage()).printException(); - return null; - } - } - - @Nullable - public static Item getItem(String string) - { - if(string == null) - return null; - - NBTTagCompound tag = getTagCompound(string); - if (tag != null) - string = string.replace(tag.toString(), ""); - - if (string.contains(";")) - string = string.replace(string.substring(string.indexOf(";")), ""); - - return Item.getByNameOrId(string); - } - - public static ItemStack getItemStack(String string) - { - if(string == null) - return null; - - Item item = getItem(string); - - if(item == null) - return ItemStack.EMPTY; - - ItemStack stack = new ItemStack(item, 1, getMeta(string)); - NBTTagCompound tag = getTagCompound(string); - if (tag != null) - stack.setTagCompound(tag); - - return stack; - } - - @Nullable - public static NBTTagCompound getTagCompound(String string) - { - NBTTagCompound tag = null; - if(string == null) - return null; - - if (string.contains("{")) - { - if (!string.contains("}")) - new InvalidConfigException("Missing } at : " + string).printException(); - - String nbt = string.substring(string.indexOf("{")); - string = string.replace(nbt, ""); - try - { - tag = JsonToNBT.getTagFromJson(nbt); - } - catch (NBTException e) - { - new InvalidConfigException("Error while parsing NBT: " + e.getMessage()).printException(); - return null; - } - - } - else if (string.contains("}")) - new InvalidConfigException("Missing { at : " + string).printException(); - - return tag; - } - -} diff --git a/src/main/java/tschipp/carryon/common/item/ItemEntity.java b/src/main/java/tschipp/carryon/common/item/ItemEntity.java deleted file mode 100644 index 392c879..0000000 --- a/src/main/java/tschipp/carryon/common/item/ItemEntity.java +++ /dev/null @@ -1,221 +0,0 @@ -package tschipp.carryon.common.item; - -import javax.annotation.Nonnull; - -import net.minecraft.block.Block; -import net.minecraft.entity.Entity; -import net.minecraft.entity.EntityList; -import net.minecraft.entity.EntityLiving; -import net.minecraft.entity.EntityLivingBase; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.init.MobEffects; -import net.minecraft.item.Item; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.potion.PotionEffect; -import net.minecraft.util.EnumActionResult; -import net.minecraft.util.EnumFacing; -import net.minecraft.util.EnumHand; -import net.minecraft.util.ResourceLocation; -import net.minecraft.util.math.BlockPos; -import net.minecraft.util.text.translation.I18n; -import net.minecraft.world.World; -import net.minecraftforge.fml.common.network.NetworkRegistry.TargetPoint; -import net.minecraftforge.fml.common.registry.GameRegistry; -import tschipp.carryon.CarryOn; -import tschipp.carryon.common.config.CarryOnConfig; -import tschipp.carryon.network.client.CarrySlotPacket; - -public class ItemEntity extends Item -{ - - public static final String ENTITY_DATA_KEY = "entityData"; - - public ItemEntity() - { - this.setUnlocalizedName("entity_item"); - this.setRegistryName(CarryOn.MODID, "entity_item"); - GameRegistry.register(this); - this.setMaxStackSize(1); - } - - @Override - public String getItemStackDisplayName(ItemStack stack) - { - if (hasEntityData(stack)) - { - return I18n.translateToLocal("entity."+EntityList.getTranslationName(new ResourceLocation(getEntityName(stack))) + ".name"); - } - - return ""; - } - - public static boolean hasEntityData(ItemStack stack) - { - if (stack.hasTagCompound()) - { - NBTTagCompound tag = stack.getTagCompound(); - return tag.hasKey(ENTITY_DATA_KEY) && tag.hasKey("entity"); - } - return false; - } - - public static boolean storeEntityData(@Nonnull Entity entity, World world, ItemStack stack) - { - if (entity == null) - return false; - - if (stack.isEmpty()) - return false; - - NBTTagCompound entityData = new NBTTagCompound(); - entityData = entity.writeToNBT(entityData); - - String name = EntityList.getKey(entity).toString(); - - NBTTagCompound tag = stack.hasTagCompound() ? stack.getTagCompound() : new NBTTagCompound(); - if (tag.hasKey(ENTITY_DATA_KEY)) - return false; - - tag.setTag(ENTITY_DATA_KEY, entityData); - tag.setString("entity", name); - stack.setTagCompound(tag); - return true; - } - - @Override - public EnumActionResult onItemUse(EntityPlayer player, World world, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) - { - ItemStack stack = player.getHeldItem(hand); - Block block = world.getBlockState(pos).getBlock(); - - if (hasEntityData(stack)) - { - BlockPos finalPos = pos; - - if (!block.isReplaceable(world, pos)) - { - finalPos = pos.offset(facing); - } - - Entity entity = getEntity(stack, world); - if (entity != null) - { - if (!world.isRemote) - { - entity.setPositionAndRotation(finalPos.getX() + 0.5, finalPos.getY(), finalPos.getZ() + 0.5, 180 + player.rotationYawHead, 0.0f); - world.spawnEntity(entity); - if (entity instanceof EntityLiving) - { - ((EntityLiving) entity).playLivingSound(); - } - clearEntityData(stack); - player.setHeldItem(hand, ItemStack.EMPTY); - CarryOn.network.sendToAllAround(new CarrySlotPacket(9, player.getEntityId()), new TargetPoint(world.provider.getDimension(), player.posX, player.posY, player.posZ, 256)); - } - player.getEntityData().removeTag("overrideKey"); - return EnumActionResult.SUCCESS; - } - } - - return EnumActionResult.FAIL; - } - - @Override - public void onUpdate(ItemStack stack, World world, Entity entity, int itemSlot, boolean isSelected) - { - if (hasEntityData(stack)) - { - if(getEntity(stack, world) == null) - stack = ItemStack.EMPTY; - - if (entity instanceof EntityLivingBase) - { - if(entity instanceof EntityPlayer && CarryOnConfig.settings.slownessInCreative ? false : ((EntityPlayer)entity).isCreative()) - return; - - ((EntityLivingBase) entity).addPotionEffect(new PotionEffect(MobEffects.SLOWNESS, 1, potionLevel(stack, world), false, false)); - } - - } - else - { - stack = ItemStack.EMPTY; - } - } - - public static void clearEntityData(ItemStack stack) - { - if (stack.hasTagCompound()) - { - NBTTagCompound tag = stack.getTagCompound(); - tag.removeTag(ENTITY_DATA_KEY); - tag.removeTag("entity"); - } - } - - public static NBTTagCompound getEntityData(ItemStack stack) - { - if (stack.hasTagCompound()) - { - NBTTagCompound tag = stack.getTagCompound(); - return tag.getCompoundTag(ENTITY_DATA_KEY); - } - return null; - } - - public static Entity getEntity(ItemStack stack, World world) - { - if (world == null) - return null; - - String name = getEntityName(stack); - - NBTTagCompound e = getEntityData(stack); - Entity entity = EntityList.createEntityByIDFromName(new ResourceLocation(name), world); - if (entity != null) - entity.readFromNBT(e); - - return entity; - } - - public static String getEntityName(ItemStack stack) - { - if (stack.hasTagCompound()) - { - NBTTagCompound tag = stack.getTagCompound(); - return tag.getString("entity"); - } - return null; - } - - public static String getCustomName(ItemStack stack) - { - if (stack.hasTagCompound()) - { - NBTTagCompound tag = stack.getTagCompound(); - if (tag.hasKey("CustomName") && !tag.getString("CustomName").isEmpty()) { - return tag.toString(); - } else { - return tag.toString(); - } - } - return null; - } - - private int potionLevel(ItemStack stack, World world) - { - Entity e = getEntity(stack, world); - if(e == null) - return 1; - - int i = (int)(e.height * e.width); - if (i > 4) - i = 4; - - if (!CarryOnConfig.settings.heavyEntities) - i = 1; - - return (int) (i * CarryOnConfig.settings.entitySlownessMultiplier); - } -} diff --git a/src/main/java/tschipp/carryon/common/item/ItemTile.java b/src/main/java/tschipp/carryon/common/item/ItemTile.java deleted file mode 100644 index 9b26c0f..0000000 --- a/src/main/java/tschipp/carryon/common/item/ItemTile.java +++ /dev/null @@ -1,333 +0,0 @@ -package tschipp.carryon.common.item; - -import java.util.Arrays; -import java.util.Iterator; -import java.util.List; - -import javax.annotation.Nullable; - -import net.minecraft.block.Block; -import net.minecraft.block.BlockStairs; -import net.minecraft.block.properties.IProperty; -import net.minecraft.block.properties.PropertyDirection; -import net.minecraft.block.state.IBlockState; -import net.minecraft.entity.Entity; -import net.minecraft.entity.EntityLivingBase; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.init.Blocks; -import net.minecraft.init.MobEffects; -import net.minecraft.item.Item; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.potion.PotionEffect; -import net.minecraft.tileentity.TileEntity; -import net.minecraft.util.EnumActionResult; -import net.minecraft.util.EnumFacing; -import net.minecraft.util.EnumHand; -import net.minecraft.util.math.BlockPos; -import net.minecraft.util.math.Vec3d; -import net.minecraft.util.text.TextComponentString; -import net.minecraft.util.text.TextFormatting; -import net.minecraft.util.text.event.ClickEvent; -import net.minecraft.util.text.event.ClickEvent.Action; -import net.minecraft.world.World; -import net.minecraftforge.fml.common.network.NetworkRegistry.TargetPoint; -import net.minecraftforge.fml.common.registry.GameRegistry; -import tschipp.carryon.CarryOn; -import tschipp.carryon.common.config.CarryOnConfig; -import tschipp.carryon.common.handler.CustomPickupOverrideHandler; -import tschipp.carryon.common.handler.ModelOverridesHandler; -import tschipp.carryon.network.client.CarrySlotPacket; - -public class ItemTile extends Item -{ - - public static final String TILE_DATA_KEY = "tileData"; - - public ItemTile() - { - this.setUnlocalizedName("tile_item"); - this.setRegistryName(CarryOn.MODID, "tile_item"); - GameRegistry.register(this); - this.setMaxStackSize(1); - } - - @Override - public String getItemStackDisplayName(ItemStack stack) - { - if (hasTileData(stack)) - { - IBlockState state = getBlockState(stack); - NBTTagCompound nbt = getTileData(stack); - - if (ModelOverridesHandler.hasCustomOverrideModel(state, nbt)) - { - Object override = ModelOverridesHandler.getOverrideObject(state, nbt); - if (override instanceof ItemStack) - return ((ItemStack) override).getDisplayName(); - else - { - IBlockState ostate = (IBlockState) override; - ItemStack itemstack = new ItemStack(ostate.getBlock().getItemDropped(ostate, this.itemRand, 0), 1, state.getBlock().damageDropped(ostate)); - return itemstack.getDisplayName(); - } - } - - return getItemStack(stack).getDisplayName(); - } - - return ""; - } - - @Override - public EnumActionResult onItemUse(EntityPlayer player, World world, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) - { - Block block = world.getBlockState(pos).getBlock(); - ItemStack stack = player.getHeldItem(hand); - if (hasTileData(stack)) - { - try - { - Vec3d vec = player.getLookVec(); - EnumFacing facing2 = EnumFacing.getFacingFromVector((float) vec.xCoord, 0f, (float) vec.zCoord); - BlockPos pos2 = pos; - Block containedblock = getBlock(stack); - int meta = getMeta(stack); - IBlockState containedstate = getBlockState(stack); - if (!world.getBlockState(pos2).getBlock().isReplaceable(world, pos2)) - { - pos2 = pos.offset(facing); - } - - if (world.getBlockState(pos2).getBlock().isReplaceable(world, pos2) && containedblock != null) - { - boolean canPlace = containedblock.canPlaceBlockAt(world, pos2); - - if (canPlace) - { - if (player.canPlayerEdit(pos, facing, stack) && world.mayPlace(containedblock, pos2, false, facing, (Entity) null)) - { - boolean set = false; - - Iterator> iterator = containedblock.getDefaultState().getPropertyKeys().iterator(); - while (iterator.hasNext()) - { - IProperty prop = iterator.next(); - Object[] allowedValues = prop.getAllowedValues().toArray(); - - if (prop instanceof PropertyDirection && this.equal(allowedValues, EnumFacing.HORIZONTALS)) - { - world.setBlockState(pos2, containedstate.withProperty(prop, containedblock instanceof BlockStairs ? facing2 : facing2.getOpposite())); - set = true; - } - else if (prop instanceof PropertyDirection && this.equal(allowedValues, EnumFacing.VALUES)) - { - facing2 = EnumFacing.getFacingFromVector((float) vec.xCoord, (float) vec.yCoord, (float) vec.zCoord); - world.setBlockState(pos2, containedstate.withProperty(prop, facing2.getOpposite())); - set = true; - } - - } - - if (!set) - world.setBlockState(pos2, containedstate); - - TileEntity tile = world.getTileEntity(pos2); - if (tile != null) - { - tile.readFromNBT(getTileData(stack)); - tile.setPos(pos2); - } - clearTileData(stack); - player.playSound(containedblock.getSoundType().getPlaceSound(), 1.0f, 0.5f); - player.setHeldItem(hand, ItemStack.EMPTY); - player.getEntityData().removeTag("overrideKey"); - CarryOn.network.sendToAllAround(new CarrySlotPacket(9, player.getEntityId()), new TargetPoint(world.provider.getDimension(), player.posX, player.posY, player.posZ, 256)); - return EnumActionResult.SUCCESS; - } - - } - } - } - catch (Exception e) - { - e.printStackTrace(); - - if (world != null && world.isRemote) - { - CarryOn.LOGGER.info("Block: " + ItemTile.getBlock(stack)); - CarryOn.LOGGER.info("BlockState: " + ItemTile.getBlockState(stack)); - CarryOn.LOGGER.info("Meta: " + ItemTile.getMeta(stack)); - CarryOn.LOGGER.info("ItemStack: " + ItemTile.getItemStack(stack)); - - if (ModelOverridesHandler.hasCustomOverrideModel(ItemTile.getBlockState(stack), ItemTile.getTileData(stack))) - CarryOn.LOGGER.info("Override Model: " + ModelOverridesHandler.getOverrideObject(ItemTile.getBlockState(stack), ItemTile.getTileData(stack))); - - if (CustomPickupOverrideHandler.hasSpecialPickupConditions(ItemTile.getBlockState(stack))) - CarryOn.LOGGER.info("Custom Pickup Condition: " + CustomPickupOverrideHandler.getPickupCondition(ItemTile.getBlockState(stack))); - - player.sendMessage(new TextComponentString(TextFormatting.RED + "Error detected. Cannot place block. Execute \"/carryon clear\" to remove the item")); - TextComponentString s = new TextComponentString(TextFormatting.GOLD + "here"); - s.getStyle().setClickEvent(new ClickEvent(Action.OPEN_URL, "https://github.com/Tschipp/CarryOn/issues")); - player.sendMessage(new TextComponentString(TextFormatting.RED + "Please report this error ").appendSibling(s)); - - } - } - - } - - return EnumActionResult.FAIL; - } - - @Override - public void onUpdate(ItemStack stack, World world, Entity entity, int itemSlot, boolean isSelected) - { - if (hasTileData(stack)) - { - if (entity instanceof EntityLivingBase) - { - if (entity instanceof EntityPlayer && CarryOnConfig.settings.slownessInCreative ? false : ((EntityPlayer) entity).isCreative()) - return; - - ((EntityLivingBase) entity).addPotionEffect(new PotionEffect(MobEffects.SLOWNESS, 1, potionLevel(stack), false, false)); - } - } - else - { - stack = ItemStack.EMPTY; - } - } - - public static boolean hasTileData(ItemStack stack) - { - if (stack.hasTagCompound()) - { - NBTTagCompound tag = stack.getTagCompound(); - return tag.hasKey(TILE_DATA_KEY) && tag.hasKey("block") && tag.hasKey("meta") && tag.hasKey("stateid"); - } - return false; - } - - public static boolean storeTileData(@Nullable TileEntity tile, World world, BlockPos pos, IBlockState state, ItemStack stack) - { - if (stack.isEmpty()) - return false; - - NBTTagCompound chest = new NBTTagCompound(); - if (tile != null) - chest = tile.writeToNBT(chest); - - NBTTagCompound tag = stack.hasTagCompound() ? stack.getTagCompound() : new NBTTagCompound(); - if (tag.hasKey(TILE_DATA_KEY)) - return false; - - tag.setTag(TILE_DATA_KEY, chest); - - ItemStack drop = new ItemStack(state.getBlock().getItemDropped(state, itemRand, 0), 1, state.getBlock().damageDropped(state)); - - tag.setString("block", state.getBlock().getRegistryName().toString()); - Item item = Item.getItemFromBlock(state.getBlock()); - tag.setInteger("meta", drop.getItemDamage()); - tag.setInteger("stateid", Block.getStateId(state)); - stack.setTagCompound(tag); - return true; - } - - public static void clearTileData(ItemStack stack) - { - if (stack.hasTagCompound()) - { - NBTTagCompound tag = stack.getTagCompound(); - tag.removeTag(TILE_DATA_KEY); - tag.removeTag("block"); - tag.removeTag("meta"); - tag.removeTag("stateid"); - } - } - - public static NBTTagCompound getTileData(ItemStack stack) - { - if (stack.hasTagCompound()) - { - NBTTagCompound tag = stack.getTagCompound(); - return tag.getCompoundTag(TILE_DATA_KEY); - } - return null; - } - - public static Block getBlock(ItemStack stack) - { - if (stack.hasTagCompound()) - { - NBTTagCompound tag = stack.getTagCompound(); - int id = tag.getInteger("stateid"); - return Block.getStateById(id).getBlock(); - } - return Blocks.AIR; - } - - public static int getMeta(ItemStack stack) - { - if (stack.hasTagCompound()) - { - NBTTagCompound tag = stack.getTagCompound(); - int meta = tag.getInteger("meta"); - return meta; - } - return 0; - } - - public static ItemStack getItemStack(ItemStack stack) - { - return new ItemStack(getBlock(stack), 1, getMeta(stack)); - } - - public static IBlockState getBlockState(ItemStack stack) - { - if (stack.hasTagCompound()) - { - NBTTagCompound tag = stack.getTagCompound(); - int id = tag.getInteger("stateid"); - return Block.getStateById(id); - } - return Blocks.AIR.getDefaultState(); - } - - public static boolean isLocked(BlockPos pos, World world) - { - TileEntity te = world.getTileEntity(pos); - if (te != null) - { - NBTTagCompound tag = new NBTTagCompound(); - te.writeToNBT(tag); - return tag.hasKey("Lock") ? !tag.getString("Lock").equals("") : false; - } - - return false; - } - - private boolean equal(Object[] a, Object[] b) - { - if (a.length != b.length) - return false; - - List lA = Arrays.asList(a); - List lB = Arrays.asList(b); - - return lA.containsAll(lB); - } - - private int potionLevel(ItemStack stack) - { - String nbt = getTileData(stack).toString(); - int i = nbt.length() / 500; - - if (i > 4) - i = 4; - - if (!CarryOnConfig.settings.heavyTiles) - i = 1; - - return (int) (i * CarryOnConfig.settings.blockSlownessMultiplier); - } -} diff --git a/src/main/java/tschipp/carryon/interfaces/ICarryOnData.java b/src/main/java/tschipp/carryon/interfaces/ICarryOnData.java new file mode 100644 index 0000000..5e28dbb --- /dev/null +++ b/src/main/java/tschipp/carryon/interfaces/ICarryOnData.java @@ -0,0 +1,11 @@ +package tschipp.carryon.interfaces; + +import net.minecraft.nbt.CompoundTag; + +public interface ICarryOnData { + + public CompoundTag getCarryOnData(); + + public void setCarryOnData(CompoundTag tag); + +} \ No newline at end of file diff --git a/src/main/java/tschipp/carryon/items/ItemEntity.java b/src/main/java/tschipp/carryon/items/ItemEntity.java new file mode 100644 index 0000000..1c9177e --- /dev/null +++ b/src/main/java/tschipp/carryon/items/ItemEntity.java @@ -0,0 +1,213 @@ +package tschipp.carryon.items; + +import net.minecraft.entity.Entity; +import net.minecraft.entity.EntityType; +import net.minecraft.entity.LivingEntity; +import net.minecraft.entity.effect.StatusEffectInstance; +import net.minecraft.entity.effect.StatusEffects; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.item.Item; +import net.minecraft.item.ItemPlacementContext; +import net.minecraft.item.ItemStack; +import net.minecraft.item.ItemUsageContext; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.text.StringTextComponent; +import net.minecraft.text.TextComponent; +import net.minecraft.text.TranslatableTextComponent; +import net.minecraft.util.ActionResult; +import net.minecraft.util.Hand; +import net.minecraft.util.Identifier; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.Direction; +import net.minecraft.world.World; + +public class ItemEntity extends Item { + + public static final String ENTITY_DATA_KEY = "entityData"; + + public ItemEntity() { + super(new Item.Settings().stackSize(1)); + } + + @Override + public TextComponent getTranslatedNameTrimmed(ItemStack stack) { + if (hasEntityData(stack)) { + return new TranslatableTextComponent(getEntityType(stack).getTranslationKey()); + } + + return new StringTextComponent(""); + } + + public static boolean hasEntityData(ItemStack stack) { + if (stack.hasTag()) { + CompoundTag tag = stack.getTag(); + return tag.containsKey(ENTITY_DATA_KEY) && tag.containsKey("entity"); + } + return false; + } + + public static boolean storeEntityData(Entity entity, World world, ItemStack stack) { + if (entity == null) + return false; + + if (stack.isEmpty()) + return false; + + CompoundTag entityData = new CompoundTag(); + entityData = entity.toTag(entityData); + EntityType type = entity.getType(); + + String name = EntityType.getId(type).toString(); + + CompoundTag tag = stack.hasTag() ? stack.getTag() : new CompoundTag(); + if (tag.containsKey(ENTITY_DATA_KEY)) + return false; + + tag.put(ENTITY_DATA_KEY, entityData); + tag.putString("entity", name); + stack.setTag(tag); + return true; + } + + @Override + public ActionResult useOnBlock(ItemUsageContext context) { + + Direction Direction = context.getFacing(); + PlayerEntity player = context.getPlayer(); + World world = context.getWorld(); + BlockPos pos = context.getPos(); + ItemStack stack = context.getItemStack(); + + // if(Loader.isModLoaded("betterplacement")) + // { + // if(CarryOnKeybinds.isKeyPressed(player)) + // return ActionResult.FAIL; + // } + + if (hasEntityData(stack)) { + BlockPos finalPos = pos; + + if (!world.getBlockState(finalPos).method_11587(new ItemPlacementContext(context))) + { + finalPos = pos.offset(Direction); + } + + Entity entity = getEntity(stack, world); + if (entity != null) { + if (!world.isClient) { + entity.setPositionAndAngles(finalPos.getX() + 0.5, finalPos.getY(), finalPos.getZ() + 0.5, + 180 + player.yaw, 0.0f); + world.spawnEntity(entity); + if (entity instanceof LivingEntity) { + // ((LivingEntity) entity).sound.playLivingSound(); + } + clearEntityData(stack); + player.setStackInHand(Hand.MAIN, ItemStack.EMPTY); + // ItemEvents.sendPacket(player, 9, 0); + + } + // player.getEntityData().remove("overrideKey"); + return ActionResult.SUCCESS; + } + } + + return ActionResult.FAILURE; + } + + @Override + public void onUpdate(ItemStack stack, World world, Entity entity, int itemSlot, boolean isSelected) { + if (hasEntityData(stack)) { + if (getEntity(stack, world) == null) + stack = ItemStack.EMPTY; + + if (entity instanceof LivingEntity) { + if (entity instanceof PlayerEntity + && /* CarryOnConfig.settings.slownessInCreative ? false : */ ((PlayerEntity) entity) + .isCreative()) + return; + + ((LivingEntity) entity).addPotionEffect( + new StatusEffectInstance(StatusEffects.SLOWNESS, 1, potionLevel(stack, world), false, false)); + } + + } else { + stack = ItemStack.EMPTY; + } + } + + public static void clearEntityData(ItemStack stack) { + if (stack.hasTag()) { + CompoundTag tag = stack.getTag(); + tag.remove(ENTITY_DATA_KEY); + tag.remove("entity"); + } + } + + public static CompoundTag getEntityData(ItemStack stack) { + if (stack.hasTag()) { + CompoundTag tag = stack.getTag(); + return tag.getCompound(ENTITY_DATA_KEY); + } + return null; + } + + public static Entity getEntity(ItemStack stack, World world) { + if (world == null) + return null; + + String name = getEntityName(stack); + + CompoundTag e = getEntityData(stack); + Entity entity = EntityType.createInstance(world, new Identifier(name)); + if (entity != null) + entity.fromTag(e); + + return entity; + } + + public static String getEntityName(ItemStack stack) { + if (stack.hasTag()) { + CompoundTag tag = stack.getTag(); + return tag.getString("entity"); + } + return null; + } + + public static EntityType getEntityType(ItemStack stack) { + if (stack.hasTag()) { + CompoundTag tag = stack.getTag(); + String name = tag.getString("entity"); + EntityType type = EntityType.get(name); + return type; + } + return null; + } + + public static String getCustomName(ItemStack stack) { + if (stack.hasTag()) { + CompoundTag tag = stack.getTag(); + if (tag.containsKey("CustomName") && !tag.getString("CustomName").isEmpty()) { + return tag.toString(); + } else { + return tag.toString(); + } + } + return null; + } + + private int potionLevel(ItemStack stack, World world) { + Entity e = getEntity(stack, world); + if (e == null) + return 1; + + int i = (int) (e.height * e.width); + if (i > 4) + i = 4; + + // if (!CarryOnConfig.settings.heavyEntities) + // i = 1; + + // return (int) (i * CarryOnConfig.settings.entitySlownessMultiplier); + return i * 1; + } +} diff --git a/src/main/java/tschipp/carryon/items/ItemTile.java b/src/main/java/tschipp/carryon/items/ItemTile.java new file mode 100644 index 0000000..cf70a8a --- /dev/null +++ b/src/main/java/tschipp/carryon/items/ItemTile.java @@ -0,0 +1,351 @@ +package tschipp.carryon.items; + +import java.util.Set; + +import net.minecraft.block.Block; +import net.minecraft.block.BlockState; +import net.minecraft.block.Blocks; +import net.minecraft.block.entity.BlockEntity; +import net.minecraft.entity.Entity; +import net.minecraft.entity.LivingEntity; +import net.minecraft.entity.effect.StatusEffectInstance; +import net.minecraft.entity.effect.StatusEffects; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.item.Item; +import net.minecraft.item.ItemPlacementContext; +import net.minecraft.item.ItemStack; +import net.minecraft.item.ItemUsageContext; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.text.StringTextComponent; +import net.minecraft.text.TextComponent; +import net.minecraft.util.ActionResult; +import net.minecraft.util.Hand; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.Direction; +import net.minecraft.util.math.Vec3d; +import net.minecraft.util.registry.Registry; +import net.minecraft.world.World; + +public class ItemTile extends Item { + + public static final String TILE_DATA_KEY = "tileData"; + public static final String[] Direction_KEYS = new String[] { "rotation", "rot", "Direction", "face", "direction", "dir", + "front" }; + + public ItemTile() { + super(new Item.Settings().stackSize(1)); + } + + @Override + public TextComponent getTranslatedNameTrimmed(ItemStack stack) { + if (hasTileData(stack)) { + // BlockState state = getBlockState(stack); + // CompoundTag nbt = getTileData(stack); + + // if (ModelOverridesHandler.hasCustomOverrideModel(state, nbt)) + // { + // Object override = ModelOverridesHandler.getOverrideObject(state, nbt); + // if (override instanceof ItemStack) + // return ((ItemStack) override).getDisplayName(); + // else + // { + // BlockState ostate = (BlockState) override; + // List drops = ostate.getDroppedStacks(new LootContext.Builder()); + // ItemStack itemstack = new ItemStack(ostate.getBlock().getItemDropped(ostate, this.random, 0), 1, state.getBlock().damageDropped(ostate)); + // return itemstack.getDisplayName(); + // } + // } + + return getItemStack(stack).getItem().getTranslatedNameTrimmed(getItemStack(stack)); + } + + return new StringTextComponent(""); + } + + @Override + public ActionResult useOnBlock(ItemUsageContext context) + { + // if (Loader.isModLoaded("betterplacement")) + // { + // if (CarryOnKeybinds.isKeyPressed(player)) + // return EnumActionResult.FAIL; + // } + + Direction direction = context.getFacing(); + PlayerEntity player = context.getPlayer(); + World world = context.getWorld(); + BlockPos pos = context.getPos(); + ItemStack stack = context.getItemStack(); + + + // Block block = world.getBlockState(pos).getBlock(); + if (hasTileData(stack)) + { + try + { + Vec3d vec = player.getRotationVecClient(); + Direction direction2 = Direction.getFacing((float) vec.x, 0f, (float) vec.z); + BlockPos pos2 = pos; + Block containedblock = getBlock(stack); + BlockState containedstate = getBlockState(stack); + if (!world.getBlockState(pos).method_11587(new ItemPlacementContext(context))) + { + pos2 = pos.offset(direction); + } + + if (world.getBlockState(pos2).getBlock().method_9579(world.getBlockState(pos2), world, pos2) && containedblock != null) + { + boolean canPlace = containedblock.canPlaceAt(world.getBlockState(pos2), world, pos2); + + if (canPlace) + { + if (player.canPlaceBlock(pos2, direction, stack) && world.canPlayerModifyAt(player, pos2)) + { + // Handles Blockstate rotation + // Iterator> iterator = containedblock.getDefaultState().getProperties().iterator(); + // while (iterator.hasNext()) + // { + // Property prop = iterator.next(); + // Object[] allowedValues = prop.getValues().toArray(); + + // if (prop instanceof DirectionProperty && this.equal(allowedValues, horizontals)) + // { + // world.setBlockState(pos2, containedstate.with(prop, containedblock instanceof StairsBlock ? Direction2 : Direction2.getOpposite())); + // set = true; + // } + // else if (prop instanceof DirectionProperty && this.equal(allowedValues, Direction.values())) + // { + // Direction2 = Direction.getDirection((float) vec.x, (float) vec.y, (float) vec.z); + // world.setBlockState(pos2, containedstate.with(prop, Direction2.getOpposite())); + // set = true; + // } + // } + + BlockState actualState = containedblock.getPlacementState(new ItemPlacementContext(context)); + world.setBlockState(pos2, actualState); + + // world.updateNeighborsAlways(pos2, containedblock); + // If the blockstate doesn't handle rotation, try to + // change rotation via NBT + if (!getTileData(stack).isEmpty()) + { + CompoundTag tag = getTileData(stack); + Set keys = tag.getKeys(); + keytester: + for (String key : keys) + { + for (String DirectionKey : Direction_KEYS) + { + if (key.toLowerCase().equals(DirectionKey)) + { + byte type = tag.getType(key); + switch (type) + { + case 8: + tag.putString(key, direction2.getOpposite().getName()); + break; + case 3: + tag.putInt(key, direction2.getOpposite().getId()); + break; + case 1: + tag.putByte(key, (byte) direction2.getOpposite().getId()); + break; + default: + break; + } + + break keytester; + } + } + } + } + + BlockEntity tile = world.getBlockEntity(pos2); + if (tile != null) + { + tile.fromTag(getTileData(stack)); + tile.setPos(pos2); + } + clearTileData(stack); + player.playSoundAtEntity(containedstate.getSoundGroup().getPlaceSound(), 1.0f, 0.5f); + player.setStackInHand(Hand.MAIN, ItemStack.EMPTY); + // player.nbt.remove("overrideKey"); + // ItemEvents.sendPacket(player, 9, 0); + return ActionResult.SUCCESS; + } + + } + } + } + catch (Exception e) + { + e.printStackTrace(); + + // if (world != null && world.isRemote) + // { + // CarryOn.LOGGER.info("Block: " + ItemTile.getBlock(stack)); + // CarryOn.LOGGER.info("BlockState: " + ItemTile.getBlockState(stack)); + // CarryOn.LOGGER.info("Meta: " + ItemTile.getMeta(stack)); + // CarryOn.LOGGER.info("ItemStack: " + ItemTile.getItemStack(stack)); + + // if (ModelOverridesHandler.hasCustomOverrideModel(ItemTile.getBlockState(stack), ItemTile.getTileData(stack))) + // CarryOn.LOGGER.info("Override Model: " + ModelOverridesHandler.getOverrideObject(ItemTile.getBlockState(stack), ItemTile.getTileData(stack))); + + // if (CustomPickupOverrideHandler.hasSpecialPickupConditions(ItemTile.getBlockState(stack))) + // CarryOn.LOGGER.info("Custom Pickup Condition: " + CustomPickupOverrideHandler.getPickupCondition(ItemTile.getBlockState(stack))); + + // player.sendMessage(new TextComponentString(TextFormatting.RED + "Error detected. Cannot place block. Execute \"/carryon clear\" to remove the item")); + // TextComponentString s = new TextComponentString(TextFormatting.GOLD + "here"); + // s.getStyle().setClickEvent(new ClickEvent(Action.OPEN_URL, "https://github.com/Tschipp/CarryOn/issues")); + // player.sendMessage(new TextComponentString(TextFormatting.RED + "Please report this error ").appendSibling(s)); + + // } + } + + } + + return ActionResult.FAILURE; + } + + @Override + public void onUpdate(ItemStack stack, World world, Entity entity, int itemSlot, boolean isSelected) + { + if (hasTileData(stack)) + { + if (entity instanceof LivingEntity) + { + if (entity instanceof PlayerEntity && /*CarryOnConfig.settings.slownessInCreative ? false : */ ((PlayerEntity) entity).isCreative()) + return; + + ((LivingEntity) entity).addPotionEffect(new StatusEffectInstance(StatusEffects.SLOWNESS, 1, potionLevel(stack), false, false)); + } + } + else + { + stack = ItemStack.EMPTY; + } + } + + public static boolean hasTileData(ItemStack stack) + { + if (stack.hasTag()) + { + CompoundTag tag = stack.getTag(); + return tag.containsKey(TILE_DATA_KEY) && tag.containsKey("block") && tag.containsKey("stateid"); + } + return false; + } + + public static boolean storeTileData(BlockEntity tile, World world, BlockPos pos, BlockState state, ItemStack stack) + { + if (stack.isEmpty()) + return false; + + CompoundTag chest = new CompoundTag(); + if (tile != null) + chest = tile.toTag(chest); + + CompoundTag tag = stack.hasTag() ? stack.getTag() : new CompoundTag(); + if (tag.containsKey(TILE_DATA_KEY)) + return false; + + tag.put(TILE_DATA_KEY, chest); + + // ItemStack drop = new ItemStack(state.getBlock().getItemDropped(state, ItemTile.random, 0), 1, state.getBlock().damageDropped(state)); + + tag.putString("block", Registry.BLOCK.getId(getBlock(stack)).toString()); + // Item item = Item.getItemFromBlock(state.getBlock()); + tag.putInt("stateid", Block.getRawIdFromState(state)); + stack.setTag(tag); + return true; + } + + public static void clearTileData(ItemStack stack) + { + if (stack.hasTag()) + { + CompoundTag tag = stack.getTag(); + tag.remove(TILE_DATA_KEY); + tag.remove("block"); + tag.remove("stateid"); + } + } + + public static CompoundTag getTileData(ItemStack stack) + { + if (stack.hasTag()) + { + CompoundTag tag = stack.getTag(); + return (CompoundTag)tag.getTag(TILE_DATA_KEY); + } + return null; + } + + public static Block getBlock(ItemStack stack) + { + if (stack.hasTag()) + { + CompoundTag tag = stack.getTag(); + int id = tag.getInt("stateid"); + return Block.getStateFromRawId(id).getBlock(); + } + return Blocks.AIR; + } + + public static ItemStack getItemStack(ItemStack stack) + { + return new ItemStack(getBlock(stack), 1); + } + + public static BlockState getBlockState(ItemStack stack) + { + if (stack.hasTag()) + { + CompoundTag tag = stack.getTag(); + int id = tag.getInt("stateid"); + return Block.getStateFromRawId(id); + } + return Blocks.AIR.getDefaultState(); + } + + public static boolean isLocked(BlockPos pos, World world) + { + BlockEntity te = world.getBlockEntity(pos); + if (te != null) + { + CompoundTag tag = new CompoundTag(); + te.toTag(tag); + return tag.containsKey("Lock") ? !tag.getString("Lock").equals("") : false; + } + + return false; + } + + // private boolean equal(Object[] a, Object[] b) + // { + // if (a.length != b.length) + // return false; + + // List lA = Arrays.asList(a); + // List lB = Arrays.asList(b); + + // return lA.containsAll(lB); + // } + + private int potionLevel(ItemStack stack) + { + String nbt = getTileData(stack).toString(); + int i = nbt.length() / 500; + + if (i > 4) + i = 4; + + // if (!CarryOnConfig.settings.heavyTiles) + // i = 1; + + // return (int) (i * CarryOnConfig.settings.blockSlownessMultiplier); + + return i * 1; + // return 0; + } +} diff --git a/src/main/java/tschipp/carryon/keybinds/CarryOnKeybinds.java b/src/main/java/tschipp/carryon/keybinds/CarryOnKeybinds.java new file mode 100644 index 0000000..c8424f5 --- /dev/null +++ b/src/main/java/tschipp/carryon/keybinds/CarryOnKeybinds.java @@ -0,0 +1,45 @@ +package tschipp.carryon.keybinds; + +import net.fabricmc.api.EnvType; +import net.fabricmc.api.Environment; +import net.minecraft.client.settings.KeyBinding; +import net.minecraft.client.util.InputUtil; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.nbt.CompoundTag; +import tschipp.carryon.interfaces.ICarryOnData; + + +public class CarryOnKeybinds +{ + + public static final String KEYBIND_KEY = "carryOnKeyPressed"; + public static KeyBinding carryKey; + + @Environment(EnvType.CLIENT) + public static void init() + { + carryKey = new KeyBinding("key.carry.desc", InputUtil.Type.KEY_KEYBOARD, 340, "key.carry.category"); + } + + public static boolean isKeyPressed(PlayerEntity player) + { + ICarryOnData data = (ICarryOnData)player; + CompoundTag tag = data.getCarryOnData(); + if(tag != null && tag.containsKey(KEYBIND_KEY)) + { + return tag.getBoolean(KEYBIND_KEY); + } + return false; + } + + public static void setKeyPressed(PlayerEntity player, boolean pressed) + { + ICarryOnData data = (ICarryOnData)player; + CompoundTag tag = data.getCarryOnData(); + tag.putBoolean(KEYBIND_KEY, pressed); + data.setCarryOnData(tag); + } + + + +} diff --git a/src/main/java/tschipp/carryon/mixin/client/ArmorRendererMixin.java b/src/main/java/tschipp/carryon/mixin/client/ArmorRendererMixin.java new file mode 100644 index 0000000..e7092e4 --- /dev/null +++ b/src/main/java/tschipp/carryon/mixin/client/ArmorRendererMixin.java @@ -0,0 +1,48 @@ +package tschipp.carryon.mixin.client; + +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +import net.minecraft.class_3883; +import net.minecraft.client.model.Model; +import net.minecraft.client.render.entity.ArmorBipedEntityRenderer; +import net.minecraft.client.render.entity.ArmorEntityRenderer; +import net.minecraft.client.render.entity.model.BipedEntityModel; +import net.minecraft.entity.LivingEntity; +import net.minecraft.item.ItemStack; +import tschipp.carryon.RegistryHandler; +import tschipp.carryon.render.ICarrying; + +@Mixin(ArmorBipedEntityRenderer.class) +public abstract class ArmorRendererMixin, A extends BipedEntityModel> extends ArmorEntityRenderer { + + protected ArmorRendererMixin(class_3883 var1, A var2, A var3) { + super(var1, var2, var3); + } + + //Used to be "render" + @Inject(method = "method_17157", at = @At("HEAD")) + private void onRenderArmor(LivingEntity living, float var2, float var3, float var4, float var5, float var6, float var7, float var8, CallbackInfo info) + { + ItemStack stack = living.getMainHandStack(); + ICarrying model = (ICarrying)this.modelBody; + + if (!stack.isEmpty() && stack.getItem() == RegistryHandler.TILE_ITEM) + model.setCarryingBlock(true); + else + model.setCarryingBlock(false); + + if (!stack.isEmpty() && stack.getItem() == RegistryHandler.ENTITY_ITEM) + model.setCarryingEntity(true); + else + model.setCarryingEntity(false); + } + + @Override + public void method_17157(T var1, float var2, float var3, float var4, float var5, float var6, float var7, float var8) { + super.method_17157(var1, var2, var3, var4, var5, var6, var7, var8); + } + +} \ No newline at end of file diff --git a/src/main/java/tschipp/carryon/mixin/client/BipedModelMixin.java b/src/main/java/tschipp/carryon/mixin/client/BipedModelMixin.java new file mode 100644 index 0000000..5aaa9b5 --- /dev/null +++ b/src/main/java/tschipp/carryon/mixin/client/BipedModelMixin.java @@ -0,0 +1,74 @@ +package tschipp.carryon.mixin.client; + +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +import net.minecraft.client.model.Cuboid; +import net.minecraft.client.render.entity.model.BipedEntityModel; +import net.minecraft.entity.LivingEntity; +import tschipp.carryon.render.ICarrying; + +@Mixin(BipedEntityModel.class) +public class BipedModelMixin implements ICarrying { + + private boolean isCarryingBlock; + private boolean isCarryingEntity; + + @Shadow + public Cuboid armRight; + @Shadow + public Cuboid armLeft; + + @Shadow + public boolean isSneaking; + + + public boolean isCarryingBlock() + { + return isCarryingBlock; + } + + public boolean isCarryingEntity() + { + return isCarryingEntity; + } + + public void setCarryingBlock(boolean isCarrying) + { + this.isCarryingBlock = isCarrying; + } + + public void setCarryingEntity(boolean isCarrying) + { + this.isCarryingEntity = isCarrying; + } + + //setRotationAngles + @Inject(method = "method_17087", at = @At("RETURN")) + public void onSetAngles(LivingEntity var1, float var2, float var3, float var4, float var5, float var6, float var7, CallbackInfo info) + { + if(this.isCarryingBlock()) + { + armRight.pitch = -1F + (this.isSneaking ? 0f : 0.2f); + armLeft.pitch = -1F + (this.isSneaking ? 0f : 0.2f); + armRight.roll = 0f; + armLeft.roll = 0f; + armRight.yaw = 0f; + armLeft.yaw = 0f; + } + else if (this.isCarryingEntity()) + { + armRight.pitch = -1.2F + (this.isSneaking ? 0f : 0.2f); + armLeft.pitch = -1.2F + (this.isSneaking ? 0f : 0.2f); + armRight.roll = -0.15f; + armLeft.roll = 0.15f; + armRight.yaw = 0f; + armLeft.yaw = 0f; + } + } + + +} \ No newline at end of file diff --git a/src/main/java/tschipp/carryon/mixin/client/FirstPersonMixin.java b/src/main/java/tschipp/carryon/mixin/client/FirstPersonMixin.java new file mode 100644 index 0000000..2021022 --- /dev/null +++ b/src/main/java/tschipp/carryon/mixin/client/FirstPersonMixin.java @@ -0,0 +1,31 @@ +package tschipp.carryon.mixin.client; + +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +import net.minecraft.client.MinecraftClient; +import net.minecraft.client.render.FirstPersonRenderer; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.item.ItemStack; +import tschipp.carryon.RegistryHandler; +import tschipp.carryon.render.BlockRendererLayer; +import tschipp.carryon.render.EntityRendererLayer; + +@Mixin(FirstPersonRenderer.class) +public class FirstPersonMixin { + + @Inject(method = "renderFirstPersonItem", at = @At("HEAD")) + public void onRenderItem(float partialTicks, CallbackInfo info) + { + PlayerEntity player = MinecraftClient.getInstance().player; + ItemStack stack = player.getMainHandStack(); + + if(!stack.isEmpty() && stack.getItem() == RegistryHandler.TILE_ITEM) + BlockRendererLayer.renderFirstPerson(player, stack, partialTicks); + else if(!stack.isEmpty() && stack.getItem() == RegistryHandler.ENTITY_ITEM) + EntityRendererLayer.renderFirstPerson(player, stack, partialTicks); + } + +} \ No newline at end of file diff --git a/src/main/java/tschipp/carryon/mixin/client/KeyboardMixin.java b/src/main/java/tschipp/carryon/mixin/client/KeyboardMixin.java new file mode 100644 index 0000000..ee8411f --- /dev/null +++ b/src/main/java/tschipp/carryon/mixin/client/KeyboardMixin.java @@ -0,0 +1,60 @@ +package tschipp.carryon.mixin.client; + + +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +import net.minecraft.client.MinecraftClient; +import net.minecraft.client.network.ClientPlayerEntity; +import net.minecraft.client.settings.GameOptions; +import net.minecraft.client.settings.KeyBinding; +import net.minecraft.client.util.Keyboard; +import net.minecraft.item.ItemStack; +import tschipp.carryon.CarryOn; +import tschipp.carryon.RegistryHandler; + +@Mixin(Keyboard.class) +public class KeyboardMixin { + + @Inject(method = "(JIIII)V", at = @At("HEAD"), cancellable = true) + public void onKeyPressed(long var1, int code1, int code2, int var5, int var6, CallbackInfo info) + { + ClientPlayerEntity player = MinecraftClient.getInstance().player; + GameOptions options = MinecraftClient.getInstance().options; + if (player != null) { + ItemStack held = player.getMainHandStack(); + + CarryOn.LOGGER.info(player); + CarryOn.LOGGER.info(held); + + if (!held.isEmpty() && held.getItem() == RegistryHandler.TILE_ITEM || held.getItem() == RegistryHandler.ENTITY_ITEM) + { + boolean cancel = false; + if(options.keyInventory.matches(code1, code2)) + cancel = true; + else if(options.keySwapHands.matches(code1, code2)) + cancel = true; + else if(options.keyDrop.matches(code1, code2)) + cancel = true; + else if(options.keyLoadToolbarActivator.matches(code1, code2)) + cancel = true; + else if(options.keySaveToolbarActivator.matches(code1, code2)) + cancel = true; + else if(options.keyPickItem.matches(code1, code2)) + cancel = true; + else { + for(KeyBinding key : options.keysHotbar) + { + if(key.matches(code1, code2)) + cancel = true; + } + } + + if(cancel) + info.cancel(); + } + } + } +} \ No newline at end of file diff --git a/src/main/java/tschipp/carryon/mixin/client/MouseMixin.java b/src/main/java/tschipp/carryon/mixin/client/MouseMixin.java new file mode 100644 index 0000000..ee3c1a9 --- /dev/null +++ b/src/main/java/tschipp/carryon/mixin/client/MouseMixin.java @@ -0,0 +1,46 @@ +package tschipp.carryon.mixin.client; + +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +import net.minecraft.client.MinecraftClient; +import net.minecraft.client.network.ClientPlayerEntity; +import net.minecraft.client.util.Mouse; +import net.minecraft.item.ItemStack; +import tschipp.carryon.CarryOn; +import tschipp.carryon.RegistryHandler; + +@Mixin(Mouse.class) +public class MouseMixin { + + @Inject(method = "(JDD)V", at = @At("HEAD"), cancellable = true) + private void onMouseScrolling(long var1, double var3, double var5, CallbackInfo info) { + ClientPlayerEntity player = MinecraftClient.getInstance().player; + ItemStack held = player.getMainHandStack(); + + CarryOn.LOGGER.info(player); + CarryOn.LOGGER.info(held); + + if (!held.isEmpty() && held.getItem() == RegistryHandler.TILE_ITEM + || held.getItem() == RegistryHandler.ENTITY_ITEM) + info.cancel(); + } + + @Inject(method = "(JIII)V", at = @At("HEAD"), cancellable = true) + private void onMouseButtonPress(long var1, int code, int var4, int var5, CallbackInfo info) { + ClientPlayerEntity player = MinecraftClient.getInstance().player; + if (player != null) { + ItemStack held = player.getMainHandStack(); + + CarryOn.LOGGER.info(player); + CarryOn.LOGGER.info(held); + + if (!held.isEmpty() && held.getItem() == RegistryHandler.TILE_ITEM + || held.getItem() == RegistryHandler.ENTITY_ITEM) + if (MinecraftClient.getInstance().options.keyPickItem.matches(code)) + info.cancel(); + } + } +} \ No newline at end of file diff --git a/src/main/java/tschipp/carryon/mixin/client/PlayerRendererMixin.java b/src/main/java/tschipp/carryon/mixin/client/PlayerRendererMixin.java new file mode 100644 index 0000000..9cdeb55 --- /dev/null +++ b/src/main/java/tschipp/carryon/mixin/client/PlayerRendererMixin.java @@ -0,0 +1,49 @@ +package tschipp.carryon.mixin.client; + +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +import net.minecraft.client.network.AbstractClientPlayerEntity; +import net.minecraft.client.render.entity.EntityRenderDispatcher; +import net.minecraft.client.render.entity.LivingEntityRenderer; +import net.minecraft.client.render.entity.PlayerEntityRenderer; +import net.minecraft.client.render.entity.model.PlayerEntityModel; +import net.minecraft.item.ItemStack; +import tschipp.carryon.RegistryHandler; +import tschipp.carryon.render.BlockRendererLayer; +import tschipp.carryon.render.EntityRendererLayer; +import tschipp.carryon.render.ICarrying; + +@Mixin(PlayerEntityRenderer.class) +public abstract class PlayerRendererMixin extends LivingEntityRenderer>{ + + private PlayerRendererMixin(EntityRenderDispatcher var1, PlayerEntityModel var2, float var3) { + super(var1, var2, var3); + } + + @Inject(method = "*", at = @At("RETURN")) + public void onConstructed(EntityRenderDispatcher renderDispatcher, boolean slim, CallbackInfo info) + { + this.addLayer(new BlockRendererLayer(this)); + this.addLayer(new EntityRendererLayer(this)); + } + + @Inject(method = "method_4218", at = @At("RETURN")) + private void onPreRender(AbstractClientPlayerEntity player, CallbackInfo info) + { + ItemStack stack = player.getMainHandStack(); + ICarrying model = (ICarrying)this.method_4038(); + + if (!stack.isEmpty() && stack.getItem() == RegistryHandler.TILE_ITEM) + model.setCarryingBlock(true); + else + model.setCarryingBlock(false); + + if (!stack.isEmpty() && stack.getItem() == RegistryHandler.ENTITY_ITEM) + model.setCarryingEntity(true); + else + model.setCarryingEntity(false); + } +} \ No newline at end of file diff --git a/src/main/java/tschipp/carryon/mixin/common/BlockStateMixin.java b/src/main/java/tschipp/carryon/mixin/common/BlockStateMixin.java new file mode 100644 index 0000000..16877e0 --- /dev/null +++ b/src/main/java/tschipp/carryon/mixin/common/BlockStateMixin.java @@ -0,0 +1,117 @@ +package tschipp.carryon.mixin.common; + +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; + +import net.minecraft.block.BlockState; +import net.minecraft.block.Blocks; +import net.minecraft.block.entity.BlockEntity; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.util.Hand; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.Direction; +import net.minecraft.world.World; +import tschipp.carryon.PickupHandler; +import tschipp.carryon.RegistryHandler; +import tschipp.carryon.items.ItemTile; + +@Mixin(BlockState.class) +public class BlockStateMixin { + + + //Detects right click detection + @Inject(method = "activate", at = @At("HEAD"), cancellable = true) + public void onBlockActivated(World world, BlockPos pos, PlayerEntity player, Hand hand, Direction Direction, float hitx, float hity, float hitz, CallbackInfoReturnable info) { + ItemStack main = player.getMainHandStack(); + ItemStack off = player.getOffHandStack(); + + if(main.isEmpty() && off.isEmpty() && player.isSneaking()) + { + info.cancel(); + info.setReturnValue(false); + + BlockState state = world.getBlockState(pos); + ItemStack stack = new ItemStack(RegistryHandler.TILE_ITEM); + + BlockEntity te = world.getBlockEntity(pos); + if (PickupHandler.canPlayerPickUpBlock(player, te, world, pos)) + { + // player.open.closeScreen(); + + if (ItemTile.storeTileData(te, world, pos, state, stack)) + { + + // BlockState statee = world.getBlockState(pos); + CompoundTag tag = new CompoundTag(); + tag = world.getBlockEntity(pos) != null ? world.getBlockEntity(pos).toTag(tag) : new CompoundTag(); + // CarryOnOverride override = ScriptChecker.inspectBlock(state, world, pos, tag); + // int overrideHash = 0; + // if (override != null) + // overrideHash = override.hashCode(); + + // positions.put(pos, 0); + + // boolean success = false; + + try + { + // sendPacket(player, player.inventory.currentItem, overrideHash); + + world.removeBlockEntity(pos); + world.setBlockState(pos, Blocks.AIR.getDefaultState(), 3); + player.setStackInHand(Hand.MAIN, stack); + // event.setUseBlock(Result.DENY); + // event.setUseItem(Result.DENY); + // event.setCanceled(true); + // success = true; + } + catch (Exception e) + { + // try + // { + // sendPacket(player, player.inventory.currentItem, overrideHash); + // emptyBlockEntity(te); + // world.setBlockToAir(pos); + // player.setHeldItem(EnumHand.MAIN_HAND, stack); + // event.setUseBlock(Result.DENY); + // event.setUseItem(Result.DENY); + // event.setCanceled(true); + // success = true; + // } + // catch (Exception ex) + // { + // sendPacket(player, 9, 0); + // world.setBlockState(pos, statee); + // if (!tag.hasNoTags()) + // BlockEntity.create(world, tag); + + // player.sendMessage(new TextComponentString(TextFormatting.RED + "Error detected. Cannot pick up block.")); + // TextComponentString s = new TextComponentString(TextFormatting.GOLD + "here"); + // s.getStyle().setClickEvent(new ClickEvent(Action.OPEN_URL, "https://github.com/Tschipp/CarryOn/issues")); + // player.sendMessage(new TextComponentString(TextFormatting.RED + "Please report this error ").appendSibling(s)); + // } + + } + + // if (success && override != null) + // { + // String command = override.getCommandInit(); + // if (command != null) + // player.getServer().getCommandManager().executeCommand(player.getServer(), "/execute " + player.getGameProfile().getName() + " ~ ~ ~ " + command); + // } + + } + } + } + else if(!main.isEmpty() && main.getItem() == RegistryHandler.TILE_ITEM || main.getItem() == RegistryHandler.ENTITY_ITEM) + { + info.cancel(); + } + } + + +} diff --git a/src/main/java/tschipp/carryon/mixin/common/EntityMixin.java b/src/main/java/tschipp/carryon/mixin/common/EntityMixin.java new file mode 100644 index 0000000..2b7bbfe --- /dev/null +++ b/src/main/java/tschipp/carryon/mixin/common/EntityMixin.java @@ -0,0 +1,72 @@ +package tschipp.carryon.mixin.common; + +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; + +import net.minecraft.entity.Entity; +import net.minecraft.entity.passive.AnimalEntity; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.item.ItemStack; +import net.minecraft.util.Hand; +import net.minecraft.world.World; +import tschipp.carryon.PickupHandler; +import tschipp.carryon.RegistryHandler; +import tschipp.carryon.items.ItemEntity; + +@Mixin(Entity.class) +public abstract class EntityMixin { + + @Shadow + public boolean field_6037; + + @Inject(method = "interact", at = @At("HEAD"), cancellable = true) + public void onInteract(PlayerEntity player, Hand hand, CallbackInfoReturnable info) { + + ItemStack main = player.getMainHandStack(); + ItemStack off = player.getOffHandStack(); + World world = player.world; + Entity entity = ((Entity) (Object) this); + + if (main.isEmpty() && off.isEmpty() && player.isSneaking()) { + ItemStack stack = new ItemStack(RegistryHandler.ENTITY_ITEM); + + if (!this.field_6037) { + if (entity instanceof AnimalEntity) + ((AnimalEntity) entity).detachLeash(true, true); + + if (PickupHandler.canPlayerPickUpEntity(player, entity)) { + if (ItemEntity.storeEntityData(entity, world, stack)) { + // if (entity.hasCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null)) { + // IItemHandler handler = entity + // .getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null); + // for (int i = 0; i < handler.getSlots(); i++) { + // handler.extractItem(i, 64, false); + // } + // } + + // CarryOnOverride override = ScriptChecker.inspectEntity(entity); + // int overrideHash = 0; + // if (override != null) + // overrideHash = override.hashCode(); + + // ItemEvents.sendPacket(player, player.inventory.currentItem, overrideHash); + + // if (entity instanceof LivingEntity) + // ((LivingEntity) entity).setHealth(0); + + entity.invalidate(); + player.setStackInHand(Hand.MAIN, stack); + info.cancel(); + info.setReturnValue(false); + } + } + } + + } + + } + +} \ No newline at end of file diff --git a/src/main/java/tschipp/carryon/mixin/common/PlayerMixin.java b/src/main/java/tschipp/carryon/mixin/common/PlayerMixin.java new file mode 100644 index 0000000..f6dcf9d --- /dev/null +++ b/src/main/java/tschipp/carryon/mixin/common/PlayerMixin.java @@ -0,0 +1,42 @@ +package tschipp.carryon.mixin.common; + +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +import net.minecraft.entity.EntityType; +import net.minecraft.entity.LivingEntity; +import net.minecraft.entity.data.DataTracker; +import net.minecraft.entity.data.TrackedData; +import net.minecraft.entity.data.TrackedDataHandlerRegistry; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.world.World; +import tschipp.carryon.interfaces.ICarryOnData; + +@Mixin(PlayerEntity.class) +public abstract class PlayerMixin extends LivingEntity implements ICarryOnData { + + private PlayerMixin(World var1) { + super(EntityType.PLAYER, var1); + } + + private static final TrackedData CARRYON_DATA = DataTracker.registerData(PlayerEntity.class, TrackedDataHandlerRegistry.TAG_COMPOUND);; + + @Inject(method = "initDataTracker", at = @At("RETURN")) + public void onInitDataTracker(CallbackInfo info) { + this.dataTracker.startTracking(CARRYON_DATA, new CompoundTag()); + } + + @Override + public CompoundTag getCarryOnData() { + return (CompoundTag)this.dataTracker.get(CARRYON_DATA); + } + + @Override + public void setCarryOnData(CompoundTag tag) { + this.dataTracker.set(CARRYON_DATA, tag); + } + +} \ No newline at end of file diff --git a/src/main/java/tschipp/carryon/network/client/CarrySlotPacket.java b/src/main/java/tschipp/carryon/network/client/CarrySlotPacket.java deleted file mode 100644 index 597cb5c..0000000 --- a/src/main/java/tschipp/carryon/network/client/CarrySlotPacket.java +++ /dev/null @@ -1,54 +0,0 @@ -package tschipp.carryon.network.client; - -import io.netty.buffer.ByteBuf; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraftforge.fml.common.network.ByteBufUtils; -import net.minecraftforge.fml.common.network.simpleimpl.IMessage; - -public class CarrySlotPacket implements IMessage -{ - public int slot; - public int carryOverride = 0; - public int entityid; - - public CarrySlotPacket() - { - this.slot = 9; - this.entityid = 0; - } - - public CarrySlotPacket(int slot, int entityid) - { - this.slot = slot; - this.entityid = entityid; - } - - public CarrySlotPacket(int slot, int entityid, int carryOverride) - { - this.slot = slot; - this.carryOverride = carryOverride; - this.entityid = entityid; - } - - @Override - public void fromBytes(ByteBuf buf) - { - NBTTagCompound tag = ByteBufUtils.readTag(buf); - - this.slot = tag.getInteger("slot"); - this.carryOverride = tag.getInteger("override"); - this.entityid = tag.getInteger("entityid"); - } - - @Override - public void toBytes(ByteBuf buf) - { - NBTTagCompound tag = new NBTTagCompound(); - tag.setInteger("slot", slot); - tag.setInteger("override", carryOverride); - tag.setInteger("entityid", entityid); - ByteBufUtils.writeTag(buf, tag); - - } - -} diff --git a/src/main/java/tschipp/carryon/network/client/CarrySlotPacketHandler.java b/src/main/java/tschipp/carryon/network/client/CarrySlotPacketHandler.java deleted file mode 100644 index 4c131de..0000000 --- a/src/main/java/tschipp/carryon/network/client/CarrySlotPacketHandler.java +++ /dev/null @@ -1,59 +0,0 @@ -package tschipp.carryon.network.client; - -import net.minecraft.client.Minecraft; -import net.minecraft.client.multiplayer.WorldClient; -import net.minecraft.entity.Entity; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.util.IThreadListener; -import net.minecraft.world.World; -import net.minecraftforge.fml.common.network.simpleimpl.IMessage; -import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler; -import net.minecraftforge.fml.common.network.simpleimpl.MessageContext; -import tschipp.carryon.common.scripting.ScriptChecker; - -public class CarrySlotPacketHandler implements IMessageHandler -{ - - @Override - public IMessage onMessage(final CarrySlotPacket message, final MessageContext ctx) - { - IThreadListener mainThread = Minecraft.getMinecraft(); - - mainThread.addScheduledTask(new Runnable() - { - World world = Minecraft.getMinecraft().world; - - @Override - public void run() - { - if (world != null) - { - Entity e = world.getEntityByID(message.entityid); - - if (e != null && e instanceof EntityPlayer) - { - EntityPlayer player = (EntityPlayer) e; - - if (message.slot >= 9) - { - player.getEntityData().removeTag("carrySlot"); - player.getEntityData().removeTag("overrideKey"); - } - else - { - - player.getEntityData().setInteger("carrySlot", message.slot); - if (message.carryOverride != 0) - ScriptChecker.setCarryOnOverride(player, message.carryOverride); - } - } - } - - } - - }); - - return null; - } - -} diff --git a/src/main/java/tschipp/carryon/network/client/ScriptReloadPacket.java b/src/main/java/tschipp/carryon/network/client/ScriptReloadPacket.java deleted file mode 100644 index 3cde434..0000000 --- a/src/main/java/tschipp/carryon/network/client/ScriptReloadPacket.java +++ /dev/null @@ -1,26 +0,0 @@ -package tschipp.carryon.network.client; - -import io.netty.buffer.ByteBuf; -import net.minecraftforge.fml.common.network.simpleimpl.IMessage; - -public class ScriptReloadPacket implements IMessage -{ - - public ScriptReloadPacket() - { - - } - - @Override - public void fromBytes(ByteBuf buf) - { - - } - - @Override - public void toBytes(ByteBuf buf) - { - - } - -} diff --git a/src/main/java/tschipp/carryon/network/client/ScriptReloadPacketHandler.java b/src/main/java/tschipp/carryon/network/client/ScriptReloadPacketHandler.java deleted file mode 100644 index 507e35e..0000000 --- a/src/main/java/tschipp/carryon/network/client/ScriptReloadPacketHandler.java +++ /dev/null @@ -1,35 +0,0 @@ -package tschipp.carryon.network.client; - -import net.minecraft.client.Minecraft; -import net.minecraft.client.entity.EntityPlayerSP; -import net.minecraft.util.IThreadListener; -import net.minecraftforge.fml.common.network.simpleimpl.IMessage; -import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler; -import net.minecraftforge.fml.common.network.simpleimpl.MessageContext; -import tschipp.carryon.common.scripting.ScriptReader; - -public class ScriptReloadPacketHandler implements IMessageHandler -{ - - @Override - public IMessage onMessage(ScriptReloadPacket message, MessageContext ctx) - { - IThreadListener mainThread = Minecraft.getMinecraft(); - - mainThread.addScheduledTask(new Runnable() - { - EntityPlayerSP player = Minecraft.getMinecraft().player; - - @Override - public void run() - { - if(player != null) - ScriptReader.reloadScripts(); - } - - }); - - return null; - } - -} diff --git a/src/main/java/tschipp/carryon/network/server/SyncKeybindPacket.java b/src/main/java/tschipp/carryon/network/server/SyncKeybindPacket.java deleted file mode 100644 index 3dbca52..0000000 --- a/src/main/java/tschipp/carryon/network/server/SyncKeybindPacket.java +++ /dev/null @@ -1,35 +0,0 @@ -package tschipp.carryon.network.server; - -import io.netty.buffer.ByteBuf; -import net.minecraftforge.fml.common.network.ByteBufUtils; -import net.minecraftforge.fml.common.network.simpleimpl.IMessage; - -public class SyncKeybindPacket implements IMessage -{ - - private int p; - public boolean pressed; - - public SyncKeybindPacket() - { - } - - public SyncKeybindPacket(boolean pressed) - { - this.p = pressed ? 1 : 0; - } - - @Override - public void fromBytes(ByteBuf buf) - { - this.p = ByteBufUtils.readVarInt(buf, 4); - this.pressed = p == 1 ? true : false; - } - - @Override - public void toBytes(ByteBuf buf) - { - ByteBufUtils.writeVarInt(buf, p, 4); - } - -} diff --git a/src/main/java/tschipp/carryon/network/server/SyncKeybindPacketHandler.java b/src/main/java/tschipp/carryon/network/server/SyncKeybindPacketHandler.java deleted file mode 100644 index 5379a6c..0000000 --- a/src/main/java/tschipp/carryon/network/server/SyncKeybindPacketHandler.java +++ /dev/null @@ -1,34 +0,0 @@ -package tschipp.carryon.network.server; - -import net.minecraft.entity.player.EntityPlayerMP; -import net.minecraft.util.IThreadListener; -import net.minecraft.world.WorldServer; -import net.minecraftforge.fml.common.network.simpleimpl.IMessage; -import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler; -import net.minecraftforge.fml.common.network.simpleimpl.MessageContext; -import tschipp.carryon.client.keybinds.CarryOnKeybinds; - -public class SyncKeybindPacketHandler implements IMessageHandler -{ - - @Override - public IMessage onMessage(final SyncKeybindPacket message, final MessageContext ctx) - { - IThreadListener mainThread = (WorldServer) ctx.getServerHandler().playerEntity.world; - - mainThread.addScheduledTask(new Runnable() - { - EntityPlayerMP player = ctx.getServerHandler().playerEntity; - - @Override - public void run() - { - CarryOnKeybinds.setKeyPressed(player, message.pressed); - } - - }); - - return null; - } - -} diff --git a/src/main/java/tschipp/carryon/render/BlockRendererLayer.java b/src/main/java/tschipp/carryon/render/BlockRendererLayer.java new file mode 100644 index 0000000..65c7acd --- /dev/null +++ b/src/main/java/tschipp/carryon/render/BlockRendererLayer.java @@ -0,0 +1,95 @@ +package tschipp.carryon.render; + +import com.mojang.blaze3d.platform.GLX; +import com.mojang.blaze3d.platform.GlStateManager; + +import net.minecraft.class_3883; +import net.minecraft.class_3887; +import net.minecraft.block.Block; +import net.minecraft.block.Blocks; +import net.minecraft.client.MinecraftClient; +import net.minecraft.client.network.AbstractClientPlayerEntity; +import net.minecraft.client.render.entity.model.PlayerEntityModel; +import net.minecraft.client.render.model.json.ModelTransformations.Type; +import net.minecraft.entity.LivingEntity; +import net.minecraft.item.ItemStack; +import net.minecraft.util.math.BlockPos; +import tschipp.carryon.RegistryHandler; +import tschipp.carryon.items.ItemTile; + +public class BlockRendererLayer extends class_3887> { + + private static MinecraftClient client = MinecraftClient.getInstance(); + + public BlockRendererLayer(class_3883> var1) { + super(var1); + } + + @Override + public void method_4199(AbstractClientPlayerEntity player, float var2, float var3, float partialTicks, float var5, + float var6, float var7, float var8) { + ItemStack stack = player.getMainHandStack(); + if (!stack.isEmpty() && stack.getItem() == RegistryHandler.TILE_ITEM) { + ItemStack renderStack = ItemTile.getItemStack(stack); + // BakedModel model = + // client.getItemRenderer().getModelMap().getModel(renderStack); + + GlStateManager.pushMatrix(); + GlStateManager.rotated(180, 1, 0, 0); + GlStateManager.rotated(180, 0, 1, 0); + GlStateManager.scaled(0.6, 0.6, 0.6); + GlStateManager.translated(0, -0.75, -0.65); + + if(player.isSneaking()) + { + GlStateManager.translated(0, -0.15, -0.15); + } + + if(isChest(ItemTile.getBlock(stack))) + { + GlStateManager.rotated(180, 0, 1, 0); + } + + client.getItemRenderer().renderItemWithTransformation(renderStack, Type.ORIGIN); + GlStateManager.popMatrix(); + } + } + + @Override + public boolean method_4200() { + return false; + } + + public static boolean isChest(Block block) + { + return block == Blocks.CHEST || block == Blocks.ENDER_CHEST || block == Blocks.TRAPPED_CHEST; + } + + public static void renderFirstPerson(LivingEntity entity, ItemStack stack, float partialTicks) + { + ItemStack renderStack = ItemTile.getItemStack(stack); + + GlStateManager.pushMatrix(); + GlStateManager.scaled(2.5, 2.5, 2.5); + GlStateManager.translated(0, -0.6, -1); + GlStateManager.enableBlend(); + + if(isChest(ItemTile.getBlock(stack))) + { + GlStateManager.rotated(180, 0, 1, 0); + } + + setLightCoords(); + client.getItemRenderer().renderItemWithTransformation(renderStack, Type.ORIGIN); + GlStateManager.popMatrix(); + } + + private static void setLightCoords() { + AbstractClientPlayerEntity player = client.player; + int var2 = client.world.getLightmapIndex(new BlockPos(player.x, player.y + (double)player.getEyeHeight(), player.z), 0); + float var3 = (float)(var2 & '\uffff'); + float var4 = (float)(var2 >> 16); + GLX.glMultiTexCoord2f(GLX.GL_TEXTURE1, var3, var4); + } + +} \ No newline at end of file diff --git a/src/main/java/tschipp/carryon/render/EntityRendererLayer.java b/src/main/java/tschipp/carryon/render/EntityRendererLayer.java new file mode 100644 index 0000000..73627da --- /dev/null +++ b/src/main/java/tschipp/carryon/render/EntityRendererLayer.java @@ -0,0 +1,123 @@ +package tschipp.carryon.render; + +import com.mojang.blaze3d.platform.GLX; +import com.mojang.blaze3d.platform.GlStateManager; + +import net.minecraft.class_3883; +import net.minecraft.class_3887; +import net.minecraft.block.Block; +import net.minecraft.block.Blocks; +import net.minecraft.client.MinecraftClient; +import net.minecraft.client.network.AbstractClientPlayerEntity; +import net.minecraft.client.render.entity.EntityRenderDispatcher; +import net.minecraft.client.render.entity.model.PlayerEntityModel; +import net.minecraft.entity.Entity; +import net.minecraft.entity.LivingEntity; +import net.minecraft.item.ItemStack; +import net.minecraft.util.math.BlockPos; +import tschipp.carryon.RegistryHandler; +import tschipp.carryon.items.ItemEntity; + +public class EntityRendererLayer extends class_3887> { + + private static MinecraftClient client = MinecraftClient.getInstance(); + + public EntityRendererLayer(class_3883> var1) { + super(var1); + } + + @Override + public void method_4199(AbstractClientPlayerEntity player, float var2, float var3, float partialTicks, float var5, + float var6, float var7, float var8) { + ItemStack stack = player.getMainHandStack(); + if (!stack.isEmpty() && stack.getItem() == RegistryHandler.ENTITY_ITEM) { + Entity renderEntity = ItemEntity.getEntity(stack, player.world); + + double c0 = player.prevX + (player.x - player.prevX) * partialTicks; + double c1 = player.prevY + (player.y - player.prevY) * partialTicks; + double c2 = player.prevZ + (player.z - player.prevZ) * partialTicks; + + renderEntity.setPosition(c0, c1, c2); + + EntityRenderDispatcher renderer = client.getEntityRenderManager(); + + renderEntity.yaw = 0f; + renderEntity.pitch = 0f; + float height = renderEntity.height; + float width = renderEntity.width; + float multiplier = height * width; + + GlStateManager.pushMatrix(); + GlStateManager.scaled(1, -1, 1); + GlStateManager.scaled((10 - multiplier) * 0.08, (10 - multiplier) * 0.08, (10 - multiplier) * 0.08); + GlStateManager.rotated(180, 0, 1, 0); + GlStateManager.translated(0.0, height / 2 + -(height / 2) - 1.2, width - 0.1 < 0.7 ? width - 0.1 + (0.7 - (width - 0.1)) : width - 0.1); + GlStateManager.color3f(1f, 1f, 1f); + GlStateManager.enableAlphaTest(); + + if (player.isSneaking()) { + GlStateManager.translated(0, -0.1, 0); + } + + renderer.method_3948(false); + renderer.method_3954(renderEntity, 0, 0, 0, partialTicks, 0, true); + renderer.method_3948(true); + + GlStateManager.scaled(1, 1, 1); + GlStateManager.popMatrix(); + } + } + + @Override + public boolean method_4200() { + return false; + } + + public static boolean isChest(Block block) { + return block == Blocks.CHEST || block == Blocks.ENDER_CHEST || block == Blocks.TRAPPED_CHEST; + } + + public static void renderFirstPerson(LivingEntity player, ItemStack stack, float partialTicks) + { + if (!stack.isEmpty() && stack.getItem() == RegistryHandler.ENTITY_ITEM) { + Entity renderEntity = ItemEntity.getEntity(stack, player.world); + + double c0 = player.prevX + (player.x - player.prevX) * partialTicks; + double c1 = player.prevY + (player.y - player.prevY) * partialTicks; + double c2 = player.prevZ + (player.z - player.prevZ) * partialTicks; + + renderEntity.setPosition(c0, c1, c2); + + EntityRenderDispatcher renderer = client.getEntityRenderManager(); + + renderEntity.yaw = 0f; + renderEntity.pitch = 0f; + float height = renderEntity.height; + float width = renderEntity.width; + + GlStateManager.pushMatrix(); + GlStateManager.scaled(.8, .8, .8); + GlStateManager.rotated(180, 0, 1, 0); + GlStateManager.translated(0.0, -height - .1, width + 0.1); + GlStateManager.enableAlphaTest(); + + setLightCoords(); + renderer.method_3948(false); + renderer.method_3954(renderEntity, 0, 0, 0, partialTicks, 0, true); + renderer.method_3948(true); + + GlStateManager.disableAlphaTest(); + GlStateManager.scaled(1, 1, 1); + GlStateManager.popMatrix(); + } + } + + private static void setLightCoords() { + AbstractClientPlayerEntity player = client.player; + int var2 = client.world.getLightmapIndex(new BlockPos(player.x, player.y + (double)player.getEyeHeight(), player.z), 0); + float var3 = (float)(var2 & '\uffff'); + float var4 = (float)(var2 >> 16); + GLX.glMultiTexCoord2f(GLX.GL_TEXTURE1, var3, var4); + } + +} \ No newline at end of file diff --git a/src/main/java/tschipp/carryon/render/ICarrying.java b/src/main/java/tschipp/carryon/render/ICarrying.java new file mode 100644 index 0000000..2a267fb --- /dev/null +++ b/src/main/java/tschipp/carryon/render/ICarrying.java @@ -0,0 +1,11 @@ +package tschipp.carryon.render; + +public interface ICarrying { + + public boolean isCarryingBlock(); + public boolean isCarryingEntity(); + + public void setCarryingBlock(boolean isCarrying); + public void setCarryingEntity(boolean isCarrying); + +} \ No newline at end of file diff --git a/src/main/java/tschipp/carryon/common/scripting/CarryOnOverride.java b/src/main/java/tschipp/carryon/scripting/CarryOnOverride.java similarity index 88% rename from src/main/java/tschipp/carryon/common/scripting/CarryOnOverride.java rename to src/main/java/tschipp/carryon/scripting/CarryOnOverride.java index c454e2c..26f5c4c 100644 --- a/src/main/java/tschipp/carryon/common/scripting/CarryOnOverride.java +++ b/src/main/java/tschipp/carryon/scripting/CarryOnOverride.java @@ -41,6 +41,11 @@ public class CarryOnOverride private boolean renderLeftArm = true; private boolean renderRightArm = true; + //EFFECTS + private String commandInit; + private String commandLoop; + private String commandPlace; + private boolean isBlock; private boolean isEntity; private final String path; @@ -51,6 +56,28 @@ public class CarryOnOverride this.path = path; } + + + public String getCommandInit() + { + return commandInit; + } + + public void setCommandInit(String commandInit) + { + this.commandInit = commandInit; + } + + public String getCommandLoop() + { + return commandLoop; + } + + public void setCommandLoop(String commandLoop) + { + this.commandLoop = commandLoop; + } + public String getConditionEffects() { return conditionEffects; @@ -115,7 +142,7 @@ public class CarryOnOverride { return "Code: " + this.hashCode(); } - + @Override public boolean equals(Object obj) { @@ -126,6 +153,27 @@ public class CarryOnOverride if (getClass() != obj.getClass()) return false; CarryOnOverride other = (CarryOnOverride) obj; + if (commandInit == null) + { + if (other.commandInit != null) + return false; + } + else if (!commandInit.equals(other.commandInit)) + return false; + if (commandLoop == null) + { + if (other.commandLoop != null) + return false; + } + else if (!commandLoop.equals(other.commandLoop)) + return false; + if (commandPlace == null) + { + if (other.commandPlace != null) + return false; + } + else if (!commandPlace.equals(other.commandPlace)) + return false; if (conditionAchievement == null) { if (other.conditionAchievement != null) @@ -133,6 +181,13 @@ public class CarryOnOverride } else if (!conditionAchievement.equals(other.conditionAchievement)) return false; + if (conditionEffects == null) + { + if (other.conditionEffects != null) + return false; + } + else if (!conditionEffects.equals(other.conditionEffects)) + return false; if (conditionGamemode == null) { if (other.conditionGamemode != null) @@ -172,6 +227,15 @@ public class CarryOnOverride return false; if (isEntity != other.isEntity) return false; + if (path == null) + { + if (other.path != null) + return false; + } + else if (!path.equals(other.path)) + return false; + if (renderLeftArm != other.renderLeftArm) + return false; if (renderMeta != other.renderMeta) return false; if (renderNBT == null) @@ -195,6 +259,8 @@ public class CarryOnOverride } else if (!renderNameEntity.equals(other.renderNameEntity)) return false; + if (renderRightArm != other.renderRightArm) + return false; if (renderRotation == null) { if (other.renderRotation != null) @@ -310,6 +376,8 @@ public class CarryOnOverride return true; } + + public boolean isBlock() { return isBlock; @@ -570,4 +638,18 @@ public class CarryOnOverride this.renderScale = renderScale; } + + + public String getCommandPlace() + { + return commandPlace; + } + + public void setCommandPlace(String commandPlace) + { + this.commandPlace = commandPlace; + } + + + } diff --git a/src/main/java/tschipp/carryon/common/scripting/ScriptChecker.java b/src/main/java/tschipp/carryon/scripting/ScriptChecker.java similarity index 59% rename from src/main/java/tschipp/carryon/common/scripting/ScriptChecker.java rename to src/main/java/tschipp/carryon/scripting/ScriptChecker.java index e2be7a8..991fc01 100644 --- a/src/main/java/tschipp/carryon/common/scripting/ScriptChecker.java +++ b/src/main/java/tschipp/carryon/scripting/ScriptChecker.java @@ -1,8 +1,11 @@ package tschipp.carryon.common.scripting; +import java.lang.reflect.Method; + import javax.annotation.Nullable; -import net.darkhax.gamestages.capabilities.PlayerDataHandler; +import net.minecraft.advancements.Advancement; +import net.minecraft.advancements.AdvancementManager; import net.minecraft.block.Block; import net.minecraft.block.material.Material; import net.minecraft.block.state.IBlockState; @@ -12,10 +15,14 @@ import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.util.ResourceLocation; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; +import net.minecraft.world.WorldServer; import net.minecraftforge.fml.common.Loader; +import net.minecraftforge.fml.relauncher.ReflectionHelper; import tschipp.carryon.common.config.CarryOnConfig; +import tschipp.carryon.common.handler.ListHandler; import tschipp.carryon.common.helper.ScriptParseHelper; public class ScriptChecker @@ -33,12 +40,17 @@ public class ScriptChecker float resistance = block.getExplosionResistance(null); NBTTagCompound nbt = tag; - for (CarryOnOverride override : ScriptReader.OVERRIDES.values()) + boolean isAllowed = CarryOnConfig.settings.useWhitelistBlocks ? ListHandler.isAllowed(block) : !ListHandler.isForbidden(block); + + if (isAllowed) { - if (override.isBlock()) + for (CarryOnOverride override : ScriptReader.OVERRIDES.values()) { - if (matchesAll(override, block, meta, material, hardness, resistance, nbt)) - return override; + if (override.isBlock()) + { + if (matchesAll(override, block, meta, material, hardness, resistance, nbt)) + return override; + } } } @@ -58,12 +70,17 @@ public class ScriptChecker NBTTagCompound tag = new NBTTagCompound(); entity.writeToNBT(tag); - for (CarryOnOverride override : ScriptReader.OVERRIDES.values()) + boolean isAllowed = CarryOnConfig.settings.useWhitelistEntities ? ListHandler.isAllowed(entity) : !ListHandler.isForbidden(entity); + + if (isAllowed) { - if (override.isEntity()) + for (CarryOnOverride override : ScriptReader.OVERRIDES.values()) { - if (matchesAll(override, name, height, width, health, tag)) - return override; + if (override.isEntity()) + { + if (matchesAll(override, name, height, width, health, tag)) + return override; + } } } @@ -95,14 +112,56 @@ public class ScriptChecker public static boolean fulfillsConditions(CarryOnOverride override, EntityPlayer player) { - boolean achievement = ScriptParseHelper.getAchievementFromString(override.getConditionAchievement()) == null ? true : player.hasAchievement(ScriptParseHelper.getAchievementFromString(override.getConditionAchievement())); + AdvancementManager manager = ((WorldServer) ((EntityPlayerMP) player).world).getAdvancementManager(); + Advancement adv = manager.getAdvancement(new ResourceLocation((override.getConditionAchievement()) == null ? "" : override.getConditionAchievement())); + + boolean achievement = adv == null ? true : ((EntityPlayerMP) player).getAdvancements().getProgress(adv).isDone(); boolean gamemode = ScriptParseHelper.matches(((EntityPlayerMP) player).interactionManager.getGameType().getID(), override.getConditionGamemode()); - boolean gamestage = Loader.isModLoaded("gamestages") ? (override.getConditionGamestage() != null ? PlayerDataHandler.getStageData(player).hasUnlockedStage(override.getConditionGamestage()) : true) : true; + boolean gamestage = true; + if (Loader.isModLoaded("gamestages")) + { + if (override.getConditionGamestage() != null) + { + try + { + Class gameStageHelper = Class.forName("net.darkhax.gamestages.GameStageHelper"); + Class iStageData = Class.forName("net.darkhax.gamestages.data.IStageData"); + + Method getPlayerData = ReflectionHelper.findMethod(gameStageHelper, "getPlayerData", null, EntityPlayer.class); + Method hasStage = ReflectionHelper.findMethod(iStageData, "hasStage", null, String.class); + + Object stageData = getPlayerData.invoke(null, player); + String condition = override.getConditionGamestage(); + gamestage = (boolean) hasStage.invoke(stageData, condition); + } + catch (Exception e) + { + try + { + Class playerDataHandler = Class.forName("net.darkhax.gamestages.capabilities.PlayerDataHandler"); + Class iStageData = Class.forName("net.darkhax.gamestages.capabilities.PlayerDataHandler$IStageData"); + + Method getStageData = ReflectionHelper.findMethod(playerDataHandler, "getStageData", null, EntityPlayer.class); + Method hasUnlockedStage = ReflectionHelper.findMethod(iStageData, "hasUnlockedStage", null, String.class); + + Object stageData = getStageData.invoke(null, player); + String condition = override.getConditionGamestage(); + gamestage = (boolean) hasUnlockedStage.invoke(stageData, condition); + + } + catch (Exception ex) + { + } + } + + } + } + boolean position = ScriptParseHelper.matches(player.getPosition(), override.getConditionPosition()); boolean xp = ScriptParseHelper.matches(player.experienceLevel, override.getConditionXp()); boolean scoreboard = ScriptParseHelper.matchesScore(player, override.getConditionScoreboard()); boolean effects = ScriptParseHelper.hasEffects(player, override.getConditionEffects()); - + return (achievement && gamemode && gamestage && position && xp && scoreboard && effects); } @@ -114,13 +173,13 @@ public class ScriptChecker if (tag != null && tag.hasKey("overrideKey")) { int key = tag.getInteger("overrideKey"); - + return ScriptReader.OVERRIDES.get(key); } return null; } - + public static void setCarryOnOverride(EntityPlayer player, int i) { NBTTagCompound tag = player.getEntityData(); @@ -128,5 +187,5 @@ public class ScriptChecker if (tag != null) tag.setInteger("overrideKey", i); } - + } diff --git a/src/main/java/tschipp/carryon/common/scripting/ScriptReader.java b/src/main/java/tschipp/carryon/scripting/ScriptReader.java similarity index 89% rename from src/main/java/tschipp/carryon/common/scripting/ScriptReader.java rename to src/main/java/tschipp/carryon/scripting/ScriptReader.java index 29ca9c1..6c0d4fa 100644 --- a/src/main/java/tschipp/carryon/common/scripting/ScriptReader.java +++ b/src/main/java/tschipp/carryon/scripting/ScriptReader.java @@ -29,6 +29,7 @@ public class ScriptReader public static void preInit(FMLPreInitializationEvent event) { CarryOn.CONFIGURATION_FILE = new File(event.getModConfigurationDirectory(), "carryon-scripts/"); + if (!CarryOn.CONFIGURATION_FILE.exists()) CarryOn.CONFIGURATION_FILE.mkdir(); @@ -56,8 +57,9 @@ public class ScriptReader JsonObject object = (JsonObject) json.get("object"); JsonObject conditions = (JsonObject) json.get("conditions"); JsonObject render = (JsonObject) json.get("render"); + JsonObject effects = (JsonObject) json.get("effects"); - if ((object != null && conditions != null) || (object != null && render != null)) + if ((object != null && conditions != null) || (object != null && render != null) || (object != null && effects != null)) { JsonObject block = (JsonObject) object.get("block"); JsonObject entity = (JsonObject) object.get("entity"); @@ -116,12 +118,12 @@ public class ScriptReader if (conditions != null) { JsonElement gamestage = conditions.get("gamestage"); - JsonElement achievement = conditions.get("achievement"); + JsonElement achievement = conditions.get("advancement"); JsonElement xp = conditions.get("xp"); JsonElement gamemode = conditions.get("gamemode"); JsonElement scoreboard = conditions.get("scoreboard"); JsonElement position = conditions.get("position"); - JsonElement effects = conditions.get("effects"); + JsonElement potionEffects = conditions.get("effects"); if(gamestage != null) override.setConditionGamestage(gamestage.getAsString()); @@ -135,8 +137,8 @@ public class ScriptReader override.setConditionScoreboard(scoreboard.getAsString()); if(position != null) override.setConditionPosition(position.getAsString()); - if(effects != null) - override.setConditionEffects(effects.getAsString()); + if(potionEffects != null) + override.setConditionEffects(potionEffects.getAsString()); } if (render != null) @@ -177,8 +179,21 @@ public class ScriptReader override.setRenderRightArm(renderRightArm.getAsBoolean()); } - OVERRIDES.put(override.hashCode(), override); + if(effects != null) + { + JsonElement commandInit = effects.get("commandPickup"); + JsonElement commandLoop = effects.get("commandLoop"); + JsonElement commandPlace = effects.get("commandPlace"); + if(commandInit != null) + override.setCommandInit(commandInit.getAsString()); + if(commandLoop != null) + override.setCommandLoop(commandLoop.getAsString()); + if(commandPlace != null) + override.setCommandPlace(commandPlace.getAsString()); + } + + OVERRIDES.put(override.hashCode(), override); } } } diff --git a/src/main/resources/assets/carryon/lang/en_UD.lang b/src/main/resources/assets/carryon/lang/en_UD.lang deleted file mode 100644 index 9c3ef24..0000000 --- a/src/main/resources/assets/carryon/lang/en_UD.lang +++ /dev/null @@ -1,14 +0,0 @@ -carryon.category.settings=sᵷuᴉʇʇǝS -carryon.category.blacklist=ʇsᴉꞁʞɔɐꞁᗺ -carryon.category.modeloverrides=(pǝɔuɐʌpⱯ) sǝpᴉɹɹǝʌO ꞁǝpoW -carryon.category.custompickupconditions=(pǝɔuɐʌpⱯ) suoᴉʇᴉpuoƆ dnʞɔᴉԀ ɯoʇsnƆ -carryon.category.whitelist=ʇsᴉꞁǝʇᴉɥM - -carryon.general.modeloverrides.modeloverrides=sǝpᴉɹɹǝʌO ꞁǝpoW -carryon.general.blacklist.forbiddenentities=dn ʞɔᴉd ʇouuɐɔ ɹǝʎɐꞁԀ ǝɥʇ ʇɐɥʇ sǝᴉʇᴉʇuƎ -carryon.general.blacklist.forbiddentiles=dn ʞɔᴉd ʇouuɐɔ ɹǝʎɐꞁԀ ǝɥʇ ʇɐɥʇ sʞɔoꞁᗺ -carryon.category.custompickupconditions.custompickupconditionsblocks=suoᴉʇᴉpuoƆ dnʞɔᴉԀ ʞɔoꞁᗺ ɯoʇsnƆ -carryon.category.custompickupconditions.custompickupconditionsentities=suoᴉʇᴉpuoƆ dnʞɔᴉԀ ʎʇᴉʇuƎ ɯoʇsnƆ - -key.carry.desc=ʎɹɹɐƆ -key.carry.category=uO ʎɹɹɐƆ diff --git a/src/main/resources/assets/carryon/lang/en_US.lang b/src/main/resources/assets/carryon/lang/en_US.lang deleted file mode 100644 index e854bf1..0000000 --- a/src/main/resources/assets/carryon/lang/en_US.lang +++ /dev/null @@ -1,14 +0,0 @@ -carryon.category.settings=Settings -carryon.category.blacklist=Blacklist -carryon.category.modeloverrides=Model Overrides (Advanced) -carryon.category.custompickupconditions=Custom Pickup Conditions (Advanced) -carryon.category.whitelist=Whitelist - -carryon.general.modeloverrides.modeloverrides=Model Overrides -carryon.general.blacklist.forbiddenentities=Entities that the Player cannot pick up -carryon.general.blacklist.forbiddentiles=Blocks that the Player cannot pick up -carryon.category.custompickupconditions.custompickupconditionsblocks=Custom Block Pickup Conditions -carryon.category.custompickupconditions.custompickupconditionsentities=Custom Entity Pickup Conditions - -key.carry.desc=Carry -key.carry.category=Carry On \ No newline at end of file diff --git a/src/main/resources/assets/carryon/logo.png b/src/main/resources/assets/carryon/logo.png deleted file mode 100644 index 1b9a978..0000000 Binary files a/src/main/resources/assets/carryon/logo.png and /dev/null differ diff --git a/src/main/resources/assets/carryon/models/item/entity_item.json b/src/main/resources/assets/carryon/models/item/entity_item.json new file mode 100644 index 0000000..3480261 --- /dev/null +++ b/src/main/resources/assets/carryon/models/item/entity_item.json @@ -0,0 +1,6 @@ +{ + "parent": "item/generated", + "textures": { + "layer0": "carryon:item/tile" + } +} diff --git a/src/main/resources/assets/carryon/models/item/tile.json b/src/main/resources/assets/carryon/models/item/tile.json deleted file mode 100644 index 3b02d83..0000000 --- a/src/main/resources/assets/carryon/models/item/tile.json +++ /dev/null @@ -1,33 +0,0 @@ -{ - "parent": "builtin/generated", - "textures": { - "layer0": "carryon:items/tile" - }, - "display": { - "ground": { - "rotation": [ 0, 0, 0 ], - "translation": [ 0, 2, 0], - "scale":[ 0.5, 0.5, 0.5 ] - }, - "head": { - "rotation": [ 0, 180, 0 ], - "translation": [ 0, 13, 7], - "scale":[ 1, 1, 1] - }, - "thirdperson_righthand": { - "rotation": [ 0, 0, 0 ], - "translation": [ 0, 0, 1 ], - "scale": [ 0.1, 0.1, 0.1 ] - }, - "firstperson_righthand": { - "rotation": [ 0, -90, 25 ], - "translation": [ 1.13, 3.2, 1.13], - "scale": [ 0.68, 0.68, 0.68 ] - }, - "gui": { - "rotation": [ 30, 225, 0 ], - "translation": [ 0, 0, 0], - "scale":[ 0.625, 0.625, 0.625 ] - } - } -} diff --git a/src/main/resources/assets/carryon/models/item/tile_item.json b/src/main/resources/assets/carryon/models/item/tile_item.json new file mode 100644 index 0000000..3480261 --- /dev/null +++ b/src/main/resources/assets/carryon/models/item/tile_item.json @@ -0,0 +1,6 @@ +{ + "parent": "item/generated", + "textures": { + "layer0": "carryon:item/tile" + } +} diff --git a/src/main/resources/assets/carryon/pack.png b/src/main/resources/assets/carryon/pack.png new file mode 100644 index 0000000..d492338 Binary files /dev/null and b/src/main/resources/assets/carryon/pack.png differ diff --git a/src/main/resources/assets/carryon/textures/items/tile.png b/src/main/resources/assets/carryon/textures/item/tile.png similarity index 100% rename from src/main/resources/assets/carryon/textures/items/tile.png rename to src/main/resources/assets/carryon/textures/item/tile.png diff --git a/src/main/resources/carryon.client.json b/src/main/resources/carryon.client.json new file mode 100644 index 0000000..f004681 --- /dev/null +++ b/src/main/resources/carryon.client.json @@ -0,0 +1,16 @@ +{ + "required": true, + "package": "tschipp.carryon.mixin.client", + "compatibilityLevel": "JAVA_8", + "mixins": [ + "PlayerRendererMixin", + "BipedModelMixin", + "ArmorRendererMixin", + "FirstPersonMixin", + "MouseMixin", + "KeyboardMixin" + ], + "injectors": { + "defaultRequire": 1 + } +} diff --git a/src/main/resources/carryon.common.json b/src/main/resources/carryon.common.json new file mode 100644 index 0000000..08ca5c5 --- /dev/null +++ b/src/main/resources/carryon.common.json @@ -0,0 +1,13 @@ +{ + "required": true, + "package": "tschipp.carryon.mixin.common", + "compatibilityLevel": "JAVA_8", + "mixins": [ + "BlockStateMixin", + "EntityMixin", + "PlayerMixin" + ], + "injectors": { + "defaultRequire": 1 + } +} diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json new file mode 100644 index 0000000..020b154 --- /dev/null +++ b/src/main/resources/fabric.mod.json @@ -0,0 +1,12 @@ +{ + "id": "carryon", + "name": "Carry On", + "version": "1.0.0", + "side": "universal", + "initializer": "tschipp.carryon.CarryOn", + "description": "Carry On for Fabric", + "mixins": { + "client": "carryon.client.json", + "common": "carryon.common.json" + } +} \ No newline at end of file diff --git a/src/main/resources/mcmod.info b/src/main/resources/mcmod.info deleted file mode 100644 index 17e2a17..0000000 --- a/src/main/resources/mcmod.info +++ /dev/null @@ -1,16 +0,0 @@ -[ -{ - "modid" : "carryon", - "name" : "Carry On", - "version" : "1.9.1", "mcversion" : "1.11.2", - "url" : "", - "credits" : "Tschipp, Purplicious_Cow, cy4n", - "authorList" : ["Tschipp, Purplicious_Cow, cy4n"], - "description": "Carry On is a simple mod that improves game interaction by allowing players to pick up, carry, and place single block Tile Entities using only their empty hands.", - "logoFile" : "assets/carryon/logo.png", - "updateUrl" : "https://gist.githubusercontent.com/Tschipp/dccadee7c90d7a34e6e76a35d9d6fa2e/raw/5115328bf7c35d5c5cea64bdb58becd2ca17fcac/update.json", - "parent" : "", - "dependencies": [], - "screenshots": [] -} -]