Skip to content

Commit 0f25767

Browse files
committed
Swimming in water and changed the texture pack to Sphax PureBDCraft
Swimming in lava is prohibited, it's dangerous!
1 parent 05934f4 commit 0f25767

File tree

8 files changed

+534
-269
lines changed

8 files changed

+534
-269
lines changed

chunk.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -493,7 +493,7 @@ bool Chunk::intersects(AABB &other)
493493
return false;
494494
}
495495

496-
bool Chunk::intersectsRay(GLFix rx, GLFix ry, GLFix rz, GLFix dx, GLFix dy, GLFix dz, GLFix &dist, Position &pos, AABB::SIDE &side)
496+
bool Chunk::intersectsRay(GLFix rx, GLFix ry, GLFix rz, GLFix dx, GLFix dy, GLFix dz, GLFix &dist, Position &pos, AABB::SIDE &side, bool ignore_water)
497497
{
498498
GLFix shortest_dist;
499499
if(aabb.intersectsRay(rx, ry, rz, dx, dy, dz, shortest_dist) == AABB::NONE)
@@ -522,7 +522,7 @@ bool Chunk::intersectsRay(GLFix rx, GLFix ry, GLFix rz, GLFix dx, GLFix dy, GLFi
522522

523523
BLOCK_WDATA block = blocks[x][y][z];
524524

525-
if(block == BLOCK_AIR)
525+
if(block == BLOCK_AIR || (getBLOCK(block) == BLOCK_WATER && ignore_water))
526526
continue;
527527

528528
AABB test = aabb;

chunk.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class Chunk
3535
void setGlobalBlockRelative(const int x, const int y, const int z, const BLOCK_WDATA block);
3636
AABB &getAABB() { return aabb; }
3737
bool intersects(AABB &other);
38-
bool intersectsRay(GLFix x, GLFix y, GLFix z, GLFix dx, GLFix dy, GLFix dz, GLFix &dist, Position &pos, AABB::SIDE &side);
38+
bool intersectsRay(GLFix x, GLFix y, GLFix z, GLFix dx, GLFix dy, GLFix dz, GLFix &dist, Position &pos, AABB::SIDE &side, bool ignore_water);
3939
void generate();
4040
bool saveToFile(FILE *file);
4141
bool loadFromFile(FILE *file);

license.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Author: Fabian Vogt
2-
License: GPLv3: http://www.gnu.org/licenses/gpl-3.0.en.html
2+
License: GPLv3: http://www.gnu.org/licenses/gpl-3.0.en.html (Code only, not the resources)
33

4-
The terrain.png file has been downloaded from http://www.minecraftforum.net/topic/301268-16x146-and-146-sonicrumpets-mine-co-adventures-epicly-beautiful-textures/.
5-
The loading screen wallpaper is from http://wall.alphacoders.com/big.php?i=413114 and has been created by "miroha"
4+
The terrain.png file has been downloaded from http://bdcraft.net/purebdcraft-minecraft and is licensed under the Creative Commons Attribution 3.0 License.
5+
The loading screen wallpaper is from http://wall.alphacoders.com/big.php?i=413114 and has been created by "miroha".
66
The PerlinNoise class is from https://github.com/sol-prog/Perlin_Noise and licensed under the GPL v3.

main.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,7 @@ int main(int argc, char *argv[])
225225
bool key_held_down = true, can_jump = false, tp_had_contact = false, menu_held_down = true;
226226
int tp_last_x = 0, tp_last_y = 0;
227227
GLFix vy = 0; //Y-Velocity for gravity and jumps
228+
bool in_water = false;
228229
Position selection_pos; AABB::SIDE selection_side; Position selection_pos_abs; bool do_test = true; //For intersectsRay
229230

230231
//Resize the glass texture for use as selection overlay in the inventory
@@ -401,7 +402,10 @@ int main(int argc, char *argv[])
401402
can_jump = world.intersect(aabb_moved);
402403

403404
if(!can_jump)
405+
{
404406
y += vy;
407+
aabb = aabb_moved;
408+
}
405409
else if(vy > GLFix(0))
406410
{
407411
can_jump = false;
@@ -411,6 +415,11 @@ int main(int argc, char *argv[])
411415
vy = 0;
412416

413417
vy -= 5;
418+
419+
in_water = getBLOCK(world.getBlock((x / BLOCK_SIZE).floor(), ((y + eye_pos) / BLOCK_SIZE).floor(), (z / BLOCK_SIZE).floor())) == BLOCK_WATER;
420+
421+
if(in_water)
422+
can_jump = true;
414423
}
415424

416425
if(keyPressed(KEY_NSPIRE_5) && can_jump) //Jump
@@ -484,7 +493,7 @@ int main(int argc, char *argv[])
484493
{
485494
GLFix dx = fast_sin(yr)*fast_cos(xr), dy = -fast_sin(xr), dz = fast_cos(yr)*fast_cos(xr);
486495
GLFix dist;
487-
if(!world.intersectsRay(x, y + eye_pos, z, dx, dy, dz, selection_pos, selection_side, dist))
496+
if(!world.intersectsRay(x, y + eye_pos, z, dx, dy, dz, selection_pos, selection_side, dist, in_water))
488497
selection_side = AABB::NONE;
489498
else
490499
selection_pos_abs = {x + dx * dist, y + eye_pos + dy * dist, z + dz * dist};
@@ -532,7 +541,7 @@ int main(int argc, char *argv[])
532541
{
533542
//Only set the block if there's air
534543
const BLOCK_WDATA current_block = world.getBlock(pos.x, pos.y, pos.z);
535-
if(current_block == BLOCK_AIR)
544+
if(current_block == BLOCK_AIR || (in_water && getBLOCK(current_block) == BLOCK_WATER))
536545
{
537546
if(!global_block_renderer.isOriented(inventory_entries[current_inventory_slot]))
538547
world.changeBlock(pos.x, pos.y, pos.z, inventory_entries[current_inventory_slot]);

textures/terrain.h

Lines changed: 514 additions & 258 deletions
Large diffs are not rendered by default.

textures/terrain.png

157 KB
Loading

world.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ bool World::intersect(AABB &other) const
143143
return false;
144144
}
145145

146-
bool World::intersectsRay(GLFix x, GLFix y, GLFix z, GLFix dx, GLFix dy, GLFix dz, Position &result, AABB::SIDE &side, GLFix &dist) const
146+
bool World::intersectsRay(GLFix x, GLFix y, GLFix z, GLFix dx, GLFix dy, GLFix dz, Position &result, AABB::SIDE &side, GLFix &dist, bool ignore_water) const
147147
{
148148
dist = GLFix::maxValue();
149149
Position pos;
@@ -152,7 +152,7 @@ bool World::intersectsRay(GLFix x, GLFix y, GLFix z, GLFix dx, GLFix dy, GLFix d
152152
GLFix new_dist;
153153
AABB::SIDE new_side;
154154

155-
if(c->intersectsRay(x, y, z, dx, dy, dz, new_dist, pos, new_side))
155+
if(c->intersectsRay(x, y, z, dx, dy, dz, new_dist, pos, new_side, ignore_water))
156156
{
157157
if(new_dist > dist)
158158
continue;

world.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class World
2525
void setPosition(int x, int y, int z);
2626
bool blockAction(const int x, const int y, const int z);
2727
bool intersect(AABB &other) const;
28-
bool intersectsRay(GLFix x, GLFix y, GLFix z, GLFix dx, GLFix dy, GLFix dz, Position &result, AABB::SIDE &side, GLFix &dist) const;
28+
bool intersectsRay(GLFix x, GLFix y, GLFix z, GLFix dx, GLFix dy, GLFix dz, Position &result, AABB::SIDE &side, GLFix &dist, bool ignore_water) const;
2929
const PerlinNoise &noiseGenerator() const;
3030
void clear();
3131
bool loadFromFile(FILE *file);

0 commit comments

Comments
 (0)