<commit_before>function World(scene) {
    var WS_OPEN = 1;
    var self = this;
    
    var ws = (function () {
        var loc = window.location;
        var uri = loc.protocol === "https:" ? "wss:" : "ws:";
        uri += "//" + loc.host + "/ws";
        return new WebSocket(uri);
    }());
    
    var chunkQueue = [];
    ws.onopen = function () {
        for (var k in chunkQueue) {
            ws.send(JSON.stringify(chunkQueue[k]));
        }
    }
    
    ws.onmessage = function (ev) {
        console.log(ev.data);
        var o = JSON.parse(ev.data);
        var cx = o.CX;
        var cy = o.CY;
        var cz = o.CZ;
        var data = o.Data;
        
        var chunk = chunkAt(cx, cy, cz);
        if (chunk) return;
        
        for (var ox = 0; ox < CHUNK_WIDTH; ox++) {
            for (var oy = 0; oy < CHUNK_HEIGHT; oy++) {
                for (var oz = 0; oz < CHUNK_DEPTH; oz++) {
                    data[ox][oy][oz] = new Block(data[ox][oy][oz]);
                }
            }
        }
        
        chunks[cx + "," + cy + "," + cz] = new Chunk(self, data, cx, cy, cz);
        displayChunk(cx, cy, cz);
        
        var pxc = chunkAt(cx + 1, cy, cz);
        if (pxc) pxc.refresh(scene);
        var nxc = chunkAt(cx - 1, cy, cz);
        if (nxc) nxc.refresh(scene);
        var pyc = chunkAt(cx, cy + 1, cz);
        if (pyc) pyc.refresh(scene);
        var nyc = chunkAt(cx, cy - 1, cz);
        if (nyc) nyc.refresh(scene);
        var pzc = chunkAt(cx, cy, cz + 1);
        if (pzc) pzc.refresh(scene);
        var nzc = chunkAt(cx, cy, cz - 1);
        if (nzc) nzc.refresh(scene);
    }
    
    ws.onerror = function (ev) {
        console.error(ev);
    }
    
    ws.onclose = function (ev) {
        console.error("Someone closed my websocket :(", ev);
    }

    var seed = Math.random() * 100;
    
    var chunks = {};
    
    function chunkAt(cx, cy, cz) {
        var chunk = chunks[cx + "," + cy + "," + cz];
        return chunk;
    }
    
    self.chunkAt = chunkAt;
    
    function loadChunk(cx, cy, cz) {
        var chunk = chunkAt(cx, cy, cz);
        if (chunk) return chunk;
        else queueChunk(cx, cy, cz);
    }
    
    function queueChunk(cx, cy, cz) {
        var obj = {
            cx: cx,
            cy: cy,
            cz: cz,
            seed: seed,
        };
        if (ws.readyState === WS_OPEN) {
            ws.send(JSON.stringify(obj));
        } else {
            chunkQueue[cx + "," + cy + "," + cz] = obj;
        }
    }   
    
    function displayChunk(cx, cy, cz) {
        var chunk = loadChunk(cx, cy, cz);
        if (!chunk) return;
        if (chunk.isDisplayed()) return;
        chunk.addTo(scene);
        return chunk;
    }
    
    function mod(a, b) {
        return (((a % b) + b) % b);
    }
    
    self.getSeed = function () {
        return seed;
    }
    
    self.addSmallCube = function (position) {
        if (!position) throw "Position required!";
        var cube = new THREE.Mesh( new THREE.CubeGeometry(0.1, 0.1, 0.1), new THREE.MeshNormalMaterial() );
        cube.position = position;
        scene.add(cube);
    }
    
    self.blockAt = function (wx, wy, wz) {
        var cords = worldToChunk(wx, wy, wz);
        var o = cords.o;
        var c = cords.c;
        
        var chunk = loadChunk(c.x, c.y, c.z);
        if (!chunk) return null;
        var block = chunk.blockAt(o.x, o.y, o.z);
        if (!block) throw "Could not load blockkk!!!";
        else return block;
    }
    
    self.findClosestGround = function (wx, wy, wz) {
        var cords = worldToChunk(wx, wy, wz);
        var c = cords.c;
        var o = cords.o;
        
        var chunk = loadChunk(c.x, c.y, c.z);
        if (!chunk) {
            return wy;
        }
        var block;
        if (chunk.blockAt(o.x, o.y, o.z).isType(Block.AIR)) {
            // Try and find ground below
            while (true) {
                if (o.y-- < 0) {
                    o.y = CHUNK_HEIGHT;
                    c.y--;
                    chunk = loadChunk(c.x, c.y, c.z);
                    if (!chunk) {
                        return o.y + c.y * CHUNK_HEIGHT;
                    }
                }
                block = chunk.blockAt(o.x, o.y, o.z);
                if (block && block.isType(Block.DIRT)) {
                    return o.y + c.y * CHUNK_HEIGHT;
                }
            }
        } else if (chunk.blockAt(o.x, o.y, o.z).isType(Block.DIRT)) {
            // Try and find air above
            while (true) {
                if (o.y++ >= CHUNK_HEIGHT) {
                    o.y = 0;
                    c.y++;
                    chunk = loadChunk(c.x, c.y, c.z);
                    if (!chunk) {
                        return o.y - 1 + c.y * CHUNK_HEIGHT;
                    }
                }
                block = chunk.blockAt(o.x, o.y, o.z);
                if (block && block.isType(Block.AIR)) {
                    return o.y - 1 + c.y * CHUNK_HEIGHT;
                }
            }
        } else {
            throw "findClosestGround only knows how to deal with ground and air blocks.";
        }
    }
    
    self.findWorldIntersection = function (camera) {
        var vector = new THREE.Vector3(0, 0, 0);
        var projector = new THREE.Projector();<commit_msg>Made player actually 1.6m tall (was previously 0.6m tall)<commit_after>function World(scene) {
    var WS_OPEN = 1;
    var self = this;
    
    var ws = (function () {
        var loc = window.location;
        var uri = loc.protocol === "https:" ? "wss:" : "ws:";
        uri += "//" + loc.host + "/ws";
        return new WebSocket(uri);
    }());
    
    var chunkQueue = [];
    ws.onopen = function () {
        for (var k in chunkQueue) {
            ws.send(JSON.stringify(chunkQueue[k]));
        }
    }
    
    ws.onmessage = function (ev) {
        console.log(ev.data);
        var o = JSON.parse(ev.data);
        var cx = o.CX;
        var cy = o.CY;
        var cz = o.CZ;
        var data = o.Data;
        
        var chunk = chunkAt(cx, cy, cz);
        if (chunk) return;
        
        for (var ox = 0; ox < CHUNK_WIDTH; ox++) {
            for (var oy = 0; oy < CHUNK_HEIGHT; oy++) {
                for (var oz = 0; oz < CHUNK_DEPTH; oz++) {
                    data[ox][oy][oz] = new Block(data[ox][oy][oz]);
                }
            }
        }
        
        chunks[cx + "," + cy + "," + cz] = new Chunk(self, data, cx, cy, cz);
        displayChunk(cx, cy, cz);
        
        var pxc = chunkAt(cx + 1, cy, cz);
        if (pxc) pxc.refresh(scene);
        var nxc = chunkAt(cx - 1, cy, cz);
        if (nxc) nxc.refresh(scene);
        var pyc = chunkAt(cx, cy + 1, cz);
        if (pyc) pyc.refresh(scene);
        var nyc = chunkAt(cx, cy - 1, cz);
        if (nyc) nyc.refresh(scene);
        var pzc = chunkAt(cx, cy, cz + 1);
        if (pzc) pzc.refresh(scene);
        var nzc = chunkAt(cx, cy, cz - 1);
        if (nzc) nzc.refresh(scene);
    }
    
    ws.onerror = function (ev) {
        console.error(ev);
    }
    
    ws.onclose = function (ev) {
        console.error("Someone closed my websocket :(", ev);
    }

    var seed = Math.random() * 100;
    
    var chunks = {};
    
    function chunkAt(cx, cy, cz) {
        var chunk = chunks[cx + "," + cy + "," + cz];
        return chunk;
    }
    
    self.chunkAt = chunkAt;
    
    function loadChunk(cx, cy, cz) {
        var chunk = chunkAt(cx, cy, cz);
        if (chunk) return chunk;
        else queueChunk(cx, cy, cz);
    }
    
    function queueChunk(cx, cy, cz) {
        var obj = {
            cx: cx,
            cy: cy,
            cz: cz,
            seed: seed,
        };
        if (ws.readyState === WS_OPEN) {
            ws.send(JSON.stringify(obj));
        } else {
            chunkQueue[cx + "," + cy + "," + cz] = obj;
        }
    }   
    
    function displayChunk(cx, cy, cz) {
        var chunk = loadChunk(cx, cy, cz);
        if (!chunk) return;
        if (chunk.isDisplayed()) return;
        chunk.addTo(scene);
        return chunk;
    }
    
    function mod(a, b) {
        return (((a % b) + b) % b);
    }
    
    self.getSeed = function () {
        return seed;
    }
    
    self.addSmallCube = function (position) {
        if (!position) throw "Position required!";
        var cube = new THREE.Mesh( new THREE.CubeGeometry(0.1, 0.1, 0.1), new THREE.MeshNormalMaterial() );
        cube.position = position;
        scene.add(cube);
    }
    
    self.blockAt = function (wx, wy, wz) {
        var cords = worldToChunk(wx, wy, wz);
        var o = cords.o;
        var c = cords.c;
        
        var chunk = loadChunk(c.x, c.y, c.z);
        if (!chunk) return null;
        var block = chunk.blockAt(o.x, o.y, o.z);
        if (!block) throw "Could not load blockkk!!!";
        else return block;
    }
    
    self.findClosestGround = function (wx, wy, wz) {
        var cords = worldToChunk(wx, wy, wz);
        var c = cords.c;
        var o = cords.o;
        
        var chunk = loadChunk(c.x, c.y, c.z);
        if (!chunk) {
            return wy;
        }
        var block;
        if (chunk.blockAt(o.x, o.y, o.z).isType(Block.AIR)) {
            // Try and find ground below
            while (true) {
                if (o.y-- < 0) {
                    o.y = CHUNK_HEIGHT;
                    c.y--;
                    chunk = loadChunk(c.x, c.y, c.z);
                    if (!chunk) {
                        return o.y + 1 + c.y * CHUNK_HEIGHT;
                    }
                }
                block = chunk.blockAt(o.x, o.y, o.z);
                if (block && block.isType(Block.DIRT)) {
                    return o.y + 1 + c.y * CHUNK_HEIGHT;
                }
            }
        } else if (chunk.blockAt(o.x, o.y, o.z).isType(Block.DIRT)) {
            // Try and find air above
            while (true) {
                if (o.y++ >= CHUNK_HEIGHT) {
                    o.y = 0;
                    c.y++;
                    chunk = loadChunk(c.x, c.y, c.z);
                    if (!chunk) {
                        return o.y + c.y * CHUNK_HEIGHT;
                    }
                }
                block = chunk.blockAt(o.x, o.y, o.z);
                if (block && block.isType(Block.AIR)) {
                    return o.y + c.y * CHUNK_HEIGHT;
                }
            }
        } else {
            throw "findClosestGround only knows how to deal with ground and air blocks.";
        }
    }
    
    self.findWorldIntersection = function (camera) {
        var vector = new THREE.Vector3(0, 0, 0);
        var projector = new THREE.Projector();
{'fraction_non_alphanumeric': 0.14186915887850468, 'fraction_numerical': 0.005420560747663551, 'mean_word_length': 1.2860499893185218, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 5, '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': '5487695', 'n_tokens_mistral': 3672, 'n_tokens_neox': 3529, 'n_words': 901}