1+ """Basic Commands and Instructions"""
2+
13from ._core import Insn , SingleCommandInsn , ConstructorInsn , BasicBlock
24from ..core_types import (CmdFunction ,
35 Opt ,
2022import commands as c
2123
2224class RunCommand (SingleCommandInsn ):
25+ """Runs the command given in the command variable."""
2326
2427 args = [CmdFunction ]
2528 argnames = 'cmd'
29+ argdocs = ["The command variable" ]
2630 insn_name = 'run_cmd'
2731 is_branch = True
2832
@@ -38,9 +42,13 @@ def as_cmd(self):
3842 return self .var .read ()
3943
4044class Getter (ConstructorInsn ):
45+ """Returns a command variable that when run, gives the variable's value
46+ in the 'result' of the command's execution."""
4147
4248 args = [Variable ]
4349 argnames = 'var'
50+ argdocs = ["The variable to create the getter for" ]
51+ rettype = CmdFunction
4452 insn_name = 'getter'
4553
4654 def construct (self ):
@@ -63,9 +71,14 @@ def as_cmd(self):
6371 return insn .as_single_cmd ()
6472
6573class AsSingleCmdInsn (ConstructorInsn ):
74+ """Forces a basic block to become a single command, the command is returned
75+ as a command variable. An error is raised if the block cannot be a single
76+ command."""
6677
6778 args = [BasicBlock ]
6879 argnames = 'block'
80+ argdocs = ["The basic block" ]
81+ rettype = CmdFunction
6982 insn_name = 'as_single_cmd'
7083
7184 def construct (self ):
@@ -76,75 +89,98 @@ def declare(self):
7689 pass #self.block.usage()
7790
7891class SetBlockInsn (SingleCommandInsn ):
92+ """Sets a block in the world at the given position to the given block
93+ type."""
7994
8095 args = [Position , BlockType ]
8196 argnames = 'pos block'
97+ argdocs = ["The block position" , "The block type" ]
8298 insn_name = 'setblock'
8399
84100 def get_cmd (self ):
85101 return c .Setblock (self .pos .as_blockpos (), self .block )
86102
87103class ReplaceEntityItem (SingleCommandInsn ):
104+ """Replaces an item in an entity's inventory at a specified slot with the
105+ given item. See `/replaceitem` for details."""
88106
89107 args = [EntitySelection , VirtualString , ItemType , Opt (int )]
90108 argnames = 'target slot item amount'
109+ argdocs = ["Target entities to replace their items" , "Inventory slot" ,
110+ "Replacement item" , "Replace amount" ]
91111 insn_name = 'replace_entity_item'
92112
93113 def get_cmd (self ):
94114 return c .ReplaceItem (self .target .as_resolve ().ref , str (self .slot ),
95115 self .item , self .amount )
96116
97117class ReplaceBlockItem (SingleCommandInsn ):
118+ """Replaces an item in a block's inventory at a specified slot with the
119+ given item. See `/replaceitem` for details."""
98120
99121 args = [Position , VirtualString , ItemType , Opt (int )]
100122 argnames = 'pos slot item amount'
123+ argdocs = ["Block position" , "Inventory slot" , "Replacement item" ,
124+ "Replace amount" ]
101125 insn_name = 'replace_block_item'
102126
103127 def get_cmd (self ):
104128 return c .ReplaceItem (self .pos .as_blockpos ().ref , str (self .slot ),
105129 self .item , self .amount )
106130
107131class GiveInsn (SingleCommandInsn ):
132+ """Gives targetted entities an item."""
108133
109134 args = [EntitySelection , ItemType , int ]
110135 argnames = 'targets item count'
136+ argdocs = ["Entities to give the item to" , "The item to give" , "Item count" ]
111137 insn_name = 'give'
112138
113139 def get_cmd (self ):
114140 return c .GiveItem (self .targets .as_resolve (), self .item , self .count )
115141
116142class ClearInsn (SingleCommandInsn ):
143+ """Clears items matching the given item type from targetted entities."""
117144
118145 args = [EntitySelection , ItemType , int ]
119146 argnames = 'targets item max_count'
147+ argdocs = ["Entities to clear the item from" , "Item to clear" ,
148+ "Max count of items. -1 to clear all matching items." ]
120149 insn_name = 'clear'
121150
122151 def get_cmd (self ):
123152 return c .ClearItem (self .targets .as_resolve (), self .item , self .max_count )
124153
125154class TeleportInsn (SingleCommandInsn ):
155+ """Moves target entities to a specified position."""
126156
127157 args = [EntitySelection , Position ]
128158 argnames = 'target pos'
159+ argdocs = ["Entities to move" , "Position to move to" ]
129160 insn_name = 'teleport'
130161
131162 def get_cmd (self ):
132163 return c .Teleport (self .target .as_resolve (), self .pos .as_worldpos ())
133164
134165class MoveToEntityInsn (SingleCommandInsn ):
166+ """Moves entities to another target entity."""
135167
136168 # Should be EntityRef
137169 args = [EntitySelection , EntitySelection ]
138170 argnames = 'sources target'
171+ argdocs = ["Entities to move" , "Destination entity" ]
139172 insn_name = 'move_to_entity'
140173
141174 def get_cmd (self ):
142175 return c .Teleport (self .sources .as_resolve (), self .target .as_resolve ())
143176
144177class TeleportWithRotInsn (SingleCommandInsn ):
178+ """Moves entities to the given position with a specific rotation."""
145179
146180 args = [EntitySelection , Position , PosType , PosType ]
147181 argnames = 'target pos yrot xrot'
182+ argdocs = ["Entities to move" , "Position to move to" , "y rotation" ,
183+ "x rotation" ]
148184 insn_name = 'tp_with_rot'
149185
150186 def get_cmd (self ):
@@ -159,19 +195,27 @@ def _to_resolve(self, arg):
159195 else str (arg ))
160196
161197class CloneInsn (SingleCommandInsn ):
198+ """Clones a region of blocks specified by a lower left and upper right
199+ bound to a given destination position."""
162200
163201 args = [Position , Position , Position ]
164202 argnames = 'src0 src1 dest'
203+ argdocs = ["Lower left position" , "Upper right position" ,
204+ "Destination position" ]
165205 insn_name = 'clone'
166206
167207 def get_cmd (self ):
168208 return c .Clone (self .src0 .as_blockpos (), self .src1 .as_blockpos (),
169209 self .dest .as_blockpos ())
170210
171211class GiveEntityEffectInsn (SingleCommandInsn ):
212+ """Gives target entities the specified effect. See `/effect` for details."""
172213
173214 args = [EntitySelection , VirtualString , Opt (int ), Opt (int ), Opt (str )]
174215 argnames = 'target effect seconds amp hide_particles'
216+ argdocs = ["Entities to give the effect to" , "The effect name" ,
217+ "Number of seconds the effect will last" , "Amplifier" ,
218+ "Whether to hide particles (true|false)" ]
175219 insn_name = 'give_effect'
176220
177221 def activate (self , seq ):
@@ -183,20 +227,28 @@ def get_cmd(self):
183227 self .seconds , self .amp , self .hide_particles == 'true' )
184228
185229class SpawnEntityInsn (SingleCommandInsn ):
230+ """Spawns an entity of the given type at a position."""
186231
187232 args = [VirtualString , Opt (Position ), Opt (NBTCompound )]
188233 argnames = 'entity pos data'
234+ argdocs = ["Entity type name" , "Position. Defaults to the location of the" \
235+ + " sender" , "Optional NBT data for the entity" ]
189236 insn_name = 'spawn_entity'
190237
191238 def get_cmd (self ):
192239 return c .Summon (str (self .entity ), self .pos .as_worldpos () \
193240 if self .pos else None , self .data )
194241
195242class SpawnParticleInsn (SingleCommandInsn ):
243+ """Spawn particle effects with the given parameters. See `/particle`
244+ for details."""
196245
197246 args = [VirtualString , Position , Position , float , int , str ,
198247 Opt (EntitySelection )]
199248 argnames = 'name pos delta speed count mode targets'
249+ argdocs = ["Particle name" , "Position to spawn at" , "Volume to spawn in" ,
250+ "Speed of the particle" , "Number of particles" , "Display " \
251+ + "mode (normal|force)" , "Players to show the particles to" ]
200252 insn_name = 'spawn_particle'
201253
202254 def activate (self , seq ):
@@ -208,9 +260,12 @@ def get_cmd(self):
208260 self .count , self .mode , self .targets )
209261
210262class TitleInsn (Insn ):
263+ """Show a title text to the specified players."""
211264
212265 args = [EntitySelection , str , Opt (TextObject )]
213266 argnames = 'player action text'
267+ argdocs = ["Players to show to" , "'clear' or 'reset', " \
268+ + "otherwise title|subtitle|actionbar" , "Text to show" ]
214269 insn_name = 'title'
215270
216271 def activate (self , seq ):
@@ -227,76 +282,95 @@ def apply(self, out, func):
227282 return c .Title (self .player .as_resolve (), self .action , * args )
228283
229284class SetTitleTimes (SingleCommandInsn ):
285+ """Sets the timer parameters for a title being shown to the player."""
230286
231287 args = [EntitySelection , int , int , int ]
232288 argnames = 'player fade_in stay fade_out'
289+ argdocs = ["Players to set the times on" , "Title fade in time" , "Title " + \
290+ "stay time" , "Title fade out time" ]
233291 insn_name = 'set_title_times'
234292
235293 def get_cmd (self ):
236294 return c .Title (self .player .as_resolve (), 'times' , str (self .fade_in ),
237295 str (self .stay ), str (self .fade_out ))
238296
239297class JoinTeamInsn (SingleCommandInsn ):
298+ """Adds the specified entities to the given team."""
240299
241300 args = [TeamRef , Opt (EntitySelection )]
242301 argnames = 'team members'
302+ argdocs = ["The team to join" , "Members joining the team. If NULL then " + \
303+ "the current command sender is added." ]
243304 insn_name = 'join_team'
244305
245306 def get_cmd (self ):
246307 return c .JoinTeam (self .team .ref , self .members .as_resolve () \
247308 if self .members else None )
248309
249310class TeamColorInsn (SingleCommandInsn ):
311+ """Sets the color for a team."""
250312
251313 args = [TeamRef , TextColor ]
252314 argnames = 'team color'
315+ argdocs = ["Team to modify" , "Color of the team" ]
253316 insn_name = 'team_color'
254317
255318 def get_cmd (self ):
256319 return c .TeamModify (self .team .ref , 'color' , self .color .name )
257320
258321class TeamCollisionInsn (SingleCommandInsn ):
322+ """Sets the collision behavious for a given team."""
259323
260324 args = [TeamRef , str ]
261325 argnames = 'team behaviour'
326+ argdocs = ["Team to modify" , "Collision behaviour" ]
262327 insn_name = 'team_collision'
263328
264329 def get_cmd (self ):
265330 return c .TeamModify (self .team .ref , 'collisionRule' , self .behaviour )
266331
267332class BarMaxInsn (SingleCommandInsn ):
333+ """Sets the maximum value for a bossbar."""
268334
269335 args = [BossbarRef , int ]
270336 argnames = 'bar max'
337+ argdocs = ["Bar to modify" , "Max value" ]
271338 insn_name = 'bar_set_max'
272339
273340 def get_cmd (self ):
274341 return c .BossbarSet (self .bar .ref , 'max' , c .SimpleResolve (str (self .max )))
275342
276343class BarSetPlayers (SingleCommandInsn ):
344+ """Set the players who can see the bossbar."""
277345
278346 args = [BossbarRef , Opt (EntitySelection )]
279347 argnames = 'bar players'
348+ argdocs = ["Bossbar" , "Players. If NULL then no players will be shown " \
349+ + "the bar" ]
280350 insn_name = 'bar_set_players'
281351
282352 def get_cmd (self ):
283353 return c .BossbarSet (self .bar .ref , 'players' , None if not self .players \
284354 else self .players .as_resolve ())
285355
286356class BarSetValue (SingleCommandInsn ):
357+ """Sets the current value of the given bossbar."""
287358
288359 args = [BossbarRef , int ]
289360 argnames = 'bar val'
361+ argdocs = ["Bossbar to modify" , "Bar value" ]
290362 insn_name = 'bar_set_value'
291363
292364 def get_cmd (self ):
293365 return c .BossbarSet (self .bar .ref , 'value' ,
294366 c .SimpleResolve (str (self .val )))
295367
296368class KillInsn (SingleCommandInsn ):
369+ """Despawns the target entities from the world."""
297370
298371 args = [EntitySelection ]
299372 argnames = 'target'
373+ argdocs = ["Entities to despawn" ]
300374 insn_name = 'kill'
301375
302376 def get_cmd (self ):
0 commit comments