more comments

This commit is contained in:
ZXMushroom63 2024-10-18 18:58:05 +08:00
parent ed53410e44
commit 2b73cd8f31
4 changed files with 57 additions and 34 deletions

View File

@ -1,20 +1,42 @@
//Metadata for the mod
ModAPI.meta.title("SimpleHats");
ModAPI.meta.credits("Made with ❤️ by ZXMushroom63");
ModAPI.meta.description("Use /hat to wear whatever you are holding!");
// Run the code on the server
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);
// Find the method for sending packets.
var sendPacket = ModAPI.reflect.getClassByName("NetHandlerPlayServer").methods.sendPacket.method;
// When the server is processing a command
ModAPI.addEventListener("processcommand", (event) => {
// If the command starts with /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 };
// Otherwise, get the current held item
var heldItem = event.sender.inventory.getCurrentItem();
// Get the contents of the helmet slot
var armorItem = event.sender.inventory.armorInventory[3];
// Get the inventory index of the current held item
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;
// Set the hotbar slot to the previous value of the helmet slot
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));
event.preventDefault = true;
}
});

File diff suppressed because one or more lines are too long

View File

@ -1,17 +1,22 @@
//Metadata about the vclip mod
ModAPI.meta.title("Simple VClip Exploit");
ModAPI.meta.description("Use .vclip <offset> to vertically phase through blocks.");
ModAPI.meta.credits("By ZXMushroom63");
// Require the player entity
ModAPI.require("player");
//When the player tries to send a chat message to the server
ModAPI.addEventListener("sendchatmessage", (ev) => {
var msg = ev.message.toLowerCase();
if (msg.startsWith(".vclip")) {
ev.preventDefault = true;
var yOffset = 1;
if (msg.split(" ")[1]) {
yOffset = parseFloat(msg.split(" ")[1]) || 0;
var msg = ev.message.toLowerCase(); //Get the lowercase version of the command
if (msg.startsWith(".vclip")) { //If it starts with .vclip
ev.preventDefault = true; //Don't send the chat message to the server
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 there is a second part to the command
yOffset = parseFloat(msg.split(" ")[1]) || 0; //Set the yOffset to that
}
ModAPI.player.setPosition(ModAPI.player.posX, ModAPI.player.posY
+ yOffset, ModAPI.player.posZ);
ModAPI.displayToChat("[SimpleVClip] VClipped " + yOffset + " blocks.");
+ yOffset, ModAPI.player.posZ); //Set the player's position to their current position plus the y offset.
ModAPI.displayToChat("[SimpleVClip] VClipped " + yOffset + " blocks."); //Display information to the client side chat.
}
});

View File

@ -1,34 +1,29 @@
(() => {
PluginAPI.dedicatedServer.appendCode(function () {
PluginAPI.addEventListener("processcommand", (event) => {
PluginAPI.dedicatedServer.appendCode(function () { //Run this code on the server
PluginAPI.addEventListener("processcommand", (event) => { //Command processing event
// Check if the sender is a player
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")) {
const world = event.sender.getServerForPlayer();
const senderPos = event.sender.getPosition();
// Create a sheep entity
// Create an xp orb entity
const EntityXP = ModAPI.reflect.getClassByName("EntityXPOrb");
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
AsyncSink.startDebuggingFS();
}
// Add the sheep to the world
// Add the xp orb to the world
ModAPI.promisify(ModAPI.hooks.methods.nmw_World_spawnEntityInWorld)(world.getRef(), xporb).then(result => {
// Notify the player that the sheep 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!")));
// Notify the player that the xp orb has been spawned
if (globalThis.AsyncSink) { //Stop debugging when we are done, otherwise the console will get filled up.
AsyncSink.stopDebuggingFS();
}
// Get the chat component class
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;
}
});