4
4
import java .util .ArrayList ;
5
5
import java .util .BitSet ;
6
6
import java .util .List ;
7
+ import java .util .Map ;
7
8
9
+ import com .comphenix .protocol .reflect .EquivalentConverter ;
8
10
import org .jetbrains .annotations .Nullable ;
9
11
10
12
import com .comphenix .protocol .injector .StructureCache ;
@@ -41,6 +43,7 @@ public static final class ChunkData extends AbstractWrapper {
41
43
42
44
private static final FieldAccessor BLOCK_ENTITIES_DATA_ACCESSOR ;
43
45
private static final FieldAccessor HEIGHTMAPS_ACCESSOR ;
46
+ private static final EquivalentConverter <Map <EnumWrappers .HeightmapType , long []>> HEIGHTMAPS_CONVERTER ;
44
47
private static final FieldAccessor BUFFER_ACCESSOR ;
45
48
46
49
static {
@@ -54,9 +57,17 @@ public static final class ChunkData extends AbstractWrapper {
54
57
BLOCK_ENTITIES_DATA_ACCESSOR = Accessors .getFieldAccessor (reflection .getField (FuzzyFieldContract .newBuilder ()
55
58
.typeExact (List .class )
56
59
.build ()));
57
- HEIGHTMAPS_ACCESSOR = Accessors .getFieldAccessor (reflection .getField (FuzzyFieldContract .newBuilder ()
58
- .typeExact (MinecraftReflection .getNBTCompoundClass ())
59
- .build ()));
60
+ if (MinecraftVersion .v1_21_5 .atOrAbove ()) {
61
+ HEIGHTMAPS_ACCESSOR = Accessors .getFieldAccessor (reflection .getField (FuzzyFieldContract .newBuilder ()
62
+ .typeExact (Map .class )
63
+ .build ()));
64
+ HEIGHTMAPS_CONVERTER = BukkitConverters .getMapConverter (EnumWrappers .getHeightmapTypeConverter (), Converters .passthrough (long [].class ));
65
+ } else {
66
+ HEIGHTMAPS_ACCESSOR = Accessors .getFieldAccessor (reflection .getField (FuzzyFieldContract .newBuilder ()
67
+ .typeExact (MinecraftReflection .getNBTCompoundClass ())
68
+ .build ()));
69
+ HEIGHTMAPS_CONVERTER = null ;
70
+ }
60
71
BUFFER_ACCESSOR = Accessors .getFieldAccessor (reflection .getField (FuzzyFieldContract .newBuilder ().typeExact (byte [].class ).build ()));
61
72
}
62
73
@@ -68,22 +79,50 @@ public ChunkData(Object handle) {
68
79
69
80
/**
70
81
* The heightmap of this chunk.
82
+ * <p>
83
+ * Removed in Minecraft 1.21.5.
71
84
*
72
85
* @return an NBT-Tag
86
+ * @deprecated Use {@link ChunkData#getHeightmaps()} instead.
73
87
*/
88
+ @ Deprecated
74
89
public NbtCompound getHeightmapsTag () {
75
90
return NbtFactory .fromNMSCompound (HEIGHTMAPS_ACCESSOR .get (handle ));
76
91
}
77
92
78
93
/**
79
94
* Sets the heightmap tag of this chunk.
95
+ * <p>
96
+ * Removed in Minecraft 1.21.5.
80
97
*
81
98
* @param heightmapsTag the new heightmaps tag.
99
+ * @deprecated Use {@link ChunkData#setHeightmaps(Map)} instead.
82
100
*/
101
+ @ Deprecated
83
102
public void setHeightmapsTag (NbtCompound heightmapsTag ) {
84
103
HEIGHTMAPS_ACCESSOR .set (handle , NbtFactory .fromBase (heightmapsTag ).getHandle ());
85
104
}
86
105
106
+ /**
107
+ * The heightmap of this chunk.
108
+ *
109
+ * @return a map containing the heightmaps
110
+ */
111
+ public Map <EnumWrappers .HeightmapType , long []> getHeightmaps () {
112
+ return HEIGHTMAPS_CONVERTER .getSpecific (HEIGHTMAPS_ACCESSOR .get (handle ));
113
+ }
114
+
115
+ /**
116
+ * Sets the heightmap tag of this chunk.
117
+ * <p>
118
+ * Removed in Minecraft 1.21.5.
119
+ *
120
+ * @param heightmaps the new heightmaps.
121
+ */
122
+ public void setHeightmaps (Map <EnumWrappers .HeightmapType , long []> heightmaps ) {
123
+ HEIGHTMAPS_ACCESSOR .set (handle , HEIGHTMAPS_CONVERTER .getGeneric (heightmaps ));
124
+ }
125
+
87
126
/**
88
127
* The actual structural data of this chunk as bytes.
89
128
*
@@ -130,12 +169,16 @@ public void setBlockEntityInfo(List<BlockEntityInfo> blockEntityInfo) {
130
169
131
170
/**
132
171
* Creates a new wrapper using predefined values.
172
+ * <p>
173
+ * Removed in Minecraft 1.21.5.
133
174
*
134
175
* @param heightmapsTag the heightmaps tag
135
176
* @param buffer the buffer
136
177
* @param blockEntityInfo a list of wrapped block entities
137
178
* @return a newly created wrapper
179
+ * @deprecated Use {@link ChunkData#fromValues(Map, byte[], List)} instead.
138
180
*/
181
+ @ Deprecated
139
182
public static ChunkData fromValues (NbtCompound heightmapsTag , byte [] buffer , List <BlockEntityInfo > blockEntityInfo ) {
140
183
ChunkData data = new ChunkData (LEVEL_CHUNK_PACKET_DATA_CONSTRUCTOR .invoke (StructureCache .newNullDataSerializer (), 0 , 0 ));
141
184
@@ -145,6 +188,24 @@ public static ChunkData fromValues(NbtCompound heightmapsTag, byte[] buffer, Lis
145
188
146
189
return new ChunkData (data );
147
190
}
191
+
192
+ /**
193
+ * Creates a new wrapper using predefined values.
194
+ *
195
+ * @param heightmaps the heightmaps
196
+ * @param buffer the buffer
197
+ * @param blockEntityInfo a list of wrapped block entities
198
+ * @return a newly created wrapper
199
+ */
200
+ public static ChunkData fromValues (Map <EnumWrappers .HeightmapType , long []> heightmaps , byte [] buffer , List <BlockEntityInfo > blockEntityInfo ) {
201
+ ChunkData data = new ChunkData (LEVEL_CHUNK_PACKET_DATA_CONSTRUCTOR .invoke (StructureCache .newNullDataSerializer (), 0 , 0 ));
202
+
203
+ data .setHeightmaps (heightmaps );
204
+ data .setBuffer (buffer );
205
+ data .setBlockEntityInfo (blockEntityInfo );
206
+
207
+ return new ChunkData (data );
208
+ }
148
209
}
149
210
150
211
/**
0 commit comments