moved overlay to the new command system, added spheres and boxes

This commit is contained in:
gnembon committed 2020-11-16 01:56:32 -04:00
1 parent 37391d2726
commit 7046166561
3 files changed
+73 -29

No files matched your search

+1 -1
View File
@@ -211,7 +211,7 @@ Here is a list of built-in types, with their return value formats, as well as a
* `'anchor'`: string of `feet` or `eyes`.
* `'entitytype'`: string representing a type of entity
* `'floatrange'`: pair of two numbers where one is smaller than the other
* `'players'`: returning a list of valid player entities. If configured with `'single'` returns only one player or `null`.
* `'players'`: returning a list of valid player name string, logged in or not. If configured with `'single'` returns only one player or `null`.
* `'intrange'`: same as `'floatrange'`, but requiring integers.
* `'enchantment'`: name of an enchantment
* `'item'`: triple of item type, count of 1, and nbt.
@@ -136,7 +136,7 @@ public class CarpetScriptHost extends ScriptHost
String hostName = main.getName();
List<String> commandArgs = path.stream().filter(t -> t.isArgument).map(t -> t.surface).collect(Collectors.toList());
if (commandArgs.size() != (functionSpec.function.getNumParams()-functionSpec.args.size()) )
throw CommandArgument.error("Number of parameters in function doesn't match parameters for a command");
throw CommandArgument.error("Number of parameters in function "+functionSpec.function.fullName()+" doesn't match parameters for a command");
if (path.isEmpty())
{
return command.executes((c) -> execute(c, hostName, functionSpec, Collections.emptyList()));
@@ -27,35 +27,76 @@ global_renderers = m(
}
);
__command() -> '';
global_shapes = {'sphere' -> [], 'box' -> []};
monument() -> __toggle('monument', 'structures');
fortress() -> __toggle('fortress', 'structures');
mansion() -> __toggle('mansion', 'structures');
jungle_pyramid() -> __toggle('jungle_pyramid', 'structures');
desert_pyramid() -> __toggle('desert_pyramid', 'structures');
endcity() -> __toggle('endcity', 'structures');
igloo() -> __toggle('igloo', 'structures');
shipwreck() -> __toggle('shipwreck', 'structures');
swamp_hut() -> __toggle('swamp_hut', 'structures');
stronghold() -> __toggle('stronghold', 'structures');
ocean_ruin() -> __toggle('ocean_ruin', 'structures');
buried_treasure() -> __toggle('buried_treasure', 'structures');
pillager_outpost() -> __toggle('pillager_outpost', 'structures');
mineshaft() -> __toggle('mineshaft', 'structures');
village() -> __toggle('village', 'structures');
nether_fossil() -> __toggle('nether_fossil', 'structures');
bastion_remnant() -> __toggle('bastion_remnant', 'structures');
ruined_portal() -> __toggle('ruined_portal', 'structures');
slime_chunks() -> __toggle('slime_chunks', 'chunks');
portal_coordinates() -> __toggle('coords', 'portals');
portal_links() -> __toggle('links', 'portals');
__config() ->
{
'commands' -> {
'structure <structure>' -> _(s) -> __toggle(s, 'structures'),
'slime_chunks' -> ['__toggle', 'slime_chunks', 'chunks'],
'portal coordinates' -> ['__toggle', 'coords', 'portals'],
'portal links' -> ['__toggle', 'links', 'portals'],
'<shape> <radius> following <player>' -> ['display_shape', [null,0xffffffff], true],
'<shape> <radius> at <player>' -> ['display_shape', [null,0xffffffff], false],
'<shape> <radius> following <player> <color>' -> ['display_shape', true],
'<shape> <radius> at <player> <color>' -> ['display_shape', false],
'<shape> clear' -> 'clear_shape',
'clear' -> 'clear',
},
'arguments' -> {
'structure' -> {'type' -> 'term', 'suggest' -> [
'monument', 'fortress', 'mansion', 'jungle_pyramid',
'desert_pyramid', 'endcity', 'igloo', 'shipwreck',
'swamp_hut', 'stronghold', 'ocean_ruin', 'buried_treasure',
'pillager_outpost', 'mineshaft', 'village', 'nether_fossil',
'bastion_remnant', 'ruined_portal'
]},
'player' -> {'type' -> 'players', 'single' -> true},
'radius' -> {'type' -> 'int', 'min' -> 0, 'max' -> 1024, 'suggest' -> [128, 24, 32]},
'shape' -> {'type' -> 'term', 'options' -> keys(global_shapes) },
'color' -> {'type' -> 'teamcolor'}
}
};
display_shape(shape, r, player, color, following) ->
(
clear() -> for(global_renderers, global_renderers:_:'tasks' = m() );
player = player(player);
if (!player, return());
if (shape == 'sphere',
shape_config = {
'center' -> if(following, [0,0,0], pos(player)),
'radius' -> r
}
, shape == 'box',
shape_config = {
'from' -> if(following, [-r,-r,-r], pos(player)-r),
'to' -> if(following, [r,r,r], pos(player)+r)
}
);
if (shape_config,
if (following, shape_config:'follow' = player);
shape_config:'fill' = color:1 - 200;
shape_config:'color' = color:1;
shape_config:'line' = 5;
draw_shape(shape, 72000, shape_config);
global_shapes:shape += shape_config;
)
);
clear_shape(shape) ->
(
for(global_shapes:shape, draw_shape(shape, 0, _));
global_shapes:shape = [];
);
clear() ->
(
for(global_renderers, global_renderers:_:'tasks' = m() );
for(global_shapes, clear_shape(_));
);
__toggle(feature, renderer) ->
(
@@ -63,11 +104,11 @@ __toggle(feature, renderer) ->
config = global_renderers:renderer;
if( has(config:'tasks':feature),
delete(config:'tasks':feature);
'disabled '+feature+' overlays';
print(p, format('gi disabled '+feature+' overlays'));
,
config:'tasks' += feature;
if (!config:'active', call(config:'handler', p~'name'));
'enabled '+feature+' overlays';
print(p, format('gi enabled '+feature+' overlays'));
)
);
@@ -81,6 +122,9 @@ __should_run(renderer, player_name) ->
l(p, config);
);
__structure_renderer(player_name) ->
(
l(p, config) = __should_run('structures', player_name);