From 8a03bbdb7f7cc93564d0357ee7b6a4e58099fc02 Mon Sep 17 00:00:00 2001 From: Jacob Farley Date: Sat, 25 Jul 2020 13:33:38 -0500 Subject: [PATCH] KubeJS support, 1x1 table fixes. --- build.gradle | 1 + gradle.properties | 3 +- .../io/github/alloffabric/artis/Artis.java | 10 +- .../github/alloffabric/artis/ArtisData.java | 28 +- .../artis/api/ContainerLayout.java | 13 +- .../artis/compat/kubejs/ArtisJsonBuilder.java | 174 ++++++++++ .../kubejs/ArtisJsonRegistryEventJS.java | 25 ++ .../kubejs/ArtisRecipeEventHandler.java | 297 ++++++++++++++++++ .../artis/compat/rei/ArtisCategory.java | 6 + .../inventory/ArtisCraftingController.java | 2 +- .../artis/util/BlockSettingsParser.java | 10 +- src/main/resources/fabric.mod.json | 3 + 12 files changed, 549 insertions(+), 23 deletions(-) create mode 100644 src/main/java/io/github/alloffabric/artis/compat/kubejs/ArtisJsonBuilder.java create mode 100644 src/main/java/io/github/alloffabric/artis/compat/kubejs/ArtisJsonRegistryEventJS.java create mode 100644 src/main/java/io/github/alloffabric/artis/compat/kubejs/ArtisRecipeEventHandler.java diff --git a/build.gradle b/build.gradle index 55fc1b5..8024f60 100755 --- a/build.gradle +++ b/build.gradle @@ -56,6 +56,7 @@ dependencies { modImplementation("me.shedaniel:RoughlyEnoughItems:${project.rei_version}") { exclude module: "ModMenu" } modImplementation "com.github.Siphalor:nbt-crafting:${project.nbtcrafting_version}" modImplementation "com.lettuce.fudge:artifice:${project.artifice_version}" + modImplementation "com.github.KubeJS-Mods:KubeJS-Fabric:${project.kubejs_version}" include "io.github.cottonmc:LibGui:${project.libgui_version}" include "io.github.cottonmc:StaticData:${project.static_data_version}" diff --git a/gradle.properties b/gradle.properties index f16333b..ebef282 100644 --- a/gradle.properties +++ b/gradle.properties @@ -9,13 +9,14 @@ loader_version=0.9.0+build.204 fabric_version=0.15.1+build.380-1.16.1 # Mod Properties -mod_version = 1.4.2 +mod_version = 1.4.3 maven_group = io.github.alloffabric archives_base_name = artis # Dependencies # currently not on the main fabric site, check on the maven: https://maven.fabricmc.net/net/fabricmc/fabric-api/fabric-api # libcd_version=2.5.0+1.16.1 +kubejs_version=master-SNAPSHOT libgui_version=2.2.0+1.16.1 static_data_version=1.1.2 rei_version=4.10.3 diff --git a/src/main/java/io/github/alloffabric/artis/Artis.java b/src/main/java/io/github/alloffabric/artis/Artis.java index 5f5d6d1..5cca7b0 100644 --- a/src/main/java/io/github/alloffabric/artis/Artis.java +++ b/src/main/java/io/github/alloffabric/artis/Artis.java @@ -1,6 +1,7 @@ package io.github.alloffabric.artis; import com.mojang.serialization.Lifecycle; +import dev.latvian.kubejs.script.ScriptType; import io.github.alloffabric.artis.api.ArtisExistingBlockType; import io.github.alloffabric.artis.api.ArtisExistingItemType; import io.github.alloffabric.artis.api.ArtisTableType; @@ -8,25 +9,23 @@ import io.github.alloffabric.artis.block.ArtisTableBlock; 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.event.ArtisEvents; import io.github.alloffabric.artis.inventory.ArtisCraftingController; import io.github.alloffabric.artis.util.ArtisRegistry; import net.fabricmc.api.ModInitializer; import net.fabricmc.fabric.api.client.itemgroup.FabricItemGroupBuilder; -import net.fabricmc.fabric.api.network.ClientSidePacketRegistry; import net.fabricmc.fabric.api.network.ServerSidePacketRegistry; import net.fabricmc.fabric.api.screenhandler.v1.ScreenHandlerRegistry; import net.fabricmc.fabric.impl.screenhandler.ExtendedScreenHandlerType; +import net.fabricmc.loader.api.FabricLoader; import net.minecraft.block.Block; import net.minecraft.block.entity.BlockEntity; import net.minecraft.block.entity.BlockEntityType; -import net.minecraft.client.MinecraftClient; -import net.minecraft.inventory.CraftingInventory; import net.minecraft.item.Item; import net.minecraft.item.ItemGroup; import net.minecraft.item.ItemStack; import net.minecraft.item.Items; -import net.minecraft.recipe.Recipe; import net.minecraft.screen.ScreenHandler; import net.minecraft.screen.ScreenHandlerContext; import net.minecraft.util.Identifier; @@ -85,6 +84,9 @@ private static BlockEntityType registerBlockEntity(St @Override public void onInitialize() { if (!isLoaded) { + if (FabricLoader.getInstance().isModLoaded("kubejs")) + new ArtisJsonRegistryEventJS().post(ScriptType.STARTUP, "artis.registry"); + ArtisData.loadData(); ArtisData.loadConfig(); ArtisEvents.init(); diff --git a/src/main/java/io/github/alloffabric/artis/ArtisData.java b/src/main/java/io/github/alloffabric/artis/ArtisData.java index fb9d318..e49b9d0 100644 --- a/src/main/java/io/github/alloffabric/artis/ArtisData.java +++ b/src/main/java/io/github/alloffabric/artis/ArtisData.java @@ -11,7 +11,7 @@ import io.github.cottonmc.jankson.JanksonFactory; import io.github.cottonmc.staticdata.StaticData; import io.github.cottonmc.staticdata.StaticDataItem; -import net.fabricmc.fabric.api.block.FabricBlockSettings; +import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; import net.fabricmc.loader.api.FabricLoader; import net.minecraft.block.Block; import net.minecraft.block.Blocks; @@ -60,6 +60,12 @@ public static void loadData() { } } + public static void loadData(JsonObject json) { + if (json != null) { + loadEntries("kubejs", json.containsKey("tables") ? json.getObject("tables") : json); + } + } + private static void loadEntries(String from, JsonObject json) { List keys = new ArrayList<>(json.keySet()); Collections.sort(keys); @@ -76,7 +82,7 @@ private static void loadEntries(String from, JsonObject json) { if (config.containsKey("settings")) { settings = BlockSettingsParser.parseSettings(config.getObject("settings")); } else { - settings = FabricBlockSettings.copy(Blocks.CRAFTING_TABLE).build(); + settings = FabricBlockSettings.copyOf(Blocks.CRAFTING_TABLE); } Artis.registerTable(type, settings); } @@ -89,13 +95,19 @@ static ArtisTableType getType(String key, JsonObject json) { String tableType = json.containsKey("type") ? json.get(String.class, "type") : "normal"; int width = json.getInt("width", 3); int height = json.getInt("height", 3); - if (width > 9) { - Artis.logger.error("[Artis] Table type named {} has too many columns, clamping it to 9", key); - width = 9; + if (width > 7) { + Artis.logger.warn("[Artis] Only tables up to 7 columns are supported. Anything higher may, and likely will, break visually.", key); + if (width > 9) { + Artis.logger.error("[Artis] Table type named {} has too many columns, clamping it to 9", key); + width = 9; + } } - if (height > 9) { - Artis.logger.error("[Artis] Table type named {} has too many rows, clamping it to 9", key); - height = 9; + if (height > 7) { + Artis.logger.warn("[Artis] Only tables up to 7 rows are supported. Anything higher may, and likely will, break visually.", key); + if (height > 9) { + Artis.logger.error("[Artis] Table type named {} has too many rows, clamping it to 9", key); + height = 9; + } } boolean blockEntity = json.getBoolean("block_entity", false); boolean catalystSlot = json.getInt("catalyst_slot", 0) != 0; diff --git a/src/main/java/io/github/alloffabric/artis/api/ContainerLayout.java b/src/main/java/io/github/alloffabric/artis/api/ContainerLayout.java index 923a556..1fb504b 100644 --- a/src/main/java/io/github/alloffabric/artis/api/ContainerLayout.java +++ b/src/main/java/io/github/alloffabric/artis/api/ContainerLayout.java @@ -19,12 +19,12 @@ public class ContainerLayout { private int arrowX; private final int arrowY; private final int playerX; - private final int playerY; + private int playerY; - public ContainerLayout(int gridColumns, int gridRows) { + public ContainerLayout(int gridColumns, int gridRows, boolean hasCatalyst) { this.gridWidth = gridColumns * 18; this.catalystX = gridWidth + 10; - this.resultX = catalystX + 18 + 14; + this.resultX = catalystX + 18 + 10; this.arrowX = catalystX - 3; this.craftingWidth = resultX + 22; @@ -33,7 +33,7 @@ public ContainerLayout(int gridColumns, int gridRows) { this.arrowY = midpoint + 4; this.catalystY = arrowY + 21; this.resultY = midpoint + 4; - this.craftingHeight = Math.max(35, gridHeight); + this.craftingHeight = Math.max(25, gridHeight); this.gridY = 16; this.gridX = craftingWidth > playerWidth ? 0 : ((playerWidth - craftingWidth) / 2) + 2; @@ -43,6 +43,11 @@ public ContainerLayout(int gridColumns, int gridRows) { this.playerX = playerWidth > craftingWidth ? 0 : ((craftingWidth - playerWidth) / 2) + 2; this.playerY = gridY + Math.max(48, gridHeight + 10); + if (!hasCatalyst && gridRows == 1) { + this.playerY -= 18; + } else if (hasCatalyst && gridRows == 1) { + this.playerY -= 8; + } } public int getGridX() { 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 new file mode 100644 index 0000000..a4fc270 --- /dev/null +++ b/src/main/java/io/github/alloffabric/artis/compat/kubejs/ArtisJsonBuilder.java @@ -0,0 +1,174 @@ +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 { + public JsonObject root; + public JsonObject tables; + public JsonObject table; + public JsonObject settings; + + public ArtisJsonBuilder(String i) { + super(i); + root = new JsonObject(); + tables = new JsonObject(); + table = new JsonObject(); + settings = new JsonObject(); + root.add("tables", tables); + tables.add(KubeJS.appendModId(i), table); + table.add("settings", settings); + } + + public ArtisJsonBuilder(String modId, String name) { + super(name); + root = new JsonObject(); + tables = new JsonObject(); + table = new JsonObject(); + settings = new JsonObject(); + root.add("tables", tables); + tables.add(new Identifier(modId, name).toString(), table); + table.add("settings", settings); + } + + public ArtisJsonBuilder setType(String type) { + table.addProperty("type", type); + return this; + } + + public ArtisJsonBuilder dimensions(int width, int height) { + table.addProperty("width", width); + table.addProperty("height", height); + return this; + } + + public ArtisJsonBuilder generateAssets() { + table.addProperty("generate_assets", true); + return this; + } + + public ArtisJsonBuilder color(String color) { + table.addProperty("color", color); + return this; + } + + public ArtisJsonBuilder blockEntity() { + table.addProperty("block_entity", true); + return this; + } + + public ArtisJsonBuilder catalystSlots(int amount) { + table.addProperty("catalyst_slot", amount); + return this; + } + + public ArtisJsonBuilder normalRecipes() { + table.addProperty("normal_recipes", true); + return this; + } + + public ArtisJsonBuilder bypassCheck() { + table.addProperty("bypass_check", true); + return this; + } + + public ArtisJsonBuilder copy(String original) { + settings.addProperty("copy", original); + return this; + } + + public ArtisJsonBuilder material(String material) { + settings.addProperty("material", material); + return this; + } + + public ArtisJsonBuilder materialColor(String material) { + settings.addProperty("material_color", material); + return this; + } + + public ArtisJsonBuilder collidable(boolean value) { + settings.addProperty("collidable", value); + return this; + } + + public ArtisJsonBuilder breakByHand(boolean value) { + settings.addProperty("break_by_hand", value); + return this; + } + + // Currently no breakByTool, will add later + + public ArtisJsonBuilder nonOpaque() { + settings.addProperty("non_opaque", true); + 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; + } + + public ArtisJsonBuilder hardness(float hardness) { + settings.addProperty("hardness", hardness); + return this; + } + + public ArtisJsonBuilder resistance(float resistance) { + settings.addProperty("resistance", resistance); + return this; + } + + public ArtisJsonBuilder slipperiness(float slipperiness) { + settings.addProperty("slipperiness", slipperiness); + return this; + } + + public ArtisJsonBuilder breakInstantly() { + settings.addProperty("break_instantly", true); + return this; + } + + public ArtisJsonBuilder dropsNothing() { + settings.addProperty("drops_nothing", true); + return this; + } + + public ArtisJsonBuilder dropsLike(String value) { + settings.addProperty("drops_like", value); + return this; + } + + public ArtisJsonBuilder drops(String value) { + settings.addProperty("drops", value); + return this; + } + + public ArtisJsonBuilder dynamicBounds() { + settings.addProperty("dynamic_bounds", true); + 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 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 new file mode 100644 index 0000000..db97f68 --- /dev/null +++ b/src/main/java/io/github/alloffabric/artis/compat/kubejs/ArtisJsonRegistryEventJS.java @@ -0,0 +1,25 @@ +package io.github.alloffabric.artis.compat.kubejs; + +import dev.latvian.kubejs.event.EventJS; + +/** + * @author LatvianModder + */ +public class ArtisJsonRegistryEventJS extends EventJS { + public ArtisJsonBuilder create(String name) { + ArtisJsonBuilder builder = new ArtisJsonBuilder(name); + return builder; + } + + public ArtisJsonBuilder createExistingBlock(String modId, String name) { + ArtisJsonBuilder builder = new ArtisJsonBuilder(modId, name); + builder = builder.setType("existing_block"); + return builder; + } + + public ArtisJsonBuilder createExistingItem(String modId, String name) { + ArtisJsonBuilder builder = new ArtisJsonBuilder(modId, name); + builder = builder.setType("existing_item"); + 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/ArtisRecipeEventHandler.java new file mode 100644 index 0000000..c039541 --- /dev/null +++ b/src/main/java/io/github/alloffabric/artis/compat/kubejs/ArtisRecipeEventHandler.java @@ -0,0 +1,297 @@ +package io.github.alloffabric.artis.compat.kubejs; + +import com.google.gson.JsonArray; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import dev.latvian.kubejs.KubeJSInitializer; +import dev.latvian.kubejs.item.EmptyItemStackJS; +import dev.latvian.kubejs.item.ItemStackJS; +import dev.latvian.kubejs.item.ingredient.IngredientJS; +import dev.latvian.kubejs.recipe.RecipeExceptionJS; +import dev.latvian.kubejs.recipe.RecipeJS; +import dev.latvian.kubejs.recipe.RecipeTypeJS; +import dev.latvian.kubejs.recipe.RegisterRecipeHandlersEvent; +import dev.latvian.kubejs.util.ListJS; +import dev.latvian.kubejs.util.MapJS; +import io.github.alloffabric.artis.Artis; +import io.github.alloffabric.artis.api.ArtisTableType; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +public class ArtisRecipeEventHandler implements KubeJSInitializer { + @Override + public void onKubeJSInitialization() { + RegisterRecipeHandlersEvent.EVENT.register(event -> { + for (ArtisTableType tableType : Artis.ARTIS_TABLE_TYPES) { + event.register(new RecipeTypeJS(tableType.getShaped(), ArtisShapedRecipeJS::new)); + event.register(new RecipeTypeJS(tableType.getShapeless(), ArtisShapelessRecipeJS::new)); + } + }); + } + + public class ArtisShapedRecipeJS extends RecipeJS { + private final List pattern = new ArrayList<>(); + private final List key = new ArrayList<>(); + public IngredientJS catalystItem = EmptyItemStackJS.INSTANCE; + public int cost = 1; + + @Override + public void create(ListJS args) { + if (args.size() < 3) { + if (args.size() < 2) { + throw new RecipeExceptionJS("Shaped recipe requires 3 arguments - result, pattern and keys!"); + } + // simple define + ItemStackJS result = ItemStackJS.of(args.get(0)); + if (result.isEmpty()) { + throw new RecipeExceptionJS("Shaped recipe result " + args.get(0) + " is not a valid item!"); + } + outputItems.add(result); + ListJS vertical = ListJS.orSelf(args.get(1)); + if (vertical.isEmpty()) { + throw new RecipeExceptionJS("Shaped recipe pattern is empty!"); + } + int id = 0; + for (Object o : vertical) { + StringBuilder horizontalPattern = new StringBuilder(); + ListJS horizontal = ListJS.orSelf(o); + for (Object item : horizontal) { + IngredientJS ingredient = IngredientJS.of(item); + + if (!ingredient.isEmpty()) { + String currentId = String.valueOf(id++); + horizontalPattern.append(currentId); + inputItems.add(ingredient); + key.add(currentId); + } else { + horizontalPattern.append(" "); + } + } + pattern.add(horizontalPattern.toString()); + } + return; + } + + ItemStackJS result = ItemStackJS.of(args.get(0)); + + if (result.isEmpty()) { + throw new RecipeExceptionJS("Shaped recipe result " + args.get(0) + " is not a valid item!"); + } + + outputItems.add(result); + + ListJS pattern1 = ListJS.orSelf(args.get(1)); + + if (pattern1.isEmpty()) { + throw new RecipeExceptionJS("Shaped recipe pattern is empty!"); + } + + for (Object p : pattern1) { + pattern.add(String.valueOf(p)); + } + + MapJS key1 = MapJS.of(args.get(2)); + + if (key1 == null || key1.isEmpty()) { + throw new RecipeExceptionJS("Shaped recipe key map is empty!"); + } + + for (String k : key1.keySet()) { + IngredientJS i = IngredientJS.of(key1.get(k)); + + if (!i.isEmpty()) { + inputItems.add(i); + key.add(k); + } else { + throw new RecipeExceptionJS("Shaped recipe ingredient " + key1.get(k) + " with key '" + k + "' is not a valid ingredient!"); + } + } + + if (args.size() > 3) { + IngredientJS catalyst = IngredientJS.of(args.get(3)); + + if (!catalyst.isEmpty()) { + catalystItem = catalyst; + } + } + + if (args.size() > 4 && args.get(4) instanceof Integer) { + cost = (Integer) args.get(4); + } + } + + @Override + public void deserialize() { + ItemStackJS result = ItemStackJS.resultFromRecipeJson(json.get("result")); + + if (result.isEmpty()) { + throw new RecipeExceptionJS("Shaped recipe result " + json.get("result") + " is not a valid item!"); + } + + outputItems.add(result); + + for (JsonElement e : json.get("pattern").getAsJsonArray()) { + pattern.add(e.getAsString()); + } + + if (pattern.isEmpty()) { + throw new RecipeExceptionJS("Shaped recipe pattern is empty!"); + } + + for (Map.Entry entry : json.get("key").getAsJsonObject().entrySet()) { + IngredientJS i = IngredientJS.ingredientFromRecipeJson(entry.getValue()); + + if (!i.isEmpty()) { + inputItems.add(i); + key.add(entry.getKey()); + } else { + throw new RecipeExceptionJS("Shaped recipe ingredient " + entry.getValue() + " with key '" + entry.getKey() + "' is not a valid ingredient!"); + } + } + + if (key.isEmpty()) { + throw new RecipeExceptionJS("Shaped recipe key map is empty!"); + } + + IngredientJS catalyst = IngredientJS.ingredientFromRecipeJson(json.get("catalyst")); + + if (!catalyst.equals(EmptyItemStackJS.INSTANCE) && !catalyst.isEmpty()) { + catalystItem = catalyst; + } + + if (!json.get("cost").isJsonNull()) { + cost = json.get("cost").getAsInt(); + } + } + + @Override + public void serialize() { + JsonArray patternJson = new JsonArray(); + + for (String s : pattern) { + patternJson.add(s); + } + + json.add("pattern", patternJson); + + JsonObject keyJson = new JsonObject(); + + for (int i = 0; i < key.size(); i++) { + keyJson.add(key.get(i), inputItems.get(i).toJson()); + } + + json.add("key", keyJson); + json.add("result", outputItems.get(0).toResultJson()); + if (!catalystItem.equals(EmptyItemStackJS.INSTANCE)) + json.add("catalyst", catalystItem.toJson()); + json.addProperty("cost", cost); + } + } + + public class ArtisShapelessRecipeJS extends RecipeJS { + public IngredientJS catalystItem = EmptyItemStackJS.INSTANCE; + public int cost = 0; + + public final boolean hasCatalyst(IngredientJS ingredient, boolean exact) { + if (exact ? catalystItem.equals(ingredient) : catalystItem.anyStackMatches(ingredient)) { + return true; + } + return false; + } + + @Override + public void create(ListJS args) { + ItemStackJS result = ItemStackJS.of(args.get(0)); + + if (result.isEmpty()) { + throw new RecipeExceptionJS("Shapeless recipe result " + args.get(0) + " is not a valid item!"); + } + + outputItems.add(result); + + ListJS ingredients1 = ListJS.orSelf(args.get(1)); + + if (ingredients1.isEmpty()) { + throw new RecipeExceptionJS("Shapeless recipe ingredient list is empty!"); + } + + for (Object o : ingredients1) { + IngredientJS in = IngredientJS.of(o); + + if (!in.isEmpty()) { + inputItems.add(in); + } else { + throw new RecipeExceptionJS("Shapeless recipe ingredient " + o + " is not a valid ingredient!"); + } + } + + if (inputItems.isEmpty()) { + throw new RecipeExceptionJS("Shapeless recipe ingredient list is empty!"); + } + + if (args.size() > 2) { + IngredientJS catalyst = IngredientJS.of(args.get(2)); + + if (!catalyst.isEmpty()) { + catalystItem = catalyst; + } + } + + if (args.size() > 3 && args.get(3) instanceof Integer) { + cost = (Integer) args.get(3); + } + } + + @Override + public void deserialize() { + ItemStackJS result = ItemStackJS.resultFromRecipeJson(json.get("result")); + + if (result.isEmpty()) { + throw new RecipeExceptionJS("Shapeless recipe result " + json.get("result") + " is not a valid item!"); + } + + outputItems.add(result); + + for (JsonElement e : json.get("ingredients").getAsJsonArray()) { + IngredientJS in = IngredientJS.ingredientFromRecipeJson(e); + + if (!in.isEmpty()) { + inputItems.add(in); + } else { + throw new RecipeExceptionJS("Shapeless recipe ingredient " + e + " is not a valid ingredient!"); + } + } + + if (inputItems.isEmpty()) { + throw new RecipeExceptionJS("Shapeless recipe ingredient list is empty!"); + } + + IngredientJS catalyst = IngredientJS.ingredientFromRecipeJson(json.get("catalyst")); + + if (!catalyst.equals(EmptyItemStackJS.INSTANCE) && !catalyst.isEmpty()) { + catalystItem = catalyst; + } + + if (!json.get("cost").isJsonNull()) { + cost = json.get("cost").getAsInt(); + } + } + + @Override + public void serialize() { + JsonArray ingredientsJson = new JsonArray(); + + for (IngredientJS in : inputItems) { + ingredientsJson.add(in.toJson()); + } + + json.add("ingredients", ingredientsJson); + json.add("result", outputItems.get(0).toResultJson()); + if (!catalystItem.equals(EmptyItemStackJS.INSTANCE)) + json.add("catalyst", catalystItem.toJson()); + json.addProperty("cost", cost); + } + } +} diff --git a/src/main/java/io/github/alloffabric/artis/compat/rei/ArtisCategory.java b/src/main/java/io/github/alloffabric/artis/compat/rei/ArtisCategory.java index 4622a96..2d4b108 100644 --- a/src/main/java/io/github/alloffabric/artis/compat/rei/ArtisCategory.java +++ b/src/main/java/io/github/alloffabric/artis/compat/rei/ArtisCategory.java @@ -1,6 +1,7 @@ package io.github.alloffabric.artis.compat.rei; import com.google.common.collect.Lists; +import io.github.alloffabric.artis.Artis; import io.github.alloffabric.artis.api.ArtisTableType; import io.github.alloffabric.artis.api.RecipeProvider; import it.unimi.dsi.fastutil.ints.IntList; @@ -65,6 +66,11 @@ public EntryStack getLogo() { public List setupDisplay(ArtisDisplay recipeDisplay, Rectangle bounds) { Point startPoint = new Point(bounds.getCenterX() - (getDisplayWidth(recipeDisplay) / 2) + 17, bounds.getCenterY() - (getDisplayHeight() / 2) + 15); + Artis.logger.info(this::getDisplayHeight); + if (artisTableType.hasCatalystSlot() && artisTableType.getHeight() == 1) { + bounds.setSize(bounds.width, bounds.height + 18); + } + List widgets = new LinkedList(Arrays.asList(Widgets.createRecipeBase(bounds))); if (artisTableType.hasColor()) { widgets = new LinkedList(Arrays.asList(Widgets.createRecipeBase(bounds).color(artisTableType.getColor(), artisTableType.getColor()))); diff --git a/src/main/java/io/github/alloffabric/artis/inventory/ArtisCraftingController.java b/src/main/java/io/github/alloffabric/artis/inventory/ArtisCraftingController.java index e7659be..ce2a61c 100644 --- a/src/main/java/io/github/alloffabric/artis/inventory/ArtisCraftingController.java +++ b/src/main/java/io/github/alloffabric/artis/inventory/ArtisCraftingController.java @@ -63,7 +63,7 @@ public ArtisCraftingController(ScreenHandlerType type, ArtisTableType tableType, craftInv.setStack(i, blockInventory.getStack(i)); } } - ContainerLayout layout = new ContainerLayout(tableType.getWidth(), tableType.getHeight()); + ContainerLayout layout = new ContainerLayout(tableType.getWidth(), tableType.getHeight(), tableType.hasCatalystSlot()); panel = new WPlainPanel(); setRootPanel(panel); diff --git a/src/main/java/io/github/alloffabric/artis/util/BlockSettingsParser.java b/src/main/java/io/github/alloffabric/artis/util/BlockSettingsParser.java index cd2eeda..5ca9bc5 100644 --- a/src/main/java/io/github/alloffabric/artis/util/BlockSettingsParser.java +++ b/src/main/java/io/github/alloffabric/artis/util/BlockSettingsParser.java @@ -2,7 +2,7 @@ import blue.endless.jankson.JsonObject; import io.github.alloffabric.artis.Artis; -import net.fabricmc.fabric.api.block.FabricBlockSettings; +import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; import net.minecraft.block.Block; import net.minecraft.block.Blocks; import net.minecraft.block.Material; @@ -146,17 +146,17 @@ public class BlockSettingsParser { public static Block.Settings parseSettings(JsonObject json) { if (json == null) { Artis.logger.error("[Artis] Cannot parse block settings that aren't a json object!"); - return FabricBlockSettings.copy(Blocks.CRAFTING_TABLE).build(); + return FabricBlockSettings.copyOf(Blocks.CRAFTING_TABLE); } FabricBlockSettings settings; if (json.containsKey("copy")) { String copyTarg = json.get(String.class, "copy"); - settings = FabricBlockSettings.copy(Registry.BLOCK.get(new Identifier(copyTarg))); + settings = FabricBlockSettings.copyOf(Registry.BLOCK.get(new Identifier(copyTarg))); } else if (json.containsKey("material")) { String matTarg = json.get(String.class, "material"); settings = FabricBlockSettings.of(MATERIALS.get(matTarg)); } else { - settings = FabricBlockSettings.copy(Blocks.CRAFTING_TABLE); + settings = FabricBlockSettings.copyOf(Blocks.CRAFTING_TABLE); } if (json.containsKey("break_by_hand")) { @@ -223,6 +223,6 @@ public static Block.Settings parseSettings(JsonObject json) { settings.dynamicBounds(); } - return settings.build(); + return settings; } } diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index fd2604d..4776df9 100755 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -26,6 +26,9 @@ ], "libcd": [ "io.github.alloffabric.artis.compat.libcd.ArtisLibCDPlugin" + ], + "kubejs-init": [ + "io.github.alloffabric.artis.compat.kubejs.ArtisRecipeEventHandler" ] }, "mixins": [