Wiki is missing reference for simple Provider
Ayutac opened this issue ยท 7 comments
I cannot access the component value without a provider, whatever that might be. The Wiki just says "anything will work, as long as a module allows it!" which tempted me to use the player entity as the provider, which threw a runtime exception.
So now I will go through the "Advanced" Section of the Wiki and build my own provider somehow, but surely there is an easy way? A ready-to-use implementation, maybe? Didn't found anything in the base, utils or block jar :(
Alright, added a note to the relevant page. I believe what you're doing is a bit unnecessary though, KEY.get(world)
should work fine.
I just found the SimpleComponentProvider I couldn't find before, so it's in the code, but the wiki is still missing a reference.
But ComponentProvider has from methods. This should REALLY be mentioned in the Wiki.
I got the code to work, I am suggesting an improvement in the wiki. On this page at the bottom the code example is only
public static void useMagik(Entity provider) { // anything will work, as long as a module allows it! // Retrieve a provided component int magik = MAGIK.get(provider).getValue(); // Or, if the object is not guaranteed to provide that component: int magik = MAGIK.maybeGet(provider).map(IntComponent::getValue).orElse(0); // ... }
but no examples of how to create such "anything" provider is given. I suggest to add an example, because it took me a lot of time to figure it out and I have some years of programming experience.
I personally use
ComponentProvider provider = ComponentProvider.fromWorld(world);