Skip to content

Add WithColour, WithAxis, and WithFacing in blocks#1183

Open
AkmalFairuz wants to merge 3 commits into
df-mc:masterfrom
AkmalFairuz:blocksetter
Open

Add WithColour, WithAxis, and WithFacing in blocks#1183
AkmalFairuz wants to merge 3 commits into
df-mc:masterfrom
AkmalFairuz:blocksetter

Conversation

@AkmalFairuz
Copy link
Copy Markdown
Collaborator

@AkmalFairuz AkmalFairuz commented Feb 17, 2026

Introduces WithColour, WithAxis, and WithFacing support for blocks so we can properly handle state-aware transformations in the WorldEdit server. The main use case is implementing a //rotate command that rotates selected regions while preserving block properties. Rotation only applies to blocks that depend on orientation, specifically those using Axis and Facing. By exposing these modifiers directly on the block interface, we can transform block states cleanly and deterministically during region edits without relying on hardcoded type switches.

Previously, the alternative approach relied on reflect to modify block state dynamically. That worked functionally, but the performance overhead was noticeable, especially when rotating large selections. Reflection adds unnecessary runtime cost and reduces type safety. With explicit WithAxis and WithFacing methods, rotation becomes faster.

Example:

for pos, b := range blocks {
  if a, ok := b.(block.HasFacing); ok {
    b = a.WithFacing(targetFace)
    tx.SetBlock(pos, b)
  }
}

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.

1 participant