Skip to content

Extract shared methods from duplicated block logic#33

Merged
CoderJoeW merged 7 commits intomainfrom
refactor/extract-shared-block-methods
Mar 17, 2026
Merged

Extract shared methods from duplicated block logic#33
CoderJoeW merged 7 commits intomainfrom
refactor/extract-shared-block-methods

Conversation

@CoderJoeW
Copy link
Copy Markdown
Owner

Summary

  • Extract pullPowerFromNeighbors() and updatePoweredState() into PowerBlock, removing duplicated implementations from 4 utility/power blocks each
  • Move ADJACENT_FACES constant to AtlasBlock companion, removing 4 private copies
  • Add polymorphic canProvideFluid(requestDirection) to FluidBlock with overrides in FluidPump and FluidContainer, replacing 6 when(source) type-dispatch blocks
  • Add createNoticeDialog() and BlockFace.displayName() to AtlasBlockDialog, simplifying all 3 dialog classes

Net result: -319 lines across 19 files, no behavior changes.

The same ~12-line power-pulling loop was duplicated in CobblestoneFactory,
ObsidianFactory, SmallDrill, and AutoSmelter. Move it to a shared protected
method in PowerBlock and replace all four copies.
The same 3-line method was duplicated in PowerCable, PowerSplitter,
PowerMerger, and AutoSmelter. Move it to a shared protected method
in PowerBlock and remove all four private copies.
The same 6-element BlockFace list was defined in CobblestoneFactory,
ObsidianFactory, LavaGenerator, and FluidPump. Move it to AtlasBlock
companion and remove all four private copies.
Add a polymorphic canProvideFluid(requestDirection) method to FluidBlock,
with overrides in FluidPump and FluidContainer that delegate to
canRemoveFluidFrom(). This replaces the when(source) type dispatch
duplicated across FluidPipe, FluidMerger, FluidContainer, CobblestoneFactory,
ObsidianFactory, and LavaGenerator.
…BlockDialog

Add createNoticeDialog() to centralize the close-button + notice dialog
pattern duplicated in FluidBlockDialog, TransportBlockDialog, and
PowerBlockDialog. Add BlockFace.displayName() extension to replace 8
occurrences of the same formatting logic across dialog classes.
@CoderJoeW CoderJoeW merged commit a595e0b into main Mar 17, 2026
3 checks passed
@CoderJoeW CoderJoeW deleted the refactor/extract-shared-block-methods branch March 17, 2026 05:30
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