Mrpingouin

Selector simplified pseudo code

Aug 4th, 2017
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.50 KB | None | 0 0
  1. def performSelector():
  2.     worlds = sender world if has any of r/rm/x/y/z/dx/dy/dz else all worlds (overworld, nether and end order)
  3.     list = []
  4.    
  5.     for world in worlds:
  6.         registerPredicates()
  7.         if @s:
  8.             return @s if still match, nothing otherwise
  9.         else:
  10.             list += performPredicateMatching() #in world
  11.     return getResult(list)
  12.  
  13.    
  14.    
  15. def registerPredicates():
  16.     #all the predicate registry is pretty straight forward, but there is some special cases:
  17.  
  18.     if type= is unspecified, add a type=player predicate for @a and @p
  19.     xp predicate only registered if at least one of l/lm is specified, and (l > -1 or lm > -1) default to -1 if unspecified
  20.     xp/gamemode predicate only apply to EntityPlayerMP
  21.     team predicate only apply to EntityLivingBase
  22.     radius predicate only register if at least one of r/rm is specified, and (r >= -0.5 or rm >= 0.5) default to -1 if unspecified
  23.     rx/rxm predicate only register if at least one of rx/rxm is specified, rx default to 0 and rxm default to 359
  24.     same for ry/rym
  25.    
  26.    
  27. #This method will apply the predicates in type/xp/gamemode/team/score/name/tag/radius/rotation order to all the entities it loop/scan and returns only the matching ones
  28. def performPredicateMatching():
  29.     if has dx/dy/dz:
  30.         if @a @p (or @r with no type=):
  31.             loop all alive players with a dx/dy/dz predicate (so no chunk scan)
  32.         else:
  33.             scan all alive entities in dx/dy/dz bounding Box
  34.  
  35.     else:
  36.         if r >= 0 (when r is unspecified, r = -1):
  37.             if @a @p (or @r with no type=):
  38.                 loop all alive players
  39.             else:
  40.                 scan all alive entities in r= bounding Box
  41.         else if @a:
  42.             loop all players (here is the only case where dead players can be selected)
  43.         else if @p (or @r with no type=):
  44.             loop all alive players
  45.         else:
  46.             #it should only be @e and @r[type=] or @r[type=!]
  47.             loop all entities
  48.            
  49.  
  50. def getResult(list):
  51.     if @r:
  52.         shuffle list in O(n)
  53.     else:
  54.         distance sort list in O(n*log(n))
  55.    
  56.     #the c get his value from the specified argument, if c is unspecified, it will be 0 for @a/@e and 1 for @p/@r
  57.    
  58.     if sender in list and c==1 and not @r:
  59.         return sender
  60.    
  61.     if c == 0:
  62.         return list
  63.     if c < 0:
  64.         reverse list in O(n)
  65.    
  66.     truncate list by only keeping his c first elements
  67.     return list
Advertisement
Add Comment
Please, Sign In to add comment