1
+ package com .samsthenerd .hexgloop .casting .canvas ;
2
+
3
+ import java .util .ArrayList ;
4
+ import java .util .List ;
5
+
6
+ import com .samsthenerd .hexgloop .HexGloop ;
7
+ import com .samsthenerd .hexgloop .items .HexGloopItems ;
8
+ import com .samsthenerd .hexgloop .items .ItemSlateCanvas ;
9
+
10
+ import at .petrak .hexcasting .api .spell .Action ;
11
+ import at .petrak .hexcasting .api .spell .OperationResult ;
12
+ import at .petrak .hexcasting .api .spell .OperatorUtils ;
13
+ import at .petrak .hexcasting .api .spell .casting .CastingContext ;
14
+ import at .petrak .hexcasting .api .spell .casting .eval .SpellContinuation ;
15
+ import at .petrak .hexcasting .api .spell .casting .sideeffects .OperatorSideEffect ;
16
+ import at .petrak .hexcasting .api .spell .iota .Iota ;
17
+ import at .petrak .hexcasting .api .spell .iota .NullIota ;
18
+ import kotlin .collections .CollectionsKt ;
19
+ import net .minecraft .block .MapColor ;
20
+ import net .minecraft .block .MapColor .Brightness ;
21
+ import net .minecraft .item .FilledMapItem ;
22
+ import net .minecraft .item .ItemStack ;
23
+ import net .minecraft .item .map .MapState ;
24
+ import net .minecraft .text .Text ;
25
+ import net .minecraft .util .Pair ;
26
+ import net .minecraft .util .math .Vec3d ;
27
+ import net .minecraft .util .math .Vec3i ;
28
+
29
+ public class OpPutColor implements Action {
30
+
31
+ public OpPutColor (){
32
+ }
33
+
34
+ @ Override
35
+ public boolean isGreat (){ return false ;}
36
+
37
+ @ Override
38
+ public boolean getCausesBlindDiversion (){ return false ;}
39
+
40
+ @ Override
41
+ public boolean getAlwaysProcessGreatSpell (){ return false ;}
42
+
43
+ @ Override
44
+ public Text getDisplayName (){
45
+ return DefaultImpls .getDisplayName (this );
46
+ }
47
+
48
+ @ Override
49
+ public OperationResult operate (SpellContinuation continuation , List <Iota > stack , Iota ravenmind , CastingContext context ){
50
+ // potentially get an entity first -- deal with that later
51
+ ItemStack mapStack = context .getHeldItemToOperateOn (itemstack -> itemstack .isOf (HexGloopItems .SLATE_CANVAS_ITEM .get ())).component1 ();
52
+
53
+ HexGloop .logPrint ("args: " + stack .toString ());
54
+
55
+ int brushsize = 1 ;
56
+ try {
57
+ brushsize = OperatorUtils .getIntBetween (List .of (stack .get (stack .size ()-1 )), 0 , 1 , 128 , 1 );
58
+ stack .remove (stack .size ()-1 );
59
+ } catch (Throwable mishap ) {
60
+ // do nothing
61
+ HexGloop .logPrint ("mishap: " + mishap );
62
+ }
63
+
64
+ List <Iota > args = CollectionsKt .takeLast (stack , 3 );
65
+
66
+ Integer x = null ;
67
+ if (!(args .get (0 ) instanceof NullIota )){
68
+ x = OperatorUtils .getIntBetween (args , 0 , 0 , 127 , 3 );
69
+ }
70
+ Integer y = null ;
71
+ if (!(args .get (1 ) instanceof NullIota )){
72
+ y = OperatorUtils .getIntBetween (args , 1 , 0 , 127 , 3 );
73
+ }
74
+ byte closestColor = MapColor .CLEAR .getRenderColorByte (Brightness .NORMAL );
75
+ if (!(args .get (2 ) instanceof NullIota )){
76
+ Vec3d colorVec = OperatorUtils .getVec3 (args , 2 , 3 );
77
+ closestColor = SlateCanvasUtils .getClosestMapColor (new Vec3i (colorVec .x , colorVec .y , colorVec .z ), context .getCaster ());
78
+ }
79
+
80
+ for (int i = 0 ; i < 3 ; i ++){
81
+ stack .remove (stack .size ()-1 );
82
+ }
83
+
84
+ Integer mapId = FilledMapItem .getMapId (mapStack );
85
+ if (mapId == null ){
86
+ HexGloop .logPrint ("creating a new map" );
87
+ Pair <MapState , Integer > newMapData = ItemSlateCanvas .createMapState (context .getWorld ());
88
+ mapId = newMapData .getRight ();
89
+ ItemSlateCanvas .setCanvasMapId (mapStack , mapId );
90
+ }
91
+ HexGloop .logPrint ("map id: " + mapId );
92
+ MapState mapState = FilledMapItem .getMapState (mapId , context .getWorld ());
93
+ if (x == null && y == null ){ // paint whole thing
94
+ for (int i = 0 ; i < 128 ; i ++){
95
+ for (int j = 0 ; j < 128 ; j ++){
96
+ mapState .setColor (i , j , closestColor );
97
+ }
98
+ }
99
+ } else {
100
+ int startX = 0 , startY = 0 ;
101
+ int endX = 128 , endY = 128 ;
102
+
103
+ if (x != null ){
104
+ startX = (int )(x - Math .floor ((brushsize -1 )/2.0 ));
105
+ endX = (int )(x + Math .ceil ((brushsize +1 )/2.0 ));
106
+ }
107
+
108
+ if (y != null ){
109
+ startY = (int )(y - Math .floor ((brushsize -1 )/2.0 ));
110
+ endY = (int )(y + Math .ceil ((brushsize +1 )/2.0 ));
111
+ }
112
+
113
+ // clamp all the values down to actual sizes
114
+ startX = Math .min (Math .max (0 , startX ), 128 );
115
+ startY = Math .min (Math .max (0 , startY ), 128 );
116
+ endX = Math .min (Math .max (0 , endX ), 128 );
117
+ endY = Math .min (Math .max (0 , endY ), 128 );
118
+
119
+ for (int i = startX ; i < endX ; i ++){
120
+ for (int j = startY ; j < endY ; j ++){
121
+ mapState .setColor (i , j , closestColor );
122
+ }
123
+ }
124
+ }
125
+ return new OperationResult (continuation , stack , ravenmind , new ArrayList <OperatorSideEffect >());
126
+ }
127
+
128
+ }
0 commit comments