BlockEntityLiftTimeComponent.cs 1.2 KB

12345678910111213141516171819202122232425262728293031323334
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using System.Threading.Tasks;
  5. using MineCase.Engine;
  6. using MineCase.Server.Components;
  7. namespace MineCase.Server.Game.BlockEntities.Components
  8. {
  9. internal class BlockEntityLiftTimeComponent : Component<BlockEntityGrain>, IHandle<SpawnBlockEntity>, IHandle<DestroyBlockEntity>
  10. {
  11. public BlockEntityLiftTimeComponent(string name = "blockEntityLifeTime")
  12. : base(name)
  13. {
  14. }
  15. async Task IHandle<SpawnBlockEntity>.Handle(SpawnBlockEntity message)
  16. {
  17. await AttachedObject.GetComponent<WorldComponent>().SetWorld(message.World);
  18. await AttachedObject.GetComponent<BlockWorldPositionComponent>().SetBlockWorldPosition(message.Position);
  19. AttachedObject.QueueOperation(async () =>
  20. {
  21. await AttachedObject.Tell(Enable.Default);
  22. if (AttachedObject.ValueStorage.IsDirty)
  23. await AttachedObject.WriteStateAsync();
  24. });
  25. }
  26. Task IHandle<DestroyBlockEntity>.Handle(DestroyBlockEntity message)
  27. {
  28. return AttachedObject.Tell(Disable.Default);
  29. }
  30. }
  31. }