2024-02-10 23:54:25 -06:00
|
|
|
package net.eaglerforge.api;
|
|
|
|
|
|
|
|
import net.lax1dude.eaglercraft.v1_8.log4j.LogManager;
|
|
|
|
import net.lax1dude.eaglercraft.v1_8.log4j.Logger;
|
2024-02-11 03:43:45 -06:00
|
|
|
import net.minecraft.client.ClientBrandRetriever;
|
2024-02-10 23:54:25 -06:00
|
|
|
import net.minecraft.client.Minecraft;
|
2024-02-11 03:43:45 -06:00
|
|
|
import net.minecraft.util.ChatComponentText;
|
2024-02-10 23:54:25 -06:00
|
|
|
import org.teavm.jso.JSBody;
|
|
|
|
import org.teavm.jso.JSObject;
|
|
|
|
|
2024-02-11 03:43:45 -06:00
|
|
|
import java.util.ArrayList;
|
|
|
|
|
2024-02-10 23:54:25 -06:00
|
|
|
import static net.lax1dude.eaglercraft.v1_8.EaglercraftVersion.projectForkVersion;
|
|
|
|
|
|
|
|
public class ModAPI {
|
|
|
|
private static Minecraft mc;
|
2024-02-11 03:43:45 -06:00
|
|
|
public ArrayList<String> requiredList;
|
2024-02-10 23:54:25 -06:00
|
|
|
public static final Logger log = LogManager.getLogger();
|
|
|
|
public static String version = projectForkVersion;
|
2024-02-11 03:43:45 -06:00
|
|
|
public static boolean clientPacketSendEventsEnabled = true;
|
2024-02-13 04:19:11 -06:00
|
|
|
@JSBody(params = { "version" }, script = "initAPI(version)")
|
2024-02-10 23:54:25 -06:00
|
|
|
public static native void initAPI(String version);
|
2024-02-11 03:43:45 -06:00
|
|
|
@JSBody(params = { "name" }, script = "ModAPI.events.newEvent(name);")
|
|
|
|
private static native void newEvent(String name);
|
|
|
|
|
|
|
|
@JSBody(params = { "name", "data" }, script = "ModAPI.events.callEvent(name, data); return data;")
|
|
|
|
public static native BaseData callEvent(String name, BaseData data);
|
|
|
|
|
|
|
|
@JSBody(params = { "name", "data" }, script = "ModAPI[name]=data;")
|
|
|
|
public static native void setGlobal(String name, BaseData data);
|
|
|
|
|
|
|
|
@JSBody(params = { "name" }, script = "return ModAPI[name] || {};")
|
|
|
|
public static native BaseData getGlobal(String name);
|
|
|
|
|
|
|
|
@JSBody(params = {}, script = "return ModAPI;")
|
|
|
|
public static native BaseData getModAPI();
|
|
|
|
|
|
|
|
@JSBody(params = { "data" }, script = "console.log(data);")
|
|
|
|
public static native void logJSObj(JSObject data);
|
|
|
|
|
|
|
|
public void onGlobalUpdated(String global) {
|
|
|
|
// logger.info("Global update request: "+global);
|
|
|
|
BaseData data = getGlobal(global);
|
|
|
|
// logJSObj(data);
|
|
|
|
if (data == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void onRequire(String global) {
|
|
|
|
if (!requiredList.contains(global)) {
|
|
|
|
log.info("Required global: " + global);
|
|
|
|
requiredList.add(global);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-02-10 23:54:25 -06:00
|
|
|
public ModAPI(Minecraft mcIn) {
|
|
|
|
this.mc = mcIn;
|
2024-02-11 03:43:45 -06:00
|
|
|
requiredList = new ArrayList<String>();
|
2024-02-10 23:54:25 -06:00
|
|
|
initAPI(version);
|
2024-02-11 03:43:45 -06:00
|
|
|
getModAPI().setCallbackVoidWithDataArg("displayToChat", (BaseData params) -> {
|
|
|
|
mc.ingameGUI.getChatGUI().printChatMessage(new ChatComponentText(params.getString("msg")));
|
|
|
|
});
|
|
|
|
getModAPI().setCallbackVoid("clickMouse", () -> {
|
|
|
|
mc.clickMouse();
|
|
|
|
});
|
|
|
|
getModAPI().setCallbackVoid("rightClickMouse", () -> {
|
|
|
|
mc.rightClickMouse();
|
|
|
|
});
|
|
|
|
getModAPI().set("clientBrand", ClientBrandRetriever.getClientModName());
|
|
|
|
|
|
|
|
setGlobal("mcinstance", mc);
|
2024-02-13 04:19:11 -06:00
|
|
|
getModAPI().setCallbackVoidWithDataArg("log", (BaseData params) -> {
|
|
|
|
if (params.getString("type") == "info"){
|
|
|
|
log.info(params.getString("msg"));
|
|
|
|
}
|
|
|
|
if (params.getString("type") == "debug"){
|
|
|
|
log.debug(params.getString("msg"));
|
|
|
|
}
|
|
|
|
if (params.getString("type") == "error"){
|
|
|
|
log.error(params.getString("msg"));
|
|
|
|
}
|
|
|
|
if (params.getString("type") == "warn"){
|
|
|
|
log.warn(params.getString("msg"));
|
|
|
|
}
|
|
|
|
if (params.getString("type") == "fatal"){
|
|
|
|
log.fatal(params.getString("msg"));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
getModAPI().setCallbackVoidWithDataArg("drawStringWithShadow", (BaseData params) -> {
|
|
|
|
mc.ingameGUI.getFontRenderer().drawStringWithShadow(params.getString("msg"), params.getFloat("x"), params.getFloat("y"), params.getInt("color"));
|
|
|
|
});
|
2024-02-11 03:43:45 -06:00
|
|
|
}
|
|
|
|
static void globalsFunctor(ModAPI modAPI) {
|
|
|
|
GlobalsListener.provideCallback((String name) -> {
|
|
|
|
modAPI.onGlobalUpdated(name);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
static void globalsRequireFunctor(ModAPI modAPI) {
|
|
|
|
GlobalsListener.provideRequireCallback((String name) -> {
|
|
|
|
modAPI.onRequire(name);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
static void globalsUpdateFunctor(ModAPI modAPI) {
|
|
|
|
GlobalsListener.provideUpdateCallback(() -> {
|
|
|
|
modAPI.onUpdate();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
public void onUpdate() {
|
2024-02-10 23:54:25 -06:00
|
|
|
}
|
|
|
|
}
|