func startBlockUpdate(x, y, z int32) { for X := x - 1; X <= x+1; X++ { for Y := y - 1; Y <= y+1; Y++ { for Z := z - 1; Z <= z+1; Z++ { chunk := storage.GetChunkContaining(X, Z) switch chunk.GetBlock(X, Y, Z) { case block.Water, block.StationaryWater: stopTheFloodingOMG := chunk.GetData(X, Y, Z) chunk.SetBlock(X, Y, Z, block.Water) chunk.SetData(X, Y, Z, stopTheFloodingOMG) queueUpdate(X, Y, Z) case block.Sponge: queueUpdate(X, Y, Z) case block.Gravel, block.Sand, block.LongGrass, block.RedFlower, block.YellowFlower: queueUpdate(X, Y, Z) } storage.ReleaseChunkContaining(X, Z) } } } }
func GetBlockDataAt(x, y, z int32) uint8 { if y < 0 || y > 255 { return 0 } chunk := storage.GetChunkContaining(x, z) defer storage.ReleaseChunkContaining(x, z) return chunk.GetData(x, y, z) }
func GetBlockAt(x, y, z int32) block.BlockType { if y < 0 || y > 255 { return block.Air } chunk := storage.GetChunkContaining(x, z) defer storage.ReleaseChunkContaining(x, z) return chunk.GetBlock(x, y, z) }
func setBlockNoUpdate(x, y, z int32, block block.BlockType, data uint8) { if y < 0 || y > 255 { return } chunk := storage.GetChunkContaining(x, z) defer storage.ReleaseChunkContaining(x, z) chunk.SetBlock(x, y, z, block) chunk.SetData(x, y, z, data) }
func DropItem(x, y, z float64, itemType int16, data uint8) { c := storage.GetChunkContaining(int32(x), int32(z)) defer storage.ReleaseChunkContaining(int32(x), int32(z)) ent := chunk.NewItemDrop(x, y, z, &player.InventoryItem{Type: itemType, Damage: int16(data), Count: 1}) c.SpawnEntity(chunk.Entity(ent)) var buf bytes.Buffer ent.SpawnPacket(&buf) SendToAllNearChunk(c.X, c.Z, protocol.BakedPacket(buf.Bytes())) }
func SetBlockAt(x, y, z int32, block block.BlockType, data uint8) { if y < 0 || y > 255 { return } chunk := storage.GetChunkContaining(x, z) defer storage.ReleaseChunkContaining(x, z) chunk.SetBlock(x, y, z, block) chunk.SetData(x, y, z, data) startBlockUpdate(x, y, z) queueBlockSend(x, y, z) }
func PlayerSetBlockAt(x, y, z int32, block block.BlockType, data uint8) { if y < 0 || y > 255 { return } chunk := storage.GetChunkContaining(x, z) defer storage.ReleaseChunkContaining(x, z) chunk.SetBlock(x, y, z, block) chunk.SetData(x, y, z, data) startBlockUpdate(x, y, z) SendToAll(protocol.BlockChange{X: x, Y: uint8(y), Z: z, Block: block, Data: data}) }