diff --git a/Obsidian/Commands/Modules/MainCommandModule.cs b/Obsidian/Commands/Modules/MainCommandModule.cs index 56313f52..dd5bae46 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,43 @@ public async Task DeclareCommandsTestAsync() } } + [Command("give")] + [CommandInfo("Gives you a block or item", "/get ")] + [IssuerScope(CommandIssuers.Client)] + [RequirePermission(op: true, permissions: "obsidian.give")] + 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; + + // 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)) + { + 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)] 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]