Skip to content

Commit

Permalink
Finished upgrade to architectury and attempt to see what jitpack does.
Browse files Browse the repository at this point in the history
  • Loading branch information
Waterpicker committed Feb 14, 2022
1 parent e823133 commit f846bdc
Show file tree
Hide file tree
Showing 16 changed files with 486 additions and 177 deletions.
1 change: 1 addition & 0 deletions .architectury-transformer/debug.log
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[Architectury Transformer DEBUG] Closing File Systems for D:\Git\Matrix\common\build\libs\matrix-1.0.0.jar
63 changes: 63 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
{
"version": "0.2.0",
"configurations": [
{
"type": "java",
"name": "Minecraft Client (:fabric)",
"request": "launch",
"cwd": "${workspaceFolder}/fabric/run",
"console": "internalConsole",
"stopOnEntry": false,
"mainClass": "dev.architectury.transformer.TransformerRuntime",
"vmArgs": "\"-Dfabric.dli.config\u003dD:\\Git\\Matrix\\fabric\\.gradle\\loom-cache\\launch.cfg\" \"-Dfabric.dli.env\u003dclient\" \"-Dfabric.dli.main\u003dnet.fabricmc.loader.impl.launch.knot.KnotClient\" \"-Darchitectury.main.class\u003dD:\\Git\\Matrix\\fabric\\.gradle\\architectury\\.main_class\" \"-Darchitectury.runtime.transformer\u003dD:\\Git\\Matrix\\fabric\\.gradle\\architectury\\.transforms\" \"-Darchitectury.properties\u003dD:\\Git\\Matrix\\fabric\\.gradle\\architectury\\.properties\" \"-Djdk.attach.allowAttachSelf\u003dtrue\" \"-javaagent:D:\\Git\\Matrix\\.gradle\\architectury\\architectury-transformer-agent.jar\"",
"args": "",
"env": {},
"projectName": "fabric"
},
{
"type": "java",
"name": "Minecraft Server (:fabric)",
"request": "launch",
"cwd": "${workspaceFolder}/fabric/run",
"console": "internalConsole",
"stopOnEntry": false,
"mainClass": "dev.architectury.transformer.TransformerRuntime",
"vmArgs": "\"-Dfabric.dli.config\u003dD:\\Git\\Matrix\\fabric\\.gradle\\loom-cache\\launch.cfg\" \"-Dfabric.dli.env\u003dserver\" \"-Dfabric.dli.main\u003dnet.fabricmc.loader.impl.launch.knot.KnotServer\" \"-Darchitectury.main.class\u003dD:\\Git\\Matrix\\fabric\\.gradle\\architectury\\.main_class\" \"-Darchitectury.runtime.transformer\u003dD:\\Git\\Matrix\\fabric\\.gradle\\architectury\\.transforms\" \"-Darchitectury.properties\u003dD:\\Git\\Matrix\\fabric\\.gradle\\architectury\\.properties\" \"-Djdk.attach.allowAttachSelf\u003dtrue\" \"-javaagent:D:\\Git\\Matrix\\.gradle\\architectury\\architectury-transformer-agent.jar\"",
"args": "\"nogui\"",
"env": {},
"projectName": "fabric"
},
{
"type": "java",
"name": "Minecraft Client (:forge)",
"request": "launch",
"cwd": "${workspaceFolder}/forge/run",
"console": "internalConsole",
"stopOnEntry": false,
"mainClass": "dev.architectury.transformer.TransformerRuntime",
"vmArgs": "\"-Dfabric.dli.config\u003dD:\\Git\\Matrix\\forge\\.gradle\\loom-cache\\launch.cfg\" \"-Dfabric.dli.env\u003dclient\" \"-p\" \"C:\\Users\\water\\.gradle\\caches\\modules-2\\files-2.1\\cpw.mods\\securejarhandler\\0.9.54\\24b670f2c026ec9777e64a2c2126ebc8635dbe8d\\securejarhandler-0.9.54.jar;C:\\Users\\water\\.gradle\\caches\\modules-2\\files-2.1\\org.ow2.asm\\asm-commons\\9.1\\8b971b182eb5cf100b9e8d4119152d83e00e0fdd\\asm-commons-9.1.jar;C:\\Users\\water\\.gradle\\caches\\modules-2\\files-2.1\\org.ow2.asm\\asm-util\\9.1\\36464a45d871779f3383a8a9aba2b26562a86729\\asm-util-9.1.jar;C:\\Users\\water\\.gradle\\caches\\modules-2\\files-2.1\\org.ow2.asm\\asm-analysis\\9.1\\4f61b83b81d8b659958f4bcc48907e93ecea55a0\\asm-analysis-9.1.jar;C:\\Users\\water\\.gradle\\caches\\modules-2\\files-2.1\\org.ow2.asm\\asm-tree\\9.1\\c333f2a855069cb8eb17a40a3eb8b1b67755d0eb\\asm-tree-9.1.jar;C:\\Users\\water\\.gradle\\caches\\modules-2\\files-2.1\\org.ow2.asm\\asm\\9.1\\a99500cf6eea30535eeac6be73899d048f8d12a8\\asm-9.1.jar\" \"--add-modules\" \"ALL-MODULE-PATH\" \"--add-opens\" \"java.base/java.util.jar\u003dcpw.mods.securejarhandler\" \"--add-exports\" \"java.base/sun.security.util\u003dcpw.mods.securejarhandler\" \"--add-exports\" \"jdk.naming.dns/com.sun.jndi.dns\u003djava.naming\" \"-Dfabric.dli.main\u003dcpw.mods.bootstraplauncher.BootstrapLauncher\" \"-Darchitectury.main.class\u003dD:\\Git\\Matrix\\forge\\.gradle\\architectury\\.main_class\" \"-Darchitectury.runtime.transformer\u003dD:\\Git\\Matrix\\forge\\.gradle\\architectury\\.transforms\" \"-Darchitectury.properties\u003dD:\\Git\\Matrix\\forge\\.gradle\\architectury\\.properties\" \"-Djdk.attach.allowAttachSelf\u003dtrue\" \"-javaagent:D:\\Git\\Matrix\\.gradle\\architectury\\architectury-transformer-agent.jar\"",
"args": "",
"env": {
"MOD_CLASSES": "main%%D:\\Git\\Matrix\\forge\\build\\resources\\main;main%%D:\\Git\\Matrix\\forge\\build\\classes\\java\\main",
"MCP_MAPPINGS": "loom.stub"
},
"projectName": "forge"
},
{
"type": "java",
"name": "Minecraft Server (:forge)",
"request": "launch",
"cwd": "${workspaceFolder}/forge/run",
"console": "internalConsole",
"stopOnEntry": false,
"mainClass": "dev.architectury.transformer.TransformerRuntime",
"vmArgs": "\"-Dfabric.dli.config\u003dD:\\Git\\Matrix\\forge\\.gradle\\loom-cache\\launch.cfg\" \"-Dfabric.dli.env\u003dserver\" \"-p\" \"C:\\Users\\water\\.gradle\\caches\\modules-2\\files-2.1\\cpw.mods\\securejarhandler\\0.9.54\\24b670f2c026ec9777e64a2c2126ebc8635dbe8d\\securejarhandler-0.9.54.jar;C:\\Users\\water\\.gradle\\caches\\modules-2\\files-2.1\\org.ow2.asm\\asm-commons\\9.1\\8b971b182eb5cf100b9e8d4119152d83e00e0fdd\\asm-commons-9.1.jar;C:\\Users\\water\\.gradle\\caches\\modules-2\\files-2.1\\org.ow2.asm\\asm-util\\9.1\\36464a45d871779f3383a8a9aba2b26562a86729\\asm-util-9.1.jar;C:\\Users\\water\\.gradle\\caches\\modules-2\\files-2.1\\org.ow2.asm\\asm-analysis\\9.1\\4f61b83b81d8b659958f4bcc48907e93ecea55a0\\asm-analysis-9.1.jar;C:\\Users\\water\\.gradle\\caches\\modules-2\\files-2.1\\org.ow2.asm\\asm-tree\\9.1\\c333f2a855069cb8eb17a40a3eb8b1b67755d0eb\\asm-tree-9.1.jar;C:\\Users\\water\\.gradle\\caches\\modules-2\\files-2.1\\org.ow2.asm\\asm\\9.1\\a99500cf6eea30535eeac6be73899d048f8d12a8\\asm-9.1.jar\" \"--add-modules\" \"ALL-MODULE-PATH\" \"--add-opens\" \"java.base/java.util.jar\u003dcpw.mods.securejarhandler\" \"--add-exports\" \"java.base/sun.security.util\u003dcpw.mods.securejarhandler\" \"--add-exports\" \"jdk.naming.dns/com.sun.jndi.dns\u003djava.naming\" \"-Dfabric.dli.main\u003dcpw.mods.bootstraplauncher.BootstrapLauncher\" \"-Darchitectury.main.class\u003dD:\\Git\\Matrix\\forge\\.gradle\\architectury\\.main_class\" \"-Darchitectury.runtime.transformer\u003dD:\\Git\\Matrix\\forge\\.gradle\\architectury\\.transforms\" \"-Darchitectury.properties\u003dD:\\Git\\Matrix\\forge\\.gradle\\architectury\\.properties\" \"-Djdk.attach.allowAttachSelf\u003dtrue\" \"-javaagent:D:\\Git\\Matrix\\.gradle\\architectury\\architectury-transformer-agent.jar\"",
"args": "\"nogui\"",
"env": {
"MOD_CLASSES": "main%%D:\\Git\\Matrix\\forge\\build\\resources\\main;main%%D:\\Git\\Matrix\\forge\\build\\classes\\java\\main",
"MCP_MAPPINGS": "loom.stub"
},
"projectName": "forge"
}
]
}
114 changes: 51 additions & 63 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,63 +1,51 @@
plugins {
id "fabric-loom" version "0.6-SNAPSHOT"
id "org.cadixdev.licenser" version "0.5.0"
}

