Ejemplo n.º 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)
			}
		}
	}
}
Ejemplo n.º 2
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)
}
Ejemplo n.º 3
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)
}
Ejemplo n.º 4
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})
}
Ejemplo n.º 5
0
func ChunkGen(chunkX, chunkZ int32) *chunk.Chunk {
	chunk := &chunk.Chunk{X: chunkX, Z: chunkZ}

	r := rand.New(rand.NewSource(int64(uint32(chunkX))<<32 | int64(uint32(chunkZ))))

	for x := chunkX << 4; x < (chunkX<<4)+16; x++ {
		for z := chunkZ << 4; z < (chunkZ<<4)+16; z++ {
			chunk.SetBlock(x, 0, z, block.Bedrock)

			fx := float64(x) / 16
			fz := float64(z) / 16

			stone := int32(6 + 4*util.Noise2(fx, fz))
			land := int32(58 + 8*util.Noise2(fx/10, fz/10))

			mountain := util.Noise3(fx/15, float64(land)/15, fz/15)
			isMountain := true
			mountain -= 0.4
			if mountain < 0 {
				mountain = 0
				isMountain = false
			}
			mountain *= 30

			land += int32(mountain)

			river := int32(river(util.Noise2(fx/4, fz/4)))

			smooth := util.Noise2(fx/50, fz/50) * 3

			rough := util.Noise2(fx*2, fz*2) * 2

			for y := int32(1); y < land-stone; y++ {
				chunk.SetBlock(x, y, z, block.Stone)
			}

			for y := land - stone; y < land; y++ {
				chunk.SetBlock(x, y, z, block.Dirt)
			}

			if river != 0 {
				chunk.SetBlock(x, 46-river, z, block.Gravel)
				chunk.SetBlock(x, 47-river, z, block.Gravel)
				chunk.SetBlock(x, 48-river, z, block.Gravel)
				chunk.SetBlock(x, 49-river, z, block.Gravel)
			}
			for y := 50 - river; y < 50; y++ {
				chunk.SetBlock(x, y, z, block.StationaryWater)
			}

			if river == 0 || land > 50 {
				chunk.SetBlock(x, land, z, block.Grass)
				if smooth < rough {
					if r.Intn(8) == 0 {
						fy := float64(land + 1)
						if util.Noise3(fx/10, fy/2, fz/10) > 0 {
							chunk.SetBlock(x, land+1, z, block.RedFlower)
						} else {
							chunk.SetBlock(x, land+1, z, block.YellowFlower)
						}
					} else {
						chunk.SetBlock(x, land+1, z, block.LongGrass)
						chunk.SetData(x, land+1, z, 1)
					}
				}
				if smooth < rough/5 && mountain > 1 && r.Intn(20) == 0 {
					growTree(chunk, r, x, land+1, z)
				}
				if isMountain {
					chunk.SetBiome(x, z, protocol.ExtremeHills)
				} else {
					chunk.SetBiome(x, z, protocol.Plains)
				}
			} else {
				chunk.SetBiome(x, z, protocol.River)
			}

			if river != 0 {
				chunk.SetBlock(x, 50, z, block.Air)

				for y := int32(51); y < 64 && r.Intn(20) != 0 && chunk.GetBlock(x, y, z) == block.Dirt; y++ {
					chunk.SetBlock(x, y, z, block.Stone)
				}

				for y := int32(51); y < 64 && r.Intn(4) != 0 && chunk.GetBlock(x, y, z) == block.Stone; y++ {
					chunk.SetBlock(x, y, z, block.Air)
				}

			}
		}
	}
	chunk.InitLighting()

	return chunk
}