KubeJS (Old)

KubeJS (Old)

3M Downloads

[KJS 7.2] Component "custom_object" not wraping components

pietro-lopes opened this issue ยท 2 comments

commented

Minecraft Version

1.21.1

KubeJS Version

2101.7.2-build.277

Rhino Version

2101.2.7-build.81

Architectury Version

NA

Forge/Fabric Version

Neoforge 21.1.209

Describe your issue

kubejs/data/ae2/kubejs/recipe_components.json

{
    "ae2:ingredients": {
      "type": "custom_object",
      "keys": [
        {
          "name": "top",
          "component": "optional_ingredient",
          "optional": true
        },
        {
          "name": "middle",
          "component": "ingredient"
        },
        {
          "name": "bottom",
          "component": "optional_ingredient",
          "optional": true
        }
      ]
    }
}

kubejs/data/ae2/kubejs/recipe_schema/inscriber.json

{
  "keys": [
    {
      "name": "result",
      "type": "item_stack",
      "role": "output"
    },
    {
      "name": "ingredients",
      "role": "input",
      "type": "ae2:ingredients"
    },
    {
      "name": "mode",
      "role": "other",
      "type": {
        "type": "enum",
        "enum": "appeng.recipes.handlers.InscriberProcessType"
      },
      "optional": "inscribe",
      "always_write": true
    }
  ]
}

kubejs/server_scripts/main.js

ServerEvents.recipes(event => {
  event.forEachRecipe({output: "minecraft:acacia_boat"}, event => {})
})

let $JsonOps = Java.loadClass("com.mojang.serialization.JsonOps")

ServerEvents.recipes(event => {
  const ae2 = event.recipes.ae2

  ae2.inscriber("acacia_boat",{bottom: "#ae2:all_quartz_dust", top: "#ae2:all_quartz", middle: "#ae2:all_fluix"},"press")

  ae2.inscriber("oak_trapdoor",{bottom: "minecraft:emerald", top: "minecraft:grass_block", middle: "minecraft:oak_log"})

  ae2.inscriber("oak_door", {bottom: "minecraft:diamond", top: "minecraft:dirt", middle: "minecraft:stick"}).mode("inscribe")

  ae2.inscriber("apple", {middle: "minecraft:stick"})

  event.replaceInput({type: "ae2:inscriber"}, Ingredient.of("#c:silicon"), Ingredient.of("minecraft:gold_block"))
  
  // EnumComponent should serialize to lowercase because some mods
  // like AE2 does not accept uppercase
  event.forEachRecipe({id: "ae2:inscriber/calculation_processor"}, recipe => {
    // we trick this value to be marked for serialization by passing itself
	recipe.set("mode",recipe.get("mode"))
	console.log(`Mode before serialization: ${recipe.json.get("mode")}`)
	recipe.serialize()
	console.log(`Mode after serialization: ${recipe.json.get("mode")}`)
	let decodedRecipe = recipe.getSerializer().codec().codec().decode($JsonOps.INSTANCE, recipe.json).getOrThrow().getFirst()
	console.log(`Mode from decoded recipe: ${decodedRecipe.getProcessType()}`)
  })
  // This prints the following if not fixed:
  // 
  // Mode before serialization: "press"
  // Mode after serialization: "PRESS"
  // Mode from decoded recipe: INSCRIBE
})

Crash report/logs

https://gnomebot.dev/paste/mclogs/RsP0MjY#L371

commented

Fixed

commented

Enum is not fixed yet