-
Notifications
You must be signed in to change notification settings - Fork 433
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
Add Support for Custom Item Settings #1359
base: 1.16
Are you sure you want to change the base?
Conversation
fabric-item-api-v1/src/main/java/net/fabricmc/fabric/api/item/v1/CustomItemSettingType.java
Outdated
Show resolved
Hide resolved
fabric-item-api-v1/src/main/java/net/fabricmc/fabric/api/item/v1/CustomItemSettingType.java
Outdated
Show resolved
Hide resolved
Pretty good. I assume these settings are all used by other vanilla items in modified bytecode, right? If those are exclusively used by mods mods should just add extra constructor parameters. |
… the item in question so that mods don't need to add mixins/accessor interfaces to access their settings on items.
Adding constructor parameters isn't an elegant solution when you want to be able to add settings to a wide range of item types, potentially from different mods, or if you want to ensure a large group of items have the same settings. |
fabric-item-api-v1/src/main/java/net/fabricmc/fabric/impl/item/FabricItemInternals.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fabric-item-api-v1/src/main/java/net/fabricmc/fabric/api/item/v1/CustomItemSetting.java
Outdated
Show resolved
Hide resolved
fabric-item-api-v1/src/main/java/net/fabricmc/fabric/api/item/v1/CustomItemSetting.java
Outdated
Show resolved
Hide resolved
…v1/CustomItemSetting.java Co-authored-by: liach <[email protected]>
…v1/CustomItemSetting.java Co-authored-by: liach <[email protected]>
So I thought of another way of doing this, based on one of Lambda's idea. Let's say we add For example public FabricItemSettings equipmentSlot(EquipmentSlotProvider equipmentSlotProvider) {
FabricItemInternals.computeExtraData(this).equipmentSlot(equipmentSlotProvider);
} becomes public FabricItemSettings equipmentSlot(EquipmentSlotProvider equipmentSlotProvider) {
return then(item -> ((ItemExtensions) item).fabric_setEquipmentSlotProvider(equipmentSlotProvider);
} By separating the public static Consumer<Item> fuel(int burnTicks) {
return item -> FuelRegistry.add(item, burnTicks);
}
// used like this:
.then(fuel(42)) The only downside is that it's not possible to get the current setting as it's stored within the lambda, but the current PR doesn't provide that option either. |
@Technici4n imo, the consumers being executed at the end of the constructor and not after item registration is a bit painful as it would prevent calling anything that relies on the item to be in the register. |
If you register a |
I agree that |
Can't wait to have to strip every consumers from the re-usable settings for the fake item :| Plus it's mutable and there's no way to copy an item settings properly so really not happy about that. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With regards to new item settings added by fabric api, those should still recieve dedicated setting methods.
fabric-item-api-v1/src/main/java/net/fabricmc/fabric/api/item/v1/CustomItemSetting.java
Outdated
Show resolved
Hide resolved
fabric-item-api-v1/src/main/java/net/fabricmc/fabric/api/item/v1/CustomItemSetting.java
Outdated
Show resolved
Hide resolved
fabric-item-api-v1/src/main/java/net/fabricmc/fabric/mixin/item/ItemMixin.java
Outdated
Show resolved
Hide resolved
fabric-item-api-v1/src/main/java/net/fabricmc/fabric/api/item/v1/CustomItemSetting.java
Outdated
Show resolved
Hide resolved
fabric-item-api-v1/src/main/java/net/fabricmc/fabric/impl/item/ItemExtensions.java
Outdated
Show resolved
Hide resolved
fabric-item-api-v1/src/main/java/net/fabricmc/fabric/api/item/v1/FabricItemSettings.java
Outdated
Show resolved
Hide resolved
fabric-item-api-v1/src/main/java/net/fabricmc/fabric/api/item/v1/CustomItemSetting.java
Outdated
Show resolved
Hide resolved
fabric-item-api-v1/src/main/java/net/fabricmc/fabric/api/item/v1/CustomItemSetting.java
Outdated
Show resolved
Hide resolved
fabric-item-api-v1/src/main/java/net/fabricmc/fabric/api/item/v1/CustomItemSetting.java
Outdated
Show resolved
Hide resolved
fabric-item-api-v1/src/main/java/net/fabricmc/fabric/api/item/v1/CustomItemSetting.java
Outdated
Show resolved
Hide resolved
fabric-item-api-v1/src/main/java/net/fabricmc/fabric/api/item/v1/CustomItemSetting.java
Show resolved
Hide resolved
fabric-item-api-v1/src/main/java/net/fabricmc/fabric/api/item/v1/CustomItemSetting.java
Outdated
Show resolved
Hide resolved
fabric-item-api-v1/src/main/java/net/fabricmc/fabric/api/item/v1/CustomItemSetting.java
Outdated
Show resolved
Hide resolved
fabric-item-api-v1/src/main/java/net/fabricmc/fabric/api/item/v1/CustomItemSetting.java
Outdated
Show resolved
Hide resolved
fabric-item-api-v1/src/main/java/net/fabricmc/fabric/api/item/v1/CustomItemSetting.java
Outdated
Show resolved
Hide resolved
fabric-item-api-v1/src/main/java/net/fabricmc/fabric/api/item/v1/CustomItemSetting.java
Show resolved
Hide resolved
fabric-item-api-v1/src/main/java/net/fabricmc/fabric/api/item/v1/CustomItemSetting.java
Outdated
Show resolved
Hide resolved
fabric-item-api-v1/src/main/java/net/fabricmc/fabric/impl/item/CustomItemSettingImpl.java
Show resolved
Hide resolved
fabric-item-api-v1/src/main/java/net/fabricmc/fabric/impl/item/CustomItemSettingImpl.java
Show resolved
Hide resolved
Uh... The usual rule of thumb in Fabric API is that parameters shouldn't be null unless |
Also I meant to add |
@@ -39,8 +39,7 @@ | |||
* @return this builder | |||
*/ | |||
public FabricItemSettings equipmentSlot(EquipmentSlotProvider equipmentSlotProvider) { | |||
FabricItemInternals.computeExtraData(this).equipmentSlot(equipmentSlotProvider); | |||
return this; | |||
return custom(CustomItemSettingImpl.EQUIPMENT_SLOT_PROVIDER, equipmentSlotProvider); |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The is an overlap with the api-lookup api that needs further invesigation.
This PR handles both a) transporting the data from Item.Settings.custom(data) to the constructor and b) holding and retrieving said data externally with any item instance. The latter is what api-api does as well, although significantly less conveniently.
fabric-item-api-v1/src/main/java/net/fabricmc/fabric/api/item/v1/CustomItemSetting.java
Outdated
Show resolved
Hide resolved
fabric-item-api-v1/src/main/java/net/fabricmc/fabric/api/item/v1/CustomItemSetting.java
Outdated
Show resolved
Hide resolved
fabric-item-api-v1/src/main/java/net/fabricmc/fabric/api/item/v1/FabricItemSettings.java
Show resolved
Hide resolved
fabric-item-api-v1/src/main/java/net/fabricmc/fabric/impl/item/CustomItemSettingImpl.java
Show resolved
Hide resolved
fabric-item-api-v1/src/main/java/net/fabricmc/fabric/api/item/v1/CustomItemSetting.java
Outdated
Show resolved
Hide resolved
fabric-item-api-v1/src/main/java/net/fabricmc/fabric/api/item/v1/CustomItemSetting.java
Outdated
Show resolved
Hide resolved
fabric-item-api-v1/src/main/java/net/fabricmc/fabric/api/item/v1/CustomItemSetting.java
Outdated
Show resolved
Hide resolved
I forgot to mention there that adding such a mechanism would imply doing the same for blocks. I don't really want to clutter the interface with a generic arg for block vs item, so some code duplication is in order. Not sure how much the impl can be shared. |
I do plan on adding a similar mechanism for block settings. I want to get this PR merged as a precedent for how I will handle blocks. |
- Adds another create method to CustomItemSetting - Code and JavaDoc cleanup
@sfPlayer1 was something like this ever finished? I could pick it up if needbe. |
Can probably be replaced by #2172 |
Ah, maybe. |
Currently, if a mod wants to pass custom settings for items, the best way is to subclass either
Item.Settings
orFabricItemSettings
and add the behavior there yourself. An example of this is in The Aether, where custom item settings are used for a custom rarity and enchantment glint color. If another mod, however, adds an item setting for their items via the same method, there's no way for one item to share both properties.This pull request solves that by allowing mods to attach arbitrary data to item settings. As part of this change, both the
EquipmentSlotProvider
andCustomDamageHandler
have been migrated to use this system. Their public-facing API's remain unchanged.This pull request also fixes a small bug in the testmod, wherein one of the test entrypoints would fail to launch.