mirror of
https://github.com/eaglerforge/EaglerForgeInjector
synced 2025-07-25 07:01:20 -09:00
push waypoints mod + increase meta char limit
This commit is contained in:
parent
4b3ff56718
commit
e33bd95b6a
134
examplemods/waypoints.js
Normal file
134
examplemods/waypoints.js
Normal file
@ -0,0 +1,134 @@
|
|||||||
|
(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];
|
||||||
|
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.
|
||||||
|
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(", "))));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
})();
|
10
postinit.js
10
postinit.js
@ -42,7 +42,7 @@ globalThis.modapi_postinit = "(" + (() => {
|
|||||||
if (!document.currentScript.hasAttribute("data-hash")) {
|
if (!document.currentScript.hasAttribute("data-hash")) {
|
||||||
return console.log("[ModAPIMeta] Script does not have a hashcode.");
|
return console.log("[ModAPIMeta] Script does not have a hashcode.");
|
||||||
}
|
}
|
||||||
ModAPI.meta._titleMap[document.currentScript.getAttribute("data-hash")] = limitSize(title, 16);
|
ModAPI.meta._titleMap[document.currentScript.getAttribute("data-hash")] = limitSize(title, 36);
|
||||||
}
|
}
|
||||||
ModAPI.meta.icon = function (iconSrc) {
|
ModAPI.meta.icon = function (iconSrc) {
|
||||||
if (!document.currentScript || document.currentScript.getAttribute("data-isMod") !== "true") {
|
if (!document.currentScript || document.currentScript.getAttribute("data-isMod") !== "true") {
|
||||||
@ -60,7 +60,7 @@ globalThis.modapi_postinit = "(" + (() => {
|
|||||||
if (!document.currentScript.hasAttribute("data-hash")) {
|
if (!document.currentScript.hasAttribute("data-hash")) {
|
||||||
return console.log("[ModAPIMeta] Script does not have a hashcode.");
|
return console.log("[ModAPIMeta] Script does not have a hashcode.");
|
||||||
}
|
}
|
||||||
ModAPI.meta._developerMap[document.currentScript.getAttribute("data-hash")] = limitSize(cd, 36);
|
ModAPI.meta._developerMap[document.currentScript.getAttribute("data-hash")] = limitSize(cd, 128);
|
||||||
}
|
}
|
||||||
ModAPI.meta.description = function (desc) {
|
ModAPI.meta.description = function (desc) {
|
||||||
if (!document.currentScript || document.currentScript.getAttribute("data-isMod") !== "true") {
|
if (!document.currentScript || document.currentScript.getAttribute("data-isMod") !== "true") {
|
||||||
@ -78,7 +78,7 @@ globalThis.modapi_postinit = "(" + (() => {
|
|||||||
if (!document.currentScript.hasAttribute("data-hash")) {
|
if (!document.currentScript.hasAttribute("data-hash")) {
|
||||||
return console.log("[ModAPIMeta] Script does not have a hashcode.");
|
return console.log("[ModAPIMeta] Script does not have a hashcode.");
|
||||||
}
|
}
|
||||||
ModAPI.meta._versionMap[document.currentScript.getAttribute("data-hash")] = limitSize(ver, 6);
|
ModAPI.meta._versionMap[document.currentScript.getAttribute("data-hash")] = limitSize(ver, 7);
|
||||||
}
|
}
|
||||||
ModAPI.reflect ||= {};
|
ModAPI.reflect ||= {};
|
||||||
ModAPI.server = ModAPI.serverInstance = null;
|
ModAPI.server = ModAPI.serverInstance = null;
|
||||||
@ -471,7 +471,7 @@ globalThis.modapi_postinit = "(" + (() => {
|
|||||||
}
|
}
|
||||||
ModAPI.events.listeners[name].push(callback);
|
ModAPI.events.listeners[name].push(callback);
|
||||||
}
|
}
|
||||||
console.log("[ModAPI] Added new library listener.");
|
console.log("[ModAPI] Added new library listener: " + name);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!callback || typeof callback !== "function") {
|
if (!callback || typeof callback !== "function") {
|
||||||
@ -482,7 +482,7 @@ globalThis.modapi_postinit = "(" + (() => {
|
|||||||
ModAPI.events.listeners[name] = [];
|
ModAPI.events.listeners[name] = [];
|
||||||
}
|
}
|
||||||
ModAPI.events.listeners[name].push(callback);
|
ModAPI.events.listeners[name].push(callback);
|
||||||
console.log("[ModAPI] Added new event listener.");
|
console.log("[ModAPI] Added new event listener: " + name);
|
||||||
} else {
|
} else {
|
||||||
throw new Error("[ModAPI] This event does not exist!");
|
throw new Error("[ModAPI] This event does not exist!");
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user