I am Paul Sütterlin. Currently I am studying Computer Science at Karlsruhe Institute of Technology - KIT. I love learning new technologies and connect with other developers.
I'm also very interested in AI and automation
High-Level async API to build minecraft bots.
License: MIT License
at least can you put it on it as a prerelease? I need it
The Pathfinder has the following abilities:
Currently the pathfinder only uses WASD movement, not rotation with the mouse. However sprinting only works for 'W' (forward) movement, so I will try to update this at least for jumping over multiple blocks.
Moves I want to add:
Also the ability to dynamically update a Goal and a Path is quite useful and will be added at some point.
[ERROR][15:00:59][Protocol ] > Error in readLoop: System.Threading.Tasks.TaskCanceledException: A task was canceled. at MineSharp.Protocol.MinecraftClient.StreamLoop() in ******************* at MinecraftClient.cs:line 243
Is the game mode enum correct? I have a simple bot that automatically switches to spectator mode at night time, something like:
if (currentTime is >= 12_542 and <= 23_459)
{
if (player.GameMode is not GameMode.Spectator)
{
await chat.SendCommand("gamemode spectator");
}
}
This correctly sets the game mode, but the issue is that it runs the command every time through the loop, because player.GameMode
reports as GameMode.Adventure
not GameMode.Spectator
.
Are these final two values correct, or should they be 2 and 3?
MineSharp/MineSharp.Core/Common/GameMode.cs
Lines 18 to 26 in 091d617
Update Game Mode
doesn't have any notes here: https://wiki.vg/Protocol#Player_Info_Update but other sections have it defined, like here https://wiki.vg/Protocol#Game_Event
3 Change game mode 0: Survival, 1: Creative, 2: Adventure, 3: Spectator.
How can I make the bot get an item from the creative inventory?
I tried these:
ItemInfo diamond = bot.Data.Items.ByName("diamond")!;
bot.GetPlugin<WindowPlugin>().Inventory!.SetSlot(new Slot(new Item(diamond, 1, null, null), 1));
and also this
ItemInfo diamond = bot.Data.Items.ByName("diamond")!;
Window mainInventory = new Window(255, "", 4 * 9, null, null);
Window inventory = new Window(0, "Inventory", 9, mainInventory, null);
inventory.SetSlot(new Slot(new Item(diamond, 1, null, null), 1));
but both don't work
also how does mining work?
when I do
Block b = worldPl.World.GetBlockAt(new Position(x, y, z));
await worldPl.MineBlock(b, BlockFace.Top);
nothing happens
Currently only Mojang accounts are supported.
Make all Vector3
, Position
and AABB
instances immutable by default, and add a class for mutable instances.
Unexpected and undefined behavior can be introduced quite easily currently, and its hard to spot the problem. Often it is also unclear why you shouldn't use a method.
List of problems:
SetSlot
methods for Windows. (Unsafe to use for MineSharp.Bot windows)Sometimes when a client is running for some time, the PacketFactory throws an Exception like this:
System.NullReferenceException HResult=0x80004003 Message= Object reference not set to an instance of an object. Source= MineSharp.Protocol Stack Trace: at MineSharp.Protocol.PacketFactory.WritePacket(IPacketPayload packet) in ...\MineSharp\Components\MineSharp.Protocol\PacketFactory.cs: Zeile103
Apparently after a while null
is sent as a packet, but I have no idea why this happens...
for now if the packet is null it will just be ignored
When I updated minecraft-data to the latest version, and regenerated the source files, the following error occures when starting the bot:
[ERROR][16:43:44][Protocol ] > Error reading packet!
[ERROR][16:43:44][Protocol ] > System.Exception: Invalid value: 'minecraft:nbt_tag'
at MineSharp.Data.Protocol.CommandNode.ExtraNodeDataSwitch.ExtraNodeDataSwitchState2Container.PropertiesSwitch.Read(PacketBuffer buffer, String state) in D:\MineSharp\Data\MineSharp.Data\Protocol.cs:line 1738
at MineSharp.Data.Protocol.CommandNode.ExtraNodeDataSwitch.ExtraNodeDataSwitchState2Container.<>c__DisplayClass20_0.<Read>b__2(PacketBuffer buffer) in D:\MineSharp\Data\MineSharp.Data\Protocol.cs:line 1803
at MineSharp.Data.Protocol.CommandNode.ExtraNodeDataSwitch.ExtraNodeDataSwitchState2Container.Read(PacketBuffer buffer, FlagsBitfield flags) in D:\MineSharp\Data\MineSharp.Data\Protocol.cs:line 1803
at MineSharp.Data.Protocol.CommandNode.ExtraNodeDataSwitch.<>c__DisplayClass8_0.<Read>b__2(PacketBuffer buffer) in D:\MineSharp\Data\MineSharp.Data\Protocol.cs:line 1824
at MineSharp.Data.Protocol.CommandNode.ExtraNodeDataSwitch.Read(PacketBuffer buffer, Byte state, FlagsBitfield flags) in D:\MineSharp\Data\MineSharp.Data\Protocol.cs:line 1824
at MineSharp.Data.Protocol.CommandNode.<>c__DisplayClass21_0.<Read>b__3(PacketBuffer buffer) in D:\MineSharp\Data\MineSharp.Data\Protocol.cs:line 1854
at MineSharp.Data.Protocol.CommandNode.Read(PacketBuffer buffer) in D:\MineSharp\Data\MineSharp.Data\Protocol.cs:line 1854
at MineSharp.Data.Protocol.Play.Clientbound.PacketDeclareCommands.<>c.<Read>b__10_3(PacketBuffer buffer) in D:\MineSharp\Data\MineSharp.Data\Protocol.cs:line 4091
at MineSharp.Data.Protocol.PacketBuffer.ReadArray[T](Int32 length, Func`2 reader) in D:\MineSharp\Data\MineSharp.Data\Protocol.cs:line 255
at MineSharp.Data.Protocol.Play.Clientbound.PacketDeclareCommands.<>c.<Read>b__10_0(PacketBuffer buffer) in D:\MineSharp\Data\MineSharp.Data\Protocol.cs:line 4091
at MineSharp.Data.Protocol.Play.Clientbound.PacketDeclareCommands.Read(PacketBuffer buffer) in D:\MineSharp\Data\MineSharp.Data\Protocol.cs:line 4091
at MineSharp.Data.Protocol.Play.Clientbound.Packet.ParamsSwitch.<>c.<Read>b__6_15(PacketBuffer buffer) in D:\MineSharp\Data\MineSharp.Data\Protocol.cs:line 7301
at MineSharp.Data.Protocol.Play.Clientbound.Packet.ParamsSwitch.Read(PacketBuffer buffer, String state) in D:\MineSharp\Data\MineSharp.Data\Protocol.cs:line 7301
at MineSharp.Data.Protocol.Play.Clientbound.Packet.<>c__DisplayClass11_0.<Read>b__1(PacketBuffer buffer) in D:\MineSharp\Data\MineSharp.Data\Protocol.cs:line 7615
at MineSharp.Data.Protocol.Play.Clientbound.Packet.Read(PacketBuffer buffer) in D:\MineSharp\Data\MineSharp.Data\Protocol.cs:line 7615
at MineSharp.Data.Protocol.Play.Clientbound.PlayPacketFactory.ReadPacket(PacketBuffer buffer) in D:\MineSharp\Data\MineSharp.Data\Protocol.cs:line 7621
at MineSharp.Protocol.PacketFactory.BuildPacket(Byte[] data, Int32 uncompressedLength) in D:\MineSharp\Components\MineSharp.Protocol\PacketFactory.cs:line 74
When trying to obtain a new online session for a new email for the first time, this exception is thrown.
The session however is saved and it works the next time.
Unhandled exception. System.FormatException: String '2024-02-22T15:56:54.142272440Z' was not recognized as a valid DateTime.
at System.DateTime.ParseExact(String s, String format, IFormatProvider provider)
at MineSharp.Auth.Responses.PlayerCertificate.FromBlob(CertificateBlob blob) in /_/Components/MineSharp.Auth/Responses/PlayerCertificate.cs:line 83
at MineSharp.Auth.MinecraftApi.FetchCertificates(String token) in /_/Components/MineSharp.Auth/MinecraftApi.cs:line 98
at MineSharp.Auth.MicrosoftAuth.Login(String username, DeviceCodeHandler handler, MinecraftApi api) in /_/Components/MineSharp.Auth/MicrosoftAuth.cs:line 92
at MineSharp.Bot.BotBuilder.CreateAsync() in /_/MineSharp.Bot/BotBuilder.cs:line 228
at Program.<Main>$(String[] args) in /home/psu/projects/Testing/MineSharpNugetTests/MineSharpNugetTests/Program.cs:line 6
at Program.<Main>(String[] args)
The pathfinder module is currently very simple.
Currently, it only supports walking in each direction (not diagonal). Also it can only find a path to a goal that is on the same Y-Level.
Some ToDo's to make it more usable:
The chat is currently a little bit weird and not properly implemented.
Not everytime, but often when handling MultiBlockUpdate Packets, an exception like this is thrown:
There occurred an error while handling the packet: System.IndexOutOfRangeException: Index was outside the bounds of the array. at MineSharp.World.World.MultiblockUpdate(Int64[] blocks, Int32 cX, Int32 cY, Int32 cZ) in ...\MineSharp\Components\MineSharp.World\World.cs:line 60 at MineSharp.Bot.Modules.WorldModule.handleMultiBlockChange(PacketMultiBlockChange packet) in ...\MineSharp\MineSharp.Bot\Modules\WorldModule.cs:line 61 at MineSharp.Bot.MinecraftBot.<>c__DisplayClass126_01.<On>b__1(IPacketPayload p) in ...\MineSharp\MineSharp.Bot\MinecraftBot.cs:line 167 at MineSharp.Bot.MinecraftBot.Events_PacketReceived(MinecraftClient client, IPacketPayload packet) in ...\MineSharp\MineSharp.Bot\MinecraftBot.cs:line 185 at MineSharp.Protocol.MinecraftClient.<>c__DisplayClass53_0.<StreamLoop>b__1(Object _) in ...\MineSharp\Components\MineSharp.Protocol\MinecraftClient.cs:line 188
In 1.20.3 and 1.20.4, the Connect()
method sometimes never resolves.
I think this is because of the PhysicsPlugin
, which calls await WorldPlugin.WaitForChunks()
, which never resolves because the client does not received any chunks.
My guess is that the bot messes up the ChunkBatchReceivedPacket
packet with a ChunksPerTick of 0, so the server never sends any chunks again.
Edit: The bug also occurs in 1.20.1. The PlayerPlugin never finishes initialization.
Once logged in to a Microsoft account, MineSharp is always using this account (at least on Linux), no matter what account identifier provided.
I'm pretty sure it worked on Windows when I first implemented it, but now on Linux it doesn't work.
I studied roughly how your program works and was very surprised. It seems to me, but maybe packet read and write methods would create a lot of overhead. Why didn't you just create an IPacket interface with Read and Write methods?
See how it can be made simpler in my library.
Hi.
So im actually making my own minecraft client based on MineSharp and i would love to ask.
Can you guys please implement 1.19 and bedrock suport? Bedrock is easy cause ConcreteMC/Alex already has it.
But about 1.19. Why did no one implement it yet? Is it because of missing docs or what?
Also I would love to collab to add some more features.
Please continue this conversation using e-mail or discord:
- Email: [email protected]
- Discord: ItsRedly#1174
Thank you.
MineSharp.Data downloads json files for a specific version when it's first loaded. But them as well as the dataPaths.json file are never refreshed.
Currently minesharp compiles every version data to MimeSharp.Data, which makes the compiled output bigger than it's needs. If we use preprocessor directives to declare version at compile time, the compiler won't include all version data to compiled output, which makes the output smaller.
We can also take advantage of this to create version specific features so we can have the unnecessary features of a specific version not to compile. This makes the code will potentially run faster because the if checks at runtime is already gone on versions thst if check is unnecessary on.
Hello,
Really like the project and the command line interface with autocomplete is very cool. Just having an issue with move Forward
for example.
An error occurred while performing command!
System.InvalidOperationException: Collection was modified; enumeration operation may not execute.
at bool System.Collections.Generic.List`1.Enumerator.MoveNext()
at void MineSharp.ConsoleClient.Console.Commands.Misc.BotLogCommand.DoAction(string[] argv, CancellationToken
Since the new protocol data, when an WindowItems Packet is received, the following exception is thrown:
[INFO ][20:41:13][Bot ] > Initialized Player entity: Location=(-129,5 / 68,12482421918145 / -57,5) [ERROR][20:41:13][Protocol ] > There occured an error while handling the packet: System.IndexOutOfRangeException: Index was outside the bounds of the array. at MineSharp.Windows.Window.SetSlot(Slot slot) in E:\Programming\MineSharp\Components\MineSharp.Windows\Window.cs:line 106 at MineSharp.Windows.Window.UpdateSlots(Slot[] slotData) in E:\Programming\MineSharp\Components\MineSharp.Windows\Window.cs:line 127 at MineSharp.Bot.Modules.WindowsModule.handleWindowItems(PacketWindowItems packet) in E:\Programming\MineSharp\MineSharp.Bot\Modules\WindowsModule.cs:line 166 at MineSharp.Bot.MinecraftBot.<>c__DisplayClass126_01.<On>b__1(IPacketPayload p) in E:\Programming\MineSharp\MineSharp.Bot\MinecraftBot.cs:line 167 at MineSharp.Bot.MinecraftBot.Events_PacketReceived(MinecraftClient client, IPacketPayload packet) in E:\Programming\MineSharp\MineSharp.Bot\MinecraftBot.cs:line 185 at MineSharp.Protocol.MinecraftClient.<>c__DisplayClass54_0.<<streamLoop>b__1>d.MoveNext() in E:\Programming\MineSharp\Components\MineSharp.Protocol\MinecraftClient.cs:line 201
Probably because MineSharp.Data.Protocol.Slot.ToSlot()
just sets SlotNumber to -1
it's actually not sometimes, it's most of the time. it happens a lot so I can't even detect when the bot is disconnected.
A lot of errors thrown when connecting to 1.20.2 server.
Not yet tested with 1.20.3+
MineSharp.Commands can only read the command tree for versions after 1.19.
Edit: Only works in 1.19-1.20.2
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.