@@ -55,6 +55,7 @@ internal fun JavaBlock.toNukkit(
55
55
// if (blockData.originalBedrock?.let { it.blockId == 458 && (it.data and 0x8) == 0x8 } == true) {
56
56
// Note: Tried to persist the barrel open state after a chest conversion but it is not possible, chests are open by BlockEventPacket
57
57
// }
58
+ val needsSwapping = type.properties?.getString(" facing" ).let { it == " south" || it == " west" }
58
59
val pair = when (type.properties?.getString(" type" )) {
59
60
" left" -> when (type.properties?.getString(" facing" )) {
60
61
" east" -> blockPos.xPos to blockPos.zPos + 1
@@ -75,47 +76,51 @@ internal fun JavaBlock.toNukkit(
75
76
nukkitEntity[" pairx" ] = x
76
77
nukkitEntity[" pairz" ] = z
77
78
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())
90
84
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" )
97
94
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
+ }
105
100
}
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
+ }
119
124
}
120
125
}
121
126
}
0 commit comments