Skip to content

Commit e42392e

Browse files
committed
errors Fix
1 parent 1e10d8c commit e42392e

File tree

16 files changed

+210
-274
lines changed

16 files changed

+210
-274
lines changed

coffee/client/module/InventoryBar.coffee

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,13 @@ class InventoryBar
3535
$(".xp_bar").css "width","#{500*progress}px"
3636
setFocus:(num)->
3737
$(".inv_cursor").css("left","calc(50vw - 253px + 55*#{num}px)")
38+
updateInv:(inv)->
39+
for i in [36..44]
40+
if inv[i] isnt null
41+
$(".inv_box").eq(i-36).css("background-image","url(/assets/items/#{inv[i].name}.png)")
42+
else
43+
$(".inv_box").eq(i-36).css("background-image","")
44+
return
3845
listen:()->
3946
focus=0
4047
@setFocus focus

coffee/client/module/World/BlockGeo.coffee

Lines changed: 0 additions & 70 deletions
This file was deleted.

coffee/client/module/World/CellTerrain.coffee

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ class CellTerrain
33
constructor: (options)->
44
@cellSize=options.cellSize
55
@cells={}
6-
@biomes={}
76
@loadedBlocks={}
87
vec3: (x,y,z)->
98
x=parseInt x
@@ -47,16 +46,8 @@ class CellTerrain
4746
return @cells[@vec3(x,y,z)]
4847
setCell:(cellX,cellY,cellZ,buffer)->
4948
@cells[@vec3(cellX,cellY,cellZ)]=buffer
50-
setBiome:(cellX,cellY,cellZ,biome)->
51-
@biomes[@vec3(cellX,cellY,cellZ)]=biome
52-
getBlockBiome:(blockX,blockY,blockZ)->
53-
biome=@getCellForVoxel blockX,blockY,blockZ
54-
if not biome
55-
return null
56-
voff=@computeVoxelOffset blockX,blockY,blockZ
57-
return biome[voff]
5849
getBlock:(blockX,blockY,blockZ)->
5950
if @loadedBlocks[@getVoxel(blockX,blockY,blockZ)] is undefined
60-
@loadedBlocks[@getVoxel(blockX,blockY,blockZ)]=new Block.fromStateId @getVoxel(blockX,blockY,blockZ), @getBlockBiome(blockX,blockY,blockZ)
51+
@loadedBlocks[@getVoxel(blockX,blockY,blockZ)]=new Block.fromStateId @getVoxel(blockX,blockY,blockZ)
6152
return @loadedBlocks[@getVoxel(blockX,blockY,blockZ)]
6253
export {CellTerrain}

coffee/client/module/World/World.coffee

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,11 @@ class World
3939
result=data.data.result
4040
for i in result
4141
if i isnt null
42-
_this.setCell i.x,i.y,i.z,i.cell,i.biome
42+
_this.setCell i.x,i.y,i.z,i.cell
4343
return
44-
setCell: (cellX,cellY,cellZ,buffer,biome)->
45-
@_setCell cellX,cellY,cellZ,buffer,biome
44+
setCell: (cellX,cellY,cellZ,buffer)->
45+
@_setCell cellX,cellY,cellZ,buffer
4646
@cellTerrain.setCell cellX,cellY,cellZ,buffer
47-
@cellTerrain.setBiome cellX,cellY,cellZ,biome
4847
@cellNeedsUpdate[@cellTerrain.vec3(cellX,cellY,cellZ)]=true
4948
for nei in @neighbours
5049
neiCellId=@cellTerrain.vec3(cellX+nei[0],cellY+nei[1],cellZ+nei[2])
@@ -178,10 +177,13 @@ class World
178177
intersection = @intersectsRay start, end
179178
if intersection
180179
posPlace = intersection.position.map (v, ndx) ->
181-
return (v + intersection.normal[ndx] * 0.5)
180+
return Math.floor(v + intersection.normal[ndx] * 0.5)
182181
posBreak = intersection.position.map (v, ndx) ->
183-
return (v + intersection.normal[ndx] *-0.5)
184-
return {posPlace,posBreak}
182+
return Math.floor(v + intersection.normal[ndx] *-0.5)
183+
return {
184+
posPlace
185+
posBreak
186+
}
185187
else
186188
return false
187189
_setCell: (cellX,cellY,cellZ,buffer,biome)->

