#Persistent Data not really persisting?

46 messages · Page 1 of 1 (latest)

grim anvil
#
const $Winscreen = Java.loadClass('net.minecraft.client.gui.screens.WinScreen');

ClientEvents.tick((event) => {
    if (
        $ModSavedData.getSaveData().getHordeState().toString() == 'DEFEATED' &&
        event.player.persistentData.defeatedHorde != true
    ) {
        Client.setCurrentScreen(
            new $Winscreen(true, () => {
                Client.setCurrentScreen(null);
            })
        );

        event.player.persistentData.defeatedHorde = true;
    }
});

Every time I load into a world where the horde state is defeated, it rolls the credits once.

supple archBOT
#

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

mellow iglooBOT
#

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

grim anvil
#

Apologies for the delay, @solemn nexus, I also put extra prints.

const $Winscreen = Java.loadClass('net.minecraft.client.gui.screens.WinScreen');

ClientEvents.tick((event) => {
        console.info("Has defeated horde?")
        console.info($ModSavedData.getSaveData().getHordeState().toString() == 'DEFEATED')
        console.info('Credits already played?')
        console.info(event.player.persistentData.defeatedHorde)
    
    if (
        $ModSavedData.getSaveData().getHordeState().toString() == 'DEFEATED' &&
        event.player.persistentData.defeatedHorde != true
    ) {
        console.info("Playing credits")
        Client.setCurrentScreen(
            new $Winscreen(true, () => {
                Client.setCurrentScreen(null);
            })
        );

        event.player.persistentData.defeatedHorde = true;
    }
});
mellow iglooBOT
#

Paste version of client.log from @grim anvil

solemn nexus
#

did you know that if the persistentData is undefined then js if (!event.player.persistentData.defeatedHorde) will pass as true?

#

instead you might wanna try either making it a 0/1 check or try stages if you're running into the same issue after relogging

#

stages being ```js
player.stages.has("someStageTag")

grim anvil
#

Thank you

#

Ok, tried stages and the result is the same - it doesn't seem to be saving between sessions.

The checks themselves work, the problem is that defeatedHorde persistent data is undefined at the start, and the stage is set back to false.

#

Is there a way to check advancements client-side?

grim anvil
#
const $ModSavedData = Java.loadClass('com.github.sculkhorde.core.ModSavedData');
const $Winscreen = Java.loadClass('net.minecraft.client.gui.screens.WinScreen');

ClientEvents.tick((event) => {
    console.info('Has defeated horde?');
    console.info(
        $ModSavedData.getSaveData().getHordeState().toString() == 'DEFEATED'
    );
    console.info('Credits already played?');
    console.info(event.player.stages.has('creditsPlayed'));

    if (
        $ModSavedData.getSaveData().getHordeState().toString() == 'DEFEATED' &&
        !event.player.stages.has('creditsPlayed')
    ) {
        console.info('Playing credits');
        Client.setCurrentScreen(
            new $Winscreen(true, () => {
                Client.setCurrentScreen(null);
            })
        );

        event.player.stages.add('creditsPlayed')
    }
});
solemn nexus
#

instead of clientevents.tick try PlayerEvents.tick

grim anvil
#

nothin'

solemn nexus
#

hmm

grim anvil
#

Hmm. Respawning resets the stages as well.

solemn nexus
#

it definately shouldnt be doing that

#

try installing only kubejs and testing outside your modpack

lone lotus
#

if you have this in a client script folder PlayerEvent.tick won't work that's a server script

#

if you use ClientEvent.tick then you can't edit data that stored on server side e.g. stages or persistendData

#

atleast that is what I would assume

#

you would need to use PlayerEvents.tick and then send the data to the client to play the Display

#

using NetworkEvents.dataReceived

solemn nexus
lone lotus
#

ok, I absolutely hate that the wiki isn't up to date

solemn nexus
#

lol i feel that

#

should get don on that tbh

lone lotus
#

it just says server

#

but does this then automatically handle sending the data to the server? if in client script

solemn nexus
#

that being said im not sure about this issue, if its resetting even on respawn then something is very wrong, which is why i think he should try with only kjs, maybe some mod is doing something funky

solemn nexus
#

will only fire on client side level

lone lotus
#

are there stages that are only client specifc?

#

causes that would sound like something new

solemn nexus
#

i know persistentData should work on client though maybe its not saving through sessions because it isnt saving to the world nbt?

solemn nexus
lone lotus
#

why would it save to world nbt? on a dedicated server it also wouldn't

solemn nexus
#

it wouldnt, thats what im saying

#

stages would be in the same boat

lone lotus
#

yeah then that's the issue

solemn nexus
#

so really he should do a network events in client scripts and player tick in server scripts

lone lotus
#

yeah

grim anvil
#

Ah, that's a rabbit hole I didn't want to go down, but its a learning experience, I suppose.