Exemplo n.º 1
0
func calculateLight(bs *blocksSnapshot, origX, origY, origZ int,
	x, y, z float64, face direction.Type, smooth, force bool) (uint16, uint16) {
	ox, oy, oz := face.Offset()
	if !bs.block(origX, origY, origZ).ShouldCullAgainst() {
		ox, oy, oz = 0, 0, 0
	}
	sblockLight := bs.blockLight(origX+ox, origY+oy, origZ+oz)
	sskyLight := bs.skyLight(origX+ox, origY+oy, origZ+oz)
	if !smooth {
		return uint16(sblockLight) * 4000, uint16(sskyLight) * 4000
	}
	blockLight := 0
	skyLight := 0
	count := 0

	dbl := int8(sblockLight) - 8
	if dbl < 0 {
		dbl = 0
	}
	sblockLight = byte(dbl)
	dsl := int8(sskyLight) - 8
	if dsl < 0 {
		dsl = 0
	}
	sskyLight = byte(dsl)

	ddx, ddy, ddz := face.Offset()
	dx, dy, dz := float64(ddx)*0.6, float64(ddy)*0.6, float64(ddz)*0.6
	for ox := -0.6; ox <= 0.0; ox += 0.6 {
		for oy := -0.6; oy <= 0.0; oy += 0.6 {
			for oz := -0.6; oz <= 0.0; oz += 0.6 {
				lx := round(x + ox + dx)
				ly := round(y + oy + dy)
				lz := round(z + oz + dz)
				bl := bs.blockLight(lx, ly, lz)
				sl := bs.skyLight(lx, ly, lz)
				if force && !bs.block(lx, ly, lz).Is(Blocks.Air) {
					bl = sblockLight
					sl = sskyLight
				}
				if sl == 0 && bl == 0 {
					bl = sblockLight
					sl = sskyLight
				}
				blockLight += int(bl)
				skyLight += int(sl)
				count++
			}
		}

	}

	return uint16((blockLight * 4000) / count), uint16((skyLight * 4000) / count)
}
Exemplo n.º 2
0
func calculateLight(bs *blocksSnapshot, origX, origY, origZ int,
	x, y, z float64, face direction.Type, smooth, force bool) (uint16, uint16) {
	ox, oy, oz := face.Offset()
	if !bs.block(origX, origY, origZ).ShouldCullAgainst() {
		ox, oy, oz = 0, 0, 0
	}
	sblockLight := bs.blockLight(origX+ox, origY+oy, origZ+oz)
	sskyLight := bs.skyLight(origX+ox, origY+oy, origZ+oz)
	if !smooth {
		return uint16(sblockLight) * 4000, uint16(sskyLight) * 4000
	}
	blockLight := 0
	skyLight := 0
	count := 0

	dbl := int8(sblockLight) - 8
	if dbl < 0 {
		dbl = 0
	}
	sblockLight = byte(dbl)
	dsl := int8(sskyLight) - 8
	if dsl < 0 {
		dsl = 0
	}
	sskyLight = byte(dsl)

	dx, dy, dz := face.Offset()
	for ox := -1; ox <= 0; ox++ {
		for oy := -1; oy <= 0; oy++ {
			for oz := -1; oz <= 0; oz++ {
				lx := round(x + float64(ox)*0.6 + float64(dx)*0.6)
				ly := round(y + float64(oy)*0.6 + float64(dy)*0.6)
				lz := round(z + float64(oz)*0.6 + float64(dz)*0.6)
				bl := int(bs.blockLight(lx, ly, lz))
				sl := int(bs.skyLight(lx, ly, lz))
				if force && !bs.block(lx, ly, lz).Is(Blocks.Air) {
					bl = int(sblockLight)
					sl = int(sskyLight)
				}
				if sl == 0 && bl == 0 {
					bl = int(sblockLight)
					sl = int(sskyLight)
				}
				blockLight += bl
				skyLight += sl
				count++
			}
		}

	}

	return uint16((float64(blockLight) / float64(count)) * 4000), uint16((float64(skyLight) / float64(count)) * 4000)
}
Exemplo n.º 3
0
func (p Position) ShiftDir(d direction.Type) Position {
	return p.Shift(d.Offset())
}