Skip to content

Commit 9733dd5

Browse files
committedJul 13, 2013
Leveled nodebox
1 parent a70993d commit 9733dd5

File tree

6 files changed

+46
-4
lines changed

6 files changed

+46
-4
lines changed
 

‎src/mapnode.cpp

+24-1
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ static std::vector<aabb3f> transformNodeBox(const MapNode &n,
163163
const NodeBox &nodebox, INodeDefManager *nodemgr)
164164
{
165165
std::vector<aabb3f> boxes;
166-
if(nodebox.type == NODEBOX_FIXED)
166+
if(nodebox.type == NODEBOX_FIXED || nodebox.type == NODEBOX_LEVELED)
167167
{
168168
const std::vector<aabb3f> &fixed = nodebox.fixed;
169169
int facedir = n.getFaceDir(nodemgr);
@@ -174,6 +174,11 @@ static std::vector<aabb3f> transformNodeBox(const MapNode &n,
174174
i != fixed.end(); i++)
175175
{
176176
aabb3f box = *i;
177+
178+
if (nodebox.type == NODEBOX_LEVELED) {
179+
box.MaxEdge.Y = -BS/2 + BS*((float)1/LEVELED_MAX) * n.getLevel(nodemgr);
180+
}
181+
177182
switch (axisdir)
178183
{
179184
case 0:
@@ -354,6 +359,24 @@ std::vector<aabb3f> MapNode::getSelectionBoxes(INodeDefManager *nodemgr) const
354359
return transformNodeBox(*this, f.selection_box, nodemgr);
355360
}
356361

362+
u8 MapNode::getLevel(INodeDefManager *nodemgr) const
363+
{
364+
const ContentFeatures &f = nodemgr->get(*this);
365+
if(f.liquid_type == LIQUID_SOURCE)
366+
return LIQUID_LEVEL_SOURCE;
367+
if (f.param_type_2 == CPT2_FLOWINGLIQUID)
368+
return getParam2() & LIQUID_LEVEL_MASK;
369+
if(f.liquid_type == LIQUID_FLOWING) // can remove if all param_type_2 setted
370+
return getParam2() & LIQUID_LEVEL_MASK;
371+
if(f.leveled || f.param_type_2 == CPT2_LEVELED) {
372+
u8 level = getParam2() & LEVELED_MASK;
373+
if(level) return level;
374+
if(f.leveled > LEVELED_MAX) return LEVELED_MAX;
375+
return f.leveled; //default
376+
}
377+
return 0;
378+
}
379+
357380
u32 MapNode::serializedLength(u8 version)
358381
{
359382
if(!ser_ver_supported(version))

‎src/mapnode.h

+7
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,10 @@ enum Rotation {
8787

8888
#define LIQUID_INFINITY_MASK 0x80 //0b10000000
8989

90+
// mask for param2, now as for liquid
91+
#define LEVELED_MASK 0x07
92+
#define LEVELED_MAX LEVELED_MASK
93+
9094
/*
9195
This is the stuff what the whole world consists of.
9296
*/
@@ -206,6 +210,9 @@ struct MapNode
206210
*/
207211
std::vector<aabb3f> getSelectionBoxes(INodeDefManager *nodemgr) const;
208212

213+
/* Liquid helpers */
214+
u8 getLevel(INodeDefManager *nodemgr) const;
215+
209216
/*
210217
Serialization functions
211218
*/

‎src/nodedef.cpp

+5-2
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ void NodeBox::serialize(std::ostream &os) const
5050
writeU8(os, 1); // version
5151
writeU8(os, type);
5252

53-
if(type == NODEBOX_FIXED)
53+
if(type == NODEBOX_FIXED || type == NODEBOX_LEVELED)
5454
{
5555
writeU16(os, fixed.size());
5656
for(std::vector<aabb3f>::const_iterator
@@ -82,7 +82,7 @@ void NodeBox::deSerialize(std::istream &is)
8282

8383
type = (enum NodeBoxType)readU8(is);
8484

85-
if(type == NODEBOX_FIXED)
85+
if(type == NODEBOX_FIXED || type == NODEBOX_LEVELED)
8686
{
8787
u16 fixed_count = readU16(is);
8888
while(fixed_count--)
@@ -206,6 +206,7 @@ void ContentFeatures::reset()
206206
climbable = false;
207207
buildable_to = false;
208208
rightclickable = true;
209+
leveled = 0;
209210
liquid_type = LIQUID_NONE;
210211
liquid_alternative_flowing = "";
211212
liquid_alternative_source = "";
@@ -281,6 +282,7 @@ void ContentFeatures::serialize(std::ostream &os, u16 protocol_version)
281282
// Stuff below should be moved to correct place in a version that otherwise changes
282283
// the protocol version
283284
writeU8(os, drowning);
285+
writeU8(os, leveled);
284286
}
285287

286288
void ContentFeatures::deSerialize(std::istream &is)
@@ -346,6 +348,7 @@ void ContentFeatures::deSerialize(std::istream &is)
346348
// Stuff below should be moved to correct place in a version that
347349
// otherwise changes the protocol version
348350
drowning = readU8(is);
351+
leveled = readU8(is);
349352
}catch(SerializationError &e) {};
350353
}
351354

‎src/nodedef.h

+6-1
Original file line numberDiff line numberDiff line change
@@ -56,20 +56,23 @@ enum ContentParamType2
5656
CPT2_FACEDIR,
5757
// Direction for signs, torches and such
5858
CPT2_WALLMOUNTED,
59+
// Block level like FLOWINGLIQUID
60+
CPT2_LEVELED,
5961
};
6062

6163
enum LiquidType
6264
{
6365
LIQUID_NONE,
6466
LIQUID_FLOWING,
65-
LIQUID_SOURCE
67+
LIQUID_SOURCE,
6668
};
6769

6870
enum NodeBoxType
6971
{
7072
NODEBOX_REGULAR, // Regular block; allows buildable_to
7173
NODEBOX_FIXED, // Static separately defined box(es)
7274
NODEBOX_WALLMOUNTED, // Box for wall mounted nodes; (top, bottom, side)
75+
NODEBOX_LEVELED, // Same as fixed, but with dynamic height from param2. for snow, ...
7376
};
7477

7578
struct NodeBox
@@ -207,6 +210,8 @@ struct ContentFeatures
207210
bool buildable_to;
208211
// Player cannot build to these (placement prediction disabled)
209212
bool rightclickable;
213+
// Flowing liquid or snow, value = default level
214+
u8 leveled;
210215
// Whether the node is non-liquid, source liquid or flowing liquid
211216
enum LiquidType liquid_type;
212217
// If the content is liquid, this is the flowing version of the liquid.

‎src/script/common/c_content.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,8 @@ ContentFeatures read_content_features(lua_State *L, int index)
389389
// the slowest possible
390390
f.liquid_viscosity = getintfield_default(L, index,
391391
"liquid_viscosity", f.liquid_viscosity);
392+
f.leveled = getintfield_default(L, index, "leveled", f.leveled);
393+
392394
getboolfield(L, index, "liquid_renewable", f.liquid_renewable);
393395
getboolfield(L, index, "drowning", f.drowning);
394396
// Amount of light the node emits

‎src/script/cpp_api/s_node.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ struct EnumString ScriptApiNode::es_ContentParamType2[] =
5050
{CPT2_FLOWINGLIQUID, "flowingliquid"},
5151
{CPT2_FACEDIR, "facedir"},
5252
{CPT2_WALLMOUNTED, "wallmounted"},
53+
{CPT2_LEVELED, "leveled"},
5354
{0, NULL},
5455
};
5556

@@ -73,6 +74,7 @@ struct EnumString ScriptApiNode::es_NodeBoxType[] =
7374
{NODEBOX_REGULAR, "regular"},
7475
{NODEBOX_FIXED, "fixed"},
7576
{NODEBOX_WALLMOUNTED, "wallmounted"},
77+
{NODEBOX_LEVELED, "leveled"},
7678
{0, NULL},
7779
};
7880

0 commit comments

Comments
 (0)
Please sign in to comment.