Skip to content

Commit

Permalink
added error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
Shadowbee27 committed Nov 22, 2024
1 parent ae339bf commit a7eab6c
Show file tree
Hide file tree
Showing 7 changed files with 188 additions and 49 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "MC_calculator"
version = "1.1.1"
version = "1.2.0"
edition = "2021"

[dependencies]
21 changes: 21 additions & 0 deletions src/lib/check_for_error.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
pub fn check_for_error(data: f64) -> bool {
if data == 0.0 {
true
} else {
false
}
}
pub fn check_for_errors_p1(cords: [f64; 2]) -> bool {
if cords[0] == 0.0 {
true
} else {
false
}
}
pub fn check_for_errors_p2(cords: [f64; 2]) -> bool {
if cords[1] == 0.0 {
true
} else {
false
}
}
12 changes: 6 additions & 6 deletions src/lib/input.rs
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
use std::io;
pub fn portal_input() -> [f32; 2] {
let mut cords: [f32; 2] = [0.0, 0.0];
pub fn portal_input() -> [f64; 2] {
let mut cords: [f64; 2] = [0.0, 0.0];
println!("Please enter the x coordinate");
let mut x = String::new();
io::stdin().read_line(&mut x).expect("Failed to read line");
println!("Please enter the z coordinate");
let mut z = String::new();
io::stdin().read_line(&mut z).expect("Failed to read line");
cords[1] = z.trim().parse().unwrap();
cords[0] = x.trim().parse().unwrap();
cords[1] = z.trim().parse().unwrap_or(0.0);
cords[0] = x.trim().parse().unwrap_or(0.0);
cords
}
pub fn storage_input() -> f32 {
pub fn storage_input() -> f64 {
let mut input = String::new();
io::stdin()
.read_line(&mut input)
.expect("Failed to read line");
input.trim().parse().unwrap()
input.trim().parse().unwrap_or(0.0)
}
pub fn menu_input() -> String {
let mut input = String::new();
Expand Down
1 change: 1 addition & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::lib::input;
use std::process::exit;
pub mod lib {
pub mod check_for_error;
pub mod input;
}
pub mod opperations {
Expand Down
153 changes: 122 additions & 31 deletions src/opperations/item_opperations.rs
Original file line number Diff line number Diff line change
@@ -1,72 +1,163 @@
use crate::lib::check_for_error::check_for_error;
use crate::{input, menus};

pub fn stack_to_items() {
println!("Please enter the stack count that you want to turn into items");
let mut ic = input::storage_input();
ic *= 64.0;
println!("the item count is {}", ic);
menus::item_operations_input()
let is_error = check_for_error(ic);
match is_error {
true => {
println!("Invalid Input, please Input a valid number.");
stack_to_items()
}
false => {
ic *= 64.0;
println!("the item count is {}", ic);
menus::item_operations_input()
}
}
}
pub fn items_to_stack() {
println!("Please enter the item count that you want to turn into stacks");
let mut sc = input::storage_input();
sc /= 64.0;
println!("the stack count is {}", sc);
menus::item_operations_input()
let is_error = check_for_error(sc);
match is_error {
true => {
println!("Invalid Input, please Input a valid number.");
items_to_stack()
}
false => {
sc /= 64.0;
println!("the item count is {}", sc);
menus::item_operations_input()
}
}
}
pub fn items_to_shulker() {
println!("Please enter the item count that you want to turn into shulkerboxes");
let mut sc = input::storage_input();
sc /= 1728.0;
println!("the shulker count is {}", sc);
menus::item_operations_input()
let is_error = check_for_error(sc);
match is_error {
true => {
println!("Invalid Input, please Input a valid number.");
items_to_shulker()
}
false => {
sc /= 1728.0;
println!("the shulker count is {}", sc);
menus::item_operations_input()
}
}
}
pub fn shulker_to_items() {
println!("Please enter the shulker count that you want to turn into items");
let mut sc = input::storage_input();
sc *= 1728.0;
println!("the item count is {}", sc);
menus::item_operations_input()
let is_error = check_for_error(sc);
match is_error {
true => {
println!("Invalid Input, please Input a valid number.");
shulker_to_items()
}
false => {
sc *= 1728.0;
println!("the item count is {}", sc);
menus::item_operations_input()
}
}
}
pub fn items_to_dchests() {
println!("Please enter the shulker count that you want to turn into items");
let mut sc = input::storage_input();
sc /= 3456.0;
println!("the item count is {}", sc);
menus::item_operations_input()
let is_error = check_for_error(sc);
match is_error {
true => {
println!("Invalid Input, please Input a valid number.");
items_to_dchests()
}
false => {
sc /= 3456.0;
println!("the item count is {}", sc);
menus::item_operations_input()
}
}
}
pub fn dchests_to_items() {
println!("Please enter the shulker count that you want to turn into items");
let mut sc = input::storage_input();
sc *= 3456.0;
println!("the item count is {}", sc);
menus::item_operations_input()
let is_error = check_for_error(sc);
match is_error {
true => {
println!("Invalid Input, please Input a valid number.");
dchests_to_items()
}
false => {
sc *= 3456.0;
println!("the item count is {}", sc);
menus::item_operations_input()
}
}
}
pub fn stacks_to_dchests() {
println!("Please enter the shulker count that you want to turn into items");
let mut sc = input::storage_input();
sc /= 54.0;
println!("the item count is {}", sc);
menus::item_operations_input()
let is_error = check_for_error(sc);
match is_error {
true => {
println!("Invalid Input, please Input a valid number.");
stacks_to_dchests()
}
false => {
sc /= 54.0;
println!("the item count is {}", sc);
menus::item_operations_input()
}
}
}
pub fn dchests_to_stacks() {
println!("Please enter the shulker count that you want to turn into items");
let mut sc = input::storage_input();
sc *= 54.0;
println!("the item count is {}", sc);
menus::item_operations_input()
let is_error = check_for_error(sc);
match is_error {
true => {
println!("Invalid Input, please Input a valid number.");
dchests_to_stacks()
}
false => {
sc *= 54.0;
println!("the item count is {}", sc);
menus::item_operations_input()
}
}
}
pub fn dchests_to_fullshulker() {
println!("Please enter the shulker count that you want to turn into items");
let mut sc = input::storage_input();
sc *= 93312.0;
println!("the item count is {}", sc);
menus::item_operations_input()
let is_error = check_for_error(sc);
match is_error {
true => {
println!("Invalid Input, please Input a valid number.");
dchests_to_fullshulker()
}
false => {
sc *= 93312.0;
println!("the item count is {}", sc);
menus::item_operations_input()
}
}
}
pub fn fullshulker_to_dchests() {
println!("Please enter the shulker count that you want to turn into items");
let mut sc = input::storage_input();
sc /= 93312.0;
println!("the item count is {}", sc);
menus::item_operations_input()
}
let is_error = check_for_error(sc);
match is_error {
true => {
println!("Invalid Input, please Input a valid number.");
fullshulker_to_dchests()
}
false => {
sc /= 93312.0;
println!("the item count is {}", sc);
menus::item_operations_input()
}
}
}
46 changes: 36 additions & 10 deletions src/opperations/portal_opperations.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,41 @@
use crate::lib::check_for_error::check_for_error;
use crate::{input, menus};

pub fn portal_to_nether() {
let cords: [f32; 2] = input::portal_input();
let xn = cords[0] * 8.0;
let yn = cords[1] * 8.0;
println!("the x coordinate is {}, the y coordinate is {}", xn, yn);
menus::portal_input()
let cords: [f64; 2] = input::portal_input();
let is_error = check_for_error(cords[0]);
if is_error == true {
println!("Invalid Input, please Input a valid number.");
portal_to_nether()
} else {
let is_error2 = check_for_error(cords[1]);
if is_error2 == true {
println!("Invalid Input, please Input a valid number.");
portal_to_nether()
} else {
let xn = cords[0] * 8.0;
let yn = cords[1] * 8.0;
println!("the x coordinate is {}, the y coordinate is {}", xn, yn);
menus::portal_input();
}
}
}
pub fn portal_to_overworld() {
let cords: [f32; 2] = input::portal_input();
let xo: f32 = cords[0] / 8.0;
let yo: f32 = cords[1] / 8.0;
println!("the x coordinate is {}, the y coordinate is {}", xo, yo);
menus::portal_input()
let cords: [f64; 2] = input::portal_input();
let is_error = check_for_error(cords[0]);
if is_error == true {
println!("Invalid Input, please Input a valid number.");
portal_to_nether()
} else {
let is_error2 = check_for_error(cords[1]);
if is_error2 == true {
println!("Invalid Input, please Input a valid number.");
portal_to_overworld()
} else {
let xo = cords[0] / 8.0;
let yo = cords[1] / 8.0;
println!("the x coordinate is {}, the y coordinate is {}", xo, yo);
menus::portal_input();
}
}
}

0 comments on commit a7eab6c

Please sign in to comment.