From 88506fd397e1424472213043c58e167217637129 Mon Sep 17 00:00:00 2001 From: rollrat Date: Sun, 17 Nov 2024 15:11:53 +0900 Subject: [PATCH] Fix nbt position translation --- src/nbt/mod.rs | 69 +++++++++++++++++++----------------- src/transform/placer/mod.rs | 2 +- src/world/position.rs | 2 +- test/and-gate.nbt | Bin 462 -> 454 bytes 4 files changed, 38 insertions(+), 35 deletions(-) diff --git a/src/nbt/mod.rs b/src/nbt/mod.rs index ec481dc..520cf5b 100644 --- a/src/nbt/mod.rs +++ b/src/nbt/mod.rs @@ -108,30 +108,33 @@ fn nbt_block_name(block: &Block) -> (String, String, Option) let (palette_name, specify_name, property) = match block.kind { BlockKind::Air => ("air", "air".to_owned(), None), BlockKind::Cobble { .. } => ("stone_bricks", "stone_bricks".to_owned(), None), - BlockKind::Switch { is_on } => ( - "lever", - "lever".to_owned(), - Some(NBTPaletteProperty { - face: match block.direction { - Direction::Bottom => Some("floor".to_owned()), - Direction::Top => Some("ceiling".to_owned()), - Direction::East | Direction::West | Direction::South | Direction::North => { - Some("wall".to_owned()) - } - _ => unreachable!(), - }, - facing: match block.direction { - Direction::Bottom | Direction::Top => None, - Direction::East => Some("south".to_owned()), - Direction::West => Some("north".to_owned()), - Direction::South => Some("west".to_owned()), - Direction::North => Some("east".to_owned()), - _ => unreachable!(), - }, - powered: is_on.then(|| "true".to_owned()), - ..Default::default() - }), - ), + BlockKind::Switch { is_on } => { + let facing = match block.direction { + Direction::Bottom | Direction::Top => None, + Direction::East => Some("south".to_owned()), + Direction::West => Some("north".to_owned()), + Direction::South => Some("east".to_owned()), + Direction::North => Some("west".to_owned()), + _ => unreachable!(), + }; + ( + "lever", + format!("lever_{is_on}_{}", facing.clone().unwrap_or_default()), + Some(NBTPaletteProperty { + face: match block.direction { + Direction::Bottom => Some("floor".to_owned()), + Direction::Top => Some("ceiling".to_owned()), + Direction::East | Direction::West | Direction::South | Direction::North => { + Some("wall".to_owned()) + } + _ => unreachable!(), + }, + facing, + powered: is_on.then(|| "true".to_owned()), + ..Default::default() + }), + ) + } BlockKind::Redstone { state, strength, .. } => ( @@ -139,8 +142,8 @@ fn nbt_block_name(block: &Block) -> (String, String, Option) format!("redstone_wire_{}_{}", strength, state), Some(NBTPaletteProperty { power: Some(strength.to_string()), - east: ((state & RedstoneState::South as usize) > 0).then(|| "side".to_owned()), - west: ((state & RedstoneState::North as usize) > 0).then(|| "side".to_owned()), + east: ((state & RedstoneState::North as usize) > 0).then(|| "side".to_owned()), + west: ((state & RedstoneState::South as usize) > 0).then(|| "side".to_owned()), south: ((state & RedstoneState::West as usize) > 0).then(|| "side".to_owned()), north: ((state & RedstoneState::East as usize) > 0).then(|| "side".to_owned()), ..Default::default() @@ -151,10 +154,10 @@ fn nbt_block_name(block: &Block) -> (String, String, Option) ("redstone_torch", "redstone_torch".to_owned(), None) } else { let facing = match block.direction { - Direction::East => "south", - Direction::West => "north", - Direction::South => "west", - Direction::North => "east", + Direction::East => "north", + Direction::West => "south", + Direction::South => "east", + Direction::North => "west", _ => unreachable!(), } .to_owned(); @@ -186,7 +189,7 @@ fn nbt_block_name(block: &Block) -> (String, String, Option) ( "repeater", - "repeater".to_owned(), + format!("repeater_{facing}_{is_on}_{is_locked}_{delay}"), Some(NBTPaletteProperty { facing: Some(facing), delay: Some(delay.to_string()), @@ -224,15 +227,15 @@ fn world3d_to_nbt(world: &World3D) -> NBTRoot { blocks.push(NBTBlock { state: palette_index[&specify_name] as i32, - pos: (pos.2 as i32, pos.0 as i32, pos.1 as i32), + pos: (pos.1 as i32, pos.2 as i32, pos.0 as i32), }); } NBTRoot { size: ( + world.size.1 as i32, world.size.2 as i32, world.size.0 as i32, - world.size.1 as i32, ), blocks, palette, diff --git a/src/transform/placer/mod.rs b/src/transform/placer/mod.rs index 99f2fbc..2ce77de 100644 --- a/src/transform/placer/mod.rs +++ b/src/transform/placer/mod.rs @@ -15,7 +15,7 @@ use crate::{ logic::LogicType, world::{ block::{Block, BlockKind, Direction, RedstoneState}, - position::{self, DimSize, Position}, + position::{DimSize, Position}, world::World3D, }, }; diff --git a/src/world/position.rs b/src/world/position.rs index 80708c6..8008b5d 100644 --- a/src/world/position.rs +++ b/src/world/position.rs @@ -1,6 +1,6 @@ use super::block::{Direction, RedstoneState, RedstoneStateType}; -// 위치 +// 위치 (x, y, z) #[derive(Debug, Copy, Clone, Eq, PartialEq, Hash, PartialOrd, Ord)] pub struct Position(pub usize, pub usize, pub usize); diff --git a/test/and-gate.nbt b/test/and-gate.nbt index bf4316462fda970548d0b6cbcaae384245df304a..aaa908f8f787f13b723827161a09030a99e4a17b 100644 GIT binary patch literal 454 zcmV;%0XhC3iwFP!00002|E1R5PQox42H>wh9|DQ-Og-@)JoXAaGTs3h@F9zXE?t$x ztG6iI_$l;_k`U;4`|inTmyL-=WSjC!3=wVLgWabc(O_D+*?TjNqh~|hgd#}%9%q=^ zHSL7{wU<%pjG}yx271hXMjvJr;87{hnH~-F9C*xOMyEVyG789C^5~T3C}UC{o6abp zM+2El9-H!TI-`Id4P-8P7+60Hco^_7;Gu4vk7@ksT`fM8(!|iBm^<{jp?S6kqH5XMi3C_=!NBx6nF4u2lrDy{E wSvTAj#E0*>#KA_|LEm|w==>r5^8f$< literal 462 zcmb2|=3oE;rvFQ)UGzI-AkudGvRGp0N58!vW%qpJ++(zlQSz}ucXI44txo@Z)?*1} zZ~7zT3B%E_{rZtIh}9a%ZwDQfY6HxtbnwtKCh4)8I-vTg|Z29bKyr9qY%hh2&#|v@B zzl(r6YB)Y99%yHf2Ww)GXZ@i8vRmrI#fE;i8lDHq4D!rBW>ieuo%N~9`N90hk4m(@ zc<)Or+^m_c7qgGcU$lPHX_s%Wat`ZFd854L6t`GfXyofhR}x?Bl0M~KzNhy3-LgGj z4qmglKdrBN=CX~^WlnZwjoa@&smpnIs$zrfzkd_F&aKXpTcdq#?;p<+z1QXox4&ur zu{n0mV;i<3hrdr+-oEATqSJf)Q{GMa_c7%0Tla|V{ia(>-)jBKzdzwpjU+!00|Nk2 Cli%n7