add mod loader

This commit is contained in:
radmanplays 2024-02-15 15:30:47 +03:30
parent f3ea418cfe
commit 00d76e5f27
20 changed files with 1184 additions and 26 deletions

View File

@ -5,8 +5,10 @@
# Version: 1.0
# Author: lax1dude
> CHANGE 2 : 11 @ 2 : 9
> CHANGE 2 : 13 @ 2 : 9
~ import net.eaglerforge.gui.ModGUI;
~ import net.eaglerforge.gui.WIP_GuiMods;
~ import net.lax1dude.eaglercraft.v1_8.Mouse;
~ import net.lax1dude.eaglercraft.v1_8.opengl.GlStateManager;
~ import net.lax1dude.eaglercraft.v1_8.sp.SingleplayerServerController;
@ -49,8 +51,10 @@
~ this.buttonList.add(lanButton = new GuiButton(7, this.width / 2 + 2, this.height / 4 + 96 + b0, 98, 20,
~ I18n.format(LANServerController.isLANOpen() ? "menu.closeLan" : "menu.openToLan", new Object[0])));
> CHANGE 4 : 9 @ 4 : 5
> CHANGE 4 : 11 @ 4 : 5
~ this.buttonList.add(new GuiButton(69420, this.width / 2 - 100, this.height / 4 + 73 + b0,
~ I18n.format("eaglerforge.menu.mods", new Object[0])));
~ lanButton.enabled = SingleplayerServerController.isWorldRunning();
~ if (!hasSentAutoSave) {
~ hasSentAutoSave = true;
@ -73,7 +77,14 @@
~ this.mc.shutdownIntegratedServer(new GuiMultiplayer(new GuiMainMenu()));
> CHANGE 16 : 30 @ 16 : 17
> INSERT 9 : 13 @ 9
+ case 69420:
+ // this.mc.displayGuiScreen(new GuiMods(this));
+ ModGUI.displayGui();
+ break;
> CHANGE 7 : 21 @ 7 : 8
~ if (!LANServerController.supported()) {
~ mc.displayGuiScreen(new GuiScreenLANNotSupported(this));

View File

@ -5,7 +5,10 @@
# Version: 1.0
# Author: lax1dude
> DELETE 2 @ 2 : 3
> CHANGE 2 : 4 @ 2 : 3
~ import net.eaglerforge.gui.ModGUI;
~
> DELETE 3 @ 3 : 4
@ -16,7 +19,7 @@
> CHANGE 2 : 30 @ 2 : 4
~
~ import net.eaglerforge.GuiMods;
~ import net.eaglerforge.gui.WIP_GuiMods;
~ import net.lax1dude.eaglercraft.v1_8.EagRuntime;
~ import net.lax1dude.eaglercraft.v1_8.EaglerInputStream;
~ import net.lax1dude.eaglercraft.v1_8.EaglercraftRandom;
@ -52,7 +55,9 @@
> DELETE 3 @ 3 : 5
> DELETE 4 @ 4 : 11
> DELETE 2 @ 2 : 3
> DELETE 1 @ 1 : 8
> DELETE 2 @ 2 : 3
@ -214,10 +219,11 @@
~ if (parGuiButton.id == 4) {
~ this.mc.displayGuiScreen(new GuiScreenEditProfile(this));
> INSERT 1 : 4 @ 1
> INSERT 1 : 5 @ 1
+ if (parGuiButton.id == 69420) {
+ this.mc.displayGuiScreen(new GuiMods(this));
+ // this.mc.displayGuiScreen(new WIP_GuiMods(this));
+ ModGUI.displayGui();
+ }
> CHANGE 1 : 3 @ 1 : 3

View File

@ -7,12 +7,11 @@
> DELETE 2 @ 2 : 3
> INSERT 1 : 8 @ 1
> INSERT 1 : 7 @ 1
+
+ import com.google.common.collect.Lists;
+
+ import net.eaglerforge.GuiMods;
+ import net.lax1dude.eaglercraft.v1_8.sp.lan.LANServerController;
+ import net.lax1dude.eaglercraft.v1_8.sp.lan.LANServerList;
+ import net.lax1dude.eaglercraft.v1_8.sp.relay.RelayManager;

View File

@ -5,10 +5,9 @@
# Version: 1.0
# Author: lax1dude
> CHANGE 3 : 10 @ 3 : 5
> CHANGE 3 : 9 @ 3 : 5
~
~ import net.eaglerforge.api.BaseData;
~ import net.lax1dude.eaglercraft.v1_8.EaglercraftRandom;
~ import net.lax1dude.eaglercraft.v1_8.EaglercraftUUID;
~ import net.lax1dude.eaglercraft.v1_8.HString;

View File

@ -7,11 +7,9 @@
> DELETE 2 @ 2 : 5
> CHANGE 4 : 14 @ 4 : 6
> CHANGE 4 : 12 @ 4 : 6
~
~ import net.eaglerforge.api.BaseData;
~ import net.eaglerforge.api.ModData;
~ import net.lax1dude.eaglercraft.v1_8.EaglercraftRandom;
~ import net.lax1dude.eaglercraft.v1_8.EaglercraftUUID;
~

View File

@ -7,11 +7,9 @@
> DELETE 2 @ 2 : 5
> CHANGE 2 : 11 @ 2 : 3
> CHANGE 2 : 9 @ 2 : 3
~
~ import net.eaglerforge.api.BaseData;
~ import net.eaglerforge.api.ModData;
~ import net.lax1dude.eaglercraft.v1_8.EaglercraftUUID;
~
~ import com.google.common.base.Charsets;

View File

@ -12,7 +12,7 @@
~ eaglercraft.recording.start=reen...
~ eaglercraft.soundCategory.voice=Voice
> INSERT 1 : 200 @ 1
> INSERT 1 : 202 @ 1
+ eaglercraft.resourcePack.prompt.title=What do you want to do with '%s'?
+ eaglercraft.resourcePack.prompt.text=Tip: Hold Shift to skip this screen when selecting a resource pack!
@ -209,9 +209,11 @@
+ eaglercraft.command.clientStub=This command is client side!
+
+ eaglerforge.menu.mods=Mods
+ eaglerforge.menu.mods.title=Loaded Mods
+ eaglerforge.menu.mods.title1=Available mods
+ eaglerforge.menu.mods.title2=Selected mods
+ eaglerforge.menu.mods.addmod=Add Mod
+ eaglerforge.menu.mods.removemod=Remove Mod
+ eaglerforge.menu.mods.info=(Only .js files)
+
> INSERT 163 : 350 @ 163

View File

@ -4,6 +4,8 @@ import net.lax1dude.eaglercraft.v1_8.log4j.LogManager;
import net.lax1dude.eaglercraft.v1_8.log4j.Logger;
import org.teavm.jso.JSBody;
import net.eaglerforge.gui.ModLoader;
public class EaglerForge {
public static final Logger log = LogManager.getLogger();
@JSBody(params = { "message" }, script = "alert(message)")
@ -22,5 +24,6 @@ public class EaglerForge {
public static void init() {
log.info("Starting EaglerForge!");
log.info("Loading Mods...");
ModLoader.loadLoader();
}
}

View File

@ -1,5 +1,6 @@
package net.eaglerforge.api;
import net.eaglerforge.gui.ModGUI;
import net.lax1dude.eaglercraft.v1_8.log4j.LogManager;
import net.lax1dude.eaglercraft.v1_8.log4j.Logger;
import net.minecraft.client.ClientBrandRetriever;
@ -90,6 +91,7 @@ public class ModAPI {
getModAPI().setCallbackVoidWithDataArg("drawStringWithShadow", (BaseData params) -> {
mc.ingameGUI.getFontRenderer().drawStringWithShadow(params.getString("msg"), params.getFloat("x"), params.getFloat("y"), params.getInt("color"));
});
ModGUI.loadFont();
}
static void globalsFunctor(ModAPI modAPI) {
GlobalsListener.provideCallback((String name) -> {

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,27 @@
package net.eaglerforge.gui;
import org.teavm.jso.JSBody;
public class ModLoader {
public static String[] Mods = {};
@JSBody(params = { "Mods" }, script = "window.ModLoader(Mods);")
public static native void loadMods(String[] Mods);
@JSBody(params = {}, script = "loadLoader();")
public static native void loadLoader();
@JSBody(params = { "Mods" }, script = "localStorage.setItem('ml::Mods', JSON.stringify(Mods))")
private static native void saveMods(String[] Mods);
@JSBody(params = {}, script = "try { return JSON.parse(localStorage.getItem('ml::Mods')||'[]') } catch(err) {return []}")
private static native String[] retrieveMods();
public static void saveModsToLocalStorage() {
saveMods(Mods);
};
public static void loadModsFromLocalStorage() {
Mods = retrieveMods();
};
}

View File

@ -0,0 +1,235 @@
package net.eaglerforge.gui;
// WIP -radmanplays
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import com.google.common.collect.Lists;
import net.lax1dude.eaglercraft.v1_8.EagRuntime;
import net.lax1dude.eaglercraft.v1_8.vfs.SYS;
import net.lax1dude.eaglercraft.v1_8.internal.FileChooserResult;
import net.lax1dude.eaglercraft.v1_8.log4j.LogManager;
import net.lax1dude.eaglercraft.v1_8.log4j.Logger;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.GuiOptionButton;
import net.minecraft.client.gui.GuiResourcePackAvailable;
import net.minecraft.client.gui.GuiResourcePackSelected;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.resources.I18n;
import net.minecraft.client.resources.ResourcePackListEntry;
import net.minecraft.client.resources.ResourcePackListEntryFound;
import net.minecraft.client.resources.ResourcePackRepository;
public class WIP_GuiMods extends GuiScreen {
private static final Logger logger = LogManager.getLogger();
private final GuiScreen parentScreen;
private List<ResourcePackListEntry> availableResourcePacks;
private List<ResourcePackListEntry> selectedResourcePacks;
private GuiResourcePackAvailable availableResourcePacksList;
private GuiResourcePackSelected selectedResourcePacksList;
private boolean changed = false;
public WIP_GuiMods(GuiScreen parentScreenIn) {
this.parentScreen = parentScreenIn;
}
/**+
* Adds the buttons (and other controls) to the screen in
* question. Called when the GUI is displayed and when the
* window resizes, the buttonList is cleared beforehand.
*/
public void initGui() {
GuiButton btn;
this.buttonList.add(btn = new GuiOptionButton(2, this.width / 2 - 154, this.height - 48,
I18n.format("eaglerforge.menu.mods.addmod"
+ "", new Object[0])));
btn.enabled = SYS.VFS != null;
this.buttonList.add(
new GuiOptionButton(1, this.width / 2 + 4, this.height - 48, I18n.format("gui.done", new Object[0])));
if (!this.changed) {
this.availableResourcePacks = Lists.newArrayList();
this.selectedResourcePacks = Lists.newArrayList();
ResourcePackRepository resourcepackrepository = this.mc.getResourcePackRepository();
resourcepackrepository.updateRepositoryEntriesAll();
ArrayList arraylist = Lists.newArrayList(resourcepackrepository.getRepositoryEntriesAll());
arraylist.removeAll(resourcepackrepository.getRepositoryEntries());
}
this.availableResourcePacksList = new GuiResourcePackAvailable(this.mc, 200, this.height,
this.availableResourcePacks);
this.availableResourcePacksList.setSlotXBoundsFromLeft(this.width / 2 - 4 - 200);
this.availableResourcePacksList.registerScrollButtons(7, 8);
this.selectedResourcePacksList = new GuiResourcePackSelected(this.mc, 200, this.height,
this.selectedResourcePacks);
this.selectedResourcePacksList.setSlotXBoundsFromLeft(this.width / 2 + 4);
this.selectedResourcePacksList.registerScrollButtons(7, 8);
}
/**+
* Handles mouse input.
*/
public void handleMouseInput() throws IOException {
super.handleMouseInput();
this.selectedResourcePacksList.handleMouseInput();
this.availableResourcePacksList.handleMouseInput();
}
public boolean hasResourcePackEntry(ResourcePackListEntry parResourcePackListEntry) {
return this.selectedResourcePacks.contains(parResourcePackListEntry);
}
/**+
* Returns the list containing the resource pack entry, returns
* the selected list if it is selected, otherwise returns the
* available list
*/
public List<ResourcePackListEntry> getListContaining(ResourcePackListEntry parResourcePackListEntry) {
return this.hasResourcePackEntry(parResourcePackListEntry) ? this.selectedResourcePacks
: this.availableResourcePacks;
}
/**+
* Returns a list containing the available resource packs
*/
public List<ResourcePackListEntry> getAvailableResourcePacks() {
return this.availableResourcePacks;
}
/**+
* Returns a list containing the selected resource packs
*/
public List<ResourcePackListEntry> getSelectedResourcePacks() {
return this.selectedResourcePacks;
}
/**+
* Called by the controls from the buttonList when activated.
* (Mouse pressed for buttons)
*/
protected void actionPerformed(GuiButton parGuiButton) {
if (parGuiButton.enabled) {
if (parGuiButton.id == 2) {
if (SYS.VFS == null)
return;
EagRuntime.displayFileChooser("text/javascript", "js");
} else if (parGuiButton.id == 1) {
if (this.changed) {
ArrayList arraylist = Lists.newArrayList();
for (ResourcePackListEntry resourcepacklistentry : this.selectedResourcePacks) {
if (resourcepacklistentry instanceof ResourcePackListEntryFound) {
arraylist.add(((ResourcePackListEntryFound) resourcepacklistentry).func_148318_i());
}
}
Collections.reverse(arraylist);
this.mc.getResourcePackRepository().setRepositories(arraylist);
this.mc.gameSettings.resourcePacks.clear();
this.mc.gameSettings.field_183018_l.clear();
for (ResourcePackRepository.Entry resourcepackrepository$entry : (List<ResourcePackRepository.Entry>) arraylist) {
this.mc.gameSettings.resourcePacks.add(resourcepackrepository$entry.getResourcePackName());
if (resourcepackrepository$entry.func_183027_f() != 1) {
this.mc.gameSettings.field_183018_l.add(resourcepackrepository$entry.getResourcePackName());
}
}
this.mc.loadingScreen.eaglerShow(I18n.format("resourcePack.load.refreshing"),
I18n.format("resourcePack.load.pleaseWait"));
this.mc.gameSettings.saveOptions();
this.mc.refreshResources();
}
this.mc.displayGuiScreen(this.parentScreen);
}
}
}
public void updateScreen() {
FileChooserResult packFile = null;
if (EagRuntime.fileChooserHasResult()) {
packFile = EagRuntime.getFileChooserResult();
}
if (packFile == null)
return;
logger.info("Loading resource pack: {}", packFile.fileName);
mc.loadingScreen.eaglerShow(I18n.format("resourcePack.load.loading"), packFile.fileName);
SYS.loadResourcePack(packFile.fileName, new ByteArrayInputStream(packFile.fileData), null);
ArrayList arraylist = Lists.newArrayList();
for (ResourcePackListEntry resourcepacklistentry : this.selectedResourcePacks) {
if (resourcepacklistentry instanceof ResourcePackListEntryFound) {
arraylist.add(((ResourcePackListEntryFound) resourcepacklistentry).func_148318_i());
}
}
Collections.reverse(arraylist);
this.mc.getResourcePackRepository().setRepositories(arraylist);
this.mc.gameSettings.resourcePacks.clear();
this.mc.gameSettings.field_183018_l.clear();
for (ResourcePackRepository.Entry resourcepackrepository$entry : (List<ResourcePackRepository.Entry>) arraylist) {
this.mc.gameSettings.resourcePacks.add(resourcepackrepository$entry.getResourcePackName());
if (resourcepackrepository$entry.func_183027_f() != 1) {
this.mc.gameSettings.field_183018_l.add(resourcepackrepository$entry.getResourcePackName());
}
}
this.mc.gameSettings.saveOptions();
boolean wasChanged = this.changed;
this.changed = false;
this.initGui();
this.changed = wasChanged;
}
/**+
* Called when the mouse is clicked. Args : mouseX, mouseY,
* clickedButton
*/
protected void mouseClicked(int parInt1, int parInt2, int parInt3) {
super.mouseClicked(parInt1, parInt2, parInt3);
this.availableResourcePacksList.mouseClicked(parInt1, parInt2, parInt3);
this.selectedResourcePacksList.mouseClicked(parInt1, parInt2, parInt3);
}
/**+
* Called when a mouse button is released. Args : mouseX,
* mouseY, releaseButton
*/
protected void mouseReleased(int i, int j, int k) {
super.mouseReleased(i, j, k);
}
/**+
* Draws the screen and all the components in it. Args : mouseX,
* mouseY, renderPartialTicks
*/
public void drawScreen(int i, int j, float f) {
this.drawBackground(0);
this.availableResourcePacksList.drawScreen(i, j, f);
this.selectedResourcePacksList.drawScreen(i, j, f);
this.drawCenteredString(this.fontRendererObj, I18n.format("eaglerforge.menu.mods", new Object[0]), this.width / 2,
16, 16777215);
this.drawCenteredString(this.fontRendererObj, I18n.format("eaglerforge.menu.mods.info", new Object[0]),
this.width / 2 - 77, this.height - 26, 0xFF0000);
super.drawScreen(i, j, f);
}
/**+
* Marks the selected resource packs list as changed to trigger
* a resource reload when the screen is closed
*/
public void markChanged() {
this.changed = true;
}
}

View File

@ -2,7 +2,6 @@ package net.lax1dude.eaglercraft.v1_8;
import java.math.BigInteger;
import static net.eaglerforge.GuiMods.ModsLoaded;
public class EaglercraftVersion {
@ -50,7 +49,7 @@ public class EaglercraftVersion {
// Miscellaneous variables:
public static final String mainMenuStringA = "Minecraft* 1.8.8";
public static final String mainMenuStringB = projectForkName + " " + projectForkVersion + " (" + ModsLoaded + " Mods loaded)";
public static final String mainMenuStringB = projectForkName + " " + projectForkVersion + " (" + 0 + " Mods loaded)";
public static final String mainMenuStringC = "";
public static final String mainMenuStringD = "Resources Copyright Mojang AB";

View File

@ -3,7 +3,7 @@ package net.lax1dude.eaglercraft.v1_8.log4j;
import java.text.SimpleDateFormat;
import java.util.Date;
import net.eaglerforge.api.ModData;
/*import net.eaglerforge.api.ModData;*/
import net.lax1dude.eaglercraft.v1_8.EagRuntime;
import net.lax1dude.eaglercraft.v1_8.internal.PlatformRuntime;
@ -22,7 +22,7 @@ import net.lax1dude.eaglercraft.v1_8.internal.PlatformRuntime;
* POSSIBILITY OF SUCH DAMAGE.
*
*/
public class Logger extends ModData {
public class Logger /*extends ModData*/ {
public final String loggerName;

View File

@ -0,0 +1,121 @@
function initAPI(version) {
var ModAPI = {};
ModAPI.events = {};
ModAPI.events.types = ["event"];
ModAPI.events.listeners = { "event": [] };
ModAPI.globals = {};
ModAPI.addEventListener = function AddEventListener(name, callback) {
if (!callback) {
throw new Error("Invalid callback!");
}
if (ModAPI.events.types.includes(name)) {
if (!Array.isArray(ModAPI.events.listeners[name])) {
ModAPI.events.listeners[name] = [];
}
ModAPI.events.listeners[name].push(callback);
console.log("Added new event listener.");
} else {
throw new Error("This event does not exist!");
}
};
ModAPI.removeEventListener = function removeEventListener(name, func, slow) {
if (!func) {
throw new Error("Invalid callback!");
}
if (!Array.isArray(ModAPI.events.listeners[name])) {
ModAPI.events.listeners[name] = [];
}
var targetArr = ModAPI.events.listeners[name];
if (!slow) {
if (targetArr.indexOf(func) !== -1) {
targetArr.splice(targetArr.indexOf(func), 1);
console.log("Removed event listener.");
}
} else {
var functionString = func.toString();
targetArr.forEach((f, i) => {
if (f.toString() === functionString) {
targetArr.splice(i, 1);
console.log("Removed event listener.");
}
});
}
};
ModAPI.events.newEvent = function newEvent(name) {
ModAPI.events.types.push(name);
};
ModAPI.events.callEvent = function callEvent(name, data) {
if (
!ModAPI.events.types.includes(name) ||
!Array.isArray(ModAPI.events.listeners[name])
) {
if (!Array.isArray(ModAPI.events.listeners[name])) {
if (ModAPI.events.types.includes(name)) {
ModAPI.events.listeners.event.forEach((func) => {
func({ event: name, data: data });
});
return;
}
return;
}
console.error(
"The ModAPI has been called with an invalid event name: " + name
);
console.error("Please report this bug to the repo.");
return;
}
ModAPI.events.listeners[name].forEach((func) => {
func(data);
});
ModAPI.events.listeners.event.forEach((func) => {
func({ event: name, data: data });
});
ModAPI.globals._initUpdate();
};
ModAPI.updateComponent = function updateComponent(component) {
if (
typeof component !== "string" ||
ModAPI[component] === null ||
ModAPI[component] === undefined
) {
return;
}
if (!ModAPI.globals || !ModAPI.globals.onGlobalsUpdate) {
return;
}
if (!ModAPI.globals.toUpdate) {
ModAPI.globals.toUpdate = [];
}
if (ModAPI.globals.toUpdate.indexOf(component) === -1) {
ModAPI.globals.toUpdate.push(component);
}
};
ModAPI.require = function require(component) {
if (typeof component !== "string") {
return;
}
if (!ModAPI.globals || !ModAPI.globals.onRequire) {
return;
}
ModAPI.globals.onRequire(component);
};
ModAPI.globals._initUpdate = function _initUpdate() {
if (!ModAPI.globals.toUpdate) {
ModAPI.globals.toUpdate = [];
}
ModAPI.globals.toUpdate.forEach((id) => {
ModAPI.globals.onGlobalsUpdate(id);
});
ModAPI.globals.toUpdate = [];
};
window.ModAPI = ModAPI;
}

View File

@ -0,0 +1,169 @@
function displayGui() {
function gui() {
if (document.querySelector("#eaglerpl_gui")) {
document.querySelector("#eaglerpl_gui").remove();
}
localStorage.setItem(
"ml::Mods",
localStorage.getItem("ml::Mods") || "[]"
);
try {
localStorage.setItem(
"ml::Mods",
JSON.stringify(JSON.parse(localStorage.getItem("ml::Mods")))
);
} catch (error) {
localStorage.setItem("ml::Mods", "[]");
}
var Mods = JSON.parse(localStorage.getItem("ml::Mods"));
var container = document.createElement("div");
container.id = "eaglerpl_gui";
container.style = `width:100%; height: 100%; position: fixed; top: 0; left: 0; z-index: 10; color: white; font-family: Minecraftia, sans-serif; overflow-y: scroll; overflow-x: hidden; background-image: url(data:image/png;base64,UklGRhoBAABXRUJQVlA4TA0BAAAvn8AnAIWjtpEECdnA2N0DsTROy7xUqfrWw0jbyLkJKTz0+I20jTT/Bo89e1YR/Wfktm0Y+wNKLobT7QP/n/B7Z/naW26QHoTpHB7LFouyKHlzeHxfCStSuj9KdbC8z1IJ5iWiyQed48vtYJ+lUu0t4VwranS1XMIutSiLYlbb8G54uf2p3VPSfRZtSrlsPFjOzZZrd/us3B3uK+HcHJQql+xbLMrS/WqNpm6DeZ/VIPVYaN/KzUbp91nd9xl5pYu50dU2W417nbdTj5l2Ne92uM9qXNpyf6+oXkabHKXaZ1HS4Iaqpim+1KIJ+0M49/LjNbTGP5mrrMZEuc7Uzcb1ViOJ6TuOt4NGJs+zDgA=); background-color: rgb(60,60,60); background-blend-mode: multiply; background-size: 64px;`;
var title = document.createElement("h1");
title.style = "text-shadow: 0px 0px 4px;";
title.innerHTML = "Mod Manager";
var closeButton = document.createElement("a");
closeButton.style = `margin-left: 2rem; color: red;`;
closeButton.href = "javascript:void(0)";
closeButton.addEventListener("click", () => {
document.querySelector("#eaglerpl_gui").remove();
});
closeButton.innerHTML = "[X]";
title.appendChild(closeButton);
container.appendChild(title);
var warningPoster = document.createElement("p");
warningPoster.style = "font-size: 0.8rem; color: orangered;";
warningPoster.innerHTML =
"Warning: Installing Mods gives them full control over the game. Be cautious when installing them.<br>Mods that have been removed also need a reload to stop running in the background.";
container.appendChild(warningPoster);
var tipPoster = document.createElement("p");
tipPoster.style = "font-size: 0.8rem; color: yellow;";
tipPoster.innerHTML =
"Tip: if the mods say that they failed loading, try refreshing the gui";
container.appendChild(tipPoster);
var table = document.createElement("table");
table.style = "table-layout: fixed; width: 100%";
var headerRow = document.createElement("tr");
headerRow.style = "background: rgb(50,50,50);";
var urlBox = document.createElement("th");
urlBox.style = "text-align: center;";
urlBox.innerHTML = "URL";
headerRow.appendChild(urlBox);
var statusBox = document.createElement("th");
statusBox.style = "text-align: center; width: 15%;";
statusBox.innerHTML = "Status";
headerRow.appendChild(statusBox);
table.appendChild(headerRow);
Mods.forEach((url) => {
var row = document.createElement("tr");
row.style = `box-shadow: 0px 2px 0px grey;`;
var urlBox = document.createElement("td");
urlBox.style = "user-select: text;";
var textWrapper = document.createElement("div");
textWrapper.style = `max-width: 100%; overflow-wrap: anywhere; max-height: 3rem; overflow-y: scroll;`;
textWrapper.innerText = url;
urlBox.append(textWrapper);
row.appendChild(urlBox);
var statusBox = document.createElement("td");
statusBox.innerHTML = ((curl) => {
var targs = document.querySelectorAll("script[data-Mod]");
for (let i = 0; i < targs.length; i++) {
const elem = targs[i];
if (elem.getAttribute("data-Mod") === curl) {
return "LOADED";
}
}
return "FAILED";
})(url);
switch (statusBox.innerHTML) {
case "LOADED":
statusBox.style = "background-color: green; text-align: center;";
break;
case "FAILED":
statusBox.style = "background-color: dimgrey; text-align: center;";
break;
default:
break;
}
var binBtn = document.createElement("button");
binBtn.style =
"background: transparent; text-align: center; color: yellow; cursor: pointer; font-family: 'Minecraftia', sans-serif; text-decoration: underline; border: 0; margin-left: 1rem; font-size: 1rem;";
binBtn.innerHTML = "[X]";
binBtn.addEventListener("click", () => {
if (!window.confirm("Delete Mod?") || Mods.indexOf(url) === -1) {
return;
}
Mods.splice(Mods.indexOf(url), 1);
localStorage.setItem("ml::Mods", JSON.stringify(Mods));
gui();
});
statusBox.appendChild(binBtn);
row.appendChild(statusBox);
table.appendChild(row);
});
var addBtn = document.createElement("button");
addBtn.style =
"background: transparent; text-align: center; color: yellow; cursor: pointer; font-family: 'Minecraftia', sans-serif; text-decoration: underline; border: 0; margin-right: 1rem; font-size: 1rem;";
addBtn.innerHTML = "Add new";
addBtn.addEventListener("click", () => {
var newMod = window.prompt("URL of Mod: ", "http://example.com/example.js");
Mods.push(
newMod
);
localStorage.setItem("ml::Mods", JSON.stringify(Mods));
if(window.ModLoader){
ModLoader([newMod]);
}
gui();
});
var uploadBtn = document.createElement("button");
uploadBtn.style =
"background: transparent; text-align: center; color: yellow; cursor: pointer; font-family: 'Minecraftia', sans-serif; text-decoration: underline; border: 0; font-size: 1rem;";
uploadBtn.innerHTML = "Upload...";
uploadBtn.addEventListener("click", function uploadBtnListener() {
var filePicker = document.createElement("input");
filePicker.type = "file";
filePicker.accept = ".js";
filePicker.addEventListener("input", function onInput() {
if (filePicker.files[0]) {
var reader = new FileReader();
reader.addEventListener("load", function onModRead() {
var newMod = reader.result.replace(";base64", `;fs=${encodeURIComponent(filePicker.files[0].name) || "unknown"};base64`);
Mods.push(newMod);
localStorage.setItem("ml::Mods", JSON.stringify(Mods));
if(window.ModLoader){
ModLoader([newMod]);
}
gui();
});
reader.readAsDataURL(filePicker.files[0]);
}
});
filePicker.click();
});
container.appendChild(table);
container.appendChild(addBtn);
container.appendChild(uploadBtn);
var notice = document.createElement("a");
notice.innerHTML = "Refresh GUI";
notice.href = "javascript:void(0)";
notice.addEventListener("click", function reloadListener() {
setTimeout(gui, 500);
this.remove();
});
notice.style =
"color: yellow; display: block; margin-top: 2rem; width: 0; white-space: nowrap;";
container.appendChild(notice);
//ModAPI.events.callEvent("gui", {});
document.body.appendChild(container);
}
gui();
}

View File

@ -0,0 +1,131 @@
function loadLoader() {
window.ModLoader = function ModLoader(ModsArr) {
if (!window.eaglerMLoaderMainRun) {
var searchParams = new URLSearchParams(location.search);
searchParams.getAll("Mod").forEach((ModToAdd) => {
console.log(
"EaglerML: Adding Mod to loadlist from search params: " + ModToAdd
);
ModsArr.push(ModToAdd);
});
if (
!!eaglercraftXOpts &&
!!eaglercraftXOpts.Mods &&
Array.isArray(eaglercraftXOpts.Mods)
) {
eaglercraftXOpts.Mods.forEach((ModToAdd) => {
console.log(
"EaglerML: Adding Mod to loadlist from eaglercraftXOpts: " +
ModToAdd
);
ModsArr.push(ModToAdd);
});
}
window.eaglerMLoaderMainRun = true;
}
if (window.noLoadMods === true) {
ModsArr.splice(0, ModsArr.length);
}
function checkModsLoaded(totalLoaded, identifier) {
console.log(
"EaglerML: Checking if Mods are finished :: " +
totalLoaded +
"/" +
ModsArr.length
);
if (totalLoaded >= ModsArr.length) {
clearInterval(identifier);
window.ModGracePeriod = false;
if (
window.eaglerMLoaderMainRun &&
ModAPI &&
ModAPI.events &&
ModAPI.events.callEvent
) {
ModAPI.events.callEvent("load", {});
}
console.log(
"EaglerML: Checking if Mods are finished :: All Mods loaded! Grace period off."
);
}
}
function methodB(currentMod) {
try {
console.log("EaglerML: Loading " + currentMod + " via method B.");
var script = document.createElement("script");
script.src = currentMod;
script.setAttribute("data-Mod", currentMod);
script.setAttribute("data-isMod", true);
script.onerror = () => {
console.log(
"EaglerML: Failed to load " + currentMod + " via method B!"
);
script.remove();
totalLoaded++;
};
script.onload = () => {
console.log(
"EaglerML: Successfully loaded " + currentMod + " via method B."
);
totalLoaded++;
};
document.body.appendChild(script);
} catch (error) {
console.log(
"EaglerML: Oh no! The Mod " + currentMod + " failed to load!"
);
totalLoaded++;
}
}
window.ModGracePeriod = true;
var totalLoaded = 0;
var loaderCheckInterval = null;
ModsArr.forEach((c) => {
let currentMod = c;
console.log("EaglerML: Starting " + currentMod);
try {
var req = new XMLHttpRequest();
req.open("GET", currentMod);
req.onload = function xhrLoadHandler() {
console.log("EaglerML: Loading " + currentMod + " via method A.");
var script = document.createElement("script");
try {
script.src =
"data:text/javascript," + encodeURIComponent(req.responseText);
} catch (error) {
methodB(currentMod);
return;
}
script.setAttribute("data-Mod", currentMod);
script.setAttribute("data-isMod", true);
script.onerror = () => {
console.log(
"EaglerML: Failed to load " + currentMod + " via method A!"
);
script.remove();
totalLoaded++;
};
script.onload = () => {
console.log(
"EaglerML: Successfully loaded " + currentMod + " via method A."
);
totalLoaded++;
};
document.body.appendChild(script);
};
req.onerror = function xhrErrorHandler() {
methodB(currentMod);
};
req.send();
} catch (error) {
methodB(currentMod);
}
});
loaderCheckInterval = setInterval(() => {
checkModsLoaded(totalLoaded, loaderCheckInterval);
}, 500);
console.log(
"EaglerML: Starting to load " + ModsArr.length + " Mods..."
);
};
}

View File

@ -36,6 +36,433 @@ Compile it yourself here: https://gitlab.com/lax1dude/eaglercraftx-1.8/
<meta property="og:title" content="EaglercraftX 1.8 Offline" />
<meta property="og:description" content="this file is not a website, whoever uploaded it to this URL is a dumbass" />
<script type="text/javascript">
function initAPI(version) {
var ModAPI = {};
ModAPI.events = {};
ModAPI.events.types = ["event"];
ModAPI.events.listeners = { "event": [] };
ModAPI.globals = {};
ModAPI.addEventListener = function AddEventListener(name, callback) {
if (!callback) {
throw new Error("Invalid callback!");
}
if (ModAPI.events.types.includes(name)) {
if (!Array.isArray(ModAPI.events.listeners[name])) {
ModAPI.events.listeners[name] = [];
}
ModAPI.events.listeners[name].push(callback);
console.log("Added new event listener.");
} else {
throw new Error("This event does not exist!");
}
};
ModAPI.removeEventListener = function removeEventListener(name, func, slow) {
if (!func) {
throw new Error("Invalid callback!");
}
if (!Array.isArray(ModAPI.events.listeners[name])) {
ModAPI.events.listeners[name] = [];
}
var targetArr = ModAPI.events.listeners[name];
if (!slow) {
if (targetArr.indexOf(func) !== -1) {
targetArr.splice(targetArr.indexOf(func), 1);
console.log("Removed event listener.");
}
} else {
var functionString = func.toString();
targetArr.forEach((f, i) => {
if (f.toString() === functionString) {
targetArr.splice(i, 1);
console.log("Removed event listener.");
}
});
}
};
ModAPI.events.newEvent = function newEvent(name) {
ModAPI.events.types.push(name);
};
ModAPI.events.callEvent = function callEvent(name, data) {
if (
!ModAPI.events.types.includes(name) ||
!Array.isArray(ModAPI.events.listeners[name])
) {
if (!Array.isArray(ModAPI.events.listeners[name])) {
if (ModAPI.events.types.includes(name)) {
ModAPI.events.listeners.event.forEach((func) => {
func({ event: name, data: data });
});
return;
}
return;
}
console.error(
"The ModAPI has been called with an invalid event name: " + name
);
console.error("Please report this bug to the repo.");
return;
}
ModAPI.events.listeners[name].forEach((func) => {
func(data);
});
ModAPI.events.listeners.event.forEach((func) => {
func({ event: name, data: data });
});
ModAPI.globals._initUpdate();
};
ModAPI.updateComponent = function updateComponent(component) {
if (
typeof component !== "string" ||
ModAPI[component] === null ||
ModAPI[component] === undefined
) {
return;
}
if (!ModAPI.globals || !ModAPI.globals.onGlobalsUpdate) {
return;
}
if (!ModAPI.globals.toUpdate) {
ModAPI.globals.toUpdate = [];
}
if (ModAPI.globals.toUpdate.indexOf(component) === -1) {
ModAPI.globals.toUpdate.push(component);
}
};
ModAPI.require = function require(component) {
if (typeof component !== "string") {
return;
}
if (!ModAPI.globals || !ModAPI.globals.onRequire) {
return;
}
ModAPI.globals.onRequire(component);
};
ModAPI.globals._initUpdate = function _initUpdate() {
if (!ModAPI.globals.toUpdate) {
ModAPI.globals.toUpdate = [];
}
ModAPI.globals.toUpdate.forEach((id) => {
ModAPI.globals.onGlobalsUpdate(id);
});
ModAPI.globals.toUpdate = [];
};
window.ModAPI = ModAPI;
}
</script>
<script type="text/javascript">
function loadLoader() {
window.ModLoader = function ModLoader(ModsArr) {
if (!window.eaglerMLoaderMainRun) {
var searchParams = new URLSearchParams(location.search);
searchParams.getAll("Mod").forEach((ModToAdd) => {
console.log(
"EaglerML: Adding Mod to loadlist from search params: " + ModToAdd
);
ModsArr.push(ModToAdd);
});
if (
!!eaglercraftXOpts &&
!!eaglercraftXOpts.Mods &&
Array.isArray(eaglercraftXOpts.Mods)
) {
eaglercraftXOpts.Mods.forEach((ModToAdd) => {
console.log(
"EaglerML: Adding Mod to loadlist from eaglercraftXOpts: " +
ModToAdd
);
ModsArr.push(ModToAdd);
});
}
window.eaglerMLoaderMainRun = true;
}
if (window.noLoadMods === true) {
ModsArr.splice(0, ModsArr.length);
}
function checkModsLoaded(totalLoaded, identifier) {
console.log(
"EaglerML: Checking if Mods are finished :: " +
totalLoaded +
"/" +
ModsArr.length
);
if (totalLoaded >= ModsArr.length) {
clearInterval(identifier);
window.ModGracePeriod = false;
if (
window.eaglerMLoaderMainRun &&
ModAPI &&
ModAPI.events &&
ModAPI.events.callEvent
) {
ModAPI.events.callEvent("load", {});
}
console.log(
"EaglerML: Checking if Mods are finished :: All Mods loaded! Grace period off."
);
}
}
function methodB(currentMod) {
try {
console.log("EaglerML: Loading " + currentMod + " via method B.");
var script = document.createElement("script");
script.src = currentMod;
script.setAttribute("data-Mod", currentMod);
script.setAttribute("data-isMod", true);
script.onerror = () => {
console.log(
"EaglerML: Failed to load " + currentMod + " via method B!"
);
script.remove();
totalLoaded++;
};
script.onload = () => {
console.log(
"EaglerML: Successfully loaded " + currentMod + " via method B."
);
totalLoaded++;
};
document.body.appendChild(script);
} catch (error) {
console.log(
"EaglerML: Oh no! The Mod " + currentMod + " failed to load!"
);
totalLoaded++;
}
}
window.ModGracePeriod = true;
var totalLoaded = 0;
var loaderCheckInterval = null;
ModsArr.forEach((c) => {
let currentMod = c;
console.log("EaglerML: Starting " + currentMod);
try {
var req = new XMLHttpRequest();
req.open("GET", currentMod);
req.onload = function xhrLoadHandler() {
console.log("EaglerML: Loading " + currentMod + " via method A.");
var script = document.createElement("script");
try {
script.src =
"data:text/javascript," + encodeURIComponent(req.responseText);
} catch (error) {
methodB(currentMod);
return;
}
script.setAttribute("data-Mod", currentMod);
script.setAttribute("data-isMod", true);
script.onerror = () => {
console.log(
"EaglerML: Failed to load " + currentMod + " via method A!"
);
script.remove();
totalLoaded++;
};
script.onload = () => {
console.log(
"EaglerML: Successfully loaded " + currentMod + " via method A."
);
totalLoaded++;
};
document.body.appendChild(script);
};
req.onerror = function xhrErrorHandler() {
methodB(currentMod);
};
req.send();
} catch (error) {
methodB(currentMod);
}
});
loaderCheckInterval = setInterval(() => {
checkModsLoaded(totalLoaded, loaderCheckInterval);
}, 500);
console.log(
"EaglerML: Starting to load " + ModsArr.length + " Mods..."
);
};
}
</script>
<script type="text/javascript">
function displayGui() {
function gui() {
if (document.querySelector("#eaglerpl_gui")) {
document.querySelector("#eaglerpl_gui").remove();
}
localStorage.setItem(
"ml::Mods",
localStorage.getItem("ml::Mods") || "[]"
);
try {
localStorage.setItem(
"ml::Mods",
JSON.stringify(JSON.parse(localStorage.getItem("ml::Mods")))
);
} catch (error) {
localStorage.setItem("ml::Mods", "[]");
}
var Mods = JSON.parse(localStorage.getItem("ml::Mods"));
var container = document.createElement("div");
container.id = "eaglerpl_gui";
container.style = `width:100%; height: 100%; position: fixed; top: 0; left: 0; z-index: 10; color: white; font-family: Minecraftia, sans-serif; overflow-y: scroll; overflow-x: hidden; background-image: url(data:image/png;base64,UklGRhoBAABXRUJQVlA4TA0BAAAvn8AnAIWjtpEECdnA2N0DsTROy7xUqfrWw0jbyLkJKTz0+I20jTT/Bo89e1YR/Wfktm0Y+wNKLobT7QP/n/B7Z/naW26QHoTpHB7LFouyKHlzeHxfCStSuj9KdbC8z1IJ5iWiyQed48vtYJ+lUu0t4VwranS1XMIutSiLYlbb8G54uf2p3VPSfRZtSrlsPFjOzZZrd/us3B3uK+HcHJQql+xbLMrS/WqNpm6DeZ/VIPVYaN/KzUbp91nd9xl5pYu50dU2W417nbdTj5l2Ne92uM9qXNpyf6+oXkabHKXaZ1HS4Iaqpim+1KIJ+0M49/LjNbTGP5mrrMZEuc7Uzcb1ViOJ6TuOt4NGJs+zDgA=); background-color: rgb(60,60,60); background-blend-mode: multiply; background-size: 64px;`;
var title = document.createElement("h1");
title.style = "text-shadow: 0px 0px 4px;";
title.innerHTML = "Mod Manager";
var closeButton = document.createElement("a");
closeButton.style = `margin-left: 2rem; color: red;`;
closeButton.href = "javascript:void(0)";
closeButton.addEventListener("click", () => {
document.querySelector("#eaglerpl_gui").remove();
});
closeButton.innerHTML = "[X]";
title.appendChild(closeButton);
container.appendChild(title);
var warningPoster = document.createElement("p");
warningPoster.style = "font-size: 0.8rem; color: orangered;";
warningPoster.innerHTML =
"Warning: Installing Mods gives them full control over the game. Be cautious when installing them.<br>Mods that have been removed also need a reload to stop running in the background.";
container.appendChild(warningPoster);
var tipPoster = document.createElement("p");
tipPoster.style = "font-size: 0.8rem; color: yellow;";
tipPoster.innerHTML =
"Tip: if the mods say that they failed loading, try refreshing the gui";
container.appendChild(tipPoster);
var table = document.createElement("table");
table.style = "table-layout: fixed; width: 100%";
var headerRow = document.createElement("tr");
headerRow.style = "background: rgb(50,50,50);";
var urlBox = document.createElement("th");
urlBox.style = "text-align: center;";
urlBox.innerHTML = "URL";
headerRow.appendChild(urlBox);
var statusBox = document.createElement("th");
statusBox.style = "text-align: center; width: 15%;";
statusBox.innerHTML = "Status";
headerRow.appendChild(statusBox);
table.appendChild(headerRow);
Mods.forEach((url) => {
var row = document.createElement("tr");
row.style = `box-shadow: 0px 2px 0px grey;`;
var urlBox = document.createElement("td");
urlBox.style = "user-select: text;";
var textWrapper = document.createElement("div");
textWrapper.style = `max-width: 100%; overflow-wrap: anywhere; max-height: 3rem; overflow-y: scroll;`;
textWrapper.innerText = url;
urlBox.append(textWrapper);
row.appendChild(urlBox);
var statusBox = document.createElement("td");
statusBox.innerHTML = ((curl) => {
var targs = document.querySelectorAll("script[data-Mod]");
for (let i = 0; i < targs.length; i++) {
const elem = targs[i];
if (elem.getAttribute("data-Mod") === curl) {
return "LOADED";
}
}
return "FAILED";
})(url);
switch (statusBox.innerHTML) {
case "LOADED":
statusBox.style = "background-color: green; text-align: center;";
break;
case "FAILED":
statusBox.style = "background-color: dimgrey; text-align: center;";
break;
default:
break;
}
var binBtn = document.createElement("button");
binBtn.style =
"background: transparent; text-align: center; color: yellow; cursor: pointer; font-family: 'Minecraftia', sans-serif; text-decoration: underline; border: 0; margin-left: 1rem; font-size: 1rem;";
binBtn.innerHTML = "[X]";
binBtn.addEventListener("click", () => {
if (!window.confirm("Delete Mod?") || Mods.indexOf(url) === -1) {
return;
}
Mods.splice(Mods.indexOf(url), 1);
localStorage.setItem("ml::Mods", JSON.stringify(Mods));
gui();
});
statusBox.appendChild(binBtn);
row.appendChild(statusBox);
table.appendChild(row);
});
var addBtn = document.createElement("button");
addBtn.style =
"background: transparent; text-align: center; color: yellow; cursor: pointer; font-family: 'Minecraftia', sans-serif; text-decoration: underline; border: 0; margin-right: 1rem; font-size: 1rem;";
addBtn.innerHTML = "Add new";
addBtn.addEventListener("click", () => {
var newMod = window.prompt("URL of Mod: ", "http://example.com/example.js");
Mods.push(
newMod
);
localStorage.setItem("ml::Mods", JSON.stringify(Mods));
if(window.ModLoader){
ModLoader([newMod]);
}
gui();
});
var uploadBtn = document.createElement("button");
uploadBtn.style =
"background: transparent; text-align: center; color: yellow; cursor: pointer; font-family: 'Minecraftia', sans-serif; text-decoration: underline; border: 0; font-size: 1rem;";
uploadBtn.innerHTML = "Upload...";
uploadBtn.addEventListener("click", function uploadBtnListener() {
var filePicker = document.createElement("input");
filePicker.type = "file";
filePicker.accept = ".js";
filePicker.addEventListener("input", function onInput() {
if (filePicker.files[0]) {
var reader = new FileReader();
reader.addEventListener("load", function onModRead() {
var newMod = reader.result.replace(";base64", `;fs=${encodeURIComponent(filePicker.files[0].name) || "unknown"};base64`);
Mods.push(newMod);
localStorage.setItem("ml::Mods", JSON.stringify(Mods));
if(window.ModLoader){
ModLoader([newMod]);
}
gui();
});
reader.readAsDataURL(filePicker.files[0]);
}
});
filePicker.click();
});
container.appendChild(table);
container.appendChild(addBtn);
container.appendChild(uploadBtn);
var notice = document.createElement("a");
notice.innerHTML = "Refresh GUI";
notice.href = "javascript:void(0)";
notice.addEventListener("click", function reloadListener() {
setTimeout(gui, 500);
this.remove();
});
notice.style =
"color: yellow; display: block; margin-top: 2rem; width: 0; white-space: nowrap;";
container.appendChild(notice);
//ModAPI.events.callEvent("gui", {});
document.body.appendChild(container);
}
gui();
}
</script>
<script type="text/javascript">
"use strict";
const relayId = Math.floor(Math.random() * 3);

View File

@ -5,12 +5,15 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="description" content="EaglercraftX 1.8 test directory HTML page" />
<meta name="keywords" content="eaglercraft, eaglercraftx, minecraft, 1.8, 1.8.8" />
<title>EaglercraftX 1.8</title>
<title>EaglerForge prerelease</title>
<meta property="og:locale" content="en-US" />
<meta property="og:type" content="website" />
<meta property="og:title" content="EaglercraftX 1.8" />
<meta property="og:description" content="test directory HTML page" />
<link type="image/png" rel="shortcut icon" href="favicon.png" />
<script type="text/javascript" src="ModAPI.js"></script>
<script type="text/javascript" src="ModLoader.js"></script>
<script type="text/javascript" src="ModGUI.js"></script>
<script type="text/javascript" src="classes.js"></script>
<script type="text/javascript">
"use strict";

View File

@ -576,7 +576,7 @@ public class PlatformInput {
lockKeys();
lockKeys = true;
}
requestFullscreen(canvas);
requestFullscreenonbody();
}
}
@ -599,6 +599,9 @@ public class PlatformInput {
@JSBody(params = { "element" }, script = "element.requestFullscreen();")
private static native void requestFullscreen(HTMLElement element);
@JSBody(params = { }, script = "let gamebody = document.getElementById('game_frame');\n" + "gamebody.requestFullscreen();")
private static native void requestFullscreenonbody();
public static void showCursor(EnumCursorType cursor) {
switch(cursor) {
case DEFAULT: