From 7eafce2e89b54dc481f610b481d962f61e01a242 Mon Sep 17 00:00:00 2001 From: Romain Beaumont Date: Sat, 24 Oct 2015 01:41:54 +0200 Subject: [PATCH 1/4] trying to fix things --- .gitignore | 2 +- app.js | 37 +++++++++++++++++++------------------ extract_textures.js | 4 ++-- mineflayer-voxel.js | 2 +- package.json | 18 +++++++++++------- 5 files changed, 34 insertions(+), 29 deletions(-) diff --git a/.gitignore b/.gitignore index ea29fd7..7ea0afb 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,4 @@ /node_modules /public/client.js -/public/textures +/public/assets /public/char.png diff --git a/app.js b/app.js index 8ed8621..8efc8e7 100644 --- a/app.js +++ b/app.js @@ -25,18 +25,18 @@ function materialIndex(name) { var mat = { 'air':0, - 'snow':0, - 'rose':0, + // 'snow':0, + /* 'rose':0, 'flower':0, 'sapling':0, 'mushroom':0, - 'tallgrass':0, + 'tallgrass':0,*/ 'stone': 1, 'grass': 2, 'dirt': 3, 'stonebrick': 4, - 'wood': 5, + /* 'wood': 5, 'bedrock': 7, 'sand': 8, 'gravel': 9, @@ -44,9 +44,9 @@ function materialIndex(name) { 'oreIron': 11, 'oreCoal': 12, 'oreLapis': 13, - 'oreDiamond': 14, + 'oreDiamond': 14,*/ 'log': 15, - 'leaves': 16, + //'leaves': 16, // 'glass': 17, // 'tallgrass': 18, // 'flower': 19, @@ -54,7 +54,7 @@ function materialIndex(name) { // 'mushroom': 21, // 'torch': 22, // 'workbench': 22, - 'furnace': 23 + // 'furnace': 23 }[name] return mat !== undefined ? mat : 1; @@ -71,11 +71,12 @@ socket.on('spawn', function(position) { startingPosition: pixelPosition, worldOrigin: pixelPosition, - texturePath: './textures/blocks/', - materials: ['stone', ['grass_top', 'dirt', 'grass_side'], 'dirt', 'stonebrick', 'wood', 'sapling', 'bedrock', 'sand', 'gravel', 'oreGold', 'oreIron', 'oreCoal', 'oreLapis', 'oreDiamond', ['tree_top', 'tree_top', 'tree_side'], 'leaves', 'glass', 'tallgrass', 'flower', 'rose', 'mushroom_brown', 'torch', ['workbench_top', 'workbench_top', 'workbench_side'], ['furnace_top', 'furnace_side', 'furnace_front']], + texturePath: './assets/minecraft/textures/blocks/', + materials: ['stone', ['grass_top', 'dirt', 'grass_side'], 'dirt', 'stonebrick', 'glass'], - mesher: require('./transgreedy').mesher, - }) + mesher: require('./transgreedy').mesher + }); + game.gravity=[0, -0.0000036, 0]; window.game = game; window.createVoxelPlayer = voxelPlayer(game); @@ -85,18 +86,18 @@ socket.on('spawn', function(position) { // Blend top of grass with green color var biomeGreen = new game.THREE.Color(8368696); - game.materials.get('grass_top')[2].color = biomeGreen; + /*game.materials.get('grass_top')[2].color = biomeGreen; game.materials.get('leaves').forEach(function(material) { material.color = biomeGreen; material.ambient = biomeGreen; material.transparent = true; - }) + })*/ highlight(game); game.on('mousedown', function (pos) { console.log(pos, game.getBlock(pos)) }); - game.view.renderer.sortObjects = false; + //game.view.renderer.sortObjects = false; // Unmodifed // {"memory":{"programs":2,"geometries":695,"textures":60}, @@ -106,9 +107,9 @@ socket.on('spawn', function(position) { // {"memory":{"programs":2,"geometries":695,"textures":14}, // "render":{"calls":671,"vertices":238434,"faces":79478,"points":0}} - setTimeout(function onStartupTimeout() { + /* setTimeout(function onStartupTimeout() { console.log(JSON.stringify(game.view.renderer.info)); - }, 1000); + }, 1000);*/ } }) @@ -179,8 +180,8 @@ function createPlayer(entity) { console.log('Creating '+entity.username); - var player = createVoxelPlayer('/skin/'+entity.username+'.png') - // player.possess() + var player = createVoxelPlayer('/skins/'+entity.username+'.png'); + // player.possess setMobPosition(player, entity); return player; } diff --git a/extract_textures.js b/extract_textures.js index c898f6c..f57421a 100644 --- a/extract_textures.js +++ b/extract_textures.js @@ -13,13 +13,13 @@ var filetype = child_process.exec('file '+file, function(error, stdout) { process.exit(1); } - var unzipList = child_process.exec('unzip -l "'+file+'" | grep textures/blocks/quartz', function(error, stdout, stderr) { + var unzipList = child_process.exec('unzip -l "'+file+'" | grep assets/minecraft/textures/blocks/quartz', function(error, stdout, stderr) { if (error) { console.log('Error: No quartz blocks found in archive. Is the minecraft.jar new enough? Try a snapshot.'); process.exit(1); } var home = path.join(path.dirname(process.argv[1]), 'public'); - unzip = child_process.spawn('unzip', [file, 'textures*', '-d', home], { stdio:['ignore', process.stdout, process.stderr] }); + unzip = child_process.spawn('unzip', [file, 'assets/minecraft/textures*', '-d', home], { stdio:['ignore', process.stdout, process.stderr] }); }) }) diff --git a/mineflayer-voxel.js b/mineflayer-voxel.js index 8544022..9f5654d 100644 --- a/mineflayer-voxel.js +++ b/mineflayer-voxel.js @@ -21,7 +21,7 @@ function inject(mineflayer, bot, options) { io.set('log level', 0); if (!options.disableLogging) { - app.use(express.logger('tiny')); + app.use(require("morgan")('tiny')); } // Serve out textures and such diff --git a/package.json b/package.json index fa2b6af..4c672ec 100644 --- a/package.json +++ b/package.json @@ -5,23 +5,27 @@ "main": "mineflayer-voxel.js", "author": "Kent Karlsson ", "license": "BSD", - "repository": - { + "repository": { "type": "git", "url": "http://github.com/vogonistic/mineflayer-voxel.git" }, "keywords": [ - "mineflayer", "bot", "minecraft", "voxel", "voxel.js" + "mineflayer", + "bot", + "minecraft", + "voxel", + "voxel.js" ], "dependencies": { - "vec3": ">= 0.1", + "browserify": ">= 1.17", + "express": ">= 3.0.6", "mineflayer": ">= 0.0.28", "mineflayer-navigate": ">= 0.0.8", + "morgan": "^1.6.1", + "socket.io": ">= 0.9.13", + "vec3": ">= 0.1", "voxel-engine": ">= 0.5", "voxel-highlight": ">= 0.0.1", - "express": ">= 3.0.6", - "socket.io": ">= 0.9.13", - "browserify": ">= 1.17", "voxel-player": "latest" } } From 411af7dbd73f2ed01a910647117c3e816c06105b Mon Sep 17 00:00:00 2001 From: Romain Beaumont Date: Tue, 5 Jan 2016 12:59:12 +0100 Subject: [PATCH 2/4] lock down the dependencies version to keep this working, and add some info about where the jar might be --- README.md | 2 ++ package.json | 18 +++++++++--------- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 87677e6..7a8be97 100644 --- a/README.md +++ b/README.md @@ -15,6 +15,8 @@ You must extract textures from minecraft.jar (Note, must be snapshot, not the cu `node extract_textures.js ` +For example `node extract_textures.js ~/.minecraft/versions/1.8/1.8.jar` + ### Usage `npm start` \ No newline at end of file diff --git a/package.json b/package.json index 4c672ec..5f063b7 100644 --- a/package.json +++ b/package.json @@ -17,15 +17,15 @@ "voxel.js" ], "dependencies": { - "browserify": ">= 1.17", - "express": ">= 3.0.6", - "mineflayer": ">= 0.0.28", - "mineflayer-navigate": ">= 0.0.8", + "browserify": "^12.0.1", + "express": "^4.13", + "mineflayer": "^1.5.3", + "mineflayer-navigate": "^0.0.9", "morgan": "^1.6.1", - "socket.io": ">= 0.9.13", - "vec3": ">= 0.1", - "voxel-engine": ">= 0.5", - "voxel-highlight": ">= 0.0.1", - "voxel-player": "latest" + "socket.io": "^1.3.7", + "vec3": "^0.1.3", + "voxel-engine": "^0.20.2", + "voxel-highlight": "^0.0.10", + "voxel-player": "^0.1.0" } } From 656dd1975892f3c33c32a06786ae7db5a1043ada Mon Sep 17 00:00:00 2001 From: Romain Beaumont Date: Tue, 5 Jan 2016 13:19:09 +0100 Subject: [PATCH 3/4] fix a few errors concerning chunk positions --- app.js | 2 +- mineflayer-voxel.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app.js b/app.js index 8efc8e7..e91003b 100644 --- a/app.js +++ b/app.js @@ -252,7 +252,7 @@ socket.on('chunkData', function(chunk) { }; if (window.game) { - window.game.voxels.emit('missingChunk', chunk.position.x/32, chunk.position.y/32, chunk.position.z/32); + window.game.voxels.emit('missingChunk', [chunk.position.x/32, chunk.position.y/32, chunk.position.z/32]); } }) diff --git a/mineflayer-voxel.js b/mineflayer-voxel.js index 9f5654d..1c5df06 100644 --- a/mineflayer-voxel.js +++ b/mineflayer-voxel.js @@ -186,7 +186,7 @@ function inject(mineflayer, bot, options) { }); socket.on('missingChunk', function(pos) { - var chunk = getChunk(mineflayer.vec3(x,y,z)); + var chunk = getChunk(mineflayer.vec3(pos[0],pos[1],pos[2])); if (chunk) socket.json.emit('chunkData', chunk); }) From ff986558c66c5b5959cf2f20cd1af8f94d8700ad Mon Sep 17 00:00:00 2001 From: Romain Beaumont Date: Tue, 5 Jan 2016 14:03:07 +0100 Subject: [PATCH 4/4] disable other players display temporarily to fix display of chunks (it does that for some reason) --- app.js | 9 ++++++--- mineflayer-voxel.js | 16 ++++++++-------- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/app.js b/app.js index e91003b..2fa4330 100644 --- a/app.js +++ b/app.js @@ -193,6 +193,7 @@ function setMobPosition(mob, entity) { } socket.on('entitySpawn', function onEntitySpawn(entity) { + return; entities[entity.id] = entity; if (entity.type === 'player') { @@ -201,12 +202,14 @@ socket.on('entitySpawn', function onEntitySpawn(entity) { }); socket.on('entityMoved', function onEntityMoved(entity) { + return; if (entity.type === 'player') { var player = players[entity.id]; if (!player) { - player = createPlayer(entity) + player = createPlayer(entity); + players[entity.id]=player; } - setMobPosition(player.avatar, entity); + if(player) setMobPosition(player.avatar, entity); // console.log(entity.username+' moved to '+vec3(player.avatar.position)) } entities[entity.id] = entity; @@ -237,7 +240,7 @@ function generate_blockCache(x,y,z) { // New chunk loading mechanism window.chunkCache = {}; socket.on('chunkData', function(chunk) { - console.log('chunkData', chunk.key, chunk.position, chunk.blocks.length); + //console.log('chunkData', chunk.key, chunk.position, chunk.blocks.length); var voxels = new Int8Array(chunk.blocks.length); // var voxels = new Array(chunk.blocks.length); diff --git a/mineflayer-voxel.js b/mineflayer-voxel.js index 1c5df06..50f1dd2 100644 --- a/mineflayer-voxel.js +++ b/mineflayer-voxel.js @@ -16,7 +16,7 @@ function inject(mineflayer, bot, options) { , server = require('http').createServer(app) , io = require('socket.io').listen(server) , port = options.port || 0 - , host = options.host || '0.0.0.0' + , host = options.host || '0.0.0.0'; io.set('log level', 0); @@ -59,7 +59,7 @@ function inject(mineflayer, bot, options) { }) } }); - }) + }); server.listen(port, function() { console.info("Listening at http://" + host + ":" + server.address().port); @@ -70,16 +70,16 @@ function inject(mineflayer, bot, options) { Vec3.prototype.chunkPosition = function() { var offset = this.modulus(chunkSize); return this.minus(offset).floored(); - } + }; Vec3.prototype.toChunkCoordinate = function() { var offset = this.modulus(chunkSize); return this.minus(offset).scaled(1/32).floored(); - } + }; Vec3.prototype.toVoxelCoordinate = function() { return this.scaled(32); - } + }; function getBlockInfo() { // get the highest block id @@ -153,7 +153,7 @@ function inject(mineflayer, bot, options) { bot.on('spawn', function() { socket.emit('spawn', serializedPosition(bot.entity.position)); - }) + }); bot.on('move', function() { socket.emit('entity', bot.entity); @@ -175,7 +175,7 @@ function inject(mineflayer, bot, options) { // console.log('blockUpdate new:'+(newBlock ? newBlock.name : '?')+' old:'+(oldBlock ? oldBlock.name : '?')) if (!newBlock) return; socket.emit('blockUpdate', serializedBlock(newBlock)); - }) + }); socket.on('controlState', function(state) { bot.setControlState(state.name, state.value); @@ -189,7 +189,7 @@ function inject(mineflayer, bot, options) { var chunk = getChunk(mineflayer.vec3(pos[0],pos[1],pos[2])); if (chunk) socket.json.emit('chunkData', chunk); - }) + }); function serializedPosition(position) { return [position.x, position.y, position.z]