apply plugin: "java"

sourceCompatibility = 1.8
targetCompatibility = 1.8

sourceSets {
testmod
}

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"
}
}

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
}
plugins {
id "architectury-plugin" version "3.4-SNAPSHOT"
id "dev.architectury.loom" version "0.10.0-SNAPSHOT" apply false
}

architectury {
minecraft = rootProject.minecraft_version
}

subprojects {
apply plugin: "dev.architectury.loom"

loom {
silentMojangMappingsLicense()
}

dependencies {
minecraft "com.mojang:minecraft:${rootProject.minecraft_version}"
// The following line declares the mojmap mappings, you may use other mappings as well
mappings loom.officialMojangMappings()
// The following line declares the yarn mappings you may select this one as well.
// mappings "net.fabricmc:yarn:1.18+build.1:v2"
}
}

allprojects {
apply plugin: "java"
apply plugin: "architectury-plugin"
apply plugin: "maven-publish"

archivesBaseName = rootProject.archives_base_name
version = rootProject.version
group = rootProject.group

repositories {
// Add repositories to retrieve artifacts from in here.
// You should only use this when depending on other mods because
// Loom adds the essential maven repositories to download Minecraft and libraries from automatically.
// See https://docs.gradle.org/current/userguide/declaring_repositories.html
// for more information about repositories.
}

tasks.withType(JavaCompile) {
options.encoding = "UTF-8"
options.release = 17
}

java {
withSourcesJar()
}
}
25 changes: 25 additions & 0 deletions common/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
dependencies {
// We depend on fabric loader here to use the fabric @Environment annotations and get the mixin dependencies
// Do NOT use other classes from fabric loader
modImplementation "net.fabricmc:fabric-loader:${rootProject.fabric_loader_version}"
// Remove the next line if you don't want to depend on the API
modApi "dev.architectury:architectury:${rootProject.architectury_version}"
}

