コード例 #1
0
ファイル: chunk.go プロジェクト: nictuku/chunkymonkey
// 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
		chunk.newActiveBlocks[blockIndex] = false, false
	}

	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.
			chunk.activeBlocks[blockIndex] = false, false
		}

		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.
			chunk.activeBlocks[blockIndex] = false, false
		}
	}
}
コード例 #2
0
ファイル: chunk.go プロジェクト: huwenshu/chunkymonkey
// 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, true
			} else {
				// Block now inactive. Remove this block from the active list.
				chunk.activeBlocks[blockIndex] = false, false
			}
		}
	}

	chunk.storeDirty = true
}