#another final nbt defining post

11 messages · Page 1 of 1 (latest)

manic gorge
#

So in this script we're defining the nbt of spell scrolls and it works for those. however there are also these spell books with similar nbt data, im wondering if its as simple as changing a few let values ```js
ItemEvents.rightClicked('irons_spellbooks:scroll',e => {
const {item, player, level} = e
// Get Scroll Stuff
let nbt = item.nbt
let scrollLevel = nbt?.ISB_spell?.level
let scrollType = nbt?.ISB_spell.type
if(scrollLevel == 1) return // Early return for beginner Scrolls

// Get Powers
let originsOrigin = player.nbt.ForgeCaps['apoli:powers']
let types = {
fire: [2, 33, 59, 1, 10],
ender: [60, 44, 42, 4, 3, 21, 30],
blood: [8, 22, 25, 26, 29, 57, 39, 58, 66],
evocation: [9, 13, 14, 16, 19, 20, 31, 32, 38, 45, 64],
holy: [7, 15, 18, 27, 41, 43, 61, 62],
ice: [6, 12, 34, 40, 48],
lightning: [5, 23, 24, 37, 46, 65],
void: [35, 47, 56],
poison: [49, 50, 51, 52, 53, 54, 55]
}
// Get TypeKey
let resultKey = Object.keys(types).find(key => types[key].includes(scrollType));

// Crosscheck element and level
for(let i = 0; i < originsOrigin['Powers'].length; i++){
let power = originsOrigin['Powers'][i].Type
let element = power.split('/')[0].split(':')[1]
let powerType = power.split('/')[1].replace('lvl', '')
if(resultKey == element && scrollLevel == powerType) return
}
e.cancel()
})mainly thesejs
let scrollLevel = nbt?.ISB_spell?.level
let scrollType = nbt?.ISB_spell.type``` ive attatched the 2 nbt datas in the post and the scroll is the one being used in the code tazz simplified

high wraithBOT
#

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

manic gorge
#

i just realized taz is already workin on this so i mightve opened this post for nothing despair

wraith scroll
#
ItemEvents.rightClicked(e => {
    const {item, player, level} = e
    
    if(item.mod != 'irons_spellbooks') return
    
    // Set some NBT Variables
    let nbt = item.nbt
    let spell
    let scrollLevel
    let scrollType

    // Get Book or Scroll Stuff
    if(item.id.contains('spell_book')){
        spell = nbt?.ISB_spellbook?.spells[nbt?.ISB_spellbook?.activeSpellIndex]
        scrollLevel = spell.level
        scrollType = spell.id
    }
    else if(item.id == 'irons_spellbooks:scroll'){
        spell = nbt?.ISB_spell
        scrollLevel = spell.level
        scrollType = spell.type
    }
    if(scrollLevel == 1) return  // Early return for beginner Scrolls

    // Get Powers
    let originsOrigin = player.nbt.ForgeCaps['apoli:powers']
    let types = {
        fire: [2, 33, 59, 1, 10],
        ender: [60, 44, 42, 4, 3, 21, 30],
        blood: [8, 22, 25, 26, 29, 57, 39, 58, 66],
        evocation: [9, 13, 14, 16, 19, 20, 31, 32, 38, 45, 64],
        holy: [7, 15, 18, 27, 41, 43, 61, 62],
        ice: [6, 12, 34, 40, 48],
        lightning: [5, 23, 24, 37, 46, 65],
        void: [35, 47, 56],
        poison: [49, 50, 51, 52, 53, 54, 55]
    }
    // Get TypeKey
    let resultKey = Object.keys(types).find(key => types[key].includes(scrollType));

    // Crosscheck element and level
    for(let i = 0; i < originsOrigin['Powers'].length; i++){
        let power = originsOrigin['Powers'][i].Type
        let element = power.split('/')[0].split(':')[1]
        let powerType = power.split('/')[1].replace('lvl', '')
        if(resultKey == element && scrollLevel == powerType) return
    }
    e.cancel()
})```
#

Explanation:

  • we removed the initial item at line 1
  • added a modid check with early return in line 4
  • check for either a "spell_book" or a scroll
  • get NBT Data needed (book uses spell.id for some reason)

rest stayed same

manic gorge
#

oh snap

#

lemme try it out one sec

#

i now see how if statements should really be used rofl

wraith scroll
#

if u need further information/explanation, feel free to reach out

manic gorge
#

will do, im booting up an instance real quick to make sure i dont mess it up

manic gorge