mirror of
https://github.com/eaglerforge/EaglerForgeInjector
synced 2025-07-23 06:01:38 -09:00
more comments
This commit is contained in:
parent
ed53410e44
commit
2b73cd8f31
@ -1,20 +1,42 @@
|
|||||||
|
//Metadata for the mod
|
||||||
ModAPI.meta.title("SimpleHats");
|
ModAPI.meta.title("SimpleHats");
|
||||||
ModAPI.meta.credits("Made with ❤️ by ZXMushroom63");
|
ModAPI.meta.credits("Made with ❤️ by ZXMushroom63");
|
||||||
ModAPI.meta.description("Use /hat to wear whatever you are holding!");
|
ModAPI.meta.description("Use /hat to wear whatever you are holding!");
|
||||||
|
|
||||||
|
// Run the code on the server
|
||||||
ModAPI.dedicatedServer.appendCode(function () {
|
ModAPI.dedicatedServer.appendCode(function () {
|
||||||
|
// Find the constructor for the held item change packet that has only one argument.
|
||||||
|
// This will be used to notify the client that their hotbar has been updated.
|
||||||
var makePacketItemChange = ModAPI.reflect.getClassByName("S09PacketHeldItemChange").constructors.find(x => x.length === 1);
|
var makePacketItemChange = ModAPI.reflect.getClassByName("S09PacketHeldItemChange").constructors.find(x => x.length === 1);
|
||||||
|
|
||||||
|
// Find the method for sending packets.
|
||||||
var sendPacket = ModAPI.reflect.getClassByName("NetHandlerPlayServer").methods.sendPacket.method;
|
var sendPacket = ModAPI.reflect.getClassByName("NetHandlerPlayServer").methods.sendPacket.method;
|
||||||
|
|
||||||
|
// When the server is processing a command
|
||||||
ModAPI.addEventListener("processcommand", (event) => {
|
ModAPI.addEventListener("processcommand", (event) => {
|
||||||
|
// If the command starts with /hat
|
||||||
if (event.command.toLowerCase().startsWith("/hat")) {
|
if (event.command.toLowerCase().startsWith("/hat")) {
|
||||||
|
// Cancel if the sender isn't a player
|
||||||
if (!ModAPI.reflect.getClassById("net.minecraft.entity.player.EntityPlayerMP").instanceOf(event.sender.getRef())) { return };
|
if (!ModAPI.reflect.getClassById("net.minecraft.entity.player.EntityPlayerMP").instanceOf(event.sender.getRef())) { return };
|
||||||
|
|
||||||
|
// Otherwise, get the current held item
|
||||||
var heldItem = event.sender.inventory.getCurrentItem();
|
var heldItem = event.sender.inventory.getCurrentItem();
|
||||||
|
|
||||||
|
// Get the contents of the helmet slot
|
||||||
var armorItem = event.sender.inventory.armorInventory[3];
|
var armorItem = event.sender.inventory.armorInventory[3];
|
||||||
|
|
||||||
|
// Get the inventory index of the current held item
|
||||||
var hotbarIdx = event.sender.inventory.currentItem;
|
var hotbarIdx = event.sender.inventory.currentItem;
|
||||||
|
|
||||||
|
// Set the helmet slot to heldItem.getRef() (raw java object) if heldItem exists, otherwise set it to null
|
||||||
event.sender.inventory.armorInventory[3] = heldItem ? heldItem.getRef() : null;
|
event.sender.inventory.armorInventory[3] = heldItem ? heldItem.getRef() : null;
|
||||||
|
|
||||||
|
// Set the hotbar slot to the previous value of the helmet slot
|
||||||
event.sender.inventory.mainInventory[hotbarIdx] = armorItem ? armorItem.getRef() : null;
|
event.sender.inventory.mainInventory[hotbarIdx] = armorItem ? armorItem.getRef() : null;
|
||||||
|
|
||||||
|
// Use the sendPacket method to send a item change packet to the client.
|
||||||
sendPacket(event.sender.playerNetServerHandler.getRef(), makePacketItemChange(hotbarIdx));
|
sendPacket(event.sender.playerNetServerHandler.getRef(), makePacketItemChange(hotbarIdx));
|
||||||
|
|
||||||
event.preventDefault = true;
|
event.preventDefault = true;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
File diff suppressed because one or more lines are too long
@ -1,17 +1,22 @@
|
|||||||
|
//Metadata about the vclip mod
|
||||||
ModAPI.meta.title("Simple VClip Exploit");
|
ModAPI.meta.title("Simple VClip Exploit");
|
||||||
ModAPI.meta.description("Use .vclip <offset> to vertically phase through blocks.");
|
ModAPI.meta.description("Use .vclip <offset> to vertically phase through blocks.");
|
||||||
ModAPI.meta.credits("By ZXMushroom63");
|
ModAPI.meta.credits("By ZXMushroom63");
|
||||||
|
|
||||||
|
// Require the player entity
|
||||||
ModAPI.require("player");
|
ModAPI.require("player");
|
||||||
|
|
||||||
|
//When the player tries to send a chat message to the server
|
||||||
ModAPI.addEventListener("sendchatmessage", (ev) => {
|
ModAPI.addEventListener("sendchatmessage", (ev) => {
|
||||||
var msg = ev.message.toLowerCase();
|
var msg = ev.message.toLowerCase(); //Get the lowercase version of the command
|
||||||
if (msg.startsWith(".vclip")) {
|
if (msg.startsWith(".vclip")) { //If it starts with .vclip
|
||||||
ev.preventDefault = true;
|
ev.preventDefault = true; //Don't send the chat message to the server
|
||||||
var yOffset = 1;
|
var yOffset = 1; //Set the default Y offset to 1. This let's you use .vclip with no arguments to "unstuck" yourself;
|
||||||
if (msg.split(" ")[1]) {
|
if (msg.split(" ")[1]) { //If there is a second part to the command
|
||||||
yOffset = parseFloat(msg.split(" ")[1]) || 0;
|
yOffset = parseFloat(msg.split(" ")[1]) || 0; //Set the yOffset to that
|
||||||
}
|
}
|
||||||
ModAPI.player.setPosition(ModAPI.player.posX, ModAPI.player.posY
|
ModAPI.player.setPosition(ModAPI.player.posX, ModAPI.player.posY
|
||||||
+ yOffset, ModAPI.player.posZ);
|
+ yOffset, ModAPI.player.posZ); //Set the player's position to their current position plus the y offset.
|
||||||
ModAPI.displayToChat("[SimpleVClip] VClipped " + yOffset + " blocks.");
|
ModAPI.displayToChat("[SimpleVClip] VClipped " + yOffset + " blocks."); //Display information to the client side chat.
|
||||||
}
|
}
|
||||||
});
|
});
|
@ -1,34 +1,29 @@
|
|||||||
(() => {
|
(() => {
|
||||||
PluginAPI.dedicatedServer.appendCode(function () {
|
PluginAPI.dedicatedServer.appendCode(function () { //Run this code on the server
|
||||||
PluginAPI.addEventListener("processcommand", (event) => {
|
PluginAPI.addEventListener("processcommand", (event) => { //Command processing event
|
||||||
// Check if the sender is a player
|
// Check if the sender is a player
|
||||||
if (!ModAPI.reflect.getClassById("net.minecraft.entity.player.EntityPlayerMP").instanceOf(event.sender.getRef())) { return; }
|
if (!ModAPI.reflect.getClassById("net.minecraft.entity.player.EntityPlayerMP").instanceOf(event.sender.getRef())) { return; }
|
||||||
|
|
||||||
// Check if the command is "/spawnsheep"
|
// Check if the command is "/spawnxp"
|
||||||
if (event.command.toLowerCase().startsWith("/spawnxp")) {
|
if (event.command.toLowerCase().startsWith("/spawnxp")) {
|
||||||
const world = event.sender.getServerForPlayer();
|
const world = event.sender.getServerForPlayer();
|
||||||
const senderPos = event.sender.getPosition();
|
const senderPos = event.sender.getPosition();
|
||||||
|
|
||||||
// Create a sheep entity
|
// Create an xp orb entity
|
||||||
const EntityXP = ModAPI.reflect.getClassByName("EntityXPOrb");
|
const EntityXP = ModAPI.reflect.getClassByName("EntityXPOrb");
|
||||||
const xporb = EntityXP.constructors[0](world.getRef(), senderPos.getX(), senderPos.getY(), senderPos.getZ(), 10);
|
const xporb = EntityXP.constructors[0](world.getRef(), senderPos.getX(), senderPos.getY(), senderPos.getZ(), 10);
|
||||||
|
|
||||||
if (globalThis.AsyncSink) { //If we can, start the AsyncSink debugger to see filesystem requests
|
// Add the xp orb to the world
|
||||||
AsyncSink.startDebuggingFS();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Add the sheep to the world
|
|
||||||
ModAPI.promisify(ModAPI.hooks.methods.nmw_World_spawnEntityInWorld)(world.getRef(), xporb).then(result => {
|
ModAPI.promisify(ModAPI.hooks.methods.nmw_World_spawnEntityInWorld)(world.getRef(), xporb).then(result => {
|
||||||
// Notify the player that the sheep has been spawned
|
// Notify the player that the xp orb has been spawned
|
||||||
const ChatComponentTextClass = ModAPI.reflect.getClassById("net.minecraft.util.ChatComponentText");
|
|
||||||
event.sender.addChatMessage(ChatComponentTextClass.constructors[0](ModAPI.util.str("An xp orb has been spawned!")));
|
|
||||||
|
|
||||||
if (globalThis.AsyncSink) { //Stop debugging when we are done, otherwise the console will get filled up.
|
// Get the chat component class
|
||||||
AsyncSink.stopDebuggingFS();
|
const ChatComponentTextClass = ModAPI.reflect.getClassById("net.minecraft.util.ChatComponentText");
|
||||||
}
|
// Construct the chat component and send it to the client.
|
||||||
|
event.sender.addChatMessage(ChatComponentTextClass.constructors[0](ModAPI.util.str("An xp orb has been spawned!")));
|
||||||
});
|
});
|
||||||
|
|
||||||
// Prevent the command from executing further
|
// Prevent the command from executing further (stops syntax errors / command does not exist errors)
|
||||||
event.preventDefault = true;
|
event.preventDefault = true;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user