Follow some of clippy's suggestions
This commit is contained in:
parent
c25dba3c8b
commit
c70f9548c6
|
@ -19,6 +19,7 @@ log = "0.3.5"
|
|||
cgmath = "0.7.0"
|
||||
lazy_static = "0.1.15"
|
||||
collision = {git = "https://github.com/csherratt/collision-rs", rev = "f80825e"}
|
||||
# clippy = "*"
|
||||
|
||||
[dependencies.steven_gl]
|
||||
path = "./gl"
|
||||
|
|
|
@ -61,7 +61,7 @@ pub struct EVPCipher {
|
|||
}
|
||||
|
||||
impl EVPCipher {
|
||||
pub fn new(key: &Vec<u8>, iv: &Vec<u8>, decrypt: bool) -> EVPCipher {
|
||||
pub fn new(key: &[u8], iv: &[u8], decrypt: bool) -> EVPCipher {
|
||||
unsafe {
|
||||
let mut e = EVPCipher {
|
||||
internal: ptr::Unique::new(EVP_CIPHER_CTX_new()),
|
||||
|
@ -131,7 +131,7 @@ pub struct PublicKey {
|
|||
}
|
||||
|
||||
impl PublicKey {
|
||||
pub fn new(data: &Vec<u8>) -> PublicKey {
|
||||
pub fn new(data: &[u8]) -> PublicKey {
|
||||
unsafe {
|
||||
let cert = d2i_RSA_PUBKEY(ptr::null_mut(), &data.as_ptr(), data.len() as libc::c_int);
|
||||
if cert.is_null() {
|
||||
|
|
|
@ -43,7 +43,7 @@ impl Var for CVar<String> {
|
|||
format!("\"{}\"", val.downcast_ref::<String>().unwrap())
|
||||
}
|
||||
|
||||
fn deserialize(&self, input: &String) -> Box<Any> {
|
||||
fn deserialize(&self, input: &str) -> Box<Any> {
|
||||
Box::new((&input[1..input.len() - 1]).to_owned())
|
||||
}
|
||||
|
||||
|
@ -57,7 +57,7 @@ impl Var for CVar<String> {
|
|||
|
||||
pub trait Var {
|
||||
fn serialize(&self, val: &Box<Any>) -> String;
|
||||
fn deserialize(&self, input: &String) -> Box<Any>;
|
||||
fn deserialize(&self, input: &str) -> Box<Any>;
|
||||
fn description(&self) -> &'static str;
|
||||
fn can_serialize(&self) -> bool;
|
||||
}
|
||||
|
@ -142,12 +142,10 @@ impl Console {
|
|||
} else {
|
||||
self.position = 0.0;
|
||||
}
|
||||
} else if self.position > -220.0 {
|
||||
self.position -= delta * 4.0;
|
||||
} else {
|
||||
if self.position > -220.0 {
|
||||
self.position -= delta * 4.0;
|
||||
} else {
|
||||
self.position = -220.0;
|
||||
}
|
||||
self.position = -220.0;
|
||||
}
|
||||
let w = match ui_container.mode {
|
||||
ui::Mode::Scaled => width,
|
||||
|
|
|
@ -252,7 +252,7 @@ impl Manager {
|
|||
Some(ref val) => if val.1 == entity.generation { &val.0 } else { return None },
|
||||
None => return None,
|
||||
};
|
||||
if !set.as_ref().map(|v| v.get(key.id)).unwrap_or(false) {
|
||||
if !set.as_ref().map_or(false, |v| v.get(key.id)) {
|
||||
return None;
|
||||
}
|
||||
|
||||
|
@ -276,7 +276,7 @@ impl Manager {
|
|||
Some(ref val) => if val.1 == entity.generation { &val.0 } else { return None },
|
||||
None => return None,
|
||||
};
|
||||
if !set.as_ref().map(|v| v.get(key.id)).unwrap_or(false) {
|
||||
if !set.as_ref().map_or(false, |v| v.get(key.id)) {
|
||||
return None;
|
||||
}
|
||||
|
||||
|
|
|
@ -171,8 +171,8 @@ impl fmt::Display for Color {
|
|||
}
|
||||
|
||||
impl Color {
|
||||
fn from_string(val: &String) -> Self {
|
||||
match val.as_ref() {
|
||||
fn from_string(val: &str) -> Self {
|
||||
match val {
|
||||
"black" => Color::Black,
|
||||
"dark_blue" => Color::DarkBlue,
|
||||
"dark_green" => Color::DarkGreen,
|
||||
|
@ -188,7 +188,6 @@ impl Color {
|
|||
"red" => Color::Red,
|
||||
"light_purple" => Color::LightPurple,
|
||||
"yellow" => Color::Yellow,
|
||||
"white" => Color::White,
|
||||
val if val.len() == 7 && val.as_bytes()[0] == b'#' => {
|
||||
let r = match u8::from_str_radix(&val[1..3], 16) {
|
||||
Ok(r) => r,
|
||||
|
@ -204,7 +203,7 @@ impl Color {
|
|||
};
|
||||
Color::RGB(r, g, b)
|
||||
}
|
||||
_ => Color::White,
|
||||
"white" | _ => Color::White,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
11
src/main.rs
11
src/main.rs
|
@ -14,6 +14,17 @@
|
|||
|
||||
#![recursion_limit="300"]
|
||||
#![feature(const_fn)]
|
||||
#![feature(plugin)]
|
||||
|
||||
// #![plugin(clippy)]
|
||||
// #![allow(similar_names)]
|
||||
// #![allow(new_without_default)]
|
||||
// #![allow(many_single_char_names)]
|
||||
// #![allow(if_not_else)]
|
||||
// #![allow(float_cmp)]
|
||||
// #![allow(single_char_pattern)]
|
||||
// #![allow(too_many_arguments)]
|
||||
// #![allow(cyclomatic_complexity)]
|
||||
|
||||
extern crate sdl2;
|
||||
extern crate image;
|
||||
|
|
|
@ -96,10 +96,8 @@ impl Factory {
|
|||
}
|
||||
if !missing {
|
||||
let mut m = models.write().unwrap();
|
||||
if !m.models.contains_key(&key) {
|
||||
if !m.load_model(plugin, name) {
|
||||
error!("Error loading model {}:{}", plugin, name);
|
||||
}
|
||||
if !m.models.contains_key(&key) && !m.load_model(plugin, name) {
|
||||
error!("Error loading model {}:{}", plugin, name);
|
||||
}
|
||||
if let Some(model) = m.models.get(&key) {
|
||||
if let Some(var) = model.get_variants(variant) {
|
||||
|
@ -207,14 +205,13 @@ impl Factory {
|
|||
},
|
||||
};
|
||||
let block_model: serde_json::Value = try_log!(opt serde_json::from_reader(file));
|
||||
let model = match self.parse_model(plugin, &block_model) {
|
||||
match self.parse_model(plugin, &block_model) {
|
||||
Some(val) => val,
|
||||
None => {
|
||||
error!("Failed to parse model {}", format!("models/{}.json", parent));
|
||||
return None
|
||||
},
|
||||
};
|
||||
model
|
||||
}
|
||||
} else {
|
||||
RawModel {
|
||||
texture_vars: HashMap::with_hasher(BuildHasherDefault::default()),
|
||||
|
@ -282,36 +279,39 @@ impl Factory {
|
|||
for dir in Direction::all() {
|
||||
if let Some(face) = faces.get(dir.as_string()) {
|
||||
element.faces[dir.index()] = Some(BlockFace {
|
||||
uv: face.find("uv").and_then(|v| v.as_array()).map(|v| [
|
||||
v[0].as_f64().unwrap(),
|
||||
v[1].as_f64().unwrap(),
|
||||
v[2].as_f64().unwrap(),
|
||||
v[3].as_f64().unwrap()
|
||||
]).unwrap_or_else(|| {
|
||||
let mut uv = [0.0, 0.0, 16.0, 16.0];
|
||||
match dir {
|
||||
Direction::North | Direction::South => {
|
||||
uv[0] = element.from[0];
|
||||
uv[2] = element.to[0];
|
||||
uv[1] = 16.0 - element.to[1];
|
||||
uv[3] = 16.0 - element.from[1];
|
||||
},
|
||||
Direction::West | Direction::East => {
|
||||
uv[0] = element.from[2];
|
||||
uv[2] = element.to[2];
|
||||
uv[1] = 16.0 - element.to[1];
|
||||
uv[3] = 16.0 - element.from[1];
|
||||
},
|
||||
Direction::Down | Direction::Up => {
|
||||
uv[0] = element.from[0];
|
||||
uv[2] = element.to[0];
|
||||
uv[1] = 16.0 - element.to[2];
|
||||
uv[3] = 16.0 - element.from[2];
|
||||
},
|
||||
_ => unreachable!(),
|
||||
}
|
||||
uv
|
||||
}),
|
||||
uv: face.find("uv").and_then(|v| v.as_array()).map_or_else(
|
||||
|| {
|
||||
let mut uv = [0.0, 0.0, 16.0, 16.0];
|
||||
match dir {
|
||||
Direction::North | Direction::South => {
|
||||
uv[0] = element.from[0];
|
||||
uv[2] = element.to[0];
|
||||
uv[1] = 16.0 - element.to[1];
|
||||
uv[3] = 16.0 - element.from[1];
|
||||
},
|
||||
Direction::West | Direction::East => {
|
||||
uv[0] = element.from[2];
|
||||
uv[2] = element.to[2];
|
||||
uv[1] = 16.0 - element.to[1];
|
||||
uv[3] = 16.0 - element.from[1];
|
||||
},
|
||||
Direction::Down | Direction::Up => {
|
||||
uv[0] = element.from[0];
|
||||
uv[2] = element.to[0];
|
||||
uv[1] = 16.0 - element.to[2];
|
||||
uv[3] = 16.0 - element.from[2];
|
||||
},
|
||||
_ => unreachable!(),
|
||||
}
|
||||
uv
|
||||
},
|
||||
|v| [
|
||||
v[0].as_f64().unwrap(),
|
||||
v[1].as_f64().unwrap(),
|
||||
v[2].as_f64().unwrap(),
|
||||
v[3].as_f64().unwrap()
|
||||
]
|
||||
),
|
||||
texture: face.find("texture")
|
||||
.and_then(|v| v.as_string())
|
||||
.map(|v| if v.starts_with('#') {
|
||||
|
@ -326,12 +326,10 @@ impl Factory {
|
|||
),
|
||||
rotation: face.find("rotation")
|
||||
.and_then(|v| v.as_i64())
|
||||
.map(|v| v as i32)
|
||||
.unwrap_or(0),
|
||||
.map_or(0, |v| v as i32),
|
||||
tint_index: face.find("tintindex")
|
||||
.and_then(|v| v.as_i64())
|
||||
.map(|v| v as i32)
|
||||
.unwrap_or(-1),
|
||||
.map_or(-1, |v| v as i32),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -339,11 +337,11 @@ impl Factory {
|
|||
|
||||
if let Some(rotation) = v.find("rotation") {
|
||||
element.rotation = Some(BlockRotation {
|
||||
origin: rotation.find("origin").and_then(|v| v.as_array()).map(|v| [
|
||||
origin: rotation.find("origin").and_then(|v| v.as_array()).map_or([8.0, 8.0, 8.0], |v| [
|
||||
v[0].as_f64().unwrap(),
|
||||
v[1].as_f64().unwrap(),
|
||||
v[2].as_f64().unwrap()
|
||||
]).unwrap_or([8.0, 8.0, 8.0]),
|
||||
]),
|
||||
axis: rotation.find("axis").and_then(|v| v.as_string()).unwrap_or("").to_owned(),
|
||||
angle: rotation.find("angle").and_then(|v| v.as_f64()).unwrap_or(0.0),
|
||||
rescale: rotation.find("rescale").and_then(|v| v.as_boolean()).unwrap_or(false),
|
||||
|
@ -682,7 +680,7 @@ struct RawModel {
|
|||
impl RawModel {
|
||||
fn lookup_texture(&self, name: &str) -> String {
|
||||
if !name.is_empty() && name.starts_with('#') {
|
||||
let tex = self.texture_vars.get(&name[1..]).map(|v| v.clone()).unwrap_or("".to_owned());
|
||||
let tex = self.texture_vars.get(&name[1..]).cloned().unwrap_or("".to_owned());
|
||||
return self.lookup_texture(&tex);
|
||||
}
|
||||
name.to_owned()
|
||||
|
|
|
@ -273,7 +273,7 @@ impl Serializable for Tag {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn write_string(buf: &mut io::Write, s: &String) -> io::Result<()> {
|
||||
pub fn write_string(buf: &mut io::Write, s: &str) -> io::Result<()> {
|
||||
let data = s.as_bytes();
|
||||
try!((data.len() as i16).write_to(buf));
|
||||
buf.write_all(data)
|
||||
|
|
|
@ -802,17 +802,16 @@ impl Conn {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn enable_encyption(&mut self, key: &Vec<u8>, decrypt: bool) {
|
||||
pub fn enable_encyption(&mut self, key: &[u8], decrypt: bool) {
|
||||
self.cipher = Option::Some(openssl::EVPCipher::new(key, key, decrypt));
|
||||
}
|
||||
|
||||
pub fn set_compresssion(&mut self, threshold: i32, read: bool) {
|
||||
self.compression_threshold = threshold;
|
||||
if !read {
|
||||
self.compression_write = Some(ZlibEncoder::new(io::Cursor::new(Vec::new()),
|
||||
flate2::Compression::Default));
|
||||
} else {
|
||||
if read {
|
||||
self.compression_read = Some(ZlibDecoder::new(io::Cursor::new(Vec::new())));
|
||||
} else {
|
||||
self.compression_write = Some(ZlibEncoder::new(io::Cursor::new(Vec::new()), flate2::Compression::Default));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -100,11 +100,11 @@ impl Profile {
|
|||
Ok(self)
|
||||
}
|
||||
|
||||
pub fn join_server(&self, server_id: &str, shared_key: &Vec<u8>, public_key: &Vec<u8>) -> Result<(), super::Error> {
|
||||
pub fn join_server(&self, server_id: &str, shared_key: &[u8], public_key: &[u8]) -> Result<(), super::Error> {
|
||||
let mut sha1 = openssl::SHA1::new();
|
||||
sha1.update(server_id.as_bytes());
|
||||
sha1.update(&shared_key[..]);
|
||||
sha1.update(&public_key[..]);
|
||||
sha1.update(shared_key);
|
||||
sha1.update(public_key);
|
||||
let mut hash = sha1.bytes();
|
||||
|
||||
// Mojang uses a hex method which allows for
|
||||
|
|
|
@ -59,7 +59,7 @@ state_packets!(
|
|||
text: String =,
|
||||
assume_command: bool =,
|
||||
has_target: bool =,
|
||||
target: Option<types::Position> = when(|p: &TabComplete| p.has_target == true),
|
||||
target: Option<types::Position> = when(|p: &TabComplete| p.has_target),
|
||||
}
|
||||
// ChatMessage is sent by the client when it sends a chat message or
|
||||
// executes a command (prefixed by '/').
|
||||
|
|
|
@ -785,9 +785,9 @@ impl TextureManager {
|
|||
|
||||
fn get_texture(&self, name: &str) -> Option<Texture> {
|
||||
if let Some(_) = name.find(':') {
|
||||
self.textures.get(name).map(|v| v.clone())
|
||||
self.textures.get(name).cloned()
|
||||
} else {
|
||||
self.textures.get(&format!("minecraft:{}", name)).map(|v| v.clone())
|
||||
self.textures.get(&format!("minecraft:{}", name)).cloned()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -178,8 +178,8 @@ impl UIState {
|
|||
self.count = 0;
|
||||
}
|
||||
|
||||
pub fn add_bytes(&mut self, data: &Vec<u8>) {
|
||||
self.data.extend(data);
|
||||
pub fn add_bytes(&mut self, data: &[u8]) {
|
||||
self.data.extend_from_slice(data);
|
||||
self.count += (data.len() / (28 * 4)) * 6;
|
||||
}
|
||||
|
||||
|
|
|
@ -59,9 +59,8 @@ impl Manager {
|
|||
pub fn open(&self, plugin: &str, name: &str) -> Option<Box<io::Read>> {
|
||||
for pack in self.packs.iter().rev() {
|
||||
let path = format!("assets/{}/{}", plugin, name);
|
||||
match pack.open(&path) {
|
||||
Some(val) => return Some(val),
|
||||
None => {}
|
||||
if let Some(val) = pack.open(&path) {
|
||||
return Some(val);
|
||||
}
|
||||
}
|
||||
None
|
||||
|
@ -71,9 +70,8 @@ impl Manager {
|
|||
let mut ret = Vec::new();
|
||||
for pack in self.packs.iter().rev() {
|
||||
let path = format!("assets/{}/{}", plugin, name);
|
||||
match pack.open(&path) {
|
||||
Some(val) => ret.push(val),
|
||||
None => {}
|
||||
if let Some(val) = pack.open(&path) {
|
||||
ret.push(val);
|
||||
}
|
||||
}
|
||||
ret
|
||||
|
|
|
@ -302,18 +302,16 @@ impl Server {
|
|||
if self.is_key_pressed(Keycode::LCtrl) {
|
||||
self.position.y -= speed * delta;
|
||||
}
|
||||
} else {
|
||||
if self.on_ground {
|
||||
if self.is_key_pressed(Keycode::Space) {
|
||||
self.v_speed = 0.15;
|
||||
} else {
|
||||
self.v_speed = 0.0;
|
||||
}
|
||||
} else if self.on_ground {
|
||||
if self.is_key_pressed(Keycode::Space) {
|
||||
self.v_speed = 0.15;
|
||||
} else {
|
||||
self.v_speed -= 0.01 * delta;
|
||||
if self.v_speed < -0.3 {
|
||||
self.v_speed = -0.3;
|
||||
}
|
||||
self.v_speed = 0.0;
|
||||
}
|
||||
} else {
|
||||
self.v_speed -= 0.01 * delta;
|
||||
if self.v_speed < -0.3 {
|
||||
self.v_speed = -0.3;
|
||||
}
|
||||
}
|
||||
self.position.x += forward * yaw.cos() * delta * speed;
|
||||
|
@ -527,7 +525,7 @@ impl Server {
|
|||
}
|
||||
|
||||
fn is_key_pressed(&self, key: Keycode) -> bool {
|
||||
self.pressed_keys.get(&key).map(|v| *v).unwrap_or(false)
|
||||
self.pressed_keys.get(&key).map_or(false, |v| *v)
|
||||
}
|
||||
|
||||
pub fn write_packet<T: protocol::PacketType>(&mut self, p: T) {
|
||||
|
|
|
@ -95,11 +95,11 @@ impl Map {
|
|||
let mask = (1 << self.bit_size) - 1;
|
||||
let ii = i % 64;
|
||||
let pos2 = (i + self.bit_size - 1) / 64;
|
||||
if pos2 != pos {
|
||||
if pos2 == pos {
|
||||
((self.bits[pos] >> ii) & mask) as usize
|
||||
} else {
|
||||
let used = 64 - ii;
|
||||
(((self.bits[pos] >> ii) | (self.bits[pos2] << used)) & mask) as usize
|
||||
} else {
|
||||
((self.bits[pos] >> ii) & mask) as usize
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -543,7 +543,7 @@ impl Container {
|
|||
let i = self.elements_list.iter()
|
||||
.map(|v| self.elements.get(v).unwrap())
|
||||
.position(|v| v.is_focused());
|
||||
let mut current = i.map(|v| v + 1).unwrap_or(0) % self.elements_list.len();
|
||||
let mut current = i.map_or(0, |v| v + 1) % self.elements_list.len();
|
||||
|
||||
// Clear the old focus
|
||||
if let Some(pos) = i {
|
||||
|
|
|
@ -129,7 +129,7 @@ macro_rules! define_blocks {
|
|||
let data: Option<usize> = ($datafunc).map(|v| v + (internal_ids::$name << 4));
|
||||
return data;
|
||||
)*
|
||||
return Some(internal_ids::$name << 4);
|
||||
Some(internal_ids::$name << 4)
|
||||
}
|
||||
)+
|
||||
}
|
||||
|
@ -174,7 +174,7 @@ macro_rules! define_blocks {
|
|||
$($fname,)*
|
||||
} => {
|
||||
$(return String::from($variant);)*
|
||||
return "normal".to_owned();
|
||||
"normal".to_owned()
|
||||
}
|
||||
)+
|
||||
}
|
||||
|
@ -188,7 +188,7 @@ macro_rules! define_blocks {
|
|||
$($fname,)*
|
||||
} => {
|
||||
$(return $tint;)*
|
||||
return TintType::Default;
|
||||
TintType::Default
|
||||
}
|
||||
)+
|
||||
}
|
||||
|
@ -202,10 +202,10 @@ macro_rules! define_blocks {
|
|||
$($fname,)*
|
||||
} => {
|
||||
$(return $collision;)*
|
||||
return vec![Aabb3::new(
|
||||
vec![Aabb3::new(
|
||||
Point3::new(0.0, 0.0, 0.0),
|
||||
Point3::new(1.0, 1.0, 1.0)
|
||||
)];
|
||||
)]
|
||||
}
|
||||
)+
|
||||
}
|
||||
|
@ -225,9 +225,9 @@ macro_rules! define_blocks {
|
|||
let $z = z;
|
||||
return $update_state;
|
||||
)*
|
||||
return Block::$name {
|
||||
Block::$name {
|
||||
$($fname: $fname,)*
|
||||
};
|
||||
}
|
||||
}
|
||||
)+
|
||||
}
|
||||
|
@ -2912,19 +2912,19 @@ impl StairShape {
|
|||
fn get_stair_info(world: &super::World, x: i32, y: i32, z: i32) -> Option<(Direction, StairHalf)> {
|
||||
use self::Block::*;
|
||||
match world.get_block(x, y, z) {
|
||||
OakStairs{facing, half, ..} => Some((facing, half)),
|
||||
StoneStairs{facing, half, ..} => Some((facing, half)),
|
||||
BrickStairs{facing, half, ..} => Some((facing, half)),
|
||||
StoneBrickStairs{facing, half, ..} => Some((facing, half)),
|
||||
NetherBrickStairs{facing, half, ..} => Some((facing, half)),
|
||||
SandstoneStairs{facing, half, ..} => Some((facing, half)),
|
||||
SpruceStairs{facing, half, ..} => Some((facing, half)),
|
||||
BirchStairs{facing, half, ..} => Some((facing, half)),
|
||||
JungleStairs{facing, half, ..} => Some((facing, half)),
|
||||
QuartzStairs{facing, half, ..} => Some((facing, half)),
|
||||
AcaciaStairs{facing, half, ..} => Some((facing, half)),
|
||||
DarkOakStairs{facing, half, ..} => Some((facing, half)),
|
||||
RedSandstoneStairs{facing, half, ..} => Some((facing, half)),
|
||||
OakStairs{facing, half, ..} |
|
||||
StoneStairs{facing, half, ..} |
|
||||
BrickStairs{facing, half, ..} |
|
||||
StoneBrickStairs{facing, half, ..} |
|
||||
NetherBrickStairs{facing, half, ..} |
|
||||
SandstoneStairs{facing, half, ..} |
|
||||
SpruceStairs{facing, half, ..} |
|
||||
BirchStairs{facing, half, ..} |
|
||||
JungleStairs{facing, half, ..} |
|
||||
QuartzStairs{facing, half, ..} |
|
||||
AcaciaStairs{facing, half, ..} |
|
||||
DarkOakStairs{facing, half, ..} |
|
||||
RedSandstoneStairs{facing, half, ..} |
|
||||
PurpurStairs{facing, half, ..} => Some((facing, half)),
|
||||
_ => None,
|
||||
}
|
||||
|
|
|
@ -52,10 +52,7 @@ impl World {
|
|||
|
||||
fn set_block_raw(&mut self, x: i32, y: i32, z: i32, b: block::Block) {
|
||||
let cpos = CPos(x >> 4, z >> 4);
|
||||
if !self.chunks.contains_key(&cpos) {
|
||||
self.chunks.insert(cpos, Chunk::new(cpos));
|
||||
}
|
||||
let chunk = self.chunks.get_mut(&cpos).unwrap();
|
||||
let chunk = self.chunks.entry(cpos).or_insert_with(|| Chunk::new(cpos));
|
||||
chunk.set_block(x & 0xF, y, z & 0xF, b);
|
||||
}
|
||||
|
||||
|
@ -130,7 +127,7 @@ impl World {
|
|||
if renderer.frustum.contains(bounds) == collision::Relation::Out {
|
||||
continue;
|
||||
}
|
||||
(sec.is_some(), sec.map(|v| v.cull_info).unwrap_or(chunk_builder::CullInfo::all_vis()))
|
||||
(sec.is_some(), sec.map_or(chunk_builder::CullInfo::all_vis(), |v| v.cull_info))
|
||||
} else {
|
||||
continue;
|
||||
};
|
||||
|
@ -361,7 +358,7 @@ impl World {
|
|||
|
||||
for i in 0 .. 4096 {
|
||||
let val = m.get(i);
|
||||
let block_id = block_map.get(&val).map(|v| *v as usize).unwrap_or(val);
|
||||
let block_id = block_map.get(&val).map_or(val, |v| *v as usize);
|
||||
let block = block::Block::by_vanilla_id(block_id);
|
||||
let i = i as i32;
|
||||
section.set_block(
|
||||
|
@ -586,6 +583,7 @@ impl Section {
|
|||
}
|
||||
|
||||
fn set_block(&mut self, x: i32, y: i32, z: i32, b: block::Block) {
|
||||
use std::collections::hash_map::Entry;
|
||||
let old = self.get_block(x, y, z);
|
||||
if old == b {
|
||||
return;
|
||||
|
@ -600,12 +598,13 @@ impl Section {
|
|||
}
|
||||
}
|
||||
|
||||
if !self.rev_block_map.contains_key(&b) {
|
||||
if let Entry::Vacant(entry) = self.rev_block_map.entry(b) {
|
||||
let mut found = false;
|
||||
let id = entry.insert(self.block_map.len());
|
||||
for (i, ref mut info) in self.block_map.iter_mut().enumerate() {
|
||||
if info.1 == 0 {
|
||||
info.0 = b;
|
||||
self.rev_block_map.insert(b, i);
|
||||
*id = i;
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
|
@ -616,7 +615,6 @@ impl Section {
|
|||
let new_blocks = self.blocks.resize(new_size);
|
||||
self.blocks = new_blocks;
|
||||
}
|
||||
self.rev_block_map.insert(b, self.block_map.len());
|
||||
self.block_map.push((b, 0));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue