Archive eaglerforge-injector (tool, 1.8.8, clean-with-notes)
This commit is contained in:
@@ -0,0 +1,46 @@
|
|||||||
|
{
|
||||||
|
"slug": "eaglerforge-injector",
|
||||||
|
"name": "EaglerForge Injector",
|
||||||
|
"category": "tool",
|
||||||
|
"mc_version": "1.8.8",
|
||||||
|
"author": "EaglerForge Team",
|
||||||
|
"license": "MIT",
|
||||||
|
"upstream_ref": "main",
|
||||||
|
"sha256": "0b987a562fa5b9d03fbb50d370456d5720b48d5bc4e50db6405200989ef746e7",
|
||||||
|
"size": 5318436,
|
||||||
|
"storage": {
|
||||||
|
"git_path": null,
|
||||||
|
"fs_url": null
|
||||||
|
},
|
||||||
|
"play": {
|
||||||
|
"sandbox_url": "https://play-archive.eaglercraft.tech/eaglerforge-injector/",
|
||||||
|
"sandbox_attr": "allow-scripts allow-downloads",
|
||||||
|
"network_notes": "Client-side mod injector running entirely in browser"
|
||||||
|
},
|
||||||
|
"sources": [
|
||||||
|
{
|
||||||
|
"url": "https://github.com/eaglerforge/EaglerForgeInjector",
|
||||||
|
"retrieved_at": "2026-11-28T03:10:30Z",
|
||||||
|
"type": "upstream",
|
||||||
|
"notes": "Source repository on GitHub"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"url": "https://eaglerforge.github.io/EaglerForgeInjector/",
|
||||||
|
"retrieved_at": "2026-11-28T03:10:30Z",
|
||||||
|
"type": "other",
|
||||||
|
"notes": "Live web-based injector application on GitHub Pages"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"vetting": {
|
||||||
|
"verdict": "clean-with-notes",
|
||||||
|
"tools": [
|
||||||
|
"vet-static.mjs",
|
||||||
|
"virustotal-hash",
|
||||||
|
"static-code-review"
|
||||||
|
],
|
||||||
|
"date": "2026-11-28",
|
||||||
|
"notes": "Mod loader/injector by design: injects <script> tags and fetches mods in core/modloader.js:178,215,217 with indexedDB ('EF_MODS'), uses new Function for runtime patching in core/postinit.js:493,945,1036 and examplemods/lib.customitems.js:106-112; includes babel.min.js and filesaver.min.js. [vet-claude] Confirmed: mod loader by design (dynamic script injection / new Function / fetch of user-supplied mods) - arbitrary-code capability but no hardcoded remote endpoints; example mods only fetch data: URIs. Only load trusted mods.",
|
||||||
|
"reviewer": "vet-gemini + vet-claude"
|
||||||
|
},
|
||||||
|
"large_files_omitted_from_git": []
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
# EaglerForge Injector
|
||||||
|
|
||||||
|
Modding API injector tool for vanilla EaglercraftX builds. Enables injecting client mods into unminified offline HTML downloads directly in the browser or via CLI/Node.js.
|
||||||
|
|
||||||
|
- **Archive page:** https://archive.eaglercraft.tech/entries/eaglerforge-injector.html
|
||||||
|
- **Play:** https://play-archive.eaglercraft.tech/eaglerforge-injector/
|
||||||
|
- **MC Version:** 1.8.8
|
||||||
|
- **Author:** EaglerForge Team
|
||||||
|
- **License:** MIT
|
||||||
|
- **SHA-256:** `0b987a562fa5b9d03fbb50d370456d5720b48d5bc4e50db6405200989ef746e7`
|
||||||
|
- **Vetting:** clean-with-notes (2026-11-28)
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
node_modules
|
||||||
|
EaglercraftX_1.8_Offline_en_US.html
|
||||||
|
processed.html
|
||||||
|
1.12.html
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
MIT License
|
||||||
|
|
||||||
|
Copyright (c) 2024 Eagler Forge
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
1. Non-Commercial Use Only
|
||||||
|
The Software and any Derivative Works may not be sold, licensed, or otherwise used for commercial purposes. This includes, but is not limited to, charging money for access, selling within an app or game, and monetizing through advertising or tracking.
|
||||||
|
|
||||||
|
2. No Advertising or Tracking
|
||||||
|
The Software and any Derivative Works must not contain any form of advertising, user tracking, or data collection for monetization purposes.
|
||||||
|
|
||||||
|
3. No Misleading Representation
|
||||||
|
You may not misrepresent the origin of the Software or Derivative Works. You must not imply that your use or distribution is endorsed by the original author(s) unless you have explicit written permission.
|
||||||
|
|
||||||
|
4. Attribution Required
|
||||||
|
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software and any Derivative Works.
|
||||||
|
|
||||||
|
5. The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
# EaglerForgeInjector
|
||||||
|
An advanced modding API injector for unminified, unobfuscated, unsigned eaglercraft builds.
|
||||||
|
Current features:
|
||||||
|
- Method hooking/monkey patching
|
||||||
|
- Reflection
|
||||||
|
- Custom classes
|
||||||
|
- Modify the dedicated server
|
||||||
|
|
||||||
|
### How to use:
|
||||||
|
#### Online
|
||||||
|
Go to https://eaglerforge.github.io/EaglerForgeInjector/ and upload an unminified, unobfuscated, unsigned EaglercraftX offline download.
|
||||||
|
|
||||||
|
#### Portable Offline
|
||||||
|
Download this repository as a .zip, and extract it. Open index.html with your preferred browser (use `ctrl` + `O` on a new tab) and upload an unminified, unobfuscated, unsigned EaglercraftX offline download.
|
||||||
|
|
||||||
|
#### Offline CLI
|
||||||
|
- Clone the repository and run `npm ci` to install the required libraries.
|
||||||
|
- In the project directory, run `npm run efi /help` for use instructions.
|
||||||
|
- This is good for bypassing browser memory limitations, for minifying.
|
||||||
|
- Yes, I am forcing DOS command syntax upon you
|
||||||
|
|
||||||
|
#### npx command
|
||||||
|
- Run `npm install -g eaglerforgeinjector` to install eaglerforgeinjector.
|
||||||
|
- Run `npx efi /help` for use instructions.
|
||||||
|
|
||||||
|
#### How does it work?
|
||||||
|
This tool matches patterns in eaglercraft builds and adds patching code to let you modify how the code works at runtime. It then adds a [corelib](./core/postinit.js) that initialises the `ModAPI` object.
|
||||||
|
|
||||||
|
#### History
|
||||||
|
EaglerForgeInjector is a replacement for the `ModAPI` in the [old eaglerforge](https://github.com/EaglerForge/EaglerForge-old), which was maintained by @radmanplays. The legacy eaglerforge was a port of [Leah Anderson's EaglerReborn (dmca'd)](https://github.com/EaglerReborn/reborn)'s `PluginAPI` (created by me, @ZXMushroom63) to run on newer versions of Eaglercraft, with a few improvements and new features. Unlike EaglerForgeInjector, both legacy eaglerforge and eaglerreborn manually exposed properties and methods one by one.
|
||||||
|
|
||||||
|
## Discord server
|
||||||
|
[https://discord.gg/rbxN7kby5W](https://discord.gg/rbxN7kby5W)
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
var backgroundLogs = document.createElement("div");
|
||||||
|
backgroundLogs.style = `
|
||||||
|
color: lime;
|
||||||
|
opacity: 0.1;
|
||||||
|
font-family: monospace;
|
||||||
|
position: fixed;
|
||||||
|
top: 0;
|
||||||
|
left: 0;
|
||||||
|
width: 100vw;
|
||||||
|
height: 100vh;
|
||||||
|
z-index: -1;
|
||||||
|
pointer-events: none;
|
||||||
|
overflow: none;
|
||||||
|
user-select: none;
|
||||||
|
`;
|
||||||
|
const bgLogsList = [];
|
||||||
|
document.documentElement.appendChild(backgroundLogs);
|
||||||
|
var dirty = true;
|
||||||
|
function backgroundLog(text, unSuppress) {
|
||||||
|
var linesExcess = backgroundLogs.scrollHeight - window.innerHeight;
|
||||||
|
for (i = 0; i < linesExcess; i++) {
|
||||||
|
bgLogsList.shift();
|
||||||
|
}
|
||||||
|
bgLogsList.push(text);
|
||||||
|
dirty = true;
|
||||||
|
if (!unSuppress) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
dirty = false;
|
||||||
|
backgroundLogs.innerText = bgLogsList.join("\n");
|
||||||
|
}
|
||||||
|
backgroundLog("Awaiting input...");
|
||||||
@@ -0,0 +1,50 @@
|
|||||||
|
document.querySelector("title").innerText = `EaglerForge Injector ${EFIConfig.ModAPIVersion}`;
|
||||||
|
document.querySelector("h1").innerText = `EaglerForge Injector ${EFIConfig.ModAPIVersion}`;
|
||||||
|
|
||||||
|
document.querySelector("#giveme").addEventListener("click", () => {
|
||||||
|
if (
|
||||||
|
!document.querySelector("input").files ||
|
||||||
|
!document.querySelector("input").files[0]
|
||||||
|
) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// @type File
|
||||||
|
var file = document.querySelector("input").files[0];
|
||||||
|
var fileType = file.name.split(".");
|
||||||
|
fileType = fileType[fileType.length - 1];
|
||||||
|
|
||||||
|
file.text().then(async (string) => {
|
||||||
|
var patchedFile = string;
|
||||||
|
|
||||||
|
EFIConfig.doServerExtras = false;
|
||||||
|
patchedFile = await patchClient(string, new DOMParser());
|
||||||
|
|
||||||
|
var blob = new Blob([patchedFile], { type: file.type });
|
||||||
|
saveAs(blob, "processed." + fileType);
|
||||||
|
backgroundLog("Saving file...", true);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
document.querySelector("#givemeserver").addEventListener("click", () => {
|
||||||
|
if (
|
||||||
|
!document.querySelector("input").files ||
|
||||||
|
!document.querySelector("input").files[0]
|
||||||
|
) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// @type File
|
||||||
|
var file = document.querySelector("input").files[0];
|
||||||
|
var fileType = file.name.split(".");
|
||||||
|
fileType = fileType[fileType.length - 1];
|
||||||
|
|
||||||
|
file.text().then(async (string) => {
|
||||||
|
var patchedFile = string;
|
||||||
|
|
||||||
|
EFIConfig.doServerExtras = true;
|
||||||
|
patchedFile = await patchClient(string, new DOMParser());
|
||||||
|
|
||||||
|
var blob = new Blob([patchedFile], { type: file.type });
|
||||||
|
saveAs(blob, "efserver." + fileType);
|
||||||
|
backgroundLog("Saving file...", true);
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -0,0 +1,55 @@
|
|||||||
|
#!/usr/bin/env node
|
||||||
|
const { DOMParser } = require("@xmldom/xmldom");
|
||||||
|
const fs = require("fs/promises");
|
||||||
|
const EFI = require("./core/core");
|
||||||
|
|
||||||
|
async function main() {
|
||||||
|
const args = process.argv.slice(2);
|
||||||
|
|
||||||
|
if (args.includes("/help") || args.length === 0) {
|
||||||
|
console.log("***************************");
|
||||||
|
console.log("* EaglerForgeInjector CLI *");
|
||||||
|
console.log("***************************");
|
||||||
|
console.log("");
|
||||||
|
console.log("> npx efi /help #shows this help text");
|
||||||
|
console.log("> npx efi my_unminified_file.html #does nothing");
|
||||||
|
console.log("> npx efi my_unminified_file.html /eaglerforge #injects eaglerforge");
|
||||||
|
console.log("> npx efi my_unminified_file.html /minify #minifies file");
|
||||||
|
console.log("> npx efi my_unminified_file.html /minify /minify_extras #minifies file with extra optimisations");
|
||||||
|
console.log("> npx efi my_unminified_file.html /eaglerforge /minify #minifies file and injects eaglerforge");
|
||||||
|
console.log("> npx efi my_unminified_file.html /server_extras #inject server hosting stuff");
|
||||||
|
console.log("> npx efi my_unminified_file.html output.html /eaglerforge /minify #minifies file and injects eaglerforge, write to file named output.html");
|
||||||
|
console.log("> npx efi my_unminified_file.html /verbose #much logging");
|
||||||
|
console.log("By default, output is written to processed.html");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const inputFile = args[0];
|
||||||
|
if (!inputFile) {
|
||||||
|
return console.error("No file provided!");
|
||||||
|
}
|
||||||
|
EFI.conf.doMinify = args.includes("/minify");
|
||||||
|
EFI.conf.doEaglerforge = args.includes("/eaglerforge");
|
||||||
|
EFI.conf.doServerExtras = args.includes("/server_extras");
|
||||||
|
EFI.conf.doMinifyPlus = args.includes("/minify_extras");
|
||||||
|
EFI.conf.verbose = args.includes("/verbose");
|
||||||
|
const string = await fs.readFile(inputFile, {encoding: 'utf-8'});
|
||||||
|
const bannedEscapeCodes = { //babel added support for every newline escape code in existence. browser javascript code can process these unescaped, but babel-cli can't
|
||||||
|
"\u2028": "\\u2028",
|
||||||
|
"\u0085": "\\u0085",
|
||||||
|
"\u2029": "\\u2029",
|
||||||
|
}
|
||||||
|
const res = await EFI.patchClient(
|
||||||
|
Object.entries(bannedEscapeCodes).reduce((acc, ent)=>acc.replaceAll(ent[0], ent[1]), string),
|
||||||
|
new DOMParser()
|
||||||
|
);
|
||||||
|
if (res) {
|
||||||
|
var output = args[1];
|
||||||
|
if (!output || !output.endsWith(".html")) {
|
||||||
|
output = "processed.html";
|
||||||
|
}
|
||||||
|
console.log("Writing to " + output);
|
||||||
|
await fs.writeFile(output, res);
|
||||||
|
console.log("Done!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
main();
|
||||||
@@ -0,0 +1,437 @@
|
|||||||
|
var assets = {
|
||||||
|
modapi_guikit: null,
|
||||||
|
modapi_postinit: null,
|
||||||
|
modapi_modloader: null,
|
||||||
|
PatchesRegistry: null,
|
||||||
|
EFServer: null,
|
||||||
|
minify: null
|
||||||
|
};
|
||||||
|
if (globalThis.process) {
|
||||||
|
assets.modapi_guikit = require("./modgui").modapi_guikit;
|
||||||
|
assets.modapi_postinit = require("./postinit").modapi_postinit;
|
||||||
|
assets.modapi_modloader = require("./modloader").modapi_modloader;
|
||||||
|
assets.PatchesRegistry = require("./patches").PatchesRegistry;
|
||||||
|
assets.EFServer = require("./efserver").EFServer;
|
||||||
|
assets.minify = require("./minify").minify;
|
||||||
|
} else {
|
||||||
|
assets.PatchesRegistry = PatchesRegistry;
|
||||||
|
assets.minify = minify;
|
||||||
|
assets.EFServer = EFServer;
|
||||||
|
assets.modapi_postinit = modapi_postinit;
|
||||||
|
assets.modapi_modloader = modapi_modloader;
|
||||||
|
assets.modapi_guikit = modapi_guikit;
|
||||||
|
}
|
||||||
|
var modapi_preinit = `globalThis.ModAPI ||= {};
|
||||||
|
ModAPI.hooks ||= {};
|
||||||
|
ModAPI.hooks.freezeCallstack = false;
|
||||||
|
ModAPI.hooks._rippedData ||= [];
|
||||||
|
ModAPI.hooks._rippedInterfaceMap ||= {};
|
||||||
|
ModAPI.hooks._teavm ||= {};
|
||||||
|
ModAPI.hooks._rippedConstructors ||= {};
|
||||||
|
ModAPI.hooks._rippedInternalConstructors ||= {};
|
||||||
|
ModAPI.hooks.methods ||= {};
|
||||||
|
ModAPI.hooks._rippedMethodTypeMap ||= {};
|
||||||
|
ModAPI.hooks._postInit ||= ()=>{};
|
||||||
|
ModAPI.hooks._rippedStaticProperties ||= {};
|
||||||
|
ModAPI.hooks._rippedStaticIndexer ||= {};
|
||||||
|
`;
|
||||||
|
var freezeCallstack = `if(ModAPI.hooks.freezeCallstack){return false};`;
|
||||||
|
const EFIConfig = {
|
||||||
|
ModAPIVersion: "v2.7.97", //also change in package.json
|
||||||
|
doEaglerforge: true,
|
||||||
|
verbose: false,
|
||||||
|
doServerExtras: false,
|
||||||
|
doMinify: false,
|
||||||
|
doMinifyPlus: false
|
||||||
|
}
|
||||||
|
if (globalThis.process) {
|
||||||
|
var backgroundLog = (x) => {
|
||||||
|
if (EFIConfig.verbose) {
|
||||||
|
console.log(x);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
var alert = console.error;
|
||||||
|
var confirm = console.warn;
|
||||||
|
}
|
||||||
|
function wait(ms) {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
setTimeout(() => { resolve(); }, ms);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
function _status(x) {
|
||||||
|
if (globalThis.process) {
|
||||||
|
return console.log(x);
|
||||||
|
}
|
||||||
|
backgroundLog(x, true);
|
||||||
|
document.querySelector("#status").innerText = x;
|
||||||
|
}
|
||||||
|
function entriesToStaticVariableProxy(entries, prefix, clinitList) {
|
||||||
|
prefix = prefix.replace(
|
||||||
|
"var ",
|
||||||
|
""
|
||||||
|
);
|
||||||
|
if (entries.length === 0) {
|
||||||
|
return `ModAPI.hooks._rippedStaticProperties[\`${prefix}\`]={};`;
|
||||||
|
}
|
||||||
|
if (clinitList.includes(prefix + "_$callClinit")) {
|
||||||
|
entries.push({
|
||||||
|
name: "$callClinit",
|
||||||
|
variable: prefix + "_$callClinit"
|
||||||
|
});
|
||||||
|
}
|
||||||
|
var getComponents = "";
|
||||||
|
entries.forEach((entry) => {
|
||||||
|
getComponents += `
|
||||||
|
case \`${entry.name}\`: return ${entry.variable};`;
|
||||||
|
});
|
||||||
|
getComponents += `
|
||||||
|
default: return Reflect.get(a,b,c);`
|
||||||
|
|
||||||
|
var setComponents = "";
|
||||||
|
entries.forEach((entry) => {
|
||||||
|
setComponents += `
|
||||||
|
case \`${entry.name}\`: ${entry.variable} = c; break;`;
|
||||||
|
});
|
||||||
|
setComponents += ` default: a[b]=c;`
|
||||||
|
/*/
|
||||||
|
|
||||||
|
ModAPI.hooks._rippedStaticIndexer[\`${prefix.replace(
|
||||||
|
"var ",
|
||||||
|
""
|
||||||
|
)}\`] = [${entries
|
||||||
|
.flatMap((x) => {
|
||||||
|
return '"' + x.name + '"';
|
||||||
|
})
|
||||||
|
.join(",")}];
|
||||||
|
/*/
|
||||||
|
var proxy = `ModAPI.hooks._rippedStaticProperties[\`${prefix.replace(
|
||||||
|
"var ",
|
||||||
|
""
|
||||||
|
)}\`] = new Proxy({${entries
|
||||||
|
.flatMap((x) => {
|
||||||
|
return '"' + x.name + '"';
|
||||||
|
})
|
||||||
|
.join(":null,") + (entries.length > 0 ? ":null" : "")
|
||||||
|
}}, {
|
||||||
|
get: function (a,b,c) {
|
||||||
|
switch (b) {
|
||||||
|
${getComponents}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
set: function (a,b,c) {
|
||||||
|
switch (b) {
|
||||||
|
${setComponents}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
});`;
|
||||||
|
return proxy;
|
||||||
|
}
|
||||||
|
async function processClasses(string, parser) {
|
||||||
|
_status("Running EaglerForgeInjector " + EFIConfig.ModAPIVersion);
|
||||||
|
if (string.includes("__eaglerforgeinjector_installation_flag__")) {
|
||||||
|
backgroundLog("Detected input containing EFI installation flag.", true);
|
||||||
|
return alert("this file already has EaglerForge injected in it, you nonce.\nif you're trying to update, you need a vanilla file.")
|
||||||
|
}
|
||||||
|
if (!string.includes("function nmc_Minecraft_startGame(")) {
|
||||||
|
backgroundLog("Detected invalid input.\nPlease ensure file is unsigned, unminified and unobfuscated.", true);
|
||||||
|
return alert("This file does not match the requirements for EaglerForgeInjector. (not unminified & unobfuscated). Check info.")
|
||||||
|
}
|
||||||
|
if (EFIConfig.doMinify) {
|
||||||
|
if (!confirm("The minify step is extremely slow, especially on lower-end devices, and can take upwards of 15 minutes.") && !module) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
backgroundLog("[MINIFY] Minify warning bypassed.");
|
||||||
|
if (globalThis.process) {
|
||||||
|
await wait(1000);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_status("Beginning patch process...");
|
||||||
|
await wait(50);
|
||||||
|
var patchedFile = string;
|
||||||
|
patchedFile = patchedFile.replaceAll(
|
||||||
|
`(function(root, module) {`,
|
||||||
|
`${modapi_preinit}
|
||||||
|
(function(root, module) {`
|
||||||
|
);
|
||||||
|
patchedFile = patchedFile.replaceAll(
|
||||||
|
`var main;(function(){`,
|
||||||
|
`${modapi_preinit}
|
||||||
|
var main;(function(){`
|
||||||
|
);
|
||||||
|
|
||||||
|
_status("Patching threads and reflect metadata...");
|
||||||
|
|
||||||
|
await wait(50);
|
||||||
|
patchedFile = patchedFile
|
||||||
|
.replace("\r", "")
|
||||||
|
.replace(
|
||||||
|
"var main;\n(function() {",
|
||||||
|
modapi_preinit + "var main;\n(function() {"
|
||||||
|
);
|
||||||
|
backgroundLog("[JSPATCH] Adding pre-init script");
|
||||||
|
patchedFile = patchedFile.replace(
|
||||||
|
/function \$rt_metadata\(data\)( ?){/gm,
|
||||||
|
`function $rt_metadata(data) {
|
||||||
|
/*/EaglerForge Client Patch/*/
|
||||||
|
ModAPI.hooks._rippedData.push(data);
|
||||||
|
/*/EaglerForge Client Patch/*/`
|
||||||
|
);
|
||||||
|
backgroundLog("[JSPATCH] Redirecting $rt_metadata to ModAPI.hooks._rippedData");
|
||||||
|
patchedFile = patchedFile.replaceAll(
|
||||||
|
`return thread != null && thread.isResuming()`,
|
||||||
|
(match) => {
|
||||||
|
return freezeCallstack + match;
|
||||||
|
}
|
||||||
|
);
|
||||||
|
backgroundLog("[JSPATCH] Freeze-callstack patch on TeaVMThread.isResuming()");
|
||||||
|
patchedFile = patchedFile.replaceAll(
|
||||||
|
`return thread != null && thread.isSuspending();`,
|
||||||
|
(match) => {
|
||||||
|
return freezeCallstack + match;
|
||||||
|
}
|
||||||
|
);
|
||||||
|
backgroundLog("[JSPATCH] Freeze-callstack patch on TeaVMThread.isSuspending()");
|
||||||
|
|
||||||
|
patchedFile = patchedFile.replaceAll(
|
||||||
|
`return $rt_currentNativeThread;`,
|
||||||
|
(match) => {
|
||||||
|
return (
|
||||||
|
`if(ModAPI.hooks.freezeCallstack){return {isResuming: ()=>{false}, isSuspending: ()=>{false}, push: (a)=>{}, pop: ()=>{console.warn("Frozen stack was popped, context is now unstable.")}}};` +
|
||||||
|
match
|
||||||
|
);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
backgroundLog("[JSPATCH] Freeze-callstack patch thread getter");
|
||||||
|
|
||||||
|
patchedFile = patchedFile.replaceAll("function TeaVMThread(", "globalThis.ModAPI.hooks.TeaVMThread = TeaVMThread;\nfunction TeaVMThread(");
|
||||||
|
|
||||||
|
_status("Getting clinit list...");
|
||||||
|
var clinitList = [...patchedFile.matchAll(/^[\t ]*function \S+?_\S+?_\$callClinit\(/gm)].map(x => x[0].replaceAll("function ", "").replaceAll("(", "").trim());
|
||||||
|
|
||||||
|
_status("Extracting constructors and methods...");
|
||||||
|
await wait(50);
|
||||||
|
|
||||||
|
const extractConstructorRegex =
|
||||||
|
/^\s*function (\S*?)__init_\d*?\((?!\$)/gm;
|
||||||
|
const extractConstructorFullNameRegex =
|
||||||
|
/function (\S*?)__init_[0-9]*/gm;
|
||||||
|
patchedFile = patchedFile.replaceAll(
|
||||||
|
extractConstructorRegex,
|
||||||
|
(match) => {
|
||||||
|
var fullName = match.match(extractConstructorFullNameRegex);
|
||||||
|
fullName = fullName[0].replace("function ", "");
|
||||||
|
return (
|
||||||
|
`ModAPI.hooks._rippedConstructors[\`${fullName}\`] = ${fullName};
|
||||||
|
` + match
|
||||||
|
);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
backgroundLog("-> Extract contructor 1");
|
||||||
|
|
||||||
|
const extractInternalConstructorRegex =
|
||||||
|
/^\s*function (\S*?)__init_\d*?\(\$this/gm; //same as extract constructor regex, but only allow $this as first argument
|
||||||
|
patchedFile = patchedFile.replaceAll(
|
||||||
|
extractInternalConstructorRegex,
|
||||||
|
(match) => {
|
||||||
|
var fullName = match.match(extractConstructorFullNameRegex);
|
||||||
|
fullName = fullName[0].replace("function ", "");
|
||||||
|
return (
|
||||||
|
`ModAPI.hooks._rippedInternalConstructors[\`${fullName}\`] = ${fullName};
|
||||||
|
` + match
|
||||||
|
);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
backgroundLog("-> Extract contructor 2");
|
||||||
|
|
||||||
|
const extractInstanceMethodRegex =
|
||||||
|
/^[\t ]*function \S+?_\S+?_\S+?\((\$this)?/gm; // /^[\t ]*function \S+?_\S+?_\S+?\(\$this/gm
|
||||||
|
const extractInstanceMethodFullNameRegex = /function (\S*?)\(/gm; // /function (\S*?)\(\$this/gm
|
||||||
|
patchedFile = patchedFile.replaceAll(
|
||||||
|
extractInstanceMethodRegex,
|
||||||
|
(match) => {
|
||||||
|
if (
|
||||||
|
match.includes("__init_") ||
|
||||||
|
match.includes("__clinit_") ||
|
||||||
|
match.includes("_$callClinit")
|
||||||
|
) {
|
||||||
|
return match;
|
||||||
|
}
|
||||||
|
var fullName = match.match(extractInstanceMethodFullNameRegex);
|
||||||
|
fullName = fullName[0].replace("function ", "").replace("(", "");
|
||||||
|
return (
|
||||||
|
`function ${fullName}(...args) {
|
||||||
|
return ModAPI.hooks.methods[\`${fullName}\`].apply(this, args);
|
||||||
|
}
|
||||||
|
ModAPI.hooks._rippedMethodTypeMap[\`${fullName}\`] = \`${match.endsWith("($this") ? "instance" : "static"
|
||||||
|
}\`;
|
||||||
|
ModAPI.hooks.methods[\`${fullName}\`]=` +
|
||||||
|
match.replace(fullName + "(", "(")
|
||||||
|
);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
backgroundLog("-> Extract instance methods");
|
||||||
|
backgroundLog("-> Expose instance methods");
|
||||||
|
|
||||||
|
var staticVariables = [
|
||||||
|
...patchedFile.matchAll(/var \S+?_\S+?_\S+? = /gm),
|
||||||
|
].flatMap((x) => {
|
||||||
|
return x[0];
|
||||||
|
}).filter(x => {
|
||||||
|
return (!x.includes("$_clinit_$")) && (!x.includes("$lambda$"))
|
||||||
|
});
|
||||||
|
backgroundLog("-> Extract static variables");
|
||||||
|
//Also stores classes from $rt_classWithoutFields(0)
|
||||||
|
patchedFile = patchedFile.replaceAll(
|
||||||
|
/var \S+?_\S+? = \$rt_classWithoutFields\(\S*?\);/gm,
|
||||||
|
function (match) {
|
||||||
|
var prefix = match.replaceAll(
|
||||||
|
/ = \$rt_classWithoutFields\(\S*?\);/gm,
|
||||||
|
""
|
||||||
|
);
|
||||||
|
var entries = [];
|
||||||
|
|
||||||
|
staticVariables.forEach((entry) => {
|
||||||
|
if (entry.startsWith(prefix)) {
|
||||||
|
var variableName = entry
|
||||||
|
.replace("var ", "")
|
||||||
|
.replace(" = ", "");
|
||||||
|
var segments = variableName.split("_");
|
||||||
|
segments.splice(0, 2);
|
||||||
|
var name = segments.join("_");
|
||||||
|
entries.push({
|
||||||
|
name: name,
|
||||||
|
variable: variableName,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
var proxy = entriesToStaticVariableProxy(entries, prefix, clinitList);
|
||||||
|
var shortPrefix = prefix.replace(
|
||||||
|
"var ",
|
||||||
|
""
|
||||||
|
);
|
||||||
|
return match + `ModAPI.hooks._rippedInterfaceMap[\`${shortPrefix}\`]=${shortPrefix};` + proxy;
|
||||||
|
}
|
||||||
|
);
|
||||||
|
//Edge cases. sigh
|
||||||
|
//Done: add support for static properties on classes with constructors like this: function nmcg_GuiMainMenu() {
|
||||||
|
backgroundLog("-> Expose static variables");
|
||||||
|
|
||||||
|
|
||||||
|
patchedFile = patchedFile.replaceAll(
|
||||||
|
/function [a-z]+?_([a-zA-Z0-9\$]+?)\(\) \{/gm,
|
||||||
|
(match) => {
|
||||||
|
var prefix = "var " + match.replace("function ", "").replace("() {", "");
|
||||||
|
var entries = [];
|
||||||
|
|
||||||
|
staticVariables.forEach((entry) => {
|
||||||
|
if (entry.startsWith(prefix)) {
|
||||||
|
var variableName = entry
|
||||||
|
.replace("var ", "")
|
||||||
|
.replace(" = ", "");
|
||||||
|
var segments = variableName.split("_");
|
||||||
|
segments.splice(0, 2);
|
||||||
|
var name = segments.join("_");
|
||||||
|
entries.push({
|
||||||
|
name: name,
|
||||||
|
variable: variableName,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
var proxy = entriesToStaticVariableProxy(entries, prefix, clinitList);
|
||||||
|
|
||||||
|
return proxy + "\n" + match;
|
||||||
|
}
|
||||||
|
);
|
||||||
|
_status("Extracting teavm internals...");
|
||||||
|
await wait(50);
|
||||||
|
patchedFile = patchedFile.replaceAll(
|
||||||
|
/function \$rt_\S+?\(/gm,
|
||||||
|
(match) => {
|
||||||
|
var name = match.replace("function ", "");
|
||||||
|
name = name.substring(0, name.length - 1);
|
||||||
|
return (
|
||||||
|
`ModAPI.hooks._teavm[\`${name}\`]=${name};
|
||||||
|
` + match
|
||||||
|
);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
_status("Applying bonus patches from patch registry...");
|
||||||
|
await wait(50);
|
||||||
|
patchedFile = assets.PatchesRegistry.patchFile(patchedFile);
|
||||||
|
|
||||||
|
if (EFIConfig.doMinify) {
|
||||||
|
_status("Shrinking file...");
|
||||||
|
await wait(50);
|
||||||
|
if (globalThis.process) {
|
||||||
|
let _minify = assets.minify;
|
||||||
|
patchedFile = await _minify(patchedFile, parser, EFIConfig);
|
||||||
|
} else {
|
||||||
|
patchedFile = await minify(patchedFile, parser, EFIConfig);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
_status("Injecting scripts...");
|
||||||
|
await wait(50);
|
||||||
|
// 1.12 check is using nleit_MainClass, because peyton felt like renaming stuff. annoying, but useful too ig
|
||||||
|
patchedFile = patchedFile.replace(
|
||||||
|
` id="game_frame">`,
|
||||||
|
` id="game_frame">
|
||||||
|
\<script id="modapi_patchesreg_events"\>${assets.PatchesRegistry.getEventInjectorCode()};\<\/script\>
|
||||||
|
\<script id="modapi_postinit"\>${assets.modapi_postinit.replace("__modapi_version_code__", EFIConfig.ModAPIVersion)}\<\/script\>
|
||||||
|
\<script id="modapi_modloader"\>${assets.modapi_modloader}\<\/script\>
|
||||||
|
\<script id="modapi_guikit"\>${assets.modapi_guikit}\<\/script\>
|
||||||
|
\<script id="modapi_postinit_data"\>globalThis.modapi_postinit = \`${assets.modapi_postinit.replaceAll("\\", "\\\\")}\`\<\/script\>
|
||||||
|
\<script id="libserverside"\>{"._|_libserverside_|_."}\<\/script\>
|
||||||
|
\<script id="__eaglerforgeinjector_installation_flag__"\>console.log("Thank you for using EaglerForge!");\<\/script\>`
|
||||||
|
);
|
||||||
|
backgroundLog("[HTML] Injecting script files");
|
||||||
|
patchedFile = patchedFile.replace(`<title>EaglercraftX`, `<title>EFI ${EFIConfig.ModAPIVersion} on`);
|
||||||
|
patchedFile = patchedFile.replace(`<title>Eaglercraft`, `<title>EFI ${EFIConfig.ModAPIVersion} on`);
|
||||||
|
|
||||||
|
backgroundLog("[HTML] Injecting title");
|
||||||
|
patchedFile = patchedFile.replaceAll(/main\(\);\s*?}/gm, (match) => {
|
||||||
|
return match.replace("main();", "main();ModAPI.hooks._postInit();");
|
||||||
|
});
|
||||||
|
backgroundLog("[HTML] Injecting main function");
|
||||||
|
|
||||||
|
_status("Done, awaiting input...");
|
||||||
|
await wait(50);
|
||||||
|
return patchedFile;
|
||||||
|
}
|
||||||
|
async function patchClient(string, parser) {
|
||||||
|
var patchedFile = string;
|
||||||
|
if (EFIConfig.doEaglerforge) {
|
||||||
|
patchedFile = await processClasses(patchedFile, parser);
|
||||||
|
} else if (EFIConfig.doMinify) {
|
||||||
|
patchedFile = await minify(patchedFile, parser, EFIConfig);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!patchedFile) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (EFIConfig.doServerExtras) {
|
||||||
|
patchedFile = patchedFile.replace(`{"._|_libserverside_|_."}`, `(${assets.EFServer.toString()})()`);
|
||||||
|
backgroundLog("[EFSERVER] Injecting libserverside corelib");
|
||||||
|
patchedFile = patchedFile.replace("<title>EFI", "<title>EF Server");
|
||||||
|
backgroundLog("[EFSERVER] Patching title");
|
||||||
|
} else {
|
||||||
|
patchedFile.replace(`{"._|_libserverside_|_."}`, "");
|
||||||
|
}
|
||||||
|
return patchedFile;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (globalThis.process) {
|
||||||
|
module.exports = {
|
||||||
|
patchClient: patchClient,
|
||||||
|
conf: EFIConfig
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,290 @@
|
|||||||
|
function EFServer() {
|
||||||
|
ModAPI.meta.title("Server Manager");
|
||||||
|
ModAPI.meta.version("a0");
|
||||||
|
ModAPI.meta.description("_");
|
||||||
|
ModAPI.meta.credits("ZXMushroom63 & radmanplays");
|
||||||
|
|
||||||
|
|
||||||
|
const gui = document.createElement("div");
|
||||||
|
gui.innerText = "EFSERVER CONSOLE";
|
||||||
|
gui.style.background = "black";
|
||||||
|
gui.style.fontFamily = "sans-serif";
|
||||||
|
gui.style.zIndex = 254;
|
||||||
|
gui.style.position = "fixed";
|
||||||
|
gui.style.display = "none";
|
||||||
|
gui.style.height = "calc(100vh - 1rem - 4px)";
|
||||||
|
gui.style.overflowY = "scroll";
|
||||||
|
gui.style.color = "white";
|
||||||
|
gui.style.top = gui.style.left = gui.style.bottom = gui.style.right = 0;
|
||||||
|
document.documentElement.appendChild(gui);
|
||||||
|
|
||||||
|
var cmdbox = document.createElement("input");
|
||||||
|
cmdbox.style.position = "absolute";
|
||||||
|
cmdbox.style.left = "0";
|
||||||
|
cmdbox.style.bottom = "0";
|
||||||
|
cmdbox.style.right = "0";
|
||||||
|
cmdbox.style.position = "inline-block";
|
||||||
|
cmdbox.style.border = "0";
|
||||||
|
cmdbox.style.borderTop = "2px solid white";
|
||||||
|
cmdbox.style.background = "black";
|
||||||
|
cmdbox.style.zIndex = 255;
|
||||||
|
cmdbox.style.color = "white";
|
||||||
|
cmdbox.style.height = "1rem";
|
||||||
|
cmdbox.type = "text";
|
||||||
|
cmdbox.addEventListener("keydown", (e) => {
|
||||||
|
e.stopPropagation();
|
||||||
|
e.stopImmediatePropagation();
|
||||||
|
}, true);
|
||||||
|
cmdbox.addEventListener("keyup", (e) => {
|
||||||
|
e.stopPropagation();
|
||||||
|
e.stopImmediatePropagation();
|
||||||
|
if (e.key === "Enter") {
|
||||||
|
e.preventDefault();
|
||||||
|
toServer("chat", cmdbox.value);
|
||||||
|
cmdbox.value = "";
|
||||||
|
}
|
||||||
|
}, true);
|
||||||
|
document.documentElement.appendChild(cmdbox);
|
||||||
|
|
||||||
|
function worldUpdate() {
|
||||||
|
if (ModAPI.mc && ModAPI.mc.theWorld) {
|
||||||
|
ModAPI.hooks.methods.nmcs_GameSettings_saveOptions = ()=>{};
|
||||||
|
ModAPI.settings.limitFramerate = 1;
|
||||||
|
ModAPI.settings.enableVsync = 0;
|
||||||
|
showgui();
|
||||||
|
openSharedWorld()
|
||||||
|
} else {
|
||||||
|
hidegui();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
setInterval(() => {
|
||||||
|
worldUpdate();
|
||||||
|
}, 100);
|
||||||
|
|
||||||
|
function showgui() {
|
||||||
|
gui.style.opacity = "1";
|
||||||
|
gui.style.display = "block";
|
||||||
|
cmdbox.style.opacity = "1";
|
||||||
|
cmdbox.style.display = "block";
|
||||||
|
}
|
||||||
|
function hidegui() {
|
||||||
|
gui.style.opacity = "0";
|
||||||
|
gui.style.display = "none";
|
||||||
|
cmdbox.style.opacity = "0";
|
||||||
|
cmdbox.style.display = "none";
|
||||||
|
}
|
||||||
|
|
||||||
|
function EFB2__defineExecCmdAsGlobal() {
|
||||||
|
var getServer = ModAPI.reflect.getClassById("net.minecraft.server.MinecraftServer").staticMethods.getServer.method;
|
||||||
|
globalThis.efb2__executeCommandAs = function efb2__executeCommandAs($commandsender, command, feedback) {
|
||||||
|
var server = getServer();
|
||||||
|
if (!server) { return };
|
||||||
|
var commandManager = server.$commandManager;
|
||||||
|
|
||||||
|
//lie a bit
|
||||||
|
var x = $commandsender.$canCommandSenderUseCommand;
|
||||||
|
$commandsender.$canCommandSenderUseCommand = () => 1;
|
||||||
|
|
||||||
|
var y = $commandsender.$sendCommandFeedback;
|
||||||
|
$commandsender.$sendCommandFeedback = feedback ? () => 1 : () => 0;
|
||||||
|
|
||||||
|
try {
|
||||||
|
commandManager.$executeCommand($commandsender, ModAPI.util.str(command));
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error);
|
||||||
|
}
|
||||||
|
|
||||||
|
$commandsender.$canCommandSenderUseCommand = x;
|
||||||
|
$commandsender.$sendCommandFeedback = y;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ModAPI.dedicatedServer.appendCode(EFB2__defineExecCmdAsGlobal);
|
||||||
|
|
||||||
|
ModAPI.hooks.methods.nmc_LoadingScreenRenderer_eaglerShow = ()=>{};
|
||||||
|
var opening = false;
|
||||||
|
function openSharedWorld() {
|
||||||
|
var platform = ModAPI.reflect.getClassById("net.lax1dude.eaglercraft.v1_8.internal.PlatformWebRTC");
|
||||||
|
if (!opening && ModAPI.mc.theWorld && !ModAPI.hooks.methods.nlevsl_LANServerController_isLANOpen()) {
|
||||||
|
platform.staticVariables.rtcLANServer = ModAPI.reflect.getClassById("net.lax1dude.eaglercraft.v1_8.internal.PlatformWebRTC$LANServer").constructors[0]();
|
||||||
|
var worldName = ModAPI.util.unstr(ModAPI.mc.thePlayer.getName().getRef()) + "'s World";
|
||||||
|
opening = true;
|
||||||
|
ModAPI.promisify(ModAPI.hooks.methods.nlevsl_LANServerController_shareToLAN)({
|
||||||
|
$accept: (status)=>{
|
||||||
|
gui.innerText += "\n" + ModAPI.util.ustr(status);
|
||||||
|
}
|
||||||
|
}, ModAPI.util.str(worldName), 0).then(code => {
|
||||||
|
opening = true; //change to false later
|
||||||
|
if (code != null) {
|
||||||
|
ModAPI.hooks.methods.nlevs_SingleplayerServerController_configureLAN(ModAPI.mc.playerController.currentGameType.getRef(), 0);
|
||||||
|
var msg = "code: " + ModAPI.util.ustr(code) + " relay: " + ModAPI.util.ustr(ModAPI.hooks.methods.nlevsl_LANServerController_getCurrentURI());
|
||||||
|
alert(msg);
|
||||||
|
gui.innerText += "\n" + msg;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
NETWORKING OPCODES
|
||||||
|
chat - bidirectional, send chat to server/client
|
||||||
|
*/
|
||||||
|
|
||||||
|
function toServer(opcode, data) {
|
||||||
|
client_comms_channel.postMessage({
|
||||||
|
opcode: opcode,
|
||||||
|
audience: "server",
|
||||||
|
data: data,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
var token = crypto.randomUUID();
|
||||||
|
const clientMessageHandlers = {
|
||||||
|
chat: function (data) {
|
||||||
|
if (gui.scrollHeight > (innerHeight * 5)) {
|
||||||
|
gui.innerText = "Console cleared. Logs were over 5 pages long.";
|
||||||
|
}
|
||||||
|
gui.innerText += "\n" + data.replaceAll("§r", "");
|
||||||
|
gui.scrollTop = gui.scrollHeight;
|
||||||
|
},
|
||||||
|
};
|
||||||
|
var client_comms_channel = new BroadcastChannel("efserv:" + token);
|
||||||
|
client_comms_channel.addEventListener("message", (ev) => {
|
||||||
|
if (ev.data.audience !== "client") {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (clientMessageHandlers[ev.data.opcode]) {
|
||||||
|
clientMessageHandlers[ev.data.opcode](ev.data.data);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
ModAPI.dedicatedServer.appendCode(
|
||||||
|
`globalThis.efhost_security_token = "${token}";`
|
||||||
|
);
|
||||||
|
ModAPI.dedicatedServer.appendCode(function () {
|
||||||
|
var comms = new BroadcastChannel(
|
||||||
|
"efserv:" + globalThis.efhost_security_token
|
||||||
|
);
|
||||||
|
|
||||||
|
function toClient(opcode, data) {
|
||||||
|
comms.postMessage({
|
||||||
|
opcode: opcode,
|
||||||
|
audience: "client",
|
||||||
|
data: data,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function getHostPlayer() {
|
||||||
|
var host = null;
|
||||||
|
ModAPI.server.getRef().$worldServers.data.forEach((world) => {
|
||||||
|
host ||= world.$playerEntities.$array1.data.find((player) => {
|
||||||
|
if (!player) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var nameKey = ModAPI.util.getNearestProperty(
|
||||||
|
player.$gameProfile,
|
||||||
|
"$name"
|
||||||
|
);
|
||||||
|
return ModAPI.util.ustr(player.$gameProfile[nameKey]) === "HOST";
|
||||||
|
});
|
||||||
|
});
|
||||||
|
return host;
|
||||||
|
}
|
||||||
|
|
||||||
|
const messageHandlers = {
|
||||||
|
chat: function (data) {
|
||||||
|
var host = getHostPlayer();
|
||||||
|
if (!host) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
host.$addChatMessage = (comp)=>{toClient("chat", ModAPI.util.ustr(comp.$getUnformattedText()))};
|
||||||
|
efb2__executeCommandAs(getHostPlayer(), data, true);
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
comms.addEventListener("message", (ev) => {
|
||||||
|
if (ev.data.audience !== "server") {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (messageHandlers[ev.data.opcode]) {
|
||||||
|
messageHandlers[ev.data.opcode](ev.data.data);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
var oldLog = ModAPI.hooks.methods.nlevl_Logger_log;
|
||||||
|
ModAPI.hooks.methods.nlevl_Logger_log = function (...args) {
|
||||||
|
toClient("chat", ModAPI.util.ustr(args[2]));
|
||||||
|
return oldLog.apply(this, args);
|
||||||
|
};
|
||||||
|
|
||||||
|
ModAPI.addEventListener("tick", ()=>{
|
||||||
|
var host = ModAPI.util.wrap(getHostPlayer());
|
||||||
|
if (!host) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
host.posY = -10;
|
||||||
|
host.posX = 0;
|
||||||
|
host.posZ = 0;
|
||||||
|
host.capabilities.disableDamage = 1;
|
||||||
|
host.capabilities.isCreativeMode = 1;
|
||||||
|
host.capabilities.isFlying = 1;
|
||||||
|
host.motionY = 0;
|
||||||
|
host.motionX = 0;
|
||||||
|
host.motionZ = 0;
|
||||||
|
host.isDead = 0;
|
||||||
|
host.setHealth(20);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function renameButton(array, originalName, newName) {
|
||||||
|
array.find(
|
||||||
|
(x) => ModAPI.util.ustr(x.displayString.getRef()) === originalName
|
||||||
|
).displayString = ModAPI.util.str(newName);
|
||||||
|
}
|
||||||
|
|
||||||
|
const mainmenuinit = ModAPI.hooks.methods.nmcg_GuiMainMenu_initGui;
|
||||||
|
ModAPI.hooks.methods.nmcg_GuiMainMenu_initGui = function (...args) {
|
||||||
|
var result = mainmenuinit.apply(this, args);
|
||||||
|
var wrappedGuiObject = ModAPI.util.wrap(args[0], args[0], false, false);
|
||||||
|
wrappedGuiObject.splashText = ModAPI.util.str("Server Hosting Mode");
|
||||||
|
var btnarray = wrappedGuiObject.buttonList.array1;
|
||||||
|
renameButton(btnarray, "Singleplayer", "Host Server");
|
||||||
|
|
||||||
|
return result;
|
||||||
|
};
|
||||||
|
|
||||||
|
const GuiSelectWorldinit = ModAPI.hooks.methods.nmcg_GuiSelectWorld_initGui;
|
||||||
|
ModAPI.hooks.methods.nmcg_GuiSelectWorld_initGui = function (...args) {
|
||||||
|
var result = GuiSelectWorldinit.apply(this, args);
|
||||||
|
var wrappedGuiObject = ModAPI.util.wrap(args[0], args[0], false, false);
|
||||||
|
var btnarray = wrappedGuiObject.buttonList.array1.data;
|
||||||
|
//renameButton(btnarray, "Create", "Create Server");
|
||||||
|
|
||||||
|
return result;
|
||||||
|
};
|
||||||
|
|
||||||
|
const mainmenuactions = ModAPI.hooks.methods.nmcg_GuiMainMenu_actionPerformed;
|
||||||
|
ModAPI.hooks.methods.nmcg_GuiMainMenu_actionPerformed = function (...args) {
|
||||||
|
ModAPI.hooks.methods.nlevp_EaglerProfile_setName(ModAPI.util.str("HOST"));
|
||||||
|
var idKey = ModAPI.util.getNearestProperty(args[1], "$id");
|
||||||
|
var guiButtonid = args[1][idKey];
|
||||||
|
var blockedIds = [2]; // put the blocked/disabled button ids in there
|
||||||
|
if (blockedIds.includes(guiButtonid)) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return mainmenuactions.apply(this, args);
|
||||||
|
};
|
||||||
|
|
||||||
|
// disable rendering
|
||||||
|
ModAPI.hooks.methods.nmcr_EntityRenderer_renderWorld = () => { };
|
||||||
|
}
|
||||||
|
|
||||||
|
if (globalThis.process) {
|
||||||
|
module.exports = {
|
||||||
|
EFServer: EFServer
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,72 @@
|
|||||||
|
if (!globalThis.Babel) {
|
||||||
|
globalThis.Babel = require("@babel/core");
|
||||||
|
}
|
||||||
|
function wait(ms) {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
setTimeout(() => { resolve(); }, ms);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
const MINIFY = function () {
|
||||||
|
return {
|
||||||
|
visitor: {
|
||||||
|
Identifier(path) {
|
||||||
|
if (path.node.name === "$ptr") {
|
||||||
|
path.node.name = "r";
|
||||||
|
}
|
||||||
|
if (path.node.name === "$tmp") {
|
||||||
|
path.node.name = "m";
|
||||||
|
}
|
||||||
|
if (path.node.name === "$thread") {
|
||||||
|
path.node.name = "t";
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}
|
||||||
|
};
|
||||||
|
};
|
||||||
|
async function minify(input, parser, EFIConfig) {
|
||||||
|
var _status = globalThis._status || console.log;
|
||||||
|
|
||||||
|
let isHtml = true;
|
||||||
|
let inputHtml = input;
|
||||||
|
|
||||||
|
if (!input.trim().startsWith('<')) {
|
||||||
|
isHtml = false;
|
||||||
|
inputHtml = `<script>${input}</script>`;
|
||||||
|
}
|
||||||
|
|
||||||
|
_status("[MINIFY] Parsing html...");
|
||||||
|
await wait(50);
|
||||||
|
const doc = parser.parseFromString(inputHtml, 'text/html');
|
||||||
|
const scriptTags = doc.getElementsByTagName('script');
|
||||||
|
await wait(200); //trying to get chrome to gc
|
||||||
|
for (let i = 0; i < scriptTags.length; i++) {
|
||||||
|
const scriptTag = scriptTags[i];
|
||||||
|
const code = scriptTag.textContent;
|
||||||
|
_status("[MINIFY] Transpiling script #" + (i + 1) + " of length " + Math.round(code.length / 1000) + "k...");
|
||||||
|
await wait(150);
|
||||||
|
|
||||||
|
|
||||||
|
const output = Babel.transform(code, {
|
||||||
|
plugins: EFIConfig.doMinifyPlus ? [
|
||||||
|
MINIFY()
|
||||||
|
] : []
|
||||||
|
});
|
||||||
|
scriptTag.textContent = output.code;
|
||||||
|
await wait(10);
|
||||||
|
}
|
||||||
|
|
||||||
|
_status("[MINIFY] Job complete!");
|
||||||
|
await wait(50);
|
||||||
|
|
||||||
|
if (isHtml) {
|
||||||
|
return globalThis.process ? doc.toString() : doc.documentElement.outerHTML;
|
||||||
|
} else {
|
||||||
|
return doc.querySelector('script').textContent;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (globalThis.process) {
|
||||||
|
module.exports = {
|
||||||
|
minify: minify
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,325 @@
|
|||||||
|
|
||||||
|
const modapi_guikit = "(" + (() => {
|
||||||
|
// ModAPI GUI made by TheIdiotPlays
|
||||||
|
// https://github.com/TheIdiotPlays
|
||||||
|
var splashes = [
|
||||||
|
"Now with A.I.D.S (automatically injected dedicated server)",
|
||||||
|
"Only causes death 90% of the time!",
|
||||||
|
"HTML is better.",
|
||||||
|
"https://github.com/EaglerForge",
|
||||||
|
"hey you should check out https://github.com/ZXMushroom63/scratch-gui",
|
||||||
|
"99% of people stop gambling before they win big.",
|
||||||
|
"Now with free estradiol!",
|
||||||
|
"Now with H.I.V (Hyper Injected Virtual-debugger)",
|
||||||
|
"asdasd",
|
||||||
|
"Star us on GitHub to support us! https://github.com/EaglerForge/EaglerForgeInjector"
|
||||||
|
];
|
||||||
|
var gui = `<div id="modapi_gui_container">
|
||||||
|
<header>
|
||||||
|
<h1 class="title">EaglerForge Mod Manager</h1>
|
||||||
|
<h4>
|
||||||
|
<!-- Now with with A.I.D.S. (automatically injected dedicated server)! -->
|
||||||
|
{splash_msg}
|
||||||
|
</h4>
|
||||||
|
<h5>
|
||||||
|
Warning: installing malicious mods can delete your worlds, ip-grab you, or even download more serious malware onto your computer. The EaglerForge developers are not liable for any damage caused by the use of EaglerForge and its related tools.
|
||||||
|
</h5>
|
||||||
|
</header>
|
||||||
|
|
||||||
|
<table id="modapi_gui_modTable">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<td>
|
||||||
|
Mod
|
||||||
|
</td>
|
||||||
|
<td class="nothing"></td>
|
||||||
|
<td>
|
||||||
|
Controls
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
|
||||||
|
<div class="controls">
|
||||||
|
<button class="button" onclick="window.modapi_uploadmod()">Upload Mod (.js)</button>
|
||||||
|
<button class="button" onclick="window.modapi_addmod()">Add Mod From URL</button>
|
||||||
|
<button class="button" style="text-shadow: 0px 0px 10px rgba(255, 0, 0, 0.5)" onclick="window.modapi_clearmods()">Clear All Mods</button>
|
||||||
|
<button class="button _doneButton" onclick="this.parentElement.parentElement.remove();">Done</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<span>(reload to apply changes)</span>
|
||||||
|
|
||||||
|
<footer>
|
||||||
|
<p>
|
||||||
|
GUI by <a href="https://github.com/TheIdiotPlays">TheIdiotPlays</a>
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
Modloader linker by
|
||||||
|
<a href="https://github.com/ZXMushroom63">ZXMushroom63</a>
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
API by <a href="https://github.com/ZXMushroom63">ZXMushroom63,</a> <a href="https://leah.chromebooks.lol">Leah Anderson,</a> and <a href="https://github.com/radmanplays">radmanplays</a>
|
||||||
|
</p>
|
||||||
|
</footer>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
#modapi_gui_container td:not(.nothing):not(:has(.button)) {
|
||||||
|
padding: 0.5rem 1.5rem;
|
||||||
|
margin: 0.5rem;
|
||||||
|
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
|
||||||
|
}
|
||||||
|
#modapi_gui_container td.nothing {
|
||||||
|
user-select: none;
|
||||||
|
opacity: 0;
|
||||||
|
width: 5rem;
|
||||||
|
}
|
||||||
|
#modapi_gui_container td {
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
#modapi_gui_container h4, #modapi_gui_container h5 {
|
||||||
|
padding-bottom: 0;
|
||||||
|
margin-bottom: 0;
|
||||||
|
}
|
||||||
|
#modapi_gui_container h5 {
|
||||||
|
color: white;
|
||||||
|
text-shadow: 0px 0px 10px rgba(255,0,0,0.5);
|
||||||
|
font-size: 0.75rem;
|
||||||
|
}
|
||||||
|
#modapi_gui_container a {
|
||||||
|
color: white;
|
||||||
|
transition: 1s;
|
||||||
|
}
|
||||||
|
#modapi_gui_container a:hover {
|
||||||
|
color: lightblue;
|
||||||
|
}
|
||||||
|
|
||||||
|
#modapi_gui_container {
|
||||||
|
overflow-y: scroll;
|
||||||
|
overflow-x: hidden;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: space-between;
|
||||||
|
height: 100vh;
|
||||||
|
width: 100vw;
|
||||||
|
position: fixed;
|
||||||
|
z-index: 127;
|
||||||
|
top: 0;
|
||||||
|
left: 0;
|
||||||
|
font-family: sans-serif;
|
||||||
|
background: white;
|
||||||
|
}
|
||||||
|
|
||||||
|
#modapi_gui_container header {
|
||||||
|
background-color: #333;
|
||||||
|
width: 100%;
|
||||||
|
padding: 1rem 0;
|
||||||
|
text-align: center;
|
||||||
|
color: white;
|
||||||
|
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
|
||||||
|
}
|
||||||
|
|
||||||
|
#modapi_gui_container .title {
|
||||||
|
font-size: 3rem;
|
||||||
|
margin: 0;
|
||||||
|
font-weight: 700;
|
||||||
|
text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5);
|
||||||
|
}
|
||||||
|
|
||||||
|
#modapi_gui_container .controls {
|
||||||
|
display: flex;
|
||||||
|
gap: 1rem;
|
||||||
|
margin-bottom: 2rem;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
justify-content: center;
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
#modapi_gui_container .button {
|
||||||
|
background-color: #555;
|
||||||
|
color: white;
|
||||||
|
padding: 12px 24px;
|
||||||
|
font-size: 1rem;
|
||||||
|
font-weight: 600;
|
||||||
|
border: none;
|
||||||
|
border-radius: 2px;
|
||||||
|
cursor: pointer;
|
||||||
|
transition: background-color 0.3s ease, transform 0.2s ease;
|
||||||
|
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
|
||||||
|
}
|
||||||
|
|
||||||
|
#modapi_gui_container .button:hover {
|
||||||
|
background-color: #777;
|
||||||
|
transform: translateY(-2px);
|
||||||
|
}
|
||||||
|
|
||||||
|
#modapi_gui_container footer {
|
||||||
|
width: 100%;
|
||||||
|
padding: 1rem;
|
||||||
|
background-color: #333;
|
||||||
|
text-align: center;
|
||||||
|
color: white;
|
||||||
|
font-size: 1.25rem;
|
||||||
|
box-shadow: 0 -4px 6px rgba(0, 0, 0, 0.1);
|
||||||
|
}
|
||||||
|
#modapi_gui_modTable {
|
||||||
|
min-width: 40vw;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</div>`;
|
||||||
|
|
||||||
|
async function fileToText(file) {
|
||||||
|
return new Promise((res, rej) => {
|
||||||
|
var fr = new FileReader();
|
||||||
|
fr.addEventListener("error", (e) => { rej(e); });
|
||||||
|
fr.addEventListener("load", (e) => { res(fr.result); });
|
||||||
|
fr.readAsText(file);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
window.modapi_displayModGui = async function (cb) {
|
||||||
|
if (!getMods) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (document.querySelector("#modapi_gui_container")) {
|
||||||
|
cb ||= document.querySelector("#modapi_gui_container")._cb;
|
||||||
|
document.querySelector("#modapi_gui_container").remove();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
var element = document.createElement("div");
|
||||||
|
|
||||||
|
element.innerHTML = gui.replace("{splash_msg}", splashes[Math.floor(Math.random() * splashes.length)]);
|
||||||
|
|
||||||
|
document.body.appendChild(element);
|
||||||
|
|
||||||
|
document.querySelector("#modapi_gui_container")._cb = cb;
|
||||||
|
|
||||||
|
var modsList = await getMods();
|
||||||
|
var tbody = document.querySelector("#modapi_gui_container #modapi_gui_modTable tbody");
|
||||||
|
tbody.innerHTML = "";
|
||||||
|
modsList.forEach((modtxt, i) => {
|
||||||
|
if (!modtxt) { return }
|
||||||
|
var hash = ModAPI.util.hashCode(modtxt);
|
||||||
|
var tr = document.createElement("tr");
|
||||||
|
var mod = document.createElement("td");
|
||||||
|
|
||||||
|
if (ModAPI.meta._titleMap[hash]) {
|
||||||
|
//Mod has metadata
|
||||||
|
if (ModAPI.meta._iconMap[hash]) {
|
||||||
|
var img = document.createElement("img");
|
||||||
|
img.style.width = "48px";
|
||||||
|
img.style.height = "48px";
|
||||||
|
img.style.imageRendering = "pixelated";
|
||||||
|
img.src = ModAPI.meta._iconMap[hash];
|
||||||
|
mod.appendChild(img);
|
||||||
|
}
|
||||||
|
var h4 = document.createElement("h4");
|
||||||
|
h4.style.margin = 0;
|
||||||
|
h4.style.padding = 0;
|
||||||
|
h4.innerText = ModAPI.meta._titleMap[hash] + (ModAPI.meta._versionMap[hash] ? " " + ModAPI.meta._versionMap[hash] : "");
|
||||||
|
mod.appendChild(h4);
|
||||||
|
if (ModAPI.meta._developerMap[hash]) {
|
||||||
|
var h6 = document.createElement("h6");
|
||||||
|
h6.style.margin = 0;
|
||||||
|
h6.style.padding = 0;
|
||||||
|
h6.innerText = ModAPI.meta._developerMap[hash];
|
||||||
|
mod.appendChild(h6);
|
||||||
|
}
|
||||||
|
if (ModAPI.meta._descriptionMap[hash]) {
|
||||||
|
var span = document.createElement("span");
|
||||||
|
span.style.fontSize = "0.65rem";
|
||||||
|
span.innerText = ModAPI.meta._descriptionMap[hash];
|
||||||
|
mod.appendChild(span);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
//Mod does not have metadata
|
||||||
|
if (modtxt.length > 125) {
|
||||||
|
try {
|
||||||
|
mod.innerText = modtxt.match(/data:text\/\S+?;fs=\S+;/m)[0]
|
||||||
|
} catch (error) {
|
||||||
|
mod.innerText = "Unknown Mod.";
|
||||||
|
}
|
||||||
|
} else { mod.innerText = modtxt; }
|
||||||
|
}
|
||||||
|
|
||||||
|
var spacer = document.createElement("td");
|
||||||
|
spacer.classList.add("nothing");
|
||||||
|
var controls = document.createElement("td");
|
||||||
|
|
||||||
|
var deleteBtn = document.createElement("button");
|
||||||
|
deleteBtn.innerText = "Delete";
|
||||||
|
deleteBtn.style.height = "3rem";
|
||||||
|
deleteBtn.addEventListener("click", async () => {
|
||||||
|
await removeMod(i);
|
||||||
|
window.modapi_displayModGui();
|
||||||
|
});
|
||||||
|
deleteBtn.classList.add("button");
|
||||||
|
controls.appendChild(deleteBtn);
|
||||||
|
|
||||||
|
if (typeof ModAPI.meta._configMap[hash] === "function") {
|
||||||
|
var configBtn = document.createElement("button");
|
||||||
|
configBtn.innerText = "Config";
|
||||||
|
configBtn.style.height = "3rem";
|
||||||
|
configBtn.style.marginLeft = "1rem";
|
||||||
|
configBtn.addEventListener("click", async () => {
|
||||||
|
ModAPI.meta._configMap[hash]();
|
||||||
|
});
|
||||||
|
configBtn.classList.add("button");
|
||||||
|
controls.appendChild(configBtn);
|
||||||
|
}
|
||||||
|
|
||||||
|
tr.appendChild(mod);
|
||||||
|
tr.appendChild(spacer);
|
||||||
|
tr.appendChild(controls);
|
||||||
|
tbody.appendChild(tr);
|
||||||
|
});
|
||||||
|
var once = false;
|
||||||
|
if (cb) {
|
||||||
|
document.querySelector("#modapi_gui_container ._doneButton").addEventListener("mousedown", ()=>{
|
||||||
|
if (once) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
once = true;
|
||||||
|
cb();
|
||||||
|
document.querySelector("#modapi_gui_container").remove();
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
window.modapi_clearmods = async () => {
|
||||||
|
await resetMods();
|
||||||
|
window.modapi_displayModGui();
|
||||||
|
}
|
||||||
|
window.modapi_addmod = async () => {
|
||||||
|
var mod = window.prompt("Paste in the URL of the mod you wish to add: ");
|
||||||
|
if (!mod || mod.length === 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
await addMod(mod);
|
||||||
|
window.modapi_displayModGui();
|
||||||
|
}
|
||||||
|
window.modapi_uploadmod = async () => {
|
||||||
|
var f = document.createElement("input");
|
||||||
|
f.type = "file";
|
||||||
|
f.accept = "text/javascript";
|
||||||
|
f.multiple = true;
|
||||||
|
f.addEventListener("input", async () => {
|
||||||
|
if (f.files.length < 1) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
for (let i = 0; i < f.files.length; i++) {
|
||||||
|
await addFileMod(f.files[i].name, (await fileToText(f.files[i])));
|
||||||
|
}
|
||||||
|
window.modapi_displayModGui();
|
||||||
|
});
|
||||||
|
f.click();
|
||||||
|
}
|
||||||
|
}).toString() + ")();";
|
||||||
|
|
||||||
|
if (globalThis.process) {
|
||||||
|
module.exports = {
|
||||||
|
modapi_guikit: modapi_guikit
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,261 @@
|
|||||||
|
const modapi_modloader = "(" + (() => {
|
||||||
|
globalThis.promisifyIDBRequest = function promisifyIDBRequest(request) {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
request.onsuccess = () => resolve(request.result);
|
||||||
|
request.onerror = () => reject(request.error);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
globalThis.getDatabase = async function getDatabase() {
|
||||||
|
const dbRequest = indexedDB.open("EF_MODS");
|
||||||
|
const db = await promisifyIDBRequest(dbRequest);
|
||||||
|
|
||||||
|
if (!db.objectStoreNames.contains("filesystem")) {
|
||||||
|
db.close();
|
||||||
|
const version = db.version + 1;
|
||||||
|
const upgradeRequest = indexedDB.open("EF_MODS", version);
|
||||||
|
upgradeRequest.onupgradeneeded = (event) => {
|
||||||
|
const upgradedDb = event.target.result;
|
||||||
|
upgradedDb.createObjectStore("filesystem");
|
||||||
|
};
|
||||||
|
return promisifyIDBRequest(upgradeRequest);
|
||||||
|
}
|
||||||
|
|
||||||
|
return db;
|
||||||
|
}
|
||||||
|
|
||||||
|
globalThis.getMods = async function getMods() {
|
||||||
|
const db = await getDatabase();
|
||||||
|
const transaction = db.transaction(["filesystem"], "readonly");
|
||||||
|
const objectStore = transaction.objectStore("filesystem");
|
||||||
|
const object = await promisifyIDBRequest(objectStore.get("mods.txt"));
|
||||||
|
var out = object ? (await object.text()).split("|").toSorted() : [];
|
||||||
|
db.close();
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
|
globalThis.getMod = async function getMod(mod) {
|
||||||
|
const db = await getDatabase();
|
||||||
|
const transaction = db.transaction(["filesystem"], "readonly");
|
||||||
|
const objectStore = transaction.objectStore("filesystem");
|
||||||
|
const object = await promisifyIDBRequest(objectStore.get("mods/" + mod));
|
||||||
|
var out = object ? (await object.text()) : "";
|
||||||
|
db.close();
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
|
globalThis.saveMods = async function saveMods(mods) {
|
||||||
|
const db = await getDatabase();
|
||||||
|
const transaction = db.transaction(["filesystem"], "readwrite");
|
||||||
|
const objectStore = transaction.objectStore("filesystem");
|
||||||
|
const encoder = new TextEncoder();
|
||||||
|
const modsData = encoder.encode(mods.toSorted().join("|"));
|
||||||
|
const modsBlob = new Blob([modsData], { type: "text/plain" });
|
||||||
|
await promisifyIDBRequest(objectStore.put(modsBlob, "mods.txt"));
|
||||||
|
db.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
globalThis.addMod = async function addMod(mod) {
|
||||||
|
const mods = await getMods();
|
||||||
|
mods.push("web@" + mod);
|
||||||
|
await saveMods(mods);
|
||||||
|
}
|
||||||
|
|
||||||
|
globalThis.addFileMod = async function addFileMod(mod, textContents) {
|
||||||
|
const mods = await getMods();
|
||||||
|
if (mods.includes(mod)) {
|
||||||
|
await removeMod(mods.indexOf(mod));
|
||||||
|
} else {
|
||||||
|
mods.push(mod);
|
||||||
|
}
|
||||||
|
await saveMods(mods);
|
||||||
|
|
||||||
|
const db = await getDatabase();
|
||||||
|
const transaction = db.transaction(["filesystem"], "readwrite");
|
||||||
|
const objectStore = transaction.objectStore("filesystem");
|
||||||
|
const encoder = new TextEncoder();
|
||||||
|
const modsData = encoder.encode(textContents);
|
||||||
|
const modsBlob = new Blob([modsData], { type: "text/plain" });
|
||||||
|
await promisifyIDBRequest(objectStore.put(modsBlob, "mods/" + mod));
|
||||||
|
db.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
globalThis.removeMod = async function removeMod(index) {
|
||||||
|
const mods = await getMods();
|
||||||
|
if (index >= 0 && index < mods.length) {
|
||||||
|
var deleted = mods.splice(index, 1)[0];
|
||||||
|
await saveMods(mods);
|
||||||
|
if (!deleted.startsWith("web@")) {
|
||||||
|
const db = await getDatabase();
|
||||||
|
const transaction = db.transaction(["filesystem"], "readwrite");
|
||||||
|
const objectStore = transaction.objectStore("filesystem");
|
||||||
|
await promisifyIDBRequest(objectStore.delete("mods/" + deleted));
|
||||||
|
db.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
globalThis.resetMods = async function resetMods() {
|
||||||
|
console.log("Resetting mods...");
|
||||||
|
const db = await getDatabase();
|
||||||
|
const transaction = db.transaction(["filesystem"], "readwrite");
|
||||||
|
const objectStore = transaction.objectStore("filesystem");
|
||||||
|
await promisifyIDBRequest(objectStore.clear());
|
||||||
|
console.log("Mods reset");
|
||||||
|
db.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
globalThis.modLoader = async 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("web@" + modToAdd);
|
||||||
|
});
|
||||||
|
searchParams.getAll("plugin").forEach((modToAdd) => {
|
||||||
|
console.log(
|
||||||
|
"[EaglerML] Adding mod to loadlist from search params: " + modToAdd
|
||||||
|
);
|
||||||
|
modsArr.push("web@" + 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("web@" + modToAdd);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log("[EaglerML] Searching in iDB");
|
||||||
|
try {
|
||||||
|
var idbMods = await getMods();
|
||||||
|
modsArr = modsArr.concat(idbMods
|
||||||
|
.filter(x => { return x && x.length > 0 })
|
||||||
|
);
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error);
|
||||||
|
}
|
||||||
|
|
||||||
|
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.setAttribute("data-hash", ModAPI.util.hashCode("web@" + currentMod));
|
||||||
|
script.src = 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.sort();
|
||||||
|
for (let i = 0; i < modsArr.length; i++) {
|
||||||
|
let currentMod = modsArr[i];
|
||||||
|
var isIDBMod = !currentMod.startsWith("web@");
|
||||||
|
if (!isIDBMod) {
|
||||||
|
currentMod = currentMod.replace("web@", "");
|
||||||
|
}
|
||||||
|
console.log("[EaglerML] Starting " + currentMod);
|
||||||
|
try {
|
||||||
|
var responseText = isIDBMod ? await getMod(currentMod) : await (await fetch(currentMod)).text();
|
||||||
|
console.log("[EaglerML] Loading " + currentMod + " via method A.");
|
||||||
|
var script = document.createElement("script");
|
||||||
|
script.setAttribute("data-hash", ModAPI.util.hashCode((isIDBMod ? "" : "web@") + currentMod));
|
||||||
|
try {
|
||||||
|
script.src =
|
||||||
|
"data:text/javascript," + encodeURIComponent(responseText);
|
||||||
|
} catch (error) {
|
||||||
|
methodB(currentMod);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
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);
|
||||||
|
} catch (error) {
|
||||||
|
methodB(currentMod);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
loaderCheckInterval = setInterval(() => {
|
||||||
|
checkModsLoaded(totalLoaded, loaderCheckInterval);
|
||||||
|
}, 500);
|
||||||
|
console.log(
|
||||||
|
"[EaglerML] Starting to load " + modsArr.length + " mods..."
|
||||||
|
);
|
||||||
|
window.returnTotalLoadedMods = function returnTotalLoadedMods() {
|
||||||
|
return totalLoaded;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}).toString() + ")();"
|
||||||
|
|
||||||
|
if (globalThis.process) {
|
||||||
|
module.exports = {
|
||||||
|
modapi_modloader: modapi_modloader
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,44 @@
|
|||||||
|
class PatchesRegistry {
|
||||||
|
static patchFns = []
|
||||||
|
static patchedEventNames = []
|
||||||
|
static getEventInjectorCode() {
|
||||||
|
return "globalThis.modapi_specialevents = [" + PatchesRegistry.patchedEventNames.flatMap(x=>`\`${x}\``).join(",") + "];";
|
||||||
|
}
|
||||||
|
static patchFile(x) {
|
||||||
|
var current = x;
|
||||||
|
PatchesRegistry.patchFns.forEach(fn => {
|
||||||
|
current = fn(current);
|
||||||
|
});
|
||||||
|
return current;
|
||||||
|
}
|
||||||
|
static addPatch(fn) {
|
||||||
|
PatchesRegistry.patchFns.push(fn);
|
||||||
|
}
|
||||||
|
static regSpecialEvent(x) {
|
||||||
|
PatchesRegistry.patchedEventNames.push(x);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// PatchesRegistry.regSpecialEvent("test");
|
||||||
|
// PatchesRegistry.addPatch(function (input) {
|
||||||
|
// var output = input;
|
||||||
|
// return output;
|
||||||
|
// })
|
||||||
|
|
||||||
|
PatchesRegistry.regSpecialEvent("render");
|
||||||
|
PatchesRegistry.addPatch(function (input) {
|
||||||
|
var output = input.replaceAll(
|
||||||
|
/continue main;\s+?}\s+?if\s?\(!\$this.\$renderHand\)/gm
|
||||||
|
,
|
||||||
|
`continue main;
|
||||||
|
}
|
||||||
|
ModAPI.events.callEvent("render",{partialTicks:$partialTicks})
|
||||||
|
if (!$this.$renderHand)`
|
||||||
|
);
|
||||||
|
return output;
|
||||||
|
});
|
||||||
|
|
||||||
|
if (globalThis.process) {
|
||||||
|
module.exports = {
|
||||||
|
PatchesRegistry: PatchesRegistry
|
||||||
|
}
|
||||||
|
}
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,38 @@
|
|||||||
|
## ModAPI.array
|
||||||
|
ModAPI.array contains the API for creating java arrays easily.
|
||||||
|
|
||||||
|
Methods:
|
||||||
|
- `ModAPI.array.object(class: Class|String, jsarray: object[]) : Object[]`
|
||||||
|
- Converts a javascript array of a class to a java array of a class.
|
||||||
|
- The class argument can be a raw java class (eg. `ModAPI.reflect.getClassByName(...).class`)
|
||||||
|
- It can also be a string `"java.util.String"`
|
||||||
|
- `ModAPI.array.object(class: Class, size: number) : Object[]`
|
||||||
|
- Creates a java array of a class with the specified size.
|
||||||
|
- `ModAPI.array.boolean(jsarray: boolean[]) : Boolean[]`
|
||||||
|
- Takes a java cript array of booleans (`true`/`false`) and converts it into a java array.
|
||||||
|
- `ModAPI.array.boolean(size: number) : Boolean[]`
|
||||||
|
- Creates a boolean array with the specified size.
|
||||||
|
- `ModAPI.array.byte(jsarray: number[]) : Byte[]`
|
||||||
|
- Takes a javascript array of numbers and converts it into a java byte array.
|
||||||
|
- `ModAPI.array.byte(size: number) : Byte[]`
|
||||||
|
- Creates a byte array with the specified size.
|
||||||
|
- `ModAPI.array.char(jsarray: number[]) : Char[]`
|
||||||
|
- Takes a javascript array of numbers and converts it into a java char array.
|
||||||
|
- `ModAPI.array.char(size: number) : Char[]`
|
||||||
|
- Creates a char array with the specified size.
|
||||||
|
- `ModAPI.array.short(jsarray: number[]) : Short[]`
|
||||||
|
- Takes a javascript array of numbers and converts it into a java short array.
|
||||||
|
- `ModAPI.array.short(size: number) : Short[]`
|
||||||
|
- Creates a short array with the specified size.
|
||||||
|
- `ModAPI.array.int(jsarray: number[]) : Int[]`
|
||||||
|
- Takes a javascript array of numbers and converts it into a java int array.
|
||||||
|
- `ModAPI.array.int(size: number) : Int[]`
|
||||||
|
- Creates a int array with the specified size.
|
||||||
|
- `ModAPI.array.float(jsarray: number[]) : Float[]`
|
||||||
|
- Takes a javascript array of numbers and converts it into a java float array.
|
||||||
|
- `ModAPI.array.float(size: number) : Float[]`
|
||||||
|
- Creates a float array with the specified size.
|
||||||
|
- `ModAPI.array.double(jsarray: number[]) : Float[]`
|
||||||
|
- Takes a javascript array of numbers and converts it into a java double array.
|
||||||
|
- `ModAPI.array.double(size: number) : Float[]`
|
||||||
|
- Creates a double array with the specified size.
|
||||||
@@ -0,0 +1,39 @@
|
|||||||
|
## ModAPI.dedicatedServer
|
||||||
|
|
||||||
|
This is the dedicated server module, used for modding singleplayer in more powerful ways.
|
||||||
|
|
||||||
|
ModAPI.dedicatedServer has the following methods:
|
||||||
|
|
||||||
|
- `appendCode(code: Function | String) : void`
|
||||||
|
- Injects provided code into the dedicated server.
|
||||||
|
|
||||||
|
|
||||||
|
### Modding the dedicated server
|
||||||
|
Eaglercraft runs the dedicated server in a service worker. This means that in order to run code to mod the dedicated server, you have to change context into the service worker.
|
||||||
|
|
||||||
|
`ModAPI.dedicatedServer.appendCode()` allows you to inject code into the dedicates server before startup. The code injected will throw errors if it attempts to access resources outside the functions context.
|
||||||
|
|
||||||
|
For example, take a look at this mod, which will inject some code that does nothing into the dedicated server:
|
||||||
|
```javascript
|
||||||
|
var myVariable = 4;
|
||||||
|
function myServerSideModCode() {
|
||||||
|
function subfunction() {
|
||||||
|
console.log("serverside!!!");
|
||||||
|
}
|
||||||
|
subfunction();
|
||||||
|
//Successfully running serverside
|
||||||
|
//However, we cannot access `myVariable`
|
||||||
|
}
|
||||||
|
ModAPI.dedicatedServer.appendCode(myServerSideModCode);
|
||||||
|
```
|
||||||
|
|
||||||
|
You can check if a mod if running serverside using this:
|
||||||
|
```javascript
|
||||||
|
function myServerSideModCode(isServerSide) {
|
||||||
|
console.log(isServerSide);
|
||||||
|
}
|
||||||
|
myServerSideModCode(); //logs undefined
|
||||||
|
ModAPI.dedicatedServer.appendCode(myServerSideModCode); //when server starts, will log `true`
|
||||||
|
```
|
||||||
|
|
||||||
|
Once serverside, you can only access server side events, like `serverstart` or `tick`. [See serverside events](events.md#server-side-events)
|
||||||
@@ -0,0 +1,119 @@
|
|||||||
|
## Events
|
||||||
|
Events broadcast data for use in mods.
|
||||||
|
|
||||||
|
- `ModAPI.addEventListener(eventName: String, callback: Function) : void`
|
||||||
|
- Used to register an event handler. Eg:
|
||||||
|
- ```javascript
|
||||||
|
function myHandler(event) {
|
||||||
|
console.log(event);
|
||||||
|
}
|
||||||
|
ModAPI.addEventListener("update", myHandler);
|
||||||
|
```
|
||||||
|
- `ModAPI.removeEventListener(eventName: String, callback: Function) : void`
|
||||||
|
- Used to unregister an event handler. Eg:
|
||||||
|
- ```javascript
|
||||||
|
function myHandler(event) {
|
||||||
|
console.log(event);
|
||||||
|
}
|
||||||
|
ModAPI.removeEventListener("update", myHandler);
|
||||||
|
```
|
||||||
|
|
||||||
|
### Basic Events
|
||||||
|
- `update`:
|
||||||
|
- Called every client side tick.
|
||||||
|
- Event object is blank.
|
||||||
|
- `load`:
|
||||||
|
- Called when all mods have finished loading.
|
||||||
|
- Event object is blank.
|
||||||
|
- `sendchatmessage`:
|
||||||
|
- Called just before the player sends a chat message.
|
||||||
|
- Passes an object with properties:
|
||||||
|
- `message: String`
|
||||||
|
- String representing the chat message.
|
||||||
|
- `preventDefault: Boolean`
|
||||||
|
- Boolean representing whether or not to cancel processing the chat message. Default is `false`.
|
||||||
|
- `event`:
|
||||||
|
- Called when any event is called. Passes an object with properties:
|
||||||
|
- Passes an object with properties:
|
||||||
|
- `event: String`
|
||||||
|
- String representing the type of event being fired.
|
||||||
|
- `data: Object`
|
||||||
|
- Object representing the original arguments to be passed to the callback.
|
||||||
|
- `frame`:
|
||||||
|
- Called just when a frame is rendered on the client.
|
||||||
|
- Event object is blank.
|
||||||
|
- `render`:
|
||||||
|
- Called when 3D is rendered.
|
||||||
|
- Event object is has one property:
|
||||||
|
- `partialTicks`: number representing the fraction of ticks passed at this frame.
|
||||||
|
### Server Side Events
|
||||||
|
Can only be used in the context of the dedicated server. More: [DedicatedServerDocumentation](dedicatedserver.md)
|
||||||
|
- `serverstart`:
|
||||||
|
- Called when the dedicated server starts.
|
||||||
|
- Event object is blank.
|
||||||
|
- `bootstrap`:
|
||||||
|
- Called when the dedicated server registers blocks, items, materials, enchantments, etc.
|
||||||
|
- This is when you should register cstom blocks and items.
|
||||||
|
- Event object is blank.
|
||||||
|
- `serverstop`:
|
||||||
|
- Called when the dedicated server stops.
|
||||||
|
- Event object is blank.
|
||||||
|
- `tick`:
|
||||||
|
- Called when the server ticks.
|
||||||
|
- Passes an object with properties:
|
||||||
|
- `preventDefault: Boolean`
|
||||||
|
- Boolean representing whether or not to cancel the tick. Default is `false`.
|
||||||
|
- `receivechatmessage`:
|
||||||
|
- Called when the server receives a chat message.
|
||||||
|
- Passes an object with properties:
|
||||||
|
- `message: String`
|
||||||
|
- String representing the chat message.
|
||||||
|
- `preventDefault: Boolean`
|
||||||
|
- Boolean representing whether or not to cancel processing the chat message. Default is `false`.
|
||||||
|
- `processcommand`:
|
||||||
|
- Called when the server receives a command.
|
||||||
|
- Passes an object with properties:
|
||||||
|
- `command: String`
|
||||||
|
- String representing the command.
|
||||||
|
- `sender: ICommandSender`
|
||||||
|
- Object that sent the command
|
||||||
|
- `preventDefault: Boolean`
|
||||||
|
- Boolean representing whether or not to cancel processing the command. Default is `false`.
|
||||||
|
|
||||||
|
### Events Global, adding new events
|
||||||
|
The events global, `ModAPI.events`, allows you to register new event types and call them.
|
||||||
|
|
||||||
|
#### ModAPI.events.newEvent(eventName: String)
|
||||||
|
You can register new events using ModAPI, as long as the event name starts with `custom:` (`lib:` is only useful for library loading). For example, if I want to add a new event that can be used by other mods, I can use `ModAPI.events.newEvent("custom:myevent")`.
|
||||||
|
|
||||||
|
|
||||||
|
#### ModAPI.events.callEvent(eventName: String, data: Object)
|
||||||
|
You can then call events via `ModAPI.events.callEvent`. For example, to trigger `custom:myevent` with a secret code value, I can run `ModAPI.events.callEvent("custom:myevent", {secretCode: "1234"});`.
|
||||||
|
|
||||||
|
Here is an example on using this:
|
||||||
|
```javascript
|
||||||
|
// Mod #1, registers event handler for custom event
|
||||||
|
ModAPI.addEventListener("custom:myevent", (e)=>{
|
||||||
|
alert(e.secretCode);
|
||||||
|
});
|
||||||
|
```
|
||||||
|
```javascript
|
||||||
|
// Mod #2, registers and calls custom event
|
||||||
|
ModAPI.events.newEvent("custom:myevent");
|
||||||
|
ModAPI.events.callEvent("custom:myevent", {
|
||||||
|
secretCode: "1234"
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Using library load events
|
||||||
|
```javascript
|
||||||
|
// Mod #2, registers and calls lib event
|
||||||
|
ModAPI.events.newEvent("lib:mylibrary:loaded");
|
||||||
|
ModAPI.events.callEvent("lib:mylibrary:loaded", {});
|
||||||
|
```
|
||||||
|
```javascript
|
||||||
|
// Mod #1, registers event handler for lib event
|
||||||
|
ModAPI.addEventListener("lib:mylibrary:loaded", (e)=>{
|
||||||
|
//Lib events function differently to normal events, as when they are called once, any new event listener with automatically fire upon being registered.
|
||||||
|
});
|
||||||
|
```
|
||||||
@@ -0,0 +1,40 @@
|
|||||||
|
## ModAPI.hooks
|
||||||
|
ModAPI.hooks is the global generated by actual code.
|
||||||
|
It has quite a few propeties, but most of them are just foundations for more user friendly parts of the ModAPI, so I won't explain them.
|
||||||
|
|
||||||
|
### Property: ModAPI.hooks.methods
|
||||||
|
`ModAPI.hooks.methods` is a String-to-method dictionary/object of every java method. This allows you to do pretty much whatever you want in terms of modifying and hooking into code.
|
||||||
|
It's properties are defined by the package of the java class, as well as that methods name. For example, `net.minecraft.world.World`'s `spawnEntityInWorld` method will be named `ModAPI.hooks.methods.nmw_World_spawnEntityInWorld`, where `nmw` is `net.minecraft.world`. You can automate finding this by using `ModAPI.util.getMethodFromPackage("com.package.abc.MyClass", "myMethod")`, which is an alorithm that automatically finds the key in `ModAPI.hooks.methods`.
|
||||||
|
|
||||||
|
Due to the injector's patches, all game code runs by calling these ModAPI.hooks.methods functions, which allows you to call, patch, replace and modify the game's source code in realtime.
|
||||||
|
|
||||||
|
To call a method, use `ModAPI.hooks.methods[ModAPI.util.getMethodFromPackage("com.package.abc.MyClass", "myMethod")](argument1, argument2, etc);`.
|
||||||
|
|
||||||
|
Complexities with calling methods:
|
||||||
|
Methods that are described in EaglercraftX's source code as `static` can be called by replacing boolean values `true`/`false` with `1` and `0`, respectively. Strings have to be converted by using `ModAPI.util.str("string")` or one of it's aliases. To pass data from a ModAPI proxy you have to use .getRef(), eg: `ModAPI.player.getRef(); //raw java player object`.
|
||||||
|
|
||||||
|
Non static methods must be called with the object they are running on (the value of the `this` keyword in the java source). Do this by using the object as the first argument. For example, look at this code:
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
ModAPI.require("world");
|
||||||
|
ModAPI.hooks.methods.nmw_World_spawnEntityInWorld(ModAPI.world.getRef(), *an entity object*);
|
||||||
|
```
|
||||||
|
|
||||||
|
- To replace a method with another, you can use:
|
||||||
|
- `ModAPI.hooks.methods[ModAPI.util.getMethodFromPackage("com.package.abc.MyClass", "myMethod")] = function () {}`
|
||||||
|
- To intercept inputs to a method, you can us
|
||||||
|
- ```javascript
|
||||||
|
var myMethodName = ModAPI.util.getMethodFromPackage("com.package.abc.MyClass", "myMethod");
|
||||||
|
const originalMethod = ModAPI.hooks.methods[myMethodName];
|
||||||
|
ModAPI.hooks.methods[myMethodName] = function (...args) {
|
||||||
|
//args is the array of arguments passed in.
|
||||||
|
//on an instance method, this first (args[0]) will almost always
|
||||||
|
//be $this, ie: the object the method is being run on
|
||||||
|
return originalMethod.apply(this, args);
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
Please note that if you are just calling methods, I recommend attempting to call the method directly on the object. `Eg: ModAPI.world.spawnEntityInWorld(*an entity object*)` or using `ModAPI.reflect.getClassByName("MyClass").methods.methodName.method()`;
|
||||||
|
|
||||||
|
### Property: ModAPI.hooks._teavm
|
||||||
|
`ModAPI.hooks._teavm` is usually only used for internal purposes, but it is basically a collection of every internal TeaVM method. Keep in mind that this only stores references (for performance reasons), so modifying and editing it's contents will not affect the way the game runs.
|
||||||
@@ -0,0 +1,185 @@
|
|||||||
|
# EaglerForge ModAPI Documentation
|
||||||
|
The EaglerForge ModAPI is housed in a global JavaScript object stored on `globalThis`, called `ModAPI` or `PluginAPI`. (both are identical)
|
||||||
|
|
||||||
|
### Important Notice!
|
||||||
|
From people used to the doc prior to EaglerForgeInjector, now, when you see something like `ModAPI.world`'s type is `World`, that literally means it is identical to an instance of `net.minecraft.world.World` from java. For easier modding, here are some online javadocs, that explain properties from each individual method and proerty of every 1.8 class:
|
||||||
|
|
||||||
|
https://nurmarvin.github.io/Minecraft-1.8-JavaDocs/overview-summary.html - Javadoc for vanilla 1.8
|
||||||
|
https://eaglerreborn.github.io/javadoc/ - EaglerReborn (EF precursor) javadoc, for EaglercraftX u17 (missing serverside classes, this version didn't have singleplayer)
|
||||||
|
An up-to-date javadoc for EaglercraftX is coming soon, in the meanwhile, I recommend modding with a local EaglercraftX workspace, so you can inspect the contents of each class.
|
||||||
|
|
||||||
|
Additionally, when you se that something like `ModAPI.mcinstance` is `Raw<Minecraft>` this means that it has a lot of TeaVM nonsense like '$' prefixes before everything, as well has making it difficult to call the objects methods.
|
||||||
|
|
||||||
|
### Global ModAPI Object:
|
||||||
|
|
||||||
|
The global object has the following properties:
|
||||||
|
- `ModAPI.player: EntityPlayerSP`
|
||||||
|
- Only accessible after `ModAPI.require("player")` is called, this is the local player entity. It is regenerated every time the `update` event is called.
|
||||||
|
- `ModAPI.world: WorldClient`
|
||||||
|
- Only accessible after `ModAPI.require("world")` is called, this is the client-side world. It is regenerated every time the `update` event is called.
|
||||||
|
- `ModAPI.network: NetHandlerPlayClient`
|
||||||
|
- Only accessible after `ModAPI.require("network")` is called, this is the client's networking handler. It is regenerated every time the `update` event is called.
|
||||||
|
- `ModAPI.settings: GameSettings`
|
||||||
|
- This is the Minecraft client's settings. It is generated upon init.
|
||||||
|
- `ModAPI.items: Map<String, Item>`
|
||||||
|
- This is a key-value dictionary of all of the items in the game. It is generated upon init from the static variables of the `Items` class.
|
||||||
|
- For example, to access the item class for `acacia_door`, you can use `ModAPI.items["acacia_door"]`
|
||||||
|
- `ModAPI.blocks: Map<String, Block>`
|
||||||
|
- This is a key-value dictionary of all of the blocks in the game. It is generated upon init from the static variables of the `Blocks` class.
|
||||||
|
- For example, to access the block class for `bedrock`, you can use `ModAPI.blocks["bedrock"]`
|
||||||
|
- `ModAPI.materials: Map<String, Material>`
|
||||||
|
- This is a key-value dictionary of all of the blocks in the game. It is generated upon init from the static variables of the `Material` class.
|
||||||
|
- For example, to access the material class for `portal`, you can use `ModAPI.materials["portal"]`
|
||||||
|
- `ModAPI.enchantments: Map<String, Enchantment|Object>`
|
||||||
|
- This is a key-value dictionary of all of the enchantments in the game. It is generated upon init from the static variables of the `Enchantment` class.
|
||||||
|
- For example, to access the enchantment class for `knockback`, you can use `ModAPI.enchantments["knockback"]`
|
||||||
|
- As the enchantment class has other static variables, `Object.keys` will also return non-enchantment keys such as `enchantmentsBookList`.
|
||||||
|
- `ModAPI.blockSounds: Map<String, SoundType>` (1.12 only)
|
||||||
|
- This is a key-value dictionary of `SoundType`s. Used in `.setSoundType(soundType)` when registering custom blocks in 1.12.
|
||||||
|
- `ModAPI.minecraft: Minecraft`
|
||||||
|
- This is the minecraft instance for the client, generated upon init.
|
||||||
|
- It can also be accessed using `ModAPI.mc`
|
||||||
|
- `ModAPI.mcinstance: Raw<Minecraft>`
|
||||||
|
- This is the raw minecraft instance for the client, generated upon init.
|
||||||
|
- It can also be accessed using `ModAPI.javaClient`
|
||||||
|
- It can also be accessed using `ModAPI.minecraft.getRef()`
|
||||||
|
- It can also be accessed using `Minecraft`
|
||||||
|
- Only here for compatibility
|
||||||
|
- `ModAPI.server: MinecraftServer`
|
||||||
|
- This is the dedicated minecraft server in the service worker, generated when the `serverstart`.
|
||||||
|
- It can only be accessed in the dedicated server's context. (See `ModAPI.dedicatedServer`)
|
||||||
|
- It can also be accessed using `ModAPI.serverInstance`
|
||||||
|
- `ModAPI.rawServer: MinecraftServer`
|
||||||
|
- This is the dedicated minecraft server in the service worker, generated when the `serverstart` event is fired.
|
||||||
|
- It can only be accessed in the dedicated server's context. (See `ModAPI.dedicatedServer`)
|
||||||
|
- It can also be accessed using `ModAPI.server.getRef()`
|
||||||
|
- `ModAPI.hooks`
|
||||||
|
- This is the internal hooking map for ModAPI and can be used to patch, intercept, or rewrite internal functions, and more.
|
||||||
|
- More: [HooksDocumentation](hooks.md)
|
||||||
|
- `ModAPI.util`
|
||||||
|
- This contains utilities for using `ModAPI.hooks`, `ModAPI.reflect`, and more.
|
||||||
|
- More: [UtilDocumentation](utils.md)
|
||||||
|
- `ModAPI.reflect`
|
||||||
|
- This is a wrapper around `ModAPI.hooks`, `ModAPI.hooks._teavm` and `ModAPI.hooks._classMap` that makes accessing and using internal java classes in mods much easier.
|
||||||
|
- More: [ReflectDocumentation](reflect.md)
|
||||||
|
- `ModAPI.dedicatedServer`
|
||||||
|
- This object is used to push code for use in the dedicated server.
|
||||||
|
- Once the dedicated server worker has started, it is unuseable.
|
||||||
|
- More: [DedicatedServerDocumentation](dedicatedserver.md)
|
||||||
|
- `ModAPI.meta`
|
||||||
|
- This module is used to register metadata for mods such as their title, credits, icon and description.
|
||||||
|
- More: [MetaDocumentation](meta.md)
|
||||||
|
- `ModAPI.array`
|
||||||
|
- This module is used to interact and create arrays easily.
|
||||||
|
- More: [ArrayDocumentation](array.md)
|
||||||
|
- `ModAPI.keygen`
|
||||||
|
- This module is used to get IDs for registering blocks and items without hardcoding an ID.
|
||||||
|
- More: [KeygenDocumentation](keygen.md)
|
||||||
|
- `ModAPI.resolution`
|
||||||
|
- This module is used to query information about GUI dimensions, to make drawing to the screen easier, generated when the `frame` event is fired.
|
||||||
|
- Deprecated alias (please do not use): `ModAPI.ScaledResolution`
|
||||||
|
- More: [ArrayDocumentation](array.md)
|
||||||
|
- `ModAPI.version: String`
|
||||||
|
- The version of ModAPI.
|
||||||
|
- `ModAPI.is_1_12: Boolean`
|
||||||
|
- Property defining wether or not ModAPI thinks the current version is 1.12-based.
|
||||||
|
- `ModAPI.isServer: Boolean`
|
||||||
|
- Property defining wether or not ModAPI thinks it is running on the dedicated server.
|
||||||
|
- `ModAPI.flavour: String`
|
||||||
|
- The flavour of ModAPI. Hardcoded to be `"injector"`.
|
||||||
|
|
||||||
|
The ModAPI object has the following methods:
|
||||||
|
- `addEventListener(eventName: String, callback: Function) : void`
|
||||||
|
- More: [EventDocumentation](events.md)
|
||||||
|
- `require(componentName: String) : void`
|
||||||
|
- Import required modules, such as `player` and `network`.
|
||||||
|
- Usage: `ModAPI.require("module")`
|
||||||
|
- `displayToChat(message: String) : void`
|
||||||
|
- Displays client-side message to user's ingame chat gui.
|
||||||
|
- Usage: `ModAPI.displayToChat("Hello World.")`
|
||||||
|
- `clickMouse() : void`
|
||||||
|
- Triggers a left click ingame.
|
||||||
|
- `rightClickMouse() : void`
|
||||||
|
- Triggers a right click ingame.
|
||||||
|
- `getFPS() : int`
|
||||||
|
- Gets the frames per second of the game
|
||||||
|
- `promisify(asyncJavaMethod: Method | Constructor) : PromisifiedJavaRunner`
|
||||||
|
- Allows running java methods that are @Async/@Async dependent.
|
||||||
|
- More: [PromisifyDocumentation](promisify.md)
|
||||||
|
- `addCredit(category: String, contributor: String, contents: String)`
|
||||||
|
- Lets you easily add credits to Eaglercraft's credits.txt
|
||||||
|
- eg: `ModAPI.addCredit("My Cool Mod", "Username", " - Coded the mod\n - Wrote somne credits")`
|
||||||
|
|
||||||
|
|
||||||
|
## Handling strings, numbers and booleans to and from java.
|
||||||
|
Java strings and JavaScript strings are not the same. Calling a method like this: `ModAPI.player.sendChatMessage("hello world")`, will not work, as you are running a Java method with a JavaScript string. To convert a JS string to a Java string, use `ModAPI.util.str(yourString)`. For example, the correct version of the above example is `ModAPI.player.sendChatMessage(ModAPI.util.str("hello world"))`. This problem is automatically mitigated on a few functions, namely `ModAPI.displayToChat()`.
|
||||||
|
|
||||||
|
|
||||||
|
---
|
||||||
|
Java numbers and JavaScript numbers are stored the same way, with no problems with having to cast, like with strings. This is why you can simply do something like `ModAPI.player.motionY = 99999`, without having to do any conversion.
|
||||||
|
|
||||||
|
|
||||||
|
---
|
||||||
|
Booleans in Java are stored as a number, where `1` means `true` and `0` means `false`. There are no functions for converting inbetween these, because it is very easy to do so (unlike strings). To convert a javascript boolean into a java boolean simply multiply you boolean by 1.
|
||||||
|
|
||||||
|
Eg:
|
||||||
|
```javascript
|
||||||
|
var myBool = true;
|
||||||
|
console.log(myBool * 1);
|
||||||
|
// logs '1'
|
||||||
|
|
||||||
|
var myBool = false;
|
||||||
|
console.log(myBool * 1);
|
||||||
|
// logs '0'
|
||||||
|
```
|
||||||
|
|
||||||
|
Better yet, if you need to use booleans very often, just store them as numbers directly in javascript. JavaScript if statements already recognise `0` as false, so something like:
|
||||||
|
```javascript
|
||||||
|
var condition = 0;
|
||||||
|
if (condition) {
|
||||||
|
console.log("yes");
|
||||||
|
} else {
|
||||||
|
console.log("no");
|
||||||
|
}
|
||||||
|
// outputs 'no'
|
||||||
|
```
|
||||||
|
will work out of the box.
|
||||||
|
|
||||||
|
## Accessing raw data
|
||||||
|
In ModAPI's architecture, when you request an object like `ModAPI.player`, instead of giving you `ModAPI.mcinstance.$thePlayer`, it will return a `TeaVM_to_Recursive_BaseData_ProxyConf` proxy. These automatically remove the `$` prefixes, make instance methods run with the actaul object, and a variety other features.
|
||||||
|
|
||||||
|
However, when calling methods via `ModAPI.hooks`, `ModAPI.reflect`, or even just running a method that takes in object arguments on something like `ModAPI.player`, passing in these ModAPI proxies will cause an error.
|
||||||
|
|
||||||
|
To pass in raw java data simply call `getRef()` on the proxy which will return the raw, unmodified version of it.
|
||||||
|
|
||||||
|
For example, take the method `setRenderViewEntity()` on `ModAPI.mcinstance`. Instead of passing an entity from `ModAPI.world.loadedEntityList.get(index)` directly, you need to use `ModAPI.world.loadedEntityList.get(index).getRef()`. Demo code:
|
||||||
|
```javascript
|
||||||
|
var entityIndex = 1; //Index of the entity to look for. 0 means first, which is usually the player, so 1 is usually a natural entity.
|
||||||
|
ModAPI.mc.setRenderViewEntity(ModAPI.world.loadedEntityList.get(entityIndex).getRef());
|
||||||
|
```
|
||||||
|
Note that an entry for `getRef` will not appear from `Object.keys` and similar web APIs.
|
||||||
|
|
||||||
|
## Checking if an object is a proxy
|
||||||
|
All proxied objects have a property `isModProxy` which is equal to true. Note that an entry for `isModProxy` will not appear from `Object.keys` and similar web APIs.
|
||||||
|
|
||||||
|
## Corrective Proxies
|
||||||
|
By default, accessing a global like `ModAPI.player` will return a proxy to the original player that removes $ prefixes, as well as making instance methods callable. TeaVM has a quirk where it adds numerical suffixes to some properties. For example `ModAPI.player.inGround0` instead of `ModAPI.player.inGround`. As this is a large issue due to these suffixes changing for every eaglercraft update, you can now bypass this by obtaining a corrective version of `ModAPI.player`, using `ModAPI.player.getCorrective()`.
|
||||||
|
|
||||||
|
For example:
|
||||||
|
```javascript
|
||||||
|
ModAPI.player.inGround //returns undefined
|
||||||
|
ModAPI.player.inGround0 //returns 1 or 0, the correct value
|
||||||
|
|
||||||
|
ModAPI.player.isCorrective() //returns false
|
||||||
|
|
||||||
|
var correctedPlayer = ModAPI.player.getCorrective();
|
||||||
|
|
||||||
|
correctedPlayer.inGround //returns 1 or 0, the correct value
|
||||||
|
correctedPlayer.inGround0 //returns 1 or 0, the correct value
|
||||||
|
|
||||||
|
correctedPlayer.isCorrective() //returns true
|
||||||
|
```
|
||||||
|
|
||||||
|
You can check if an object is corrective using `<object>.isCorrective()`;
|
||||||
|
|
||||||
|
Accessing children of a corrective object will also make them corrective. `correctedPlayer.fishEntity.isCorrective(); //true`
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
## ModAPI.keygen
|
||||||
|
ModAPI.keygen contains the API for getting numerical item, block and entity IDs from a string. It looks at registries to derive the IDs, so IDs will not be automatically reserved until a block/item is actually registered into the game. Ideally, you'd want to call a keygen method just before registering your block.
|
||||||
|
|
||||||
|
Methods:
|
||||||
|
- `ModAPI.keygen.item(itemId: String) : number`
|
||||||
|
- Example usage is: `var id = ModAPI.keygen.item("my_example_item");`
|
||||||
|
- `ModAPI.keygen.block(blockId: String) : number`
|
||||||
|
- Example usage is: `var id = ModAPI.keygen.block("my_example_block");`
|
||||||
|
- `ModAPI.keygen.entity(entityId: String) : number`
|
||||||
|
- Example usage is: `var id = ModAPI.keygen.entity("my_example_entity");`
|
||||||
|
- `ModAPI.keygen.sound(soundId: String) : number`
|
||||||
|
- Example usage is: `var id = ModAPI.keygen.sound("my.example.sound");`
|
||||||
|
- `ModAPI.keygen.enchantment(enchantmentId: String) : number`
|
||||||
|
- Example usage is: `var id = ModAPI.keygen.enchantment("sharpness_v2");`
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
## ModAPI.meta
|
||||||
|
ModAPI.meta contains the API for registering metadata on mods easily.
|
||||||
|
|
||||||
|
Methods:
|
||||||
|
- `ModAPI.meta.title(title: String)`
|
||||||
|
- Sets the title of the mod. This is mandatory if any metadata is to be displayed. Character limit of 16.
|
||||||
|
- `ModAPI.meta.credits(credits: String)`
|
||||||
|
- Sets the credits of the mod. Character limit of 36.
|
||||||
|
- `ModAPI.meta.description(desc: String)`
|
||||||
|
- Sets the description of the mod. Character limit of 160.
|
||||||
|
- `ModAPI.meta.icon(iconURL: String)`
|
||||||
|
- Sets the icon of the mod.
|
||||||
|
- It can be extremely low res, it will not appear blurry.
|
||||||
|
- `ModAPI.meta.version(versionCode: String)`
|
||||||
|
- Sets the version of the mod. Appended after the title.
|
||||||
|
- `ModAPI.meta.config(configFn: Function)`
|
||||||
|
- Once the client is fully loaded, creates a button in the mod manager GUI that runs the specified function when pressed.
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
## ModAPI.promisify()
|
||||||
|
Some methods in java are asynchronous, meaning that they don't return a value/modify state immediately. Calling them in an event or in a patch to a normal function will cause a stack implosion, characterised by the client/dedicated server hanging without any error messages.
|
||||||
|
|
||||||
|
In order to call them properly from javascript, you need to use the `ModAPI.promisify()` function.
|
||||||
|
|
||||||
|
For example, here we have a simple client-side command that will try to use the `PlatformRuntime` class to download data from a URI:
|
||||||
|
```javascript
|
||||||
|
ModAPI.addEventListener("sendchatmessage", function downloadSomething(e) {
|
||||||
|
if (e.message.toLowerCase().startsWith("/downloadtest")) {
|
||||||
|
var arraybuffer = ModAPI.hooks.methods.nlevi_PlatformRuntime_downloadRemoteURI(ModAPI.util.str("data:text/plain,hi"));
|
||||||
|
console.log(arraybuffer);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
```
|
||||||
|
This will cause the client to hang. The correct way of calling this asynchronous method is like this:
|
||||||
|
```javascript
|
||||||
|
ModAPI.addEventListener("sendchatmessage", function downloadSomething(e) {
|
||||||
|
if (e.message.toLowerCase().startsWith("/downloadtest")) {
|
||||||
|
ModAPI.promisify(ModAPI.hooks.methods.nlevi_PlatformRuntime_downloadRemoteURI)(ModAPI.util.str("data:text/plain,hi")).then(arraybuffer => {
|
||||||
|
console.log(arraybuffer);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
The way this promisify method works is by taking in a java method, and (effectively) converting it into a javascript async function.
|
||||||
|
For example, you can do:
|
||||||
|
```javascript
|
||||||
|
var asyncDownloadRemoteURI = ModAPI.promisify(ModAPI.hooks.methods.nlevi_PlatformRuntime_downloadRemoteURI);
|
||||||
|
|
||||||
|
console.log(typeof asyncDownloadRemoteURI); //Logs function
|
||||||
|
```
|
||||||
|
|
||||||
|
When it is called, like any other asyncronous function, it returns a `Promise` object.
|
||||||
|
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise
|
||||||
|
|
||||||
|
You can replace the argument with any other method or constructor, including non asynchronous ones.
|
||||||
@@ -0,0 +1,84 @@
|
|||||||
|
## ModAPI.reflect
|
||||||
|
|
||||||
|
ModAPI.reflect supplies a user friendly wrapper for accessing and interacting with java classes from javascript.
|
||||||
|
|
||||||
|
Properties:
|
||||||
|
|
||||||
|
- `classes: ReflectClass[]`
|
||||||
|
- `ModAPI.reflect.classes` is an array of ReflectClasses, representing (almost) every java class.
|
||||||
|
- `classMap: Map<String, ReflectClass>` is a map of every class.
|
||||||
|
|
||||||
|
Methods:
|
||||||
|
|
||||||
|
- `ModAPI.reflect.getClassById(classId: String) : ReflectClass`
|
||||||
|
- This method is used to find a class by its id.
|
||||||
|
- For example, to get the `Minecraft` class, you can use `ModAPI.reflect.getClassById("net.minecraft.client.Minecraft")`
|
||||||
|
- `ModAPI.reflect.getClassByName(className: String) : ReflectClass`
|
||||||
|
- This method is used to find a class by its id.
|
||||||
|
- For example, to get the `Minecraft` class, you can use `ModAPI.reflect.getClassById("Minecraft")`
|
||||||
|
- This runs slower than `getClassById` because it has to filter through all classes. Make sure to cache the result rather than calling it over and over again.
|
||||||
|
- `ModAPI.reflect.getSuper(rClass: ReflectClass, filter: Function?) : Function`
|
||||||
|
- Gets a super function from a reflect class. This is used to extend built in classes, like `Block`.
|
||||||
|
- For an example, see lines [29](https://github.com/eaglerforge/EaglerForgeInjector/blob/6e8598c180f96a65c0c101be72e6d0fa53195404/examplemods/unlucky_blocks.js#L29) and [33](https://github.com/eaglerforge/EaglerForgeInjector/blob/6e8598c180f96a65c0c101be72e6d0fa53195404/examplemods/unlucky_blocks.js#L33) in `unlucky_blocks.js`
|
||||||
|
- When called without a filter function, the filter defaults to `(fn)=>fn.length === 1`
|
||||||
|
- `ModAPI.reflect.prototypeStack(rClass: ReflectClass, target: Class/ConstructorFunction) : void`
|
||||||
|
- Copies methods from a reflect class and it's parents onto a target native JavaScript class. This allows TeaVM to use these objects normally, without you having to manually reimplement every method. In other words, this is the equivalent of extending a class.
|
||||||
|
- Also adds some metadata to make the class work with `ModAPI.util.asClass`
|
||||||
|
- [Example usage](https://github.com/eaglerforge/EaglerForgeInjector/blob/6e8598c180f96a65c0c101be72e6d0fa53195404/examplemods/unlucky_blocks.js#L37)
|
||||||
|
- `ModAPI.reflect.implements(target: Class/ConstructorFunction, interface: ReflectClass)`
|
||||||
|
- Marks the provided interface as a supertype of the target class.
|
||||||
|
- JavaScript equivalent of the `implements` keyword
|
||||||
|
### ReflectClass Definition
|
||||||
|
|
||||||
|
Each `ReflectClass` has the following properties:
|
||||||
|
|
||||||
|
- `binaryName: String?`
|
||||||
|
- The binary name of the class in question. Eg: `Lnet.minecraft.client.entity.EntityPlayerSP;`
|
||||||
|
- Will be `null` if `hasMeta` is equal to `false`
|
||||||
|
- `class: Class?`
|
||||||
|
- The actual class. Cannot be used easily with `new` keyword, this is mostly useful for extending using `prototype`.
|
||||||
|
- Will be `null` if `hasMeta` is equal to `false`
|
||||||
|
- `compiledName: String`
|
||||||
|
- The TeaVM compiled name of the class. It is equal to the first letters of the package, an underscore, and the class name. Eg: `nmce_EntityPlayerSP`
|
||||||
|
- `constructors: Function[]`
|
||||||
|
- The constructors for the class.
|
||||||
|
- `hasMeta: Boolean`
|
||||||
|
- Wether or not the class has metadata saved by TeaVM.
|
||||||
|
- `id: String?`
|
||||||
|
- The class id of the class. Eg: `net.minecraft.client.entity.EntityPlayerSP`
|
||||||
|
- Will be `null` if `hasMeta` is equal to `false`
|
||||||
|
- `name: String`
|
||||||
|
- The name of the class. Eg: `EntityPlayerSP`
|
||||||
|
- `methods: Map<String, ReflectMethod>`
|
||||||
|
- `staticMethods: Map<String, ReflectMethod>`
|
||||||
|
- `staticVariableNames: String[]`
|
||||||
|
- List of all the static variable names for the class.
|
||||||
|
- `staticVariables: Map<String, *>`
|
||||||
|
- key-value dictionary of all the static variables in a class.
|
||||||
|
- `superclass: ReflectClass?`
|
||||||
|
- The superclass.
|
||||||
|
|
||||||
|
Each `ReflectClass` has the following methods:
|
||||||
|
|
||||||
|
- `instanceOf(object: Object)`
|
||||||
|
- Checks if the `object` is an instance of the class.
|
||||||
|
- `getConstructorByArgs(...argumentNames) : Function`
|
||||||
|
- Finds a constructor that matches the specified argument names. Eg:
|
||||||
|
- `ModAPI.reflect.getClassByName("ItemStack").getConstructorByArgs("blockIn", "amount")`
|
||||||
|
|
||||||
|
### ReflectMethod Definition
|
||||||
|
|
||||||
|
Each `ReflectMethod` has the following properties:
|
||||||
|
|
||||||
|
- `methodName: String`
|
||||||
|
- The compiled method name of the method. Eg: `nmce_EntityPlayerSP_closeScreen`.
|
||||||
|
- `methodNameShort: String`
|
||||||
|
- The short name of the method. Eg: `closeScreen`.
|
||||||
|
|
||||||
|
Each `ReflectClass` has the following methods:
|
||||||
|
- `method(...)`
|
||||||
|
- This is the java method.
|
||||||
|
- If it is an instance method (accessed from a ReflectClasses' `methods` property), the first argument should be an instance of the class. Eg: `ModAPI.reflect.getClassByName("EntityPlayerSP").methods.closeScreen.method(ModAPI.player.getRef())`
|
||||||
|
- If it is a static method (accessed from a ReflectClasses' `staticMethods` property), call the method as usual. Eg: `ModAPI.reflect.getClassById("net.minecraft.init.Items").staticMethods.getRegisteredItem.method(ModAPI.util.str("apple"))`
|
||||||
|
|
||||||
|
Keep in mind that you need to wrap strings using `ModAPI.util.str("MyString")`, convert booleans into respective numbers (`true`->`1`, `false`->`0`), and get references of ModAPI proxies (`ModAPI.player`->`ModAPI.player.getRef()`);
|
||||||
@@ -0,0 +1,87 @@
|
|||||||
|
## ModAPI.util
|
||||||
|
|
||||||
|
ModAPI.util provides and exposes a large number of utilities for interacting with ModAPI.
|
||||||
|
|
||||||
|
Properties:
|
||||||
|
|
||||||
|
- `StaticProps_ProxyConf: ProxyConfiguration`
|
||||||
|
- This is the proxy configuration used for exposing `ModAPI.items`, `ModAPI.blocks`, `ModAPI.enchantments` and `ModAPI.materials`
|
||||||
|
- See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy/Proxy
|
||||||
|
- `TeaVM_to_BaseData_ProxyConf: ProxyConfiguration`
|
||||||
|
- This is a non-recursive proxy config for removing prefixes from java objects.
|
||||||
|
- `TeaVM_to_Recursive_BaseData_ProxyConf: ProxyConfiguration`
|
||||||
|
- This is a recursive proxy config for removing prefixes from java objects. It handles properties (both object and array) as well as function outputs. Used for `ModAPI.player`, `ModAPI.mc`, `ModAPI.world`, `ModAPI.network` and more.
|
||||||
|
- `TeaVMArray_To_Recursive_BaseData_ProxyConf: ProxyConfiguration`
|
||||||
|
- This is a recursive proxy config for handling arrays from `TeaVM_to_Recursive_BaseData_ProxyConf`
|
||||||
|
|
||||||
|
Methods:
|
||||||
|
|
||||||
|
- `ModAPI.util.str(jsString: String) : java.lang.String`
|
||||||
|
- Converts a javascript string to a java string, for use in java methods and constructors.
|
||||||
|
- Alias: `ModAPI.util.string()`
|
||||||
|
- `ModAPI.util.unstr(jclString: java.lang.String) : String`
|
||||||
|
- Converts a java string to a javascript string.
|
||||||
|
- Alias: `ModAPI.util.ustr()`
|
||||||
|
- Alias: `ModAPI.util.unstring()`
|
||||||
|
- Alias: `ModAPI.util.jclStrToJsStr()`
|
||||||
|
- `ModAPI.util.getMethodFromPackage(classId: String, methodName: String) : String`
|
||||||
|
- Takes a class id (eg: `net.minecraft.client.Minecraft`) and a method name (eg: `middleClickMouse`) and returns its key in `ModAPI.hooks.methods`.
|
||||||
|
- `ModAPI.util.stringToUint16Array(string: String) : Uint16Array`
|
||||||
|
- Encodes a string into a uint16array.
|
||||||
|
- `ModAPI.util.setStringContent(jclString: java.lang.String, contents: String) : void`
|
||||||
|
- Writes a new javascript string into the contents of a java string.
|
||||||
|
- `ModAPI.util.getMethodFromPackage(classId: String, methodName: String) : String`
|
||||||
|
- Takes a class id (eg: `net.minecraft.client.Minecraft`) and a method name (eg: `middleClickMouse`) and returns its key in `ModAPI.hooks.methods`.
|
||||||
|
- `ModAPI.util.hashCode(string: String) : String`
|
||||||
|
- Returns the hash of a string.
|
||||||
|
- `ModAPI.util.isCritical() : boolean`
|
||||||
|
- Checks wether the thread is in a critical state.
|
||||||
|
- When patching methods, it is good practice to allow the method to resume as usual if this is `true`, to avoid stack implosions. (yes, those are real)
|
||||||
|
- `ModAPI.util.bootstrap() : void`
|
||||||
|
- Regenerate proxies for ModAPI.items, .blocks, .materials, .enchantments
|
||||||
|
- `ModAPI.util.createArray(class, jsArray) : Object[]`
|
||||||
|
- Makes a java array from a class and a javascript array.
|
||||||
|
- The class parameter can be retrieved via reflect: `ModAPI.reflect.getClassById("net.minecraft.util.BlockPos").class`
|
||||||
|
- `ModAPI.util.wrap(obj: Object) : object`
|
||||||
|
- Returns a wrapper around native java objects, removing prefixes and fixing method outputs.
|
||||||
|
- `ModAPI.util.getNearestProperty(object: Object, property: string) : string`
|
||||||
|
- Finds the nearest property name to the one you specify (suffix based). This is used to mitigate teavm adding random suffixes to properties.
|
||||||
|
- `ModAPI.util.modifyFunction(fn: Function, patcherFunction: Function) : string`
|
||||||
|
- Returns a modifies version of a function, where the patcher function can be used to modify the contents of a function. Example:
|
||||||
|
```javascript
|
||||||
|
function add(a, b) {
|
||||||
|
return a + b;
|
||||||
|
}
|
||||||
|
var multiply = ModAPI.util.modifyFunction(add, (code)=>{
|
||||||
|
return code.replaceAll("a + b", "a * b");
|
||||||
|
});
|
||||||
|
console.log(multiply(2, 3));
|
||||||
|
//Logs 6
|
||||||
|
```
|
||||||
|
- `ModAPI.util.modifyFunction(fn: Function, patcherFunction: Function) : string`
|
||||||
|
- Returns a modifies version of a function, where the patcher function can be used to modify the contents of a function. Example:
|
||||||
|
```javascript
|
||||||
|
function add(a, b) {
|
||||||
|
return a + b;
|
||||||
|
}
|
||||||
|
var multiply = ModAPI.util.modifyFunction(add, (code)=>{
|
||||||
|
return code.replaceAll("a + b", "a * b");
|
||||||
|
});
|
||||||
|
console.log(multiply(2, 3));
|
||||||
|
//Logs 6
|
||||||
|
```
|
||||||
|
- `ModAPI.util.getIdFromItem(item: Item) : number`
|
||||||
|
- Gets the ID of an item
|
||||||
|
- `ModAPI.util.getItemById(id: number) : Item`
|
||||||
|
- Gets an item by it's ID
|
||||||
|
- `ModAPI.util.getItemFromBlock(block: Block) : ItemBlock`
|
||||||
|
- Gets an item from a block.
|
||||||
|
- `ModAPI.util.getIdFromBlock(block: Block) : number`
|
||||||
|
- Gets the ID of a block
|
||||||
|
- `ModAPI.util.getBlockById(id: number) : Block`
|
||||||
|
- Gets a block by it's ID
|
||||||
|
- `ModAPI.util.getBlockFromItem(item: Item) : Block`
|
||||||
|
- Gets a block from an ItemBlock instance.
|
||||||
|
- `ModAPI.util.asClass(class: Class) : Class`
|
||||||
|
- Converts a javascript class to a java class.
|
||||||
|
- Equivalent of using `MyClass.class` in java.
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
# EaglerForge Injector Architecture
|
||||||
|
The Injector has several layers (or steps) in it's patching process. These layers can be put into two seperate categories: pre-processing and post-processing. The injector patches the EaglercraftX build with the pre-processor ahead of time, and then the post-processor is appended to the EaglercraftX build.
|
||||||
|
|
||||||
|
## Preprocessing
|
||||||
|
The preprocessor's job is to find and hook into as many internal TeaVM / Minecraft methods as possible.
|
||||||
|
|
||||||
|
The first thing it does is it adds a piece of pre-initialisation code at the start of the TeaVM module, to define global varaibles such as `ModAPI` and `ModAPI.hooks`.
|
||||||
|
|
||||||
|
Then it:
|
||||||
|
|
||||||
|
Hooks into the `$rt_metadata` function, intercepting its arguments and storing them in the array `ModAPI.hooks._rippedData`.
|
||||||
|
|
||||||
|
Hooks into the the teavm threading shim and adds controls to freeze the callstack.
|
||||||
|
|
||||||
|
Looks for the `#game_frame` element, and then adds the post-processing codes after it (`modapi_postinit`, `modapi_modloader` and `modapi_guikit`). It also stores a copy of the `modapi_postinit` script into a fourth post init script, for the post-processing scripts to inject into the dedicated server.
|
||||||
|
|
||||||
|
Searches for constructors and appends them to the `ModAPI.hooks._rippedConstructors` dictionary.
|
||||||
|
|
||||||
|
Extracts and hooks into all class methods, storing their type (`instance` or `static`) into `ModAPI.hooks._rippedMethodTypeMap`, and storing the method itself in `ModAPI.hooks.methods`
|
||||||
|
|
||||||
|
Finds static class variables, and build a proxy object for them, to allow for readwrite access even though there is no way to expose their context. The keys for the static properties of a specific class are stored under `ModAPI.hooks._rippedStaticIndexer` and the proxy objects are stored in `ModAPI.hooks._rippedStaticProperties`.
|
||||||
|
|
||||||
|
Finally, it adds references (not hooks, as they would tank performance) to all TeaVM internal methods, most importantly `$rt_str` and `$rt_ustr`, used for interaction with jcl strings.
|
||||||
|
|
||||||
|
## Postprocessing
|
||||||
|
The post processor is much simpler than the preprocessor, but it effectively uses the data in `ModAPI.hooks` to create a (mostly) backwards compatible `ModAPI` global.
|
||||||
@@ -0,0 +1,53 @@
|
|||||||
|
# Compiling Eaglercraft with support for EFI
|
||||||
|
In recent updates of eaglercraft, compiling for EaglerForgeInjector has become a great deal more complicated. To enable reflection and disable obfuscation, follow these steps once you have an EaglercraftX workspace set up:
|
||||||
|
|
||||||
|
|
||||||
|
1. In any files named `build.gradle`, set the `obfuscate` property to `false`.
|
||||||
|
2. In any files named `build.gradle`, find any code that looks like this:
|
||||||
|
```javascript
|
||||||
|
tasks.named("generateJavaScript") {
|
||||||
|
doLast {
|
||||||
|
|
||||||
|
// NOTE: This step may break at any time, and is not required for 99% of browsers
|
||||||
|
|
||||||
|
def phile = file(folder + "/" + name)
|
||||||
|
def dest = phile.getText("UTF-8")
|
||||||
|
def i = dest.substring(0, dest.indexOf("=\$rt_globals.Symbol('jsoClass');")).lastIndexOf("let ")
|
||||||
|
dest = dest.substring(0, i) + "var" + dest.substring(i + 3)
|
||||||
|
def j = dest.indexOf("function(\$rt_globals,\$rt_exports){")
|
||||||
|
dest = dest.substring(0, j + 34) + "\n" + file(folder + "/ES6ShimScript.txt").getText("UTF-8") + "\n" + dest.substring(j + 34)
|
||||||
|
phile.write(dest, "UTF-8")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
and delete it.
|
||||||
|
3. Inside of the `src/teavm/java/net/lax1dude/eaglercraft/v1_8/internal/teavm/` folder, create a new file called `ForceReflection.java`, with these contents:
|
||||||
|
```java
|
||||||
|
package net.lax1dude.eaglercraft.v1_8.internal.teavm;
|
||||||
|
|
||||||
|
public class ForceReflection {
|
||||||
|
public static Object myObject;
|
||||||
|
|
||||||
|
public static Object forceInit(Class iClass) {
|
||||||
|
myObject = new ReflectiveClass();
|
||||||
|
try {
|
||||||
|
myObject = iClass.newInstance();
|
||||||
|
} catch (Exception e) {
|
||||||
|
// TODO: handle exception
|
||||||
|
}
|
||||||
|
return myObject;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class ReflectiveClass {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
4. In the same folder, edit `MainClass.java` edit the start of the `main(String[] args)` method to look like this:
|
||||||
|
```java
|
||||||
|
public static void main(String[] args) {
|
||||||
|
ForceReflection.forceInit(ForceReflection.class);
|
||||||
|
if(args.length == 1) {
|
||||||
|
//... rest of method
|
||||||
|
```
|
||||||
|
5. Finally, build an offline download by using `CompileJS.bat`/`CompileJS.sh` and then `MakeOfflineDownload.bat`/`MakeOfflineDownload.sh`.
|
||||||
|
6. You can then upload the `EaglercraftX_1.8_Offline_en_US.html` into EaglerForgeInjector.
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
## eaglercraftXOpts and search parameters
|
||||||
|
|
||||||
|
### noInitialModGui
|
||||||
|
- `processed.html?noInitialModGui=true`
|
||||||
|
or inside eaglercraftXOpts
|
||||||
|
|
||||||
|
disables the mod gui display on startup
|
||||||
|
|
||||||
|
|
||||||
|
### Adding mods
|
||||||
|
Set eaglercraftXOpts.Mods to an array of mod urls.
|
||||||
|
|
||||||
|
You can also use search parameters, eg:
|
||||||
|
- `processed.html?mod=https://example.com/mod.js`
|
||||||
|
- `processed.html?mod=https://example.com/mod.js&mod=https://example.com/mod2.js`
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
# EaglerForgeInjector
|
||||||
|
EaglerForge Injector is a tool that uses regular expressions to attach itself to internal code inside of raw EaglercraftX offline downloads (sounds easy, isn't at all).
|
||||||
|
|
||||||
|
### Documentation fragments
|
||||||
|
[Injector Architecture](architecture.md)
|
||||||
|
|
||||||
|
[TeaVM quirks](quirks.md)
|
||||||
|
|
||||||
|
[Modding tutorials](tutorials/index.md)
|
||||||
|
|
||||||
|
[Modding API documentation](apidoc/index.md)
|
||||||
|
|
||||||
|
[Compiling the client for EaglerForgeInjector](compiling_client.md)
|
||||||
|
|
||||||
|
[eaglercraftXopts and search parameters](config.md)
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
## TeaVM Quirks and Caveats
|
||||||
|
When TeaVM compiles code, it sometimes does strange things.
|
||||||
|
|
||||||
|
#### Property Suffixes
|
||||||
|
TeaVM will add suffixes to some variables, seemingly randomly. An example is the property `inGround` of any entity. When accessing this on the `ModAPI.player.fishEntity` object, TeaVM has renamed it to `inGround2`. Can be mitigated with `ModAPI.util.getNearestProperty`, or, even better, using a corrective version of ModAPI.player.
|
||||||
|
|
||||||
|
#### Collapsing Methods
|
||||||
|
When I was trying to hook into the server-side processing of chat messages, I found that chat packets were handled by the method `processChatMessage` in `NetHandlerPlayServer`. However, in the compiled JavaScript, this method no longer exists. This is because it is only used once, in the `processPacket` method of `C01PacketChatMessage`. TeaVM automatically saw this, and collapsed one method into the other.
|
||||||
|
|
||||||
|
#### Dedicated Server Not Responding / Client Not Responding
|
||||||
|
Incorrectly patching methods with ModAPI.hooks (such as returning `false` instead of `0`, or a javascript string without using `ModAPI.str()`) will effectively cause the memory stack to implode, along with all crash handlers. I came across this when I was using the `processcommand` event with preventDefault set to true. I didn't return any value when patching methods for the event being `preventDefault`ed, when the output expected was a java boolean (`0`/`1`). This would cause the dedicated server to freeze/lock up, without triggering any form of crash.
|
||||||
|
|
||||||
|
Update 13/09/2024:
|
||||||
|
Any form of incorrect data type, even passing the wrong values, can cause this sort of hang. I encountered this when trying to set a block in the world to any form of wood or leaf block, without adding iproperties to the tree type.
|
||||||
|
|
||||||
|
Update 13/09/2024:
|
||||||
|
Calling methods while the TeaVM thread is in a critical transition state (see `ModAPI.util.isCritical()`) will shift the call stack, cause methods to access the incorrect values at runtime, and also cause the stack to implode. Gotta love TeaVM.
|
||||||
|
|
||||||
|
Update 22/09/2024:
|
||||||
|
See Asynchronous Code
|
||||||
|
|
||||||
|
Update 4/10/2024:
|
||||||
|
@Async issue solved, see [PromisifyDocumentation](apidoc/promisify.md)
|
||||||
|
|
||||||
|
#### TeaVM thread suspension/resumption
|
||||||
|
TeaVM allows for writing asynchronous callbacks, which eaglercraft uses for file operations and downloading from URIs. However, when a method that makes use of an async callback gets run from ModAPI, it triggers a stack implosion due to mismatches in value types upon return (as well as a whole other myriad of symptoms). Currently this is not supported by ModAPI, and it will take some time until it will be. In the meanwhile, avoid using constructors or methods that access a file or use other asynchronous apis. Examples:
|
||||||
|
- Constructing an EntityPlayerMP
|
||||||
|
- Setting blocks in the world in some occasions
|
||||||
|
|
||||||
|
Potential workarounds: This isn't confirmed yet, but there is a probable chance that overriding or patching methods in classes like VFile2 or PlatformFilesystem is a viable workaround. (22/09/2024).
|
||||||
|
I'll be verifying this is the future and if it is possible, releasing a library for it. (the maybe-library is going to be called AsyncSink if it will exist)
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
## Coming Soon / It's not done yet.
|
||||||
File diff suppressed because one or more lines are too long
@@ -0,0 +1,127 @@
|
|||||||
|
## Custom Item Tutorial with ModAPI
|
||||||
|
This tutorial will cover making custom items with ModAPI. It is recommended that you follow the [custom block tutorial](custom_block.md) first, as this tutorial is more fast-paced. The custom item we'll be adding will set the player's velocity to a random value when used, to demonstrate how methods can be overridden.
|
||||||
|
|
||||||
|
We'll begin with a constant item texture encoded into a data URI, as well as some metadata.
|
||||||
|
```javascript
|
||||||
|
(function CustomItemMod() {
|
||||||
|
const itemTexture = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAKZJREFUOE9j/P//PxMDBIBoEP6HREOl4PLIciA2AyPIgMcM//7KgvWSDJjBBpx9/+YvJzc3Sbq12DhB6sEGsJ19/+YnmQawYhigzc7FcPXnN4KugbqAHWQAy9n3b34T4wJkw6EGYLqAoNVQBWS5ANlwZBfAvUCs/0EGkW0AzBKqGoCSDgh5A80F2KMRpAgfAKUT6kcjsfEPUycmKMQgy8AETkgUZWcAS3CPIf4oSPsAAAAASUVORK5CYII=";
|
||||||
|
|
||||||
|
ModAPI.meta.title("Custom Item Mod");
|
||||||
|
ModAPI.meta.icon(itemTexture);
|
||||||
|
ModAPI.meta.description("it's a custom item. what more do you want");
|
||||||
|
ModAPI.meta.credits("By <author_name>");
|
||||||
|
})();
|
||||||
|
```
|
||||||
|
|
||||||
|
Add a function that will contain the code to register the item called `CustomItem`. Inside it we'll do something really similar to the custom blocks tutorial, where we'll define a custom item class, and then register it (or, if on the server, wait until the `bootstrap` event fires). The reason it's contained in a function is to make the job of running the same code on the server and client easier.
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
(function CustomItemMod() {
|
||||||
|
//...
|
||||||
|
|
||||||
|
function CustomItem() {
|
||||||
|
var creativeMiscTab = ModAPI.reflect.getClassById("net.minecraft.creativetab.CreativeTabs").staticVariables.tabMisc; //chuck it in the miscellaneous category ig
|
||||||
|
var itemClass = ModAPI.reflect.getClassById("net.minecraft.item.Item"); //Get the item class
|
||||||
|
var itemSuper = ModAPI.reflect.getSuper(itemClass, (x) => x.length === 1); //Get the super() function of the item class that has a length of 1
|
||||||
|
function CustomItem() {
|
||||||
|
itemSuper(this); //Use super function to get block properties on this class.
|
||||||
|
this.$setCreativeTab(creativeMiscTab); //Set the creative tab of the item to be the misc tab
|
||||||
|
}
|
||||||
|
ModAPI.reflect.prototypeStack(itemClass, CustomItem); // ModAPI equivalent of `extends` in java
|
||||||
|
CustomItem.prototype.$onItemRightClick = function ($itemstack, $world, $player) { //example of how to override a method
|
||||||
|
//use ModAPI.util.wrap to create a proxy of the player and the world without $ prefixes on the properties and methods
|
||||||
|
var player = ModAPI.util.wrap($player);
|
||||||
|
var world = ModAPI.util.wrap($world);
|
||||||
|
|
||||||
|
if (!world.isRemote) { //If we are on the server
|
||||||
|
// Math.random() returns a number from 0.0 to 1.0, so we subtract 0.5 and then multiply by 2 to make it become -1.0 to 1.0 instead
|
||||||
|
player.motionX += (Math.random() - 0.5) * 3;
|
||||||
|
player.motionZ += (Math.random() - 0.5) * 3;
|
||||||
|
|
||||||
|
player.motionY += Math.random() * 1.5; // gravity is a thing, so no negative numbers here otherwise it'll be boring
|
||||||
|
}
|
||||||
|
|
||||||
|
return $itemstack;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Internal registration function. This will be used to actually register the item on both the client and the server.
|
||||||
|
function internal_reg() {
|
||||||
|
// Construct an instance of the CustomItem, and set it's unlocalized name (translation id)
|
||||||
|
var custom_item = (new CustomItem()).$setUnlocalizedName(
|
||||||
|
ModAPI.util.str("custom_item")
|
||||||
|
);
|
||||||
|
//Register it using ModAPI.keygen() to get the item id.
|
||||||
|
itemClass.staticMethods.registerItem.method(ModAPI.keygen.item("custom_item"), ModAPI.util.str("custom_item"), custom_item);
|
||||||
|
|
||||||
|
//Expose it to ModAPI
|
||||||
|
ModAPI.items["custom_item"] = custom_item;
|
||||||
|
|
||||||
|
//return the instance.
|
||||||
|
return custom_item;
|
||||||
|
}
|
||||||
|
|
||||||
|
//if the item global exists (and it will on the client), register the item and return the registered instance.
|
||||||
|
if (ModAPI.items) {
|
||||||
|
return internal_reg();
|
||||||
|
} else {
|
||||||
|
//Otherwise attatch the registration method to the bootstrap method.
|
||||||
|
ModAPI.addEventListener("bootstrap", internal_reg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})();
|
||||||
|
```
|
||||||
|
|
||||||
|
Now let's run the `CustomItem` function on the server and the client, and then use [AsyncSink](../../examplemods/AsyncSink.js) to create an in-memory resource pack to load item textures and models!
|
||||||
|
```javascript
|
||||||
|
(function CustomItemMod() {
|
||||||
|
const itemTexture = "...";
|
||||||
|
|
||||||
|
ModAPI.meta.title("Custom Item Mod");
|
||||||
|
ModAPI.meta.icon(itemTexture);
|
||||||
|
ModAPI.meta.description("it's a custom item. what more do you want");
|
||||||
|
ModAPI.meta.credits("By <author_name>");
|
||||||
|
|
||||||
|
function CustomItem() {
|
||||||
|
// ...
|
||||||
|
}
|
||||||
|
|
||||||
|
// Run the function when the dedicated server loads.
|
||||||
|
ModAPI.dedicatedServer.appendCode(CustomItem);
|
||||||
|
|
||||||
|
// Run the function on the client
|
||||||
|
var custom_item = CustomItem();
|
||||||
|
|
||||||
|
ModAPI.addEventListener("lib:asyncsink", async () => {
|
||||||
|
ModAPI.addEventListener("lib:asyncsink:registeritems", (renderItem)=>{
|
||||||
|
renderItem.registerItem(custom_item, ModAPI.util.str("custom_item"));
|
||||||
|
});
|
||||||
|
AsyncSink.L10N.set("item.custom_item.name", "Cool Custom Item");
|
||||||
|
AsyncSink.setFile("resourcepacks/AsyncSinkLib/assets/minecraft/models/item/custom_item.json", JSON.stringify(
|
||||||
|
{
|
||||||
|
"parent": "builtin/generated",
|
||||||
|
"textures": {
|
||||||
|
"layer0": "items/custom_item"
|
||||||
|
},
|
||||||
|
"display": {
|
||||||
|
"thirdperson": {
|
||||||
|
"rotation": [ -90, 0, 0 ],
|
||||||
|
"translation": [ 0, 1, -3 ],
|
||||||
|
"scale": [ 0.55, 0.55, 0.55 ]
|
||||||
|
},
|
||||||
|
"firstperson": {
|
||||||
|
"rotation": [ 0, -135, 25 ],
|
||||||
|
"translation": [ 0, 4, 2 ],
|
||||||
|
"scale": [ 1.7, 1.7, 1.7 ]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
));
|
||||||
|
AsyncSink.setFile("resourcepacks/AsyncSinkLib/assets/minecraft/textures/items/custom_item.png", await (await fetch(
|
||||||
|
itemTexture
|
||||||
|
)).arrayBuffer());
|
||||||
|
});
|
||||||
|
})();
|
||||||
|
```
|
||||||
|
|
||||||
|
That's it! Upload your completed mod, run `.reload_tex` in chat in a singleplayer world and use your new item!\
|
||||||
|
[completed mod]()
|
||||||
@@ -0,0 +1,90 @@
|
|||||||
|
## Disable All Particles
|
||||||
|
Particles in minecraft are really laggy, and there's a large chance you may want to disable them to boost your FPS when breaking blocks.
|
||||||
|
|
||||||
|
Let's look through the Eaglercraft 1.8 source code to find where particles are rendered. We can do this with a global search for `particle`. You'll find a lot of hits in the `EffectRenderer` class in the `net.minecraft.client.particle` package. We methods we'll want to patch are:
|
||||||
|
- `renderParticles`
|
||||||
|
- `addEffect`
|
||||||
|
- `addBlockDestroyEffects`
|
||||||
|
- `hasParticlesInAlphaLayer`
|
||||||
|
|
||||||
|
For the first 3 methods, you can see that they are defined something like:
|
||||||
|
```java
|
||||||
|
public void renderParticles() {
|
||||||
|
// render particles code.
|
||||||
|
}
|
||||||
|
```
|
||||||
|
The `void` in `public void` means that it does not expect a return value.
|
||||||
|
Using [`ModAPI.util.getMethodFromPackage`](../apidoc/utils.md) we can find the compiled method name, and look for it in [`ModAPI.hooks.methods`](../apidoc/hooks.md#property-modapihooksmethods).
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
(function NoParticles() {
|
||||||
|
//Basic, boilerplate code
|
||||||
|
ModAPI.meta.title("No Particles");
|
||||||
|
ModAPI.meta.description("Disables all particles in game");
|
||||||
|
ModAPI.meta.credits("By <developer name>");
|
||||||
|
|
||||||
|
ModAPI.hooks.methods[
|
||||||
|
ModAPI.util.getMethodFromPackage("net.minecraft.client.particle.EffectRenderer", "renderParticles")
|
||||||
|
] = function () {}; //Override renderParticles in EffectRenderer to an empty function that does nothing.
|
||||||
|
})();
|
||||||
|
```
|
||||||
|
|
||||||
|
We can also do this for `addEffect` and `addBlockDestroyEffects`.
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
(function NoParticles() {
|
||||||
|
//Basic, boilerplate code
|
||||||
|
ModAPI.meta.title("No Particles");
|
||||||
|
ModAPI.meta.description("Disables all particles in game");
|
||||||
|
ModAPI.meta.credits("By <developer name>");
|
||||||
|
|
||||||
|
ModAPI.hooks.methods[
|
||||||
|
ModAPI.util.getMethodFromPackage("net.minecraft.client.particle.EffectRenderer", "renderParticles")
|
||||||
|
] = function () {}; //Override renderParticles in EffectRenderer with an empty function that does nothing.
|
||||||
|
|
||||||
|
ModAPI.hooks.methods[
|
||||||
|
ModAPI.util.getMethodFromPackage("net.minecraft.client.particle.EffectRenderer", "addEffect")
|
||||||
|
] = function () {}; //Override addEffect in EffectRenderer with an empty function that does nothing.
|
||||||
|
|
||||||
|
ModAPI.hooks.methods[
|
||||||
|
ModAPI.util.getMethodFromPackage("net.minecraft.client.particle.EffectRenderer", "addBlockDestroyEffects")
|
||||||
|
] = function () {}; //Override addBlockDestroyEffects in EffectRenderer with an empty function that does nothing.
|
||||||
|
})();
|
||||||
|
```
|
||||||
|
|
||||||
|
For `hasParticlesInAlphaLayer`, it doesn't use `void`, but instead a `boolean`.
|
||||||
|
```java
|
||||||
|
public boolean hasParticlesInAlphaLayer() {
|
||||||
|
// hasParticlesInAlphaLayer code.
|
||||||
|
}
|
||||||
|
```
|
||||||
|
When TeaVM translates booleans, it converts booleans to integers:
|
||||||
|
- `false` turns into `0`
|
||||||
|
- `true` turns into `1`
|
||||||
|
|
||||||
|
So when we override `hasParticlesInAlphaLayer`, we'll need to return a `0` or a `1`. Since we want the game to think that there aren't any particles in the alpha layer, we'll return `0` (false).
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
(function NoParticles() {
|
||||||
|
//Basic, boilerplate code
|
||||||
|
ModAPI.meta.title("No Particles");
|
||||||
|
ModAPI.meta.description("Disables all particles in game");
|
||||||
|
ModAPI.meta.credits("By <developer name>");
|
||||||
|
|
||||||
|
ModAPI.hooks.methods[
|
||||||
|
ModAPI.util.getMethodFromPackage("net.minecraft.client.particle.EffectRenderer", "renderParticles")
|
||||||
|
] = function () {}; //Override renderParticles in EffectRenderer with an empty function that does nothing.
|
||||||
|
|
||||||
|
ModAPI.hooks.methods[
|
||||||
|
ModAPI.util.getMethodFromPackage("net.minecraft.client.particle.EffectRenderer", "addEffect")
|
||||||
|
] = function () {}; //Override addEffect in EffectRenderer with an empty function that does nothing.
|
||||||
|
|
||||||
|
ModAPI.hooks.methods[
|
||||||
|
ModAPI.util.getMethodFromPackage("net.minecraft.client.particle.EffectRenderer", "addBlockDestroyEffects")
|
||||||
|
] = function () {}; //Override addBlockDestroyEffects in EffectRenderer with an empty function that does nothing.
|
||||||
|
|
||||||
|
ModAPI.hooks.methods[
|
||||||
|
ModAPI.util.getMethodFromPackage("net.minecraft.client.particle.EffectRenderer", "hasParticlesInAlphaLayer")
|
||||||
|
] = function () {return 0}; //Override hasParticlesInAlphaLayer in EffectRenderer with a function that returns 0.
|
||||||
|
})();
|
||||||
|
```
|
||||||
@@ -0,0 +1,71 @@
|
|||||||
|
## /hat with ModAPI
|
||||||
|
/hat is a common server-side plugin that lets you put any block/item on your head. This tutorial will explain how to register a server-side command, construct a packet, and send it to a player.
|
||||||
|
[`S09PacketHeldItemChange` constructors](https://nurmarvin.github.io/Minecraft-1.8-JavaDocs/net/minecraft/network/play/server/S09PacketHeldItemChange.html)
|
||||||
|
|
||||||
|
|
||||||
|
As always, start with the basic boilerplate IIFE with credits:
|
||||||
|
```javascript
|
||||||
|
(function HatMod() {
|
||||||
|
ModAPI.meta.title("Hat Mod");
|
||||||
|
ModAPI.meta.description("Use /hat to put anything on your head.");
|
||||||
|
ModAPI.meta.credits("By <author_name>");
|
||||||
|
})();
|
||||||
|
```
|
||||||
|
In order to add a server side command, we need to:
|
||||||
|
- Write a function to run on the server.
|
||||||
|
- In this function, we'll add a listener to the [`processcommand` event](../apidoc/events.md#server-side-events)
|
||||||
|
- We'll check if the command is `/hat`
|
||||||
|
- If it is, we'll swap their head and current hand inventory slots, and send a network packet.
|
||||||
|
- Finally, the function from step 1 is thrown into [`ModAPI.dedicatedServer.appendCode`](../apidoc/dedicatedserver.md)
|
||||||
|
|
||||||
|
Here's the completed code:
|
||||||
|
```javascript
|
||||||
|
(function HatMod() {
|
||||||
|
ModAPI.meta.title("Hat Mod");
|
||||||
|
ModAPI.meta.description("Use /hat to put anything on your head.");
|
||||||
|
ModAPI.meta.credits("By <author_name>");
|
||||||
|
|
||||||
|
ModAPI.dedicatedServer.appendCode(function serverSideCode() {
|
||||||
|
// Find the constructor for the held item change packet that has only one argument.
|
||||||
|
// This will be used to notify the client that their hotbar has been updated.
|
||||||
|
// Reference: https://nurmarvin.github.io/Minecraft-1.8-JavaDocs/net/minecraft/network/play/server/S09PacketHeldItemChange.html
|
||||||
|
var S09PacketHeldItemChange_Constructor = ModAPI.reflect.getClassByName("S09PacketHeldItemChange").constructors.find(x => x.length === 1);
|
||||||
|
|
||||||
|
//Add an event listener for when a command is processed on the server.
|
||||||
|
ModAPI.addEventListener("processcommand", (event) => {
|
||||||
|
// If the command starts with /hat
|
||||||
|
if (event.command.toLowerCase().startsWith("/hat")) {
|
||||||
|
// Exit if the sender isn't a player
|
||||||
|
if (
|
||||||
|
!ModAPI.reflect.getClassById("net.minecraft.entity.player.EntityPlayerMP").instanceOf(
|
||||||
|
event.sender.getRef()
|
||||||
|
)
|
||||||
|
) {
|
||||||
|
return
|
||||||
|
};
|
||||||
|
|
||||||
|
// Get the current held item
|
||||||
|
var heldItem = event.sender.inventory.getCurrentItem();
|
||||||
|
|
||||||
|
// Get the contents of the helmet slot
|
||||||
|
var armorItem = event.sender.inventory.armorInventory[3];
|
||||||
|
|
||||||
|
// Get the inventory index of the current held item
|
||||||
|
var hotbarIdx = event.sender.inventory.currentItem;
|
||||||
|
|
||||||
|
// Set the helmet slot to heldItem.getRef() (raw java object) if heldItem exists, otherwise set it to null
|
||||||
|
event.sender.inventory.armorInventory[3] = heldItem ? heldItem.getRef() : null;
|
||||||
|
|
||||||
|
// Set the hotbar slot to the original value of the helmet slot if it has a value, otherwise set it to null
|
||||||
|
event.sender.inventory.mainInventory[hotbarIdx] = armorItem ? armorItem.getRef() : null;
|
||||||
|
|
||||||
|
// Make a packet to notify the client that the selected hotbar slot has been updated.
|
||||||
|
event.sender.playerNetServerHandler.sendPacket(makePacketItemChange(hotbarIdx));
|
||||||
|
|
||||||
|
// Prevent the 'unknown command' error
|
||||||
|
event.preventDefault = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
})();
|
||||||
|
```
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
## Mod tutorials with ModAPI
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
### Beginner
|
||||||
|
|
||||||
|
Prerequisites:
|
||||||
|
- Basic knowledge of JavaScript
|
||||||
|
- A good code editor (recommended: https://vscode.dev)
|
||||||
|
|
||||||
|
Tutorials:
|
||||||
|
- [Step Hack](step.md)
|
||||||
|
- [Spider Hack](spider.md)
|
||||||
|
- [VClip Exploit](vclip.md)
|
||||||
|
|
||||||
|
### Intermediate
|
||||||
|
Prerequisites:
|
||||||
|
- Intermediate knowledge of JavaScript (functions, arrays, promises, callbacks, keys and values in objects)
|
||||||
|
- A good code editor (recommended: https://vscode.dev)
|
||||||
|
- A copy of the eaglercraft workspace (optional, get it at: https://git.eaglercraft.rip/eaglercraft/eaglercraft-1.8-workspace)
|
||||||
|
|
||||||
|
Tutorials:
|
||||||
|
- [Disable All Particles](disable_all_particles.md)
|
||||||
|
- [Slippery Mod](slippery.md)
|
||||||
|
- [/hat mod](hat.md)
|
||||||
|
- [/spawnxp command](spawnxp.md)
|
||||||
|
|
||||||
|
### Advanced
|
||||||
|
Prerequisites:
|
||||||
|
- Advanced knowledge of JavaScript (prototypes)
|
||||||
|
- A good code editor (recommended: https://vscode.dev)
|
||||||
|
- A copy of the eaglercraft workspace (get it at: https://git.eaglercraft.rip/eaglercraft/eaglercraft-1.8-workspace)
|
||||||
|
- Your EaglerForgeInjector processed.html opened in an editor (optional)
|
||||||
|
|
||||||
|
Tutorials:
|
||||||
|
- [Custom Blocks](custom_block.md)
|
||||||
|
- [Custom Items](custom_item.md)
|
||||||
|
- [Timescale Command](timescale.md)
|
||||||
@@ -0,0 +1,109 @@
|
|||||||
|
## Slippery Mod with ModAPI
|
||||||
|
In this tutorial you will learn how to modify properties of blocks, and run the code that does this on both the dedicated server and the client.
|
||||||
|
|
||||||
|
We'll begin with the basic boilerplate mod code:
|
||||||
|
```javascript
|
||||||
|
(function SlipperyMod() {
|
||||||
|
ModAPI.meta.title("Slippery Mod");
|
||||||
|
ModAPI.meta.description("Makes everything turn into ice.");
|
||||||
|
ModAPI.meta.credits("By <author_name>");
|
||||||
|
|
||||||
|
//New code will go here!
|
||||||
|
})();
|
||||||
|
```
|
||||||
|
|
||||||
|
Let's write the client side part of the code first.
|
||||||
|
- We'll get the keys for the ModAPI.blocks object (ids of each block) using [`Object.keys()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/keys)
|
||||||
|
- Then, we'll loop over those keys, and modify their respective block to be as slippery as ice.
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
var blockKeys = Object.keys(ModAPI.blocks);
|
||||||
|
|
||||||
|
blockKeys.forEach(key => { //for each key (block id)
|
||||||
|
//make sure the block has a slipperiness property
|
||||||
|
//https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Optional_chaining
|
||||||
|
if(ModAPI.blocks[key]?.slipperiness) {
|
||||||
|
ModAPI.blocks[key].slipperiness = 0.98; //Set the slipperiness value of the block at that key to 0.98
|
||||||
|
}
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
Your code should now look like this:
|
||||||
|
```javascript
|
||||||
|
(function SlipperyMod() {
|
||||||
|
ModAPI.meta.title("Slippery Mod");
|
||||||
|
ModAPI.meta.description("Makes everything turn into ice.");
|
||||||
|
ModAPI.meta.credits("By <author_name>");
|
||||||
|
|
||||||
|
var blockKeys = Object.keys(ModAPI.blocks);
|
||||||
|
blockKeys.forEach(key => {
|
||||||
|
if(ModAPI.blocks[key]?.slipperiness) {
|
||||||
|
ModAPI.blocks[key].slipperiness = 0.98;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
})();
|
||||||
|
```
|
||||||
|
|
||||||
|
Your code should now look like this:
|
||||||
|
```javascript
|
||||||
|
(function SlipperyMod() {
|
||||||
|
ModAPI.meta.title("Slippery Mod");
|
||||||
|
ModAPI.meta.description("Makes everything turn into ice.");
|
||||||
|
ModAPI.meta.credits("By <author_name>");
|
||||||
|
|
||||||
|
var blockKeys = Object.keys(ModAPI.blocks);
|
||||||
|
blockKeys.forEach(key => {
|
||||||
|
if(ModAPI.blocks[key]?.slipperiness) {
|
||||||
|
ModAPI.blocks[key].slipperiness = 0.98;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
//dedicated server code will be added here
|
||||||
|
})();
|
||||||
|
```
|
||||||
|
|
||||||
|
Currently this only runs on the client meaning in singleplayer, when you throw an item or punch a sheep, it still won't slide. Only you will.
|
||||||
|
|
||||||
|
We'll have to duplicate the code to run on the server using [`ModAPI.dedicatedServer`](../apidoc/dedicatedserver.md).
|
||||||
|
We also have to run the code after the `serverstart` event, as on the server, `ModAPI.blocks` is only created when it is needed.
|
||||||
|
```javascript
|
||||||
|
ModAPI.dedicatedServer.appendCode(function () {
|
||||||
|
//Code in here cannot reference outside variables.
|
||||||
|
ModAPI.addEventListener("serverstart", function () {
|
||||||
|
var blockKeys = Object.keys(ModAPI.blocks);
|
||||||
|
blockKeys.forEach(key => {
|
||||||
|
if(ModAPI.blocks[key]?.slipperiness) {
|
||||||
|
ModAPI.blocks[key].slipperiness = 0.98;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
let's add this to the final mod, and we'll be finished!
|
||||||
|
```javascript
|
||||||
|
(function SlipperyMod() {
|
||||||
|
ModAPI.meta.title("Slippery Mod");
|
||||||
|
ModAPI.meta.description("Makes everything turn into ice.");
|
||||||
|
ModAPI.meta.credits("By <author_name>");
|
||||||
|
|
||||||
|
var blockKeys = Object.keys(ModAPI.blocks);
|
||||||
|
blockKeys.forEach(key => {
|
||||||
|
if(ModAPI.blocks[key]?.slipperiness) {
|
||||||
|
ModAPI.blocks[key].slipperiness = 0.98;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
ModAPI.dedicatedServer.appendCode(function () {
|
||||||
|
//Code in here cannot reference outside variables.
|
||||||
|
ModAPI.addEventListener("serverstart", function () {
|
||||||
|
var blockKeys = Object.keys(ModAPI.blocks);
|
||||||
|
blockKeys.forEach(key => {
|
||||||
|
if(ModAPI.blocks[key]?.slipperiness) {
|
||||||
|
ModAPI.blocks[key].slipperiness = 0.98;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
})();
|
||||||
|
```
|
||||||
@@ -0,0 +1,67 @@
|
|||||||
|
## /spawnxp command
|
||||||
|
This tutorial will cover spawning in entities using the [`ModAPI.promisify()`](../apidoc/promisify.md) API.
|
||||||
|
|
||||||
|
As usual, we'll start with the boilerplate:
|
||||||
|
```javascript
|
||||||
|
(function SpawnXPMod() {
|
||||||
|
ModAPI.meta.title("Spawn XP");
|
||||||
|
ModAPI.meta.description("Adds a /spawnxp command.");
|
||||||
|
ModAPI.meta.credits("By <author_name>");
|
||||||
|
|
||||||
|
//future code
|
||||||
|
})();
|
||||||
|
```
|
||||||
|
We'll move context to the server, and add a command listener, and ensure the sender is a player:
|
||||||
|
```javascript
|
||||||
|
PluginAPI.dedicatedServer.appendCode(function () { //Run this code on the server
|
||||||
|
PluginAPI.addEventListener("processcommand", (event) => { //Command processing event
|
||||||
|
if (
|
||||||
|
!ModAPI.reflect.getClassById("net.minecraft.entity.player.EntityPlayerMP")
|
||||||
|
.instanceOf(event.sender.getRef())
|
||||||
|
) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
Next, we'll check that the command is /spawnxp. If it is, we'll get the current dimension of the player, and spawn an XP orb at the sender's position. To construct the XP orb, we'll get the `EntityXPOrb` class and get the [first constructor](https://nurmarvin.github.io/Minecraft-1.8-JavaDocs/net/minecraft/entity/EntityXPOrb.html)
|
||||||
|
```javascript
|
||||||
|
PluginAPI.dedicatedServer.appendCode(function () { //Run this code on the server
|
||||||
|
PluginAPI.addEventListener("processcommand", (event) => { //Command processing event
|
||||||
|
if (
|
||||||
|
!ModAPI.reflect.getClassById("net.minecraft.entity.player.EntityPlayerMP") //If it isn't a player, exit the method
|
||||||
|
.instanceOf(event.sender.getRef())
|
||||||
|
) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (event.command.toLowerCase().startWith("/spawnxp")) {
|
||||||
|
const world = event.sender.getServerForPlayer(); //get the current dimension
|
||||||
|
const senderPos = event.sender.getPosition(); //get the player's current position
|
||||||
|
|
||||||
|
const EntityXP = ModAPI.reflect.getClassByName("EntityXPOrb"); // Get the entity xp orb class
|
||||||
|
|
||||||
|
const xporb = EntityXP.constructors[0](world.getRef(), senderPos.getX(), senderPos.getY(), senderPos.getZ(), 10); //Construct the first constructor, with arguments, World, x, y, z, xp value
|
||||||
|
|
||||||
|
//Get the spawn entity in world method
|
||||||
|
var spawnEntityInWorldMethod = ModAPI.hooks.methods[ModAPI.util.getMethodFromPackage("net.minecraft.world.World", "spawnEntityInWorld")];
|
||||||
|
//Because this method reads and writes data to chunks, it tries to save and load the eaglercraft state, which won't work if eaglercraft is also running its own code.
|
||||||
|
//To work around this issue, use ModAPI.promisify() to convert the method into one that returns a promise
|
||||||
|
spawnEntityInWorldMethod = ModAPI.promisify(spawnEntityInWorldMethod);
|
||||||
|
|
||||||
|
//we can now use the spawnEntityInWorld method
|
||||||
|
//wherever you see getRef(), it means to retrieve the raw, untouched data that TeaVM can use.
|
||||||
|
spawnEntityInWorldMethod(world.getRef(), xporb).then(result => {
|
||||||
|
// Get the chat component class
|
||||||
|
const ChatComponentTextClass = ModAPI.reflect.getClassById("net.minecraft.util.ChatComponentText");
|
||||||
|
|
||||||
|
// Construct the chat component and send it to the client.
|
||||||
|
event.sender.addChatMessage(ChatComponentTextClass.constructors[0](ModAPI.util.str("An xp orb has been spawned!")));
|
||||||
|
});
|
||||||
|
|
||||||
|
//Stop the unknown command error
|
||||||
|
event.preventDefault = true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -0,0 +1,41 @@
|
|||||||
|
## Spider Hack with ModAPI
|
||||||
|
A spider hack allows players to climb up any wall like a spider.
|
||||||
|
|
||||||
|
Start by creating a new file in your code editor. Save it to a folder on your device, ensuring that the file extension is `.js`.
|
||||||
|
|
||||||
|
The spider hack has a lot of similarities to the step hack, so lets copy the step hack and rename the `stepHackUpdateCode` function to `spiderHackUpdateCode`:
|
||||||
|
```javascript
|
||||||
|
ModAPI.require("player");
|
||||||
|
|
||||||
|
function spiderHackUpdateCode() {
|
||||||
|
//We will add code here.
|
||||||
|
}
|
||||||
|
ModAPI.addEventListener("update", spiderHackUpdateCode);
|
||||||
|
```
|
||||||
|
|
||||||
|
Most spider hacks work by checking if the player is walking into a wall, and then setting their vertical velocity to a constant amount (usually `0.2`, for parity with ladders).
|
||||||
|
Let's start by checking if the player is walking into a wall, by adding an if statement inside the `spiderHackUpdateCode` function:
|
||||||
|
```javascript
|
||||||
|
if (ModAPI.player.isCollidedHorizontally) {
|
||||||
|
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
Now, let's set the player's vertical velocity:
|
||||||
|
```javascript
|
||||||
|
if (ModAPI.player.isCollidedHorizontally) {
|
||||||
|
ModAPI.player.motionY = 0.2; //Feel free to change this value to something bigger, smaller or even negative.
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
Time to see the final code:
|
||||||
|
```javascript
|
||||||
|
ModAPI.require("player");
|
||||||
|
|
||||||
|
function spiderHackUpdateCode() {
|
||||||
|
if (ModAPI.player.isCollidedHorizontally) {
|
||||||
|
ModAPI.player.motionY = 0.2; //Feel free to change this value to something bigger, smaller or even negative.
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ModAPI.addEventListener("update", spiderHackUpdateCode);
|
||||||
|
```
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
## Step Hack with ModAPI
|
||||||
|
A step hack allows a player to walk up full blocks (or more) as if they were slabs.
|
||||||
|
|
||||||
|
Start by creating a new file in your code editor. Save it to a folder on your device, ensuring that the file extension is `.js`.
|
||||||
|
|
||||||
|
Let's start by requiring the player. This will allow us to change attributes on the player:
|
||||||
|
```javascript
|
||||||
|
ModAPI.require("player");
|
||||||
|
```
|
||||||
|
|
||||||
|
Now, we have to detect when the player in a world. This will be done with the `update` event, which runs every tick while the player is in a world. In EaglerForge's ModAPI, to run code on an event, you have to create a function. Then, you register the function to an event.
|
||||||
|
```javascript
|
||||||
|
ModAPI.require("player");
|
||||||
|
|
||||||
|
function stepHackUpdateCode() {
|
||||||
|
//We will add code here.
|
||||||
|
}
|
||||||
|
ModAPI.addEventListener("update", stepHackUpdateCode);
|
||||||
|
```
|
||||||
|
|
||||||
|
Inside this method, lets change the player's `stepHeight`, which controls how high they can step. By default this is `0.5`, to alow players to walk up slabs or stairs. I'll change it to `2` for demonstration purposes. You can also try any other number, like `0`, `6`, etc.
|
||||||
|
```javascript
|
||||||
|
ModAPI.require("player");
|
||||||
|
|
||||||
|
function stepHackUpdateCode() {
|
||||||
|
ModAPI.player.stepHeight = 2;
|
||||||
|
}
|
||||||
|
ModAPI.addEventListener("update", stepHackUpdateCode);
|
||||||
|
```
|
||||||
|
|
||||||
|
Now, to load this mod, open your EaglerForge build, and in the start screen select `Upload Mod (.js)`. Upload the mod you created, and you should now be able to walk up two block tall pillars, or more depending on what `stepHeight` you selected.
|
||||||
|
|
||||||
|
Disclaimer: using this on servers may get you banned/kicked for cheating!
|
||||||
@@ -0,0 +1,103 @@
|
|||||||
|
## Timescale Mod with ModAPI
|
||||||
|
This mod will cover adding a new command that controls the speed that Eaglercraft runs at. This tutorial assumes that you have some knowledge on how to use [BigInt](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt) in JavaScript.
|
||||||
|
|
||||||
|
Let's get our basic template code down:
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
(function TimescaleCommand() {
|
||||||
|
ModAPI.meta.title("Timescale Command");
|
||||||
|
ModAPI.meta.description("use /timescale to control time");
|
||||||
|
ModAPI.meta.credits("By <author_name>");
|
||||||
|
})()
|
||||||
|
```
|
||||||
|
|
||||||
|
Our mod is going to be split into 2 distinct parts: client-side and server-side. The client will modify `ModAPI.mc.timer.timerSpeed` when a `/timescale` command is sent, while the server will set the timescale to a global variable, and then modify `net.minecraft.server.MinecraftServer`'s `getCurrentTimeMillis()` to change the rate calculations happen at on the server.\
|
||||||
|
\
|
||||||
|
However, there is a slight logistical problem: the server gets the time in milliseconds as a JavaScript [BigInt](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt), which means we can't just multiply it by a number, we have to either multiply or divide it by another BigInt.
|
||||||
|
```javascript
|
||||||
|
var x = 1n * 1.0; //TypeError
|
||||||
|
|
||||||
|
var x = 1n * 1n; //Success
|
||||||
|
```
|
||||||
|
To allow us to both speed up and slow down time, we'll need to check if the speed inputted is greater or equal to 1. If it is, we round it and then convert it to a `BigInt`, which we'll store on the `globalThis` object. If it's less we'll need to find the speed to the power of -1, or `1 / speed`. We can then round this value and convert that to a `BigInt` to store on `globalThis`. We'll also set `globalThis.timeScaleDividing` to `true`, to signal to replaced `getCurrentTimeMillis()` to divide by the `BigInt` speed factor instead of multiply.\
|
||||||
|
\
|
||||||
|
Finally, due to our `BigInt` rounding shenanigans on the server, we have to replicate the rounding inaccuracy on the client.\
|
||||||
|
\
|
||||||
|
Let's implement the client side part.
|
||||||
|
```javascript
|
||||||
|
(function TimescaleCommand() {
|
||||||
|
ModAPI.meta.title("Timescale Command");
|
||||||
|
ModAPI.meta.description("use /timescale to control time");
|
||||||
|
ModAPI.meta.credits("By <author_name>");
|
||||||
|
|
||||||
|
ModAPI.addEventListener("sendchatmessage", (event) => { // before a message gets sent to the server
|
||||||
|
if (event.message.toLowerCase().startsWith("/timescale")) { //if it is the timescale command
|
||||||
|
var speed = parseFloat(event.message.split(" ")[1]); //get the part of the message after the space
|
||||||
|
if (!speed) { //If it doesn't exist, set it to 1.
|
||||||
|
speed = 1;
|
||||||
|
} else { //If it does exist:
|
||||||
|
if (speed < 1) { //When the speed is less than 1, round the denominator (1 over x)
|
||||||
|
speed = 1 / Math.round(1 / speed);
|
||||||
|
} else {
|
||||||
|
// When the speed is greater or equal to 1, round the numerator (x over 1)
|
||||||
|
speed = Math.round(speed);
|
||||||
|
}
|
||||||
|
// Set the speed
|
||||||
|
ModAPI.mc.timer.timerSpeed = speed;
|
||||||
|
}
|
||||||
|
// Log the speed to chat
|
||||||
|
ModAPI.displayToChat("[Timescale] Set world timescale to " + speed.toFixed(2) + ".");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
})()
|
||||||
|
```
|
||||||
|
Now for the serverside part.
|
||||||
|
```javascript
|
||||||
|
(function TimescaleCommand() {
|
||||||
|
//...
|
||||||
|
|
||||||
|
ModAPI.dedicatedServer.appendCode(function () { // Run on the server
|
||||||
|
globalThis.timeScale = 1n; // Initialize globalThis.timeScale
|
||||||
|
globalThis.timeScaleDividing = false; // Initialize globalThis.timeScaleDividing
|
||||||
|
|
||||||
|
ModAPI.addEventListener("processcommand", (event) => { // when the server receives a command
|
||||||
|
if (event.command.toLowerCase().startsWith("/timescale")) { // if it is a timescale command
|
||||||
|
var speed = parseFloat(event.command.split(" ")[1]); // get the second part of the command (the speed of time)
|
||||||
|
if (!speed) { // If it doesn't exist, set it to 1.
|
||||||
|
globalThis.timeScale = 1n;
|
||||||
|
globalThis.timeScaleDividing = false;
|
||||||
|
} else { // If it does exist:
|
||||||
|
if (speed < 1) {
|
||||||
|
// When the speed is less than 1, round the denominator (1 over x)
|
||||||
|
// And enable division mode
|
||||||
|
globalThis.timeScaleDividing = true;
|
||||||
|
globalThis.timeScale = BigInt(Math.round(1 / speed));
|
||||||
|
} else {
|
||||||
|
// When the speed is greater or equal to 1, round the numerator (x over 1)
|
||||||
|
// And disable division mode
|
||||||
|
globalThis.timeScaleDividing = false;
|
||||||
|
globalThis.timeScale = BigInt(Math.round(speed));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (ModAPI.server) { //If the server is initialized
|
||||||
|
//Bump the current time forward so the server doesn't try to play catch-up
|
||||||
|
ModAPI.server.currentTime = ModAPI.hooks.methods[ModAPI.util.getMethodFromPackage("net.minecraft.server.MinecraftServer", "getCurrentTimeMillis")]();
|
||||||
|
}
|
||||||
|
|
||||||
|
//Prevent the command not found error from appearing
|
||||||
|
event.preventDefault = true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
//Monkey patch the getCurrentTime function.
|
||||||
|
const original_getCurrentTime = ModAPI.hooks.methods[ModAPI.util.getMethodFromPackage("net.minecraft.server.MinecraftServer", "getCurrentTimeMillis")];
|
||||||
|
ModAPI.hooks.methods[ModAPI.util.getMethodFromPackage("net.minecraft.server.MinecraftServer", "getCurrentTimeMillis")] = function () {
|
||||||
|
if (globalThis.timeScaleDividing) { //If we are in divide mode
|
||||||
|
return original_getCurrentTime() / globalThis.timeScale; //Return the current time divided by the time scale
|
||||||
|
} else {
|
||||||
|
return original_getCurrentTime() * globalThis.timeScale; //Else, return the current time multiplied by the time scale
|
||||||
|
}
|
||||||
|
};
|
||||||
|
});
|
||||||
|
})()
|
||||||
|
```
|
||||||
@@ -0,0 +1,82 @@
|
|||||||
|
## VClip Exploit with ModAPI
|
||||||
|
Most minecraft servers have an exploit where you can trick the server into clipping you up to 10 blocks up or down through ceilings or floors.
|
||||||
|
|
||||||
|
### Part 1: Setup
|
||||||
|
|
||||||
|
Make a new file in your editor, and call it something like `vclip.js`
|
||||||
|
First, let's setup a basic [IIFE (immediately invoked function expression)](https://developer.mozilla.org/en-US/docs/Glossary/IIFE) around our mod code. This ensures that we don't leak variables that can interfere wiht other mods.\
|
||||||
|
Example of the issue: if mod A and mod B both use `var myVariable = 0`, the value for myVariable will get overwritten.
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
(function VClipExploit() {
|
||||||
|
//Future code here
|
||||||
|
})(); //We define a function, called VClipExploit, which we wrap in parantheses () and immediately execute.
|
||||||
|
```
|
||||||
|
This allows us to use variables without worrying about mod compatibility, as variables are scoped to the function.
|
||||||
|
|
||||||
|
\
|
||||||
|
Then, we'll add some basic [metadata](../apidoc/meta.md) for the mod loader (note that this is optional, but makes the mod look a lot better in the GUI once the game is loaded.)\
|
||||||
|
We'll also require the player, so the `ModAPI.player` global is generated.
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
(function VClipExploit() {
|
||||||
|
ModAPI.meta.title("VClip Exploit");
|
||||||
|
ModAPI.meta.description("todo: add description.");
|
||||||
|
ModAPI.meta.credits("By author_name");
|
||||||
|
|
||||||
|
ModAPI.require("player");
|
||||||
|
|
||||||
|
|
||||||
|
})();
|
||||||
|
```
|
||||||
|
|
||||||
|
### Part 2: VClip Exploit
|
||||||
|
Our VClip exploit will be triggered by a client-side command, `.vclip <amount>`.
|
||||||
|
Let's start off with the vclip command by adding an event listener to when the player sends a chat message:
|
||||||
|
```javascript
|
||||||
|
(function VClipExploit() {
|
||||||
|
ModAPI.meta.title("VClip Exploit");
|
||||||
|
ModAPI.meta.description("todo: add description.");
|
||||||
|
ModAPI.meta.credits("By author_name");
|
||||||
|
|
||||||
|
ModAPI.require("player");
|
||||||
|
|
||||||
|
ModAPI.addEventListener("sendchatmessage", (ev) => {
|
||||||
|
// handler code here
|
||||||
|
});
|
||||||
|
})();
|
||||||
|
```
|
||||||
|
In this event handler, we can get the content of the message by using `event.message`, process it, and check whether it is using the `.vclip` command. We can do this by casting the string to lowercase, using [`string.toLowerCase()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/toLowerCase), checking if the result of that is a call to the `.vclip` command using [`string.startsWith()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/startsWith).
|
||||||
|
|
||||||
|
If it is a call to the VClip command, we can use [`string.split(" ")`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/split) to get all the arguments, find the vclip amount, and change the player's position.
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
(function VClipExploit() {
|
||||||
|
ModAPI.meta.title("VClip Exploit");
|
||||||
|
ModAPI.meta.description("todo: add description.");
|
||||||
|
ModAPI.meta.credits("By author_name");
|
||||||
|
|
||||||
|
ModAPI.require("player");
|
||||||
|
|
||||||
|
ModAPI.addEventListener("sendchatmessage", (ev) => {
|
||||||
|
var string = ev.message.toLowerCase(); //Get the lower case version of the command
|
||||||
|
if (string.startsWith(".vclip")) { //does the chat message start with .vclip?
|
||||||
|
ev.preventDefault = true; //we don't want this being sent into chat as a message
|
||||||
|
var yOffset = 1; //The offset on the y axis
|
||||||
|
var args = string.split(" ");
|
||||||
|
if (args[1]) { //If the second argument to .vclip exists (the vclip <amount>)
|
||||||
|
yOffset = parseFloat(args[1]) || 0; //Convert the second argument into a number. We use || to replace NaN (invalid numbers) with 0. Then, store it into the y offset.
|
||||||
|
} //This allows you to just type .vclip to clip upwards 1 block.
|
||||||
|
|
||||||
|
ModAPI.player.setPosition( //This function sets the players position to an XYZ coordinate
|
||||||
|
ModAPI.player.posX,
|
||||||
|
ModAPI.player.posY + yOffset, //All XYZ elements are the same, except we add the yOffset variable to the y axis.
|
||||||
|
ModAPI.player.posZ
|
||||||
|
);
|
||||||
|
|
||||||
|
//Finally, log the amount we've VClipped into the chat.
|
||||||
|
ModAPI.displayToChat("[VClip] VClipped " + yOffset + " blocks.");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
})();
|
||||||
|
```
|
||||||
@@ -0,0 +1,444 @@
|
|||||||
|
ModAPI.meta.title("AsyncSink");
|
||||||
|
ModAPI.meta.description("Library for patching and hooking into asynchronous filesystem requests for EaglercraftX.");
|
||||||
|
const asyncSinkIcon = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABIAAAASCAYAAABWzo5XAAAAAXNSR0IArs4c6QAAAL9JREFUOE9jZGBg+M9ABcAIMsgtPo3hzZ2zYONEVIxJZu9aOIsBbJCRtTHcEJAgLgBSh82ic0fPIgyCKQAJXrx4EcUsfX19sBiIRrYU5gu4Qchew2cQyHSQYehBgdNruFwEcybMZci+gIcRIa+hhxu6LzBiDZvX0A1BDyuivYbLIJK8pqevjze5GlsbMxAdayCT/PQwDRS2gaQror2m36KH4SqjZybwxEl0gsQWRkM01ogpVQh6jaJihBgXEFIDAAIQ9AFDJlrxAAAAAElFTkSuQmCC";
|
||||||
|
ModAPI.meta.icon(asyncSinkIcon);
|
||||||
|
ModAPI.meta.credits("By ZXMushroom63");
|
||||||
|
(function AsyncSinkFn() {
|
||||||
|
const ResourceLocation = ModAPI.reflect.getClassByName("ResourceLocation").constructors.find(x => x.length === 1);
|
||||||
|
//AsyncSink is a plugin to debug and override asynchronous methods in EaglercraftX
|
||||||
|
async function runtimeComponent() {
|
||||||
|
let booleanResult;
|
||||||
|
|
||||||
|
if (ModAPI.is_1_12) {
|
||||||
|
const _boolRes = ModAPI.reflect.getClassById("net.lax1dude.eaglercraft.internal.teavm.BooleanResult").constructors[0];
|
||||||
|
booleanResult = (b) => _boolRes(b * 1);
|
||||||
|
} else {
|
||||||
|
booleanResult = (b) => ModAPI.hooks.methods.nlevit_BooleanResult__new(b * 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
const wrap = ModAPI.hooks.methods.otji_JSWrapper_wrap;
|
||||||
|
const unwrap = ModAPI.hooks.methods.otji_JSWrapper_unwrap;
|
||||||
|
function getAsyncHandlerName(name) {
|
||||||
|
var suffix = `$AsyncHandlers_${name}$_asyncCall_$`;
|
||||||
|
return ModAPI.hooks._rippedMethodKeys.find(x => x.endsWith(suffix));
|
||||||
|
}
|
||||||
|
var fs_debugging = false;
|
||||||
|
const encoder = new TextEncoder('utf-8');
|
||||||
|
var filesystemPlatform = (ModAPI.hooks.methods.nlevit_IndexedDBFilesystem$AsyncHandlers_readWholeFile || ModAPI.hooks.methods.nleit_IndexedDBFilesystem$AsyncHandlers_readWholeFile) ? true : false;
|
||||||
|
if (!filesystemPlatform) {
|
||||||
|
console.warn("AsyncSink requires EaglercraftX u37 or greater to work! Attempting to run anyway...");
|
||||||
|
}
|
||||||
|
const AsyncSink = {};
|
||||||
|
const originalSuspend = ModAPI.hooks.TeaVMThread.prototype.suspend;
|
||||||
|
AsyncSink.startDebugging = function hookIntoSuspend() {
|
||||||
|
ModAPI.hooks.TeaVMThread.prototype.suspend = function suspend(...args) {
|
||||||
|
console.log("[AsyncSink] Context suspended! Callback: ", args[0]);
|
||||||
|
return originalSuspend.apply(this, args);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
AsyncSink.stopDebugging = function unhookFromSuspend() {
|
||||||
|
ModAPI.hooks.TeaVMThread.prototype.suspend = originalSuspend;
|
||||||
|
}
|
||||||
|
|
||||||
|
AsyncSink.startDebuggingFS = function hookIntoSuspend() {
|
||||||
|
fs_debugging = true;
|
||||||
|
}
|
||||||
|
AsyncSink.stopDebuggingFS = function unhookFromSuspend() {
|
||||||
|
fs_debugging = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// @type Map<string, ArrayBuffer>
|
||||||
|
AsyncSink.FS = new Map();
|
||||||
|
AsyncSink.L10N = new Map();
|
||||||
|
AsyncSink.FSOverride = new Set();
|
||||||
|
AsyncSink.MIDDLEWARE = [];
|
||||||
|
|
||||||
|
//takes in a ResourceLocation and removes cached data. Use to only reload a specific texture if you know where it is stored.
|
||||||
|
AsyncSink.clearResourcePointer = function clearResourcePointer(resourceLocation) {
|
||||||
|
if (!resourceLocation) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var res = ModAPI.util.wrap((resourceLocation.isModProxy === true) ? resourceLocation.getRef() : resourceLocation);
|
||||||
|
res.cachedPointer = null;
|
||||||
|
res.cachedPointerType = 0;
|
||||||
|
ModAPI.mc.getTextureManager().mapTextureObjects.remove(res.getRef());
|
||||||
|
}
|
||||||
|
AsyncSink.setFile = function setFile(path, data) {
|
||||||
|
if (typeof data === "string") {
|
||||||
|
data = encoder.encode(data).buffer;
|
||||||
|
}
|
||||||
|
AsyncSink.FSOverride.add(path);
|
||||||
|
AsyncSink.FS.set(path, data);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
AsyncSink.deleteFile = function deleteFile(path) {
|
||||||
|
AsyncSink.FSOverride.delete(path);
|
||||||
|
AsyncSink.FS.delete(path);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
AsyncSink.hideFile = function hideFile(path) {
|
||||||
|
AsyncSink.FSOverride.add(path);
|
||||||
|
AsyncSink.FS.delete(path);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
AsyncSink.getFile = function getFile(path) {
|
||||||
|
return AsyncSink.FS.get(path) || new ArrayBuffer(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
AsyncSink.fileExists = function fileExists(path) {
|
||||||
|
return AsyncSink.FS.has(path);
|
||||||
|
}
|
||||||
|
|
||||||
|
var readWholeFileName = getAsyncHandlerName("readWholeFile");
|
||||||
|
var writeWholeFileName = getAsyncHandlerName("writeWholeFile");
|
||||||
|
var deleteFileName = getAsyncHandlerName("deleteFile");
|
||||||
|
var fileExistsName = getAsyncHandlerName("fileExists");
|
||||||
|
|
||||||
|
const originalReadWholeFile = ModAPI.hooks.methods[readWholeFileName];
|
||||||
|
ModAPI.hooks.methods[readWholeFileName] = function (...args) {
|
||||||
|
if (fs_debugging) {
|
||||||
|
console.log("[AsynkSinkFS] File read request sent: " + ModAPI.util.ustr(args[1]));
|
||||||
|
}
|
||||||
|
if (AsyncSink.FSOverride.has(ModAPI.util.ustr(args[1]))) {
|
||||||
|
if (fs_debugging) {
|
||||||
|
console.log("[AsynkSinkFS] Replied with copy from fake filesystem.");
|
||||||
|
}
|
||||||
|
return wrap(AsyncSink.getFile(ModAPI.util.ustr(args[1])));
|
||||||
|
}
|
||||||
|
var ev = { method: "read", file: ModAPI.util.ustr(args[1]), shim: false, shimOutput: new ArrayBuffer() };
|
||||||
|
AsyncSink.MIDDLEWARE.forEach((fn) => { fn(ev) });
|
||||||
|
if (ev.shim) {
|
||||||
|
return wrap(ev.shimOutput);
|
||||||
|
}
|
||||||
|
return originalReadWholeFile.apply(this, args);
|
||||||
|
};
|
||||||
|
|
||||||
|
const originalWriteWholeFile = ModAPI.hooks.methods[writeWholeFileName];
|
||||||
|
ModAPI.hooks.methods[writeWholeFileName] = function (...args) {
|
||||||
|
if (fs_debugging) {
|
||||||
|
console.log("[AsynkSinkFS] File write request sent: " + ModAPI.util.ustr(args[1]), args[2]);
|
||||||
|
}
|
||||||
|
if (AsyncSink.FSOverride.has(ModAPI.util.ustr(args[1]))) {
|
||||||
|
if (fs_debugging) {
|
||||||
|
console.log("[AsynkSinkFS] Writing to fake filesystem.");
|
||||||
|
}
|
||||||
|
AsyncSink.setFile(ModAPI.util.ustr(args[1]), args[2]);
|
||||||
|
return booleanResult(true);
|
||||||
|
}
|
||||||
|
var ev = { method: "write", file: ModAPI.util.ustr(args[1]), data: args[2], shim: false, shimOutput: true };
|
||||||
|
AsyncSink.MIDDLEWARE.forEach((fn) => { fn(ev) });
|
||||||
|
if (ev.shim) {
|
||||||
|
return booleanResult(ev.shimOutput);
|
||||||
|
}
|
||||||
|
return originalWriteWholeFile.apply(this, args);
|
||||||
|
};
|
||||||
|
|
||||||
|
const originalDeleteFile = ModAPI.hooks.methods[deleteFileName];
|
||||||
|
ModAPI.hooks.methods[deleteFileName] = function (...args) {
|
||||||
|
if (fs_debugging) {
|
||||||
|
console.log("[AsynkSinkFS] File delete request sent: " + ModAPI.util.ustr(args[1]));
|
||||||
|
}
|
||||||
|
if (AsyncSink.FSOverride.has(ModAPI.util.ustr(args[1]))) {
|
||||||
|
if (fs_debugging) {
|
||||||
|
console.log("[AsynkSinkFS] Deleting entry from fake filesystem.");
|
||||||
|
}
|
||||||
|
AsyncSink.deleteFile(ModAPI.util.ustr(args[1]));
|
||||||
|
return booleanResult(true);
|
||||||
|
}
|
||||||
|
var ev = { method: "delete", file: ModAPI.util.ustr(args[1]), shim: false, shimOutput: true };
|
||||||
|
AsyncSink.MIDDLEWARE.forEach((fn) => { fn(ev) });
|
||||||
|
if (ev.shim) {
|
||||||
|
return booleanResult(ev.shimOutput);
|
||||||
|
}
|
||||||
|
return originalDeleteFile.apply(this, args);
|
||||||
|
};
|
||||||
|
|
||||||
|
const originalFileExists = ModAPI.hooks.methods[fileExistsName];
|
||||||
|
ModAPI.hooks.methods[fileExistsName] = function (...args) {
|
||||||
|
if (fs_debugging) {
|
||||||
|
console.log("[AsynkSinkFS] File exists request sent: " + ModAPI.util.ustr(args[1]));
|
||||||
|
}
|
||||||
|
if (AsyncSink.FSOverride.has(ModAPI.util.ustr(args[1]))) {
|
||||||
|
if (fs_debugging) {
|
||||||
|
console.log("[AsynkSinkFS] Replying with information from fake filesystem.");
|
||||||
|
}
|
||||||
|
var result = AsyncSink.fileExists(ModAPI.util.ustr(args[1]));
|
||||||
|
return booleanResult(result);
|
||||||
|
}
|
||||||
|
var ev = { method: "exists", file: ModAPI.util.ustr(args[1]), shim: false, shimOutput: true };
|
||||||
|
AsyncSink.MIDDLEWARE.forEach((fn) => { fn(ev) });
|
||||||
|
if (ev.shim) {
|
||||||
|
return booleanResult(ev.shimOutput);
|
||||||
|
}
|
||||||
|
return originalFileExists.apply(this, args);
|
||||||
|
};
|
||||||
|
|
||||||
|
const L10NRead = ModAPI.util.getMethodFromPackage("net.minecraft.util.StatCollector", "translateToLocal");
|
||||||
|
const originalL10NRead = ModAPI.hooks.methods[L10NRead];
|
||||||
|
ModAPI.hooks.methods[L10NRead] = function (...args) {
|
||||||
|
var key = ModAPI.util.ustr(args[0]);
|
||||||
|
if (AsyncSink.L10N.has(key)) {
|
||||||
|
return ModAPI.util.str(AsyncSink.L10N.get(key));
|
||||||
|
}
|
||||||
|
return originalL10NRead.apply(this, args);
|
||||||
|
};
|
||||||
|
|
||||||
|
const L18NFormat = ModAPI.util.getMethodFromPackage("net.minecraft.client.resources.I18n", "format");
|
||||||
|
const originalL18NFormat = ModAPI.hooks.methods[L18NFormat];
|
||||||
|
ModAPI.hooks.methods[L18NFormat] = function (...args) {
|
||||||
|
var key = ModAPI.util.ustr(args[0]);
|
||||||
|
if (AsyncSink.L10N.has(key)) {
|
||||||
|
args[0] = ModAPI.util.str(AsyncSink.L10N.get(key));
|
||||||
|
}
|
||||||
|
return originalL18NFormat.apply(this, args);
|
||||||
|
};
|
||||||
|
|
||||||
|
const LanguageMapTranslate = ModAPI.util.getMethodFromPackage("net.minecraft.util.text.translation.LanguageMap", "tryTranslateKey");
|
||||||
|
const originalLanguageMapTranslate = ModAPI.hooks.methods[LanguageMapTranslate];
|
||||||
|
ModAPI.hooks.methods[LanguageMapTranslate] = function (...args) {
|
||||||
|
var key = ModAPI.util.ustr(args[1]);
|
||||||
|
if (AsyncSink.L10N.has(key)) {
|
||||||
|
args[1] = ModAPI.util.str(AsyncSink.L10N.get(key));
|
||||||
|
}
|
||||||
|
return originalLanguageMapTranslate.apply(this, args);
|
||||||
|
};
|
||||||
|
|
||||||
|
const LanguageMapCheckTranslate = ModAPI.util.getMethodFromPackage("net.minecraft.util.text.translation.LanguageMap", "isKeyTranslated");
|
||||||
|
const originalLanguageMapCheckTranslate = ModAPI.hooks.methods[LanguageMapCheckTranslate];
|
||||||
|
ModAPI.hooks.methods[LanguageMapCheckTranslate] = function (...args) {
|
||||||
|
var key = ModAPI.util.ustr(args[1]);
|
||||||
|
if (AsyncSink.L10N.has(key)) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
return originalLanguageMapTranslate.apply(this, args);
|
||||||
|
};
|
||||||
|
|
||||||
|
const L10NCheck = ModAPI.util.getMethodFromPackage("net.minecraft.util.StatCollector", "canTranslate");
|
||||||
|
const originalL10NCheck = ModAPI.hooks.methods[L10NCheck];
|
||||||
|
ModAPI.hooks.methods[L10NCheck] = function (...args) {
|
||||||
|
if (AsyncSink.L10N.has(ModAPI.util.ustr(args[0]))) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
return originalL10NCheck.apply(this, args);
|
||||||
|
};
|
||||||
|
|
||||||
|
globalThis.AsyncSink = AsyncSink;
|
||||||
|
ModAPI.events.newEvent("lib:asyncsink");
|
||||||
|
ModAPI.events.callEvent("lib:asyncsink", {});
|
||||||
|
console.log("[AsyncSink] Loaded!");
|
||||||
|
}
|
||||||
|
runtimeComponent();
|
||||||
|
ModAPI.dedicatedServer.appendCode(runtimeComponent);
|
||||||
|
|
||||||
|
|
||||||
|
async function assureAsyncSinkResources() {
|
||||||
|
const dec = new TextDecoder("utf-8");
|
||||||
|
const enc = new TextEncoder("utf-8");
|
||||||
|
var resourcePackKey = ModAPI.is_1_12 ? "_net_lax1dude_eaglercraft_v1_8_internal_PlatformFilesystem_1_12_2_" : (await indexedDB.databases()).find(x => x?.name?.endsWith("_resourcePacks")).name;
|
||||||
|
const dbRequest = indexedDB.open(resourcePackKey);
|
||||||
|
const db = await promisifyIDBRequest(dbRequest);
|
||||||
|
const transaction = db.transaction(["filesystem"], "readonly");
|
||||||
|
const objectStore = transaction.objectStore("filesystem");
|
||||||
|
var object = (await promisifyIDBRequest(objectStore.get(["resourcepacks/manifest.json"])))?.data;
|
||||||
|
var resourcePackList = object ? JSON.parse(dec.decode(object)) : { resourcePacks: [] };
|
||||||
|
var pack = {
|
||||||
|
domains: ["minecraft", "eagler"],
|
||||||
|
folder: "AsyncSinkLib",
|
||||||
|
name: "AsyncSinkLib",
|
||||||
|
timestamp: Date.now()
|
||||||
|
};
|
||||||
|
if (!Array.isArray(resourcePackList.resourcePacks)) {
|
||||||
|
resourcePackList.resourcePacks = [];
|
||||||
|
}
|
||||||
|
if (resourcePackList.resourcePacks.find(x => x.name === "AsyncSinkLib")) {
|
||||||
|
var idx = resourcePackList.resourcePacks.indexOf(resourcePackList.resourcePacks.find(x => x.name === "AsyncSinkLib"));
|
||||||
|
resourcePackList.resourcePacks[idx] = pack;
|
||||||
|
} else {
|
||||||
|
resourcePackList.resourcePacks.push(pack);
|
||||||
|
}
|
||||||
|
|
||||||
|
const writeableTransaction = db.transaction(["filesystem"], "readwrite");
|
||||||
|
const writeableObjectStore = writeableTransaction.objectStore("filesystem");
|
||||||
|
await promisifyIDBRequest(writeableObjectStore.put({
|
||||||
|
path: "resourcepacks/manifest.json",
|
||||||
|
data: enc.encode(JSON.stringify(resourcePackList)).buffer
|
||||||
|
}));
|
||||||
|
await promisifyIDBRequest(writeableObjectStore.put({
|
||||||
|
path: "resourcepacks/AsyncSinkLib/pack.mcmeta",
|
||||||
|
data: enc.encode(JSON.stringify({
|
||||||
|
"pack": {
|
||||||
|
"pack_format": ModAPI.is_1_12 ? 3 : 1,
|
||||||
|
"description": "AsyncSink Library Resources"
|
||||||
|
}
|
||||||
|
})).buffer
|
||||||
|
}));
|
||||||
|
|
||||||
|
var icon = {
|
||||||
|
path: "resourcepacks/AsyncSinkLib/pack.png",
|
||||||
|
data: await (await fetch(asyncSinkIcon)).arrayBuffer()
|
||||||
|
};
|
||||||
|
|
||||||
|
const imageTransaction = db.transaction(["filesystem"], "readwrite");
|
||||||
|
const imageObjectStore = imageTransaction.objectStore("filesystem");
|
||||||
|
|
||||||
|
await promisifyIDBRequest(imageObjectStore.put(icon));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Client side reminders to enable the AsyncSink Resource Pack
|
||||||
|
var asyncSinkInstallStatus = false;
|
||||||
|
var installMessage = document.createElement("span");
|
||||||
|
installMessage.innerText = "Please enable the AsyncSink resource pack\nIn game, use the .reload_tex command to load textures for modded blocks and items.";
|
||||||
|
installMessage.style = "background-color: rgba(0,0,0,0.7); color: red; position: fixed; top: 0; left: 0; font-family: sans-serif; pointer-events: none; user-select: none;";
|
||||||
|
document.body.appendChild(installMessage);
|
||||||
|
|
||||||
|
assureAsyncSinkResources();
|
||||||
|
setInterval(() => {
|
||||||
|
var resourcePackEntries = ModAPI.mc.mcResourcePackRepository.getRepositoryEntries().getCorrective();
|
||||||
|
var array = resourcePackEntries.array || [resourcePackEntries.element];
|
||||||
|
asyncSinkInstallStatus = array.find(x => ModAPI.util.ustr(x.reResourcePack.resourcePackFile.getRef()) === "AsyncSinkLib") ? true : false;
|
||||||
|
//assureAsyncSinkResources();
|
||||||
|
if (asyncSinkInstallStatus) {
|
||||||
|
installMessage.style.display = "none";
|
||||||
|
} else {
|
||||||
|
installMessage.style.display = "initial";
|
||||||
|
}
|
||||||
|
}, 8000);
|
||||||
|
ModAPI.events.newEvent("custom:asyncsink_reloaded");
|
||||||
|
ModAPI.addEventListener("sendchatmessage", (e) => {
|
||||||
|
if (e.message.toLowerCase().startsWith(".reload_tex")) {
|
||||||
|
e.preventDefault = true;
|
||||||
|
ModAPI.mc.renderItem.itemModelMesher.simpleShapesCache.clear();
|
||||||
|
ModAPI.promisify(ModAPI.mc.refreshResources)().then(() => {
|
||||||
|
ModAPI.events.callEvent("custom:asyncsink_reloaded", {});
|
||||||
|
ModAPI.events.callEvent("lib:asyncsink:registeritems", ModAPI.mc.renderItem);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
ModAPI.events.newEvent("lib:asyncsink:registeritems");
|
||||||
|
const regItemsName = ModAPI.util.getMethodFromPackage("net.minecraft.client.renderer.entity.RenderItem", "registerItems");
|
||||||
|
const oldRegisterItems = ModAPI.hooks.methods[regItemsName];
|
||||||
|
ModAPI.hooks.methods[regItemsName] = function (...args) {
|
||||||
|
oldRegisterItems.apply(this, args);
|
||||||
|
ModAPI.events.callEvent("lib:asyncsink:registeritems", ModAPI.util.wrap(args[0]));
|
||||||
|
}
|
||||||
|
|
||||||
|
AsyncSink.Audio = {};
|
||||||
|
AsyncSink.Audio.Category = ModAPI.reflect.getClassByName("SoundCategory").staticVariables;
|
||||||
|
AsyncSink.Audio.Objects = [];
|
||||||
|
const SoundHandler_onResourceManagerReload = ModAPI.hooks.methods[ModAPI.util.getMethodFromPackage("net.minecraft.client.audio.SoundHandler", "onResourceManagerReload")];
|
||||||
|
ModAPI.hooks.methods[ModAPI.util.getMethodFromPackage("net.minecraft.client.audio.SoundHandler", "onResourceManagerReload")] = function (...args) {
|
||||||
|
SoundHandler_onResourceManagerReload.apply(this, args);
|
||||||
|
if (ModAPI.util.isCritical()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var snd = ModAPI.mc.mcSoundHandler;
|
||||||
|
var registry = (snd.sndRegistry || snd.soundRegistry).getCorrective().soundRegistry;
|
||||||
|
console.log("[AsyncSink] Populating sound registry hash map with " + AsyncSink.Audio.Objects.length + " sound effects.");
|
||||||
|
AsyncSink.Audio.Objects.forEach(pair => {
|
||||||
|
registry.put(pair[0], pair[1]);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// key = "mob.entity.say"
|
||||||
|
// values = SoundEntry[]
|
||||||
|
// category: AsyncSink.Audio.Category.*
|
||||||
|
// SoundEntry = {path: String, pitch: 1, volume: 1, streaming: false}
|
||||||
|
const EaglercraftRandom = ModAPI.reflect.getClassByName("EaglercraftRandom").constructors.find(x => x.length === 0);
|
||||||
|
|
||||||
|
function makeSoundEventAccessor(soundpoolentry, weight) {
|
||||||
|
const SoundEventAccessorClass = ModAPI.reflect.getClassByName("SoundEventAccessor").class;
|
||||||
|
var object = new SoundEventAccessorClass;
|
||||||
|
var wrapped = ModAPI.util.wrap(object).getCorrective();
|
||||||
|
wrapped.entry = soundpoolentry;
|
||||||
|
wrapped.weight = weight;
|
||||||
|
return object;
|
||||||
|
}
|
||||||
|
|
||||||
|
function makeSoundEventAccessorComposite(rKey, pitch, volume, category) {
|
||||||
|
const SoundEventAccessorCompositeClass = ModAPI.reflect.getClassByName("SoundEventAccessorComposite").class;
|
||||||
|
var object = new SoundEventAccessorCompositeClass;
|
||||||
|
var wrapped = ModAPI.util.wrap(object).getCorrective();
|
||||||
|
wrapped.soundLocation = rKey;
|
||||||
|
wrapped.eventPitch = pitch;
|
||||||
|
wrapped.eventVolume = volume;
|
||||||
|
wrapped.category = category;
|
||||||
|
wrapped.soundPool = ModAPI.hooks.methods.cgcc_Lists_newArrayList1();
|
||||||
|
wrapped.rnd = EaglercraftRandom();
|
||||||
|
return object;
|
||||||
|
}
|
||||||
|
function makeSoundEventAccessor112(rKey, subttl) {
|
||||||
|
const SoundEventAccessorClass = ModAPI.reflect.getClassByName("SoundEventAccessor").class;
|
||||||
|
var object = new SoundEventAccessorClass;
|
||||||
|
var wrapped = ModAPI.util.wrap(object).getCorrective();
|
||||||
|
wrapped.location = rKey;
|
||||||
|
wrapped.subtitle = ModAPI.util.str(subttl);
|
||||||
|
wrapped.accessorList = ModAPI.hooks.methods.cgcc_Lists_newArrayList0();
|
||||||
|
wrapped.rnd = EaglercraftRandom();
|
||||||
|
return object;
|
||||||
|
}
|
||||||
|
if (ModAPI.is_1_12) {
|
||||||
|
const soundType = ModAPI.reflect.getClassById("net.minecraft.client.audio.Sound$Type").staticVariables.FILE;
|
||||||
|
const mkSound = ModAPI.reflect.getClassById("net.minecraft.client.audio.Sound").constructors[0];
|
||||||
|
const SoundEvent = ModAPI.reflect.getClassById("net.minecraft.util.SoundEvent");
|
||||||
|
const SoundEvents = ModAPI.reflect.getClassById("net.minecraft.init.SoundEvents");
|
||||||
|
|
||||||
|
AsyncSink.Audio.register = function addSfx(key, unused, values, subtitle) {
|
||||||
|
subtitle ||= "(AsyncSink Sound)";
|
||||||
|
if (unused) {
|
||||||
|
console.log("Category is not a property of the sound in 1.12, category for " + key + " will be unused.");
|
||||||
|
}
|
||||||
|
|
||||||
|
const rKey = ResourceLocation(ModAPI.util.str(key));
|
||||||
|
|
||||||
|
const ev = new SoundEvent.class;
|
||||||
|
ev.$soundName = rKey;
|
||||||
|
ModAPI.util.wrap(SoundEvent.staticVariables.REGISTRY).register(ModAPI.keygen.sound(key), rKey, ev);
|
||||||
|
const outObj = SoundEvents.staticMethods.getRegisteredSoundEvent.method(ModAPI.util.str(key));
|
||||||
|
|
||||||
|
var snd = ModAPI.mc.mcSoundHandler.getCorrective();
|
||||||
|
var registry = snd.soundRegistry.soundRegistry;
|
||||||
|
|
||||||
|
|
||||||
|
var soundPool = values.map(se => {
|
||||||
|
return mkSound(ModAPI.util.str(se.path.replace("sounds/", "").replace(".ogg", "")), se.volume, se.pitch, 1, soundType, 1 * se.streaming);
|
||||||
|
});
|
||||||
|
var eventAccessor = makeSoundEventAccessor112(rKey, subtitle);
|
||||||
|
var eventAccessorWrapped = ModAPI.util.wrap(eventAccessor);
|
||||||
|
soundPool.forEach(sound => {
|
||||||
|
eventAccessorWrapped.accessorList.add(sound);
|
||||||
|
});
|
||||||
|
AsyncSink.Audio.Objects.push([rKey, eventAccessor]);
|
||||||
|
registry.put(rKey, eventAccessor);
|
||||||
|
values.map(x => "resourcepacks/AsyncSinkLib/assets/minecraft/" + x.path + ".mcmeta").forEach(x => AsyncSink.setFile(x, new ArrayBuffer(0)));
|
||||||
|
return outObj;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
const SoundPoolEntry = ModAPI.reflect.getClassByName("SoundPoolEntry").constructors.find(x => x.length === 4);
|
||||||
|
AsyncSink.Audio.register = function addSfx(key, category, values) {
|
||||||
|
if (!category) {
|
||||||
|
throw new Error("[AsyncSink] Invalid audio category provided: " + category);
|
||||||
|
}
|
||||||
|
var snd = ModAPI.mc.mcSoundHandler;
|
||||||
|
var registry = snd.sndRegistry.soundRegistry;
|
||||||
|
var rKey = ResourceLocation(ModAPI.util.str(key));
|
||||||
|
var soundPool = values.map(se => {
|
||||||
|
var path = ResourceLocation(ModAPI.util.str(se.path));
|
||||||
|
return SoundPoolEntry(path, se.pitch, se.volume, 1 * se.streaming);
|
||||||
|
}).map(spe => {
|
||||||
|
return makeSoundEventAccessor(spe, 1); // 1 = weight
|
||||||
|
});
|
||||||
|
var compositeSound = makeSoundEventAccessorComposite(rKey, 1, 1, category);
|
||||||
|
var compositeSoundWrapped = ModAPI.util.wrap(compositeSound);
|
||||||
|
soundPool.forEach(sound => {
|
||||||
|
compositeSoundWrapped.soundPool.add(sound);
|
||||||
|
});
|
||||||
|
AsyncSink.Audio.Objects.push([rKey, compositeSound]);
|
||||||
|
registry.put(rKey, compositeSound);
|
||||||
|
values.map(x => "resourcepacks/AsyncSinkLib/assets/minecraft/" + x.path + ".mcmeta").forEach(x => AsyncSink.setFile(x, new ArrayBuffer(0)));
|
||||||
|
return soundPool;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})();
|
||||||
@@ -0,0 +1,45 @@
|
|||||||
|
//Demo mod showing how to use lib.customitems.js
|
||||||
|
ModAPI.addEventListener("lib:libcustomitems:loaded", () => {
|
||||||
|
console.log("Registered my cool custom item.");
|
||||||
|
LibCustomItems.registerItem({
|
||||||
|
tag: "mymod:test_item_1",
|
||||||
|
base: "magma_cream",
|
||||||
|
name: "Custom Item",
|
||||||
|
qty: 32,
|
||||||
|
useRecipe: true,
|
||||||
|
recipe: [
|
||||||
|
"###",
|
||||||
|
"# #",
|
||||||
|
"###"
|
||||||
|
],
|
||||||
|
recipeLegend: {
|
||||||
|
"#": {
|
||||||
|
"type": "block",
|
||||||
|
"id": "dirt"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
//Optional: onRightClickGround
|
||||||
|
onRightClickGround: `/*/user, world, itemstack, blockpos/*/
|
||||||
|
itemstack.stackSize -= 1;
|
||||||
|
if (itemstack.stackSize < 1) {
|
||||||
|
user.inventory.mainInventory[user.inventory.currentItem] = null;
|
||||||
|
}
|
||||||
|
user.setHealth(2);
|
||||||
|
return true; //PreventDefault
|
||||||
|
`,
|
||||||
|
//Optional: onLeftClickGround
|
||||||
|
onLeftClickGround: `/*/user, world, itemstack, blockpos/*/
|
||||||
|
itemstack.stackSize -= 1;
|
||||||
|
if (itemstack.stackSize < 1) {
|
||||||
|
user.inventory.mainInventory[user.inventory.currentItem] = null;
|
||||||
|
}
|
||||||
|
user.setHealth(20);
|
||||||
|
return true; //PreventDefault
|
||||||
|
`,
|
||||||
|
//Optional: craftingExtra
|
||||||
|
craftingExtra: `/*/itemstack/*/
|
||||||
|
let enchant = ModAPI.reflect.getClassByName("Enchantment").staticMethods.getEnchantmentById.method(5); //ENCHANTMENT_OXYGEN (respiration)
|
||||||
|
itemstack.addEnchantment(enchant);
|
||||||
|
`,
|
||||||
|
});
|
||||||
|
});
|
||||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -0,0 +1,94 @@
|
|||||||
|
(function CustomItemMod() {
|
||||||
|
const itemTexture = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAKZJREFUOE9j/P//PxMDBIBoEP6HREOl4PLIciA2AyPIgMcM//7KgvWSDJjBBpx9/+YvJzc3Sbq12DhB6sEGsJ19/+YnmQawYhigzc7FcPXnN4KugbqAHWQAy9n3b34T4wJkw6EGYLqAoNVQBWS5ANlwZBfAvUCs/0EGkW0AzBKqGoCSDgh5A80F2KMRpAgfAKUT6kcjsfEPUycmKMQgy8AETkgUZWcAS3CPIf4oSPsAAAAASUVORK5CYII=";
|
||||||
|
|
||||||
|
ModAPI.meta.title("Custom Item Mod");
|
||||||
|
ModAPI.meta.icon(itemTexture);
|
||||||
|
ModAPI.meta.description("it's a custom item. what more do you want");
|
||||||
|
ModAPI.meta.credits("By <author_name>");
|
||||||
|
|
||||||
|
function CustomItem() {
|
||||||
|
var creativeMiscTab = ModAPI.reflect.getClassById("net.minecraft.creativetab.CreativeTabs").staticVariables.tabMisc; //chuck it in the miscellaneous category ig
|
||||||
|
var itemClass = ModAPI.reflect.getClassById("net.minecraft.item.Item"); //Get the item class
|
||||||
|
var itemSuper = ModAPI.reflect.getSuper(itemClass, (x) => x.length === 1); //Get the super() function of the item class that has a length of 1
|
||||||
|
function CustomItem() {
|
||||||
|
itemSuper(this); //Use super function to get block properties on this class.
|
||||||
|
this.$setCreativeTab(creativeMiscTab); //Set the creative tab of the item to be the misc tab
|
||||||
|
}
|
||||||
|
ModAPI.reflect.prototypeStack(itemClass, CustomItem); // ModAPI equivalent of `extends` in java
|
||||||
|
CustomItem.prototype.$onItemRightClick = function ($itemstack, $world, $player) { //example of how to override a method
|
||||||
|
//use ModAPI.util.wrap to create a proxy of the player and the world without $ prefixes on the properties and methods
|
||||||
|
var player = ModAPI.util.wrap($player);
|
||||||
|
var world = ModAPI.util.wrap($world);
|
||||||
|
|
||||||
|
if (!world.isRemote) { //If we are on the server
|
||||||
|
// Math.random() returns a number from 0.0 to 1.0, so we subtract 0.5 and then multiply by 2 to make it become -1.0 to 1.0 instead
|
||||||
|
player.motionX += (Math.random() - 0.5) * 3;
|
||||||
|
player.motionZ += (Math.random() - 0.5) * 3;
|
||||||
|
|
||||||
|
player.motionY += Math.random() * 1.5; // gravity is a thing, so no negative numbers here otherwise it'll be boring
|
||||||
|
}
|
||||||
|
|
||||||
|
return $itemstack;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Internal registration function. This will be used to actually register the item on both the client and the server.
|
||||||
|
function internal_reg() {
|
||||||
|
// Construct an instance of the CustomItem, and set it's unlocalized name (translation id)
|
||||||
|
var custom_item = (new CustomItem()).$setUnlocalizedName(
|
||||||
|
ModAPI.util.str("custom_item")
|
||||||
|
);
|
||||||
|
//Register it using ModAPI.keygen() to get the item id.
|
||||||
|
itemClass.staticMethods.registerItem.method(ModAPI.keygen.item("custom_item"), ModAPI.util.str("custom_item"), custom_item);
|
||||||
|
|
||||||
|
//Expose it to ModAPI
|
||||||
|
ModAPI.items["custom_item"] = custom_item;
|
||||||
|
|
||||||
|
//return the instance.
|
||||||
|
return custom_item;
|
||||||
|
}
|
||||||
|
|
||||||
|
//if the item global exists (and it will on the client), register the item and return the registered instance.
|
||||||
|
if (ModAPI.items) {
|
||||||
|
return internal_reg();
|
||||||
|
} else {
|
||||||
|
//Otherwise attatch the registration method to the bootstrap method.
|
||||||
|
ModAPI.addEventListener("bootstrap", internal_reg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Run the function when the dedicated server loads.
|
||||||
|
ModAPI.dedicatedServer.appendCode(CustomItem);
|
||||||
|
|
||||||
|
// Run the function on the client
|
||||||
|
var custom_item = CustomItem();
|
||||||
|
|
||||||
|
ModAPI.addEventListener("lib:asyncsink", async () => {
|
||||||
|
ModAPI.addEventListener("lib:asyncsink:registeritems", (renderItem)=>{
|
||||||
|
renderItem.registerItem(custom_item, ModAPI.util.str("custom_item"));
|
||||||
|
});
|
||||||
|
AsyncSink.L10N.set("item.custom_item.name", "Cool Custom Item");
|
||||||
|
AsyncSink.setFile("resourcepacks/AsyncSinkLib/assets/minecraft/models/item/custom_item.json", JSON.stringify(
|
||||||
|
{
|
||||||
|
"parent": "builtin/generated",
|
||||||
|
"textures": {
|
||||||
|
"layer0": "items/custom_item"
|
||||||
|
},
|
||||||
|
"display": {
|
||||||
|
"thirdperson": {
|
||||||
|
"rotation": [ -90, 0, 0 ],
|
||||||
|
"translation": [ 0, 1, -3 ],
|
||||||
|
"scale": [ 0.55, 0.55, 0.55 ]
|
||||||
|
},
|
||||||
|
"firstperson": {
|
||||||
|
"rotation": [ 0, -135, 25 ],
|
||||||
|
"translation": [ 0, 4, 2 ],
|
||||||
|
"scale": [ 1.7, 1.7, 1.7 ]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
));
|
||||||
|
AsyncSink.setFile("resourcepacks/AsyncSinkLib/assets/minecraft/textures/items/custom_item.png", await (await fetch(
|
||||||
|
itemTexture
|
||||||
|
)).arrayBuffer());
|
||||||
|
});
|
||||||
|
})();
|
||||||
@@ -0,0 +1,237 @@
|
|||||||
|
ModAPI.meta.title("WorldEdit");
|
||||||
|
ModAPI.meta.credits("By radmanplays");
|
||||||
|
ModAPI.meta.icon("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAcUlEQVR42mNgoAcw1xT4D8Jka25LVQNjkg2Bac4OlP9fGqFImgHImmHY00z0f4af3H+SDADZDNIc6SwJpjXkuP+THHggm5ENIckrMGeDbIZ5hWgDQJo709XhziYpOpFtJjnuKdaM7OwhYjMIkG0zpQAAtFpjWIvu2dwAAAAASUVORK5CYII=");
|
||||||
|
ModAPI.meta.description("Use //wand, //set and //walls in singleplayer worlds.");
|
||||||
|
ModAPI.addEventListener("lib:libcustomitems:loaded", () => {
|
||||||
|
console.log("Registered worldedit custom items.");
|
||||||
|
LibCustomItems.registerItem({
|
||||||
|
tag: "worldedit:wand",
|
||||||
|
base: "wooden_axe",
|
||||||
|
name: "Wand",
|
||||||
|
qty: 1,
|
||||||
|
recipe: [
|
||||||
|
" ",
|
||||||
|
" # ",
|
||||||
|
" "
|
||||||
|
],
|
||||||
|
recipeLegend: {
|
||||||
|
"#": {
|
||||||
|
"type": "item",
|
||||||
|
"id": "wooden_axe"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
onRightClickGround: `/*/user, world, itemstack, blockpos/*/
|
||||||
|
const prefix = "§7[§4worldedit§7] ";
|
||||||
|
var username = ModAPI.util.str(user.getName());
|
||||||
|
|
||||||
|
globalThis.pos2x = {}
|
||||||
|
globalThis.pos2y = {}
|
||||||
|
globalThis.pos2z = {}
|
||||||
|
|
||||||
|
globalThis.pos2x[username] = blockpos.x
|
||||||
|
globalThis.pos2y[username] = blockpos.y
|
||||||
|
globalThis.pos2z[username] = blockpos.z
|
||||||
|
console.log("rightclick: " + blockpos.x + ", " + blockpos.y + ", " + blockpos.z)
|
||||||
|
// Send chat message to player
|
||||||
|
user.addChatMessage(ModAPI.reflect.getClassById("net.minecraft.util.ChatComponentText").constructors[0](ModAPI.util.str(prefix + "Pos #2 set to: " + blockpos.x + ", " + blockpos.y + ", " + blockpos.z)))
|
||||||
|
return true;
|
||||||
|
`,
|
||||||
|
onLeftClickGround: `/*/user, world, itemstack, blockpos/*/
|
||||||
|
const prefix = "§7[§4worldedit§7] ";
|
||||||
|
var username = ModAPI.util.str(user.getName());
|
||||||
|
|
||||||
|
globalThis.posx = {}
|
||||||
|
globalThis.posy = {}
|
||||||
|
globalThis.posz = {}
|
||||||
|
|
||||||
|
globalThis.posx[username] = blockpos.x
|
||||||
|
globalThis.posy[username] = blockpos.y
|
||||||
|
globalThis.posz[username] = blockpos.z
|
||||||
|
|
||||||
|
// Send chat message to player
|
||||||
|
user.addChatMessage(ModAPI.reflect.getClassById("net.minecraft.util.ChatComponentText").constructors[0](ModAPI.util.str(prefix + "Pos #1 set to: " + blockpos.x + ", " + blockpos.y + ", " + blockpos.z)))
|
||||||
|
return true;
|
||||||
|
`
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
(() => {
|
||||||
|
PluginAPI.dedicatedServer.appendCode(function () {
|
||||||
|
PluginAPI.addEventListener("processcommand", (event) => {
|
||||||
|
if (!ModAPI.reflect.getClassById("net.minecraft.entity.player.EntityPlayerMP").instanceOf(event.sender.getRef())) {return}
|
||||||
|
const prefix = "§7[§4worldedit§7] ";
|
||||||
|
if (event.command.toLowerCase().startsWith("//wand")) {
|
||||||
|
// Create a new ItemStack for the custom item
|
||||||
|
const ItemStackClass = ModAPI.reflect.getClassById("net.minecraft.item.ItemStack");
|
||||||
|
const itemStack = ItemStackClass.constructors[4](
|
||||||
|
ModAPI.items["wooden_axe"].getRef(), 1
|
||||||
|
);
|
||||||
|
|
||||||
|
// Create NBT data for the item
|
||||||
|
const NBTTagCompoundClass = ModAPI.reflect.getClassById("net.minecraft.nbt.NBTTagCompound");
|
||||||
|
itemStack.$stackTagCompound = NBTTagCompoundClass.constructors[0]();
|
||||||
|
const displayTag = NBTTagCompoundClass.constructors[0]();
|
||||||
|
itemStack.$stackTagCompound.$setTag(ModAPI.util.str("display"), displayTag);
|
||||||
|
|
||||||
|
// Add the enchant effect to the item
|
||||||
|
let enchant = ModAPI.hooks._classMap.nme_Enchantment.staticMethods.getEnchantmentById.method(0);
|
||||||
|
enchant.$effectId = -1;
|
||||||
|
itemStack.$addEnchantment(enchant);
|
||||||
|
|
||||||
|
// Set item name
|
||||||
|
displayTag.$setString(ModAPI.util.str("Name"), ModAPI.util.str("Wand"));
|
||||||
|
|
||||||
|
// Set item lore
|
||||||
|
var loreList = ModAPI.reflect.getClassById("net.minecraft.nbt.NBTTagList").constructors[0]();
|
||||||
|
loreList.$appendTag(ModAPI.reflect.getClassById("net.minecraft.nbt.NBTTagString").constructors.filter(x => { return x.length === 1 })[0](ModAPI.util.str("worldedit:wand")));
|
||||||
|
displayTag.$setTag(ModAPI.util.str("Lore"), loreList);
|
||||||
|
|
||||||
|
// Add the item to the sender's inventory
|
||||||
|
const player = event.sender;
|
||||||
|
player.inventory.addItemStackToInventory(itemStack);
|
||||||
|
|
||||||
|
// Notify the sender
|
||||||
|
const ChatComponentTextClass = ModAPI.reflect.getClassById("net.minecraft.util.ChatComponentText");
|
||||||
|
player.addChatMessage(ChatComponentTextClass.constructors[0](ModAPI.util.str(prefix + "A wand has been added to your inventory!")));
|
||||||
|
player.addChatMessage(ChatComponentTextClass.constructors[0](ModAPI.util.str(prefix + "Left click: select pos #1; Right click: select pos #2")));
|
||||||
|
|
||||||
|
event.preventDefault = true;
|
||||||
|
}
|
||||||
|
var blockPosConstructor = ModAPI.reflect.getClassById("net.minecraft.util.BlockPos").constructors.find((x) => { return x.length === 3 });
|
||||||
|
if (event.command.toLowerCase().startsWith("//set")) {
|
||||||
|
const args = event.command.substring("//set ".length);
|
||||||
|
var username = ModAPI.util.str(event.sender.getName());
|
||||||
|
|
||||||
|
if (args) {
|
||||||
|
const blockTypeName = args
|
||||||
|
const x1 = globalThis.posx[username], y1 = globalThis.posy[username], z1 = globalThis.posz[username];
|
||||||
|
const x2 = globalThis.pos2x[username], y2 = globalThis.pos2y[username], z2 = globalThis.pos2z[username];
|
||||||
|
|
||||||
|
// Validate block and get block type
|
||||||
|
const blockType = ModAPI.blocks[blockTypeName];
|
||||||
|
if (!blockType) {
|
||||||
|
event.sender.addChatMessage(ModAPI.reflect.getClassById("net.minecraft.util.ChatComponentText").constructors[0](ModAPI.util.str(prefix + `Invalid block: ${blockTypeName}`)));
|
||||||
|
event.preventDefault = true;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const block = blockType.getDefaultState().getRef();
|
||||||
|
|
||||||
|
// Get min and max coordinates for the fill region
|
||||||
|
const xMin = Math.min(x1, x2), xMax = Math.max(x1, x2);
|
||||||
|
const yMin = Math.min(y1, y2), yMax = Math.max(y1, y2);
|
||||||
|
const zMin = Math.min(z1, z2), zMax = Math.max(z1, z2);
|
||||||
|
|
||||||
|
// Loop through the region and set the blocks
|
||||||
|
for (let x = xMin; x <= xMax; x++) {
|
||||||
|
for (let y = yMin; y <= yMax; y++) {
|
||||||
|
for (let z = zMin; z <= zMax; z++) {
|
||||||
|
const blockPos = blockPosConstructor(x, y, z);
|
||||||
|
event.sender.getServerForPlayer().setBlockState(blockPos, block, 3);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Notify the player that the blocks have been set
|
||||||
|
event.sender.addChatMessage(ModAPI.reflect.getClassById("net.minecraft.util.ChatComponentText").constructors[0](ModAPI.util.str(prefix + `Set blocks to ${blockTypeName}`)));
|
||||||
|
} else{
|
||||||
|
event.sender.addChatMessage(ModAPI.reflect.getClassById("net.minecraft.util.ChatComponentText").constructors[0](ModAPI.util.str(prefix + `Arguments not found!`)));
|
||||||
|
}
|
||||||
|
event.preventDefault = true;
|
||||||
|
}
|
||||||
|
if (event.command.toLowerCase().startsWith("//walls")) {
|
||||||
|
const args = event.command.substring("//walls ".length);
|
||||||
|
var username = ModAPI.util.str(event.sender.getName());
|
||||||
|
|
||||||
|
if (args) {
|
||||||
|
const blockTypeName = args;
|
||||||
|
const x1 = globalThis.posx[username], y1 = globalThis.posy[username], z1 = globalThis.posz[username];
|
||||||
|
const x2 = globalThis.pos2x[username], y2 = globalThis.pos2y[username], z2 = globalThis.pos2z[username];
|
||||||
|
|
||||||
|
// Validate block and get block type
|
||||||
|
const blockType = ModAPI.blocks[blockTypeName];
|
||||||
|
if (!blockType) {
|
||||||
|
event.sender.addChatMessage(ModAPI.reflect.getClassById("net.minecraft.util.ChatComponentText").constructors[0](ModAPI.util.str(prefix + `Invalid block: ${blockTypeName}`)));
|
||||||
|
event.preventDefault = true;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const block = blockType.getDefaultState().getRef();
|
||||||
|
|
||||||
|
// Get min and max coordinates for the region
|
||||||
|
const xMin = Math.min(x1, x2), xMax = Math.max(x1, x2);
|
||||||
|
const yMin = Math.min(y1, y2), yMax = Math.max(y1, y2);
|
||||||
|
const zMin = Math.min(z1, z2), zMax = Math.max(z1, z2);
|
||||||
|
|
||||||
|
// Loop through the region and set the walls (exclude interior blocks)
|
||||||
|
for (let x = xMin; x <= xMax; x++) {
|
||||||
|
for (let y = yMin; y <= yMax; y++) {
|
||||||
|
for (let z = zMin; z <= zMax; z++) {
|
||||||
|
if (x === xMin || x === xMax || z === zMin || z === zMax) {
|
||||||
|
const blockPos = blockPosConstructor(x, y, z);
|
||||||
|
event.sender.getServerForPlayer().setBlockState(blockPos, block, 3);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Notify the player that the walls have been set
|
||||||
|
event.sender.addChatMessage(ModAPI.reflect.getClassById("net.minecraft.util.ChatComponentText").constructors[0](ModAPI.util.str(prefix + `Walls set to ${blockTypeName}`)));
|
||||||
|
} else {
|
||||||
|
event.sender.addChatMessage(ModAPI.reflect.getClassById("net.minecraft.util.ChatComponentText").constructors[0](ModAPI.util.str(prefix + `Arguments not found!`)));
|
||||||
|
}
|
||||||
|
event.preventDefault = true;
|
||||||
|
}
|
||||||
|
// "this command was made by EymenWSMC. comments included" - radmanplays
|
||||||
|
if (event.command.toLowerCase().startsWith("//replacenear")) {
|
||||||
|
const args = event.command.split(" ").slice(1);
|
||||||
|
if (args.length < 3) {
|
||||||
|
event.sender.addChatMessage(ModAPI.reflect.getClassById("net.minecraft.util.ChatComponentText").constructors[0](ModAPI.util.str(prefix + "Usage: //replacenear <radius> <targetBlock> <replacementBlock>")));
|
||||||
|
event.preventDefault = true;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const radius = parseInt(args[0]);
|
||||||
|
const targetBlockName = args[1];
|
||||||
|
const replacementBlockName = args[2];
|
||||||
|
|
||||||
|
const targetBlock = ModAPI.blocks[targetBlockName];
|
||||||
|
const replacementBlock = ModAPI.blocks[replacementBlockName];
|
||||||
|
if (!targetBlock || !replacementBlock) {
|
||||||
|
event.sender.addChatMessage(ModAPI.reflect.getClassById("net.minecraft.util.ChatComponentText").constructors[0](ModAPI.util.str(prefix + "Invalid block names!")));
|
||||||
|
event.preventDefault = true;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//Replacing logic
|
||||||
|
const targetBlockState = targetBlock.getDefaultState().getRef();
|
||||||
|
const replacementBlockState = replacementBlock.getDefaultState().getRef();
|
||||||
|
|
||||||
|
const playerPos = event.sender.getPosition();
|
||||||
|
const xStart = Math.floor(playerPos.x - radius);
|
||||||
|
const xEnd = Math.floor(playerPos.x + radius);
|
||||||
|
const yStart = Math.floor(playerPos.y - radius);
|
||||||
|
const yEnd = Math.floor(playerPos.y + radius);
|
||||||
|
const zStart = Math.floor(playerPos.z - radius);
|
||||||
|
const zEnd = Math.floor(playerPos.z + radius);
|
||||||
|
|
||||||
|
//Replace ity with radoius
|
||||||
|
for (let x = xStart; x <= xEnd; x++) {
|
||||||
|
for (let y = yStart; y <= yEnd; y++) {
|
||||||
|
for (let z = zStart; z <= zEnd; z++) {
|
||||||
|
const blockPos = blockPosConstructor(x, y, z);
|
||||||
|
const currentBlock = event.sender.getServerForPlayer().getBlockState(blockPos);
|
||||||
|
|
||||||
|
if (currentBlock.equals(targetBlockState)) {
|
||||||
|
event.sender.getServerForPlayer().setBlockState(blockPos, replacementBlockState, 3);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//Send messages shit
|
||||||
|
event.sender.addChatMessage(ModAPI.reflect.getClassById("net.minecraft.util.ChatComponentText").constructors[0](ModAPI.util.str(prefix + `Replaced ${targetBlockName} with ${replacementBlockName} within radius ${radius}`)));
|
||||||
|
event.preventDefault = true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
})();
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
(function AntiAFKMod() {
|
||||||
|
ModAPI.meta.title("Anti AFK Mod");
|
||||||
|
ModAPI.meta.credits("By ZXMushroom63");
|
||||||
|
ModAPI.meta.description("Type .afk in game chat to toggle the mod");
|
||||||
|
ModAPI.require("player");
|
||||||
|
var active = null;
|
||||||
|
function queueJump() {
|
||||||
|
try {
|
||||||
|
ModAPI.player.jump();
|
||||||
|
} catch (error) {
|
||||||
|
|
||||||
|
}
|
||||||
|
active = setTimeout(queueJump, 15000 + (10000 * Math.random()));
|
||||||
|
}
|
||||||
|
ModAPI.addEventListener("sendchatmessage", (e)=>{
|
||||||
|
if (e.message.toLowerCase() === ".afk") {
|
||||||
|
if (active === null) {
|
||||||
|
queueJump();
|
||||||
|
ModAPI.displayToChat("Activated anti-afk mod!\nI recommend using the sliders mod to decrease your max fps to save battery.");
|
||||||
|
} else {
|
||||||
|
clearTimeout(active);
|
||||||
|
active = null;
|
||||||
|
ModAPI.displayToChat("Deactivated anti-afk mod.");
|
||||||
|
}
|
||||||
|
e.preventDefault = true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
})();
|
||||||
File diff suppressed because one or more lines are too long
@@ -0,0 +1,121 @@
|
|||||||
|
//THIS IS A DEMO MOD
|
||||||
|
|
||||||
|
|
||||||
|
//nice little utility function to fix the block identity map
|
||||||
|
function fixupBlockIds() {
|
||||||
|
var blockRegistry = ModAPI.util.wrap(ModAPI.reflect.getClassById("net.minecraft.block.Block").staticVariables.blockRegistry).getCorrective();
|
||||||
|
var BLOCK_STATE_IDS = ModAPI.util.wrap(ModAPI.reflect.getClassById("net.minecraft.block.Block").staticVariables.BLOCK_STATE_IDS).getCorrective();
|
||||||
|
blockRegistry.registryObjects.hashTableKToV.forEach(entry => {
|
||||||
|
if (entry) {
|
||||||
|
var block = entry.value;
|
||||||
|
var validStates = block.getBlockState().getValidStates();
|
||||||
|
var stateArray = validStates.array || [validStates.element];
|
||||||
|
stateArray.forEach(iblockstate => {
|
||||||
|
var i = blockRegistry.getIDForObject(block.getRef()) << 4 | block.getMetaFromState(iblockstate.getRef());
|
||||||
|
BLOCK_STATE_IDS.put(iblockstate.getRef(), i);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
function makeSteveBlock() {
|
||||||
|
var blockClass = ModAPI.reflect.getClassById("net.minecraft.block.Block");
|
||||||
|
var blockSuper = ModAPI.reflect.getSuper(blockClass, (x) => x.length === 2);
|
||||||
|
var creativeBlockTab = ModAPI.reflect.getClassById("net.minecraft.creativetab.CreativeTabs").staticVariables.tabBlock;
|
||||||
|
function nmb_BlockSteve() {
|
||||||
|
blockSuper(this, ModAPI.materials.rock.getRef());
|
||||||
|
this.$defaultBlockState = this.$blockState.$getBaseState();
|
||||||
|
this.$setCreativeTab(creativeBlockTab);
|
||||||
|
}
|
||||||
|
ModAPI.reflect.prototypeStack(blockClass, nmb_BlockSteve);
|
||||||
|
globalThis.nmb_BlockSteve = nmb_BlockSteve;
|
||||||
|
}
|
||||||
|
function registerSteveClientSide() {
|
||||||
|
var itemClass = ModAPI.reflect.getClassById("net.minecraft.item.Item");
|
||||||
|
var blockClass = ModAPI.reflect.getClassById("net.minecraft.block.Block");
|
||||||
|
var block_of_steve = (new nmb_BlockSteve()).$setHardness(-1.0).$setStepSound(blockClass.staticVariables.soundTypeGravel).$setUnlocalizedName(
|
||||||
|
ModAPI.util.str("steve")
|
||||||
|
);
|
||||||
|
blockClass.staticMethods.registerBlock0.method(
|
||||||
|
ModAPI.keygen.block("steve"),
|
||||||
|
ModAPI.util.str("steve"),
|
||||||
|
block_of_steve
|
||||||
|
);
|
||||||
|
itemClass.staticMethods.registerItemBlock0.method(block_of_steve);
|
||||||
|
ModAPI.addEventListener("lib:asyncsink", async () => {
|
||||||
|
ModAPI.addEventListener("lib:asyncsink:registeritems", (renderItem)=>{
|
||||||
|
renderItem.registerBlock(block_of_steve, ModAPI.util.str("steve"));
|
||||||
|
});
|
||||||
|
AsyncSink.L10N.set("tile.steve.name", "Block Of Steve");
|
||||||
|
AsyncSink.setFile("resourcepacks/AsyncSinkLib/assets/minecraft/models/block/steve.json", JSON.stringify(
|
||||||
|
{
|
||||||
|
"parent": "block/cube_all",
|
||||||
|
"textures": {
|
||||||
|
"all": "blocks/steve"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
));
|
||||||
|
AsyncSink.setFile("resourcepacks/AsyncSinkLib/assets/minecraft/models/item/steve.json", JSON.stringify(
|
||||||
|
{
|
||||||
|
"parent": "block/steve",
|
||||||
|
"display": {
|
||||||
|
"thirdperson": {
|
||||||
|
"rotation": [10, -45, 170],
|
||||||
|
"translation": [0, 1.5, -2.75],
|
||||||
|
"scale": [0.375, 0.375, 0.375]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
));
|
||||||
|
AsyncSink.setFile("resourcepacks/AsyncSinkLib/assets/minecraft/blockstates/steve.json", JSON.stringify(
|
||||||
|
{
|
||||||
|
"variants": {
|
||||||
|
"normal": [
|
||||||
|
{ "model": "steve" },
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
));
|
||||||
|
AsyncSink.setFile("resourcepacks/AsyncSinkLib/assets/minecraft/textures/blocks/steve.png", await (await fetch(
|
||||||
|
"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAE0SURBVDhPpdO9S8NAHMbxy3sVfJmMg6h7FRXXkkUUX0addSjo4OAfIDqLIoiLi3+BRRx0EIQOnV0EcVAIWkR0KIFgrcEktX6vcXD0nuE+5Afhnhw5bWy4qylaidOfVQhT0zFKYozjBHVdzi3TwCZvteaS/0fLD8oGf5OzTeyxNUyE3Ln2HmGctpuxKuS3wd76CgPHsrEj142NeojCkHsFry+4c3aJ6g1OtlZp0Ok4DD4i+Y2GIZ+DMMAhtw+fHu8xi3IDM9t5YfMQF71dLHo+ZjsfXbh4WtnH0vYaqp/BcXGGM3D7BxiYTi+el8uYZWm2gM/VB/Tfaqje4GB5iga2Jv+sUuUa5/ITmOXq7gbnC+MY1r9QvcHG9AgN0lRex1u/ilr7ehqWvBNZvMlRbESfqNhAiG/Pb1bHXpMbFgAAAABJRU5ErkJggg=="
|
||||||
|
)).arrayBuffer());
|
||||||
|
});
|
||||||
|
ModAPI.blocks["steve"] = block_of_steve;
|
||||||
|
}
|
||||||
|
function registerSteveServerSide() {
|
||||||
|
function fixupBlockIds() {
|
||||||
|
var blockRegistry = ModAPI.util.wrap(ModAPI.reflect.getClassById("net.minecraft.block.Block").staticVariables.blockRegistry).getCorrective();
|
||||||
|
var BLOCK_STATE_IDS = ModAPI.util.wrap(ModAPI.reflect.getClassById("net.minecraft.block.Block").staticVariables.BLOCK_STATE_IDS).getCorrective();
|
||||||
|
blockRegistry.registryObjects.hashTableKToV.forEach(entry => {
|
||||||
|
if (entry) {
|
||||||
|
var block = entry.value;
|
||||||
|
var validStates = block.getBlockState().getValidStates();
|
||||||
|
var stateArray = validStates.array || [validStates.element];
|
||||||
|
stateArray.forEach(iblockstate => {
|
||||||
|
var i = blockRegistry.getIDForObject(block.getRef()) << 4 | block.getMetaFromState(iblockstate.getRef());
|
||||||
|
BLOCK_STATE_IDS.put(iblockstate.getRef(), i);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
var blockClass = ModAPI.reflect.getClassById("net.minecraft.block.Block");
|
||||||
|
var itemClass = ModAPI.reflect.getClassById("net.minecraft.item.Item");
|
||||||
|
ModAPI.addEventListener("bootstrap", () => {
|
||||||
|
var block_of_steve = (new nmb_BlockSteve()).$setHardness(-1.0).$setStepSound(blockClass.staticVariables.soundTypeGravel).$setUnlocalizedName(
|
||||||
|
ModAPI.util.str("steve")
|
||||||
|
);
|
||||||
|
blockClass.staticMethods.registerBlock0.method(
|
||||||
|
ModAPI.keygen.block("steve"), //use blockid 198. MAKE SURE TO CHANGE IF YOU ARE MAKING A MOD USING THIS, MAXIMUM BLOCK ID IS 4095.
|
||||||
|
ModAPI.util.str("steve"),
|
||||||
|
block_of_steve
|
||||||
|
);
|
||||||
|
itemClass.staticMethods.registerItemBlock0.method(block_of_steve);
|
||||||
|
fixupBlockIds();
|
||||||
|
ModAPI.blocks["steve"] = block_of_steve;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
ModAPI.dedicatedServer.appendCode(makeSteveBlock);
|
||||||
|
makeSteveBlock();
|
||||||
|
registerSteveClientSide();
|
||||||
|
fixupBlockIds();
|
||||||
|
|
||||||
|
ModAPI.dedicatedServer.appendCode(registerSteveServerSide);
|
||||||
@@ -0,0 +1,111 @@
|
|||||||
|
//THIS IS A DEMO MOD
|
||||||
|
|
||||||
|
|
||||||
|
//nice little utility function to fix the block identity map
|
||||||
|
function fixupBlockIds() {
|
||||||
|
var blockRegistry = ModAPI.util.wrap(ModAPI.reflect.getClassById("net.minecraft.block.Block").staticVariables.blockRegistry).getCorrective();
|
||||||
|
var BLOCK_STATE_IDS = ModAPI.util.wrap(ModAPI.reflect.getClassById("net.minecraft.block.Block").staticVariables.BLOCK_STATE_IDS).getCorrective();
|
||||||
|
blockRegistry.registryObjects.hashTableKToV.forEach(entry => {
|
||||||
|
if (entry) {
|
||||||
|
var block = entry.value;
|
||||||
|
var validStates = block.getBlockState().getValidStates();
|
||||||
|
var stateArray = validStates.array || [validStates.element];
|
||||||
|
stateArray.forEach(iblockstate => {
|
||||||
|
var i = blockRegistry.getIDForObject(block.getRef()) << 4 | block.getMetaFromState(iblockstate.getRef());
|
||||||
|
BLOCK_STATE_IDS.put(iblockstate.getRef(), i);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
function registerSteveClientSide() {
|
||||||
|
var creativeBlockTab = ModAPI.reflect.getClassById("net.minecraft.creativetab.CreativeTabs").staticVariables.tabBlock;
|
||||||
|
var itemClass = ModAPI.reflect.getClassById("net.minecraft.item.Item");
|
||||||
|
var blockClass = ModAPI.reflect.getClassById("net.minecraft.block.Block");
|
||||||
|
var constructor = blockClass.constructors.find(x=>x.length === 1);
|
||||||
|
var block_of_steve = constructor(ModAPI.materials.rock.getRef()).$setHardness(-1.0).$setStepSound(blockClass.staticVariables.soundTypeGravel).$setUnlocalizedName(
|
||||||
|
ModAPI.util.str("steve")
|
||||||
|
).$setCreativeTab(creativeBlockTab);
|
||||||
|
blockClass.staticMethods.registerBlock0.method(
|
||||||
|
ModAPI.keygen.block("steve"), //use blockid 198. MAKE SURE TO CHANGE IF YOU ARE MAKING A MOD USING THIS, MAXIMUM BLOCK ID IS 4095.
|
||||||
|
ModAPI.util.str("steve"),
|
||||||
|
block_of_steve
|
||||||
|
);
|
||||||
|
itemClass.staticMethods.registerItemBlock0.method(block_of_steve);
|
||||||
|
|
||||||
|
ModAPI.addEventListener("lib:asyncsink", async () => {
|
||||||
|
ModAPI.addEventListener("lib:asyncsink:registeritems", (renderItem)=>{
|
||||||
|
renderItem.registerBlock(block_of_steve, ModAPI.util.str("steve"));
|
||||||
|
});
|
||||||
|
AsyncSink.L10N.set("tile.steve.name", "Block Of Steve");
|
||||||
|
AsyncSink.setFile("resourcepacks/AsyncSinkLib/assets/minecraft/models/block/steve.json", JSON.stringify(
|
||||||
|
{
|
||||||
|
"parent": "block/cube_all",
|
||||||
|
"textures": {
|
||||||
|
"all": "blocks/steve"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
));
|
||||||
|
AsyncSink.setFile("resourcepacks/AsyncSinkLib/assets/minecraft/models/item/steve.json", JSON.stringify(
|
||||||
|
{
|
||||||
|
"parent": "block/steve",
|
||||||
|
"display": {
|
||||||
|
"thirdperson": {
|
||||||
|
"rotation": [10, -45, 170],
|
||||||
|
"translation": [0, 1.5, -2.75],
|
||||||
|
"scale": [0.375, 0.375, 0.375]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
));
|
||||||
|
AsyncSink.setFile("resourcepacks/AsyncSinkLib/assets/minecraft/blockstates/steve.json", JSON.stringify(
|
||||||
|
{
|
||||||
|
"variants": {
|
||||||
|
"normal": [
|
||||||
|
{ "model": "steve" },
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
));
|
||||||
|
AsyncSink.setFile("resourcepacks/AsyncSinkLib/assets/minecraft/textures/blocks/steve.png", await (await fetch(
|
||||||
|
"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAE0SURBVDhPpdO9S8NAHMbxy3sVfJmMg6h7FRXXkkUUX0addSjo4OAfIDqLIoiLi3+BRRx0EIQOnV0EcVAIWkR0KIFgrcEktX6vcXD0nuE+5Afhnhw5bWy4qylaidOfVQhT0zFKYozjBHVdzi3TwCZvteaS/0fLD8oGf5OzTeyxNUyE3Ln2HmGctpuxKuS3wd76CgPHsrEj142NeojCkHsFry+4c3aJ6g1OtlZp0Ok4DD4i+Y2GIZ+DMMAhtw+fHu8xi3IDM9t5YfMQF71dLHo+ZjsfXbh4WtnH0vYaqp/BcXGGM3D7BxiYTi+el8uYZWm2gM/VB/Tfaqje4GB5iga2Jv+sUuUa5/ITmOXq7gbnC+MY1r9QvcHG9AgN0lRex1u/ilr7ehqWvBNZvMlRbESfqNhAiG/Pb1bHXpMbFgAAAABJRU5ErkJggg=="
|
||||||
|
)).arrayBuffer());
|
||||||
|
});
|
||||||
|
ModAPI.blocks["steve"] = block_of_steve;
|
||||||
|
}
|
||||||
|
function registerSteveServerSide() {
|
||||||
|
function fixupBlockIds() {
|
||||||
|
var blockRegistry = ModAPI.util.wrap(ModAPI.reflect.getClassById("net.minecraft.block.Block").staticVariables.blockRegistry).getCorrective();
|
||||||
|
var BLOCK_STATE_IDS = ModAPI.util.wrap(ModAPI.reflect.getClassById("net.minecraft.block.Block").staticVariables.BLOCK_STATE_IDS).getCorrective();
|
||||||
|
blockRegistry.registryObjects.hashTableKToV.forEach(entry => {
|
||||||
|
if (entry) {
|
||||||
|
var block = entry.value;
|
||||||
|
var validStates = block.getBlockState().getValidStates();
|
||||||
|
var stateArray = validStates.array || [validStates.element];
|
||||||
|
stateArray.forEach(iblockstate => {
|
||||||
|
var i = blockRegistry.getIDForObject(block.getRef()) << 4 | block.getMetaFromState(iblockstate.getRef());
|
||||||
|
BLOCK_STATE_IDS.put(iblockstate.getRef(), i);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
var creativeBlockTab = ModAPI.reflect.getClassById("net.minecraft.creativetab.CreativeTabs").staticVariables.tabBlock;
|
||||||
|
var blockClass = ModAPI.reflect.getClassById("net.minecraft.block.Block");
|
||||||
|
var itemClass = ModAPI.reflect.getClassById("net.minecraft.item.Item");
|
||||||
|
var constructor = blockClass.constructors.find(x=>x.length === 1);
|
||||||
|
ModAPI.addEventListener("bootstrap", () => {
|
||||||
|
var block_of_steve = constructor(ModAPI.materials.rock.getRef()).$setHardness(-1.0).$setStepSound(blockClass.staticVariables.soundTypeGravel).$setUnlocalizedName(
|
||||||
|
ModAPI.util.str("steve")
|
||||||
|
).$setCreativeTab(creativeBlockTab);
|
||||||
|
blockClass.staticMethods.registerBlock0.method(
|
||||||
|
ModAPI.keygen.block("steve"), //use blockid 198. MAKE SURE TO CHANGE IF YOU ARE MAKING A MOD USING THIS, MAXIMUM BLOCK ID IS 4095.
|
||||||
|
ModAPI.util.str("steve"),
|
||||||
|
block_of_steve
|
||||||
|
);
|
||||||
|
itemClass.staticMethods.registerItemBlock0.method(block_of_steve);
|
||||||
|
fixupBlockIds();
|
||||||
|
ModAPI.blocks["steve"] = block_of_steve;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
registerSteveClientSide();
|
||||||
|
fixupBlockIds();
|
||||||
|
ModAPI.dedicatedServer.appendCode(registerSteveServerSide);
|
||||||
@@ -0,0 +1,148 @@
|
|||||||
|
(function CubeEntity() {
|
||||||
|
ModAPI.meta.title("Cube Entity");
|
||||||
|
ModAPI.meta.version("v0");
|
||||||
|
ModAPI.meta.description("testing custom entities");
|
||||||
|
ModAPI.meta.credits("By ZXMushroom63");
|
||||||
|
function waitForRenderManager() {
|
||||||
|
return new Promise((res, rej)=>{
|
||||||
|
function check() {
|
||||||
|
if (ModAPI.mc.renderManager) {
|
||||||
|
res();
|
||||||
|
} else {
|
||||||
|
setTimeout(check, 1/20);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
check();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
function registerEntity() {
|
||||||
|
// Utils
|
||||||
|
const ResourceLocation = ModAPI.reflect.getClassByName("ResourceLocation").constructors.find(x => x.length === 1);
|
||||||
|
const GlStateManager = Object.fromEntries(Object.values(ModAPI.reflect.getClassByName("GlStateManager").staticMethods).map(x => [x.methodNameShort, x.method]));
|
||||||
|
const IAnimals = ModAPI.reflect.getClassById("net.minecraft.entity.passive.IAnimals");
|
||||||
|
|
||||||
|
// START CUSTOM ENTITY
|
||||||
|
var entityClass = ModAPI.reflect.getClassById("net.minecraft.entity.Entity");
|
||||||
|
var entitySuper = ModAPI.reflect.getSuper(entityClass, (x) => x.length === 2);
|
||||||
|
var nme_EntityCube = function nme_EntityCube($worldIn) {
|
||||||
|
entitySuper(this, $worldIn);
|
||||||
|
this.$preventEntitySpawning = 1;
|
||||||
|
this.$setSize(1, 1);
|
||||||
|
}
|
||||||
|
ModAPI.reflect.prototypeStack(entityClass, nme_EntityCube);
|
||||||
|
|
||||||
|
//Turns out that minecraft 1.8's networking code is really stupid. Notch hardcoded every entity except for ones that implement the IAnimals interface.
|
||||||
|
//I don't know why, and I don't really care either. As long as it works (been working on this for too long, losing sanity)
|
||||||
|
ModAPI.reflect.implements(nme_EntityCube, IAnimals);
|
||||||
|
|
||||||
|
nme_EntityCube.prototype.$canTriggerWalking = function () { return 0 };
|
||||||
|
nme_EntityCube.prototype.$canBePushed = function () { return 1 };
|
||||||
|
nme_EntityCube.prototype.$getCollisionBox = function () { return this.$getEntityBoundingBox() };
|
||||||
|
nme_EntityCube.prototype.$getCollisionBoundingBox = function () { return this.$getEntityBoundingBox() };
|
||||||
|
nme_EntityCube.prototype.$readEntityFromNBT = function (nbtTagCompount) { // Needed, is an abstract method in parent class
|
||||||
|
nbtTagCompount = ModAPI.util.wrap(nbtTagCompount);
|
||||||
|
};
|
||||||
|
nme_EntityCube.prototype.$writeEntityToNBT = function (nbtTagCompount) { // Needed, is an abstract method in parent class
|
||||||
|
nbtTagCompount = ModAPI.util.wrap(nbtTagCompount);
|
||||||
|
};
|
||||||
|
nme_EntityCube.prototype.$entityInit = function () {
|
||||||
|
console.log("Cube entity created!");
|
||||||
|
};
|
||||||
|
// END CUSTOM ENTITY
|
||||||
|
|
||||||
|
|
||||||
|
// START CUSTOM MODEL
|
||||||
|
var ModelRenderer = ModAPI.reflect.getClassById("net.minecraft.client.model.ModelRenderer").constructors.find(x => x.length === 1);
|
||||||
|
var modelBaseClass = ModAPI.reflect.getClassById("net.minecraft.client.model.ModelBase");
|
||||||
|
var modelBaseSuper = ModAPI.reflect.getSuper(modelBaseClass); //while super isn't used when extending this class, java implies the call.
|
||||||
|
var nmcm_ModelCube = function nmcm_ModelCube() {
|
||||||
|
modelBaseSuper(this);
|
||||||
|
this.$textureWidth = 64;
|
||||||
|
this.$textureHeight = 64;
|
||||||
|
this.$cubeRenderer = ModelRenderer(this).$setTextureOffset(0, 0);
|
||||||
|
this.$cubeRenderer.$addBox0(0, 0, 0, 64, 64, 64);
|
||||||
|
this.$cubeRenderer.$setRotationPoint(0, 0, 0);
|
||||||
|
}
|
||||||
|
ModAPI.reflect.prototypeStack(modelBaseClass, nmcm_ModelCube);
|
||||||
|
nmcm_ModelCube.prototype.$render = function ($entity, useless1, useless2, partialTicks, useless3, useless4, degToRad) {
|
||||||
|
this.$cubeRenderer.$render(degToRad);
|
||||||
|
}
|
||||||
|
// END CUSTOM MODEL
|
||||||
|
|
||||||
|
|
||||||
|
// START CUSTOM RENDERER
|
||||||
|
var renderClass = ModAPI.reflect.getClassById("net.minecraft.client.renderer.entity.Render");
|
||||||
|
var renderSuper = ModAPI.reflect.getSuper(renderClass, (x) => x.length === 2);
|
||||||
|
const cubeTextures = ResourceLocation(ModAPI.util.str("textures/entity/cube.png"));
|
||||||
|
var nmcre_RenderCube = function nmcre_RenderCube(renderManager) {
|
||||||
|
renderSuper(this, renderManager);
|
||||||
|
this.$modelCube = new nmcm_ModelCube();
|
||||||
|
this.$shadowSize = 0.5;
|
||||||
|
}
|
||||||
|
ModAPI.reflect.prototypeStack(renderClass, nmcre_RenderCube);
|
||||||
|
nmcre_RenderCube.prototype.$getEntityTexture = function (entity) {
|
||||||
|
return cubeTextures;
|
||||||
|
}
|
||||||
|
const parentDoRender = nmcre_RenderCube.prototype.$doRender;
|
||||||
|
nmcre_RenderCube.prototype.$doRender = function (entity, x, y, z, yaw, pitch) {
|
||||||
|
GlStateManager.pushMatrix();
|
||||||
|
GlStateManager.translate(x + 0.5, y, z + 0.5);
|
||||||
|
GlStateManager.rotate(180 - yaw, 0, 1, 0);
|
||||||
|
GlStateManager.scale(0.25, 0.25, 0.25);
|
||||||
|
this.$bindEntityTexture(entity);
|
||||||
|
this.$modelCube.$render(entity, 0, 0, -0.1, 0, 0, 0.0625);
|
||||||
|
GlStateManager.popMatrix();
|
||||||
|
parentDoRender.apply(this, [entity, x, y, z, yaw, pitch]);
|
||||||
|
}
|
||||||
|
const ID = ModAPI.keygen.entity("cube");
|
||||||
|
ModAPI.reflect.getClassById("net.minecraft.entity.EntityList").staticMethods.addMapping0.method(
|
||||||
|
ModAPI.util.asClass(nme_EntityCube),
|
||||||
|
{
|
||||||
|
$createEntity: function ($worldIn) {
|
||||||
|
return new nme_EntityCube($worldIn);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
ModAPI.util.str("Cube"),
|
||||||
|
ID,
|
||||||
|
0x000000, //egg base
|
||||||
|
0x00FF00 //egg spots
|
||||||
|
);
|
||||||
|
// Note that the spawn egg for this will not work, as spawn eggs only spawn entities that are a subclass of EntityLivingBase
|
||||||
|
console.log(ID);
|
||||||
|
|
||||||
|
ModAPI.addEventListener("lib:asyncsink", async () => {
|
||||||
|
AsyncSink.L10N.set("entity.Cube.name", "Cube (TM)");
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
return {
|
||||||
|
EntityCube: nme_EntityCube,
|
||||||
|
ModelCube: nmcm_ModelCube,
|
||||||
|
RenderCube: nmcre_RenderCube,
|
||||||
|
cubeTexture: cubeTextures
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ModAPI.dedicatedServer.appendCode(registerEntity);
|
||||||
|
var data = registerEntity();
|
||||||
|
|
||||||
|
ModAPI.addEventListener("lib:asyncsink", async () => {
|
||||||
|
AsyncSink.setFile("resourcepacks/AsyncSinkLib/assets/minecraft/textures/entity/cube.png", await (await fetch(
|
||||||
|
"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEAAAABACAYAAACqaXHeAAAAAXNSR0IArs4c6QAAAQBJREFUeF7l0BFzAmAAgOGvKxgMgiAYDIJgEARBEASDQTAIgiAYBEEQBN0NBkEQBEEQBIMgCAZBEAwGgyAIgiAIgiConxE88PJ790RCCNdYCOGeRe/4j4SYDvCgAzzqAHEdIKEDJHWAJx3gWQdI6QBpHeBFB8joAFkdIKcD5HWAgg5Q1AFedYA3HaCkA7zrAGUdoKIDVHWAmg7woQPUdYCGDtDUAVo6QFsH6OgAnzrAlw7Q1QF6OkBfBxjoAEMdYKQDjHWAiQ7wrQNMdYCZDjDXAX50gIUOsNQBVjrArw7wpwP86wBrHWCjA2x1gJ0OsNcBDjrAUQc46QBnHeBiA9wALSueIjTE4PwAAAAASUVORK5CYII="
|
||||||
|
)).arrayBuffer());
|
||||||
|
AsyncSink.hideFile("resourcepacks/AsyncSinkLib/assets/minecraft/textures/entity/cube.png.mcmeta");
|
||||||
|
|
||||||
|
await waitForRenderManager()
|
||||||
|
ModAPI.mc.renderManager.entityRenderMap.put(ModAPI.util.asClass(data.EntityCube), new data.RenderCube(ModAPI.mc.renderManager.getRef()));
|
||||||
|
ModAPI.promisify(ModAPI.mc.renderEngine.bindTexture)(data.cubeTexture).then(() => {
|
||||||
|
console.log("Loaded cube texture into cache.");
|
||||||
|
});
|
||||||
|
});
|
||||||
|
console.log(data);
|
||||||
|
window.temp1 = data;
|
||||||
|
})();
|
||||||
|
//var cube_man = new temp1.EntityCube(ModAPI.mc.theWorld.getRef());
|
||||||
|
//cube_man.$setPosition(-191, 74, 26);
|
||||||
|
//AsyncSink.startDebugging();
|
||||||
|
//AsyncSink.startDebuggingFS();
|
||||||
|
//ModAPI.mc.theWorld.spawnEntityInWorld(cube_man);
|
||||||
@@ -0,0 +1,122 @@
|
|||||||
|
//THIS IS A DEMO MOD
|
||||||
|
|
||||||
|
|
||||||
|
//nice little utility function to fix the block identity map
|
||||||
|
function fixupBlockIds() {
|
||||||
|
var blockRegistry = ModAPI.util.wrap(ModAPI.reflect.getClassById("net.minecraft.block.Block").staticVariables.blockRegistry).getCorrective();
|
||||||
|
var BLOCK_STATE_IDS = ModAPI.util.wrap(ModAPI.reflect.getClassById("net.minecraft.block.Block").staticVariables.BLOCK_STATE_IDS).getCorrective();
|
||||||
|
blockRegistry.registryObjects.hashTableKToV.forEach(entry => {
|
||||||
|
if (entry) {
|
||||||
|
var block = entry.value;
|
||||||
|
var validStates = block.getBlockState().getValidStates();
|
||||||
|
var stateArray = validStates.array || [validStates.element];
|
||||||
|
stateArray.forEach(iblockstate => {
|
||||||
|
var i = blockRegistry.getIDForObject(block.getRef()) << 4 | block.getMetaFromState(iblockstate.getRef());
|
||||||
|
BLOCK_STATE_IDS.put(iblockstate.getRef(), i);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
function makeSteveBlock() {
|
||||||
|
var blockClass = ModAPI.reflect.getClassById("net.minecraft.block.Block");
|
||||||
|
var blockSuper = ModAPI.reflect.getSuper(blockClass, (x) => x.length === 2);
|
||||||
|
var creativeBlockTab = ModAPI.reflect.getClassById("net.minecraft.creativetab.CreativeTabs").staticVariables.tabBlock;
|
||||||
|
function nmb_BlockSteve() {
|
||||||
|
blockSuper(this, ModAPI.materials.rock.getRef());
|
||||||
|
//this.$defaultBlockState = this.$blockState.$getBaseState(); built-in in 1.12
|
||||||
|
this.$setCreativeTab(creativeBlockTab);
|
||||||
|
}
|
||||||
|
ModAPI.reflect.prototypeStack(blockClass, nmb_BlockSteve);
|
||||||
|
globalThis.nmb_BlockSteve = nmb_BlockSteve;
|
||||||
|
}
|
||||||
|
function registerSteveClientSide() {
|
||||||
|
var itemClass = ModAPI.reflect.getClassById("net.minecraft.item.Item");
|
||||||
|
var blockClass = ModAPI.reflect.getClassById("net.minecraft.block.Block");
|
||||||
|
var block_of_steve = (new nmb_BlockSteve()).$setHardness(-1.0).$setSoundType(ModAPI.blockSounds.PLANT.getRef()).$setUnlocalizedName(
|
||||||
|
ModAPI.util.str("steve")
|
||||||
|
);
|
||||||
|
blockClass.staticMethods.registerBlock0.method(
|
||||||
|
ModAPI.keygen.block("steve"),
|
||||||
|
ModAPI.util.str("steve"),
|
||||||
|
block_of_steve
|
||||||
|
);
|
||||||
|
itemClass.staticMethods.registerItemBlock0.method(block_of_steve);
|
||||||
|
ModAPI.addEventListener("lib:asyncsink", async () => {
|
||||||
|
ModAPI.addEventListener("lib:asyncsink:registeritems", (renderItem)=>{
|
||||||
|
console.log("registered!!");
|
||||||
|
renderItem.registerBlock(block_of_steve, ModAPI.util.str("steve"));
|
||||||
|
});
|
||||||
|
AsyncSink.L10N.set("tile.steve.name", "Block Of Steve");
|
||||||
|
AsyncSink.setFile("resourcepacks/AsyncSinkLib/assets/minecraft/models/block/steve.json", JSON.stringify(
|
||||||
|
{
|
||||||
|
"parent": "block/cube_all",
|
||||||
|
"textures": {
|
||||||
|
"all": "blocks/steve"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
));
|
||||||
|
AsyncSink.setFile("resourcepacks/AsyncSinkLib/assets/minecraft/models/item/steve.json", JSON.stringify(
|
||||||
|
{
|
||||||
|
"parent": "block/steve",
|
||||||
|
"display": {
|
||||||
|
"thirdperson": {
|
||||||
|
"rotation": [10, -45, 170],
|
||||||
|
"translation": [0, 1.5, -2.75],
|
||||||
|
"scale": [0.375, 0.375, 0.375]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
));
|
||||||
|
AsyncSink.setFile("resourcepacks/AsyncSinkLib/assets/minecraft/blockstates/steve.json", JSON.stringify(
|
||||||
|
{
|
||||||
|
"variants": {
|
||||||
|
"normal": [
|
||||||
|
{ "model": "steve" },
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
));
|
||||||
|
AsyncSink.setFile("resourcepacks/AsyncSinkLib/assets/minecraft/textures/blocks/steve.png", await (await fetch(
|
||||||
|
"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAE0SURBVDhPpdO9S8NAHMbxy3sVfJmMg6h7FRXXkkUUX0addSjo4OAfIDqLIoiLi3+BRRx0EIQOnV0EcVAIWkR0KIFgrcEktX6vcXD0nuE+5Afhnhw5bWy4qylaidOfVQhT0zFKYozjBHVdzi3TwCZvteaS/0fLD8oGf5OzTeyxNUyE3Ln2HmGctpuxKuS3wd76CgPHsrEj142NeojCkHsFry+4c3aJ6g1OtlZp0Ok4DD4i+Y2GIZ+DMMAhtw+fHu8xi3IDM9t5YfMQF71dLHo+ZjsfXbh4WtnH0vYaqp/BcXGGM3D7BxiYTi+el8uYZWm2gM/VB/Tfaqje4GB5iga2Jv+sUuUa5/ITmOXq7gbnC+MY1r9QvcHG9AgN0lRex1u/ilr7ehqWvBNZvMlRbESfqNhAiG/Pb1bHXpMbFgAAAABJRU5ErkJggg=="
|
||||||
|
)).arrayBuffer());
|
||||||
|
});
|
||||||
|
ModAPI.blocks["steve"] = block_of_steve;
|
||||||
|
}
|
||||||
|
function registerSteveServerSide() {
|
||||||
|
function fixupBlockIds() {
|
||||||
|
var blockRegistry = ModAPI.util.wrap(ModAPI.reflect.getClassById("net.minecraft.block.Block").staticVariables.blockRegistry).getCorrective();
|
||||||
|
var BLOCK_STATE_IDS = ModAPI.util.wrap(ModAPI.reflect.getClassById("net.minecraft.block.Block").staticVariables.BLOCK_STATE_IDS).getCorrective();
|
||||||
|
blockRegistry.registryObjects.hashTableKToV.forEach(entry => {
|
||||||
|
if (entry) {
|
||||||
|
var block = entry.value;
|
||||||
|
var validStates = block.getBlockState().getValidStates();
|
||||||
|
var stateArray = validStates.array || [validStates.element];
|
||||||
|
stateArray.forEach(iblockstate => {
|
||||||
|
var i = blockRegistry.getIDForObject(block.getRef()) << 4 | block.getMetaFromState(iblockstate.getRef());
|
||||||
|
BLOCK_STATE_IDS.put(iblockstate.getRef(), i);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
var blockClass = ModAPI.reflect.getClassById("net.minecraft.block.Block");
|
||||||
|
var itemClass = ModAPI.reflect.getClassById("net.minecraft.item.Item");
|
||||||
|
ModAPI.addEventListener("bootstrap", () => {
|
||||||
|
var block_of_steve = (new nmb_BlockSteve()).$setHardness(-1.0).$setSoundType(ModAPI.blockSounds.PLANT.getRef()).$setUnlocalizedName(
|
||||||
|
ModAPI.util.str("steve")
|
||||||
|
);
|
||||||
|
blockClass.staticMethods.registerBlock0.method(
|
||||||
|
ModAPI.keygen.block("steve"), //MAXIMUM BLOCK ID IS 4095. keygen method accounts for this
|
||||||
|
ModAPI.util.str("steve"),
|
||||||
|
block_of_steve
|
||||||
|
);
|
||||||
|
itemClass.staticMethods.registerItemBlock0.method(block_of_steve);
|
||||||
|
fixupBlockIds();
|
||||||
|
ModAPI.blocks["steve"] = block_of_steve;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
ModAPI.dedicatedServer.appendCode(makeSteveBlock);
|
||||||
|
makeSteveBlock();
|
||||||
|
registerSteveClientSide();
|
||||||
|
fixupBlockIds();
|
||||||
|
|
||||||
|
ModAPI.dedicatedServer.appendCode(registerSteveServerSide);
|
||||||
@@ -0,0 +1,57 @@
|
|||||||
|
(function AddDiamondRecipe() {
|
||||||
|
ModAPI.meta.title("DiamondCraftingRecipeMod");
|
||||||
|
ModAPI.meta.description("Adds a crafting recipe to create diamond blocks from dirt.");
|
||||||
|
|
||||||
|
async function addDiamondRecipe() {
|
||||||
|
await new Promise((res, rej) => {
|
||||||
|
if (ModAPI.blocks) {
|
||||||
|
res()
|
||||||
|
} else {
|
||||||
|
ModAPI.addEventListener("bootstrap", res);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
var ObjectClass = ModAPI.reflect.getClassById("java.lang.Object").class;
|
||||||
|
function ToChar(char) {
|
||||||
|
return ModAPI.reflect.getClassById("java.lang.Character").staticMethods.valueOf.method(char[0].charCodeAt(0));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Define the recipe legend to map characters to items
|
||||||
|
var recipeLegend = {
|
||||||
|
"D": {
|
||||||
|
type: "block",
|
||||||
|
id: "dirt" // Using dirt blocks
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// Define the crafting grid pattern for the recipe
|
||||||
|
var recipePattern = [
|
||||||
|
"DDD",
|
||||||
|
"DDD",
|
||||||
|
"DDD"
|
||||||
|
];
|
||||||
|
|
||||||
|
// Convert the recipe pattern and legend into the required format
|
||||||
|
var recipeInternal = [];
|
||||||
|
Object.keys(recipeLegend).forEach((key) => {
|
||||||
|
recipeInternal.push(ToChar(key));
|
||||||
|
var ingredient = (recipeLegend[key].type === "block" ? ModAPI.blocks : ModAPI.items)[recipeLegend[key].id].getRef();
|
||||||
|
recipeInternal.push(ingredient);
|
||||||
|
});
|
||||||
|
|
||||||
|
var recipeContents = recipePattern.map(row => ModAPI.util.str(row));
|
||||||
|
var recipe = ModAPI.util.makeArray(ObjectClass, recipeContents.concat(recipeInternal));
|
||||||
|
|
||||||
|
// Define the output item as diamond_block
|
||||||
|
var resultItem = ModAPI.reflect.getClassById("net.minecraft.item.ItemStack").constructors[1](ModAPI.blocks["diamond_block"].getRef(), 1);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// Register the recipe with CraftingManager
|
||||||
|
var craftingManager = ModAPI.reflect.getClassById("net.minecraft.item.crafting.CraftingManager").staticMethods.getInstance.method();
|
||||||
|
ModAPI.hooks.methods.nmic_CraftingManager_addRecipe(craftingManager, resultItem, recipe);
|
||||||
|
}
|
||||||
|
|
||||||
|
ModAPI.dedicatedServer.appendCode(addDiamondRecipe);
|
||||||
|
|
||||||
|
addDiamondRecipe();
|
||||||
|
})();
|
||||||
@@ -0,0 +1,43 @@
|
|||||||
|
(function AddDiamondRecipe() {
|
||||||
|
ModAPI.meta.title("DiamondCraftingRecipeMod 1.12");
|
||||||
|
ModAPI.meta.description("Adds a crafting recipe to create diamond blocks from dirt.");
|
||||||
|
|
||||||
|
async function registerRecipe(isServer) {
|
||||||
|
if (isServer) {
|
||||||
|
await new Promise((res, rej) => {
|
||||||
|
ModAPI.addEventListener("bootstrap", res);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
const parseJson = ModAPI.reflect.getClassByName("JSONObject").constructors.findLast(x => x.length === 1);
|
||||||
|
const CraftingManager = ModAPI.reflect.getClassByName("CraftingManager");
|
||||||
|
const CraftingManagerMethods = CraftingManager.staticMethods;
|
||||||
|
const jsonData = parseJson(ModAPI.util.str(`{
|
||||||
|
"type": "crafting_shaped", ${/*/or crafting_shapeless/*/""}
|
||||||
|
"pattern": [
|
||||||
|
"I I",
|
||||||
|
" i ",
|
||||||
|
"iii"
|
||||||
|
],
|
||||||
|
"key": {
|
||||||
|
"I": {
|
||||||
|
"item": "minecraft:dirt",
|
||||||
|
data: 0 ${/*/data param optional!!!/*/""}
|
||||||
|
},
|
||||||
|
"i": {
|
||||||
|
"item": "minecraft:grass",
|
||||||
|
data: 0 ${/*/data param optional!!!/*/""}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"result": {
|
||||||
|
"item": "minecraft:diamond",
|
||||||
|
"data": 0,
|
||||||
|
"count": 4
|
||||||
|
}
|
||||||
|
}`.trim()));
|
||||||
|
const recipeObj = CraftingManagerMethods.func_193376_a.method(jsonData); //convert json to an IRecipe
|
||||||
|
CraftingManagerMethods.func_193379_a.method(ModAPI.util.str("coolrecipeid"), recipeObj); //register recipe under resource location
|
||||||
|
}
|
||||||
|
|
||||||
|
ModAPI.dedicatedServer.appendCode(registerRecipe);
|
||||||
|
registerRecipe(false);
|
||||||
|
})();
|
||||||
@@ -0,0 +1,143 @@
|
|||||||
|
//utility function to return an array of GuiButtons from an array of JS objects, while automatically binding them
|
||||||
|
function button_utility_script(inputArr, bindingClass, actionBindMode) {
|
||||||
|
// By ZXMushroom63
|
||||||
|
// action bind mode:
|
||||||
|
// 0 - bind to the same as the binding class
|
||||||
|
// 1 - do not bind
|
||||||
|
// 2 - bind to GuiScreen
|
||||||
|
actionBindMode ||= 0;
|
||||||
|
var button = ModAPI.reflect.getClassById("net.minecraft.client.gui.GuiButton").constructors.find(x => x.length === 6);
|
||||||
|
var originalActionPerformed = ModAPI.hooks.methods[ModAPI.util.getMethodFromPackage(actionBindMode === 2 ? "net.minecraft.client.gui.GuiScreen" : bindingClass, "actionPerformed")];
|
||||||
|
var originalInit = ModAPI.hooks.methods[ModAPI.util.getMethodFromPackage(bindingClass, "initGui")];
|
||||||
|
var out = inputArr.flatMap(x => {
|
||||||
|
var btn = button(x.uid, x.x, x.y, x.w, x.h, ModAPI.util.str(x.text));
|
||||||
|
return btn;
|
||||||
|
});
|
||||||
|
if (actionBindMode !== 1) {
|
||||||
|
ModAPI.hooks.methods[ModAPI.util.getMethodFromPackage(actionBindMode === 2 ? "net.minecraft.client.gui.GuiScreen" : bindingClass, "actionPerformed")] = function (...args) {
|
||||||
|
var id = ModAPI.util.wrap(args[1]).getCorrective().id;
|
||||||
|
var jsAction = inputArr.find(x => x.uid === id);
|
||||||
|
if (jsAction) {
|
||||||
|
jsAction.click(ModAPI.util.wrap(args[0]));
|
||||||
|
}
|
||||||
|
return originalActionPerformed.apply(this, args);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ModAPI.hooks.methods[ModAPI.util.getMethodFromPackage(bindingClass, "initGui")] = function (...args) {
|
||||||
|
originalInit.apply(this, args);
|
||||||
|
var gui = ModAPI.util.wrap(args[0]).getCorrective();
|
||||||
|
out.forEach(guiButton => {
|
||||||
|
gui.buttonList.add(guiButton);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
(() => {
|
||||||
|
ModAPI.require("player");
|
||||||
|
var backlog = [];
|
||||||
|
var delayState = false;
|
||||||
|
|
||||||
|
const originalSend = WebSocket.prototype.send;
|
||||||
|
|
||||||
|
//Override WebSocket.send, so when eagler tries to send messages, it runs our code instead
|
||||||
|
Object.defineProperty(WebSocket.prototype, 'send', {
|
||||||
|
configurable: true,
|
||||||
|
enumerable: false,
|
||||||
|
writable: false,
|
||||||
|
value: function (data) {
|
||||||
|
//If blinking, push data to backlog along with it's websocket instance.
|
||||||
|
if (delayState) {
|
||||||
|
backlog.push({ data: data, thisArg: this });
|
||||||
|
} else { //Else send the data as normal
|
||||||
|
originalSend.call(this, data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
ModAPI.meta.title("Dupe Hunting");
|
||||||
|
ModAPI.meta.description("⚠️Only works over WS, not local. May induce bans.⚠️");
|
||||||
|
ModAPI.meta.credits("by ZXMushroom63");
|
||||||
|
|
||||||
|
var dupeHuntButtons = [{
|
||||||
|
text: "Silently Close",
|
||||||
|
click: () => {
|
||||||
|
ModAPI.minecraft.displayGuiScreen(null);
|
||||||
|
},
|
||||||
|
x: 0,
|
||||||
|
y: 0,
|
||||||
|
w: 100,
|
||||||
|
h: 20,
|
||||||
|
uid: 142715254
|
||||||
|
},
|
||||||
|
{
|
||||||
|
text: "Toggle Delay",
|
||||||
|
click: () => {
|
||||||
|
delayState = !delayState;
|
||||||
|
alert(delayState ? "Delay On" : "Sending Packets...");
|
||||||
|
if (delayState === false) {
|
||||||
|
for (let i = 0; i < backlog.length; i++) {
|
||||||
|
const backlogItem = backlog[i];
|
||||||
|
originalSend.call(backlogItem.thisArg, backlogItem.data);
|
||||||
|
}
|
||||||
|
backlog = [];
|
||||||
|
}
|
||||||
|
},
|
||||||
|
x: 0,
|
||||||
|
y: 20,
|
||||||
|
w: 100,
|
||||||
|
h: 20,
|
||||||
|
uid: 142715253
|
||||||
|
},
|
||||||
|
{
|
||||||
|
text: "Server Close",
|
||||||
|
click: () => {
|
||||||
|
var CloseWindow = ModAPI.reflect.getClassByName("C0DPacketCloseWindow").constructors[0];
|
||||||
|
ModAPI.player.sendQueue.addToSendQueue(CloseWindow(ModAPI.player.openContainer.getCorrective().windowId));
|
||||||
|
},
|
||||||
|
x: 0,
|
||||||
|
y: 40,
|
||||||
|
w: 100,
|
||||||
|
h: 20,
|
||||||
|
uid: 142715252
|
||||||
|
},
|
||||||
|
{
|
||||||
|
text: "Send & Disconnect",
|
||||||
|
click: () => {
|
||||||
|
delayState = false;
|
||||||
|
for (let i = 0; i < backlog.length; i++) {
|
||||||
|
const backlogItem = backlog[i];
|
||||||
|
originalSend.call(backlogItem.thisArg, backlogItem.data);
|
||||||
|
}
|
||||||
|
backlog = [];
|
||||||
|
ModAPI.mc.getNetHandler().getNetworkManager().doClientDisconnect(ModAPI.hooks._classMap[ModAPI.util.getCompiledName("net.minecraft.util.ChatComponentText")].constructors[0](ModAPI.util.str("Dupe Hunting Utils Disconnect")));
|
||||||
|
},
|
||||||
|
x: 0,
|
||||||
|
y: 60,
|
||||||
|
w: 100,
|
||||||
|
h: 20,
|
||||||
|
uid: 142715251
|
||||||
|
},
|
||||||
|
{
|
||||||
|
text: "Use Chat",
|
||||||
|
click: () => {
|
||||||
|
var p = window.prompt("Input chat/command:", "Hello World");
|
||||||
|
if (p) {
|
||||||
|
ModAPI.player.sendChatMessage(ModAPI.util.str(p));
|
||||||
|
}
|
||||||
|
},
|
||||||
|
x: 0,
|
||||||
|
y: 80,
|
||||||
|
w: 100,
|
||||||
|
h: 20,
|
||||||
|
uid: 142715250
|
||||||
|
}];
|
||||||
|
|
||||||
|
[
|
||||||
|
"net.minecraft.client.gui.inventory.GuiInventory",
|
||||||
|
"net.minecraft.client.gui.inventory.GuiContainerCreative",
|
||||||
|
"net.minecraft.client.gui.inventory.GuiBeacon"
|
||||||
|
].forEach(ui => {
|
||||||
|
button_utility_script(dupeHuntButtons, ui, 2);
|
||||||
|
});
|
||||||
|
})();
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
(() => {
|
||||||
|
ModAPI.meta.title("/ray_trace_test");
|
||||||
|
ModAPI.meta.description("Mod to test server-side raycasting.");
|
||||||
|
ModAPI.meta.credits("By ZXMushroom63");
|
||||||
|
|
||||||
|
PluginAPI.dedicatedServer.appendCode(function () {
|
||||||
|
PluginAPI.addEventListener("processcommand", (event) => {
|
||||||
|
if (event.command.toLowerCase().startsWith("/ray_trace_test")) {
|
||||||
|
if (
|
||||||
|
ModAPI.reflect.getClassById("net.minecraft.entity.player.EntityPlayerMP").instanceOf(event.sender.getRef())
|
||||||
|
) {
|
||||||
|
//raytrace distance = 6
|
||||||
|
//the 0 on the end is for client side view bobbing (frame based). we are on the server so using 0 as default.
|
||||||
|
var movingObjectPosition = event.sender.rayTrace(6, 0).getCorrective();
|
||||||
|
console.log(movingObjectPosition);
|
||||||
|
|
||||||
|
//var hitVec = movingObjectPosition.hitVec;
|
||||||
|
|
||||||
|
event.sender.addChatMessage(ModAPI.reflect.getClassById("net.minecraft.util.ChatComponentText").constructors[0](
|
||||||
|
movingObjectPosition.toString().getRef() //This is a java string, but that's ok since it goes into a java method.
|
||||||
|
));
|
||||||
|
}
|
||||||
|
event.preventDefault = true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
})();
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
(() => {
|
||||||
|
ModAPI.meta.title("Fullscreen Fixer");
|
||||||
|
ModAPI.meta.description("Makes HTML guis still appear in fullscreen.");
|
||||||
|
ModAPI.meta.credits("By ZXMushroom63");
|
||||||
|
|
||||||
|
var oldF11 = HTMLElement.prototype.requestFullscreen;
|
||||||
|
HTMLElement.prototype.requestFullscreen = function () {
|
||||||
|
if (this instanceof HTMLBodyElement) {
|
||||||
|
oldF11.apply(this, []);
|
||||||
|
} else {
|
||||||
|
document.body.requestFullscreen();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})();
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
(function MinecartSpeedMod() {
|
||||||
|
ModAPI.meta.title("Faster Minecarts");
|
||||||
|
ModAPI.meta.description("Faster minecarts! Use /minecart_speed {factor} to edit the minecart's speed. Carts are very prone to being flung off rails.");
|
||||||
|
ModAPI.meta.credits("By ZXMushroom63");
|
||||||
|
ModAPI.meta.version("v1.0");
|
||||||
|
|
||||||
|
ModAPI.dedicatedServer.appendCode(function () {
|
||||||
|
ModAPI.addEventListener("processcommand", (event) => {
|
||||||
|
if (event.command.toLowerCase().startsWith("/minecart_speed")) {
|
||||||
|
var speed = parseFloat(event.command.substring("/minecart_speed ".length)) || 1;
|
||||||
|
var trueSpeed = speed * 0.4;
|
||||||
|
ModAPI.hooks.methods.nmei_EntityMinecart_getMaximumSpeed = () => trueSpeed;
|
||||||
|
event.sender.addChatMessage(ModAPI.reflect.getClassById("net.minecraft.util.ChatComponentText").constructors[0](ModAPI.util.str("Set minecart speed to "+speed)));
|
||||||
|
event.preventDefault = true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
})();
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
const originalGetBurnTime = ModAPI.hooks.methods[ModAPI.util.getMethodFromPackage("net.minecraft.tileentity.TileEntityFurnace", "getItemBurnTime")];
|
||||||
|
ModAPI.hooks.methods[ModAPI.util.getMethodFromPackage("net.minecraft.tileentity.TileEntityFurnace", "getItemBurnTime")] = function (...args) {
|
||||||
|
if (args[0].$item === ModAPI.items.string.getRef()) {
|
||||||
|
return 50;
|
||||||
|
}
|
||||||
|
return originalGetBurnTime.apply(this, args);
|
||||||
|
};
|
||||||
@@ -0,0 +1,44 @@
|
|||||||
|
(function grapplehook() {
|
||||||
|
PluginAPI.require("player"); //Require the player
|
||||||
|
globalThis.GrappleHookPlugin = {
|
||||||
|
oldXYZ: [0, 0, 0], //The previous hook position.
|
||||||
|
prev: "NONE", //The previous state
|
||||||
|
scaleH: 0.25, //Used for X and Z velocity
|
||||||
|
scaleV: 0.15, //((Grapple Y) minus (Player Y)) times scaleV
|
||||||
|
lift: 0.4, //Base vertical motion
|
||||||
|
crouchToCancel: true //Whether or not crouching should disable the grappling hook.
|
||||||
|
};
|
||||||
|
PluginAPI.addEventListener("update", () => { //Every client tick
|
||||||
|
var player = ModAPI.player.getCorrective(); //Gets the corrective version of the player object. This removes broken proerty suffixes. You usually don't need this, but in my case, I do.
|
||||||
|
if (!player.fishEntity) { //If the fish hook does not exist.
|
||||||
|
if (GrappleHookPlugin.prev === "GROUND" && (!GrappleHookPlugin.crouchToCancel || !player.isSneaking())) { //If the old state was ground
|
||||||
|
GrappleHookPlugin.prev = "NONE"; //Update the state
|
||||||
|
var mx = GrappleHookPlugin.oldXYZ[0] - player.posX; //Get delta X
|
||||||
|
var my = GrappleHookPlugin.oldXYZ[1] - player.posY; //Get delta Y
|
||||||
|
var mz = GrappleHookPlugin.oldXYZ[2] - player.posZ; //Get delta Z
|
||||||
|
mx *= GrappleHookPlugin.scaleH; //Multiply by horizontal scale
|
||||||
|
my *= GrappleHookPlugin.scaleV; //Multiply by vertical scale
|
||||||
|
mz *= GrappleHookPlugin.scaleH; //Multiply by horizontal scale
|
||||||
|
player.motionX += mx; //Add x motion
|
||||||
|
player.motionY += my + GrappleHookPlugin.lift; //Add y motion, plus base lift.
|
||||||
|
player.motionZ += mz; //Add z motion
|
||||||
|
} else {
|
||||||
|
GrappleHookPlugin.prev = "NONE";
|
||||||
|
}
|
||||||
|
} else if (GrappleHookPlugin.prev === "NONE") { //If the hook exists, but the previous state was NONE, update the state.
|
||||||
|
GrappleHookPlugin.prev = "AIR";
|
||||||
|
}
|
||||||
|
if (
|
||||||
|
player.fishEntity !== undefined && //If the fish hook exists
|
||||||
|
GrappleHookPlugin.prev === "AIR" && //And the hook was previously in the air
|
||||||
|
(player.fishEntity.inGround || player.fishEntity.onGround) //And the hook is in the ground
|
||||||
|
) {
|
||||||
|
GrappleHookPlugin.oldXYZ = [ //Set old grapple hook position
|
||||||
|
player.fishEntity.posX,
|
||||||
|
player.fishEntity.posY,
|
||||||
|
player.fishEntity.posZ,
|
||||||
|
];
|
||||||
|
GrappleHookPlugin.prev = "GROUND";//Update state
|
||||||
|
}
|
||||||
|
});
|
||||||
|
})();
|
||||||
@@ -0,0 +1,137 @@
|
|||||||
|
(()=>{
|
||||||
|
const itemTexture = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAADySURBVFhH7ZQxDoMwDEVNr4G6VmJC6mk4Itdh7VpxjsBPDaKVCLZxypInIccg5zs/CVQoKAj8uHLjeETouo6HvlQcU3yJ932PIKkTceRAFH8NA6dE3IzbVogdQBOPtuVXfk5IJ8jWhKY4SxPaQvcmLEWuTUj/A1sqiEEcTQBENDWjvh3mvZtxccLiwMqvE0DrhNUBCCy1KSdAUsPiwFYcpM5ENrYWh3tdI4cT4dk0MSKPXzMSRSC+PMi14mcO4e7esv2iJqyHEGDVPCR6jyMC5luERXOfuoY7QFi8MKsDe6tXk8OBv7Ge/E96DZeKFwoOEE1wUX7TFh5zsgAAAABJRU5ErkJggg==";
|
||||||
|
ModAPI.meta.title("guns");
|
||||||
|
ModAPI.meta.version("v1.0");
|
||||||
|
ModAPI.meta.icon(itemTexture);
|
||||||
|
ModAPI.meta.description("Requires AsyncSink.");
|
||||||
|
|
||||||
|
ModAPI.require("player");
|
||||||
|
|
||||||
|
function PistolItem() {
|
||||||
|
var recoilSpeed = 0; //recoil controller
|
||||||
|
var DamageSourceClass = ModAPI.reflect.getClassByName("DamageSource");
|
||||||
|
var creativeMiscTab = ModAPI.reflect.getClassById("net.minecraft.creativetab.CreativeTabs").staticVariables.tabMisc;
|
||||||
|
var itemClass = ModAPI.reflect.getClassById("net.minecraft.item.Item");
|
||||||
|
var itemSuper = ModAPI.reflect.getSuper(itemClass, (x) => x.length === 1);
|
||||||
|
var nmi_ItemPistol = function nmi_ItemPistol() {
|
||||||
|
itemSuper(this); //Use super function to get block properties on this class.
|
||||||
|
this.$setCreativeTab(creativeMiscTab);
|
||||||
|
}
|
||||||
|
|
||||||
|
ModAPI.addEventListener("update", ()=>{ //recoil update loop (client)
|
||||||
|
ModAPI.player.rotationPitch -= recoilSpeed;
|
||||||
|
recoilSpeed *= 0.7;
|
||||||
|
});
|
||||||
|
|
||||||
|
function entityRayCast(player, world, range) {
|
||||||
|
const HEADSHOT_MAX_DISTANCE_FROM_HEAD = 0.72;
|
||||||
|
var eyePosition = player.getPositionEyes(0.0);
|
||||||
|
var targetPosition = player.rayTrace(range, 0).hitVec;
|
||||||
|
var entities = world.getEntitiesWithinAABBExcludingEntity(
|
||||||
|
player.getRef(),
|
||||||
|
player.getEntityBoundingBox().expand(range, range, range).getRef()
|
||||||
|
).getCorrective().array;
|
||||||
|
var closestEntity = null;
|
||||||
|
var isHeadshot = false;
|
||||||
|
var closestDistance = range;
|
||||||
|
|
||||||
|
// Iterate through all entities to find the one the player is looking at
|
||||||
|
for (var i = 0; i < entities.length; i++) {
|
||||||
|
if (!entities[i]) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
var entity = entities[i];
|
||||||
|
|
||||||
|
// Check if the entity's bounding box intersects with the player's ray
|
||||||
|
var entityBB = entity.getEntityBoundingBox().expand(0.3, 0.3, 0.3);
|
||||||
|
var intercept = entityBB.calculateIntercept(eyePosition.getRef(), targetPosition.getRef());
|
||||||
|
|
||||||
|
if (intercept != null) {
|
||||||
|
var distance = eyePosition.distanceTo(intercept.hitVec.getRef());
|
||||||
|
if (distance < closestDistance) {
|
||||||
|
closestDistance = distance;
|
||||||
|
closestEntity = entity;
|
||||||
|
isHeadshot = entity.getPositionEyes(0.0).distanceTo(intercept.hitVec.getRef()) < HEADSHOT_MAX_DISTANCE_FROM_HEAD;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var rayTraceResult = closestEntity;
|
||||||
|
if (rayTraceResult != null){
|
||||||
|
return {entity: rayTraceResult, headshot: isHeadshot};
|
||||||
|
} else{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ModAPI.reflect.prototypeStack(itemClass, nmi_ItemPistol);
|
||||||
|
nmi_ItemPistol.prototype.$onItemRightClick = function ($itemstack, $world, $player) {
|
||||||
|
var cactus = DamageSourceClass.staticVariables.cactus;
|
||||||
|
var world = ModAPI.util.wrap($world);
|
||||||
|
var entityplayer = ModAPI.util.wrap($player);
|
||||||
|
var shotentitydata = entityRayCast(entityplayer, world, 16.0);
|
||||||
|
if (shotentitydata != null){
|
||||||
|
if (world.isRemote) {
|
||||||
|
recoilSpeed += 4;
|
||||||
|
} else {
|
||||||
|
shotentitydata.entity.attackEntityFrom(cactus, 10 + (16 * shotentitydata.headshot));
|
||||||
|
if (shotentitydata.headshot) {
|
||||||
|
console.log("H E A D S H O T");
|
||||||
|
}
|
||||||
|
world.playSoundAtEntity(entityplayer.getRef(), ModAPI.util.str("tile.piston.out"), 1.0, 1.8);
|
||||||
|
}
|
||||||
|
} else if (!world.isRemote) {
|
||||||
|
world.playSoundAtEntity(entityplayer.getRef(), ModAPI.util.str("random.click"), 1.0, 1.8);
|
||||||
|
}
|
||||||
|
return $itemstack;
|
||||||
|
}
|
||||||
|
|
||||||
|
function internal_reg() {
|
||||||
|
var pistol_item = (new nmi_ItemPistol()).$setUnlocalizedName(
|
||||||
|
ModAPI.util.str("pistol")
|
||||||
|
).$setMaxStackSize(1);
|
||||||
|
itemClass.staticMethods.registerItem.method(ModAPI.keygen.item("pistol"), ModAPI.util.str("pistol"), pistol_item);
|
||||||
|
ModAPI.items["pistol"] = pistol_item;
|
||||||
|
|
||||||
|
return pistol_item;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ModAPI.items) {
|
||||||
|
return internal_reg();
|
||||||
|
} else {
|
||||||
|
ModAPI.addEventListener("bootstrap", internal_reg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ModAPI.dedicatedServer.appendCode(PistolItem);
|
||||||
|
var pistol_item = PistolItem();
|
||||||
|
|
||||||
|
ModAPI.addEventListener("lib:asyncsink", async () => {
|
||||||
|
ModAPI.addEventListener("lib:asyncsink:registeritems", (renderItem)=>{
|
||||||
|
renderItem.registerItem(pistol_item, ModAPI.util.str("pistol"));
|
||||||
|
});
|
||||||
|
AsyncSink.L10N.set("item.pistol.name", "Pistol");
|
||||||
|
AsyncSink.setFile("resourcepacks/AsyncSinkLib/assets/minecraft/models/item/pistol.json", JSON.stringify(
|
||||||
|
{
|
||||||
|
"parent": "builtin/generated",
|
||||||
|
"textures": {
|
||||||
|
"layer0": "items/pistol"
|
||||||
|
},
|
||||||
|
"display": {
|
||||||
|
"thirdperson": {
|
||||||
|
"rotation": [ 5, 80, -45 ],
|
||||||
|
"translation": [ 0, 1, -3 ],
|
||||||
|
"scale": [ 1.0, 1.0, 1.0 ]
|
||||||
|
},
|
||||||
|
"firstperson": {
|
||||||
|
"rotation": [ 0, -135, 25 ],
|
||||||
|
"translation": [ 0, 4, 2 ],
|
||||||
|
"scale": [ 1.8, 1.8, 1.8 ]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
));
|
||||||
|
AsyncSink.setFile("resourcepacks/AsyncSinkLib/assets/minecraft/textures/items/pistol.png", await (await fetch(
|
||||||
|
itemTexture
|
||||||
|
)).arrayBuffer());
|
||||||
|
});
|
||||||
|
})();
|
||||||
@@ -0,0 +1,184 @@
|
|||||||
|
(()=>{
|
||||||
|
const itemTexture = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAADySURBVFhH7ZQxDoMwDEVNr4G6VmJC6mk4Itdh7VpxjsBPDaKVCLZxypInIccg5zs/CVQoKAj8uHLjeETouo6HvlQcU3yJ932PIKkTceRAFH8NA6dE3IzbVogdQBOPtuVXfk5IJ8jWhKY4SxPaQvcmLEWuTUj/A1sqiEEcTQBENDWjvh3mvZtxccLiwMqvE0DrhNUBCCy1KSdAUsPiwFYcpM5ENrYWh3tdI4cT4dk0MSKPXzMSRSC+PMi14mcO4e7esv2iJqyHEGDVPCR6jyMC5luERXOfuoY7QFi8MKsDe6tXk8OBv7Ge/E96DZeKFwoOEE1wUX7TFh5zsgAAAABJRU5ErkJggg==";
|
||||||
|
ModAPI.meta.title("guns");
|
||||||
|
ModAPI.meta.version("v1.0");
|
||||||
|
ModAPI.meta.icon(itemTexture);
|
||||||
|
ModAPI.meta.description("Requires AsyncSink.");
|
||||||
|
|
||||||
|
ModAPI.require("player");
|
||||||
|
|
||||||
|
function PistolItem() {
|
||||||
|
var recoilSpeed = 0; //recoil controller
|
||||||
|
var DamageSourceClass = ModAPI.reflect.getClassByName("DamageSource");
|
||||||
|
var creativeMiscTab = ModAPI.reflect.getClassById("net.minecraft.creativetab.CreativeTabs").staticVariables.tabMisc;
|
||||||
|
var itemClass = ModAPI.reflect.getClassById("net.minecraft.item.Item");
|
||||||
|
var itemSuper = ModAPI.reflect.getSuper(itemClass, (x) => x.length === 1);
|
||||||
|
var nmi_ItemPistol = function nmi_ItemPistol() {
|
||||||
|
itemSuper(this); //Use super function to get block properties on this class.
|
||||||
|
this.$setCreativeTab(creativeMiscTab);
|
||||||
|
}
|
||||||
|
|
||||||
|
ModAPI.addEventListener("update", ()=>{ //recoil update loop (client)
|
||||||
|
ModAPI.player.rotationPitch -= recoilSpeed;
|
||||||
|
recoilSpeed *= 0.7;
|
||||||
|
});
|
||||||
|
|
||||||
|
function entityRayCast(player, world, range) {
|
||||||
|
const HEADSHOT_MAX_DISTANCE_FROM_HEAD = 0.72;
|
||||||
|
var eyePosition = player.getPositionEyes(0.0);
|
||||||
|
var targetPosition = player.rayTrace(range, 0).hitVec;
|
||||||
|
var entities = world.getEntitiesWithinAABBExcludingEntity(
|
||||||
|
player.getRef(),
|
||||||
|
player.getEntityBoundingBox().expand(range, range, range).getRef()
|
||||||
|
).getCorrective().array;
|
||||||
|
var closestEntity = null;
|
||||||
|
var isHeadshot = false;
|
||||||
|
var closestDistance = range;
|
||||||
|
|
||||||
|
// Iterate through all entities to find the one the player is looking at
|
||||||
|
for (var i = 0; i < entities.length; i++) {
|
||||||
|
if (!entities[i]) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
var entity = entities[i];
|
||||||
|
|
||||||
|
// Check if the entity's bounding box intersects with the player's ray
|
||||||
|
var entityBB = entity.getEntityBoundingBox().expand(0.3, 0.3, 0.3);
|
||||||
|
var intercept = entityBB.calculateIntercept(eyePosition.getRef(), targetPosition.getRef());
|
||||||
|
|
||||||
|
if (intercept != null) {
|
||||||
|
var distance = eyePosition.distanceTo(intercept.hitVec.getRef());
|
||||||
|
if (distance < closestDistance) {
|
||||||
|
closestDistance = distance;
|
||||||
|
closestEntity = entity;
|
||||||
|
isHeadshot = entity.getPositionEyes(0.0).distanceTo(intercept.hitVec.getRef()) < HEADSHOT_MAX_DISTANCE_FROM_HEAD;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var rayTraceResult = closestEntity;
|
||||||
|
if (rayTraceResult != null){
|
||||||
|
return {entity: rayTraceResult, headshot: isHeadshot};
|
||||||
|
} else{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ModAPI.reflect.prototypeStack(itemClass, nmi_ItemPistol);
|
||||||
|
nmi_ItemPistol.prototype.$onItemRightClick = function ($itemstack, $world, $player) {
|
||||||
|
var cactus = DamageSourceClass.staticVariables.cactus;
|
||||||
|
var world = ModAPI.util.wrap($world);
|
||||||
|
var entityplayer = ModAPI.util.wrap($player);
|
||||||
|
var shotentitydata = entityRayCast(entityplayer, world, 16.0);
|
||||||
|
if (shotentitydata != null){
|
||||||
|
if (world.isRemote) {
|
||||||
|
recoilSpeed += 4;
|
||||||
|
} else {
|
||||||
|
shotentitydata.entity.attackEntityFrom(cactus, 10 + (16 * shotentitydata.headshot));
|
||||||
|
if (shotentitydata.headshot) {
|
||||||
|
console.log("H E A D S H O T");
|
||||||
|
}
|
||||||
|
world.playSoundAtEntity(entityplayer.getRef(), ModAPI.util.str("tile.piston.out"), 1.0, 1.8);
|
||||||
|
}
|
||||||
|
} else if (!world.isRemote) {
|
||||||
|
world.playSoundAtEntity(entityplayer.getRef(), ModAPI.util.str("random.click"), 1.0, 1.8);
|
||||||
|
}
|
||||||
|
return $itemstack;
|
||||||
|
}
|
||||||
|
|
||||||
|
async function addGunRecipe(gunItem) {
|
||||||
|
var ObjectClass = ModAPI.reflect.getClassById("java.lang.Object").class;
|
||||||
|
function ToChar(char) {
|
||||||
|
return ModAPI.reflect.getClassById("java.lang.Character").staticMethods.valueOf.method(char[0].charCodeAt(0));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Define the recipe legend to map characters to items
|
||||||
|
var recipeLegend = {
|
||||||
|
"I": {
|
||||||
|
type: "item",
|
||||||
|
id: "iron_ingot" // Using dirt blocks
|
||||||
|
},
|
||||||
|
"C": {
|
||||||
|
type: "block",
|
||||||
|
id: "iron_block" // Using dirt blocks
|
||||||
|
},
|
||||||
|
"Q": {
|
||||||
|
type: "item",
|
||||||
|
id: "gunpowder" // Using dirt blocks
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
// Define the crafting grid pattern for the recipe
|
||||||
|
var recipePattern = [
|
||||||
|
"IIC",
|
||||||
|
" QI"
|
||||||
|
];
|
||||||
|
|
||||||
|
// Convert the recipe pattern and legend into the required format
|
||||||
|
var recipeInternal = [];
|
||||||
|
Object.keys(recipeLegend).forEach((key) => {
|
||||||
|
recipeInternal.push(ToChar(key));
|
||||||
|
var ingredient = (recipeLegend[key].type === "block" ? ModAPI.blocks : ModAPI.items)[recipeLegend[key].id].getRef();
|
||||||
|
recipeInternal.push(ingredient);
|
||||||
|
});
|
||||||
|
|
||||||
|
var recipeContents = recipePattern.flatMap(row => ModAPI.util.str(row));
|
||||||
|
var recipe = ModAPI.util.makeArray(ObjectClass, recipeContents.concat(recipeInternal));
|
||||||
|
|
||||||
|
var resultItem = ModAPI.reflect.getClassById("net.minecraft.item.ItemStack").constructors[4](gunItem, 1);
|
||||||
|
|
||||||
|
|
||||||
|
// Register the recipe with CraftingManager
|
||||||
|
var craftingManager = ModAPI.reflect.getClassById("net.minecraft.item.crafting.CraftingManager").staticMethods.getInstance.method();
|
||||||
|
ModAPI.hooks.methods.nmic_CraftingManager_addRecipe(craftingManager, resultItem, recipe);
|
||||||
|
}
|
||||||
|
|
||||||
|
function internal_reg() {
|
||||||
|
var pistol_item = (new nmi_ItemPistol()).$setUnlocalizedName(
|
||||||
|
ModAPI.util.str("pistol")
|
||||||
|
).$setMaxStackSize(1);
|
||||||
|
itemClass.staticMethods.registerItem.method(ModAPI.keygen.item("pistol"), ModAPI.util.str("pistol"), pistol_item);
|
||||||
|
ModAPI.items["pistol"] = pistol_item;
|
||||||
|
addGunRecipe(pistol_item);
|
||||||
|
return pistol_item;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ModAPI.items) {
|
||||||
|
return internal_reg();
|
||||||
|
} else {
|
||||||
|
ModAPI.addEventListener("bootstrap", internal_reg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ModAPI.dedicatedServer.appendCode(PistolItem);
|
||||||
|
var pistol_item = PistolItem();
|
||||||
|
|
||||||
|
ModAPI.addEventListener("lib:asyncsink", async () => {
|
||||||
|
ModAPI.addEventListener("lib:asyncsink:registeritems", (renderItem)=>{
|
||||||
|
renderItem.registerItem(pistol_item, ModAPI.util.str("pistol"));
|
||||||
|
});
|
||||||
|
AsyncSink.L10N.set("item.pistol.name", "Pistol");
|
||||||
|
AsyncSink.setFile("resourcepacks/AsyncSinkLib/assets/minecraft/models/item/pistol.json", JSON.stringify(
|
||||||
|
{
|
||||||
|
"parent": "builtin/generated",
|
||||||
|
"textures": {
|
||||||
|
"layer0": "items/pistol"
|
||||||
|
},
|
||||||
|
"display": {
|
||||||
|
"thirdperson": {
|
||||||
|
"rotation": [ 5, 80, -45 ],
|
||||||
|
"translation": [ 0, 1, -3 ],
|
||||||
|
"scale": [ 1.0, 1.0, 1.0 ]
|
||||||
|
},
|
||||||
|
"firstperson": {
|
||||||
|
"rotation": [ 0, -135, 25 ],
|
||||||
|
"translation": [ 0, 4, 2 ],
|
||||||
|
"scale": [ 1.8, 1.8, 1.8 ]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
));
|
||||||
|
AsyncSink.setFile("resourcepacks/AsyncSinkLib/assets/minecraft/textures/items/pistol.png", await (await fetch(
|
||||||
|
itemTexture
|
||||||
|
)).arrayBuffer());
|
||||||
|
});
|
||||||
|
})();
|
||||||
@@ -0,0 +1,40 @@
|
|||||||
|
//Metadata for the mod
|
||||||
|
ModAPI.meta.title("SimpleHats");
|
||||||
|
ModAPI.meta.credits("Made with ❤️ by ZXMushroom63");
|
||||||
|
ModAPI.meta.description("Use /hat to wear whatever you are holding!");
|
||||||
|
|
||||||
|
// Run the code on the server
|
||||||
|
ModAPI.dedicatedServer.appendCode(function () {
|
||||||
|
// Find the constructor for the held item change packet that has only one argument.
|
||||||
|
// This will be used to notify the client that their hotbar has been updated.
|
||||||
|
var makePacketItemChange = ModAPI.reflect.getClassByName("S09PacketHeldItemChange").constructors.find(x => x.length === 1);
|
||||||
|
|
||||||
|
// When the server is processing a command
|
||||||
|
ModAPI.addEventListener("processcommand", (event) => {
|
||||||
|
// If the command starts with /hat
|
||||||
|
if (event.command.toLowerCase().startsWith("/hat")) {
|
||||||
|
// Cancel if the sender isn't a player
|
||||||
|
if (!ModAPI.reflect.getClassById("net.minecraft.entity.player.EntityPlayerMP").instanceOf(event.sender.getRef())) { return };
|
||||||
|
|
||||||
|
// Otherwise, get the current held item
|
||||||
|
var heldItem = event.sender.inventory.getCurrentItem();
|
||||||
|
|
||||||
|
// Get the contents of the helmet slot
|
||||||
|
var armorItem = event.sender.inventory.armorInventory[3];
|
||||||
|
|
||||||
|
// Get the inventory index of the current held item
|
||||||
|
var hotbarIdx = event.sender.inventory.currentItem;
|
||||||
|
|
||||||
|
// Set the helmet slot to heldItem.getRef() (raw java object) if heldItem exists, otherwise set it to null
|
||||||
|
event.sender.inventory.armorInventory[3] = heldItem ? heldItem.getRef() : null;
|
||||||
|
|
||||||
|
// Set the hotbar slot to the previous value of the helmet slot
|
||||||
|
event.sender.inventory.mainInventory[hotbarIdx] = armorItem ? armorItem.getRef() : null;
|
||||||
|
|
||||||
|
// Use the sendPacket method to send a item change packet to the client.
|
||||||
|
event.sender.playerNetServerHandler.sendPacket(makePacketItemChange(hotbarIdx));
|
||||||
|
|
||||||
|
event.preventDefault = true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
File diff suppressed because one or more lines are too long
@@ -0,0 +1,168 @@
|
|||||||
|
// Library to make adding custom items with EaglerForgeInjector much easier.
|
||||||
|
(function LibItems() {
|
||||||
|
ModAPI.meta.title("LibCustomItems");
|
||||||
|
ModAPI.meta.credits("By ZXMushroom63");
|
||||||
|
ModAPI.meta.icon("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAQdJREFUOE9jZGBg+M9AAWAEGbBl2QmyjPCJsmAgaABbdybc8F+l01EswmsATONXLi4GYSkpBgZ+foY1O3cyuHWuhhuC1QBkjf///QMrFtHWZmD4+BHDEBQDUGzU1ITb8ubqVZyGoBjwsCONQYqXl0FYU5MBpAlsKxRgM+STUwoDhgG66upgZ4IAuiEooRcXx/DpCRuqAU97shg0jYzgfsVpSFwcg5mZGcOedRewGDBhAgPDokUohsBthmoE8U+dOoXdBfHHjoElUQxB03i9oABspnTJNFQXgARB3oAbwsAAdirMRmSNMFdhTQcwQ/BpxGsAzCUwRSCn4gJE5QV8uQxuAFlZEaoJAKrYrAHl38o6AAAAAElFTkSuQmCC");
|
||||||
|
ModAPI.meta.description("Library to make adding basic custom items easier.");
|
||||||
|
ModAPI.events.newEvent("lib:libcustomitems:loaded");
|
||||||
|
function libServerside() {
|
||||||
|
var packetblockchange = ModAPI.reflect.getClassByName("S23PacketBlockChange").constructors.find(x => { return x.length === 2 });
|
||||||
|
var sendPacket = ModAPI.reflect.getClassByName("NetHandlerPlayServer").methods.sendPacket.method;
|
||||||
|
globalThis.LCI_REGISTRY ||= [];
|
||||||
|
globalThis.LCI_RMBEVENTS ||= {};
|
||||||
|
globalThis.LCI_LMBEVENTS ||= {};
|
||||||
|
globalThis.LCI_RECIPEEVENTS ||= {};
|
||||||
|
globalThis.LCI_ITEMDB ||= {};
|
||||||
|
globalThis.LibCustomItems = {
|
||||||
|
makeItemStack: function makeItemStack(tag) {
|
||||||
|
return globalThis.LCI_ITEMDB[tag] || null;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
var useName = ModAPI.util.getMethodFromPackage("net.minecraft.network.NetHandlerPlayServer", "processPlayerBlockPlacement");
|
||||||
|
var oldUse = ModAPI.hooks.methods[useName];
|
||||||
|
ModAPI.hooks.methods[useName] = function ($this, packet) {
|
||||||
|
if ($this?.$playerEntity?.$inventory && $this.$playerEntity.$inventory.$getCurrentItem()) {
|
||||||
|
var item = $this.$playerEntity.$inventory.$getCurrentItem();
|
||||||
|
if (item.$stackTagCompound && item.$stackTagCompound.$hasKey(ModAPI.util.str("display"), 10)) {
|
||||||
|
var displayTag = item.$stackTagCompound.$getCompoundTag(ModAPI.util.str("display"));
|
||||||
|
if (displayTag.$hasKey(ModAPI.util.str("Lore"), 9)) {
|
||||||
|
var loreTag = displayTag.$getTag(ModAPI.util.str("Lore"));
|
||||||
|
if (loreTag.$tagCount() > 0 && globalThis.LCI_REGISTRY.includes(ModAPI.util.ustr(loreTag.$getStringTagAt(0)))) {
|
||||||
|
var cid = ModAPI.util.ustr(loreTag.$getStringTagAt(0));
|
||||||
|
if (!globalThis.LCI_RMBEVENTS[cid]) {
|
||||||
|
return oldUse.apply(this, [$this, packet]);
|
||||||
|
}
|
||||||
|
var positionTag = Object.keys(packet).filter(x => { return x.startsWith("$position") })[0];
|
||||||
|
if (packet[positionTag].$x === -1 && packet[positionTag].$y === -1 && packet[positionTag].$z === -1) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
var r = globalThis.LCI_RMBEVENTS[cid].call(globalThis,
|
||||||
|
new Proxy($this.$playerEntity, ModAPI.util.TeaVM_to_Recursive_BaseData_ProxyConf),
|
||||||
|
new Proxy($this.$serverController.$worldServerForDimension($this.$playerEntity.$dimension), ModAPI.util.TeaVM_to_Recursive_BaseData_ProxyConf),
|
||||||
|
new Proxy(item, ModAPI.util.TeaVM_to_Recursive_BaseData_ProxyConf),
|
||||||
|
new Proxy(packet[positionTag], ModAPI.util.TeaVM_to_Recursive_BaseData_ProxyConf));
|
||||||
|
if (!r) {
|
||||||
|
return oldUse.apply(this, [$this, packet]);
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return oldUse.apply(this, [$this, packet]);
|
||||||
|
}
|
||||||
|
var digName = ModAPI.util.getMethodFromPackage("net.minecraft.network.NetHandlerPlayServer", "processPlayerDigging");
|
||||||
|
var oldDig = ModAPI.hooks.methods[digName];
|
||||||
|
ModAPI.hooks.methods[digName] = function ($this, packet) {
|
||||||
|
if ($this?.$playerEntity?.$inventory && $this.$playerEntity.$inventory.$getCurrentItem()) {
|
||||||
|
var item = $this.$playerEntity.$inventory.$getCurrentItem();
|
||||||
|
if (item.$stackTagCompound && item.$stackTagCompound.$hasKey(ModAPI.util.str("display"), 10)) {
|
||||||
|
var displayTag = item.$stackTagCompound.$getCompoundTag(ModAPI.util.str("display"));
|
||||||
|
if (displayTag.$hasKey(ModAPI.util.str("Lore"), 9)) {
|
||||||
|
var loreTag = displayTag.$getTag(ModAPI.util.str("Lore"));
|
||||||
|
if (loreTag.$tagCount() > 0 && globalThis.LCI_REGISTRY.includes(ModAPI.util.ustr(loreTag.$getStringTagAt(0)))) {
|
||||||
|
var cid = ModAPI.util.ustr(loreTag.$getStringTagAt(0));
|
||||||
|
if (!globalThis.LCI_LMBEVENTS[cid]) {
|
||||||
|
return oldDig.apply(this, [$this, packet]);
|
||||||
|
}
|
||||||
|
var $status = ModAPI.util.getNearestProperty(packet, "$status");
|
||||||
|
var statusTag = Object.keys(packet[$status]).find(x => { return x.startsWith("$name") });
|
||||||
|
var positionTag = Object.keys(packet).filter(x => { return x.startsWith("$position") })[0];
|
||||||
|
var stat = ModAPI.util.unstr(packet[$status][statusTag]);
|
||||||
|
if (stat === "START_DESTROY_BLOCK") {
|
||||||
|
sendPacket($this, packetblockchange($this.$serverController.$worldServerForDimension($this.$playerEntity.$dimension), packet[positionTag]));
|
||||||
|
}
|
||||||
|
if (stat !== "START_DESTROY_BLOCK") {
|
||||||
|
if (stat === "STOP_DESTROY_BLOCK") {
|
||||||
|
sendPacket($this, packetblockchange($this.$serverController.$worldServerForDimension($this.$playerEntity.$dimension), packet[positionTag]));
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
var r = globalThis.LCI_LMBEVENTS[cid].call(globalThis,
|
||||||
|
new Proxy($this.$playerEntity, ModAPI.util.TeaVM_to_Recursive_BaseData_ProxyConf),
|
||||||
|
new Proxy($this.$serverController.$worldServerForDimension($this.$playerEntity.$dimension), ModAPI.util.TeaVM_to_Recursive_BaseData_ProxyConf),
|
||||||
|
new Proxy(item, ModAPI.util.TeaVM_to_Recursive_BaseData_ProxyConf),
|
||||||
|
new Proxy(packet[positionTag], ModAPI.util.TeaVM_to_Recursive_BaseData_ProxyConf));
|
||||||
|
if (!r) {
|
||||||
|
return oldDig.apply(this, [$this, packet]);
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return oldDig.apply(this, [$this, packet]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
function LCI_registerItem(data) {
|
||||||
|
globalThis.LCI_REGISTRY ||= [];
|
||||||
|
globalThis.LCI_RMBEVENTS ||= {};
|
||||||
|
globalThis.LCI_LMBEVENTS ||= {};
|
||||||
|
globalThis.LCI_RECIPEEVENTS ||= {};
|
||||||
|
globalThis.LCI_ITEMDB ||= {};
|
||||||
|
globalThis.LCI_REGISTRY.push(data.tag);
|
||||||
|
if (data.onRightClickGround) {
|
||||||
|
globalThis.LCI_RMBEVENTS[data.tag] = new Function("user", "world", "itemstack", "blockpos", data.onRightClickGround);
|
||||||
|
}
|
||||||
|
if (data.onLeftClickGround) {
|
||||||
|
globalThis.LCI_LMBEVENTS[data.tag] = new Function("user", "world", "itemstack", "blockpos", data.onLeftClickGround);
|
||||||
|
}
|
||||||
|
if (data.craftingExtra) {
|
||||||
|
globalThis.LCI_RECIPEEVENTS[data.tag] = new Function("itemstack", data.craftingExtra);
|
||||||
|
}
|
||||||
|
var ObjectClass = ModAPI.reflect.getClassById("java.lang.Object").class;
|
||||||
|
function ToChar(char) {
|
||||||
|
return ModAPI.reflect.getClassById("java.lang.Character").staticMethods.valueOf.method(char[0].charCodeAt(0));
|
||||||
|
}
|
||||||
|
ModAPI.dedicatedServer.appendCode(`(function () {
|
||||||
|
function handler() {
|
||||||
|
LCI_registerItem(${JSON.stringify(data)});
|
||||||
|
ModAPI.removeEventListener("tick", handler);
|
||||||
|
}
|
||||||
|
ModAPI.addEventListener("tick", handler);
|
||||||
|
})()`);
|
||||||
|
var recipeInternal = [];
|
||||||
|
Object.keys(data.recipeLegend).forEach((key) => {
|
||||||
|
recipeInternal.push(ToChar(key));
|
||||||
|
var ingredient = null;
|
||||||
|
var schema = data.recipeLegend[key];
|
||||||
|
if (schema.type === "block") {
|
||||||
|
ingredient = ModAPI.blocks[schema.id].getRef();
|
||||||
|
} else {
|
||||||
|
ingredient = ModAPI.items[schema.id].getRef();
|
||||||
|
}
|
||||||
|
recipeInternal.push(ingredient);
|
||||||
|
});
|
||||||
|
var recipeContents = data.recipe.flatMap(x => { return ModAPI.util.str(x) });
|
||||||
|
var recipe = ModAPI.util.makeArray(ObjectClass, recipeContents.concat(recipeInternal));
|
||||||
|
|
||||||
|
var testItem = ModAPI.reflect.getClassById("net.minecraft.item.ItemStack").constructors[4](ModAPI.items[data.base].getRef(), data.qty);
|
||||||
|
testItem.$stackTagCompound = ModAPI.reflect.getClassById("net.minecraft.nbt.NBTTagCompound").constructors[0]();
|
||||||
|
testItem.$stackTagCompound.$setTag(ModAPI.util.str("display"), ModAPI.reflect.getClassById("net.minecraft.nbt.NBTTagCompound").constructors[0]());
|
||||||
|
var displayTag = testItem.$stackTagCompound.$getCompoundTag(ModAPI.util.str("display"));
|
||||||
|
displayTag.$setString(ModAPI.util.str("Name"), ModAPI.util.str(data.name));
|
||||||
|
var lore = ModAPI.reflect.getClassById("net.minecraft.nbt.NBTTagList").constructors[0]();
|
||||||
|
lore.$appendTag(ModAPI.reflect.getClassById("net.minecraft.nbt.NBTTagString").constructors.filter(x => { return x.length === 1 })[0](ModAPI.util.str(data.tag)));
|
||||||
|
displayTag.$setTag(ModAPI.util.str("Lore"), lore);
|
||||||
|
if (globalThis.LCI_RECIPEEVENTS[data.tag]) {
|
||||||
|
globalThis.LCI_RECIPEEVENTS[data.tag](new Proxy(testItem, ModAPI.util.TeaVM_to_Recursive_BaseData_ProxyConf));
|
||||||
|
}
|
||||||
|
globalThis.LCI_ITEMDB[data.tag] = new Proxy(testItem, ModAPI.util.TeaVM_to_Recursive_BaseData_ProxyConf);
|
||||||
|
|
||||||
|
var craftingManager = ModAPI.reflect.getClassById("net.minecraft.item.crafting.CraftingManager").staticMethods.getInstance.method();
|
||||||
|
if((data.useRecipe !== false) || (data.useRecipe !== "false")) {
|
||||||
|
ModAPI.hooks.methods.nmic_CraftingManager_addRecipe(craftingManager, testItem, recipe);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ModAPI.dedicatedServer.appendCode(libServerside);
|
||||||
|
ModAPI.dedicatedServer.appendCode("globalThis.LCI_registerItem = " + LCI_registerItem.toString());
|
||||||
|
window.LibCustomItems = {};
|
||||||
|
LibCustomItems.registerItem = function register(data) {
|
||||||
|
LCI_registerItem(data);
|
||||||
|
}
|
||||||
|
LibCustomItems.makeItemStack = function makeItemStack(tag) {
|
||||||
|
return globalThis.LCI_ITEMDB[tag] || null;
|
||||||
|
}
|
||||||
|
ModAPI.events.callEvent("lib:libcustomitems:loaded", {});
|
||||||
|
})();
|
||||||
File diff suppressed because one or more lines are too long
@@ -0,0 +1,8 @@
|
|||||||
|
// Use ModAPI.util.getMethodFromPackage to find the internal name of the block destroy effect method
|
||||||
|
// and we replace it with our own function, that does nothing.
|
||||||
|
ModAPI.hooks.methods[
|
||||||
|
ModAPI.util.getMethodFromPackage(
|
||||||
|
"net.minecraft.client.particles.EffectRenderer",
|
||||||
|
"addBlockDestroyEffects"
|
||||||
|
)
|
||||||
|
] = () => {}
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
ModAPI.hooks.methods[ModAPI.util.getMethodFromPackage("net.minecraft.client.particle.EffectRenderer", "renderParticles")] = ()=>{};
|
||||||
|
ModAPI.hooks.methods[ModAPI.util.getMethodFromPackage("net.minecraft.client.particle.EffectRenderer", "addEffect")] = ()=>{};
|
||||||
|
ModAPI.hooks.methods[ModAPI.util.getMethodFromPackage("net.minecraft.client.particle.EffectRenderer", "addBlockDestroyEffects")] = ()=>{};
|
||||||
|
ModAPI.hooks.methods[ModAPI.util.getMethodFromPackage("net.minecraft.client.particle.EffectRenderer", "hasParticlesInAlphaLayer")] = ()=>{return 0};
|
||||||
File diff suppressed because one or more lines are too long
@@ -0,0 +1,284 @@
|
|||||||
|
(function servermod() {
|
||||||
|
ModAPI.meta.title("Server Manager");
|
||||||
|
ModAPI.meta.version("a0");
|
||||||
|
ModAPI.meta.description("_");
|
||||||
|
ModAPI.meta.credits("ZXMushroom63 & radmanplays");
|
||||||
|
|
||||||
|
|
||||||
|
const gui = document.createElement("div");
|
||||||
|
gui.innerText = "EFSERVER CONSOLE";
|
||||||
|
gui.style.background = "black";
|
||||||
|
gui.style.fontFamily = "sans-serif";
|
||||||
|
gui.style.zIndex = 254;
|
||||||
|
gui.style.position = "fixed";
|
||||||
|
gui.style.display = "none";
|
||||||
|
gui.style.height = "calc(100vh - 1rem - 4px)";
|
||||||
|
gui.style.overflowY = "scroll";
|
||||||
|
gui.style.color = "white";
|
||||||
|
gui.style.top = gui.style.left = gui.style.bottom = gui.style.right = 0;
|
||||||
|
document.documentElement.appendChild(gui);
|
||||||
|
|
||||||
|
var cmdbox = document.createElement("input");
|
||||||
|
cmdbox.style.position = "absolute";
|
||||||
|
cmdbox.style.left = "0";
|
||||||
|
cmdbox.style.bottom = "0";
|
||||||
|
cmdbox.style.right = "0";
|
||||||
|
cmdbox.style.position = "inline-block";
|
||||||
|
cmdbox.style.border = "0";
|
||||||
|
cmdbox.style.borderTop = "2px solid white";
|
||||||
|
cmdbox.style.background = "black";
|
||||||
|
cmdbox.style.zIndex = 255;
|
||||||
|
cmdbox.style.color = "white";
|
||||||
|
cmdbox.style.height = "1rem";
|
||||||
|
cmdbox.type = "text";
|
||||||
|
cmdbox.addEventListener("keydown", (e) => {
|
||||||
|
e.stopPropagation();
|
||||||
|
e.stopImmediatePropagation();
|
||||||
|
}, true);
|
||||||
|
cmdbox.addEventListener("keyup", (e) => {
|
||||||
|
e.stopPropagation();
|
||||||
|
e.stopImmediatePropagation();
|
||||||
|
if (e.key === "Enter") {
|
||||||
|
e.preventDefault();
|
||||||
|
toServer("chat", cmdbox.value);
|
||||||
|
cmdbox.value = "";
|
||||||
|
}
|
||||||
|
}, true);
|
||||||
|
document.documentElement.appendChild(cmdbox);
|
||||||
|
|
||||||
|
function worldUpdate() {
|
||||||
|
if (ModAPI.mc && ModAPI.mc.theWorld) {
|
||||||
|
ModAPI.hooks.methods.nmcs_GameSettings_saveOptions = ()=>{};
|
||||||
|
ModAPI.settings.limitFramerate = 1;
|
||||||
|
ModAPI.settings.enableVsync = 0;
|
||||||
|
showgui();
|
||||||
|
openSharedWorld()
|
||||||
|
} else {
|
||||||
|
hidegui();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
setInterval(() => {
|
||||||
|
worldUpdate();
|
||||||
|
}, 100);
|
||||||
|
|
||||||
|
function showgui() {
|
||||||
|
gui.style.opacity = "1";
|
||||||
|
gui.style.display = "block";
|
||||||
|
cmdbox.style.opacity = "1";
|
||||||
|
cmdbox.style.display = "block";
|
||||||
|
}
|
||||||
|
function hidegui() {
|
||||||
|
gui.style.opacity = "0";
|
||||||
|
gui.style.display = "none";
|
||||||
|
cmdbox.style.opacity = "0";
|
||||||
|
cmdbox.style.display = "none";
|
||||||
|
}
|
||||||
|
|
||||||
|
function EFB2__defineExecCmdAsGlobal() {
|
||||||
|
var getServer = ModAPI.reflect.getClassById("net.minecraft.server.MinecraftServer").staticMethods.getServer.method;
|
||||||
|
globalThis.efb2__executeCommandAs = function efb2__executeCommandAs($commandsender, command, feedback) {
|
||||||
|
var server = getServer();
|
||||||
|
if (!server) { return };
|
||||||
|
var commandManager = server.$commandManager;
|
||||||
|
|
||||||
|
//lie a bit
|
||||||
|
var x = $commandsender.$canCommandSenderUseCommand;
|
||||||
|
$commandsender.$canCommandSenderUseCommand = () => 1;
|
||||||
|
|
||||||
|
var y = $commandsender.$sendCommandFeedback;
|
||||||
|
$commandsender.$sendCommandFeedback = feedback ? () => 1 : () => 0;
|
||||||
|
|
||||||
|
try {
|
||||||
|
commandManager.$executeCommand($commandsender, ModAPI.util.str(command));
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error);
|
||||||
|
}
|
||||||
|
|
||||||
|
$commandsender.$canCommandSenderUseCommand = x;
|
||||||
|
$commandsender.$sendCommandFeedback = y;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ModAPI.dedicatedServer.appendCode(EFB2__defineExecCmdAsGlobal);
|
||||||
|
|
||||||
|
ModAPI.hooks.methods.nmc_LoadingScreenRenderer_eaglerShow = ()=>{};
|
||||||
|
var opening = false;
|
||||||
|
function openSharedWorld() {
|
||||||
|
var platform = ModAPI.reflect.getClassById("net.lax1dude.eaglercraft.v1_8.internal.PlatformWebRTC");
|
||||||
|
if (!opening && ModAPI.mc.theWorld && !ModAPI.hooks.methods.nlevsl_LANServerController_isLANOpen()) {
|
||||||
|
platform.staticVariables.rtcLANServer = ModAPI.reflect.getClassById("net.lax1dude.eaglercraft.v1_8.internal.PlatformWebRTC$LANServer").constructors[0]();
|
||||||
|
var worldName = ModAPI.util.unstr(ModAPI.mc.thePlayer.getName().getRef()) + "'s World";
|
||||||
|
opening = true;
|
||||||
|
ModAPI.promisify(ModAPI.hooks.methods.nlevsl_LANServerController_shareToLAN)({
|
||||||
|
$accept: (status)=>{
|
||||||
|
gui.innerText += "\n" + ModAPI.util.ustr(status);
|
||||||
|
}
|
||||||
|
}, ModAPI.util.str(worldName), 0).then(code => {
|
||||||
|
opening = false;
|
||||||
|
if (code != null) {
|
||||||
|
ModAPI.hooks.methods.nlevs_SingleplayerServerController_configureLAN(ModAPI.mc.playerController.currentGameType.getRef(), 0);
|
||||||
|
var msg = "code: " + ModAPI.util.ustr(code) + " relay: " + ModAPI.util.ustr(ModAPI.hooks.methods.nlevsl_LANServerController_getCurrentURI());
|
||||||
|
alert(msg);
|
||||||
|
gui.innerText += "\n" + msg;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
NETWORKING OPCODES
|
||||||
|
chat - bidirectional, send chat to server/client
|
||||||
|
*/
|
||||||
|
|
||||||
|
function toServer(opcode, data) {
|
||||||
|
client_comms_channel.postMessage({
|
||||||
|
opcode: opcode,
|
||||||
|
audience: "server",
|
||||||
|
data: data,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
var token = crypto.randomUUID();
|
||||||
|
const clientMessageHandlers = {
|
||||||
|
chat: function (data) {
|
||||||
|
if (gui.scrollHeight > (innerHeight * 5)) {
|
||||||
|
gui.innerText = "Console cleared. Logs were over 5 pages long.";
|
||||||
|
}
|
||||||
|
gui.innerText += "\n" + data.replaceAll("§r", "");
|
||||||
|
gui.scrollTop = gui.scrollHeight;
|
||||||
|
},
|
||||||
|
};
|
||||||
|
var client_comms_channel = new BroadcastChannel("efserv:" + token);
|
||||||
|
client_comms_channel.addEventListener("message", (ev) => {
|
||||||
|
if (ev.data.audience !== "client") {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (clientMessageHandlers[ev.data.opcode]) {
|
||||||
|
clientMessageHandlers[ev.data.opcode](ev.data.data);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
ModAPI.dedicatedServer.appendCode(
|
||||||
|
`globalThis.efhost_security_token = "${token}";`
|
||||||
|
);
|
||||||
|
ModAPI.dedicatedServer.appendCode(function () {
|
||||||
|
var comms = new BroadcastChannel(
|
||||||
|
"efserv:" + globalThis.efhost_security_token
|
||||||
|
);
|
||||||
|
|
||||||
|
function toClient(opcode, data) {
|
||||||
|
comms.postMessage({
|
||||||
|
opcode: opcode,
|
||||||
|
audience: "client",
|
||||||
|
data: data,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function getHostPlayer() {
|
||||||
|
var host = null;
|
||||||
|
ModAPI.server.getRef().$worldServers.data.forEach((world) => {
|
||||||
|
host ||= world.$playerEntities.$array1.data.find((player) => {
|
||||||
|
if (!player) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var nameKey = ModAPI.util.getNearestProperty(
|
||||||
|
player.$gameProfile,
|
||||||
|
"$name"
|
||||||
|
);
|
||||||
|
return ModAPI.util.ustr(player.$gameProfile[nameKey]) === "HOST";
|
||||||
|
});
|
||||||
|
});
|
||||||
|
return host;
|
||||||
|
}
|
||||||
|
|
||||||
|
const messageHandlers = {
|
||||||
|
chat: function (data) {
|
||||||
|
var host = getHostPlayer();
|
||||||
|
if (!host) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
host.$addChatMessage = (comp)=>{toClient("chat", ModAPI.util.ustr(comp.$getUnformattedText()))};
|
||||||
|
efb2__executeCommandAs(getHostPlayer(), data, true);
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
comms.addEventListener("message", (ev) => {
|
||||||
|
if (ev.data.audience !== "server") {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (messageHandlers[ev.data.opcode]) {
|
||||||
|
messageHandlers[ev.data.opcode](ev.data.data);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
var oldLog = ModAPI.hooks.methods.nlevl_Logger_log;
|
||||||
|
ModAPI.hooks.methods.nlevl_Logger_log = function (...args) {
|
||||||
|
toClient("chat", ModAPI.util.ustr(args[2]));
|
||||||
|
return oldLog.apply(this, args);
|
||||||
|
};
|
||||||
|
|
||||||
|
ModAPI.addEventListener("tick", ()=>{
|
||||||
|
var host = ModAPI.util.wrap(getHostPlayer());
|
||||||
|
if (!host) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
host.posY = -10;
|
||||||
|
host.posX = 0;
|
||||||
|
host.posZ = 0;
|
||||||
|
host.capabilities.disableDamage = 1;
|
||||||
|
host.capabilities.isCreativeMode = 1;
|
||||||
|
host.capabilities.isFlying = 1;
|
||||||
|
host.motionY = 0;
|
||||||
|
host.motionX = 0;
|
||||||
|
host.motionZ = 0;
|
||||||
|
host.isDead = 0;
|
||||||
|
host.setHealth(20);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function renameButton(array, originalName, newName) {
|
||||||
|
array.find(
|
||||||
|
(x) => ModAPI.util.ustr(x.displayString.getRef()) === originalName
|
||||||
|
).displayString = ModAPI.util.str(newName);
|
||||||
|
}
|
||||||
|
|
||||||
|
const mainmenuinit = ModAPI.hooks.methods.nmcg_GuiMainMenu_initGui;
|
||||||
|
ModAPI.hooks.methods.nmcg_GuiMainMenu_initGui = function (...args) {
|
||||||
|
var result = mainmenuinit.apply(this, args);
|
||||||
|
var wrappedGuiObject = ModAPI.util.wrap(args[0], args[0], false, false);
|
||||||
|
wrappedGuiObject.splashText = ModAPI.util.str("Server Hosting Mode");
|
||||||
|
var btnarray = wrappedGuiObject.buttonList.array1;
|
||||||
|
renameButton(btnarray, "Singleplayer", "Host Server");
|
||||||
|
|
||||||
|
return result;
|
||||||
|
};
|
||||||
|
|
||||||
|
const GuiSelectWorldinit = ModAPI.hooks.methods.nmcg_GuiSelectWorld_initGui;
|
||||||
|
ModAPI.hooks.methods.nmcg_GuiSelectWorld_initGui = function (...args) {
|
||||||
|
var result = GuiSelectWorldinit.apply(this, args);
|
||||||
|
var wrappedGuiObject = ModAPI.util.wrap(args[0], args[0], false, false);
|
||||||
|
var btnarray = wrappedGuiObject.buttonList.array1.data;
|
||||||
|
//renameButton(btnarray, "Create", "Create Server");
|
||||||
|
|
||||||
|
return result;
|
||||||
|
};
|
||||||
|
|
||||||
|
const mainmenuactions = ModAPI.hooks.methods.nmcg_GuiMainMenu_actionPerformed;
|
||||||
|
ModAPI.hooks.methods.nmcg_GuiMainMenu_actionPerformed = function (...args) {
|
||||||
|
ModAPI.hooks.methods.nlevp_EaglerProfile_setName(ModAPI.util.str("HOST"));
|
||||||
|
var idKey = ModAPI.util.getNearestProperty(args[1], "$id");
|
||||||
|
var guiButtonid = args[1][idKey];
|
||||||
|
var blockedIds = [2]; // put the blocked/disabled button ids in there
|
||||||
|
if (blockedIds.includes(guiButtonid)) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return mainmenuactions.apply(this, args);
|
||||||
|
};
|
||||||
|
|
||||||
|
// disable rendering
|
||||||
|
ModAPI.hooks.methods.nmcr_EntityRenderer_renderWorld = () => { };
|
||||||
|
})();
|
||||||
@@ -0,0 +1,47 @@
|
|||||||
|
(function Sliders() {
|
||||||
|
ModAPI.meta.title("Sliders");
|
||||||
|
ModAPI.meta.description("Remove the clamping on sliders.");
|
||||||
|
ModAPI.meta.credits("By ZXMushroom63");
|
||||||
|
|
||||||
|
const MathHelper_clamp_float = ModAPI.util.getMethodFromPackage("net.minecraft.util.MathHelper", "clamp_float");
|
||||||
|
const GuiOptionSlider_mouseDragged = ModAPI.util.getMethodFromPackage("net.minecraft.client.gui.GuiOptionSlider", "mouseDragged");
|
||||||
|
const GuiOptionSlider_mousePressed = ModAPI.util.getMethodFromPackage("net.minecraft.client.gui.GuiOptionSlider", "mousePressed");
|
||||||
|
const GameSetting$Options_normalizeValue = ModAPI.util.getMethodFromPackage("net.minecraft.client.settings.GameSettings$Options", "normalizeValue");
|
||||||
|
const GameSetting$Options_snapToStepClamp = ModAPI.util.getMethodFromPackage("net.minecraft.client.settings.GameSettings$Options", "snapToStepClamp");
|
||||||
|
|
||||||
|
const GuiOptionSlider_mouseDragged_fn = ModAPI.hooks.methods[GuiOptionSlider_mouseDragged];
|
||||||
|
const GuiOptionSlider_mousePressed_fn = ModAPI.hooks.methods[GuiOptionSlider_mousePressed];
|
||||||
|
const GameSetting$Options_normalizeValue_fn = ModAPI.hooks.methods[GameSetting$Options_normalizeValue];
|
||||||
|
const GameSetting$Options_snapToStepClamp_fn = ModAPI.hooks.methods[GameSetting$Options_snapToStepClamp];
|
||||||
|
const MathHelper_clamp_float_fn = ModAPI.hooks.methods[MathHelper_clamp_float];
|
||||||
|
|
||||||
|
const fakeClampMethod = (x)=>x;
|
||||||
|
|
||||||
|
ModAPI.hooks.methods[GuiOptionSlider_mouseDragged] = function (...args) {
|
||||||
|
ModAPI.hooks.methods[MathHelper_clamp_float] = fakeClampMethod;
|
||||||
|
var ret = GuiOptionSlider_mouseDragged_fn.apply(this, args);
|
||||||
|
ModAPI.hooks.methods[MathHelper_clamp_float] = MathHelper_clamp_float_fn;
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
ModAPI.hooks.methods[GuiOptionSlider_mousePressed] = function (...args) {
|
||||||
|
ModAPI.hooks.methods[MathHelper_clamp_float] = fakeClampMethod;
|
||||||
|
var ret = GuiOptionSlider_mousePressed_fn.apply(this, args);
|
||||||
|
ModAPI.hooks.methods[MathHelper_clamp_float] = MathHelper_clamp_float_fn;
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
ModAPI.hooks.methods[GameSetting$Options_normalizeValue] = function (...args) {
|
||||||
|
ModAPI.hooks.methods[MathHelper_clamp_float] = fakeClampMethod;
|
||||||
|
var ret = GameSetting$Options_normalizeValue_fn.apply(this, args);
|
||||||
|
ModAPI.hooks.methods[MathHelper_clamp_float] = MathHelper_clamp_float_fn;
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ModAPI.hooks.methods[GameSetting$Options_snapToStepClamp] = function (...args) {
|
||||||
|
// ModAPI.hooks.methods[MathHelper_clamp_float] = fakeClampMethod;
|
||||||
|
// var ret = GameSetting$Options_snapToStepClamp_fn.apply(this, args);
|
||||||
|
// ModAPI.hooks.methods[MathHelper_clamp_float] = MathHelper_clamp_float_fn;
|
||||||
|
// return ret;
|
||||||
|
// }
|
||||||
|
})();
|
||||||
File diff suppressed because one or more lines are too long
@@ -0,0 +1,15 @@
|
|||||||
|
(() => {
|
||||||
|
PluginAPI.dedicatedServer.appendCode(function () {
|
||||||
|
PluginAPI.addEventListener("processcommand", (event) => {
|
||||||
|
if (event.command.toLowerCase().startsWith("/talkback")) {
|
||||||
|
var message = event.command.substring("/talkback ".length);
|
||||||
|
if (
|
||||||
|
ModAPI.reflect.getClassById("net.minecraft.entity.player.EntityPlayerMP").instanceOf(event.sender.getRef())
|
||||||
|
) {
|
||||||
|
event.sender.addChatMessage(ModAPI.reflect.getClassById("net.minecraft.util.ChatComponentText").constructors[0](ModAPI.util.str(message.toUpperCase())));
|
||||||
|
}
|
||||||
|
event.preventDefault = true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
})();
|
||||||
@@ -0,0 +1,71 @@
|
|||||||
|
(() => {
|
||||||
|
ModAPI.meta.title("Timescale Command");
|
||||||
|
ModAPI.meta.description("/timescale 0.5 to halve the speed of time");
|
||||||
|
ModAPI.meta.credits("By ZXMushroom63");
|
||||||
|
globalThis.timeScale = 1n;
|
||||||
|
globalThis.timeScaleDividing = false;
|
||||||
|
PluginAPI.addEventListener("sendchatmessage", (event) => {
|
||||||
|
if (event.message.toLowerCase().startsWith("/timescale")) {
|
||||||
|
var speed = parseFloat(event.message.split(" ")[1]);
|
||||||
|
if (!speed) {
|
||||||
|
globalThis.timeScale = 1n;
|
||||||
|
globalThis.timeScaleDividing = false;
|
||||||
|
PluginAPI.mc.timer.timerSpeed = 1;
|
||||||
|
} else {
|
||||||
|
if (speed < 1) {
|
||||||
|
globalThis.timeScaleDividing = true;
|
||||||
|
globalThis.timeScale = BigInt(Math.round(1 / speed));
|
||||||
|
} else {
|
||||||
|
globalThis.timeScaleDividing = false;
|
||||||
|
globalThis.timeScale = BigInt(Math.round(speed));
|
||||||
|
}
|
||||||
|
PluginAPI.mc.timer.timerSpeed = speed;
|
||||||
|
}
|
||||||
|
PluginAPI.mc.systemTime = PluginAPI.hooks.methods[ModAPI.util.getMethodFromPackage("net.minecraft.client.Minecraft", "getSystemTime")]();
|
||||||
|
PluginAPI.mc.debugUpdateTime = PluginAPI.hooks.methods[ModAPI.util.getMethodFromPackage("net.minecraft.client.Minecraft", "getSystemTime")]() - 1000n;
|
||||||
|
PluginAPI.mc.timer.lastSyncSysClock = PluginAPI.hooks.methods[ModAPI.util.getMethodFromPackage("net.minecraft.client.Minecraft", "getSystemTime")]();
|
||||||
|
PluginAPI.displayToChat("[Timescale] Set world timescale to " + speed.toFixed(2) + ".");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
PluginAPI.dedicatedServer.appendCode(function () {
|
||||||
|
globalThis.timeScale = 1n;
|
||||||
|
globalThis.timeScaleDividing = false;
|
||||||
|
PluginAPI.addEventListener("processcommand", (event) => {
|
||||||
|
if (event.command.toLowerCase().startsWith("/timescale")) {
|
||||||
|
var speed = parseFloat(event.command.split(" ")[1]);
|
||||||
|
if (!speed) {
|
||||||
|
globalThis.timeScale = 1n;
|
||||||
|
globalThis.timeScaleDividing = false;
|
||||||
|
} else {
|
||||||
|
if (speed < 1) {
|
||||||
|
globalThis.timeScaleDividing = true;
|
||||||
|
globalThis.timeScale = BigInt(Math.round(1 / speed));
|
||||||
|
} else {
|
||||||
|
globalThis.timeScaleDividing = false;
|
||||||
|
globalThis.timeScale = BigInt(Math.round(speed));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (ModAPI.server) {
|
||||||
|
ModAPI.server.currentTime = PluginAPI.hooks.methods[ModAPI.util.getMethodFromPackage("net.minecraft.server.MinecraftServer", "getCurrentTimeMillis")]();
|
||||||
|
}
|
||||||
|
event.preventDefault = true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
const original_getCurrentTime = ModAPI.hooks.methods[ModAPI.util.getMethodFromPackage("net.minecraft.server.MinecraftServer", "getCurrentTimeMillis")];
|
||||||
|
PluginAPI.hooks.methods[ModAPI.util.getMethodFromPackage("net.minecraft.server.MinecraftServer", "getCurrentTimeMillis")] = function () {
|
||||||
|
if (globalThis.timeScaleDividing) {
|
||||||
|
return original_getCurrentTime() / globalThis.timeScale;
|
||||||
|
} else {
|
||||||
|
return original_getCurrentTime() * globalThis.timeScale;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
});
|
||||||
|
const original_getSystemTime = ModAPI.hooks.methods[ModAPI.util.getMethodFromPackage("net.minecraft.client.Minecraft", "getSystemTime")];
|
||||||
|
PluginAPI.hooks.methods[ModAPI.util.getMethodFromPackage("net.minecraft.client.Minecraft", "getSystemTime")] = function () {
|
||||||
|
if (globalThis.timeScaleDividing) {
|
||||||
|
return original_getSystemTime() / globalThis.timeScale;
|
||||||
|
} else {
|
||||||
|
return original_getSystemTime() * globalThis.timeScale;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
})();
|
||||||
@@ -0,0 +1,126 @@
|
|||||||
|
(()=>{
|
||||||
|
const unluckyBlockTexture = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAOhJREFUOE9jnJn2/z8DGvj4koHh9UOIoKg8AwO/OLoKBJ8RZED6LEbcKvDIzEz7z8DY5f//f9lGTANCGTAcxrCaAVUd2IBSg///uy+gSqBr/sJwF+6O7QwqcHaXPxYXgDTDNCArtmXYBtZ4mMELbkCpwX8GjDDwZLjD8IXhFopCkA5s4mAXEBOIMC+BXIbsKnAYEDIAOTywBiI+A0DO5mFQBvsZXTNIjKALQAHHw6CG4mzkZIE3HYAUEjIAHIjY0gGxyRIcjfgMgIUBNv+DLAEbgCspgxTAYgCXAUSnA1xegscCPj8TytoAA5eEOx9BbCgAAAAASUVORK5CYII=";
|
||||||
|
ModAPI.meta.title("Unlucky Blocks");
|
||||||
|
ModAPI.meta.version("v1.0");
|
||||||
|
ModAPI.meta.description("These purple cubes ruined my life. Requires AsyncSink.");
|
||||||
|
ModAPI.meta.credits("By ZXMushroom63");
|
||||||
|
ModAPI.meta.icon(unluckyBlockTexture);
|
||||||
|
|
||||||
|
function UnluckyBlocks() {
|
||||||
|
function fixupBlockIds() {
|
||||||
|
var blockRegistry = ModAPI.util.wrap(ModAPI.reflect.getClassById("net.minecraft.block.Block").staticVariables.blockRegistry).getCorrective();
|
||||||
|
var BLOCK_STATE_IDS = ModAPI.util.wrap(ModAPI.reflect.getClassById("net.minecraft.block.Block").staticVariables.BLOCK_STATE_IDS).getCorrective();
|
||||||
|
blockRegistry.registryObjects.hashTableKToV.forEach(entry => {
|
||||||
|
if (entry) {
|
||||||
|
var block = entry.value;
|
||||||
|
var validStates = block.getBlockState().getValidStates();
|
||||||
|
var stateArray = validStates.array || [validStates.element];
|
||||||
|
stateArray.forEach(iblockstate => {
|
||||||
|
var i = blockRegistry.getIDForObject(block.getRef()) << 4 | block.getMetaFromState(iblockstate.getRef());
|
||||||
|
BLOCK_STATE_IDS.put(iblockstate.getRef(), i);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
var itemClass = ModAPI.reflect.getClassById("net.minecraft.item.Item");
|
||||||
|
var blockClass = ModAPI.reflect.getClassById("net.minecraft.block.Block");
|
||||||
|
var blockSuper = ModAPI.reflect.getSuper(blockClass, (x) => x.length === 2); //Get super function from the block class with a target length of two. ($this (mandatory), material (optional))
|
||||||
|
var creativeBlockTab = ModAPI.reflect.getClassById("net.minecraft.creativetab.CreativeTabs").staticVariables.tabBlock;
|
||||||
|
var breakBlockMethod = blockClass.methods.breakBlock.method;
|
||||||
|
function nmb_BlockUnlucky() {
|
||||||
|
blockSuper(this, ModAPI.materials.rock.getRef()); //Use super function to get block properties on this class.
|
||||||
|
this.$defaultBlockState = this.$blockState.$getBaseState();
|
||||||
|
this.$setCreativeTab(creativeBlockTab);
|
||||||
|
}
|
||||||
|
ModAPI.reflect.prototypeStack(blockClass, nmb_BlockUnlucky);
|
||||||
|
nmb_BlockUnlucky.prototype.$breakBlock = function ($world, $blockpos, $blockstate) {
|
||||||
|
var world = ModAPI.util.wrap($world);
|
||||||
|
var blockpos = ModAPI.util.wrap($blockpos);
|
||||||
|
if (Math.random() < 1) { //was gonna add random events but couldn't be bothered. Enjoy exploding!
|
||||||
|
world.newExplosion(null, blockpos.getX() + 0.5, blockpos.getY() + 0.5,
|
||||||
|
blockpos.getZ() + 0.5, 9, 1, 1);
|
||||||
|
}
|
||||||
|
return breakBlockMethod(this, $world, $blockpos, $blockstate);
|
||||||
|
}
|
||||||
|
|
||||||
|
function internal_reg() {
|
||||||
|
var block_of_unluckiness = (new nmb_BlockUnlucky()).$setHardness(0.0).$setStepSound(blockClass.staticVariables.soundTypePiston).$setUnlocalizedName(
|
||||||
|
ModAPI.util.str("unluckiness")
|
||||||
|
);
|
||||||
|
blockClass.staticMethods.registerBlock0.method(
|
||||||
|
ModAPI.keygen.block("unluckiness"),
|
||||||
|
ModAPI.util.str("unluckiness"),
|
||||||
|
block_of_unluckiness
|
||||||
|
);
|
||||||
|
itemClass.staticMethods.registerItemBlock0.method(block_of_unluckiness);
|
||||||
|
fixupBlockIds();
|
||||||
|
ModAPI.blocks["unluckiness"] = block_of_unluckiness;
|
||||||
|
|
||||||
|
return block_of_unluckiness;
|
||||||
|
}
|
||||||
|
|
||||||
|
const WorldGenMineable = ModAPI.reflect.getClassById("net.minecraft.world.gen.feature.WorldGenMinable").constructors.find(x=>x.length===2);
|
||||||
|
|
||||||
|
const BiomeDecorator_decorate = ModAPI.util.getMethodFromPackage("net.minecraft.world.biome.BiomeDecorator", "decorate");
|
||||||
|
const oldDecorate = ModAPI.hooks.methods[BiomeDecorator_decorate];
|
||||||
|
ModAPI.hooks.methods[BiomeDecorator_decorate] = function ($this, $world, $random, $biomeGenBase, $blockpos) {
|
||||||
|
if (!$this.$currentWorld) {
|
||||||
|
$this.$unluckyBlockGen = WorldGenMineable(ModAPI.blocks.unluckiness.getDefaultState().getRef(), 4);
|
||||||
|
}
|
||||||
|
return oldDecorate.apply(this, [$this, $world, $random, $biomeGenBase, $blockpos]);
|
||||||
|
}
|
||||||
|
|
||||||
|
const BiomeDecorator_generateOres = ModAPI.util.getMethodFromPackage("net.minecraft.world.biome.BiomeDecorator", "generateOres");
|
||||||
|
const oldGenerateOres = ModAPI.hooks.methods[BiomeDecorator_generateOres];
|
||||||
|
ModAPI.hooks.methods[BiomeDecorator_generateOres] = function ($this) {
|
||||||
|
$this.$genStandardOre1(105, $this.$unluckyBlockGen || null, 0, 256);
|
||||||
|
return oldGenerateOres.apply(this, [$this]);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ModAPI.materials) {
|
||||||
|
return internal_reg();
|
||||||
|
} else {
|
||||||
|
ModAPI.addEventListener("bootstrap", internal_reg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ModAPI.dedicatedServer.appendCode(UnluckyBlocks);
|
||||||
|
var block_of_unluckiness = UnluckyBlocks();
|
||||||
|
ModAPI.addEventListener("lib:asyncsink", async () => {
|
||||||
|
ModAPI.addEventListener("lib:asyncsink:registeritems", (renderItem)=>{
|
||||||
|
renderItem.registerBlock(block_of_unluckiness, ModAPI.util.str("unluckiness"));
|
||||||
|
});
|
||||||
|
AsyncSink.L10N.set("tile.unluckiness.name", "Unlucky Block");
|
||||||
|
AsyncSink.setFile("resourcepacks/AsyncSinkLib/assets/minecraft/models/block/unluckiness.json", JSON.stringify(
|
||||||
|
{
|
||||||
|
"parent": "block/cube_all",
|
||||||
|
"textures": {
|
||||||
|
"all": "blocks/unluckiness"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
));
|
||||||
|
AsyncSink.setFile("resourcepacks/AsyncSinkLib/assets/minecraft/models/item/unluckiness.json", JSON.stringify(
|
||||||
|
{
|
||||||
|
"parent": "block/unluckiness",
|
||||||
|
"display": {
|
||||||
|
"thirdperson": {
|
||||||
|
"rotation": [10, -45, 170],
|
||||||
|
"translation": [0, 1.5, -2.75],
|
||||||
|
"scale": [0.375, 0.375, 0.375]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
));
|
||||||
|
AsyncSink.setFile("resourcepacks/AsyncSinkLib/assets/minecraft/blockstates/unluckiness.json", JSON.stringify(
|
||||||
|
{
|
||||||
|
"variants": {
|
||||||
|
"normal": [
|
||||||
|
{ "model": "unluckiness" },
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
));
|
||||||
|
AsyncSink.setFile("resourcepacks/AsyncSinkLib/assets/minecraft/textures/blocks/unluckiness.png", await (await fetch(
|
||||||
|
unluckyBlockTexture
|
||||||
|
)).arrayBuffer());
|
||||||
|
});
|
||||||
|
})();
|
||||||
@@ -0,0 +1,72 @@
|
|||||||
|
// This is an example mod on how to register an item.
|
||||||
|
(()=>{
|
||||||
|
const itemTexture = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAKZJREFUOE9j/P//PxMDBIBoEP6HREOl4PLIciA2AyPIgMcM//7KgvWSDJjBBpx9/+YvJzc3Sbq12DhB6sEGsJ19/+YnmQawYhigzc7FcPXnN4KugbqAHWQAy9n3b34T4wJkw6EGYLqAoNVQBWS5ANlwZBfAvUCs/0EGkW0AzBKqGoCSDgh5A80F2KMRpAgfAKUT6kcjsfEPUycmKMQgy8AETkgUZWcAS3CPIf4oSPsAAAAASUVORK5CYII=";
|
||||||
|
//this texture is REALLY bad, so the item appears 2d in game. (it uses partially transparent pixels around the edges in some spots ;-;)
|
||||||
|
ModAPI.meta.title("Adding items demo.");
|
||||||
|
ModAPI.meta.version("v1.0");
|
||||||
|
ModAPI.meta.icon(itemTexture);
|
||||||
|
ModAPI.meta.description("Requires AsyncSink.");
|
||||||
|
|
||||||
|
function ExampleItem() {
|
||||||
|
var creativeMiscTab = ModAPI.reflect.getClassById("net.minecraft.creativetab.CreativeTabs").staticVariables.tabMisc;
|
||||||
|
var itemClass = ModAPI.reflect.getClassById("net.minecraft.item.Item");
|
||||||
|
var itemSuper = ModAPI.reflect.getSuper(itemClass, (x) => x.length === 1);
|
||||||
|
function nmi_ItemExample() {
|
||||||
|
itemSuper(this); //Use super function to get block properties on this class.
|
||||||
|
this.$setCreativeTab(creativeMiscTab);
|
||||||
|
}
|
||||||
|
ModAPI.reflect.prototypeStack(itemClass, nmi_ItemExample);
|
||||||
|
nmi_ItemExample.prototype.$onItemRightClick = function ($itemstack, $world, $player) { //example of how to override a method
|
||||||
|
return $itemstack;
|
||||||
|
}
|
||||||
|
|
||||||
|
function internal_reg() {
|
||||||
|
var example_item = (new nmi_ItemExample()).$setUnlocalizedName(
|
||||||
|
ModAPI.util.str("exampleitem")
|
||||||
|
);
|
||||||
|
itemClass.staticMethods.registerItem.method(ModAPI.keygen.item("exampleitem"), ModAPI.util.str("exampleitem"), example_item);
|
||||||
|
ModAPI.items["exampleitem"] = example_item;
|
||||||
|
|
||||||
|
return example_item;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ModAPI.items) {
|
||||||
|
return internal_reg();
|
||||||
|
} else {
|
||||||
|
ModAPI.addEventListener("bootstrap", internal_reg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ModAPI.dedicatedServer.appendCode(ExampleItem);
|
||||||
|
var example_item = ExampleItem();
|
||||||
|
|
||||||
|
ModAPI.addEventListener("lib:asyncsink", async () => {
|
||||||
|
ModAPI.addEventListener("lib:asyncsink:registeritems", (renderItem)=>{
|
||||||
|
renderItem.registerItem(example_item, ModAPI.util.str("exampleitem"));
|
||||||
|
});
|
||||||
|
AsyncSink.L10N.set("item.exampleitem.name", "Example Item");
|
||||||
|
AsyncSink.setFile("resourcepacks/AsyncSinkLib/assets/minecraft/models/item/exampleitem.json", JSON.stringify(
|
||||||
|
{
|
||||||
|
"parent": "builtin/generated",
|
||||||
|
"textures": {
|
||||||
|
"layer0": "items/exampleitem"
|
||||||
|
},
|
||||||
|
"display": {
|
||||||
|
"thirdperson": {
|
||||||
|
"rotation": [ -90, 0, 0 ],
|
||||||
|
"translation": [ 0, 1, -3 ],
|
||||||
|
"scale": [ 0.55, 0.55, 0.55 ]
|
||||||
|
},
|
||||||
|
"firstperson": {
|
||||||
|
"rotation": [ 0, -135, 25 ],
|
||||||
|
"translation": [ 0, 4, 2 ],
|
||||||
|
"scale": [ 1.7, 1.7, 1.7 ]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
));
|
||||||
|
AsyncSink.setFile("resourcepacks/AsyncSinkLib/assets/minecraft/textures/items/exampleitem.png", await (await fetch(
|
||||||
|
itemTexture
|
||||||
|
)).arrayBuffer());
|
||||||
|
});
|
||||||
|
})();
|
||||||
@@ -0,0 +1,69 @@
|
|||||||
|
// This is an example mod on how to register an item.
|
||||||
|
(()=>{
|
||||||
|
const itemTexture = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAKZJREFUOE9j/P//PxMDBIBoEP6HREOl4PLIciA2AyPIgMcM//7KgvWSDJjBBpx9/+YvJzc3Sbq12DhB6sEGsJ19/+YnmQawYhigzc7FcPXnN4KugbqAHWQAy9n3b34T4wJkw6EGYLqAoNVQBWS5ANlwZBfAvUCs/0EGkW0AzBKqGoCSDgh5A80F2KMRpAgfAKUT6kcjsfEPUycmKMQgy8AETkgUZWcAS3CPIf4oSPsAAAAASUVORK5CYII=";
|
||||||
|
//this texture is REALLY bad, so the item appears 2d in game. (it uses partially transparent pixels around the edges in some spots ;-;)
|
||||||
|
ModAPI.meta.title("Adding items demo.");
|
||||||
|
ModAPI.meta.version("v1.0");
|
||||||
|
ModAPI.meta.icon(itemTexture);
|
||||||
|
ModAPI.meta.description("Requires AsyncSink.");
|
||||||
|
|
||||||
|
function ExampleItem() {
|
||||||
|
var creativeMiscTab = ModAPI.reflect.getClassById("net.minecraft.creativetab.CreativeTabs").staticVariables.MISC;
|
||||||
|
var itemClass = ModAPI.reflect.getClassById("net.minecraft.item.Item");
|
||||||
|
var itemSuper = ModAPI.reflect.getSuper(itemClass, (x) => x.length === 1);
|
||||||
|
function nmi_ItemExample() {
|
||||||
|
itemSuper(this); //Use super function to get block properties on this class.
|
||||||
|
this.$setCreativeTab(creativeMiscTab);
|
||||||
|
}
|
||||||
|
ModAPI.reflect.prototypeStack(itemClass, nmi_ItemExample);
|
||||||
|
|
||||||
|
function internal_reg() {
|
||||||
|
var example_item = (new nmi_ItemExample()).$setUnlocalizedName(
|
||||||
|
ModAPI.util.str("exampleitem")
|
||||||
|
);
|
||||||
|
itemClass.staticMethods.registerItem.method(ModAPI.keygen.item("exampleitem"), ModAPI.util.str("exampleitem"), example_item);
|
||||||
|
ModAPI.items["exampleitem"] = example_item;
|
||||||
|
|
||||||
|
return example_item;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ModAPI.items) {
|
||||||
|
return internal_reg();
|
||||||
|
} else {
|
||||||
|
ModAPI.addEventListener("bootstrap", internal_reg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ModAPI.dedicatedServer.appendCode(ExampleItem);
|
||||||
|
var example_item = ExampleItem();
|
||||||
|
|
||||||
|
ModAPI.addEventListener("lib:asyncsink", async () => {
|
||||||
|
ModAPI.addEventListener("lib:asyncsink:registeritems", (renderItem)=>{
|
||||||
|
renderItem.registerItem(example_item, ModAPI.util.str("exampleitem"));
|
||||||
|
});
|
||||||
|
AsyncSink.L10N.set("item.exampleitem.name", "Example Item");
|
||||||
|
AsyncSink.setFile("resourcepacks/AsyncSinkLib/assets/minecraft/models/item/exampleitem.json", JSON.stringify(
|
||||||
|
{
|
||||||
|
"parent": "builtin/generated",
|
||||||
|
"textures": {
|
||||||
|
"layer0": "items/exampleitem"
|
||||||
|
},
|
||||||
|
"display": {
|
||||||
|
"thirdperson": {
|
||||||
|
"rotation": [ -90, 0, 0 ],
|
||||||
|
"translation": [ 0, 1, -3 ],
|
||||||
|
"scale": [ 0.55, 0.55, 0.55 ]
|
||||||
|
},
|
||||||
|
"firstperson": {
|
||||||
|
"rotation": [ 0, -135, 25 ],
|
||||||
|
"translation": [ 0, 4, 2 ],
|
||||||
|
"scale": [ 1.7, 1.7, 1.7 ]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
));
|
||||||
|
AsyncSink.setFile("resourcepacks/AsyncSinkLib/assets/minecraft/textures/items/exampleitem.png", await (await fetch(
|
||||||
|
itemTexture
|
||||||
|
)).arrayBuffer());
|
||||||
|
});
|
||||||
|
})();
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
//Metadata about the vclip mod
|
||||||
|
ModAPI.meta.title("Simple VClip Exploit");
|
||||||
|
ModAPI.meta.description("Use .vclip <offset> to vertically phase through blocks.");
|
||||||
|
ModAPI.meta.credits("By ZXMushroom63");
|
||||||
|
|
||||||
|
// Require the player entity
|
||||||
|
ModAPI.require("player");
|
||||||
|
|
||||||
|
//When the player tries to send a chat message to the server
|
||||||
|
ModAPI.addEventListener("sendchatmessage", (ev) => {
|
||||||
|
var msg = ev.message.toLowerCase(); //Get the lowercase version of the command
|
||||||
|
if (msg.startsWith(".vclip")) { //If it starts with .vclip
|
||||||
|
ev.preventDefault = true; //Don't send the chat message to the server
|
||||||
|
var yOffset = 1; //Set the default Y offset to 1. This let's you use .vclip with no arguments to "unstuck" yourself;
|
||||||
|
if (msg.split(" ")[1]) { //If there is a second part to the command
|
||||||
|
yOffset = parseFloat(msg.split(" ")[1]) || 0; //Set the yOffset to that
|
||||||
|
}
|
||||||
|
ModAPI.player.setPosition(ModAPI.player.posX, ModAPI.player.posY
|
||||||
|
+ yOffset, ModAPI.player.posZ); //Set the player's position to their current position plus the y offset.
|
||||||
|
ModAPI.displayToChat("[SimpleVClip] VClipped " + yOffset + " blocks."); //Display information to the client side chat.
|
||||||
|
}
|
||||||
|
});
|
||||||
@@ -0,0 +1,133 @@
|
|||||||
|
(function TreeChopperMod() {
|
||||||
|
ModAPI.meta.title("Vein Miner");
|
||||||
|
ModAPI.meta.description("Vein-mines trees & ores while crouching. Press the 'config' button for settings.");
|
||||||
|
ModAPI.meta.credits("By ZXMushroom63");
|
||||||
|
ModAPI.meta.version("v1.0");
|
||||||
|
globalThis.VEINMINERCONF = {
|
||||||
|
doLogs: true,
|
||||||
|
doOres: true,
|
||||||
|
doGravel: false,
|
||||||
|
doClay: false,
|
||||||
|
};
|
||||||
|
try {
|
||||||
|
Object.assign(conf, JSON.parse(localStorage.getItem("trc_mod::conf") || "{}"));
|
||||||
|
} catch (error) {
|
||||||
|
//swallow
|
||||||
|
}
|
||||||
|
ModAPI.meta.config(() => {
|
||||||
|
var conf = document.createElement("div");
|
||||||
|
conf.innerHTML = `
|
||||||
|
<h1>Vein Miner Settings <a href="javascript:void(0)" onclick="this.parentElement.parentElement.remove()" style="color:red">[X]</a></h1>
|
||||||
|
<sub>Refresh page to apply settings</sub><br>
|
||||||
|
<label>Veinmine Logs: </label><input type=checkbox ${VEINMINERCONF.doLogs ? "checked" : ""} oninput="VEINMINERCONF.doLogs = this.checked; this.parentElement.__save();"></input><br>
|
||||||
|
<label>Veinmine Ores: </label><input type=checkbox ${VEINMINERCONF.doOres ? "checked" : ""} oninput="VEINMINERCONF.doOres = this.checked; this.parentElement.__save();"></input><br>
|
||||||
|
<label>Veinmine Gravel: </label><input type=checkbox ${VEINMINERCONF.doGravel ? "checked" : ""} oninput="VEINMINERCONF.doGravel = this.checked; this.parentElement.__save();"></input><br>
|
||||||
|
<label>Veinmine Clay: </label><input type=checkbox ${VEINMINERCONF.doClay ? "checked" : ""} oninput="VEINMINERCONF.doClay = this.checked; this.parentElement.__save();"></input><br>
|
||||||
|
`;
|
||||||
|
conf.style = "position: fixed; background-color: white; color: black; width: 100vw; height: 100vh; z-index: 256;top:0;left:0;";
|
||||||
|
conf.__save = () => localStorage.setItem("trc_mod::conf", JSON.stringify(VEINMINERCONF));
|
||||||
|
document.body.appendChild(conf);
|
||||||
|
});
|
||||||
|
|
||||||
|
ModAPI.dedicatedServer.appendCode(`globalThis.VEINMINERCONF = ${JSON.stringify(VEINMINERCONF)};`);
|
||||||
|
|
||||||
|
ModAPI.dedicatedServer.appendCode(function () {
|
||||||
|
ModAPI.addEventListener("bootstrap", () => {
|
||||||
|
const axes = [ModAPI.items.iron_axe, ModAPI.items.stone_axe, ModAPI.items.golden_axe, ModAPI.items.wooden_axe, ModAPI.items.diamond_axe].map(x => x.getRef());
|
||||||
|
const logs = ["log", "log2"].map(x => ModAPI.blocks[x].getRef());
|
||||||
|
const targettedBlockIds = [];
|
||||||
|
if (VEINMINERCONF.doLogs) {
|
||||||
|
targettedBlockIds.push("log", "log2");
|
||||||
|
}
|
||||||
|
if (VEINMINERCONF.doOres) {
|
||||||
|
targettedBlockIds.push("coal_ore", "gold_ore", "iron_ore", "lapis_ore", "quartz_ore", "diamond_ore", "emerald_ore", "redstone_ore", "lit_redstone_ore");
|
||||||
|
}
|
||||||
|
if (VEINMINERCONF.doGravel) {
|
||||||
|
targettedBlockIds.push("gravel");
|
||||||
|
}
|
||||||
|
if (VEINMINERCONF.doClay) {
|
||||||
|
targettedBlockIds.push("clay");
|
||||||
|
}
|
||||||
|
console.log(targettedBlockIds);
|
||||||
|
const valid_log_blocks = targettedBlockIds.map(x => ModAPI.blocks[x].getRef());
|
||||||
|
|
||||||
|
function stringifyBlockPos(blockPos) {
|
||||||
|
return blockPos.x + "," + blockPos.y + "," + blockPos.z;
|
||||||
|
}
|
||||||
|
function getNeighbors(blockPos) {
|
||||||
|
return [
|
||||||
|
//direct neighbors
|
||||||
|
blockPos.down(1),
|
||||||
|
blockPos.up(1),
|
||||||
|
blockPos.north(1),
|
||||||
|
blockPos.south(1),
|
||||||
|
blockPos.east(1),
|
||||||
|
blockPos.west(1),
|
||||||
|
|
||||||
|
//edges
|
||||||
|
blockPos.down(1).north(1),
|
||||||
|
blockPos.down(1).south(1),
|
||||||
|
blockPos.down(1).east(1),
|
||||||
|
blockPos.down(1).west(1),
|
||||||
|
blockPos.up(1).north(1),
|
||||||
|
blockPos.up(1).south(1),
|
||||||
|
blockPos.up(1).east(1),
|
||||||
|
blockPos.up(1).west(1),
|
||||||
|
blockPos.north(1).east(1),
|
||||||
|
blockPos.north(1).west(1),
|
||||||
|
blockPos.south(1).east(1),
|
||||||
|
blockPos.south(1).west(1),
|
||||||
|
|
||||||
|
//corners
|
||||||
|
blockPos.down(1).north(1).east(1),
|
||||||
|
blockPos.down(1).north(1).west(1),
|
||||||
|
blockPos.down(1).south(1).east(1),
|
||||||
|
blockPos.down(1).south(1).west(1),
|
||||||
|
blockPos.up(1).north(1).east(1),
|
||||||
|
blockPos.up(1).north(1).west(1),
|
||||||
|
blockPos.up(1).south(1).east(1),
|
||||||
|
blockPos.up(1).south(1).west(1),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
async function getBlockGraph(blockPos, getBlockState, targetType) {
|
||||||
|
const closed = [stringifyBlockPos(blockPos)];
|
||||||
|
const logs = [];
|
||||||
|
const open = [...getNeighbors(blockPos)];
|
||||||
|
const maxIters = 120;
|
||||||
|
var i = 0;
|
||||||
|
while (open.length > 0 && i < maxIters) {
|
||||||
|
const target = open.pop();
|
||||||
|
|
||||||
|
closed.push(stringifyBlockPos(target));
|
||||||
|
|
||||||
|
i++;
|
||||||
|
const iBlockState = await getBlockState(target.getRef());
|
||||||
|
if (iBlockState.block.getRef() === targetType) {
|
||||||
|
logs.push(target);
|
||||||
|
open.push(...getNeighbors(target).filter(x => !closed.includes(stringifyBlockPos(x))));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return logs;
|
||||||
|
}
|
||||||
|
|
||||||
|
valid_log_blocks.forEach(b => {
|
||||||
|
const originalHarvest = b.$harvestBlock;
|
||||||
|
b.$harvestBlock = function ($theWorld, $player, $blockpos, $blockstate, $tileentity, ...args) {
|
||||||
|
const blockState = ModAPI.util.wrap($blockstate);
|
||||||
|
const player = ModAPI.util.wrap($player);
|
||||||
|
if (player.isSneaking() && !ModAPI.util.isCritical() && !(logs.includes(blockState.block.getRef()) && !axes.includes(player.inventory.mainInventory[player.inventory.currentItem]?.getCorrective()?.item?.getRef()))) {
|
||||||
|
ModAPI.promisify(async () => {
|
||||||
|
var world = ModAPI.util.wrap($theWorld);
|
||||||
|
var harvestCall = ModAPI.promisify(ModAPI.is_1_12 ? player.interactionManager.tryHarvestBlock : player.theItemInWorldManager.tryHarvestBlock);
|
||||||
|
const blocks = await getBlockGraph(ModAPI.util.wrap($blockpos), ModAPI.promisify(world.getBlockState), b);
|
||||||
|
for (let i = 0; i < blocks.length; i++) {
|
||||||
|
await harvestCall(blocks[i].getRef());
|
||||||
|
}
|
||||||
|
})();
|
||||||
|
}
|
||||||
|
originalHarvest.apply(this, [$theWorld, $player, $blockpos, $blockstate, $tileentity, ...args]);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
})();
|
||||||
@@ -0,0 +1,138 @@
|
|||||||
|
(function Waypoints() {
|
||||||
|
ModAPI.meta.title("Waypoints Mod");
|
||||||
|
ModAPI.meta.description("Use /setwp <name> to make a waypoint, and /wp <name> to go to it. /remwp <name> to delete a waypoint. /listwp to list all waypoints.");
|
||||||
|
ModAPI.meta.credits("By blizz828, Block_2222 & ZXMushroom63");
|
||||||
|
|
||||||
|
ModAPI.dedicatedServer.appendCode(async ()=>{ //The mods should probably be running on the server
|
||||||
|
function initDB(dbName, storeName) {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
const request = indexedDB.open(dbName, 2);
|
||||||
|
|
||||||
|
request.onupgradeneeded = (event) => {
|
||||||
|
const db = event.target.result;
|
||||||
|
if (!db.objectStoreNames.contains(storeName)) {
|
||||||
|
db.createObjectStore(storeName);
|
||||||
|
}
|
||||||
|
resolve(db);
|
||||||
|
};
|
||||||
|
|
||||||
|
request.onsuccess = (event) => {
|
||||||
|
const db = event.target.result;
|
||||||
|
resolve(db);
|
||||||
|
};
|
||||||
|
|
||||||
|
request.onerror = (event) => {
|
||||||
|
reject('Error opening database: ' + event.target.errorCode);
|
||||||
|
};
|
||||||
|
});
|
||||||
|
}
|
||||||
|
function storeString(dbName, storeName, key, value) {
|
||||||
|
return initDB(dbName, storeName).then((db) => {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
const transaction = db.transaction(storeName, 'readwrite');
|
||||||
|
const store = transaction.objectStore(storeName);
|
||||||
|
const putRequest = store.put(value, key);
|
||||||
|
|
||||||
|
putRequest.onsuccess = () => {
|
||||||
|
resolve('String stored successfully.');
|
||||||
|
};
|
||||||
|
|
||||||
|
putRequest.onerror = (event) => {
|
||||||
|
reject('Error storing string: ' + event.target.errorCode);
|
||||||
|
};
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
function retrieveString(dbName, storeName, key) {
|
||||||
|
return initDB(dbName, storeName).then((db) => {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
const transaction = db.transaction(storeName, 'readonly');
|
||||||
|
const store = transaction.objectStore(storeName);
|
||||||
|
const getRequest = store.get(key);
|
||||||
|
|
||||||
|
getRequest.onsuccess = () => {
|
||||||
|
if (getRequest.result !== undefined) {
|
||||||
|
resolve(getRequest.result);
|
||||||
|
} else {
|
||||||
|
resolve('');
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
getRequest.onerror = (event) => {
|
||||||
|
resolve('');
|
||||||
|
};
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
var data = {};
|
||||||
|
try {
|
||||||
|
data = JSON.parse(await retrieveString("waypoints_db", "waypoints", "waypoints"));
|
||||||
|
} catch(e) {
|
||||||
|
//didn't ask
|
||||||
|
}
|
||||||
|
|
||||||
|
async function saveData() {
|
||||||
|
await storeString("waypoints_db", "waypoints", "waypoints", JSON.stringify(data));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
ModAPI.addEventListener("processcommand", (e)=>{
|
||||||
|
if (!ModAPI.reflect.getClassById("net.minecraft.entity.player.EntityPlayerMP").instanceOf(e.sender.getRef())) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (e.command.toLowerCase().startsWith("/setwp ") && e.sender.canCommandSenderUseCommand(2, ModAPI.util.str("setwp"))) {
|
||||||
|
e.preventDefault = true;
|
||||||
|
var pos = e.sender.getPosition();
|
||||||
|
var name = ModAPI.util.unstring(e.sender.getName().getRef());
|
||||||
|
var waypointId = e.command.split(" ")[1] || "waypoint";
|
||||||
|
waypointId = waypointId.replace(/[^a-zA-Z0-9_]/gm, "_");
|
||||||
|
if (!data[name]) {
|
||||||
|
data[name] = {};
|
||||||
|
}
|
||||||
|
data[name][waypointId] = [pos.x,pos.y,pos.z,e.sender.dimension];
|
||||||
|
saveData();
|
||||||
|
e.sender.addChatMessage(ModAPI.reflect.getClassById("net.minecraft.util.ChatComponentText").constructors[0](ModAPI.util.str("Set waypoint "+waypointId+".")));
|
||||||
|
}
|
||||||
|
if (e.command.toLowerCase().startsWith("/wp ") && e.sender.canCommandSenderUseCommand(2, ModAPI.util.str("wp"))) {
|
||||||
|
e.preventDefault = true;
|
||||||
|
var name = ModAPI.util.unstring(e.sender.getName().getRef());
|
||||||
|
var waypointId = e.command.split(" ")[1];
|
||||||
|
if (waypointId && Array.isArray(data?.[name]?.[waypointId])) {
|
||||||
|
|
||||||
|
// Wildly important! regular setPosition triggers minecraft's built in anti-cheat and teleports you back in the same tick.
|
||||||
|
if (data?.[name]?.[waypointId]?.[3] && (data?.[name]?.[waypointId]?.[3] !== e.sender.dimension)) {
|
||||||
|
e.sender.travelToDimension(data?.[name]?.[waypointId]?.[3]);
|
||||||
|
}
|
||||||
|
|
||||||
|
e.sender.setPositionAndUpdate(...data?.[name]?.[waypointId]);
|
||||||
|
|
||||||
|
e.sender.addChatMessage(ModAPI.reflect.getClassById("net.minecraft.util.ChatComponentText").constructors[0](ModAPI.util.str("Teleported to waypoint " + waypointId + ".")));
|
||||||
|
} else {
|
||||||
|
e.sender.addChatMessage(ModAPI.reflect.getClassById("net.minecraft.util.ChatComponentText").constructors[0](ModAPI.util.str("No such waypoint.")));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (e.command.toLowerCase().startsWith("/remwp ") && e.sender.canCommandSenderUseCommand(2, ModAPI.util.str("remwp"))) {
|
||||||
|
e.preventDefault = true;
|
||||||
|
var name = ModAPI.util.unstring(e.sender.getName().getRef());
|
||||||
|
var waypointId = e.command.split(" ")[1] || "waypoint";
|
||||||
|
if (!data[name]) {
|
||||||
|
data[name] = {};
|
||||||
|
}
|
||||||
|
delete data[name][waypointId];
|
||||||
|
saveData();
|
||||||
|
e.sender.addChatMessage(ModAPI.reflect.getClassById("net.minecraft.util.ChatComponentText").constructors[0](ModAPI.util.str("Removed waypoint "+waypointId+".")));
|
||||||
|
}
|
||||||
|
if ((e.command.toLowerCase() === "/listwp") && e.sender.canCommandSenderUseCommand(2, ModAPI.util.str("listwp"))) {
|
||||||
|
e.preventDefault = true;
|
||||||
|
var name = ModAPI.util.unstring(e.sender.getName().getRef());
|
||||||
|
if (!data[name]) {
|
||||||
|
data[name] = {};
|
||||||
|
}
|
||||||
|
e.sender.addChatMessage(ModAPI.reflect.getClassById("net.minecraft.util.ChatComponentText").constructors[0](ModAPI.util.str("Your waypoints: " + Object.keys(data[name]).join(", "))));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
})();
|
||||||
File diff suppressed because one or more lines are too long
@@ -0,0 +1,31 @@
|
|||||||
|
(() => {
|
||||||
|
PluginAPI.dedicatedServer.appendCode(function () { //Run this code on the server
|
||||||
|
PluginAPI.addEventListener("processcommand", (event) => { //Command processing event
|
||||||
|
// Check if the sender is a player
|
||||||
|
if (!ModAPI.reflect.getClassById("net.minecraft.entity.player.EntityPlayerMP").instanceOf(event.sender.getRef())) { return; }
|
||||||
|
|
||||||
|
// Check if the command is "/spawnxp"
|
||||||
|
if (event.command.toLowerCase().startsWith("/spawnxp")) {
|
||||||
|
const world = event.sender.getServerForPlayer();
|
||||||
|
const senderPos = event.sender.getPosition();
|
||||||
|
|
||||||
|
// Create an xp orb entity
|
||||||
|
const EntityXP = ModAPI.reflect.getClassByName("EntityXPOrb");
|
||||||
|
const xporb = EntityXP.constructors[0](world.getRef(), senderPos.getX(), senderPos.getY(), senderPos.getZ(), 10);
|
||||||
|
|
||||||
|
// Add the xp orb to the world
|
||||||
|
ModAPI.promisify(ModAPI.hooks.methods.nmw_World_spawnEntityInWorld)(world.getRef(), xporb).then(result => {
|
||||||
|
// Notify the player that the xp orb has been spawned
|
||||||
|
|
||||||
|
// Get the chat component class
|
||||||
|
const ChatComponentTextClass = ModAPI.reflect.getClassById("net.minecraft.util.ChatComponentText");
|
||||||
|
// Construct the chat component and send it to the client.
|
||||||
|
event.sender.addChatMessage(ChatComponentTextClass.constructors[0](ModAPI.util.str("An xp orb has been spawned!")));
|
||||||
|
});
|
||||||
|
|
||||||
|
// Prevent the command from executing further (stops syntax errors / command does not exist errors)
|
||||||
|
event.preventDefault = true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
})();
|
||||||
@@ -0,0 +1,191 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8" />
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||||
|
<meta name="description" content="EaglerForge Injector is a tool designed for modifying or injecting code into Eaglercraft clients, supporting 1.8 and 1.12.">
|
||||||
|
<link rel="canonical" href="https://eaglerforge.github.io/eaglerforgeinjector/">
|
||||||
|
<meta property="og:type" content="website">
|
||||||
|
<meta property="og:locale" content="en_US">
|
||||||
|
<meta property="og:title" content="EaglerForge Injector - Modding API for Eaglercraft">
|
||||||
|
<meta property="og:url" content="https://eaglerforge.github.io/eaglerforgeinjector/">
|
||||||
|
<meta property="og:site_name" content="EaglerForge Injector - Modding API for Eaglercraft">
|
||||||
|
|
||||||
|
<meta property="og:image" content="http://eaglerforge.github.io/EaglerForgeInjector/res/EaglerForgeInjector.png">
|
||||||
|
<meta property="og:image:width" content="1024">
|
||||||
|
<meta property="og:image:height" content="1024">
|
||||||
|
<meta property="og:image:type" content="image/png">
|
||||||
|
|
||||||
|
<meta name="author" content="EaglerForge Team">
|
||||||
|
|
||||||
|
<title>Loading...</title>
|
||||||
|
<link
|
||||||
|
href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css"
|
||||||
|
rel="stylesheet"
|
||||||
|
/>
|
||||||
|
<link
|
||||||
|
href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.1/css/all.min.css"
|
||||||
|
rel="stylesheet"
|
||||||
|
/>
|
||||||
|
<style>
|
||||||
|
body {
|
||||||
|
background-color: #2b2b2b;
|
||||||
|
color: #ffffff;
|
||||||
|
overflow-x: hidden;
|
||||||
|
overflow-y: scroll;
|
||||||
|
}
|
||||||
|
.container {
|
||||||
|
text-align: center;
|
||||||
|
margin-top: 50px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.github-button-container {
|
||||||
|
position: absolute;
|
||||||
|
top: 10px;
|
||||||
|
right: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.github-button-container a.btn {
|
||||||
|
color: #ffffff;
|
||||||
|
border-color: #ffffff;
|
||||||
|
}
|
||||||
|
|
||||||
|
.github-button-container a.btn:hover {
|
||||||
|
background-color: #ffffff;
|
||||||
|
color: #000000;
|
||||||
|
}
|
||||||
|
#info {
|
||||||
|
text-align: left;
|
||||||
|
min-width: 50vw;
|
||||||
|
}
|
||||||
|
details {
|
||||||
|
text-align: left;
|
||||||
|
padding: 6px;
|
||||||
|
border-radius: 1rem;
|
||||||
|
background-color: rgba(0, 0, 0, 0.5);
|
||||||
|
margin-bottom: 1rem;
|
||||||
|
}
|
||||||
|
summary {
|
||||||
|
background-color: rgba(255, 255, 255, 0.1);
|
||||||
|
padding: 4px;
|
||||||
|
border-radius: 0.6rem;
|
||||||
|
padding-left: 8px;
|
||||||
|
}
|
||||||
|
h6 {
|
||||||
|
font-weight: normal;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div class="container">
|
||||||
|
<h1>EaglerForge Injector</h1>
|
||||||
|
<div class="github-button-container">
|
||||||
|
<a
|
||||||
|
href="https://github.com/eaglerforge/EaglerForgeInjector"
|
||||||
|
class="btn btn-default"
|
||||||
|
target="_blank"
|
||||||
|
>
|
||||||
|
<i class="fab fa-github"></i> GitHub
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
<h6>
|
||||||
|
Adds ModAPI with more functionality (adds hooking into functions,
|
||||||
|
exposes all classes, etc) to unminified unobfuscated EaglercraftX
|
||||||
|
offline downloads (web support coming soon).
|
||||||
|
</h6>
|
||||||
|
<br />
|
||||||
|
<div class="custom-file mb-3">
|
||||||
|
<input
|
||||||
|
class="custom-file-input"
|
||||||
|
type="file"
|
||||||
|
id="htmlFile"
|
||||||
|
accept=".html,.js"
|
||||||
|
/>
|
||||||
|
<label class="custom-file-label" for="htmlFile"
|
||||||
|
>Choose .html file...</label
|
||||||
|
>
|
||||||
|
<br />
|
||||||
|
<span>
|
||||||
|
<label>Minify: </label><input type="checkbox" oninput="EFIConfig.doMinify = this.checked">
|
||||||
|
|
||||||
|
<label>MinifyExtras: </label><input type="checkbox" oninput="EFIConfig.doMinifyPlus = this.checked">
|
||||||
|
|
||||||
|
<label>EaglerForge: </label><input checked type="checkbox" oninput="EFIConfig.doEaglerforge = this.checked">
|
||||||
|
<code id="status">Awaiting input...</code></span>
|
||||||
|
<br /><br />
|
||||||
|
<button class="btn btn-primary" id="giveme">Make modded client</button>
|
||||||
|
<button class="btn btn-primary" id="givemeserver">
|
||||||
|
Make modded server (Indev)
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<br /><br /><br />
|
||||||
|
<span>Info:</span>
|
||||||
|
<div id="#info">
|
||||||
|
<details>
|
||||||
|
<summary>
|
||||||
|
Where can I download an unobfuscated unsigned Eaglercraft build?
|
||||||
|
</summary>
|
||||||
|
<p>
|
||||||
|
<strong>1.8:</strong>
|
||||||
|
<a href="https://github.com/Eaglercraft-Archive/unminified-eaglercraft-builds/releases/latest">
|
||||||
|
https://github.com/Eaglercraft-Archive/unminified-eaglercraft-builds/releases/latest
|
||||||
|
</a>
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
<strong>1.12:</strong>
|
||||||
|
<a href="https://github.com/Eaglercraft-Archive/unminified-eaglercraft-builds-1.12/releases/latest">
|
||||||
|
https://github.com/Eaglercraft-Archive/unminified-eaglercraft-builds-1.12/releases/latest
|
||||||
|
</a>
|
||||||
|
</p>
|
||||||
|
</details>
|
||||||
|
<details>
|
||||||
|
<summary>
|
||||||
|
How do I compile my own unobfuscated unsigned Eaglercraft build?
|
||||||
|
</summary>
|
||||||
|
<a href="docs/compiling_client">tutorial here</a>
|
||||||
|
</details>
|
||||||
|
<details>
|
||||||
|
<summary>How does this tool work?</summary>
|
||||||
|
The injector works by analysing your uploaded file for patterns that
|
||||||
|
appear in TeaVM's compiled JavaScript code. Then, it will replace all
|
||||||
|
functions with proxies to the original code, which it moves into
|
||||||
|
<code>ModAPI.hooks.methods</code>. It does similar things with static
|
||||||
|
properties and constructors, and then hooks into
|
||||||
|
<code>$rt_metadata</code> to access auxilary information.
|
||||||
|
</details>
|
||||||
|
<details>
|
||||||
|
<summary>Where documentation???</summary>
|
||||||
|
<a href="https://eaglerforge.github.io/EaglerForgeInjector/docs"
|
||||||
|
>https://eaglerforge.github.io/EaglerForgeInjector/docs</a
|
||||||
|
>
|
||||||
|
</details>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Libraries -->
|
||||||
|
<script src="libs/babel.min.js"></script>
|
||||||
|
<script src="libs/filesaver.min.js"></script>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
document.querySelector("#htmlFile").addEventListener("input", (e) => {
|
||||||
|
if (e.target.files[0]) {
|
||||||
|
document.querySelector(".custom-file-label").innerText =
|
||||||
|
e.target.files[0].name;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<!-- Code assets -->
|
||||||
|
<script src="core/patches.js"></script>
|
||||||
|
<script src="core/minify.js"></script>
|
||||||
|
<script src="core/postinit.js"></script>
|
||||||
|
<script src="core/modloader.js"></script>
|
||||||
|
<script src="core/modgui.js"></script>
|
||||||
|
<script src="core/efserver.js"></script>
|
||||||
|
<script src="core/core.js"></script>
|
||||||
|
|
||||||
|
<script src="backgroundLogger.js"></script>
|
||||||
|
<script src="browser.js"></script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
File diff suppressed because one or more lines are too long
@@ -0,0 +1,2 @@
|
|||||||
|
//FileSaver.min.js
|
||||||
|
(function(a,b){if("function"==typeof define&&define.amd)define([],b);else if("undefined"!=typeof exports)b();else{b(),a.FileSaver={exports:{}}.exports}})(this,function(){"use strict";function b(a,b){return"undefined"==typeof b?b={autoBom:!1}:"object"!=typeof b&&(console.warn("Deprecated: Expected third argument to be a object"),b={autoBom:!b}),b.autoBom&&/^\s*(?:text\/\S*|application\/xml|\S*\/\S*\+xml)\s*;.*charset\s*=\s*utf-8/i.test(a.type)?new Blob(["\uFEFF",a],{type:a.type}):a}function c(a,b,c){var d=new XMLHttpRequest;d.open("GET",a),d.responseType="blob",d.onload=function(){g(d.response,b,c)},d.onerror=function(){console.error("could not download file")},d.send()}function d(a){var b=new XMLHttpRequest;b.open("HEAD",a,!1);try{b.send()}catch(a){}return 200<=b.status&&299>=b.status}function e(a){try{a.dispatchEvent(new MouseEvent("click"))}catch(c){var b=document.createEvent("MouseEvents");b.initMouseEvent("click",!0,!0,window,0,0,0,80,20,!1,!1,!1,!1,0,null),a.dispatchEvent(b)}}var f="object"==typeof window&&window.window===window?window:"object"==typeof self&&self.self===self?self:"object"==typeof global&&global.global===global?global:void 0,a=/Macintosh/.test(navigator.userAgent)&&/AppleWebKit/.test(navigator.userAgent)&&!/Safari/.test(navigator.userAgent),g=f.saveAs||("object"!=typeof window||window!==f?function(){}:"download"in HTMLAnchorElement.prototype&&!a?function(b,g,h){var i=f.URL||f.webkitURL,j=document.createElement("a");g=g||b.name||"download",j.download=g,j.rel="noopener","string"==typeof b?(j.href=b,j.origin===location.origin?e(j):d(j.href)?c(b,g,h):e(j,j.target="_blank")):(j.href=i.createObjectURL(b),setTimeout(function(){i.revokeObjectURL(j.href)},4E4),setTimeout(function(){e(j)},0))}:"msSaveOrOpenBlob"in navigator?function(f,g,h){if(g=g||f.name||"download","string"!=typeof f)navigator.msSaveOrOpenBlob(b(f,h),g);else if(d(f))c(f,g,h);else{var i=document.createElement("a");i.href=f,i.target="_blank",setTimeout(function(){e(i)})}}:function(b,d,e,g){if(g=g||open("","_blank"),g&&(g.document.title=g.document.body.innerText="downloading..."),"string"==typeof b)return c(b,d,e);var h="application/octet-stream"===b.type,i=/constructor/i.test(f.HTMLElement)||f.safari,j=/CriOS\/[\d]+/.test(navigator.userAgent);if((j||h&&i||a)&&"undefined"!=typeof FileReader){var k=new FileReader;k.onloadend=function(){var a=k.result;a=j?a:a.replace(/^data:[^;]*;/,"data:attachment/file;"),g?g.location.href=a:location=a,g=null},k.readAsDataURL(b)}else{var l=f.URL||f.webkitURL,m=l.createObjectURL(b);g?g.location=m:location.href=m,g=null,setTimeout(function(){l.revokeObjectURL(m)},4E4)}});f.saveAs=g.saveAs=g,"undefined"!=typeof module&&(module.exports=g)});
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
#!/usr/bin/env node
|
||||||
|
const { spawn } = require('child_process');
|
||||||
|
const path = require('path');
|
||||||
|
|
||||||
|
const os = require('os');
|
||||||
|
let cliPath = path.join(__dirname, 'cli.js');
|
||||||
|
if (!require('fs').existsSync(cliPath)) {
|
||||||
|
cliPath = path.join(__dirname, 'bin', 'cli.js');
|
||||||
|
if (!require('fs').existsSync(cliPath)) {
|
||||||
|
console.error("Error: cli.js not found. Expected it in either the same directory as this script, or in a 'bin' subdirectory.");
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const memUsage = Math.min(16384, Math.floor(os.totalmem() / 1024 / 1024 / 2));
|
||||||
|
|
||||||
|
const nodeOptions = ["--max-old-space-size=" + memUsage];
|
||||||
|
const cliArgs = process.argv.slice(2);
|
||||||
|
const command = process.execPath;
|
||||||
|
|
||||||
|
const child = spawn(command, [...nodeOptions, cliPath, ...cliArgs], {
|
||||||
|
stdio: 'inherit',
|
||||||
|
});
|
||||||
|
|
||||||
|
child.on('error', (err) => {
|
||||||
|
console.error(err.message);
|
||||||
|
process.exit(1);
|
||||||
|
});
|
||||||
|
|
||||||
|
child.on('close', (code) => {
|
||||||
|
if (code !== 0) {
|
||||||
|
console.error(`exited with code ${code}`);
|
||||||
|
}
|
||||||
|
process.exit(code);
|
||||||
|
});
|
||||||
+512
@@ -0,0 +1,512 @@
|
|||||||
|
{
|
||||||
|
"name": "eaglerforgeinjector",
|
||||||
|
"version": "2.7.97",
|
||||||
|
"lockfileVersion": 3,
|
||||||
|
"requires": true,
|
||||||
|
"packages": {
|
||||||
|
"": {
|
||||||
|
"name": "eaglerforgeinjector",
|
||||||
|
"version": "2.7.97",
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"@babel/core": "^7.29.0"
|
||||||
|
},
|
||||||
|
"bin": {
|
||||||
|
"efi": "npx_wrapper.js"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"@xmldom/xmldom": "^0.9.8"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/@babel/code-frame": {
|
||||||
|
"version": "7.29.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.29.0.tgz",
|
||||||
|
"integrity": "sha512-9NhCeYjq9+3uxgdtp20LSiJXJvN0FeCtNGpJxuMFZ1Kv3cWUNb6DOhJwUvcVCzKGR66cw4njwM6hrJLqgOwbcw==",
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"@babel/helper-validator-identifier": "^7.28.5",
|
||||||
|
"js-tokens": "^4.0.0",
|
||||||
|
"picocolors": "^1.1.1"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=6.9.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/@babel/compat-data": {
|
||||||
|
"version": "7.29.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/@babel/compat-data/-/compat-data-7.29.0.tgz",
|
||||||
|
"integrity": "sha512-T1NCJqT/j9+cn8fvkt7jtwbLBfLC/1y1c7NtCeXFRgzGTsafi68MRv8yzkYSapBnFA6L3U2VSc02ciDzoAJhJg==",
|
||||||
|
"license": "MIT",
|
||||||
|
"engines": {
|
||||||
|
"node": ">=6.9.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/@babel/core": {
|
||||||
|
"version": "7.29.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/@babel/core/-/core-7.29.0.tgz",
|
||||||
|
"integrity": "sha512-CGOfOJqWjg2qW/Mb6zNsDm+u5vFQ8DxXfbM09z69p5Z6+mE1ikP2jUXw+j42Pf1XTYED2Rni5f95npYeuwMDQA==",
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"@babel/code-frame": "^7.29.0",
|
||||||
|
"@babel/generator": "^7.29.0",
|
||||||
|
"@babel/helper-compilation-targets": "^7.28.6",
|
||||||
|
"@babel/helper-module-transforms": "^7.28.6",
|
||||||
|
"@babel/helpers": "^7.28.6",
|
||||||
|
"@babel/parser": "^7.29.0",
|
||||||
|
"@babel/template": "^7.28.6",
|
||||||
|
"@babel/traverse": "^7.29.0",
|
||||||
|
"@babel/types": "^7.29.0",
|
||||||
|
"@jridgewell/remapping": "^2.3.5",
|
||||||
|
"convert-source-map": "^2.0.0",
|
||||||
|
"debug": "^4.1.0",
|
||||||
|
"gensync": "^1.0.0-beta.2",
|
||||||
|
"json5": "^2.2.3",
|
||||||
|
"semver": "^6.3.1"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=6.9.0"
|
||||||
|
},
|
||||||
|
"funding": {
|
||||||
|
"type": "opencollective",
|
||||||
|
"url": "https://opencollective.com/babel"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/@babel/generator": {
|
||||||
|
"version": "7.29.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/@babel/generator/-/generator-7.29.1.tgz",
|
||||||
|
"integrity": "sha512-qsaF+9Qcm2Qv8SRIMMscAvG4O3lJ0F1GuMo5HR/Bp02LopNgnZBC/EkbevHFeGs4ls/oPz9v+Bsmzbkbe+0dUw==",
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"@babel/parser": "^7.29.0",
|
||||||
|
"@babel/types": "^7.29.0",
|
||||||
|
"@jridgewell/gen-mapping": "^0.3.12",
|
||||||
|
"@jridgewell/trace-mapping": "^0.3.28",
|
||||||
|
"jsesc": "^3.0.2"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=6.9.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/@babel/helper-compilation-targets": {
|
||||||
|
"version": "7.28.6",
|
||||||
|
"resolved": "https://registry.npmjs.org/@babel/helper-compilation-targets/-/helper-compilation-targets-7.28.6.tgz",
|
||||||
|
"integrity": "sha512-JYtls3hqi15fcx5GaSNL7SCTJ2MNmjrkHXg4FSpOA/grxK8KwyZ5bubHsCq8FXCkua6xhuaaBit+3b7+VZRfcA==",
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"@babel/compat-data": "^7.28.6",
|
||||||
|
"@babel/helper-validator-option": "^7.27.1",
|
||||||
|
"browserslist": "^4.24.0",
|
||||||
|
"lru-cache": "^5.1.1",
|
||||||
|
"semver": "^6.3.1"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=6.9.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/@babel/helper-globals": {
|
||||||
|
"version": "7.28.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/@babel/helper-globals/-/helper-globals-7.28.0.tgz",
|
||||||
|
"integrity": "sha512-+W6cISkXFa1jXsDEdYA8HeevQT/FULhxzR99pxphltZcVaugps53THCeiWA8SguxxpSp3gKPiuYfSWopkLQ4hw==",
|
||||||
|
"license": "MIT",
|
||||||
|
"engines": {
|
||||||
|
"node": ">=6.9.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/@babel/helper-module-imports": {
|
||||||
|
"version": "7.28.6",
|
||||||
|
"resolved": "https://registry.npmjs.org/@babel/helper-module-imports/-/helper-module-imports-7.28.6.tgz",
|
||||||
|
"integrity": "sha512-l5XkZK7r7wa9LucGw9LwZyyCUscb4x37JWTPz7swwFE/0FMQAGpiWUZn8u9DzkSBWEcK25jmvubfpw2dnAMdbw==",
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"@babel/traverse": "^7.28.6",
|
||||||
|
"@babel/types": "^7.28.6"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=6.9.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/@babel/helper-module-transforms": {
|
||||||
|
"version": "7.28.6",
|
||||||
|
"resolved": "https://registry.npmjs.org/@babel/helper-module-transforms/-/helper-module-transforms-7.28.6.tgz",
|
||||||
|
"integrity": "sha512-67oXFAYr2cDLDVGLXTEABjdBJZ6drElUSI7WKp70NrpyISso3plG9SAGEF6y7zbha/wOzUByWWTJvEDVNIUGcA==",
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"@babel/helper-module-imports": "^7.28.6",
|
||||||
|
"@babel/helper-validator-identifier": "^7.28.5",
|
||||||
|
"@babel/traverse": "^7.28.6"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=6.9.0"
|
||||||
|
},
|
||||||
|
"peerDependencies": {
|
||||||
|
"@babel/core": "^7.0.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/@babel/helper-string-parser": {
|
||||||
|
"version": "7.27.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/@babel/helper-string-parser/-/helper-string-parser-7.27.1.tgz",
|
||||||
|
"integrity": "sha512-qMlSxKbpRlAridDExk92nSobyDdpPijUq2DW6oDnUqd0iOGxmQjyqhMIihI9+zv4LPyZdRje2cavWPbCbWm3eA==",
|
||||||
|
"license": "MIT",
|
||||||
|
"engines": {
|
||||||
|
"node": ">=6.9.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/@babel/helper-validator-identifier": {
|
||||||
|
"version": "7.28.5",
|
||||||
|
"resolved": "https://registry.npmjs.org/@babel/helper-validator-identifier/-/helper-validator-identifier-7.28.5.tgz",
|
||||||
|
"integrity": "sha512-qSs4ifwzKJSV39ucNjsvc6WVHs6b7S03sOh2OcHF9UHfVPqWWALUsNUVzhSBiItjRZoLHx7nIarVjqKVusUZ1Q==",
|
||||||
|
"license": "MIT",
|
||||||
|
"engines": {
|
||||||
|
"node": ">=6.9.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/@babel/helper-validator-option": {
|
||||||
|
"version": "7.27.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/@babel/helper-validator-option/-/helper-validator-option-7.27.1.tgz",
|
||||||
|
"integrity": "sha512-YvjJow9FxbhFFKDSuFnVCe2WxXk1zWc22fFePVNEaWJEu8IrZVlda6N0uHwzZrUM1il7NC9Mlp4MaJYbYd9JSg==",
|
||||||
|
"license": "MIT",
|
||||||
|
"engines": {
|
||||||
|
"node": ">=6.9.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/@babel/helpers": {
|
||||||
|
"version": "7.29.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/@babel/helpers/-/helpers-7.29.2.tgz",
|
||||||
|
"integrity": "sha512-HoGuUs4sCZNezVEKdVcwqmZN8GoHirLUcLaYVNBK2J0DadGtdcqgr3BCbvH8+XUo4NGjNl3VOtSjEKNzqfFgKw==",
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"@babel/template": "^7.28.6",
|
||||||
|
"@babel/types": "^7.29.0"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=6.9.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/@babel/parser": {
|
||||||
|
"version": "7.29.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/@babel/parser/-/parser-7.29.2.tgz",
|
||||||
|
"integrity": "sha512-4GgRzy/+fsBa72/RZVJmGKPmZu9Byn8o4MoLpmNe1m8ZfYnz5emHLQz3U4gLud6Zwl0RZIcgiLD7Uq7ySFuDLA==",
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"@babel/types": "^7.29.0"
|
||||||
|
},
|
||||||
|
"bin": {
|
||||||
|
"parser": "bin/babel-parser.js"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=6.0.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/@babel/template": {
|
||||||
|
"version": "7.28.6",
|
||||||
|
"resolved": "https://registry.npmjs.org/@babel/template/-/template-7.28.6.tgz",
|
||||||
|
"integrity": "sha512-YA6Ma2KsCdGb+WC6UpBVFJGXL58MDA6oyONbjyF/+5sBgxY/dwkhLogbMT2GXXyU84/IhRw/2D1Os1B/giz+BQ==",
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"@babel/code-frame": "^7.28.6",
|
||||||
|
"@babel/parser": "^7.28.6",
|
||||||
|
"@babel/types": "^7.28.6"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=6.9.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/@babel/traverse": {
|
||||||
|
"version": "7.29.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/@babel/traverse/-/traverse-7.29.0.tgz",
|
||||||
|
"integrity": "sha512-4HPiQr0X7+waHfyXPZpWPfWL/J7dcN1mx9gL6WdQVMbPnF3+ZhSMs8tCxN7oHddJE9fhNE7+lxdnlyemKfJRuA==",
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"@babel/code-frame": "^7.29.0",
|
||||||
|
"@babel/generator": "^7.29.0",
|
||||||
|
"@babel/helper-globals": "^7.28.0",
|
||||||
|
"@babel/parser": "^7.29.0",
|
||||||
|
"@babel/template": "^7.28.6",
|
||||||
|
"@babel/types": "^7.29.0",
|
||||||
|
"debug": "^4.3.1"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=6.9.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/@babel/types": {
|
||||||
|
"version": "7.29.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/@babel/types/-/types-7.29.0.tgz",
|
||||||
|
"integrity": "sha512-LwdZHpScM4Qz8Xw2iKSzS+cfglZzJGvofQICy7W7v4caru4EaAmyUuO6BGrbyQ2mYV11W0U8j5mBhd14dd3B0A==",
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"@babel/helper-string-parser": "^7.27.1",
|
||||||
|
"@babel/helper-validator-identifier": "^7.28.5"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=6.9.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/@jridgewell/gen-mapping": {
|
||||||
|
"version": "0.3.13",
|
||||||
|
"resolved": "https://registry.npmjs.org/@jridgewell/gen-mapping/-/gen-mapping-0.3.13.tgz",
|
||||||
|
"integrity": "sha512-2kkt/7niJ6MgEPxF0bYdQ6etZaA+fQvDcLKckhy1yIQOzaoKjBBjSj63/aLVjYE3qhRt5dvM+uUyfCg6UKCBbA==",
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"@jridgewell/sourcemap-codec": "^1.5.0",
|
||||||
|
"@jridgewell/trace-mapping": "^0.3.24"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/@jridgewell/remapping": {
|
||||||
|
"version": "2.3.5",
|
||||||
|
"resolved": "https://registry.npmjs.org/@jridgewell/remapping/-/remapping-2.3.5.tgz",
|
||||||
|
"integrity": "sha512-LI9u/+laYG4Ds1TDKSJW2YPrIlcVYOwi2fUC6xB43lueCjgxV4lffOCZCtYFiH6TNOX+tQKXx97T4IKHbhyHEQ==",
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"@jridgewell/gen-mapping": "^0.3.5",
|
||||||
|
"@jridgewell/trace-mapping": "^0.3.24"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/@jridgewell/resolve-uri": {
|
||||||
|
"version": "3.1.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/@jridgewell/resolve-uri/-/resolve-uri-3.1.2.tgz",
|
||||||
|
"integrity": "sha512-bRISgCIjP20/tbWSPWMEi54QVPRZExkuD9lJL+UIxUKtwVJA8wW1Trb1jMs1RFXo1CBTNZ/5hpC9QvmKWdopKw==",
|
||||||
|
"license": "MIT",
|
||||||
|
"engines": {
|
||||||
|
"node": ">=6.0.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/@jridgewell/sourcemap-codec": {
|
||||||
|
"version": "1.5.5",
|
||||||
|
"resolved": "https://registry.npmjs.org/@jridgewell/sourcemap-codec/-/sourcemap-codec-1.5.5.tgz",
|
||||||
|
"integrity": "sha512-cYQ9310grqxueWbl+WuIUIaiUaDcj7WOq5fVhEljNVgRfOUhY9fy2zTvfoqWsnebh8Sl70VScFbICvJnLKB0Og==",
|
||||||
|
"license": "MIT"
|
||||||
|
},
|
||||||
|
"node_modules/@jridgewell/trace-mapping": {
|
||||||
|
"version": "0.3.31",
|
||||||
|
"resolved": "https://registry.npmjs.org/@jridgewell/trace-mapping/-/trace-mapping-0.3.31.tgz",
|
||||||
|
"integrity": "sha512-zzNR+SdQSDJzc8joaeP8QQoCQr8NuYx2dIIytl1QeBEZHJ9uW6hebsrYgbz8hJwUQao3TWCMtmfV8Nu1twOLAw==",
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"@jridgewell/resolve-uri": "^3.1.0",
|
||||||
|
"@jridgewell/sourcemap-codec": "^1.4.14"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/@xmldom/xmldom": {
|
||||||
|
"version": "0.9.9",
|
||||||
|
"resolved": "https://registry.npmjs.org/@xmldom/xmldom/-/xmldom-0.9.9.tgz",
|
||||||
|
"integrity": "sha512-qycIHAucxy/LXAYIjmLmtQ8q9GPnMbnjG1KXhWm9o5sCr6pOYDATkMPiTNa6/v8eELyqOQ2FsEqeoFYmgv/gJg==",
|
||||||
|
"dev": true,
|
||||||
|
"license": "MIT",
|
||||||
|
"engines": {
|
||||||
|
"node": ">=14.6"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/baseline-browser-mapping": {
|
||||||
|
"version": "2.10.13",
|
||||||
|
"resolved": "https://registry.npmjs.org/baseline-browser-mapping/-/baseline-browser-mapping-2.10.13.tgz",
|
||||||
|
"integrity": "sha512-BL2sTuHOdy0YT1lYieUxTw/QMtPBC3pmlJC6xk8BBYVv6vcw3SGdKemQ+Xsx9ik2F/lYDO9tqsFQH1r9PFuHKw==",
|
||||||
|
"license": "Apache-2.0",
|
||||||
|
"bin": {
|
||||||
|
"baseline-browser-mapping": "dist/cli.cjs"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=6.0.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/browserslist": {
|
||||||
|
"version": "4.28.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/browserslist/-/browserslist-4.28.2.tgz",
|
||||||
|
"integrity": "sha512-48xSriZYYg+8qXna9kwqjIVzuQxi+KYWp2+5nCYnYKPTr0LvD89Jqk2Or5ogxz0NUMfIjhh2lIUX/LyX9B4oIg==",
|
||||||
|
"funding": [
|
||||||
|
{
|
||||||
|
"type": "opencollective",
|
||||||
|
"url": "https://opencollective.com/browserslist"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "tidelift",
|
||||||
|
"url": "https://tidelift.com/funding/github/npm/browserslist"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "github",
|
||||||
|
"url": "https://github.com/sponsors/ai"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"baseline-browser-mapping": "^2.10.12",
|
||||||
|
"caniuse-lite": "^1.0.30001782",
|
||||||
|
"electron-to-chromium": "^1.5.328",
|
||||||
|
"node-releases": "^2.0.36",
|
||||||
|
"update-browserslist-db": "^1.2.3"
|
||||||
|
},
|
||||||
|
"bin": {
|
||||||
|
"browserslist": "cli.js"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": "^6 || ^7 || ^8 || ^9 || ^10 || ^11 || ^12 || >=13.7"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/caniuse-lite": {
|
||||||
|
"version": "1.0.30001784",
|
||||||
|
"resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001784.tgz",
|
||||||
|
"integrity": "sha512-WU346nBTklUV9YfUl60fqRbU5ZqyXlqvo1SgigE1OAXK5bFL8LL9q1K7aap3N739l4BvNqnkm3YrGHiY9sfUQw==",
|
||||||
|
"funding": [
|
||||||
|
{
|
||||||
|
"type": "opencollective",
|
||||||
|
"url": "https://opencollective.com/browserslist"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "tidelift",
|
||||||
|
"url": "https://tidelift.com/funding/github/npm/caniuse-lite"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "github",
|
||||||
|
"url": "https://github.com/sponsors/ai"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"license": "CC-BY-4.0"
|
||||||
|
},
|
||||||
|
"node_modules/convert-source-map": {
|
||||||
|
"version": "2.0.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/convert-source-map/-/convert-source-map-2.0.0.tgz",
|
||||||
|
"integrity": "sha512-Kvp459HrV2FEJ1CAsi1Ku+MY3kasH19TFykTz2xWmMeq6bk2NU3XXvfJ+Q61m0xktWwt+1HSYf3JZsTms3aRJg=="
|
||||||
|
},
|
||||||
|
"node_modules/debug": {
|
||||||
|
"version": "4.4.3",
|
||||||
|
"resolved": "https://registry.npmjs.org/debug/-/debug-4.4.3.tgz",
|
||||||
|
"integrity": "sha512-RGwwWnwQvkVfavKVt22FGLw+xYSdzARwm0ru6DhTVA3umU5hZc28V3kO4stgYryrTlLpuvgI9GiijltAjNbcqA==",
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"ms": "^2.1.3"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=6.0"
|
||||||
|
},
|
||||||
|
"peerDependenciesMeta": {
|
||||||
|
"supports-color": {
|
||||||
|
"optional": true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/electron-to-chromium": {
|
||||||
|
"version": "1.5.331",
|
||||||
|
"resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.5.331.tgz",
|
||||||
|
"integrity": "sha512-IbxXrsTlD3hRodkLnbxAPP4OuJYdWCeM3IOdT+CpcMoIwIoDfCmRpEtSPfwBXxVkg9xmBeY7Lz2Eo2TDn/HC3Q==",
|
||||||
|
"license": "ISC"
|
||||||
|
},
|
||||||
|
"node_modules/escalade": {
|
||||||
|
"version": "3.2.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/escalade/-/escalade-3.2.0.tgz",
|
||||||
|
"integrity": "sha512-WUj2qlxaQtO4g6Pq5c29GTcWGDyd8itL8zTlipgECz3JesAiiOKotd8JU6otB3PACgG6xkJUyVhboMS+bje/jA==",
|
||||||
|
"license": "MIT",
|
||||||
|
"engines": {
|
||||||
|
"node": ">=6"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/gensync": {
|
||||||
|
"version": "1.0.0-beta.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/gensync/-/gensync-1.0.0-beta.2.tgz",
|
||||||
|
"integrity": "sha512-3hN7NaskYvMDLQY55gnW3NQ+mesEAepTqlg+VEbj7zzqEMBVNhzcGYYeqFo/TlYz6eQiFcp1HcsCZO+nGgS8zg==",
|
||||||
|
"engines": {
|
||||||
|
"node": ">=6.9.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/js-tokens": {
|
||||||
|
"version": "4.0.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-4.0.0.tgz",
|
||||||
|
"integrity": "sha512-RdJUflcE3cUzKiMqQgsCu06FPu9UdIJO0beYbPhHN4k6apgJtifcoCtT9bcxOpYBtpD2kCM6Sbzg4CausW/PKQ==",
|
||||||
|
"license": "MIT"
|
||||||
|
},
|
||||||
|
"node_modules/jsesc": {
|
||||||
|
"version": "3.1.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/jsesc/-/jsesc-3.1.0.tgz",
|
||||||
|
"integrity": "sha512-/sM3dO2FOzXjKQhJuo0Q173wf2KOo8t4I8vHy6lF9poUp7bKT0/NHE8fPX23PwfhnykfqnC2xRxOnVw5XuGIaA==",
|
||||||
|
"license": "MIT",
|
||||||
|
"bin": {
|
||||||
|
"jsesc": "bin/jsesc"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=6"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/json5": {
|
||||||
|
"version": "2.2.3",
|
||||||
|
"resolved": "https://registry.npmjs.org/json5/-/json5-2.2.3.tgz",
|
||||||
|
"integrity": "sha512-XmOWe7eyHYH14cLdVPoyg+GOH3rYX++KpzrylJwSW98t3Nk+U8XOl8FWKOgwtzdb8lXGf6zYwDUzeHMWfxasyg==",
|
||||||
|
"bin": {
|
||||||
|
"json5": "lib/cli.js"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=6"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/lru-cache": {
|
||||||
|
"version": "5.1.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-5.1.1.tgz",
|
||||||
|
"integrity": "sha512-KpNARQA3Iwv+jTA0utUVVbrh+Jlrr1Fv0e56GGzAFOXN7dk/FviaDW8LHmK52DlcH4WP2n6gI8vN1aesBFgo9w==",
|
||||||
|
"license": "ISC",
|
||||||
|
"dependencies": {
|
||||||
|
"yallist": "^3.0.2"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/ms": {
|
||||||
|
"version": "2.1.3",
|
||||||
|
"resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz",
|
||||||
|
"integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==",
|
||||||
|
"license": "MIT"
|
||||||
|
},
|
||||||
|
"node_modules/node-releases": {
|
||||||
|
"version": "2.0.37",
|
||||||
|
"resolved": "https://registry.npmjs.org/node-releases/-/node-releases-2.0.37.tgz",
|
||||||
|
"integrity": "sha512-1h5gKZCF+pO/o3Iqt5Jp7wc9rH3eJJ0+nh/CIoiRwjRxde/hAHyLPXYN4V3CqKAbiZPSeJFSWHmJsbkicta0Eg==",
|
||||||
|
"license": "MIT"
|
||||||
|
},
|
||||||
|
"node_modules/picocolors": {
|
||||||
|
"version": "1.1.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/picocolors/-/picocolors-1.1.1.tgz",
|
||||||
|
"integrity": "sha512-xceH2snhtb5M9liqDsmEw56le376mTZkEX/jEb/RxNFyegNul7eNslCXP9FDj/Lcu0X8KEyMceP2ntpaHrDEVA==",
|
||||||
|
"license": "ISC"
|
||||||
|
},
|
||||||
|
"node_modules/semver": {
|
||||||
|
"version": "6.3.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/semver/-/semver-6.3.1.tgz",
|
||||||
|
"integrity": "sha512-BR7VvDCVHO+q2xBEWskxS6DJE1qRnb7DxzUrogb71CWoSficBxYsiAGd+Kl0mmq/MprG9yArRkyrQxTO6XjMzA==",
|
||||||
|
"license": "ISC",
|
||||||
|
"bin": {
|
||||||
|
"semver": "bin/semver.js"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/update-browserslist-db": {
|
||||||
|
"version": "1.2.3",
|
||||||
|
"resolved": "https://registry.npmjs.org/update-browserslist-db/-/update-browserslist-db-1.2.3.tgz",
|
||||||
|
"integrity": "sha512-Js0m9cx+qOgDxo0eMiFGEueWztz+d4+M3rGlmKPT+T4IS/jP4ylw3Nwpu6cpTTP8R1MAC1kF4VbdLt3ARf209w==",
|
||||||
|
"funding": [
|
||||||
|
{
|
||||||
|
"type": "opencollective",
|
||||||
|
"url": "https://opencollective.com/browserslist"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "tidelift",
|
||||||
|
"url": "https://tidelift.com/funding/github/npm/browserslist"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "github",
|
||||||
|
"url": "https://github.com/sponsors/ai"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"escalade": "^3.2.0",
|
||||||
|
"picocolors": "^1.1.1"
|
||||||
|
},
|
||||||
|
"bin": {
|
||||||
|
"update-browserslist-db": "cli.js"
|
||||||
|
},
|
||||||
|
"peerDependencies": {
|
||||||
|
"browserslist": ">= 4.21.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/yallist": {
|
||||||
|
"version": "3.1.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/yallist/-/yallist-3.1.1.tgz",
|
||||||
|
"integrity": "sha512-a4UGQaWPH59mOXUYnAG2ewncQS4i4F43Tv3JoAM+s2VDAmS9NsK8GpDMLrCHPksFT7h3K6TOoUNn2pb7RoXx4g==",
|
||||||
|
"license": "ISC"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
{
|
||||||
|
"name": "eaglerforgeinjector",
|
||||||
|
"version": "2.7.97",
|
||||||
|
"description": "Advanced modding API injector for unminified, unobfuscated, unsigned eaglercraft builds.",
|
||||||
|
"main": "node.js",
|
||||||
|
"directories": {
|
||||||
|
"doc": "docs"
|
||||||
|
},
|
||||||
|
"scripts": {
|
||||||
|
"efi": "node --max-old-space-size=16384 cli.js"
|
||||||
|
},
|
||||||
|
"bin": {
|
||||||
|
"efi": "./npx_wrapper.js"
|
||||||
|
},
|
||||||
|
"author": "EaglerForge Team",
|
||||||
|
"license": "MIT",
|
||||||
|
"devDependencies": {
|
||||||
|
"@xmldom/xmldom": "^0.9.8"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"@babel/core": "^7.29.0"
|
||||||
|
}
|
||||||
|
}
|
||||||
Binary file not shown.
|
After Width: | Height: | Size: 22 KiB |
Reference in New Issue
Block a user