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

Add data-driven shields #128

Open
StellarWind22 opened this issue Dec 24, 2022 · 7 comments
Open

Add data-driven shields #128

StellarWind22 opened this issue Dec 24, 2022 · 7 comments
Labels
enhancement New feature or request

Comments

@StellarWind22
Copy link
Owner

Allow items to be treated as shields by simply including them in the #fabricshieldlib:shields tag. Any shields registered this way will just use default settings(cooldown);

@StellarWind22 StellarWind22 added the enhancement New feature or request label Dec 24, 2022
@StellarWind22 StellarWind22 added this to the 1.7.0 milestone Dec 24, 2022
@CringeStar CringeStar removed this from the 1.7.0 milestone Mar 5, 2023
@rikka0w0
Copy link
Contributor

Is this still work in progress?

@CringeStar
Copy link
Collaborator

Still brainstorming it. Currently we're more focused on updating the wiki page and ironing out bugs.

@rikka0w0
Copy link
Contributor

rikka0w0 commented Dec 1, 2024

The int getCoolDownTicks(); and boolean supportsBanner(); in interface FabricShield should return the vanilla value by default, so that modders can simply implement the FabricShield interface to make their custom shield.

Speaking of the data-driven shields, my suggestion is to create a shield registry similar to how the vanilla biome registry works. The shield characteristics are described in JSON files (/data/<mod_id>/fabricshieldlib/shield/<shield_name>.json). The "shield_name" should match the item name of the shield. Each of those JSON files will be serialized into instances of a Java record (Lets call it FabricShieldProperty).

We use Mixin to add a method (public @Nullable FabricShieldProperties getShieldProperties();) to the vanilla Item class. Upon the first call, it looks up the FabricShieldProperty from the shield registry and then caches the result (can be null). In the Fabric shield lib implementation where we need to get info about the shield, we first retrieve the item, then examine the return of its getShieldProperties() method. A shield should have a non-null return value.

@rikka0w0
Copy link
Contributor

rikka0w0 commented Dec 3, 2024

Another way of doing this is to take advantage of the DataComponent system introduced in 1.21.

We will consider all items in #fabricshieldlib:shields as shields (perhaps should be the conventional shield tag?). When a player is holding these items, he can block attacks just like a vanilla shield. The cooling downtime and enchantment value are the same as the vanilla shield.

If a modded shield wants to have a different cooling downtime or enchantment value, the modder can add a newly-defined
DataComponentType called FabricShieldProperty and put specifications there. If FabricShieldProperty is not present on a modded shield's DataComponent list, vanilla values will be used.

@rikka0w0
Copy link
Contributor

rikka0w0 commented Dec 4, 2024

@CringeStar
Copy link
Collaborator

CringeStar commented Dec 10, 2024

The int getCoolDownTicks(); and boolean supportsBanner(); in interface FabricShield should return the vanilla value by default, so that modders can simply implement the FabricShield interface to make their custom shield.

Yeah, makes sense! I wonder why we ddint do that in the first place lol.

We will consider all items in #fabricshieldlib:shields as shields (perhaps should be the conventional shield tag?).

We only use the proprietary tag in versions where the c: isnt available.

When a player is holding these items, he can block attacks just like a vanilla shield. The cooling downtime and enchantment value are the same as the vanilla shield.

Yeah that's basically @StellarWind22 's initial plan with this. Would this just entail changing every check for "FabricShield" into a check for "c:shield"?

If a modded shield wants to have a different cooling downtime or enchantment value, the modder can add a newly-defined DataComponentType called FabricShieldProperty and put specifications there.

Yeah, sounds good!

newly-defined DataComponentType called FabricShieldProperty and put specifications there. If FabricShieldProperty is not present on a modded shield's DataComponent list, vanilla values will be used.

Sorry, but I am not very familiar with DataCompnents yet (school hasn't given me time to look into them), but how would this change the item initialization process? Would devs still just do new fabricshielditem or would we have to change the process up?

See my progress here: https://github.com/rikka0w0/Fabric-Shield-Lib/tree/experimental

Will check out after exams along with your PR #182!

@CringeStar
Copy link
Collaborator

CringeStar commented Dec 21, 2024

See my progress here: https://github.com/rikka0w0/Fabric-Shield-Lib/tree/experimental

I LOVE the FabricShieldUtils.java you made! I still have to look at the rest of the repo, but I just wanted to check out the utils file after I saw it in your PR/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants