Skip to content

Commit e17d7fd

Browse files
committed
BlockPlace prototype
1 parent fda0597 commit e17d7fd

File tree

6 files changed

+87
-10
lines changed

6 files changed

+87
-10
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
2+
class BlockPlace
3+
constructor:(game)->
4+
@game=game
5+
placeBlock:()->
6+
pos=@game.world.getRayBlock()
7+
vector=[
8+
pos.posPlace[0]-pos.posBreak[0]
9+
pos.posPlace[1]-pos.posBreak[1]
10+
pos.posPlace[2]-pos.posBreak[2]
11+
]
12+
pos.posBreak[1]-=16
13+
@game.socket.emit "blockPlace", pos.posBreak,vector
14+
15+
export {BlockPlace}

coffee/src/client/module/index.coffee

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {Chat} from './Chat.js'
1313
import {Entities} from './Entities.js'
1414
import {PlayerInInventory} from './PlayerInInventory.js'
1515
import {BlockBreak} from './BlockBreak.js'
16+
import {BlockPlace} from './BlockPlace.js'
1617

1718
class Game
1819
constructor:(options)->
@@ -59,6 +60,7 @@ class Game
5960
@pii=new PlayerInInventory @
6061
@ent=new Entities @
6162
@bb=new BlockBreak @
63+
@bp=new BlockPlace @
6264
@world=new World @
6365
@chat=new Chat @
6466
@inv_bar = new InventoryBar @
@@ -148,13 +150,17 @@ class Game
148150
gui.add( @params, 'chunkdist',0,10,1).name( 'Render distance' ).listen()
149151
@mouse=false
150152
$(document).mousedown (e)->
151-
_this.mouse=true
152-
if _this.FPC.gameState is "gameLock"
153-
_this.bb.digRequest()
153+
if e.which is 1
154+
_this.mouse=true
155+
if _this.FPC.gameState is "gameLock"
156+
_this.bb.digRequest()
157+
else if e.which is 3
158+
_this.bp.placeBlock()
154159
return
155160
$(document).mouseup (e)->
156-
_this.mouse=false
157-
_this.bb.stopDigging()
161+
if e.which is 1
162+
_this.mouse=false
163+
_this.bb.stopDigging()
158164
@animate()
159165
animate:()->
160166
_this=@

coffee/src/server.coffee

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,21 @@ module.exports=(type)->
117117
return
118118
,10
119119
socketEventMap={
120+
"blockPlace":(pos,vec)->
121+
console.log pos,vec
122+
block=bot().blockAt(new vec3(pos...))
123+
vecx=[
124+
[1,0,0]
125+
[-1,0,0]
126+
[0,1,0]
127+
[0,-1,0]
128+
]
129+
bot().placeBlock block,new vec3(vec...),(r)->
130+
console.log r
131+
return
132+
133+
134+
return
120135
"invc":(num)->
121136
item=bot().inventory.slots[num+36]
122137
if item isnt null

src/client/module/BlockPlace.js

Lines changed: 21 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/client/module/index.js

Lines changed: 16 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/server.js

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)