Data API Implementation


#24

Would it be possible to add persistent custom data to items. And possibly some hooks for using the item. That way we could add special modifiers to the items such as %damage increase, frost attacks, ... etc. But the idea is the programmer implements a custom data attribute and when an item is created we can attach one or more of these custom data attributes. Then when the item is used (attack an entity, or other use item events) it will automatically call the corresponding custom attribute. This would need to persist inside of the item data. I feel like this fits in similarly to how we will be able to customize the functionality of entities.

edit: Just to clarify, this is the entity system i was referring to:
https://forums.spongepowered.org/t/component-system-and-minecraft/76

edit2: Another page describing the component system:
https://docs.google.com/document/d/1DpItVK8Ir2qQTZrMQM2Lhb1bmjIuY-PtrAJYE5kepj0/edit

Also does the Data API have hooks into the component entity system? (And has the entity component system been implemented?)


#25

Yes.

Make a custom DataManipulator that extends AbstractDataManipulator, then wait for the implementation to handle custom data.

Your hooks are your events, then read the data and register your callbacks (or if you must, modify the event)

adding callbacks to events allows other plugins to co-operate with yours in order to change your actions if needed.

The Entity Component System hasn't seen much love in a long while, but the Data API has elements that are similar.

I think the current plan is to hold off as Mojang themselves might be heading towards a ECS and the hope is by waiting it may be able to be compatible with sponges.


#26

Excellent! Really looking forward to this as working with items as it is in bukkit is a nightmare.

Thanks for the information. Sad to hear about the entity component system, but I peaked around the code and it does seem to provide some better customization than bukkit already.

I heard Grum was working on some form of ECS? If this is true then entity customization should reach an entirely new level.


#27

Sorry for the delay, after being sick and a certain amount of work needing to be done, I've finally managed to implement all the DataManipulators themselves, now all that is needed is writing all the DataUtils to make those data manipulators usable.

Yesterday, I implemented HealthData and tested, here's a pic of using it in action!


#28


CODE:

human.getHealthData().setHealth(40);

Build Sponge: №445.


#29

Do you know what exception is being thrown that is causing the error?

At a guess it will be because you are setting the current health above the maximum health, but I would have expected the DataManipulator to have capped the health at the maximum. It may be a bug.


#30

Code:

human.getHealthData().setMaxHealth(40);

The result is the same.
As if HealthData is not implemented.


#31

What version of sponge are you using?


#32

Sponge build 445.

In the console.

java.lang.AbstractMethodError

#33

Ok I have no idea why it isn't working, file a bug.

Shows that the healthUtil should be implemented.


#34

Also sorry, I missed that you were using the latest version in your earlier post.


#35

The individual methods such as getHealthData() and getFooData() from various entity interfaces aren't implemented directly yet. The data implementation revolves around it working with the methods provided from DataHolder, in this case calling getData(HealthData.class).get() is valid to perform on any Living entity.

Another thing to note, while SpongeCommon may have certain things implemented, if the SpongeCommon reference isn't updated for Sponge and SpongeVanilla, they won't be made available.


#36

Method setMaxHealt return error NoSuchMethodError

Code:

HealthData health = player.getData(HealthData.class).get();
double d = 40.0;
health.setMaxHealth(d);

#37

GameModeData!


#38

MaxFluidTankCapacity