Skip to content

Commit f8d5e3e

Browse files
committed
expose EquipmentCondition
1 parent d15129e commit f8d5e3e

File tree

3 files changed

+157
-0
lines changed

3 files changed

+157
-0
lines changed
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
/*
2+
* This file is part of SpongeAPI, licensed under the MIT License (MIT).
3+
*
4+
* Copyright (c) SpongePowered <https://www.spongepowered.org>
5+
* Copyright (c) contributors
6+
*
7+
* Permission is hereby granted, free of charge, to any person obtaining a copy
8+
* of this software and associated documentation files (the "Software"), to deal
9+
* in the Software without restriction, including without limitation the rights
10+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
* copies of the Software, and to permit persons to whom the Software is
12+
* furnished to do so, subject to the following conditions:
13+
*
14+
* The above copyright notice and this permission notice shall be included in
15+
* all copies or substantial portions of the Software.
16+
*
17+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23+
* THE SOFTWARE.
24+
*/
25+
package org.spongepowered.api.item.inventory.equipment;
26+
27+
import net.kyori.adventure.text.ComponentLike;
28+
import org.spongepowered.api.Sponge;
29+
import org.spongepowered.api.data.type.StringRepresentable;
30+
import org.spongepowered.api.registry.DefaultedRegistryValue;
31+
import org.spongepowered.api.util.annotation.CatalogedBy;
32+
33+
import java.util.Objects;
34+
import java.util.function.Predicate;
35+
import java.util.function.Supplier;
36+
37+
/**
38+
* Represents some condition for {@link EquipmentType}.
39+
*/
40+
@CatalogedBy(EquipmentConditions.class)
41+
public interface EquipmentCondition extends DefaultedRegistryValue<EquipmentCondition>, StringRepresentable, ComponentLike {
42+
43+
/**
44+
* Returns the most specific equipment condition for the given equipment type.
45+
*
46+
* @param type The equipment type
47+
* @return The equipment condition
48+
*/
49+
static EquipmentCondition byType(final Supplier<? extends EquipmentType> type) {
50+
return EquipmentCondition.byType(Objects.requireNonNull(type, "type").get());
51+
}
52+
53+
/**
54+
* Returns the most specific equipment condition for the given equipment type.
55+
*
56+
* @param type The equipment type
57+
* @return The equipment condition
58+
*/
59+
static EquipmentCondition byType(final EquipmentType type) {
60+
return Sponge.game().factoryProvider().provide(Factory.class).byType(type);
61+
}
62+
63+
/**
64+
* Tests whether the equipment type is suitable for this condition.
65+
*
66+
* @param type The equipment type to test
67+
* @return True if the equipment type is suitable for this condition
68+
*/
69+
default boolean test(final Supplier<? extends EquipmentType> type) {
70+
return this.test(Objects.requireNonNull(type, "type").get());
71+
}
72+
73+
/**
74+
* Tests whether the equipment type is suitable for this condition.
75+
*
76+
* @param type The equipment type to test
77+
* @return True if the equipment type is suitable for this condition
78+
*/
79+
boolean test(EquipmentType type);
80+
81+
interface Factory {
82+
83+
EquipmentCondition byType(EquipmentType type);
84+
}
85+
}
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
/*
2+
* This file is part of SpongeAPI, licensed under the MIT License (MIT).
3+
*
4+
* Copyright (c) SpongePowered <https://www.spongepowered.org>
5+
* Copyright (c) contributors
6+
*
7+
* Permission is hereby granted, free of charge, to any person obtaining a copy
8+
* of this software and associated documentation files (the "Software"), to deal
9+
* in the Software without restriction, including without limitation the rights
10+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
* copies of the Software, and to permit persons to whom the Software is
12+
* furnished to do so, subject to the following conditions:
13+
*
14+
* The above copyright notice and this permission notice shall be included in
15+
* all copies or substantial portions of the Software.
16+
*
17+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23+
* THE SOFTWARE.
24+
*/
25+
package org.spongepowered.api.item.inventory.equipment;
26+
27+
import org.spongepowered.api.ResourceKey;
28+
import org.spongepowered.api.Sponge;
29+
import org.spongepowered.api.registry.DefaultedRegistryReference;
30+
import org.spongepowered.api.registry.Registry;
31+
import org.spongepowered.api.registry.RegistryKey;
32+
import org.spongepowered.api.registry.RegistryTypes;
33+
34+
/**
35+
* <!-- This file is automatically generated. Any manual changes will be overwritten. -->
36+
*/
37+
public final class EquipmentConditions {
38+
39+
public static final DefaultedRegistryReference<EquipmentCondition> ANY = EquipmentConditions.key(ResourceKey.sponge("any"));
40+
41+
public static final DefaultedRegistryReference<EquipmentCondition> ARMOR = EquipmentConditions.key(ResourceKey.sponge("armor"));
42+
43+
public static final DefaultedRegistryReference<EquipmentCondition> BODY = EquipmentConditions.key(ResourceKey.sponge("body"));
44+
45+
public static final DefaultedRegistryReference<EquipmentCondition> CHEST = EquipmentConditions.key(ResourceKey.sponge("chest"));
46+
47+
public static final DefaultedRegistryReference<EquipmentCondition> FEET = EquipmentConditions.key(ResourceKey.sponge("feet"));
48+
49+
public static final DefaultedRegistryReference<EquipmentCondition> HAND = EquipmentConditions.key(ResourceKey.sponge("hand"));
50+
51+
public static final DefaultedRegistryReference<EquipmentCondition> HEAD = EquipmentConditions.key(ResourceKey.sponge("head"));
52+
53+
public static final DefaultedRegistryReference<EquipmentCondition> LEGS = EquipmentConditions.key(ResourceKey.sponge("legs"));
54+
55+
public static final DefaultedRegistryReference<EquipmentCondition> MAINHAND = EquipmentConditions.key(ResourceKey.sponge("mainhand"));
56+
57+
public static final DefaultedRegistryReference<EquipmentCondition> OFFHAND = EquipmentConditions.key(ResourceKey.sponge("offhand"));
58+
59+
private EquipmentConditions() {
60+
}
61+
62+
public static Registry<EquipmentCondition> registry() {
63+
return Sponge.game().registry(RegistryTypes.EQUIPMENT_CONDITION);
64+
}
65+
66+
private static DefaultedRegistryReference<EquipmentCondition> key(final ResourceKey location) {
67+
return RegistryKey.of(RegistryTypes.EQUIPMENT_CONDITION, location).asDefaultedReference(Sponge::game);
68+
}
69+
}

src/main/java/org/spongepowered/api/registry/RegistryTypes.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@
127127
import org.spongepowered.api.item.ItemType;
128128
import org.spongepowered.api.item.enchantment.EnchantmentType;
129129
import org.spongepowered.api.item.inventory.ContainerType;
130+
import org.spongepowered.api.item.inventory.equipment.EquipmentCondition;
130131
import org.spongepowered.api.item.inventory.equipment.EquipmentGroup;
131132
import org.spongepowered.api.item.inventory.equipment.EquipmentType;
132133
import org.spongepowered.api.item.inventory.menu.ClickType;
@@ -369,6 +370,8 @@ public final class RegistryTypes {
369370

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

373+
public static final DefaultedRegistryType<EquipmentCondition> EQUIPMENT_CONDITION = RegistryTypes.spongeKeyInGame("equipment_condition");
374+
372375
public static final DefaultedRegistryType<EquipmentGroup> EQUIPMENT_GROUP = RegistryTypes.spongeKeyInGame("equipment_group");
373376

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

0 commit comments

Comments
 (0)