Skip to content

Commit

Permalink
hats mod
Browse files Browse the repository at this point in the history
  • Loading branch information
ZXMushroom63 committed Sep 13, 2024
1 parent 42c6214 commit 8e46550
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions examplemods/hats.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
ModAPI.meta.title("SimpleHats");
ModAPI.meta.credits("Made with ❤️ by ZXMushroom63");
ModAPI.meta.description("Use /hat to wear whatever you are holding!");
ModAPI.dedicatedServer.appendCode(function () {
var makePacketItemChange = ModAPI.reflect.getClassByName("S09PacketHeldItemChange").constructors.find(x => x.length === 1);
var sendPacket = ModAPI.reflect.getClassByName("NetHandlerPlayServer").methods.sendPacket.method;

ModAPI.addEventListener("processcommand", (event) => {
if (event.command.toLowerCase().startsWith("/hat")) {
if (!ModAPI.reflect.getClassById("net.minecraft.entity.player.EntityPlayerMP").instanceOf(event.sender.getRef())) { return };
var heldItem = event.sender.inventory.getCurrentItem();
var armorItem = event.sender.inventory.armorInventory[3];
var hotbarIdx = event.sender.inventory.currentItem;

event.sender.inventory.armorInventory[3] = heldItem ? heldItem.getRef() : null;
event.sender.inventory.mainInventory[hotbarIdx] = armorItem ? armorItem.getRef() : null;
sendPacket(event.sender.playerNetServerHandler.getRef(), makePacketItemChange(hotbarIdx));
event.preventDefault = true;
}
});
});

0 comments on commit 8e46550

Please sign in to comment.