Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add features specific to Shulkers, ShulkerBullets and ShulkerBoxes. #1903

Merged
merged 4 commits into from
Mar 16, 2019
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,35 @@
*/
package org.spongepowered.api.block.tileentity.carrier;

import org.spongepowered.api.data.key.Keys;
import org.spongepowered.api.data.manipulator.mutable.DyeableData;
import org.spongepowered.api.data.type.DyeColor;
import org.spongepowered.api.data.value.mutable.Value;

/**
* Represents a ShulkerBox. ShulkerBoxes are specific in that when they are
* mined, they drop themselves with the contents added in themselves, so placing
* them back as items will result in a restored inventory.
*/
public interface ShulkerBox extends TileEntityCarrier {

/**
* Gets a copy of the {@link DyeableData} representing the color of this
* {@link ShulkerBox}.
*
* @return A copy of the dye data
*/
default DyeableData getDyeData() {
return get(DyeableData.class).get();
}

/**
* Gets the current {@link Value} of {@link DyeColor} for this
* {@link ShulkerBox}.
*
* @return The current value of dye color for this shulker box
*/
default Value<DyeColor> color() {
return getValue(Keys.DYE_COLOR).get();
}
}
10 changes: 9 additions & 1 deletion src/main/java/org/spongepowered/api/data/key/Keys.java
Original file line number Diff line number Diff line change
Expand Up @@ -609,7 +609,7 @@ public final class Keys {

/**
* Represents the {@link Key} for representing the {@link Direction}
* of a {@link BlockState}.
* of a {@link BlockState} or an {@link Entity}.
*
* @see DirectionalData#direction()
*/
Expand Down Expand Up @@ -2097,6 +2097,14 @@ public final class Keys {
*/
public static final Key<OptionalValue<UUID>> TAMED_OWNER = DummyObjectProvider.createExtendedFor(Key.class,"TAMED_OWNER");

/**
* Represents the {@link Key} for a targeted entity,
* like by a {@link ShulkerBullet}.
*
* @see TargetedEntityData#value
*/
public static final Key<Value<Entity>> TARGETED_ENTITY = DummyObjectProvider.createExtendedFor(Key.class,"TARGETED_ENTITY");
ImMorpheus marked this conversation as resolved.
Show resolved Hide resolved

/**
* Represents the {@link Key} for the location targeted by an
* {@link EyeOfEnder} or a {@link Player}'s compass.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import org.spongepowered.api.entity.ExperienceOrb;
import org.spongepowered.api.entity.FallingBlock;
import org.spongepowered.api.entity.Item;
import org.spongepowered.api.entity.ShulkerBullet;
import org.spongepowered.api.entity.explosive.Explosive;
import org.spongepowered.api.entity.hanging.ItemFrame;
import org.spongepowered.api.entity.hanging.Painting;
Expand Down Expand Up @@ -273,6 +274,11 @@ public final class CatalogEntityData {
* {@link Entity}. Usually applicable to {@link Living} entities.
*/
public static final Class<LeashData> LEASH_DATA = LeashData.class;
/**
* Represents the target entity an entity is either guided or aiming
* towards. Usually applicable for {@link ShulkerBullet}s.
*/
public static final Class<TargetedEntityData> TARGETED_ENTITY_DATA = TargetedEntityData.class;
/**
* Represents the target location an entity is either guided or aiming
* towards. Usually applicable for {@link EyeOfEnder}s.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* 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.data.manipulator.immutable.entity;

import org.spongepowered.api.data.manipulator.ImmutableDataManipulator;
import org.spongepowered.api.data.manipulator.mutable.entity.TargetedEntityData;
import org.spongepowered.api.data.value.immutable.ImmutableValue;
import org.spongepowered.api.entity.Entity;

public interface ImmutableTargetedEntityData extends ImmutableDataManipulator<ImmutableTargetedEntityData, TargetedEntityData> {

/**
* Gets the {@link ImmutableValue} for the targeted {@link Entity}.
*
* @return The immutable value for the targeted entity
*/
ImmutableValue<Entity> value();
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,14 @@
import org.spongepowered.api.data.manipulator.DataManipulator;
import org.spongepowered.api.data.manipulator.immutable.block.ImmutableDirectionalData;
import org.spongepowered.api.data.value.mutable.Value;
import org.spongepowered.api.entity.Entity;
import org.spongepowered.api.entity.EntityTypes;
import org.spongepowered.api.util.Direction;

/**
* An {@link DataManipulator} for the {@link Direction} state of a
* {@link BlockState}. Usually applicable for {@link BlockTypes#STANDING_SIGN},
* {@link BlockTypes#WALL_SIGN}, {@link BlockTypes#WOODEN_DOOR}, etc.
* A {@link DataManipulator} for the {@link Direction} state of a
* {@link BlockState} or an {@link Entity}. Usually applicable for {@link BlockTypes#STANDING_SIGN},
* {@link BlockTypes#WALL_SIGN}, {@link BlockTypes#WOODEN_DOOR}, {@link EntityTypes#SHULKER}, etc.
*/
public interface DirectionalData extends DataManipulator<DirectionalData, ImmutableDirectionalData> {

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* 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.data.manipulator.mutable.entity;

import org.spongepowered.api.data.key.Keys;
import org.spongepowered.api.data.manipulator.DataManipulator;
import org.spongepowered.api.data.manipulator.immutable.entity.ImmutableTargetedEntityData;
import org.spongepowered.api.data.value.mutable.Value;
import org.spongepowered.api.entity.Entity;
import org.spongepowered.api.entity.ShulkerBullet;

/**
* A {@link DataManipulator} handling a targeted {@link Entity}.
*
* <p>For a {@link ShulkerBullet} this will be entity the bullet will try to reach.</p>
*/
public interface TargetedEntityData extends DataManipulator<TargetedEntityData, ImmutableTargetedEntityData> {

/**
* Gets the {@link Value} for the targeted {@link Entity}.
*
* @return The value for the targeted entity
* @see Keys#TARGETED_ENTITY
*/
Value<Entity> value();
}
32 changes: 31 additions & 1 deletion src/main/java/org/spongepowered/api/entity/ShulkerBullet.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,36 @@
*/
package org.spongepowered.api.entity;

public interface ShulkerBullet extends Entity {
import org.spongepowered.api.data.key.Keys;
import org.spongepowered.api.data.manipulator.mutable.block.DirectionalData;
import org.spongepowered.api.data.value.mutable.Value;
import org.spongepowered.api.entity.living.golem.Shulker;
import org.spongepowered.api.entity.projectile.DamagingProjectile;
import org.spongepowered.api.entity.projectile.EntityTargetingProjectile;
import org.spongepowered.api.util.Direction;

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

/**
* Gets a copy of the {@link DirectionalData} being used for this
* {@link ShulkerBullet} entity.
*
* @return A copy of the directional data
*/
default DirectionalData getDirectionalData() {
return get(DirectionalData.class).get();
}

/**
* Gets the {@link Value} for the current direction this
* {@link ShulkerBullet} is going to.
*
* @return The current direction value
*/
default Value<Direction> direction() {
return getValue(Keys.DIRECTION).get();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,67 @@
*/
package org.spongepowered.api.entity.living.golem;

public interface Shulker extends Golem {
import org.spongepowered.api.data.key.Keys;
import org.spongepowered.api.data.manipulator.mutable.DyeableData;
import org.spongepowered.api.data.manipulator.mutable.block.DirectionalData;
import org.spongepowered.api.data.type.DyeColor;
import org.spongepowered.api.data.value.mutable.Value;
import org.spongepowered.api.entity.Entity;
import org.spongepowered.api.entity.projectile.EntityTargetingProjectile;
import org.spongepowered.api.entity.projectile.source.ProjectileSource;
import org.spongepowered.api.util.Direction;

import java.util.Optional;

public interface Shulker extends Golem, ProjectileSource {

/**
* Gets a copy of the {@link DyeableData} representing the color of this
* {@link Shulker} entity.
*
* @return A copy of the dye data
*/
default DyeableData getDyeData() {
return get(DyeableData.class).get();
}

/**
* Gets the current {@link Value} of {@link DyeColor} for this
* {@link Shulker}.
*
* @return The current value of dye color for this shulker
*/
default Value<DyeColor> color() {
return getValue(Keys.DYE_COLOR).get();
}

/**
* Gets a copy of the {@link DirectionalData} representing the direction this
* {@link Shulker} is oriented towards.
*
* @return A copy of the directional data
*/
default DirectionalData getDirectionalData() {
return get(DirectionalData.class).get();
}

/**
* Gets the current {@link Value} of {@link Direction} for this {@link Shulker}.
*
* @return The current value of direction for this shulker
*/
default Value<Direction> direction() {
return getValue(Keys.DIRECTION).get();
}

/**
* Launches a new {@link EntityTargetingProjectile} from this {@link Shulker}.
*
* @param projectileClass The class of the projectile to launch
* @param target the target to assign to the launched projectile
* @param <P> The type of {@link EntityTargetingProjectile}
*
* @return the projectile if successfully launched, {@link Optional#empty()} otherwise
*/
<P extends EntityTargetingProjectile> Optional<P> launchWithTarget(Class<P> projectileClass, Entity target);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* 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.data.key.Keys;
import org.spongepowered.api.data.manipulator.mutable.entity.TargetedEntityData;
import org.spongepowered.api.data.value.mutable.Value;
import org.spongepowered.api.entity.Entity;

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

/**
* Gets the targeted entity data for this {@link EntityTargetingProjectile}.
*
* <p>The targeted entity data defines which entity this projectile will target.</p>
*
* @return A copy of the targeted entity data
*/
default TargetedEntityData getTargetData() {
return getOrCreate(TargetedEntityData.class).get();
}

/**
* Gets the entity this projectile will target.
*
* @return The targeted entity
*/
default Value<Entity> target() {
return getValue(Keys.TARGETED_ENTITY).get();
}
}
7 changes: 5 additions & 2 deletions src/main/java/org/spongepowered/api/util/TypeTokens.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@
import org.spongepowered.api.effect.particle.ParticleType;
import org.spongepowered.api.effect.potion.PotionEffect;
import org.spongepowered.api.effect.potion.PotionEffectType;
import org.spongepowered.api.entity.Entity;
import org.spongepowered.api.entity.EntityArchetype;
import org.spongepowered.api.entity.EntitySnapshot;
import org.spongepowered.api.entity.EntityType;
Expand Down Expand Up @@ -254,6 +255,8 @@ public final class TypeTokens {
@Deprecated
public static final TypeToken<OptionalValue<Living>> LAST_ATTACKER_VALUE_TOKEN = new TypeToken<OptionalValue<Living>>() {private static final long serialVersionUID = -1;};

public static final TypeToken<List<? extends DataSerializable>> LIST_DATA_SERIALIZEABLE_TOKEN = new TypeToken<List<? extends DataSerializable>>() {private static final long serialVersionUID = -1;};

public static final TypeToken<List<DyeColor>> LIST_DYE_COLOR_TOKEN = new TypeToken<List<DyeColor>>() {private static final long serialVersionUID = -1;};

public static final TypeToken<ListValue<DyeColor>> LIST_DYE_COLOR_VALUE_TOKEN = new TypeToken<ListValue<DyeColor>>() {private static final long serialVersionUID = -1;};
Expand Down Expand Up @@ -326,6 +329,8 @@ public final class TypeTokens {

public static final TypeToken<OptionalValue<EntitySnapshot>> OPTIONAL_ENTITY_SNAPSHOT_VALUE_TOKEN = new TypeToken<OptionalValue<EntitySnapshot>>() {private static final long serialVersionUID = -1;};

public static final TypeToken<OptionalValue<Entity>> OPTIONAL_ENTITY_VALUE_TOKEN = new TypeToken<OptionalValue<Entity>>() {private static final long serialVersionUID = -1;};

public static final TypeToken<Optional<PotionEffectType>> OPTIONAL_POTION_TOKEN = new TypeToken<Optional<PotionEffectType>>() {private static final long serialVersionUID = -1;};

public static final TypeToken<OptionalValue<PotionEffectType>> OPTIONAL_POTION_VALUE_TOKEN = new TypeToken<OptionalValue<PotionEffectType>>() {private static final long serialVersionUID = -1;};
Expand Down Expand Up @@ -478,8 +483,6 @@ public final class TypeTokens {

public static final TypeToken<Value<WireAttachmentType>> WIRE_ATTACHMENT_TYPE_VALUE_TOKEN = new TypeToken<Value<WireAttachmentType>>() {private static final long serialVersionUID = -1;};

public static final TypeToken<List<? extends DataSerializable>> LIST_DATA_SERIALIZEABLE_TOKEN = new TypeToken<List<? extends DataSerializable>>() {private static final long serialVersionUID = -1;};

// SORTFIELDS:OFF

// Suppress default constructor to ensure non-instantiability.
Expand Down