예제 #1
0
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)
			}
		}
	}
}
예제 #2
0
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)
}
예제 #3
0
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)
}
예제 #4
0
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)
}
예제 #5
0
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()))
}
예제 #6
0
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)
}
예제 #7
0
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})
}