Skip to content

Commit 31ca7c9

Browse files
committed
NetStandard Alex.Networking.Java
1 parent 32f83b2 commit 31ca7c9

33 files changed

+280
-971
lines changed

src/Alex.Common/Alex.Common.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
</PropertyGroup>
1717

1818
<ItemGroup>
19-
<PackageReference Include="MiNET.fnbt" Version="1.0.22" />
2019
<PackageReference Include="MojangAPI" Version="1.1.0" />
2120
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
2221
<PackageReference Include="NLog" Version="4.7.15" />

src/Alex/Alex.cs

Lines changed: 44 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
using Alex.Worlds.Multiplayer.Java;
4242
using Alex.Worlds.Singleplayer;
4343
using Microsoft.Extensions.DependencyInjection;
44+
using Microsoft.Extensions.DependencyInjection.Extensions;
4445
using Microsoft.Extensions.Hosting;
4546
using Microsoft.Xna.Framework;
4647
using Microsoft.Xna.Framework.Content;
@@ -54,7 +55,6 @@
5455
using RocketUI.Input.Listeners;
5556
using RocketUI.Utilities.Extensions;
5657
using RocketUI.Utilities.Helpers;
57-
using SimpleInjector;
5858
using SixLabors.ImageSharp;
5959
using SixLabors.ImageSharp.PixelFormats;
6060
using GpuResourceManager = Alex.Common.Graphics.GpuResources.GpuResourceManager;
@@ -285,59 +285,71 @@ protected override void Initialize()
285285

