示例#1
0
        public async Task PlaceBlock(BlockWorldPos location, EntityInteractHand hand, PlayerDiggingFace face, Vector3 cursorPosition)
        {
            if (face != PlayerDiggingFace.Special)
            {
                var world      = AttachedObject.GetWorld();
                var blockState = await world.GetBlockState(GrainFactory, location);

                var blockHandler = BlockHandler.Create((BlockId)blockState.Id);
                if (blockHandler.IsUsable)
                {
                    await blockHandler.UseBy(AttachedObject, GrainFactory, world, location, cursorPosition);
                }
                else
                {
                    var heldItem = await AttachedObject.GetComponent <HeldItemComponent>().GetHeldItem();

                    if (!heldItem.slot.IsEmpty)
                    {
                        var itemHandler = ItemHandler.Create((uint)heldItem.slot.BlockId);
                        if (itemHandler.IsPlaceable)
                        {
                            var inventory = AttachedObject.GetComponent <InventoryComponent>().GetInventoryWindow();
                            await itemHandler.PlaceBy(AttachedObject, GrainFactory, world, location, inventory, heldItem.index, face, cursorPosition);
                        }
                    }
                }
            }
        }
        public Task <IChunkColumn> GetChunk(ChunkWorldPos pos)
        {
            IWorld world          = AttachedObject.GetWorld();
            var    chunkColumnKey = world.MakeAddressByPartitionKey(new ChunkWorldPos(pos.X, pos.Z));

            return(Task.FromResult(GrainFactory.GetGrain <IChunkColumn>(chunkColumnKey)));
        }
示例#3
0
        async Task IHandle <PlayerLoggedIn> .Handle(PlayerLoggedIn message)
        {
            _loaded = false;
            await _chunkLoader.JoinGame(AttachedObject.GetWorld(), AttachedObject);

            _loaded = true;
        }
        public Task <BiomeId> GetBlockBiome(BlockWorldPos pos)
        {
            BlockChunkPos blockChunkPos  = pos.ToBlockChunkPos();
            ChunkWorldPos chunkWorldPos  = pos.ToChunkWorldPos();
            IWorld        world          = AttachedObject.GetWorld();
            var           chunkColumnKey = world.MakeAddressByPartitionKey(new ChunkWorldPos(chunkWorldPos.X, chunkWorldPos.Z));

            return(GrainFactory.GetGrain <IChunkColumn>(chunkColumnKey).GetBlockBiome(
                       blockChunkPos.X,
                       blockChunkPos.Z));
        }
示例#5
0
        private async Task Respawn()
        {
            var generator = AttachedObject.GetComponent <ClientboundPacketComponent>().GetGenerator();

            var teleportComponent = AttachedObject.GetComponent <TeleportComponent>();
            var world             = AttachedObject.GetWorld();
            var spawnPos          = await world.GetSpawnPosition();

            await teleportComponent.Teleport(spawnPos, 0, 0);

            await generator.Respawn(Dimension.Overworld, await world.GetSeed(), new GameMode { ModeClass = GameMode.Class.Survival, IsHardcore = false }, LevelTypes.Default);

            AttachedObject.SetLocalValue(HealthComponent.HealthProperty, AttachedObject.GetValue(HealthComponent.MaxHealthProperty));
            AttachedObject.SetLocalValue(FoodComponent.FoodProperty, AttachedObject.GetValue(FoodComponent.MaxFoodProperty));
            AttachedObject.SetLocalValue(DeathComponent.IsDeathProperty, false);
        }