MCCTeam / Minecraft-Console-Client

Lightweight console for Minecraft chat and automated scripts
https://mccteam.github.io
Other
1.67k stars 402 forks source link

Sugar Cane farm #1871

Closed D4W3-GS closed 2 years ago

D4W3-GS commented 2 years ago

Prerequisites

Console Client Version

Latest

Describe your problem

Hi,

I play on minecraft server where farming is very important. I want to automize my sugar cane farm with console client bot. I only find scripts where u must define x, y and z where the sugar cane is, but in my case its imposible. (screen: https://paste.sk/FfmTze)

Can u somehow help me?

Suggest a possible solution

No response

Attach screenshot here (If applicable)

https://paste.sk/FfmTze

Minecraft Version

1.16.5

Device

VPS

Operating System

Linux

xXjojaXx commented 2 years ago

In a chatbot you could use List<Location> sugarcanes = GetWorld().FindBlock(GetCurrentLocation(), Material.SugarCane, 20) to get the location of all sugarcane blocks in a radius of 20 blocks. Then you could iterate over them and break them as normal: foreach (Location sugarcane in sugarcanes) { ... (Normal breaking Code) } As always this solution isn't tested and could contain typing/capitalizing errors. I hope I could help you.

D4W3-GS commented 2 years ago

Oh,

I'm little bit stupid and I don't know how to write some script in C. Can u help me also with it?

xXjojaXx commented 2 years ago

Don't worry, not everone has to be able to do everything. First of all you have to use c#, which means you have to start by creating an file of type cs (ex. "SugarCane.cs" instead of "SugarCane.txt"). Then you have to create an mcc ChatBot within it using the code you found and the code i have shown you above, which means you should have the following in the file you created: Coming soon - don' t have enough time rn

Daenges commented 2 years ago

If I am allowed to give some inspiration:

        /// <summary>
        /// This function returns all sugar cane blocks that are above another sugar cane
        /// or optionally between two
        /// </summary>
        /// <param name="radius">Radius that should be checked</param>
        /// <param name="fullGrown">Only return positions of sugar cane that are 3 high</param>
        /// <returns>List of sugar cane blocks to break</returns>

        private List<Location> collectSugarCaneBlocks(int radius, bool fullGrown = true) 
        {
            return GetWorld().FindBlock(GetCurrentLocation(), Material.SugarCane, radius).Where(block =>
                (GetWorld().GetBlock(new Location(block.X, block.Y + 1, block.Z)).Type == Material.SugarCane || !fullGrown) &&
                GetWorld().GetBlock(new Location(block.X, block.Y - 1, block.Z)).Type == Material.SugarCane).ToList();
        }

I wrote a function which returns every sugar cane block that is at least above another one in a given radius. With the fullGrown parameter you can specify wheather only 3 high formations should be returned.

Further inspiration can be found here, where I made a script to dig up cubes.

If you combine both the bot can scan for grown sugar cane, walk to it and mine it fully autonomous.

ORelio commented 2 years ago

Just go on the server, walk in the sugar cane, disconnect, connect with mcc, run /move get and you'll know the coordinates. Of course improving the bot to automatically farm nearby sugar canes is also cool :)

xXjojaXx commented 2 years ago

If I am allowed to give some inspiration:

        /// <summary>
        /// This function returns all sugar cane blocks that are above another sugar cane
        /// or optionally between two
        /// </summary>
        /// <param name="radius">Radius that should be checked</param>
        /// <param name="fullGrown">Only return positions of sugar cane that are 3 high</param>
        /// <returns>List of sugar cane blocks to break</returns>

        private List<Location> collectSugarCaneBlocks(int radius, bool fullGrown = true) 
        {
            return GetWorld().FindBlock(GetCurrentLocation(), Material.SugarCane, radius).Where(block =>
                (GetWorld().GetBlock(new Location(block.X, block.Y + 1, block.Z)).Type == Material.SugarCane || !fullGrown) &&
                GetWorld().GetBlock(new Location(block.X, block.Y - 1, block.Z)).Type == Material.SugarCane).ToList();
        }

I wrote a function which returns every sugar cane block that is at least above another one in a given radius. With the fullGrown parameter you can specify wheather only 3 high formations should be returned.

Further inspiration can be found here, where I made a script to dig up cubes.

If you combine both the bot can scan for grown sugar cane, walk to it and mine it fully autonomous.

Very neat function you wrote above, appreciate it. I will combine it with another script to be able to farm completely automatically. But if you have more of your freetime left it also would be very nice if you could make an well written example Chatbot out of it. I think @D4W3-GS would need it as one piece since he doesn't seem to be far enough into programming to understand the code himself, yet. Thank you very much.

Daenges commented 2 years ago

@xXjojaXx @ORelio well although it seems easy it is not actually. In the cube mining script I experienced that terrain handling including mining and walking works very inconsistent.

Debugging it is a GIANT PAIN.

Sometimes I execute a MoveTo() command and it simply does not execute the walking process. Meanwhile the /move command works perfectly fine. I noticed that even my cubemine script is not breaking blocks correctly anymore. This is how far I got up to this point. Currently the client is neither breaking blocks, nor moving.

xXjojaXx commented 2 years ago

@xXjojaXx @ORelio well although it seems easy it is not actually. In the cube mining script I experienced that terrain handling including mining and walking works very inconsistent.

Debugging it is a GIANT PAIN.

Sometimes I execute a MoveTo() command and it simply does not execute the walking process. Meanwhile the /move command works perfectly fine. I noticed that even my cubemine script is not breaking blocks correctly anymore. This is how far I got up to this point. Currently the client is neither breaking blocks, nor moving.

I know, it's the same with Inventory Handling sometimes. Debugging can be a real pain in some cases. I never thought that it's gonna be easy to do and I'm very grateful you have started working on it. Do you have a clue about what the current issue could be? Nothing suspicious from my point of view. Unfortunately I don't have time to run through a trial and error process with my computer right now.

Daenges commented 2 years ago

@xXjojaXx EDIT: I found a bug in my code and I got the movement working. Lets see if I can make the block breaking work.

Daenges commented 2 years ago

@xXjojaXx So since the digging is kind of strange, I fired up my cubemine script and apparantly it also fails on the digging task: Click for Video.

Apparently the block mining function is broken? I tried to do this:

        private void digBlockBelow()
        {
            var loc = new Location(GetCurrentLocation().X, GetCurrentLocation().Y - 1, GetCurrentLocation().Z);
            LogToConsole(string.Format("Mine: X:{0}, Y:{1}, Z:{2}", loc.X, loc.Y, loc.Z));
            DigBlock(loc);
        }

And the bot only swang the pickaxe once without anything happening.

xXjojaXx commented 2 years ago

@Daenges Was the result returned by DigBlock() true?

Daenges commented 2 years ago

@xXjojaXx Yep.

xXjojaXx commented 2 years ago

@Daenges Mmhh, sry I don't get it. ~That should only happen if the server replies that the Block was successfully broken, right?~ Also which version are you using for testing?

ReinforceZwei commented 2 years ago

Returning true from DigBlock() doesn't mean the block have been broke on the server, but indicating the packet was successfully sent to the server. To confirm whether the block have been mined, listen for the block change and multi block change packets.

Daenges commented 2 years ago

@xXjojaXx I am using a 1.16.5 paper server, since it is the latest version with terrain handling. (Recently updated to the newest available paper version, but this should not break the bot.)

@ReinforceZwei thank you for this information. I previously solved this problem with just waiting until the coordinate of the block I am breaking is filled with air, but this looks way more elegant.

Unfortunately this does not solve the problem, that the block is not breaking in the first place.

xXjojaXx commented 2 years ago

Did you have a look at the MCC Code and if it's even working correctly, because the Packet for PlayerDigging has changed (or at least the id) between the older version 1.8.9(v47) and 1.16.4. Maybe you could try to test on another version first, if nothing else coming to your mind is solving your issue.

Daenges commented 2 years ago

@xXjojaXx I programmed the script on the same version (1.16.5 a few months ago). Nothing changed except the paper version and a newer MCC version.

Daenges commented 2 years ago

@xXjojaXx Found the issue. **Astronomous facepalm** I reset the spawn area to my testing ground, because I was playing around with the /move north -f command and was annoyed that the client always spawned somewhere else and I needed to teleport it after every test. So apparently servers have a range of protection around the spawn of a few chunks. This means that non OP players (e.g. the bot) are unable to mine in this radius (16 chunks default, also the reason why it failed everywhere I tried it). And since no Plugin is preventing this, you will not even get a message. -_-

xXjojaXx commented 2 years ago

That's why debugging is so annoying. There is always a new issue coming up, you didn't even knew about before. But well done, I'm excited about your final product😉

Daenges commented 2 years ago

@xXjojaXx Bot finished. You can get the script from my pull request.

xXjojaXx commented 2 years ago

@Daenges Thanks for your great work! I assume @D4W3-GS will be as happy with your work as me and this issue can be closed ; )

milutinke commented 2 years ago

Implemented in #1882