#nbt on output items?

30 messages · Page 1 of 1 (latest)

thorny kraken
#

trying to set the color of the sophisticated backpack (which is the hex code of the dye converted to decimal for some reason), based on the color of create toolbox used (just a parameter for now)
for example, brown is 8606770, so it would be toolboxToBackpackWithColor('brown', 8606770)

function toolboxToBackpackWithColor(color, outColor) {
  event.shaped(Item.of('sophisticatedbackpacks:backpack', '{borderColor:' + outColor + ',clothColor:' + outColor + '}'),
  [
    'ABA',
    'ACA',
    'BBB'
  ], {
    A: 'minecraft:string',
    B: 'minecraft:leather',
    C: 'create:' + color + '_toolbox'
  })
}
blazing swanBOT
#

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

pliant mango
#
  1. you need access to the ServerEvents.recipes, but you aren't passing the event alongside the color & outColor. This will only work if the function toolboxToBackpackWithColor is a nested function. My example will treat it as a regular one and expects it to exist as it's own function outside of ServerEvents.recipes

  2. as you are dealing with static, limited amount of pre-known strings, it is much easier to simply use Template Literals

The single/double quotes must be replaced with backticks
This allows you to use somestring${variable} and it'll automagically work as a string. Your current attempt at concatenation with 'string'+variable+'string' uses this same logic, but it won't work due to expecting an identifier

ashen elbowBOT
#

Paste version of backpackwithcolor.js from @pliant mango

pliant mango
#

I guesstimated how the backpack output string would look. You'll need to verify ingame with a backpack and run /kjs hand whilst holding it, and see if sophisticatedbackpacks:backpack[{borderColor:${outColor},clothColor:${outColor}}] is correct structure

thorny kraken
thorny kraken
#

Which does not include any form of bracket

#

I have just realized that I am an idiot and I am using 1.20.1 not 1.21

#

Well if you have answers regardless they would be appreciated

plush flame
# thorny kraken I have just realized that I am an idiot and I am using 1.20.1 not 1.21

What's the issue then? I tested your code and it works.

ServerEvents.recipes(event=>{
    function toolboxToBackpackWithColor(color, outColor) {
        event.shaped(Item.of('sophisticatedbackpacks:backpack', '{borderColor:' + outColor + ',clothColor:' + outColor + '}'),
        [
          'ABA',
          'ACA',
          'BBB'
        ], {
          A: 'minecraft:string',
          B: 'minecraft:leather',
          C: 'create:' + color + '_toolbox'
        })
    }
    toolboxToBackpackWithColor('brown', 8606770)
})
thorny kraken
#

wha how

#

that does not work for me

plush flame
#

send your server.log

ashen elbowBOT
#

Please send your KubeJS server log. It can be found at /minecraft/logs/kubejs/server.log.
If you are on 1.18 or 1.16 it will be called server.txt.
Please send the file directly, without links or snippets.

thorny kraken
#

well my game has decided to crash now, give me a minute

ashen elbowBOT
#

Paste version of OGfZ8gm.log from @thorny kraken

plush flame
#

Hmmm. How does your recipe script look like?

thorny kraken
#
ServerEvents.recipes(event => {
    event.remove({
      not: [
        { output: 'sophisticatedbackpacks:backpack' },
        { output: 'sophisticatedbackpacks:netherite_backpack' }
      ],
      output: '#curios:back'
    })
    event.remove({ id: 'sophisticatedbackpacks:backpack' })
    event.shaped('sophisticatedbackpacks:iron_backpack', [
      ' A ',
      'BCB',
      ' A '
    ], {
      A: 'minecraft:iron_ingot',
      B: 'minecraft:iron_block',
      C: 'sophisticatedbackpacks:copper_backpack'
    })
    
    backpackCraftWithBlocks('', 'copper')
    backpackCraftWithBlocks('', 'iron')
    backpackCraftWithBlocks('iron', 'gold')
    backpackCraftWithBlocks('gold', 'diamond')
    
    function backpackCraftWithBlocks(tierIn, tierOut) {
      event.shaped('sophisticatedbackpacks:' + tierOut + '_backpack', [
        'ABA',
        'BCB',
        'ABA'
      ], {
        A: 'minecraft:' + tierOut + (tierOut.equals('diamond') ? '' : '_ingot'),
        B: 'minecraft:' + tierOut + '_block',
        C: 'sophisticatedbackpacks:' + tierIn + (tierIn.equals('') ? '' : '_') + 'backpack'
      })
    }
    
    toolboxToBackpackWithColor('brown', 0)
    toolboxToBackpackWithColor('brown', 8606770)
    // toolboxToBackpackWithColor('white', 16383998)
    // toolboxToBackpackWithColor('orange', 16351261)
    // toolboxToBackpackWithColor('magenta', 13061821)
    // toolboxToBackpackWithColor('light_blue', 3847130)
    // toolboxToBackpackWithColor('yellow', 16701501)
    // toolboxToBackpackWithColor('lime', 8439583)
    // toolboxToBackpackWithColor('pink', 15961002)
    // toolboxToBackpackWithColor('gray', 4673362)
    // toolboxToBackpackWithColor('light_gray', 10329495)
    // toolboxToBackpackWithColor('cyan', 1481884)
    // toolboxToBackpackWithColor('purple', 8991416)
    // toolboxToBackpackWithColor('blue', 3949738)
    // toolboxToBackpackWithColor('green', 6192150)
    // toolboxToBackpackWithColor('red', 11546150)
    // toolboxToBackpackWithColor('black', 1908001)
    
    function toolboxToBackpackWithColor(color, outColor) {
        event.shaped((outColor == 0) ? 'sophisticatedbackpacks:backpack' : Item.of('sophisticatedbackpacks:backpack', `{borderColor:${outColor},clothColor:${outColor}}`), [
        'ABA',
        'ACA',
        'BBB'
      ], {
        A: 'minecraft:string',
        B: 'minecraft:leather',
        C: `create:${color}_toolbox`
      })
    }
})
plush flame
#

Maybe you should remove toolboxToBackpackWithColor('brown', 0) and put all the other lines after the function definition.

thorny kraken
#

nope

#

still not generating any recipes

#

i believe that the issue is in the Item.of part

#

but /kubejs hand generates this Item.of('sophisticatedbackpacks:backpack', '{borderColor:16383998,clothColor:16383998}')

#

so i cannot see what could be wrong

#

(thats for white)

#

ah i figured it out

#

last time that i had it working, it was displaying on the default backpack entry, now it only displays on its respective color entry