KubeJS

KubeJS

69M Downloads

I don't know what I am doing.

Draemonaurious opened this issue ยท 1 comments

commented

I've added a mod to a mod pack and one of it's recipes interferes with another recipe. I wanted to remove this recipe and change it to something else. I've read the wiki and looked at samples and what I have written doesn't work. I have double and triple checked the id's and they are correct. There are no errors in the logs, (I started with some errors pertaining to my coding but as far as I can tell I've corrected them).

Can someone please help me understand my failure. I have the .js located in the server scripts folder. Here is the code I wrote:

onEvent('recipes', event => {
//Recipe removals
event.remove({
output: [
'decorative_blocks:lattice',
]
})
event.shaped('decorative_blocks:lattice', [
' S ',
'STS',
' S '
], {
S: 'minecraft:stick',
T: 'minecraft:string'
})
})

The original recipe remains and continues to interfere. I have also reloaded the server scripts inside the game.

commented

Here's your problem:

event.remove({
  output: [ // This line
    'decorative_blocks:lattice',
  ] // And this
})

Those []s should not be there.

event.remove(
  {output: 'decorative_blocks:lattice'}
)

Here's a removal script that should be less unwieldy to use than event.remove:

const REMOVE = [
  {output: "decorative_blocks:lattice"}, /** 
                                          * Add entries here.
                                          * Strings and regexes will be interpreted as {id: } so you never need to type,
                                          * say, {id: "minecraft:stone"}, you can just use "minecraft:stone".
                                          * You may safely remove this comment block.
                                          */
]

events.listen('recipes', (event) => { // On the recipe event
  REMOVE.forEach((removal) => { // loop through REMOVE
    if (
      typeof removal === 'string' ||
      (typeof removal === 'object' && removal instanceof RegExp)
    ) { // if the removal is a string or regex
      event.remove({ id: removal }) // interpret it as {id}
    } else { // otherwise
      event.remove(removal) // interpret it directly
    }
  })
})

If you use this script, make sure to make another for your recipes. It's good practice to keep them separate IMO.