Skip to content

Commit

Permalink
reapir village
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaohengying committed Dec 3, 2021
1 parent b9bc883 commit d093297
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 47 deletions.
1 change: 1 addition & 0 deletions api/block/BlockSource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ namespace trapdoor {
}

Block *BlockSource::getBlock(const BlockPos &blockPos) {
printf("%d %d %d)", blockPos.x, blockPos.y, blockPos.z);
return SYM_CALL(Block * (*)(void *, const BlockPos &),
BlockSource_getBlock_b39e5e5d, this, blockPos);
}
Expand Down
2 changes: 1 addition & 1 deletion mod/TrapdoorMod.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ namespace mod {
void TrapdoorMod::useOnHook(Actor *player, const std::string &itemName,
BlockPos &pos, unsigned int facing,
const Vec3 &v) {
// L_INFO("%.2f %.2f %.2f %s", v.x, v.y, v.z, itemName.c_str());
L_INFO("%.2f %.2f %.2f %s", v.x, v.y, v.z, itemName.c_str());
//取消注释这一行可以看到右击地面的是什么东西
if (itemName == "Bone" && this->spawnHelper.isEnable()) {
spawnHelper.updateVerticalSpawnPositions(pos, player);
Expand Down
60 changes: 29 additions & 31 deletions mod/function/BlockRotationHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ namespace mod {
using trapdoor::BlockSource;
if (!this->enable) return;
auto block = blockSource->getBlock(pos);
printf("%d(%s)", block->getLegacy()->getBlockID(),
block->getName().c_str());
auto air = trapdoor::getBlockByID(trapdoor::AIR);
auto variant = block->getVariant();
auto name = block->getName();
Expand Down Expand Up @@ -49,12 +51,12 @@ namespace mod {
blockSource->setBlock(&pos, newBlock);
}

// else if (name.find("cake") != std::string::npos) {
// auto newState = (variant + 1) % 7;
// auto newBlock =
// block->getLegacy()->tryGetStateBlock(newState);
// blockSource->setBlock(&pos, newBlock);
// }
// else if (name.find("cake") != std::string::npos) {
// auto newState = (variant + 1) % 7;
// auto newBlock =
// block->getLegacy()->tryGetStateBlock(newState);
// blockSource->setBlock(&pos, newBlock);
// }
else if (name.find("grindstone") != std::string::npos) {
auto newState = (variant + 1) % 12;
auto newBlock = block->getLegacy()->tryGetStateBlock(newState);
Expand Down Expand Up @@ -118,24 +120,26 @@ namespace mod {
}
}

void BlockRotationHelper::addAction(const std::initializer_list<std::string> &patterns,
const RotateAction &rotateAction) {
void BlockRotationHelper::addAction(
const std::initializer_list<std::string> &patterns,
const RotateAction &rotateAction) {
std::set<std::string> pat(patterns);
this->actionList.emplace_back(patterns, rotateAction);

}

void
BlockRotationHelper::newRotate(trapdoor::BlockPos &pos, trapdoor::BlockSource *blockSource, const trapdoor::Vec3 &v,
trapdoor::FACING facing) const {
void BlockRotationHelper::newRotate(trapdoor::BlockPos &pos,
trapdoor::BlockSource *blockSource,
const trapdoor::Vec3 &v,
trapdoor::FACING facing) const {
auto block = blockSource->getBlock(pos);
auto variant = block->getVariant();
auto blockName = blockSource->getBlock(pos)->getName();
for (const auto &act:actionList) {
for (const auto &act : actionList) {
if (act.match(blockName)) {
auto newVariant = act.action(variant, v, facing);
if (newVariant != variant) {
auto newBlock = block->getLegacy()->tryGetStateBlock(newVariant);
auto newBlock =
block->getLegacy()->tryGetStateBlock(newVariant);
auto air = trapdoor::getBlockByID(trapdoor::AIR);
blockSource->setBlock(&pos, air);
blockSource->setBlock(&pos, newBlock);
Expand All @@ -146,29 +150,23 @@ namespace mod {
}

void BlockRotationHelper::init() {
using trapdoor::BlockSource;
using trapdoor::FACING;
using trapdoor::Vec3;
using trapdoor::BlockSource;
this->addAction({"piston", "repeater"},
//根据当前特殊值,玩家点击的位置和方向来返回新的特殊值
[](int variant, const Vec3 &v, FACING facing) {
return variant;
});

this->addAction({"cake"},
[](int variant, const Vec3 &v, FACING facing) {
return variant;
});



this->addAction(
{"piston", "repeater"},
//根据当前特殊值,玩家点击的位置和方向来返回新的特殊值
[](int variant, const Vec3 &v, FACING facing) { return variant; });

this->addAction({"cake"}, [](int variant, const Vec3 &v,
FACING facing) { return variant; });
}

bool BlockRotateAction::match(const std::string &name) const {
return std::any_of(patterns.begin(), patterns.end(), [&](const std::string &pattern) {
return pattern.find(name) != std::string::npos;
});
return std::any_of(patterns.begin(), patterns.end(),
[&](const std::string &pattern) {
return pattern.find(name) != std::string::npos;
});
}

} // namespace mod
27 changes: 12 additions & 15 deletions mod/village/Village.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ namespace mod {
const size_t GOLEM_NUM_OFFSET = 30;
// from Village::_trySpawnDefenderDwellers
const size_t DWELLER_POI_MAP_OFFSET = 96;

const size_t DWELLER_TICK_MAP_OFFSET = 160;
// Village::_getDwellerMap
const size_t DWELLER_TICK_MAP_OFFSET = 152;

struct DwellerData {
uint64_t tick;
Expand Down Expand Up @@ -89,15 +89,15 @@ namespace mod {

// get worked villager num
int Village::getWorkedVillagerNum() {
// from Village::_trySpawnDefenderDwellers
auto timeOfDay = *(reinterpret_cast<int64_t *>(this) + 60) - 24000;
auto begin = *(reinterpret_cast<int64_t *>(this) + 85);
auto end = *(reinterpret_cast<int64_t *>(this) + 86);
int num;
for (num = 0; begin != end; begin += 16) {
if (*(int64_t *)(begin + 8) > timeOfDay) ++num;
}
return num;
// from Village::_trySpawnDefenderDwellers
// auto timeOfDay = *(reinterpret_cast<int64_t *>(this) + 54) - 24000;
// auto begin = *(reinterpret_cast<int64_t *>(this) + 76);
// auto end = *(reinterpret_cast<int64_t *>(this) + 77);
// int num;
// for (num = 0; begin != end; begin += 16) {
// if (*(int64_t *)(begin + 8) > timeOfDay) ++num;
// }
return -1;
}

// check can actor iron golem
Expand Down Expand Up @@ -345,17 +345,14 @@ namespace mod {
.num(village->getIronGolemNum())
.text(" b:")
.num(village->getBedPOICount())
.text(" s:")
.num((int)village->canSpawnIronGolem())
.text(" [")
.pos(aabb.p1.toBlockPos())
.text("-")
.text("")
.pos(aabb.p2.toBlockPos())
.text("]\n");
}
}
builder.send(player);
// builder.send();
}

void VillageHelper::tick() {
Expand Down

0 comments on commit d093297

Please sign in to comment.