2024-12-08 00:56:32|Myriagame |source:minecraft skins
This tutorial is set by the author's setting without permission.
Project goal
After the player gets up, the type and time of the next moon incident will be output in the chat bar.
text
levelevents.tick (event => {// Write the code here
})
Key code
1. Get the list of moon incidents and take the first value: Don't ask me why I take 0, and ask because the list of lists starts from 0
var moon = event.level.getlunarcontext (). Lunarforecast.Forecast [0]
2. Get the type of moon event:
Let Moon_type = Moon.getlunareventkey (). Path
3. Planning date for obtaining the moon incident:
let scheduleddy = moon.scheDuledDay ()
Complete code
levelevents.tick (event => {Var moon = event.level.getlunarcontext (). Lunarforecast.Forecast [0]
Let moon_type = moon.getlunareventkey (). PATH
// Get the current game days (game day)
Let today = math.trunc (event.level.daytime ()/24000)
// Get the planning date of the recent moon incident
Let scheduleDding = Moon.scheDuledDay ()
// Get the interval
Let interval = (sduleddy)-(today)
// Get the current game time (for planning tasks)
If (event.level.getdytime ()%24000 == 10) {{
Event.server.runcommandsilent (`say $ {` `distance $ {moon_type} and $ {intermodring ()` `` ``)
}
})
Code optimization
However, when the above code is running, a large amount of error information will be output in the log, because this is the case where the Event is NULL in Kubejs6.(Figure) Solution:
Divide the first step of the key code into two steps, first obtain and judge whether the value of the Event.Leveel.GetlunarContext () is null, and if it is NULL, it is over.
Otherwise, get the moon event list and take the first value.
var moon_context = event.level.getlunarcontext ()Var Moon
if (moon_context == null) {
Return;
} Else {
Moon = Moon_Context.lunarforecast.Forecast [0]
}
Optimized complete code
levelevents.tick (event => {Var Moon_Context = Event.Level.GetlunarContext ()
Var Moon
If (moon_context == null) {
Return;
} Else {
Moon = Moon_Context.lunarforecast.Forecast [0]
}
Let moon_type = moon.getlunareventkey (). PATH
// Get the current game days (game day)
Let today = math.trunc (event.level.daytime ()/24000)
// Get the plan of the recent incident month
Let scheduleDding = Moon.scheDuledDay ()
// Get the interval
Let interval = (sduleddy)-(today)
// Get the current game time (for planning tasks)
If (event.level.getdytime ()%24000 == 10) {{
Event.server.runcommandsilent (`say $ {` `distance $ {moon_type} and $ {Internet.tostring ()}` `}}
})
Module version
Kubejs: 1902.6.2-build.45
Moon event: 2.1.0.6
Minecraft: 1.19.2
Effect display
National Service DNF Dark Ni
2025-01-28 09:19:27The new screenshot of the be
2025-01-28 09:18:57The 15th anniversary wallpap
2025-01-28 09:18:273DM Xuanyuan Sinicization Gr
2025-01-28 09:17:57French magazine is the first
2025-01-28 09:17:27The sneak game "Republic" wi
2025-01-28 09:16:57The story between humans and
2025-01-28 09:16:27Capture "Trinity 3: Artifact
2025-01-28 09:15:27Wind direction change "Myste
2025-01-28 09:14:57DICE's new project "Dream" w
2025-01-28 09:14:27Pirate Minecraft Skins
Minecraft Skins
2024-12-10 04:11:27Pirate Minecraft Skins
Minecraft Skins
2024-12-10 04:11:26Master Minecraft Skins
Minecraft Skins
2024-12-10 04:11:25King Minecraft Skins
Minecraft Skins
2024-12-10 04:11:25Guide Minecraft Skins
Minecraft Skins
2024-12-10 04:11:24Dark Knight Minecraft Skins
Minecraft Skins
2024-12-10 04:11:23Sparta Minecraft Skins
Minecraft Skins
2024-12-10 04:11:23Moncraft Skins of the War
Minecraft Skins
2024-12-10 04:11:22Red Witch Minecraft Skins
Minecraft Skins
2024-12-10 04:11:22Golden Cavaliers Minecraft S
Minecraft Skins
2024-12-10 04:11:22