From bc2819cab2978c61b2ca1d7b68a5d1f223e8647a Mon Sep 17 00:00:00 2001 From: Mark Holmquist Date: Wed, 27 Jul 2011 10:18:09 -0700 Subject: [PATCH 1/5] Added ladders--they don't have any use yet, though --- data/item_ladder.png | Bin 0 -> 581 bytes data/ladder.png | Bin 0 -> 691 bytes src/content_craft.cpp | 16 +++++++++++++ src/content_mapblock.cpp | 47 ++++++++++++++++++++++++++++++++++++ src/content_mapnode.cpp | 13 ++++++++++ src/content_mapnode.h | 1 + src/game.cpp | 50 +++++++++++++++++++++++++++++++++++++++ 7 files changed, 127 insertions(+) create mode 100644 data/item_ladder.png create mode 100644 data/ladder.png diff --git a/data/item_ladder.png b/data/item_ladder.png new file mode 100644 index 0000000000000000000000000000000000000000..f35978ff94352873d8d0060614b449fa7f208981 GIT binary patch literal 581 zcmV-L0=oT)P)Px#32;bRa{vGf6951U69E94oEQKA00(qQO+^RW2O0(eD*uG3f&c&k*GWV{R4C7N z(!XmIK@P(FRlh@? z-oF*aX%vs7EC672X|~%7ip=mmv`qeK`zzOpqD)a8G`iUEF&pl?eyg$4VU_~`+gopc z1-+*02*XR_NGELd%B9m6_qsj&+gCHRKtm#khfiLdbTI(v9iLw9Y_4CNGEB=bO++0R z=g%oxRe6-g0w&bWt82+{lq91p&+*UiL#dLi!V>7DK(HSQnF)~uNbn0zK~(Pf)8{>pAWsguQn6!q&(tsoBa=dNZr0&b0PyDX zUNRI~nHk~0WTDChvu&NBj!3CCC~{I;JA3_ccWg`b4~p#>Q&Ch@18vd>P>1;k_>BVa TRIpI^00000NkvXXu0mjfQ8D^V literal 0 HcmV?d00001 diff --git a/data/ladder.png b/data/ladder.png new file mode 100644 index 0000000000000000000000000000000000000000..dbbd680ec27c8aef38165f96ca27bfe3cb144996 GIT binary patch literal 691 zcmV;k0!;mhP)Px#24YJ`L;(K){{a7>y{D4^000SaNLh0L01FcU01FcV0GgZ_00007bV*G`2ipf4 z1vwxJh(bO900J{fL_t(I%YBp2Y7~HsDc@zrGYj8aoq6e{+(2W#@7y&MVCscK+bglP;TKOItfXV5OfT{=Py4} z5pLdEVHkvX{(#O=?|8uCS%3aNm2miG2aAlrpl+G5Gu?rQzYp$>-tVz1VoupgeBwl~)SPJKSLn77eVp``%^|E<^Wb^w@M Z`Y#$^E%7qwXI}sS002ovPDHLkV1g}?CyW39 literal 0 HcmV?d00001 diff --git a/src/content_craft.cpp b/src/content_craft.cpp index b5a1dc776..481ea1a63 100644 --- a/src/content_craft.cpp +++ b/src/content_craft.cpp @@ -413,6 +413,22 @@ InventoryItem *craft_get_result(InventoryItem **items) } } + // Ladder + { + ItemSpec specs[9]; + specs[0] = ItemSpec(ITEM_CRAFT, "Stick"); + specs[2] = ItemSpec(ITEM_CRAFT, "Stick"); + specs[3] = ItemSpec(ITEM_CRAFT, "Stick"); + specs[4] = ItemSpec(ITEM_CRAFT, "Stick"); + specs[5] = ItemSpec(ITEM_CRAFT, "Stick"); + specs[6] = ItemSpec(ITEM_CRAFT, "Stick"); + specs[8] = ItemSpec(ITEM_CRAFT, "Stick"); + if(checkItemCombination(items, specs)) + { + return new MaterialItem(CONTENT_LADDER, 1); + } + } + return NULL; } diff --git a/src/content_mapblock.cpp b/src/content_mapblock.cpp index 3044c8b35..ceb673606 100644 --- a/src/content_mapblock.cpp +++ b/src/content_mapblock.cpp @@ -1134,6 +1134,53 @@ void mapblock_mesh_generate_special(MeshMakeData *data, u16 indices[] = {0,1,2,2,3,0}; collector.append(material_rail, vertices, 4, indices, 6); } + else if (n.d == CONTENT_LADDER) { + u8 l = decode_light(n.getLightBlend(data->m_daynight_ratio)); + video::SColor c(255,l,l,l); + + float d = (float)BS/16; + + // Assume wall is at X+ + video::S3DVertex vertices[4] = + { + video::S3DVertex(BS/2-d,-BS/2,-BS/2, 0,0,0, c, 0,1), + video::S3DVertex(BS/2-d,-BS/2,BS/2, 0,0,0, c, 1,1), + video::S3DVertex(BS/2-d,BS/2,BS/2, 0,0,0, c, 1,0), + video::S3DVertex(BS/2-d,BS/2,-BS/2, 0,0,0, c, 0,0), + }; + + v3s16 dir = unpackDir(n.dir); + + for(s32 i=0; i<4; i++) + { + if(dir == v3s16(1,0,0)) + vertices[i].Pos.rotateXZBy(0); + if(dir == v3s16(-1,0,0)) + vertices[i].Pos.rotateXZBy(180); + if(dir == v3s16(0,0,1)) + vertices[i].Pos.rotateXZBy(90); + if(dir == v3s16(0,0,-1)) + vertices[i].Pos.rotateXZBy(-90); + if(dir == v3s16(0,-1,0)) + vertices[i].Pos.rotateXYBy(-90); + if(dir == v3s16(0,1,0)) + vertices[i].Pos.rotateXYBy(90); + + vertices[i].Pos += intToFloat(p + blockpos_nodes, BS); + } + + video::SMaterial material_ladder; + material_ladder.setFlag(video::EMF_LIGHTING, false); + material_ladder.setFlag(video::EMF_BACK_FACE_CULLING, false); + material_ladder.setFlag(video::EMF_BILINEAR_FILTER, false); + material_ladder.setFlag(video::EMF_FOG_ENABLE, true); + material_ladder.MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF; + material_ladder.setTexture(0, g_texturesource->getTextureRaw("ladder.png")); + + u16 indices[] = {0,1,2,2,3,0}; + // Add to mesh collector + collector.append(material_ladder, vertices, 4, indices, 6); + } } } #endif diff --git a/src/content_mapnode.cpp b/src/content_mapnode.cpp index 7589f06ed..e3235778a 100644 --- a/src/content_mapnode.cpp +++ b/src/content_mapnode.cpp @@ -303,6 +303,19 @@ void content_mapnode_init() f->walkable = false; setDirtLikeDiggingProperties(f->digging_properties, 0.75); + i = CONTENT_LADDER; + f = &content_features(i); + f->setInventoryTexture("item_ladder.png"); + f->light_propagates = true; + f->param_type = CPT_LIGHT; + f->is_ground_content = true; + f->dug_item = std::string("MaterialItem ")+itos(i)+" 1"; + f->wall_mounted = true; + f->solidness = 0; + f->air_equivalent = true; + f->walkable = false; + setWoodLikeDiggingProperties(f->digging_properties, 0.5); + // Deprecated i = CONTENT_COALSTONE; f = &content_features(i); diff --git a/src/content_mapnode.h b/src/content_mapnode.h index 609df0a95..8f44126cf 100644 --- a/src/content_mapnode.h +++ b/src/content_mapnode.h @@ -46,6 +46,7 @@ MapNode mapnode_translate_to_internal(MapNode n_from, u8 version); #define CONTENT_FURNACE 16 #define CONTENT_FENCE 21 #define CONTENT_RAIL 30 +#define CONTENT_LADDER 31 // 0x800...0xfff (2048...4095): higher 4 bytes of param2 are not usable #define CONTENT_GRASS 0x800 //1 diff --git a/src/game.cpp b/src/game.cpp index 6c0474ee7..d8ea45fb1 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -538,6 +538,56 @@ void getPointedNode(Client *client, v3f player_position, } } } + + else if(n.getContent() == CONTENT_LADDER) + { + v3s16 dir = unpackDir(n.dir); + v3f dir_f = v3f(dir.X, dir.Y, dir.Z); + dir_f *= BS/2 - BS/6 - BS/20; + v3f cpf = npf + dir_f; + f32 distance = (cpf - camera_position).getLength(); + + v3f vertices[4] = + { + v3f(BS*0.42,-BS/2,-BS/2), + v3f(BS*0.49, BS/2, BS/2), + }; + + for(s32 i=0; i<2; i++) + { + if(dir == v3s16(1,0,0)) + vertices[i].rotateXZBy(0); + if(dir == v3s16(-1,0,0)) + vertices[i].rotateXZBy(180); + if(dir == v3s16(0,0,1)) + vertices[i].rotateXZBy(90); + if(dir == v3s16(0,0,-1)) + vertices[i].rotateXZBy(-90); + if(dir == v3s16(0,-1,0)) + vertices[i].rotateXYBy(-90); + if(dir == v3s16(0,1,0)) + vertices[i].rotateXYBy(90); + + vertices[i] += npf; + } + + core::aabbox3d box; + + box = core::aabbox3d(vertices[0]); + box.addInternalPoint(vertices[1]); + + if(distance < mindistance) + { + if(box.intersectsWithLine(shootline)) + { + nodefound = true; + nodepos = np; + neighbourpos = np; + mindistance = distance; + nodehilightbox = box; + } + } + } else if(n.getContent() == CONTENT_RAIL) { v3s16 dir = unpackDir(n.param0); From 1c59cff8328bd85d6aed7df38b7eaddbeeca0aec Mon Sep 17 00:00:00 2001 From: Mark Holmquist Date: Wed, 27 Jul 2011 14:38:48 -0700 Subject: [PATCH 2/5] Ladders implemented! --- src/content_mapnode.cpp | 1 + src/mapnode.h | 3 +++ src/player.cpp | 30 +++++++++++++++++++++++++++++- src/player.h | 1 + 4 files changed, 34 insertions(+), 1 deletion(-) diff --git a/src/content_mapnode.cpp b/src/content_mapnode.cpp index e3235778a..8e97fa6cd 100644 --- a/src/content_mapnode.cpp +++ b/src/content_mapnode.cpp @@ -314,6 +314,7 @@ void content_mapnode_init() f->solidness = 0; f->air_equivalent = true; f->walkable = false; + f->climbable = true; setWoodLikeDiggingProperties(f->digging_properties, 0.5); // Deprecated diff --git a/src/mapnode.h b/src/mapnode.h index 1fb84e1c9..484ad4e19 100644 --- a/src/mapnode.h +++ b/src/mapnode.h @@ -128,6 +128,8 @@ struct ContentFeatures bool pointable; // Player can dig these bool diggable; + // Player can climb these + bool climbable; // Player can build on these bool buildable_to; // Whether the node has no liquid, source liquid or flowing liquid @@ -171,6 +173,7 @@ struct ContentFeatures walkable = true; pointable = true; diggable = true; + climbable = false; buildable_to = false; liquid_type = LIQUID_NONE; wall_mounted = false; diff --git a/src/player.cpp b/src/player.cpp index c43276ef1..3846cd8f9 100644 --- a/src/player.cpp +++ b/src/player.cpp @@ -375,6 +375,21 @@ void LocalPlayer::move(f32 dtime, Map &map, f32 pos_max_d, in_water_stable = false; } + /* + Check if player is climbing + */ + + try { + v3s16 pp = floatToInt(position + v3f(0,0.5*BS,0), BS); + v3s16 pp2 = floatToInt(position + v3f(0,-0.2*BS,0), BS); + is_climbing = (content_features(map.getNode(pp).d).climbable || + content_features(map.getNode(pp2).d).climbable); + } + catch(InvalidPositionException &e) + { + is_climbing = false; + } + /* Collision uncertainty radius Make it a bit larger than the maximum distance of movement @@ -461,7 +476,7 @@ void LocalPlayer::move(f32 dtime, Map &map, f32 pos_max_d, Player is allowed to jump when this is true. */ touching_ground = false; - + /*std::cout<<"Checking collisions for (" < (" @@ -814,6 +829,19 @@ void LocalPlayer::applyControl(float dtime) } } + if (is_climbing) { + if (control.up || control.left || control.right || control.down) { + v3f speed = getSpeed(); + speed.Y = 2*BS; + setSpeed(speed); + } + else { + v3f speed = getSpeed(); + speed.Y = -2*BS; + setSpeed(speed); + } + } + // The speed of the player (Y is ignored) if(superspeed) speed = speed.normalize() * walkspeed_max * 5.0; diff --git a/src/player.h b/src/player.h index 29460e1e1..78ca14948 100644 --- a/src/player.h +++ b/src/player.h @@ -118,6 +118,7 @@ public: bool in_water; // This is more stable and defines the maximum speed of the player bool in_water_stable; + bool is_climbing; bool swimming_up; Inventory inventory; From 8e67f4c4e617a8fcbb9176de1bf0b267acfc6e2f Mon Sep 17 00:00:00 2001 From: Mark Holmquist Date: Sat, 30 Jul 2011 17:26:13 -0700 Subject: [PATCH 3/5] Fixed a few problems in the ladder update, and changed the speed to account for gravity --- src/content_mapblock.cpp | 4 ++-- src/game.cpp | 2 +- src/player.cpp | 6 +++--- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/content_mapblock.cpp b/src/content_mapblock.cpp index ceb673606..ed2cd766a 100644 --- a/src/content_mapblock.cpp +++ b/src/content_mapblock.cpp @@ -1134,7 +1134,7 @@ void mapblock_mesh_generate_special(MeshMakeData *data, u16 indices[] = {0,1,2,2,3,0}; collector.append(material_rail, vertices, 4, indices, 6); } - else if (n.d == CONTENT_LADDER) { + else if (n.getContent() == CONTENT_LADDER) { u8 l = decode_light(n.getLightBlend(data->m_daynight_ratio)); video::SColor c(255,l,l,l); @@ -1149,7 +1149,7 @@ void mapblock_mesh_generate_special(MeshMakeData *data, video::S3DVertex(BS/2-d,BS/2,-BS/2, 0,0,0, c, 0,0), }; - v3s16 dir = unpackDir(n.dir); + v3s16 dir = unpackDir(n.param2); for(s32 i=0; i<4; i++) { diff --git a/src/game.cpp b/src/game.cpp index d8ea45fb1..fb5d7cb93 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -541,7 +541,7 @@ void getPointedNode(Client *client, v3f player_position, else if(n.getContent() == CONTENT_LADDER) { - v3s16 dir = unpackDir(n.dir); + v3s16 dir = unpackDir(n.param2); v3f dir_f = v3f(dir.X, dir.Y, dir.Z); dir_f *= BS/2 - BS/6 - BS/20; v3f cpf = npf + dir_f; diff --git a/src/player.cpp b/src/player.cpp index 3846cd8f9..270f795b5 100644 --- a/src/player.cpp +++ b/src/player.cpp @@ -382,8 +382,8 @@ void LocalPlayer::move(f32 dtime, Map &map, f32 pos_max_d, try { v3s16 pp = floatToInt(position + v3f(0,0.5*BS,0), BS); v3s16 pp2 = floatToInt(position + v3f(0,-0.2*BS,0), BS); - is_climbing = (content_features(map.getNode(pp).d).climbable || - content_features(map.getNode(pp2).d).climbable); + is_climbing = (content_features(map.getNode(pp).getContent()).climbable || + content_features(map.getNode(pp2).getContent()).climbable); } catch(InvalidPositionException &e) { @@ -832,7 +832,7 @@ void LocalPlayer::applyControl(float dtime) if (is_climbing) { if (control.up || control.left || control.right || control.down) { v3f speed = getSpeed(); - speed.Y = 2*BS; + speed.Y = 2.5*BS; setSpeed(speed); } else { From 267744a56871f6eecbb80c7999c2fcd79989fc1e Mon Sep 17 00:00:00 2001 From: Mark Holmquist Date: Sat, 30 Jul 2011 21:53:05 -0700 Subject: [PATCH 4/5] Fixing ladders again --- src/environment.cpp | 4 +++- src/player.cpp | 27 +++++++++++++-------------- 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/src/environment.cpp b/src/environment.cpp index e9b94f3fa..680d209fc 100644 --- a/src/environment.cpp +++ b/src/environment.cpp @@ -1511,6 +1511,8 @@ void ClientEnvironment::step(float dtime) /* Get the speed the player is going */ + bool is_climbing = lplayer->is_climbing; + f32 player_speed = 0.001; // just some small value player_speed = lplayer->getSpeed().getLength(); @@ -1568,7 +1570,7 @@ void ClientEnvironment::step(float dtime) v3f lplayerpos = lplayer->getPosition(); // Apply physics - if(free_move == false) + if(free_move == false && is_climbing == false) { // Gravity v3f speed = lplayer->getSpeed(); diff --git a/src/player.cpp b/src/player.cpp index 270f795b5..be478e869 100644 --- a/src/player.cpp +++ b/src/player.cpp @@ -382,8 +382,8 @@ void LocalPlayer::move(f32 dtime, Map &map, f32 pos_max_d, try { v3s16 pp = floatToInt(position + v3f(0,0.5*BS,0), BS); v3s16 pp2 = floatToInt(position + v3f(0,-0.2*BS,0), BS); - is_climbing = (content_features(map.getNode(pp).getContent()).climbable || - content_features(map.getNode(pp2).getContent()).climbable); + is_climbing = ((content_features(map.getNode(pp).getContent()).climbable || + content_features(map.getNode(pp2).getContent()).climbable) && !free_move); } catch(InvalidPositionException &e) { @@ -738,7 +738,7 @@ void LocalPlayer::applyControl(float dtime) bool fast_move = g_settings.getBool("fast_move"); bool continuous_forward = g_settings.getBool("continuous_forward"); - if(free_move) + if(free_move || is_climbing) { v3f speed = getSpeed(); speed.Y = 0; @@ -765,6 +765,12 @@ void LocalPlayer::applyControl(float dtime) speed.Y = -walkspeed_max; setSpeed(speed); } + else if(is_climbing) + { + v3f speed = getSpeed(); + speed.Y = -3*BS; + setSpeed(speed); + } else { // If not free movement but fast is allowed, aux1 is @@ -827,17 +833,10 @@ void LocalPlayer::applyControl(float dtime) setSpeed(speed); swimming_up = true; } - } - - if (is_climbing) { - if (control.up || control.left || control.right || control.down) { - v3f speed = getSpeed(); - speed.Y = 2.5*BS; - setSpeed(speed); - } - else { - v3f speed = getSpeed(); - speed.Y = -2*BS; + else if(is_climbing) + { + v3f speed = getSpeed(); + speed.Y = 3*BS; setSpeed(speed); } } From 7bd9e53ae630feabe42ab48369913f93beac26a7 Mon Sep 17 00:00:00 2001 From: Mark Holmquist Date: Sat, 30 Jul 2011 17:46:43 -0700 Subject: [PATCH 5/5] Changing CONTENT_LADDER to be an extended block --- src/content_mapnode.h | 1 - 1 file changed, 1 deletion(-) diff --git a/src/content_mapnode.h b/src/content_mapnode.h index 8f44126cf..9643db746 100644 --- a/src/content_mapnode.h +++ b/src/content_mapnode.h @@ -76,6 +76,5 @@ MapNode mapnode_translate_to_internal(MapNode n_from, u8 version); #define CONTENT_NC 0x817 #define CONTENT_NC_RB 0x818 - #endif