@@ -12,6 +12,7 @@ import {GUI} from './jsm/libs/dat.gui.module.js'
1212import {Chat} from ' ./Chat.js'
1313import {Entities} from ' ./Entities.js'
1414import {PlayerInInventory} from ' ./PlayerInInventory.js'
15+ import {BlockBreak} from ' ./BlockBreak.js'
1516
1617class Game
1718 constructor : (options )->
@@ -131,20 +132,25 @@ class Game
131132 return
132133 " entities " : (entities )->
133134 _this .ent .update entities
135+ return
136+ " diggingCompleted " : (block )->
137+ _this .bb .done = true
138+ return
139+ " diggingAborted " : (block )->
140+ return
141+ " digTime " : (time ,block )->
142+ _this .bb .startDigging time
143+ return
134144 }
135145 for i of eventMap
136146 @socket .on i,eventMap[i]
137147
138- @cursor = new THREE.LineSegments (
139- new THREE.EdgesGeometry (
140- new THREE.BoxGeometry 1 , 1 , 1
141- ),
142- new THREE.LineBasicMaterial {
143- color : 0x000000 ,
144- linewidth : 0.5
145- }
146- )
147- @scene .add @cursor
148+ @bb = new BlockBreak {
149+ scene : @scene
150+ al : @al
151+ world : @world
152+ socket : @socket
153+ }
148154 gui = new GUI ()
149155 @params = {
150156 fog : false
@@ -161,10 +167,15 @@ class Game
161167 _this .scene .fog = null
162168 gui .add ( @world .material , ' wireframe' ).name ( ' Wireframe' ).listen ()
163169 gui .add ( @params , ' chunkdist' ,0 ,10 ,1 ).name ( ' Render distance' ).listen ()
170+ @mouse = false
164171 $ (document ).mousedown (e)->
172+ _this .mouse = true
165173 if _this .FPC .gameState is " gameLock"
166- console . log _this .world . cellTerrain . getBlock _this . world . getRayBlock (). posBreak ...
174+ _this .bb . digRequest ()
167175 return
176+ $ (document ).mouseup (e)->
177+ _this .mouse = false
178+ _this .bb .stopDigging ()
168179 @ animate ()
169180 animate : ()->
170181 _this = @
@@ -176,6 +187,7 @@ class Game
176187 _this .animate ()
177188 return
178189 render : ()->
190+ _this = @
179191 width = window .innerWidth
180192 height = window .innerHeight
181193 if @canvas .width isnt width or @canvas .height isnt height
@@ -185,13 +197,11 @@ class Game
185197 @camera .aspect = width / height
186198 @camera .updateProjectionMatrix ()
187199
188- rayBlock = @world .getRayBlock ()
189- if rayBlock
190- pos = rayBlock .posBreak
191- @cursor .position .set pos...
192- @cursor .visible = true
193- else
194- @cursor .visible = false
200+ @bb .updatePos ()->
201+ if _this .bb .isDigging
202+ _this .bb .stopDigging ()
203+ if _this .mouse and _this .bb .done
204+ _this .bb .digRequest ()
195205
196206 @world .updateCellsAroundPlayer @camera .position ,@params .chunkdist
197207
0 commit comments