-
Notifications
You must be signed in to change notification settings - Fork 22
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
1e1c0be
commit 6954b68
Showing
4 changed files
with
70 additions
and
92 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
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
This file was deleted.
Oops, something went wrong.
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,36 @@ | ||
(() => { | ||
PluginAPI.dedicatedServer.appendCode(function () { | ||
PluginAPI.addEventListener("processcommand", (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" | ||
if (event.command.toLowerCase().startsWith("/spawnxp")) { | ||
const world = event.sender.getServerForPlayer(); | ||
const senderPos = event.sender.getPosition(); | ||
|
||
// Create a sheep 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 | ||
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!"))); | ||
|
||
if (globalThis.AsyncSink) { //Stop debugging when we are done, otherwise the console will get filled up. | ||
AsyncSink.stopDebuggingFS(); | ||
} | ||
}); | ||
|
||
// Prevent the command from executing further | ||
event.preventDefault = true; | ||
} | ||
}); | ||
}); | ||
})(); |