From 730990cee5d55e25c8b7be5e45c2b99621d94940 Mon Sep 17 00:00:00 2001 From: Milutinke Date: Tue, 18 Oct 2022 22:39:48 +0200 Subject: [PATCH] Switched to a faster implementation of FindBlock proposed by Daenges, tested on Farmer Bot. Tweaked the amount of bone mealing in the Farmer Bot. --- MinecraftClient/ChatBots/Farmer.cs | 2 +- MinecraftClient/Mapping/World.cs | 30 ++++++++++-------------------- 2 files changed, 11 insertions(+), 21 deletions(-) diff --git a/MinecraftClient/ChatBots/Farmer.cs b/MinecraftClient/ChatBots/Farmer.cs index 7ac5262d..52b3f8ee 100644 --- a/MinecraftClient/ChatBots/Farmer.cs +++ b/MinecraftClient/ChatBots/Farmer.cs @@ -420,7 +420,7 @@ namespace MinecraftClient.ChatBots LogDebug("Trying to bonemeal: " + location2); // Send like 4 bonemeal attempts, it should do the job with 2-3, but sometimes doesn't do - for (int boneMealTimes = 0; boneMealTimes < 4; boneMealTimes++) + for (int boneMealTimes = 0; boneMealTimes < (cropType == CropType.Beetroot ? 6 : 5); boneMealTimes++) { // TODO: Do a check if the carrot/potato is on the first growth stage // if so, use: new Location(location.X, (double)(location.Y - 1) + (double)0.93750, location.Z) diff --git a/MinecraftClient/Mapping/World.cs b/MinecraftClient/Mapping/World.cs index 0e9a3241..25908155 100644 --- a/MinecraftClient/Mapping/World.cs +++ b/MinecraftClient/Mapping/World.cs @@ -169,26 +169,16 @@ namespace MinecraftClient.Mapping /// Block matching the specified block type public List FindBlock(Location from, Material block, int radiusx, int radiusy, int radiusz) { - Location minPoint = new(from.X - radiusx, from.Y - radiusy, from.Z - radiusz); - Location maxPoint = new(from.X + radiusx, from.Y + radiusy, from.Z + radiusz); - List list = new() { }; - for (double x = minPoint.X; x <= maxPoint.X; x++) - { - for (double y = minPoint.Y; y <= maxPoint.Y; y++) - { - for (double z = minPoint.Z; z <= maxPoint.Z; z++) - { - Location doneloc = new(x, y, z); - Block doneblock = GetBlock(doneloc); - Material blockType = doneblock.Type; - if (blockType == block) - { - list.Add(doneloc); - } - } - } - } - return list; + Location minPoint = new Location(from.X - radiusx, from.Y - radiusy, from.Z - radiusz); + Location maxPoint = new Location(from.X + radiusx, from.Y + radiusy, from.Z + radiusz); + + List xRange = Enumerable.Range(Convert.ToInt32(Math.Floor(minPoint.X)), Convert.ToInt32(Math.Floor(maxPoint.X - minPoint.X)) + 1).ToList(); + List yRange = Enumerable.Range(Convert.ToInt32(Math.Floor(minPoint.Y)), Convert.ToInt32(Math.Floor(maxPoint.Y - minPoint.Y)) + 1).ToList(); + List zRange = Enumerable.Range(Convert.ToInt32(Math.Floor(minPoint.Z)), Convert.ToInt32(Math.Floor(maxPoint.Z - minPoint.Z)) + 1).ToList(); + + List listOfBlocks = xRange.SelectMany(x => yRange.SelectMany(y => zRange.Select(z => new Location(x, y, z)))).ToList(); + + return listOfBlocks.Where(loc => GetBlock(loc).Type == block).ToList(); } ///