Use block bounding boxes

This commit is contained in:
Tom
2020-09-23 19:02:32 -07:00
parent eb6289da6a
commit 565b241f0e
4 changed files with 4071 additions and 3995 deletions

View File

@ -43,6 +43,7 @@ func main() {
package shape
import (
"github.com/Tnze/go-mc/bot/world"
"github.com/Tnze/go-mc/data/block"
)
@ -63,6 +64,27 @@ type BoundingBox struct {
Min,Max BoundingTriplet
}
// CollisionBoxes returns the set of bounding boxes for that block state ID.
func CollisionBoxes(bStateID world.BlockStatus) ([]BoundingBox, error) {
bID := block.StateID[uint32(bStateID)]
if bID == 0 {
return nil, fmt.Errorf("unknown state ID: %v", bStateID)
}
b, ok := block.ByID[bID]
if !ok {
return nil, fmt.Errorf("unknown block ID: %v", bID)
}
shapes, ok := ByBlockID[bID]
if !ok {
return nil, fmt.Errorf("unknown shape for block ID: %v", bID)
}
shapeIdx := (uint32(bStateID) - b.MinStateID) % uint32(len(shapes))
if int(shapeIdx) > len(shapes) {
return nil, fmt.Errorf("shape index out of bounds: %v >= %v", shapeIdx, len(shapes))
}
return Dimensions[shapes[shapeIdx]].Boxes, nil
}
`)
fmt.Println()