Skip to content

Commit

Permalink
Merge pull request #20 from eaglerforge/main
Browse files Browse the repository at this point in the history
Update stable to latest
  • Loading branch information
ZXMushroom63 authored Oct 1, 2024
2 parents 8237541 + 9fd38d8 commit 85ad018
Show file tree
Hide file tree
Showing 17 changed files with 547 additions and 23 deletions.
14 changes: 13 additions & 1 deletion docs/apidoc/utils.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,16 @@ Methods:
- `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.
- 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
```
26 changes: 25 additions & 1 deletion examplemods/AsyncSink.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
ModAPI.meta.title("AsyncSink");
ModAPI.meta.description("Library for patching and hooking into asynchronous filesystem requests for EaglercraftX.");
ModAPI.meta.icon("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABIAAAASCAYAAABWzo5XAAAAAXNSR0IArs4c6QAAAL9JREFUOE9jZGBg+M9ABcAIMsgtPo3hzZ2zYONEVIxJZu9aOIsBbJCRtTHcEJAgLgBSh82ic0fPIgyCKQAJXrx4EcUsfX19sBiIRrYU5gu4Qchew2cQyHSQYehBgdNruFwEcybMZci+gIcRIa+hhxu6LzBiDZvX0A1BDyuivYbLIJK8pqevjze5GlsbMxAdayCT/PQwDRS2gaQror2m36KH4SqjZybwxEl0gsQWRkM01ogpVQh6jaJihBgXEFIDAAIQ9AFDJlrxAAAAAElFTkSuQmCC");
ModAPI.meta.credits("By ZXMushroom63");
(function AsyncSinkFn() {
//AsyncSink is a plugin to debug and override asynchronous methods in EaglercraftX
function runtimeComponent() {
Expand Down Expand Up @@ -76,7 +80,11 @@
}
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);
};

Expand All @@ -92,6 +100,11 @@
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);
};

Expand All @@ -107,6 +120,11 @@
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);
};

