From 17e10c0775e72bd82c43cd6352c32094b82cc09d Mon Sep 17 00:00:00 2001 From: echo Date: Mon, 22 Jul 2024 17:27:36 +0330 Subject: [PATCH] echo reportedly ran `git add .` in `src/main/resources` instead of `src/` --- .../dev/exhq/ajarc/computer/ComputerBlockEntity.java | 4 ++++ src/main/java/dev/exhq/ajarc/vm/JsVm.java | 11 +++++++++++ 2 files changed, 15 insertions(+) diff --git a/src/main/java/dev/exhq/ajarc/computer/ComputerBlockEntity.java b/src/main/java/dev/exhq/ajarc/computer/ComputerBlockEntity.java index 46de15b..9554a8f 100644 --- a/src/main/java/dev/exhq/ajarc/computer/ComputerBlockEntity.java +++ b/src/main/java/dev/exhq/ajarc/computer/ComputerBlockEntity.java @@ -14,6 +14,7 @@ import net.minecraft.nbt.NbtOps; import net.minecraft.network.chat.Component; import net.minecraft.world.SimpleMenuProvider; import net.minecraft.world.entity.player.Player; +import net.minecraft.world.level.block.PumpkinBlock; import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.level.block.state.BlockState; import org.apache.commons.io.IOUtils; @@ -56,6 +57,9 @@ public class ComputerBlockEntity extends BlockEntity { public AjarFileSystem getFileSystem() { return fileSystem; } + public JsVm getVm() { + return jsVm; + } @Override protected void saveAdditional(@NotNull CompoundTag pTag, HolderLookup.@NotNull Provider pRegistries) { diff --git a/src/main/java/dev/exhq/ajarc/vm/JsVm.java b/src/main/java/dev/exhq/ajarc/vm/JsVm.java index 013190b..ca4b264 100644 --- a/src/main/java/dev/exhq/ajarc/vm/JsVm.java +++ b/src/main/java/dev/exhq/ajarc/vm/JsVm.java @@ -25,6 +25,7 @@ public class JsVm { this.entity = entity; this.sandbox.inject("screen", new ScreenHelper(entity)); this.sandbox.inject("fs", new FileSystemHelper(entity)); + this.sandbox.inject("js", new Js(entity)); this.sandbox.allow(ProcessHelper.class); } @@ -138,6 +139,16 @@ public class JsVm { } } + public class Js { + private final ComputerBlockEntity entity; + + public Js(ComputerBlockEntity entity) {this.entity = entity;} + public void run(String path){ + var fs = new FileSystemHelper(entity); + entity.getVm().executeScript(fs.readFile(path), new String[0]); + } + } + public void executeScript(String source, String[] args) { try { // TODO: provide an import facility of some sort