Sets the block at the position and returns its new state (index in the block palette). Resizes the palette if needed X, Y, Z should be relative to the chunk section (AKA x&0x0f, y&0x0f, z&0x0f)
(x, y, z byte, b AnvilBlock)
| 95 | // Sets the block at the position and returns its new state (index in the block palette). Resizes the palette if needed |
| 96 | // X, Y, Z should be relative to the chunk section (AKA x&0x0f, y&0x0f, z&0x0f) |
| 97 | func (s *Section) SetBlock(x, y, z byte, b AnvilBlock) (state int64) { |
| 98 | var ok bool |
| 99 | state, ok = s.index(b) |
| 100 | if !ok { |
| 101 | panic("not now") |
| 102 | oldBPE := s.blockBitsPerEntry |
| 103 | s.add(b) |
| 104 | state = int64(len(s.BlockStates.Palette) - 1) |
| 105 | if oldBPE != s.blockBitsPerEntry { |
| 106 | newDataLen := 4096 / (64 / s.blockBitsPerEntry) |
| 107 | if len(s.BlockStates.Data) < newDataLen { |
| 108 | s.BlockStates.Data = make([]int64, newDataLen) |
| 109 | } |
| 110 | clear(s.BlockStates.Data) |
| 111 | |
| 112 | for x := byte(0); x < 16; x++ { |
| 113 | for y := byte(0); y < 16; y++ { |
| 114 | for z := byte(0); z < 16; z++ { |
| 115 | s.setBlockState(x, y, z, s.blockState(x, y, z)) |
| 116 | } |
| 117 | } |
| 118 | } |
| 119 | } |
| 120 | } |
| 121 | |
| 122 | long, off := s.offset(int(x), int(y), int(z)) |
| 123 | mask := int64(^((1<<s.blockBitsPerEntry - 1) << off)) |
| 124 | |
| 125 | s.BlockStates.Data[long] &= mask |
| 126 | s.BlockStates.Data[long] |= state << off |
| 127 | |
| 128 | return state |
| 129 | } |
| 130 | |
| 131 | func (s *Section) index(b AnvilBlock) (i int64, ok bool) { |
| 132 | for i, entry := range s.BlockStates.Palette { |
nothing calls this directly
no test coverage detected