mirror of
https://github.com/eaglerforge/EaglerForgeInjector
synced 2025-07-24 22:51:18 -09:00
Update npcspawner.js
This commit is contained in:
parent
e2b50d77f3
commit
48d64cf8a4
@ -1,33 +1,35 @@
|
|||||||
(() => {
|
(() => {
|
||||||
PluginAPI.dedicatedServer.appendCode(function () {
|
PluginAPI.dedicatedServer.appendCode(function () {
|
||||||
PluginAPI.addEventListener("processcommand", (event) => {
|
PluginAPI.addEventListener("processcommand", (event) => {
|
||||||
if (!ModAPI.reflect.getClassById("net.minecraft.entity.player.EntityPlayerMP").instanceOf(event.sender.getRef())) { return }
|
if (!ModAPI.reflect.getClassById("net.minecraft.entity.player.EntityPlayerMP").instanceOf(event.sender.getRef())) { return; }
|
||||||
|
|
||||||
if (event.command.toLowerCase().startsWith("/spawnnpc")) {
|
if (event.command.toLowerCase().startsWith("//spawnsteve")) {
|
||||||
const world = event.sender.getEntityWorld();
|
const world = event.sender.getServerForPlayer();
|
||||||
const playerPos = event.sender.getPosition();
|
const senderPos = event.sender.getPosition();
|
||||||
|
|
||||||
|
// Create a fake player GameProfile
|
||||||
// Create a fake player entity with a string-based UUID
|
|
||||||
const GameProfileClass = ModAPI.reflect.getClassById("com.mojang.authlib.GameProfile");
|
const GameProfileClass = ModAPI.reflect.getClassById("com.mojang.authlib.GameProfile");
|
||||||
const fakeProfile = GameProfileClass.constructors[2](
|
const fakeProfile = GameProfileClass.constructors[2](
|
||||||
event.sender.getGameProfile().id2.toString(), ModAPI.util.str("Steve")
|
ModAPI.reflect.getClassById("java.util.UUID").staticMethods.randomUUID(), ModAPI.util.str("Steve")
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// Get the EntityPlayerMP class to spawn the fake player
|
||||||
const EntityPlayerMPClass = ModAPI.reflect.getClassById("net.minecraft.entity.player.EntityPlayerMP");
|
const EntityPlayerMPClass = ModAPI.reflect.getClassById("net.minecraft.entity.player.EntityPlayerMP");
|
||||||
const fakePlayer = EntityPlayerMPClass.constructors[1](
|
const fakePlayer = EntityPlayerMPClass.constructors[1](
|
||||||
world.getMinecraftServer(), world.getRef(), fakeProfile, world.getPlayerInteractionManager()
|
world.getMinecraftServer(), world.getRef(), fakeProfile, world.getPlayerInteractionManager()
|
||||||
);
|
);
|
||||||
|
|
||||||
// Set the player position
|
// Set the fake player position to be near the command sender
|
||||||
fakePlayer.setPosition(playerPos.$getX(), playerPos.$getY(), playerPos.$getZ());
|
fakePlayer.setPosition(senderPos.$getX(), senderPos.$getY(), senderPos.$getZ());
|
||||||
|
|
||||||
// Add the fake player to the world
|
// Add the fake player to the world
|
||||||
world.addEntityToWorld(fakePlayer.getEntityId(), fakePlayer);
|
world.addEntityToWorld(fakePlayer.getEntityId(), fakePlayer);
|
||||||
|
|
||||||
// Send a confirmation message to the player
|
// Notify the player that the fake player has been spawned
|
||||||
event.sender.addChatMessage(ModAPI.reflect.getClassById("net.minecraft.util.ChatComponentText").constructors[0](ModAPI.util.str("Fake Steve has been spawned!")));
|
const ChatComponentTextClass = ModAPI.reflect.getClassById("net.minecraft.util.ChatComponentText");
|
||||||
|
event.sender.addChatMessage(ChatComponentTextClass.constructors[0](ModAPI.util.str("Fake Steve has been spawned!")));
|
||||||
|
|
||||||
|
// Prevent the command from executing further
|
||||||
event.preventDefault = true;
|
event.preventDefault = true;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user