Improve alignment with stairs when moving
This commit is contained in:
@ -50,6 +50,15 @@ func LadderDirection(bStateID world.BlockStatus) Direction {
|
|||||||
return Direction(((uint32(bStateID) - block.Ladder.MinStateID) & 0xE) >> 1)
|
return Direction(((uint32(bStateID) - block.Ladder.MinStateID) & 0xE) >> 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func ChestDirection(bStateID world.BlockStatus) Direction {
|
||||||
|
return Direction(((uint32(bStateID) - block.Chest.MinStateID) / 6) & 0x3)
|
||||||
|
}
|
||||||
|
|
||||||
|
func StairsDirection(bStateID world.BlockStatus) Direction {
|
||||||
|
b := block.StateID[uint32(bStateID)]
|
||||||
|
return Direction(((uint32(bStateID) - block.ByID[b].MinStateID) / 20) & 0x3)
|
||||||
|
}
|
||||||
|
|
||||||
// Movement represents a single type of movement in a path.
|
// Movement represents a single type of movement in a path.
|
||||||
type Movement uint8
|
type Movement uint8
|
||||||
|
|
||||||
|
@ -128,9 +128,8 @@ func (t Tile) Inputs(pos, deltaPos, vel Point, runTime time.Duration) Inputs {
|
|||||||
|
|
||||||
case AscendLadder:
|
case AscendLadder:
|
||||||
dist2 := math.Sqrt(deltaPos.X*deltaPos.X + deltaPos.Z*deltaPos.Z)
|
dist2 := math.Sqrt(deltaPos.X*deltaPos.X + deltaPos.Z*deltaPos.Z)
|
||||||
bStateID := t.Nav.World.GetBlockStatus(t.Pos.X, t.Pos.Y, t.Pos.Z)
|
|
||||||
|
|
||||||
if x, _, z := LadderDirection(bStateID).Offset(); dist2 > (0.9*0.9) && deltaPos.Y < 0 {
|
if x, _, z := LadderDirection(t.BlockStatus).Offset(); dist2 > (0.9*0.9) && deltaPos.Y < 0 {
|
||||||
pos.X -= (0.25 * float64(x))
|
pos.X -= (0.25 * float64(x))
|
||||||
pos.Z -= (0.25 * float64(z))
|
pos.Z -= (0.25 * float64(z))
|
||||||
} else {
|
} else {
|
||||||
@ -146,11 +145,29 @@ func (t Tile) Inputs(pos, deltaPos, vel Point, runTime time.Duration) Inputs {
|
|||||||
}
|
}
|
||||||
|
|
||||||
case AscendNorth, AscendSouth, AscendEast, AscendWest:
|
case AscendNorth, AscendSouth, AscendEast, AscendWest:
|
||||||
b := block.ByID[block.StateID[uint32(t.BlockStatus)]]
|
var (
|
||||||
noJump := strings.HasSuffix(b.Name, "_stairs") && runTime < (1250*time.Millisecond)
|
b = block.ByID[block.StateID[uint32(t.BlockStatus)]]
|
||||||
|
isStairs = strings.HasSuffix(b.Name, "_stairs")
|
||||||
|
maybeStuck = runTime < 1250*time.Millisecond
|
||||||
|
dist2 = math.Sqrt(deltaPos.X*deltaPos.X + deltaPos.Z*deltaPos.Z)
|
||||||
|
)
|
||||||
|
out.Jump = dist2 < 1.75 && deltaPos.Y < -0.81
|
||||||
|
|
||||||
dist2 := math.Sqrt(deltaPos.X*deltaPos.X + deltaPos.Z*deltaPos.Z)
|
// Special logic for stairs: Try to go towards the downwards edge initially.
|
||||||
out.Jump = dist2 < 1.75 && deltaPos.Y < -0.81 && !noJump
|
if isStairs && dist2 > (0.9*0.9) && deltaPos.Y < 0 {
|
||||||
|
if x, _, z := StairsDirection(t.BlockStatus).Offset(); dist2 > (0.9*0.9) && deltaPos.Y < 0 {
|
||||||
|
pos.X += (0.49 * float64(x))
|
||||||
|
pos.Z += (0.49 * float64(z))
|
||||||
|
}
|
||||||
|
|
||||||
|
at = math.Atan2(-pos.X+float64(t.Pos.X)+0.5, -pos.Z+float64(t.Pos.Z)+0.5)
|
||||||
|
out = Inputs{
|
||||||
|
ThrottleX: math.Sin(at),
|
||||||
|
ThrottleZ: math.Cos(at),
|
||||||
|
Yaw: math.NaN(),
|
||||||
|
Jump: out.Jump && !maybeStuck,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Turn off the throttle if we get stuck on the jump.
|
// Turn off the throttle if we get stuck on the jump.
|
||||||
if dist2 < 1 && deltaPos.Y < 0 && vel.Y == 0 {
|
if dist2 < 1 && deltaPos.Y < 0 && vel.Y == 0 {
|
||||||
|
@ -7,6 +7,18 @@ type Info struct {
|
|||||||
Slots int
|
Slots int
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (i Info) PlayerInvStart() int {
|
||||||
|
return i.Start
|
||||||
|
}
|
||||||
|
|
||||||
|
func (i Info) PlayerInvEnd() int {
|
||||||
|
return i.End
|
||||||
|
}
|
||||||
|
|
||||||
|
func (i Info) HotbarIdx(place int) int {
|
||||||
|
return i.End - (8 - place)
|
||||||
|
}
|
||||||
|
|
||||||
var ByType = map[int]Info{
|
var ByType = map[int]Info{
|
||||||
-1: Info{Name: "inventory", Start: 9, End: 44, Slots: 46},
|
-1: Info{Name: "inventory", Start: 9, End: 44, Slots: 46},
|
||||||
0: Info{Name: "generic_9x1", Start: 1 * 9, End: 1*9 + 35, Slots: 1*9 + 36},
|
0: Info{Name: "generic_9x1", Start: 1 * 9, End: 1*9 + 35, Slots: 1*9 + 36},
|
||||||
|
Reference in New Issue
Block a user