#Need help creating functions for custom recipes

29 messages · Page 1 of 1 (latest)

valid scaffold
#

I'm still very new to JavaScript as a whole so this could be me misunderstanding stuff but I'm trying to create a function to help me make recipes for recipetypes without explicit KJS support, but I keep getting errors and I got no clue why.

//in lib/recipe_types/extended_mushrooms.js
function ExtendedMushroomsRecipes() {}

ExtendedMushroomsRecipes.prototype = {

    fairy_ring: (inputs, output, time) => {

        let ingredients = []
        for(let i = 0; i < inputs.length; i++) {
            ingredients[i] = inputs[i].toJson()
        }

        return {
            type: 'extendedmushrooms:fairy_ring_recipe',
            ingredients: ingredients,
            result: output.toJson(),
            recipeTime: time
        }

    }
}
//in recipes/hexerei.js
ServerEvents.recipes(event => {

    event.custom(global.extendedmushrooms.fairy_ring(['hexerei:mandrake_flowers', 'hexerei:mandrake_root', 'hexerei:mandrake_flowers', 'hexerei:mandrake_root'], 'hexerei:mandrake_flower', 200))

})
//in constants.js
global.extendedmushrooms = ExtendedMushroomsRecipes()

errors:

[13:16:20] [ERROR] ! #294: Error loading KubeJS script: server_scripts:constants.js': ReferenceError: "ExtendedMushroomsRecipes" is not defined. (server_scripts:constants.js#294)
[13:16:32] [ERROR] ! #4: Error occurred while handling event 'ServerEvents.recipes': TypeError: Cannot call method "fairy_ring" of undefined (server_scripts:recipes/hexerei.js#4)
radiant turtleBOT
#

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

viral canyonBOT
#

Paste version of server.log from @valid scaffold

unique scarab
#

what the what

valid scaffold
#

i dont know

#

code no work im dumb so idk why

unique scarab
#
//in lib/recipe_types/extended_mushrooms.js

global.extendedmushrooms.fairy_ring = (e, inputs, output, time) => {
  e.custom({
    type: 'extendedmushrooms:fairy_ring_recipe',
    ingredients: inputs.map(i => i.toJson()),
    result: output.toJson(),
    recipeTime: time
  })
}
#

actually

#

let me change that

#
//in recipes/hexerei.js
ServerEvents.recipes(e => {
  global.extendedmushrooms.fairy_ring(e, ['hexerei:mandrake_flowers', 'hexerei:mandrake_root', 'hexerei:mandrake_flowers', 'hexerei:mandrake_root'], 'hexerei:mandrake_flower', 200)
})
valid scaffold
#

oh that's probably easier

unique scarab
#

but you could also not use global at all, unless you need to use these scripts in client or startup

valid scaffold
#

a const is probably better true

unique scarab
#

just make sure the file where you define the helper functions has a higher priority

valid scaffold
#

how do i set the priority?

viral canyonBOT
#

Here's a list of useful websites, mods and servers:

unique scarab
#

wait wrong command

viral canyonBOT
#

In 1.19.2 you can use various headers at the top of a script to change its load conditions.
For example:

//ignored: true
console.log("I am never printed")
//packmode: default
console.log('I will only print when packmode in kubejs/config/common.properties is set to default')
//requires: minecraft
//requires: create
console.log('I will only print when mods with ids of minecraft AND create are loaded')

You can stack these too, like so

//priority: 10
//packmode: hard
//requires: create
//requires: tconstruct
console.log('I am complicated!')
valid scaffold
#

ah ok

#

thanks

#

seems kind of weird to have them as comments but that works ig

unique scarab
#

thats how it do

valid scaffold
#

wait why is the method to convert to json called toJson() for ingredients but toJsonJS() for itemstacks?

unique scarab
#

ive never seen the second one before hmmm

#

if youre on 6.1 you might not even need either of them

valid scaffold
#

i am on 6.1

valid scaffold
#

was just being an idiot had to convert to ingredient/itemstack
this works now

const extendedMushroomsFairyRing = (event, inputs, output, time) => {
    event.custom({
        type: 'extendedmushrooms:fairy_ring_recipe',
        ingredients: inputs.map(i => Ingredient.of(i).toJson()),
        result: Item.of(output).toJson(),
        recipeTime: time
    })
}