<s> """<STR_LIT>""" <EOL> import collections <EOL> import logging <EOL> import math <EOL> from spockbot . mcdata import blocks , constants as const <EOL> from spockbot . mcdata . utils import BoundingBox <EOL> from spockbot . plugins . base import PluginBase , pl_announce <EOL> from spockbot . plugins . tools import collision <EOL> from spockbot . vector import Vector3 <EOL> logger = logging . getLogger ( '<STR_LIT>' ) <EOL> FP_MAGIC = <NUM_LIT> <EOL> class PhysicsCore ( object ) : <EOL> def __init__ ( self , pos , vec , abilities ) : <EOL> self . pos = pos <EOL> self . vec = vec <EOL> self . sprinting = False <EOL> self . move_accel = abilities . walking_speed <EOL> self . abilities = abilities <EOL> self . direction = Vector3 ( ) <EOL> def jump ( self ) : <EOL> if self . pos . on_ground : <EOL> if self . sprinting : <EOL> ground_speed = Vector3 ( self . vec . x , <NUM_LIT:0> , self . vec . z ) <EOL> if ground_speed : <EOL> self . vec += ground_speed . norm ( ) * const . PHY_JMP_MUL <EOL> self . vec . y = const . PHY_JMP_ABS <EOL> def walk ( self ) : <EOL> self . sprinting = False <EOL> self . move_accel = self . abilities . walking_speed <EOL> def sprint ( self ) : <EOL> self . sprinting = True <EOL> self . move_accel = self . abilities . walking_speed * const . PHY_SPR_MUL <EOL> def move_target ( self , vector ) : <EOL> self . direction = vector - self . pos <EOL> self . direction . y = <NUM_LIT:0> <EOL> if self . direction <= Vector3 ( self . vec . x , <NUM_LIT:0> , self . vec . z ) : <EOL> return True <EOL> def move_vector ( self , vector ) : <EOL> vector . y = <NUM_LIT:0> <EOL> self . direction = vector <EOL> def move_angle ( self , angle , radians = False ) : <EOL> angle = angle if radians else math . radians ( angle ) <EOL> self . direction = Vector3 ( math . sin ( angle ) , <NUM_LIT:0> , math . cos ( angle ) ) <EOL> @ pl_announce ( '<STR_LIT>' ) <EOL> class PhysicsPlugin ( PluginBase ) : <EOL> requires = ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> events = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } <EOL> def __init__ ( self , ploader , settings ) : <EOL> super ( PhysicsPlugin , self ) . __init__ ( ploader , settings ) <EOL> self . vec = Vector3 ( <NUM_LIT:0.0> , <NUM_LIT:0.0> , <NUM_LIT:0.0> ) <EOL> self . col = collision . MTVTest ( <EOL> self . world , BoundingBox ( const . PLAYER_WIDTH , const . PLAYER_HEIGHT ) <EOL> ) <EOL> self . pos = self . clientinfo . position <EOL> self . skip_tick = False <EOL> self . pc = PhysicsCore ( self . pos , self . vec , self . clientinfo . abilities ) <EOL> ploader . provides ( '<STR_LIT>' , self . pc ) <EOL> def skip_physics ( self , _ = None , __ = None ) : <EOL> self . vec . zero ( ) <EOL> self . skip_tick = True <EOL> def suspend_physics ( self , _ = None , __ = None ) : <EOL> self . vec . zero ( ) <EOL> self . event . unreg_event_handler ( '<STR_LIT>' , self . physics_tick ) <EOL> def resume_physics ( self , _ = None , __ = None ) : <EOL> self . event . reg_event_handler ( '<STR_LIT>' , self . physics_tick ) <EOL> def client_tick ( self , name , data ) : <EOL> self . net . push_packet ( '<STR_LIT>' , <EOL> self . clientinfo . position . get_dict ( ) ) <EOL> def physics_tick ( self , _ , __ ) : <EOL> if self . skip_tick : <EOL> self . skip_tick = False <EOL> return <EOL> self . apply_accel ( ) <EOL> mtv = self . get_mtv ( ) <EOL> self . apply_vector ( mtv ) <EOL> self . pos . on_ground = mtv . y > <NUM_LIT:0> <EOL> self . vec -= Vector3 ( <NUM_LIT:0> , const . PHY_GAV_ACC , <NUM_LIT:0> ) <EOL> self . apply_drag ( ) <EOL> self . pc . direction = Vector3 ( ) <EOL> def get_block_slip ( self ) : <EOL> if self . pos . on_ground : <EOL> bpos = self . pos . floor ( ) <EOL> return blocks . get_block ( * self . world . get_block ( * bpos ) ) . slipperiness <EOL> return <NUM_LIT:1> <EOL> def apply_accel ( self ) : <EOL> if not self . pc . direction : <EOL> return <EOL> if self . pos . on_ground : <EOL> block_slip = self . get_block_slip ( ) <EOL> accel_mod = const . BASE_GND_SLIP ** <NUM_LIT:3> / block_slip ** <NUM_LIT:3> <EOL> accel = self . pc . move_accel * accel_mod * const . PHY_BASE_DRG <EOL> else : <EOL> accel = const . PHY_JMP_ACC <EOL> self . vec += self . pc . direction . norm ( ) * accel <EOL> def apply_vector ( self , mtv ) : <EOL> self . pos += ( self . vec + mtv ) <EOL> self . vec . x = <NUM_LIT:0> if mtv . x else self . vec . x <EOL> self . vec . y = <NUM_LIT:0> if mtv . y else self . vec . y <EOL> self . vec . z = <NUM_LIT:0> if mtv . z else self . vec . z <EOL> def apply_drag ( self ) : <EOL> drag = self . get_block_slip ( ) * const . PHY_DRG_MUL <EOL> self . vec . x *= drag <EOL> self . vec . z *= drag <EOL> self . vec . y *= const . PHY_BASE_DRG <EOL> def get_mtv ( self ) : <EOL> pos = self . pos + self . vec <EOL> pos = collision . uncenter_position ( pos , self . col . bbox ) <EOL> q = collections . deque ( ( Vector3 ( ) , ) ) <EOL> while q : <EOL> current_vector = q . popleft ( ) <EOL> transform_vectors = self . col . check_collision ( pos , current_vector ) <EOL> if not all ( transform_vectors ) : <EOL> break <EOL> for vector in transform_vectors : <EOL> test_vec = self . vec + current_vector + vector <EOL> if test_vec . dist_sq ( ) <= self . vec . dist_sq ( ) + FP_MAGIC : <EOL> q . append ( current_vector + vector ) <EOL> else : <EOL> logger . debug ( '<STR_LIT>' ) <EOL> self . vec . zero ( ) <EOL> return Vector3 ( ) <EOL> possible_mtv = [ current_vector ] <EOL> while q : <EOL> current_vector = q . popleft ( ) <EOL> transform_vectors = self . col . check_collision ( pos , current_vector ) <EOL> if not all ( transform_vectors ) : <EOL> possible_mtv . append ( current_vector ) <EOL> return min ( possible_mtv ) </s>
