From 6c153689b06b1b575f27494238ba3fb5c548f885 Mon Sep 17 00:00:00 2001 From: Ryan Date: Wed, 11 Dec 2024 22:38:42 +0100 Subject: [PATCH 1/4] Add give command --- .../Commands/Modules/MainCommandModule.cs | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/Obsidian/Commands/Modules/MainCommandModule.cs b/Obsidian/Commands/Modules/MainCommandModule.cs index 56313f52..85bccaa6 100644 --- a/Obsidian/Commands/Modules/MainCommandModule.cs +++ b/Obsidian/Commands/Modules/MainCommandModule.cs @@ -2,6 +2,7 @@ using Obsidian.API.Utilities; using Obsidian.Commands.Framework.Entities; using Obsidian.Entities; +using Obsidian.Net.Packets.Play.Clientbound; using Obsidian.Registries; using Obsidian.WorldData; using System.Collections.Frozen; @@ -204,6 +205,34 @@ public async Task DeclareCommandsTestAsync() } } + [Command("give")] + [CommandInfo("Gives you a block or item", "/get ")] + [IssuerScope(CommandIssuers.Client)] + [RequirePermission(op: true, permissions: "obsidian.give")] + public async Task GiveAsync(string item, int amount = 1) + { + if (this.Player is not Player player) + return; + + // find material from string (enum Material) + if (Enum.TryParse(item, out Material material)) + { + var slot = player.Inventory.AddItem(new ItemStack(material, count: amount)); + await player.SendMessageAsync($"Given you {ChatColor.Gold}{amount} {item}(s)"); + player.client.SendPacket(new ContainerSetSlotPacket + { + Slot = (short)slot, + ContainerId = 0, + SlotData = player.Inventory.GetItem(slot)!, + StateId = player.Inventory.StateId++ + }); + } + else + { + await player.SendMessageAsync($"{ChatColor.Red}Invalid item: {item}"); + } + } + [Command("gamemode")] [CommandInfo("Change your gamemode.", "/gamemode ")] [IssuerScope(CommandIssuers.Client)] From 08bbc405c4750bf0f23ac6cd7e6ac4b121aee1e5 Mon Sep 17 00:00:00 2001 From: Ryan Date: Wed, 11 Dec 2024 22:42:00 +0100 Subject: [PATCH 2/4] Allow pascal_case in /give --- Obsidian/Commands/Modules/MainCommandModule.cs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Obsidian/Commands/Modules/MainCommandModule.cs b/Obsidian/Commands/Modules/MainCommandModule.cs index 85bccaa6..ef6c4676 100644 --- a/Obsidian/Commands/Modules/MainCommandModule.cs +++ b/Obsidian/Commands/Modules/MainCommandModule.cs @@ -214,6 +214,12 @@ public async Task GiveAsync(string item, int amount = 1) if (this.Player is not Player player) return; + // convert snake_case to PascalCase + if(item.Contains('_')) + { + var parts = item.Split('_'); + item = string.Join("", parts.Select(x => $"{x[0].ToString().ToUpperInvariant()}{x.Substring(1)}")); + } // find material from string (enum Material) if (Enum.TryParse(item, out Material material)) { From f05090c0d6829e2c63f8a361bb7f688c9af301f1 Mon Sep 17 00:00:00 2001 From: Ryan Date: Wed, 11 Dec 2024 22:45:27 +0100 Subject: [PATCH 3/4] Add giveasync with an argument as an overload --- Obsidian/Commands/Modules/MainCommandModule.cs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Obsidian/Commands/Modules/MainCommandModule.cs b/Obsidian/Commands/Modules/MainCommandModule.cs index ef6c4676..dd5bae46 100644 --- a/Obsidian/Commands/Modules/MainCommandModule.cs +++ b/Obsidian/Commands/Modules/MainCommandModule.cs @@ -209,7 +209,10 @@ public async Task DeclareCommandsTestAsync() [CommandInfo("Gives you a block or item", "/get ")] [IssuerScope(CommandIssuers.Client)] [RequirePermission(op: true, permissions: "obsidian.give")] - public async Task GiveAsync(string item, int amount = 1) + public Task GiveAsync(string item) => GiveAsync(item); + + [CommandOverload] + public async Task GiveAsync(string item, int amount = 64) { if (this.Player is not Player player) return; From 3eae35855e7287f8daad0a61827e8eccb2ef2d16 Mon Sep 17 00:00:00 2001 From: Ryan Date: Wed, 11 Dec 2024 22:46:46 +0100 Subject: [PATCH 4/4] lol I see --- Obsidian/Net/MinecraftStream.Reading.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Obsidian/Net/MinecraftStream.Reading.cs b/Obsidian/Net/MinecraftStream.Reading.cs index cf743b10..ec0416bd 100644 --- a/Obsidian/Net/MinecraftStream.Reading.cs +++ b/Obsidian/Net/MinecraftStream.Reading.cs @@ -666,7 +666,7 @@ public Guid ReadGuid() => return itemStack; } - return null; + return itemStack; } [ReadMethod]