#.toResultJson Problem 1.19.2 custom recipe event

34 messages · Page 1 of 1 (latest)

teal halo
#

Hi. I have scoured the discord and found several tickets in relation to this, unfortunately through the past couple of hours and many revisions I still have not found a solution.

If someone could maybe help point me in the right direction it would be greatly appreciated. I followed the section here
https://wiki.latvian.dev/books/kubejs-legacy/page/recipeeventjs

in relation to the event.custom

ServerEvents.recipes(e => {
    const ensDust = `exnihilosequentia:dust`
    const ensRack = `exnihilosequentia:crushed_netherrack`
    const ensEnd = `exnihilosequentia:crushed_end_stone`
    const compCobble = `compressium:cobblestone_1`
    const compGravel = `compressium:gravel_1`
    const compSand = `compressium:sand_1`
    const compNethRack = `compressium:netherrack_1`
    const compEndSt = `compressium:endstone_1`



    //THIS IS BREAKING AT toResultJson
    function hammer(input, result) {
        e.custom({
        type: `exnihilosequentia:hammer`,
        ingredients: Ingredient.of(input).toJson(),
        results: [Item.of(result).toResultJson()]
        })
    }



    function counthammer(input, output, count) {
        e.custom({
        type: `exnihilosequentia:hammer`,
        input: Ingredient.of(input).toJson(),
        results: [Item.of(output).withCount(count).toResultJson()]
        })
    }





hammer(compCobble, compGravel)
hammer(compGravel, compSand)
counthammer(compSand, ensDust, 9)
counthammer(compNethRack, ensRack, 9)
counthammer(compEndSt, ensEnd, 9)

})

again any help would be greatly appreciated. Thank you!

leaden galleonBOT
#

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

grave rock
#

try using toJson instead

#

toResultJson was (iirc) used to fix 1.16.5 jank

teal halo
#

in the result line?

grave rock
#

yeah replace toResultJson with toJson

teal halo
#

Will try.

#

Unfortunately that led to this error

[23:14:19] [ERROR] ! mod_specific/ex_nihilo/compressed.js#15: Failed to create custom JSON recipe from '{"type":"exnihilosequentia:hammer","ingredients":{"item":"compressium:cobblestone_1"},"results":[{"item":"compressium:gravel_1","count":1}]}': Recipe component key 'input' not found! Valid keys: [input:input_item, results:builder{chance:float,count:int,item:string}[]]```
#

oh

#

Ok so i fixed the Ingredients: line seems the documentation is a little off there

#

but now get this error

[23:20:14] [ERROR] ! Error occurred while handling event 'ServerEvents.recipes': java.lang.IllegalArgumentException: Missing required key 'chance:float'!
[23:20:14] [ERROR] ! java.lang.IllegalArgumentException: Missing required key 'chance:float'!```
dire orchid
#

try adding on .withChance(float chance) to the Item.of()

#

you should be fine to just stick it before or after the withCount(int count)

teal halo
#

Well. That fixed the chance:float error. However I'm back to this one.

[01:10:25] [ERROR] ! mod_specific/ex_nihilo/compressed.js#15: Error occurred while handling event 'ServerEvents.recipes': TypeError: Cannot find function toJson in object 'compressium:gravel_1'.

Here is the current script.

ServerEvents.recipes(e => {
    const ensDust = `exnihilosequentia:dust`
    const ensRack = `exnihilosequentia:crushed_netherrack`
    const ensEnd = `exnihilosequentia:crushed_end_stone`
    const compCobble = `compressium:cobblestone_1`
    const compGravel = `compressium:gravel_1`
    const compSand = `compressium:sand_1`
    const compNethRack = `compressium:netherrack_1`
    const compEndSt = `compressium:endstone_1`




    function hammer(input, result) {
        e.custom({
        type: `exnihilosequentia:hammer`,
        input: Ingredient.of(input).toJson(),
        results: [Item.of(result).withChance(1.0).toJson()],
        chance: 100
        })
    }



    function counthammer(input, output, count) {
        e.custom({
        type: `exnihilosequentia:hammer`,
        input: Ingredient.of(input).toJson(),
        results: [Item.of(output).withChance(1.0).withCount(count).toJson()],
        chance: 100
        })
    }





hammer(compCobble, compGravel)
hammer(compGravel, compSand)
counthammer(compSand, ensDust, 9.0)
counthammer(compNethRack, ensRack, 9.0)
counthammer(compEndSt, ensEnd, 9.0)

})
fast eagle
#

that just means toJson() doesnt exist

teal halo
#

Unfortunately I'm not skilled enough to know what that means. I was just following the docs

dire orchid
#

you might not need to use toJson() here i think

#

try without it and see if it works

teal halo
#

Yeah i tried without and it delivers an error where its looking for toJson

[14:39:06] [ERROR] ! Error occurred while handling event 'ServerEvents.recipes': java.lang.IllegalArgumentException: Expected JSON object!
[14:39:06] [ERROR] ! java.lang.IllegalArgumentException: Expected JSON object!

dire orchid
#

uh, this seems weird, but try toJsonJS()

teal halo
#

Well its a different error atleast

[15:19:05] [ERROR] ! mod_specific/ex_nihilo/compressed.js#12: Error occurred while handling event 'ServerEvents.recipes': TypeError: Cannot find function toJsonJS in object net.minecraft.world.item.crafting.Ingredient@332c87ce.
[15:19:05] [INFO] Posted recipe events in 25.98 ms
#

Line 12 is this function

    function hammer(input, output) {
        e.custom({
            type: `exnihilosequentia:hammer`,
            input: Ingredient.of(input).toJsonJS(),
            results: [Item.of(output).withChance(1.0).toJsonJS()],
            })
        }
dire orchid
#

hm

teal halo
#

Tried this way

ServerEvents.recipes(e => {

    e.custom({
        type: `exnihilosequentia:hammer`,
        input: [
        { item: `compressium:cobblestone_1` }
        ],
        tool: { tag: '#exnihilosequentia:hammer' },
        result: [
        { item: `compressium:gravel_1`, count: 1 }
        ]
    })

})

and got this

dire orchid
#

you got the key name wrong

teal halo
#

yeah

dire orchid
#

needs to be results, not result

teal halo
#

just fixed and testing it

dire orchid
#

it's probably gonna ask for the chance key again aswell

teal halo
#

1.0 is 100%?

dire orchid
#

ye

teal halo
#

OMG it works

#

thank you sooooo much for your help. Ive been banging my head on this for days

#

Heres the corrected section for anyone that finds this in the future.

ServerEvents.recipes(e => {

    e.custom({
        type: `exnihilosequentia:hammer`,
        input: [
        { item: `compressium:cobblestone_1` }
        ],
        tool: { tag: '#exnihilosequentia:hammer' },
        results: [
        { item: `compressium:gravel_1`, count: 1, chance: 1.0 }
        ]
    })

})