Skip to content

Commit

Permalink
added basic MineBlock() and PlaceBlock() methods
Browse files Browse the repository at this point in the history
  • Loading branch information
psu-de committed Nov 25, 2023
1 parent 1465ece commit 9ed06ae
Show file tree
Hide file tree
Showing 10 changed files with 38 additions and 13 deletions.
8 changes: 4 additions & 4 deletions .github/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Inspired by [Mineflayer](https://github.com/PrismarineJS/mineflayer).

If you're interested in this project, feel free to contribute!

Because of the rework, all versions from 1.18-1.20.1 are supported!
Minecraft Java 1.18 - 1.20.1 supported

# Current features

Expand All @@ -22,10 +22,10 @@ Because of the rework, all versions from 1.18-1.20.1 are supported!
- ⚡ Events
- 🐖 Entity tracking
- 🌍 World tracking (query the world for blocks)
- ~~⛏️ Mining~~
- ~~👷‍♂️ Building~~
- ⛏️ Mining (very simple, needs some more work)
- 👷‍♂️ Building (very simple, needs some more work)
- ~~🛠️ Crafting~~
- 🪟 High-Level window api (needs some more work)
- 🪟 High-Level window Api
- ~~⚔️ Attacking entities~~
- ~~🏃 Movements (Walking, Sprinting, Jumping, Sneaking)~~
- ~~🔎 Simple Pathfinder~~
Expand Down
6 changes: 3 additions & 3 deletions MineSharp.Bot.IntegrationTests/Program.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
using MineSharp.Bot.IntegrationTests.Tests;

await WorldTests.TestPlaceBlock();
Environment.Exit(0);

await PlayerTests.TestHealth();
await PlayerTests.TestDeath();
await PlayerTests.TestRespawn();
Expand All @@ -14,3 +11,6 @@

await WindowTests.TestInventoryUpdate();
await WindowTests.TestOpenContainer();

await WorldTests.TestPlaceBlock();
await WorldTests.TestMineBlock();
4 changes: 2 additions & 2 deletions MineSharp.Bot.IntegrationTests/TestServer/server.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#Minecraft server properties
#Thu Nov 23 21:31:48 UTC 2023
#Sat Nov 25 16:33:00 UTC 2023
enable-jmx-monitoring=false
rcon.port=25575
level-seed=
Expand Down Expand Up @@ -38,7 +38,7 @@ hide-online-players=false
resource-pack=
entity-broadcast-range-percentage=100
simulation-distance=10
rcon.password=488ce3b32438f9d21bbff5fc
rcon.password=48ff80c3aa9ac6da1071caf9
player-idle-timeout=0
force-gamemode=false
rate-limit=0
Expand Down
Binary file not shown.
Binary file not shown.
Binary file modified MineSharp.Bot.IntegrationTests/TestServer/world/data/raids.dat
Binary file not shown.
Binary file not shown.
Binary file modified MineSharp.Bot.IntegrationTests/TestServer/world/level.dat
Binary file not shown.
Binary file modified MineSharp.Bot.IntegrationTests/TestServer/world/level.dat_old
Binary file not shown.
33 changes: 29 additions & 4 deletions MineSharp.Bot.IntegrationTests/Tests/WorldTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using MineSharp.Bot.Plugins;
using MineSharp.Core.Common;
using System.Collections.Concurrent;
using MineSharp.Bot.Chat;

namespace MineSharp.Bot.IntegrationTests.Tests;

Expand Down Expand Up @@ -58,16 +59,27 @@ public static Task TestMineBlock()
await bot.World!.WaitForChunks();

var position = new Position(-8, -59, 20);

await bot.Chat!.SendChat("/tp @p -5 -60 20");

bot.Chat!.OnChatMessageReceived += (sender, player, message, type, senderName) =>
{
if (type != ChatMessageType.GameInfo)
return;

var chat = new MineSharp.Core.Common.Chat(message);
if (chat.Message == "testMineBlock success")
{
source.TrySetResult(true);
}
};

await Task.Delay(1000);

var result = await bot.World.MineBlock(
bot.World!.World!.GetBlockAt(position));

Console.WriteLine(result);

source.TrySetResult(result == MineBlockStatus.Finished);
if (result != MineBlockStatus.Finished)
source.TrySetResult(false);
}, commandDelay: 1000);
}

Expand All @@ -81,6 +93,19 @@ public static Task TestPlaceBlock()
await bot.Chat!.SendChat("/tp @p -5 -60 20");
await bot.Chat!.SendChat("/clear");
await bot.Chat!.SendChat("/give @p dirt");

bot.Chat!.OnChatMessageReceived += (sender, player, message, type, senderName) =>
{
if (type != ChatMessageType.GameInfo)
return;

var chat = new MineSharp.Core.Common.Chat(message);
if (chat.Message == "testPlaceBlock success")
{
source.TrySetResult(true);
}
};

await Task.Delay(1000);
await bot.World!.PlaceBlock(position);
});
Expand Down

0 comments on commit 9ed06ae

Please sign in to comment.