Skip to content

Commit 026f18f

Browse files
jstzwjsunnycase
authored andcommitted
Entity action (#57)
* Set seed from setting file * Add entity action process * Add packet player on ground. * Add isOnGround in player grain * Update isOnGround in player grain
1 parent 170ddd2 commit 026f18f

File tree

5 files changed

+107
-8
lines changed

5 files changed

+107
-8
lines changed
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.IO;
4+
using System.Text;
5+
using MineCase.Serialization;
6+
7+
namespace MineCase.Protocol.Play
8+
{
9+
public enum ActionId : uint
10+
{
11+
StartSneaking = 0,
12+
StopSneaking = 1,
13+
LeaveBed = 2,
14+
StartSprinting = 3,
15+
StopSprinting = 4,
16+
StartJumpWithHorse = 5,
17+
StopJumpWithHorse = 6,
18+
OpenHorseInventory = 7,
19+
StartFlyingWithElytra = 8
20+
}
21+
22+
[Packet(0x15)]
23+
public sealed class EntityAction
24+
{
25+
[SerializeAs(DataType.VarInt)]
26+
public uint EntityId;
27+
28+
[SerializeAs(DataType.VarInt)]
29+
public ActionId ActionId;
30+
31+
[SerializeAs(DataType.VarInt)]
32+
public uint JumpBoost;
33+
34+
public static EntityAction Deserialize(ref SpanReader br)
35+
{
36+
return new EntityAction
37+
{
38+
EntityId = br.ReadAsVarInt(out _),
39+
ActionId = (ActionId)br.ReadAsVarInt(out _),
40+
JumpBoost = br.ReadAsVarInt(out _)
41+
};
42+
}
43+
}
44+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Text;
4+
using MineCase.Serialization;
5+
6+
namespace MineCase.Protocol.Play
7+
{
8+
[Packet(0x0D)]
9+
public sealed class PlayerOnGround
10+
{
11+
[SerializeAs(DataType.Boolean)]
12+
public bool OnGround;
13+
14+
public static PlayerOnGround Deserialize(ref SpanReader br)
15+
{
16+
return new PlayerOnGround
17+
{
18+
OnGround = br.ReadAsBoolean(),
19+
};
20+
}
21+
}
22+
}

src/MineCase.Server.Grains/Game/Entities/PlayerGrain.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ internal class PlayerGrain : EntityGrain, IPlayer
4242

4343
private (Position, BlockState)? _diggingBlock;
4444

45+
private bool _isOnGround;
46+
4547
public override Task OnActivateAsync()
4648
{
4749
_inventory = GrainFactory.GetGrain<IInventoryWindow>(Guid.NewGuid());
@@ -50,6 +52,7 @@ public override Task OnActivateAsync()
5052
_level = 0;
5153
_teleportId = 0;
5254
_levelMaxExp = 7;
55+
_isOnGround = true;
5356

5457
return base.OnActivateAsync();
5558
}
@@ -222,5 +225,11 @@ public Task SetHeldItem(short slot)
222225
{
223226
return Task.CompletedTask;
224227
}
228+
229+
public Task SetOnGround(bool state)
230+
{
231+
_isOnGround = state;
232+
return Task.CompletedTask;
233+
}
225234
}
226235
}

src/MineCase.Server.Grains/Network/PacketRouterGrain.Play.cs

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,31 +46,41 @@ private object DeserializePlayPacket(UncompressedPacket packet)
4646
innerPacket = ServerboundKeepAlive.Deserialize(ref br);
4747
break;
4848

49-
// Position And Look
50-
case 0x0F:
51-
innerPacket = DeferPacket(ServerboundPositionAndLook.Deserialize(ref br));
49+
// Player On Ground
50+
case 0x0D:
51+
innerPacket = DeferPacket(PlayerOnGround.Deserialize(ref br));
5252
break;
5353

5454
// Player Position
5555
case 0x0E:
5656
innerPacket = DeferPacket(PlayerPosition.Deserialize(ref br));
5757
break;
5858

59+
// Position And Look
60+
case 0x0F:
61+
innerPacket = DeferPacket(ServerboundPositionAndLook.Deserialize(ref br));
62+
break;
63+
5964
// Player Look
6065
case 0x10:
6166
innerPacket = DeferPacket(PlayerLook.Deserialize(ref br));
6267
break;
6368

64-
// Held Item Change
65-
case 0x1A:
66-
innerPacket = DeferPacket(ServerboundHeldItemChange.Deserialize(ref br));
67-
break;
68-
6969
// Player Digging
7070
case 0x14:
7171
innerPacket = DeferPacket(PlayerDigging.Deserialize(ref br));
7272
break;
7373

74+
// Entity Action
75+
case 0x15:
76+
innerPacket = DeferPacket(EntityAction.Deserialize(ref br));
77+
break;
78+
79+
// Held Item Change
80+
case 0x1A:
81+
innerPacket = DeferPacket(ServerboundHeldItemChange.Deserialize(ref br));
82+
break;
83+
7484
// Animation
7585
case 0x1D:
7686
innerPacket = DeferPacket(ServerboundAnimation.Deserialize(ref br));
@@ -130,6 +140,12 @@ private async Task DispatchPacket(ServerboundPositionAndLook packet)
130140
player.SetLook(packet.Yaw, packet.Pitch, packet.OnGround).Ignore();
131141
}
132142

143+
private async Task DispatchPacket(PlayerOnGround packet)
144+
{
145+
var player = await _user.GetPlayer();
146+
await player.SetOnGround(packet.OnGround);
147+
}
148+
133149
private async Task DispatchPacket(PlayerPosition packet)
134150
{
135151
var player = await _user.GetPlayer();
@@ -185,6 +201,12 @@ private async Task DispatchPacket(PlayerDigging packet)
185201
}
186202
}
187203

204+
private Task DispatchPacket(EntityAction packet)
205+
{
206+
// TODO Set Entity Action
207+
return Task.CompletedTask;
208+
}
209+
188210
private Task DispatchPacket(ServerboundAnimation packet)
189211
{
190212
return Task.CompletedTask;

src/MineCase.Server.Interfaces/Game/Entities/IPlayer.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,5 +54,7 @@ public interface IPlayer : IEntity
5454
Task PlaceBlock(Position location, EntityInteractHand hand, PlayerDiggingFace face, Vector3 cursorPosition);
5555

5656
Task SetHeldItem(short slot);
57+
58+
Task SetOnGround(bool state);
5759
}
5860
}

0 commit comments

Comments
 (0)