Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] trying to fix things #1

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/node_modules
/public/client.js
/public/textures
/public/assets
/public/char.png
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ You must extract textures from minecraft.jar (Note, must be snapshot, not the cu

`node extract_textures.js <path_to_minecraft.jar>`

For example `node extract_textures.js ~/.minecraft/versions/1.8/1.8.jar`

### Usage

`npm start`
48 changes: 26 additions & 22 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,36 +25,36 @@ 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,
'oreGold': 10,
'oreIron': 11,
'oreCoal': 12,
'oreLapis': 13,
'oreDiamond': 14,
'oreDiamond': 14,*/
'log': 15,
'leaves': 16,
//'leaves': 16,
// 'glass': 17,
// 'tallgrass': 18,
// 'flower': 19,
// 'rose': 20,
// 'mushroom': 21,
// 'torch': 22,
// 'workbench': 22,
'furnace': 23
// 'furnace': 23
}[name]

return mat !== undefined ? mat : 1;
Expand All @@ -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);
Expand All @@ -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},
Expand All @@ -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);*/
}
})

Expand Down Expand Up @@ -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;
}
Expand All @@ -192,6 +193,7 @@ function setMobPosition(mob, entity) {
}

socket.on('entitySpawn', function onEntitySpawn(entity) {
return;
entities[entity.id] = entity;

if (entity.type === 'player') {
Expand All @@ -200,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;
Expand Down Expand Up @@ -236,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);
Expand All @@ -251,7 +255,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]);
}
})

Expand Down
4 changes: 2 additions & 2 deletions extract_textures.js
Original file line number Diff line number Diff line change
Expand Up @@ -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] });
})
})
20 changes: 10 additions & 10 deletions mineflayer-voxel.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ 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);

if (!options.disableLogging) {
app.use(express.logger('tiny'));
app.use(require("morgan")('tiny'));
}

// Serve out textures and such
Expand Down Expand Up @@ -59,7 +59,7 @@ function inject(mineflayer, bot, options) {
})
}
});
})
});

server.listen(port, function() {
console.info("Listening at http://" + host + ":" + server.address().port);
Expand All @@ -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
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -186,10 +186,10 @@ 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);
})
});

function serializedPosition(position) {
return [position.x, position.y, position.z]
Expand Down
28 changes: 16 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,27 @@
"main": "mineflayer-voxel.js",
"author": "Kent Karlsson <[email protected]>",
"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",
"mineflayer": ">= 0.0.28",
"mineflayer-navigate": ">= 0.0.8",
"voxel-engine": ">= 0.5",
"voxel-highlight": ">= 0.0.1",
"express": ">= 3.0.6",
"socket.io": ">= 0.9.13",
"browserify": ">= 1.17",
"voxel-player": "latest"
"browserify": "^12.0.1",
"express": "^4.13",
"mineflayer": "^1.5.3",
"mineflayer-navigate": "^0.0.9",
"morgan": "^1.6.1",
"socket.io": "^1.3.7",
"vec3": "^0.1.3",
"voxel-engine": "^0.20.2",
"voxel-highlight": "^0.0.10",
"voxel-player": "^0.1.0"
}
}