diff --git a/WorldEdit/WorldEdit.cpp b/WorldEdit/WorldEdit.cpp index 55f92c2..e6bfb5a 100644 --- a/WorldEdit/WorldEdit.cpp +++ b/WorldEdit/WorldEdit.cpp @@ -52,11 +52,15 @@ // } THook(void, "?buildSerializationId@Block@@IEAAXI@Z", Block* block, unsigned int id) { + original(block, id); auto& blockName = worldedit::getBlockNameMap(); auto& blockId = worldedit::getBlockIdMap(); auto blockid = block->getId(); blockName[blockid] = block->getTypeName(); blockId[block->getTypeName()] = blockid; + // std::cout << const_cast(&block->getLegacyBlock())->buildDescriptionId(*block) << " " << blockid + // << std::endl; + // std::cout << block->getTypeName() << " " << blockid << std::endl; // std::cout << const_cast(&block->getLegacyBlock())->getTypeName() << std::endl; // auto color = block->getLegacyBlock().getMapColor().toHexString(); // if (getBlockColorssMap().find(color) != getBlockColorssMap().end()) { @@ -66,7 +70,7 @@ THook(void, "?buildSerializationId@Block@@IEAAXI@Z", Block* block, unsigned int // getBlockColorssMap()[color] = block->getNbt()->toSNBT(0, // SnbtFormat::Minimize); // } - return original(block, id); + return; } namespace worldedit { @@ -78,9 +82,10 @@ namespace worldedit { class PlayerData& getPlayersData(std::string xuid) { auto& playerDataMap = getPlayersDataMap(); - if (playerDataMap.find(xuid) == playerDataMap.end()) { + if (playerDataMap.find(xuid) == playerDataMap.end() || (!playerDataMap[xuid].init)) { playerDataMap[xuid] = PlayerData(Global->getPlayer(xuid)); } + // std::cout << "maxHistoryLength " << playerDataMap[xuid].maxHistoryLength << std::endl; return playerDataMap[xuid]; } diff --git a/core/brush/tool.cpp b/core/brush/tool.cpp index 0380615..0ac13da 100644 --- a/core/brush/tool.cpp +++ b/core/brush/tool.cpp @@ -175,7 +175,7 @@ namespace worldedit { while (!q.empty()) { auto pos1 = q.front(); q.pop(); - boundingBox = boundingBox.merge(pos1); + boundingBox.merge(pos1); if (needEdge) { BoundingBox(pos1 - 1, pos1 + 1).forEachBlockInBox([&](const BlockPos& tmpPos) { if (tmpPos != pos1 && pos0.distanceTo(tmpPos) <= 0.5 + size && diff --git a/core/command/RegionOperationCommand.cpp b/core/command/RegionOperationCommand.cpp index 6d4d1e2..3975d92 100644 --- a/core/command/RegionOperationCommand.cpp +++ b/core/command/RegionOperationCommand.cpp @@ -41,30 +41,41 @@ namespace worldedit { auto player = origin.getPlayer(); auto xuid = player->getXuid(); auto& playerData = getPlayersData(xuid); + // std::cout << "maxHistoryLength " << playerData.maxHistoryLength << std::endl; if (playerData.region != nullptr && playerData.region->hasSelected()) { Region* region = playerData.region; + // std::cout << "maxHistoryLength " << playerData.maxHistoryLength << " " << __LINE__ << std::endl; auto center = region->getCenter(); + // std::cout << "maxHistoryLength " << playerData.maxHistoryLength << " " << __LINE__ << std::endl; auto dimID = region->getDimensionID(); + // std::cout << "maxHistoryLength " << playerData.maxHistoryLength << " " << __LINE__ << std::endl; auto boundingBox = region->getBoundBox(); + // std::cout << "maxHistoryLength " << playerData.maxHistoryLength << " " << __LINE__ << std::endl; auto blockSource = &player->getRegion(); + // std::cout << "maxHistoryLength " << playerData.maxHistoryLength << " " << __LINE__ << std::endl; + // std::cout << "what" << __LINE__ << std::endl; + // std::cout << "maxHistoryLength " << playerData.maxHistoryLength << std::endl; if (playerData.maxHistoryLength > 0) { auto history = playerData.getNextHistory(); *history = Clipboard(boundingBox.max - boundingBox.min); history->playerRelPos.x = dimID; history->playerPos = boundingBox.min; + // std::cout << "what" << __LINE__ << std::endl; region->forEachBlockInRegion([&](const BlockPos& pos) { auto localPos = pos - boundingBox.min; - auto blockInstance = Level::getBlockInstance(pos,player->getDimensionId()); + auto blockInstance = Level::getBlockInstance(pos, player->getDimensionId()); history->storeBlock(blockInstance, localPos); }); + // std::cout << "what" << __LINE__ << std::endl; } long long i = 0; auto playerPos = player->getPosition(); auto playerRot = player->getRotation(); + // std::cout << "what" << __LINE__ << std::endl; EvalFunctions f; f.setbs(blockSource); f.setbox(boundingBox); @@ -76,14 +87,18 @@ namespace worldedit { bps = results["blockPattern"].get(); } else if (results["block"].isSet) { bps = results["block"].get()->getTypeName(); + // std::cout << "what" << std::endl; } + // std::cout << "maxHistoryLength " << playerData.maxHistoryLength << " " << __LINE__ << std::endl; BlockPattern blockPattern(bps, xuid, region); + // std::cout << "maxHistoryLength " << playerData.maxHistoryLength << " " << __LINE__ << std::endl; region->forEachBlockInRegion([&](const BlockPos& pos) { setFunction(variables, f, boundingBox, playerPos, pos, center); i += blockPattern.setBlock(variables, f, blockSource, pos); }); + // std::cout << "what" << __LINE__ << std::endl; output.trSuccess("worldedit.set.success", i); } else { output.trError("worldedit.error.incomplete-region"); @@ -170,7 +185,7 @@ namespace worldedit { static_cast(kz + 0.5)}; if (radius == 0) { tmp.insert(kpos); - boundingBox = boundingBox.merge(kpos); + boundingBox.merge(kpos); } else { BoundingBox(kpos - static_cast(radius + 1), kpos + static_cast(radius + 1)) @@ -178,7 +193,7 @@ namespace worldedit { if (sqrt(pow2(posk.x - kx) + pow2(posk.y - ky) + pow2(posk.z - kz)) <= 0.5 + radius) { tmp.insert(posk); - boundingBox = boundingBox.merge(posk); + boundingBox.merge(posk); } }); } @@ -189,7 +204,7 @@ namespace worldedit { .forEachBlockInBox([&](const BlockPos& posk) { if ((pos - posk).length() <= 0.5 + radius) { tmp.insert(posk); - boundingBox = boundingBox.merge(posk); + boundingBox.merge(posk); } }); }); @@ -204,7 +219,7 @@ namespace worldedit { boundingBox.forEachBlockInBox([&](const BlockPos& pos) { auto localPos = pos - boundingBox.min; - auto blockInstance = Level::getBlockInstance(pos,player->getDimensionId()); + auto blockInstance = Level::getBlockInstance(pos, player->getDimensionId()); history->storeBlock(blockInstance, localPos); }); } @@ -252,7 +267,7 @@ namespace worldedit { } output.trSuccess("worldedit.rope.success", i); - } catch (std::bad_alloc) { + } catch (...) { output.trError("worldedit.memory.out"); return; } @@ -321,7 +336,7 @@ namespace worldedit { boundingBox.forEachBlockInBox([&](const BlockPos& pos) { auto localPos = pos - boundingBox.min; - auto blockInstance = Level::getBlockInstance(pos,player->getDimensionId()); + auto blockInstance = Level::getBlockInstance(pos, player->getDimensionId()); history->storeBlock(blockInstance, localPos); }); } @@ -391,7 +406,7 @@ namespace worldedit { }); output.trSuccess("worldedit.line.success", i); - } catch (std::bad_alloc) { + } catch (...) { output.trError("worldedit.memory.out"); return; } @@ -482,7 +497,7 @@ namespace worldedit { boundingBox.forEachBlockInBox([&](const BlockPos& pos) { auto localPos = pos - boundingBox.min; - auto blockInstance = Level::getBlockInstance(pos,player->getDimensionId()); + auto blockInstance = Level::getBlockInstance(pos, player->getDimensionId()); history->storeBlock(blockInstance, localPos); }); } @@ -493,7 +508,7 @@ namespace worldedit { i += blockPattern.setBlock(variables, f, blockSource, pos); }); - } catch (std::bad_alloc) { + } catch (...) { output.trError("worldedit.memory.out"); return; } @@ -519,7 +534,7 @@ namespace worldedit { points.clear(); for (double t = 0; t <= 1; t += step) { auto pos = interpol.getPosition(t); - boundingBox = boundingBox.merge(pos.toBlockPos()); + boundingBox.merge(pos.toBlockPos()); points.push_back(pos); } boundingBox.min -= static_cast(radius) + 1; @@ -533,7 +548,7 @@ namespace worldedit { boundingBox.forEachBlockInBox([&](const BlockPos& pos) { auto localPos = pos - boundingBox.min; - auto blockInstance = Level::getBlockInstance(pos,player->getDimensionId()); + auto blockInstance = Level::getBlockInstance(pos, player->getDimensionId()); history->storeBlock(blockInstance, localPos); }); } @@ -582,7 +597,7 @@ namespace worldedit { i += blockPattern.setBlock(variables, f, blockSource, pos); } }); - } catch (std::bad_alloc) { + } catch (...) { output.trError("worldedit.memory.out"); return; } @@ -696,7 +711,7 @@ namespace worldedit { radiuses.clear(); for (double t = 0; t <= 1; t += step) { auto pos = interpol.getPosition(t); - boundingBox = boundingBox.merge(pos.toBlockPos()); + boundingBox.merge(pos.toBlockPos()); points.push_back(pos); radiuses.push_back(std::max(getRadius(t), 0.1)); } @@ -711,7 +726,7 @@ namespace worldedit { boundingBox.forEachBlockInBox([&](const BlockPos& pos) { auto localPos = pos - boundingBox.min; - auto blockInstance = Level::getBlockInstance(pos,player->getDimensionId()); + auto blockInstance = Level::getBlockInstance(pos, player->getDimensionId()); history->storeBlock(blockInstance, localPos); }); } @@ -781,7 +796,7 @@ namespace worldedit { }); output.trSuccess("worldedit.spike.success", i); - } catch (std::bad_alloc) { + } catch (...) { output.trError("worldedit.memory.out"); return; } @@ -825,7 +840,7 @@ namespace worldedit { region->forEachBlockInRegion([&](const BlockPos& pos) { auto localPos = pos - boundingBox.min; - auto blockInstance = Level::getBlockInstance(pos,player->getDimensionId()); + auto blockInstance = Level::getBlockInstance(pos, player->getDimensionId()); history->storeBlock(blockInstance, localPos); }); } @@ -902,7 +917,7 @@ namespace worldedit { boundingBox.forEachBlockInBox([&](const BlockPos& pos) { auto localPos = pos - boundingBox.min; - auto blockInstance = Level::getBlockInstance(pos,player->getDimensionId()); + auto blockInstance = Level::getBlockInstance(pos, player->getDimensionId()); history->storeBlock(blockInstance, localPos); }); } @@ -994,7 +1009,7 @@ namespace worldedit { auto center = region->getCenter(); auto dimID = region->getDimensionID(); auto boundingBox = region->getBoundBox(); - auto boundingBoxLast = boundingBox; + auto boundingBoxHistory = boundingBox; auto blockSource = &player->getRegion(); BlockPos movingVec; @@ -1004,9 +1019,9 @@ namespace worldedit { movingVec = faceVec * (boundingBox.max - boundingBox.min + 1); } - boundingBoxLast.min = boundingBoxLast.min + movingVec * times; - boundingBoxLast.max = boundingBoxLast.max + movingVec * times; - auto boundingBoxHistory = boundingBoxLast.merge(boundingBox); + boundingBoxHistory.min = boundingBoxHistory.min + movingVec * times; + boundingBoxHistory.max = boundingBoxHistory.max + movingVec * times; + boundingBoxHistory.merge(boundingBox); auto history = playerData.getNextHistory(); *history = Clipboard(boundingBoxHistory.max - boundingBoxHistory.min); @@ -1015,7 +1030,7 @@ namespace worldedit { boundingBoxHistory.forEachBlockInBox([&](const BlockPos& pos) { auto localPos = pos - boundingBoxHistory.min; - auto blockInstance = Level::getBlockInstance(pos,player->getDimensionId()); + auto blockInstance = Level::getBlockInstance(pos, player->getDimensionId()); history->storeBlock(blockInstance, localPos); }); @@ -1123,9 +1138,10 @@ namespace worldedit { auto boundingBox = region->getBoundBox(); auto boundingBoxLast = boundingBox; auto blockSource = &player->getRegion(); - + boundingBoxLast.min = boundingBoxLast.min + faceVec; boundingBoxLast.max = boundingBoxLast.max + faceVec; + auto box = boundingBoxLast; auto boundingBoxHistory = boundingBoxLast.merge(boundingBox); auto history = playerData.getNextHistory(); @@ -1135,13 +1151,13 @@ namespace worldedit { boundingBox.forEachBlockInBox([&](const BlockPos& pos) { auto localPos = pos - boundingBoxHistory.min; - auto blockInstance = Level::getBlockInstance(pos,player->getDimensionId()); + auto blockInstance = Level::getBlockInstance(pos, player->getDimensionId()); history->storeBlock(blockInstance, localPos); }); - boundingBoxLast.forEachBlockInBox([&](const BlockPos& pos) { + box.forEachBlockInBox([&](const BlockPos& pos) { auto localPos = pos - boundingBoxHistory.min; if (!history->getSet(localPos).hasBlock) { - auto blockInstance = Level::getBlockInstance(pos,player->getDimensionId()); + auto blockInstance = Level::getBlockInstance(pos, player->getDimensionId()); history->storeBlock(blockInstance, localPos); } }); @@ -1232,7 +1248,7 @@ namespace worldedit { region->forEachBlockInRegion([&](const BlockPos& pos) { auto localPos = pos - boundingBox.min; - auto blockInstance = Level::getBlockInstance(pos,player->getDimensionId()); + auto blockInstance = Level::getBlockInstance(pos, player->getDimensionId()); history->storeBlock(blockInstance, localPos); }); } @@ -1309,7 +1325,7 @@ namespace worldedit { }); output.trSuccess("worldedit.gen.success", genfunc, i); - } catch (std::bad_alloc) { + } catch (...) { output.trError("worldedit.memory.out"); return; } @@ -1347,7 +1363,7 @@ namespace worldedit { region->forEachBlockInRegion([&](const BlockPos& pos) { auto localPos = pos - boundingBox.min; - auto blockInstance = Level::getBlockInstance(pos,player->getDimensionId()); + auto blockInstance = Level::getBlockInstance(pos, player->getDimensionId()); history->storeBlock(blockInstance, localPos); }); } @@ -1434,7 +1450,7 @@ namespace worldedit { region->forEachBlockInRegion([&](const BlockPos& pos) { auto localPos = pos - boundingBox.min; - auto blockInstance = Level::getBlockInstance(pos,player->getDimensionId()); + auto blockInstance = Level::getBlockInstance(pos, player->getDimensionId()); history->storeBlock(blockInstance, localPos); }); } @@ -1501,7 +1517,7 @@ namespace worldedit { region->forTopBlockInRegion([&](const BlockPos& pos) { auto localPos = pos - boundingBox.min; - auto blockInstance = Level::getBlockInstance(pos,player->getDimensionId()); + auto blockInstance = Level::getBlockInstance(pos, player->getDimensionId()); history->storeBlock(blockInstance, localPos); }); } @@ -1558,7 +1574,7 @@ namespace worldedit { region->forEachBlockInRegion([&](const BlockPos& pos) { auto localPos = pos - boundingBox.min; - auto blockInstance = Level::getBlockInstance(pos,player->getDimensionId()); + auto blockInstance = Level::getBlockInstance(pos, player->getDimensionId()); history->storeBlock(blockInstance, localPos); }); } @@ -1628,7 +1644,7 @@ namespace worldedit { region->forEachBlockInRegion([&](const BlockPos& pos) { auto localPos = pos - boundingBox.min; - auto blockInstance = Level::getBlockInstance(pos,player->getDimensionId()); + auto blockInstance = Level::getBlockInstance(pos, player->getDimensionId()); history->storeBlock(blockInstance, localPos); }); } @@ -1694,7 +1710,7 @@ namespace worldedit { } }); output.trSuccess("worldedit.hollow.success", i); - } catch (std::bad_alloc) { + } catch (...) { output.trError("worldedit.memory.out"); return; } @@ -1735,7 +1751,7 @@ namespace worldedit { boundingBox.forEachBlockInBox([&](const BlockPos& pos) { auto localPos = pos - boundingBox.min; - auto blockInstance = Level::getBlockInstance(pos,player->getDimensionId()); + auto blockInstance = Level::getBlockInstance(pos, player->getDimensionId()); history->storeBlock(blockInstance, localPos); }); } @@ -1848,7 +1864,7 @@ namespace worldedit { blocksMap[exBlockName] = 1; } } - auto blockInstance = Level::getBlockInstance(pos,player->getDimensionId()); + auto blockInstance = Level::getBlockInstance(pos, player->getDimensionId()); if (blockInstance.hasContainer()) { auto container = blockInstance.getContainer(); @@ -1995,7 +2011,7 @@ namespace worldedit { boundingBox.forEachBlockInBox([&](const BlockPos& pos) { auto localPos = pos - boundingBox.min; - auto blockInstance = Level::getBlockInstance(pos,player->getDimensionId()); + auto blockInstance = Level::getBlockInstance(pos, player->getDimensionId()); history->storeBlock(blockInstance, localPos); }); } diff --git a/core/command/allCommand.cpp b/core/command/allCommand.cpp index f7d66ab..4010254 100644 --- a/core/command/allCommand.cpp +++ b/core/command/allCommand.cpp @@ -17,6 +17,10 @@ #include "Nlohmann/json.hpp" +#include "LoggerAPI.h" + +Logger logger("WorldEdit"); + namespace worldedit { void commandsSetup() { brushCommandSetup(); @@ -60,12 +64,15 @@ namespace worldedit { for (auto& b : blockList.items()) { std::string key = b.key(); - std::cout << key << std::endl; if (!isBEBlock(key)) { Block* block = nullptr; + std::string bname = b.value()["bedrock_identifier"]; + stringReplace(bname, "stone_block_", "stone_"); + stringReplace(bname, "sealan_tern", "sealantern"); + stringReplace(bname, "concrete_powder", "concretepowder"); if (b.value().contains("bedrock_states")) { std::string snbt = "{\"name\":\""; - snbt += b.value()["bedrock_identifier"]; + snbt += bname; snbt += "\",\"states\":"; std::string states = b.value()["bedrock_states"].dump(); stringReplace(states, ":false", ":0b"); @@ -75,15 +82,17 @@ namespace worldedit { try { block = Block::create(CompoundTag::fromSNBT(snbt).get()); } catch (...) { - std::cout << snbt << std::endl; + logger.error(snbt); + break; } // if (block == nullptr) - // std::cout << snbt << std::endl; + // logger.error(bname); } else { try { - block = Block::create(b.value()["bedrock_identifier"], 0); + block = Block::create(bname, 0); } catch (...) { - std::cout << b.value()["bedrock_identifier"] << std::endl; + logger.error(bname); + break; } } if (block != nullptr) { @@ -95,9 +104,10 @@ namespace worldedit { try { Global->setSoftEnumValues("blockPattern", blocksName); - std::cout << "blockPattern" << std::endl; + // std::cout << "blockPattern" << std::endl; } catch (...) { - std::cout << "blockPattern error" << std::endl; + logger.error("blockPattern error"); + // std::cout << "blockPattern error" << std::endl; } }, 20); diff --git a/core/data/PlayerData.cpp b/core/data/PlayerData.cpp index effa6d9..040105e 100644 --- a/core/data/PlayerData.cpp +++ b/core/data/PlayerData.cpp @@ -28,12 +28,50 @@ namespace worldedit { } PlayerData::PlayerData() { - historyList.resize(0); + init = false; + xuid = ""; + maxHistoryLength = 20; + updateArg = 2; + updateExArg = 1; + + mainPos; + mainPosTime = 0; + mainPosDim = -1; + + vicePos; + vicePosTime = 0; + vicePosDim = -1; + + gMask = ""; + region = nullptr; + historyList.clear(); + historyFlag1 = 0; + historyFlag2 = 0; + historyList.resize(maxHistoryLength); } PlayerData::PlayerData(::Player* player) { + historyList.clear(); + historyFlag1 = 0; + historyFlag2 = 0; historyList.resize(maxHistoryLength); xuid = player->getXuid(); + init = true; + maxHistoryLength = 20; + updateArg = 2; + updateExArg = 1; + + mainPos; + mainPosTime = 0; + mainPosDim = -1; + + vicePos; + vicePosTime = 0; + vicePosDim = -1; + + gMask = ""; + region = nullptr; + // std::cout << "maxHistoryLength " << maxHistoryLength << std::endl; } bool PlayerData::changeVicePos(BlockInstance blockInstance, bool output) { @@ -52,8 +90,8 @@ namespace worldedit { } if (region->setVicePos(pos, player->getDimensionId())) { if (output) - player->sendText("worldedit.selection." + region->getName() + ".explain.secondary", - pos.toString(), region->size()); + player->sendText("worldedit.selection." + region->getName() + ".explain.secondary", pos.toString(), + region->size()); vicePos = pos; vicePosTime = 0; vicePosDim = player->getDimensionId(); @@ -81,8 +119,8 @@ namespace worldedit { } if (region->setMainPos(pos, player->getDimensionId())) { if (output) - player->sendText("worldedit.selection." + region->getName() + ".explain.primary", - pos.toString(), region->size()); + player->sendText("worldedit.selection." + region->getName() + ".explain.primary", pos.toString(), + region->size()); mainPos = pos; mainPosTime = 0; mainPosDim = player->getDimensionId(); @@ -97,8 +135,7 @@ namespace worldedit { return false; } - void PlayerData::setVarByPlayer( - std::unordered_map<::std::string, double>& variables) { + void PlayerData::setVarByPlayer(std::unordered_map<::std::string, double>& variables) { Player* player = Global->getPlayer(xuid); auto playerPos = player->getPosition(); auto playerRot = player->getRotation(); @@ -109,14 +146,11 @@ namespace worldedit { variables["pt"] = playerRot.y; } - bool PlayerData::setBlockForHistory(BlockSource* blockSource, - const BlockPos& pos, - Block* block, - Block* exblock) { + bool PlayerData::setBlockForHistory(BlockSource* blockSource, const BlockPos& pos, Block* block, Block* exblock) { CommandUtils::clearBlockEntityContents(*blockSource, pos); blockSource->setExtraBlock(pos, *BedrockBlocks::mAir, 16 + updateArg); // if (updateExArg % 2 == 1) { - blockSource->setBlock(pos, *block, updateArg, nullptr, nullptr); + blockSource->setBlock(pos, *block, updateArg, nullptr, nullptr); // } // else { // blockSource->setBlockNoUpdate(pos.x, pos.y, pos.z, *block); @@ -126,11 +160,10 @@ namespace worldedit { blockSource->setExtraBlock(pos, *exblock, 16 + updateArg); } } else { - blockSource->setExtraBlock(pos, *VanillaBlocks::mFlowingWater, - 16 + updateArg); + blockSource->setExtraBlock(pos, *VanillaBlocks::mFlowingWater, 16 + updateArg); // if (updateExArg % 2 == 1) { - blockSource->setBlock(pos, *block, updateArg, nullptr, nullptr); - // } + blockSource->setBlock(pos, *block, updateArg, nullptr, nullptr); + // } // else { // blockSource->setBlockNoUpdate(pos.x, pos.y, pos.z, *block); // } @@ -138,13 +171,12 @@ namespace worldedit { return true; } - bool PlayerData::setBlockSimple( - BlockSource* blockSource, - class EvalFunctions& funcs, - std::unordered_map const& var, - const BlockPos& pos, - Block* block, - Block* exblock) { + bool PlayerData::setBlockSimple(BlockSource* blockSource, + class EvalFunctions& funcs, + std::unordered_map const& var, + const BlockPos& pos, + Block* block, + Block* exblock) { if (gMask != "") { if (cpp_eval::eval(gMask, var, funcs) <= 0.5) { return false; @@ -154,7 +186,7 @@ namespace worldedit { CommandUtils::clearBlockEntityContents(*blockSource, pos); blockSource->setExtraBlock(pos, *BedrockBlocks::mAir, 16 + updateArg); // if (updateExArg % 2 == 1) { - blockSource->setBlock(pos, *block, updateArg, nullptr, nullptr); + blockSource->setBlock(pos, *block, updateArg, nullptr, nullptr); // } else { // blockSource->setBlockNoUpdate(pos.x, pos.y, pos.z, *block); // } @@ -163,10 +195,9 @@ namespace worldedit { blockSource->setExtraBlock(pos, *exblock, 16 + updateArg); } } else { - blockSource->setExtraBlock(pos, *VanillaBlocks::mFlowingWater, - 16 + updateArg); + blockSource->setExtraBlock(pos, *VanillaBlocks::mFlowingWater, 16 + updateArg); // if (updateExArg % 2 == 1) { - blockSource->setBlock(pos, *block, updateArg, nullptr, nullptr); + blockSource->setBlock(pos, *block, updateArg, nullptr, nullptr); // } else { // blockSource->setBlockNoUpdate(pos.x, pos.y, pos.z, *block); // } @@ -175,6 +206,7 @@ namespace worldedit { } Clipboard* PlayerData::getNextHistory() { + std::cout << "getNextHistory" << std::endl; historyFlag2 += 1; historyFlag2 %= maxHistoryLength; historyFlag1 = historyFlag2; @@ -182,6 +214,7 @@ namespace worldedit { } std::pair PlayerData::getUndoHistory() { + std::cout << "getUndoHistory" << std::endl; std::pair result = {nullptr, -1}; int maximum = (historyFlag1 + 1) % maxHistoryLength; int current = historyFlag2; @@ -204,6 +237,7 @@ namespace worldedit { } std::pair PlayerData::getRedoHistory() { + std::cout << "getRedoHistory" << std::endl; std::pair result = {nullptr, -1}; int maximum = (historyFlag1 + 1) % maxHistoryLength; int current = historyFlag2 + 1; @@ -228,28 +262,32 @@ namespace worldedit { float maxDistance, bool ignoreBorderBlocks, bool fullOnly) { - Player* player = Global->getPlayer(xuid); + try { + Player* player = Global->getPlayer(xuid); - auto* bs = &player->getRegion(); - auto pos = player->getCameraPos(); - auto viewVec = player->getViewVector(1.0f); - auto viewPos = pos + (viewVec * maxDistance); - int maxDisManhattan = (int)((maxDistance + 1) * 2); - HitResult result = const_cast(bs)->clip(pos, viewPos, includeLiquid, solidOnly, maxDisManhattan, - ignoreBorderBlocks, fullOnly); - if (result.isHit() || (includeLiquid && result.isHitLiquid())) { - BlockPos bpos{}; - if (includeLiquid && result.isHitLiquid()) { - bpos = result.getLiquidPos(); - face = result.getLiquidFacing(); - } else { - bpos = result.getBlockPos(); - face = result.getFacing(); + auto* bs = &player->getRegion(); + auto pos = player->getCameraPos(); + auto viewVec = player->getViewVector(1.0f); + auto viewPos = pos + (viewVec * maxDistance); + int maxDisManhattan = (int)((maxDistance + 1) * 2); + HitResult result = const_cast(bs)->clip(pos, viewPos, includeLiquid, solidOnly, + maxDisManhattan, ignoreBorderBlocks, fullOnly); + if (result.isHit() || (includeLiquid && result.isHitLiquid())) { + BlockPos bpos{}; + if (includeLiquid && result.isHitLiquid()) { + bpos = result.getLiquidPos(); + face = result.getLiquidFacing(); + } else { + bpos = result.getBlockPos(); + face = result.getFacing(); + } + if (pos.toBlockPos().distanceTo(bpos) < maxDistance) + return Level::getBlockInstance(bpos, player->getDimensionId()); } - // auto block = const_cast(&bs.getBlock(bpos)); - return Level::getBlockInstance(bpos, player->getDimensionId()); + return BlockInstance::Null; + } catch (...) { + return BlockInstance::Null; } - return BlockInstance::Null; } BlockInstance PlayerData::getBlockFromViewVector(bool includeLiquid, diff --git a/core/data/PlayerData.h b/core/data/PlayerData.h index 12d05eb..d64f172 100644 --- a/core/data/PlayerData.h +++ b/core/data/PlayerData.h @@ -8,7 +8,8 @@ namespace worldedit { class PlayerData { public: - std::string xuid=""; + bool init = false; + std::string xuid = ""; int maxHistoryLength = 20; int updateArg = 2; int updateExArg = 1; @@ -39,27 +40,29 @@ namespace worldedit { std::pair getRedoHistory(); bool changeMainPos(BlockInstance blockInstance, bool output = true); bool changeVicePos(BlockInstance blockInstance, bool output = true); - void setVarByPlayer( - std::unordered_map<::std::string, double>& variables); - bool setBlockSimple( - class BlockSource* blockSource, - class EvalFunctions& funcs, - std::unordered_map const& var, - const BlockPos& pos, - class Block* block = const_cast(BedrockBlocks::mAir), - class Block* exblock = const_cast(BedrockBlocks::mAir)); - bool setBlockForHistory( - class BlockSource* blockSource, - const BlockPos& pos, - class Block* block , - class Block* exblock); - class BlockInstance getBlockFromViewVector(FaceID& face,bool includeLiquid = false, bool solidOnly = false, float maxDistance = 5.25f, bool ignoreBorderBlocks = true, bool fullOnly = false); - class BlockInstance getBlockFromViewVector(bool includeLiquid = false, - bool solidOnly = false, - float maxDistance = 5.25f, - bool ignoreBorderBlocks = true, - bool fullOnly = false); - ~PlayerData(); + void setVarByPlayer(std::unordered_map<::std::string, double>& variables); + bool setBlockSimple(class BlockSource* blockSource, + class EvalFunctions& funcs, + std::unordered_map const& var, + const BlockPos& pos, + class Block* block = const_cast(BedrockBlocks::mAir), + class Block* exblock = const_cast(BedrockBlocks::mAir)); + bool setBlockForHistory(class BlockSource* blockSource, + const BlockPos& pos, + class Block* block, + class Block* exblock); + class BlockInstance getBlockFromViewVector(FaceID& face, + bool includeLiquid = false, + bool solidOnly = false, + float maxDistance = 5.25f, + bool ignoreBorderBlocks = true, + bool fullOnly = false); + class BlockInstance getBlockFromViewVector(bool includeLiquid = false, + bool solidOnly = false, + float maxDistance = 5.25f, + bool ignoreBorderBlocks = true, + bool fullOnly = false); + ~PlayerData(); }; } // namespace worldedit \ No newline at end of file diff --git a/core/eval/Eval.cpp b/core/eval/Eval.cpp index 1daad1e..ec609c1 100644 --- a/core/eval/Eval.cpp +++ b/core/eval/Eval.cpp @@ -8,6 +8,7 @@ #include #include "FastNoiseLite.h" #include "Utils/RNG.h" +#include "I18nAPI.h" // #include #define tryGetParameter(size, params, n, f, t) \ @@ -60,8 +61,8 @@ namespace worldedit { try { posMap.resize(size.x * size.y * size.z + 1); solidMap = std::vector(size.x * size.y * size.z + 1, 0); - } catch (std::bad_alloc) { - Level::broadcastText("Out of memory", TextType::RAW); + } catch (...) { + Level::broadcastText(tr("worldedit.memory.out"), TextType::RAW); return; } posMap[size.x * size.y * size.z] = {0, 0, 0}; diff --git a/core/eval/blur.cpp b/core/eval/blur.cpp index f3e9313..6e78805 100644 --- a/core/eval/blur.cpp +++ b/core/eval/blur.cpp @@ -3,6 +3,7 @@ // #include "blur.hpp" #include "MC/Level.hpp" +#include "I18nAPI.h" namespace worldedit { @@ -40,8 +41,8 @@ namespace worldedit { std::vector res; try { res.resize(heightMap.size()); - } catch (std::bad_alloc) { - Level::broadcastText("Out of memory", TextType::RAW); + } catch (...) { + Level::broadcastText(tr("worldedit.memory.out"), TextType::RAW); return std::vector(0); } auto kernel = gaussianKernel(ksize); diff --git a/core/region/LoftRegion.cpp b/core/region/LoftRegion.cpp index d9e20e4..3a963ca 100644 --- a/core/region/LoftRegion.cpp +++ b/core/region/LoftRegion.cpp @@ -135,7 +135,7 @@ namespace worldedit { for (double t2 = 0; t2 <= 1.0; t2 += step2) { auto tmpPos = tmpCurve.getPosition(t2).toBlockPos(); posCache.insert(PosWithUV(tmpPos, 1 - t2, 1 - t)); - box = box.merge(tmpPos); + box.merge(tmpPos); } } boundingBox = box; diff --git a/core/store/Clipboard.hpp b/core/store/Clipboard.hpp index 63794d9..43742d0 100644 --- a/core/store/Clipboard.hpp +++ b/core/store/Clipboard.hpp @@ -7,6 +7,7 @@ #include #include #include +#include "I18nAPI.h" #include "BlockNBTSet.hpp" namespace worldedit { @@ -38,8 +39,8 @@ namespace worldedit { blockslist.clear(); try { blockslist.resize(vsize); - } catch (std::bad_alloc) { - Level::broadcastText("Out of memory", TextType::RAW); + } catch (...) { + Level::broadcastText(tr("worldedit.memory.out"), TextType::RAW); return; } } diff --git a/core/subscribe/player.cpp b/core/subscribe/player.cpp index 8a5b65d..b829ca4 100644 --- a/core/subscribe/player.cpp +++ b/core/subscribe/player.cpp @@ -123,7 +123,6 @@ namespace worldedit { } } else { tickMap[xuid] = tick; - auto& playerDataMap = getPlayersDataMap(); itemName += std::to_string(item->getAuxValue()); if (playerData.brushMap.find(itemName) != playerData.brushMap.end()) { @@ -167,13 +166,13 @@ namespace worldedit { void playerSubscribe() { Event::PlayerUseItemOnEvent::subscribe([](const Event::PlayerUseItemOnEvent& ev) { - std::cout << "PlayerUseItemOnEvent" << std::endl; + // std::cout << "PlayerUseItemOnEvent" << std::endl; return playerRightClick(ev.mPlayer, false, ev.mItemStack, *const_cast(&ev.mBlockInstance), static_cast(ev.mFace)); }); Event::PlayerUseItemEvent::subscribe([](const Event::PlayerUseItemEvent& ev) { - std::cout << "PlayerUseItemEvent" << std::endl; + // std::cout << "PlayerUseItemEvent" << std::endl; bool requiereWater = true; if (Level::getBlock(ev.mPlayer->getPosition().toBlockPos(), ev.mPlayer->getDimensionId()) != BedrockBlocks::mAir) { @@ -184,13 +183,13 @@ namespace worldedit { auto& playerData = getPlayersData(xuid); BlockInstance blockInstance = playerData.getBlockFromViewVector(face, requiereWater, false, 2048.0f); - std::cout << blockInstance.getBlock()->getTypeName() << std::endl; + // std::cout << blockInstance.getBlock()->getTypeName() << std::endl; return playerRightClick(ev.mPlayer, true, ev.mItemStack, blockInstance, face); }); Event::PlayerDestroyBlockEvent::subscribe([](const Event::PlayerDestroyBlockEvent& ev) { - std::cout << "PlayerDestroyBlockEvent" << std::endl; + // std::cout << "PlayerDestroyBlockEvent" << std::endl; bool requiereWater = true; if (Level::getBlock(ev.mPlayer->getPosition().toBlockPos(), ev.mPlayer->getDimensionId()) != BedrockBlocks::mAir) { @@ -205,7 +204,7 @@ namespace worldedit { }); Event::PlayerOpenContainerEvent::subscribe([](const Event::PlayerOpenContainerEvent& ev) { - std::cout << "PlayerOpenContainerEvent" << std::endl; + // std::cout << "PlayerOpenContainerEvent" << std::endl; bool requiereWater = true; if (Level::getBlock(ev.mPlayer->getPosition().toBlockPos(), ev.mPlayer->getDimensionId()) != BedrockBlocks::mAir) { @@ -219,7 +218,7 @@ namespace worldedit { }); Event::PlayerPlaceBlockEvent::subscribe([](const Event::PlayerPlaceBlockEvent& ev) { - std::cout << "PlayerPlaceBlockEvent" << std::endl; + // std::cout << "PlayerPlaceBlockEvent" << std::endl; bool requiereWater = true; if (Level::getBlock(ev.mPlayer->getPosition().toBlockPos(), ev.mPlayer->getDimensionId()) != BedrockBlocks::mAir) { @@ -241,7 +240,7 @@ THook(void, NetworkIdentifier const& networkIdentifier, AnimatePacket const& animatePacket) { if (animatePacket.mAction == AnimatePacket::Action::Swing) { - std::cout << "Swing" << std::endl; + // std::cout << "Swing" << std::endl; Player* player = serverNetworkHandler->getServerPlayer(networkIdentifier); bool requiereWater = true; if (Level::getBlock(player->getPosition().toBlockPos(), player->getDimensionId()) != BedrockBlocks::mAir) {