Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
OEOTYAN committed Jul 8, 2022
1 parent 1a8026f commit 54d8b21
Show file tree
Hide file tree
Showing 12 changed files with 637 additions and 171 deletions.
52 changes: 21 additions & 31 deletions Template/WorldEdit.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,21 @@

#define WE_DIR (std::string("plugins/WorldEdit/"))

#define INNERIZE_GMASK \
std::function<void(EvalFunctions&, std::unordered_map<std::string, double> const&, \
std::function<void()> const&)> \
gMaskLambda; \
std::string gMask = ""; \
if (mod.playerGMaskMap.find(xuid) != mod.playerGMaskMap.end()) { \
gMask = mod.playerGMaskMap[xuid]; \
gMaskLambda = [&](EvalFunctions& func, const std::unordered_map<std::string, double>& var, \
std::function<void()> const& todo) mutable { \
if (cpp_eval::eval<double>(gMask.c_str(), var, func) > 0.5) { \
todo(); \
} \
}; \
} else { \
gMaskLambda = [&](EvalFunctions& func, const std::unordered_map<std::string, double>& var, \
std::function<void()> const& todo) mutable { todo(); }; \
#define INNERIZE_GMASK \
std::function<void(EvalFunctions&, std::unordered_map<std::string, double> const&, std::function<void()> const&)> \
gMaskLambda; \
std::string gMask = ""; \
if (mod.playerGMaskMap.find(xuid) != mod.playerGMaskMap.end()) { \
gMask = mod.playerGMaskMap[xuid]; \
gMaskLambda = [&](EvalFunctions& func, const std::unordered_map<std::string, double>& var, \
std::function<void()> const& todo) mutable { \
if (cpp_eval::eval<double>(gMask.c_str(), var, func) > 0.5) { \
todo(); \
} \
}; \
} else { \
gMaskLambda = [&](EvalFunctions& func, const std::unordered_map<std::string, double>& var, \
std::function<void()> const& todo) mutable { todo(); }; \
}

namespace worldedit {
Expand All @@ -39,22 +38,13 @@ namespace worldedit {
int updateArg = 2;
int updateExArg = 1;
std::unordered_map<std::string, Region*> playerRegionMap;
std::unordered_map<std::string,
std::pair<BlockPos, std::pair<int, int>>>
playerMainPosMap;
std::unordered_map<std::string,
std::pair<BlockPos, std::pair<int, int>>>
playerVicePosMap;
std::unordered_map<std::string, std::pair<BlockPos, std::pair<int, int>>> playerMainPosMap;
std::unordered_map<std::string, std::pair<BlockPos, std::pair<int, int>>> playerVicePosMap;
std::unordered_map<std::string, Clipboard> playerClipboardMap;
std::unordered_map<std::string, std::unordered_map<std::string, Tool*>>
playerHandToolMap;
std::unordered_map<std::string, std::unordered_map<std::string,Brush*>>
playerBrushMap;
std::unordered_map<std::string, std::unordered_map<std::string, Tool*>> playerHandToolMap;
std::unordered_map<std::string, std::unordered_map<std::string, Brush*>> playerBrushMap;
std::unordered_map<std::string, std::string> playerGMaskMap;
std::unordered_map<
std::string,
std::pair<std::vector<Clipboard>, std::pair<int, int>>>
playerHistoryMap;
std::unordered_map<std::string, std::pair<std::vector<Clipboard>, std::pair<int, int>>> playerHistoryMap;

void renderMVpos();
Clipboard* getPlayerNextHistory(std::string xuid);
Expand All @@ -64,7 +54,7 @@ namespace worldedit {
WE& getMod();
std::unordered_map<int, std::string>& getBlockNameMap();
std::unordered_map<std::string, int>& getBlockIdMap();
std::unordered_map<mce::Color, int>& getBlockColorMap();
std::unordered_map<mce::Color, int>& getBlockColorMap();
Block* getBlock(int id);
std::string getBlockName(int id);
int getBlockId(const std::string& name);
Expand Down
57 changes: 47 additions & 10 deletions core/command/ClipboardCommand.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

// #include "pch.h"
#include <MC/CommandUtils.hpp>
#include "MC/StructureTemplate.hpp"
// #include <MC/BlockInstance.hpp>
// #include <MC/Block.hpp>
// #include <MC/BlockActor.hpp>
Expand Down Expand Up @@ -62,17 +63,36 @@ namespace worldedit {
mod.playerRegionMap[xuid]->hasSelected()) {
auto* region = mod.playerRegionMap[xuid];
auto boundingBox = region->getBoundBox();
mod.playerClipboardMap[xuid] = Clipboard(boundingBox.max - boundingBox.min);
auto* clipboard = &mod.playerClipboardMap[xuid];
*clipboard = Clipboard(boundingBox.max - boundingBox.min);
auto pPos = origin.getPlayer()->getPosition() - Vec3(0.0, 1.62, 0.0);
mod.playerClipboardMap[xuid].playerPos = pPos.toBlockPos();
mod.playerClipboardMap[xuid].playerRelPos = pPos.toBlockPos() - boundingBox.min;
clipboard->playerPos = pPos.toBlockPos();
clipboard->playerRelPos = pPos.toBlockPos() - boundingBox.min;
auto dimID = mod.playerRegionMap[xuid]->getDimensionID();
auto blockSource = Level::getBlockSource(dimID);
mod.playerRegionMap[xuid]->forEachBlockInRegion([&](const BlockPos& pos) {
auto localPos = pos - boundingBox.min;
auto blockInstance = blockSource->getBlockInstance(pos);
mod.playerClipboardMap[xuid].storeBlock(blockInstance, localPos);
clipboard->storeBlock(blockInstance, localPos);
});
if (true) {
auto st = StructureTemplate("worldedit_copy_cmd_tmp");
auto setting = StructureSettings();
setting.setIgnoreBlocks(true);
setting.setIgnoreEntities(false);
setting.setMirror(Mirror::None_15);
setting.setStructureSize(boundingBox.max - boundingBox.min + 1);
setting.setRotation(Rotation::None_14);
st.fillFromWorld(*blockSource, boundingBox.min + BlockPos(0, 1, 0), setting);
// auto structure = st.toTag()->toBinaryNBT();
// std::cout << structure << std::endl;
boundingBox += BlockPos(0, 1, 0);
clipboard->entityStr =
// StructureTemplate::fromWorld("worldedit_copy_cmd_tmp", dimID,
// boundingBox.min, boundingBox.max,
// false, true)
st.toTag()->toBinaryNBT();
}
output.success(fmt::format("§aregion copied"));
} else {
output.error("You don't have a region yet");
Expand Down Expand Up @@ -109,13 +129,14 @@ namespace worldedit {

auto pPos = origin.getPlayer()->getPosition() - Vec3(0.0, 1.62, 0.0);

mod.playerClipboardMap[xuid] = Clipboard(boundingBox.max - boundingBox.min);
mod.playerClipboardMap[xuid].playerPos = pPos.toBlockPos();
mod.playerClipboardMap[xuid].playerRelPos = pPos.toBlockPos() - boundingBox.min;
auto* clipboard = &mod.playerClipboardMap[xuid];
*clipboard = Clipboard(boundingBox.max - boundingBox.min);
clipboard->playerPos = pPos.toBlockPos();
clipboard->playerRelPos = pPos.toBlockPos() - boundingBox.min;
region->forEachBlockInRegion([&](const BlockPos& pos) {
auto localPos = pos - boundingBox.min;
auto blockInstance = blockSource->getBlockInstance(pos);
mod.playerClipboardMap[xuid].storeBlock(blockInstance, localPos);
clipboard->storeBlock(blockInstance, localPos);
});
region->forEachBlockInRegion([&](const BlockPos& pos) { setBlockSimple(blockSource, pos); });
output.success(fmt::format("§aregion cutted"));
Expand All @@ -128,15 +149,15 @@ namespace worldedit {
DynamicCommand::setup(
"paste", // command name
"paste your clipboard", // command description
{}, {ParamData("args", ParamType::SoftEnum, true, "-anos", "-anos")}, {{"args"}},
{}, {ParamData("args", ParamType::SoftEnum, true, "-anose", "-anose")}, {{"args"}},
// dynamic command callback
[](DynamicCommand const& command, CommandOrigin const& origin, CommandOutput& output,
std::unordered_map<std::string, DynamicCommand::Result>& results) {
auto& mod = worldedit::getMod();
auto xuid = origin.getPlayer()->getXuid();
if (mod.playerClipboardMap.find(xuid) != mod.playerClipboardMap.end()) {
auto* clipboard = &mod.playerClipboardMap[xuid];
bool arg_a = false, arg_n = false, arg_o = false, arg_s = false;
bool arg_a = false, arg_n = false, arg_o = false, arg_s = false, arg_e = false;
if (results["args"].isSet) {
auto str = results["args"].getRaw<std::string>();
if (str.find("-") == std::string::npos) {
Expand All @@ -155,6 +176,9 @@ namespace worldedit {
if (str.find("s") != std::string::npos) {
arg_s = true;
}
if (str.find("e") != std::string::npos) {
arg_e = true;
}
}
BlockPos pbPos;
if (arg_o) {
Expand Down Expand Up @@ -203,7 +227,20 @@ namespace worldedit {
clipboard->setBlocks(pos, worldPos, blockSource);
});
}
if (arg_e && !clipboard->entityStr.empty()) {
auto st = StructureTemplate("worldedit_copy_cmd_tmp");
st.getData()->load(*(CompoundTag::fromBinaryNBT(clipboard->entityStr).get()));
auto& palette = Global<Level>->getBlockPalette();
auto setting = StructureSettings();
setting.setMirror(clipboard->mirror);
setting.setStructureSize(st.getSize());
setting.setRotation(clipboard->rotation);
st.placeInWorld(*blockSource, palette,
clipboard->getPos({0, 0, 0}) + pbPos + BlockPos(0, 1, 0), setting, nullptr,
false);
}
}

output.success(fmt::format("§aclipboard pasted"));
} else {
output.error("You don't have a clipboard yet");
Expand Down
Loading

0 comments on commit 54d8b21

Please sign in to comment.