@@ -79,6 +79,7 @@ class PlayerLocalController extends EntityController {
79
79
pm . addEventListener ( "pause=>play" , this [ "pause=>play" ] ) ;
80
80
pm . addEventListener ( "play=>pause" , this [ "play=>pause" ] ) ;
81
81
} ;
82
+ // 转换成键盘消息 复用键盘的处理逻辑
82
83
setMoveBtns ( moveBtns = null ) {
83
84
if ( this . moveBtns ) {
84
85
for ( let btn of "up,left,down,right,jump,upleft,upright,flyup,flydown,fly,sneak" . split ( "," ) ) {
@@ -133,6 +134,17 @@ class PlayerLocalController extends EntityController {
133
134
if ( type in this ) this [ type ] ( event ) ;
134
135
this . dispatchEvent ( type , event ) ;
135
136
} ;
137
+ getHitting ( bType = Block . renderType . NORMAL ) {
138
+ let entity = this . entity ,
139
+ world = entity . world ,
140
+ start = entity . getEyePosition ( ) ,
141
+ end = entity . getDirection ( 20 ) ;
142
+ vec3 . add ( start , end , end ) ;
143
+ return world . rayTraceBlock ( start , end , ( x , y , z ) => {
144
+ let b = world . getBlock ( x , y , z ) ;
145
+ return b && b . name !== "air" && b . renderType === bType ;
146
+ } ) ;
147
+ } ;
136
148
_setEntityPitchAndYaw ( movementX , movementY ) {
137
149
let i = this . mousemoveSensitivity * ( Math . PI / 180 ) ;
138
150
// movementX left- right+ movementY up- down+
@@ -159,15 +171,7 @@ class PlayerLocalController extends EntityController {
159
171
if ( e . button === 0 ) this . mouseRightBtnDown = true ;
160
172
if ( e . button === 2 ) this . mouseLeftBtnDown = true ;
161
173
const destroyOrPlaceBlock = ( ) => {
162
- let entity = this . entity ,
163
- world = entity . world ,
164
- start = entity . getEyePosition ( ) ,
165
- end = entity . getDirection ( 20 ) ;
166
- vec3 . add ( start , end , end ) ;
167
- let hit = world . rayTraceBlock ( start , end , ( x , y , z ) => {
168
- let b = world . getBlock ( x , y , z ) ;
169
- return b && b . name !== "air" ;
170
- } ) ;
174
+ const world = this . entity . world , hit = this . getHitting ( ) ;
171
175
if ( hit === null || hit . axis === "" ) return ;
172
176
let pos = hit . blockPos ;
173
177
if ( this . mouseLeftBtnDown ) {
0 commit comments