CustomiesDevs / Customies

A PocketMine-MP plugin that implements support for custom blocks, items and entities.
MIT License
112 stars 52 forks source link

Use Closures for registering blocks #37

Closed TwistedAsylumMC closed 2 years ago

TwistedAsylumMC commented 2 years ago

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.