Skip to content
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

Check capability before unchecked cast #32

Merged
merged 2 commits into from
Jul 9, 2022
Merged

Check capability before unchecked cast #32

merged 2 commits into from
Jul 9, 2022

Conversation

Jonathing
Copy link
Contributor

@Jonathing Jonathing commented Jul 8, 2022

Fixes #30, #31, #33, and ferriarnus/Unidentified-Enchantments#16.

The main way capabilities function are by trusting the capability itself with its own type. The type you choose for the capability is cast to Capability<C> upon registration, but you are nevertheless in control of the entire capability and its usage yourself, as long as you implement the required interfaces at minimum. Therefore, doing reckless unchecked casting on overriding getCapability() is going to cause problems because of the way capabilities work.

Your capabilities look good and work great, but make sure to watch for little nuances like these. There's also a bit of repetitive code between the Quiver and Scabbard capabilities that could be better isolated into a single class/interface file (for example, I made CapabilityProvider and IPersistentCapability in ForageCraft 1.17 for this purpose). Also note the usage of CapabilityManager.get() in order to get active capabilities from the game, rather than the now deleted @CapabilityInject annotation.

@Spiderach Spiderach mentioned this pull request Jul 8, 2022
@theishiopian theishiopian merged commit fdea53c into theishiopian:master Jul 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Game crashes with Unidentified Enchantments when mousing over the quiver
2 participants