Skip to content
This repository was archived by the owner on Sep 13, 2025. It is now read-only.

Commit 4d37c0b

Browse files
author
Blue Staggo
committed
Synchronize block placement
Ideally I'd have a whole separate class for handling this but this is early in development so I won't bother just yet
1 parent 94c7c68 commit 4d37c0b

1 file changed

Lines changed: 22 additions & 14 deletions

File tree

VoxelThing.Client/src/Gui/Screens/IngameScreen.cs

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using VoxelThing.Game;
88
using VoxelThing.Game.Blocks;
99
using VoxelThing.Game.Maths;
10+
using VoxelThing.Game.Networking;
1011
using VoxelThing.Game.Worlds;
1112

1213
namespace VoxelThing.Client.Gui.Screens;
@@ -239,22 +240,29 @@ protected override void OnMouseClicked(PositionalMouseButtonEventArgs args)
239240
int z = raycast.HitZ;
240241
Direction face = raycast.HitFace;
241242

242-
if (args.Button == MouseButton.Button1)
243+
switch (args.Button)
243244
{
244-
Game.World.SetBlock(x, y, z, null);
245-
}
246-
else if (args.Button == MouseButton.Button2)
247-
{
248-
Block? placedBlock = GetPlacedBlock();
249-
if (placedBlock is null) return;
245+
case MouseButton.Button1:
246+
{
247+
Game.World.SetBlock(x, y, z, null);
248+
Game.PacketHandler?.Server.SendPacket(new CSetBlock(x, y, z, Block.AirId));
249+
break;
250+
}
251+
case MouseButton.Button2:
252+
{
253+
Block? placedBlock = GetPlacedBlock();
254+
if (placedBlock is null) return;
250255

251-
x += face.GetX();
252-
y += face.GetY();
253-
z += face.GetZ();
254-
255-
if (Game.World.GetBlock(x, y, z) is not null) return;
256-
Game.World.SetBlock(x, y, z, placedBlock);
257-
swingTick = 10;
256+
x += face.GetX();
257+
y += face.GetY();
258+
z += face.GetZ();
259+
260+
if (Game.World.GetBlock(x, y, z) is not null) return;
261+
Game.World.SetBlock(x, y, z, placedBlock);
262+
Game.PacketHandler?.Server.SendPacket(new CSetBlock(x, y, z, placedBlock.Id));
263+
swingTick = 10;
264+
break;
265+
}
258266
}
259267
}
260268
}

0 commit comments

Comments
 (0)