Skip to content

Commit

Permalink
Fix : hooper counter can not work when cross dimension
Browse files Browse the repository at this point in the history
  • Loading branch information
hhhxiao committed Apr 16, 2022
1 parent 42ca95f commit 2b4bbb7
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 8 deletions.
8 changes: 6 additions & 2 deletions api/block/Block.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,15 @@ namespace trapdoor {
//获取方块实体的位置
BlockPos *BlockActor::getPosition() {
return offset_cast<BlockPos *>(this, off::BLOCKACTOR_GET_POSITION);
// return reinterpret_cast<BlockPos *>(reinterpret_cast<VA>(this) + 44);
}
BlockSource *BlockActor::getBlockSource() {
BlockSource *BlockActor::getBlockSource() { // NOLINT
// TODO
return nullptr;
}
Block *BlockActor::getBlock() {
return SYM_CALL(trapdoor::Block * (*)(BlockActor *),
BlockActor_getBlock_64387bdc, this);
return nullptr;
}

} // namespace trapdoor
3 changes: 2 additions & 1 deletion api/block/Block.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ namespace trapdoor {
BlockPos* getPosition();

//获取方块对象
// Block *getBlock();
Block *getBlock();

//通过方块实体获取方块源
BlockSource* getBlockSource();
};
Expand Down
Binary file modified api/lib/SymHook.h
Binary file not shown.
24 changes: 19 additions & 5 deletions mod/function/HopperCounter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,15 +92,15 @@ namespace mod {
std::string stringBuilder;
trapdoor::MessageBuilder builder;
builder.textF("Channel [%d]: Total %d items in %d gt (%.3f min(s))\n",
channel, n, gameTick, gameTick / 1200.0);
channel, n, gameTick, gameTick / 1200.0f);

for (const auto &i : counterList) {
auto itemName = GetItemLocalName(i.first);
builder.textF(" - %s: ", itemName.c_str())
.sTextF(trapdoor::MSG_COLOR::GREEN, "%d", i.second)
.text("(")
.sTextF(trapdoor::MSG_COLOR::GREEN, "%.3f",
i.second * 1.0 / gameTick * 72000)
i.second * 1.0f / gameTick * 72000)
.text("/hour)\n");
}
builder.send(actor);
Expand All @@ -121,9 +121,23 @@ THook(void, HopperBlockActor_setItem_c0e5f3ce,
auto real_this = reinterpret_cast<trapdoor::BlockActor *>(
reinterpret_cast<VA>(hopperActor) - 200);
auto position = real_this->getPosition();
L_DEBUG("postion is:%d %d %d", position->x, position->y, position->z);
auto nearestPlayer =
trapdoor::bdsMod->getLevel()->getNearestPlayer(*position);
L_DEBUG("position is:%d %d %d", position->x, position->y, position->z);
auto block = real_this->getBlockSource();

trapdoor::Actor *nearestPlayer = nullptr;

auto *hopper_block = real_this->getBlock();

trapdoor::bdsMod->getLevel()->forEachPlayer([&](trapdoor::Actor *player) {
if (!player) return;
auto bs = player->getBlockSource();
if (!bs) return;
auto *block = bs->getBlock(*position);
if (hopper_block && block && block == hopper_block) {
nearestPlayer = player;
}
});

if (!nearestPlayer) {
original(hopperActor, index, itemStack);
return;
Expand Down
3 changes: 3 additions & 0 deletions tools/sym/user_sym
Original file line number Diff line number Diff line change
Expand Up @@ -152,3 +152,6 @@

#获取区块坐标
?getPosition@LevelChunk@@QEBAAEBVChunkPos@@XZ

#从BlockActor获取Block对象
?getBlock@BlockActor@@QEBAPEBVBlock@@XZ

0 comments on commit 2b4bbb7

Please sign in to comment.