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