AutoFish now checks if the fishing hook is ours

This commit is contained in:
ReinforceZwei 2020-03-26 16:50:29 +08:00 committed by ORelio
parent bc449b404e
commit 66afe127cb

View file

@ -10,11 +10,12 @@ namespace MinecraftClient.ChatBots
{ {
class AutoFishing : ChatBot class AutoFishing : ChatBot
{ {
private Dictionary<int, Entity> fishingRod = new Dictionary<int, Entity>(); private Entity fishingRod;
private Double fishingHookThreshold = 0.2; private Double fishingHookThreshold = 0.2;
private Location LastPos = new Location(); private Location LastPos = new Location();
private DateTime CaughtTime = DateTime.Now; private DateTime CaughtTime = DateTime.Now;
private bool inventoryEnabled; private bool inventoryEnabled;
private bool isFishing = false;
public override void Initialize() public override void Initialize()
{ {
@ -30,15 +31,31 @@ namespace MinecraftClient.ChatBots
public override void OnEntitySpawn(Entity entity) public override void OnEntitySpawn(Entity entity)
{ {
if (entity.TypeID == 102) if (entity.TypeID == 102)
{
if (Entity.CalculateDistance(GetCurrentLocation(), entity.Location) < 2 && !isFishing)
{ {
ConsoleIO.WriteLine("Threw a fishing rod"); ConsoleIO.WriteLine("Threw a fishing rod");
fishingRod.Add(entity.ID, entity); fishingRod = entity;
LastPos = entity.Location; LastPos = entity.Location;
isFishing = true;
}
}
}
public override void OnEntityDespawn(Entity entity)
{
if(entity.TypeID == 102)
{
if(entity.ID == fishingRod.ID)
{
isFishing = false;
}
} }
} }
public override void OnEntityMove(Entity entity) public override void OnEntityMove(Entity entity)
{ {
if (fishingRod.ContainsKey(entity.ID)) if (isFishing)
{
if (fishingRod.ID == entity.ID)
{ {
Location Pos = entity.Location; Location Pos = entity.Location;
Double Dx = LastPos.X - Pos.X; Double Dx = LastPos.X - Pos.X;
@ -59,7 +76,8 @@ namespace MinecraftClient.ChatBots
} }
} }
} }
fishingRod[entity.ID] = entity; fishingRod = entity;
}
} }
} }
@ -68,14 +86,14 @@ namespace MinecraftClient.ChatBots
/// </summary> /// </summary>
public void OnCaughtFish() public void OnCaughtFish()
{ {
ConsoleIO.WriteLine("Caught a fish!"); ConsoleIO.WriteLine(GetTimestamp()+": Caught a fish!");
// retract fishing rod // retract fishing rod
UseItemOnHand(); UseItemOnHand();
if (inventoryEnabled) if (inventoryEnabled)
{ {
if (!hasFishingRod()) if (!hasFishingRod())
{ {
ConsoleIO.WriteLine("No Fishing Rod on hand. Maybe broken?"); ConsoleIO.WriteLine(GetTimestamp() + ": No Fishing Rod on hand. Maybe broken?");
return; return;
} }
} }