#Enhanced Celestials Event Checker

89 messages · Page 1 of 1 (latest)

median void
#

Hi I just wanted to know how could I have KubeJS (version 6.2) detect when an Enhanced Celestials event takes place? I have tried asking in their server but I didnt get a response, which I understand because they get lots of people who ask questions so that's fair. Anyways, I've looked through the source code they have for 1.19.2:
https://github.com/CorgiTaco/Enhanced-Celestials/tree/1.19.X

Here is some simple code I have, this is an example.js file stored in my server_scripts instance and I have tested and I know it loads when the world is loaded so the issue is with the code:

// shows when world loads, so file loading works
console.info('Hello, World! (Loaded SERVER scripts!!!)')


// general simplified concept of what im trying to do
ServerEvents.tick(event => {
    if(event === 'enhancedcelestials:blood_moon') console.info("BLOOD MOON")
})

i know event needs to have event.something, just not sure exactly what for this mod

the output here is just to check that it works, what i plan to do is add a gamestage (but i have seen posts of people that have done this so i can refer to those) because then those gamestages will be used in conjunction with InControl mod to customise mob spawns, this is so i can make an event kind of like Terraria's blood moons, where instead of just spawning more hostile mobs like enhanced celestials does by default, i also have a particular selection of mobs that can only spawn during this event

if anyone knows how i can grab this event i would appreciate if you could let me know, i do know that the event can be activated by /enhancedcelestials setLunarEvent enhancedcelestials:blood_moon, if that helps at all

TLDR; simple code i have tries to do something when enhancedcelestials:blood_moon event occurs but is not working, wondering if anyone knows how to check when the event happens

dusky questBOT
#

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

left rover
#
const $LunarForecast = Java.loadClass('corgitaco.enhancedcelestials.lunarevent.LunarForecast')
ServerEvents.tick(event => {
    if (event.server.time % 20 == 0) {
        console.log($LunarForecast.getCurrentEvent())
        console.log($LunarForecast.getCurrentEventRaw())
        console.log($LunarForecast.getCurrentEvent().toString())
        console.log($LunarForecast.getCurrentEventRaw().toString())
    }
})

Try this, have not tested this, send your log after trying this

median void
left rover
#

Can you just send your server.log?

median void
#

Ah okay okay

modest sandBOT
#

Paste version of server.log from @median void

median void
#

That's in the logs/kubejs subfolder right?

left rover
#
const $LunarForecast = Java.loadClass('corgitaco.enhancedcelestials.lunarevent.LunarForecast')
ServerEvents.tick(event => {
        console.log("TICK")
        console.log($LunarForecast.getCurrentEvent())
        console.log($LunarForecast.getCurrentEventRaw())
        console.log($LunarForecast.getCurrentEvent().toString())
        console.log($LunarForecast.getCurrentEventRaw().toString())
})
#

try this

left rover
median void
#

okay thanks ill try the new one

#

Okay im getting an output now but its errors, here is the new server.log file:

modest sandBOT
#

Paste version of server.log from @median void

left rover
#

Oh yeah its private

#

wait no?

median void
#

lets just make it public

#

nobody has to know

left rover
#

I wish it was that easy

median void
#

yea idk why it says no public

#

