Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
OEOTYAN committed Feb 2, 2023
1 parent 2d00ffa commit 57b4b74
Show file tree
Hide file tree
Showing 45 changed files with 776 additions and 430 deletions.
7 changes: 2 additions & 5 deletions core/brush/Brush.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@
#include "Brush.h"
#include <mc/BlockInstance.hpp>
#include <mc/Player.hpp>
#include "store/BlockPattern.hpp"
#include "store/Patterns.h"
namespace worldedit {
Brush::~Brush() {
delete pattern;
pattern = nullptr;
}
long long Brush::set(Player* player, ::BlockInstance blockInstance) {
return -2;
Expand All @@ -31,6 +29,5 @@ namespace worldedit {
return false;
}

Brush::Brush(unsigned short s, BlockPattern* bp) : size(s), pattern(bp) {
}
Brush::Brush(unsigned short s, std::unique_ptr<Pattern> p) : size(s), pattern(std::move(p)) {}
} // namespace worldedit
15 changes: 9 additions & 6 deletions core/brush/Brush.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,24 @@
#include <mc/BlockInstance.hpp>
#include <mc/Player.hpp>
#include "eval/Eval.h"
#include "store/Patterns.h"

namespace worldedit {
class Brush {
public:
unsigned short size = 0;
class BlockPattern* pattern = nullptr;
std::unique_ptr<Pattern> pattern = nullptr;
std::string mask = "";
bool needFace = false;
bool lneedFace = false;
Brush(){}
Brush(unsigned short, BlockPattern*);
Brush() {}
Brush(unsigned short, std::unique_ptr<Pattern> p);
void setMask(std::string const& 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 std::unordered_map<std::string, double>& var,
std::function<void()> const& todo);
virtual long long lset(class Player*, class ::BlockInstance);
bool maskFunc(class EvalFunctions& func,
const std::unordered_map<std::string, double>& var,
std::function<void()> const& todo);

virtual ~Brush();
};
Expand Down
1 change: 1 addition & 0 deletions core/brush/Brushs.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "tool.h"
#include "Brush.h"
#include "MixBrush.h"
#include "FlatBrush.h"
#include "CubeBrush.h"
#include "ColorBrush.h"
#include "DeformBrush.h"
Expand Down
2 changes: 1 addition & 1 deletion core/brush/ClipboardBrush.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
//

#include "ClipboardBrush.h"
#include "store/BlockPattern.hpp"
#include "store/Patterns.h"
#include "store/BlockNBTSet.hpp"
#include <mc/Player.hpp>
#include "WorldEdit.h"
Expand Down
24 changes: 6 additions & 18 deletions core/brush/ColorBrush.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,18 @@
#include "WorldEdit.h"
#include "utils/ColorTool.h"
#include "mc/StaticVanillaBlocks.hpp"
#include "mc/GrassBlock.hpp"
#include "mc/BlockSource.hpp"
#include "mc/BlockInstance.hpp"
#include "store/BlockPattern.hpp"
#include "store/Patterns.h"

namespace worldedit {
ColorBrush::ColorBrush(unsigned short size,
float density,
float opacity,
mce::Color color,
class BlockPattern* bp,
std::unique_ptr<Pattern> bp,
bool mixbox)
: Brush(size, bp), density(density), opacity(opacity), color(color), useMixboxLerp(mixbox) {}
: Brush(size, std::move(bp)), density(density), opacity(opacity), color(color), useMixboxLerp(mixbox) {}

long long ColorBrush::set(Player* player, BlockInstance blockInstance) {
long long iter = 0;
Expand Down Expand Up @@ -129,24 +128,14 @@ namespace worldedit {
if (cmap.find(block) != cmap.end()) {
hereColor = cmap[block];
}
// else if (block == StaticVanillaBlocks::mGrass) {
// mce::Color tmpColor =
// dynamic_cast<GrassBlock*>(const_cast<BlockLegacy*>(block->getLegacyBlockPtr()))
// ->getMapColor(*blockSource, pos1, *block);
// if (tmpColor.a != 0) {
// hereColor = cmap[block];
// }
// }
// logger().debug("hereColor {}", finalColor.toHexString());
// logger().debug("finalColor {}", finalColor.toHexString());

hereColor = useMixboxLerp ? mixboxLerp(hereColor, finalColor,
smoothBrushAlpha(static_cast<float>(pos1.distanceTo(pos0)),
density, opacity, size))
: linearLerp(hereColor, finalColor,
smoothBrushAlpha(static_cast<float>(pos1.distanceTo(pos0)),
density, opacity, size));
// logger().debug("hereColor {}", hereColor.toHexString());
// logger().debug("minDist");

double minDist = DBL_MAX;
Block* minBlock = nullptr;
for (auto& i : getColorBlockMap()) {
Expand All @@ -158,8 +147,7 @@ namespace worldedit {
}
}
}
// logger().debug("{}", (unsigned long long)(minBlock));
// logger().debug("setBlockSimple");

iter += playerData.setBlockSimple(blockSource, f, variables, pos1, minBlock);
});
}
Expand Down
2 changes: 1 addition & 1 deletion core/brush/ColorBrush.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace worldedit {
float opacity = 1;
bool useMixboxLerp = true;
mce::Color color = {1, 1, 1, 1};
ColorBrush(unsigned short size, float density, float opacity, mce::Color color, class BlockPattern* bp,bool mixbox);
ColorBrush(unsigned short size, float density, float opacity, mce::Color color, std::unique_ptr<Pattern> bp,bool mixbox);
long long set(Player* player, BlockInstance blockInstance) override;
};
} // namespace worldedit
5 changes: 3 additions & 2 deletions core/brush/CubeBrush.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@

