Skip to content

Commit

Permalink
Refactor tameable entities
Browse files Browse the repository at this point in the history
- Abstract Ownable entities in a separate interface
- Make TraderLlama extend Llama
- Make Camel Sittable
- Rename Keys.Tamer to Keys.OWNER
  • Loading branch information
ImMorpheus committed Jun 29, 2024
1 parent ab88627 commit f0b529b
Show file tree
Hide file tree
Showing 12 changed files with 48 additions and 62 deletions.
12 changes: 6 additions & 6 deletions src/main/java/org/spongepowered/api/data/Keys.java
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@
import org.spongepowered.api.entity.ExperienceOrb;
import org.spongepowered.api.entity.FallingBlock;
import org.spongepowered.api.entity.Item;
import org.spongepowered.api.entity.Ownable;
import org.spongepowered.api.entity.ai.goal.GoalExecutorTypes;
import org.spongepowered.api.entity.display.BillboardType;
import org.spongepowered.api.entity.display.DisplayEntity;
Expand Down Expand Up @@ -153,7 +154,6 @@
import org.spongepowered.api.entity.living.animal.Wolf;
import org.spongepowered.api.entity.living.animal.cow.Mooshroom;
import org.spongepowered.api.entity.living.animal.horse.Horse;
import org.spongepowered.api.entity.living.animal.horse.HorseLike;
import org.spongepowered.api.entity.living.animal.horse.PackHorse;
import org.spongepowered.api.entity.living.animal.horse.llama.Llama;
import org.spongepowered.api.entity.living.animal.horse.llama.TraderLlama;
Expand Down Expand Up @@ -2472,6 +2472,11 @@ public final class Keys {
*/
public static final Key<Value<Orientation>> ORIENTATION = Keys.key(ResourceKey.sponge("orientation"), Orientation.class);

/**
* The owner of a {@link Ownable}.
*/
public static final Key<Value<UUID>> OWNER = Keys.key(ResourceKey.sponge("owner"), UUID.class);

/**
* The content of a {@link ItemTypes#WRITTEN_BOOK} {@link ItemStack}.
*
Expand Down Expand Up @@ -3120,11 +3125,6 @@ public final class Keys {
*/
public static final Key<Value<Double>> SWIFTNESS = Keys.key(ResourceKey.sponge("swiftness"), Double.class);

/**
* The tamer of a {@link TameableAnimal} or {@link HorseLike}.
*/
public static final Key<Value<UUID>> TAMER = Keys.key(ResourceKey.sponge("tamer"), UUID.class);

/**
* The targeted entity either by an {@link Agent} and it's
* {@link GoalExecutorTypes#TARGET} selector or by a {@link FishingBobber} or {@link ShulkerBullet}.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,34 +22,25 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package org.spongepowered.api.entity.living.animal.horse;
package org.spongepowered.api.entity;

import org.spongepowered.api.data.Keys;
import org.spongepowered.api.data.value.Value;
import org.spongepowered.api.entity.living.animal.TameableAnimal;

import java.util.Optional;
import java.util.UUID;

public interface TameableHorse extends HorseLike, TameableAnimal {

/**
* {@link Keys#TAMER}
*
* @return The tamer of the horse
*/
@Override
default Optional<Value.Mutable<UUID>> tamer() {
return this.getValue(Keys.TAMER).map(Value::asMutable);
}
/**
* Represents an {@link Entity} which can be owned.
*/
public interface Ownable extends Entity {

/**
* {@link Keys#IS_TAMED}
* {@link Keys#OWNER}
*
* @return Whether the horse is currently tamed
* @return The owner of the entity
*/
@Override
default Value.Mutable<Boolean> tamed() {
return this.requireValue(Keys.IS_TAMED).asMutable();
default Optional<Value.Mutable<UUID>> owner() {
return this.getValue(Keys.OWNER).map(Value::asMutable);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ default Value.Mutable<Boolean> purring() {
* {@link Keys#IS_BEGGING_FOR_FOOD}
*
* <p>In vanilla, a cat begs for food every so many ticks
* if {@link TameableAnimal#tamer()} returns {@link Optional#isPresent()}.</p>
* if {@link TameableAnimal#owner()} returns {@link Optional#isPresent()}.</p>
*
* @return Whether this cat is purring
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,9 @@

import org.spongepowered.api.data.Keys;
import org.spongepowered.api.data.value.Value;
import org.spongepowered.api.entity.Ownable;

import java.util.Optional;
import java.util.UUID;

public interface TameableAnimal extends Animal, Sittable {

/**
* {@link Keys#TAMER}
*
* @return The tamer of the animal
*/
default Optional<Value.Mutable<UUID>> tamer() {
return this.getValue(Keys.TAMER).map(Value::asMutable);
}
public interface TameableAnimal extends Animal, Ownable, Sittable {

/**
* {@link Keys#IS_TAMED}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@
*/
package org.spongepowered.api.entity.living.animal.horse;

public interface Camel extends HorseLike {
import org.spongepowered.api.entity.living.animal.Sittable;

/**
* Represents a Camel.
*/
public interface Camel extends HorseLike, Sittable {

}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
*/
package org.spongepowered.api.entity.living.animal.horse;

public interface Donkey extends TameableHorse, PackHorse {
/**
* Represents a Donkey.
*/
public interface Donkey extends PackHorse {

}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
/**
* Represents a Horse.
*/
public interface Horse extends TameableHorse {
public interface Horse extends HorseLike {

/**
* {@link Keys#HORSE_COLOR}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,25 +26,15 @@

import org.spongepowered.api.data.Keys;
import org.spongepowered.api.data.value.Value;
import org.spongepowered.api.entity.Ownable;
import org.spongepowered.api.entity.living.animal.Animal;
import org.spongepowered.api.item.inventory.Carrier;

import java.util.Optional;
import java.util.UUID;

/**
* An abstract representation of a Horse.
*/
public interface HorseLike extends Animal, Carrier {

/**
* {@link Keys#IS_SADDLED}
*
* @return Whether the horse is saddled
*/
default Value.Mutable<Boolean> saddled() {
return this.requireValue(Keys.IS_SADDLED).asMutable();
}
public interface HorseLike extends Animal, Ownable, Carrier {

/**
* {@link Keys#IS_TAMED}
Expand All @@ -56,12 +46,12 @@ default Value.Mutable<Boolean> tamed() {
}

/**
* {@link Keys#TAMER}
* {@link Keys#IS_SADDLED}
*
* @return The tamer of the horse
* @return Whether the horse is saddled
*/
default Optional<Value.Mutable<UUID>> tamer() {
return this.getValue(Keys.TAMER).map(Value::asMutable);
default Value.Mutable<Boolean> saddled() {
return this.requireValue(Keys.IS_SADDLED).asMutable();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
*/
package org.spongepowered.api.entity.living.animal.horse;

public interface Mule extends TameableHorse, PackHorse {
/**
* Represents a Mule.
*/
public interface Mule extends PackHorse {

}
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,15 @@
import org.spongepowered.api.data.Keys;
import org.spongepowered.api.data.value.Value;

/**
* Represents an {@link HorseLike} which can have a chest.
*/
public interface PackHorse extends HorseLike {

/**
* {@link Keys#HAS_CHEST}
*
* @return Whether the horse is has a chest or not
* @return Whether the horse has a chest or not
*/
default Value.Mutable<Boolean> hasChest() {
return this.requireValue(Keys.HAS_CHEST).asMutable();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,13 @@
import org.spongepowered.api.data.type.LlamaType;
import org.spongepowered.api.data.value.Value;
import org.spongepowered.api.entity.living.animal.horse.PackHorse;
import org.spongepowered.api.entity.living.animal.horse.TameableHorse;

/**
* Represents a Llama. Llamas are unique in that
* they can be ridden by players, but not controlled by players. Likewise, they
* have colors and styles and can have storage "strength".
*/
public interface Llama extends LlamaLike, TameableHorse, PackHorse {
public interface Llama extends LlamaLike, PackHorse {

/**
* {@link Keys#LLAMA_TYPE}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@
import org.spongepowered.api.data.value.Value;
import org.spongepowered.api.util.Ticks;

public interface TraderLlama extends LlamaLike {
/**
* Represents a TraderLlama.
*/
public interface TraderLlama extends Llama {

/**
* {@link Keys#DESPAWN_DELAY}
Expand Down

0 comments on commit f0b529b

Please sign in to comment.