diff --git a/Cargo.toml b/Cargo.toml index 8587c440..d219a987 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -64,6 +64,7 @@ glutin = "0.31" glutin-winit = "0.4" arc-swap = "1.7.0" +# phf = "0.11" [dependencies.leafish_resources] path = "./resources" diff --git a/protocol/src/item.rs b/protocol/src/item.rs index 02013c3f..d6f73334 100644 --- a/protocol/src/item.rs +++ b/protocol/src/item.rs @@ -128,8 +128,7 @@ impl ItemMeta { Some(tag) => tag .1 .as_compound() - .map(|comp| comp.get("display").clone().map(|val| val.as_compound())) - .flatten() + .and_then(|comp| comp.get("display").map(|val| val.as_compound())) .flatten(), None => None, } @@ -137,29 +136,26 @@ impl ItemMeta { pub fn display_name(&self) -> Option { self.display() - .map(|val| { + .and_then(|val| { val.get("Name") - .map(|name| name.as_str().map(|name| Component::from_str(name))) + .map(|name| name.as_str().map(Component::from_str)) }) .flatten() - .flatten() } pub fn lore(&self) -> Vec { self.display() - .map(|val| { + .and_then(|val| { val.get("Lore").map(|lore| { lore.as_list().map(|lore| { lore.iter() - .map(|line| line.as_str().map(|line| Component::from_str(line))) - .flatten() + .filter_map(|line| line.as_str().map(Component::from_str)) .collect::>() }) }) }) .flatten() - .flatten() - .unwrap_or(vec![]) + .unwrap_or_default() } pub fn repair_cost(&self) -> Option { @@ -167,8 +163,7 @@ impl ItemMeta { Some(tag) => tag .1 .as_compound() - .map(|comp| comp.get("RepairCost").clone().map(|val| val.as_int())) - .flatten() + .and_then(|comp| comp.get("RepairCost").map(|val| val.as_int())) .flatten(), None => None, } @@ -179,36 +174,26 @@ impl ItemMeta { Some(tag) => tag .1 .as_compound() - .map(|comp| { + .and_then(|comp| { comp.get("ench").map(|ench| { ench.as_list().map(|enchs| { enchs .iter() - .map(|ench| { - ench.as_compound() - .map(|ench| { - ench.get("lvl") - .map(|lvl| lvl.as_short()) - .flatten() - .zip( - ench.get("id") - .map(|id| id.as_short()) - .flatten(), - ) - .map(|(level, id)| { - Enchantment::new(id as u16, level) - }) - .flatten() - }) - .flatten() + .filter_map(|ench| { + ench.as_compound().and_then(|ench| { + ench.get("lvl") + .and_then(|lvl| lvl.as_short()) + .zip(ench.get("id").and_then(|id| id.as_short())) + .and_then(|(level, id)| { + Enchantment::new(id as u16, level) + }) + }) }) - .flatten() .collect::>() }) }) }) .flatten() - .flatten() .unwrap_or(vec![]), None => vec![], } diff --git a/protocol/src/protocol/packet.rs b/protocol/src/protocol/packet.rs index 185afc36..fe98be6b 100644 --- a/protocol/src/protocol/packet.rs +++ b/protocol/src/protocol/packet.rs @@ -3421,8 +3421,8 @@ pub fn send_position( pub fn send_look(conn: &mut Conn, yaw: f32, pitch: f32, on_ground: bool) -> Result<(), Error> { conn.write_packet(crate::protocol::packet::play::serverbound::PlayerLook { - yaw, - pitch, + yaw: -yaw * (180.0 / PI), + pitch: (-pitch * (180.0 / PI) + 180.0).min(90.0), // used to make sure, that we don't send impossible pitch values on_ground, }) } diff --git a/src/inventory/material/versions/mapping1_10_2.rs b/src/inventory/material/versions/mapping1_10_2.rs index 9dcc5271..055b3d7a 100644 --- a/src/inventory/material/versions/mapping1_10_2.rs +++ b/src/inventory/material/versions/mapping1_10_2.rs @@ -1,3 +1,4 @@ +use super::mapping1_12_2::*; use crate::inventory::Material; pub fn to_id(mat: Material) -> u16 { @@ -430,53 +431,53 @@ pub fn to_id(mat: Material) -> u16 { } } -pub fn to_material(material_id: u16) -> Material { +pub fn to_material(material_id: u16, damage: isize) -> Material { match material_id { 0 => Material::Air, - 1 => Material::Stone, + 1 => map_stone(damage), 2 => Material::Grass, - 3 => Material::Dirt, + 3 => map_dirt(damage), 4 => Material::Cobblestone, - 5 => Material::Wood, - 6 => Material::Sapling, + 5 => map_planks(damage), + 6 => map_sapling(damage), 7 => Material::Bedrock, 8 => Material::Water, 9 => Material::StationaryWater, 10 => Material::Lava, 11 => Material::StationaryLava, - 12 => Material::Sand, + 12 => map_sand(damage), 13 => Material::Gravel, 14 => Material::GoldOre, 15 => Material::IronOre, 16 => Material::CoalOre, - 17 => Material::Log, - 18 => Material::Leaves, - 19 => Material::Sponge, + 17 => map_log(damage), + 18 => map_leaves(damage), + 19 => map_sponge(damage), 20 => Material::Glass, 21 => Material::LapisOre, 22 => Material::LapisBlock, 23 => Material::Dispenser, - 24 => Material::Sandstone, + 24 => map_sandstone(damage), 25 => Material::NoteBlock, 26 => Material::BedBlock, 27 => Material::PoweredRail, 28 => Material::DetectorRail, 29 => Material::PistonStickyBase, 30 => Material::Web, - 31 => Material::LongGrass, + 31 => map_tall_grass(damage), 32 => Material::DeadBush, 33 => Material::PistonBase, 34 => Material::PistonExtension, - 35 => Material::Wool, + 35 => map_wool(damage), 36 => Material::PistonMovingPiece, 37 => Material::YellowFlower, - 38 => Material::RedRose, + 38 => map_flower(damage), 39 => Material::BrownMushroom, 40 => Material::RedMushroom, 41 => Material::GoldBlock, 42 => Material::IronBlock, 43 => Material::DoubleStep, - 44 => Material::Step, + 44 => map_stone_slab(damage), 45 => Material::Brick, 46 => Material::Tnt, 47 => Material::Bookshelf, @@ -527,10 +528,10 @@ pub fn to_material(material_id: u16) -> Material { 92 => Material::CakeBlock, 93 => Material::DiodeBlockOff, 94 => Material::DiodeBlockOn, - 95 => Material::StainedGlass, + 95 => map_glass(damage), 96 => Material::TrapDoor, - 97 => Material::MonsterEggs, - 98 => Material::SmoothBrick, + 97 => map_infested_stone(damage), + 98 => map_stone_bricks(damage), 99 => Material::HugeMushroom1, 100 => Material::HugeMushroom2, 101 => Material::IronFence, @@ -558,7 +559,7 @@ pub fn to_material(material_id: u16) -> Material { 123 => Material::RedstoneLampOff, 124 => Material::RedstoneLampOn, 125 => Material::WoodDoubleStep, - 126 => Material::WoodStep, + 126 => map_wood_slab(damage), 127 => Material::Cocoa, 128 => Material::SandstoneStairs, 129 => Material::EmeraldOre, @@ -571,13 +572,13 @@ pub fn to_material(material_id: u16) -> Material { 136 => Material::JungleWoodStairs, 137 => Material::Command, 138 => Material::Beacon, - 139 => Material::CobbleWall, + 139 => map_cobble_wall(damage), 140 => Material::FlowerPot, 141 => Material::Carrot, 142 => Material::Potato, 143 => Material::WoodButton, - 144 => Material::Skull, - 145 => Material::Anvil, + 144 => map_skull(damage), + 145 => map_anvil(damage), 146 => Material::TrappedChest, 147 => Material::GoldPlate, 148 => Material::IronPlate, @@ -587,31 +588,31 @@ pub fn to_material(material_id: u16) -> Material { 152 => Material::RedstoneBlock, 153 => Material::QuartzOre, 154 => Material::Hopper, - 155 => Material::QuartzBlock, + 155 => map_quartz(damage), 156 => Material::QuartzStairs, 157 => Material::ActivatorRail, 158 => Material::Dropper, - 159 => Material::StainedClay, - 160 => Material::StainedGlassPane, - 161 => Material::Leaves2, - 162 => Material::Log2, + 159 => map_terracotta(damage), + 160 => map_glass_pane(damage), + 161 => map_leaves2(damage), + 162 => map_log2(damage), 163 => Material::AcaciaStairs, 164 => Material::DarkOakStairs, 165 => Material::SlimeBlock, 166 => Material::Barrier, 167 => Material::IronTrapdoor, - 168 => Material::Prismarine, + 168 => map_prismarine(damage), 169 => Material::SeaLantern, 170 => Material::HayBlock, - 171 => Material::Carpet, + 171 => map_carpet(damage), 172 => Material::HardClay, 173 => Material::CoalBlock, 174 => Material::PackedIce, - 175 => Material::DoublePlant, + 175 => map_double_plant(damage), 176 => Material::StandingBanner, 177 => Material::WallBanner, 178 => Material::DaylightDetectorInverted, - 179 => Material::RedSandstone, + 179 => map_red_sandstone(damage), 180 => Material::RedSandstoneStairs, 181 => Material::DoubleStoneSlab2, 182 => Material::StoneSlab2, @@ -717,7 +718,7 @@ pub fn to_material(material_id: u16) -> Material { 319 => Material::Pork, 320 => Material::GrilledPork, 321 => Material::Painting, - 322 => Material::GoldenApple, + 322 => map_gapple(damage), 323 => Material::Sign, 324 => Material::WoodDoor, 325 => Material::Bucket, @@ -744,13 +745,13 @@ pub fn to_material(material_id: u16) -> Material { 346 => Material::FishingRod, 347 => Material::Watch, 348 => Material::GlowstoneDust, - 349 => Material::RawFish, - 350 => Material::CookedFish, - 351 => Material::InkSack, + 349 => map_fish(damage), + 350 => map_cooked_fish(damage), + 351 => map_dye(damage), 352 => Material::Bone, 353 => Material::Sugar, 354 => Material::Cake, - 355 => Material::Bed, + 355 => map_bed(damage), 356 => Material::Diode, 357 => Material::Cookie, 358 => Material::Map, @@ -820,7 +821,7 @@ pub fn to_material(material_id: u16) -> Material { 422 => Material::CommandMinecart, 423 => Material::Mutton, 424 => Material::CookedMutton, - 425 => Material::Banner, + 425 => map_banner(damage), 426 => Material::EndCrystal, 427 => Material::SpruceDoorItem, 428 => Material::BirchDoorItem, diff --git a/src/inventory/material/versions/mapping1_11_2.rs b/src/inventory/material/versions/mapping1_11_2.rs index 03c68ae1..632500d5 100644 --- a/src/inventory/material/versions/mapping1_11_2.rs +++ b/src/inventory/material/versions/mapping1_11_2.rs @@ -1,3 +1,4 @@ +use super::mapping1_12_2::*; use crate::inventory::Material; pub fn to_id(mat: Material) -> u16 { @@ -450,53 +451,53 @@ pub fn to_id(mat: Material) -> u16 { } } -pub fn to_material(material_id: u16) -> Material { +pub fn to_material(material_id: u16, damage: isize) -> Material { match material_id { 0 => Material::Air, - 1 => Material::Stone, + 1 => map_stone(damage), 2 => Material::Grass, - 3 => Material::Dirt, + 3 => map_dirt(damage), 4 => Material::Cobblestone, - 5 => Material::Wood, - 6 => Material::Sapling, + 5 => map_planks(damage), + 6 => map_sapling(damage), 7 => Material::Bedrock, 8 => Material::Water, 9 => Material::StationaryWater, 10 => Material::Lava, 11 => Material::StationaryLava, - 12 => Material::Sand, + 12 => map_sand(damage), 13 => Material::Gravel, 14 => Material::GoldOre, 15 => Material::IronOre, 16 => Material::CoalOre, - 17 => Material::Log, - 18 => Material::Leaves, - 19 => Material::Sponge, + 17 => map_log(damage), + 18 => map_leaves(damage), + 19 => map_sponge(damage), 20 => Material::Glass, 21 => Material::LapisOre, 22 => Material::LapisBlock, 23 => Material::Dispenser, - 24 => Material::Sandstone, + 24 => map_sandstone(damage), 25 => Material::NoteBlock, 26 => Material::BedBlock, 27 => Material::PoweredRail, 28 => Material::DetectorRail, 29 => Material::PistonStickyBase, 30 => Material::Web, - 31 => Material::LongGrass, + 31 => map_tall_grass(damage), 32 => Material::DeadBush, 33 => Material::PistonBase, 34 => Material::PistonExtension, - 35 => Material::Wool, + 35 => map_wool(damage), 36 => Material::PistonMovingPiece, 37 => Material::YellowFlower, - 38 => Material::RedRose, + 38 => map_flower(damage), 39 => Material::BrownMushroom, 40 => Material::RedMushroom, 41 => Material::GoldBlock, 42 => Material::IronBlock, 43 => Material::DoubleStep, - 44 => Material::Step, + 44 => map_stone_slab(damage), 45 => Material::Brick, 46 => Material::Tnt, 47 => Material::Bookshelf, @@ -547,10 +548,10 @@ pub fn to_material(material_id: u16) -> Material { 92 => Material::CakeBlock, 93 => Material::DiodeBlockOff, 94 => Material::DiodeBlockOn, - 95 => Material::StainedGlass, + 95 => map_glass(damage), 96 => Material::TrapDoor, - 97 => Material::MonsterEggs, - 98 => Material::SmoothBrick, + 97 => map_infested_stone(damage), + 98 => map_stone_bricks(damage), 99 => Material::HugeMushroom1, 100 => Material::HugeMushroom2, 101 => Material::IronFence, @@ -578,7 +579,7 @@ pub fn to_material(material_id: u16) -> Material { 123 => Material::RedstoneLampOff, 124 => Material::RedstoneLampOn, 125 => Material::WoodDoubleStep, - 126 => Material::WoodStep, + 126 => map_wood_slab(damage), 127 => Material::Cocoa, 128 => Material::SandstoneStairs, 129 => Material::EmeraldOre, @@ -591,13 +592,13 @@ pub fn to_material(material_id: u16) -> Material { 136 => Material::JungleWoodStairs, 137 => Material::Command, 138 => Material::Beacon, - 139 => Material::CobbleWall, + 139 => map_cobble_wall(damage), 140 => Material::FlowerPot, 141 => Material::Carrot, 142 => Material::Potato, 143 => Material::WoodButton, - 144 => Material::Skull, - 145 => Material::Anvil, + 144 => map_skull(damage), + 145 => map_anvil(damage), 146 => Material::TrappedChest, 147 => Material::GoldPlate, 148 => Material::IronPlate, @@ -607,31 +608,31 @@ pub fn to_material(material_id: u16) -> Material { 152 => Material::RedstoneBlock, 153 => Material::QuartzOre, 154 => Material::Hopper, - 155 => Material::QuartzBlock, + 155 => map_quartz(damage), 156 => Material::QuartzStairs, 157 => Material::ActivatorRail, 158 => Material::Dropper, - 159 => Material::StainedClay, - 160 => Material::StainedGlassPane, - 161 => Material::Leaves2, - 162 => Material::Log2, + 159 => map_terracotta(damage), + 160 => map_glass_pane(damage), + 161 => map_leaves2(damage), + 162 => map_log2(damage), 163 => Material::AcaciaStairs, 164 => Material::DarkOakStairs, 165 => Material::SlimeBlock, 166 => Material::Barrier, 167 => Material::IronTrapdoor, - 168 => Material::Prismarine, + 168 => map_prismarine(damage), 169 => Material::SeaLantern, 170 => Material::HayBlock, - 171 => Material::Carpet, + 171 => map_carpet(damage), 172 => Material::HardClay, 173 => Material::CoalBlock, 174 => Material::PackedIce, - 175 => Material::DoublePlant, + 175 => map_double_plant(damage), 176 => Material::StandingBanner, 177 => Material::WallBanner, 178 => Material::DaylightDetectorInverted, - 179 => Material::RedSandstone, + 179 => map_red_sandstone(damage), 180 => Material::RedSandstoneStairs, 181 => Material::DoubleStoneSlab2, 182 => Material::StoneSlab2, @@ -754,7 +755,7 @@ pub fn to_material(material_id: u16) -> Material { 319 => Material::Pork, 320 => Material::GrilledPork, 321 => Material::Painting, - 322 => Material::GoldenApple, + 322 => map_gapple(damage), 323 => Material::Sign, 324 => Material::WoodDoor, 325 => Material::Bucket, @@ -781,13 +782,13 @@ pub fn to_material(material_id: u16) -> Material { 346 => Material::FishingRod, 347 => Material::Watch, 348 => Material::GlowstoneDust, - 349 => Material::RawFish, - 350 => Material::CookedFish, - 351 => Material::InkSack, + 349 => map_fish(damage), + 350 => map_cooked_fish(damage), + 351 => map_dye(damage), 352 => Material::Bone, 353 => Material::Sugar, 354 => Material::Cake, - 355 => Material::Bed, + 355 => map_bed(damage), 356 => Material::Diode, 357 => Material::Cookie, 358 => Material::Map, @@ -857,7 +858,7 @@ pub fn to_material(material_id: u16) -> Material { 422 => Material::CommandMinecart, 423 => Material::Mutton, 424 => Material::CookedMutton, - 425 => Material::Banner, + 425 => map_banner(damage), 426 => Material::EndCrystal, 427 => Material::SpruceDoorItem, 428 => Material::BirchDoorItem, diff --git a/src/inventory/material/versions/mapping1_12_2.rs b/src/inventory/material/versions/mapping1_12_2.rs index 894c28c0..fb25ceca 100644 --- a/src/inventory/material/versions/mapping1_12_2.rs +++ b/src/inventory/material/versions/mapping1_12_2.rs @@ -469,53 +469,53 @@ pub fn to_id(mat: Material) -> u16 { } } -pub fn to_material(material_id: u16) -> Material { +pub fn to_material(material_id: u16, damage: isize) -> Material { match material_id { 0 => Material::Air, - 1 => Material::Stone, + 1 => map_stone(damage), 2 => Material::Grass, - 3 => Material::Dirt, + 3 => map_dirt(damage), 4 => Material::Cobblestone, - 5 => Material::Wood, - 6 => Material::Sapling, + 5 => map_planks(damage), + 6 => map_sapling(damage), 7 => Material::Bedrock, 8 => Material::Water, 9 => Material::StationaryWater, 10 => Material::Lava, 11 => Material::StationaryLava, - 12 => Material::Sand, + 12 => map_sand(damage), 13 => Material::Gravel, 14 => Material::GoldOre, 15 => Material::IronOre, 16 => Material::CoalOre, - 17 => Material::Log, - 18 => Material::Leaves, - 19 => Material::Sponge, + 17 => map_log(damage), + 18 => map_leaves(damage), + 19 => map_sponge(damage), 20 => Material::Glass, 21 => Material::LapisOre, 22 => Material::LapisBlock, 23 => Material::Dispenser, - 24 => Material::Sandstone, + 24 => map_sandstone(damage), 25 => Material::NoteBlock, 26 => Material::BedBlock, 27 => Material::PoweredRail, 28 => Material::DetectorRail, 29 => Material::PistonStickyBase, 30 => Material::Web, - 31 => Material::LongGrass, + 31 => map_tall_grass(damage), 32 => Material::DeadBush, 33 => Material::PistonBase, 34 => Material::PistonExtension, - 35 => Material::Wool, + 35 => map_wool(damage), 36 => Material::PistonMovingPiece, 37 => Material::YellowFlower, - 38 => Material::RedRose, + 38 => map_flower(damage), 39 => Material::BrownMushroom, 40 => Material::RedMushroom, 41 => Material::GoldBlock, 42 => Material::IronBlock, 43 => Material::DoubleStep, - 44 => Material::Step, + 44 => map_stone_slab(damage), 45 => Material::Brick, 46 => Material::Tnt, 47 => Material::Bookshelf, @@ -566,10 +566,10 @@ pub fn to_material(material_id: u16) -> Material { 92 => Material::CakeBlock, 93 => Material::DiodeBlockOff, 94 => Material::DiodeBlockOn, - 95 => Material::StainedGlass, + 95 => map_glass(damage), 96 => Material::TrapDoor, - 97 => Material::MonsterEggs, - 98 => Material::SmoothBrick, + 97 => map_infested_stone(damage), + 98 => map_stone_bricks(damage), 99 => Material::HugeMushroom1, 100 => Material::HugeMushroom2, 101 => Material::IronFence, @@ -597,7 +597,7 @@ pub fn to_material(material_id: u16) -> Material { 123 => Material::RedstoneLampOff, 124 => Material::RedstoneLampOn, 125 => Material::WoodDoubleStep, - 126 => Material::WoodStep, + 126 => map_wood_slab(damage), 127 => Material::Cocoa, 128 => Material::SandstoneStairs, 129 => Material::EmeraldOre, @@ -610,13 +610,13 @@ pub fn to_material(material_id: u16) -> Material { 136 => Material::JungleWoodStairs, 137 => Material::Command, 138 => Material::Beacon, - 139 => Material::CobbleWall, + 139 => map_cobble_wall(damage), 140 => Material::FlowerPot, 141 => Material::Carrot, 142 => Material::Potato, 143 => Material::WoodButton, - 144 => Material::Skull, - 145 => Material::Anvil, + 144 => map_skull(damage), + 145 => map_anvil(damage), 146 => Material::TrappedChest, 147 => Material::GoldPlate, 148 => Material::IronPlate, @@ -626,31 +626,31 @@ pub fn to_material(material_id: u16) -> Material { 152 => Material::RedstoneBlock, 153 => Material::QuartzOre, 154 => Material::Hopper, - 155 => Material::QuartzBlock, + 155 => map_quartz(damage), 156 => Material::QuartzStairs, 157 => Material::ActivatorRail, 158 => Material::Dropper, - 159 => Material::StainedClay, - 160 => Material::StainedGlassPane, - 161 => Material::Leaves2, - 162 => Material::Log2, + 159 => map_terracotta(damage), + 160 => map_glass_pane(damage), + 161 => map_leaves2(damage), + 162 => map_log2(damage), 163 => Material::AcaciaStairs, 164 => Material::DarkOakStairs, 165 => Material::SlimeBlock, 166 => Material::Barrier, 167 => Material::IronTrapdoor, - 168 => Material::Prismarine, + 168 => map_prismarine(damage), 169 => Material::SeaLantern, 170 => Material::HayBlock, - 171 => Material::Carpet, + 171 => map_carpet(damage), 172 => Material::HardClay, 173 => Material::CoalBlock, 174 => Material::PackedIce, - 175 => Material::DoublePlant, + 175 => map_double_plant(damage), 176 => Material::StandingBanner, 177 => Material::WallBanner, 178 => Material::DaylightDetectorInverted, - 179 => Material::RedSandstone, + 179 => map_red_sandstone(damage), 180 => Material::RedSandstoneStairs, 181 => Material::DoubleStoneSlab2, 182 => Material::StoneSlab2, @@ -722,8 +722,8 @@ pub fn to_material(material_id: u16) -> Material { 248 => Material::GreenGlazedTerracotta, 249 => Material::RedGlazedTerracotta, 250 => Material::BlackGlazedTerracotta, - 251 => Material::Concrete, - 252 => Material::ConcretePowder, + 251 => map_concrete(damage), + 252 => map_concrete_powder(damage), 255 => Material::StructureBlock, 256 => Material::IronSpade, 257 => Material::IronPickaxe, @@ -791,7 +791,7 @@ pub fn to_material(material_id: u16) -> Material { 319 => Material::Pork, 320 => Material::GrilledPork, 321 => Material::Painting, - 322 => Material::GoldenApple, + 322 => map_gapple(damage), 323 => Material::Sign, 324 => Material::WoodDoor, 325 => Material::Bucket, @@ -818,13 +818,13 @@ pub fn to_material(material_id: u16) -> Material { 346 => Material::FishingRod, 347 => Material::Watch, 348 => Material::GlowstoneDust, - 349 => Material::RawFish, - 350 => Material::CookedFish, - 351 => Material::InkSack, + 349 => map_fish(damage), + 350 => map_cooked_fish(damage), + 351 => map_dye(damage), 352 => Material::Bone, 353 => Material::Sugar, 354 => Material::Cake, - 355 => Material::Bed, + 355 => map_bed(damage), 356 => Material::Diode, 357 => Material::Cookie, 358 => Material::Map, @@ -894,7 +894,7 @@ pub fn to_material(material_id: u16) -> Material { 422 => Material::CommandMinecart, 423 => Material::Mutton, 424 => Material::CookedMutton, - 425 => Material::Banner, + 425 => map_banner(damage), 426 => Material::EndCrystal, 427 => Material::SpruceDoorItem, 428 => Material::BirchDoorItem, @@ -1061,3 +1061,494 @@ pub fn get_stack_size(mat: Material) -> u8 { _ => 64, } } + +pub(crate) fn map_log(damage: isize) -> Material { + match damage { + 0 => Material::OakLog, + 1 => Material::SpruceLog, + 2 => Material::BirchLog, + 3 => Material::JungleLog, + _ => Material::Air, + } +} + +pub(crate) fn map_log2(damage: isize) -> Material { + match damage { + 0 => Material::AcaciaLog, + 1 => Material::DarkOakLog, + _ => Material::Air, + } +} + +pub(crate) fn map_prismarine(damage: isize) -> Material { + match damage { + 0 => Material::Prismarine, + 1 => Material::PrismarineBricks, + 2 => Material::DarkPrismarine, + _ => Material::Air, + } +} + +pub(crate) fn map_planks(damage: isize) -> Material { + match damage { + 0 => Material::OakPlanks, + 1 => Material::SprucePlanks, + 2 => Material::BirchPlanks, + 3 => Material::JunglePlanks, + 4 => Material::AcaciaPlanks, + 5 => Material::DarkOakPlanks, + _ => Material::Air, + } +} + +pub(crate) fn map_infested_stone(damage: isize) -> Material { + match damage { + 0 => Material::InfestedStone, + 1 => Material::InfestedCobblestone, + 2 => Material::InfestedStoneBricks, + 3 => Material::InfestedMossyStoneBricks, + 4 => Material::InfestedCrackedStoneBricks, + 5 => Material::InfestedChiseledStoneBricks, + _ => Material::Air, + } +} + +pub(crate) fn map_quartz(damage: isize) -> Material { + match damage { + 0 => Material::QuartzBlock, + 1 => Material::ChiseledQuartzBlock, + 2 => Material::QuartzPillar, + _ => Material::Air, + } +} + +pub(crate) fn map_flower(damage: isize) -> Material { + match damage { + 0 => Material::Poppy, + 1 => Material::BlueOrchid, + 2 => Material::Allium, + 3 => Material::AzureBluet, + 4 => Material::OrangeTulip, + 5 => Material::WhiteTulip, + 6 => Material::PinkTulip, + 7 => Material::PinkTulip, + 8 => Material::OxeyeDaisy, + _ => Material::Air, + } +} + +pub(crate) fn map_red_sandstone(damage: isize) -> Material { + match damage { + 0 => Material::RedSandstone, + 1 => Material::ChiseledRedSandstone, + 2 => Material::SmoothRedSandstone, + _ => Material::Air, + } +} + +pub(crate) fn map_anvil(damage: isize) -> Material { + match damage { + 0 => Material::Anvil, + 1 => Material::ChippedAnvil, + 2 => Material::DamagedAnvil, + _ => Material::Air, + } +} + +pub(crate) fn map_banner(damage: isize) -> Material { + match damage { + 0 => Material::BlackBanner, + 1 => Material::RedBanner, + 2 => Material::GreenBanner, + 3 => Material::BrownBanner, + 4 => Material::BlueBanner, + 5 => Material::PurpleBanner, + 6 => Material::CyanBanner, + 7 => Material::LightGrayBanner, + 8 => Material::GrayBanner, + 9 => Material::PinkBanner, + 10 => Material::LimeBanner, + 11 => Material::YellowBanner, + 12 => Material::LightBlueBanner, + 13 => Material::MagentaBanner, + 14 => Material::OrangeBanner, + 15 => Material::WhiteBanner, + _ => Material::Air, + } +} + +pub(crate) fn map_bed(damage: isize) -> Material { + match 15 - damage { + 0 => Material::BlackBed, + 1 => Material::RedBed, + 2 => Material::GreenBed, + 3 => Material::BrownBed, + 4 => Material::BlueBed, + 5 => Material::PurpleBed, + 6 => Material::CyanBed, + 7 => Material::LightGrayBed, + 8 => Material::GrayBed, + 9 => Material::PinkBed, + 10 => Material::LimeBed, + 11 => Material::YellowBed, + 12 => Material::LightBlueBed, + 13 => Material::MagentaBed, + 14 => Material::OrangeBed, + 15 => Material::WhiteBed, + _ => Material::Air, + } +} + +pub(crate) fn map_carpet(damage: isize) -> Material { + match 15 - damage { + 0 => Material::BlackCarpet, + 1 => Material::RedCarpet, + 2 => Material::GreenCarpet, + 3 => Material::BrownCarpet, + 4 => Material::BlueCarpet, + 5 => Material::PurpleCarpet, + 6 => Material::CyanCarpet, + 7 => Material::LightGrayCarpet, + 8 => Material::GrayCarpet, + 9 => Material::PinkCarpet, + 10 => Material::LimeCarpet, + 11 => Material::YellowCarpet, + 12 => Material::LightBlueCarpet, + 13 => Material::MagentaCarpet, + 14 => Material::OrangeCarpet, + 15 => Material::WhiteCarpet, + _ => Material::Air, + } +} + +pub(crate) fn map_cobble_wall(damage: isize) -> Material { + match damage { + 0 => Material::CobblestoneWall, + 1 => Material::MossyCobblestoneWall, + _ => Material::Air, + } +} + +pub(crate) fn map_concrete(damage: isize) -> Material { + match 15 - damage { + 0 => Material::BlackConcrete, + 1 => Material::RedConcrete, + 2 => Material::GreenConcrete, + 3 => Material::BrownConcrete, + 4 => Material::BlueConcrete, + 5 => Material::PurpleConcrete, + 6 => Material::CyanConcrete, + 7 => Material::LightGrayConcrete, + 8 => Material::GrayConcrete, + 9 => Material::PinkConcrete, + 10 => Material::LimeConcrete, + 11 => Material::YellowConcrete, + 12 => Material::LightBlueConcrete, + 13 => Material::MagentaConcrete, + 14 => Material::OrangeConcrete, + 15 => Material::WhiteConcrete, + _ => Material::Air, + } +} + +pub(crate) fn map_concrete_powder(damage: isize) -> Material { + match 15 - damage { + 0 => Material::BlackConcretePowder, + 1 => Material::RedConcretePowder, + 2 => Material::GreenConcretePowder, + 3 => Material::BrownConcretePowder, + 4 => Material::BlueConcretePowder, + 5 => Material::PurpleConcretePowder, + 6 => Material::CyanConcretePowder, + 7 => Material::LightGrayConcretePowder, + 8 => Material::GrayConcretePowder, + 9 => Material::PinkConcretePowder, + 10 => Material::LimeConcretePowder, + 11 => Material::YellowConcretePowder, + 12 => Material::LightBlueConcretePowder, + 13 => Material::MagentaConcretePowder, + 14 => Material::OrangeConcretePowder, + 15 => Material::WhiteConcretePowder, + _ => Material::Air, + } +} + +pub(crate) fn map_cooked_fish(damage: isize) -> Material { + match damage { + 0 => Material::CookedFish, + 1 => Material::CookedSalmon, + _ => Material::Air, + } +} + +pub(crate) fn map_dirt(damage: isize) -> Material { + match damage { + 0 => Material::Dirt, + 1 => Material::CoarseDirt, + 2 => Material::Podzol, + _ => Material::Air, + } +} + +pub(crate) fn map_double_plant(damage: isize) -> Material { + match damage { + 0 => Material::Sunflower, + 1 => Material::Lilac, + 2 => Material::TallGrass, + 3 => Material::LargeFern, + 4 => Material::RoseBush, + 5 => Material::Peony, + _ => Material::Air, + } +} + +pub(crate) fn map_dye(damage: isize) -> Material { + match 15 - damage { + 0 => Material::InkSac, + 1 => Material::RedDye, + 2 => Material::GreenDye, + 3 => Material::CocoaBeans, + 4 => Material::LapisLazuli, + 5 => Material::PurpleDye, + 6 => Material::CyanDye, + 7 => Material::LightGrayDye, + 8 => Material::GrayDye, + 9 => Material::PinkDye, + 10 => Material::LimeDye, + 11 => Material::YellowDye, + 12 => Material::LightBlueDye, + 13 => Material::MagentaDye, + 14 => Material::OrangeDye, + 15 => Material::BoneMeal, + _ => Material::Air, + } +} + +pub(crate) fn map_fish(damage: isize) -> Material { + match damage { + 0 => Material::RawFish, + 1 => Material::Salmon, + 2 => Material::TropicalFish, + 3 => Material::Pufferfish, + _ => Material::Air, + } +} + +pub(crate) fn map_gapple(damage: isize) -> Material { + match damage { + 0 => Material::GoldenApple, + 1 => Material::EnchantedGoldenApple, + _ => Material::Air, + } +} + +pub(crate) fn map_leaves(damage: isize) -> Material { + match damage { + 0 => Material::OakLeaves, + 1 => Material::SpruceLeaves, + 2 => Material::BirchLeaves, + 3 => Material::JungleLeaves, + _ => Material::Air, + } +} + +pub(crate) fn map_leaves2(damage: isize) -> Material { + match damage { + 0 => Material::AcaciaLeaves, + 1 => Material::DarkOakLeaves, + _ => Material::Air, + } +} + +pub(crate) fn map_sand(damage: isize) -> Material { + match damage { + 0 => Material::Sand, + 1 => Material::RedSand, + _ => Material::Air, + } +} + +pub(crate) fn map_sandstone(damage: isize) -> Material { + match damage { + 0 => Material::Sandstone, + 1 => Material::ChiseledSandstone, + 2 => Material::SmoothSandstone, + _ => Material::Air, + } +} + +pub(crate) fn map_sapling(damage: isize) -> Material { + match damage { + 0 => Material::OakSapling, + 1 => Material::SpruceSapling, + 2 => Material::BirchSapling, + 3 => Material::JungleSapling, + 4 => Material::AcaciaSapling, + 5 => Material::DarkOakSapling, + _ => Material::Air, + } +} + +pub(crate) fn map_skull(damage: isize) -> Material { + match damage { + 0 => Material::SkeletonSkull, + 1 => Material::WitherSkeletonSkull, + 2 => Material::ZombieHead, + 3 => Material::PlayerHead, + 4 => Material::CreeperHead, + 5 => Material::DragonHead, + _ => Material::Air, + } +} + +pub(crate) fn map_sponge(damage: isize) -> Material { + match damage { + 0 => Material::Sponge, + 1 => Material::WetSponge, + _ => Material::Air, + } +} + +pub(crate) fn map_glass(damage: isize) -> Material { + match 15 - damage { + 0 => Material::BlackStainedGlass, + 1 => Material::RedStainedGlass, + 2 => Material::GreenStainedGlass, + 3 => Material::BrownStainedGlass, + 4 => Material::BlueStainedGlass, + 5 => Material::PurpleStainedGlass, + 6 => Material::CyanStainedGlass, + 7 => Material::LightGrayStainedGlass, + 8 => Material::GrayStainedGlass, + 9 => Material::PinkStainedGlass, + 10 => Material::LimeStainedGlass, + 11 => Material::YellowStainedGlass, + 12 => Material::LightBlueStainedGlass, + 13 => Material::MagentaStainedGlass, + 14 => Material::OrangeStainedGlass, + 15 => Material::WhiteStainedGlass, + _ => Material::Air, + } +} + +pub(crate) fn map_glass_pane(damage: isize) -> Material { + match 15 - damage { + 0 => Material::BlackStainedGlassPane, + 1 => Material::RedStainedGlassPane, + 2 => Material::GreenStainedGlassPane, + 3 => Material::BrownStainedGlassPane, + 4 => Material::BlueStainedGlassPane, + 5 => Material::PurpleStainedGlassPane, + 6 => Material::CyanStainedGlassPane, + 7 => Material::LightGrayStainedGlassPane, + 8 => Material::GrayStainedGlassPane, + 9 => Material::PinkStainedGlassPane, + 10 => Material::LimeStainedGlassPane, + 11 => Material::YellowStainedGlassPane, + 12 => Material::LightBlueStainedGlassPane, + 13 => Material::MagentaStainedGlassPane, + 14 => Material::OrangeStainedGlassPane, + 15 => Material::WhiteStainedGlassPane, + _ => Material::Air, + } +} + +pub(crate) fn map_terracotta(damage: isize) -> Material { + match 15 - damage { + 0 => Material::BlackTerracotta, + 1 => Material::RedTerracotta, + 2 => Material::GreenTerracotta, + 3 => Material::BrownTerracotta, + 4 => Material::BlueTerracotta, + 5 => Material::PurpleTerracotta, + 6 => Material::CyanTerracotta, + 7 => Material::LightGrayTerracotta, + 8 => Material::GrayTerracotta, + 9 => Material::PinkTerracotta, + 10 => Material::LimeTerracotta, + 11 => Material::YellowTerracotta, + 12 => Material::LightBlueTerracotta, + 13 => Material::MagentaTerracotta, + 14 => Material::OrangeTerracotta, + 15 => Material::WhiteTerracotta, + _ => Material::Air, + } +} + +pub(crate) fn map_stone(damage: isize) -> Material { + match damage { + 0 => Material::Stone, + 1 => Material::Granite, + 2 => Material::PolishedGranite, + 3 => Material::Diorite, + 4 => Material::PolishedDiorite, + 5 => Material::Andesite, + 6 => Material::PolishedAndesite, + _ => Material::Air, + } +} + +pub(crate) fn map_stone_slab(damage: isize) -> Material { + match damage { + 0 => Material::StoneSlab, + 1 => Material::SandstoneSlab, + 3 => Material::CobblestoneSlab, + 4 => Material::BrickSlab, + 5 => Material::StoneBrickSlab, + 6 => Material::NetherBrickSlab, + 7 => Material::QuartzSlab, + _ => Material::Air, + } +} + +pub(crate) fn map_stone_bricks(damage: isize) -> Material { + match damage { + 0 => Material::StoneBricks, + 1 => Material::MossyStoneBricks, + 2 => Material::CrackedStoneBricks, + 3 => Material::ChiseledStoneBricks, + _ => Material::Air, + } +} + +pub(crate) fn map_tall_grass(damage: isize) -> Material { + match damage { + 1 => Material::Grass, + 2 => Material::Fern, + _ => Material::Air, + } +} + +pub(crate) fn map_wood_slab(damage: isize) -> Material { + match damage { + 0 => Material::OakSlab, + 1 => Material::SpruceSlab, + 2 => Material::BirchSlab, + 3 => Material::JungleSlab, + 4 => Material::AcaciaSlab, + 5 => Material::DarkOakSlab, + _ => Material::Air, + } +} + +pub(crate) fn map_wool(damage: isize) -> Material { + match 15 - damage { + 0 => Material::BlackWool, + 1 => Material::RedWool, + 2 => Material::GreenWool, + 3 => Material::BrownWool, + 4 => Material::BlueWool, + 5 => Material::PurpleWool, + 6 => Material::CyanWool, + 7 => Material::LightGrayWool, + 8 => Material::GrayWool, + 9 => Material::PinkWool, + 10 => Material::LimeWool, + 11 => Material::YellowWool, + 12 => Material::LightBlueWool, + 13 => Material::MagentaWool, + 14 => Material::OrangeWool, + 15 => Material::WhiteWool, + _ => Material::Air, + } +} diff --git a/src/inventory/material/versions/mapping1_7_10.rs b/src/inventory/material/versions/mapping1_7_10.rs index cd099ee0..3daaaffa 100644 --- a/src/inventory/material/versions/mapping1_7_10.rs +++ b/src/inventory/material/versions/mapping1_7_10.rs @@ -1,5 +1,7 @@ use crate::inventory::Material; +use super::mapping1_12_2::*; + pub fn to_id(mat: Material) -> u16 { match mat { Material::Air => 0, @@ -349,53 +351,53 @@ pub fn to_id(mat: Material) -> u16 { } } -pub fn to_material(material_id: u16) -> Material { +pub fn to_material(material_id: u16, damage: isize) -> Material { match material_id { 0 => Material::Air, - 1 => Material::Stone, + 1 => map_stone(damage), 2 => Material::Grass, - 3 => Material::Dirt, + 3 => map_dirt(damage), 4 => Material::Cobblestone, - 5 => Material::Wood, - 6 => Material::Sapling, + 5 => map_planks(damage), + 6 => map_sapling(damage), 7 => Material::Bedrock, 8 => Material::Water, 9 => Material::StationaryWater, 10 => Material::Lava, 11 => Material::StationaryLava, - 12 => Material::Sand, + 12 => map_sand(damage), 13 => Material::Gravel, 14 => Material::GoldOre, 15 => Material::IronOre, 16 => Material::CoalOre, - 17 => Material::Log, - 18 => Material::Leaves, - 19 => Material::Sponge, + 17 => map_log(damage), + 18 => map_leaves(damage), + 19 => map_sponge(damage), 20 => Material::Glass, 21 => Material::LapisOre, 22 => Material::LapisBlock, 23 => Material::Dispenser, - 24 => Material::Sandstone, + 24 => map_sandstone(damage), 25 => Material::NoteBlock, 26 => Material::BedBlock, 27 => Material::PoweredRail, 28 => Material::DetectorRail, 29 => Material::PistonStickyBase, 30 => Material::Web, - 31 => Material::LongGrass, + 31 => map_tall_grass(damage), 32 => Material::DeadBush, 33 => Material::PistonBase, 34 => Material::PistonExtension, - 35 => Material::Wool, + 35 => map_wool(damage), 36 => Material::PistonMovingPiece, 37 => Material::YellowFlower, - 38 => Material::RedRose, + 38 => map_flower(damage), 39 => Material::BrownMushroom, 40 => Material::RedMushroom, 41 => Material::GoldBlock, 42 => Material::IronBlock, 43 => Material::DoubleStep, - 44 => Material::Step, + 44 => map_stone_slab(damage), 45 => Material::Brick, 46 => Material::Tnt, 47 => Material::Bookshelf, @@ -446,11 +448,10 @@ pub fn to_material(material_id: u16) -> Material { 92 => Material::CakeBlock, 93 => Material::DiodeBlockOff, 94 => Material::DiodeBlockOn, - // 95 => Material::LockedChest, //Deprecated - 95 => Material::StainedGlass, + 95 => map_glass(damage), 96 => Material::TrapDoor, - 97 => Material::MonsterEggs, - 98 => Material::SmoothBrick, + 97 => map_infested_stone(damage), + 98 => map_stone_bricks(damage), 99 => Material::HugeMushroom1, 100 => Material::HugeMushroom2, 101 => Material::IronFence, @@ -478,7 +479,7 @@ pub fn to_material(material_id: u16) -> Material { 123 => Material::RedstoneLampOff, 124 => Material::RedstoneLampOn, 125 => Material::WoodDoubleStep, - 126 => Material::WoodStep, + 126 => map_wood_slab(damage), 127 => Material::Cocoa, 128 => Material::SandstoneStairs, 129 => Material::EmeraldOre, @@ -491,13 +492,13 @@ pub fn to_material(material_id: u16) -> Material { 136 => Material::JungleWoodStairs, 137 => Material::Command, 138 => Material::Beacon, - 139 => Material::CobbleWall, + 139 => map_cobble_wall(damage), 140 => Material::FlowerPot, 141 => Material::Carrot, 142 => Material::Potato, 143 => Material::WoodButton, - 144 => Material::Skull, - 145 => Material::Anvil, + 144 => map_skull(damage), + 145 => map_anvil(damage), 146 => Material::TrappedChest, 147 => Material::GoldPlate, 148 => Material::IronPlate, @@ -507,22 +508,105 @@ pub fn to_material(material_id: u16) -> Material { 152 => Material::RedstoneBlock, 153 => Material::QuartzOre, 154 => Material::Hopper, - 155 => Material::QuartzBlock, + 155 => map_quartz(damage), 156 => Material::QuartzStairs, 157 => Material::ActivatorRail, 158 => Material::Dropper, - 159 => Material::StainedClay, - 160 => Material::StainedGlassPane, - 161 => Material::Leaves2, - 162 => Material::Log2, + 159 => map_terracotta(damage), + 160 => map_glass_pane(damage), + 161 => map_leaves2(damage), + 162 => map_log2(damage), 163 => Material::AcaciaStairs, 164 => Material::DarkOakStairs, + 165 => Material::SlimeBlock, + 166 => Material::Barrier, + 167 => Material::IronTrapdoor, + 168 => map_prismarine(damage), + 169 => Material::SeaLantern, 170 => Material::HayBlock, - 171 => Material::Carpet, + 171 => map_carpet(damage), 172 => Material::HardClay, 173 => Material::CoalBlock, 174 => Material::PackedIce, - 175 => Material::DoublePlant, + 175 => map_double_plant(damage), + 176 => Material::StandingBanner, + 177 => Material::WallBanner, + 178 => Material::DaylightDetectorInverted, + 179 => map_red_sandstone(damage), + 180 => Material::RedSandstoneStairs, + 181 => Material::DoubleStoneSlab2, + 182 => Material::StoneSlab2, + 183 => Material::SpruceFenceGate, + 184 => Material::BirchFenceGate, + 185 => Material::JungleFenceGate, + 186 => Material::DarkOakFenceGate, + 187 => Material::AcaciaFenceGate, + 188 => Material::SpruceFence, + 189 => Material::BirchFence, + 190 => Material::JungleFence, + 191 => Material::DarkOakFence, + 192 => Material::AcaciaFence, + 193 => Material::SpruceDoor, + 194 => Material::BirchDoor, + 195 => Material::JungleDoor, + 196 => Material::AcaciaDoor, + 197 => Material::DarkOakDoor, + 198 => Material::EndRod, + 199 => Material::ChorusPlant, + 200 => Material::ChorusFlower, + 201 => Material::PurpurBlock, + 202 => Material::PurpurPillar, + 203 => Material::PurpurStairs, + 204 => Material::PurpurDoubleSlab, + 205 => Material::PurpurSlab, + 206 => Material::EndBricks, + 207 => Material::BeetrootBlock, + 208 => Material::GrassPath, + 209 => Material::EndGateway, + 210 => Material::CommandRepeating, + 211 => Material::CommandChain, + 212 => Material::FrostedIce, + 213 => Material::Magma, + 214 => Material::NetherWartBlock, + 215 => Material::RedNetherBrick, + 216 => Material::BoneBlock, + 217 => Material::StructureVoid, + 218 => Material::Observer, + 219 => Material::WhiteShulkerBox, + 220 => Material::OrangeShulkerBox, + 221 => Material::MagentaShulkerBox, + 222 => Material::LightBlueShulkerBox, + 223 => Material::YellowShulkerBox, + 224 => Material::LimeShulkerBox, + 225 => Material::PinkShulkerBox, + 226 => Material::GrayShulkerBox, + 227 => Material::SilverShulkerBox, + 228 => Material::CyanShulkerBox, + 229 => Material::PurpleShulkerBox, + 230 => Material::BlueShulkerBox, + 231 => Material::BrownShulkerBox, + 232 => Material::GreenShulkerBox, + 233 => Material::RedShulkerBox, + 234 => Material::BlackShulkerBox, + 235 => Material::WhiteGlazedTerracotta, + 236 => Material::OrangeGlazedTerracotta, + 237 => Material::MagentaGlazedTerracotta, + 238 => Material::LightBlueGlazedTerracotta, + 239 => Material::YellowGlazedTerracotta, + 240 => Material::LimeGlazedTerracotta, + 241 => Material::PinkGlazedTerracotta, + 242 => Material::GrayGlazedTerracotta, + 243 => Material::SilverGlazedTerracotta, + 244 => Material::CyanGlazedTerracotta, + 245 => Material::PurpleGlazedTerracotta, + 246 => Material::BlueGlazedTerracotta, + 247 => Material::BrownGlazedTerracotta, + 248 => Material::GreenGlazedTerracotta, + 249 => Material::RedGlazedTerracotta, + 250 => Material::BlackGlazedTerracotta, + 251 => map_concrete(damage), + 252 => map_concrete_powder(damage), + 255 => Material::StructureBlock, 256 => Material::IronSpade, 257 => Material::IronPickaxe, 258 => Material::IronAxe, @@ -589,7 +673,7 @@ pub fn to_material(material_id: u16) -> Material { 319 => Material::Pork, 320 => Material::GrilledPork, 321 => Material::Painting, - 322 => Material::GoldenApple, + 322 => map_gapple(damage), 323 => Material::Sign, 324 => Material::WoodDoor, 325 => Material::Bucket, @@ -616,13 +700,13 @@ pub fn to_material(material_id: u16) -> Material { 346 => Material::FishingRod, 347 => Material::Watch, 348 => Material::GlowstoneDust, - 349 => Material::RawFish, - 350 => Material::CookedFish, - 351 => Material::InkSack, + 349 => map_fish(damage), + 350 => map_cooked_fish(damage), + 351 => map_dye(damage), 352 => Material::Bone, 353 => Material::Sugar, 354 => Material::Cake, - 355 => Material::Bed, + 355 => map_bed(damage), 356 => Material::Diode, 357 => Material::Cookie, 358 => Material::Map, @@ -676,6 +760,14 @@ pub fn to_material(material_id: u16) -> Material { 406 => Material::Quartz, 407 => Material::ExplosiveMinecart, 408 => Material::HopperMinecart, + 409 => Material::PrismarineShard, + 410 => Material::PrismarineCrystals, + 411 => Material::Rabbit, + 412 => Material::CookedRabbit, + 413 => Material::RabbitStew, + 414 => Material::RabbitFoot, + 415 => Material::RabbitHide, + 416 => Material::ArmorStand, 417 => Material::IronBarding, 418 => Material::GoldBarding, 419 => Material::DiamondBarding, diff --git a/src/inventory/material/versions/mapping1_8_8.rs b/src/inventory/material/versions/mapping1_8_8.rs index 47e2cc5a..a4deea15 100644 --- a/src/inventory/material/versions/mapping1_8_8.rs +++ b/src/inventory/material/versions/mapping1_8_8.rs @@ -1,5 +1,7 @@ use crate::inventory::Material; +use super::mapping1_12_2::*; + pub fn to_id(mat: Material) -> u16 { match mat { Material::Air => 0, @@ -391,53 +393,53 @@ pub fn to_id(mat: Material) -> u16 { } } -pub fn to_material(material_id: u16) -> Material { +pub fn to_material(material_id: u16, damage: isize) -> Material { match material_id { 0 => Material::Air, - 1 => Material::Stone, + 1 => map_stone(damage), 2 => Material::Grass, - 3 => Material::Dirt, + 3 => map_dirt(damage), 4 => Material::Cobblestone, - 5 => Material::Wood, - 6 => Material::Sapling, + 5 => map_planks(damage), + 6 => map_sapling(damage), 7 => Material::Bedrock, 8 => Material::Water, 9 => Material::StationaryWater, 10 => Material::Lava, 11 => Material::StationaryLava, - 12 => Material::Sand, + 12 => map_sand(damage), 13 => Material::Gravel, 14 => Material::GoldOre, 15 => Material::IronOre, 16 => Material::CoalOre, - 17 => Material::Log, - 18 => Material::Leaves, - 19 => Material::Sponge, + 17 => map_log(damage), + 18 => map_leaves(damage), + 19 => map_sponge(damage), 20 => Material::Glass, 21 => Material::LapisOre, 22 => Material::LapisBlock, 23 => Material::Dispenser, - 24 => Material::Sandstone, + 24 => map_sandstone(damage), 25 => Material::NoteBlock, 26 => Material::BedBlock, 27 => Material::PoweredRail, 28 => Material::DetectorRail, 29 => Material::PistonStickyBase, 30 => Material::Web, - 31 => Material::LongGrass, + 31 => map_tall_grass(damage), 32 => Material::DeadBush, 33 => Material::PistonBase, 34 => Material::PistonExtension, - 35 => Material::Wool, + 35 => map_wool(damage), 36 => Material::PistonMovingPiece, 37 => Material::YellowFlower, - 38 => Material::RedRose, + 38 => map_flower(damage), 39 => Material::BrownMushroom, 40 => Material::RedMushroom, 41 => Material::GoldBlock, 42 => Material::IronBlock, 43 => Material::DoubleStep, - 44 => Material::Step, + 44 => map_stone_slab(damage), 45 => Material::Brick, 46 => Material::Tnt, 47 => Material::Bookshelf, @@ -488,10 +490,10 @@ pub fn to_material(material_id: u16) -> Material { 92 => Material::CakeBlock, 93 => Material::DiodeBlockOff, 94 => Material::DiodeBlockOn, - 95 => Material::StainedGlass, + 95 => map_glass(damage), 96 => Material::TrapDoor, - 97 => Material::MonsterEggs, - 98 => Material::SmoothBrick, + 97 => map_infested_stone(damage), + 98 => map_stone_bricks(damage), 99 => Material::HugeMushroom1, 100 => Material::HugeMushroom2, 101 => Material::IronFence, @@ -519,7 +521,7 @@ pub fn to_material(material_id: u16) -> Material { 123 => Material::RedstoneLampOff, 124 => Material::RedstoneLampOn, 125 => Material::WoodDoubleStep, - 126 => Material::WoodStep, + 126 => map_wood_slab(damage), 127 => Material::Cocoa, 128 => Material::SandstoneStairs, 129 => Material::EmeraldOre, @@ -532,13 +534,13 @@ pub fn to_material(material_id: u16) -> Material { 136 => Material::JungleWoodStairs, 137 => Material::Command, 138 => Material::Beacon, - 139 => Material::CobbleWall, + 139 => map_cobble_wall(damage), 140 => Material::FlowerPot, 141 => Material::Carrot, 142 => Material::Potato, 143 => Material::WoodButton, - 144 => Material::Skull, - 145 => Material::Anvil, + 144 => map_skull(damage), + 145 => map_anvil(damage), 146 => Material::TrappedChest, 147 => Material::GoldPlate, 148 => Material::IronPlate, @@ -548,31 +550,31 @@ pub fn to_material(material_id: u16) -> Material { 152 => Material::RedstoneBlock, 153 => Material::QuartzOre, 154 => Material::Hopper, - 155 => Material::QuartzBlock, + 155 => map_quartz(damage), 156 => Material::QuartzStairs, 157 => Material::ActivatorRail, 158 => Material::Dropper, - 159 => Material::StainedClay, - 160 => Material::StainedGlassPane, - 161 => Material::Leaves2, - 162 => Material::Log2, + 159 => map_terracotta(damage), + 160 => map_glass_pane(damage), + 161 => map_leaves2(damage), + 162 => map_log2(damage), 163 => Material::AcaciaStairs, 164 => Material::DarkOakStairs, 165 => Material::SlimeBlock, 166 => Material::Barrier, 167 => Material::IronTrapdoor, - 168 => Material::Prismarine, + 168 => map_prismarine(damage), 169 => Material::SeaLantern, 170 => Material::HayBlock, - 171 => Material::Carpet, + 171 => map_carpet(damage), 172 => Material::HardClay, 173 => Material::CoalBlock, 174 => Material::PackedIce, - 175 => Material::DoublePlant, + 175 => map_double_plant(damage), 176 => Material::StandingBanner, 177 => Material::WallBanner, 178 => Material::DaylightDetectorInverted, - 179 => Material::RedSandstone, + 179 => map_red_sandstone(damage), 180 => Material::RedSandstoneStairs, 181 => Material::DoubleStoneSlab2, 182 => Material::StoneSlab2, @@ -657,7 +659,7 @@ pub fn to_material(material_id: u16) -> Material { 319 => Material::Pork, 320 => Material::GrilledPork, 321 => Material::Painting, - 322 => Material::GoldenApple, + 322 => map_gapple(damage), 323 => Material::Sign, 324 => Material::WoodDoor, 325 => Material::Bucket, @@ -684,13 +686,13 @@ pub fn to_material(material_id: u16) -> Material { 346 => Material::FishingRod, 347 => Material::Watch, 348 => Material::GlowstoneDust, - 349 => Material::RawFish, - 350 => Material::CookedFish, - 351 => Material::InkSack, + 349 => map_fish(damage), + 350 => map_cooked_fish(damage), + 351 => map_dye(damage), 352 => Material::Bone, 353 => Material::Sugar, 354 => Material::Cake, - 355 => Material::Bed, + 355 => map_bed(damage), 356 => Material::Diode, 357 => Material::Cookie, 358 => Material::Map, @@ -760,7 +762,8 @@ pub fn to_material(material_id: u16) -> Material { 422 => Material::CommandMinecart, 423 => Material::Mutton, 424 => Material::CookedMutton, - 425 => Material::Banner, + 425 => map_banner(damage), + 426 => Material::EndCrystal, 427 => Material::SpruceDoorItem, 428 => Material::BirchDoorItem, 429 => Material::JungleDoorItem, diff --git a/src/inventory/material/versions/mapping1_9_4.rs b/src/inventory/material/versions/mapping1_9_4.rs index 65b4a2d4..0405ae6b 100644 --- a/src/inventory/material/versions/mapping1_9_4.rs +++ b/src/inventory/material/versions/mapping1_9_4.rs @@ -1,5 +1,7 @@ use crate::inventory::Material; +use super::mapping1_12_2::*; + pub fn to_id(mat: Material) -> u16 { match mat { Material::Air => 0, @@ -425,53 +427,53 @@ pub fn to_id(mat: Material) -> u16 { } } -pub fn to_material(material_id: u16) -> Material { +pub fn to_material(material_id: u16, damage: isize) -> Material { match material_id { 0 => Material::Air, - 1 => Material::Stone, + 1 => map_stone(damage), 2 => Material::Grass, - 3 => Material::Dirt, + 3 => map_dirt(damage), 4 => Material::Cobblestone, - 5 => Material::Wood, - 6 => Material::Sapling, + 5 => map_planks(damage), + 6 => map_sapling(damage), 7 => Material::Bedrock, 8 => Material::Water, 9 => Material::StationaryWater, 10 => Material::Lava, 11 => Material::StationaryLava, - 12 => Material::Sand, + 12 => map_sand(damage), 13 => Material::Gravel, 14 => Material::GoldOre, 15 => Material::IronOre, 16 => Material::CoalOre, - 17 => Material::Log, - 18 => Material::Leaves, - 19 => Material::Sponge, + 17 => map_log(damage), + 18 => map_leaves(damage), + 19 => map_sponge(damage), 20 => Material::Glass, 21 => Material::LapisOre, 22 => Material::LapisBlock, 23 => Material::Dispenser, - 24 => Material::Sandstone, + 24 => map_sandstone(damage), 25 => Material::NoteBlock, 26 => Material::BedBlock, 27 => Material::PoweredRail, 28 => Material::DetectorRail, 29 => Material::PistonStickyBase, 30 => Material::Web, - 31 => Material::LongGrass, + 31 => map_tall_grass(damage), 32 => Material::DeadBush, 33 => Material::PistonBase, 34 => Material::PistonExtension, - 35 => Material::Wool, + 35 => map_wool(damage), 36 => Material::PistonMovingPiece, 37 => Material::YellowFlower, - 38 => Material::RedRose, + 38 => map_flower(damage), 39 => Material::BrownMushroom, 40 => Material::RedMushroom, 41 => Material::GoldBlock, 42 => Material::IronBlock, 43 => Material::DoubleStep, - 44 => Material::Step, + 44 => map_stone_slab(damage), 45 => Material::Brick, 46 => Material::Tnt, 47 => Material::Bookshelf, @@ -522,10 +524,10 @@ pub fn to_material(material_id: u16) -> Material { 92 => Material::CakeBlock, 93 => Material::DiodeBlockOff, 94 => Material::DiodeBlockOn, - 95 => Material::StainedGlass, + 95 => map_glass(damage), 96 => Material::TrapDoor, - 97 => Material::MonsterEggs, - 98 => Material::SmoothBrick, + 97 => map_infested_stone(damage), + 98 => map_stone_bricks(damage), 99 => Material::HugeMushroom1, 100 => Material::HugeMushroom2, 101 => Material::IronFence, @@ -553,7 +555,7 @@ pub fn to_material(material_id: u16) -> Material { 123 => Material::RedstoneLampOff, 124 => Material::RedstoneLampOn, 125 => Material::WoodDoubleStep, - 126 => Material::WoodStep, + 126 => map_wood_slab(damage), 127 => Material::Cocoa, 128 => Material::SandstoneStairs, 129 => Material::EmeraldOre, @@ -566,13 +568,13 @@ pub fn to_material(material_id: u16) -> Material { 136 => Material::JungleWoodStairs, 137 => Material::Command, 138 => Material::Beacon, - 139 => Material::CobbleWall, + 139 => map_cobble_wall(damage), 140 => Material::FlowerPot, 141 => Material::Carrot, 142 => Material::Potato, 143 => Material::WoodButton, - 144 => Material::Skull, - 145 => Material::Anvil, + 144 => map_skull(damage), + 145 => map_anvil(damage), 146 => Material::TrappedChest, 147 => Material::GoldPlate, 148 => Material::IronPlate, @@ -582,31 +584,31 @@ pub fn to_material(material_id: u16) -> Material { 152 => Material::RedstoneBlock, 153 => Material::QuartzOre, 154 => Material::Hopper, - 155 => Material::QuartzBlock, + 155 => map_quartz(damage), 156 => Material::QuartzStairs, 157 => Material::ActivatorRail, 158 => Material::Dropper, - 159 => Material::StainedClay, - 160 => Material::StainedGlassPane, - 161 => Material::Leaves2, - 162 => Material::Log2, + 159 => map_terracotta(damage), + 160 => map_glass_pane(damage), + 161 => map_leaves2(damage), + 162 => map_log2(damage), 163 => Material::AcaciaStairs, 164 => Material::DarkOakStairs, 165 => Material::SlimeBlock, 166 => Material::Barrier, 167 => Material::IronTrapdoor, - 168 => Material::Prismarine, + 168 => map_prismarine(damage), 169 => Material::SeaLantern, 170 => Material::HayBlock, - 171 => Material::Carpet, + 171 => map_carpet(damage), 172 => Material::HardClay, 173 => Material::CoalBlock, 174 => Material::PackedIce, - 175 => Material::DoublePlant, + 175 => map_double_plant(damage), 176 => Material::StandingBanner, 177 => Material::WallBanner, 178 => Material::DaylightDetectorInverted, - 179 => Material::RedSandstone, + 179 => map_red_sandstone(damage), 180 => Material::RedSandstoneStairs, 181 => Material::DoubleStoneSlab2, 182 => Material::StoneSlab2, @@ -707,7 +709,7 @@ pub fn to_material(material_id: u16) -> Material { 319 => Material::Pork, 320 => Material::GrilledPork, 321 => Material::Painting, - 322 => Material::GoldenApple, + 322 => map_gapple(damage), 323 => Material::Sign, 324 => Material::WoodDoor, 325 => Material::Bucket, @@ -734,13 +736,13 @@ pub fn to_material(material_id: u16) -> Material { 346 => Material::FishingRod, 347 => Material::Watch, 348 => Material::GlowstoneDust, - 349 => Material::RawFish, - 350 => Material::CookedFish, - 351 => Material::InkSack, + 349 => map_fish(damage), + 350 => map_cooked_fish(damage), + 351 => map_dye(damage), 352 => Material::Bone, 353 => Material::Sugar, 354 => Material::Cake, - 355 => Material::Bed, + 355 => map_bed(damage), 356 => Material::Diode, 357 => Material::Cookie, 358 => Material::Map, @@ -810,7 +812,7 @@ pub fn to_material(material_id: u16) -> Material { 422 => Material::CommandMinecart, 423 => Material::Mutton, 424 => Material::CookedMutton, - 425 => Material::Banner, + 425 => map_banner(damage), 426 => Material::EndCrystal, 427 => Material::SpruceDoorItem, 428 => Material::BirchDoorItem, diff --git a/src/inventory/material/versions/mod.rs b/src/inventory/material/versions/mod.rs index 0ca70d91..22523e4b 100644 --- a/src/inventory/material/versions/mod.rs +++ b/src/inventory/material/versions/mod.rs @@ -12,14 +12,20 @@ mod mapping1_7_10; mod mapping1_8_8; mod mapping1_9_4; -pub fn to_material(id: u16, version: Version) -> Material { +// FIXME: support tags! +pub fn to_material( + id: u16, + damage: Option, + _tag: Option, + version: Version, +) -> Material { match version { - Version::V1_7 => mapping1_7_10::to_material(id), - Version::V1_8 => mapping1_8_8::to_material(id), - Version::V1_9 => mapping1_9_4::to_material(id), - Version::V1_10 => mapping1_10_2::to_material(id), - Version::V1_11 => mapping1_11_2::to_material(id), - Version::V1_12 => mapping1_12_2::to_material(id), + Version::V1_7 => mapping1_7_10::to_material(id, damage.unwrap()), + Version::V1_8 => mapping1_8_8::to_material(id, damage.unwrap()), + Version::V1_9 => mapping1_9_4::to_material(id, damage.unwrap()), + Version::V1_10 => mapping1_10_2::to_material(id, damage.unwrap()), + Version::V1_11 => mapping1_11_2::to_material(id, damage.unwrap()), + Version::V1_12 => mapping1_12_2::to_material(id, damage.unwrap()), Version::V1_13 => mapping1_13_2::to_material(id), Version::V1_13_2 => mapping1_13_2::to_material(id), Version::V1_14 => mapping1_14_4::to_material(id), diff --git a/src/server/mod.rs b/src/server/mod.rs index 489aa464..cf59d1bf 100644 --- a/src/server/mod.rs +++ b/src/server/mod.rs @@ -1694,8 +1694,13 @@ impl Server { let item = item.map(|stack| { let id = stack.id; Item { + material: to_material( + id as u16, + Some(stack.damage.unwrap_or(0)), + None, + self.mapped_protocol_version, + ), stack, - material: to_material(id as u16, self.mapped_protocol_version), } }); top_inventory.write().cursor = item.clone(); @@ -1711,8 +1716,13 @@ impl Server { let item = item.map(|stack| { let id = stack.id; Item { + material: to_material( + id as u16, + Some(stack.damage.unwrap_or(0)), + None, + self.mapped_protocol_version, + ), stack, - material: to_material(id as u16, self.mapped_protocol_version), } }); inventory.write().set_item(slot as u16, item.clone());