Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/main/java/org/spongepowered/api/data/Keys.java
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,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;
Expand Down Expand Up @@ -2181,6 +2182,11 @@ public final class Keys {
*/
public static final Key<Value<Boolean>> IS_WET = Keys.key(ResourceKey.sponge("is_wet"), Boolean.class);

/**
* The {@link ItemAttribute}s an {@link ItemStackLike} can apply.
*/
public static final Key<ListValue<ItemAttribute>> ITEM_ATTRIBUTES = Keys.listKey(ResourceKey.sponge("item_attributes"), ItemAttribute.class);

/**
* The {@link ItemDisplayType display type} of a {@link org.spongepowered.api.entity.display.ItemDisplay}.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<? extends AttributeOperation> 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}.
*
Expand Down
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.ItemStackLike;
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 ItemStackLike} 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);
}
}
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);
}
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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,11 @@ public interface EquipmentType extends DefaultedRegistryValue<EquipmentType>, St
* @return The group
*/
EquipmentGroup group();

/**
* Gets the most specific {@link EquipmentCondition} for this equipment type.
*
* @return The condition
*/
EquipmentCondition condition();
}
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,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;
Expand Down Expand Up @@ -372,6 +373,8 @@ public final class RegistryTypes {

public static final DefaultedRegistryType<DyeColor> DYE_COLOR = RegistryTypes.spongeKeyInGame("dye_color");

public static final DefaultedRegistryType<EquipmentCondition> EQUIPMENT_CONDITION = RegistryTypes.spongeKeyInGame("equipment_condition");

public static final DefaultedRegistryType<EquipmentGroup> EQUIPMENT_GROUP = RegistryTypes.spongeKeyInGame("equipment_group");

public static final DefaultedRegistryType<EquipmentType> EQUIPMENT_TYPE = RegistryTypes.spongeKeyInGame("equipment_type");
Expand Down
Loading