From f8d5e3e113e5e07cd6cd0fad891e89badae445fd Mon Sep 17 00:00:00 2001 From: MrHell228 Date: Mon, 15 Sep 2025 22:58:15 +0300 Subject: [PATCH 1/5] expose EquipmentCondition --- .../equipment/EquipmentCondition.java | 85 +++++++++++++++++++ .../equipment/EquipmentConditions.java | 69 +++++++++++++++ .../api/registry/RegistryTypes.java | 3 + 3 files changed, 157 insertions(+) create mode 100644 src/main/java/org/spongepowered/api/item/inventory/equipment/EquipmentCondition.java create mode 100644 src/main/java/org/spongepowered/api/item/inventory/equipment/EquipmentConditions.java diff --git a/src/main/java/org/spongepowered/api/item/inventory/equipment/EquipmentCondition.java b/src/main/java/org/spongepowered/api/item/inventory/equipment/EquipmentCondition.java new file mode 100644 index 0000000000..b171f247a1 --- /dev/null +++ b/src/main/java/org/spongepowered/api/item/inventory/equipment/EquipmentCondition.java @@ -0,0 +1,85 @@ +/* + * This file is part of SpongeAPI, licensed under the MIT License (MIT). + * + * Copyright (c) SpongePowered + * 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.Sponge; +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.Predicate; +import java.util.function.Supplier; + +/** + * Represents some condition for {@link EquipmentType}. + */ +@CatalogedBy(EquipmentConditions.class) +public interface EquipmentCondition extends DefaultedRegistryValue, StringRepresentable, ComponentLike { + + /** + * Returns the most specific equipment condition for the given equipment type. + * + * @param type The equipment type + * @return The equipment condition + */ + static EquipmentCondition byType(final Supplier type) { + return EquipmentCondition.byType(Objects.requireNonNull(type, "type").get()); + } + + /** + * Returns the most specific equipment condition for the given equipment type. + * + * @param type The equipment type + * @return The equipment condition + */ + static EquipmentCondition byType(final EquipmentType type) { + return Sponge.game().factoryProvider().provide(Factory.class).byType(type); + } + + /** + * 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 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); + + interface Factory { + + EquipmentCondition byType(EquipmentType type); + } +} diff --git a/src/main/java/org/spongepowered/api/item/inventory/equipment/EquipmentConditions.java b/src/main/java/org/spongepowered/api/item/inventory/equipment/EquipmentConditions.java new file mode 100644 index 0000000000..090b8326c1 --- /dev/null +++ b/src/main/java/org/spongepowered/api/item/inventory/equipment/EquipmentConditions.java @@ -0,0 +1,69 @@ +/* + * This file is part of SpongeAPI, licensed under the MIT License (MIT). + * + * Copyright (c) SpongePowered + * 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; + +/** + * + */ +public final class EquipmentConditions { + + public static final DefaultedRegistryReference ANY = EquipmentConditions.key(ResourceKey.sponge("any")); + + public static final DefaultedRegistryReference ARMOR = EquipmentConditions.key(ResourceKey.sponge("armor")); + + public static final DefaultedRegistryReference BODY = EquipmentConditions.key(ResourceKey.sponge("body")); + + public static final DefaultedRegistryReference CHEST = EquipmentConditions.key(ResourceKey.sponge("chest")); + + public static final DefaultedRegistryReference FEET = EquipmentConditions.key(ResourceKey.sponge("feet")); + + public static final DefaultedRegistryReference HAND = EquipmentConditions.key(ResourceKey.sponge("hand")); + + public static final DefaultedRegistryReference HEAD = EquipmentConditions.key(ResourceKey.sponge("head")); + + public static final DefaultedRegistryReference LEGS = EquipmentConditions.key(ResourceKey.sponge("legs")); + + public static final DefaultedRegistryReference MAINHAND = EquipmentConditions.key(ResourceKey.sponge("mainhand")); + + public static final DefaultedRegistryReference OFFHAND = EquipmentConditions.key(ResourceKey.sponge("offhand")); + + private EquipmentConditions() { + } + + public static Registry registry() { + return Sponge.game().registry(RegistryTypes.EQUIPMENT_CONDITION); + } + + private static DefaultedRegistryReference key(final ResourceKey location) { + return RegistryKey.of(RegistryTypes.EQUIPMENT_CONDITION, location).asDefaultedReference(Sponge::game); + } +} diff --git a/src/main/java/org/spongepowered/api/registry/RegistryTypes.java b/src/main/java/org/spongepowered/api/registry/RegistryTypes.java index b4cc7d8aad..6a21c28adb 100644 --- a/src/main/java/org/spongepowered/api/registry/RegistryTypes.java +++ b/src/main/java/org/spongepowered/api/registry/RegistryTypes.java @@ -127,6 +127,7 @@ import org.spongepowered.api.item.ItemType; import org.spongepowered.api.item.enchantment.EnchantmentType; import org.spongepowered.api.item.inventory.ContainerType; +import org.spongepowered.api.item.inventory.equipment.EquipmentCondition; import org.spongepowered.api.item.inventory.equipment.EquipmentGroup; import org.spongepowered.api.item.inventory.equipment.EquipmentType; import org.spongepowered.api.item.inventory.menu.ClickType; @@ -369,6 +370,8 @@ public final class RegistryTypes { public static final DefaultedRegistryType DYE_COLOR = RegistryTypes.spongeKeyInGame("dye_color"); + public static final DefaultedRegistryType EQUIPMENT_CONDITION = RegistryTypes.spongeKeyInGame("equipment_condition"); + public static final DefaultedRegistryType EQUIPMENT_GROUP = RegistryTypes.spongeKeyInGame("equipment_group"); public static final DefaultedRegistryType EQUIPMENT_TYPE = RegistryTypes.spongeKeyInGame("equipment_type"); From 70f38fe9c00cbffa67096beea73ac9a735697486 Mon Sep 17 00:00:00 2001 From: MrHell228 Date: Mon, 15 Sep 2025 23:59:58 +0300 Subject: [PATCH 2/5] expose ItemAttribute with corresponding key --- .../java/org/spongepowered/api/data/Keys.java | 6 + .../api/entity/attribute/ItemAttribute.java | 114 ++++++++++++++++++ 2 files changed, 120 insertions(+) create mode 100644 src/main/java/org/spongepowered/api/entity/attribute/ItemAttribute.java diff --git a/src/main/java/org/spongepowered/api/data/Keys.java b/src/main/java/org/spongepowered/api/data/Keys.java index a22f3aacd7..cde79aa898 100644 --- a/src/main/java/org/spongepowered/api/data/Keys.java +++ b/src/main/java/org/spongepowered/api/data/Keys.java @@ -128,6 +128,7 @@ import org.spongepowered.api.entity.Item; import org.spongepowered.api.entity.Ownable; import org.spongepowered.api.entity.ai.goal.GoalExecutorTypes; +import org.spongepowered.api.entity.attribute.ItemAttribute; import org.spongepowered.api.entity.display.BillboardType; import org.spongepowered.api.entity.display.DisplayEntity; import org.spongepowered.api.entity.display.ItemDisplayType; @@ -2170,6 +2171,11 @@ public final class Keys { */ public static final Key> IS_WET = Keys.key(ResourceKey.sponge("is_wet"), Boolean.class); + /** + * The {@link ItemAttribute}s an {@link ItemStack} can apply. + */ + public static final Key> ITEM_ATTRIBUTES = Keys.listKey(ResourceKey.sponge("item_attributes"), ItemAttribute.class); + /** * The {@link ItemDisplayType display type} of a {@link org.spongepowered.api.entity.display.ItemDisplay}. */ diff --git a/src/main/java/org/spongepowered/api/entity/attribute/ItemAttribute.java b/src/main/java/org/spongepowered/api/entity/attribute/ItemAttribute.java new file mode 100644 index 0000000000..71dfa55547 --- /dev/null +++ b/src/main/java/org/spongepowered/api/entity/attribute/ItemAttribute.java @@ -0,0 +1,114 @@ +/* + * This file is part of SpongeAPI, licensed under the MIT License (MIT). + * + * Copyright (c) SpongePowered + * 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 type, final AttributeModifier modifier, final Supplier 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 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 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); + } +} From d7482b9848411d6a46d2b74c32481f0256eb9e8e Mon Sep 17 00:00:00 2001 From: MrHell228 Date: Tue, 16 Sep 2025 01:21:03 +0300 Subject: [PATCH 3/5] add factory-like methods for AttributeModifier creation --- .../entity/attribute/AttributeModifier.java | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/main/java/org/spongepowered/api/entity/attribute/AttributeModifier.java b/src/main/java/org/spongepowered/api/entity/attribute/AttributeModifier.java index b34c745847..ec587da064 100644 --- a/src/main/java/org/spongepowered/api/entity/attribute/AttributeModifier.java +++ b/src/main/java/org/spongepowered/api/entity/attribute/AttributeModifier.java @@ -24,6 +24,7 @@ */ package org.spongepowered.api.entity.attribute; +import org.spongepowered.api.ResourceKey; import org.spongepowered.api.ResourceKeyed; import org.spongepowered.api.Sponge; import org.spongepowered.api.item.inventory.ItemStack; @@ -38,6 +39,30 @@ */ public interface AttributeModifier extends ResourceKeyed { + /** + * Creates an attribute modifier with the given values. + * + * @param key The resource key + * @param operation The attribute operation + * @param amount The amount + * @return The attribute modifier + */ + static AttributeModifier of(final ResourceKey key, final Supplier operation, final double amount) { + return AttributeModifier.builder().key(key).operation(operation).amount(amount).build(); + } + + /** + * Creates an attribute modifier with the given values. + * + * @param key The resource key + * @param operation The attribute operation + * @param amount The amount + * @return The attribute modifier + */ + static AttributeModifier of(final ResourceKey key, final AttributeOperation operation, final double amount) { + return AttributeModifier.builder().key(key).operation(operation).amount(amount).build(); + } + /** * Creates a new {@link Builder} to create an {@link AttributeModifier}. * From d2a570eb8683a89079eb4d99e51a8e3f3c4799ba Mon Sep 17 00:00:00 2001 From: MrHell228 Date: Wed, 24 Sep 2025 19:20:09 +0300 Subject: [PATCH 4/5] change EquipmentCondition.byType to EquipmentType method --- .../equipment/EquipmentCondition.java | 27 ------------------- .../inventory/equipment/EquipmentType.java | 7 +++++ 2 files changed, 7 insertions(+), 27 deletions(-) diff --git a/src/main/java/org/spongepowered/api/item/inventory/equipment/EquipmentCondition.java b/src/main/java/org/spongepowered/api/item/inventory/equipment/EquipmentCondition.java index b171f247a1..9bfe345588 100644 --- a/src/main/java/org/spongepowered/api/item/inventory/equipment/EquipmentCondition.java +++ b/src/main/java/org/spongepowered/api/item/inventory/equipment/EquipmentCondition.java @@ -25,13 +25,11 @@ package org.spongepowered.api.item.inventory.equipment; import net.kyori.adventure.text.ComponentLike; -import org.spongepowered.api.Sponge; 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.Predicate; import java.util.function.Supplier; /** @@ -40,26 +38,6 @@ @CatalogedBy(EquipmentConditions.class) public interface EquipmentCondition extends DefaultedRegistryValue, StringRepresentable, ComponentLike { - /** - * Returns the most specific equipment condition for the given equipment type. - * - * @param type The equipment type - * @return The equipment condition - */ - static EquipmentCondition byType(final Supplier type) { - return EquipmentCondition.byType(Objects.requireNonNull(type, "type").get()); - } - - /** - * Returns the most specific equipment condition for the given equipment type. - * - * @param type The equipment type - * @return The equipment condition - */ - static EquipmentCondition byType(final EquipmentType type) { - return Sponge.game().factoryProvider().provide(Factory.class).byType(type); - } - /** * Tests whether the equipment type is suitable for this condition. * @@ -77,9 +55,4 @@ default boolean test(final Supplier type) { * @return True if the equipment type is suitable for this condition */ boolean test(EquipmentType type); - - interface Factory { - - EquipmentCondition byType(EquipmentType type); - } } diff --git a/src/main/java/org/spongepowered/api/item/inventory/equipment/EquipmentType.java b/src/main/java/org/spongepowered/api/item/inventory/equipment/EquipmentType.java index 3353344888..f24f78ed05 100644 --- a/src/main/java/org/spongepowered/api/item/inventory/equipment/EquipmentType.java +++ b/src/main/java/org/spongepowered/api/item/inventory/equipment/EquipmentType.java @@ -40,4 +40,11 @@ public interface EquipmentType extends DefaultedRegistryValue, St * @return The group */ EquipmentGroup group(); + + /** + * Gets the most specific {@link EquipmentCondition} for this equipment type. + * + * @return The condition + */ + EquipmentCondition condition(); } From 01f256bd22344a1224fd76c3738477eb36a7b094 Mon Sep 17 00:00:00 2001 From: MrHell228 Date: Thu, 25 Sep 2025 00:13:39 +0300 Subject: [PATCH 5/5] change ItemStack mentions to ItemStackLike --- src/main/java/org/spongepowered/api/data/Keys.java | 2 +- .../org/spongepowered/api/entity/attribute/ItemAttribute.java | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/spongepowered/api/data/Keys.java b/src/main/java/org/spongepowered/api/data/Keys.java index 5b6c9fec09..485d356b75 100644 --- a/src/main/java/org/spongepowered/api/data/Keys.java +++ b/src/main/java/org/spongepowered/api/data/Keys.java @@ -2183,7 +2183,7 @@ public final class Keys { public static final Key> IS_WET = Keys.key(ResourceKey.sponge("is_wet"), Boolean.class); /** - * The {@link ItemAttribute}s an {@link ItemStack} can apply. + * The {@link ItemAttribute}s an {@link ItemStackLike} can apply. */ public static final Key> ITEM_ATTRIBUTES = Keys.listKey(ResourceKey.sponge("item_attributes"), ItemAttribute.class); diff --git a/src/main/java/org/spongepowered/api/entity/attribute/ItemAttribute.java b/src/main/java/org/spongepowered/api/entity/attribute/ItemAttribute.java index 71dfa55547..77e304d71d 100644 --- a/src/main/java/org/spongepowered/api/entity/attribute/ItemAttribute.java +++ b/src/main/java/org/spongepowered/api/entity/attribute/ItemAttribute.java @@ -26,7 +26,7 @@ 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.ItemStackLike; import org.spongepowered.api.item.inventory.equipment.EquipmentCondition; import java.util.Objects; @@ -34,7 +34,7 @@ /** * Represents an {@link AttributeModifier} for the specific {@link AttributeType} - * an {@link ItemStack} can apply when the {@link EquipmentCondition} is met. + * an {@link ItemStackLike} can apply when the {@link EquipmentCondition} is met. */ public interface ItemAttribute {