coffee/client/module/World/chunk.worker.coffee

Lines changed: 65 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import {CellTerrain} from './CellTerrain.js'
2-
import {BlockGeo} from './BlockGeo.js'
32

43
console.log "CHUNK WORKER STARTED!"
54

@@ -9,10 +8,70 @@ class TerrainManager
98
@cellTerrain=new CellTerrain {
109
cellSize:@cellSize
1110
}
12-
@BlockGeo=new BlockGeo {
13-
toxelSize:options.toxelSize
14-
blocksMapping:options.blocksMapping
15-
}
11+
@toxelSize=options.toxelSize
12+
@q=1/@toxelSize
13+
@blocksMapping=options.blocksMapping
14+
genBlockFace: (type,block,pos)->
15+
if block.name is "water"
16+
toxX=@blocksMapping["water_flow"]["x"]
17+
toxY=@blocksMapping["water_flow"]["y"]
18+
else if @blocksMapping[block.name]
19+
toxX=@blocksMapping[block.name]["x"]
20+
toxY=@blocksMapping[block.name]["y"]
21+
else
22+
toxX=@blocksMapping["debug"]["x"]
23+
toxY=28-@blocksMapping["debug"]["y"]
24+
li = [255,255,255]
25+
sh = [0,0,0]
26+
toxX-=1
27+
toxY-=1
28+
x1=@q*toxX
29+
y1=1-@q*toxY-@q
30+
x2=@q*toxX+@q
31+
y2=1-@q*toxY
32+
uv=[
33+
[x1,y1]
34+
[x1,y2]
35+
[x2,y1]
36+
[x2,y2]
37+
]
38+
switch type
39+
when "pz"
40+
return {
41+
pos:[-0.5+pos[0], -0.5+pos[1], 0.5+pos[2],0.5+pos[0], -0.5+pos[1], 0.5+pos[2],-0.5+pos[0], 0.5+pos[1], 0.5+pos[2],-0.5+pos[0], 0.5+pos[1], 0.5+pos[2],0.5+pos[0], -0.5+pos[1], 0.5+pos[2],0.5+pos[0], 0.5+pos[1], 0.5+pos[2]]
42+
norm:[0, 0, 1,0, 0, 1,0, 0, 1,0, 0, 1,0, 0, 1,0, 0, 1]
43+
uv:[uv[0]...,uv[2]...,uv[1]...,uv[1]...,uv[2]...,uv[3]...]
44+
}
45+
when "nx"
46+
return {
47+
pos:[ 0.5+pos[0], -0.5+pos[1], 0.5+pos[2], 0.5+pos[0], -0.5+pos[1], -0.5+pos[2],0.5+pos[0], 0.5+pos[1], 0.5+pos[2], 0.5+pos[0], 0.5+pos[1], 0.5+pos[2],0.5+pos[0], -0.5+pos[1], -0.5+pos[2], 0.5+pos[0], 0.5+pos[1], -0.5+pos[2]]
48+
norm:[ 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0]
49+
uv:[uv[0]...,uv[2]...,uv[1]...,uv[1]...,uv[2]...,uv[3]...]
50+
}
51+
when "nz"
52+
return {
53+
pos:[ 0.5+pos[0], -0.5+pos[1], -0.5+pos[2],-0.5+pos[0], -0.5+pos[1], -0.5+pos[2],0.5+pos[0], 0.5+pos[1], -0.5+pos[2], 0.5+pos[0], 0.5+pos[1], -0.5+pos[2],-0.5+pos[0], -0.5+pos[1], -0.5+pos[2],-0.5+pos[0], 0.5+pos[1], -0.5+pos[2]]
54+
norm:[ 0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, -1]
55+
uv:[uv[0]...,uv[2]...,uv[1]...,uv[1]...,uv[2]...,uv[3]...]
56+
}
57+
when "px"
58+
return {
59+
pos:[-0.5+pos[0], -0.5+pos[1], -0.5+pos[2],-0.5+pos[0], -0.5+pos[1], 0.5+pos[2],-0.5+pos[0], 0.5+pos[1], -0.5+pos[2],-0.5+pos[0], 0.5+pos[1], -0.5+pos[2],-0.5+pos[0], -0.5+pos[1], 0.5+pos[2],-0.5+pos[0], 0.5+pos[1], 0.5+pos[2]]
60+
norm:[-1, 0, 0,-1, 0, 0,-1, 0, 0,-1, 0, 0,-1, 0, 0,-1, 0, 0]
61+
uv:[uv[0]...,uv[2]...,uv[1]...,uv[1]...,uv[2]...,uv[3]...]
62+
}
63+
when "py"
64+
return {
65+
pos:[ 0.5+pos[0], 0.5+pos[1], -0.5+pos[2],-0.5+pos[0], 0.5+pos[1], -0.5+pos[2],0.5+pos[0], 0.5+pos[1], 0.5+pos[2], 0.5+pos[0], 0.5+pos[1], 0.5+pos[2],-0.5+pos[0], 0.5+pos[1], -0.5+pos[2],-0.5+pos[0], 0.5+pos[1], 0.5+pos[2]]
66+
norm:[ 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0]
67+
uv:[uv[0]...,uv[2]...,uv[1]...,uv[1]...,uv[2]...,uv[3]...]
68+
}
69+
when "ny"
70+
return {
71+
pos:[ 0.5+pos[0], -0.5+pos[1], 0.5+pos[2],-0.5+pos[0], -0.5+pos[1], 0.5+pos[2],0.5+pos[0], -0.5+pos[1], -0.5+pos[2], 0.5+pos[0], -0.5+pos[1], -0.5+pos[2],-0.5+pos[0], -0.5+pos[1], 0.5+pos[2],-0.5+pos[0], -0.5+pos[1], -0.5+pos[2]]
72+
norm:[ 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0]
73+
uv:[uv[0]...,uv[2]...,uv[1]...,uv[1]...,uv[2]...,uv[3]...]
74+
}
1675
genCellGeo: (cellX,cellY,cellZ)->
1776
_this=@
1877
positions=[]
@@ -29,7 +88,7 @@ class TerrainManager
2988
else
3089
return [0.3,0.3,0.3]
3190
addFace=(type,pos)->
32-
faceVertex=_this.BlockGeo.genBlockFace type,_this.cellTerrain.getBlock(pos...),pos
91+
faceVertex=_this.genBlockFace type,_this.cellTerrain.getBlock(pos...),pos
3392
positions.push faceVertex.pos...
3493
normals.push faceVertex.norm...
3594
uvs.push faceVertex.uv...
@@ -115,7 +174,6 @@ class TerrainManager
115174
uvs
116175
colors
117176
}
118-
119177
addEventListener "message", (e)->
120178
fn = handlers[e.data.type]
121179
if not fn
@@ -150,5 +208,4 @@ handlers={
150208
}
151209
setCell: (data)->
152210
terrain.cellTerrain.setCell data[0],data[1],data[2],data[3]
153-
terrain.cellTerrain.setBiome data[0],data[1],data[2],data[4]
154211
}

