mirror of
https://github.com/eaglerforge/EaglerForgeInjector
synced 2025-07-24 22:51:18 -09:00
Merge branch 'main' of https://github.com/eaglerforge/EaglerForgeInjector
This commit is contained in:
commit
402a73642d
39
examplemods/mobnpcspawner.js
Normal file
39
examplemods/mobnpcspawner.js
Normal file
@ -0,0 +1,39 @@
|
||||
(() => {
|
||||
PluginAPI.dedicatedServer.appendCode(function () {
|
||||
PluginAPI.addEventListener("processcommand", (event) => {
|
||||
|
||||
// Check if the command is "/spawnnpc"
|
||||
if (event.command.toLowerCase().startsWith("/spawnnpc")) {
|
||||
const world = event.sender.getServerForPlayer();
|
||||
const senderPos = event.sender.getPosition();
|
||||
|
||||
// Create a sheep entity
|
||||
const EntitySheepClass = ModAPI.reflect.getClassById("net.minecraft.entity.passive.EntitySheep");
|
||||
const sheep = EntitySheepClass.constructors[1](world.getRef());
|
||||
|
||||
// Set sheep's position to player's position
|
||||
sheep.setPosition(senderPos.getX(), senderPos.getY(), senderPos.getZ());
|
||||
|
||||
// Disable AI (no AI behavior)
|
||||
sheep.getDataWatcher().updateObject(15, 1); // AI flag, 15 is the byte for AI, 1 means no AI
|
||||
|
||||
// Disable gravity
|
||||
sheep.noGravity = 1;
|
||||
|
||||
// Make sheep invincible
|
||||
sheep.setEntityInvulnerable(1);
|
||||
|
||||
// Add the sheep to the world
|
||||
world.spawnEntityInWorld(sheep);
|
||||
|
||||
// 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("A special sheep has been spawned!")));
|
||||
|
||||
|
||||
// Prevent the command from executing further
|
||||
event.preventDefault = true;
|
||||
}
|
||||
});
|
||||
});
|
||||
})();
|
Loading…
x
Reference in New Issue
Block a user