Skip to content

Commit

Permalink
faet: add most region
Browse files Browse the repository at this point in the history
  • Loading branch information
OEOTYAN committed Apr 6, 2024
1 parent 0e85353 commit 4465f54
Show file tree
Hide file tree
Showing 121 changed files with 11,720 additions and 10,625 deletions.
43 changes: 20 additions & 23 deletions old/core/brush/Brush.cpp
Original file line number Diff line number Diff line change
@@ -1,31 +1,28 @@
//
// Created by OEOTYAN on 2022/06/10.
//
#include "Brush.h"
#include "store/Patterns.h"
#include <mc/BlockInstance.hpp>
#include <mc/Player.hpp>
#include "store/Patterns.h"
namespace worldedit {
long long Brush::set(Player* player, ::BlockInstance blockInstance) {
return -2;
}
long long Brush::lset(Player* player, ::BlockInstance blockInstance) {
return -2;
}
bool Brush::maskFunc(EvalFunctions& func,
const phmap::flat_hash_map<std::string, double>& var,
std::function<void()> const& todo) {
if (mask != "") {
if (cpp_eval::eval<double>(mask, var, func) > 0.5) {
todo();
return true;
}
} else {
namespace we {
long long Brush::set(Player* player, ::BlockInstance blockInstance) { return -2; }
long long Brush::lset(Player* player, ::BlockInstance blockInstance) { return -2; }
bool Brush::maskFunc(
EvalFunctions& func,
const phmap::flat_hash_map<std::string, double>& var,
std::function<void()> const& todo
) {
if (mask != "") {
if (cpp_eval::eval<double>(mask, var, func) > 0.5) {
todo();
return true;
}
return false;
} else {
todo();
return true;
}
return false;
}

Brush::Brush(unsigned short s, std::unique_ptr<Pattern> p) : size(s), pattern(std::move(p)) {}
} // namespace worldedit
Brush::Brush(unsigned short s, std::unique_ptr<Pattern> p)
: size(s),
pattern(std::move(p)) {}
} // namespace we
45 changes: 22 additions & 23 deletions old/core/brush/Brush.h
Original file line number Diff line number Diff line change
@@ -1,27 +1,26 @@
//
// Created by OEOTYAN on 2022/06/09.
//
#pragma once
#include <mc/BlockInstance.hpp>
#include <mc/Player.hpp>
#include "eval/Eval.h"
#include "store/Patterns.h"
#include <mc/BlockInstance.hpp>
#include <mc/Player.hpp>

namespace worldedit {
class Brush {
public:
unsigned short size = 0;
std::unique_ptr<Pattern> pattern = nullptr;
std::string mask = "";
bool needFace = false;
bool lneedFace = false;
Brush() {}
Brush(unsigned short, std::unique_ptr<Pattern> p);
void setMask(std::string_view str = "") { mask = str; };
virtual long long set(class Player*, class ::BlockInstance);
virtual long long lset(class Player*, class ::BlockInstance);
bool maskFunc(class EvalFunctions& func,
const phmap::flat_hash_map<std::string, double>& var,
std::function<void()> const& todo);
};
} // namespace worldedit
namespace we {
class Brush {
public:
unsigned short size = 0;
std::unique_ptr<Pattern> pattern = nullptr;
std::string mask = "";
bool needFace = false;
bool lneedFace = false;
Brush() {}
Brush(unsigned short, std::unique_ptr<Pattern> p);
void setMask(std::string_view str = "") { mask = str; };
virtual long long set(class Player*, class ::BlockInstance);
virtual long long lset(class Player*, class ::BlockInstance);
bool maskFunc(
class EvalFunctions& func,
const phmap::flat_hash_map<std::string, double>& var,
std::function<void()> const& todo
);
};
} // namespace we
19 changes: 8 additions & 11 deletions old/core/brush/Brushs.h
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
//
// Created by OEOTYAN on 2022/06/09.
//
#pragma once

#include "tool.h"
#include "Brush.h"
#include "MixBrush.h"
#include "FlatBrush.h"
#include "CubeBrush.h"
#include "ClipboardBrush.h"
#include "ColorBrush.h"
#include "CubeBrush.h"
#include "CylinderBrush.h"
#include "DeformBrush.h"
#include "SmoothBrush.h"
#include "SphereBrush.h"
#include "FlatBrush.h"
#include "GravityBrush.h"
#include "CylinderBrush.h"
#include "ClipboardBrush.h"
#include "ImageHeightmapBrush.h"
#include "MixBrush.h"
#include "SmoothBrush.h"
#include "SphereBrush.h"
#include "tool.h"
130 changes: 66 additions & 64 deletions old/core/brush/ClipboardBrush.cpp
Original file line number Diff line number Diff line change
@@ -1,76 +1,78 @@
//
// Created by OEOTYAN on 2022/06/10.
//

#include "ClipboardBrush.h"
#include "store/Patterns.h"
#include "WorldEdit.h"
#include "store/BlockNBTSet.hpp"
#include "store/Patterns.h"
#include <mc/Player.hpp>
#include "WorldEdit.h"

namespace worldedit {
ClipboardBrush::ClipboardBrush(unsigned short s, Clipboard& c, bool o, bool a)
: Brush(s, nullptr), center(o), ignoreAir(a), clipboard(c) {}
long long ClipboardBrush::set(Player* player, BlockInstance blockInstance) {
if (blockInstance == BlockInstance::Null) {
return -2;
}
auto xuid = player->getXuid();
auto& playerData = getPlayersData(xuid);
BlockPos pbPos;
if (center) {
BoundingBox box(BlockPos::ZERO, clipboard.board);
pbPos = blockInstance.getPosition() - box.getCenter() + clipboard.playerRelPos;
} else {
pbPos = blockInstance.getPosition();
}
auto dimID = player->getDimensionId();
namespace we {
ClipboardBrush::ClipboardBrush(unsigned short s, Clipboard& c, bool o, bool a)
: Brush(s, nullptr),
center(o),
ignoreAir(a),
clipboard(c) {}
long long ClipboardBrush::set(Player* player, BlockInstance blockInstance) {
if (blockInstance == BlockInstance::Null) {
return -2;
}
auto xuid = player->getXuid();
auto& playerData = getPlayersData(xuid);
BlockPos pbPos;
if (center) {
BoundingBox box(BlockPos::ZERO, clipboard.board);
pbPos = blockInstance.getPosition() - box.getCenter() + clipboard.playerRelPos;
} else {
pbPos = blockInstance.getPosition();
}
auto dimID = player->getDimensionId();

auto playerPos = player->getPosition();
auto playerRot = player->getRotation();
auto blockSource = &player->getDimensionBlockSource();
BoundingBox box = clipboard.getBoundingBox() + pbPos;
auto playerPos = player->getPosition();
auto playerRot = player->getRotation();
auto blockSource = &player->getDimensionBlockSource();
BoundingBox box = clipboard.getBoundingBox() + pbPos;

if (playerData.maxHistoryLength > 0) {
auto& history = playerData.getNextHistory();
history = std::move(Clipboard(box.max - box.min));
history.playerRelPos.x = dimID;
history.playerPos = box.min;
box.forEachBlockInBox([&](const BlockPos& pos) {
auto localPos = pos - box.min;
auto blockInstance = blockSource->getBlockInstance(pos);
history.storeBlock(blockInstance, localPos);
});
}
if (playerData.maxHistoryLength > 0) {
auto& history = playerData.getNextHistory();
history = std::move(Clipboard(box.max - box.min));
history.playerRelPos.x = dimID;
history.playerPos = box.min;
box.forEachBlockInBox([&](BlockPos const& pos) {
auto localPos = pos - box.min;
auto blockInstance = blockSource->getBlockInstance(pos);
history.storeBlock(blockInstance, localPos);
});
}

EvalFunctions f;
f.setbs(blockSource);
f.setbox(box);
phmap::flat_hash_map<std::string, double> variables;
playerData.setVarByPlayer(variables);
long long i = 0;
if (ignoreAir) {
clipboard.forEachBlockInClipboard([&](const BlockPos& pos) {
if (clipboard.getSet(pos).getBlock() == BedrockBlocks::mAir &&
clipboard.getSet(pos).getExBlock() == BedrockBlocks::mAir) {
return;
}
auto worldPos = clipboard.getPos(pos) + pbPos;
EvalFunctions f;
f.setbs(blockSource);
f.setbox(box);
phmap::flat_hash_map<std::string, double> variables;
playerData.setVarByPlayer(variables);
long long i = 0;
if (ignoreAir) {
clipboard.forEachBlockInClipboard([&](BlockPos const& pos) {
if (clipboard.getSet(pos).getBlock() == BedrockBlocks::mAir
&& clipboard.getSet(pos).getExBlock() == BedrockBlocks::mAir) {
return;
}
auto worldPos = clipboard.getPos(pos) + pbPos;

setFunction(variables, f, box, playerPos, worldPos, box.toAABB().getCenter());
maskFunc(f, variables, [&]() mutable {
i += playerData.clipboard.setBlocks(pos, worldPos, blockSource, playerData, f, variables);
});
setFunction(variables, f, box, playerPos, worldPos, box.toAABB().getCenter());
maskFunc(f, variables, [&]() mutable {
i += playerData.clipboard
.setBlocks(pos, worldPos, blockSource, playerData, f, variables);
});
} else {
clipboard.forEachBlockInClipboard([&](const BlockPos& pos) {
auto worldPos = clipboard.getPos(pos) + pbPos;
setFunction(variables, f, box, playerPos, worldPos, box.toAABB().getCenter());
maskFunc(f, variables, [&]() mutable {
i += playerData.clipboard.setBlocks(pos, worldPos, blockSource, playerData, f, variables);
});
});
} else {
clipboard.forEachBlockInClipboard([&](BlockPos const& pos) {
auto worldPos = clipboard.getPos(pos) + pbPos;
setFunction(variables, f, box, playerPos, worldPos, box.toAABB().getCenter());
maskFunc(f, variables, [&]() mutable {
i += playerData.clipboard
.setBlocks(pos, worldPos, blockSource, playerData, f, variables);
});
}
return i;
});
}
} // namespace worldedit
return i;
}
} // namespace we
23 changes: 10 additions & 13 deletions old/core/brush/ClipboardBrush.h
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
//
// Created by OEOTYAN on 2022/06/10.
//
#pragma once

#include "Brush.h"
#include "store/Clipboard.hpp"
namespace worldedit {
class ClipboardBrush final : public Brush {
public:
Clipboard clipboard;
bool center = true;
bool ignoreAir = false;
ClipboardBrush(unsigned short, Clipboard&, bool, bool);
long long set(Player* player, BlockInstance blockInstance) override;
};
} // namespace worldedit
namespace we {
class ClipboardBrush : public Brush {
public:
Clipboard clipboard;
bool center = true;
bool ignoreAir = false;
ClipboardBrush(unsigned short, Clipboard&, bool, bool);
long long set(Player* player, BlockInstance blockInstance) override;
};
} // namespace we
Loading

0 comments on commit 4465f54

Please sign in to comment.