private void ScheduleLightingUpdate(BlockCoordinates coordinates, bool blockLight = false) { var chunkCoords = new ChunkCoordinates(coordinates.X >> 4, coordinates.Z >> 4); ChunkColumn chunk; if (ChunkManager.TryGetChunk(chunkCoords, out chunk)) { var cx = coordinates.X & 0xf; var cy = coordinates.Y & 0xff; var cz = coordinates.Z & 0xf; if (blockLight) { chunk.ScheduleBlocklightUpdate(cx, cy, cz); } else { chunk.ScheduleSkylightUpdate(cx, cy, cz); } } }
public void SetBlock(Block block) { var x = block.Coordinates.X; var y = block.Coordinates.Y; var z = block.Coordinates.Z; var chunkCoords = new ChunkCoordinates(x >> 4, z >> 4); IChunkColumn chunk; if (ChunkManager.TryGetChunk(chunkCoords, out chunk)) { var cx = x & 0xf; var cy = y & 0xff; var cz = z & 0xf; chunk.SetBlock(cx, cy, cz, block); ChunkManager.ScheduleChunkUpdate(new ChunkCoordinates(x >> 4, z >> 4), ScheduleType.Scheduled | ScheduleType.Lighting, true); UpdateNeighbors(x, y, z); CheckForUpdate(chunkCoords, cx, cz); } }
public void SetBlockLight(BlockCoordinates coordinates, byte value) { var chunkCoords = new ChunkCoordinates(coordinates); ChunkColumn chunk; if (ChunkManager.TryGetChunk(chunkCoords, out chunk)) { if (chunk.SetBlocklight(coordinates.X & 0xf, coordinates.Y & 0xff, coordinates.Z & 0xf, value)) { var x = coordinates.X; var y = coordinates.Y; var z = coordinates.Z; ScheduleLightingUpdate(new BlockCoordinates(x + 1, y, z), true); ScheduleLightingUpdate(new BlockCoordinates(x + -1, y, z), true); ScheduleLightingUpdate(new BlockCoordinates(x, y, z + 1), true); ScheduleLightingUpdate(new BlockCoordinates(x, y, z + -1), true); ScheduleLightingUpdate(new BlockCoordinates(x, y + 1, z), true); ScheduleLightingUpdate(new BlockCoordinates(x, y + -1, z), true); } } }
public void SetSkyLight(BlockCoordinates coordinates, byte p1) { var chunkCoords = new ChunkCoordinates(coordinates); ChunkColumn chunk; if (ChunkManager.TryGetChunk(chunkCoords, out chunk)) { if (chunk.SetSkyLight(coordinates.X & 0xf, coordinates.Y & 0xff, coordinates.Z & 0xf, p1)) { var x = coordinates.X; var y = coordinates.Y; var z = coordinates.Z; ScheduleLightingUpdate(new BlockCoordinates(x + 1, y, z)); ScheduleLightingUpdate(new BlockCoordinates(x - 1, y, z)); ScheduleLightingUpdate(new BlockCoordinates(x, y, z + 1)); ScheduleLightingUpdate(new BlockCoordinates(x, y, z - 1)); ScheduleLightingUpdate(new BlockCoordinates(x, y + 1, z)); ScheduleLightingUpdate(new BlockCoordinates(x, y - 1, z)); } } }
public void ChunkUpdate(IChunkColumn chunkColumn, ScheduleType type = ScheduleType.Lighting) { ChunkManager.ScheduleChunkUpdate(new ChunkCoordinates(chunkColumn.X, chunkColumn.Z), type); }
public BlockCoordinates FindBlockPosition(BlockCoordinates coords, out IChunkColumn chunk) { ChunkManager.TryGetChunk(new ChunkCoordinates(coords.X >> 4, coords.Z >> 4), out chunk); return(new BlockCoordinates(coords.X & 0xf, coords.Y & 0xff, coords.Z & 0xf)); }
public void RebuildChunks() { ChunkManager.RebuildAll(); }
public void ResetChunks() { ChunkManager.ClearChunks(); }
public World(IServiceProvider serviceProvider, GraphicsDevice graphics, AlexOptions options, Camera camera, INetworkProvider networkProvider) { Graphics = graphics; Camera = camera; Options = options; PhysicsEngine = new PhysicsManager(this); ChunkManager = new ChunkManager(serviceProvider, graphics, this); EntityManager = new EntityManager(graphics, this, networkProvider); Ticker = new TickManager(); PlayerList = new PlayerList(); ChunkManager.Start(); var settings = serviceProvider.GetRequiredService <IOptionsProvider>(); var profileService = serviceProvider.GetRequiredService <IPlayerProfileService>(); var resources = serviceProvider.GetRequiredService <ResourceManager>(); EventDispatcher = serviceProvider.GetRequiredService <IEventDispatcher>(); string username = string.Empty; Skin skin = profileService?.CurrentProfile?.Skin; if (skin == null) { resources.ResourcePack.TryGetBitmap("entity/alex", out var rawTexture); var t = TextureUtils.BitmapToTexture2D(graphics, rawTexture); skin = new Skin() { Texture = t, Slim = true }; } if (!string.IsNullOrWhiteSpace(profileService?.CurrentProfile?.Username)) { username = profileService.CurrentProfile.Username; } Player = new Player(graphics, serviceProvider.GetRequiredService <Alex>().InputManager, username, this, skin, networkProvider, PlayerIndex.One, camera); Player.KnownPosition = new PlayerLocation(GetSpawnPoint()); Camera.MoveTo(Player.KnownPosition, Vector3.Zero); Options.FieldOfVision.ValueChanged += FieldOfVisionOnValueChanged; Camera.FOV = Options.FieldOfVision.Value; PhysicsEngine.AddTickable(Player); if (networkProvider is BedrockClient) { Player.SetInventory(new BedrockInventory(46)); } // Player.Inventory.IsPeInventory = true; /*if (ItemFactory.TryGetItem("minecraft:diamond_sword", out var sword)) * { * Player.Inventory[Player.Inventory.SelectedSlot] = sword; * Player.Inventory.MainHand = sword; * } * else * { * Log.Warn($"Could not get diamond sword!"); * }*/ EventDispatcher.RegisterEvents(this); FormManager = new BedrockFormManager(networkProvider, serviceProvider.GetRequiredService <GuiManager>(), serviceProvider.GetService <Alex>().InputManager); SkyRenderer = new SkyBox(serviceProvider, graphics, this); //SkyLightCalculations = new SkyLightCalculations(); UseDepthMap = options.VideoOptions.Depthmap; options.VideoOptions.Depthmap.Bind((old, newValue) => { UseDepthMap = newValue; }); ServerType = (networkProvider is BedrockClient) ? ServerType.Bedrock : ServerType.Java; }
public void UnloadChunk(ChunkCoordinates coordinates) { ChunkManager.RemoveChunk(coordinates); EntityManager.UnloadEntities(coordinates); }
public void ClearChunksAndEntities() { EntityManager.ClearEntities(); ChunkManager.ClearChunks(); }
public World(IServiceProvider serviceProvider, GraphicsDevice graphics, AlexOptions options, NetworkProvider networkProvider) { Graphics = graphics; Options = options; PhysicsEngine = new PhysicsManager(this); ChunkManager = new ChunkManager(serviceProvider, graphics, this); EntityManager = new EntityManager(graphics, this, networkProvider); Ticker = new TickManager(); PlayerList = new PlayerList(); Ticker.RegisterTicked(this); Ticker.RegisterTicked(EntityManager); //Ticker.RegisterTicked(PhysicsEngine); Ticker.RegisterTicked(ChunkManager); ChunkManager.Start(); var profileService = serviceProvider.GetRequiredService <IPlayerProfileService>(); var resources = serviceProvider.GetRequiredService <ResourceManager>(); EventDispatcher = serviceProvider.GetRequiredService <IEventDispatcher>(); string username = string.Empty; PooledTexture2D texture; if (Alex.PlayerTexture != null) { texture = TextureUtils.BitmapToTexture2D(graphics, Alex.PlayerTexture); } else { resources.ResourcePack.TryGetBitmap("entity/alex", out var rawTexture); texture = TextureUtils.BitmapToTexture2D(graphics, rawTexture); } Skin skin = profileService?.CurrentProfile?.Skin; if (skin == null) { skin = new Skin() { Texture = texture, Slim = true }; } if (!string.IsNullOrWhiteSpace(profileService?.CurrentProfile?.Username)) { username = profileService.CurrentProfile.Username; } Player = new Player(graphics, serviceProvider.GetRequiredService <Alex>().InputManager, username, this, skin, networkProvider, PlayerIndex.One); Camera = new EntityCamera(Player); if (Alex.PlayerModel != null) { EntityModelRenderer modelRenderer = new EntityModelRenderer(Alex.PlayerModel, texture); if (modelRenderer.Valid) { Player.ModelRenderer = modelRenderer; } } Player.KnownPosition = new PlayerLocation(GetSpawnPoint()); Options.FieldOfVision.ValueChanged += FieldOfVisionOnValueChanged; Camera.FOV = Options.FieldOfVision.Value; PhysicsEngine.AddTickable(Player); EventDispatcher.RegisterEvents(this); var guiManager = serviceProvider.GetRequiredService <GuiManager>(); InventoryManager = new InventoryManager(guiManager); SkyRenderer = new SkyBox(serviceProvider, graphics, this); options.VideoOptions.RenderDistance.Bind( (old, newValue) => { Camera.SetRenderDistance(newValue); }); Camera.SetRenderDistance(options.VideoOptions.RenderDistance); }
public SkyLightBlockAccess(ChunkManager worldProvider, ChunkColumn chunk) : this(worldProvider, -1) { _chunk = chunk; _coord = new ChunkCoordinates(chunk.X, chunk.Z); }
public SkyLightBlockAccess(ChunkManager worldProvider, int heightForUnloadedChunk = 255) { _worldProvider = worldProvider; _heightForUnloadedChunk = heightForUnloadedChunk; }