-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Add OptionalInterface and OptionalMethod to replace the Optional class #4174
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
Actually no, this should all be deprecated and be removed in favor of the Capability system. |
|
@LexManos How do you implement a CapabilityProvider for an optional dependency? |
|
Alpvax, like this: Or this: General solution:
Things to remember:
|
|
@HenryLoenwind have you ever actually tested the bc compact code? I'm pretty sure it's broken, in part by using the wrong modid. I'm also not sure that it's necessary to reference the class by reflection, java seems to handle it fine if you just never call a method if it doesn't exist. |
|
I believe that as long as the file is there for compilation, it is not needed at runtime if it is never called (Hence all the ClassNotFoundExceptions at runtime when people try to use client-only classes on the server). Adding an adapter which the check can be delegated to seems to be the way forwards, thanks. |
|
https://github.com/SleepyTrousers/EnderIO/blob/1.11-base/src/main/java/crazypants/enderio/power/CapInjectHandler.java#L35-L42 is the recomended way, it shouldn't need the try around it because that function should only ever be called by the event. And if the event is fired the Cap class is there. But having the try doesn't hurt anything. That's WHY I made @CapInject work on methods. THere are PLENTY of ways to do it without causing crashes, Capabilities were SPECIFICALLY designed to replace the need for @optional |
|
Yes, I completely forgot that CapabilityInject works on methods. Am I correct in thinking that you still need to use a wrapper around the capabilty handler, as if the class doesn't exist it will crash? |
|
This has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
Java 8 and Guava both have an
Optionalclass - moving these annotations outside of theOptionalclass removes the need to import them (importingOptional.Methodwill conflict withjava.lang.reflect.Method, as well) or use fully-qualified class names.This pull request:
net.minecraftforge.fml.common.Optional, with no replacementnet.minecraftforge.fml.common.Optional$InterfaceList, replaced bynet.minecraftforge.fml.common.OptionalInterface$OptionalInterfaceList(though repeatingOptionalInterfaceshould be preferred now)net.minecraftforge.fml.common.Optional$Interface, replaced bynet.minecraftforge.fml.common.OptionalInterfacenet.minecraftforge.fml.common.Optional$Method, replaced bynet.minecraftforge.fml.common.OptionalMethodAdditionally,
net.minecraftforge.fml.common.OptionalInterfaceis repeatable.