Skip to content

Commit dca6f95

Browse files
Fix #87 Double chest facing north and east have contents swapped
1 parent 70734e4 commit dca6f95

File tree

2 files changed

+46
-39
lines changed

2 files changed

+46
-39
lines changed

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ the server won't break if you have these items in your inventory anymore.
2323
### Fixes
2424
- [#78] Error parsing sign text: IllegalStateException: component must not be null
2525
- [#79] Region files with axis number (X or Z) higher then 9 being ignored
26+
- [#87] Double chests facing north and east have the contents swapped
2627
- Internal mappings for barrel, grindstone, lectern, stonecutter, bell, campfire, bee_nest and beehive.
2728
Does not affects the output because they aren't supported by Nukkit 1.X, so they were all replaced by other blocks.
2829

@@ -134,8 +135,9 @@ them will be very bright.
134135

135136
[#78]: https://github.com/GameModsBR/Java2Nukkit-World-Converter/issues/78
136137
[#79]: https://github.com/GameModsBR/Java2Nukkit-World-Converter/issues/79
137-
138138
[#84]: https://github.com/GameModsBR/Java2Nukkit-World-Converter/issues/84
139+
[#87]: https://github.com/GameModsBR/Java2Nukkit-World-Converter/issues/87
140+
139141

140142
[Region 2.0.0]: https://gamemodsbr.github.io/Region-Manipulator/CHANGELOG.html#200---2020-01-24
141143
[Region 1.1.0]: https://gamemodsbr.github.io/Region-Manipulator/CHANGELOG.html#110---2019-06-02

src/main/kotlin/br/com/gamemods/j2nwc/internal/block-converter.kt

Lines changed: 43 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ internal fun JavaBlock.toNukkit(
5555
//if (blockData.originalBedrock?.let { it.blockId == 458 && (it.data and 0x8) == 0x8 } == true) {
5656
// Note: Tried to persist the barrel open state after a chest conversion but it is not possible, chests are open by BlockEventPacket
5757
//}
58+
val needsSwapping = type.properties?.getString("facing").let { it == "south" || it == "west" }
5859
val pair = when (type.properties?.getString("type")) {
5960
"left" -> when (type.properties?.getString("facing")) {
6061
"east" -> blockPos.xPos to blockPos.zPos +1
@@ -75,47 +76,51 @@ internal fun JavaBlock.toNukkit(
7576
nukkitEntity["pairx"] = x
7677
nukkitEntity["pairz"] = z
7778

78-
val y = blockPos.yPos
79-
val pairedChunkPos = ChunkPos(floor(x / 16.0).toInt(), floor(z / 16.0).toInt())
80-
val currentChunkPos = ChunkPos(floor(blockPos.xPos / 16.0).toInt(), floor(blockPos.zPos / 16.0).toInt())
81-
fun swapItems(nukkitRegion: Region) {
82-
nukkitRegion[pairedChunkPos]?.level?.getCompoundList("TileEntities")
83-
?.find { it.getInt("x") == x && it.getInt("y") == y && it.getInt("z") == z }
84-
?.also { pairedEntity ->
85-
if (pairedEntity.getNullableBooleanByte("--pair-processed--")) {
86-
pairedEntity.remove("--pair-processed--")
87-
} else {
88-
val thisItems = nukkitEntity.getList("Items")
89-
val otherItems = pairedEntity.getList("Items")
79+
if (needsSwapping) {
80+
val y = blockPos.yPos
81+
val pairedChunkPos = ChunkPos(floor(x / 16.0).toInt(), floor(z / 16.0).toInt())
82+
val currentChunkPos =
83+
ChunkPos(floor(blockPos.xPos / 16.0).toInt(), floor(blockPos.zPos / 16.0).toInt())
9084

91-
pairedEntity["Items"] = thisItems
92-
nukkitEntity["Items"] = otherItems
93-
nukkitEntity["--pair-processed--"] = true
94-
}
95-
}
96-
}
85+
fun swapItems(nukkitRegion: Region) {
86+
nukkitRegion[pairedChunkPos]?.level?.getCompoundList("TileEntities")
87+
?.find { it.getInt("x") == x && it.getInt("y") == y && it.getInt("z") == z }
88+
?.also { pairedEntity ->
89+
if (pairedEntity.getNullableBooleanByte("--pair-processed--")) {
90+
pairedEntity.remove("--pair-processed--")
91+
} else {
92+
val thisItems = nukkitEntity.getList("Items")
93+
val otherItems = pairedEntity.getList("Items")
9794

98-
val currentRegX = floor(currentChunkPos.xPos / 32.0).toInt()
99-
val currentRegZ = floor(currentChunkPos.zPos / 32.0).toInt()
100-
val pairedRegX = floor(pairedChunkPos.xPos / 32.0).toInt()
101-
val pairedRegZ = floor(pairedChunkPos.zPos / 32.0).toInt()
102-
if (currentRegX == pairedRegX && currentRegZ == pairedRegZ) {
103-
regionPostConversionHooks += { _, nukkitRegion ->
104-
swapItems(nukkitRegion)
95+
pairedEntity["Items"] = thisItems
96+
nukkitEntity["Items"] = otherItems
97+
nukkitEntity["--pair-processed--"] = true
98+
}
99+
}
105100
}
106-
} else {
107-
worldHooks += { _, worldDir ->
108-
try {
109-
modifyRegion(worldDir, pairedRegX, pairedRegZ, ::swapItems)
110-
} catch (e: FileNotFoundException) {
111-
System.err.println(
112-
"Could not swap the double chest items between the chests $blockPos and ${BlockPos(
113-
x,
114-
y,
115-
z
116-
)} because the file r.$pairedRegX.$pairedRegZ.mca does not exists!"
117-
)
118-
System.err.println(e.toString())
101+
102+
val currentRegX = floor(currentChunkPos.xPos / 32.0).toInt()
103+
val currentRegZ = floor(currentChunkPos.zPos / 32.0).toInt()
104+
val pairedRegX = floor(pairedChunkPos.xPos / 32.0).toInt()
105+
val pairedRegZ = floor(pairedChunkPos.zPos / 32.0).toInt()
106+
if (currentRegX == pairedRegX && currentRegZ == pairedRegZ) {
107+
regionPostConversionHooks += { _, nukkitRegion ->
108+
swapItems(nukkitRegion)
109+
}
110+
} else {
111+
worldHooks += { _, worldDir ->
112+
try {
113+
modifyRegion(worldDir, pairedRegX, pairedRegZ, ::swapItems)
114+
} catch (e: FileNotFoundException) {
115+
System.err.println(
116+
"Could not swap the double chest items between the chests $blockPos and ${BlockPos(
117+
x,
118+
y,
119+
z
120+
)} because the file r.$pairedRegX.$pairedRegZ.mca does not exists!"
121+
)
122+
System.err.println(e.toString())
123+
}
119124
}
120125
}
121126
}

0 commit comments

Comments
 (0)