Skip to content

Commit 134a2c8

Browse files
authored
Add block mining system (#43)
* Add digging * modify bat files. * add Position serialization. * add protocol packets. * add basic handling swing hand for player. * add basic handling PlayerDigging packet. * fix swing hand logic, rename animation packet classes. * fix errors * 添加 digging 响应 * 搞定 finished digging 广播 * 生成 pickup * 不会写 * 添加基本的捡东西 * 添加 block 放置
1 parent 8a337da commit 134a2c8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+1461
-101
lines changed

run_gateway.bat

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1-
cd src\MineCase.Gateway
1+
@echo off
2+
3+
echo start MineCase.Gateway...
4+
pushd src\MineCase.Gateway
25
start dotnet run
3-
pause
6+
popd

run_server.bat

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
1-
cd src
1+
@echo off
2+
3+
echo building MineCase...
4+
pushd src
25
dotnet restore
3-
dotnet build
6+
dotnet build -c debug
7+
popd
48

5-
cd MineCase.Server
9+
echo start MineCase.Server...
10+
pushd src\MineCase.Server
611
start dotnet run
7-
8-
pause
12+
echo run "run_gateway.bat" when server is ready.
13+
popd
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
namespace MineCase.Formats
2+
{
3+
public enum ClientboundAnimationId : byte
4+
{
5+
SwingMainArm = 0,
6+
TakeDamage = 1,
7+
LeaveBed = 2,
8+
SwingOffHand = 3,
9+
CriticalEffect = 4,
10+
MagicCriticalEffect = 5
11+
}
12+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Text;
4+
5+
namespace MineCase.Formats
6+
{
7+
public struct Position
8+
{
9+
public int X { get; set; }
10+
11+
public int Y { get; set; }
12+
13+
public int Z { get; set; }
14+
}
15+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Text;
4+
5+
namespace MineCase.Formats
6+
{
7+
public sealed class Slot
8+
{
9+
public static Slot Empty { get; } = new Slot();
10+
11+
public bool IsEmpty => BlockId == -1;
12+
13+
public short BlockId { get; set; } = -1;
14+
15+
public byte ItemCount { get; set; }
16+
17+
public short ItemDamage { get; set; }
18+
}
19+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
namespace MineCase.Formats
2+
{
3+
public enum SwingHandState : byte
4+
{
5+
MainHand = 0,
6+
OffHand = 1
7+
}
8+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Text;
4+
using MineCase.Serialization;
5+
using Orleans.Concurrency;
6+
7+
namespace MineCase.Protocol.Play
8+
{
9+
public enum Hand : uint
10+
{
11+
Main = 0,
12+
Off = 1
13+
}
14+
15+
[Immutable]
16+
[Packet(0x1D)]
17+
public sealed class ServerboundAnimation
18+
{
19+
[SerializeAs(DataType.VarInt)]
20+
public Hand Hand;
21+
22+
public static ServerboundAnimation Deserialize(ref SpanReader br)
23+
{
24+
return new ServerboundAnimation
25+
{
26+
Hand = (Hand)br.ReadAsVarInt(out _)
27+
};
28+
}
29+
}
30+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
using System.IO;
2+
using MineCase.Formats;
3+
using MineCase.Serialization;
4+
using Orleans.Concurrency;
5+
6+
namespace MineCase.Protocol.Play
7+
{
8+
[Immutable]
9+
[Packet(0x08)]
10+
public sealed class BlockBreakAnimation : ISerializablePacket
11+
{
12+
[SerializeAs(DataType.VarInt)]
13+
public uint EntityID;
14+
15+
[SerializeAs(DataType.Position)]
16+
public Position BlockPosition;
17+
18+
[SerializeAs(DataType.Byte)]
19+
public byte DestoryStage;
20+
21+
public void Serialize(BinaryWriter bw)
22+
{
23+
bw.WriteAsVarInt(EntityID, out _);
24+
bw.WriteAsPosition(BlockPosition);
25+
bw.WriteAsByte(DestoryStage);
26+
}
27+
}
28+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.IO;
4+
using System.Text;
5+
using MineCase.Formats;
6+
using MineCase.Serialization;
7+
using Orleans.Concurrency;
8+
9+
namespace MineCase.Protocol.Play
10+
{
11+
[Immutable]
12+
[Packet(0x0B)]
13+
public sealed class BlockChange : ISerializablePacket
14+
{
15+
[SerializeAs(DataType.Position)]
16+
public Position Location;
17+
18+
[SerializeAs(DataType.VarInt)]
19+
public uint BlockId;
20+
21+
public void Serialize(BinaryWriter bw)
22+
{
23+
bw.WriteAsPosition(Location);
24+
bw.WriteAsVarInt(BlockId, out _);
25+
}
26+
}
27+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
using System.IO;
2+
using MineCase.Formats;
3+
using MineCase.Serialization;
4+
using Orleans.Concurrency;
5+
6+
namespace MineCase.Protocol.Play
7+
{
8+
[Immutable]
9+
[Packet(0x06)]
10+
public sealed class ClientboundAnimation : ISerializablePacket
11+
{
12+
[SerializeAs(DataType.VarInt)]
13+
public uint EntityID;
14+
15+
[SerializeAs(DataType.Byte)]
16+
public ClientboundAnimationId AnimationID;
17+
18+
public void Serialize(BinaryWriter bw)
19+
{
20+
// TODO: check enum to byte.
21+
byte animationID = (byte)AnimationID;
22+
bw.WriteAsVarInt(EntityID, out _);
23+
bw.WriteAsByte(animationID);
24+
}
25+
}
26+
}

0 commit comments

Comments
 (0)