it says it is :(

#

but theres this:
private Holder<LunarEvent> currentEvent;

#

wait that doesnt make sense tho

#

thats just a local variable

left rover
#

Yeah I saw that, ill take another look in a little bit

median void
#

nvm

left rover
#
    public Holder<LunarEvent> getCurrentEvent(boolean isClearSkies) {
        if (this.dimensionSettingsHolder.value().requiresClearSkies() && !isClearSkies) {
            return this.defaultEvent;
        }
        return currentEvent;
    }
#

It has an input

#
const $LunarForecast = Java.loadClass('corgitaco.enhancedcelestials.lunarevent.LunarForecast')
ServerEvents.tick(event => {
        console.log("TICK")
        console.log($LunarForecast.getCurrentEvent(true))
        console.log($LunarForecast.getCurrentEventRaw())
        console.log($LunarForecast.getCurrentEvent(true).toString())
        console.log($LunarForecast.getCurrentEventRaw().toString())
})

Try this

median void
#

ill try it but then theres also this issue:

public Holder<LunarEvent> getCurrentEventRaw() {
        return currentEvent;
    }
#

this one has no input

#

i tried commenting out all but getCurrentEventRaw() before and it gave same result but ill try again just in case

left rover
#

Ill take a better look once I get back to my dorm.

median void
#

Okay thanks so much, this is the server.log file anyways, its the same message of no public instance though so ill try ask again in CorgiTacos server too

modest sandBOT
#

Paste version of server.log from @median void

bright axle
#

you need to find a public static to use without instantiating the method otherwise you need to instantiate the class before using

median void
#

like something thats already being used?

left rover
#

Oooh, so like this?

console.log(new $LunarForecast.getCurrentEvent(true))
#
const $LunarForecast = Java.loadClass('corgitaco.enhancedcelestials.lunarevent.LunarForecast')
ServerEvents.tick(event => {
        console.log("TICK")
        console.log(new $LunarForecast.getCurrentEvent(true))
        console.log(new $LunarForecast.getCurrentEventRaw())
        console.log(new $LunarForecast.getCurrentEvent(true).toString())
        console.log(new $LunarForecast.getCurrentEventRaw().toString())
})

try this

median void
modest sandBOT
#

Paste version of server.log from @median void

median void
#

or i guess if its public anywhere and of type Holder<LunarEvent>?

#

if this is too much i can always opt to read the chat instead

#

because its the same message every time, so thats an alternative

bright axle
#

I checked their code and they mixing Level and add getLunarContext(),
so use the Level tick event, not Server tick and use

console.log(event.level.getLunarContext().getCurrentEventRaw())

median void
#

okay thanks ill try this

#

lol i just crashed my game

#

i tried to change something, it was a big no no

bright axle
#

I forgot getLunarForecast() before getCurrentEventRaw()

median void
#

ok ill add that

#

thanks

bright axle
#

console.log(event.level.getLunarContext().getLunarForecast().getCurrentEventRaw())

median void
#

ok thanks ill try this

bright axle
#

I'm doing on mobile so bear with me lol

median void
#

ur like 1000x better than me and im on pc lol

#

im just the guy clicking the buttons

#

idk what the buttons do

#

i just rly like buttons

#

wait wtf

#

lemme repost

#
[06/12/2023 01:02:39 AM] [Server thread/ERROR] example.js#48: Error occurred while handling event 'LevelEvents.tick': TypeError: Cannot call method "getLunarForecast" of null

[06/12/2023 01:02:39 AM] [Server thread/INFO] example.js#46: TICK

[06/12/2023 01:02:39 AM] [Server thread/INFO] example.js#48: Reference{ResourceKey[enhancedcelestials:lunar/event / enhancedcelestials:blood_moon]=corgitaco.enhancedcelestials.api.lunarevent.LunarEvent@7f872cb4} [net.minecraft.core.Holder$Reference]
#

its grabbing it now

#

now i can just add a statement to check if its the right one

#

so when its a blood moon it runs whatever

bright axle
#

just add a null check because lunar context can be null sometimes

median void
#

yea ill just have it do nothing if its null

#

thanks so much guys

#

am i allowed this open so i can post the final one with all the events once ive figured them all out?

#

to keep this*

#

just so if anyone comes across it they can see

bright axle
#

yes

median void
#

ok all good

bright axle
median void
#

This code template will detect current Enhanced Celestials lunar events, then you can do whatever for each event, be it adding a gamestage, printing to chat, or adding a gamestage AND printing to chat, groundbreaking

I have explained how i think it works but to be honest i would have never been able to do this myself, i got lots of help from people here, thanks guys!!!!

modest sandBOT
#

Paste version of example.js from @median void

median void
#

i am not sure how efficient this code is, my game crashed a few times during testing, but i also have ram problems so thats worth noting

#

thanks aidan and uncandango!!!

left rover
#

LevelEvents.tick is fired once a tick per dimension btw

#

so if you have 8 dimensions in your modpack then it will fire 8 times a tick

bright axle
#

8 loaded dimensions*

left rover
#

you can use this to filter out only the overworld

    if (event.level == event.server.getOverworld().getLevel()) {
        // Code here
    }
median void
#

okay thanks i can note that

median void
#

kind of forgot to close it, but before i do, here is an implementation of what i wanted to do, which was basically implementing gamestages using the separate mod, NOT the built-in game stages that KubeJS has

im not sure exactly how you would implement it without running commands because GameStages uses ZenScript and im also not rly sure how i could do it through the program and not through running commands via KubeJS but thats how i did it

basically whenever a condition for any of the lunar events is met, a gamestage is added using the commands the Game Stages mod provides, and the same when the lunar event ends to remove it. conveniently, Game Stages seems to automatically ensure there are no duplicate stages and thats why we dont need to worry about checking if the gamestage is already given, the same can be said for removing, if the player doesnt have the game stage, nothing is removed and it moves on, so we can just put all the remove commands at the end, this could probably be more efficient but thats it

anyone who looks at this, please let me know about efficiency, im not very good at this as u can probably tell and this may even look like a silly solution, but it works for my particular case and if anyone has any better advice lmk, otherwise i can close the thread as this is pretty much the template and an example of how it could be applied and that seems good enough

modest sandBOT
#

Paste version of example_with_game_stages_mod.js from @median void

left rover
#

Cool!

median void
#

forgot to close this my bad