1
1
package com .gtnewhorizons .neid .mixins .early .minecraft ;
2
2
3
- import java .nio .ByteBuffer ;
4
-
5
3
import net .minecraft .nbt .NBTTagCompound ;
6
- import net .minecraft .nbt .NBTTagList ;
7
- import net .minecraft .world .World ;
8
4
import net .minecraft .world .chunk .NibbleArray ;
9
5
import net .minecraft .world .chunk .storage .AnvilChunkLoader ;
10
6
import net .minecraft .world .chunk .storage .ExtendedBlockStorage ;
11
7
12
8
import org .spongepowered .asm .mixin .Mixin ;
13
9
import org .spongepowered .asm .mixin .injection .At ;
14
- import org .spongepowered .asm .mixin .injection .Inject ;
15
10
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 ;
18
11
19
12
import com .gtnewhorizons .neid .Constants ;
20
13
import com .gtnewhorizons .neid .NEIDConfig ;
21
14
import com .gtnewhorizons .neid .mixins .interfaces .IExtendedBlockStorageMixin ;
22
15
import com .llamalad7 .mixinextras .sugar .Local ;
23
- import com .llamalad7 .mixinextras .sugar .ref .LocalRef ;
24
16
25
- @ Mixin (value = AnvilChunkLoader .class , priority = 1 )
17
+ @ Mixin (AnvilChunkLoader .class )
26
18
public class MixinAnvilChunkLoader {
27
19
28
- @ Inject (method = "writeChunkToNBT" , at = @ At ("HEAD" ))
29
- private void neid$injectLevelTag (CallbackInfo ci , @ Local NBTTagCompound tag ) {
30
- tag .setBoolean ("NEID" , true );
31
- }
32
-
33
20
@ Redirect (
34
- method = "writeChunkToNBT" ,
35
- at = @ At (
36
- value = "INVOKE" ,
37
- target = "Lnet/minecraft/nbt/NBTTagCompound;setByteArray(Ljava/lang/String;[B)V" ,
38
- ordinal = 0 ),
39
- require = 1 )
21
+ method = "writeChunkToNBT" ,
22
+ at = @ At (
23
+ value = "INVOKE" ,
24
+ target = "Lnet/minecraft/nbt/NBTTagCompound;setByteArray(Ljava/lang/String;[B)V" ,
25
+ ordinal = 0 ),
26
+ require = 1 )
40
27
private void neid$overrideWriteLSBArray (NBTTagCompound nbt , String s , byte [] oldbrokenbytes ,
41
- @ Local (ordinal = 0 ) ExtendedBlockStorage ebs ) {
28
+ @ Local (ordinal = 0 ) ExtendedBlockStorage ebs ) {
42
29
IExtendedBlockStorageMixin ebsMixin = (IExtendedBlockStorageMixin ) ebs ;
43
30
nbt .setByteArray ("Blocks16" , ebsMixin .getBlockData ());
44
31
if (NEIDConfig .PostNeidWorldsSupport ) {
@@ -73,14 +60,14 @@ public class MixinAnvilChunkLoader {
73
60
}
74
61
75
62
@ Redirect (
76
- method = "writeChunkToNBT" ,
77
- at = @ At (
78
- value = "INVOKE" ,
79
- target = "Lnet/minecraft/nbt/NBTTagCompound;setByteArray(Ljava/lang/String;[B)V" ,
80
- ordinal = 2 ),
81
- require = 1 )
63
+ method = "writeChunkToNBT" ,
64
+ at = @ At (
65
+ value = "INVOKE" ,
66
+ target = "Lnet/minecraft/nbt/NBTTagCompound;setByteArray(Ljava/lang/String;[B)V" ,
67
+ ordinal = 2 ),
68
+ require = 1 )
82
69
private void neid$overrideWriteMetadataArray (NBTTagCompound nbt , String s , byte [] oldbrokenbytes ,
83
- @ Local (ordinal = 0 ) ExtendedBlockStorage ebs ) {
70
+ @ Local (ordinal = 0 ) ExtendedBlockStorage ebs ) {
84
71
IExtendedBlockStorageMixin ebsMixin = (IExtendedBlockStorageMixin ) ebs ;
85
72
nbt .setByteArray ("Data16" , ebsMixin .getBlockMeta ());
86
73
if (NEIDConfig .PostNeidWorldsSupport ) {
@@ -104,94 +91,67 @@ public class MixinAnvilChunkLoader {
104
91
}
105
92
}
106
93
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
-
157
94
@ Redirect (
158
- method = "readChunkFromNBT" ,
159
- at = @ At (
160
- value = "INVOKE" ,
161
- target = "Lnet/minecraft/world/chunk/storage/ExtendedBlockStorage;setBlockLSBArray([B)V" ),
162
- require = 1 )
95
+ method = "readChunkFromNBT" ,
96
+ at = @ At (
97
+ value = "INVOKE" ,
98
+ target = "Lnet/minecraft/world/chunk/storage/ExtendedBlockStorage;setBlockLSBArray([B)V" ),
99
+ require = 1 )
163
100
private void neid$overrideReadLSBArray (ExtendedBlockStorage ebs , byte [] oldbrokenbytes ,
164
- @ Local (ordinal = 1 ) NBTTagCompound nbt ) {
101
+ @ Local (ordinal = 1 ) NBTTagCompound nbt ) {
165
102
IExtendedBlockStorageMixin ebsMixin = (IExtendedBlockStorageMixin ) ebs ;
166
103
if (nbt .hasKey ("Blocks16" )) {
167
104
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
+ }
168
120
} else {
169
121
assert false ;
170
122
}
171
123
}
172
124
173
125
@ Redirect (
174
- method = "readChunkFromNBT" ,
175
- at = @ At (
176
- value = "INVOKE" ,
177
- target = "Lnet/minecraft/nbt/NBTTagCompound;hasKey(Ljava/lang/String;I)Z" ,
178
- ordinal = 0 ),
179
- require = 1 )
126
+ method = "readChunkFromNBT" ,
127
+ at = @ At (
128
+ value = "INVOKE" ,
129
+ target = "Lnet/minecraft/nbt/NBTTagCompound;hasKey(Ljava/lang/String;I)Z" ,
130
+ ordinal = 0 ),
131
+ require = 1 )
180
132
private boolean neid$overrideReadMSBArray (NBTTagCompound nbttagcompound1 , String s , int i ) {
181
133
return false ;
182
134
}
183
135
184
136
@ Redirect (
185
- method = "readChunkFromNBT" ,
186
- at = @ At (
187
- value = "INVOKE" ,
188
- target = "Lnet/minecraft/world/chunk/storage/ExtendedBlockStorage;setBlockMetadataArray(Lnet/minecraft/world/chunk/NibbleArray;)V" ),
189
- require = 1 )
137
+ method = "readChunkFromNBT" ,
138
+ at = @ At (
139
+ value = "INVOKE" ,
140
+ target = "Lnet/minecraft/world/chunk/storage/ExtendedBlockStorage;setBlockMetadataArray(Lnet/minecraft/world/chunk/NibbleArray;)V" ),
141
+ require = 1 )
190
142
private void neid$overrideReadMetadataArray (ExtendedBlockStorage ebs , NibbleArray oldBrokenNibbleArray ,
191
- @ Local (ordinal = 1 ) NBTTagCompound nbt ) {
143
+ @ Local (ordinal = 1 ) NBTTagCompound nbt ) {
192
144
IExtendedBlockStorageMixin ebsMixin = (IExtendedBlockStorageMixin ) ebs ;
193
145
if (nbt .hasKey ("Data16" )) {
194
146
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
+ }
195
155
} else {
196
156
assert false ;
197
157
}
0 commit comments