Skip to content
New issue

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

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

Already on GitHub? # to your account

Use Closures for registering blocks #37

Merged
merged 6 commits into from
Sep 28, 2022
Merged

Conversation

TwistedAsylumMC
Copy link
Collaborator

This pull request aims to solve two big problems with the CustomiesBlockFactory->registerBlock() API:

  1. The current method is very limiting and does not work for every type of block due to different constructor signatures. For example slabs require a BlockIdentifierFlattened whereas we only accept a BlockIdentifier, meaning the user needs to create a new class that inherits the same behaviour to use within Customies.
  2. The way we currently register blocks on all threads is by serializing the Block objects and using the same registering method. This causes issues when blocks inherit properties that are not serialiable, crashing the server as a result. Using slabs as an example again, their SlabType is an enum which implements the NotSerializable trait.

The solution to both of these problems is instead of accepting a class name along with other information such as BlockBreakInfo, we instead accept a single Closure which returns an instance of the Block. This allows for blocks to be constructed however they are needed, and also removes the requirement for serializing the Block objects to register them on other threads.

@unickorn unickorn added the enhancement New feature or request label Sep 26, 2022
@abimek abimek self-requested a review September 27, 2022 02:11
@TwistedAsylumMC TwistedAsylumMC merged commit e918c28 into master Sep 28, 2022
@TwistedAsylumMC TwistedAsylumMC deleted the feature/blockfuncs branch November 12, 2022 01:28
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants