1
1
package com .gtnewhorizons .neid .mixins .early .minecraft ;
2
2
3
3
import net .minecraft .nbt .NBTTagCompound ;
4
+ import net .minecraft .world .chunk .NibbleArray ;
4
5
import net .minecraft .world .chunk .storage .AnvilChunkLoader ;
5
6
import net .minecraft .world .chunk .storage .ExtendedBlockStorage ;
6
7
@@ -23,11 +24,11 @@ public class MixinAnvilChunkLoader {
23
24
target = "Lnet/minecraft/nbt/NBTTagCompound;setByteArray(Ljava/lang/String;[B)V" ,
24
25
ordinal = 0 ),
25
26
require = 1 )
26
- private void neid$overrideSetByteArray (NBTTagCompound nbt , String s , byte [] oldbrokenbytes ,
27
+ private void neid$overrideWriteLSBArray (NBTTagCompound nbt , String s , byte [] oldbrokenbytes ,
27
28
@ Local (ordinal = 0 ) ExtendedBlockStorage ebs ) {
28
29
IExtendedBlockStorageMixin ebsMixin = (IExtendedBlockStorageMixin ) ebs ;
29
30
nbt .setByteArray ("Blocks16" , ebsMixin .getBlockData ());
30
- if (NEIDConfig .postNeidWorldsSupport ) {
31
+ if (NEIDConfig .PostNeidWorldsSupport ) {
31
32
final short [] data = ebsMixin .getBlock16BArray ();
32
33
final byte [] lsbData = new byte [data .length ];
33
34
byte [] msbData = null ;
@@ -58,13 +59,45 @@ public class MixinAnvilChunkLoader {
58
59
}
59
60
}
60
61
62
+ @ Redirect (
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 )
69
+ private void neid$overrideWriteMetadataArray (NBTTagCompound nbt , String s , byte [] oldbrokenbytes ,
70
+ @ Local (ordinal = 0 ) ExtendedBlockStorage ebs ) {
71
+ IExtendedBlockStorageMixin ebsMixin = (IExtendedBlockStorageMixin ) ebs ;
72
+ nbt .setByteArray ("Data16" , ebsMixin .getBlockMeta ());
73
+ if (NEIDConfig .PostNeidWorldsSupport ) {
74
+ final short [] data = ebsMixin .getBlock16BMetaArray ();
75
+ final byte [] metaData = new byte [data .length / 2 ];
76
+ for (int i = 0 ; i < data .length ; i += 2 ) {
77
+ int meta1 = data [i ];
78
+ int meta2 = data [i + 1 ];
79
+
80
+ if (meta1 < 0 || meta1 > 15 ) {
81
+ meta1 = 0 ;
82
+ }
83
+ if (meta2 < 0 || meta2 > 15 ) {
84
+ meta2 = 0 ;
85
+ }
86
+
87
+ metaData [i / 2 ] = (byte ) (meta2 << 4 | meta1 );
88
+ final int meta = data [i ];
89
+ }
90
+ nbt .setByteArray ("Data" , metaData );
91
+ }
92
+ }
93
+
61
94
@ Redirect (
62
95
method = "readChunkFromNBT" ,
63
96
at = @ At (
64
97
value = "INVOKE" ,
65
98
target = "Lnet/minecraft/world/chunk/storage/ExtendedBlockStorage;setBlockLSBArray([B)V" ),
66
99
require = 1 )
67
- private void neid$overrideSetLSBArray (ExtendedBlockStorage ebs , byte [] oldbrokenbytes ,
100
+ private void neid$overrideReadLSBArray (ExtendedBlockStorage ebs , byte [] oldbrokenbytes ,
68
101
@ Local (ordinal = 1 ) NBTTagCompound nbt ) {
69
102
IExtendedBlockStorageMixin ebsMixin = (IExtendedBlockStorageMixin ) ebs ;
70
103
if (nbt .hasKey ("Blocks16" )) {
@@ -96,7 +129,31 @@ public class MixinAnvilChunkLoader {
96
129
target = "Lnet/minecraft/nbt/NBTTagCompound;hasKey(Ljava/lang/String;I)Z" ,
97
130
ordinal = 0 ),
98
131
require = 1 )
99
- private boolean neid$nukeMSBCheck (NBTTagCompound nbttagcompound1 , String s , int i ) {
132
+ private boolean neid$overrideReadMSBArray (NBTTagCompound nbttagcompound1 , String s , int i ) {
100
133
return false ;
101
134
}
135
+
136
+ @ Redirect (
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 )
142
+ private void neid$overrideReadMetadataArray (ExtendedBlockStorage ebs , NibbleArray oldBrokenNibbleArray ,
143
+ @ Local (ordinal = 1 ) NBTTagCompound nbt ) {
144
+ IExtendedBlockStorageMixin ebsMixin = (IExtendedBlockStorageMixin ) ebs ;
145
+ if (nbt .hasKey ("Data16" )) {
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
+ }
155
+ } else {
156
+ assert false ;
157
+ }
158
+ }
102
159
}
0 commit comments