#Why won't the .include() method work?

2 messages · Page 1 of 1 (latest)

strange kayak
#

I'm trying to search an array for specific values for ftb quest tasks but the .include() method to search the array is not working. Here is the code I used (some of it is temp):

Code to generate the array:

global.playerBreedData

ForgeEvents.onEvent("net.minecraftforge.event.entity.living.BabyEntitySpawnEvent", event => global.spawnBaby(event))
/**
 * 
 * @param {Internal.BabyEntitySpawnEvent_} event 
 */
global.spawnBaby = event => {
    let { child, parentA, parentB } = event
    // Love causes are the players who bred the entities. It does not have to be the same player.
    let /**@type {Internal.ServerPlayer} */ loveCauseA = parentA.getLoveCause()
    let /**@type {Internal.ServerPlayer} */  loveCauseB = parentB.getLoveCause()
    if ((!loveCauseA || !loveCauseB)) return console.log("Baby spawned without player involvement")
    // You can keep track of them by storing them inside the respective player's persistent data.
    if (!loveCauseA.persistentData.BredAnimals) loveCauseA.persistentData.BredAnimals = []

    let mobBred = child.type

    loveCauseA.persistentData.BredAnimals.push(mobBred)

    global.playerBreedData = loveCauseA.persistentData.BredAnimals
}

Code to check array:

PlayerEvents.tick(event => {
    console.log(global.playerBreedData)
    console.log(global.playerBreedData.length)

    if (global.playerBreedData.includes("minecraft:cow")) {
        console.log('All Is Good!')
    }
})

The console returns the error:

Error in 'PlayerEvents.tick': TypeError: Cannot find function includes in object ["minecraft:cow"].

The array exists and the correct data is returning in the first 2 tests.

The first test returns: ["minecraft:cow"] [net.minecraft.nbt.ListTag]

I don't know if it is any shenanigans with 1.20.1 kubejs or what.

rugged fjordBOT
#

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