From aad8d966da874b44613f25567aa580b714cff05d Mon Sep 17 00:00:00 2001 From: Jacob Farley Date: Sat, 25 Jul 2020 14:51:51 -0500 Subject: [PATCH] No more .build, hello automatic building. --- .../io/github/alloffabric/artis/Artis.java | 6 +++- .../artis/compat/kubejs/ArtisJsonBuilder.java | 29 +++++++++---------- .../kubejs/ArtisJsonRegistryEventJS.java | 3 ++ ...cipeEventHandler.java => ArtisKubeJS.java} | 17 ++++++++++- src/main/resources/fabric.mod.json | 2 +- 5 files changed, 38 insertions(+), 19 deletions(-) rename src/main/java/io/github/alloffabric/artis/compat/kubejs/{ArtisRecipeEventHandler.java => ArtisKubeJS.java} (93%) diff --git a/src/main/java/io/github/alloffabric/artis/Artis.java b/src/main/java/io/github/alloffabric/artis/Artis.java index 5cca7b0..7d39231 100644 --- a/src/main/java/io/github/alloffabric/artis/Artis.java +++ b/src/main/java/io/github/alloffabric/artis/Artis.java @@ -10,6 +10,7 @@ import io.github.alloffabric.artis.block.ArtisTableItem; import io.github.alloffabric.artis.block.entity.ArtisTableBlockEntity; import io.github.alloffabric.artis.compat.kubejs.ArtisJsonRegistryEventJS; +import io.github.alloffabric.artis.compat.kubejs.ArtisKubeJS; import io.github.alloffabric.artis.event.ArtisEvents; import io.github.alloffabric.artis.inventory.ArtisCraftingController; import io.github.alloffabric.artis.util.ArtisRegistry; @@ -84,9 +85,12 @@ private static BlockEntityType registerBlockEntity(St @Override public void onInitialize() { if (!isLoaded) { - if (FabricLoader.getInstance().isModLoaded("kubejs")) + if (FabricLoader.getInstance().isModLoaded("kubejs")) { new ArtisJsonRegistryEventJS().post(ScriptType.STARTUP, "artis.registry"); + ArtisKubeJS.initTables(); + } + ArtisData.loadData(); ArtisData.loadConfig(); ArtisEvents.init(); diff --git a/src/main/java/io/github/alloffabric/artis/compat/kubejs/ArtisJsonBuilder.java b/src/main/java/io/github/alloffabric/artis/compat/kubejs/ArtisJsonBuilder.java index a4fc270..71cdf56 100644 --- a/src/main/java/io/github/alloffabric/artis/compat/kubejs/ArtisJsonBuilder.java +++ b/src/main/java/io/github/alloffabric/artis/compat/kubejs/ArtisJsonBuilder.java @@ -1,11 +1,8 @@ package io.github.alloffabric.artis.compat.kubejs; -import blue.endless.jankson.api.SyntaxError; import com.google.gson.JsonObject; import dev.latvian.kubejs.KubeJS; import dev.latvian.kubejs.util.BuilderBase; -import io.github.alloffabric.artis.Artis; -import io.github.alloffabric.artis.ArtisData; import net.minecraft.util.Identifier; public class ArtisJsonBuilder extends BuilderBase { @@ -92,6 +89,11 @@ public ArtisJsonBuilder materialColor(String material) { return this; } + public ArtisJsonBuilder sounds(String sounds) { + settings.addProperty("sounds", sounds); + return this; + } + public ArtisJsonBuilder collidable(boolean value) { settings.addProperty("collidable", value); return this; @@ -109,11 +111,6 @@ public ArtisJsonBuilder nonOpaque() { return this; } - public ArtisJsonBuilder sounds(String sounds) { - settings.addProperty("sounds", sounds); - return this; - } - public ArtisJsonBuilder lightLevel(int level) { settings.addProperty("light_level", level); return this; @@ -159,14 +156,14 @@ public ArtisJsonBuilder dynamicBounds() { return this; } - public void build() { - try { - ArtisData.loadData(ArtisData.jankson.load(root.toString())); - Artis.logger.info(root.toString()); - } catch (SyntaxError syntaxError) { - Artis.logger.error("[Artis] Error converting JSON for KubeJS. Is JSON empty?"); - } - } +// public void build() { +// try { +// ArtisData.loadData(ArtisData.jankson.load(root.toString())); +// Artis.logger.info(root.toString()); +// } catch (SyntaxError syntaxError) { +// Artis.logger.error("[Artis] Error converting JSON for KubeJS. Is JSON empty?"); +// } +// } public String getType() { return "block"; diff --git a/src/main/java/io/github/alloffabric/artis/compat/kubejs/ArtisJsonRegistryEventJS.java b/src/main/java/io/github/alloffabric/artis/compat/kubejs/ArtisJsonRegistryEventJS.java index db97f68..08952cc 100644 --- a/src/main/java/io/github/alloffabric/artis/compat/kubejs/ArtisJsonRegistryEventJS.java +++ b/src/main/java/io/github/alloffabric/artis/compat/kubejs/ArtisJsonRegistryEventJS.java @@ -8,18 +8,21 @@ public class ArtisJsonRegistryEventJS extends EventJS { public ArtisJsonBuilder create(String name) { ArtisJsonBuilder builder = new ArtisJsonBuilder(name); + ArtisKubeJS.ARTIS_JSON_BUILDERS.add(builder); return builder; } public ArtisJsonBuilder createExistingBlock(String modId, String name) { ArtisJsonBuilder builder = new ArtisJsonBuilder(modId, name); builder = builder.setType("existing_block"); + ArtisKubeJS.ARTIS_JSON_BUILDERS.add(builder); return builder; } public ArtisJsonBuilder createExistingItem(String modId, String name) { ArtisJsonBuilder builder = new ArtisJsonBuilder(modId, name); builder = builder.setType("existing_item"); + ArtisKubeJS.ARTIS_JSON_BUILDERS.add(builder); return builder; } } \ No newline at end of file diff --git a/src/main/java/io/github/alloffabric/artis/compat/kubejs/ArtisRecipeEventHandler.java b/src/main/java/io/github/alloffabric/artis/compat/kubejs/ArtisKubeJS.java similarity index 93% rename from src/main/java/io/github/alloffabric/artis/compat/kubejs/ArtisRecipeEventHandler.java rename to src/main/java/io/github/alloffabric/artis/compat/kubejs/ArtisKubeJS.java index c039541..cc8a481 100644 --- a/src/main/java/io/github/alloffabric/artis/compat/kubejs/ArtisRecipeEventHandler.java +++ b/src/main/java/io/github/alloffabric/artis/compat/kubejs/ArtisKubeJS.java @@ -1,5 +1,6 @@ package io.github.alloffabric.artis.compat.kubejs; +import blue.endless.jankson.api.SyntaxError; import com.google.gson.JsonArray; import com.google.gson.JsonElement; import com.google.gson.JsonObject; @@ -14,13 +15,27 @@ import dev.latvian.kubejs.util.ListJS; import dev.latvian.kubejs.util.MapJS; import io.github.alloffabric.artis.Artis; +import io.github.alloffabric.artis.ArtisData; import io.github.alloffabric.artis.api.ArtisTableType; import java.util.ArrayList; import java.util.List; import java.util.Map; -public class ArtisRecipeEventHandler implements KubeJSInitializer { +public class ArtisKubeJS implements KubeJSInitializer { + public static final ArrayList ARTIS_JSON_BUILDERS = new ArrayList<>(); + + public static void initTables() { + for (ArtisJsonBuilder artisJsonBuilder : ARTIS_JSON_BUILDERS) { + try { + ArtisData.loadData(ArtisData.jankson.load(artisJsonBuilder.root.toString())); + Artis.logger.info(artisJsonBuilder.root.toString()); + } catch (SyntaxError syntaxError) { + Artis.logger.error("[Artis] Error converting JSON for KubeJS. Is JSON empty?"); + } + } + } + @Override public void onKubeJSInitialization() { RegisterRecipeHandlersEvent.EVENT.register(event -> { diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index 4776df9..de4e568 100755 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -28,7 +28,7 @@ "io.github.alloffabric.artis.compat.libcd.ArtisLibCDPlugin" ], "kubejs-init": [ - "io.github.alloffabric.artis.compat.kubejs.ArtisRecipeEventHandler" + "io.github.alloffabric.artis.compat.kubejs.ArtisKubeJS" ] }, "mixins": [