Replacing draw and distance with apps (#553)
* added draw.sc app Now working on distance app * Adding apps as carpet rules * adding distance app Co-authored-by: altrisi <altrisi.trillosierra@gmail.com>
This commit is contained in:
1 parent
7d727d9717
commit
aeb3e382a6
5 files changed
+257
-1
No files matched your search
@@ -73,6 +73,7 @@ public class CarpetSettings
|
||||
|
||||
/*
|
||||
These will be turned when events can be added / removed in code
|
||||
Then also gotta remember to remove relevant rules
|
||||
|
||||
@Rule(
|
||||
desc = "Turns on internal camera path tracing app",
|
||||
@@ -97,9 +98,29 @@ public class CarpetSettings
|
||||
appSource = "ai_tracker"
|
||||
)
|
||||
public static boolean commandAITracker = true;
|
||||
|
||||
@Rule(
|
||||
desc = "Enables /draw commands",
|
||||
extra = {
|
||||
"... allows for drawing simple shapes or",
|
||||
"other shapes which are sorta difficult to do normally"
|
||||
},
|
||||
appSource = "draw",
|
||||
category = {FEATURE, SCARPET, COMMAND}
|
||||
)
|
||||
public static String commandDraw = "true";
|
||||
|
||||
@Rule(
|
||||
desc = "Enables /distance command to measure in game distance between points",
|
||||
extra = "Also enables brown carpet placement action if 'carpets' rule is turned on as well",
|
||||
appSource = "distance",
|
||||
category = {FEATURE, SCARPET, COMMAND}
|
||||
)
|
||||
public static String commandDistance = "true";
|
||||
*/
|
||||
|
||||
|
||||
|
||||
@Rule(desc = "Gbhs sgnf sadsgras fhskdpri!", category = EXPERIMENTAL)
|
||||
public static boolean superSecretSetting = false;
|
||||
|
||||
@@ -374,6 +395,7 @@ public class CarpetSettings
|
||||
@Rule(desc = "Enables /draw commands", extra = {"... allows for drawing simple shapes or","other shapes which are sorta difficult to do normally"}, category = COMMAND)
|
||||
public static String commandDraw = "true";
|
||||
|
||||
|
||||
@Rule(
|
||||
desc = "Enables /script command",
|
||||
extra = "An in-game scripting API for Scarpet programming language",
|
||||
|
||||
@@ -84,6 +84,8 @@ public class CarpetScriptServer
|
||||
registerBuiltInScript(BundledModule.carpetNative("math", true));
|
||||
registerBuiltInScript(BundledModule.carpetNative("chunk_display", false));
|
||||
registerBuiltInScript(BundledModule.carpetNative("ai_tracker", false));
|
||||
registerSettingsApp(BundledModule.carpetNative("draw_rc_1", false));
|
||||
registerSettingsApp(BundledModule.carpetNative("distance_rc_1", false));
|
||||
}
|
||||
|
||||
public CarpetScriptServer(MinecraftServer server)
|
||||
|
||||
@@ -0,0 +1,88 @@
|
||||
import('math','_euclidean','_manhattan','_round');
|
||||
|
||||
__config()->{
|
||||
'commands'->{
|
||||
'from <start_pos>'->'set_start',
|
||||
'from <start_pos> to <end_pos>'->'_calculate',
|
||||
'to <end_pos>'->_(end_pos)->(_calculate(null,end_pos)),
|
||||
'toggle_line'->'_toggle_line'
|
||||
},
|
||||
'scope'->'player'
|
||||
};
|
||||
|
||||
global_position=null;
|
||||
global_end_position=null;
|
||||
|
||||
global_show_line=false;
|
||||
|
||||
global_line = {
|
||||
'start_pos'->global_position,
|
||||
'end_pos'->global_end_position
|
||||
};
|
||||
|
||||
set_start(pos)->(
|
||||
global_position= pos;
|
||||
print(player(),format('gi Initial point set to: ', 'g '+pos,'?/tp '+(str(pos)-','-'['-']')))
|
||||
);
|
||||
|
||||
_toggle_line()->(
|
||||
global_show_line= !global_show_line;
|
||||
if(global_show_line,
|
||||
print('Toggled lines on');
|
||||
if(global_end_position,_draw_line()),//making sure that there is a start an end pos, and Ive made it so there is no end pos without start pos
|
||||
print('Toggled lines off')
|
||||
);
|
||||
null
|
||||
);
|
||||
|
||||
_calculate(start_pos, end_pos)->(
|
||||
if(start_pos!=null,
|
||||
set_start(start_pos);
|
||||
calculate(end_pos),
|
||||
if(global_position,
|
||||
calculate(end_pos),
|
||||
print(player(),format('r There was no initial point for '+player()));
|
||||
set_start(end_pos)
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
__on_player_right_clicks_block(player, item_tuple, hand, block, face, hitvec) ->(
|
||||
pos = pos_offset(block,face);//for clicking against the wall.
|
||||
if(block=='brown_carpet' && system_info('world_carpet_rules'):'carpets'=='true',
|
||||
if(global_position==null||player~'sneaking',//wont complain for first carpet
|
||||
set_start(pos),
|
||||
_calculate(null,pos)
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
calculate(end_pos)->(
|
||||
start_pos = global_position;
|
||||
[dx,dy,dz] = map(start_pos-end_pos,abs(_));
|
||||
|
||||
manhattan = _round(_manhattan([dx, dy, dz],[0,0,0]),100);//rounding to nearest 0.01 for precision, but not ridiculous decimal places
|
||||
spherical = _round(_euclidean([dx, dy, dz],[0,0,0]),100);
|
||||
cylindrical = _round(_euclidean([dx, 0, dz],[0,0,0]),100);//useful for chunk distances etc.
|
||||
|
||||
print(player(),format(
|
||||
'w Distance between ',
|
||||
'c '+start_pos,'?/tp '+(str(start_pos)-','-'['-']'), 'w and ',
|
||||
'c '+end_pos,'?/tp '+(str(end_pos)-','-'['-']'), 'w :\n',
|
||||
'w - Spherical: ', 'wb '+spherical+'\n',
|
||||
'w - Cylindrical: ', 'wb '+cylindrical+'\n',
|
||||
'w - Manhattan: ', 'wb '+manhattan
|
||||
));
|
||||
|
||||
global_end_position = end_pos;
|
||||
|
||||
schedule(0,'_draw_line');
|
||||
);
|
||||
|
||||
_draw_line()->(
|
||||
if(global_show_line,//It will always draw from the global positions, so it will turn on if there is a line
|
||||
draw_shape('line',20,'from',global_position,'to',global_end_position, 'player',player(),'color',0x000000FF);
|
||||
draw_shape('label',20,'pos',global_end_position,'text',_round(_euclidean(global_position,global_end_position),100),'color',0x000000FF);
|
||||
schedule(20,'_draw_line')
|
||||
)
|
||||
);
|
||||
@@ -0,0 +1,142 @@
|
||||
import('math','_euclidean_sq','_vec_length');
|
||||
|
||||
__config() -> {
|
||||
'commands'->{
|
||||
'sphere <center> <radius> <block>'->['draw_sphere',null,true],
|
||||
'sphere <center> <radius> <block> replace <replacement>'->['draw_sphere',true],
|
||||
'ball <center> <radius> <block>'->['draw_sphere',null,false],
|
||||
'ball <center> <radius> <block> replace <replacement>'->['draw_sphere',false],
|
||||
'diamond <center> <radius> <block>'->['draw_diamond',null],
|
||||
'diamond <center> <radius> <block> replace <replacement>'->'draw_diamond',
|
||||
'pyramid <center> <radius> <height> <pointing> <orientation> <block> <hollow>'->['draw_pyramid',null, true],
|
||||
'pyramid <center> <radius> <height> <pointing> <orientation> <block> <hollow> replace <replacement>'->['draw_pyramid', true],
|
||||
'cone <center> <radius> <height> <pointing> <orientation> <block> <hollow>'->['draw_pyramid',null, false],
|
||||
'cone <center> <radius> <height> <pointing> <orientation> <block> <hollow> replace <replacement>'->['draw_pyramid', false],
|
||||
'cuboid <center> <radius> <height> <orientation> <block> <hollow>'->['draw_prism', null, true],
|
||||
'cuboid <center> <radius> <height> <orientation> <block> <hollow> replace <replacement>'->['draw_prism', true],
|
||||
'cylinder <center> <radius> <height> <orientation> <block> <hollow>'->['draw_prism', null, false],
|
||||
'cylinder <center> <radius> <height> <orientation> <block> <hollow> replace <replacement>'->['draw_prism', false]
|
||||
},
|
||||
'arguments'->{
|
||||
'center'->{'type'->'pos', 'loaded'->'true'},
|
||||
'radius'->{'type'->'int', 'suggest'->[], 'min'->0},//to avoid default suggestions
|
||||
'replacement'->{'type'->'block'},
|
||||
'height'->{'type'->'int', 'suggest'->[],'min'->0},
|
||||
'orientation'->{'type'->'term', 'suggest'->['x','y','z']},
|
||||
'pointing'->{'type'->'term','suggest'->['up','down']},
|
||||
'hollow'->{'type'->'term','suggest'->['hollow','solid']},
|
||||
},
|
||||
'scope'->'global'
|
||||
};
|
||||
|
||||
|
||||
//"Boilerplate" code
|
||||
|
||||
set_block(x, y, z, block, replacement)-> (
|
||||
if(block != block(x, y, z),
|
||||
without_updates(set([x, y, z],block));
|
||||
global_affected:0 += [x, y, z];
|
||||
global_affected:1 += 1;
|
||||
);
|
||||
);
|
||||
|
||||
global_affected = [[],0];
|
||||
|
||||
affected(player) -> (
|
||||
print(player,format('gi Filled ' + global_affected:1 + ' blocks'));
|
||||
affected = global_affected:1;
|
||||
|
||||
if(system_info('world_carpet_rules'):'fillUpdates',
|
||||
for(global_affected:0,update(_));//updating if fillUpdates is true
|
||||
);
|
||||
|
||||
global_affected = [[],0];
|
||||
affected
|
||||
);
|
||||
|
||||
length_sq(vec) -> _vec_length(vec)^2;
|
||||
|
||||
fill_flat(pos, offset, dr, rectangle, orientation, block, hollow, replacement)->(
|
||||
r = floor(dr);
|
||||
drsq = dr^2;
|
||||
if(orientation=='x',
|
||||
scan(pos,0,-r,-r,
|
||||
if((!hollow && (rectangle || _y^2 + _z^2 <= drsq))||//if not hollow, vry simple
|
||||
(hollow && ((rectangle && (abs(_y) == r || abs(_z) ==r)) || //If hollow and it's a rectangle
|
||||
(!rectangle && (_y^2 + _z^2 <= drsq && (abs(_y)+1)^ 2 + (abs(_z)+1)^2 >= drsq)))),//If hollow and not rectangle
|
||||
set_block(_x+offset,_y,_z,block, replacement)
|
||||
)
|
||||
),
|
||||
orientation == 'y',
|
||||
scan(pos,-r,0,-r,
|
||||
if((!hollow && (rectangle || _x^2 + _z^2 <= drsq))||//if not hollow, vry simple
|
||||
(hollow && ((rectangle && (abs(_x) == r || abs(_z) ==r)) || //If hollow and it's a rectangle
|
||||
(!rectangle && (_x^2 + _z^2 <= drsq && (abs(_x)+1)^ 2 + (abs(_z)+1)^2 >= drsq)))),//If hollow and not rectangle
|
||||
set_block(_x,_y+offset,_z,block, replacement)
|
||||
)
|
||||
),
|
||||
orientation == 'z',
|
||||
scan(pos,-r,-r,0,
|
||||
if((!hollow && (rectangle || _y^2 + _x^2 <= drsq))||//if not hollow, vry simple
|
||||
(hollow && ((rectangle && (abs(_y) == r || abs(_x) ==r)) || //If hollow and it's a rectangle
|
||||
(!rectangle && (_y^2 + _x^2 <= drsq && (abs(_y)+1)^ 2 + (abs(_x)+1)^2 >= drsq)))),//If hollow and not rectangle
|
||||
set_block(_x,_y,_z+offset,block, replacement)
|
||||
)
|
||||
),
|
||||
print(player(),format('r Error while running command: orientation can only be "x", "y" or "z", '+orientation+' is invalid.'));
|
||||
global_affected = [[],0];
|
||||
);
|
||||
);
|
||||
|
||||
//drawing commands
|
||||
|
||||
draw_sphere(centre, radius, block, replacement, hollow)->(
|
||||
scan(centre,[radius,radius,radius],
|
||||
l = length_sq([_x,_y,_z]-centre);
|
||||
if((l<=radius^2+radius) && (!hollow || l>=radius^2-radius),
|
||||
set_block(_x, _y, _z, block, replacement)
|
||||
)
|
||||
);
|
||||
|
||||
affected(player());
|
||||
);
|
||||
|
||||
draw_diamond(pos, radius, block, replacement)->(
|
||||
|
||||
c_for(r=0, r<radius, r+=1,
|
||||
y = r-radius+1;
|
||||
c_for(x=-r,x<=r,x+=1,
|
||||
z=r-abs(x);
|
||||
|
||||
set_block(pos:0+x,pos:1-y,pos:2+z, block, replacement);
|
||||
set_block(pos:0+x,pos:1-y,pos:2-z, block, replacement);
|
||||
set_block(pos:0+x,pos:1+y,pos:2+z, block, replacement);
|
||||
set_block(pos:0+x,pos:1+y,pos:2-z, block, replacement);
|
||||
)
|
||||
);
|
||||
|
||||
affected(player())
|
||||
);
|
||||
|
||||
draw_pyramid(pos, radius, height, pointing, orientation, block, fill_type, replacement, is_square)->(
|
||||
|
||||
hollow = fill_type=='hollow';
|
||||
pointup = pointing=='up';
|
||||
|
||||
for(range(height),
|
||||
r = if(pointup, radius - radius * _ / height -1, radius * _ / height);
|
||||
fill_flat(pos, _, r, is_square, orientation, block, if((pointup&&_==0)||(!pointup && _==height-1),false,hollow),replacement)//Always close bottom off
|
||||
);
|
||||
affected(player())
|
||||
);
|
||||
|
||||
draw_prism(pos, rad, height, orientation, block, fill_type, replacement, is_square)->(
|
||||
|
||||
hollow = fill_type =='hollow';
|
||||
radius = rad+0.5;
|
||||
|
||||
for(range(height),
|
||||
fill_flat(pos, _, radius, is_square, orientation, block, if(_==0 || _==height-1,false,hollow), replacement)//Always close ends off
|
||||
);
|
||||
affected(player())
|
||||
);
|
||||
@@ -1,3 +1,5 @@
|
||||
_euclidean_sq(vec1, vec2) -> reduce(vec1 - vec2, _a + _*_, 0);
|
||||
_euclidean(vec1, vec2) -> sqrt(reduce(vec1 - vec2, _a + _*_, 0));
|
||||
_vec_length(vec) -> sqrt(reduce(vec, _a + _*_, 0));
|
||||
_manhattan(vec1, vec2) -> reduce(vec1-vec2,_a+abs(_),0);
|
||||
_vec_length(vec) -> sqrt(reduce(vec, _a + _*_, 0));
|
||||
_round(num,precision) -> round(num*precision)/precision;
|
||||
Reference in new issue
Block a user