我正在 Minecraft spigot 中制作一个地下城生成器,并尝试使用 World Edit API 实现复制粘贴方法。我在文档中看不到太多内容,我相信 chatGPT 提供了过时的信息,如下所示:
public void cloneWithWorldEdit(Location fromMin, Location fromMax, Location to) throws WorldEditException {
WorldEditPlugin worldEdit = (WorldEditPlugin) Bukkit.getServer().getPluginManager().getPlugin("WorldEdit");
com.sk89q.worldedit.world.World world = BukkitAdapter.adapt(fromMin.getWorld());
// Define the source region
Region sourceRegion = new CuboidRegion(BukkitAdapter.asBlockVector(fromMin), BukkitAdapter.asBlockVector(fromMax));
// Define the destination
BlockVector3 toVector = BukkitAdapter.asBlockVector(to);
// Create an edit session
try (EditSession editSession = WorldEdit.getInstance().getEditSessionFactory().getEditSession(world, -1)) {
ForwardExtentCopy copy = new ForwardExtentCopy(editSession, sourceRegion, editSession, toVector);
// Perform the operation
Operations.completeLegacy(copy);
// Remember to commit changes of the edit session
editSession.flushSession();
}
}
让我知道这是否接近或者是否有更简单的方法来做到这一点。我最终想运行更复杂的世界编辑功能,但现在我只想复制/粘贴
WorldEdit Docs 应包含足够的信息,以放弃依赖聊天机器人。它包含您可能希望使用 WorldEdit API 执行的许多常见任务的示例,例如使用 Schematics。
try (EditSession editSession = WorldEdit.getInstance().newEditSession(world)) {
Operation operation = new ClipboardHolder(clipboard)
.createPaste(editSession)
.to(BlockVector3.at(x, y, z))
// configure here
.build();
Operations.complete(operation);
}
还有其他有用的教程,例如:如何使用 WorldEdit API 加载和保存原理图