mirror of
https://github.com/eaglerforge/EaglerForgeInjector
synced 2025-07-24 22:51:18 -09:00
make worldedit work
This commit is contained in:
parent
99be1d0cc7
commit
f247fe990e
@ -20,29 +20,26 @@ ModAPI.addEventListener("lib:libcustomitems:loaded", () => {
|
|||||||
},
|
},
|
||||||
onRightClickGround: `/*/user, world, itemstack, blockpos/*/
|
onRightClickGround: `/*/user, world, itemstack, blockpos/*/
|
||||||
const prefix = "§7[§4worldedit§7] ";
|
const prefix = "§7[§4worldedit§7] ";
|
||||||
const pos = blockpos;
|
|
||||||
const positions = globalThis.playerPositions[user.getName()] ||= {};
|
globalThis.pos2x = blockpos.x
|
||||||
|
globalThis.pos2y = blockpos.y
|
||||||
// Save position #2
|
globalThis.pos2z = blockpos.z
|
||||||
positions.pos2 = pos;
|
|
||||||
|
|
||||||
// Send chat message to player
|
// Send chat message to player
|
||||||
user.addChatMessage(ModAPI.reflect.getClassById("net.minecraft.util.ChatComponentText").constructors[0](ModAPI.util.str(
|
user.addChatMessage(ModAPI.reflect.getClassById("net.minecraft.util.ChatComponentText").constructors[0](ModAPI.util.str(prefix + "Pos #2 set to: " + blockpos.x + ", " + blockpos.y + ", " + blockpos.z)))
|
||||||
ModAPI.util.str(prefix + "Pos #2 selected at: " + pos.$x + ", " + pos.$y + ", " + pos.$z))
|
|
||||||
));
|
));
|
||||||
return true;
|
return true;
|
||||||
`,
|
`,
|
||||||
onLeftClickGround: `/*/user, world, itemstack, blockpos/*/
|
onLeftClickGround: `/*/user, world, itemstack, blockpos/*/
|
||||||
const prefix = "§7[§4worldedit§7] ";
|
const prefix = "§7[§4worldedit§7] ";
|
||||||
const pos = blockpos;
|
|
||||||
const positions = globalThis.playerPositions[user.getName()] ||= {};
|
globalThis.posx = blockpos.x
|
||||||
|
globalThis.posy = blockpos.y
|
||||||
|
globalThis.posz = blockpos.z
|
||||||
|
|
||||||
// Save position #1
|
|
||||||
positions.pos1 = pos;
|
|
||||||
|
|
||||||
// Send chat message to player
|
// Send chat message to player
|
||||||
user.addChatMessage(ModAPI.reflect.getClassById("net.minecraft.util.ChatComponentText").constructors[0](ModAPI.util.str(
|
user.addChatMessage(ModAPI.reflect.getClassById("net.minecraft.util.ChatComponentText").constructors[0](ModAPI.util.str(prefix + "Pos #1 set to: " + blockpos.x + ", " + blockpos.y + ", " + blockpos.z)))
|
||||||
ModAPI.util.str(prefix + "Pos #1 selected at: " + pos.$x + ", " + pos.$y + ", " + pos.$z))
|
|
||||||
));
|
));
|
||||||
return true;
|
return true;
|
||||||
`
|
`
|
||||||
@ -86,57 +83,44 @@ ModAPI.addEventListener("lib:libcustomitems:loaded", () => {
|
|||||||
|
|
||||||
event.preventDefault = true;
|
event.preventDefault = true;
|
||||||
}
|
}
|
||||||
|
var blockPosConstructor = ModAPI.reflect.getClassById("net.minecraft.util.BlockPos").constructors.find((x) => { return x.length === 3 });
|
||||||
if (event.command.toLowerCase().startsWith("//set")) {
|
if (event.command.toLowerCase().startsWith("//set")) {
|
||||||
const player = event.sender;
|
const args = event.command.substring("//set ".length);
|
||||||
// Parse command parameters
|
|
||||||
const params = event.command.substring("//set ".length);
|
if (args) {
|
||||||
if (!params) {
|
const blockTypeName = args
|
||||||
player.addChatMessage(ChatComponentTextClass.constructors[0](ModAPI.util.str(prefix + "§cUsage: //set <block_type>")));
|
const x1 = globalThis.posx, y1 = globalThis.posy, z1 = globalThis.posz;
|
||||||
event.preventDefault = true;
|
const x2 = globalThis.pos2x, y2 = globalThis.pos2y, z2 = globalThis.pos2z;
|
||||||
return;
|
|
||||||
}
|
// Validate block and get block type
|
||||||
|
const blockType = ModAPI.blocks[blockTypeName];
|
||||||
const blockType = params;
|
if (!blockType) {
|
||||||
const positions = globalThis.playerPositions[player.getName()];
|
event.sender.addChatMessage(ModAPI.reflect.getClassById("net.minecraft.util.ChatComponentText").constructors[0](ModAPI.util.str(prefix + `Invalid block: ${blockTypeName}`)));
|
||||||
|
event.preventDefault = true;
|
||||||
// Validate block type and positions
|
return;
|
||||||
if (typeof ModAPI.blocks[blockType] !== 'undefined') {
|
}
|
||||||
player.addChatMessage(ChatComponentTextClass.constructors[0](ModAPI.util.str(prefix + "§cInvalid block type.")));
|
const block = blockType.getDefaultState().getRef();
|
||||||
event.preventDefault = true;
|
|
||||||
return;
|
// Get min and max coordinates for the fill region
|
||||||
}
|
const xMin = Math.min(x1, x2), xMax = Math.max(x1, x2);
|
||||||
const block = ModAPI.blocks[blockType];
|
const yMin = Math.min(y1, y2), yMax = Math.max(y1, y2);
|
||||||
|
const zMin = Math.min(z1, z2), zMax = Math.max(z1, z2);
|
||||||
if (!positions || !positions.pos1 || !positions.pos2) {
|
|
||||||
player.addChatMessage(ChatComponentTextClass.constructors[0](ModAPI.util.str(prefix + "§cPositions not set. Use left and right click to set positions.")));
|
// Loop through the region and set the blocks
|
||||||
event.preventDefault = true;
|
for (let x = xMin; x <= xMax; x++) {
|
||||||
return;
|
for (let y = yMin; y <= yMax; y++) {
|
||||||
}
|
for (let z = zMin; z <= zMax; z++) {
|
||||||
|
const blockPos = blockPosConstructor(x, y, z);
|
||||||
const blockState = block.getDefaultState().getRef();
|
event.sender.getServerForPlayer().setBlockState(blockPos, block, 3);
|
||||||
const world = player.getServerForPlayer().getWorld();
|
}
|
||||||
|
|
||||||
// Get coordinates
|
|
||||||
const x1 = Math.min(positions.pos1.$x, positions.pos2.$x);
|
|
||||||
const y1 = Math.min(positions.pos1.$y, positions.pos2.$y);
|
|
||||||
const z1 = Math.min(positions.pos1.$z, positions.pos2.$z);
|
|
||||||
const x2 = Math.max(positions.pos1.$x, positions.pos2.$x);
|
|
||||||
const y2 = Math.max(positions.pos1.$y, positions.pos2.$y);
|
|
||||||
const z2 = Math.max(positions.pos1.$z, positions.pos2.$z);
|
|
||||||
|
|
||||||
// Set blocks in the specified area
|
|
||||||
for (let x = x1; x <= x2; x++) {
|
|
||||||
for (let y = y1; y <= y2; y++) {
|
|
||||||
for (let z = z1; z <= z2; z++) {
|
|
||||||
const blockPos = ModAPI.reflect.getClassById("net.minecraft.util.BlockPos").constructors[0](x, y, z);
|
|
||||||
world.setBlockState(blockPos, blockState, 3);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Notify the player that the blocks have been set
|
||||||
|
event.sender.addChatMessage(ModAPI.reflect.getClassById("net.minecraft.util.ChatComponentText").constructors[0](ModAPI.util.str(prefix + `Set blocks from (${x1}, ${y1}, ${z1}) to (${x2}, ${y2}, ${z2}) to ${blockTypeName}`)));
|
||||||
|
} else{
|
||||||
|
event.sender.addChatMessage(ModAPI.reflect.getClassById("net.minecraft.util.ChatComponentText").constructors[0](ModAPI.util.str(prefix + `Arguments not found!`)));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Notify the sender
|
|
||||||
player.addChatMessage(ChatComponentTextClass.constructors[0](ModAPI.util.str(prefix + "§aBlocks set successfully.")));
|
|
||||||
|
|
||||||
event.preventDefault = true;
|
event.preventDefault = true;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user