286286
private void RegisterServiceContainer()
287287
{
288-
SimpleInjector.Container container = new SimpleInjector.Container();
289-
container.Options.ResolveUnregisteredConcreteTypes = true;
288+
var container = new ServiceCollection();
289+
//container.Options.ResolveUnregisteredConcreteTypes = true;
290290

291-
container.RegisterInstance<Game>(this);
292-
container.RegisterInstance<Alex>(this);
293-
container.RegisterInstance<IGraphicsDeviceService>(DeviceManager);
294-
container.RegisterInstance<GraphicsDevice>(GraphicsDevice);
295-
container.RegisterSingleton<IGuiRenderer, GuiRenderer>();
296-
container.RegisterSingleton<GuiManager>();
297-
container.RegisterSingleton<InputManager>();
298-
container.RegisterInstance<IServiceProvider>(container);
291+
container.AddSingleton<Game>(this);
292+
container.AddSingleton<Alex>(this);
293+
container.AddSingleton<IGraphicsDeviceService>(DeviceManager);
294+
container.AddSingleton<GraphicsDevice>(GraphicsDevice);
295+
container.AddSingleton<IGuiRenderer, GuiRenderer>();
296+
container.AddSingleton<GuiManager>();
297+
container.AddSingleton<InputManager>();
298+
//container.AddSingleton<IServiceProvider>(container);
299299

300-
container.RegisterSingleton<JavaServerQueryProvider>();
301-
container.RegisterSingleton<BedrockServerQueryProvider>();
300+
container.AddSingleton<JavaServerQueryProvider>();
301+
container.AddSingleton<BedrockServerQueryProvider>();
302302

303-
container.Register<IRegistryManager, RegistryManager>(Lifestyle.Singleton);
303+
container.AddSingleton<IRegistryManager, RegistryManager>();
304304

305-
container.RegisterSingleton<ResourceManager>();
306-
container.RegisterInstance<ServerTypeManager>(ServerTypeManager);
307-
container.Register<XboxAuthService>(Lifestyle.Singleton);
305+
container.AddSingleton<ResourceManager>();
306+
container.AddSingleton<ServerTypeManager>(ServerTypeManager);
307+
container.AddSingleton<XboxAuthService>();
308308

309-
container.Register<BlobCache>(Lifestyle.Singleton);
310-
container.Register<ResourcePackCache>(Lifestyle.Singleton);
309+
container.AddSingleton<BlobCache>();
310+
container.AddSingleton<ResourcePackCache>();
311311

312-
container.RegisterInstance<ContentManager>(Content);
313-
container.RegisterInstance<IStorageSystem>(Storage);
314-
container.RegisterInstance<IOptionsProvider>(Options);
315-
container.RegisterInstance<Audio.AudioEngine>(AudioEngine);
312+
container.AddSingleton<ContentManager>(Content);
313+
container.AddSingleton<IStorageSystem>(Storage);
314+
container.AddSingleton<IOptionsProvider>(Options);
315+
container.AddSingleton<Audio.AudioEngine>(AudioEngine);
316316

317-
container.RegisterSingleton<GuiPanoramaSkyBox>();
317+
container.AddSingleton<GuiPanoramaSkyBox>();
318318

319319
// RocketUI
320-
container.Collection.Register<IInputListenerFactory>(
320+
container.TryAddEnumerable(ServiceDescriptor.Singleton(typeof(IInputListenerFactory), typeof(AlexKeyboardInputListenerFactory)));
321+
container.TryAddEnumerable(ServiceDescriptor.Singleton(typeof(IInputListenerFactory), typeof(AlexMouseInputListenerFactory)));
322+
container.TryAddEnumerable(ServiceDescriptor.Singleton(typeof(IInputListenerFactory), typeof(AlexGamePadInputListenerFactory)));
323+
324+
/*
321325
new Type[]
322326
{
323327
typeof(AlexKeyboardInputListenerFactory), typeof(AlexMouseInputListenerFactory),
324328
typeof(AlexGamePadInputListenerFactory)
325-
}, Lifestyle.Singleton);
329+
}, Lifestyle.Singleton);*/
326330

327-
container.Collection.Register<IHostedService>(typeof(Alex).Assembly);
331+
foreach (var s in typeof(Alex).Assembly.GetTypes())
332+
{
333+
if (typeof(IHostedService).IsAssignableFrom(s))
334+
{
335+
container.TryAddEnumerable(ServiceDescriptor.Singleton(typeof(IHostedService), s));
336+
}
337+
}
328338

329339
if (LaunchSettings.RocketDebugging)
330340
{
331-
container.RegisterSingleton<RocketDebugSocketServer>();
332-
container.Collection.Append<IHostedService, RocketDebugSocketServer>();
341+
//container.AddSingleton<RocketDebugSocketServer>();
342+
container.AddHostedService<RocketDebugSocketServer>();
343+
//container.Collection.Append<IHostedService, RocketDebugSocketServer>();
333344
}
334345

335346
PluginManager.Initiate(container, Options, LaunchSettings);
336347

337-
container.Verify();
338-
Services.AddService<IServiceProvider>(container);
348+
var c = container.BuildServiceProvider();
349+
//container.Verify();
350+
Services.AddService<IServiceProvider>(c);
339351

340-
ServiceContainer = container;
352+
ServiceContainer = c;
341353
PluginManager.Setup(ServiceContainer);
342354
}
343355

src/Alex/Alex.csproj

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,12 +98,10 @@
9898
<PackageReference Include="FmodAudio" Version="2.2.5" />
9999
<PackageReference Include="jose-jwt" Version="3.2.0" />
100100
<PackageReference Include="Microsoft.Identity.Client" Version="4.37.0" />
101-
<PackageReference Include="MiNET.fnbt" Version="1.0.22" />
102101
<PackageReference Include="MojangAPI" Version="1.1.0" />
103102
<PackageReference Include="Mono.Cecil" Version="0.11.4" />
104103
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
105104
<PackageReference Include="NLog" Version="4.7.15" />
106-
<PackageReference Include="PuppeteerSharp" Version="6.2.0" />
107105
<PackageReference Include="System.Globalization" Version="4.3.0" />
108106
<PackageReference Include="System.Reactive.Core" Version="5.0.0" />
109107
<PackageReference Include="System.Reactive.Interfaces" Version="5.0.0" />

src/Alex/Audio/AudioEngine.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System.IO;
55
using Alex.Common.Services;
66
using Alex.Common.Utils;
7+
using Alex.Interfaces;
78
using Alex.ResourcePackLib;
89
using Alex.ResourcePackLib.Json.Bedrock.Sound;
910
using FmodAudio;
@@ -256,16 +257,16 @@ private string GetName(Sounds sound)
256257
return sound.ToString();
257258
}
258259

