mirror of https://github.com/Minestom/Minestom.git
Initial Witness interface
Signed-off-by: TheMode <themode@outlook.fr>
This commit is contained in:
parent
549a9a9b52
commit
68e5e21964
|
@ -0,0 +1,64 @@
|
||||||
|
package net.minestom.server;
|
||||||
|
|
||||||
|
import net.minestom.server.entity.Entity;
|
||||||
|
import net.minestom.server.entity.Player;
|
||||||
|
import org.jetbrains.annotations.ApiStatus;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
import java.util.function.Predicate;
|
||||||
|
|
||||||
|
public interface Witness extends Viewable {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets if this entity is automatically sent to surrounding players.
|
||||||
|
* True by default.
|
||||||
|
*
|
||||||
|
* @return true if the entity is automatically viewable for close players, false otherwise
|
||||||
|
*/
|
||||||
|
boolean isAutoViewable();
|
||||||
|
|
||||||
|
void setAutoViewable(boolean autoViewable);
|
||||||
|
|
||||||
|
void updateViewableRule(@NotNull Predicate<Player> predicate);
|
||||||
|
|
||||||
|
@ApiStatus.Experimental
|
||||||
|
void updateViewableRule();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets if surrounding entities are automatically visible by this.
|
||||||
|
* True by default.
|
||||||
|
*
|
||||||
|
* @return true if surrounding entities are visible by this
|
||||||
|
*/
|
||||||
|
@ApiStatus.Experimental
|
||||||
|
boolean autoViewEntities();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Decides if surrounding entities must be visible.
|
||||||
|
*
|
||||||
|
* @param autoViewer true to add view surrounding entities, false to remove
|
||||||
|
*/
|
||||||
|
@ApiStatus.Experimental
|
||||||
|
void setAutoViewEntities(boolean autoViewer);
|
||||||
|
|
||||||
|
@ApiStatus.Experimental
|
||||||
|
void updateViewerRule(@NotNull Predicate<Entity> predicate);
|
||||||
|
|
||||||
|
@ApiStatus.Experimental
|
||||||
|
void updateViewerRule();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets if this entity's viewers (surrounding players) can be predicted from surrounding chunks.
|
||||||
|
*/
|
||||||
|
boolean hasPredictableViewers();
|
||||||
|
|
||||||
|
@ApiStatus.Internal
|
||||||
|
default void updateNewViewer(@NotNull Player player) {
|
||||||
|
// Empty
|
||||||
|
}
|
||||||
|
|
||||||
|
@ApiStatus.Internal
|
||||||
|
default void updateOldViewer(@NotNull Player player) {
|
||||||
|
// Empty
|
||||||
|
}
|
||||||
|
}
|
|
@ -7,7 +7,7 @@ import net.kyori.adventure.text.event.HoverEvent.ShowEntity;
|
||||||
import net.kyori.adventure.text.event.HoverEventSource;
|
import net.kyori.adventure.text.event.HoverEventSource;
|
||||||
import net.minestom.server.MinecraftServer;
|
import net.minestom.server.MinecraftServer;
|
||||||
import net.minestom.server.Tickable;
|
import net.minestom.server.Tickable;
|
||||||
import net.minestom.server.Viewable;
|
import net.minestom.server.Witness;
|
||||||
import net.minestom.server.acquirable.Acquirable;
|
import net.minestom.server.acquirable.Acquirable;
|
||||||
import net.minestom.server.collision.BoundingBox;
|
import net.minestom.server.collision.BoundingBox;
|
||||||
import net.minestom.server.collision.CollisionUtils;
|
import net.minestom.server.collision.CollisionUtils;
|
||||||
|
@ -67,7 +67,7 @@ import java.util.function.UnaryOperator;
|
||||||
* <p>
|
* <p>
|
||||||
* To create your own entity you probably want to extends {@link LivingEntity} or {@link EntityCreature} instead.
|
* To create your own entity you probably want to extends {@link LivingEntity} or {@link EntityCreature} instead.
|
||||||
*/
|
*/
|
||||||
public class Entity implements Viewable, Tickable, TagHandler, PermissionHandler, HoverEventSource<ShowEntity>, Sound.Emitter {
|
public class Entity implements Witness, Tickable, TagHandler, PermissionHandler, HoverEventSource<ShowEntity>, Sound.Emitter {
|
||||||
|
|
||||||
private static final Map<Integer, Entity> ENTITY_BY_ID = new ConcurrentHashMap<>();
|
private static final Map<Integer, Entity> ENTITY_BY_ID = new ConcurrentHashMap<>();
|
||||||
private static final Map<UUID, Entity> ENTITY_BY_UUID = new ConcurrentHashMap<>();
|
private static final Map<UUID, Entity> ENTITY_BY_UUID = new ConcurrentHashMap<>();
|
||||||
|
@ -343,63 +343,42 @@ public class Entity implements Viewable, Tickable, TagHandler, PermissionHandler
|
||||||
lookAt(entity.position);
|
lookAt(entity.position);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
@Override
|
||||||
* Gets if this entity is automatically sent to surrounding players.
|
|
||||||
* True by default.
|
|
||||||
*
|
|
||||||
* @return true if the entity is automatically viewable for close players, false otherwise
|
|
||||||
*/
|
|
||||||
public boolean isAutoViewable() {
|
public boolean isAutoViewable() {
|
||||||
return viewEngine.viewableOption.isAuto();
|
return viewEngine.viewableOption.isAuto();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
@Override
|
||||||
* Decides if this entity should be auto-viewable by nearby players.
|
|
||||||
*
|
|
||||||
* @param autoViewable true to add surrounding players, false to remove
|
|
||||||
* @see #isAutoViewable()
|
|
||||||
*/
|
|
||||||
public void setAutoViewable(boolean autoViewable) {
|
public void setAutoViewable(boolean autoViewable) {
|
||||||
this.viewEngine.viewableOption.updateAuto(autoViewable);
|
this.viewEngine.viewableOption.updateAuto(autoViewable);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ApiStatus.Experimental
|
@Override
|
||||||
public void updateViewableRule(@NotNull Predicate<Player> predicate) {
|
public void updateViewableRule(@NotNull Predicate<Player> predicate) {
|
||||||
this.viewEngine.viewableOption.updateRule(predicate);
|
this.viewEngine.viewableOption.updateRule(predicate);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ApiStatus.Experimental
|
@Override
|
||||||
public void updateViewableRule() {
|
public void updateViewableRule() {
|
||||||
this.viewEngine.viewableOption.updateRule();
|
this.viewEngine.viewableOption.updateRule();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
@Override
|
||||||
* Gets if surrounding entities are automatically visible by this.
|
|
||||||
* True by default.
|
|
||||||
*
|
|
||||||
* @return true if surrounding entities are visible by this
|
|
||||||
*/
|
|
||||||
@ApiStatus.Experimental
|
|
||||||
public boolean autoViewEntities() {
|
public boolean autoViewEntities() {
|
||||||
return viewEngine.viewerOption.isAuto();
|
return viewEngine.viewerOption.isAuto();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
@Override
|
||||||
* Decides if surrounding entities must be visible.
|
|
||||||
*
|
|
||||||
* @param autoViewer true to add view surrounding entities, false to remove
|
|
||||||
*/
|
|
||||||
@ApiStatus.Experimental
|
|
||||||
public void setAutoViewEntities(boolean autoViewer) {
|
public void setAutoViewEntities(boolean autoViewer) {
|
||||||
this.viewEngine.viewerOption.updateAuto(autoViewer);
|
this.viewEngine.viewerOption.updateAuto(autoViewer);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ApiStatus.Experimental
|
@Override
|
||||||
public void updateViewerRule(@NotNull Predicate<Entity> predicate) {
|
public void updateViewerRule(@NotNull Predicate<Entity> predicate) {
|
||||||
this.viewEngine.viewerOption.updateRule(predicate);
|
this.viewEngine.viewerOption.updateRule(predicate);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ApiStatus.Experimental
|
@Override
|
||||||
public void updateViewerRule() {
|
public void updateViewerRule() {
|
||||||
this.viewEngine.viewerOption.updateRule();
|
this.viewEngine.viewerOption.updateRule();
|
||||||
}
|
}
|
||||||
|
@ -418,13 +397,7 @@ public class Entity implements Viewable, Tickable, TagHandler, PermissionHandler
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
@Override
|
||||||
* Called when a new viewer must be shown.
|
|
||||||
* Method can be subject to deadlocking if the target's viewers are also accessed.
|
|
||||||
*
|
|
||||||
* @param player the player to send the packets to
|
|
||||||
*/
|
|
||||||
@ApiStatus.Internal
|
|
||||||
public void updateNewViewer(@NotNull Player player) {
|
public void updateNewViewer(@NotNull Player player) {
|
||||||
player.sendPacket(getEntityType().registry().spawnType().getSpawnPacket(this));
|
player.sendPacket(getEntityType().registry().spawnType().getSpawnPacket(this));
|
||||||
if (hasVelocity()) player.sendPacket(getVelocityPacket());
|
if (hasVelocity()) player.sendPacket(getVelocityPacket());
|
||||||
|
@ -441,13 +414,7 @@ public class Entity implements Viewable, Tickable, TagHandler, PermissionHandler
|
||||||
player.sendPacket(new EntityHeadLookPacket(getEntityId(), position.yaw()));
|
player.sendPacket(new EntityHeadLookPacket(getEntityId(), position.yaw()));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
@Override
|
||||||
* Called when a viewer must be destroyed.
|
|
||||||
* Method can be subject to deadlocking if the target's viewers are also accessed.
|
|
||||||
*
|
|
||||||
* @param player the player to send the packets to
|
|
||||||
*/
|
|
||||||
@ApiStatus.Internal
|
|
||||||
public void updateOldViewer(@NotNull Player player) {
|
public void updateOldViewer(@NotNull Player player) {
|
||||||
final Set<Entity> passengers = this.passengers;
|
final Set<Entity> passengers = this.passengers;
|
||||||
if (!passengers.isEmpty()) {
|
if (!passengers.isEmpty()) {
|
||||||
|
@ -463,9 +430,7 @@ public class Entity implements Viewable, Tickable, TagHandler, PermissionHandler
|
||||||
return viewers;
|
return viewers;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
@Override
|
||||||
* Gets if this entity's viewers (surrounding players) can be predicted from surrounding chunks.
|
|
||||||
*/
|
|
||||||
public boolean hasPredictableViewers() {
|
public boolean hasPredictableViewers() {
|
||||||
return viewEngine.hasPredictableViewers();
|
return viewEngine.hasPredictableViewers();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue