mirror of
https://github.com/eaglerforge/EaglerForgeInjector
synced 2025-07-24 22:51:18 -09:00
frame event, scaledresolution, crafting postprocessing for LCI
This commit is contained in:
parent
c1234e997b
commit
8d4a8152be
@ -39,7 +39,9 @@ Events broadcast data for use in mods.
|
|||||||
- String representing the type of event being fired.
|
- String representing the type of event being fired.
|
||||||
- `data: Object`
|
- `data: Object`
|
||||||
- Object representing the original arguments to be passed to the callback.
|
- 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.
|
||||||
### Server Side Events
|
### Server Side Events
|
||||||
Can only be used in the context of the dedicated server. More: [DedicatedServerDocumentation](dedicatedserver.md)
|
Can only be used in the context of the dedicated server. More: [DedicatedServerDocumentation](dedicatedserver.md)
|
||||||
- `serverstart`:
|
- `serverstart`:
|
||||||
|
@ -59,6 +59,10 @@ The global object has the following properties:
|
|||||||
- `ModAPI.array`
|
- `ModAPI.array`
|
||||||
- This object is used to interact and create arrays easily.
|
- This object is used to interact and create arrays easily.
|
||||||
- More: [ArrayDocumentation](array.md)
|
- More: [ArrayDocumentation](array.md)
|
||||||
|
- `ModAPI.resolution`
|
||||||
|
- This object 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`
|
- `ModAPI.version: String`
|
||||||
- The version of ModAPI.
|
- The version of ModAPI.
|
||||||
- `ModAPI.flavour: String`
|
- `ModAPI.flavour: String`
|
||||||
|
@ -6,11 +6,12 @@
|
|||||||
ModAPI.meta.description("Library to make adding basic custom items easier.");
|
ModAPI.meta.description("Library to make adding basic custom items easier.");
|
||||||
ModAPI.events.newEvent("lib:libcustomitems:loaded");
|
ModAPI.events.newEvent("lib:libcustomitems:loaded");
|
||||||
function libServerside() {
|
function libServerside() {
|
||||||
var packetblockchange = ModAPI.reflect.getClassByName("S23PacketBlockChange").constructors.find(x => {return x.length === 2});
|
var packetblockchange = ModAPI.reflect.getClassByName("S23PacketBlockChange").constructors.find(x => { return x.length === 2 });
|
||||||
var sendPacket = ModAPI.reflect.getClassByName("NetHandlerPlayServer").methods.sendPacket.method;
|
var sendPacket = ModAPI.reflect.getClassByName("NetHandlerPlayServer").methods.sendPacket.method;
|
||||||
globalThis.LCI_REGISTRY ||= [];
|
globalThis.LCI_REGISTRY ||= [];
|
||||||
globalThis.LCI_RMBEVENTS ||= {};
|
globalThis.LCI_RMBEVENTS ||= {};
|
||||||
globalThis.LCI_LMBEVENTS ||= {};
|
globalThis.LCI_LMBEVENTS ||= {};
|
||||||
|
globalThis.LCI_RECIPEEVENTS ||= {};
|
||||||
var useName = ModAPI.util.getMethodFromPackage("net.minecraft.network.NetHandlerPlayServer", "processPlayerBlockPlacement");
|
var useName = ModAPI.util.getMethodFromPackage("net.minecraft.network.NetHandlerPlayServer", "processPlayerBlockPlacement");
|
||||||
var oldUse = ModAPI.hooks.methods[useName];
|
var oldUse = ModAPI.hooks.methods[useName];
|
||||||
ModAPI.hooks.methods[useName] = function ($this, packet) {
|
ModAPI.hooks.methods[useName] = function ($this, packet) {
|
||||||
@ -61,15 +62,15 @@
|
|||||||
var statusTag = Object.keys(packet.$status).find(x => { return x.startsWith("$name") });
|
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 positionTag = Object.keys(packet).filter(x => { return x.startsWith("$position") })[0];
|
||||||
var stat = ModAPI.util.unstr(packet.$status[statusTag]);
|
var stat = ModAPI.util.unstr(packet.$status[statusTag]);
|
||||||
if (stat === "START_DESTROY_BLOCK") {
|
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]));
|
sendPacket($this, packetblockchange($this.$serverController.$worldServerForDimension($this.$playerEntity.$dimension), packet[positionTag]));
|
||||||
}
|
}
|
||||||
if (stat !== "START_DESTROY_BLOCK") {
|
return 0;
|
||||||
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,
|
var r = globalThis.LCI_LMBEVENTS[cid].call(globalThis,
|
||||||
new Proxy($this.$playerEntity, ModAPI.util.TeaVM_to_Recursive_BaseData_ProxyConf),
|
new Proxy($this.$playerEntity, ModAPI.util.TeaVM_to_Recursive_BaseData_ProxyConf),
|
||||||
@ -91,6 +92,7 @@
|
|||||||
globalThis.LCI_REGISTRY ||= [];
|
globalThis.LCI_REGISTRY ||= [];
|
||||||
globalThis.LCI_RMBEVENTS ||= {};
|
globalThis.LCI_RMBEVENTS ||= {};
|
||||||
globalThis.LCI_LMBEVENTS ||= {};
|
globalThis.LCI_LMBEVENTS ||= {};
|
||||||
|
globalThis.LCI_RECIPEEVENTS ||= {};
|
||||||
globalThis.LCI_REGISTRY.push(data.tag);
|
globalThis.LCI_REGISTRY.push(data.tag);
|
||||||
if (data.onRightClickGround) {
|
if (data.onRightClickGround) {
|
||||||
globalThis.LCI_RMBEVENTS[data.tag] = new Function("user", "world", "itemstack", "blockpos", data.onRightClickGround);
|
globalThis.LCI_RMBEVENTS[data.tag] = new Function("user", "world", "itemstack", "blockpos", data.onRightClickGround);
|
||||||
@ -98,6 +100,9 @@
|
|||||||
if (data.onLeftClickGround) {
|
if (data.onLeftClickGround) {
|
||||||
globalThis.LCI_LMBEVENTS[data.tag] = new Function("user", "world", "itemstack", "blockpos", 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;
|
var ObjectClass = ModAPI.reflect.getClassById("java.lang.Object").class;
|
||||||
function ToChar(char) {
|
function ToChar(char) {
|
||||||
return ModAPI.reflect.getClassById("java.lang.Character").staticMethods.valueOf.method(char[0].charCodeAt(0));
|
return ModAPI.reflect.getClassById("java.lang.Character").staticMethods.valueOf.method(char[0].charCodeAt(0));
|
||||||
@ -132,6 +137,9 @@
|
|||||||
var lore = ModAPI.reflect.getClassById("net.minecraft.nbt.NBTTagList").constructors[0]();
|
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)));
|
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);
|
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));
|
||||||
|
}
|
||||||
|
|
||||||
var craftingManager = ModAPI.reflect.getClassById("net.minecraft.item.crafting.CraftingManager").staticMethods.getInstance.method();
|
var craftingManager = ModAPI.reflect.getClassById("net.minecraft.item.crafting.CraftingManager").staticMethods.getInstance.method();
|
||||||
ModAPI.hooks.methods.nmic_CraftingManager_addRecipe(craftingManager, testItem, recipe);
|
ModAPI.hooks.methods.nmic_CraftingManager_addRecipe(craftingManager, testItem, recipe);
|
||||||
|
@ -648,6 +648,18 @@ globalThis.modapi_postinit = `(() => {
|
|||||||
return sendChatMessage.apply(this, [$this, $message]);
|
return sendChatMessage.apply(this, [$this, $message]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const ScaledResolutionConstructor = ModAPI.reflect.getClassByName("ScaledResolution").constructors[0];
|
||||||
|
ModAPI.events.newEvent("frame", "client");
|
||||||
|
const frameMethodName = ModAPI.util.getMethodFromPackage("net.minecraft.client.Minecraft", "runTick");
|
||||||
|
const frameMethod = ModAPI.hooks.methods[frameMethodName];
|
||||||
|
ModAPI.hooks.methods[frameMethodName] = function (...args) {
|
||||||
|
ModAPI.events.callEvent("frame", {});
|
||||||
|
if (ModAPI.required.has("resolution") && ModAPI.mcinstance) {
|
||||||
|
ModAPI.ScaledResolution = ModAPI.resolution = new Proxy(ScaledResolutionConstructor(ModAPI.mcinstance), TeaVM_to_Recursive_BaseData_ProxyConf);
|
||||||
|
}
|
||||||
|
return frameMethod.apply(this, args);
|
||||||
|
}
|
||||||
|
|
||||||
ModAPI.events.newEvent("tick", "server");
|
ModAPI.events.newEvent("tick", "server");
|
||||||
const serverTickMethodName = ModAPI.util.getMethodFromPackage("net.minecraft.server.MinecraftServer", "tick");
|
const serverTickMethodName = ModAPI.util.getMethodFromPackage("net.minecraft.server.MinecraftServer", "tick");
|
||||||
const serverTickMethod = ModAPI.hooks.methods[serverTickMethodName];
|
const serverTickMethod = ModAPI.hooks.methods[serverTickMethodName];
|
||||||
|
12
postinit.js
12
postinit.js
@ -648,6 +648,18 @@
|
|||||||
return sendChatMessage.apply(this, [$this, $message]);
|
return sendChatMessage.apply(this, [$this, $message]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const ScaledResolutionConstructor = ModAPI.reflect.getClassByName("ScaledResolution").constructors[0];
|
||||||
|
ModAPI.events.newEvent("frame", "client");
|
||||||
|
const frameMethodName = ModAPI.util.getMethodFromPackage("net.minecraft.client.Minecraft", "runTick");
|
||||||
|
const frameMethod = ModAPI.hooks.methods[frameMethodName];
|
||||||
|
ModAPI.hooks.methods[frameMethodName] = function (...args) {
|
||||||
|
ModAPI.events.callEvent("frame", {});
|
||||||
|
if (ModAPI.required.has("resolution") && ModAPI.mcinstance) {
|
||||||
|
ModAPI.ScaledResolution = ModAPI.resolution = new Proxy(ScaledResolutionConstructor(ModAPI.mcinstance), TeaVM_to_Recursive_BaseData_ProxyConf);
|
||||||
|
}
|
||||||
|
return frameMethod.apply(this, args);
|
||||||
|
}
|
||||||
|
|
||||||
ModAPI.events.newEvent("tick", "server");
|
ModAPI.events.newEvent("tick", "server");
|
||||||
const serverTickMethodName = ModAPI.util.getMethodFromPackage("net.minecraft.server.MinecraftServer", "tick");
|
const serverTickMethodName = ModAPI.util.getMethodFromPackage("net.minecraft.server.MinecraftServer", "tick");
|
||||||
const serverTickMethod = ModAPI.hooks.methods[serverTickMethodName];
|
const serverTickMethod = ModAPI.hooks.methods[serverTickMethodName];
|
||||||
|
Loading…
x
Reference in New Issue
Block a user