mirror of
https://github.com/MCCTeam/Minecraft-Console-Client
synced 2025-10-14 21:22:49 +00:00
Add command to check player health and saturation
This commit is contained in:
parent
fe020c74c7
commit
975e6d4daa
5 changed files with 31 additions and 8 deletions
18
MinecraftClient/Commands/Status.cs
Normal file
18
MinecraftClient/Commands/Status.cs
Normal file
|
|
@ -0,0 +1,18 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace MinecraftClient.Commands
|
||||||
|
{
|
||||||
|
class Status : Command
|
||||||
|
{
|
||||||
|
public override string CMDName { get { return "status"; } }
|
||||||
|
public override string CMDDesc { get { return "status: Display Health and Food saturation."; } }
|
||||||
|
|
||||||
|
public override string Run(McTcpClient handler, string command, Dictionary<string, object> localVars)
|
||||||
|
{
|
||||||
|
return "Health: " + handler.GetHealth() + "\n[MCC] Saturation: " + handler.GetSaturation(); // any good ways to print multiple lines?
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -58,9 +58,9 @@ namespace MinecraftClient
|
||||||
private int respawnTicks = 0;
|
private int respawnTicks = 0;
|
||||||
|
|
||||||
private int playerEntityID;
|
private int playerEntityID;
|
||||||
// not really understand the Inventory Class
|
|
||||||
// so I use a Dict instead for player inventory
|
private float playerHealth;
|
||||||
//private Dictionary<int, Inventory.Item> playerItems;
|
private int playerFoodSaturation;
|
||||||
|
|
||||||
// Entity handling
|
// Entity handling
|
||||||
private Dictionary<int, Entity> entities = new Dictionary<int, Entity>();
|
private Dictionary<int, Entity> entities = new Dictionary<int, Entity>();
|
||||||
|
|
@ -78,6 +78,8 @@ namespace MinecraftClient
|
||||||
public Location GetCurrentLocation() { return location; }
|
public Location GetCurrentLocation() { return location; }
|
||||||
public World GetWorld() { return world; }
|
public World GetWorld() { return world; }
|
||||||
public Double GetServerTPS() { return serverTPS; }
|
public Double GetServerTPS() { return serverTPS; }
|
||||||
|
public float GetHealth() { return playerHealth; }
|
||||||
|
public int GetSaturation() { return playerFoodSaturation; }
|
||||||
|
|
||||||
// get bots list for unloading them by commands
|
// get bots list for unloading them by commands
|
||||||
public List<ChatBot> GetLoadedChatBots()
|
public List<ChatBot> GetLoadedChatBots()
|
||||||
|
|
@ -1540,8 +1542,10 @@ namespace MinecraftClient
|
||||||
/// Called when client player's health changed, e.g. getting attack
|
/// Called when client player's health changed, e.g. getting attack
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="health">Player current health</param>
|
/// <param name="health">Player current health</param>
|
||||||
public void OnUpdateHealth(float health)
|
public void OnUpdateHealth(float health, int Food)
|
||||||
{
|
{
|
||||||
|
playerHealth = health;
|
||||||
|
playerFoodSaturation = Food;
|
||||||
if (health <= 0)
|
if (health <= 0)
|
||||||
{
|
{
|
||||||
if (Settings.AutoRespawn)
|
if (Settings.AutoRespawn)
|
||||||
|
|
|
||||||
|
|
@ -101,6 +101,7 @@
|
||||||
<Compile Include="Commands\Script.cs" />
|
<Compile Include="Commands\Script.cs" />
|
||||||
<Compile Include="Commands\Send.cs" />
|
<Compile Include="Commands\Send.cs" />
|
||||||
<Compile Include="Commands\Set.cs" />
|
<Compile Include="Commands\Set.cs" />
|
||||||
|
<Compile Include="Commands\Status.cs" />
|
||||||
<Compile Include="Commands\UseItem.cs" />
|
<Compile Include="Commands\UseItem.cs" />
|
||||||
<Compile Include="Inventory\Container.cs" />
|
<Compile Include="Inventory\Container.cs" />
|
||||||
<Compile Include="Inventory\ContainerType.cs" />
|
<Compile Include="Inventory\ContainerType.cs" />
|
||||||
|
|
|
||||||
|
|
@ -725,10 +725,10 @@ namespace MinecraftClient.Protocol.Handlers
|
||||||
break;
|
break;
|
||||||
case PacketIncomingType.UpdateHealth:
|
case PacketIncomingType.UpdateHealth:
|
||||||
float health = dataTypes.ReadNextFloat(packetData);
|
float health = dataTypes.ReadNextFloat(packetData);
|
||||||
// don't need them
|
int Food = dataTypes.ReadNextVarInt(packetData);
|
||||||
dataTypes.ReadNextVarInt(packetData);
|
// Food Saturation, not useful
|
||||||
dataTypes.ReadNextFloat(packetData);
|
dataTypes.ReadNextFloat(packetData);
|
||||||
handler.OnUpdateHealth(health);
|
handler.OnUpdateHealth(health, Food);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
return false; //Ignored packet
|
return false; //Ignored packet
|
||||||
|
|
|
||||||
|
|
@ -212,7 +212,7 @@ namespace MinecraftClient.Protocol
|
||||||
/// <param name="item">Item (may be null for empty slot)</param>
|
/// <param name="item">Item (may be null for empty slot)</param>
|
||||||
void OnSetSlot(byte inventoryID, short slotID, Item item);
|
void OnSetSlot(byte inventoryID, short slotID, Item item);
|
||||||
|
|
||||||
void OnUpdateHealth(float health);
|
void OnUpdateHealth(float health, int Food);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Called when the Player entity ID has been received from the server
|
/// Called when the Player entity ID has been received from the server
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue