-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
42c6214
commit 8e46550
Showing
1 changed file
with
21 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
}); | ||
}); |