mirror of
https://github.com/eaglerforge/EaglerForgeInjector
synced 2025-07-23 14:11:16 -09:00
version meta, even bigger char limits, and test blocklook plugin
This commit is contained in:
parent
1f32472c01
commit
cd8121ad22
@ -5,9 +5,9 @@ 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 24.
|
||||
- Sets the credits of the mod. Character limit of 36.
|
||||
- `ModAPI.meta.description(desc: String)`
|
||||
- Sets the description of the mod. Character limit of 64.
|
||||
- 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.
|
73
examplemods/blocklook.js
Normal file
73
examplemods/blocklook.js
Normal file
@ -0,0 +1,73 @@
|
||||
//WIP Blocklook plugin
|
||||
//If someone can fix the crash, thank you and also i'll add you to credits.
|
||||
ModAPI.meta.title("BlockLook");
|
||||
ModAPI.meta.credits("Made with ❤️ by ZXMushroom63");
|
||||
ModAPI.meta.icon("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAPlJREFUOE+Fk7EVwjAMRM8TQJEmS0DBBtAwBEtQwBBkCBqGoIEhsgFNGrKDeOdEjuw4Rk1eLN33WbIdAEEmROJl51yuDFyVtFgrVVTKZwEqfAnQAjiPm+dcRQAVfkchnRCg33sCYn0ABLsd0NeTiACFfAC8DSQLoFS6AUDQFQCFDBX7GhHMAPIE3HFqNkGHOhZWAvSuAFC/jlvbkIv/q9AUADdz4Ad8g3xwHHvtBBPNwhEUMHYuAuwArJgoAU5mZm3iIAAAuO2CAwLM4GcOyKeLHIC5cBc2A2gGWA8reiOjMdqGLz2cv1c5GdzkKHmZWhccpEJr0xbn6n64M6oBwREDxAAAAABJRU5ErkJggg==");
|
||||
ModAPI.meta.description("EaglerForge port of the bukkit BlockLook plugin by GeorgeNotFound. Use /blocklook in a single-player world to toggle the plugin.");
|
||||
ModAPI.dedicatedServer.appendCode(function () {
|
||||
var worldMethodMap = ModAPI.reflect.getClassById("net.minecraft.world.World").methods;
|
||||
var rayTraceMethod = worldMethodMap[Object.keys(worldMethodMap).filter(key => {
|
||||
return key.startsWith("rayTraceBlocks") && worldMethodMap[key].method.length === 4;
|
||||
})].method;
|
||||
var blockPosConstructor = ModAPI.reflect.getClassById("net.minecraft.util.BlockPos").constructors.find((x) => { return x.length === 3 });
|
||||
var blockStateConstructor = ModAPI.reflect.getClassByName("BlockState").constructors[0];
|
||||
var blockTypesList = Object.keys(ModAPI.blocks);
|
||||
var iproperty = ModAPI.reflect.getClassById("net.minecraft.block.property.IProperty").class;
|
||||
function getPlayerEntitiesAndTheirWorld() {
|
||||
var out = [];
|
||||
ModAPI.server.worldServers.forEach(x => {
|
||||
var list = x.playerEntities;
|
||||
var size = list.size();
|
||||
for (let i = 0; i < size; i++) {
|
||||
const playerEntity = list.get(i);
|
||||
if (playerEntity) {
|
||||
out.push({
|
||||
world: x,
|
||||
player: playerEntity
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
return out;
|
||||
};
|
||||
var active = false;
|
||||
ModAPI.addEventListener("processcommand", (event) => {
|
||||
if (event.command.toLowerCase().startsWith("/blocklook")) {
|
||||
active = !active;
|
||||
var playerEntities = getPlayerEntitiesAndTheirWorld();
|
||||
playerEntities.forEach(pair => {
|
||||
pair.player.addChatMessage(
|
||||
ModAPI.reflect.getClassById("net.minecraft.util.ChatComponentText").constructors[0](ModAPI.util.str(
|
||||
"[BlockLook] Toggled to " + (active ? "on" : off)
|
||||
))
|
||||
)
|
||||
});
|
||||
event.preventDefault = true;
|
||||
}
|
||||
});
|
||||
ModAPI.addEventListener("tick", () => {
|
||||
if (!active) {
|
||||
return;
|
||||
}
|
||||
active = false; //Don't run every tick, for debugging purposes.
|
||||
var playerEntities = getPlayerEntitiesAndTheirWorld();
|
||||
playerEntities.forEach(pair => {
|
||||
var start = pair.player.getPositionEyes(1).getRef();
|
||||
var lookVector = pair.player.getLook(1);
|
||||
lookVector.xCoord *= 50;
|
||||
lookVector.yCoord *= 50;
|
||||
lookVector.zCoord *= 50;
|
||||
lookVector.addVector(start.$xCoord, start.$yCoord, start.$zCoord);
|
||||
var hitResult = rayTraceMethod(pair.world.getRef(), start, lookVector.getRef(), 0);
|
||||
console.log("trace complete.");
|
||||
if (hitResult) {
|
||||
console.log("Attempting to set world state.");
|
||||
var blockPos = blockPosConstructor(hitResult.$hitVec.$xCoord, hitResult.$hitVec.$yCoord, hitResult.$hitVec.$zCoord);
|
||||
var blockType = blockTypesList[Math.floor(Math.random() * blockTypesList.length)];
|
||||
blockType = ModAPI.blocks[blockType];
|
||||
pair.world.setBlockState(blockPos, blockStateConstructor(blockType.getRef(), ModAPI.util.makeArray(iproperty, [])), 0);
|
||||
}
|
||||
console.log("sub complete");
|
||||
});
|
||||
});
|
||||
});
|
@ -201,7 +201,7 @@ globalThis.modapi_guikit = `// ModAPI GUI made by TheIdiotPlays
|
||||
var h4 = document.createElement("h4");
|
||||
h4.style.margin = 0;
|
||||
h4.style.padding = 0;
|
||||
h4.innerText = ModAPI.meta._titleMap[hash];
|
||||
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");
|
||||
|
@ -201,7 +201,7 @@
|
||||
var h4 = document.createElement("h4");
|
||||
h4.style.margin = 0;
|
||||
h4.style.padding = 0;
|
||||
h4.innerText = ModAPI.meta._titleMap[hash];
|
||||
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");
|
||||
|
@ -19,6 +19,7 @@ globalThis.modapi_postinit = `(() => {
|
||||
ModAPI.meta._descriptionMap = {};
|
||||
ModAPI.meta._developerMap = {};
|
||||
ModAPI.meta._iconMap = {};
|
||||
ModAPI.meta._versionMap = {};
|
||||
function limitSize(x, n) {
|
||||
if (x.length > n) {
|
||||
return x.substring(0, n) + "…";
|
||||
@ -51,7 +52,7 @@ globalThis.modapi_postinit = `(() => {
|
||||
if (!document.currentScript.hasAttribute("data-hash")) {
|
||||
return console.log("[ModAPIMeta] Script does not have a hashcode.");
|
||||
}
|
||||
ModAPI.meta._developerMap[document.currentScript.getAttribute("data-hash")] = limitSize(cd, 24);
|
||||
ModAPI.meta._developerMap[document.currentScript.getAttribute("data-hash")] = limitSize(cd, 36);
|
||||
}
|
||||
ModAPI.meta.description = function (desc) {
|
||||
if (!document.currentScript || document.currentScript.getAttribute("data-isMod") !== "true") {
|
||||
@ -60,7 +61,16 @@ globalThis.modapi_postinit = `(() => {
|
||||
if (!document.currentScript.hasAttribute("data-hash")) {
|
||||
return console.log("[ModAPIMeta] Script does not have a hashcode.");
|
||||
}
|
||||
ModAPI.meta._descriptionMap[document.currentScript.getAttribute("data-hash")] = limitSize(desc, 64);
|
||||
ModAPI.meta._descriptionMap[document.currentScript.getAttribute("data-hash")] = limitSize(desc, 160);
|
||||
}
|
||||
ModAPI.meta.version = function (ver) {
|
||||
if (!document.currentScript || document.currentScript.getAttribute("data-isMod") !== "true") {
|
||||
return console.log("[ModAPIMeta] Cannot set meta for non-mod script.");
|
||||
}
|
||||
if (!document.currentScript.hasAttribute("data-hash")) {
|
||||
return console.log("[ModAPIMeta] Script does not have a hashcode.");
|
||||
}
|
||||
ModAPI.meta._versionMap[document.currentScript.getAttribute("data-hash")] = limitSize(ver, 6);
|
||||
}
|
||||
ModAPI.reflect ||= {};
|
||||
ModAPI.server = ModAPI.serverInstance = null;
|
||||
|
14
postinit.js
14
postinit.js
@ -19,6 +19,7 @@
|
||||
ModAPI.meta._descriptionMap = {};
|
||||
ModAPI.meta._developerMap = {};
|
||||
ModAPI.meta._iconMap = {};
|
||||
ModAPI.meta._versionMap = {};
|
||||
function limitSize(x, n) {
|
||||
if (x.length > n) {
|
||||
return x.substring(0, n) + "…";
|
||||
@ -51,7 +52,7 @@
|
||||
if (!document.currentScript.hasAttribute("data-hash")) {
|
||||
return console.log("[ModAPIMeta] Script does not have a hashcode.");
|
||||
}
|
||||
ModAPI.meta._developerMap[document.currentScript.getAttribute("data-hash")] = limitSize(cd, 24);
|
||||
ModAPI.meta._developerMap[document.currentScript.getAttribute("data-hash")] = limitSize(cd, 36);
|
||||
}
|
||||
ModAPI.meta.description = function (desc) {
|
||||
if (!document.currentScript || document.currentScript.getAttribute("data-isMod") !== "true") {
|
||||
@ -60,7 +61,16 @@
|
||||
if (!document.currentScript.hasAttribute("data-hash")) {
|
||||
return console.log("[ModAPIMeta] Script does not have a hashcode.");
|
||||
}
|
||||
ModAPI.meta._descriptionMap[document.currentScript.getAttribute("data-hash")] = limitSize(desc, 64);
|
||||
ModAPI.meta._descriptionMap[document.currentScript.getAttribute("data-hash")] = limitSize(desc, 160);
|
||||
}
|
||||
ModAPI.meta.version = function (ver) {
|
||||
if (!document.currentScript || document.currentScript.getAttribute("data-isMod") !== "true") {
|
||||
return console.log("[ModAPIMeta] Cannot set meta for non-mod script.");
|
||||
}
|
||||
if (!document.currentScript.hasAttribute("data-hash")) {
|
||||
return console.log("[ModAPIMeta] Script does not have a hashcode.");
|
||||
}
|
||||
ModAPI.meta._versionMap[document.currentScript.getAttribute("data-hash")] = limitSize(ver, 6);
|
||||
}
|
||||
ModAPI.reflect ||= {};
|
||||
ModAPI.server = ModAPI.serverInstance = null;
|
||||
|
Loading…
x
Reference in New Issue
Block a user