use super::FakePlayerConnection; use graphite_mc_protocol::types::GameProfile; use graphite_server::{ entity::position::{Coordinate, Position, Rotation}, inventory::inventory_handler::VanillaPlayerInventory, player::{player_vec::PlayerVec, PlayerService}, universe::{Universe, UniverseService}, world::{TickPhase, World, WorldService}, }; use std::pin::Pin; pub fn create_game_profile() -> GameProfile { GameProfile { username: "Moulberry".into(), uuid: 0xd0e05de76067454dbeaec6d19d886191, properties: vec![], } } pub fn create_universe_and_player() -> ( Pin>>, Pin>, ) { let mut universe = create_universe(); let player = create_player(&mut universe); (universe, player) } pub fn create_player( universe: &mut Universe, ) -> Pin> { let mut conn = Box::from(FakePlayerConnection::new()); universe.handle_player_connect(conn.as_mut(), create_game_profile()); Pin::from(conn) } pub fn create_universe() -> Pin>> { let service = DummyUniverseService { the_world: World::new_with_default_chunks(DummyWorldService { players: PlayerVec::new(), }, 5, 24, 5), }; let pinned = Box::pin(Universe::create_dummy(service)); DummyUniverseService::initialize(&pinned); pinned } pub struct DummyUniverseService { pub the_world: World, } impl UniverseService for DummyUniverseService { type ConnectionReferenceType = *mut FakePlayerConnection; fn handle_player_join( universe: &mut Universe, proto_player: graphite_server::player::proto_player::ProtoPlayer, ) { universe.service.the_world.handle_player_join(proto_player); } fn initialize(universe: &Universe) { universe.service.the_world.initialize(universe); } fn tick(universe: &mut Universe) { universe.service.the_world.tick(); } fn get_player_count(universe: &Universe) -> usize { DummyWorldService::get_player_count(&universe.service.the_world) } } pub struct DummyWorldService { pub players: PlayerVec, } impl WorldService for DummyWorldService { type UniverseServiceType = DummyUniverseService; const CHUNK_VIEW_DISTANCE: u8 = 8; const ENTITY_VIEW_DISTANCE: u8 = 1; fn handle_player_join( world: &mut World, proto_player: graphite_server::player::proto_player::ProtoPlayer, ) { world .service .players .add( proto_player, DummyPlayerService, Position { coord: Coordinate { x: 40.0, y: 224.0, z: 40.0, }, rot: Rotation::default(), }, ) .unwrap(); } fn initialize(world: &World) { world.service.players.initialize(world); } fn tick(world: &mut World, phase: TickPhase) { world.service.players.tick(phase); } fn get_player_count(world: &World) -> usize { world.service.players.len() } } pub struct DummyPlayerService; impl PlayerService for DummyPlayerService { const FAST_PACKET_RESPONSE: bool = true; type UniverseServiceType = DummyUniverseService; type WorldServiceType = DummyWorldService; type InventoryHandlerType = VanillaPlayerInventory; }