Skip to content

Commit 37d8998

Browse files
committed
Fix only chest can contains items when given a legacy BDX file
1 parent b902ed7 commit 37d8998

File tree

3 files changed

+70
-41
lines changed

3 files changed

+70
-41
lines changed

converter/chest_block.go

Lines changed: 0 additions & 38 deletions
This file was deleted.

converter/container_data.go

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
package converter
2+
3+
import (
4+
"fmt"
5+
"strings"
6+
7+
"github.com/TriM-Organization/bedrock-world-operator/block"
8+
"github.com/TriM-Organization/merry-memory/protocol/encoding"
9+
)
10+
11+
// SetContainerData ..
12+
func (c *converter) SetContainerData(data []encoding.ChestSlot) error {
13+
var blockNBTID string
14+
15+
items := make([]any, 0)
16+
nbtMap := map[string]any{
17+
"x": c.penPos[0],
18+
"y": c.penPos[1],
19+
"z": c.penPos[2],
20+
}
21+
for _, value := range data {
22+
items = append(items, map[string]any{
23+
"Count": byte(value.Count),
24+
"Damage": int16(value.Damage),
25+
"Name": value.Name,
26+
"Slot": byte(value.Slot),
27+
})
28+
}
29+
30+
blockRuntimeID, err := c.mcworld.LoadBlock(c.penPos[0], int16(c.penPos[1]), c.penPos[2])
31+
if err != nil {
32+
return fmt.Errorf("SetCommandBlock: %v", err)
33+
}
34+
blockName, _, _ := block.RuntimeIDToState(blockRuntimeID)
35+
36+
switch blockName {
37+
case "minecraft:blast_furnace", "minecraft:lit_blast_furnace":
38+
blockNBTID = "BlastFurnace"
39+
case "minecraft:furnace", "minecraft:lit_furnace":
40+
blockNBTID = "Furnace"
41+
case "minecraft:smoker", "minecraft:lit_smoker":
42+
blockNBTID = "Smoker"
43+
case "minecraft:chest", "minecraft:trapped_chest":
44+
blockNBTID = "Chest"
45+
case "minecraft:hopper":
46+
blockNBTID = "Hopper"
47+
case "minecraft:dispenser":
48+
blockNBTID = "Dispenser"
49+
case "minecraft:dropper":
50+
blockNBTID = "Dropper"
51+
case "minecraft:barrel":
52+
blockNBTID = "Barrel"
53+
case "minecraft:crafter":
54+
blockNBTID = "Crafter"
55+
}
56+
if strings.Contains(blockName, "shulker_box") {
57+
blockNBTID = "ShulkerBox"
58+
nbtMap["facing"] = byte(1)
59+
}
60+
61+
nbtMap["Items"] = items
62+
nbtMap["id"] = blockNBTID
63+
if err = c.mcworld.SetBlockNBT(c.penPos[0], c.penPos[1], c.penPos[2], nbtMap); err != nil {
64+
return fmt.Errorf("SetCommandBlock: %v", err)
65+
}
66+
return nil
67+
}

converter/converter.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,14 +139,14 @@ func ConvertBDXToMCWorld(bdxPath string, mcworldPath string) error {
139139
if err = converter.SetRuntimeBlock(uint32(c.BlockRuntimeID)); err != nil {
140140
return fmt.Errorf("ConvertBDXToMCWorld: %v", err)
141141
}
142-
if err = converter.SetChestBlock(c.ChestSlots); err != nil {
142+
if err = converter.SetContainerData(c.ChestSlots); err != nil {
143143
return fmt.Errorf("ConvertBDXToMCWorld: %v", err)
144144
}
145145
case *command.PlaceRuntimeBlockWithChestDataAndUint32RuntimeID:
146146
if err = converter.SetRuntimeBlock(c.BlockRuntimeID); err != nil {
147147
return fmt.Errorf("ConvertBDXToMCWorld: %v", err)
148148
}
149-
if err = converter.SetChestBlock(c.ChestSlots); err != nil {
149+
if err = converter.SetContainerData(c.ChestSlots); err != nil {
150150
return fmt.Errorf("ConvertBDXToMCWorld: %v", err)
151151
}
152152
case *command.AssignDebugData:
@@ -155,7 +155,7 @@ func ConvertBDXToMCWorld(bdxPath string, mcworldPath string) error {
155155
if err = converter.SetBlockLegacyByIndex(c.BlockConstantStringID, c.BlockData); err != nil {
156156
return fmt.Errorf("ConvertBDXToMCWorld: %v", err)
157157
}
158-
if err = converter.SetChestBlock(c.ChestSlots); err != nil {
158+
if err = converter.SetContainerData(c.ChestSlots); err != nil {
159159
return fmt.Errorf("ConvertBDXToMCWorld: %v", err)
160160
}
161161
case *command.PlaceBlockWithNBTData:

0 commit comments

Comments
 (0)