Skip to content

Add drawAdditionalCallback to StructurePipRenderingState#50

Merged
Gu-ZT merged 2 commits into
Anvil-Dev:dev/26.1from
ZhuRuoLing:feat/1.26.1/draw_additional
Jun 21, 2026
Merged

Add drawAdditionalCallback to StructurePipRenderingState#50
Gu-ZT merged 2 commits into
Anvil-Dev:dev/26.1from
ZhuRuoLing:feat/1.26.1/draw_additional

Conversation

@ZhuRuoLing

Copy link
Copy Markdown
Contributor

Add Support for Additional Draw Callbacks in Structure Picture-in-Picture Rendering

What's Changed

This PR adds support for custom drawing callbacks in the structure picture-in-picture (PiP) rendering system, enabling more flexible rendering of additional elements during structure visualization.

Changes Summary

  1. GuiRenderExtras.java

    • Added new overloaded submitStructure() methods that accept a BiConsumer<SubmitNodeCollector, PoseStack> callback parameter for drawing additional elements
    • Updated existing submitStructure() calls to pass null as the new callback parameter for backward compatibility
    • Added import for BiConsumer and SubmitNodeCollector
  2. StructurePipRenderer.java

    • Moved RenderBuffers, SubmitNodeStorage, GameRenderer, and FeatureRenderDispatcher initialization outside the loop to improve performance
    • Added callback invocation after block entities are rendered but before feature rendering
    • Added pose stack validation to ensure proper pose stack state after rendering
    • Improved buffer management with additional endBatch() call
  3. StructurePipRenderingState.java

    • Extended the record to include drawAdditionalCallback field
    • Updated both constructors to accept and pass through the callback parameter
    • Added necessary imports for BiConsumer and SubmitNodeCollector

Benefits

  • Extensibility: Allows custom rendering logic to be injected into the structure PiP rendering pipeline
  • Performance: Optimized render state initialization by moving it outside the block entity loop
  • Robustness: Added pose stack validation to catch rendering state errors

Type of Change

  • ✨ Feature addition
  • 🔧 Performance improvement
  • 🛡️ Code robustness enhancement

ZhuRuoLing

This comment was marked as spam.

@ZhuRuoLing ZhuRuoLing left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review Summary

Verdict: Approved ✅ (0 critical, 0 warnings, 3 suggestions)

PR: #50 -- Add drawAdditionalCallback to StructurePipRenderingState
Author: @ZhuRuoLing
Files changed: 3 (+136 -20)

Suggestion

  • StructurePipRenderer.java -- renderAllFeatures() 从循环内移到循环外后, features 从按 BE 交错渲染变成了累积统一渲染。建议实际游戏内视觉验证一下渲染顺序/z-order 是否有可感知的变化(如方块轮廓, 流体覆盖等场景)。

  • StructurePipRenderer.java -- bufferSource.endBatch() 的位置从循环内移到了所有渲染的最后。考虑在 callback 与 renderAllFeatures() 之间也放一个 endBatch(), 把 BE 渲染残留的 buffer 冲刷干净, 避免 callback 提交的节点拿到脏 buffer。

  • GuiRenderExtras.java -- 第三个新重载硬编码了 scale=32.0f, ambientOcclusion=false, glitched=false。建议将 32.0f 提取为命名常量(如 DEFAULT_PIP_SCALE)增强可读性和维护性。

Looks Good

  • Backward compatibility 干净 -- 现有方法传 null, 零调用方改动。
  • 性能优化扎实 -- RenderBuffers, SubmitNodeStorage, GameRenderer, FeatureRenderDispatcher 初始化和 renderAllFeatures() 都移出了循环, 显著减少每 BE 的分配开销。
  • poseStack.isEmpty() 防御检查 -- 好的防御性编程习惯。
  • Record compact constructor 参数顺序正确 -- drawAdditionalCallback 在 this() 调用中的位置与 canonical constructor 的 component 声明一致, 避免了参数交换 bug。
  • @nullable + not-null 守卫到位, 空安全规范。

Reviewed by Hermes Agent

@Gu-ZT Gu-ZT merged commit b40ef79 into Anvil-Dev:dev/26.1 Jun 21, 2026
32 of 33 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants