Merge branch 'master' into 1.16

This commit is contained in:
gnembon committed 2020-03-18 02:01:01 -03:00
commit 583e023eb1
25 files changed
+3886 -99

No files matched your search

+40
View File
@@ -0,0 +1,40 @@
# Scarpet Language Documentation
## Language Specification
[Overview](/docs/scarpet/language/Overview.md)
[Variables and Constants](/docs/scarpet/language/VariablesAndConstants.md)
[Operators](/docs/scarpet/language/Operators.md)
[Mathematical Functions](/docs/scarpet/language/Math.md)
[System Functions](/docs/scarpet/language/SystemFunctions.md)
[Loops and Higher Order Functions](/docs/scarpet/language/LoopsAndHigherOrderFunctions.md)
[User Defined Functions and Control Flow](/docs/scarpet/language/FunctionsAndControlFlow.md)
[Container Types](/docs/scarpet/language/Containers.md)
## Minecraft API
[Overview](/docs/scarpet/api/Overview.md)
[Blocks and World Access](/docs/scarpet/api/BlocksAndWorldAccess.md)
[Block Iterations](/docs/scarpet/api/BlockIterations.md)
[Entities](/docs/scarpet/api/Entities.md)
[Inventories](/docs/scarpet/api/Inventories.md)
[Events](/docs/scarpet/api/Events.md)
[Auxiliary Functions](/docs/scarpet/api/Auxiliary.md)
[`/script` Command](/docs/scarpet/api/ScriptCommand.md)
## [One Page](/docs/scarpet/Full.md)
+3150
View File
File diff suppressed because it is too large. Load diff
+1 -1
View File
@@ -7,7 +7,7 @@ as `(2+4)-3`, which in case of numbers doesn't matter, but since `scarpet` allow
the associativity would matter, and may lead to unintended effects:
Important operator is function definition `->` operator. It will be covered
in {@link carpet.script.Expression#UserDefinedFunctionsAndControlFlow}
in [User Defined Functions and Program Control Flow](docs/scarpet/language/FunctionsAndControlFlow.md)
<pre>
'123'+4-2 => ('123'+4)-2 => '1234'-2 => '134'
+8 -5
View File
@@ -62,7 +62,7 @@ or an OVERLY complex example:
or simply
<pre>
/script run print('There is'+for(rect(x,9,z,8,8,8), _ == 'diamond_ore')+' diamond ore around you')
/script run print('There is '+for(rect(x,9,z,8,8,8), _ == 'diamond_ore')+' diamond ore around you')
</pre>
It definitely pays to check what higher level `scarpet` functions have to offer.
@@ -112,16 +112,17 @@ Or rather:
<pre>
if
(
x&lt;y+6,
( x&lt;y+6,
(
set(x,8+y,z,'air');
plop(x,top('surface',x,z),z,'birch')
),
// else if
sin(query(player(),'yaw'))>0.5,
(
plop(0,0,0,'boulder')
),
// else
particle('fire',x,y,z)
)
</pre>
@@ -134,8 +135,10 @@ have problems with them
## Functions and scoping
Users can define functions in the form `fun(args....) -> expression` and they are compiled and saved for further
execution in this but also subsequent calls of /script command. Functions can also be assigned to variables,
passed as arguments, called with `call` function, but in most cases you would want to call them directly by
execution in this, but also subsequent calls of /script command, added to events, etc. Functions can also be
assigned to variables,
passed as arguments, called with `call('fun', args...)` function, but in most cases you would want to
call them directly by
name, in the form of `fun(args...)`. This means that once defined functions are saved with the world for
further use. For variables, there are two types of them, global - which are shared anywhere in the code,
and those are all which name starts with 'global_', and local variables which is everything else and those
+6 -5
View File
@@ -51,10 +51,10 @@ number('2')+number('2') => 4
Returns a formatted string representing expression. Accepts formatting style accepted by `String.format`.
Supported types (with `"%?"` syntax):
* d, o, x: integers
* a, e, f, g: floats
* b: booleans
* s: strings
* `d`, `o`, `x`: integers, octal, hex
* `a`, `e`, `f`, `g`: floats
* `b`: booleans
* `s`: strings
<pre>
str(null) => null
@@ -81,7 +81,8 @@ the off-tick time in between ticks that didn't take 50ms. There are however bene
like fine time control not relying on the tick clock, or running things independent on each other. You can still run
your actions on tick-by-tick basis, either taking control of the execution using `game_tick()` API function
(nasty solution), or scheduling tick using `schedule()` function (much nicer solution), but threading often gives
the neatest solution to solve problems in parallel (see scarpet camera).
the neatest solution to solve problems in parallel
(see [scarpet camera](/src/main/resources/assets/carpet/scripts/camera.sc)).
Due to limitations with the game, there are some limits to the threading as well. You cannot for
instance `join_task()` at all from the main script and server thread, because any use of Minecraft specific
+99
View File
@@ -0,0 +1,99 @@
abs
acos
acosh
acot
all
asin
asinh
atan
atan2
atanh
bool
break
call
ceil
continue
copy
cos
cosh
cot
coth
csc
csch
deg
delete
exit
fact
filter
first
floor
for
get
has
hash_code
if
import
join
keys
l
length
log
log10
log1p
loop
lower
m
mandelbrot
map
max
min
not
number
outer
pairs
perlin
print
profile_expr
put
rad
rand
range
reduce
relu
replace
replace_first
return
round
sec
sech
simplex
sin
sinh
sleep
slice
sort
sort_key
synchronize
system_variable_get
system_variable_set
split
sqrt
str
tan
tanh
task
task_completed
task_count
task_join
task_value
throw
time
title
try
type
undef
upper
values
var
vars
while
+93
View File
@@ -0,0 +1,93 @@
air
biome
blast_resistance
block
block_data
block_light
block_properties
block_sound
block_tick
blocks_daylight
blocks_movement
brightness
chunk_tickets
create_marker
current_dimension
destroy
diamond
drop_item
emitted_light
entity_area
entity_event
entity_id
entity_list
entity_selector
escape_nbt
flammable
game_tick
generation_status
hardness
harvest
in_dimension
in_slime_chunk
inventory_find
inventory_get
inventory_remove
inventory_set
inventory_size
item_category
light
liquid
load_app_data
loaded
loaded_status
logger
map_colour
material
modify
nbt
neighbours
opacity
particle
particle_line
particle_rect
place_item
player
plop
poi
pos
pos_offset
power
property
query
random_tick
rect
remove_all_markers
reset_chunk
run
save
scan
schedule
see_sky
seed
set
set_biome
set_poi
set_structure
sky_light
solid
sound
spawn
stack_limit
statistic
store_app_data
structures
structure_references
suffocates
tick_time
ticks_randomly
top
transparent
update
volume
without_updates
+11
View File
@@ -0,0 +1,11 @@
_
_a
_i
_x
_y
_z
euler
false
null
pi
true
+28
View File
@@ -0,0 +1,28 @@
__command
__config
__on_chunk_generated
__on_close
__on_player_attacks_entity
__on_player_breaks_block
__on_player_clicks_block
__on_player_deploys_elytra
__on_player_drops_item
__on_player_drops_stack
__on_player_finishes_using_item
__on_player_interacts_with_block
__on_player_interacts_with_entity
__on_player_jumps
__on_player_places_block
__on_player_releases_item
__on_player_rides
__on_player_right_clicks_block
__on_player_starts_sneaking
__on_player_starts_sprinting
__on_player_stops_sneaking
__on_player_stops_sprinting
__on_player_uses_item
__on_player_wakes_up
__on_statistic
__on_tick
__on_tick_ender
__on_tick_nether
Binary file not shown.

After

Width:  |  Height:  |  Size: 51 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 47 KiB

@@ -0,0 +1,136 @@
<NotepadPlus>
<UserLang name="scarpet" ext="sc scl" udlVersion="2.1">
<Settings>
<Global caseIgnored="yes" allowFoldOfComments="no" foldCompact="no" forcePureLC="0" decimalSeparator="0" />
<Prefix Keywords1="no" Keywords2="no" Keywords3="no" Keywords4="no" Keywords5="no" Keywords6="yes" Keywords7="no" Keywords8="no" />
</Settings>
<KeywordLists>
<Keywords name="Comments">00// 01 02 03 04</Keywords>
<Keywords name="Numbers, prefix1">0x</Keywords>
<Keywords name="Numbers, prefix2"></Keywords>
<Keywords name="Numbers, extras1"></Keywords>
<Keywords name="Numbers, extras2"></Keywords>
<Keywords name="Numbers, suffix1"></Keywords>
<Keywords name="Numbers, suffix2"></Keywords>
<Keywords name="Numbers, range"></Keywords>
<Keywords name="Operators1">; + - * / % ^ &amp;&amp; || &gt; &gt;= &lt; &lt;= == != = += -&gt; &lt;&gt; ! ~ , :</Keywords>
<Keywords name="Operators2"></Keywords>
<Keywords name="Folders in code1, open">(</Keywords>
<Keywords name="Folders in code1, middle"></Keywords>
<Keywords name="Folders in code1, close">)</Keywords>
<Keywords name="Folders in code2, open"></Keywords>
<Keywords name="Folders in code2, middle"></Keywords>
<Keywords name="Folders in code2, close"></Keywords>
<Keywords name="Folders in comment, open"></Keywords>
<Keywords name="Folders in comment, middle"></Keywords>
<Keywords name="Folders in comment, close"></Keywords>
<Keywords name="Keywords1">
not fact rand
sin cos tan asin acos atan atan2 sinh cosh tanh sec csc sech csch cot acot coth asinh acosh atanh
rad deg
log log10 log1p
sqrt
max min abs round floor ceil
mandelbrot relu
perlin simplex
print return exit throw try
task task_count task_value task_join task_completed synchronize
system_variable_get system_variable_set
l join split slice sort sort_key range m keys values pairs copy
get put has delete
var undef vars if loop map filter first all for while reduce continue break
import call outer type hash_code bool number str length rand sleep time profile_expr lower upper title replace replace_first
</Keywords>
<Keywords name="Keywords2">
block pos pos_offset solid air liquid flammable
transparent opacity blocks_daylight emitted_light light block_light sky_light see_sky brightness
hardness blast_resistance top loaded suffocates power ticks_randomly update block_tick random_tick in_slime_chunk
set without_updates
blocks_movement block_sound material map_colour property block_properties block_data poi set_poi
place_item set_biome biome loaded_status generation_status chunk_tickets
structures structure_references set_structure reset_chunk
player spawn entity_id entity_list entity_area entity_selector query modify entity_event
stack_limit item_category inventory_size inventory_has_items inventory_get inventory_set inventory_find inventory_remove drop_item
scan volume neighbours rect diamond
logger sound particle particle_line particle_rect
run save tick_time game_tick seed current_dimension in_dimension
plop harvest destroy schedule nbt create_marker remove_all_markers load_app_data store_app_data escape_nbt statistic
</Keywords>
<Keywords name="Keywords3">euler pi null true false</Keywords>
<Keywords name="Keywords4">x y z p</Keywords>
<Keywords name="Keywords5">_ _i _a _x _y _z</Keywords>
<Keywords name="Keywords6">global_</Keywords>
<Keywords name="Keywords7">
__command
__config
__on_chunk_generated
__on_close
__on_player_attacks_entity
__on_player_breaks_block
__on_player_clicks_block
__on_player_deploys_elytra
__on_player_drops_item
__on_player_drops_stack
__on_player_finishes_using_item
__on_player_interacts_with_block
__on_player_interacts_with_entity
__on_player_jumps
__on_player_places_block
__on_player_releases_item
__on_player_rides
__on_player_right_clicks_block
__on_player_starts_sneaking
__on_player_starts_sprinting
__on_player_stops_sneaking
__on_player_stops_sprinting
__on_player_uses_item
__on_player_wakes_up
__on_statistic
__on_tick
__on_tick_ender
__on_tick_nether
</Keywords>
<Keywords name="Keywords8">$</Keywords>
<Keywords name="Delimiters">00&apos; 01\ 02&apos; 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23</Keywords>
</KeywordLists>
<Styles>
<WordsStyle name="DEFAULT" fgColor="000040" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" />
<WordsStyle name="COMMENTS" fgColor="000000" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" />
<WordsStyle name="LINE COMMENTS" fgColor="808080" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" />
<WordsStyle name="NUMBERS" fgColor="008040" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" />
<WordsStyle name="KEYWORDS1" fgColor="0000FF" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" />
<WordsStyle name="KEYWORDS2" fgColor="800000" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" />
<WordsStyle name="KEYWORDS3" fgColor="0080C0" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" />
<WordsStyle name="KEYWORDS4" fgColor="400080" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" />
<WordsStyle name="KEYWORDS5" fgColor="FF0080" bgColor="FFFFFF" fontName="" fontStyle="1" nesting="0" />
<WordsStyle name="KEYWORDS6" fgColor="008000" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" />
<WordsStyle name="KEYWORDS7" fgColor="FF8040" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" />
<WordsStyle name="KEYWORDS8" fgColor="DEDEDE" bgColor="FFFFFF" fontName="" fontStyle="1" nesting="0" />
<WordsStyle name="OPERATORS" fgColor="804040" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" />
<WordsStyle name="FOLDER IN CODE1" fgColor="515151" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" />
<WordsStyle name="FOLDER IN CODE2" fgColor="000000" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" />
<WordsStyle name="FOLDER IN COMMENT" fgColor="000000" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" />
<WordsStyle name="DELIMITERS1" fgColor="0080C0" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" />
<WordsStyle name="DELIMITERS2" fgColor="000000" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" />
<WordsStyle name="DELIMITERS3" fgColor="000000" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" />
<WordsStyle name="DELIMITERS4" fgColor="000000" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" />
<WordsStyle name="DELIMITERS5" fgColor="000000" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" />
<WordsStyle name="DELIMITERS6" fgColor="000000" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" />
<WordsStyle name="DELIMITERS7" fgColor="000000" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" />
<WordsStyle name="DELIMITERS8" fgColor="000000" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" />
</Styles>
</UserLang>
</NotepadPlus>
@@ -0,0 +1,64 @@
<NotepadPlus>
<UserLang name="scarpet" ext="sc" udlVersion="2.1">
<Settings>
<Global caseIgnored="yes" allowFoldOfComments="no" foldCompact="no" forcePureLC="0" decimalSeparator="0" />
<Prefix Keywords1="no" Keywords2="no" Keywords3="no" Keywords4="no" Keywords5="no" Keywords6="yes" Keywords7="no" Keywords8="no" />
</Settings>
<KeywordLists>
<Keywords name="Comments"></Keywords>
<Keywords name="Numbers, prefix1"></Keywords>
<Keywords name="Numbers, prefix2"></Keywords>
<Keywords name="Numbers, extras1"></Keywords>
<Keywords name="Numbers, extras2"></Keywords>
<Keywords name="Numbers, suffix1"></Keywords>
<Keywords name="Numbers, suffix2"></Keywords>
<Keywords name="Numbers, range"></Keywords>
<Keywords name="Operators1">; + - * / % ^ &amp;&amp; || &gt; &gt;= &lt; &lt;= == != = += -&gt; &lt;&gt; ! , ~</Keywords>
<Keywords name="Operators2"></Keywords>
<Keywords name="Folders in code1, open">(</Keywords>
<Keywords name="Folders in code1, middle"></Keywords>
<Keywords name="Folders in code1, close">)</Keywords>
<Keywords name="Folders in code2, open"></Keywords>
<Keywords name="Folders in code2, middle"></Keywords>
<Keywords name="Folders in code2, close"></Keywords>
<Keywords name="Folders in comment, open"></Keywords>
<Keywords name="Folders in comment, middle"></Keywords>
<Keywords name="Folders in comment, close"></Keywords>
<Keywords name="Keywords1">not fact rand sin cos tan asin acos atan atan2 sinh cosh tanh sec csc sech csch cot acot coth asinh acosh atanh rad deg log log10 log1p sqrt max min abs round floor ceil mandelbrot relu print return exit throw try l join split slice sort sort_key range element put var undef vars if loop map filter first all for while reduce outer bool number str length rand sleep time</Keywords>
<Keywords name="Keywords2">block pos solid air liquid flammable transparent opacity blocks_daylight emitted_light light block_light sky_light see_sky hardness blast_resistance top loaded loaded_ep suffocates power ticks_randomly update block_tick random_tick set blocks_movement block_sound material map_colour property player entity_id entity_list entity_area entity_selector query modify scan volume neighbours rect diamond sound particle particle_line particle_rect run save tick_time game_tick plop harvest destroy schedule</Keywords>
<Keywords name="Keywords3">euler pi null true false</Keywords>
<Keywords name="Keywords4">x y z p</Keywords>
<Keywords name="Keywords5">_ _i _a _x _y _z</Keywords>
<Keywords name="Keywords6">global_</Keywords>
<Keywords name="Keywords7">__command __on_player_jumps __on_player_deploys_elytra __on_player_wakes_up __on_player_rides __on_player_uses_item __on_player_clicks_block __on_player_right_clicks_block __on_player_breaks_block __on_player_interacts_with_entity __on_player_attacks_entity __on_player_starts_sneaking __on_player_stops_sneaking __on_player_starts_sprinting __on_player_stops_sprinting</Keywords>
<Keywords name="Keywords8">$</Keywords>
<Keywords name="Delimiters">00&apos; 01\ 02&apos; 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23</Keywords>
</KeywordLists>
<Styles>
<WordsStyle name="DEFAULT" fgColor="000040" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" />
<WordsStyle name="COMMENTS" fgColor="000000" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" />
<WordsStyle name="LINE COMMENTS" fgColor="000000" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" />
<WordsStyle name="NUMBERS" fgColor="008040" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" />
<WordsStyle name="KEYWORDS1" fgColor="0000FF" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" />
<WordsStyle name="KEYWORDS2" fgColor="800000" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" />
<WordsStyle name="KEYWORDS3" fgColor="0080C0" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" />
<WordsStyle name="KEYWORDS4" fgColor="400080" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" />
<WordsStyle name="KEYWORDS5" fgColor="FF0080" bgColor="FFFFFF" fontName="" fontStyle="1" nesting="0" />
<WordsStyle name="KEYWORDS6" fgColor="008000" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" />
<WordsStyle name="KEYWORDS7" fgColor="FF8040" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" />
<WordsStyle name="KEYWORDS8" fgColor="DEDEDE" bgColor="FFFFFF" fontName="" fontStyle="1" nesting="0" />
<WordsStyle name="OPERATORS" fgColor="804040" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" />
<WordsStyle name="FOLDER IN CODE1" fgColor="804000" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" />
<WordsStyle name="FOLDER IN CODE2" fgColor="000000" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" />
<WordsStyle name="FOLDER IN COMMENT" fgColor="000000" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" />
<WordsStyle name="DELIMITERS1" fgColor="0080C0" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" />
<WordsStyle name="DELIMITERS2" fgColor="000000" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" />
<WordsStyle name="DELIMITERS3" fgColor="000000" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" />
<WordsStyle name="DELIMITERS4" fgColor="000000" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" />
<WordsStyle name="DELIMITERS5" fgColor="000000" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" />
<WordsStyle name="DELIMITERS6" fgColor="000000" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" />
<WordsStyle name="DELIMITERS7" fgColor="000000" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" />
<WordsStyle name="DELIMITERS8" fgColor="000000" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" />
</Styles>
</UserLang>
</NotepadPlus>
@@ -0,0 +1,64 @@
<NotepadPlus>
<UserLang name="scarpet" ext="sc" udlVersion="2.1">
<Settings>
<Global caseIgnored="yes" allowFoldOfComments="no" foldCompact="no" forcePureLC="0" decimalSeparator="0" />
<Prefix Keywords1="no" Keywords2="no" Keywords3="no" Keywords4="no" Keywords5="no" Keywords6="yes" Keywords7="no" Keywords8="no" />
</Settings>
<KeywordLists>
<Keywords name="Comments">00// 01 02 03 04</Keywords>
<Keywords name="Numbers, prefix1"></Keywords>
<Keywords name="Numbers, prefix2"></Keywords>
<Keywords name="Numbers, extras1"></Keywords>
<Keywords name="Numbers, extras2"></Keywords>
<Keywords name="Numbers, suffix1"></Keywords>
<Keywords name="Numbers, suffix2"></Keywords>
<Keywords name="Numbers, range"></Keywords>
<Keywords name="Operators1">; + - * / % ^ &amp;&amp; || &gt; &gt;= &lt; &lt;= == != = += -&gt; &lt;&gt; ! , ~</Keywords>
<Keywords name="Operators2"></Keywords>
<Keywords name="Folders in code1, open">(</Keywords>
<Keywords name="Folders in code1, middle"></Keywords>
<Keywords name="Folders in code1, close">)</Keywords>
<Keywords name="Folders in code2, open"></Keywords>
<Keywords name="Folders in code2, middle"></Keywords>
<Keywords name="Folders in code2, close"></Keywords>
<Keywords name="Folders in comment, open"></Keywords>
<Keywords name="Folders in comment, middle"></Keywords>
<Keywords name="Folders in comment, close"></Keywords>
<Keywords name="Keywords1">not fact rand sin cos tan asin acos atan atan2 sinh cosh tanh sec csc sech csch cot acot coth asinh acosh atanh rad deg log log10 log1p sqrt max min abs round floor ceil mandelbrot relu &#x000D;&#x000A;&#x000D;&#x000A;print return exit throw try &#x000D;&#x000A;&#x000D;&#x000A;l join split slice sort sort_key range get put &#x000D;&#x000A;&#x000D;&#x000A;var undef vars if loop map filter first all for while reduce &#x000D;&#x000A;&#x000D;&#x000A;outer type bool number str length rand sleep time</Keywords>
<Keywords name="Keywords2">block pos solid air liquid flammable transparent opacity blocks_daylight emitted_light light block_light sky_light see_sky hardness blast_resistance top loaded loaded_ep suffocates power ticks_randomly update block_tick random_tick set blocks_movement block_sound material map_colour property block_properties block_data place_item set_biome&#x000D;&#x000A;&#x000D;&#x000A;player spawn entity_id entity_list entity_area entity_selector query modify&#x000D;&#x000A;&#x000D;&#x000A;stack_limit inventory_size inventory_get inventory_set inventory_find inventory_remove drop_item&#x000D;&#x000A;&#x000D;&#x000A;scan volume neighbours rect diamond &#x000D;&#x000A;&#x000D;&#x000A;sound particle particle_line particle_rect run save tick_time game_tick plop harvest destroy schedule nbt create_marker remove_all_markers</Keywords>
<Keywords name="Keywords3">euler pi null true false</Keywords>
<Keywords name="Keywords4">x y z p</Keywords>
<Keywords name="Keywords5">_ _i _a _x _y _z</Keywords>
<Keywords name="Keywords6">global_</Keywords>
<Keywords name="Keywords7">__command __on_player_jumps __on_player_deploys_elytra __on_player_wakes_up __on_player_rides __on_player_uses_item __on_player_clicks_block __on_player_right_clicks_block __on_player_breaks_block __on_player_interacts_with_entity __on_player_attacks_entity __on_player_starts_sneaking __on_player_stops_sneaking __on_player_starts_sprinting __on_player_stops_sprinting&#x000D;&#x000A;__on_tick&#x000D;&#x000A;__on_tick_ender&#x000D;&#x000A;__on_tick_nether</Keywords>
<Keywords name="Keywords8">$</Keywords>
<Keywords name="Delimiters">00&apos; 01\ 02&apos; 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23</Keywords>
</KeywordLists>
<Styles>
<WordsStyle name="DEFAULT" fgColor="000040" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" />
<WordsStyle name="COMMENTS" fgColor="000000" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" />
<WordsStyle name="LINE COMMENTS" fgColor="C0C0C0" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" />
<WordsStyle name="NUMBERS" fgColor="008040" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" />
<WordsStyle name="KEYWORDS1" fgColor="0000FF" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" />
<WordsStyle name="KEYWORDS2" fgColor="800000" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" />
<WordsStyle name="KEYWORDS3" fgColor="0080C0" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" />
<WordsStyle name="KEYWORDS4" fgColor="400080" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" />
<WordsStyle name="KEYWORDS5" fgColor="FF0080" bgColor="FFFFFF" fontName="" fontStyle="1" nesting="0" />
<WordsStyle name="KEYWORDS6" fgColor="008000" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" />
<WordsStyle name="KEYWORDS7" fgColor="FF8040" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" />
<WordsStyle name="KEYWORDS8" fgColor="DEDEDE" bgColor="FFFFFF" fontName="" fontStyle="1" nesting="0" />
<WordsStyle name="OPERATORS" fgColor="804040" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" />
<WordsStyle name="FOLDER IN CODE1" fgColor="804000" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" />
<WordsStyle name="FOLDER IN CODE2" fgColor="000000" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" />
<WordsStyle name="FOLDER IN COMMENT" fgColor="000000" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" />
<WordsStyle name="DELIMITERS1" fgColor="0080C0" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" />
<WordsStyle name="DELIMITERS2" fgColor="000000" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" />
<WordsStyle name="DELIMITERS3" fgColor="000000" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" />
<WordsStyle name="DELIMITERS4" fgColor="000000" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" />
<WordsStyle name="DELIMITERS5" fgColor="000000" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" />
<WordsStyle name="DELIMITERS6" fgColor="000000" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" />
<WordsStyle name="DELIMITERS7" fgColor="000000" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" />
<WordsStyle name="DELIMITERS8" fgColor="000000" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" />
</Styles>
</UserLang>
</NotepadPlus>
@@ -0,0 +1,64 @@
<NotepadPlus>
<UserLang name="scarpet" ext="sc" udlVersion="2.1">
<Settings>
<Global caseIgnored="yes" allowFoldOfComments="no" foldCompact="no" forcePureLC="0" decimalSeparator="0" />
<Prefix Keywords1="no" Keywords2="no" Keywords3="no" Keywords4="no" Keywords5="no" Keywords6="yes" Keywords7="no" Keywords8="no" />
</Settings>
<KeywordLists>
<Keywords name="Comments">00// 01 02 03 04</Keywords>
<Keywords name="Numbers, prefix1">0x</Keywords>
<Keywords name="Numbers, prefix2"></Keywords>
<Keywords name="Numbers, extras1"></Keywords>
<Keywords name="Numbers, extras2"></Keywords>
<Keywords name="Numbers, suffix1"></Keywords>
<Keywords name="Numbers, suffix2"></Keywords>
<Keywords name="Numbers, range"></Keywords>
<Keywords name="Operators1">; + - * / % ^ &amp;&amp; || &gt; &gt;= &lt; &lt;= == != = += -&gt; &lt;&gt; ! ~ , :</Keywords>
<Keywords name="Operators2"></Keywords>
<Keywords name="Folders in code1, open">(</Keywords>
<Keywords name="Folders in code1, middle"></Keywords>
<Keywords name="Folders in code1, close">)</Keywords>
<Keywords name="Folders in code2, open"></Keywords>
<Keywords name="Folders in code2, middle"></Keywords>
<Keywords name="Folders in code2, close"></Keywords>
<Keywords name="Folders in comment, open"></Keywords>
<Keywords name="Folders in comment, middle"></Keywords>
<Keywords name="Folders in comment, close"></Keywords>
<Keywords name="Keywords1">not fact rand sin cos tan asin acos atan atan2 sinh cosh tanh sec csc sech csch cot acot coth asinh acosh atanh rad deg log log10 log1p sqrt max min abs round floor ceil mandelbrot relu &#x000D;&#x000A;&#x000D;&#x000A;print return exit throw try &#x000D;&#x000A;&#x000D;&#x000A;l join split slice sort sort_key range m keys values pairs&#x000D;&#x000A;&#x000D;&#x000A;get put has delete&#x000D;&#x000A;&#x000D;&#x000A;var undef vars if loop map filter first all for while reduce &#x000D;&#x000A;&#x000D;&#x000A;outer type bool number str length rand sleep time profile_expr lower upper title</Keywords>
<Keywords name="Keywords2">block pos pos_offset solid air liquid flammable transparent opacity blocks_daylight emitted_light light block_light sky_light see_sky hardness blast_resistance top loaded loaded_ep suffocates power ticks_randomly update block_tick random_tick set blocks_movement block_sound material map_colour property block_properties block_data place_item set_biome biome&#x000D;&#x000A;&#x000D;&#x000A;player spawn entity_id entity_list entity_area entity_selector query modify entity_event&#x000D;&#x000A;&#x000D;&#x000A;stack_limit item_category inventory_size inventory_has_items inventory_get inventory_set inventory_find inventory_remove drop_item&#x000D;&#x000A;&#x000D;&#x000A;scan volume neighbours rect diamond &#x000D;&#x000A;&#x000D;&#x000A;logger sound particle particle_line particle_rect run save tick_time game_tick current_dimension in_dimension plop harvest destroy schedule nbt create_marker remove_all_markers load_app_data store_app_data</Keywords>
<Keywords name="Keywords3">euler pi null true false</Keywords>
<Keywords name="Keywords4">x y z p</Keywords>
<Keywords name="Keywords5">_ _i _a _x _y _z</Keywords>
<Keywords name="Keywords6">global_</Keywords>
<Keywords name="Keywords7">__command __config __on_player_jumps __on_player_deploys_elytra __on_player_wakes_up __on_player_rides __on_player_uses_item __on_player_clicks_block __on_player_right_clicks_block __on_player_breaks_block __on_player_interacts_with_entity __on_player_attacks_entity __on_player_starts_sneaking __on_player_stops_sneaking __on_player_starts_sprinting __on_player_stops_sprinting&#x000D;&#x000A;__on_player_releases_item&#x000D;&#x000A;__on_player_finishes_using_item&#x000D;&#x000A;__on_player_drops_item&#x000D;&#x000A;__on_player_drops_stack&#x000D;&#x000A;__on_tick&#x000D;&#x000A;__on_tick_ender&#x000D;&#x000A;__on_tick_nether</Keywords>
<Keywords name="Keywords8">$</Keywords>
<Keywords name="Delimiters">00&apos; 01\ 02&apos; 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23</Keywords>
</KeywordLists>
<Styles>
<WordsStyle name="DEFAULT" fgColor="000040" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" />
<WordsStyle name="COMMENTS" fgColor="000000" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" />
<WordsStyle name="LINE COMMENTS" fgColor="808080" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" />
<WordsStyle name="NUMBERS" fgColor="008040" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" />
<WordsStyle name="KEYWORDS1" fgColor="0000FF" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" />
<WordsStyle name="KEYWORDS2" fgColor="800000" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" />
<WordsStyle name="KEYWORDS3" fgColor="0080C0" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" />
<WordsStyle name="KEYWORDS4" fgColor="400080" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" />
<WordsStyle name="KEYWORDS5" fgColor="FF0080" bgColor="FFFFFF" fontName="" fontStyle="1" nesting="0" />
<WordsStyle name="KEYWORDS6" fgColor="008000" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" />
<WordsStyle name="KEYWORDS7" fgColor="FF8040" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" />
<WordsStyle name="KEYWORDS8" fgColor="DEDEDE" bgColor="FFFFFF" fontName="" fontStyle="1" nesting="0" />
<WordsStyle name="OPERATORS" fgColor="804040" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" />
<WordsStyle name="FOLDER IN CODE1" fgColor="515151" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" />
<WordsStyle name="FOLDER IN CODE2" fgColor="000000" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" />
<WordsStyle name="FOLDER IN COMMENT" fgColor="000000" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" />
<WordsStyle name="DELIMITERS1" fgColor="0080C0" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" />
<WordsStyle name="DELIMITERS2" fgColor="000000" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" />
<WordsStyle name="DELIMITERS3" fgColor="000000" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" />
<WordsStyle name="DELIMITERS4" fgColor="000000" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" />
<WordsStyle name="DELIMITERS5" fgColor="000000" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" />
<WordsStyle name="DELIMITERS6" fgColor="000000" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" />
<WordsStyle name="DELIMITERS7" fgColor="000000" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" />
<WordsStyle name="DELIMITERS8" fgColor="000000" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" />
</Styles>
</UserLang>
</NotepadPlus>
@@ -0,0 +1,64 @@
<NotepadPlus>
<UserLang name="scarpet" ext="sc" udlVersion="2.1">
<Settings>
<Global caseIgnored="yes" allowFoldOfComments="no" foldCompact="no" forcePureLC="0" decimalSeparator="0" />
<Prefix Keywords1="no" Keywords2="no" Keywords3="no" Keywords4="no" Keywords5="no" Keywords6="yes" Keywords7="no" Keywords8="no" />
</Settings>
<KeywordLists>
<Keywords name="Comments">00// 01 02 03 04</Keywords>
<Keywords name="Numbers, prefix1">0x</Keywords>
<Keywords name="Numbers, prefix2"></Keywords>
<Keywords name="Numbers, extras1"></Keywords>
<Keywords name="Numbers, extras2"></Keywords>
<Keywords name="Numbers, suffix1"></Keywords>
<Keywords name="Numbers, suffix2"></Keywords>
<Keywords name="Numbers, range"></Keywords>
<Keywords name="Operators1">; + - * / % ^ &amp;&amp; || &gt; &gt;= &lt; &lt;= == != = += -&gt; &lt;&gt; ! ~ , :</Keywords>
<Keywords name="Operators2"></Keywords>
<Keywords name="Folders in code1, open">(</Keywords>
<Keywords name="Folders in code1, middle"></Keywords>
<Keywords name="Folders in code1, close">)</Keywords>
<Keywords name="Folders in code2, open"></Keywords>
<Keywords name="Folders in code2, middle"></Keywords>
<Keywords name="Folders in code2, close"></Keywords>
<Keywords name="Folders in comment, open"></Keywords>
<Keywords name="Folders in comment, middle"></Keywords>
<Keywords name="Folders in comment, close"></Keywords>
<Keywords name="Keywords1">not fact rand sin cos tan asin acos atan atan2 sinh cosh tanh sec csc sech csch cot acot coth asinh acosh atanh rad deg log log10 log1p sqrt max min abs round floor ceil mandelbrot relu &#x000D;&#x000A;&#x000D;&#x000A;print return exit throw try &#x000D;&#x000A;&#x000D;&#x000A;l join split slice sort sort_key range m keys values pairs copy&#x000D;&#x000A;&#x000D;&#x000A;get put has delete&#x000D;&#x000A;&#x000D;&#x000A;var undef vars if loop map filter first all for while reduce continue break&#x000D;&#x000A;&#x000D;&#x000A;call outer type bool number str length rand sleep time profile_expr lower upper title replace replace_first</Keywords>
<Keywords name="Keywords2">block pos pos_offset solid air liquid flammable transparent opacity blocks_daylight emitted_light light block_light sky_light see_sky hardness blast_resistance top loaded suffocates power ticks_randomly update block_tick random_tick set blocks_movement block_sound material map_colour property block_properties block_data place_item set_biome biome loaded_status generation_status chunk_tickets&#x000D;&#x000A;&#x000D;&#x000A;player spawn entity_id entity_list entity_area entity_selector query modify entity_event&#x000D;&#x000A;&#x000D;&#x000A;stack_limit item_category inventory_size inventory_has_items inventory_get inventory_set inventory_find inventory_remove drop_item&#x000D;&#x000A;&#x000D;&#x000A;scan volume neighbours rect diamond &#x000D;&#x000A;&#x000D;&#x000A;logger sound particle particle_line particle_rect run save tick_time game_tick current_dimension in_dimension plop harvest destroy schedule nbt create_marker remove_all_markers load_app_data store_app_data escape_nbt</Keywords>
<Keywords name="Keywords3">euler pi null true false</Keywords>
<Keywords name="Keywords4">x y z p</Keywords>
<Keywords name="Keywords5">_ _i _a _x _y _z</Keywords>
<Keywords name="Keywords6">global_</Keywords>
<Keywords name="Keywords7">__command __config __on_player_jumps __on_player_deploys_elytra __on_player_wakes_up __on_player_rides __on_player_uses_item __on_player_clicks_block __on_player_right_clicks_block __on_player_breaks_block __on_player_interacts_with_entity __on_player_attacks_entity __on_player_starts_sneaking __on_player_stops_sneaking __on_player_starts_sprinting __on_player_stops_sprinting&#x000D;&#x000A;__on_player_releases_item&#x000D;&#x000A;__on_player_finishes_using_item&#x000D;&#x000A;__on_player_drops_item&#x000D;&#x000A;__on_player_drops_stack&#x000D;&#x000A;__on_tick&#x000D;&#x000A;__on_tick_ender&#x000D;&#x000A;__on_tick_nether</Keywords>
<Keywords name="Keywords8">$</Keywords>
<Keywords name="Delimiters">00&apos; 01\ 02&apos; 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23</Keywords>
</KeywordLists>
<Styles>
<WordsStyle name="DEFAULT" fgColor="000040" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" />
<WordsStyle name="COMMENTS" fgColor="000000" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" />
<WordsStyle name="LINE COMMENTS" fgColor="808080" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" />
<WordsStyle name="NUMBERS" fgColor="008040" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" />
<WordsStyle name="KEYWORDS1" fgColor="0000FF" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" />
<WordsStyle name="KEYWORDS2" fgColor="800000" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" />
<WordsStyle name="KEYWORDS3" fgColor="0080C0" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" />
<WordsStyle name="KEYWORDS4" fgColor="400080" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" />
<WordsStyle name="KEYWORDS5" fgColor="FF0080" bgColor="FFFFFF" fontName="" fontStyle="1" nesting="0" />
<WordsStyle name="KEYWORDS6" fgColor="008000" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" />
<WordsStyle name="KEYWORDS7" fgColor="FF8040" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" />
<WordsStyle name="KEYWORDS8" fgColor="DEDEDE" bgColor="FFFFFF" fontName="" fontStyle="1" nesting="0" />
<WordsStyle name="OPERATORS" fgColor="804040" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" />
<WordsStyle name="FOLDER IN CODE1" fgColor="515151" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" />
<WordsStyle name="FOLDER IN CODE2" fgColor="000000" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" />
<WordsStyle name="FOLDER IN COMMENT" fgColor="000000" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" />
<WordsStyle name="DELIMITERS1" fgColor="0080C0" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" />
<WordsStyle name="DELIMITERS2" fgColor="000000" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" />
<WordsStyle name="DELIMITERS3" fgColor="000000" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" />
<WordsStyle name="DELIMITERS4" fgColor="000000" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" />
<WordsStyle name="DELIMITERS5" fgColor="000000" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" />
<WordsStyle name="DELIMITERS6" fgColor="000000" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" />
<WordsStyle name="DELIMITERS7" fgColor="000000" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" />
<WordsStyle name="DELIMITERS8" fgColor="000000" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" />
</Styles>
</UserLang>
</NotepadPlus>
+2
View File
@@ -0,0 +1,2 @@
cat docs/scarpet/language/Overview.md docs/scarpet/language/VariablesAndConstants.md docs/scarpet/language/Operators.md docs/scarpet/language/Math.md docs/scarpet/language/SystemFunctions.md docs/scarpet/language/LoopsAndHigherOrderFunctions.md docs/scarpet/language/FunctionsAndControlFlow.md docs/scarpet/language/Containers.md docs/scarpet/api/Overview.md docs/scarpet/api/BlocksAndWorldAccess.md docs/scarpet/api/BlockIterations.md docs/scarpet/api/Entities.md docs/scarpet/api/Inventories.md docs/scarpet/api/Events.md docs/scarpet/api/Auxiliary.md docs/scarpet/api/ScriptCommand.md > docs/scarpet/Full.md
@@ -1,14 +1,8 @@
package carpet.commands;
import carpet.CarpetServer;
import carpet.script.CarpetScriptHost;
import carpet.script.*;
import carpet.CarpetSettings;
import carpet.script.CarpetEventServer;
import carpet.script.CarpetExpression;
import carpet.script.Expression;
import carpet.script.ExpressionInspector;
import carpet.script.LazyValue;
import carpet.script.Tokenizer;
import carpet.script.exception.CarpetExpressionException;
import carpet.script.value.FunctionValue;
import carpet.settings.SettingsManager;
@@ -31,11 +25,9 @@ import net.minecraft.util.Clearable;
import net.minecraft.util.math.BlockPos;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.util.math.BlockBox;
import org.apache.commons.lang3.StringUtils;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Locale;
import java.util.*;
import java.util.concurrent.CompletableFuture;
import java.util.function.Predicate;
import java.util.function.Supplier;
@@ -47,6 +39,33 @@ import static net.minecraft.server.command.CommandSource.suggestMatching;
public class ScriptCommand
{
private static TreeSet<String> scarpetFunctions;
private static TreeSet<String> APIFunctions;
static
{
Set<String> allFunctions = (new CarpetExpression(null, "null", null, null)).getExpr().getFunctionNames();
scarpetFunctions = new TreeSet<>(Expression.none.getFunctionNames());
APIFunctions = allFunctions.stream().filter(s -> !scarpetFunctions.contains(s)).collect(Collectors.toCollection(TreeSet::new));
}
public static List<String> suggestFunctions(ScriptHost host, String previous, String prefix)
{
previous = previous.replace("\\'", "");
int quoteCount = StringUtils.countMatches(previous,'\'');
if (quoteCount % 2 == 1)
return Collections.emptyList();
int maxLen = prefix.length()<3 ? (prefix.length()*2+1) : 1234;
List<String> scarpetMatches = scarpetFunctions.stream().
filter(s -> s.startsWith(prefix) && s.length() <= maxLen).map(s -> s+"(").collect(Collectors.toList());
scarpetMatches.addAll(APIFunctions.stream().
filter(s -> s.startsWith(prefix) && s.length() <= maxLen).map(s -> s+"(").collect(Collectors.toList()));
// not that useful in commandline, more so in external scripts, so skipping here
//scarpetMatches.addAll(CarpetServer.scriptServer.events.eventHandlers.keySet().stream().
// filter(s -> s.startsWith(prefix) && s.length() <= maxLen).map(s -> "__"+s+"(").collect(Collectors.toList()));
scarpetMatches.addAll(host.globaFunctionNames(host.main, s -> s.startsWith(prefix)).map(s -> s+"(").collect(Collectors.toList()));
scarpetMatches.addAll(host.globaVariableNames(host.main, s -> s.startsWith(prefix)).collect(Collectors.toList()));
return scarpetMatches;
}
private static CompletableFuture<Suggestions> suggestCode(
CommandContext<ServerCommandSource> context,
@@ -66,7 +85,7 @@ public class ScriptCommand
return suggestionsBuilder.buildFuture();
String prefix = lastToken.reverse().toString();
String previousString = previous.substring(0,previous.length()-prefix.length()) ;
ExpressionInspector.suggestFunctions(currentHost, previousString, prefix).forEach(text -> suggestionsBuilder.suggest(previousString+text));
suggestFunctions(currentHost, previousString, prefix).forEach(text -> suggestionsBuilder.suggest(previousString+text));
return suggestionsBuilder.buildFuture();
}
@@ -333,7 +352,7 @@ public class ScriptCommand
}
Expression expr = fun.getExpression();
Tokenizer.Token tok = fun.getToken();
List<String> snippet = ExpressionInspector.Expression_getExpressionSnippet(tok, expr);
List<String> snippet = expr.getExpressionSnippet(tok);
Messenger.m(source, "wb "+fun.fullName(),"t defined at: line "+(tok.lineno+1)+" pos "+(tok.linepos+1));
for (String snippetLine: snippet)
{
@@ -1,7 +1,7 @@
package carpet.mixins;
import carpet.CarpetServer;
import carpet.script.ExpressionInspector;
import carpet.script.CarpetExpression;
import carpet.CarpetSettings;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.LivingEntity;
@@ -32,9 +32,9 @@ public abstract class ArmorStandEntity_scarpetMarkerMixin extends LivingEntity
{
if ((CarpetSettings.scriptsAutoload || !CarpetSettings.commandScript.equals("false")) && !world.isClient)
{
if (getScoreboardTags().contains(ExpressionInspector.MARKER_STRING))
if (getScoreboardTags().contains(CarpetExpression.MARKER_STRING))
{
String prefix = ExpressionInspector.MARKER_STRING+"_";
String prefix = CarpetExpression.MARKER_STRING+"_";
Optional<String> owner = getScoreboardTags().stream().filter(s -> s.startsWith(prefix)).findFirst();
if (owner.isPresent())
{
@@ -139,10 +139,11 @@ public class CarpetExpression
private final ServerCommandSource source;
private final BlockPos origin;
private final Expression expr;
Expression getExpr() {return expr;}
public Expression getExpr() {return expr;}
private static long tickStart = 0L;
// dummy entity for dummy requirements in the loot tables (see snowball)
private static FallingBlockEntity DUMMY_ENTITY = new FallingBlockEntity(EntityType.FALLING_BLOCK, null);
public static final String MARKER_STRING = "__scarpet_marker";
private static boolean stopAll = false;
@@ -2377,8 +2378,8 @@ public class CarpetExpression
(float)pointLocator.yaw,
(float) pointLocator.pitch
);
armorstand.addScoreboardTag(ExpressionInspector.MARKER_STRING+"_"+((cc.host.getName()==null)?"":cc.host.getName()));
armorstand.addScoreboardTag(ExpressionInspector.MARKER_STRING);
armorstand.addScoreboardTag(MARKER_STRING+"_"+((cc.host.getName()==null)?"":cc.host.getName()));
armorstand.addScoreboardTag(MARKER_STRING);
if (targetBlock != null)
armorstand.equipStack(EquipmentSlot.HEAD, new ItemStack(targetBlock.getBlock().asItem()));
if (!name.isEmpty())
@@ -2399,7 +2400,7 @@ public class CarpetExpression
this.expr.addLazyFunction("remove_all_markers", 0, (c, t, lv) -> {
CarpetContext cc = (CarpetContext)c;
int total = 0;
String markerName = ExpressionInspector.MARKER_STRING+"_"+((cc.host.getName()==null)?"":cc.host.getName());
String markerName = MARKER_STRING+"_"+((cc.host.getName()==null)?"":cc.host.getName());
for (Entity e : cc.s.getWorld().getEntities(EntityType.ARMOR_STAND, (as) -> as.getScoreboardTags().contains(markerName)))
{
total ++;
@@ -346,7 +346,7 @@ public class CarpetScriptHost extends ScriptHost
}
});
String markerName = ExpressionInspector.MARKER_STRING+"_"+((getName()==null)?"":getName());
String markerName = CarpetExpression.MARKER_STRING+"_"+((getName()==null)?"":getName());
for (ServerWorld world : CarpetServer.minecraft_server.getWorlds())
{
for (Entity e : world.getEntities(EntityType.ARMOR_STAND, (as) -> as.getScoreboardTags().contains(markerName)))
+10 -4
View File
@@ -99,6 +99,12 @@ public class Expression
public Module module = null;
public String getModuleName()
{
return module == null?null:module.getName();
}
void asATextSource()
{
allowNewlineSubstitutions = false;
@@ -119,11 +125,11 @@ public class Expression
boolean isAnOperator(String opname) { return operators.containsKey(opname) || operators.containsKey(opname+"u");}
private final Map<String, ILazyFunction> functions = new Object2ObjectOpenHashMap<>();
Set<String> getFunctionNames() {return functions.keySet();}
public Set<String> getFunctionNames() {return functions.keySet();}
static List<String> getExpressionSnippet(Tokenizer.Token token, Expression expr)
public List<String> getExpressionSnippet(Tokenizer.Token token)
{
String code = expr.getCodeString();
String code = this.getCodeString();
List<String> output = new ArrayList<>();
for (String line: getExpressionSnippetLeftContext(token, code, 1))
{
@@ -1949,7 +1955,7 @@ public class Expression
return var;
}
static final Expression none = new Expression("null");
public static final Expression none = new Expression("null");
/**
* @param expression .
*/
@@ -1,55 +0,0 @@
package carpet.script;
import org.apache.commons.lang3.StringUtils;
import java.util.Collections;
import java.util.List;
import java.util.Set;
import java.util.TreeSet;
import java.util.stream.Collectors;
/**
* sole purpose of this package is to provide public access to package-private methods of Expression and CarpetExpression
* classes so they don't leave garbage in javadocs
*/
public class ExpressionInspector
{
public static final String MARKER_STRING = "__scarpet_marker";
public static List<String> Expression_getExpressionSnippet(Tokenizer.Token token, Expression expr)
{
return Expression.getExpressionSnippet(token, expr);
}
public static String Expression_getModuleName(Expression e)
{
return e.module == null?null:e.module.getName();
}
private static TreeSet<String> scarpetFunctions;
private static TreeSet<String> APIFunctions;
static
{
Set<String> allFunctions = (new CarpetExpression(null, "null", null, null)).getExpr().getFunctionNames();
scarpetFunctions = new TreeSet<>(Expression.none.getFunctionNames());
APIFunctions = allFunctions.stream().filter(s -> !scarpetFunctions.contains(s)).collect(Collectors.toCollection(TreeSet::new));
}
public static List<String> suggestFunctions(ScriptHost host, String previous, String prefix)
{
previous = previous.replace("\\'", "");
int quoteCount = StringUtils.countMatches(previous,'\'');
if (quoteCount % 2 == 1)
return Collections.emptyList();
int maxLen = prefix.length()<3 ? (prefix.length()*2+1) : 1234;
List<String> scarpetMatches = scarpetFunctions.stream().
filter(s -> s.startsWith(prefix) && s.length() <= maxLen).map(s -> s+"(").collect(Collectors.toList());
scarpetMatches.addAll(APIFunctions.stream().
filter(s -> s.startsWith(prefix) && s.length() <= maxLen).map(s -> s+"(").collect(Collectors.toList()));
// not that useful in commandline, more so in external scripts, so skipping here
//scarpetMatches.addAll(CarpetServer.scriptServer.events.eventHandlers.keySet().stream().
// filter(s -> s.startsWith(prefix) && s.length() <= maxLen).map(s -> "__"+s+"(").collect(Collectors.toList()));
scarpetMatches.addAll(host.globaFunctionNames(host.main, s -> s.startsWith(prefix)).map(s -> s+"(").collect(Collectors.toList()));
scarpetMatches.addAll(host.globaVariableNames(host.main, s -> s.startsWith(prefix)).collect(Collectors.toList()));
return scarpetMatches;
}
}
@@ -9,9 +9,6 @@ import carpet.script.value.FunctionValue;
import java.util.ArrayList;
import java.util.List;
import static carpet.script.ExpressionInspector.Expression_getExpressionSnippet;
import static carpet.script.ExpressionInspector.Expression_getModuleName;
/* The expression evaluators exception class. */
public class ExpressionException extends RuntimeException implements ResolvedException
{
@@ -40,10 +37,10 @@ public class ExpressionException extends RuntimeException implements ResolvedExc
{
List<String> errMsg = new ArrayList<>();
errmessage += Expression_getModuleName(expr) == null?"":(" in "+Expression_getModuleName(expr));
errmessage += expr.getModuleName() == null?"":(" in "+expr.getModuleName());
if (token != null)
{
List<String> snippet = Expression_getExpressionSnippet(token, expr);
List<String> snippet = expr.getExpressionSnippet(token);
errMsg.addAll(snippet);
if (snippet.size() != 1)
@@ -113,7 +113,7 @@ public class ListValue extends AbstractListValue implements ContainerValueInterf
}
else
{
throw new InternalExpressionException("Cannot subtract two lists of uneven sizes");
throw new InternalExpressionException("Cannot add two lists of uneven sizes");
}
}
else
@@ -178,7 +178,7 @@ public class ListValue extends AbstractListValue implements ContainerValueInterf
}
else
{
throw new InternalExpressionException("Cannot subtract two lists of uneven sizes");
throw new InternalExpressionException("Cannot multiply two lists of uneven sizes");
}
}
else
@@ -205,7 +205,7 @@ public class ListValue extends AbstractListValue implements ContainerValueInterf
}
else
{
throw new InternalExpressionException("Cannot subtract two lists of uneven sizes");
throw new InternalExpressionException("Cannot divide two lists of uneven sizes");
}
}
else