Add a collidable flag to Material
This commit is contained in:
parent
3038596b27
commit
287867dbcd
|
@ -359,7 +359,10 @@ pub enum TintType {
|
||||||
define_blocks! {
|
define_blocks! {
|
||||||
Air {
|
Air {
|
||||||
props {},
|
props {},
|
||||||
material material::INVISIBLE,
|
material material::Material {
|
||||||
|
collidable: false,
|
||||||
|
.. material::INVISIBLE
|
||||||
|
},
|
||||||
model { ("minecraft", "air") },
|
model { ("minecraft", "air") },
|
||||||
collision vec![],
|
collision vec![],
|
||||||
}
|
}
|
||||||
|
@ -1395,7 +1398,6 @@ define_blocks! {
|
||||||
material material::NON_SOLID,
|
material material::NON_SOLID,
|
||||||
model { ("minecraft", "stone_button") },
|
model { ("minecraft", "stone_button") },
|
||||||
variant format!("facing={},powered={}", facing.as_string(), powered),
|
variant format!("facing={},powered={}", facing.as_string(), powered),
|
||||||
collision vec![],
|
|
||||||
}
|
}
|
||||||
SnowLayer {
|
SnowLayer {
|
||||||
props {
|
props {
|
||||||
|
@ -2535,7 +2537,6 @@ define_blocks! {
|
||||||
material material::NON_SOLID,
|
material material::NON_SOLID,
|
||||||
model { ("minecraft", "wooden_button") },
|
model { ("minecraft", "wooden_button") },
|
||||||
variant format!("facing={},powered={}", facing.as_string(), powered),
|
variant format!("facing={},powered={}", facing.as_string(), powered),
|
||||||
collision vec![],
|
|
||||||
}
|
}
|
||||||
Skull {
|
Skull {
|
||||||
props {
|
props {
|
||||||
|
|
|
@ -7,6 +7,7 @@ pub struct Material {
|
||||||
pub transparent: bool,
|
pub transparent: bool,
|
||||||
pub absorbed_light: u8,
|
pub absorbed_light: u8,
|
||||||
pub emitted_light: u8,
|
pub emitted_light: u8,
|
||||||
|
pub collidable: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub const INVISIBLE: Material = Material {
|
pub const INVISIBLE: Material = Material {
|
||||||
|
@ -17,6 +18,7 @@ pub const INVISIBLE: Material = Material {
|
||||||
transparent: false,
|
transparent: false,
|
||||||
absorbed_light: 0, // Special because of sky light
|
absorbed_light: 0, // Special because of sky light
|
||||||
emitted_light: 0,
|
emitted_light: 0,
|
||||||
|
collidable: true,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const SOLID: Material = Material {
|
pub const SOLID: Material = Material {
|
||||||
|
@ -27,6 +29,7 @@ pub const SOLID: Material = Material {
|
||||||
transparent: false,
|
transparent: false,
|
||||||
absorbed_light: 15,
|
absorbed_light: 15,
|
||||||
emitted_light: 0,
|
emitted_light: 0,
|
||||||
|
collidable: true,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const NON_SOLID: Material = Material {
|
pub const NON_SOLID: Material = Material {
|
||||||
|
|
|
@ -667,11 +667,13 @@ fn check_collisions(world: &world::World, position: &mut TargetPosition, last_po
|
||||||
for z in min_z .. max_z {
|
for z in min_z .. max_z {
|
||||||
for x in min_x .. max_x {
|
for x in min_x .. max_x {
|
||||||
let block = world.get_block(BPosition::new(x, y, z));
|
let block = world.get_block(BPosition::new(x, y, z));
|
||||||
for bb in block.get_collision_boxes() {
|
if block.get_material().collidable {
|
||||||
let bb = bb.add_v(cgmath::Vector3::new(x as f64, y as f64, z as f64));
|
for bb in block.get_collision_boxes() {
|
||||||
if bb.collides(&bounds) {
|
let bb = bb.add_v(cgmath::Vector3::new(x as f64, y as f64, z as f64));
|
||||||
bounds = bounds.move_out_of(bb, dir);
|
if bb.collides(&bounds) {
|
||||||
hit = true;
|
bounds = bounds.move_out_of(bb, dir);
|
||||||
|
hit = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue