From 287867dbcd49f3b256902db97fde1718f119c3c4 Mon Sep 17 00:00:00 2001 From: Thinkofname Date: Thu, 21 Apr 2016 21:47:39 +0100 Subject: [PATCH] Add a collidable flag to Material --- blocks/src/lib.rs | 7 ++++--- blocks/src/material.rs | 3 +++ src/entity/player.rs | 12 +++++++----- 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/blocks/src/lib.rs b/blocks/src/lib.rs index 6f80058..c2af944 100644 --- a/blocks/src/lib.rs +++ b/blocks/src/lib.rs @@ -359,7 +359,10 @@ pub enum TintType { define_blocks! { Air { props {}, - material material::INVISIBLE, + material material::Material { + collidable: false, + .. material::INVISIBLE + }, model { ("minecraft", "air") }, collision vec![], } @@ -1395,7 +1398,6 @@ define_blocks! { material material::NON_SOLID, model { ("minecraft", "stone_button") }, variant format!("facing={},powered={}", facing.as_string(), powered), - collision vec![], } SnowLayer { props { @@ -2535,7 +2537,6 @@ define_blocks! { material material::NON_SOLID, model { ("minecraft", "wooden_button") }, variant format!("facing={},powered={}", facing.as_string(), powered), - collision vec![], } Skull { props { diff --git a/blocks/src/material.rs b/blocks/src/material.rs index a921b50..a809bab 100644 --- a/blocks/src/material.rs +++ b/blocks/src/material.rs @@ -7,6 +7,7 @@ pub struct Material { pub transparent: bool, pub absorbed_light: u8, pub emitted_light: u8, + pub collidable: bool, } pub const INVISIBLE: Material = Material { @@ -17,6 +18,7 @@ pub const INVISIBLE: Material = Material { transparent: false, absorbed_light: 0, // Special because of sky light emitted_light: 0, + collidable: true, }; pub const SOLID: Material = Material { @@ -27,6 +29,7 @@ pub const SOLID: Material = Material { transparent: false, absorbed_light: 15, emitted_light: 0, + collidable: true, }; pub const NON_SOLID: Material = Material { diff --git a/src/entity/player.rs b/src/entity/player.rs index 3c86675..f5ed8a6 100644 --- a/src/entity/player.rs +++ b/src/entity/player.rs @@ -667,11 +667,13 @@ fn check_collisions(world: &world::World, position: &mut TargetPosition, last_po for z in min_z .. max_z { for x in min_x .. max_x { let block = world.get_block(BPosition::new(x, y, z)); - for bb in block.get_collision_boxes() { - let bb = bb.add_v(cgmath::Vector3::new(x as f64, y as f64, z as f64)); - if bb.collides(&bounds) { - bounds = bounds.move_out_of(bb, dir); - hit = true; + if block.get_material().collidable { + for bb in block.get_collision_boxes() { + let bb = bb.add_v(cgmath::Vector3::new(x as f64, y as f64, z as f64)); + if bb.collides(&bounds) { + bounds = bounds.move_out_of(bb, dir); + hit = true; + } } } }