This commit is contained in:
parent
0a3883513e
commit
cbcbaa2f29
@ -26,12 +26,11 @@ apply from: './typescript.build.gradle'
|
||||
apply from: './jni.build.gradle'
|
||||
|
||||
processResources {
|
||||
inputs.property 'version', version
|
||||
inputs.property 'name', rootProject.name
|
||||
|
||||
from(sourceSets.main.resources.srcDirs) {
|
||||
include 'fabric.mod.json'
|
||||
expand 'version': version, 'name': rootProject.name
|
||||
expand 'name': rootProject.name
|
||||
}
|
||||
|
||||
from(sourceSets.main.resources.srcDirs) {
|
||||
|
@ -1,7 +1,6 @@
|
||||
package com.thebrokenrail.scriptcraft.api;
|
||||
|
||||
import com.thebrokenrail.scriptcraft.api.bridge.Bridges;
|
||||
import com.thebrokenrail.scriptcraft.api.event.Events;
|
||||
import com.thebrokenrail.scriptcraft.core.ScriptCraftEntrypoint;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
@ -21,8 +20,8 @@ public class ScriptCraftAPI implements ScriptCraftEntrypoint {
|
||||
return false;
|
||||
}
|
||||
|
||||
static {
|
||||
@Override
|
||||
public void registerBridges() {
|
||||
Bridges.init();
|
||||
Events.init();
|
||||
}
|
||||
}
|
@ -15,5 +15,6 @@ public class Bridges {
|
||||
InventoryBridges.register();
|
||||
PlayerEntityBridges.register();
|
||||
BlockEntityBridges.register();
|
||||
EventBridges.register();
|
||||
}
|
||||
}
|
||||
|
@ -1,10 +1,10 @@
|
||||
package com.thebrokenrail.scriptcraft.api.event;
|
||||
package com.thebrokenrail.scriptcraft.api.bridge;
|
||||
|
||||
import com.thebrokenrail.scriptcraft.core.ScriptCraftCore;
|
||||
import net.fabricmc.fabric.api.event.world.WorldTickCallback;
|
||||
|
||||
public class Events {
|
||||
public static void init() {
|
||||
WorldTickCallback.EVENT.register(world -> ScriptCraftCore.useBridge("TickEvent.run", world));
|
||||
class EventBridges {
|
||||
static void register() {
|
||||
WorldTickCallback.EVENT.register(world -> ScriptCraftCore.useBridge("Event.tick", world));
|
||||
}
|
||||
}
|
@ -5,6 +5,7 @@ import com.thebrokenrail.scriptcraft.core.quickjs.QuickJSManager;
|
||||
import net.fabricmc.api.ModInitializer;
|
||||
import net.fabricmc.loader.api.FabricLoader;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.regex.Pattern;
|
||||
@ -40,15 +41,20 @@ public class ScriptCraftCore implements ModInitializer {
|
||||
@Override
|
||||
protected Object run(QuickJSNative quickjs) {
|
||||
List<ScriptCraftEntrypoint> mods = FabricLoader.getInstance().getEntrypoints(NAMESPACE, ScriptCraftEntrypoint.class);
|
||||
List<ScriptCraftEntrypoint> initializedMods = new ArrayList<>();
|
||||
for (ScriptCraftEntrypoint mod : mods) {
|
||||
if (MOD_ID_PATTERN.matcher(mod.getModID()).matches()) {
|
||||
mod.registerBridges();
|
||||
if (mod.shouldAutoLoad()) {
|
||||
quickjs.run("import '" + mod.getModID() + "';");
|
||||
initializedMods.add(mod);
|
||||
}
|
||||
} else {
|
||||
throw new RuntimeException("Invalid Mod ID: " + mod.getModID());
|
||||
System.err.println("Invalid Mod ID: " + mod.getModID());
|
||||
}
|
||||
}
|
||||
for (ScriptCraftEntrypoint mod : initializedMods) {
|
||||
quickjs.run("import '" + mod.getModID() + "';");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
});
|
||||
|
@ -8,4 +8,7 @@ public interface ScriptCraftEntrypoint {
|
||||
default boolean shouldAutoLoad() {
|
||||
return true;
|
||||
}
|
||||
|
||||
default void registerBridges() {
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
{
|
||||
"schemaVersion": 1,
|
||||
"id": "scriptcraft",
|
||||
"version": "${version}",
|
||||
"version": "1.0.0",
|
||||
"name": "${name}",
|
||||
"description": "JS API for Minecraft",
|
||||
"authors": [
|
||||
|
Reference in New Issue
Block a user