259-
public bool PlaySound(Sounds sound, Vector3 position, float pitch, float volume, bool isGlobal = false)
260+
public bool PlaySound(Sounds sound, IVector3 position, float pitch, float volume, bool isGlobal = false)
260261
{
261-
return PlaySound(GetName(sound), position, pitch, volume, isGlobal);
262+
return PlaySound(GetName(sound), position.ToXna(), pitch, volume, isGlobal);
262263
}
263264

264-
public bool PlayJavaSound(string sound, Vector3 position, float pitch, float volume, bool isGlobal = false)
265+
public bool PlayJavaSound(string sound, IVector3 position, float pitch, float volume, bool isGlobal = false)
265266
{
266267
if (_soundMapping.TryGetValue(sound, out var mapped))
267268
{
268-
return PlaySound(mapped, position, pitch, volume, isGlobal);
269+
return PlaySound(mapped, position.ToXna(), pitch, volume, isGlobal);
269270
}
270271

271272
return false;

src/Alex/Entities/Generic/EntityArmorStand.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -84,32 +84,32 @@ protected override void HandleJavaMeta(MetaDataEntry entry)
8484
switch (entry.Index)
8585
{
8686
case 15: //Head
87-
SetHeadRotation(rotation.Rotation);
87+
SetHeadRotation(rotation.Rotation.ToXna());
8888

8989
break;
9090

9191
case 16: //Body
92-
SetBodyRotation(rotation.Rotation);
92+
SetBodyRotation(rotation.Rotation.ToXna());
9393

9494
break;
9595

9696
case 17: //Left Arm
97-
SetArmRotation(rotation.Rotation, true);
97+
SetArmRotation(rotation.Rotation.ToXna(), true);
9898

9999
break;
100100

101101
case 18: //Right Arm
102-
SetArmRotation(rotation.Rotation, false);
102+
SetArmRotation(rotation.Rotation.ToXna(), false);
103103

104104
break;
105105

106106
case 19: //Left Leg
107-
SetLegRotation(rotation.Rotation, true);
107+
SetLegRotation(rotation.Rotation.ToXna(), true);
108108

109109
break;
110110

111111
case 20: //Right Leg
112-
SetLegRotation(rotation.Rotation, false);
112+
SetLegRotation(rotation.Rotation.ToXna(), false);
113113

114114
break;
115115
}

src/Alex/Extensions.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System.Text;
55
using Alex.Blocks.Minecraft.Signs;
66
using Alex.Blocks.Minecraft.Terracotta;
7+
using Alex.Common;
78
using Alex.Common.Blocks;
89
using Alex.Common.Gui.Graphics;
910
using Alex.Common.Utils.Vectors;
@@ -23,6 +24,26 @@ public static class Extensions
2324
{
2425
static Extensions() { }
2526

27+
public static IColor ToInterface(this Color color)
28+
{
29+
return new ColorPrimitive(color.R, color.G, color.B, color.A);
30+
}
31+
32+
public static IVector3 ToInterface(this Vector3 color)
33+
{
34+
return new Vector3Primitive(color.X, color.Y, color.Z);
35+
}
36+
37+
public static Vector3 ToXna(this IVector3 vector)
38+
{
39+
return new Vector3(vector.X, vector.Y, vector.Z);
40+
}
41+
42+
public static uint PackedValue(this IColor color)
43+
{
44+
return (uint) ((int) color.A << 24 | (int) color.B << 16 | (int) color.G << 8) | (uint) color.R;
45+
}
46+
2647
public static Color Blend(this Color color, Color backColor, byte amount)
2748
{
2849
amount = (byte)(255 - amount);

src/Alex/Gui/Dialogs/BrowserDialog.cs

Lines changed: 0 additions & 136 deletions
This file was deleted.

src/Alex/Gui/Elements/Scoreboard/ScoreboardObjective.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
using Microsoft.Xna.Framework;
99
using NLog;
1010
using RocketUI;
11+
using Color = Microsoft.Xna.Framework.Color;
1112

1213
namespace Alex.Gui.Elements.Scoreboard
1314
{

0 commit comments

Comments
 (0)