<commit_before>﻿using System.Collections.Generic;

namespace Adventure
{
	internal class World
	{
		private Dictionary<Position, Chunk> LoadedChunks = new Dictionary<Position, Chunk>();

		public void Update()
		{
			List<Position> unload = new List<Position>();

			//Update loaded chunks
			foreach (KeyValuePair<Position, Chunk> kv in LoadedChunks)
			{
				kv.Value.Update();

				//If timed out add to unload list
				if (kv.Value.Idle > Chunk.Timeout)
				{
					unload.Add(kv.Key);
				}
			}

			//Unload chunks
			foreach (Position p in unload)
			{
				LoadedChunks[p].SaveToFile();
				LoadedChunks.Remove(p);
			}
		}

		public void SetTile(Position pos, Tile tile)
		{
			Position chunkpos = new Position(pos.x / Chunk.Size, pos.y / Chunk.Size, pos.z / Chunk.Size);
			Chunk c = GetChunk(chunkpos);
			c.Idle = 0;
			c.Tiles[pos.x - chunkpos.x, pos.y - chunkpos.y, pos.z - chunkpos.z] = tile;
		}

		public Tile GetTile(Position pos)
		{
			Position chunkpos = new Position(pos.x / Chunk.Size, pos.y / Chunk.Size, pos.z / Chunk.Size);
			Chunk c = GetChunk(chunkpos);
			c.Idle = 0;
			return c.Tiles[pos.x - chunkpos.x, pos.y - chunkpos.y, pos.z - chunkpos.z];<commit_msg>fixed chunk adressing bug<commit_after>﻿using System.Collections.Generic;

namespace Adventure
{
	internal class World
	{
		private Dictionary<Position, Chunk> LoadedChunks = new Dictionary<Position, Chunk>();

		public void Update()
		{
			List<Position> unload = new List<Position>();

			//Update loaded chunks
			foreach (KeyValuePair<Position, Chunk> kv in LoadedChunks)
			{
				kv.Value.Update();

				//If timed out add to unload list
				if (kv.Value.Idle > Chunk.Timeout)
				{
					unload.Add(kv.Key);
				}
			}

			//Unload chunks
			foreach (Position p in unload)
			{
				LoadedChunks[p].SaveToFile();
				LoadedChunks.Remove(p);
			}
		}

		public void SetTile(Position pos, Tile tile)
		{
			Position chunkpos = new Position(pos.x / Chunk.Size, pos.y / Chunk.Size, pos.z / Chunk.Size);
			Chunk c = GetChunk(chunkpos);
			c.Idle = 0;
			c.Tiles[pos.x - (chunkpos.x * Chunk.Size), pos.y - (chunkpos.y * Chunk.Size), pos.z - (chunkpos.z * Chunk.Size)] = tile;
		}

		public Tile GetTile(Position pos)
		{
			Position chunkpos = new Position(pos.x / Chunk.Size, pos.y / Chunk.Size, pos.z / Chunk.Size);
			Chunk c = GetChunk(chunkpos);
			c.Idle = 0;
			return c.Tiles[pos.x - (chunkpos.x * Chunk.Size), pos.y - (chunkpos.y * Chunk.Size), pos.z - (chunkpos.z * Chunk.Size)];
{'fraction_non_alphanumeric': 0.13823767178658045, 'fraction_numerical': 0.0016168148746968471, 'mean_word_length': 2.9161392405063293, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1843448', 'n_tokens_mistral': 1049, 'n_tokens_neox': 890, 'n_words': 214}