aboutsummaryrefslogtreecommitdiff
path: root/Minecraft.World/Material.cpp
blob: d17965dfb26efece4479e0cdbbffd2018fc6313f (plain)
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
#include "stdafx.h"
#include "Material.h"
#include "DecorationMaterial.h"
#include "GasMaterial.h"
#include "LiquidMaterial.h"
#include "PortalMaterial.h"
#include "WebMaterial.h"// 4J added, Java version just does a local alteration when instantiating the Material for webs to get the same thing

Material *Material::air = nullptr;
Material *Material::grass = nullptr;
Material *Material::dirt = nullptr;
Material *Material::wood = nullptr;
Material *Material::stone = nullptr;
Material *Material::metal = nullptr;
Material *Material::heavyMetal = nullptr;
Material *Material::water = nullptr;
Material *Material::lava = nullptr;
Material *Material::leaves = nullptr;
Material *Material::plant = nullptr;
Material *Material::replaceable_plant = nullptr;
Material *Material::sponge = nullptr;
Material *Material::cloth = nullptr;
Material *Material::fire = nullptr;
Material *Material::sand = nullptr;
Material *Material::decoration = nullptr;
Material *Material::clothDecoration = nullptr;
Material *Material::glass = nullptr;
Material *Material::buildable_glass = nullptr;
Material *Material::explosive = nullptr;
Material *Material::coral = nullptr;
Material *Material::ice = nullptr;
Material *Material::topSnow = nullptr;
Material *Material::snow = nullptr;
Material *Material::cactus = nullptr;
Material *Material::clay = nullptr;
Material *Material::vegetable = nullptr;
Material *Material::egg = nullptr;
Material *Material::portal = nullptr;
Material *Material::cake = nullptr;
Material *Material::piston = nullptr;
Material *Material::web = nullptr;

void Material::staticCtor()
{
	Material::air = new GasMaterial(MaterialColor::none);
	Material::grass = new Material(MaterialColor::grass);
	Material::dirt = new Material(MaterialColor::dirt);
	Material::wood = (new Material(MaterialColor::wood))->flammable();
	Material::stone = (new Material(MaterialColor::stone))->notAlwaysDestroyable();
	Material::metal = (new Material(MaterialColor::metal))->notAlwaysDestroyable();
	Material::heavyMetal = (new Material(MaterialColor::metal))->notAlwaysDestroyable()->notPushable();
	Material::water = (new LiquidMaterial(MaterialColor::water))->destroyOnPush();
	Material::lava = (new LiquidMaterial(MaterialColor::fire))->destroyOnPush();
	Material::leaves = (new Material(MaterialColor::plant))->flammable()->neverBuildable()->destroyOnPush();
	Material::plant = (new DecorationMaterial(MaterialColor::plant))->destroyOnPush();
	Material::replaceable_plant = (new DecorationMaterial(MaterialColor::plant))->flammable()->destroyOnPush()->replaceable();
	Material::sponge = new Material(MaterialColor::cloth);
	Material::cloth = (new Material(MaterialColor::cloth))->flammable();
	Material::fire = (new GasMaterial(MaterialColor::none))->destroyOnPush();
	Material::sand = new Material(MaterialColor::sand);
	Material::decoration = (new DecorationMaterial(MaterialColor::none))->destroyOnPush();
	Material::clothDecoration = (new DecorationMaterial(MaterialColor::cloth))->flammable();
	Material::glass = (new Material(MaterialColor::none))->neverBuildable()->makeDestroyedByHand();
	Material::buildable_glass = (new Material(MaterialColor::none))->makeDestroyedByHand();
	Material::explosive = (new Material(MaterialColor::fire))->flammable()->neverBuildable();
	Material::coral = (new Material(MaterialColor::plant))->destroyOnPush();
	Material::ice = (new Material(MaterialColor::ice))->neverBuildable()->makeDestroyedByHand();
	Material::topSnow = (new DecorationMaterial(MaterialColor::snow))->replaceable()->neverBuildable()->notAlwaysDestroyable()->destroyOnPush();
	Material::snow = (new Material(MaterialColor::snow))->notAlwaysDestroyable();
	Material::cactus = (new Material(MaterialColor::plant))->neverBuildable()->destroyOnPush();
	Material::clay = (new Material(MaterialColor::clay));
	Material::vegetable = (new Material(MaterialColor::plant))->destroyOnPush();
	Material::egg = ( new Material(MaterialColor::plant))->destroyOnPush();
	Material::portal = (new PortalMaterial(MaterialColor::none))->notPushable();
	Material::cake = (new Material(MaterialColor::none))->destroyOnPush();
	// 4J added WebMaterial, Java version just does a local alteration when instantiating the Material for webs to get the same thing
	Material::web = (new WebMaterial(MaterialColor::cloth))->notAlwaysDestroyable()->destroyOnPush();
	Material::piston  = (new Material(MaterialColor::stone))->notPushable();
}

Material::Material(MaterialColor *color)
{
	this->color = color;

	// 4J Stu - Default inits
	_flammable = false;
	_replaceable = false;
	_neverBuildable = false;
	_isAlwaysDestroyable = true;
	pushReaction = 0;
	destroyedByHand = false;
}

bool Material::isLiquid()
{
    return false;
}

bool Material::letsWaterThrough()
{
    return (!isLiquid() && !isSolid());
}

bool Material::isSolid()
{
    return true;
}

bool Material::blocksLight()
{
    return true;
}

bool Material::blocksMotion()
{
    return true;
}

Material *Material::neverBuildable()
{
    this->_neverBuildable = true;
    return this;
}

Material *Material::notAlwaysDestroyable()
{
	this->_isAlwaysDestroyable = false;
	return this;
}

Material *Material::flammable()
{
    this->_flammable = true;
    return this;
}

bool Material::isFlammable()
{
    return _flammable;
}

Material *Material::replaceable()
{
    this->_replaceable = true;
    return this;
}

bool Material::isReplaceable()
{
    return _replaceable;
}

bool Material::isSolidBlocking()
{
    if (_neverBuildable) return false;
    return blocksMotion();
}

bool Material::isAlwaysDestroyable()
{
    // these materials will always drop resources when destroyed, regardless
	// of player's equipment
    return _isAlwaysDestroyable;
}

int Material::getPushReaction()
{
	return pushReaction;
}

Material *Material::makeDestroyedByHand()
{
	this->destroyedByHand = true;
	return this;
}

bool Material::isDestroyedByHand()
{
	return destroyedByHand;
}

Material *Material::destroyOnPush()
{
	pushReaction = PUSH_DESTROY;
	return this;
}

Material *Material::notPushable()
{
	pushReaction = PUSH_BLOCK;
	return this;
}