#Create New Age energizing steps in Sequenced Assembly

33 messages · Page 1 of 1 (latest)

lofty tide
#

Create New Age adds energisers and support for the energisers in sequenced assembly steps. Ex: https://gitlab.com/antarcticgardens/create-new-age/-/blob/mc1.20.1/v1.2/dev/forge/src/generated/resources/data/create_new_age/recipes/sequenced_assembly/enchanted_golden_apple.json

I'm assuming as long as an intermediate sequence is a valid RecipeJS json, this should work.

console.log(
  e.recipes.create
    .sequenced_assembly('minecraft:stone', 'minecraft:cobbled_deepslate', [
      e.recipes.createPressing('minecraft:stone', 'minecraft:stone'),
      e.custom({
        type: 'create_new_age:energising',
        energyNeeded: 20000,
        ingredients: [
          {
            item: 'minecraft:stone',
            count: 1,
          },
        ],
        results: [
          {
            item: 'minecraft:stone',
            count: 1,
          },
        ],
      }),
    ])
    .transitionalItem('minecraft:stone')
    .loops(1)
)

I can tell that this is resulting in the correct custom JSON because I can see in my logs:

[20:23:32] [WARN] Error parsing recipe create:kjs/elmz0havrfy39lpkztirwnlib[create:sequenced_assembly]: {"type":"create:sequenced_assembly","results":[{"item":"minecraft:stone","count":1}],"ingredient":{"item":"minecraft:cobbled_deepslate"},"sequence":[{"type":"create:pressing","results":[{"item":"minecraft:stone","count":1}],"ingredients":[{"item":"minecraft:stone"}]},{"type":"create_new_age:energising","energyNeeded":20000,"ingredients":[{"item":"minecraft:stone","count":1}],"results":[{"item":"minecraft:stone","count":1}]}],"transitionalItem":{"item":"minecraft:stone","count":1},"loops":1}: Cannot invoke "com.google.gson.JsonElement.getAsInt()" because the return value of "com.google.gson.JsonObject.get(String)" is null

If I pretty print that JSON:

{
    type: 'create:sequenced_assembly',
    results: [{ item: 'minecraft:stone', count: 1 }],
    ingredient: { item: 'minecraft:cobbled_deepslate' },
    sequence: [
      {
        type: 'create:pressing',
        results: [{ item: 'minecraft:stone', count: 1 }],
        ingredients: [{ item: 'minecraft:stone' }],
      },
      {
        type: 'create_new_age:energising',
        energyNeeded: 20000,
        ingredients: [{ item: 'minecraft:stone', count: 1 }],
        results: [{ item: 'minecraft:stone', count: 1 }],
      },
    ],
    transitionalItem: { item: 'minecraft:stone', count: 1 },
    loops: 1,
  }

This looks like a correct sequenced assembly recipe, but I think either KJS Create or KJS itself is trying to read an int from somewhere that it doesn't expect. I've looked through the source for SequencedAssemblyRecipeSchema and NestedRecipeComponent, but I don't understand enough of the surrounding context. Could someone with more experience take a look? If this is a small issue, I can probably PR it in.

light matrixBOT
#

Once your ticket has been resolved, please close it with </ticket close:1054771505520717835> command!

lofty tide
#

Doing the recipe with e.custom() on the exact JSON does not work either, as I also get the same error:

Cannot invoke "com.google.gson.JsonElement.getAsInt()" because the return value of "com.google.gson.JsonObject.get(String)" is null
weak vortex
#

it should just take any RecipeJS hrm

#

if u add the recipe outside there does it work

lofty tide
#

How do you mean outside?

weak vortex
#

like not as part of sequenced assembly

lofty tide
#

Okay

#

That sent me down a rabbit hole and reminded why I wrote a MASSIVE block comment in my code.

#

The gitlab contains the code for their newest version, which uses the key energyNeeded isntead of energy_needed.

#

If I change everything above to use that, everything works.

daring latch
#

looks like it is energy_needed

lofty tide
#

Yeah, I even had this commented in a massive block comment to make sure I wouldn't forget

weak vortex
#

usually Json.get(string) == null errors are thrown by the mod not kjs

lofty tide
daring latch
#

this is the branch you mentioned

lofty tide
#

Yeah, I was looking at their 1.20 branch, but that's not the branch that's built and released.

weak vortex
lofty tide
#
/**
 * Energiser recipes from Create: New Age
 * @param {Internal.RecipesEventJS} e
 * @param {OutputItem_|string} output
 * @param {InputItem_|string} input
 * @param {number} energyNeeded
 * @returns {Internal.RecipeJS}
 */
const createEnergising = (e, output, input, energyNeeded) => {
  const base = {
    type: 'create_new_age:energising',
    // https://gitlab.com/antarcticgardens/create-new-age
    // JSON recipe key changed in latest dev branch to 'energyNeeded' instead of
    // 'energy_needed'
    energy_needed: energyNeeded !== undefined ? energyNeeded : 1000,
    ingredients: [],
    results: [],
  }
  const parsedInput = Parser.parseItemInput(input)
  if (parsedInput === null) throw new Error(`Invalid input ${input}`)
  base.ingredients.push(parsedInput)
  const itemOutput = Parser.parseItemOutput(output)
  if (itemOutput === null) throw new Error(`Invalid output ${output}`)
  base.results.push(itemOutput)
  return e.custom(base)
}

I wasted so much time before debugging this.

#

Anyway, to get native support for Create energizing:

e.recipes.create
  .sequenced_assembly('minecraft:stone', 'minecraft:cobbled_deepslate', [
    e.recipes.createPressing('minecraft:stone', 'minecraft:stone'),
    e.custom({
      type: 'create_new_age:energising',
      energy_needed: 20000,
      ingredients: [
        {
          item: 'minecraft:stone',
          count: 1,
        },
      ],
      results: [
        {
          item: 'minecraft:stone',
          count: 1,
        },
      ],
    }),
  ])
  .transitionalItem('minecraft:stone')
  .loops(1)
weak vortex
#

u can use energyNeeded ?? 100 instead of the undefined check btw

lofty tide
#

I posted about this before, the nullish coalescing operator does not do what you think it does in Rhino.

weak vortex
#

also be very wary of using identical checks cause kjs typewrappers dont trigger there

lofty tide
weak vortex
#

comparing anything you get from java, as they will usually be the java version rrather thwn the js version (java.lang.String instead of string)

lofty tide
#

Yes, I expect that to be the case. I'm very careful in my code about the types that get passed around.

#

MEanwhile for nullish coalescing:

const a = {}
console.log(undefined ?? 5) // prints 0
console.log(null ?? 5) // prints 0
console.log((undefined ?? 5) + 1) // prints 1
console.log((null ?? 5) + 1) // prints 2
console.log(a.field ?? 5) // prints 2
#

In a NORMAL Js compiler this is what SHOULD happen:

const a = {}
console.log(undefined ?? 5) // prints 5
console.log(null ?? 5) // prints 5
console.log((undefined ?? 5) + 1) // prints 6
console.log((null ?? 5) + 1) // prints 6
console.log(a.field ?? 5) // prints 5
#

Anyway, the original issue was solved by changing energyNeeded to energy_needed, ended up being stupid anyway.