#include "CubeBrush.h"
#include "builder/SimpleBuilder.h"
#include "store/Patterns.h"

namespace worldedit {
CubeBrush::CubeBrush(unsigned short s, BlockPattern* bp, bool a) : Brush(s, bp), hollow(a) {}
CubeBrush::CubeBrush(unsigned short s, std::unique_ptr<Pattern> bp, bool a) : Brush(s, std::move(bp)), hollow(a) {}
long long CubeBrush::set(Player* player, BlockInstance blockInstance) {
if (blockInstance == BlockInstance::Null) {
return -2;
}
return SimpleBuilder::buildCube(blockInstance.getPosition(), blockInstance.getDimensionId(), player->getXuid(),
pattern, size, hollow,mask);
pattern.get(), size, hollow, mask);
}
} // namespace worldedit
2 changes: 1 addition & 1 deletion core/brush/CubeBrush.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace worldedit {
class CubeBrush : public Brush {
public:
bool hollow = false;
CubeBrush(unsigned short, BlockPattern*, bool);
CubeBrush(unsigned short, std::unique_ptr<Pattern>, bool);
long long set(Player* player, BlockInstance blockInstance) override;
};
} // namespace worldedit
7 changes: 4 additions & 3 deletions core/brush/CylinderBrush.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@

#include "CylinderBrush.h"
#include "builder/SimpleBuilder.h"
#include "store/Patterns.h"
namespace worldedit {
CylinderBrush::CylinderBrush(unsigned short s, BlockPattern* bp, int h, bool a)
: Brush(s, bp), height(h), hollow(a) {}
CylinderBrush::CylinderBrush(unsigned short s, std::unique_ptr<Pattern> bp, int h, bool a)
: Brush(s, std::move(bp)), height(h), hollow(a) {}
long long CylinderBrush::set(Player* player, BlockInstance blockInstance) {
if (blockInstance == BlockInstance::Null) {
return -2;
}
return SimpleBuilder::buildCylinder(blockInstance.getPosition(), blockInstance.getDimensionId(),
player->getXuid(), pattern, size, height, hollow,mask);
player->getXuid(), pattern.get(), size, height, hollow, mask);
}
} // namespace worldedit
2 changes: 1 addition & 1 deletion core/brush/CylinderBrush.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace worldedit {
public:
bool hollow = false;
int height = 0;
CylinderBrush(unsigned short, BlockPattern*, int, bool);
CylinderBrush(unsigned short, std::unique_ptr<Pattern>, int, bool);
long long set(Player* player, BlockInstance blockInstance) override;
};
} // namespace worldedit
70 changes: 70 additions & 0 deletions core/brush/FlatBrush.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
//
// Created by OEOTYAN on 2023/02/03.
//

