mirror of
https://github.com/smartcmd/MinecraftConsoles.git
synced 2026-04-25 16:37:21 +00:00
Theres documentation at https://sylvessa.zip/fourkit/ now. And a bunch of other changes. Check the discord server for a more comprehensive list
92 lines
3 KiB
C#
92 lines
3 KiB
C#
namespace Minecraft.Server.FourKit.Entity;
|
|
|
|
/// <summary>
|
|
/// Represents a base entity in the world
|
|
/// </summary>
|
|
public abstract class Entity
|
|
{
|
|
private Location _location = new();
|
|
private Guid _uniqueId = Guid.NewGuid();
|
|
private float _fallDistance;
|
|
private int _dimensionId;
|
|
private int _entityId;
|
|
private EntityType _entityType = EntityType.UNKNOWN;
|
|
|
|
/// <summary>
|
|
/// Gets the entity's current position.
|
|
/// </summary>
|
|
/// <returns>a new copy of <see cref="Location"/> containing the position of this entity</returns>
|
|
public Location getLocation() => _location;
|
|
|
|
/// <summary>
|
|
/// Returns a unique id for this entity
|
|
/// </summary>
|
|
/// <returns>Entity id</returns>
|
|
public virtual int getEntityId() => _entityId;
|
|
|
|
/// <summary>
|
|
/// Get the type of the entity.
|
|
/// </summary>
|
|
/// <returns>The <see cref="EntityType"/> of this entity.</returns>
|
|
public new virtual EntityType getType() => _entityType;
|
|
public new virtual EntityType GetType() => _entityType;
|
|
|
|
/// <summary>
|
|
/// Returns a unique and persistent id for this entity. Note that this is not the standard UUID for players.
|
|
/// </summary>
|
|
/// <returns>A <see cref="Guid"/> unique to this entity.</returns>
|
|
public Guid getUniqueId() => _uniqueId;
|
|
|
|
/// <summary>
|
|
/// Teleports this entity to the given location.
|
|
/// This calls into the native server to perform the actual teleport.
|
|
/// </summary>
|
|
/// <param name="location">The destination location.</param>
|
|
/// <returns><c>true</c> if the teleport was successful.</returns>
|
|
public virtual bool teleport(Location location)
|
|
{
|
|
NativeBridge.TeleportEntity?.Invoke(getEntityId(), _dimensionId, location.getX(), location.getY(), location.getZ());
|
|
SetLocation(location);
|
|
return true;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Sets the fall distance for this entity.
|
|
/// </summary>
|
|
/// <param name="distance">The fall distance value.</param>
|
|
public void setFallDistance(float distance)
|
|
{
|
|
_fallDistance = distance;
|
|
NativeBridge.SetFallDistance?.Invoke(getEntityId(), distance);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Returns the distance this entity has fallen.
|
|
/// </summary>
|
|
/// <returns>The current fall distance.</returns>
|
|
public float getFallDistance() => _fallDistance;
|
|
|
|
/// <summary>
|
|
/// Gets the current world this entity resides in.
|
|
/// </summary>
|
|
/// <returns>World containing this entity.</returns>
|
|
public World getWorld() => FourKit.getWorld(_dimensionId);
|
|
|
|
// INTERNAL
|
|
internal void SetLocation(Location location)
|
|
{
|
|
_location = location;
|
|
}
|
|
|
|
internal void SetFallDistanceInternal(float distance) => _fallDistance = distance;
|
|
|
|
internal void SetUniqueId(Guid id)
|
|
{
|
|
_uniqueId = id;
|
|
}
|
|
|
|
internal void SetDimensionInternal(int dimensionId) => _dimensionId = dimensionId;
|
|
internal void SetEntityIdInternal(int entityId) => _entityId = entityId;
|
|
internal void SetEntityTypeInternal(EntityType entityType) => _entityType = entityType;
|
|
}
|