architectury {
common()
}

publishing {
publications {
mavenCommon(MavenPublication) {
artifactId = rootProject.archives_base_name
from components.java
}
}

// See https://docs.gradle.org/current/userguide/publishing_maven.html for information on how to set up publishing.
repositories {
// Add repositories to publish to here.
}
}
Original file line number Diff line number Diff line change
@@ -1,59 +1,68 @@
package org.dimdev.matrix;

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.
*
* <p>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.</p>
*
* <p>Using Annotations is simple and easy to migrate to.
* You no longer have to worry about skipping a call to
* {@code Registry.register(...)}.</p>
*/
public class Matrix {
/**
*
* @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);
}
});
}
}
package org.dimdev.matrix;

import dev.architectury.registry.registries.DeferredRegister;
import net.minecraft.core.Registry;
import net.minecraft.resources.ResourceKey;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.BlockItem;
import net.minecraft.world.item.Item;

import java.lang.reflect.Modifier;
import java.util.Arrays;

/**
* An Annotation Based Registration Library.
*
* <p>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.</p>
*
* <p>Using Annotations is simple and easy to migrate to.
* You no longer have to worry about skipping a call to
* {@code Registry.register(...)}.</p>
*/
public class Matrix {
/**
*
* @param clazz The class that should be scanned for registry entries.
* @param registryKey The resource key for the registry being registered to.
*/
@SuppressWarnings({"unchecked", "rawtypes"})
public static <T, S> void register(Class<T> clazz, ResourceKey<Registry<S>> registryKey) {
Registrar registrar = clazz.getAnnotation(Registrar.class);
if (registrar == null) {
return;
}

String modid = registrar.modid();

Class<?> element = registrar.element();

DeferredRegister<S> deferredRegister = DeferredRegister.create(modid, registryKey);

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);

deferredRegister.register(new ResourceLocation(modid, field.getAnnotation(RegistryEntry.class).value()), () -> (S) value);
if (value instanceof BlockItem) {
Item.BY_BLOCK.put(((BlockItem) value).getBlock(), (Item) value);
}
} catch (IllegalAccessException e) {
throw new AssertionError(e);
} catch (ClassCastException e) {
//TODO: Make this print more concise details than a stacktrace
e.printStackTrace();
}
});
}
}
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
package org.dimdev.matrix;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

/**
* Specifies the namespace for registry entries.
*
* <p>This must be annotated on the class you wish
* to keep all your registry entries (as fields).</p>
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
public @interface Registrar {
Class<?> element();

String modid();
}
package org.dimdev.matrix;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

/**
* Specifies the namespace for registry entries.
*
* <p>This must be annotated on the class you wish
* to keep all your registry entries (as fields).</p>
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
public @interface Registrar {
Class<?> element();

String modid();
}
Loading

0 comments on commit f846bdc

Please sign in to comment.