go-mc icon indicating copy to clipboard operation
go-mc copied to clipboard

Clean way to set block state on local chunk coordinates?

Open maxsupermanhd opened this issue 4 years ago • 1 comments

I am trying to make procedural generation for chunks, is there a better way of setting block state than calculating section and local section coordinates? Maybe a helper function of some sort would be nice.

maxsupermanhd avatar Apr 25 '22 19:04 maxsupermanhd

For now I came with following procedure:

func SetChunkBlock(c *level.Chunk, lx, ly, lz, bs int) {
	sid := (ly+64)/16 + 4
	if len(c.Sections) <= sid {
		log.Printf("Failed to set block %d at %d %d %d because there is no section %d (%d allocated)", bs, lx, ly, lz, sid, len(c.Sections))
		return
	}
	c.Sections[sid].SetBlock((ly%16)*16*16+lz*16+lx, bs)
}

However client ignores chunk or block is not actually placed.

maxsupermanhd avatar Apr 26 '22 13:04 maxsupermanhd