Skip to content
This repository has been archived by the owner on Apr 10, 2024. It is now read-only.

Commit

Permalink
Add support of the latest bdump format to the Component of universal …
Browse files Browse the repository at this point in the history
…import of Omega (#149)
  • Loading branch information
Happy2018new authored Dec 22, 2022
1 parent 83d2fbb commit daddbc2
Show file tree
Hide file tree
Showing 5 changed files with 161 additions and 38 deletions.
11 changes: 7 additions & 4 deletions mirror/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,13 @@ var TimeStampNotFound = time.Unix(0, 0).Unix()
// 收到/保存/读取该区块时区块所在的位置 ChunkX/ChunkZ (ChunkX=X>>4)
// 以及区块收到/保存的时间 (Unix Second)
type ChunkData struct {
Chunk *chunk.Chunk
BlockNbts map[define.CubePos]map[string]interface{}
SyncTime int64
ChunkPos define.ChunkPos
Chunk *chunk.Chunk
BlockNbts map[define.CubePos]map[string]interface{}
BlockName map[define.CubePos]string // for bdx
BlockStates map[define.CubePos]string // for bdx
BlockData map[define.CubePos]uint16 // for bdx
SyncTime int64
ChunkPos define.ChunkPos
}

func (cd *ChunkData) GetSyncTime() time.Time {
Expand Down
38 changes: 34 additions & 4 deletions omega/utils/structure/bdx.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"encoding/binary"
"fmt"
"io"
"phoenixbuilder/bridge/bridge_fmt"
I18n "phoenixbuilder/fastbuilder/i18n"
"phoenixbuilder/fastbuilder/types"
"phoenixbuilder/fastbuilder/world_provider"
Expand Down Expand Up @@ -138,8 +137,9 @@ func handleBDXCMD(br io.Reader, infoSender func(string)) (author string, blockCh
}
blockData := binary.BigEndian.Uint16(blockDataBytes)
blockChan <- &IOBlockForDecoder{
Pos: brushPosition,
RTID: legacyRunTimeIDRemapper.GetRTID(blockId, blockData),
Pos: brushPosition,
BlockName: legacyRunTimeIDRemapper.palatteIDToBlockNameMapping[blockId],
BlockData: blockData,
}
} else if cmd == 8 {
brushPosition[2]++
Expand Down Expand Up @@ -176,7 +176,23 @@ func handleBDXCMD(br io.Reader, infoSender func(string)) (author string, blockCh
jumpval := binary.BigEndian.Uint32(rdst)
brushPosition[2] += int(jumpval)
} else if cmd == 13 {
bridge_fmt.Printf("WARNING: BDump/Import: Use of reserved command\n")
rdst := make([]byte, 2)
_, err := br.Read(rdst)
if err != nil {
infoSender("Failed to get argument for cmd[pos4], file may be corrupted")
return
}
blockId := binary.BigEndian.Uint16(rdst)
block_states_string, err := ReadBrString(br)
if err != nil {
infoSender("Failed to get argument for cmd[pos5], file may be corrupted")
return
}
blockChan <- &IOBlockForDecoder{
Pos: brushPosition,
BlockStates: block_states_string,
BlockName: legacyRunTimeIDRemapper.palatteIDToBlockNameMapping[blockId],
}
} else if cmd == 14 {
brushPosition[0]++
} else if cmd == 15 {
Expand Down Expand Up @@ -611,6 +627,20 @@ func handleBDXCMD(br io.Reader, infoSender func(string)) (author string, blockCh
// Point: pos,
// }
// }
} else if cmd == 39 {
buffer_length := make([]byte, 4)
_, err := br.Read(buffer_length)
if err != nil {
infoSender("Failed to get the length of buffer, file may be corrupted")
return
}
bufferLength := binary.BigEndian.Uint32(buffer_length)
buffer := make([]byte, bufferLength)
_, err = br.Read(buffer)
if err != nil {
infoSender("Failed to get the buffer, file may be corrupted")
return
}
} else {
// fmt.Println("ERROR!")
infoSender(fmt.Sprintf("unimplemented method found : %d", cmd))
Expand Down
16 changes: 14 additions & 2 deletions omega/utils/structure/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,20 @@ func (o *Builder) Build(blocksIn chan *IOBlockForBuilder, speed int, boostSleepT
}

} else {
cmd := fmt.Sprintf("setblock %v %v %v %v %v", block.Pos[0], block.Pos[1], block.Pos[2], strings.Replace(blk.Name, "minecraft:", "", 1), blk.Val)
o.BlockCmdSender(cmd)
// fmt.Println(block.BlockName, block.BlockStates, block.BlockData, "test")
if block.BlockName != "" && block.BlockStates != "" {
cmd := fmt.Sprintf("setblock %v %v %v %v %v", block.Pos[0], block.Pos[1], block.Pos[2], strings.Replace(block.BlockName, "minecraft:", "", 1), block.BlockStates)
o.BlockCmdSender(cmd)
// fmt.Println(cmd)
} else if block.BlockName != "" && block.BlockStates == "" {
cmd := fmt.Sprintf("setblock %v %v %v %v %v", block.Pos[0], block.Pos[1], block.Pos[2], strings.Replace(block.BlockName, "minecraft:", "", 1), block.BlockData)
o.BlockCmdSender(cmd)
// fmt.Println(cmd)
} else {
cmd := fmt.Sprintf("setblock %v %v %v %v %v", block.Pos[0], block.Pos[1], block.Pos[2], strings.Replace(blk.Name, "minecraft:", "", 1), blk.Val)
o.BlockCmdSender(cmd)
// fmt.Println(cmd)
}
}
counter++
}
Expand Down
22 changes: 14 additions & 8 deletions omega/utils/structure/define.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,23 @@ import (
)

type IOBlockForBuilder struct {
Pos define.CubePos
RTID uint32
NBT map[string]interface{}
Hit bool
Expand16 bool
Pos define.CubePos
BlockName string // for operation 13 which named `PlaceBlockWithBlockStates`
BlockStates string // for operation 13 which named `PlaceBlockWithBlockStates`
BlockData uint16 // for operation 7 which named `PlaceBlock`
RTID uint32
NBT map[string]interface{}
Hit bool
Expand16 bool
}

type IOBlockForDecoder struct {
Pos define.CubePos
RTID uint32
NBT map[string]interface{}
Pos define.CubePos
BlockName string // for operation 13 which named `PlaceBlockWithBlockStates`
BlockStates string // for operation 13 which named `PlaceBlockWithBlockStates`
BlockData uint16 // for operation 7 which named `PlaceBlock`
RTID uint32
NBT map[string]interface{}
}

type CommandBlockNBT struct {
Expand Down
112 changes: 92 additions & 20 deletions omega/utils/structure/pos.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,12 @@ func AlterImportPosStartAndSpeedWithReArrangeOnce(inChan chan *IOBlockForDecoder
chunks := make(map[define.ChunkPos]*mirror.ChunkData)
lastChunkPos := define.ChunkPos{0, 0}
lastChunk := &mirror.ChunkData{
Chunk: chunk.New(chunk.AirRID, define.Range{-64, 319}),
BlockNbts: make(map[define.CubePos]map[string]interface{}),
ChunkPos: lastChunkPos,
Chunk: chunk.New(chunk.AirRID, define.Range{-64, 319}),
BlockNbts: make(map[define.CubePos]map[string]interface{}),
BlockName: make(map[define.CubePos]string), // for bdx
BlockStates: make(map[define.CubePos]string), // for bdx
BlockData: make(map[define.CubePos]uint16), // for bdx
ChunkPos: lastChunkPos,
}
chunks[lastChunkPos] = lastChunk

Expand All @@ -77,9 +80,12 @@ func AlterImportPosStartAndSpeedWithReArrangeOnce(inChan chan *IOBlockForDecoder
if !hasK {
// chunk=&mirror.ChunkData{}
c = &mirror.ChunkData{
Chunk: chunk.New(chunk.AirRID, define.Range{-64, 319}),
BlockNbts: make(map[define.CubePos]map[string]interface{}),
ChunkPos: chunkPos,
Chunk: chunk.New(chunk.AirRID, define.Range{-64, 319}),
BlockNbts: make(map[define.CubePos]map[string]interface{}),
BlockName: make(map[define.CubePos]string), // for bdx
BlockStates: make(map[define.CubePos]string), // for bdx
BlockData: make(map[define.CubePos]uint16), // for bdx
ChunkPos: chunkPos,
}
chunks[chunkPos] = c
}
Expand All @@ -90,6 +96,14 @@ func AlterImportPosStartAndSpeedWithReArrangeOnce(inChan chan *IOBlockForDecoder
if b.NBT != nil {
lastChunk.BlockNbts[b.Pos] = b.NBT
}
if b.BlockName != "" && b.BlockStates == "" {
lastChunk.BlockName[b.Pos] = b.BlockName
lastChunk.BlockData[b.Pos] = b.BlockData
} // for bdx
if b.BlockName != "" && b.BlockStates != "" {
lastChunk.BlockName[b.Pos] = b.BlockName
lastChunk.BlockStates[b.Pos] = b.BlockStates
} // for bdx
}

// do rearrange
Expand All @@ -105,9 +119,12 @@ func AlterImportPosStartAndSpeedWithReArrangeOnce(inChan chan *IOBlockForDecoder
chunks = make(map[define.ChunkPos]*mirror.ChunkData)
lastChunkPos = define.ChunkPos{0, 0}
lastChunk = &mirror.ChunkData{
Chunk: chunk.New(chunk.AirRID, define.Range{-64, 319}),
BlockNbts: make(map[define.CubePos]map[string]interface{}),
ChunkPos: lastChunkPos,
Chunk: chunk.New(chunk.AirRID, define.Range{-64, 319}),
BlockNbts: make(map[define.CubePos]map[string]interface{}),
BlockName: make(map[define.CubePos]string), // for bdx
BlockStates: make(map[define.CubePos]string), // for bdx
BlockData: make(map[define.CubePos]uint16), // for bdx
ChunkPos: lastChunkPos,
}
}
}
Expand Down Expand Up @@ -163,6 +180,9 @@ func AlterImportPosStartAndSpeedWithReArrangeOnce(inChan chan *IOBlockForDecoder
chunk := chunks[chunkPos]
// fmt.Println(chunkPos)
nbts := chunk.BlockNbts
blockName := chunk.BlockName // for bdx
blockStates := chunk.BlockStates // for bdx
blockData := chunk.BlockData // for bdx
for subChunkI := int16(0); subChunkI < 24; subChunkI++ {
subChunk := chunk.Chunk.Sub()[subChunkI]
if subChunk.Empty() {
Expand All @@ -180,10 +200,28 @@ func AlterImportPosStartAndSpeedWithReArrangeOnce(inChan chan *IOBlockForDecoder
if counter < startFrom {
counter += 16 * 16 * 16
} else {
outChan <- &IOBlockForBuilder{
Pos: p,
RTID: blk,
Expand16: true,
if blockName[p] != "" && blockStates[p] != "" {
outChan <- &IOBlockForBuilder{
Pos: p,
RTID: blk,
Expand16: true,
BlockName: blockName[p], // for operation 13 which named `PlaceBlockWithBlockStates`
BlockStates: blockStates[p], // for operation 13 which named `PlaceBlockWithBlockStates`
}
} else if blockName[p] != "" && blockStates[p] == "" {
outChan <- &IOBlockForBuilder{
Pos: p,
RTID: blk,
Expand16: true,
BlockName: blockName[p], // for operation 7 which named `PlaceBlock`
BlockData: blockData[p], // for operation 7 which named `PlaceBlock`
}
} else {
outChan <- &IOBlockForBuilder{
Pos: p,
RTID: blk,
Expand16: true,
}
}
}
continue
Expand All @@ -205,15 +243,49 @@ func AlterImportPosStartAndSpeedWithReArrangeOnce(inChan chan *IOBlockForDecoder
continue
}
if nbt, hasK := nbts[p]; hasK {
outChan <- &IOBlockForBuilder{
Pos: p,
RTID: blk,
NBT: nbt,
if blockName[p] != "" && blockStates[p] != "" {
outChan <- &IOBlockForBuilder{
Pos: p,
RTID: blk,
NBT: nbt,
BlockName: blockName[p], // for operation 13 which named `PlaceBlockWithBlockStates`
BlockStates: blockStates[p], // for operation 13 which named `PlaceBlockWithBlockStates`
}
} else if blockName[p] != "" && blockStates[p] == "" {
outChan <- &IOBlockForBuilder{
Pos: p,
RTID: blk,
NBT: nbt,
BlockName: blockName[p], // for operation 7 which named `PlaceBlock`
BlockData: blockData[p], // for operation 7 which named `PlaceBlock`
}
} else {
outChan <- &IOBlockForBuilder{
Pos: p,
RTID: blk,
NBT: nbt,
}
}
} else {
outChan <- &IOBlockForBuilder{
Pos: p,
RTID: blk,
if blockName[p] != "" && blockStates[p] != "" {
outChan <- &IOBlockForBuilder{
Pos: p,
RTID: blk,
BlockName: blockName[p], // for operation 13 which named `PlaceBlockWithBlockStates`
BlockStates: blockStates[p], // for operation 13 which named `PlaceBlockWithBlockStates`
}
} else if blockName[p] != "" && blockStates[p] == "" {
outChan <- &IOBlockForBuilder{
Pos: p,
RTID: blk,
BlockName: blockName[p], // for operation 7 which named `PlaceBlock`
BlockData: blockData[p], // for operation 7 which named `PlaceBlock`
}
} else {
outChan <- &IOBlockForBuilder{
Pos: p,
RTID: blk,
}
}
}
}
Expand Down

0 comments on commit daddbc2

Please sign in to comment.