MCPcopy Create free account
hub / github.com/ZeppelinMC/Zeppelin / SetBlock

Method SetBlock

server/world/chunk/section/section.go:97–129  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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)
97func (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
131func (s *Section) index(b AnvilBlock) (i int64, ok bool) {
132 for i, entry := range s.BlockStates.Palette {

Callers

nothing calls this directly

Calls 5

indexMethod · 0.95
addMethod · 0.95
setBlockStateMethod · 0.95
blockStateMethod · 0.95
offsetMethod · 0.95

Tested by

no test coverage detected