forked from Firigion/scarpets
-
Notifications
You must be signed in to change notification settings - Fork 0
/
curves.sc
1382 lines (1149 loc) · 45.6 KB
/
curves.sc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
__command() -> null;
// to store marker positions and object handles
global_settings = {
'show_pos' -> true ,
'paste_with_air' -> false ,
'circle_axis' -> 'y' ,
'wave_axis' -> 'xy' ,
'replace_block' -> false ,
'rotate' -> false , //TODO
'slope_mode' -> false ,
'max_template_size' -> 100 ,
'preview_enabled' -> false , //TODO
'undo_history_size' -> 100 ,
'max_operations_per_tick' -> 10000 ,
};
global_block_alias = {
'water_bucket' -> 'water' ,
'lava_bucket' -> 'lava' ,
'feather' -> 'air' ,
'ender_eye' -> 'end_portal' ,
'flint_and_steel' -> 'nether_portal',
};
global_history = {
'overworld' -> [] ,
'the_nether' -> [] ,
'the_end' -> [] ,
};
// keeps track of how many blocks have been set this tick
global_set_count = 0;
////// Utilities ///////
__get_replace_block() -> (
block = query(player(), 'holds', 'offhand'):0;
alias = global_block_alias:block;
if(alias==null, block, alias)
);
__set_and_save(pos, material) -> ( //defaults to no replace
global_this_story:length(global_this_story) = [pos, block(pos)];
set(pos , material);
);
__set_block(pos, material, replace_block) -> (
__set_and_save(pos, material);
if(global_set_count > global_settings:'max_operations_per_tick',
global_set_count = 0;
game_tick(20);
);
);
__get_center() -> (
dim = player() ~ 'dimension';
if(global_positions:dim:2 == null,
pos(player()),
global_positions:dim:2
)
);
__extend(list, extension) -> (
len = length(list);
for(extension, list:(len+_i) = _);
return(list)
);
__reflect(list) -> map(range(length(list)-1, -1, -1), list:_ );
// saves selected area, minus air
__make_template() -> (
dim = player() ~ 'dimension';
if(!global_all_set:dim,
print(format('rb Error: ', 'y You need to make a selection first' ));
return(true) // dont paste anything
);
pos0 = global_positions:dim:0;
pos1 = global_positions:dim:1;
global_template = l();
origin = map(range(3), min(pos0:_, pos1:_)); //negative-most corner in all dimensions
volume(
pos0:0, pos0:1, pos0:2,
pos1:0, pos1:1, pos1:2,
if(global_settings:'paste_with_air',
global_template:length(global_template) = [pos(_)-origin, _],
if(!air(_), global_template:length(global_template) = [pos(_)-origin, _] ) //save non-air blocks and positions
);
);
// Handle template size warning
if(length(global_template) > global_settings:'max_template_size',
print( format(
'buy Warning',
'y : ',
'w Template is too big. Your tried to paste ',
str('by %d ', length(global_template)),
str('w blocks %s, but max size is ', if(global_settings:'paste_with_air', '(counting air)', '(not counting air)') ),
str('by %d', global_settings:'max_template_size' ),
'w .\nTry increasing it with ',
'b [this] ', '^t Click here!', '?/curves set_max_template_size 200',
'w command.'
) );
true, // tempalte too big, don't paste it
false // paste it
)
);
// clone template at given position
__clone_template(pos, replace_block) -> (
for(global_template, __set_block(pos + _:0, _:1, replace_block) );
);
__make_set_function(dim, material, replace_block) -> (
if( material == 'template',
// make with tempalte
if(__make_template(), return() ); // retrn if tempalte was too big
offset = map(global_positions:dim:0 - global_positions:dim:1, abs(_)) / 2; //offsets the selection so that it clones it in the center of the block
__set_function(position, outer(replace_block), outer(offset)) -> __clone_template( position - offset, replace_block);
,
// else, make from block material
__set_function(position, outer(material), outer(replace_block)) -> __set_block( position, material, replace_block);
);
);
////// Helixes ///////
// ---- Utils ----
// mainly for debug porpuses
_circle(radius, material) -> (
circ = __make_circle(radius);
c = pos(player());
for(circ,
set(c + l(_:0, 0, _:1), material);
create_marker(str(_i), c + l(_:0, 0, _:1))
);
);
__rotated90(list_to_rotate) -> ( //rotates 90 degrees
map(list_to_rotate, l(_:1, -_:0))
);
__helix_get_step(circle, perimeter, advance_step, i) ->( //defaults to axis y
circle_pos = circle:(i%perimeter);
step = l(circle_pos:0, i * advance_step, circle_pos:1) ;
);
__make_circle(radius) -> (
z_function(x, outer(radius)) -> round(sqrt(radius * radius - x*x));
range_val = radius * cos(45); //this spans a quarter circle
x_range = range(-range_val, range_val);
quarter1 = map(x_range, l(_, z_function(_)) ); // starts with quarter circle
half = __extend(quarter1, __rotated90(quarter1)); // add a quarter by rotating it 90 degrees
__extend(half,__rotated90(__rotated90(half))); // rotate the half circle 180 degrees and add it
);
__assert_pitch(pitch) -> (
if(pitch == 0,
print(format('rb Error: ', str('y %s must not be zero', if(global_settings:'slope_mode', 'Slope', 'Pitch')) ) );
true,
false
);
);
// ---- Draw funtions ----
__preview_helix(circle, center, pitch, size, iterations_left) -> (
perimeter = length(circle); // ammount of blocks in one revolution
advance_step = if(global_settings:'slope_mode', pitch, pitch/perimeter); //pitch encodes slope if slope_mode == true
loop(floor( size / advance_step) - 1 , //loop over the total ammount of helixes
this_step = __helix_get_step(circle, perimeter, advance_step, _);
next_step = __helix_get_step(circle, perimeter, advance_step, _+1);
draw_shape('line', 15, 'from', center + this_step, 'to', center + next_step);
);
if(iterations_left > 0,
schedule(10, '__preview_helix', circle, center, pitch, size, iterations_left-1)
);
);
preview_helix(radius, pitch, size, time) -> (
if(__assert_pitch(pitch), return('') );
center = __get_center(); // center coordiantes
circle = __make_circle(radius);
iterations = time * 2; // time is a value in seconds, will render every 10 gt
__preview_helix(circle, center, pitch, size, iterations);
);
//main funtion to draw helix from material
__draw_helix(circle, center, pitch, size, material) -> (
dim = player() ~ 'dimension';
if(__assert_pitch(pitch), return('') );
perimeter = length(circle); // ammount of blocks in one revolution
replace_block = __get_replace_block();
advance_step = if(global_settings:'slope_mode', pitch, pitch/perimeter); //pitch encodes slope if slope_mode == true
global_this_story = [];
__make_set_function(dim, material, replace_block);
//else, make out of material
loop(floor( size / advance_step), //loop over the total ammount of helixes
this_step = __helix_get_step(circle, perimeter, advance_step, _);
__set_function(center + this_step);
);
__put_into_history(global_this_story, dim); //ensure max history size is not exceeded
print(str('Set %d blocks', length(global_this_story) ));
);
helix(radius, pitch, size, material) -> (
center = __get_center(); // center coordiantes
circle = __make_circle(radius);
__draw_helix(circle, center, pitch, size, material);
);
antihelix(radius, pitch, size, material) -> (
center = __get_center(); // center coordiantes
circle = __make_circle(radius);
circle = __reflect(circle); // to spin the other way around
__draw_helix(circle, center, pitch, size, material);
);
multihelix(radius, pitch, size, ammount, material) -> (
center = __get_center(); // center coordiantes
circle = __make_circle(radius);
perimeter = length(circle); // ammount of blocks in one revolution
loop(ammount,
jump = floor(_ * perimeter/ammount); // by how many places to advance to get to the next circle
this_circ = __extend(slice(circle, jump), slice(circle, 0, jump) ); // redefine the circle last for this iteration
__draw_helix(this_circ, center, pitch, size, material);
);
);
antimultihelix(radius, pitch, size, ammount, material) -> (
center = __get_center(); // center coordiantes
circle = __make_circle(radius);
circle = __reflect(circle); // to spin the other way around
perimeter = length(circle); // ammount of blocks in one revolution
loop(ammount,
jump = floor(_ * perimeter/ammount); // by how many places to advance to get to the next circle
this_circ = __extend(slice(circle, jump), slice(circle, 0, jump) ); // redefine the circle last for this iteration
__draw_helix(this_circ, center, pitch, size, material);
);
);
////// Spirals ///////
// ---- Utils ----
__arclength_poly(exponent, turns, radius) -> (
radius * (360 * turns) ^ (exponent +1) / (exponent + 1 );
);
__arclength_exp(base, turns, radius) -> (
radius * sqrt(1+ln(base)^2)/ln(base) * base^(360*turns - 1)
);
// ---- Draw funtions ----
__draw_spiral(arclength, material) -> (
dim = player() ~ 'dimension';
center = __get_center();
replace_block = __get_replace_block();
global_this_story = [];
position_list = [];
// define function to set with
__make_set_function(dim, material, replace_block);
parameter = l( range(arclength) ) / arclength;
for( parameter,
position = map(center + __circular_parametric_curve_get_step( u(_) , v(_) , 0), floor(_) );
// check for repeated spots
if( position_list ~ position,
continue(),
position_list:length(position_list) = position
);
__set_function(position);
);
__put_into_history(global_this_story, dim); //ensure max history size is not exceeded
print(str('Set %d blocks', length(global_this_story) ));
return('');
);
spiral(turns, exponent, radius, phase, material) -> (
u(t, outer(exponent), outer(radius), outer(phase)) -> radius * t^exponent * cos(t + phase);
v(t, outer(exponent), outer(radius), outer(phase)) -> radius * t^exponent * sin(t + phase);
//__draw_spiral( __arclength_poly(exponent, turns, radius), material)
__arclength_poly(exponent, turns, radius)
);
logspiral(turns, base, radius, phase, material) -> (
u(t, outer(base), outer(radius), outer(phase)) -> radius * base^t * cos(t + phase);
v(t, outer(base), outer(radius), outer(phase)) -> radius * base^t * sin(t + phase);
);
antispiral(turns, exponent, radius, phase, material) -> (
u(t, outer(exponent), outer(radius), outer(phase)) -> radius * t^exponent * cos(-t + phase);
v(t, outer(exponent), outer(radius), outer(phase)) -> radius * t^exponent * sin(-t + phase);
);
antilogspiral(turns, base, radius, phase, material) -> (
u(t, outer(base), outer(radius), outer(phase)) -> radius * base^t * cos(-t + phase);
v(t, outer(base), outer(radius), outer(phase)) -> radius * base^t * sin(-t + phase);
);
////// Waves ///////
// ---- Utils ----
__wave_get_step(wave, len, current_offset, i) -> (
wave_pos = wave:(i%len);
this_step = l(wave_pos:0 + current_offset , wave_pos:1, 0) ;
);
__make_curve(L, A) -> (
// make first quarter
start_pos = pos( block(pos(player())) ); // to get integer coords
x = range(L/4 + 1);
curve = map(x, l(_, floor(A * sin(360 *_ / L)) ));
curve = __fill_in(curve);
//add second quarter
quarter_size = curve:(length(curve)-1):0;
reflected_quarter = map(curve, l(quarter_size * 2 + 1- _:0, _:1) );
reflected_quarter = __reflect(reflected_quarter);
curve = __extend(curve, reflected_quarter);
//add last half
half_size = curve:(length(curve)-1):0;
reflected_half = map(curve, l(half_size * 2 - _:0, - _:1) );
reflected_half = __reflect(reflected_half);
delete(reflected_half, 0); // to avoid overlap where they meet
delete(reflected_half, length(reflected_half)-1); // to avoid overlap with the next bit
curve = __extend(curve, reflected_half);
);
__fill_in(in_list) -> (
out_list = l();
len = length(in_list);
loop( len ,
out_list:length(out_list) = in_list:_;
if(_ < len, // dont run the last one
d = in_list:(_+1):1 - in_list:_:1;
i = _;
loop( d -1 ,
out_list:length(out_list) = in_list:i + l(0,_+1);
);
);
);
out_list;
);
// ---- Draw funtions ----
wave(wavelength, amplitude, size, material) -> (
dim = player() ~ 'dimension';
start = __get_center();
wave = __make_curve(wavelength, amplitude);
lenx = wave:(length(wave) - 1):0; //how long the wave is in one dimension
len = length(wave);
fractional_fit = size/lenx; //ammount of times the curve fits in target size
replace_block = __get_replace_block();
global_this_story = [];
__make_set_function(dim, material, replace_block);
loop( floor( fractional_fit * len ),
current_period = floor(_ / len);
this_step = __wave_get_step(wave, len, current_period * lenx, _);
__set_function(start + this_step);
);
__put_into_history(global_this_story, dim); //ensure max history size is not exceeded
print(str('Set %d blocks', length(global_this_story) ));
return('');
);
////// Circle wave ///////
// ---- Utils ----
__circular_parametric_curve_get_step(u, v, w) -> [u, w, v]; // defaults to y axis
__get_arclength_planar(R, A, k, arc) -> (
// Arclength should be int(sqrt( (A * k * cos(k*t))^2 + (A * sin(k*t) + d)^2 ))
// Doing this approximation means heavily oversampling the curve
arclength = sqrt(A*A * k*k + A*A + R*R + 2*A*R) * arc;
);
__get_arclength_tarsverse(R, A, k, arc) -> (
// Arclength should be int(sqrt( R^2 + (A * k * cos(k*t))^2 ))
// Doing this approximation means heavily oversampling the curve
arclength = sqrt(R*R + A*A * k*k) * arc;
);
__get_param(arclength, arc) -> (
parameter = arc * l( range(arclength) ) / arclength;
);
__create_planar_functions(R, A, k, from) -> (
u(t, outer(A), outer(R), outer(k), outer(from) ) -> (R + A * sin(t * k) ) * cos(t + from);
v(t, outer(A), outer(R), outer(k), outer(from) ) -> (R + A * sin(t * k) ) * sin(t + from);
w(t) -> 0;
);
__create_transverse_functions(R, A, k, from) -> (
u(t, outer(R), outer(from) ) -> R * cos(t + from);
v(t, outer(R), outer(from) ) -> R * sin(t + from);
w(t, outer(A), outer(k) ) -> A * sin( k * t );
);
// ---- Draw functions ----
__draw_circle_wave(parameter, material) -> (
dim = player() ~ 'dimension';
center = __get_center();
replace_block = __get_replace_block();
global_this_story = [];
position_list = [];
// define function to set with
__make_set_function(dim, material, replace_block);
for( parameter,
position = map(center + __circular_parametric_curve_get_step( u(_) , v(_) , w(_)), floor(_) );
// check for repeated spots
if( position_list ~ position,
continue(),
position_list:length(position_list) = position
);
__set_function(position);
);
__put_into_history(global_this_story, dim); //ensure max history size is not exceeded
print(str('Set %d blocks', length(global_this_story) ));
return('');
);
cwave_planar(radius, amplitude, cycles, material) -> (
cwave_planar_partial(radius, amplitude, cycles, 0, 360, material);
);
cwave_planar_partial(radius, amplitude, cycles, from, to, material) -> (
arc = abs(to-from);
arclength = __get_arclength_planar(radius, amplitude, cycles, arc);
parameter = __get_param(arclength, arc);
__create_planar_functions(radius, amplitude, cycles, from);
__draw_circle_wave(parameter, material);
);
cwave_transverse(radius, amplitude, cycles, material) -> (
cwave_transverse_partial(radius, amplitude, cycles, 0, 360, material);
);
cwave_transverse_partial(radius, amplitude, cycles, from, to, material) -> (
arc = abs(to-from);
arclength = __get_arclength_tarsverse(radius, amplitude, cycles, arc);
parameter = __get_param(arclength, arc);
__create_transverse_functions(radius, amplitude, cycles, from);
__draw_circle_wave(parameter, material);
);
////// Stars ///////
// ---- Utils ----
__draw_line(p1, p2) -> (
m = p2-p1;
max_size = max(map(m, abs(_)));
t = l(range(max_size+1))/max_size;
for(t,
b = m * _ + p1;
__set_function(b);
);
);
// gets n equidistant points (pairs of coors) along a circle of radius R
__get_points(R, n, phase) -> (
angle_step = 360/n;
get_step(i, outer(R), outer(angle_step), outer(phase)) -> R * [ cos(i*angle_step + phase), sin(i*angle_step + phase)];
map(range(n), get_step(_) );
);
__interlace_lists(l1, l2) -> (
// asumes l1 and l2 of same length
out = [];
for(l1,
out:length(out) = _;
out:length(out) = l2:_i;
);
return(out);
);
// ---- Draw functions ----
star(outer_radius, inner_radius, n_points, phase, material) -> (
dim = player() ~ 'dimension';
center = __get_center();
replace_block = __get_replace_block();
global_this_story = [];
position_list = [];
// define function to set with
__make_set_function(dim, material, replace_block);
// get points in inner and pouter radius + interlace them
inner_points = __get_points(inner_radius, n_points, phase);
outer_points = __get_points(outer_radius, n_points, phase + 360/n_points/2);
interlaced_list = __interlace_lists(inner_points, outer_points);
interlaced_list:length(interlaced_list) = inner_points:0; // add first point at the end to close curve
// get points and draw the connecting lines
loop(length(interlaced_list)-1,
p1 = center + __circular_parametric_curve_get_step(interlaced_list:_:0, interlaced_list:_:1, 0) ;
p2 = center + __circular_parametric_curve_get_step(interlaced_list:(_+1):0, interlaced_list:(_+1):1, 0) ;
__draw_line(p1, p2);
);
__put_into_history(global_this_story, dim); //ensure max history size is not exceeded
print(str('Set %d blocks', length(global_this_story) ));
return('');
);
////// Polygon ///////
// builds on star utils
polygon(radius, n_points, rotation, material) -> (
dim = player() ~ 'dimension';
center = __get_center();
replace_block = __get_replace_block();
global_this_story = [];
position_list = [];
// define function to set with
__make_set_function(dim, material, replace_block);
// get points in inner and pouter radius + interlace them
points = __get_points(radius, n_points, rotation);
points:length(points) = points:0; // add first point at the end to close curve
// get points and draw the connecting lines
loop(length(points)-1,
p1 = center + __circular_parametric_curve_get_step(points:_:0, points:_:1, 0) ;
p2 = center + __circular_parametric_curve_get_step(points:(_+1):0, points:(_+1):1, 0) ;
__draw_line(p1, p2);
);
__put_into_history(global_this_story, dim); //ensure max history size is not exceeded
print(str('Set %d blocks', length(global_this_story) ));
return('');
);
////// Soft replace ///////
__get_states(b) -> (
properties = block_properties(pos(b));
pairs = map(properties, l(_, property(pos(b), _)) );
);
__make_properies_string(pairs) -> (
if( pairs,
props_str = join(',', map(pairs, str('%s="%s"', _:0, _:1)) ),
props_str = '',
);
);
__set_with_state(b, replace) -> (
pairs = __get_states(b);
properties_string = __make_properies_string(pairs);
__set_and_save(b, block(str('%s[%s]', replace, properties_string)) );
);
__replace_one_block(b, to_replace, replace_with) -> (
if(b == to_replace,
__set_with_state(b, replace_with)
);
);
__replace_one_block_filt(b, to_replace, replace_with, property, value) -> (
if(b == to_replace && property(b, property)==value,
__set_with_state(b, replace_with)
);
);
soft_replace() -> (
to_replace = __get_replace_block();
replace_with = query(player(), 'holds', 'mainhand'):0;
dim = player() ~ 'dimension';
if(!global_all_set:dim,
print(format('rb Error: ', 'y You need to make a selection first' ));
return('') // dont paste anything
);
global_this_story = [];
pos0 = global_positions:dim:0;
pos1 = global_positions:dim:1;
volume(
pos0:0, pos0:1, pos0:2,
pos1:0, pos1:1, pos1:2,
(
__replace_one_block(_, to_replace, replace_with)
);
);
print(global_this_story);
__put_into_history(global_this_story, dim); //ensure max history size is not exceeded
print(str('Replaced %d %s blocks with %s', length(global_this_story), to_replace, replace_with ));
);
soft_replace_filt(property, value) -> (
to_replace = __get_replace_block();
replace_with = query(player(), 'holds', 'mainhand'):0;
dim = player() ~ 'dimension';
if(!global_all_set:dim,
print(format('rb Error: ', 'y You need to make a selection first' ));
return('') // dont paste anything
);
global_this_story = l();
print(str('Replacing %s with %s', to_replace, replace_with));
volume(global_positions:0:0, global_positions:0:1, global_positions:0:2,
global_positions:1:0, global_positions:1:1, global_positions:1:2,
(
__replace_one_block_filt(_, to_replace, replace_with, property, value)
);
);
__put_into_history(global_this_story, dim); //ensure max history size is not exceeded
print(str('Replaced %d blocks', length(global_this_story) ));
);
////// Brush ///////
__paste_brush() -> (
dim = player() ~ 'dimension';
looking_at = query(player(), 'trace', 200, 'blocks');
if(looking_at == null, return(''), block_pos = pos(looking_at) );
replace_block = __get_replace_block();
if(__make_template(), return() ); //tempalte was too big
offset = map(global_positions:dim:0 - global_positions:dim:1, abs(_)) / 2; //offsets the selection so that it clones it in the center of the block
global_this_story = l();
__clone_template( block_pos - offset, replace_block);
);
////// Settings'n stuff ///////
set_max_template_size(value) -> (
if( type(value) == 'number' && value > 0,
global_settings:'max_template_size' = value;
print(format(str('b Max tempalte size value set to %s', value) ) ),
print(format('rb Error: ', 'y Max template size should be a positive number') )
);
return('')
);
set_max_operations_per_tick(value) -> (
if( type(value) == 'number' && value > 0,
global_settings:'max_template_size' = value;
print(format(str('b max operations per tick set to %s', value) ) ),
print(format('rb Error: ', 'y Max operations per tick should be a positive number') )
);
return('')
);
set_circle_axis(axis) -> (
if( ( l('x','y','z')~axis ) == null,
print(format('rb Error: ', 'y Axis must be one of ', 'yb x, y ', 'y or ', 'yb z'));
return('')
);
global_settings:'circle_axis' = axis;
if( axis == 'x',
__helix_get_step(circle, perimeter, advance_step, i) ->(
circle_pos = circle:(i%perimeter);
step = l(i * advance_step, circle_pos:0, circle_pos:1) ;
);
__circular_parametric_curve_get_step( u , v , w) -> l(w, u, v);
,
axis == 'y',
__helix_get_step(circle, perimeter, advance_step, i) ->( //defaults to axis y
circle_pos = circle:(i%perimeter);
step = l(circle_pos:0, i * advance_step, circle_pos:1)
);
__circular_parametric_curve_get_step( u , v , w) -> l(u, w, v);
,
axis == 'z',
__helix_get_step(circle, perimeter, advance_step, i) ->(
circle_pos = circle:(i%perimeter);
step = l(circle_pos:0, circle_pos:1, i * advance_step) ;
);
__circular_parametric_curve_get_step( u , v , w) -> l(u, v, w);
);
print(format(str('b Circular curves will now generate perpendicular to the %s axis', axis) ) );
return('')
);
set_wave_axis(axis) -> (
if( ( l('xy', 'xz', 'yx' ,'yz','zx', 'zy')~axis ) == null,
print(format('rb Error: ', 'y Axis must be one of ', 'yb xy, xz, yx, yz, zx ', 'y or ', 'yb zy'));
return('')
);
global_settings:'wave_axis' = axis;
if( axis == 'xy',
__wave_get_step(wave, len, current_offset, i) -> (
wave_pos = wave:(i%len);
this_step = l(wave_pos:0 + current_offset , wave_pos:1, 0) ;
),
axis == 'xz',
__wave_get_step(wave, len, current_offset, i) -> (
wave_pos = wave:(i%len);
this_step = l( wave_pos:0 + current_offset , 0, wave_pos:1) ;
),
axis == 'yx',
__wave_get_step(wave, len, current_offset, i) -> (
wave_pos = wave:(i%len);
this_step = l( wave_pos:1, wave_pos:0 + current_offset , 0) ;
),
axis == 'yz',
__wave_get_step(wave, len, current_offset, i) -> (
wave_pos = wave:(i%len);
this_step = l( 0, wave_pos:0 + current_offset , wave_pos:1) ;
),
axis == 'zx',
__wave_get_step(wave, len, current_offset, i) -> (
wave_pos = wave:(i%len);
this_step = l( wave_pos:1, 0, wave_pos:0 + current_offset ) ;
),
axis == 'zy',
__wave_get_step(wave, len, current_offset, i) -> (
wave_pos = wave:(i%len);
this_step = l( 0, wave_pos:1, wave_pos:0 + current_offset) ;
),
);
print(format(str('b Waves will now generate along the %s axis and into the %s axis', slice(axis, 0, 1), slice(axis, 1)) ) );
return('')
);
set_undo_histoy_size(value) -> (
if( type(value) == 'number' && value > 0,
global_settings:'undo_history_size' = value;
print(format(str('b Max undo value set to %s', value) ) ),
print(format('rb Error: ', 'y Undo history size should be a positive number') )
);
index = length(global_history) - global_settings:'undo_history_size';
if( index>0 , global_history = slice(global_history, index) );
return('')
);
toggle_paste_with_air() -> (
global_settings:'paste_with_air' = !global_settings:'paste_with_air';
if(global_settings:'paste_with_air',
print('Template will now be pasted with air'),
print('Template will now be pasted without air')
);
return('')
);
toggle_replace_block() -> (
global_settings:'replace_block' = !global_settings:'replace_block';
if(global_settings:'replace_block',
//if replace blocks
print( format('b Curves will now only replce block in your offhand.\n',
'g Hold bucket for liquids, feather for air, ender eye for end portal, and flint and steel for nether portal.') );
__set_block(pos, material, replace_block) -> if(block(pos) == replace_block, __set_and_save(pos, material) ),
//else
print(format( 'b Curve will paste completly, replacing whatever is there.') );
__set_block(pos, material, replace_block) -> __set_and_save(pos, material)
);
return('')
);
toggle_slope_mode() -> (
global_settings:'slope_mode' = !global_settings:'slope_mode';
if(global_settings:'slope_mode',
print(format('b Second argument of helix commands is now slope (in blocks)') ),
print(format('b Second argument of helix commands is now pitch (separation between revolutions)') )
);
return('')
);
// generate interactive string for togglable parameter
__make_toggle_setting(parameter, hover) -> (
str_list = l(
str('w * %s: ', parameter),
str('^y %s', hover),
);
str_list = __extend(str_list, __get_button('true', parameter) );
str_list = __extend(str_list, __get_button('false', parameter) );
print(player(), format(str_list))
);
__get_active_button(value) -> (
l( str('yb [%s] ', value) )
);
__get_inactive_button(value, parameter) -> (
l(
str('g [%s] ', value),
str('^gb Click to toggle'),
str('!/curves toggle_%s', parameter)
)
);
__get_button(value, parameter) -> (
bool_val = if(bool(value), global_settings:parameter, !global_settings:parameter);
if( bool_val, __get_active_button(value), __get_inactive_button(value, parameter) )
);
// generate interactive string for parameter with options
__make_value_setting(parameter, hover, options, has_arbitrary_values) -> (
str_list = l(
str('w * %s: ', parameter),
str('^y %s', hover),
);
options_list = [];
map( options,
len = length(options_list);
options_list:len = str('%sb [%s]', if(global_settings:parameter == _, 'y', 'g',), _);
options_list:(len+1) = '^bg Click to set this value';
options_list:(len+2) = str('?/curves set_%s %s', parameter, _)
);
str_list = __extend(str_list, options_list);
if( has_arbitrary_values,
current_val = ['w \ | ', str('e %s', global_settings:parameter), '^e Current value'];
str_list = __extend(str_list, current_val)
);
print(player(), format( str_list ))
);
// print all settings
settings() -> (
print(player(), '======================');
print(player(), format( 'b General settings:' ));
__make_toggle_setting('show_pos', 'Shows markers and outlines selection');
__make_toggle_setting('paste_with_air', 'Includes air when pasting template');
__make_toggle_setting('replace_block', 'Shapes will only be generated replacing block in offhand');
__make_value_setting('max_template_size', 'Limits template size to avoid freezing the game if you mess up the selection', [20, 100, 1200] , true);
__make_value_setting('undo_history_size', 'Sets the maximum ammount of actions to undo', [10, 100, 500] , true);
__make_value_setting('max_operations_per_tick', 'Sets the maximum ammount of operations per gametick', [2000, 10000, 50000] , true);
print(player(), format( 'b Shapes settings:' ));
__make_toggle_setting('slope_mode', 'Defines behaviour of second argument in helix definitions: slope or pitch');
__make_value_setting('circle_axis', 'Axis along which circular stuff is generated. Affects stars, helixes and cwaves', ['x', 'y', 'z'] , false);
__make_value_setting('wave_axis', 'Axis along which and into which waves are generated', ['xy', 'xz', 'yx' ,'yz','zx', 'zy'] , false);
print(player(), '');
return('')
);
////// Undo stuff ///////
__put_into_history(story, dim) -> (
global_set_count = 0; // reset global count
global_history:dim:length(global_history:dim) = story;
if(length(global_history:dim) > global_settings:'undo_history_size',
delete(global_history:dim, 0)
);
);
__undo(index, dim) -> (
// iterate over the story backwards
for(range(length(global_history:dim:index)-1, -1, -1),
set(global_history:dim:index:_:0, global_history:dim:index:_:1); // (position, block) pairs
);
// remove used story
delete(global_history:dim, index);
);
go_back_stories(num) -> (
//check for valid input
if( type(num) != 'number' || num <= 0,
print(format('rb Error: ', 'y Need a positive number of steps to go to'));
return('')
);
dim = player() ~ 'dimension';
index = length(global_history:dim)-num;
if(index<0,
print(format('rb Error: ', str('y You only have %d actions available to undo', length(global_history:dim) ) ));
return('')
);
__undo(index, dim);
print(str('Undid what you did %s actions ago', num ));
);
undo(num) -> (
//check for valid input
if( type(num) != 'number' || num <= 0,
print(format('rb Error: ', 'y Need a positive number of steps to undo'));
return('')
);
dim = player() ~ 'dimension';
index = length(global_history:dim)-num;
if(index<0,
print(format('rb Error: ', str('y You only have %d actions to undo available', length(global_history:dim) ) ));
return('')
);
loop(num, __undo(length(global_history:dim)-1, dim) );
print(str('Undid the last %d actions', num) );
);
////// Handle Markers //////
// Spawn a marker
__mark(i, position, dim) -> (
colours = l('red', 'lime', 'light_blue');
e = create_marker('pos' + i, position + l(0.5, 0.5, 0.5), colours:(i-1) + '_concrete', false); // crete the marker
run(str( //modify some stuff to make it fancier
'data merge entity %s {Glowing:1b, Fire:32767s}', query(e, 'uuid')
));
global_armor_stands:dim:(i-1) = query(e, 'id'); //save the id for future use
);
__remove_mark(i, dim) -> (
e = entity_id(global_armor_stands:dim:(i));
if(e != null, modify(e, 'remove'));
);
// set a position
set_pos(i) -> (
dim = player() ~ 'dimension';
try( // position index must be 1, 2 or 3
if( !reduce(range(1,4), _a + (_==i), 0),
throw();
),
print(format('rb Error: ', 'y Input must be either 1, 2 or 3 for position to set. You input ' + i) );
return()
);
// position to be set at the block the player is aiming at, or player position, if there is none
tha_block = query(player(), 'trace');
if(tha_block!=null,
tha_pos = pos(tha_block),
tha_pos = map(pos(player()), round(_))
);