From 93e4aff3576f5b5fe29aad01bc6c51c1e8c637d2 Mon Sep 17 00:00:00 2001 From: LatvianModder Date: Tue, 23 Jul 2024 15:14:59 +0300 Subject: [PATCH] Added `Platform.packMode` string, KubeJSPlugin#breakpoint, renamed example.js to main.js --- .../dev/latvian/mods/kubejs/plugin/KubeJSPlugin.java | 7 +++++++ .../latvian/mods/kubejs/script/PlatformWrapper.java | 10 +++++++++- .../dev/latvian/mods/kubejs/script/ScriptManager.java | 4 ++-- 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/main/java/dev/latvian/mods/kubejs/plugin/KubeJSPlugin.java b/src/main/java/dev/latvian/mods/kubejs/plugin/KubeJSPlugin.java index 01e40b490..0a9883fc2 100644 --- a/src/main/java/dev/latvian/mods/kubejs/plugin/KubeJSPlugin.java +++ b/src/main/java/dev/latvian/mods/kubejs/plugin/KubeJSPlugin.java @@ -24,6 +24,7 @@ import dev.latvian.mods.kubejs.script.TypeWrapperRegistry; import dev.latvian.mods.kubejs.server.DataExport; import dev.latvian.mods.kubejs.util.AttachedData; +import dev.latvian.mods.rhino.Context; import net.minecraft.resources.ResourceLocation; import net.minecraft.server.MinecraftServer; import net.minecraft.world.entity.player.Player; @@ -131,4 +132,10 @@ default void beforeScriptsLoaded(ScriptManager manager) { default void afterScriptsLoaded(ScriptManager manager) { } + + /** + * Called by Platform.breakpoint('abc', ...) from scripts, only used for debugging + */ + default void breakpoint(Context cx, Object[] args) { + } } diff --git a/src/main/java/dev/latvian/mods/kubejs/script/PlatformWrapper.java b/src/main/java/dev/latvian/mods/kubejs/script/PlatformWrapper.java index c884cf0e4..d42ea0088 100644 --- a/src/main/java/dev/latvian/mods/kubejs/script/PlatformWrapper.java +++ b/src/main/java/dev/latvian/mods/kubejs/script/PlatformWrapper.java @@ -1,6 +1,9 @@ package dev.latvian.mods.kubejs.script; +import dev.latvian.mods.kubejs.CommonProperties; import dev.latvian.mods.kubejs.KubeJS; +import dev.latvian.mods.kubejs.plugin.KubeJSPlugins; +import dev.latvian.mods.rhino.Context; import net.neoforged.api.distmarker.Dist; import net.neoforged.fml.ModList; import net.neoforged.fml.loading.FMLLoader; @@ -139,11 +142,16 @@ public static boolean isGeneratingData() { return DatagenModLoader.isRunningDataGen(); } - public static void breakpoint(Object... args) { + public static void breakpoint(Context cx, Object... args) { KubeJS.LOGGER.info(Arrays.stream(args).map(String::valueOf).collect(Collectors.joining(", "))); + KubeJSPlugins.forEachPlugin(p -> p.breakpoint(cx, args)); } public static String getCurrentThreadName() { return Thread.currentThread().getName(); } + + public static String getPackMode() { + return CommonProperties.get().packMode; + } } \ No newline at end of file diff --git a/src/main/java/dev/latvian/mods/kubejs/script/ScriptManager.java b/src/main/java/dev/latvian/mods/kubejs/script/ScriptManager.java index 22acd082a..fb2f16c72 100644 --- a/src/main/java/dev/latvian/mods/kubejs/script/ScriptManager.java +++ b/src/main/java/dev/latvian/mods/kubejs/script/ScriptManager.java @@ -67,12 +67,12 @@ public void loadPackFromDirectory(Path path, String name, boolean exampleFile) { scriptType.console.error("Failed to create script directory", ex); } - try (var out = Files.newOutputStream(path.resolve("example.js"))) { + try (var out = Files.newOutputStream(path.resolve("main.js"))) { out.write((""" // Visit the wiki for more info - https://kubejs.com/ console.info('Hello, World! (Loaded\s""" + name + " example script)')\n\n").getBytes(StandardCharsets.UTF_8)); } catch (Exception ex) { - scriptType.console.error("Failed to write example.js", ex); + scriptType.console.error("Failed to write main.js", ex); } }