Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 45 additions & 4 deletions MinecraftClient/ChatBots/Farmer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public enum CropType

public override void Initialize()
{
if (GetProtocolVersion() < Protocol18Handler.MC_1_13_Version)
if (GetProtocolVersion() < Protocol18Handler.MC_1_8_Version)
{
LogToConsole(Translations.bot_farmer_not_implemented);
return;
Expand Down Expand Up @@ -616,16 +616,19 @@ private List<Location> findCrops(int radius, CropType cropType, bool fullyGrown)
if (fullyGrown && material is Material.Melon or Material.Pumpkin)
return true;

var isFullyGrown = IsCropFullyGrown(GetWorld().GetBlock(location), cropType);
var isFullyGrown = IsCropFullyGrown(GetWorld().GetBlock(location), cropType, location);
return fullyGrown ? isFullyGrown : !isFullyGrown;
})
.ToList();
}

private bool IsCropFullyGrown(Block block, CropType cropType)
private bool IsCropFullyGrown(Block block, CropType cropType, Location? location = null)
{
var protocolVersion = GetProtocolVersion();

if (protocolVersion < Protocol18Handler.MC_1_13_Version)
return IsLegacyCropFullyGrown(block, cropType, location);

switch (cropType)
{
case CropType.Beetroot:
Expand Down Expand Up @@ -781,6 +784,44 @@ private bool IsCropFullyGrown(Block block, CropType cropType)
return false;
}

private bool IsLegacyCropFullyGrown(Block block, CropType cropType, Location? location)
{
return cropType switch
{
CropType.Beetroot => block.BlockId == 207 && block.BlockMeta >= 3,
CropType.Carrot => block.BlockId == 141 && block.BlockMeta >= 7,
CropType.Melon => block.BlockId == 105
&& (block.BlockMeta >= 7 || HasAdjacentBlock(location, Material.Melon)),
CropType.NetherWart => block.BlockId == 115 && block.BlockMeta >= 3,
CropType.Pumpkin => block.BlockId == 104
&& (block.BlockMeta >= 7 || HasAdjacentBlock(location, Material.Pumpkin)),
CropType.Potato => block.BlockId == 142 && block.BlockMeta >= 7,
CropType.Wheat => block.BlockId == 59 && block.BlockMeta >= 7,
_ => false
};
}

private bool HasAdjacentBlock(Location? location, Material material)
{
if (location is not Location stemLocation)
return false;

var world = GetWorld();
int x = (int)Math.Floor(stemLocation.X);
int y = (int)Math.Floor(stemLocation.Y);
int z = (int)Math.Floor(stemLocation.Z);

Location[] adjacentLocations =
[
new(x + 1, y, z),
new(x - 1, y, z),
new(x, y, z + 1),
new(x, y, z - 1)
];

return adjacentLocations.Any(adjacentLocation => world.GetBlock(adjacentLocation).Type == material);
}

// Yoinked from ReinforceZwei's AutoTree and adapted to search the whole of inventory in additon to the hotbar
private bool SwitchToItem(ItemType itemType)
{
Expand Down Expand Up @@ -854,4 +895,4 @@ private void LogDebug(object text)
else LogDebugToConsole(text);
}
}
}
}
1 change: 1 addition & 0 deletions MinecraftClient/Mapping/BlockPalettes/Palette112.cs
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ public class Palette112 : BlockPalette
{ 173, Material.CoalBlock },
{ 174, Material.PackedIce },
{ 175, Material.TallGrass }, // DoublePlant
{ 207, Material.Beetroots }, // BeetrootBlock
};

protected override Dictionary<int, Material> GetDict()
Expand Down
1 change: 1 addition & 0 deletions MinecraftClient/Protocol/Handlers/Protocol18.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5506,6 +5506,7 @@ public bool SendPlayerBlockPlacement(int hand, Location location, Direction face
packet.Add(0); // cursorY
packet.Add(0); // cursorZ

SendPacket(PacketTypesOut.PlayerBlockPlacement, packet);
return true;
case < MC_1_14_Version:
packet.AddRange(dataTypes.GetLocation(location));
Expand Down
2 changes: 1 addition & 1 deletion MinecraftClient/Resources/Translations/Translations.resx
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,7 @@ cooldown: {6}</value>
<value>The Farmer bot needs Terrain Handling in order to work, please enable it!</value>
</data>
<data name="bot.farmer.not_implemented" xml:space="preserve">
<value>Not implemented bellow 1.13!</value>
<value>Not implemented below 1.8!</value>
</data>
<data name="bot.farmer.radius" xml:space="preserve">
<value>Radius</value>
Expand Down
2 changes: 1 addition & 1 deletion docs/guide/chat-bots.md
Original file line number Diff line number Diff line change
Expand Up @@ -1957,7 +1957,7 @@ redirectFrom:

<div class="custom-container warning"><p class="custom-container-title">Warning</p>

**This a newly added bot, it is not perfect and was only tested in 1.19.2, there are some minor issues with it and you should treat it as an experimental bot.**
**This bot is still experimental, has some known issues, and should be treated with extra caution on legacy versions.**

</div>

Expand Down
2 changes: 1 addition & 1 deletion docs/guide/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,7 @@ Coordinate = { x = 145, y = 64, z = 2045 }

<div class="custom-container warning"><p class="custom-container-title">Warning</p>

**This feature is currently not supported in `1.4.6 - 1.9`. But we are working on getting it supported in 1.8 and 1.9.**
**This feature is currently supported on `1.8+` and is unavailable on `1.4.6 - 1.7.10`.**

</div>

Expand Down
6 changes: 3 additions & 3 deletions docs/guide/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -1016,7 +1016,7 @@ In scripts and remote control, no slash is needed to perform the command, eg. `q

<div class="custom-container warning"><p class="custom-container-title">Warning</p>

**The [Inventory Handling](configuration.md#inventoryhandling) is currently not supported in `1.4.6 - 1.9`**
**The [Inventory Handling](configuration.md#inventoryhandling) is currently supported on `1.8+` and is unavailable on `1.4.6 - 1.7.10`.**

</div>

Expand Down Expand Up @@ -1063,7 +1063,7 @@ In scripts and remote control, no slash is needed to perform the command, eg. `q

<div class="custom-container warning"><p class="custom-container-title">Warning</p>

**The [Inventory Handling](configuration.md#inventoryhandling) is currently not supported in `1.4.6 - 1.9`.**
**The [Inventory Handling](configuration.md#inventoryhandling) is currently supported on `1.8+` and is unavailable on `1.4.6 - 1.7.10`.**

</div>

Expand Down Expand Up @@ -1298,7 +1298,7 @@ In scripts and remote control, no slash is needed to perform the command, eg. `q

<div class="custom-container warning"><p class="custom-container-title">Warning</p>

**The [Inventory Handling](configuration.md#inventoryhandling) is currently not supported in `1.4.6 - 1.9`.**
**The [Inventory Handling](configuration.md#inventoryhandling) is currently supported on `1.8+` and is unavailable on `1.4.6 - 1.7.10`.**

</div>

Expand Down