Expand All @@ -122,10 +140,16 @@
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);
};
globalThis.AsyncSink = AsyncSink;
ModAPI.events.callEvent("lib:asyncsink", {});
console.log("[AsyncSink] Loaded!");
}
runtimeComponent();
ModAPI.dedicatedServer.appendCode(runtimeComponent);
Expand Down
116 changes: 116 additions & 0 deletions examplemods/astar.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
(function AStarPathfinding() {
ModAPI.meta.title("A* Pathfinding Bot");
ModAPI.meta.description("Use #move <x> <y> <z> to instruct the bot to move somewhere. Use #stop to terminate the job.");
ModAPI.meta.credits("By ZXMushroom63");

ModAPI.require("player");
ModAPI.require("world");

var blockBreakCostMultiplier = 2;
const costMap = Object.fromEntries(Object.keys(ModAPI.blocks).flatMap(x => {
ModAPI.blocks[x].readableId = x;
return [x, (Math.floor(ModAPI.blocks[x].blockHardness * 10 * blockBreakCostMultiplier) + 1) || 99999]; //Block hardness is in decimals, unbreakable blocks are negative one, and base movement cost is 1. -1 + 1 = 0, and 0 || 99999 is 99999
}));

var makeBlockPos = ModAPI.reflect.getClassById("net.minecraft.util.BlockPos").constructors.find(x=>x.length === 3);

function shouldPause(x, y, z) {
return !ModAPI.world.isAreaLoaded0(makeBlockPos(x, y, z), 2);
}

class APNode {
constructor(x, y, z, g, h, parent = null) {
this.x = x;
this.y = y;
this.z = z;
this.g = g;
this.h = h;
this.f = g + h;
this.parent = parent;
}
}

function heuristic(a, b) {
return Math.abs(a.x - b.x) + Math.abs(a.y - b.y) + Math.abs(a.z - b.z);
}

function getNeighbors(node) {
const neighbors = [];
const directions = [
[1, 0, 0], [-1, 0, 0],
[0, 1, 0], [0, -1, 0],
[0, 0, 1], [0, 0, -1]
];

for (const [dx, dy, dz] of directions) {
const x = node.x + dx;
const y = node.y + dy;
const z = node.z + dz;

if (ModAPI.world.isBlockLoaded(makeBlockPos(Math.round(x), Math.round(y), Math.round(z)))) {
neighbors.push(new APNode(x, y, z, 0, 0));
}
}
return neighbors;
}

function lookupCost(x, y, z) {
var block = ModAPI.world.getBlockState(makeBlockPos(Math.round(x), Math.round(y), Math.round(z))).block;
return costMap[block.readableId];
}

function* aStar(start, goal) {
const openSet = [];
const closedSet = new Set();
openSet.push(start);

while (openSet.length > 0) {
let current = openSet.reduce((prev, curr) => (prev.f < curr.f ? prev : curr));

if (current.x === goal.x && current.y === goal.y && current.z === goal.z) {
const path = [];
while (current) {
path.push([current.x, current.y, current.z]);
current = current.parent;
}
yield* path.reverse();
return;
}

openSet.splice(openSet.indexOf(current), 1);
closedSet.add(`${current.x},${current.y},${current.z}`);

for (const neighbor of getNeighbors(current)) {
if (closedSet.has(`${neighbor.x},${neighbor.y},${neighbor.z}`)) {
continue;
}

const tentativeG = current.g + lookupCost(neighbor.x, neighbor.y, neighbor.z);

if (!openSet.some(node => node.x === neighbor.x && node.y === neighbor.y && node.z === neighbor.z)) {
neighbor.g = tentativeG;
neighbor.h = heuristic(neighbor, goal);
neighbor.f = neighbor.g + neighbor.h;
neighbor.parent = current;
openSet.push(neighbor);
} else {
const existingNode = openSet.find(node => node.x === neighbor.x && node.y === neighbor.y && node.z === neighbor.z);
if (tentativeG < existingNode.g) {
existingNode.g = tentativeG;
existingNode.f = existingNode.g + existingNode.h;
existingNode.parent = current;
}
}
}

yield [current.x, current.y, current.z];
}

return [];
}

const start = new APNode(0, 0, 0, 0, 0);
const goal = new APNode(2, 2, 2, 0, 0);

const pathGenerator = aStar(start, goal);
})();
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//NOT FUNCTIONAL
ModAPI.meta.title("Advanced VClip Exploit");
ModAPI.meta.description("Use .vclip <offset> to vertically phase through blocks with custom packet handling.");
ModAPI.meta.credits("By radmanplays");
Expand All @@ -11,7 +12,7 @@ ModAPI.require("player");
ModAPI.addEventListener("sendchatmessage", (ev) => {
var msg = ev.message.toLowerCase();
if (msg.startsWith(".vclip")) {
ev.preventDefault();
ev.preventDefault == true;

var args = msg.split(" ");
if (args.length != 2) {
Expand All @@ -38,23 +39,23 @@ ModAPI.addEventListener("sendchatmessage", (ev) => {
for (var packetNumber = 0; packetNumber < (packetsRequired - 1); packetNumber++) {
// Simulate entity movement
ridingEntity.posY += offset / packetsRequired; // Move a fraction of the total offset
player.sendQueue.addToSendQueue({
ModAPI.network.addToSendQueue({
"action": "RIDING_JUMP", // Simulate a riding jump action
"entityId": ridingEntity.getEntityId(),
});
}

// Final move
ridingEntity.posY += offset / packetsRequired;
player.sendQueue.addToSendQueue({
ModAPI.network.addToSendQueue({
"action": "RIDING_JUMP",
"entityId": ridingEntity.getEntityId(),
});

} else {
// Player is not riding any entity
for (var packetNumber = 0; packetNumber < (packetsRequired - 1); packetNumber++) {
player.getNetHandler().addToSendQueue({
ModAPI.network.addToSendQueue({
"x": player.posX,
"y": player.posY,
"z": player.posZ,
Expand All @@ -63,7 +64,7 @@ ModAPI.addEventListener("sendchatmessage", (ev) => {
}

// Final move
player.getNetHandler().addToSendQueue({
ModAPI.network.addToSendQueue({
"x": player.posX,
"y": player.posY + offset,
"z": player.posZ,
Expand Down
File renamed without changes.
Loading

0 comments on commit 85ad018

Please sign in to comment.