coffee/client/module/World/sections.worker.coffee

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,8 @@ class BitArray
3838
endLong = @data[startLongIndex * 2 + 1]
3939
result |= endLong << (32 - indexInStartLong)
4040
return result & @valueMask
41-
length: () ->
42-
return @data.length / 2
43-
getBitsPerValue: ()->
44-
return @bitsPerValue
4541

4642
class ChunkDecoder
47-
constructor: (options)->
48-
#NOTHING
4943
getBlockIndex: (pos)->
5044
return (pos.y << 8) | (pos.z << 4) | pos.x
5145
cvo: (voxelX,voxelY,voxelZ) ->
@@ -69,20 +63,15 @@ class ChunkDecoder
6963
z:0
7064
}
7165
cell=new Uint8Array 16*16*16
72-
biome=new Uint8Array 16*16*16
7366
for x in [0..15]
7467
for y in [0..15]
7568
for z in [0..15]
76-
# ct.setVoxel packet.x+x,num+y,packet.z+z
7769
cell[@cvo(x,y,z)]=palette[data.get(@getBlockIndex({x,y,z}))]
78-
# base.push(palette[data.get(@getBlockIndex({x,y,z}))])
79-
biome[@cvo(x,y,z)]=packet.biomes[(((num+y) >> 2) & 63) << 4 | (((packet.z+z) >> 2) & 3) << 2 | (((packet.x+x) >> 2) & 3)]
8070
result.push {
8171
x:packet.x
8272
y:num
8373
z:packet.z
8474
cell
85-
biome
8675
}
8776
else
8877
result.push(null)

