6
6
import com .mojang .brigadier .exceptions .SimpleCommandExceptionType ;
7
7
import net .fabricmc .fabric .api .client .command .v2 .FabricClientCommandSource ;
8
8
import net .minecraft .block .MapColor ;
9
- import net .minecraft .block .entity .BlockEntity ;
10
9
import net .minecraft .client .MinecraftClient ;
11
10
import net .minecraft .client .network .ClientPlayerEntity ;
12
11
import net .minecraft .client .texture .NativeImage ;
30
29
import java .util .stream .Collectors ;
31
30
import java .util .stream .StreamSupport ;
32
31
33
- import static com .mojang .brigadier .arguments .IntegerArgumentType .*;
34
- import static net .fabricmc .fabric .api .client .command .v2 .ClientCommandManager .*;
32
+ import static com .mojang .brigadier .arguments .IntegerArgumentType .getInteger ;
33
+ import static com .mojang .brigadier .arguments .IntegerArgumentType .integer ;
34
+ import static net .fabricmc .fabric .api .client .command .v2 .ClientCommandManager .argument ;
35
+ import static net .fabricmc .fabric .api .client .command .v2 .ClientCommandManager .literal ;
35
36
36
37
public class MapCommand {
37
38
private static final SimpleCommandExceptionType NO_HELD_MAP_EXCEPTION = new SimpleCommandExceptionType (Text .translatable ("commands.cmap.noHeld" ));
@@ -64,8 +65,8 @@ private static MapInfo[][] getMaps(ClientPlayerEntity player, MinecraftClient cl
64
65
private static int exportMap (FabricClientCommandSource source , int upscale ) throws CommandSyntaxException {
65
66
MapInfo [][] mapInfo = getMaps (source .getPlayer (), source .getClient ());
66
67
// calculate width and height
67
- int width = mapInfo [0 ].length * 128 * upscale ;
68
- int height = mapInfo .length * 128 * upscale ;
68
+ int width = mapInfo [0 ].length * FilledMapItem . field_30907 * upscale ;
69
+ int height = mapInfo .length * FilledMapItem . field_30908 * upscale ;
69
70
70
71
try (NativeImage image = new NativeImage (NativeImage .Format .RGBA , width , height , true )) {
71
72
for (int i = 0 ; i < mapInfo .length ; ++i ) {
@@ -74,7 +75,7 @@ private static int exportMap(FabricClientCommandSource source, int upscale) thro
74
75
if (info == null ) {
75
76
continue ;
76
77
}
77
- drawMapOffset (image , info , j * 128 * upscale , i * 128 * upscale , upscale );
78
+ drawMapOffset (image , info , j * FilledMapItem . field_30907 * upscale , i * FilledMapItem . field_30908 * upscale , upscale );
78
79
}
79
80
}
80
81
File screenshotDir = new File (source .getClient ().runDirectory , "screenshots" );
@@ -93,8 +94,8 @@ private static int exportMap(FabricClientCommandSource source, int upscale) thro
93
94
}
94
95
95
96
private static void drawMapOffset (NativeImage image , MapInfo map , int xOff , int yOff , int upscale ) {
96
- for (int i = 0 ; i < 128 ; ++i ) {
97
- for (int j = 0 ; j < 128 ; ++j ) {
97
+ for (int i = 0 ; i < FilledMapItem . field_30907 ; ++i ) {
98
+ for (int j = 0 ; j < FilledMapItem . field_30908 ; ++j ) {
98
99
int color = MapColor .getRenderColor (map .getColor (i , j ));
99
100
for (int k = 0 ; k < upscale ; k ++) {
100
101
for (int l = 0 ; l < upscale ; l ++) {
@@ -117,7 +118,7 @@ private static MapInfo fromHand(ClientPlayerEntity player) throws CommandSyntaxE
117
118
return null ;
118
119
}
119
120
120
- return new MapInfo (fromItemStack (player .world , map ), 0 );
121
+ return new MapInfo (fromItemStack (player .getWorld () , map ), 0 );
121
122
}
122
123
123
124
private static MapInfo [][] fromWorld (ClientPlayerEntity player , Entity target ) {
@@ -227,7 +228,7 @@ private static MapState fromItemStack(World world, ItemStack map) throws Command
227
228
228
229
private static MapState fromItemFrame (ItemFrameEntity entity ) {
229
230
Integer mapId = entity .getMapId ().orElseThrow ();
230
- return FilledMapItem .getMapState (mapId , entity .world );
231
+ return FilledMapItem .getMapState (mapId , entity .getWorld () );
231
232
}
232
233
233
234
private record MapInfo (MapState state , int rotation ) {
@@ -236,33 +237,54 @@ public int getColor(int x, int y) {
236
237
// rotate x/y
237
238
switch (rotation % 4 ) {
238
239
case 0 -> {
239
- return state .colors [x + y * 128 ];
240
+ return state .colors [x + y * FilledMapItem . field_30907 ];
240
241
}
241
242
case 1 -> {
242
243
// 90 clockwise
243
244
int newX = y ;
244
- int newY = 127 - x ;
245
- return state .colors [newX + newY * 128 ];
245
+ int newY = FilledMapItem . field_30907 - x - 1 ;
246
+ return state .colors [newX + newY * FilledMapItem . field_30907 ];
246
247
}
247
248
case 2 -> {
248
249
// 180 clockwise
249
- int newX = 127 - x ;
250
- int newY = 127 - y ;
251
- return state .colors [newX + newY * 128 ];
250
+ int newX = FilledMapItem . field_30907 - x - 1 ;
251
+ int newY = FilledMapItem . field_30908 - y - 1 ;
252
+ return state .colors [newX + newY * FilledMapItem . field_30907 ];
252
253
}
253
254
case 3 -> {
254
255
// 270 clockwise
255
- int newX = 127 - y ;
256
+ int newX = FilledMapItem . field_30908 - y - 1 ;
256
257
int newY = x ;
257
- return state .colors [newX + newY * 128 ];
258
+ return state .colors [newX + newY * FilledMapItem . field_30907 ];
258
259
}
259
260
// this should never be possible
260
261
default -> throw new IllegalStateException ("Unexpected value: " + rotation );
261
262
}
262
263
}
264
+
265
+ public int width () {
266
+ if (rotation % 2 == 0 ) {
267
+ return FilledMapItem .field_30907 ;
268
+ } else {
269
+ return FilledMapItem .field_30908 ;
270
+ }
271
+ }
272
+
273
+ public int height () {
274
+ if (rotation % 2 == 0 ) {
275
+ return FilledMapItem .field_30908 ;
276
+ } else {
277
+ return FilledMapItem .field_30907 ;
278
+ }
279
+ }
263
280
}
264
281
265
282
private record FramePos (BlockPos pos , Direction facing ) {
283
+
284
+ }
285
+
286
+ private record Vec2i (int x , int z ) {
287
+
266
288
}
267
289
268
290
}
0 commit comments