From 176c7a68f618a6c4d6d8f5d10057ea192195afa7 Mon Sep 17 00:00:00 2001 From: Tom Date: Mon, 28 Sep 2020 19:33:18 -0700 Subject: [PATCH] Improve alignment with stairs when moving --- bot/path/movement.go | 9 +++++++++ bot/path/path.go | 29 +++++++++++++++++++++++------ data/inv/inv.go | 12 ++++++++++++ 3 files changed, 44 insertions(+), 6 deletions(-) diff --git a/bot/path/movement.go b/bot/path/movement.go index 714f5d1..87cf17e 100644 --- a/bot/path/movement.go +++ b/bot/path/movement.go @@ -50,6 +50,15 @@ func LadderDirection(bStateID world.BlockStatus) Direction { 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. type Movement uint8 diff --git a/bot/path/path.go b/bot/path/path.go index c8a9eae..0129122 100644 --- a/bot/path/path.go +++ b/bot/path/path.go @@ -128,9 +128,8 @@ func (t Tile) Inputs(pos, deltaPos, vel Point, runTime time.Duration) Inputs { case AscendLadder: 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.Z -= (0.25 * float64(z)) } else { @@ -146,11 +145,29 @@ func (t Tile) Inputs(pos, deltaPos, vel Point, runTime time.Duration) Inputs { } case AscendNorth, AscendSouth, AscendEast, AscendWest: - b := block.ByID[block.StateID[uint32(t.BlockStatus)]] - noJump := strings.HasSuffix(b.Name, "_stairs") && runTime < (1250*time.Millisecond) + var ( + 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) - out.Jump = dist2 < 1.75 && deltaPos.Y < -0.81 && !noJump + // Special logic for stairs: Try to go towards the downwards edge initially. + 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. if dist2 < 1 && deltaPos.Y < 0 && vel.Y == 0 { diff --git a/data/inv/inv.go b/data/inv/inv.go index 8c0eb67..358ac7f 100644 --- a/data/inv/inv.go +++ b/data/inv/inv.go @@ -7,6 +7,18 @@ type Info struct { 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{ -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},