diff --git a/build.gradle b/build.gradle index b4c81c8..271dd9b 100644 --- a/build.gradle +++ b/build.gradle @@ -1,32 +1,63 @@ -buildscript { - repositories { - jcenter() - maven { url "http://files.minecraftforge.net/maven" } - } - dependencies { - classpath "net.minecraftforge.gradle:ForgeGradle:2.3-SNAPSHOT" - } +plugins { + id "fabric-loom" version "0.6-SNAPSHOT" + id "org.cadixdev.licenser" version "0.5.0" } apply plugin: "java" -apply plugin: "net.minecraftforge.gradle.forge" - -group 'org.dimdev.matrix' -archivesBaseName = 'matrix' -version '1.0' sourceCompatibility = 1.8 +targetCompatibility = 1.8 -minecraft { - version "1.12.2-14.23.5.2768" - runDir "run" - mappings "stable_39" +sourceSets { + testmod } -repositories { - mavenCentral() +dependencies { + minecraft "com.mojang:minecraft:21w08b" + mappings "net.fabricmc:yarn:21w08b+build.8:v2" + modImplementation "net.fabricmc:fabric-loader:0.11.1" + testmodImplementation sourceSets.main.output + testmodCompileOnly sourceSets.main.compileClasspath + testmodRuntimeOnly sourceSets.main.runtimeClasspath + modRuntime("net.fabricmc.fabric-api:fabric-api:0.31.2+1.17") { + exclude module: "fabric-loader" + } } -dependencies { - testCompile group: 'junit', name: 'junit', version: '4.12' +version = "1.0.0" +archivesBaseName = "Matrix" +group = "org.dimdev" + +license { + include '**/*.java' +} + +processResources { + filesMatching("fabric.mod.json") { + expand "version": project.version + } + + inputs.property "version", project.version +} + +tasks.withType(JavaCompile).configureEach { + it.options.encoding = "UTF-8" + def targetVersion = 8 + if (JavaVersion.current().isJava9Compatible()) { + it.options.release.set(targetVersion) + } +} + +java { + withSourcesJar() +} + +jar { + from("LICENSE") { + rename { "${it}_${project.archivesBaseName}"} + } +} + +artifacts { + archives jar } diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index 94336fc..e708b1c 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 290541c..4d9ca16 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.3-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-6.7.1-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/gradlew b/gradlew old mode 100644 new mode 100755 index cccdd3d..4f906e0 --- a/gradlew +++ b/gradlew @@ -1,5 +1,21 @@ #!/usr/bin/env sh +# +# Copyright 2015 the original author or authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + ############################################################################## ## ## Gradle start up script for UN*X @@ -28,7 +44,7 @@ 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="" +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' # Use the maximum available, or set MAX_FD != -1 to use that value. MAX_FD="maximum" @@ -66,6 +82,7 @@ esac CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + # Determine the Java command to use to start the JVM. if [ -n "$JAVA_HOME" ] ; then if [ -x "$JAVA_HOME/jre/sh/java" ] ; then @@ -109,10 +126,11 @@ if $darwin; then GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" fi -# For Cygwin, switch paths to Windows format before running java -if $cygwin ; then +# For Cygwin or MSYS, switch paths to Windows format before running java +if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then APP_HOME=`cygpath --path --mixed "$APP_HOME"` CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` + JAVACMD=`cygpath --unix "$JAVACMD"` # We build the pattern for arguments to be converted via cygpath @@ -138,19 +156,19 @@ if $cygwin ; then else eval `echo args$i`="\"$arg\"" fi - i=$((i+1)) + i=`expr $i + 1` done case $i in - (0) set -- ;; - (1) set -- "$args0" ;; - (2) set -- "$args0" "$args1" ;; - (3) set -- "$args0" "$args1" "$args2" ;; - (4) set -- "$args0" "$args1" "$args2" "$args3" ;; - (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; - (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; - (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; - (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; - (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; + 0) set -- ;; + 1) set -- "$args0" ;; + 2) set -- "$args0" "$args1" ;; + 3) set -- "$args0" "$args1" "$args2" ;; + 4) set -- "$args0" "$args1" "$args2" "$args3" ;; + 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; + 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; + 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; + 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; + 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; esac fi @@ -159,14 +177,9 @@ save () { for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done echo " " } -APP_ARGS=$(save "$@") +APP_ARGS=`save "$@"` # Collect all arguments for the java command, following the shell quoting and substitution rules eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" -# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong -if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then - cd "$(dirname "$0")" -fi - exec "$JAVACMD" "$@" diff --git a/gradlew.bat b/gradlew.bat index f955316..ac1b06f 100644 --- a/gradlew.bat +++ b/gradlew.bat @@ -1,84 +1,89 @@ -@if "%DEBUG%" == "" @echo off -@rem ########################################################################## -@rem -@rem Gradle startup script for Windows -@rem -@rem ########################################################################## - -@rem Set local scope for the variables with windows NT shell -if "%OS%"=="Windows_NT" setlocal - -set DIRNAME=%~dp0 -if "%DIRNAME%" == "" set DIRNAME=. -set APP_BASE_NAME=%~n0 -set APP_HOME=%DIRNAME% - -@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -set DEFAULT_JVM_OPTS= - -@rem Find java.exe -if defined JAVA_HOME goto findJavaFromJavaHome - -set JAVA_EXE=java.exe -%JAVA_EXE% -version >NUL 2>&1 -if "%ERRORLEVEL%" == "0" goto init - -echo. -echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. - -goto fail - -:findJavaFromJavaHome -set JAVA_HOME=%JAVA_HOME:"=% -set JAVA_EXE=%JAVA_HOME%/bin/java.exe - -if exist "%JAVA_EXE%" goto init - -echo. -echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. - -goto fail - -:init -@rem Get command-line arguments, handling Windows variants - -if not "%OS%" == "Windows_NT" goto win9xME_args - -:win9xME_args -@rem Slurp the command line arguments. -set CMD_LINE_ARGS= -set _SKIP=2 - -:win9xME_args_slurp -if "x%~1" == "x" goto execute - -set CMD_LINE_ARGS=%* - -:execute -@rem Setup the command line - -set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar - -@rem Execute Gradle -"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% - -:end -@rem End local scope for the variables with windows NT shell -if "%ERRORLEVEL%"=="0" goto mainEnd - -:fail -rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of -rem the _cmd.exe /c_ return code! -if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 -exit /b 1 - -:mainEnd -if "%OS%"=="Windows_NT" endlocal - -:omega +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem + +@if "%DEBUG%" == "" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if "%ERRORLEVEL%" == "0" goto execute + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto execute + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* + +:end +@rem End local scope for the variables with windows NT shell +if "%ERRORLEVEL%"=="0" goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 +exit /b 1 + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/settings.gradle b/settings.gradle index e291ba4..c0075e8 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,2 +1,13 @@ -rootProject.name = 'matrix' +pluginManagement { + repositories { + jcenter() + maven { + name = 'Fabric' + url = 'https://maven.fabricmc.net/' + } + gradlePluginPortal() + mavenCentral() + } +} +rootProject.name = 'Matrix' \ No newline at end of file diff --git a/src/main/java/org/dimdev/matrix/BlockProcessor.java b/src/main/java/org/dimdev/matrix/BlockProcessor.java deleted file mode 100644 index 2bdcedc..0000000 --- a/src/main/java/org/dimdev/matrix/BlockProcessor.java +++ /dev/null @@ -1,28 +0,0 @@ -package org.dimdev.matrix; - -import javax.annotation.processing.AbstractProcessor; -import javax.annotation.processing.RoundEnvironment; -import javax.annotation.processing.SupportedAnnotationTypes; -import javax.annotation.processing.SupportedSourceVersion; -import javax.lang.model.SourceVersion; -import javax.lang.model.element.Element; -import javax.lang.model.element.TypeElement; -import java.util.Set; - -@SupportedAnnotationTypes("org.dimdev.matrix.Block") -@SupportedSourceVersion(SourceVersion.RELEASE_8) -public class BlockProcessor extends AbstractProcessor { - - @Override - public boolean process(Set extends TypeElement> annotations, RoundEnvironment roundEnv) { - try { - for (Element element : roundEnv.getElementsAnnotatedWith(Block.class)) { - Matrix.addBlock(element.getClass().getConstructor().newInstance(element.getModifiers())); - } - } catch (Exception e) { - - } - return true; - } - -} diff --git a/src/main/java/org/dimdev/matrix/Item.java b/src/main/java/org/dimdev/matrix/Item.java deleted file mode 100644 index fe6e60c..0000000 --- a/src/main/java/org/dimdev/matrix/Item.java +++ /dev/null @@ -1,27 +0,0 @@ -package org.dimdev.matrix; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -@Target(ElementType.TYPE) -@Retention(RetentionPolicy.RUNTIME) -public @interface Item { - - /** - * Sets the item registry name for the item. - */ - String registryName() default ""; - - /** - * Sets the translation key for the item. - */ - String translationKey() default ""; - - /** - * Sets the creative tab for the item - */ - Class> creativetab(); - -} diff --git a/src/main/java/org/dimdev/matrix/ItemProcessor.java b/src/main/java/org/dimdev/matrix/ItemProcessor.java deleted file mode 100644 index c92b26e..0000000 --- a/src/main/java/org/dimdev/matrix/ItemProcessor.java +++ /dev/null @@ -1,24 +0,0 @@ -package org.dimdev.matrix; - -import javax.annotation.processing.AbstractProcessor; -import javax.annotation.processing.RoundEnvironment; -import javax.annotation.processing.SupportedAnnotationTypes; -import javax.annotation.processing.SupportedSourceVersion; -import javax.lang.model.SourceVersion; -import javax.lang.model.element.Element; -import javax.lang.model.element.TypeElement; -import java.util.Set; - -@SupportedAnnotationTypes("org.dimdev.matrix.Item") -@SupportedSourceVersion(SourceVersion.RELEASE_8) -public class ItemProcessor extends AbstractProcessor { - - @Override - public boolean process(Set extends TypeElement> annotations, RoundEnvironment roundEnv) { - for (Element element : roundEnv.getElementsAnnotatedWith(Item.class)) { - - } - return true; - } - -} diff --git a/src/main/java/org/dimdev/matrix/Matrix.java b/src/main/java/org/dimdev/matrix/Matrix.java index 3f7efc0..74ad732 100644 --- a/src/main/java/org/dimdev/matrix/Matrix.java +++ b/src/main/java/org/dimdev/matrix/Matrix.java @@ -1,58 +1,59 @@ package org.dimdev.matrix; -import net.minecraftforge.fml.common.Mod; -import net.minecraftforge.fml.common.event.FMLInitializationEvent; -import net.minecraftforge.fml.common.event.FMLPostInitializationEvent; -import net.minecraftforge.fml.common.event.FMLPreInitializationEvent; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; - -import java.util.ArrayList; - +import java.lang.reflect.Modifier; +import java.util.Arrays; + +import net.minecraft.item.BlockItem; +import net.minecraft.item.Item; +import net.minecraft.util.Identifier; +import net.minecraft.util.registry.Registry; + +/** + * An Annotation Based Registration Library. + * + *
Matrix allows registering items, blocks, etc. without + * calling {@code Registry.register(...)} a bunch of times or + * registering at static init. Registering at static init + * is not safe as you might just register the entries much + * before vanilla registers its entries.
+ * + *Using Annotations is simple and easy to migrate to. + * You no longer have to worry about skipping a call to + * {@code Registry.register(...)}.
+ */ public class Matrix { - - Logger LOG = LogManager.getLogger("Matrix"); - - private static ArrayList blockQueue; - private static ArrayList itemQueue; - - @Mod.EventHandler - public void preInit(FMLPreInitializationEvent e) { - LOG.info("Preinitialization Stage"); - } - - @Mod.EventHandler - public void init(FMLInitializationEvent e) { - LOG.info("Initialization Stage"); - } - - @Mod.EventHandler - public void postInit(FMLPostInitializationEvent e) { - LOG.info("Post Initialization Stage"); - } - - public static void initializeBlockQueue() { - blockQueue = new ArrayList<>(); - } - - public static void initializeItemQueue() { - itemQueue = new ArrayList<>(); - } - - public static void addBlock(Object block) { - blockQueue.add(block); - } - - public static void addItem(Object item) { - itemQueue.add(item); - } - - public static ArrayList getBlockQueue() { - return blockQueue; - } - - public static ArrayList getItemQueue() { - return itemQueue; - } - + /** + * + * @param clazz The class that should be scanned for registry entries. + * @param registry The registry that entries should be registered to. + */ + @SuppressWarnings({"unchecked", "rawtypes"}) + public static void register(Class> clazz, Registry> registry) { + Registrar registrar = clazz.getAnnotation(Registrar.class); + if (registrar == null) { + return; + } + + String modid = registrar.modid(); + Class> element = registrar.element(); + + Arrays.stream(clazz.getFields()) + .filter(field -> field.isAnnotationPresent(RegistryEntry.class) + && Modifier.isPublic(field.getModifiers()) + && Modifier.isStatic(field.getModifiers()) + && Modifier.isFinal(field.getModifiers()) + && element.isAssignableFrom(field.getType()) + ) + .forEach(field -> { + try { + Object value = field.get(null); + Registry.register((Registry) registry, new Identifier(modid, field.getAnnotation(RegistryEntry.class).value()), element.cast(value)); + if (value instanceof BlockItem) { + Item.BLOCK_ITEMS.put(((BlockItem) value).getBlock(), (Item) value); + } + } catch (IllegalAccessException e) { + throw new AssertionError(e); + } + }); + } } diff --git a/src/main/java/org/dimdev/matrix/Block.java b/src/main/java/org/dimdev/matrix/Registrar.java similarity index 52% rename from src/main/java/org/dimdev/matrix/Block.java rename to src/main/java/org/dimdev/matrix/Registrar.java index 62b6522..26afcc4 100644 --- a/src/main/java/org/dimdev/matrix/Block.java +++ b/src/main/java/org/dimdev/matrix/Registrar.java @@ -5,18 +5,16 @@ import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; -@Target(ElementType.TYPE) +/** + * Specifies the namespace for registry entries. + * + *This must be annotated on the class you wish + * to keep all your registry entries (as fields).
+ */ @Retention(RetentionPolicy.RUNTIME) -public @interface Block { - - /** - * Sets the item registry name for the block. - */ - String registryName() default ""; - - /** - * Sets the translation key for the block. - */ - String translationKey() default ""; +@Target(ElementType.TYPE) +public @interface Registrar { + Class> element(); + String modid(); } diff --git a/src/main/java/org/dimdev/matrix/RegistrationDriver.java b/src/main/java/org/dimdev/matrix/RegistrationDriver.java deleted file mode 100644 index 60dec54..0000000 --- a/src/main/java/org/dimdev/matrix/RegistrationDriver.java +++ /dev/null @@ -1,23 +0,0 @@ -package org.dimdev.matrix; - -import net.minecraft.block.Block; -import net.minecraft.item.Item; -import net.minecraftforge.event.RegistryEvent; -import net.minecraftforge.fml.common.Mod; - -public class RegistrationDriver { - - @Mod.EventHandler - public void registerBlock(RegistryEvent.Register