Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Material Block Cleanup + Block Registration Cleanup + @ #1715

Merged
merged 6 commits into from
May 11, 2023

Conversation

Tictim
Copy link
Contributor

@Tictim Tictim commented Apr 17, 2023

What

This PR features yet another code cleanup, this time focused on material blocks - compressed blocks, frames, and surface rocks.

Implementation Details

Previous implementation of these blocks, BlockCompressed, BlockFrame and BlockOre, each used DelayedStateBlock for implementation. The class essentially bypassed the limit imposed by initialization order, by modifying internal variable with reflection. Since the restriction can be also bypassed by alternative approach shown in this PR, DelayedStateBlock is a kind of an unnecessary hack.

Additionally those three classes had very similar implementations, with most of them being identical to eachother, so I've gathered common parts to a new class BlockMaterialBase, and rewrote the three preexisting classes with the new class as superclass.

Two item classes, CompressedItemBlock and FrameItemBlock, were replaced by a new class MaterialItemBlock.

As DelayedStateBlock no longer has any usage after this PR, it is marked as deprecated.

Block registration stuff also received refactor: Compressed blocks, frames, and surface rocks now have separate list of blocks for registration, eliminating need for distinct() stream operations. Also all the block/item colors declared in ClientProxy have been moved directly to the usage, with better implementation. I don't know who came up with the idea of sharing one IBlockColor/IItemColor with multiple blocks and typechecking the block inside the color implementation, but it was certainly a funny one.

Additional Information

To become true Developer of GregTech I decided to fully embrace the tradition of our ancestor - the great Archengius, creator of GT:CE Official Edition - by creating the work with same spirit and technique as him. i.e. I made an Arch commit. Below are the list of minor code refactors included in this PR.

  • MultiblockControllerBase
    Marked structurePattern as nullable. Ran reformat once.
  • MetaItemBracketHandler
    Removed unnecessary suppression.
  • BlockCompressed / BlockFrame / BlockOre
    Removed static getItem util method that just delegated call to GTUtility#getItem.
  • BlockOre / OreItemBlock
    Changed to use vanilla setCreativeTab instead of overriding getCreativeTabs manually.
  • MetaTileEntityLargeMiner / MetaTileEntityLargeBoiler
    Removed returning null at createStructurePattern. It looked like there was some sort of init order problem similar to the one that led to creation of DelayedStateBlock, but I didn't notice any such problem both during code inspection and in-game testing.
  • MetaTileEntitySteamOven
    Removed unused variable.
  • MetaTileEntityMultiblockTank
    Changed nothing.

Potential Compatibility Issues

Mods using util methods removed from this PR, like BlockCompressed#getItem, will be affected. Other than that I'm not sure.

@Tictim Tictim added the type: refactor Suggestion to refactor a section of code label Apr 17, 2023
@ALongStringOfNumbers ALongStringOfNumbers added this to the 2.7 milestone Apr 30, 2023

public Material getGtMaterial(int meta) {
return variantProperty.getAllowedValues().get(meta);
return net.minecraft.block.material.Material.IRON;
Copy link
Contributor

Choose a reason for hiding this comment

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

Hm, why this change? I know that super should always return Material.IRON because that is set in the constructor, but I would rather just continue calling super in case we change materials on frames, or just some frames, some day

@TechLord22 TechLord22 merged commit 14bf3ed into GregTechCEu:master May 11, 2023
@Tictim Tictim deleted the block_cleanup branch May 12, 2023 03:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: refactor Suggestion to refactor a section of code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants