From b1121e91e301001cdcb5547e3f9df7ddd60394c0 Mon Sep 17 00:00:00 2001 From: ReinforceZwei <39955851+ReinforceZwei@users.noreply.github.com> Date: Wed, 8 Apr 2020 18:42:37 +0800 Subject: [PATCH] Add Item type extension --- MinecraftClient/ChatBots/AutoEat.cs | 2 +- .../Inventory/ItemTypeExtensions.cs | 52 +++++++++++++++++++ MinecraftClient/MinecraftClient.csproj | 1 + 3 files changed, 54 insertions(+), 1 deletion(-) create mode 100644 MinecraftClient/Inventory/ItemTypeExtensions.cs diff --git a/MinecraftClient/ChatBots/AutoEat.cs b/MinecraftClient/ChatBots/AutoEat.cs index 1b058c0d..1b1616b9 100644 --- a/MinecraftClient/ChatBots/AutoEat.cs +++ b/MinecraftClient/ChatBots/AutoEat.cs @@ -50,7 +50,7 @@ namespace MinecraftClient.ChatBots Container inventory = GetPlayerInventory(); bool found = false; LastSlot = CurrentSlot; - if (inventory.Items.ContainsKey(CurrentSlot + 36) && inventory.Items[CurrentSlot + 36].IsFood()) + if (inventory.Items.ContainsKey(CurrentSlot + 36) && ItemTypeExtensions.IsFood(inventory.Items[CurrentSlot + 36].Type)) { // no need to change slot found = true; diff --git a/MinecraftClient/Inventory/ItemTypeExtensions.cs b/MinecraftClient/Inventory/ItemTypeExtensions.cs new file mode 100644 index 00000000..2c448a57 --- /dev/null +++ b/MinecraftClient/Inventory/ItemTypeExtensions.cs @@ -0,0 +1,52 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace MinecraftClient.Inventory +{ + public static class ItemTypeExtensions + { + /** + * I see "this" in the MaterialExtensions class method, why need that? + * public static bool IsSolid(this Material m) + * ^^^^ + */ + public static bool IsFood(ItemType m) + { + ItemType[] t = + { + ItemType.Apple, + ItemType.BakedPotato, + ItemType.Beetroot, + ItemType.Bread, + ItemType.Carrot, + ItemType.CookedChicken, + ItemType.CookedCod, + ItemType.CookedMutton, + ItemType.CookedPorkchop, + ItemType.CookedRabbit, + ItemType.CookedSalmon, + ItemType.Cookie, + ItemType.DriedKelp, + ItemType.EnchantedGoldenApple, + ItemType.GoldenApple, + ItemType.GoldenCarrot, + ItemType.MelonSlice, + ItemType.Potato, + ItemType.PumpkinPie, + ItemType.Beef, + ItemType.Chicken, + ItemType.Cod, + ItemType.Mutton, + ItemType.Porkchop, + ItemType.Rabbit, + ItemType.Salmon, + ItemType.CookedBeef, + ItemType.SweetBerries, + ItemType.TropicalFish + }; + return t.Contains(m); + } + } +} diff --git a/MinecraftClient/MinecraftClient.csproj b/MinecraftClient/MinecraftClient.csproj index 80731ca5..b13b53a3 100644 --- a/MinecraftClient/MinecraftClient.csproj +++ b/MinecraftClient/MinecraftClient.csproj @@ -108,6 +108,7 @@ +