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