Skip to content

Commit 2a5c338

Browse files
committed
Merge branch 'api-16' into api-17
# Conflicts: # gradle.properties # src/main/java/org/spongepowered/api/data/Keys.java
2 parents a0493bd + 9805791 commit 2a5c338

File tree

10 files changed

+265
-103
lines changed

10 files changed

+265
-103
lines changed

src/main/java/org/spongepowered/api/command/registrar/tree/CommandCompletionProviders.java

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
import org.spongepowered.api.Sponge;
2929
import org.spongepowered.api.effect.sound.SoundType;
3030
import org.spongepowered.api.entity.Entity;
31-
import org.spongepowered.api.item.recipe.Recipe;
3231
import org.spongepowered.api.registry.DefaultedRegistryReference;
3332
import org.spongepowered.api.registry.Registry;
3433
import org.spongepowered.api.registry.RegistryKey;
@@ -44,15 +43,6 @@ public final class CommandCompletionProviders {
4443

4544
// SORTFIELDS:ON
4645

47-
/**
48-
* Instructs the node represented by a {@link CommandTreeNode} to display
49-
* all known {@link Recipe recipes}.
50-
*
51-
* <p>This provider is intended for use with a {@link ResourceKey} parser.
52-
* </p>
53-
*/
54-
public static final DefaultedRegistryReference<CommandCompletionProvider> ALL_RECIPES = CommandCompletionProviders.key(ResourceKey.minecraft("all_recipes"));
55-
5646
/**
5747
* Instructs the node represented by a {@link CommandTreeNode} to display
5848
* all known {@link SoundType sounds}.

src/main/java/org/spongepowered/api/data/Keys.java

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,14 @@
5555
import org.spongepowered.api.data.type.ArtType;
5656
import org.spongepowered.api.data.type.AttachmentSurface;
5757
import org.spongepowered.api.data.type.AxolotlVariant;
58-
import org.spongepowered.api.data.type.BoatType;
5958
import org.spongepowered.api.data.type.BodyPart;
6059
import org.spongepowered.api.data.type.BodyParts;
6160
import org.spongepowered.api.data.type.CatType;
6261
import org.spongepowered.api.data.type.ChestAttachmentType;
62+
import org.spongepowered.api.data.type.ChickenVariant;
6363
import org.spongepowered.api.data.type.ComparatorMode;
6464
import org.spongepowered.api.data.type.CopperOxidation;
65+
import org.spongepowered.api.data.type.CowVariant;
6566
import org.spongepowered.api.data.type.DoorHinge;
6667
import org.spongepowered.api.data.type.DripstoneSegment;
6768
import org.spongepowered.api.data.type.DyeColor;
@@ -134,6 +135,7 @@
134135
import org.spongepowered.api.entity.Item;
135136
import org.spongepowered.api.entity.Ownable;
136137
import org.spongepowered.api.entity.ai.goal.GoalExecutorTypes;
138+
import org.spongepowered.api.entity.attribute.ItemAttribute;
137139
import org.spongepowered.api.entity.display.BillboardType;
138140
import org.spongepowered.api.entity.display.DisplayEntity;
139141
import org.spongepowered.api.entity.display.ItemDisplayType;
@@ -167,6 +169,7 @@
167169
import org.spongepowered.api.entity.living.animal.TameableAnimal;
168170
import org.spongepowered.api.entity.living.animal.Turtle;
169171
import org.spongepowered.api.entity.living.animal.Wolf;
172+
import org.spongepowered.api.entity.living.animal.cow.Cow;
170173
import org.spongepowered.api.entity.living.animal.cow.Mooshroom;
171174
import org.spongepowered.api.entity.living.animal.frog.Frog;
172175
import org.spongepowered.api.entity.living.animal.horse.Horse;
@@ -578,11 +581,6 @@ public final class Keys {
578581
*/
579582
public static final Key<Value<Double>> BLOCK_TEMPERATURE = Keys.key(ResourceKey.sponge("block_temperature"), Double.class);
580583

581-
/**
582-
* The type of the boat.
583-
*/
584-
public static final Key<Value<BoatType>> BOAT_TYPE = Keys.key(ResourceKey.sponge("boat_type"), BoatType.class);
585-
586584
/**
587585
* The rotation of specific body parts of a {@link ArmorStand} or {@link Living}.
588586
*
@@ -754,6 +752,11 @@ public final class Keys {
754752
*/
755753
public static final Key<Value<Vector3d>> CHEST_ROTATION = Keys.key(ResourceKey.sponge("chest_rotation"), Vector3d.class);
756754

755+
/**
756+
* The {@link ChickenVariant} of a {@link Chicken}.
757+
*/
758+
public static final Key<Value<ChickenVariant>> CHICKEN_VARIANT = Keys.key(ResourceKey.sponge("chicken_variant"), ChickenVariant.class);
759+
757760
/**
758761
* The chunk generator of a {@link World}
759762
* Readonly
@@ -812,6 +815,11 @@ public final class Keys {
812815
*/
813816
public static final Key<Value<CopperOxidation>> COPPER_OXIDATION = Keys.key(ResourceKey.sponge("copper_oxidation"), CopperOxidation.class);
814817

818+
/**
819+
* The {@link CowVariant} of a {@link Cow}.
820+
*/
821+
public static final Key<Value<CowVariant>> COW_VARIANT = Keys.key(ResourceKey.sponge("cow_variant"), CowVariant.class);
822+
815823
/**
816824
* The {@link ItemStack} a food {@link ItemStack} converts to when eaten.
817825
*/
@@ -2212,6 +2220,11 @@ public final class Keys {
22122220
*/
22132221
public static final Key<Value<Boolean>> IS_WET = Keys.key(ResourceKey.sponge("is_wet"), Boolean.class);
22142222

2223+
/**
2224+
* The {@link ItemAttribute}s an {@link ItemStackLike} can apply.
2225+
*/
2226+
public static final Key<ListValue<ItemAttribute>> ITEM_ATTRIBUTES = Keys.listKey(ResourceKey.sponge("item_attributes"), ItemAttribute.class);
2227+
22152228
/**
22162229
* The {@link ItemDisplayType display type} of a {@link org.spongepowered.api.entity.display.ItemDisplay}.
22172230
*/

src/main/java/org/spongepowered/api/data/type/BoatTypes.java

Lines changed: 0 additions & 71 deletions
This file was deleted.

src/main/java/org/spongepowered/api/entity/attribute/AttributeModifier.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
*/
2525
package org.spongepowered.api.entity.attribute;
2626

27+
import org.spongepowered.api.ResourceKey;
2728
import org.spongepowered.api.ResourceKeyed;
2829
import org.spongepowered.api.Sponge;
2930
import org.spongepowered.api.item.inventory.ItemStack;
@@ -38,6 +39,30 @@
3839
*/
3940
public interface AttributeModifier extends ResourceKeyed {
4041

42+
/**
43+
* Creates an attribute modifier with the given values.
44+
*
45+
* @param key The resource key
46+
* @param operation The attribute operation
47+
* @param amount The amount
48+
* @return The attribute modifier
49+
*/
50+
static AttributeModifier of(final ResourceKey key, final Supplier<? extends AttributeOperation> operation, final double amount) {
51+
return AttributeModifier.builder().key(key).operation(operation).amount(amount).build();
52+
}
53+
54+
/**
55+
* Creates an attribute modifier with the given values.
56+
*
57+
* @param key The resource key
58+
* @param operation The attribute operation
59+
* @param amount The amount
60+
* @return The attribute modifier
61+
*/
62+
static AttributeModifier of(final ResourceKey key, final AttributeOperation operation, final double amount) {
63+
return AttributeModifier.builder().key(key).operation(operation).amount(amount).build();
64+
}
65+
4166
/**
4267
* Creates a new {@link Builder} to create an {@link AttributeModifier}.
4368
*
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
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.entity.attribute;
26+
27+
import org.spongepowered.api.Sponge;
28+
import org.spongepowered.api.entity.attribute.type.AttributeType;
29+
import org.spongepowered.api.item.inventory.ItemStackLike;
30+
import org.spongepowered.api.item.inventory.equipment.EquipmentCondition;
31+
32+
import java.util.Objects;
33+
import java.util.function.Supplier;
34+
35+
/**
36+
* Represents an {@link AttributeModifier} for the specific {@link AttributeType}
37+
* an {@link ItemStackLike} can apply when the {@link EquipmentCondition} is met.
38+
*/
39+
public interface ItemAttribute {
40+
41+
/**
42+
* Creates an item attribute with the given values.
43+
*
44+
* @param type The attribute type
45+
* @param modifier The attribute modifier
46+
* @param condition The equipment condition
47+
* @return The item attribute
48+
*/
49+
static ItemAttribute of(final Supplier<? extends AttributeType> type, final AttributeModifier modifier, final Supplier<? extends EquipmentCondition> condition) {
50+
return ItemAttribute.of(Objects.requireNonNull(type, "type").get(), modifier, Objects.requireNonNull(condition, "condition").get());
51+
}
52+
53+
/**
54+
* Creates an item attribute with the given values.
55+
*
56+
* @param type The attribute type
57+
* @param modifier The attribute modifier
58+
* @param condition The equipment condition
59+
* @return The item attribute
60+
*/
61+
static ItemAttribute of(final Supplier<? extends AttributeType> type, final AttributeModifier modifier, final EquipmentCondition condition) {
62+
return ItemAttribute.of(Objects.requireNonNull(type, "type").get(), modifier, condition);
63+
}
64+
65+
/**
66+
* Creates an item attribute with the given values.
67+
*
68+
* @param type The attribute type
69+
* @param modifier The attribute modifier
70+
* @param condition The equipment condition
71+
* @return The item attribute
72+
*/
73+
static ItemAttribute of(final AttributeType type, final AttributeModifier modifier, final Supplier<? extends EquipmentCondition> condition) {
74+
return ItemAttribute.of(type, modifier, Objects.requireNonNull(condition, "condition").get());
75+
}
76+
77+
/**
78+
* Creates an item attribute with the given values.
79+
*
80+
* @param type The attribute type
81+
* @param modifier The attribute modifier
82+
* @param condition The equipment condition
83+
* @return The item attribute
84+
*/
85+
static ItemAttribute of(final AttributeType type, final AttributeModifier modifier, final EquipmentCondition condition) {
86+
return Sponge.game().factoryProvider().provide(Factory.class).of(type, modifier, condition);
87+
}
88+
89+
/**
90+
* Returns the attribute type.
91+
*
92+
* @return The attribute type
93+
*/
94+
AttributeType type();
95+
96+
/**
97+
* Returns the attribute modifier.
98+
*
99+
* @return The attribute modifier
100+
*/
101+
AttributeModifier modifier();
102+
103+
/**
104+
* Returns the equipment condition.
105+
*
106+
* @return The equipment condition
107+
*/
108+
EquipmentCondition condition();
109+
110+
interface Factory {
111+
112+
ItemAttribute of(AttributeType type, AttributeModifier modifier, EquipmentCondition condition);
113+
}
114+
}

src/main/java/org/spongepowered/api/entity/vehicle/Boat.java

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
package org.spongepowered.api.entity.vehicle;
2626

2727
import org.spongepowered.api.data.Keys;
28-
import org.spongepowered.api.data.type.BoatType;
2928
import org.spongepowered.api.data.value.Value;
3029
import org.spongepowered.api.entity.Leashable;
3130

@@ -34,15 +33,6 @@
3433
*/
3534
public interface Boat extends Vehicle, Leashable {
3635

37-
/**
38-
* {@link Keys#BOAT_TYPE}
39-
*
40-
* @return The type of the boat
41-
*/
42-
default Value.Mutable<BoatType> boatType() {
43-
return this.requireValue(Keys.BOAT_TYPE).asMutable();
44-
}
45-
4636
/**
4737
* {@link Keys#IS_IN_WATER}
4838
*

src/main/java/org/spongepowered/api/data/type/BoatType.java renamed to src/main/java/org/spongepowered/api/item/inventory/equipment/EquipmentCondition.java

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,37 @@
2222
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
2323
* THE SOFTWARE.
2424
*/
25-
package org.spongepowered.api.data.type;
25+
package org.spongepowered.api.item.inventory.equipment;
2626

27+
import net.kyori.adventure.text.ComponentLike;
28+
import org.spongepowered.api.data.type.StringRepresentable;
2729
import org.spongepowered.api.registry.DefaultedRegistryValue;
2830
import org.spongepowered.api.util.annotation.CatalogedBy;
2931

30-
@CatalogedBy(BoatTypes.class)
31-
public interface BoatType extends DefaultedRegistryValue<BoatType> {
32+
import java.util.Objects;
33+
import java.util.function.Supplier;
3234

35+
/**
36+
* Represents some condition for {@link EquipmentType}.
37+
*/
38+
@CatalogedBy(EquipmentConditions.class)
39+
public interface EquipmentCondition extends DefaultedRegistryValue<EquipmentCondition>, StringRepresentable, ComponentLike {
40+
41+
/**
42+
* Tests whether the equipment type is suitable for this condition.
43+
*
44+
* @param type The equipment type to test
45+
* @return True if the equipment type is suitable for this condition
46+
*/
47+
default boolean test(final Supplier<? extends EquipmentType> type) {
48+
return this.test(Objects.requireNonNull(type, "type").get());
49+
}
50+
51+
/**
52+
* Tests whether the equipment type is suitable for this condition.
53+
*
54+
* @param type The equipment type to test
55+
* @return True if the equipment type is suitable for this condition
56+
*/
57+
boolean test(EquipmentType type);
3358
}

0 commit comments

Comments
 (0)