Exemple #1
0
func (w *World) Block(bc coords.Block) mapgen.Block {
	chunk := w.chunks[bc.Chunk()]
	if chunk == nil {
		return mapgen.BLOCK_NIL
	}
	return chunk.Block(bc.Offset())
}
Exemple #2
0
func (w *World) ChangeBlock(bc coords.Block, newBlock mapgen.Block) {
	chunk := w.Chunk(bc.Chunk())

	oc := bc.Offset()
	block := chunk.Block(oc)
	chunk.SetBlock(oc, newBlock)

	w.blockListeners.FireEvent("BlockChanged", bc, block, newBlock)
}
Exemple #3
0
func (p *persister) BlockChanged(bc coords.Block, old mapgen.Block, new mapgen.Block) {
	cc := bc.Chunk()
	chunk, err := p.loadChunk(cc)
	if err != nil {
		log.Println("Applying block change: ", err)
		return
	}
	chunk.SetBlock(bc.Offset(), new)
	err = p.saveChunk(cc, chunk)
	if err != nil {
		log.Println("Applying block change: ", err)
		return
	}
}
// Applies the given block change to the currently queued chunks
// Returns true if the change was applied (the block has not yet been
// sent), false if it should be sent to the client instead (they already
// have the chunk).
// This is needed to avoid sending stale chunks to the client.
func (cm *ChunkManager) ApplyBlockChange(bc coords.Block, b mapgen.Block) bool {
	cm.mutex.Lock()
	defer cm.mutex.Unlock()

	cc := bc.Chunk()
	status, exists := cm.chunks[cc]
	if !exists {
		// We don't techincally apply the block change to ourselves if the
		// chunk does not exist in our list, but we don't want it to be sent
		// to the client, so we return false regardless.
		return false
	}
	if status.sent {
		return false
	}
	if status.data == nil {
		log.Println("WARN: Recieved block change for chunk that is not loaded (this probably shouldn't happen?)")
		return false
	}
	oc := bc.Offset()
	status.data.SetBlock(oc, b)
	return true
}