diff --git a/buildSrc/build.gradle b/buildSrc/build.gradle
index 438afc2..bdf5af2 100644
--- a/buildSrc/build.gradle
+++ b/buildSrc/build.gradle
@@ -24,7 +24,7 @@ gradlePlugin {
plugins {
create("block-and-item-code-generator") {
id = "de.griefed.generation.block-and-item-code-generator"
- implementationClass = "de.griefed.generation.BlockAndItemCodeGenerator"
+ implementationClass = "de.griefed.generation.BlockAndItemCodeGeneratorPlugin"
}
}
}
diff --git a/buildSrc/src/main/java/de/griefed/generation/BlockAndItemCodeGeneratorPlugin.java b/buildSrc/src/main/java/de/griefed/generation/BlockAndItemCodeGeneratorPlugin.java
new file mode 100644
index 0000000..d546b3f
--- /dev/null
+++ b/buildSrc/src/main/java/de/griefed/generation/BlockAndItemCodeGeneratorPlugin.java
@@ -0,0 +1,16 @@
+package de.griefed.generation;
+
+import org.gradle.api.Plugin;
+import org.gradle.api.Project;
+
+/**
+ * Generates Forge, Fabric and Quilt block-implementations from block-definitions in a JSON-file.
+ * See definitions/blocks.json
+ * Take note that textures for blocks must be present in definitions/blocks
and the name of the textures
+ * must match the ID of the block.
+ */
+public class BlockAndItemCodeGeneratorPlugin implements Plugin {
+ public void apply(Project project) {
+ project.getTasks().register("blockAndItemCodeGen", GenerateBlocksAndItemsCode.class);
+ }
+}
diff --git a/buildSrc/src/main/java/de/griefed/generation/BlockAndItemCodeGenerator.java b/buildSrc/src/main/java/de/griefed/generation/GenerateBlocksAndItemsCode.java
similarity index 59%
rename from buildSrc/src/main/java/de/griefed/generation/BlockAndItemCodeGenerator.java
rename to buildSrc/src/main/java/de/griefed/generation/GenerateBlocksAndItemsCode.java
index 64578bc..d591bdb 100644
--- a/buildSrc/src/main/java/de/griefed/generation/BlockAndItemCodeGenerator.java
+++ b/buildSrc/src/main/java/de/griefed/generation/GenerateBlocksAndItemsCode.java
@@ -5,35 +5,31 @@
import com.fasterxml.jackson.databind.ObjectMapper;
import de.griefed.generation.blocks.BlockDefinitionParser;
import de.griefed.generation.generator.CommonSubProjectGenerator;
-import org.gradle.api.Plugin;
+import org.gradle.api.DefaultTask;
import org.gradle.api.Project;
+import org.gradle.api.tasks.TaskAction;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Properties;
-/**
- * Generates Forge, Fabric and Quilt block-implementations from block-definitions in a JSON-file.
- * See definitions/blocks.json
- * Take note that textures for blocks must be present in definitions/blocks
and the name of the textures
- * must match the ID of the block.
- */
-public class BlockAndItemCodeGenerator implements Plugin {
+public class GenerateBlocksAndItemsCode extends DefaultTask {
+
private final ObjectMapper objectMapper = new ObjectMapper()
.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES)
.enable(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY)
.enable(JsonReadFeature.ALLOW_UNESCAPED_CONTROL_CHARS.mappedFeature());
- public void apply(Project project) {
- project.getTasks().register("blockAndItemCodeGen", task -> task.doLast(s -> System.out.println("Hello from plugin " + this.getClass().getName())));
+ @TaskAction
+ public void generateCode() {
try {
Properties gradleProperties = new Properties();
- gradleProperties.load(new FileInputStream(new File(project.getRootDir(), "gradle.properties")));
+ gradleProperties.load(new FileInputStream(new File(getProject().getRootDir(), "gradle.properties")));
String modName = gradleProperties.getProperty("mod_name");
- BlockDefinitionParser parser = new BlockDefinitionParser(project, objectMapper);
- CommonSubProjectGenerator common = new CommonSubProjectGenerator(project.findProject("Common"), modName, parser, objectMapper);
+ BlockDefinitionParser parser = new BlockDefinitionParser(getProject(), objectMapper);
+ CommonSubProjectGenerator common = new CommonSubProjectGenerator(getProject().findProject("Common"), modName, parser, objectMapper);
common.run();
} catch (IOException e) {
throw new RuntimeException("Error generating block and item code.", e);