Skip to content

Commit

Permalink
Added Platform.packMode string, KubeJSPlugin#breakpoint, renamed ex…
Browse files Browse the repository at this point in the history
…ample.js to main.js
  • Loading branch information
LatvianModder committed Jul 23, 2024
1 parent eeb75f1 commit 93e4aff
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
}
}
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down

0 comments on commit 93e4aff

Please sign in to comment.