1
1
package com .gtnewhorizons .neid .mixins .early .minecraft ;
2
2
3
+ import java .nio .ByteBuffer ;
4
+
3
5
import net .minecraft .nbt .NBTTagCompound ;
6
+ import net .minecraft .nbt .NBTTagList ;
7
+ import net .minecraft .world .World ;
4
8
import net .minecraft .world .chunk .NibbleArray ;
5
9
import net .minecraft .world .chunk .storage .AnvilChunkLoader ;
6
10
import net .minecraft .world .chunk .storage .ExtendedBlockStorage ;
7
11
8
12
import org .spongepowered .asm .mixin .Mixin ;
9
13
import org .spongepowered .asm .mixin .injection .At ;
14
+ import org .spongepowered .asm .mixin .injection .Inject ;
10
15
import org .spongepowered .asm .mixin .injection .Redirect ;
16
+ import org .spongepowered .asm .mixin .injection .callback .CallbackInfo ;
17
+ import org .spongepowered .asm .mixin .injection .callback .CallbackInfoReturnable ;
11
18
12
19
import com .gtnewhorizons .neid .Constants ;
13
20
import com .gtnewhorizons .neid .NEIDConfig ;
14
21
import com .gtnewhorizons .neid .mixins .interfaces .IExtendedBlockStorageMixin ;
15
22
import com .llamalad7 .mixinextras .sugar .Local ;
23
+ import com .llamalad7 .mixinextras .sugar .ref .LocalRef ;
16
24
17
- @ Mixin (AnvilChunkLoader .class )
25
+ @ Mixin (value = AnvilChunkLoader .class , priority = 1 )
18
26
public class MixinAnvilChunkLoader {
19
27
28
+ @ Inject (method = "writeChunkToNBT" , at = @ At ("HEAD" ))
29
+ private void neid$injectLevelTag (CallbackInfo ci , @ Local NBTTagCompound tag ) {
30
+ tag .setBoolean ("NEID" , true );
31
+ }
32
+
20
33
@ Redirect (
21
34
method = "writeChunkToNBT" ,
22
35
at = @ At (
@@ -91,6 +104,56 @@ public class MixinAnvilChunkLoader {
91
104
}
92
105
}
93
106
107
+ @ Inject (
108
+ method = "checkedReadChunkFromNBT__Async" ,
109
+ at = @ At (
110
+ value = "INVOKE" ,
111
+ target = "Lnet/minecraft/world/chunk/storage/AnvilChunkLoader;readChunkFromNBT(Lnet/minecraft/world/World;Lnet/minecraft/nbt/NBTTagCompound;)Lnet/minecraft/world/chunk/Chunk;" ),
112
+ remap = false )
113
+ private void neid$preprocessOldChunk (CallbackInfoReturnable <Object []> cir , @ Local World world ,
114
+ @ Local LocalRef <NBTTagCompound > tag ) {
115
+ NBTTagCompound level = tag .get ().getCompoundTag ("Level" );
116
+
117
+ if (!level .hasKey ("NEID" )) {
118
+ NBTTagList nbttaglist = level .getTagList ("Sections" , 10 );
119
+ for (int i = 0 ; i < nbttaglist .tagCount (); i ++) {
120
+ NBTTagCompound tag1 = nbttaglist .getCompoundTagAt (i );
121
+ if (tag1 .hasKey ("Blocks" ) && !tag1 .hasKey ("Blocks16" )) {
122
+ final byte [] lsbData = tag1 .getByteArray ("Blocks" );
123
+ final short [] out = new short [Constants .BLOCKS_PER_EBS ];
124
+ if (tag1 .hasKey ("Add" )) {
125
+ final byte [] msbData = tag1 .getByteArray ("Add" );
126
+ for (int j = 0 ; j < out .length ; j += 2 ) {
127
+ final byte msPart = msbData [j / 2 ];
128
+ out [j ] = (short ) ((lsbData [j ] & 0xFF ) | (msPart & 0xF ) << 8 );
129
+ out [j + 1 ] = (short ) ((lsbData [j + 1 ] & 0xFF ) | (msPart & 0xF0 ) << 4 );
130
+ }
131
+ } else {
132
+ for (int j = 0 ; j < out .length ; j ++) {
133
+ out [j ] = (short ) (lsbData [j ] & 0xFF );
134
+ }
135
+ }
136
+ final byte [] ret = new byte [out .length * 2 ];
137
+ ByteBuffer .wrap (ret ).asShortBuffer ().put (out );
138
+ tag1 .setByteArray ("Blocks16" , ret );
139
+ }
140
+ if (tag1 .hasKey ("Data" ) && !tag1 .hasKey ("Data16" )) {
141
+ final byte [] metaData = tag1 .getByteArray ("Data" );
142
+ final short [] out = new short [Constants .BLOCKS_PER_EBS ];
143
+ for (int j = 0 ; j < out .length ; j += 2 ) {
144
+ final byte meta = metaData [j / 2 ];
145
+ out [j ] = (short ) (meta & 0xF );
146
+ out [j + 1 ] = (short ) ((meta >> 4 ) & 0xF );
147
+ }
148
+ final byte [] ret = new byte [out .length * 2 ];
149
+ ByteBuffer .wrap (ret ).asShortBuffer ().put (out );
150
+ tag1 .setByteArray ("Data16" , ret );
151
+ }
152
+ }
153
+ level .setBoolean ("NEID" , true );
154
+ }
155
+ }
156
+
94
157
@ Redirect (
95
158
method = "readChunkFromNBT" ,
96
159
at = @ At (
@@ -102,21 +165,6 @@ public class MixinAnvilChunkLoader {
102
165
IExtendedBlockStorageMixin ebsMixin = (IExtendedBlockStorageMixin ) ebs ;
103
166
if (nbt .hasKey ("Blocks16" )) {
104
167
ebsMixin .setBlockData (nbt .getByteArray ("Blocks16" ), 0 );
105
- } else if (nbt .hasKey ("Blocks" )) {
106
- final short [] out = ebsMixin .getBlock16BArray ();
107
- final byte [] lsbData = nbt .getByteArray ("Blocks" );
108
- if (nbt .hasKey ("Add" )) {
109
- final byte [] msbData = nbt .getByteArray ("Add" );
110
- for (int i = 0 ; i < out .length ; i += 2 ) {
111
- final byte msPart = msbData [i / 2 ];
112
- out [i ] = (short ) ((lsbData [i ] & 0xFF ) | (msPart & 0xF ) << 8 );
113
- out [i + 1 ] = (short ) ((lsbData [i + 1 ] & 0xFF ) | (msPart & 0xF0 ) << 4 );
114
- }
115
- } else {
116
- for (int j = 0 ; j < out .length ; ++j ) {
117
- out [j ] = (short ) (lsbData [j ] & 0xFF );
118
- }
119
- }
120
168
} else {
121
169
assert false ;
122
170
}
@@ -144,14 +192,6 @@ public class MixinAnvilChunkLoader {
144
192
IExtendedBlockStorageMixin ebsMixin = (IExtendedBlockStorageMixin ) ebs ;
145
193
if (nbt .hasKey ("Data16" )) {
146
194
ebsMixin .setBlockMeta (nbt .getByteArray ("Data16" ), 0 );
147
- } else if (nbt .hasKey ("Data" )) {
148
- final short [] out = ebsMixin .getBlock16BMetaArray ();
149
- final byte [] metaData = nbt .getByteArray ("Data" );
150
- for (int i = 0 ; i < out .length ; i += 2 ) {
151
- final byte meta = metaData [i / 2 ];
152
- out [i ] = (short ) (meta & 0xF );
153
- out [i + 1 ] = (short ) ((meta >> 4 ) & 0xF );
154
- }
155
195
} else {
156
196
assert false ;
157
197
}
0 commit comments