Skip to content

Commit b4fab13

Browse files
authored
Refactor projectiles classes (#2552)
* Refactor projectiles classes * run spotlessApply * Update EyeOfEnder.java * Rename ArrowEntity to ArrowLike * Drop EntityTargetingProjectile * Add ItemSupplier and remove ThrowableProjectile * Abstract ItemRepresentable behaviour to a separate class * Update item frames * Update ItemRepresentable.java * run spotlessApply * Rename DamagingProjectile to AcceleratingProjectile * run spotlessApply * Update ShulkerBullet.java * Update EyeOfEnder.java
1 parent 75f057f commit b4fab13

28 files changed

+103
-90
lines changed

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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -189,15 +189,15 @@
189189
import org.spongepowered.api.entity.living.player.server.ServerPlayer;
190190
import org.spongepowered.api.entity.living.slime.Slime;
191191
import org.spongepowered.api.entity.living.trader.Villager;
192-
import org.spongepowered.api.entity.projectile.DamagingProjectile;
192+
import org.spongepowered.api.entity.projectile.AcceleratingProjectile;
193193
import org.spongepowered.api.entity.projectile.EyeOfEnder;
194194
import org.spongepowered.api.entity.projectile.FishingBobber;
195195
import org.spongepowered.api.entity.projectile.IgnitingProjectile;
196196
import org.spongepowered.api.entity.projectile.Potion;
197197
import org.spongepowered.api.entity.projectile.Projectile;
198198
import org.spongepowered.api.entity.projectile.ShulkerBullet;
199199
import org.spongepowered.api.entity.projectile.arrow.Arrow;
200-
import org.spongepowered.api.entity.projectile.arrow.ArrowEntity;
200+
import org.spongepowered.api.entity.projectile.arrow.ArrowLike;
201201
import org.spongepowered.api.entity.projectile.explosive.FireworkRocket;
202202
import org.spongepowered.api.entity.projectile.explosive.WitherSkull;
203203
import org.spongepowered.api.entity.vehicle.Boat;
@@ -304,7 +304,7 @@ public final class Keys {
304304
public static final Key<Value<Double>> ABSORPTION = Keys.key(ResourceKey.sponge("absorption"), Double.class);
305305

306306
/**
307-
* The acceleration of a {@link DamagingProjectile}.
307+
* The acceleration of a {@link AcceleratingProjectile}.
308308
*/
309309
public static final Key<Value<Double>> ACCELERATION = Keys.key(ResourceKey.sponge("acceleration"), Double.class);
310310

@@ -413,7 +413,7 @@ public final class Keys {
413413
public static final Key<Value<AttachmentSurface>> ATTACHMENT_SURFACE = Keys.key(ResourceKey.sponge("attachment_surface"), AttachmentSurface.class);
414414

415415
/**
416-
* The damage dealt by an {@link ArrowEntity} on impact.
416+
* The damage dealt by an {@link ArrowLike} on impact.
417417
*/
418418
public static final Key<Value<Double>> ATTACK_DAMAGE = Keys.key(ResourceKey.sponge("attack_damage"), Double.class);
419419

@@ -781,11 +781,11 @@ public final class Keys {
781781
public static final Key<Value<SpellType>> CURRENT_SPELL = Keys.key(ResourceKey.sponge("current_spell"), SpellType.class);
782782

783783
/**
784-
* The damage dealt towards entities of a specific {@link EntityType} by a {@link ArrowEntity}.
784+
* The damage dealt towards entities of a specific {@link EntityType} by a {@link ArrowLike}.
785785
*
786786
* <p>Note that in events, the damage defined for the provided
787787
* {@link EntityType} will take priority over the "default" damage as
788-
* defined from {@link ArrowEntity#attackDamage()}.</p>
788+
* defined from {@link ArrowLike#attackDamage()}.</p>
789789
*
790790
* <p>Types not present in this mapping will be
791791
* dealt damage to according to {@link #ATTACK_DAMAGE}.</p>
@@ -2089,7 +2089,7 @@ public final class Keys {
20892089
public static final Key<Value<ItemStackSnapshot>> ITEM_STACK_SNAPSHOT = Keys.key(ResourceKey.sponge("item_stack_snapshot"), ItemStackSnapshot.class);
20902090

20912091
/**
2092-
* The custom knockback strength applied by an {@link ArrowEntity}.
2092+
* The custom knockback strength applied by an {@link ArrowLike}.
20932093
*
20942094
* <p>For the knockback provided by hits with a weapon according to the
20952095
* enchantment of the same name, see {@link #APPLIED_ENCHANTMENTS}.</p>
@@ -2538,7 +2538,7 @@ public final class Keys {
25382538
public static final Key<Value<Ticks>> PICKUP_DELAY = Keys.key(ResourceKey.sponge("pickup_delay"), Ticks.class);
25392539

25402540
/**
2541-
* The {@link PickupRule} of an {@link ArrowEntity}.
2541+
* The {@link PickupRule} of an {@link ArrowLike}.
25422542
*/
25432543
public static final Key<Value<PickupRule>> PICKUP_RULE = Keys.key(ResourceKey.sponge("pickup_rule"), PickupRule.class);
25442544

@@ -2605,7 +2605,7 @@ public final class Keys {
26052605

26062606
/**
26072607
* The potion effects that are present on an {@link Entity}
2608-
* <p>or applied by an {@link AreaEffectCloud} or {@link ArrowEntity}</p>
2608+
* <p>or applied by an {@link AreaEffectCloud} or {@link ArrowLike}</p>
26092609
* <p>or stored on an {@link ItemStack}.</p>
26102610
*/
26112611
public static final Key<ListValue<PotionEffect>> POTION_EFFECTS = Keys.listKey(ResourceKey.sponge("potion_effects"), PotionEffect.class);

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,12 @@
2424
*/
2525
package org.spongepowered.api.data.type;
2626

27-
import org.spongepowered.api.entity.projectile.arrow.ArrowEntity;
27+
import org.spongepowered.api.entity.projectile.arrow.ArrowLike;
2828
import org.spongepowered.api.registry.DefaultedRegistryValue;
2929
import org.spongepowered.api.util.annotation.CatalogedBy;
3030

3131
/**
32-
* Represents a pickup rule used by {@link ArrowEntity}s.
32+
* Represents a pickup rule used by {@link ArrowLike}s.
3333
*/
3434
@CatalogedBy(PickupRules.class)
3535
public interface PickupRule extends DefaultedRegistryValue {

src/main/java/org/spongepowered/api/entity/Item.java

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,22 +26,12 @@
2626

2727
import org.spongepowered.api.data.Keys;
2828
import org.spongepowered.api.data.value.Value;
29-
import org.spongepowered.api.item.inventory.ItemStackSnapshot;
3029
import org.spongepowered.api.util.Ticks;
3130

3231
/**
3332
* Represents an Item.
3433
*/
35-
public interface Item extends Entity {
36-
37-
/**
38-
* {@link Keys#ITEM_STACK_SNAPSHOT}
39-
*
40-
* @return The item being represented by this entity
41-
*/
42-
default Value.Mutable<ItemStackSnapshot> item() {
43-
return this.requireValue(Keys.ITEM_STACK_SNAPSHOT).asMutable();
44-
}
34+
public interface Item extends Entity, ItemRepresentable {
4535

4636
/**
4737
* {@link Keys#DESPAWN_DELAY}

src/main/java/org/spongepowered/api/entity/projectile/EntityTargetingProjectile.java renamed to src/main/java/org/spongepowered/api/entity/ItemRepresentable.java

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,25 +22,20 @@
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.entity.projectile;
25+
package org.spongepowered.api.entity;
2626

2727
import org.spongepowered.api.data.Keys;
2828
import org.spongepowered.api.data.value.Value;
29-
import org.spongepowered.api.entity.Entity;
29+
import org.spongepowered.api.item.inventory.ItemStackSnapshot;
3030

31-
import java.util.Optional;
32-
33-
/**
34-
* Represents a {@link Projectile} targeting an {@link Entity}
35-
*/
36-
public interface EntityTargetingProjectile extends Projectile {
31+
public interface ItemRepresentable extends Entity {
3732

3833
/**
39-
* {@link Keys#TARGET_ENTITY}
34+
* {@link Keys#ITEM_STACK_SNAPSHOT}
4035
*
41-
* @return The targeted entity, if available
36+
* @return The item being represented by this entity
4237
*/
43-
default Optional<Value.Mutable<Entity>> targetEntity() {
44-
return this.getValue(Keys.TARGET_ENTITY).map(Value::asMutable);
38+
default Value.Mutable<ItemStackSnapshot> item() {
39+
return this.requireValue(Keys.ITEM_STACK_SNAPSHOT).asMutable();
4540
}
4641
}

src/main/java/org/spongepowered/api/entity/OminousItemSpawner.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,5 @@
2424
*/
2525
package org.spongepowered.api.entity;
2626

27-
public interface OminousItemSpawner extends Entity {
27+
public interface OminousItemSpawner extends Entity, ItemRepresentable {
2828
}

src/main/java/org/spongepowered/api/entity/display/ItemDisplay.java

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,20 +25,12 @@
2525
package org.spongepowered.api.entity.display;
2626

2727
import org.spongepowered.api.data.Keys;
28-
import org.spongepowered.api.item.inventory.ItemStackSnapshot;
28+
import org.spongepowered.api.entity.ItemRepresentable;
2929

3030
/**
3131
* A ItemDisplay is an entity that displays a single item in the world.
3232
*/
33-
public interface ItemDisplay extends DisplayEntity {
34-
/**
35-
* Returns the {@link ItemStackSnapshot item} displayed.
36-
*
37-
* @return The item displayed
38-
*/
39-
default ItemStackSnapshot displayedItem() {
40-
return this.require(Keys.ITEM_STACK_SNAPSHOT);
41-
}
33+
public interface ItemDisplay extends DisplayEntity, ItemRepresentable {
4234

4335
/**
4436
* Returns the {@link ItemDisplayType display type}.

src/main/java/org/spongepowered/api/entity/projectile/DamagingProjectile.java renamed to src/main/java/org/spongepowered/api/entity/projectile/AcceleratingProjectile.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@
2828
import org.spongepowered.api.data.value.Value;
2929

3030
/**
31-
* Represents a {@link Projectile} that inflicts damage.
31+
* Represents a {@link Projectile} that can accelerate.
3232
*/
33-
public interface DamagingProjectile extends Projectile {
33+
public interface AcceleratingProjectile extends Projectile {
3434

3535
/**
3636
* {@link Keys#ACCELERATION}

src/main/java/org/spongepowered/api/entity/projectile/Egg.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,6 @@
2727
/**
2828
* Represents a thrown egg.
2929
*/
30-
public interface Egg extends DamagingProjectile {
30+
public interface Egg extends ThrowableItemProjectile {
3131

3232
}

src/main/java/org/spongepowered/api/entity/projectile/EnderPearl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,6 @@
2727
/**
2828
* Represents an Ender Pearl.
2929
*/
30-
public interface EnderPearl extends DamagingProjectile {
30+
public interface EnderPearl extends ThrowableItemProjectile {
3131

3232
}

src/main/java/org/spongepowered/api/entity/projectile/EvokerFangs.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,7 @@
2424
*/
2525
package org.spongepowered.api.entity.projectile;
2626

27-
public interface EvokerFangs extends Projectile {
27+
import org.spongepowered.api.entity.Entity;
28+
29+
public interface EvokerFangs extends Entity {
2830
}

0 commit comments

Comments
 (0)