Skip to content

Commit 763547e

Browse files
committed
Merge Vanish API updates into API 9
2 parents 848c702 + d5b9710 commit 763547e

File tree

5 files changed

+301
-3
lines changed

5 files changed

+301
-3
lines changed

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

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@
9595
import org.spongepowered.api.data.value.SetValue;
9696
import org.spongepowered.api.data.value.Value;
9797
import org.spongepowered.api.data.value.WeightedCollectionValue;
98+
import org.spongepowered.api.effect.VanishState;
9899
import org.spongepowered.api.effect.particle.ParticleEffect;
99100
import org.spongepowered.api.effect.particle.ParticleOption;
100101
import org.spongepowered.api.effect.particle.ParticleType;
@@ -1413,7 +1414,7 @@ public final class Keys {
14131414
* Whether an {@link Entity} is currently invisible.
14141415
* This will only simply render the entity as vanished,
14151416
* but not prevent any entity updates being sent to clients.
1416-
* To fully "vanish" an {@link Entity}, use {@link #VANISH}.
1417+
* To fully "vanish" an {@link Entity}, use {@link #VANISH_STATE}.
14171418
*/
14181419
public static final Key<Value<Boolean>> IS_INVISIBLE = Keys.key(ResourceKey.sponge("is_invisible"), Boolean.class);
14191420

@@ -2672,6 +2673,19 @@ public final class Keys {
26722673
*/
26732674
public static final Key<Value<Boolean>> UPDATE_GAME_PROFILE = Keys.key(ResourceKey.sponge("update_game_profile"), Boolean.class);
26742675

2676+
/**
2677+
* The {@link VanishState} of an {@link Entity}.
2678+
*
2679+
* <p>The presence of a vanished entity will not be made known to a client;
2680+
* no packets pertaining to this entity are sent. Client-side, this entity
2681+
* will cease to exist. Server-side it may still be targeted by hostile
2682+
* entities or collide with other entities.</p>
2683+
*
2684+
* <p>Vanishing an {@link Entity} ridden by other entities (see
2685+
* {@link #PASSENGERS} will cause problems.</p>
2686+
*/
2687+
public static final Key<Value<VanishState>> VANISH_STATE = Keys.key(ResourceKey.sponge("vanish"), VanishState.class);
2688+
26752689
/**
26762690
* Whether an {@link Entity} is vanished.
26772691
*
@@ -2682,15 +2696,19 @@ public final class Keys {
26822696
*
26832697
* <p>Vanishing an {@link Entity} ridden by other entities (see
26842698
* {@link #PASSENGERS} will cause problems.</p>
2699+
* @deprecated use {@link #VANISH_STATE}
26852700
*/
2701+
@Deprecated
26862702
public static final Key<Value<Boolean>> VANISH = Keys.key(ResourceKey.sponge("vanish"), Boolean.class);
26872703

26882704
/**
26892705
* Whether an {@link Entity} ignores collision with other entities.
26902706
*
26912707
* <p>This state will be ignored if the {@link Entity} is not also
26922708
* vanished as per {@link #VANISH}.</p>
2709+
* @deprecated use {@link #VANISH_STATE}
26932710
*/
2711+
@Deprecated
26942712
public static final Key<Value<Boolean>> VANISH_IGNORES_COLLISION = Keys.key(ResourceKey.sponge("vanish_ignores_collision"), Boolean.class);
26952713

26962714
/**
@@ -2700,7 +2718,9 @@ public final class Keys {
27002718
*
27012719
* <p>This state will be ignored if the {@link Entity} is not also
27022720
* vanished as per {@link #VANISH}.}.</p>
2721+
* @deprecated use {@link #VANISH_STATE}
27032722
*/
2723+
@Deprecated
27042724
public static final Key<Value<Boolean>> VANISH_PREVENTS_TARGETING = Keys.key(ResourceKey.sponge("vanish_prevents_targeting"), Boolean.class);
27052725

27062726
/**
Lines changed: 252 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,252 @@
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.effect;
26+
27+
import org.spongepowered.api.Sponge;
28+
import org.spongepowered.api.entity.Entity;
29+
30+
/**
31+
* Represents the state of an {@link Entity}'s vanish state.
32+
* Accessible through {@link org.spongepowered.api.data.Keys#VANISH_STATE}
33+
*/
34+
public interface VanishState {
35+
36+
/**
37+
* Gets a vanished state via {@link Factory#vanish()} with the following
38+
* defaults:
39+
* <ul>
40+
* <li>{@link VanishState#invisible()} = {@code true}</li>
41+
* <li>{@link VanishState#affectsMonsterSpawning()} = {@code false}</li>
42+
* <li>{@link VanishState#untargetable()} = {@code true}</li>
43+
* <li>{@link VanishState#createsSounds()} = {@code false}</li>
44+
* <li>{@link VanishState#createsParticles()} = {@code false}</li>
45+
* <li>{@link VanishState#triggerVibrations()} = {@code false}</li>
46+
* </ul>
47+
*
48+
* @return A vanished state with the provided defaults
49+
*/
50+
static VanishState vanished() {
51+
return Sponge.game().factoryProvider().provide(VanishState.Factory.class).vanished();
52+
}
53+
54+
/**
55+
* A {@link VanishState} that is invisible with the following defaults:
56+
* <ul>
57+
* <li>{@link VanishState#invisible()} = {@code false}</li>
58+
* <li>{@link VanishState#affectsMonsterSpawning()} = {@code true}</li>
59+
* <li>{@link VanishState#untargetable()} = {@code false}</li>
60+
* <li>{@link VanishState#createsSounds()} = {@code true}</li>
61+
* <li>{@link VanishState#createsParticles()} = {@code true}</li>
62+
* <li>{@link VanishState#triggerVibrations()} = {@code false}</li>
63+
* </ul>
64+
*
65+
* @return A visible state with the provided defaults
66+
*/
67+
static VanishState unvanished() {
68+
return Sponge.game().factoryProvider().provide(VanishState.Factory.class).unvanished();
69+
}
70+
71+
/**
72+
* Gets whether the state is visible. If an {@link Entity} is visible, then
73+
* other aspects of this state will be ignored, such as
74+
* {@link #ignoresCollisions()}, {@link #untargetable()}, etc.
75+
*
76+
* @return Whether the {@link Entity} is visible
77+
*/
78+
boolean invisible();
79+
80+
/**
81+
* Gets a vanished {@link VanishState state} with {@link #ignoresCollisions()}
82+
* and {@link #untargetable()} set to {@code true}. If the state is already
83+
* {@link #invisible()}, then the same state is returned.
84+
*
85+
* @return The vanished state
86+
*/
87+
VanishState vanish();
88+
89+
/**
90+
* Gets a visible state {@link VanishState} with {@link #ignoresCollisions()}
91+
* and {@link #untargetable()} set to {@code false}. If the state is already
92+
* {@link #invisible()} being {@code false}, then the same state is returned.
93+
*
94+
* @return The visible state
95+
*/
96+
VanishState unvanish();
97+
98+
/**
99+
* Gets if the {@link Entity} will ignore collisions. In cases where
100+
* {@link #invisible()} is {@code false}, this will return {@code false}.
101+
*
102+
* @return Whether collisions will be ignored
103+
*/
104+
boolean ignoresCollisions();
105+
106+
/**
107+
* If {@link #invisible()} returns true, this will return the
108+
* {@link VanishState} with the desired flag of
109+
* {@link #ignoresCollisions()}.
110+
*
111+
* @param ignoresCollisions Whether collisions will be ignored
112+
* @return The new VanishState, the value changed
113+
*/
114+
VanishState ignoreCollisions(boolean ignoresCollisions);
115+
116+
/**
117+
* Gets if the {@link Entity} will be untargetable by entity ai. In cases
118+
* where {@link #invisible()} is {@code false}, this will return
119+
* {@code false}.
120+
*
121+
* @return Whether the {@link Entity} will be untargetable
122+
*/
123+
boolean untargetable();
124+
125+
/**
126+
* If {@link #invisible()} returns true, this will return the
127+
* {@link VanishState} with the desired flag of
128+
* {@link #ignoresCollisions()}.
129+
*
130+
* @param untargetable Whether the entity can be targeted by AI
131+
* @return The new VanishState, the value changed
132+
*/
133+
VanishState untargetable(boolean untargetable);
134+
135+
/**
136+
* Gets if {@link #affectsMonsterSpawning()} returns {@code false}, the
137+
* vanished {@link Entity} will not spawn monsters or affect near by monster
138+
* spawners.
139+
* <p>Note that this flag works in conjunction with
140+
* {@link org.spongepowered.api.data.Keys#AFFECTS_SPAWNING} such that either
141+
* one being {@code false} will disable spawning.</p>
142+
*
143+
* @return Whether the {@link Entity} will affect monster spawning
144+
*/
145+
boolean affectsMonsterSpawning();
146+
147+
/**
148+
* If {@link #invisible()} returns true, this will return the
149+
* {@link VanishState} with the desired flag.
150+
* <p>Note that this flag works in conjunction with
151+
* {@link org.spongepowered.api.data.Keys#AFFECTS_SPAWNING} such that either
152+
* one being false will disable spawning.</p>
153+
*
154+
* @param affectsMonsterSpawning Whether the {@link Entity} will affect
155+
* monster spawning
156+
* @return The new VanishState
157+
*/
158+
VanishState affectMonsterSpawning(boolean affectsMonsterSpawning);
159+
160+
/**
161+
* Gets if the {@link Entity} will produce sounds from various actions that
162+
* occur while {@link #invisible()} is {@code true}.
163+
*
164+
* @return Whether the {@link Entity} will produce sounds while invisible
165+
*/
166+
boolean createsSounds();
167+
168+
/**
169+
* If {@link #invisible()} returns true, this will return the
170+
* {@link VanishState} with the desired flag of
171+
* {@link #createsSounds()}.
172+
*
173+
* @param createSounds Whether the {@link Entity} will produce sounds
174+
* @return The new VanishState
175+
*/
176+
VanishState createSounds(boolean createSounds);
177+
178+
/**
179+
* Gets if the {@link Entity} will produce particles from various actions
180+
* that occur while {@link #invisible()} is {@code true}.
181+
*
182+
* @return Whether the {@link Entity} will produce particles while invisible
183+
*/
184+
boolean createsParticles();
185+
186+
/**
187+
* If {@link #invisible()} returns true, this will return the
188+
* {@link VanishState} with the desired flag of
189+
* {@link #createsParticles()}.
190+
*
191+
* @param createParticles Whether the {@link Entity} will produce particles
192+
* @return The new VanishState
193+
*/
194+
VanishState createParticles(boolean createParticles);
195+
196+
/**
197+
* Gets if the {@link Entity} will trigger vibrations
198+
* from various actions while vanished. These vibrations
199+
* are generally measured/reacted by
200+
* {@link org.spongepowered.api.block.entity.SculkSensor SculkSensors}
201+
* and potentially create particles.
202+
*
203+
* @return Whether the {@link Entity} will trigger vibrations
204+
* while invisible
205+
*/
206+
boolean triggerVibrations();
207+
208+
/**
209+
* If {@link #invisible()} returns true, this will return the
210+
* {@link VanishState} with the desired flag replacing
211+
* {@link #triggerVibrations()}.
212+
*
213+
* @param triggerVibrations Whether the {@link Entity} will trigger
214+
* vibrations while invisible
215+
* @return The new VanishState
216+
*/
217+
VanishState triggerVibrations(boolean triggerVibrations);
218+
219+
interface Factory {
220+
221+
/**
222+
* Creates a {@link VanishState} that is invisible with the following
223+
* defaults:
224+
* <ul>
225+
* <li>{@link VanishState#invisible()} = {@code true}</li>
226+
* <li>{@link VanishState#affectsMonsterSpawning()} = {@code false}</li>
227+
* <li>{@link VanishState#untargetable()} = {@code true}</li>
228+
* <li>{@link VanishState#createsSounds()} = {@code false}</li>
229+
* <li>{@link VanishState#createsParticles()} = {@code false}</li>
230+
* <li>{@link VanishState#triggerVibrations()} = {@code false}</li>
231+
* </ul>
232+
*
233+
* @return A newly created invisible {@link VanishState}
234+
*/
235+
VanishState vanished();
236+
237+
/**
238+
* A {@link VanishState} that is visible with the following defaults:
239+
* <ul>
240+
* <li>{@link VanishState#invisible()} = {@code false}</li>
241+
* <li>{@link VanishState#affectsMonsterSpawning()} = {@code true}</li>
242+
* <li>{@link VanishState#untargetable()} = {@code false}</li>
243+
* <li>{@link VanishState#createsSounds()} = {@code true}</li>
244+
* <li>{@link VanishState#createsParticles()} = {@code true}</li>
245+
* <li>{@link VanishState#triggerVibrations()} = {@code false}</li>
246+
* </ul>
247+
*
248+
* @return A newly created visible {@link VanishState}
249+
*/
250+
VanishState unvanished();
251+
}
252+
}

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

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import org.spongepowered.api.data.value.ListValue;
3434
import org.spongepowered.api.data.value.SetValue;
3535
import org.spongepowered.api.data.value.Value;
36+
import org.spongepowered.api.effect.VanishState;
3637
import org.spongepowered.api.event.cause.entity.damage.source.DamageSource;
3738
import org.spongepowered.api.projectile.source.EntityProjectileSource;
3839
import org.spongepowered.api.util.AABB;
@@ -75,6 +76,7 @@
7576
*
7677
* <p>Blocks and items (when they are in inventories) are not entities.</p>
7778
*/
79+
@SuppressWarnings("deprecation")
7880
@DoNotStore
7981
public interface Entity extends Identifiable, HoverEventSource<HoverEvent.ShowEntity>, Locatable, EntityProjectileSource, Sound.Emitter,
8082
SerializableDataHolder.Mutable, RandomProvider {
@@ -325,8 +327,8 @@ default Collection<? extends Entity> nearbyEntities(final double distance, final
325327
*/
326328
default boolean canSee(final Entity entity) {
327329
Objects.requireNonNull(entity, "Entity cannot be null");
328-
final Optional<Boolean> optional = entity.get(Keys.VANISH);
329-
return !optional.isPresent() || !optional.get();
330+
final Optional<VanishState> optional = entity.get(Keys.VANISH_STATE);
331+
return !optional.map(VanishState::invisible).orElse(false);
330332
}
331333

332334
/**
@@ -606,10 +608,20 @@ default SetValue.Mutable<String> scoreboardTags() {
606608
return this.requireValue(Keys.SCOREBOARD_TAGS).asMutable();
607609
}
608610

611+
/**
612+
* {@link Keys#VANISH_STATE}
613+
*
614+
* @return The current vanish state of the entity
615+
*/
616+
default Value.Mutable<VanishState> vanishState() {
617+
return this.requireValue(Keys.VANISH_STATE).asMutable();
618+
}
619+
609620
/**
610621
* {@link Keys#VANISH}
611622
*
612623
* @return Whether the entity is vanished
624+
* @deprecated Use {@link #vanishState() VanishState} instead
613625
*/
614626
default Value.Mutable<Boolean> vanish() {
615627
return this.requireValue(Keys.VANISH).asMutable();
@@ -619,6 +631,7 @@ default Value.Mutable<Boolean> vanish() {
619631
* {@link Keys#VANISH_IGNORES_COLLISION}
620632
*
621633
* @return Whether the entity ignores collision with other entities
634+
* @deprecated Use {@link #vanishState()} instead
622635
*/
623636
default Value.Mutable<Boolean> vanishIgnoresCollision() {
624637
return this.requireValue(Keys.VANISH_IGNORES_COLLISION).asMutable();
@@ -628,6 +641,7 @@ default Value.Mutable<Boolean> vanishIgnoresCollision() {
628641
* {@link Keys#VANISH_PREVENTS_TARGETING}
629642
*
630643
* @return Whether the entity can be targeted for attack by another entity
644+
* @deprecated Use {@link #vanishState()} instead
631645
*/
632646
default Value.Mutable<Boolean> vanishPreventsTargeting() {
633647
return this.requireValue(Keys.VANISH_PREVENTS_TARGETING).asMutable();

0 commit comments

Comments
 (0)