Skip to content

Commit

Permalink
Refactor projectiles classes (#2552)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
ImMorpheus authored Jul 6, 2024
1 parent 75f057f commit b4fab13
Show file tree
Hide file tree
Showing 28 changed files with 103 additions and 90 deletions.
18 changes: 9 additions & 9 deletions src/main/java/org/spongepowered/api/data/Keys.java
Original file line number Diff line number Diff line change
Expand Up @@ -189,15 +189,15 @@
import org.spongepowered.api.entity.living.player.server.ServerPlayer;
import org.spongepowered.api.entity.living.slime.Slime;
import org.spongepowered.api.entity.living.trader.Villager;
import org.spongepowered.api.entity.projectile.DamagingProjectile;
import org.spongepowered.api.entity.projectile.AcceleratingProjectile;
import org.spongepowered.api.entity.projectile.EyeOfEnder;
import org.spongepowered.api.entity.projectile.FishingBobber;
import org.spongepowered.api.entity.projectile.IgnitingProjectile;
import org.spongepowered.api.entity.projectile.Potion;
import org.spongepowered.api.entity.projectile.Projectile;
import org.spongepowered.api.entity.projectile.ShulkerBullet;
import org.spongepowered.api.entity.projectile.arrow.Arrow;
import org.spongepowered.api.entity.projectile.arrow.ArrowEntity;
import org.spongepowered.api.entity.projectile.arrow.ArrowLike;
import org.spongepowered.api.entity.projectile.explosive.FireworkRocket;
import org.spongepowered.api.entity.projectile.explosive.WitherSkull;
import org.spongepowered.api.entity.vehicle.Boat;
Expand Down Expand Up @@ -304,7 +304,7 @@ public final class Keys {
public static final Key<Value<Double>> ABSORPTION = Keys.key(ResourceKey.sponge("absorption"), Double.class);

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

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

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

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

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

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

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

Expand Down Expand Up @@ -2605,7 +2605,7 @@ public final class Keys {

/**
* The potion effects that are present on an {@link Entity}
* <p>or applied by an {@link AreaEffectCloud} or {@link ArrowEntity}</p>
* <p>or applied by an {@link AreaEffectCloud} or {@link ArrowLike}</p>
* <p>or stored on an {@link ItemStack}.</p>
*/
public static final Key<ListValue<PotionEffect>> POTION_EFFECTS = Keys.listKey(ResourceKey.sponge("potion_effects"), PotionEffect.class);
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/spongepowered/api/data/type/PickupRule.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@
*/
package org.spongepowered.api.data.type;

import org.spongepowered.api.entity.projectile.arrow.ArrowEntity;
import org.spongepowered.api.entity.projectile.arrow.ArrowLike;
import org.spongepowered.api.registry.DefaultedRegistryValue;
import org.spongepowered.api.util.annotation.CatalogedBy;

/**
* Represents a pickup rule used by {@link ArrowEntity}s.
* Represents a pickup rule used by {@link ArrowLike}s.
*/
@CatalogedBy(PickupRules.class)
public interface PickupRule extends DefaultedRegistryValue {
Expand Down
12 changes: 1 addition & 11 deletions src/main/java/org/spongepowered/api/entity/Item.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,22 +26,12 @@

import org.spongepowered.api.data.Keys;
import org.spongepowered.api.data.value.Value;
import org.spongepowered.api.item.inventory.ItemStackSnapshot;
import org.spongepowered.api.util.Ticks;

/**
* Represents an Item.
*/
public interface Item extends Entity {

/**
* {@link Keys#ITEM_STACK_SNAPSHOT}
*
* @return The item being represented by this entity
*/
default Value.Mutable<ItemStackSnapshot> item() {
return this.requireValue(Keys.ITEM_STACK_SNAPSHOT).asMutable();
}
public interface Item extends Entity, ItemRepresentable {

/**
* {@link Keys#DESPAWN_DELAY}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,25 +22,20 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package org.spongepowered.api.entity.projectile;
package org.spongepowered.api.entity;

import org.spongepowered.api.data.Keys;
import org.spongepowered.api.data.value.Value;
import org.spongepowered.api.entity.Entity;
import org.spongepowered.api.item.inventory.ItemStackSnapshot;

import java.util.Optional;

/**
* Represents a {@link Projectile} targeting an {@link Entity}
*/
public interface EntityTargetingProjectile extends Projectile {
public interface ItemRepresentable extends Entity {

/**
* {@link Keys#TARGET_ENTITY}
* {@link Keys#ITEM_STACK_SNAPSHOT}
*
* @return The targeted entity, if available
* @return The item being represented by this entity
*/
default Optional<Value.Mutable<Entity>> targetEntity() {
return this.getValue(Keys.TARGET_ENTITY).map(Value::asMutable);
default Value.Mutable<ItemStackSnapshot> item() {
return this.requireValue(Keys.ITEM_STACK_SNAPSHOT).asMutable();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,5 @@
*/
package org.spongepowered.api.entity;

public interface OminousItemSpawner extends Entity {
public interface OminousItemSpawner extends Entity, ItemRepresentable {
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,12 @@
package org.spongepowered.api.entity.display;

import org.spongepowered.api.data.Keys;
import org.spongepowered.api.item.inventory.ItemStackSnapshot;
import org.spongepowered.api.entity.ItemRepresentable;

/**
* A ItemDisplay is an entity that displays a single item in the world.
*/
public interface ItemDisplay extends DisplayEntity {
/**
* Returns the {@link ItemStackSnapshot item} displayed.
*
* @return The item displayed
*/
default ItemStackSnapshot displayedItem() {
return this.require(Keys.ITEM_STACK_SNAPSHOT);
}
public interface ItemDisplay extends DisplayEntity, ItemRepresentable {

/**
* Returns the {@link ItemDisplayType display type}.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@
import org.spongepowered.api.data.value.Value;

/**
* Represents a {@link Projectile} that inflicts damage.
* Represents a {@link Projectile} that can accelerate.
*/
public interface DamagingProjectile extends Projectile {
public interface AcceleratingProjectile extends Projectile {

/**
* {@link Keys#ACCELERATION}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@
/**
* Represents a thrown egg.
*/
public interface Egg extends DamagingProjectile {
public interface Egg extends ThrowableItemProjectile {

}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@
/**
* Represents an Ender Pearl.
*/
public interface EnderPearl extends DamagingProjectile {
public interface EnderPearl extends ThrowableItemProjectile {

}
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,7 @@
*/
package org.spongepowered.api.entity.projectile;

public interface EvokerFangs extends Projectile {
import org.spongepowered.api.entity.Entity;

public interface EvokerFangs extends Entity {
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@
/**
* Represents a thrown experience bottle.
*/
public interface ExperienceBottle extends Projectile {
public interface ExperienceBottle extends ThrowableItemProjectile {

}
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,14 @@

import org.spongepowered.api.data.Keys;
import org.spongepowered.api.data.value.Value;
import org.spongepowered.api.entity.ItemRepresentable;
import org.spongepowered.api.util.Ticks;
import org.spongepowered.math.vector.Vector3d;

/**
* Represents an Eye of Ender.
*/
public interface EyeOfEnder extends Projectile {
public interface EyeOfEnder extends Projectile, ItemRepresentable {

/**
* {@link Keys#DESPAWN_DELAY}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,12 @@
*/
package org.spongepowered.api.entity.projectile;

import org.spongepowered.api.entity.ItemRepresentable;
import org.spongepowered.api.entity.projectile.explosive.fireball.SmallFireball;

/**
* Represents an abstract projectile that may ignite, such as {@link SmallFireball}.
*/
public interface IgnitingProjectile extends DamagingProjectile {
public interface IgnitingProjectile extends AcceleratingProjectile, ItemRepresentable {

}
Original file line number Diff line number Diff line change
Expand Up @@ -26,23 +26,12 @@

import org.spongepowered.api.data.Keys;
import org.spongepowered.api.data.value.ListValue;
import org.spongepowered.api.data.value.Value;
import org.spongepowered.api.effect.potion.PotionEffect;
import org.spongepowered.api.item.inventory.ItemStackSnapshot;

/**
* Represents a thrown potion.
*/
public interface Potion extends Projectile {

/**
* {@link Keys#ITEM_STACK_SNAPSHOT}
*
* @return The potion item represented by this potion
*/
default Value.Mutable<ItemStackSnapshot> item() {
return this.requireValue(Keys.ITEM_STACK_SNAPSHOT).asMutable();
}
public interface Potion extends ThrowableItemProjectile {

/**
* {@link Keys#POTION_EFFECTS}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@
import java.util.Optional;

/**
* Represents entities that act as projectiles and can fly in the air.
* For example, Arrows.
* Represents an abstract projectile.
*/
public interface Projectile extends Entity {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,32 @@

import org.spongepowered.api.data.Keys;
import org.spongepowered.api.data.value.Value;
import org.spongepowered.api.entity.Entity;
import org.spongepowered.api.entity.living.golem.Shulker;
import org.spongepowered.api.util.Direction;

import java.util.Optional;

/**
* A {@link ShulkerBullet} is the projectile {@link Shulker}s shoot.
*/
public interface ShulkerBullet extends EntityTargetingProjectile, DamagingProjectile {
public interface ShulkerBullet extends Projectile {

/**
* {@link Keys#DIRECTION}
*
* @return The direction of this bullet
*/
default Value.Mutable<Direction> hangingDirection() {
default Value.Mutable<Direction> flyingDirection() {
return this.requireValue(Keys.DIRECTION).asMutable();
}

/**
* {@link Keys#TARGET_ENTITY}
*
* @return The targeted entity, if available
*/
default Optional<Value.Mutable<Entity>> targetEntity() {
return this.getValue(Keys.TARGET_ENTITY).map(Value::asMutable);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@
/**
* Represents a Snowball.
*/
public interface Snowball extends DamagingProjectile {
public interface Snowball extends ThrowableItemProjectile {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* 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.projectile;

import org.spongepowered.api.entity.ItemRepresentable;

public interface ThrowableItemProjectile extends Projectile, ItemRepresentable {
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
/**
* An arrow generally "tipped" with one or more potion effects.
*/
public interface Arrow extends ArrowEntity {
public interface Arrow extends ArrowLike {

/**
* {@link Keys#POTION_EFFECTS}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@
import org.spongepowered.api.data.value.MapValue;
import org.spongepowered.api.data.value.Value;
import org.spongepowered.api.entity.EntityType;
import org.spongepowered.api.entity.projectile.DamagingProjectile;
import org.spongepowered.api.entity.projectile.Projectile;

/**
* Represents an Arrow.
* An abstract representation of an Arrow.
*/
public interface ArrowEntity extends DamagingProjectile {
public interface ArrowLike extends Projectile {

/**
* {@link Keys#PICKUP_RULE}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@
import org.spongepowered.api.effect.potion.PotionEffectTypes;

/**
* An {@link ArrowEntity} which applies the {@link PotionEffectTypes#GLOWING}
* An {@link ArrowLike} which applies the {@link PotionEffectTypes#GLOWING}
* effect on hit.
*/
public interface SpectralArrow extends ArrowEntity {
public interface SpectralArrow extends ArrowLike {

}
Loading

0 comments on commit b4fab13

Please sign in to comment.