mirror of
https://github.com/eaglerforge/EaglerForgeInjector
synced 2025-07-24 22:51:18 -09:00
xpspawner
This commit is contained in:
parent
1e1c0be950
commit
6954b68426
@ -4,8 +4,8 @@
|
|||||||
// Check if the sender is a player
|
// Check if the sender is a player
|
||||||
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; }
|
||||||
|
|
||||||
// Check if the command is "/spawnnpc"
|
// Check if the command is "/spawnsheep"
|
||||||
if (event.command.toLowerCase().startsWith("/spawnnpc")) {
|
if (event.command.toLowerCase().startsWith("/spawnsheep")) {
|
||||||
const world = event.sender.getServerForPlayer();
|
const world = event.sender.getServerForPlayer();
|
||||||
const senderPos = event.sender.getPosition();
|
const senderPos = event.sender.getPosition();
|
||||||
|
|
||||||
@ -17,21 +17,28 @@
|
|||||||
sheep.$setLocationAndAngles(senderPos.getX(), senderPos.getY(), senderPos.getZ(), senderPos.rotationYaw, senderPos.rotationPitch);
|
sheep.$setLocationAndAngles(senderPos.getX(), senderPos.getY(), senderPos.getZ(), senderPos.rotationYaw, senderPos.rotationPitch);
|
||||||
|
|
||||||
// Disable AI (no AI behavior)
|
// Disable AI (no AI behavior)
|
||||||
sheep.$setNoAI(1)
|
//sheep.$setNoAI(1)
|
||||||
|
|
||||||
// Disable gravity
|
// Disable gravity
|
||||||
sheep.$noGravity = 1;
|
//sheep.$noGravity = 1;
|
||||||
|
|
||||||
// Make sheep invincible
|
// Make sheep invincible
|
||||||
sheep.$invulnerable = 1
|
//sheep.$invulnerable = 1
|
||||||
|
|
||||||
|
if (globalThis.AsyncSink) { //If we can, start the AsyncSink debugger to see filesystem requests
|
||||||
|
AsyncSink.startDebuggingFS();
|
||||||
|
}
|
||||||
|
|
||||||
// Add the sheep to the world
|
// Add the sheep to the world
|
||||||
world.spawnEntityInWorld(sheep);
|
ModAPI.promisify(ModAPI.hooks.methods.nmw_World_spawnEntityInWorld)(world.getRef(), sheep).then(result => {
|
||||||
|
// Notify the player that the sheep has been spawned
|
||||||
// Notify the player that the sheep has been spawned
|
const ChatComponentTextClass = ModAPI.reflect.getClassById("net.minecraft.util.ChatComponentText");
|
||||||
const ChatComponentTextClass = ModAPI.reflect.getClassById("net.minecraft.util.ChatComponentText");
|
event.sender.addChatMessage(ChatComponentTextClass.constructors[0](ModAPI.util.str("A special sheep has been spawned!")));
|
||||||
event.sender.addChatMessage(ChatComponentTextClass.constructors[0](ModAPI.util.str("A special sheep 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
|
// Prevent the command from executing further
|
||||||
event.preventDefault = true;
|
event.preventDefault = true;
|
||||||
|
@ -1,28 +1,10 @@
|
|||||||
(() => {
|
(() => {
|
||||||
PluginAPI.dedicatedServer.appendCode(function () {
|
PluginAPI.dedicatedServer.appendCode(function () {
|
||||||
var ready = false;
|
|
||||||
var killFS = false;
|
|
||||||
function setup_filesystem_middleware() {
|
|
||||||
if (!ready) {
|
|
||||||
AsyncSink.MIDDLEWARE.push((ev)=>{
|
|
||||||
if (killFS) {
|
|
||||||
ev.shim = true;
|
|
||||||
if (typeof ev.shimOutput === "boolean") {
|
|
||||||
ev.shimOutput = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
ready = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
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("/spawnnpc2")) {
|
||||||
if (!globalThis.AsyncSink) {
|
AsyncSink.startDebuggingFS();
|
||||||
return console.error("NPC Spawner relies on the AsyncSink library.");
|
|
||||||
}
|
|
||||||
setup_filesystem_middleware();
|
|
||||||
const world = event.sender.getServerForPlayer();
|
const world = event.sender.getServerForPlayer();
|
||||||
const senderPos = event.sender.getPosition();
|
const senderPos = event.sender.getPosition();
|
||||||
|
|
||||||
@ -31,7 +13,7 @@
|
|||||||
var UUID = ModAPI.hooks.methods[ModAPI.util.getMethodFromPackage("net.lax1dude.eaglercraft.v1_8.EaglercraftUUID", "randomUUID")]();
|
var UUID = ModAPI.hooks.methods[ModAPI.util.getMethodFromPackage("net.lax1dude.eaglercraft.v1_8.EaglercraftUUID", "randomUUID")]();
|
||||||
|
|
||||||
//Not using UUID to make patching easier for now
|
//Not using UUID to make patching easier for now
|
||||||
|
|
||||||
const fakeProfile = GameProfileClass.constructors[1](null, ModAPI.util.str("Steve"));
|
const fakeProfile = GameProfileClass.constructors[1](null, ModAPI.util.str("Steve"));
|
||||||
|
|
||||||
// Get the PlayerInteractionManager class
|
// Get the PlayerInteractionManager class
|
||||||
@ -39,23 +21,23 @@
|
|||||||
const playerInteractionManager = PlayerInteractionManagerClass.constructors[0](world.getRef());
|
const playerInteractionManager = PlayerInteractionManagerClass.constructors[0](world.getRef());
|
||||||
|
|
||||||
// Get the EntityPlayerMP class to spawn the fake player
|
// Get the EntityPlayerMP class to spawn the fake player
|
||||||
killFS = true;
|
|
||||||
const EntityPlayerMPClass = ModAPI.reflect.getClassById("net.minecraft.entity.player.EntityPlayerMP");
|
const EntityPlayerMPClass = ModAPI.reflect.getClassById("net.minecraft.entity.player.EntityPlayerMP");
|
||||||
const fakePlayer = ModAPI.util.wrap(EntityPlayerMPClass.constructors[0](
|
ModAPI.promisify(EntityPlayerMPClass.constructors[0])(ModAPI.server.getRef(), world.getRef(), fakeProfile, playerInteractionManager).then(result => {
|
||||||
ModAPI.server.getRef(), world.getRef(), fakeProfile, playerInteractionManager
|
console.log(result);
|
||||||
));
|
var fakePlayer = ModAPI.util.wrap(result);
|
||||||
killFS = false;
|
|
||||||
|
|
||||||
// Set the fake player position to be near the command sender
|
// Set the fake player position to be near the command sender
|
||||||
console.log(senderPos);
|
console.log(senderPos);
|
||||||
fakePlayer.setPosition(senderPos.getX(), senderPos.getY(), senderPos.getZ());
|
fakePlayer.setPosition(senderPos.getX(), senderPos.getY(), senderPos.getZ());
|
||||||
|
|
||||||
// Add the fake player to the world
|
// Add the fake player to the world
|
||||||
world.spawnEntityInWorld(fakePlayer.getRef());
|
world.spawnEntityInWorld(fakePlayer.getRef());
|
||||||
|
|
||||||
|
// Notify the player that the fake player 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!")));
|
||||||
|
});
|
||||||
|
|
||||||
// Notify the player that the fake player 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
|
// Prevent the command from executing further
|
||||||
event.preventDefault = true;
|
event.preventDefault = true;
|
||||||
|
@ -1,47 +0,0 @@
|
|||||||
(() => {
|
|
||||||
PluginAPI.dedicatedServer.appendCode(function () {
|
|
||||||
PluginAPI.addEventListener("processcommand", (event) => {
|
|
||||||
if (!ModAPI.reflect.getClassById("net.minecraft.entity.player.EntityPlayerMP").instanceOf(event.sender.getRef())) { return; }
|
|
||||||
|
|
||||||
if (event.command.toLowerCase().startsWith("/spawnnpc2")) {
|
|
||||||
AsyncSink.startDebuggingFS();
|
|
||||||
const world = event.sender.getServerForPlayer();
|
|
||||||
const senderPos = event.sender.getPosition();
|
|
||||||
|
|
||||||
// Create a fake player GameProfile
|
|
||||||
const GameProfileClass = ModAPI.reflect.getClassById("net.lax1dude.eaglercraft.v1_8.mojang.authlib.GameProfile");
|
|
||||||
var UUID = ModAPI.hooks.methods[ModAPI.util.getMethodFromPackage("net.lax1dude.eaglercraft.v1_8.EaglercraftUUID", "randomUUID")]();
|
|
||||||
|
|
||||||
//Not using UUID to make patching easier for now
|
|
||||||
|
|
||||||
const fakeProfile = GameProfileClass.constructors[1](null, ModAPI.util.str("Steve"));
|
|
||||||
|
|
||||||
// Get the PlayerInteractionManager class
|
|
||||||
const PlayerInteractionManagerClass = ModAPI.reflect.getClassById("net.minecraft.server.management.ItemInWorldManager");
|
|
||||||
const playerInteractionManager = PlayerInteractionManagerClass.constructors[0](world.getRef());
|
|
||||||
|
|
||||||
// Get the EntityPlayerMP class to spawn the fake player
|
|
||||||
const EntityPlayerMPClass = ModAPI.reflect.getClassById("net.minecraft.entity.player.EntityPlayerMP");
|
|
||||||
ModAPI.promisify(EntityPlayerMPClass.constructors[0])(ModAPI.server.getRef(), world.getRef(), fakeProfile, playerInteractionManager).then(result => {
|
|
||||||
console.log(result);
|
|
||||||
var fakePlayer = ModAPI.util.wrap(result);
|
|
||||||
|
|
||||||
// Set the fake player position to be near the command sender
|
|
||||||
console.log(senderPos);
|
|
||||||
fakePlayer.setPosition(senderPos.getX(), senderPos.getY(), senderPos.getZ());
|
|
||||||
|
|
||||||
// Add the fake player to the world
|
|
||||||
world.spawnEntityInWorld(fakePlayer.getRef());
|
|
||||||
|
|
||||||
// Notify the player that the fake player 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;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
})();
|
|
36
examplemods/xpspawner.js
Normal file
36
examplemods/xpspawner.js
Normal file
@ -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;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
})();
|
Loading…
x
Reference in New Issue
Block a user