Voxelers/mcthings

Add a decorator to the Thing API

acs opened this issue · 3 comments

acs commented

After thinking how to add entities to a Thing without adding the dependency to the Entities Thing based on the extended API and located at McThings Extra, I have reached the idea of having decorators.

The idea is simple: you create a House Thing and you can add to it a Decorator. For example, a LightDecorator. This decorator will add lights to the Thing, decorate it. LightDecorator will have the logic to add torches to a House or to a hollow pyramid.

We will have a EntityDecorator which will add entities to the Thing (villagers for example).

The Decorate API is simple: decorate(thing). It will be called once the Thing is built and from the characteristics of the Thing, it will decorate it. A Thing could have a list of decorators.

The EntityDecorator could live in the McThings Extra repository. And the LightDecorator in the McThings one.

And the idea of having a LightDecorator for Things it is really interesting. How to light Things? It will depend in the kind of thing to be illuminated/lighted.

acs commented

The way to implement it is to use a decorator around the build method, so in all Things after the real build method is called, the decorator is called on it.

https://stackoverflow.com/questions/24768400/how-would-one-decorate-an-inherited-method-in-the-child-class

Let's play wiith this!

We can also have it with a different method and let the creator to decorate the Thing if she wants. Let's follow this simpler approach better!

acs commented

First version implemented:

Screenshot from 2020-05-26 23-49-50

06d4110

acs commented

Ok, all done in 0.31.0. Now it is time to start using it.