Skip to content

Commit

Permalink
Added AE2 inscriber schema
Browse files Browse the repository at this point in the history
  • Loading branch information
pietro-lopes committed Dec 19, 2023
1 parent f145f7d commit a3fbcca
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 10 deletions.
2 changes: 2 additions & 0 deletions kubejs/startup_scripts/constants_startup.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@ const $EventActor = Java.loadClass("dev.architectury.event.EventActor")
const $CustomClickEvent = Java.loadClass("dev.ftb.mods.ftblibrary.ui.CustomClickEvent").EVENT
const $EventResult = Java.loadClass("dev.architectury.event.EventResult")
const $UtilsJS = Java.loadClass("dev.latvian.mods.kubejs.util.UtilsJS")
/** @type {Internal.Stream} */
const $Stream = Java.loadClass("java.util.stream.Stream")
1 change: 1 addition & 0 deletions kubejs/startup_scripts/main_startup.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,5 @@ StartupEvents.recipeSchemaRegistry((event) => {
registerWoodencogFillingSchema(event)
registerCreateMixingSchema(event)
registerAe2ChargerSchema(event)
registerAe2InscriberSchema(event)
})
20 changes: 13 additions & 7 deletions kubejs/startup_scripts/schemas/ae2/charger.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
// priority 100

let registerAe2ChargerSchema = (/** @type {Internal.RecipeSchemaRegistryEventJS} */ event) => {
const keys = global.schemas.keys
const chargerSchema = new $RecipeSchema(
keys.ingredient,
keys.result
)
event.namespace("ae2").register("charger", chargerSchema)
}
const keys = global.schemas.keys
const chargerSchema = new $RecipeSchema(keys.result, keys.ingredient)
event.namespace("ae2").register("charger", chargerSchema)
}

/*
Tests used:
ae2.charger("gtceu:netherrack_plutonium_ore", "#create:sandpaper")
.id("gregitas:charger/test/0")
*/
23 changes: 23 additions & 0 deletions kubejs/startup_scripts/schemas/ae2/inscriber.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// priority 100

let registerAe2InscriberSchema = (/** @type {Internal.RecipeSchemaRegistryEventJS} */ event) => {
const keys = global.schemas.keys
const inscriberSchema = new $RecipeSchema(keys.result, keys.inscriber_ingredients, keys.inscriber_mode)
.constructor(breakdownInput, keys.result, keys.inscriber_middle)
.constructor(breakdownInput, keys.result, keys.inscriber_middle, keys.inscriber_top)
.constructor(breakdownInput, keys.result, keys.inscriber_middle, keys.inscriber_top, keys.inscriber_bottom)
event.namespace("ae2").register("inscriber", inscriberSchema)
}

/*
Tests used:
ae2.inscriber("acacia_boat", "#ae2:all_certus_quartz")
.id("gregitas:inscriber/test/0")
ae2.inscriber("oak_boat", "minecraft:stone", "minecraft:apple").mode("inscribe")
.id("gregitas:inscriber/test/1")
ae2.inscriber("dark_oak_boat", "minecraft:carrot", "minecraft:beef", "minecraft:cooked_rabbit").mode("press")
.id("gregitas:inscriber/test/2")
*/
10 changes: 8 additions & 2 deletions kubejs/startup_scripts/schemas/components.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,6 @@ let loadComponents = (/** @type {Internal.RecipeSchemaRegistryEventJS} */ event)
.key("modifiers")
.defaultOptional()
keys.stack = Component("outputItem").key("stack").defaultOptional()
keys.ingredient = Component("inputItem").key("ingredient")
keys.result = Component("outputItem").key("result")

comps.item_stack_provider = Component("outputItem").or(builder(keys.stack, keys.modifiers).outputRole())
keys.result_item = comps.item_stack_provider.key("result_item").defaultOptional().preferred("resultItem").allowEmpty()
Expand Down Expand Up @@ -110,4 +108,12 @@ let loadComponents = (/** @type {Internal.RecipeSchemaRegistryEventJS} */ event)
keys.heat_requirement = new $EnumComponent($HeatCondition).key("heatRequirement").defaultOptional()
comps.create_fluid_ingredient = builder(comps.fluid_tag.key("fluidTag"), keys.fluid_amount)
keys.fluid_or_item_input_array = comps.create_fluid_ingredient.or(Component("inputFluid").or(Component("inputItem"))).asArray().key("ingredients")

keys.ingredient = Component("inputItem").key("ingredient")
keys.inscriber_bottom = Component("inputItem").key("bottom").defaultOptional().allowEmpty()
keys.inscriber_middle = Component("inputItem").key("middle")
keys.inscriber_top = Component("inputItem").key("top").defaultOptional().allowEmpty()
keys.inscriber_mode = new $EnumComponent($InscriberProcessType).key("mode").optional("inscribe").alwaysWrite()
keys.result = Component("outputItem").key("result")
keys.inscriber_ingredients = builder(keys.inscriber_bottom, keys.inscriber_middle, keys.inscriber_top).key("ingredients")
}
10 changes: 9 additions & 1 deletion kubejs/startup_scripts/schemas/schema_constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
const $RecipeSchema = Java.loadClass("dev.latvian.mods.kubejs.recipe.schema.RecipeSchema")
const $RegistryComponent = Java.loadClass("dev.latvian.mods.kubejs.recipe.component.RegistryComponent")
const $EnumComponent = Java.loadClass("dev.latvian.mods.kubejs.recipe.component.EnumComponent")

const $InscriberProcessType = Java.loadClass("appeng.recipes.handlers.InscriberProcessType")
const $ForgeRule = Java.loadClass("net.dries007.tfc.common.capabilities.forge.ForgeRule")
const $HeatCondition = Java.loadClass("com.simibubi.create.content.processing.recipe.HeatCondition")

Expand Down Expand Up @@ -84,3 +84,11 @@ function writeToParent(recipe, parentKey, childKeyNameArray, childKeyValueArray)
parentKey.component.readFromMap(recipe, parentCV, map)
parentCV.write()
}

/** @type {Custom.RecipeSchemaFactory} */
function breakdownInput(recipe, schemaType, keys, from) {
recipe.set("ingredients", $Stream.of(keys).reduce(Utils.newMap(),
(acc, cur) => ["middle", "bottom", "top"].includes(cur.name)
? acc.putIfAbsent(cur.name, from.getValue(recipe, cur)) || acc
: recipe.setValue(cur, from.getValue(recipe, cur)) && acc))
}

0 comments on commit a3fbcca

Please sign in to comment.