Skip to content

Commit 63ace16

Browse files
authored
Abstract targeting to a separate interface (#2557)
* Abstract targeting to a separate interface * Update Agent.java * Update Agent.java
1 parent aaa9d23 commit 63ace16

File tree

3 files changed

+45
-14
lines changed

3 files changed

+45
-14
lines changed

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

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

27-
public interface Interaction extends Entity, Attackable {
27+
public interface Interaction extends Entity, Attackable, Targeting {
2828
// TODO Data
2929
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
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;
26+
27+
import org.spongepowered.api.data.Keys;
28+
import org.spongepowered.api.data.value.Value;
29+
30+
import java.util.Optional;
31+
32+
public interface Targeting extends Entity {
33+
34+
/**
35+
* {@link Keys#TARGET_ENTITY}
36+
*
37+
* @return The targeted entity, if available
38+
*/
39+
default Optional<Value.Mutable<Entity>> targetEntity() {
40+
return this.getValue(Keys.TARGET_ENTITY).map(Value::asMutable);
41+
}
42+
}

src/main/java/org/spongepowered/api/entity/living/Agent.java

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,10 @@
2727
import org.spongepowered.api.data.Keys;
2828
import org.spongepowered.api.data.type.HandPreference;
2929
import org.spongepowered.api.data.value.Value;
30-
import org.spongepowered.api.entity.Entity;
3130
import org.spongepowered.api.entity.Leashable;
31+
import org.spongepowered.api.entity.Targeting;
3232
import org.spongepowered.api.entity.ai.goal.GoalExecutor;
3333
import org.spongepowered.api.entity.ai.goal.GoalExecutorType;
34-
import org.spongepowered.api.entity.ai.goal.builtin.creature.target.TargetGoal;
3534
import org.spongepowered.api.item.inventory.ArmorEquipable;
3635

3736
import java.util.Optional;
@@ -40,17 +39,7 @@
4039
* An Agent represents a {@link Living} that has AI. In the future Sponge will
4140
* allow for custom AIs, but for now vanilla behavior can only be disabled.
4241
*/
43-
public interface Agent extends Living, Leashable, ArmorEquipable {
44-
45-
/**
46-
* {@link Keys#TARGET_ENTITY}
47-
*
48-
* @return The targeted entity
49-
* @see TargetGoal
50-
*/
51-
default Optional<Value.Mutable<Entity>> targetEntity() {
52-
return this.getValue(Keys.TARGET_ENTITY).map(Value::asMutable);
53-
}
42+
public interface Agent extends Living, Leashable, Targeting, ArmorEquipable {
5443

5544
/**
5645
* {@link Keys#IS_AI_ENABLED}

0 commit comments

Comments
 (0)