Skip to content

Commit

Permalink
feat(devtools): add block shape data to DevTools
Browse files Browse the repository at this point in the history
* feat(devtools): add more block shapes' data

* feat(devtools): add liquid clip shape

* refactor: introduce isAABBValid() function

* chores: remove unused collisionShapeForCamera

* fix: correct the signature of shape-related methods in Block class

---------

Co-authored-by: Vincent <[email protected]>
  • Loading branch information
smartcmd and wu-vincent authored Sep 28, 2024
1 parent d1a582e commit ab5d9f3
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 1 deletion.
25 changes: 25 additions & 0 deletions include/bedrock/world/level/block/block.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,31 @@ class Block : public BlockComponentStorage {
return out_aabb.min.x < out_aabb.max.x && out_aabb.min.y < out_aabb.max.y && out_aabb.min.z < out_aabb.max.z;
}

bool getCollisionShapeForCamera(AABB &out_aabb, IConstBlockSource const &region, BlockPos const &pos) const
{
return legacy_block_->getCollisionShapeForCamera(out_aabb, *this, region, pos);
}

const AABB &getOutline(IConstBlockSource const &region, BlockPos const &pos, AABB &buffer) const
{
return legacy_block_->getOutline(*this, region, pos, buffer);
}

const AABB &getVisualShape(AABB &buffer) const
{
return legacy_block_->getVisualShape(*this, buffer);
}

const AABB &getUIShape(AABB &buffer) const
{
return legacy_block_->getUIShape(*this, buffer);
}

bool getLiquidClipShape(BlockSource &region, BlockPos const &pos, AABB &include_box) const
{
return legacy_block_->getLiquidClipVolume(*this, region, pos, include_box);
}

private:
friend class ItemStackBase;

Expand Down
46 changes: 45 additions & 1 deletion src/endstone_devtools/vanilla_data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,16 @@ void dumpBlockData(VanillaData &data, ::Level &level)
}

block_legacy.forEachBlockPermutation([&](const ::Block &block) {
AABB collision_shape = {0};
AABB collision_shape;
AABB outline_shape;
AABB visual_shape;
AABB ui_shape;
AABB liquid_clip_shape;
block.getCollisionShape(collision_shape, region, {0, 0, 0}, nullptr);
outline_shape = block.getOutline(region, {0, 0, 0}, outline_shape);
visual_shape = block.getVisualShape(visual_shape);
ui_shape = block.getUIShape(ui_shape);
block.getLiquidClipShape(region, {0, 0, 0}, liquid_clip_shape);
auto map_color = block.getLegacyBlock().getMapColor(region, {0, 10, 0}, block);
data.block_states.push_back({
{"name", name},
Expand All @@ -121,6 +129,42 @@ void dumpBlockData(VanillaData &data, ::Level &level)
round(collision_shape.max.y),
round(collision_shape.max.z),
}},
{"outlineShape",
{
round(outline_shape.min.x),
round(outline_shape.min.y),
round(outline_shape.min.z),
round(outline_shape.max.x),
round(outline_shape.max.y),
round(outline_shape.max.z),
}},
{"visualShape",
{
round(visual_shape.min.x),
round(visual_shape.min.y),
round(visual_shape.min.z),
round(visual_shape.max.x),
round(visual_shape.max.y),
round(visual_shape.max.z),
}},
{"uiShape",
{
round(ui_shape.min.x),
round(ui_shape.min.y),
round(ui_shape.min.z),
round(ui_shape.max.x),
round(ui_shape.max.y),
round(ui_shape.max.z),
}},
{"liquidClipShape",
{
round(liquid_clip_shape.min.x),
round(liquid_clip_shape.min.y),
round(liquid_clip_shape.min.z),
round(liquid_clip_shape.max.x),
round(liquid_clip_shape.max.y),
round(liquid_clip_shape.max.z),
}},
});
data.block_palette.add(block.getSerializationId().copy());
return true;
Expand Down

0 comments on commit ab5d9f3

Please sign in to comment.