public async Task TeleportAsync(PositionF pos) { this.LastPosition = this.Position; this.Position = pos; await this.client.Server.World.ResendBaseChunksAsync(this.client); var tid = Globals.Random.Next(0, 999); await client.Server.Events.InvokePlayerTeleportedAsync( new PlayerTeleportEventArgs ( this, this.Position, pos )); await this.client.QueuePacketAsync(new ClientPlayerPositionLook { Position = pos, Flags = PositionFlags.None, TeleportId = tid }); this.TeleportId = tid; }
public void MagnitudeTest() { PositionF p = new PositionF(3, 4); var m = p.Magnitude; Assert.AreEqual(5, m); }
internal virtual async Task UpdateAsync(Server server, PositionF position, bool onGround) { var newPos = position * 32 * 64; var lastPos = this.LastPosition * 32 * 64; short newX = (short)(newPos.X - lastPos.X); short newY = (short)(newPos.Y - lastPos.Y); short newZ = (short)(newPos.Z - lastPos.Z); var isNewLocation = position != this.LastPosition; if (isNewLocation) { server.BroadcastPacketWithoutQueue(new EntityPosition { EntityId = this.EntityId, DeltaX = newX, DeltaY = newY, DeltaZ = newZ, OnGround = onGround }, this.EntityId); this.UpdatePosition(position, onGround); } await Task.CompletedTask; }
public static byte[] ToByteArray(this PositionF p) { byte[] data = new byte[8]; BitConverter.GetBytes(p.X).CopyTo(data, 0); BitConverter.GetBytes(p.Y).CopyTo(data, 4); return(data); }
public async Task TeleportAsync(CommandContext Context, [Remaining] PositionF location) { var player = (Player)Context.Player; await player.SendMessageAsync($"ight homie tryna tp you (and sip dicks) {location.X} {location.Y} {location.Z}"); await player.TeleportAsync(location); }
public void FloatInitTest() { PositionF p1 = new PositionF(3, 4); PositionF p2 = new PositionF(3f, 4f); Assert.AreEqual(p1, p2); }
public void DivisionTest() { PositionF p1 = new PositionF(10, 10); PositionF p2 = new PositionF(1, 1); float v = 10; Assert.AreEqual(p2, p1 / v); }
public void InvertTest() { PositionF p1 = new PositionF(1, 1); PositionF p2 = new PositionF(-1, -1); PositionF p3 = new PositionF(3, 3); Assert.AreEqual(p1, -p2); }
public void MinusTest() { PositionF p1 = new PositionF(1, 1); PositionF p2 = new PositionF(2, 2); PositionF p3 = new PositionF(3, 3); Assert.AreEqual(p1, p3 - p2); }
public void SumTest() { PositionF p1 = new PositionF(1, 1); PositionF p2 = new PositionF(2, 2); PositionF p3 = new PositionF(3, 3); Assert.AreEqual(p3, p1 + p2); }
public void UpdatePosition(PositionF pos, Angle yaw, Angle pitch, bool onGround = true) { this.CopyPosition(true); this.Position = pos; this.Yaw = yaw; this.Pitch = pitch; this.OnGround = onGround; }
public async Task WritePositionFAsync(PositionF value) { var val = (long)((int)value.X & 0x3FFFFFF) << 38; val |= (long)((int)value.Z & 0x3FFFFFF) << 12; val |= (long)((int)value.Y & 0xFFF); await this.WriteLongAsync(val); }
public void NotEqualTest() { PositionF p1 = new PositionF(1, 1); PositionF p2 = new PositionF(1, 1); PositionF p3 = new PositionF(1, 2); Assert.False(p1 != p2); Assert.True(p1 != p3); }
public void MultiplicationTest() { PositionF p1 = new PositionF(10, 10); PositionF p2 = new PositionF(1, 1); float v = 10; Assert.AreEqual(p1, p2 * v); Assert.AreEqual(p1, v * p2); }
public void WritePositionF(PositionF value) { var val = (long)((int)value.X & 0x3FFFFFF) << 38; val |= (long)((int)value.Z & 0x3FFFFFF) << 12; val |= (long)((int)value.Y & 0xFFF); WriteLong(val); }
internal virtual async Task UpdateAsync(Server server, PositionF position, Angle yaw, Angle pitch, bool onGround) { var newPos = position * 32 * 64; var lastPos = this.LastPosition * 32 * 64; short newX = (short)(newPos.X - lastPos.X); short newY = (short)(newPos.Y - lastPos.Y); short newZ = (short)(newPos.Z - lastPos.Z); var isNewLocation = position != this.LastPosition; var isNewRotation = yaw != this.LastYaw || pitch != this.LastPitch; if (isNewLocation) { if (isNewRotation) { server.BroadcastPacketWithoutQueue(new EntityPositionAndRotation { EntityId = this.EntityId, DeltaX = newX, DeltaY = newY, DeltaZ = newZ, Yaw = yaw, Pitch = pitch, OnGround = onGround }, this.EntityId); this.CopyLook(); } else { server.BroadcastPacketWithoutQueue(new EntityPosition { EntityId = this.EntityId, DeltaX = newX, DeltaY = newY, DeltaZ = newZ, OnGround = onGround }, this.EntityId); } this.UpdatePosition(position, yaw, pitch, onGround); } await Task.CompletedTask; }
public void PositionFSerializationTest() { var data = new byte[] { 0, 0, 0, 0, 0, 0, 0, 0 }; PositionF p = new PositionF { X = 0, Y = 0 }; var array = p.ToByteArray(); Assert.AreEqual(data.Length, array.Length); Assert.AreEqual(data, array); }
public void MoveTowardsTest() { PositionF p1 = new PositionF(3, 3); PositionF p2 = new PositionF(4, 4); float maxDistanceDelta = 2; PositionF p3 = PositionF.MoveTowards(p1, p2, maxDistanceDelta); PositionF p4 = PositionF.MoveTowards(p1, p2, 0); PositionF p5 = PositionF.MoveTowards(p2, p2, maxDistanceDelta); Assert.AreEqual(p2, p3); Assert.AreEqual(p1, p4); Assert.AreEqual(p2, p5); }
public void PositionFDeserializationTest() { PositionF p1 = new PositionF { X = 10, Y = 125 }; var array = p1.ToByteArray(); var p2 = new PositionF(); p2 = p2.FromBytes(array); Assert.AreEqual(p1.X, p2.X); Assert.AreEqual(p1.Y, p2.Y); }
public void Update(float deltaTime) { if (Unit.PositionF == _targetPosition && Unit.Position == Unit.TargetPosition) { State = States.Stay; Path = null; } if (State == States.Stay) { return; } Unit.PositionF = PositionF.MoveTowards(Unit.PositionF, _targetPosition, Speed * deltaTime); }
bool Collides(Axis axis, double offsetX = 0, double offsetY = 0) { PositionF position = PositionF + new PositionF(offsetX, offsetY); if (position[axis] < 0 || position[axis] > Level.Size[axis] - Size[axis]) { return(true); } var toRemove = new HashSet <IDisposable>(); bool shouldDie = false; foreach (Entity entity in Level.Entities.Where(entity => entity != this)) { if (position < entity.Position + entity.Size && position + Size > entity.Position) { if (entity is Spike && !(isOnGround && axis == Axis.Vertical)) { shouldDie = true; } else if (entity.IsCollidable) { return(true); } else if (entity is Coin coin) { ++scoreboard.Coins; toRemove.Add(coin); } } } if (shouldDie) { Die(); } foreach (IDisposable entity in toRemove) { entity.Dispose(); } return(false); }
internal override async Task UpdateAsync(Server server, PositionF position, Angle yaw, Angle pitch, bool onGround) { await base.UpdateAsync(server, position, yaw, pitch, onGround); this.HeadY = position.Y + 1.62f; foreach (var entity in this.World.GetEntitiesNear(this.Position, 0.8f)) { if (entity is ItemEntity item) { if (!item.CanPickup) { continue; } server.BroadcastPacketWithoutQueue(new CollectItem { CollectedEntityId = item.EntityId, CollectorEntityId = this.EntityId, PickupItemCount = item.Count }); var slot = this.Inventory.AddItem(new ItemStack(Registry.GetItem(item.Id).Type, item.Count, item.ItemMeta) { Present = true }); this.client.SendPacket(new SetSlot { Slot = (short)slot, WindowId = 0, SlotData = this.Inventory.GetItem(slot) }); await item.RemoveAsync(); } } }
internal void BroadcastPlayerDig(PlayerDiggingStore store) { var digging = store.Packet; var block = this.World.GetBlock(digging.Position); var player = this.OnlinePlayers.GetValueOrDefault(store.Player); switch (digging.Status) { case DiggingStatus.DropItem: { var droppedItem = player.GetHeldItem(); if (droppedItem is null || droppedItem.Type == Material.Air) { return; } var loc = new PositionF(player.Position.X, (float)player.HeadY - 0.3f, player.Position.Z); var item = new ItemEntity { EntityId = player + this.World.TotalLoadedEntities() + 1, Count = 1, Id = droppedItem.GetItem().Id, EntityBitMask = EntityBitMask.Glowing, World = this.World, Position = loc }; this.TryAddEntity(player.World, item); var f8 = Math.Sin(player.Pitch.Degrees * ((float)Math.PI / 180f)); var f2 = Math.Cos(player.Pitch.Degrees * ((float)Math.PI / 180f)); var f3 = Math.Sin(player.Yaw.Degrees * ((float)Math.PI / 180f)); var f4 = Math.Cos(player.Yaw.Degrees * ((float)Math.PI / 180f)); var f5 = Globals.Random.NextDouble() * ((float)Math.PI * 2f); var f6 = 0.02f * Globals.Random.NextDouble(); var vel = new Velocity((short)((double)(-f3 * f2 * 0.3F) + Math.Cos((double)f5) * (double)f6), (short)((double)(-f8 * 0.3F + 0.1F + (Globals.Random.NextDouble() - Globals.Random.NextDouble()) * 0.1F)), (short)((double)(f4 * f2 * 0.3F) + Math.Sin((double)f5) * (double)f6)); this.BroadcastPacketWithoutQueue(new SpawnEntity { EntityId = item.EntityId, Uuid = Guid.NewGuid(), Type = EntityType.Item, Position = item.Position, Pitch = 0, Yaw = 0, Data = 1, Velocity = vel }); this.BroadcastPacketWithoutQueue(new EntityMetadata { EntityId = item.EntityId, Entity = item }); player.client.SendPacket(new SetSlot { Slot = player.CurrentSlot, WindowId = 0, SlotData = player.Inventory.GetItem(player.CurrentSlot) - 1 }); player.Inventory.RemoveItem(player.CurrentSlot); break; } case DiggingStatus.StartedDigging: this.BroadcastPacketWithoutQueue(new AcknowledgePlayerDigging { Position = digging.Position, Block = block.Id, Status = digging.Status, Successful = true }); if (player.Gamemode == Gamemode.Creative) { this.BroadcastPacketWithoutQueue(new BlockChange(digging.Position, 0)); this.World.SetBlock(digging.Position, Block.Air); } break; case DiggingStatus.CancelledDigging: this.BroadcastPacketWithoutQueue(new AcknowledgePlayerDigging { Position = digging.Position, Block = block.Id, Status = digging.Status, Successful = true }); break; case DiggingStatus.FinishedDigging: { this.BroadcastPacketWithoutQueue(new AcknowledgePlayerDigging { Position = digging.Position, Block = block.Id, Status = digging.Status, Successful = true }); this.BroadcastPacketWithoutQueue(new BlockBreakAnimation { EntityId = player, Position = digging.Position, DestroyStage = -1 }); this.BroadcastPacketWithoutQueue(new BlockChange(digging.Position, 0)); this.World.SetBlock(digging.Position, Block.Air); var itemId = Registry.GetItem(block.Material).Id; if (itemId == 0) { break; } var item = new ItemEntity { EntityId = player + this.World.TotalLoadedEntities() + 1, Count = 1, Id = itemId, EntityBitMask = EntityBitMask.Glowing, World = this.World, Position = digging.Position + new PositionF( (Globals.Random.NextSingle() * 0.5f) + 0.25f, (Globals.Random.NextSingle() * 0.5f) + 0.25f, (Globals.Random.NextSingle() * 0.5f) + 0.25f) }; this.TryAddEntity(player.World, item); this.BroadcastPacketWithoutQueue(new SpawnEntity { EntityId = item.EntityId, Uuid = Guid.NewGuid(), Type = EntityType.Item, Position = item.Position, Pitch = 0, Yaw = 0, Data = 1, Velocity = Velocity.FromPosition(digging.Position) }); this.BroadcastPacketWithoutQueue(new EntityMetadata { EntityId = item.EntityId, Entity = item }); break; } } }
public void UpdatePosition(PositionF pos, bool onGround = true) { this.CopyPosition(); this.Position = pos; this.OnGround = onGround; }
public Particle(ParticleType type, PositionF position, int particleCount) { Type = type; Position = position; ParticleCount = particleCount; }
public static PositionF FromBytes(this PositionF p, byte[] data) { p.X = BitConverter.ToSingle(data, 0); p.Y = BitConverter.ToSingle(data, 4); return(p); }
public void WriteAbsolutePositionF(PositionF value) { WriteDouble(value.X); WriteDouble(value.Y); WriteDouble(value.Z); }
public PlayerPosition(PositionF pos, bool onground) { this.Position = pos; this.OnGround = onground; }
public SpawnPosition(PositionF position) { Position = position; }
void Die() { Viewport.Position.X = 0; PositionF = Level.SpawnPosition; isOnGround = true; }