#include "Global.h"
#include "FlatBrush.h"
#include "mc/Level.hpp"
#include "WorldEdit.h"
#include "mc/Dimension.hpp"
#include "utils/ColorTool.h"
#include "region/CuboidRegion.h"

namespace worldedit {
FlatBrush::FlatBrush(unsigned short size, float density) : Brush(size, nullptr), density(density) {}

long long FlatBrush::set(Player* player, BlockInstance blockInstance) {
if (blockInstance == BlockInstance::Null) {
return -2;
}
auto pos = blockInstance.getPosition();

auto xuid = player->getXuid();
auto& playerData = getPlayersData(xuid);
auto dimID = player->getDimensionId();
auto blockSource = &player->getRegion();

BoundingBox box(pos - size, pos + size);
box.min.y = pos.y;
box.max.y = pos.y;

int sizex = box.max.x - box.min.x + 1;
int sizez = box.max.z - box.min.z + 1;
std::vector<double> heightMap(sizex * sizez, -1e200);
auto range =
reinterpret_cast<Dimension*>(Global<Level>->getDimension(dimID).mHandle.lock().get())->getHeightRange();
for (int x = box.min.x; x <= box.max.x; ++x)
for (int z = box.min.z; z <= box.max.z; ++z) {
auto topy = getHighestTerrainBlock(blockSource, x, z, range.min, range.max, mask);
if (topy >= range.min && topy <= range.max) {
int cx = x - box.min.x;
int cz = z - box.min.z;
heightMap[cx * sizez + cz] =
std::lerp(topy + 0.5, pos.y + 0.5,
static_cast<double>(smoothBrushAlpha(
static_cast<float>(sqrt(pow2(x - pos.x) + pow2(z - pos.z))), density, 1, size)));
box.merge(BlockPos(x, topy, z));
}
}
box.min.y = std::max(static_cast<int>(range.min), box.min.y - 1);
box.max.y = std::min(static_cast<int>(range.max), box.max.y + 1);

if (playerData.maxHistoryLength > 0) {
auto history = playerData.getNextHistory();
*history = 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);
});
}

// logger().debug("applyHeightMap");
CuboidRegion(box, dimID).applyHeightMap(heightMap, xuid, mask);

return -2;
}

} // namespace worldedit
16 changes: 16 additions & 0 deletions core/brush/FlatBrush.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//
// Created by OEOTYAN on 2023/02/03.
//

#pragma once

#include "Brush.h"

namespace worldedit {
class FlatBrush : public Brush {
public:
float density;
FlatBrush(unsigned short size, float density);
long long set(Player* player, BlockInstance blockInstance) override;
};
} // namespace worldedit
2 changes: 1 addition & 1 deletion core/brush/ImageHeightmapBrush.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
//

#include "ImageHeightmapBrush.h"
#include "store/BlockPattern.hpp"
#include "store/Patterns.h"
#include "mc/Dimension.hpp"
#include "WorldEdit.h"

Expand Down
16 changes: 1 addition & 15 deletions core/brush/MixBrush.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,21 +82,7 @@ namespace worldedit {
return -2;
}

mce::Color finalColor;
int colorCount = 0;

for (auto& c : bColor) {
if (colorCount != 0) {
int lastColorCount = colorCount;
colorCount += c.second;
finalColor = useMixboxLerp
? mixboxLerp(c.first, finalColor, static_cast<float>(lastColorCount) / colorCount)
: linearLerp(c.first, finalColor, static_cast<float>(lastColorCount) / colorCount);
} else {
colorCount = c.second;
finalColor = c.first;
}
}
mce::Color finalColor = useMixboxLerp ? mixboxAverage(bColor) : linearAverage(bColor);

worldedit::Clipboard* history = nullptr;

Expand Down
Loading

0 comments on commit 57b4b74

Please sign in to comment.