diff options
Diffstat (limited to 'server/block_def.go')
| -rw-r--r-- | server/block_def.go | 51 |
1 files changed, 49 insertions, 2 deletions
diff --git a/server/block_def.go b/server/block_def.go index 631a388..28ae0ef 100644 --- a/server/block_def.go +++ b/server/block_def.go @@ -66,6 +66,7 @@ type blockDef struct { Opacity blockOpacity FogDensity byte FogColor [3]byte + AuthLevel authLevel Variants map[any]blockType } @@ -248,17 +249,63 @@ func getBlockDefPackets() iter.Seq[classic.Packet] { func getInventoryPackets(inventoryList []blockType) iter.Seq[classic.Packet] { return func(yield func(classic.Packet) bool) { + var ok bool for i := 0; i < 256; i++ { // clear inventory first - yield(&classic.InventoryOrder { + ok = yield(&classic.InventoryOrder { Order: 0, BlockId: byte(i), }) } for i, block := range inventoryList { - yield(&classic.InventoryOrder { + ok = yield(&classic.InventoryOrder { Order: byte(i + 1), BlockId: byte(block), }) } + if !ok { + return + } + } +} + +func getBlockPermissionPackets(auth authLevel) iter.Seq[classic.Packet] { + return func(yield func(classic.Packet) bool) { + for block, def := range blockDefinitions { + var packet classic.Packet + if auth < def.AuthLevel { + packet = &classic.SetBlockPermission { + BlockId: byte(block), + AllowPlacement: 0, + AllowDeletion: 0, + } + } else { + packet = &classic.SetBlockPermission { + BlockId: byte(block), + AllowPlacement: 1, + AllowDeletion: 1, + } + } + if !yield(packet) { + return + } + } + var placeLiquids byte + if auth >= defaultAuth { + placeLiquids = 1 + } + var ok bool + ok = yield(&classic.SetBlockPermission { + BlockId: blockWater, + AllowPlacement: placeLiquids, + AllowDeletion: placeLiquids, + }) + if !ok { + return + } + yield(&classic.SetBlockPermission { + BlockId: blockLava, + AllowPlacement: placeLiquids, + AllowDeletion: placeLiquids, + }) } } |
