@@ -492,32 +492,91 @@ namespace tsom
492492
493493 return ;
494494 }
495- else if (message == " /spawnplatform " )
495+ else if (message == " /spawntree " && m_player-> HasPermission (PlayerPermission::Admin) )
496496 {
497- // entt::handle playerEntity = m_player->GetControlledEntity();
498- // if (playerEntity)
499- // {
500- // PlanetComponent* playerPlanet = playerEntity.try_get<PlanetComponent>();
501- // if (playerPlanet)
502- // {
503- // const BlockLibrary& blockLibrary = m_player->GetServerInstance().GetBlockLibrary();
504- //
505- // Nz::Vector3f playerPos = playerEntity.get<Nz::NodeComponent>().GetGlobalPosition();
506- // ChunkIndices chunkIndices = playerPlanet->GetChunkIndicesByPosition(playerPos);
507- // if (Chunk* chunk = playerPlanet->GetChunk(chunkIndices))
508- // {
509- // std::optional<Nz::Vector3ui> coords = chunk->ComputeCoordinates(playerPos);
510- // if (coords)
511- // {
512- // Direction dir = DirectionFromNormal(playerPlanet->ComputeUpDirection(playerPos));
513- // BlockIndices blockIndices = playerPlanet->GetBlockIndices(chunkIndices, *coords);
514- // playerPlanet->GeneratePlatform(blockLibrary, dir, blockIndices);
515- //
516- // fmt::print("generated platform at {};{};{}\n", blockIndices.x, blockIndices.y, blockIndices.z);
517- // }
518- // }
519- // }
520- // }
497+ entt::handle playerEntity = m_player->GetControlledEntityReference ();
498+ if (!playerEntity)
499+ return ;
500+
501+ ServerInstance& serverInstance = m_player->GetServerInstance ();
502+
503+ ServerEnvironment* currentEnvironment = ServerEnvironment::GetEnvironment (playerEntity);
504+
505+ std::shared_ptr<const EntityClass> treeClass = serverInstance.GetEntityRegistry ().FindClass (" tree" );
506+ if (!treeClass)
507+ return ;
508+
509+ const auto & characterController = m_player->GetCharacterController ();
510+ Nz::Quaternionf cameraRot = characterController->GetCameraRotation ();
511+
512+ Nz::Vector3f hitPos, hitNormal;
513+ entt::handle hitEntity;
514+ std::uint32_t hitSubshapeID;
515+ auto callback = [&](const Nz::Physics3DSystem::RaycastHit& hitInfo)
516+ {
517+ hitPos = hitInfo.hitPosition ;
518+ hitNormal = hitInfo.hitNormal ;
519+ hitEntity = hitInfo.hitEntity ;
520+ hitSubshapeID = hitInfo.subShapeID ;
521+ };
522+
523+ struct IgnorePlayer : Nz::PhysObjectLayerFilter3D
524+ {
525+ bool ShouldCollide (Nz::PhysObjectLayer3D layer) const override
526+ {
527+ return layer != Constants::ObjectLayerPlayer;
528+ }
529+ };
530+ IgnorePlayer objectFilter;
531+
532+ auto & playerNode = playerEntity.get <Nz::NodeComponent>();
533+
534+ Nz::Vector3f cameraPos = characterController->GetEyePosition ();
535+
536+ auto & physSystem = currentEnvironment->GetWorld ().GetSystem <Nz::Physics3DSystem>();
537+ if (physSystem.RaycastQueryFirst (cameraPos, cameraPos + cameraRot * Nz::Vector3f::Forward () * 10 .f , callback, nullptr , &objectFilter))
538+ {
539+ entt::handle entity = currentEnvironment->CreateEntity ();
540+ entity.emplace <Nz::NodeComponent>(hitPos, Nz::Quaternionf::RotationBetween (Nz::Vector3f::Up (), hitNormal));
541+ entity.emplace <NetworkedComponent>();
542+ entity.emplace <DatabaseComponent>();
543+
544+ auto & treeInstance = entity.emplace <ClassInstanceComponent>(treeClass);
545+ treeInstance.UpdateProperty <EntityPropertyType::Float>(" scale" , (float ) std::rand () / RAND_MAX + 0 .5f );
546+
547+ treeClass->InitAndActivateEntity (entity);
548+ }
549+
550+ return ;
551+ }
552+ else if (message == " /spawnplatform" && m_player->HasPermission (PlayerPermission::Admin))
553+ {
554+ /*
555+ entt::handle playerEntity = m_player->GetControlledEntity();
556+ if (playerEntity)
557+ {
558+ PlanetComponent* playerPlanet = playerEntity.try_get<PlanetComponent>();
559+ if (playerPlanet)
560+ {
561+ const BlockLibrary& blockLibrary = m_player->GetServerInstance().GetBlockLibrary();
562+
563+ Nz::Vector3f playerPos = playerEntity.get<Nz::NodeComponent>().GetGlobalPosition();
564+ ChunkIndices chunkIndices = playerPlanet->GetChunkIndicesByPosition(playerPos);
565+ if (Chunk* chunk = playerPlanet->GetChunk(chunkIndices))
566+ {
567+ std::optional<Nz::Vector3ui> coords = chunk->ComputeCoordinates(playerPos);
568+ if (coords)
569+ {
570+ Direction dir = DirectionFromNormal(playerPlanet->ComputeUpDirection(playerPos));
571+ BlockIndices blockIndices = playerPlanet->GetBlockIndices(chunkIndices, *coords);
572+ playerPlanet->GeneratePlatform(blockLibrary, dir, blockIndices);
573+
574+ fmt::print("generated platform at {};{};{}\n", blockIndices.x, blockIndices.y, blockIndices.z);
575+ }
576+ }
577+ }
578+ }
579+ */
521580 return ;
522581 }
523582 else if (message == " /spawnplanet" && m_player->HasPermission (PlayerPermission::Admin))
0 commit comments