Exemplo n.º 1
0
// blockTickAll runs a "Tick" for all blocks within the chunk
func (chunk *Chunk) blockTickAll() {
	var ok bool
	var blockInstance gamerules.BlockInstance
	blockInstance.Chunk = chunk

	var blockIndex BlockIndex
	max := BlockIndex(len(chunk.blocks))

	for blockIndex = 0; blockIndex < max; blockIndex++ {
		blockInstance.BlockType, blockInstance.Data, ok = chunk.blockTypeAndData(blockIndex)
		if ok {
			blockInstance.SubLoc = blockIndex.ToSubChunkXyz()
			blockInstance.Index = blockIndex
			blockInstance.BlockLoc = *chunk.loc.ToBlockXyz(&blockInstance.SubLoc)

			if blockInstance.BlockType.Aspect.Tick(&blockInstance) {
				// Block now active, so re-queue this
				chunk.activeBlocks[blockIndex] = true
			} else {
				// Block now inactive. Remove this block from the active list.
				delete(chunk.activeBlocks, blockIndex)
			}
		}
	}

	chunk.storeDirty = true
}
Exemplo n.º 2
0
// blockTick runs any blocks that need to do something each tick.
func (chunk *Chunk) blockTick() {
	if len(chunk.activeBlocks) == 0 && len(chunk.newActiveBlocks) == 0 {
		return
	}

	for blockIndex := range chunk.newActiveBlocks {
		chunk.activeBlocks[blockIndex] = true
		delete(chunk.newActiveBlocks, blockIndex)
	}

	var ok bool
	var blockInstance gamerules.BlockInstance
	blockInstance.Chunk = chunk

	for blockIndex := range chunk.activeBlocks {
		blockInstance.BlockType, blockInstance.Data, ok = chunk.blockTypeAndData(blockIndex)
		if !ok {
			// Invalid block.
			delete(chunk.activeBlocks, blockIndex)
		}

		blockInstance.SubLoc = blockIndex.ToSubChunkXyz()
		blockInstance.Index = blockIndex
		blockInstance.BlockLoc = *chunk.loc.ToBlockXyz(&blockInstance.SubLoc)

		if !blockInstance.BlockType.Aspect.Tick(&blockInstance) {
			// Block now inactive. Remove this block from the active list.
			delete(chunk.activeBlocks, blockIndex)
		}
	}

	chunk.storeDirty = true
}