Skip to content

Commit 72aec0c

Browse files
authored
blocks: fix hier block shift (#489), add tests (#492)
* blocks: fix soul fire/soil, exclude from <1.13, fixing #489 * blocks: add unit tests for #467 #469 #474
1 parent d60a495 commit 72aec0c

File tree

1 file changed

+96
-0
lines changed

1 file changed

+96
-0
lines changed

blocks/src/lib.rs

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1397,6 +1397,7 @@ define_blocks! {
13971397
}
13981398
SoulFire {
13991399
props {},
1400+
data None,
14001401
offsets |protocol_version| { if protocol_version >= 735 { Some(0) } else { None } },
14011402
model { ("minecraft", "soul_fire") },
14021403
collision vec![],
@@ -2057,6 +2058,7 @@ define_blocks! {
20572058
}
20582059
SoulSoil {
20592060
props {},
2061+
data None,
20602062
offsets |protocol_version| { if protocol_version >= 735 { Some(0) } else { None } },
20612063
model { ("minecraft", "soul_soil") },
20622064
}
@@ -5786,6 +5788,100 @@ define_blocks! {
57865788
}
57875789
}
57885790

5791+
#[cfg(test)]
5792+
mod tests {
5793+
use super::*;
5794+
5795+
// Spot check a few blocks across different versions, including the correctly recognized last supported block
5796+
// TODO: comprehensive testing against https://github.com/PrismarineJS/minecraft-data/tree/master/data/pc
5797+
5798+
#[test]
5799+
fn hier_1_12_2() {
5800+
let id_map = VanillaIDMap::new(340);
5801+
assert_eq!(
5802+
id_map.by_vanilla_id(255 << 4, &HashMap::new()),
5803+
StructureBlock {
5804+
mode: StructureBlockMode::Save
5805+
}
5806+
);
5807+
assert_eq!(
5808+
id_map.by_vanilla_id((255 << 4) | 3, &HashMap::new()),
5809+
StructureBlock {
5810+
mode: StructureBlockMode::Data
5811+
}
5812+
);
5813+
}
5814+
5815+
#[test]
5816+
fn flat_1_13_2() {
5817+
let id_map = VanillaIDMap::new(404);
5818+
assert_eq!(
5819+
id_map.by_vanilla_id(8595, &HashMap::new()),
5820+
StructureBlock {
5821+
mode: StructureBlockMode::Save
5822+
}
5823+
);
5824+
assert_eq!(
5825+
id_map.by_vanilla_id(8598, &HashMap::new()),
5826+
StructureBlock {
5827+
mode: StructureBlockMode::Data
5828+
}
5829+
);
5830+
}
5831+
5832+
#[test]
5833+
fn flat_1_14_4() {
5834+
let id_map = VanillaIDMap::new(477);
5835+
assert_eq!(
5836+
id_map.by_vanilla_id(9113, &HashMap::new()),
5837+
Conduit { waterlogged: true }
5838+
);
5839+
assert_eq!(
5840+
id_map.by_vanilla_id(9114, &HashMap::new()),
5841+
Conduit { waterlogged: false }
5842+
);
5843+
}
5844+
5845+
#[test]
5846+
fn flat_1_15_1() {
5847+
let id_map = VanillaIDMap::new(575);
5848+
assert_eq!(
5849+
id_map.by_vanilla_id(9113, &HashMap::new()),
5850+
Conduit { waterlogged: true }
5851+
);
5852+
assert_eq!(
5853+
id_map.by_vanilla_id(9114, &HashMap::new()),
5854+
Conduit { waterlogged: false }
5855+
);
5856+
}
5857+
5858+
#[test]
5859+
fn flat_1_16() {
5860+
let id_map = VanillaIDMap::new(735);
5861+
assert_eq!(
5862+
id_map.by_vanilla_id(1048, &HashMap::new()),
5863+
NoteBlock {
5864+
instrument: NoteBlockInstrument::Pling,
5865+
note: 24,
5866+
powered: false
5867+
}
5868+
);
5869+
}
5870+
5871+
#[test]
5872+
fn flat_1_16_2() {
5873+
let id_map = VanillaIDMap::new(751);
5874+
assert_eq!(
5875+
id_map.by_vanilla_id(1048, &HashMap::new()),
5876+
NoteBlock {
5877+
instrument: NoteBlockInstrument::Pling,
5878+
note: 24,
5879+
powered: false
5880+
}
5881+
);
5882+
}
5883+
}
5884+
57895885
fn can_burn<W: WorldAccess>(world: &W, pos: Position) -> bool {
57905886
matches!(world.get_block(pos), Block::Planks { .. }
57915887
| Block::DoubleWoodenSlab { .. }

0 commit comments

Comments
 (0)