Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def performSelector():
- worlds = sender world if has any of r/rm/x/y/z/dx/dy/dz else all worlds (overworld, nether and end order)
- list = []
- for world in worlds:
- registerPredicates()
- if @s:
- return @s if still match, nothing otherwise
- else:
- list += performPredicateMatching() #in world
- return getResult(list)
- def registerPredicates():
- #all the predicate registry is pretty straight forward, but there is some special cases:
- if type= is unspecified, add a type=player predicate for @a and @p
- xp predicate only registered if at least one of l/lm is specified, and (l > -1 or lm > -1) default to -1 if unspecified
- xp/gamemode predicate only apply to EntityPlayerMP
- team predicate only apply to EntityLivingBase
- 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
- rx/rxm predicate only register if at least one of rx/rxm is specified, rx default to 0 and rxm default to 359
- same for ry/rym
- #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
- def performPredicateMatching():
- if has dx/dy/dz:
- if @a @p (or @r with no type=):
- loop all alive players with a dx/dy/dz predicate (so no chunk scan)
- else:
- scan all alive entities in dx/dy/dz bounding Box
- else:
- if r >= 0 (when r is unspecified, r = -1):
- if @a @p (or @r with no type=):
- loop all alive players
- else:
- scan all alive entities in r= bounding Box
- else if @a:
- loop all players (here is the only case where dead players can be selected)
- else if @p (or @r with no type=):
- loop all alive players
- else:
- #it should only be @e and @r[type=] or @r[type=!]
- loop all entities
- def getResult(list):
- if @r:
- shuffle list in O(n)
- else:
- distance sort list in O(n*log(n))
- #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
- if sender in list and c==1 and not @r:
- return sender
- if c == 0:
- return list
- if c < 0:
- reverse list in O(n)
- truncate list by only keeping his c first elements
- return list
Advertisement
Add Comment
Please, Sign In to add comment