summaryrefslogtreecommitdiffstats
path: root/src/Block.cpp
blob: 98f1b0a026d73a8bc3274519b991d13fcf046db4 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include "Block.hpp"

#include <string>

Block::~Block() {}

Block::Block(unsigned short id, unsigned char state,
	         unsigned char light, unsigned char sky)
        : id(id), state(state), light(light), sky (sky) {}

Block::Block() : id(0), state(0), light(0), sky(0) {}

bool operator==(const BlockId& lhs, const BlockId &rhs) {
    return (lhs.id == rhs.id) && (lhs.state == rhs.state);
}

bool operator<(const BlockId& lhs, const BlockId &rhs) {
	if (lhs.id < rhs.id)
		return true;
    return lhs.state < rhs.state;
}

std::pair<std::string, std::string> TransformBlockIdToBlockStateName(BlockId blockId) {
	switch (blockId.id) {
	case 1: {
		if (blockId.state > 6)
			break;
		static const std::pair<std::string, std::string> ids[] = {
			std::pair<std::string,std::string>("stone", "normal"),
			std::pair<std::string,std::string>("granite", "normal"),
			std::pair<std::string,std::string>("smooth_granite", "normal"),
			std::pair<std::string,std::string>("diorite", "normal"),
			std::pair<std::string,std::string>("smooth_diorite", "normal"),
			std::pair<std::string,std::string>("andesite", "normal"),
			std::pair<std::string,std::string>("smooth_andesite", "normal"),
		};
		return ids[blockId.state];		
	}
	case 2: {
		return std::make_pair("grass", "snowy=false");
	}

	default:
		break;
	}
	
	return std::make_pair("", "");
}