coffee/client/module/index.coffee

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -107,10 +107,7 @@ init = ()->
107107
inv_bar.setHp(points)
108108
return
109109
"inventory":(inv)->
110-
for i in [36..44]
111-
try
112-
$(".inv_box").eq(i-36).css("background-image","url(/assets/items/#{inv[i].name}.png)")
113-
# console.log inv[i]
110+
inv_bar.updateInv inv
114111
return
115112
"food":(points)->
116113
inv_bar.setFood(points)
@@ -149,26 +146,28 @@ init = ()->
149146
)
150147
scene.add cursor
151148

152-
#Mgła
153-
color = new THREE.Color "#adc8ff"
154-
near = 3*16-13
155-
far = 3*16-3
156-
scene.fog = new THREE.Fog color, near, far
157-
158149
#Interfejs dat.gui
159150
gui = new GUI()
160151
params={
161-
fog:true
152+
fog:false
162153
chunkdist:4
163154
}
164155
gui.add( params, 'fog' ).name( 'Enable fog' ).listen().onChange ()->
165156
if params.fog
157+
#Mgła
158+
color = new THREE.Color "#adc8ff"
159+
near = 3*16-13
160+
far = 3*16-3
166161
scene.fog = new THREE.Fog color, near, far
167162
else
168163
scene.fog = null
169164
gui.add( world.material, 'wireframe' ).name( 'Wireframe' ).listen()
170165
gui.add( params, 'chunkdist',0,10,1).name( 'Render distance' ).listen()
171166

167+
$(document).mousedown (e)->
168+
console.log world.cellTerrain.getVoxel world.getRayBlock().posBreak...
169+
return
170+
172171
#Wprawienie w ruch funkcji animate
173172
animate()
174173
return
@@ -189,9 +188,6 @@ render = ->
189188
rayBlock=world.getRayBlock()
190189
if rayBlock
191190
pos=rayBlock.posBreak
192-
pos[0]=Math.floor pos[0]
193-
pos[1]=Math.floor pos[1]
194-
pos[2]=Math.floor pos[2]
195191
cursor.position.set pos...
196192
cursor.visible=true
197193
else

coffee/server.coffee

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,10 @@ module.exports=(type)->
4747
version: config.realServer.version
4848
}
4949
bot=()->
50-
return socketInfo[socket.id].bot
50+
if socketInfo[socket.id] isnt undefined
51+
return socketInfo[socket.id].bot
52+
else
53+
return null
5154
emit=(array)->
5255
io.to(socket.id).emit array...
5356
#Eventy otrzymywane z serwera minecraftowego
@@ -81,8 +84,12 @@ module.exports=(type)->
8184
return
8285
}
8386
for i of botEventMap
84-
socketInfo[socket.id].bot.on i, botEventMap[i]
85-
87+
((i)->
88+
socketInfo[socket.id].bot.on i, ()->
89+
if bot() isnt null
90+
botEventMap[i] arguments...
91+
return
92+
)(i)
8693
inv=""
8794
socketInfo[socket.id].int=setInterval ()->
8895
inv_new=JSON.stringify(bot().inventory.slots)

src/client/module/InventoryBar.js

Lines changed: 11 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)