mirror of
https://github.com/eaglerforge/EaglerForgeInjector
synced 2025-07-23 14:11:16 -09:00
patches beginnings, corrective basedatas
This commit is contained in:
parent
9fd38d89d1
commit
e6d0aae86e
@ -1,41 +1,44 @@
|
||||
PluginAPI.require("player"); //Require the player
|
||||
var 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
|
||||
if (!PluginAPI.player.fishEntity) { //If the fish hook does not exist.
|
||||
if (GrappleHookPlugin.prev === "GROUND" && (!GrappleHookPlugin.crouchToCancel || !PluginAPI.player.isSneaking())) { //If the old state was ground
|
||||
GrappleHookPlugin.prev = "NONE"; //Update the state
|
||||
var mx = GrappleHookPlugin.oldXYZ[0] - PluginAPI.player.posX; //Get delta X
|
||||
var my = GrappleHookPlugin.oldXYZ[1] - PluginAPI.player.posY; //Get delta Y
|
||||
var mz = GrappleHookPlugin.oldXYZ[2] - PluginAPI.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
|
||||
PluginAPI.player.motionX += mx; //Add x motion
|
||||
PluginAPI.player.motionY += my + GrappleHookPlugin.lift; //Add y motion, plus base lift.
|
||||
PluginAPI.player.motionZ += mz; //Add z motion
|
||||
} else {
|
||||
GrappleHookPlugin.prev = "NONE";
|
||||
(function grapplehook() {
|
||||
PluginAPI.require("player"); //Require the player
|
||||
var 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.
|
||||
};
|
||||
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.
|
||||
PluginAPI.addEventListener("update", () => { //Every client tick
|
||||
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";
|
||||
}
|
||||
} else if (GrappleHookPlugin.prev === "NONE") { //If the hook exists, but the previous state was NONE, update the state.
|
||||
GrappleHookPlugin.prev = "AIR";
|
||||
}
|
||||
if (
|
||||
PluginAPI.player.fishEntity !== undefined && //If the fish hook exists
|
||||
GrappleHookPlugin.prev === "AIR" && //And the hook was previously in the air
|
||||
PluginAPI.player.fishEntity[PluginAPI.util.getNearestProperty(ModAPI.player.fishEntity, "inGround")] //And the hook is in the ground (the inGround property is botched with random suffixes sometimes)
|
||||
) {
|
||||
GrappleHookPlugin.oldXYZ = [ //Set old grapple hook position
|
||||
PluginAPI.player.fishEntity.posX,
|
||||
PluginAPI.player.fishEntity.posY,
|
||||
PluginAPI.player.fishEntity.posZ,
|
||||
];
|
||||
GrappleHookPlugin.prev = "GROUND";//Update state
|
||||
}
|
||||
if (
|
||||
player.fishEntity !== undefined && //If the fish hook exists
|
||||
GrappleHookPlugin.prev === "AIR" && //And the hook was previously in the air
|
||||
player.fishEntity.inGround //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
|
||||
}
|
||||
});
|
||||
});
|
13
patches.js
Normal file
13
patches.js
Normal file
@ -0,0 +1,13 @@
|
||||
class PatchesRegistry {
|
||||
static patchedEventNames = []
|
||||
static patchedEventNames = []
|
||||
static getEventInjectorCode() {
|
||||
return globalThis.modapi_specialevents = "[" + PatchesRegistry.patchedEventNames.flatMap(x=>`\`${x}\``).join(",") + "]"
|
||||
}
|
||||
}
|
||||
function addPatch(params) {
|
||||
|
||||
}
|
||||
function addSpecialEvent(eventName) {
|
||||
|
||||
}
|
86
postinit.js
86
postinit.js
@ -114,26 +114,40 @@ globalThis.modapi_postinit = "(" + (() => {
|
||||
});
|
||||
return name;
|
||||
}
|
||||
ModAPI.util.wrap = function (outputValue, target) {
|
||||
ModAPI.util.wrap = function (outputValue, target, corrective) {
|
||||
const CorrectiveArray = patchProxyConfToCorrective(ModAPI.util.TeaVMArray_To_Recursive_BaseData_ProxyConf);
|
||||
const CorrectiveRecursive = patchProxyConfToCorrective(ModAPI.util.TeaVM_to_Recursive_BaseData_ProxyConf);
|
||||
if (outputValue && typeof outputValue === "object" && Array.isArray(outputValue.data) && typeof outputValue.type === "function") {
|
||||
if (corrective) {
|
||||
return new Proxy(outputValue.data, CorrectiveArray);
|
||||
}
|
||||
return new Proxy(outputValue.data, ModAPI.util.TeaVMArray_To_Recursive_BaseData_ProxyConf);
|
||||
}
|
||||
if (outputValue && typeof outputValue === "object" && !Array.isArray(outputValue)) {
|
||||
if (corrective) {
|
||||
return new Proxy(outputValue.data, CorrectiveRecursive);
|
||||
}
|
||||
return new Proxy(outputValue, ModAPI.util.TeaVM_to_Recursive_BaseData_ProxyConf);
|
||||
}
|
||||
if (outputValue && typeof outputValue === "function" && target) {
|
||||
return function (...args) {
|
||||
var xOut = outputValue.apply(target, args);
|
||||
if (xOut && typeof xOut === "object" && Array.isArray(xOut.data) && typeof outputValue.type === "function") {
|
||||
if (corrective) {
|
||||
return new Proxy(outputValue.data, CorrectiveArray);
|
||||
}
|
||||
return new Proxy(xOut.data, ModAPI.util.TeaVMArray_To_Recursive_BaseData_ProxyConf);
|
||||
}
|
||||
if (xOut && typeof xOut === "object" && !Array.isArray(xOut)) {
|
||||
if (corrective) {
|
||||
return new Proxy(outputValue.data, CorrectiveRecursive);
|
||||
}
|
||||
return new Proxy(xOut, ModAPI.util.TeaVM_to_Recursive_BaseData_ProxyConf);
|
||||
}
|
||||
return xOut;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
return outputValue;
|
||||
}
|
||||
ModAPI.array.object = function (jclass, size) {
|
||||
if (Array.isArray(size)) {
|
||||
@ -295,61 +309,18 @@ globalThis.modapi_postinit = "(" + (() => {
|
||||
return key ? ModAPI.hooks._classMap[key] : null;
|
||||
}
|
||||
var reloadDeprecationWarnings = 0;
|
||||
const TeaVM_to_BaseData_ProxyConf = {
|
||||
ownKeys(target) {
|
||||
return Reflect.ownKeys(target).flatMap(x => x.substring(1));
|
||||
},
|
||||
getOwnPropertyDescriptor(target, prop) {
|
||||
return Object.getOwnPropertyDescriptor(target, "$" + prop);
|
||||
},
|
||||
has(target, prop) {
|
||||
return ("$" + prop) in target;
|
||||
},
|
||||
get(target, prop, receiver) {
|
||||
if (prop === "getRef") {
|
||||
return function () {
|
||||
return target;
|
||||
}
|
||||
}
|
||||
if (prop === "reload") {
|
||||
return function () {
|
||||
if (reloadDeprecationWarnings < 10) {
|
||||
console.warn("ModAPI/PluginAPI reload() is obsolete, please stop using it in code.")
|
||||
reloadDeprecationWarnings++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var outProp = "$" + prop;
|
||||
var outputValue = Reflect.get(target, outProp, receiver);
|
||||
if (outputValue && typeof outputValue === "object" && Array.isArray(outputValue.data) && typeof outputValue.type === "function") {
|
||||
return outputValue.data;
|
||||
}
|
||||
if (outputValue && typeof outputValue === "function") {
|
||||
return function (...args) {
|
||||
return outputValue.apply(target, args);
|
||||
}
|
||||
}
|
||||
return outputValue;
|
||||
},
|
||||
set(object, prop, value) {
|
||||
var outProp = "$" + prop;
|
||||
object[outProp] = value;
|
||||
return true;
|
||||
},
|
||||
};
|
||||
const TeaVMArray_To_Recursive_BaseData_ProxyConf = {
|
||||
get(target, prop, receiver) {
|
||||
var outputValue = Reflect.get(target, prop, receiver);
|
||||
if (outputValue && typeof outputValue === "object" && !Array.isArray(outputValue)) {
|
||||
return new Proxy(outputValue, TeaVM_to_Recursive_BaseData_ProxyConf);
|
||||
return ModAPI.util.wrap(outputValue, target, this._corrective);
|
||||
}
|
||||
if (prop === "getRef") {
|
||||
return function () {
|
||||
return target;
|
||||
}
|
||||
}
|
||||
return outputValue;
|
||||
return ModAPI.util.wrap(outputValue, target, this._corrective);
|
||||
},
|
||||
set(object, prop, value) {
|
||||
object[prop] = value;
|
||||
@ -367,6 +338,16 @@ globalThis.modapi_postinit = "(" + (() => {
|
||||
return ("$" + prop) in target;
|
||||
},
|
||||
get(target, prop, receiver) {
|
||||
if (prop === "getCorrective") {
|
||||
return function () {
|
||||
return new Proxy(target, patchProxyConfToCorrective(TeaVM_to_Recursive_BaseData_ProxyConf));
|
||||
}
|
||||
}
|
||||
if (prop === "isCorrective") {
|
||||
return function () {
|
||||
return !!this._corrective;
|
||||
}
|
||||
}
|
||||
if (prop === "getRef") {
|
||||
return function () {
|
||||
return target;
|
||||
@ -382,8 +363,11 @@ globalThis.modapi_postinit = "(" + (() => {
|
||||
}
|
||||
|
||||
var outProp = "$" + prop;
|
||||
if (this._corrective) {
|
||||
outProp = ModAPI.util.getNearestProperty(target, outProp);
|
||||
}
|
||||
var outputValue = Reflect.get(target, outProp, receiver);
|
||||
var wrapped = ModAPI.util.wrap(outputValue, target);
|
||||
var wrapped = ModAPI.util.wrap(outputValue, target, this._corrective);
|
||||
if (wrapped) {
|
||||
return wrapped;
|
||||
}
|
||||
@ -395,6 +379,11 @@ globalThis.modapi_postinit = "(" + (() => {
|
||||
return true;
|
||||
},
|
||||
};
|
||||
function patchProxyConfToCorrective(conf) {
|
||||
var pconf = Object.assign({}, conf);
|
||||
pconf._corrective = true;
|
||||
return pconf;
|
||||
}
|
||||
const StaticProps_ProxyConf = {
|
||||
get(target, prop, receiver) {
|
||||
var outProp = prop;
|
||||
@ -413,7 +402,6 @@ globalThis.modapi_postinit = "(" + (() => {
|
||||
return true;
|
||||
},
|
||||
};
|
||||
ModAPI.util.TeaVM_to_BaseData_ProxyConf = TeaVM_to_BaseData_ProxyConf;
|
||||
ModAPI.util.TeaVMArray_To_Recursive_BaseData_ProxyConf = TeaVMArray_To_Recursive_BaseData_ProxyConf;
|
||||
ModAPI.util.TeaVM_to_Recursive_BaseData_ProxyConf = TeaVM_to_Recursive_BaseData_ProxyConf;
|
||||
ModAPI.util.StaticProps_ProxyConf = StaticProps_ProxyConf;
|
||||
|
Loading…
x
Reference in New Issue
Block a user