-
-
Notifications
You must be signed in to change notification settings - Fork 342
Add item attributes #2602
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
Merged
Yeregorix
merged 7 commits into
SpongePowered:api-14
from
MrHell228:api-14-item-attributes
Nov 12, 2025
Merged
Add item attributes #2602
Changes from 6 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
f8d5e3e
expose EquipmentCondition
MrHell228 70f38fe
expose ItemAttribute with corresponding key
MrHell228 d7482b9
add factory-like methods for AttributeModifier creation
MrHell228 f78b122
Merge branch 'api-14' into api-14-item-attributes
MrHell228 278dac4
Merge branch 'api-14' into api-14-item-attributes
MrHell228 d2a570e
change EquipmentCondition.byType to EquipmentType method
MrHell228 01f256b
change ItemStack mentions to ItemStackLike
MrHell228 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
114 changes: 114 additions & 0 deletions
114
src/main/java/org/spongepowered/api/entity/attribute/ItemAttribute.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,114 @@ | ||
| /* | ||
| * This file is part of SpongeAPI, licensed under the MIT License (MIT). | ||
| * | ||
| * Copyright (c) SpongePowered <https://www.spongepowered.org> | ||
| * Copyright (c) contributors | ||
| * | ||
| * Permission is hereby granted, free of charge, to any person obtaining a copy | ||
| * of this software and associated documentation files (the "Software"), to deal | ||
| * in the Software without restriction, including without limitation the rights | ||
| * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
| * copies of the Software, and to permit persons to whom the Software is | ||
| * furnished to do so, subject to the following conditions: | ||
| * | ||
| * The above copyright notice and this permission notice shall be included in | ||
| * all copies or substantial portions of the Software. | ||
| * | ||
| * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
| * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
| * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
| * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
| * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
| * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
| * THE SOFTWARE. | ||
| */ | ||
| package org.spongepowered.api.entity.attribute; | ||
|
|
||
| import org.spongepowered.api.Sponge; | ||
| import org.spongepowered.api.entity.attribute.type.AttributeType; | ||
| import org.spongepowered.api.item.inventory.ItemStack; | ||
| import org.spongepowered.api.item.inventory.equipment.EquipmentCondition; | ||
|
|
||
| import java.util.Objects; | ||
| import java.util.function.Supplier; | ||
|
|
||
| /** | ||
| * Represents an {@link AttributeModifier} for the specific {@link AttributeType} | ||
| * an {@link ItemStack} can apply when the {@link EquipmentCondition} is met. | ||
| */ | ||
| public interface ItemAttribute { | ||
|
|
||
| /** | ||
| * Creates an item attribute with the given values. | ||
| * | ||
| * @param type The attribute type | ||
| * @param modifier The attribute modifier | ||
| * @param condition The equipment condition | ||
| * @return The item attribute | ||
| */ | ||
| static ItemAttribute of(final Supplier<? extends AttributeType> type, final AttributeModifier modifier, final Supplier<? extends EquipmentCondition> condition) { | ||
| return ItemAttribute.of(Objects.requireNonNull(type, "type").get(), modifier, Objects.requireNonNull(condition, "condition").get()); | ||
| } | ||
|
|
||
| /** | ||
| * Creates an item attribute with the given values. | ||
| * | ||
| * @param type The attribute type | ||
| * @param modifier The attribute modifier | ||
| * @param condition The equipment condition | ||
| * @return The item attribute | ||
| */ | ||
| static ItemAttribute of(final Supplier<? extends AttributeType> type, final AttributeModifier modifier, final EquipmentCondition condition) { | ||
| return ItemAttribute.of(Objects.requireNonNull(type, "type").get(), modifier, condition); | ||
| } | ||
|
|
||
| /** | ||
| * Creates an item attribute with the given values. | ||
| * | ||
| * @param type The attribute type | ||
| * @param modifier The attribute modifier | ||
| * @param condition The equipment condition | ||
| * @return The item attribute | ||
| */ | ||
| static ItemAttribute of(final AttributeType type, final AttributeModifier modifier, final Supplier<? extends EquipmentCondition> condition) { | ||
| return ItemAttribute.of(type, modifier, Objects.requireNonNull(condition, "condition").get()); | ||
| } | ||
|
|
||
| /** | ||
| * Creates an item attribute with the given values. | ||
| * | ||
| * @param type The attribute type | ||
| * @param modifier The attribute modifier | ||
| * @param condition The equipment condition | ||
| * @return The item attribute | ||
| */ | ||
| static ItemAttribute of(final AttributeType type, final AttributeModifier modifier, final EquipmentCondition condition) { | ||
| return Sponge.game().factoryProvider().provide(Factory.class).of(type, modifier, condition); | ||
| } | ||
|
|
||
| /** | ||
| * Returns the attribute type. | ||
| * | ||
| * @return The attribute type | ||
| */ | ||
| AttributeType type(); | ||
|
|
||
| /** | ||
| * Returns the attribute modifier. | ||
| * | ||
| * @return The attribute modifier | ||
| */ | ||
| AttributeModifier modifier(); | ||
|
|
||
| /** | ||
| * Returns the equipment condition. | ||
| * | ||
| * @return The equipment condition | ||
| */ | ||
| EquipmentCondition condition(); | ||
|
|
||
| interface Factory { | ||
|
|
||
| ItemAttribute of(AttributeType type, AttributeModifier modifier, EquipmentCondition condition); | ||
| } | ||
| } |
58 changes: 58 additions & 0 deletions
58
src/main/java/org/spongepowered/api/item/inventory/equipment/EquipmentCondition.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| /* | ||
| * This file is part of SpongeAPI, licensed under the MIT License (MIT). | ||
| * | ||
| * Copyright (c) SpongePowered <https://www.spongepowered.org> | ||
| * Copyright (c) contributors | ||
| * | ||
| * Permission is hereby granted, free of charge, to any person obtaining a copy | ||
| * of this software and associated documentation files (the "Software"), to deal | ||
| * in the Software without restriction, including without limitation the rights | ||
| * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
| * copies of the Software, and to permit persons to whom the Software is | ||
| * furnished to do so, subject to the following conditions: | ||
| * | ||
| * The above copyright notice and this permission notice shall be included in | ||
| * all copies or substantial portions of the Software. | ||
| * | ||
| * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
| * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
| * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
| * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
| * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
| * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
| * THE SOFTWARE. | ||
| */ | ||
| package org.spongepowered.api.item.inventory.equipment; | ||
|
|
||
| import net.kyori.adventure.text.ComponentLike; | ||
| import org.spongepowered.api.data.type.StringRepresentable; | ||
| import org.spongepowered.api.registry.DefaultedRegistryValue; | ||
| import org.spongepowered.api.util.annotation.CatalogedBy; | ||
|
|
||
| import java.util.Objects; | ||
| import java.util.function.Supplier; | ||
|
|
||
| /** | ||
| * Represents some condition for {@link EquipmentType}. | ||
| */ | ||
| @CatalogedBy(EquipmentConditions.class) | ||
| public interface EquipmentCondition extends DefaultedRegistryValue<EquipmentCondition>, StringRepresentable, ComponentLike { | ||
|
|
||
| /** | ||
| * Tests whether the equipment type is suitable for this condition. | ||
| * | ||
| * @param type The equipment type to test | ||
| * @return True if the equipment type is suitable for this condition | ||
| */ | ||
| default boolean test(final Supplier<? extends EquipmentType> type) { | ||
| return this.test(Objects.requireNonNull(type, "type").get()); | ||
| } | ||
|
|
||
| /** | ||
| * Tests whether the equipment type is suitable for this condition. | ||
| * | ||
| * @param type The equipment type to test | ||
| * @return True if the equipment type is suitable for this condition | ||
| */ | ||
| boolean test(EquipmentType type); | ||
| } |
69 changes: 69 additions & 0 deletions
69
src/main/java/org/spongepowered/api/item/inventory/equipment/EquipmentConditions.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| /* | ||
| * This file is part of SpongeAPI, licensed under the MIT License (MIT). | ||
| * | ||
| * Copyright (c) SpongePowered <https://www.spongepowered.org> | ||
| * Copyright (c) contributors | ||
| * | ||
| * Permission is hereby granted, free of charge, to any person obtaining a copy | ||
| * of this software and associated documentation files (the "Software"), to deal | ||
| * in the Software without restriction, including without limitation the rights | ||
| * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
| * copies of the Software, and to permit persons to whom the Software is | ||
| * furnished to do so, subject to the following conditions: | ||
| * | ||
| * The above copyright notice and this permission notice shall be included in | ||
| * all copies or substantial portions of the Software. | ||
| * | ||
| * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
| * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
| * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
| * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
| * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
| * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
| * THE SOFTWARE. | ||
| */ | ||
| package org.spongepowered.api.item.inventory.equipment; | ||
|
|
||
| import org.spongepowered.api.ResourceKey; | ||
| import org.spongepowered.api.Sponge; | ||
| import org.spongepowered.api.registry.DefaultedRegistryReference; | ||
| import org.spongepowered.api.registry.Registry; | ||
| import org.spongepowered.api.registry.RegistryKey; | ||
| import org.spongepowered.api.registry.RegistryTypes; | ||
|
|
||
| /** | ||
| * <!-- This file is automatically generated. Any manual changes will be overwritten. --> | ||
| */ | ||
| public final class EquipmentConditions { | ||
|
|
||
| public static final DefaultedRegistryReference<EquipmentCondition> ANY = EquipmentConditions.key(ResourceKey.sponge("any")); | ||
|
|
||
| public static final DefaultedRegistryReference<EquipmentCondition> ARMOR = EquipmentConditions.key(ResourceKey.sponge("armor")); | ||
|
|
||
| public static final DefaultedRegistryReference<EquipmentCondition> BODY = EquipmentConditions.key(ResourceKey.sponge("body")); | ||
|
|
||
| public static final DefaultedRegistryReference<EquipmentCondition> CHEST = EquipmentConditions.key(ResourceKey.sponge("chest")); | ||
|
|
||
| public static final DefaultedRegistryReference<EquipmentCondition> FEET = EquipmentConditions.key(ResourceKey.sponge("feet")); | ||
|
|
||
| public static final DefaultedRegistryReference<EquipmentCondition> HAND = EquipmentConditions.key(ResourceKey.sponge("hand")); | ||
|
|
||
| public static final DefaultedRegistryReference<EquipmentCondition> HEAD = EquipmentConditions.key(ResourceKey.sponge("head")); | ||
|
|
||
| public static final DefaultedRegistryReference<EquipmentCondition> LEGS = EquipmentConditions.key(ResourceKey.sponge("legs")); | ||
|
|
||
| public static final DefaultedRegistryReference<EquipmentCondition> MAINHAND = EquipmentConditions.key(ResourceKey.sponge("mainhand")); | ||
|
|
||
| public static final DefaultedRegistryReference<EquipmentCondition> OFFHAND = EquipmentConditions.key(ResourceKey.sponge("offhand")); | ||
|
|
||
| private EquipmentConditions() { | ||
| } | ||
|
|
||
| public static Registry<EquipmentCondition> registry() { | ||
| return Sponge.game().registry(RegistryTypes.EQUIPMENT_CONDITION); | ||
| } | ||
|
|
||
| private static DefaultedRegistryReference<EquipmentCondition> key(final ResourceKey location) { | ||
| return RegistryKey.of(RegistryTypes.EQUIPMENT_CONDITION, location).asDefaultedReference(Sponge::game); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
StackLike?
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.
Oh, right, changed to ItemStackLike.
Though I looked through keys and almost every stack-related key mentions ItemStack. Probably could be another PR to update all of this