Improve inventory command output (#1582)

* Improve inventory command output

* Remove unused code

* Sort item list before printing

* Fix incorrect container slot count

* Update Container.IsHotbar method
This commit is contained in:
ReinforceZwei 2021-05-11 14:02:47 +08:00 committed by GitHub
parent 1cd7c098c3
commit 073458f5f2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 78 additions and 38 deletions

View file

@ -191,5 +191,29 @@ namespace MinecraftClient.Inventory
}
return result.ToArray();
}
/// <summary>
/// Check the given slot ID is a hotbar slot and give the hotbar number
/// </summary>
/// <param name="slotId">The slot ID to check</param>
/// <param name="hotbar">Zero-based, 0-8. -1 if not a hotbar</param>
/// <returns>True if given slot ID is a hotbar slot</returns>
public bool IsHotbar(int slotId, out int hotbar)
{
int hotbarStart = Type.SlotCount() - 9;
// Remove offhand slot
if (Type == ContainerType.PlayerInventory)
hotbarStart--;
if ((slotId >= hotbarStart) && (slotId <= hotbarStart + 9))
{
hotbar = slotId - hotbarStart;
return true;
}
else
{
hotbar = -1;
return false;
}
}
}
}