Skip to content

Commit

Permalink
No more .build, hello automatic building.
Browse files Browse the repository at this point in the history
  • Loading branch information
MariaTheDinkus committed Jul 25, 2020
1 parent 853190e commit aad8d96
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 19 deletions.
6 changes: 5 additions & 1 deletion src/main/java/io/github/alloffabric/artis/Artis.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -84,9 +85,12 @@ private static <B extends BlockEntity> BlockEntityType<B> 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();
Expand Down
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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<ArtisJsonBuilder> 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 -> {
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand Down

0 comments on commit aad8d96

Please sign in to comment.