From 2f807732ad009ef731ddccebc833f72962541987 Mon Sep 17 00:00:00 2001 From: Hazel Rojas <84425557+hazelcode@users.noreply.github.com> Date: Mon, 17 Mar 2025 04:59:52 +0000 Subject: [PATCH 01/52] Resolve error for GitHub Codespace --- SteveSharp.sln | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/SteveSharp.sln b/SteveSharp.sln index 8452547..00356b2 100644 --- a/SteveSharp.sln +++ b/SteveSharp.sln @@ -5,10 +5,7 @@ VisualStudioVersion = 17.5.33627.172 MinimumVisualStudioVersion = 10.0.40219.1 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SteveSharp", "SteveSharp.csproj", "{6D99B2F6-7D41-4357-B210-E5E909B653D8}" EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "PersonalTests", "PersonalTests", "{08CE972B-3385-4258-A89A-E901C870028E}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tests", "PersonalTests\Tests\Tests.csproj", "{6642C65E-FF8E-4F33-A3E5-2552AEBD6CFB}" -EndProject + Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -19,10 +16,6 @@ Global {6D99B2F6-7D41-4357-B210-E5E909B653D8}.Debug|Any CPU.Build.0 = Debug|Any CPU {6D99B2F6-7D41-4357-B210-E5E909B653D8}.Release|Any CPU.ActiveCfg = Release|Any CPU {6D99B2F6-7D41-4357-B210-E5E909B653D8}.Release|Any CPU.Build.0 = Release|Any CPU - {6642C65E-FF8E-4F33-A3E5-2552AEBD6CFB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {6642C65E-FF8E-4F33-A3E5-2552AEBD6CFB}.Debug|Any CPU.Build.0 = Debug|Any CPU - {6642C65E-FF8E-4F33-A3E5-2552AEBD6CFB}.Release|Any CPU.ActiveCfg = Release|Any CPU - {6642C65E-FF8E-4F33-A3E5-2552AEBD6CFB}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -30,7 +23,4 @@ Global GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {F4AAACE1-9BD0-4190-B3B9-8A837F2AAEA5} EndGlobalSection - GlobalSection(NestedProjects) = preSolution - {6642C65E-FF8E-4F33-A3E5-2552AEBD6CFB} = {08CE972B-3385-4258-A89A-E901C870028E} - EndGlobalSection EndGlobal From e679f0b984ea2de07a5222a6b8d43e84076578ef Mon Sep 17 00:00:00 2001 From: Hazel Rojas <84425557+hazelcode@users.noreply.github.com> Date: Mon, 17 Mar 2025 05:10:32 +0000 Subject: [PATCH 02/52] Create FunctionBuilder for building new functions --- FunctionBuilder.cs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 FunctionBuilder.cs diff --git a/FunctionBuilder.cs b/FunctionBuilder.cs new file mode 100644 index 0000000..b8b9b01 --- /dev/null +++ b/FunctionBuilder.cs @@ -0,0 +1,17 @@ +namespace SteveSharp; + +public static class FunctionBuilder { + public static List Commands { get; set; } = new List {}; + + public static void Add(string command) { + Commands.Add(command); + } + + public static string[] Collect() { + return Commands.ToArray(); + } + + public static void Clear() { + Commands.Clear(); + } +} \ No newline at end of file From af5018824e0144904a3b65e824749b14dac45970 Mon Sep 17 00:00:00 2001 From: Hazel Rojas <84425557+hazelcode@users.noreply.github.com> Date: Mon, 17 Mar 2025 05:32:09 +0000 Subject: [PATCH 03/52] Upgrade .NET Action to .NET 8.0 --- .github/workflows/dotnet.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/dotnet.yml b/.github/workflows/dotnet.yml index dd12d4a..e537368 100644 --- a/.github/workflows/dotnet.yml +++ b/.github/workflows/dotnet.yml @@ -19,7 +19,7 @@ jobs: - name: Setup .NET uses: actions/setup-dotnet@v3 with: - dotnet-version: 6.0.x + dotnet-version: 8.0.x - name: Restore dependencies run: dotnet restore SteveSharp.csproj - name: Build From 365afbddbab684b2f2714a82440f941641524453 Mon Sep 17 00:00:00 2001 From: Hazel Rojas <84425557+hazelcode@users.noreply.github.com> Date: Mon, 17 Mar 2025 05:38:28 +0000 Subject: [PATCH 04/52] Implement Variables in Project --- Project.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/Project.cs b/Project.cs index dd2abe8..6f2e333 100644 --- a/Project.cs +++ b/Project.cs @@ -9,6 +9,7 @@ public class Project private readonly Function _load; private readonly Function _main; private readonly List _functions; + public Dictionary Variables = new(); public Project(string name, string description, string id, int pack_format, Function load, Function main, List functions, List> matrix = null!, List jsonFiles = null!) { // Display fresh SteveSharp Display From 6310fbcf1ecd7fd64a6be7bba515602abc268e56 Mon Sep 17 00:00:00 2001 From: Hazel Rojas <84425557+hazelcode@users.noreply.github.com> Date: Mon, 17 Mar 2025 05:40:15 +0000 Subject: [PATCH 05/52] Create Function context --- FunctionContext.cs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 FunctionContext.cs diff --git a/FunctionContext.cs b/FunctionContext.cs new file mode 100644 index 0000000..2e56e0d --- /dev/null +++ b/FunctionContext.cs @@ -0,0 +1,22 @@ +namespace SteveSharp; + +public class FunctionContext { + public FunctionContext(string functionName, string id, string functionPath, int packFormat, Project projectReference) { + FunctionName = functionName; + Namespace = id; + FunctionPath = functionPath; + PackFormat = packFormat; + _projectReference = projectReference; + } + public string FunctionName { get; set; } + public string Namespace { get; set; } + public string FunctionPath { get; set; } + public int PackFormat { get; set; } + private Project _projectReference { get; set; } + public Dictionary Variables { + get { + return _projectReference.Variables; + } + set {} + } +} \ No newline at end of file From 657cf1552ff5adca49f67c259edfd29853439cec Mon Sep 17 00:00:00 2001 From: Hazel Rojas <84425557+hazelcode@users.noreply.github.com> Date: Mon, 17 Mar 2025 05:43:34 +0000 Subject: [PATCH 06/52] Function modifications --- Function.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Function.cs b/Function.cs index 088126d..b4162a2 100644 --- a/Function.cs +++ b/Function.cs @@ -3,8 +3,8 @@ public class Function { public string Name = ""; - public List Body { get; set; } - public Function(string name, List body) + public Func Body { get; set; } + public Function(string name, Func body) { Name = name; Body = body; From 4ac564e32a7d900d17f619bccba21d08ddec3b57 Mon Sep 17 00:00:00 2001 From: Hazel Rojas <84425557+hazelcode@users.noreply.github.com> Date: Mon, 17 Mar 2025 06:13:02 +0000 Subject: [PATCH 07/52] Project modifications --- FunctionBuilder.cs | 14 ++++++++++++++ Project.cs | 19 ++++++++++++++++--- 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/FunctionBuilder.cs b/FunctionBuilder.cs index b8b9b01..b45497b 100644 --- a/FunctionBuilder.cs +++ b/FunctionBuilder.cs @@ -14,4 +14,18 @@ public static string[] Collect() { public static void Clear() { Commands.Clear(); } + + public static void BuildFunction(Function function, string id, int packFormat, Project project, ref Dictionary contentsRepository) { + // Create context for the function and then, register the contents + var ctx = new FunctionContext( + function.Name, + id, + FileOrganizer.GetFunctionPath(function.Name), + packFormat, + project + ); + contentsRepository.Add(function.Name, function.Body(ctx)); + // Clear stored commands for last function + Clear(); + } } \ No newline at end of file diff --git a/Project.cs b/Project.cs index 6f2e333..6eaff98 100644 --- a/Project.cs +++ b/Project.cs @@ -5,15 +5,25 @@ namespace SteveSharp { public class Project { + private string _name { get; set; } + + private string _description { get; set; } + private int _packFormat { get; set; } + private string _namespace { get; set; } public Dictionary FunctionIndex { get; set; } private readonly Function _load; private readonly Function _main; private readonly List _functions; + private Dictionary _functionContents = new(); public Dictionary Variables = new(); + public Project(string name, string description, string id, int pack_format, Function load, Function main, List functions, List> matrix = null!, List jsonFiles = null!) { // Display fresh SteveSharp Display Displays.SteveSharpDisplay(name); + _name = name; + _description = description; + _namespace = id; _load = load; _main = main; _functions = functions; @@ -46,9 +56,11 @@ public Project(string name, string description, string id, int pack_format, Func }, new JsonSerializerOptions { WriteIndented = true }) ); Displays.ProjectCreated(); - File.WriteAllLines(loadPath, _load.Body); + FunctionBuilder.BuildFunction(_load, _namespace, _packFormat, this, ref _functionContents); + File.WriteAllLines(loadPath, _functionContents[_load.Name]); Displays.WrittenFunction(_load.Name); - File.WriteAllLines(mainPath, _main.Body); + FunctionBuilder.BuildFunction(_main, _namespace, _packFormat, this, ref _functionContents); + File.WriteAllLines(mainPath, _functionContents[_main.Name]); Displays.WrittenFunction(_main.Name); if (_functions.Count > 0) @@ -86,7 +98,8 @@ public Project(string name, string description, string id, int pack_format, Func { Directory.CreateDirectory(directory); } - File.WriteAllLines(FileOrganizer.GetFunctionPath(function.Value.Name), function.Value.Body); + FunctionBuilder.BuildFunction(function.Value, _namespace, _packFormat, this, ref _functionContents); + File.WriteAllLines(FileOrganizer.GetFunctionPath(function.Value.Name), _functionContents[function.Value.Name]); } if (jsonFiles != null && jsonFiles.Count > 0) From 8b53f87de1a1f8512cc72a45bcc3c2556050ebc2 Mon Sep 17 00:00:00 2001 From: Hazel Rojas <84425557+hazelcode@users.noreply.github.com> Date: Mon, 17 Mar 2025 15:12:11 +0000 Subject: [PATCH 08/52] Implement GetFunctionCommands function --- Project.cs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/Project.cs b/Project.cs index 6eaff98..45632ef 100644 --- a/Project.cs +++ b/Project.cs @@ -17,6 +17,10 @@ public class Project private Dictionary _functionContents = new(); public Dictionary Variables = new(); + private string[] GetFunctionCommands(string functionName) { + return _functionContents[functionName]; + } + public Project(string name, string description, string id, int pack_format, Function load, Function main, List functions, List> matrix = null!, List jsonFiles = null!) { // Display fresh SteveSharp Display @@ -57,10 +61,10 @@ public Project(string name, string description, string id, int pack_format, Func ); Displays.ProjectCreated(); FunctionBuilder.BuildFunction(_load, _namespace, _packFormat, this, ref _functionContents); - File.WriteAllLines(loadPath, _functionContents[_load.Name]); + File.WriteAllLines(loadPath, GetFunctionCommands(_load.Name)); Displays.WrittenFunction(_load.Name); FunctionBuilder.BuildFunction(_main, _namespace, _packFormat, this, ref _functionContents); - File.WriteAllLines(mainPath, _functionContents[_main.Name]); + File.WriteAllLines(mainPath, GetFunctionCommands(_main.Name)); Displays.WrittenFunction(_main.Name); if (_functions.Count > 0) @@ -99,7 +103,7 @@ public Project(string name, string description, string id, int pack_format, Func Directory.CreateDirectory(directory); } FunctionBuilder.BuildFunction(function.Value, _namespace, _packFormat, this, ref _functionContents); - File.WriteAllLines(FileOrganizer.GetFunctionPath(function.Value.Name), _functionContents[function.Value.Name]); + File.WriteAllLines(FileOrganizer.GetFunctionPath(function.Value.Name), GetFunctionCommands(function.Value.Name)); } if (jsonFiles != null && jsonFiles.Count > 0) From 4af8cd012ed13bdedf69e15d6822fec714d70337 Mon Sep 17 00:00:00 2001 From: Hazel Rojas <84425557+hazelcode@users.noreply.github.com> Date: Mon, 17 Mar 2025 17:25:52 +0000 Subject: [PATCH 09/52] Modifications for FunctionBuilder --- FunctionBuilder.cs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/FunctionBuilder.cs b/FunctionBuilder.cs index b45497b..76e5dd1 100644 --- a/FunctionBuilder.cs +++ b/FunctionBuilder.cs @@ -1,14 +1,21 @@ namespace SteveSharp; public static class FunctionBuilder { - public static List Commands { get; set; } = new List {}; + public static List Commands { get; set; } = []; public static void Add(string command) { Commands.Add(command); } + public static void Add(List commands) { + Commands = [ + ..Commands, + ..commands + ]; + } + public static string[] Collect() { - return Commands.ToArray(); + return Commands.ToArray(); } public static void Clear() { From d717d7b0b109c62ebb20d3370e7f8cc68475a019 Mon Sep 17 00:00:00 2001 From: Hazel Rojas <84425557+hazelcode@users.noreply.github.com> Date: Mon, 17 Mar 2025 20:32:52 +0000 Subject: [PATCH 10/52] Rewrite Commands! --- Core/Bossbar.cs | 81 ++++++++++++------------------ Core/Chat.cs | 18 ++----- Core/Entity.cs | 63 +++++------------------- Core/Execute.cs | 61 +++++------------------ Core/For.cs | 16 ++---- Core/Recipe.cs | 6 ++- Core/Score.cs | 74 ++++++++++++---------------- Core/Strings/Bossbar.cs | 63 ++++++++++++++++++++++++ Core/Strings/Chat.cs | 23 +++++++++ Core/Strings/Entity.cs | 60 +++++++++++++++++++++++ Core/Strings/Execute.cs | 57 ++++++++++++++++++++++ Core/Strings/For.cs | 18 +++++++ Core/Strings/Function.cs | 4 ++ Core/Strings/Recipe.cs | 6 +++ Core/Strings/Score.cs | 103 +++++++++++++++++++++++++++++++++++++++ Core/Text.cs | 29 ----------- Core/XYZ.cs | 14 ++++-- 17 files changed, 440 insertions(+), 256 deletions(-) create mode 100644 Core/Strings/Bossbar.cs create mode 100644 Core/Strings/Chat.cs create mode 100644 Core/Strings/Entity.cs create mode 100644 Core/Strings/Execute.cs create mode 100644 Core/Strings/For.cs create mode 100644 Core/Strings/Function.cs create mode 100644 Core/Strings/Recipe.cs create mode 100644 Core/Strings/Score.cs delete mode 100644 Core/Text.cs diff --git a/Core/Bossbar.cs b/Core/Bossbar.cs index 4ea4a35..26aa367 100644 --- a/Core/Bossbar.cs +++ b/Core/Bossbar.cs @@ -1,8 +1,9 @@ using System.Text.Json; using SteveSharp.Generic; using SteveSharp.JsonShapes; +using Str = SteveSharp.Core.Strings; -namespace SteveSharp; +namespace SteveSharp.Core; public class Bossbar { @@ -21,56 +22,38 @@ public enum Style Notched12, Notched20 } - public static string Add(string id, TextComponent text) => $"bossbar add {id} {JsonSerializer.Serialize(text)}"; - public static string Add(string id, TextComponent[] text) => $"bossbar add {id} {JsonSerializer.Serialize(text)}"; - public static string Get(string id, GetField field) - { - Dictionary fieldStr = new() { - {GetField.Max, "max"}, - {GetField.Players, "players"}, - {GetField.Value, "value"}, - {GetField.Visible, "visible"} - }; - return $"bossbar get {id} {fieldStr[field]}"; - } - public static string Get(string id, string field) => $"bossbar get {id} {field}"; - public static string List() => "bossbar list"; - public static string Remove(string id) => $"bossbar remove {id}"; - public static string SetColor(string id, Color color) => $"bossbar set {id} color {ColorHandler.Get(color)}"; - public static string SetColor(string id, string color) => $"bossbar set {id} color {color}"; - public static string SetMax(string id, int max) => $"bossbar set {id} max {max}"; - public static string SetName(string id, TextComponent name) => $"bossbar set {id} name {JsonSerializer.Serialize(name)}"; - public static string SetName(string id, TextComponent[] name) => $"bossbar set {id} name {JsonSerializer.Serialize(name)}"; - public static string SetPlayers(string id, string targets) => $"bossbar set {id} players {targets}"; - public static string SetStyle(string id, Style style) - { - Dictionary styleStr = new() { - {Style.Notched6, "notched_6"}, - {Style.Notched10, "notched_10"}, - {Style.Notched12, "notched_12"}, - {Style.Notched20, "notched_20"} - }; - return $"bossbar set {id} style {styleStr[style]}"; - } - public static string SetStyle(string id, string style) => $"bossbar set {id} style {style}"; - public static string SetValue(string id, int value) => $"bossbar set {id} value {value}"; - public static string SetVisible(string id, bool visible) => $"bossbar set {id} visible {visible.ToString().ToLower()}"; + public static void Add(string id, TextComponent text) => FunctionBuilder.Add(Str.Bossbar.Add(id, text)); + public static void Add(string id, TextComponent[] text) => FunctionBuilder.Add(Str.Bossbar.Add(id, text)); + public static void Get(string id, GetField field) => FunctionBuilder.Add(Str.Bossbar.Get(id, field)); + public static void Get(string id, string field) => FunctionBuilder.Add(Str.Bossbar.Get(id, field)); + public static void List() => FunctionBuilder.Add(Str.Bossbar.List()); + public static void Remove(string id) => FunctionBuilder.Add(Str.Bossbar.Remove(id)); + public static void SetColor(string id, Color color) => FunctionBuilder.Add(Str.Bossbar.SetColor(id, color)); + public static void SetColor(string id, string color) => FunctionBuilder.Add(Str.Bossbar.SetColor(id, color)); + public static void SetMax(string id, int max) => FunctionBuilder.Add(Str.Bossbar.SetMax(id, max)); + public static void SetName(string id, TextComponent name) => FunctionBuilder.Add(Str.Bossbar.SetName(id, name)); + public static void SetName(string id, TextComponent[] name) => FunctionBuilder.Add(Str.Bossbar.SetName(id, name)); + public static void SetPlayers(string id, string targets) => FunctionBuilder.Add(Str.Bossbar.SetPlayers(id, targets)); + public static void SetStyle(string id, Style style) => FunctionBuilder.Add(Str.Bossbar.SetStyle(id, style)); + public static void SetStyle(string id, string style) => FunctionBuilder.Add(Str.Bossbar.SetStyle(id, style)); + public static void SetValue(string id, int value) => FunctionBuilder.Add(Str.Bossbar.SetValue(id, value)); + public static void SetVisible(string id, bool visible) => FunctionBuilder.Add(Str.Bossbar.SetVisible(id, visible)); public Bossbar(string id) { Id = id; } - public string Add(TextComponent text) => Add(this.Id!, text); - public string Add(TextComponent[] text) => Add(this.Id!, text); - public string Get(GetField field) => Get(this.Id!, field); - public string Get(string field) => Get(this.Id!, field); - public string SetColor(Color color) => SetColor(this.Id!, color); - public string SetColor(string color) => SetColor(this.Id!, color); - public string SetMax(int max) => SetMax(this.Id!, max); - public string SetName(TextComponent name) => SetName(this.Id!, name); - public string SetName(TextComponent[] name) => SetName(this.Id!, name); - public string SetPlayers(string targets) => SetPlayers(this.Id!, targets); - public string SetStyle(Style style) => SetStyle(this.Id!, style); - public string SetStyle(string style) => SetStyle(this.Id!, style); - public string SetValue(int value) => SetValue(this.Id!, value); - public string SetVisible(bool visible) => SetVisible(this.Id!, visible); + public void Add(TextComponent text) => Add(this.Id!, text); + public void Add(TextComponent[] text) => Add(this.Id!, text); + public void Get(GetField field) => Get(this.Id!, field); + public void Get(string field) => Get(this.Id!, field); + public void SetColor(Color color) => SetColor(this.Id!, color); + public void SetColor(string color) => SetColor(this.Id!, color); + public void SetMax(int max) => SetMax(this.Id!, max); + public void SetName(TextComponent name) => SetName(this.Id!, name); + public void SetName(TextComponent[] name) => SetName(this.Id!, name); + public void SetPlayers(string targets) => SetPlayers(this.Id!, targets); + public void SetStyle(Style style) => SetStyle(this.Id!, style); + public void SetStyle(string style) => SetStyle(this.Id!, style); + public void SetValue(int value) => SetValue(this.Id!, value); + public void SetVisible(bool visible) => SetVisible(this.Id!, visible); } \ No newline at end of file diff --git a/Core/Chat.cs b/Core/Chat.cs index 2908e6b..df8cfac 100644 --- a/Core/Chat.cs +++ b/Core/Chat.cs @@ -1,23 +1,13 @@ using SteveSharp.JsonShapes; using System.Text.Json; +using Str = SteveSharp.Core.Strings; namespace SteveSharp.Core { public static class Chat { - public static string Say(string msg) - { - return $"say {msg}"; - } - public static string Out(string selector, TextComponent[] text) - { - string command = "tellraw " + selector + " " + JsonSerializer.Serialize(text); - return command; - } - public static string Out(string selector, TextComponent text) - { - string command = "tellraw " + selector + " " + JsonSerializer.Serialize(text); - return command; - } + public static void Say(string msg) => FunctionBuilder.Add(Str.Chat.Say(msg)); + public static void Out(string selector, TextComponent[] text) => FunctionBuilder.Add(Str.Chat.Out(selector, text)); + public static void Out(string selector, TextComponent text) => FunctionBuilder.Add(Str.Chat.Out(selector, text)); } } diff --git a/Core/Entity.cs b/Core/Entity.cs index 50d968c..9f270fd 100644 --- a/Core/Entity.cs +++ b/Core/Entity.cs @@ -1,4 +1,6 @@ -namespace SteveSharp.Core +using Str = SteveSharp.Core.Strings; + +namespace SteveSharp.Core { public static class Entity { @@ -11,55 +13,12 @@ public static class Entity /// This method selects an entity with specific matches, recommended if you want to select an entity with specific matches. /// /// - public static string Custom(string selector, int? limit = null, string[]? tags = null, string[]? scores = null, string? team = null, string? type = null, string? distance = null, string? area = null, string? level = null, string? gamemode = null, string? horizontalRotation = null, string? verticalRotation = null, string? sort = null) { - string match = ""; - match += selector + "["; - if(limit != null) match += "limit=" + limit + ','; - if(tags?.Length >= 1){ - foreach(string tag in tags){ - match += "tag=" + tag + ","; - } - } - if(scores?.Length >= 1){ - match += "scores={"; - foreach(string score in scores){ - match += score + ','; - } - match += "},"; - } - if(team != null) match += "team=" + team + ','; - if(type != null && selector != "@a" || selector != "@r" || selector != "@p") - match += "type=" + type + ','; - if(distance != null) match += "distance=" + distance + ','; - if(area != null) match += area + ','; - if(level != null) match += "level=" + level + ','; - if(gamemode != null && selector != "@e") match += "gamemode=" + gamemode + ','; - if(horizontalRotation != null) match += "y_rotation=" + horizontalRotation + ','; - if(verticalRotation != null) match += "x_rotation=" + verticalRotation + ','; - if(sort != null) match += "sort=" + sort + ','; - if (match.EndsWith(',')) match.Remove(match.Length - 1); - match += ']'; - return match; - } - public static string Teleport(string selector, string to) - { - return $"tp {selector} {to}"; - } - public static string Summon(string entity, string[] pos, string nbt = "{}") - { - return $"summon {entity} {pos[0]} {pos[1]} {pos[2]} {nbt}"; - } - public static string AddTag(string selector, string tag) - { - return $"tag {selector} add {tag}"; - } - public static string RemoveTag(string selector, string tag) - { - return $"tag {selector} remove {tag}"; - } - public static string Kill(string selector) - { - return $"kill {selector}"; - } + public static void Custom(string selector, int? limit = null, string[]? tags = null, string[]? scores = null, string? team = null, string? type = null, string? distance = null, string? area = null, string? level = null, string? gamemode = null, string? horizontalRotation = null, string? verticalRotation = null, string? sort = null) + => FunctionBuilder.Add(Str.Entity.Custom(selector, limit, tags, scores, team, type, distance, area, level, gamemode, horizontalRotation, verticalRotation, sort)); + public static void Teleport(string selector, string to) => FunctionBuilder.Add(Str.Entity.Teleport(selector, to)); + public static void Summon(string entity, string[] pos, string nbt = "{}") => FunctionBuilder.Add(Str.Entity.Summon(entity, pos, nbt)); + public static void AddTag(string selector, string tag) => FunctionBuilder.Add(Str.Entity.AddTag(selector, tag)); + public static void RemoveTag(string selector, string tag) => FunctionBuilder.Add(Str.Entity.RemoveTag(selector, tag)); + public static void Kill(string selector) => FunctionBuilder.Add(Str.Entity.Kill(selector)); } -} +} \ No newline at end of file diff --git a/Core/Execute.cs b/Core/Execute.cs index 508af94..d43480f 100644 --- a/Core/Execute.cs +++ b/Core/Execute.cs @@ -1,55 +1,18 @@ -namespace SteveSharp.Core +using Str = SteveSharp.Core.Strings; + +namespace SteveSharp.Core { public static class Execute { const string[] defaults = null; - public static string Write(string execute, string[] commands = defaults) - { - string allCommands = ""; - foreach (string command in commands) - { - allCommands += "execute " + execute + "run " + command + "\n"; - } - return allCommands; - } - public static string As(string selector, string addition = "") - { - return "as " + selector + " " + addition; - } - public static string At(string selector, string addition = "") - { - return "at " + selector + " " + addition; - } - public static string Asat(string selector, string addition = "") - { - return "as " + selector + " at @s " + addition; - } - public static string Unless(string arguments, string addition = "") - { - return "unless " + arguments + " " + addition; - } - public static string If(string arguments, string addition = "") - { - return "if " + arguments + " " + addition; - } - public static string Summon(string entity, string[] pos, string addition = "") - { - return "summon " + entity + " " + pos[0] + " " + pos[1] + " " + pos[2] + " " + addition; - } - public static string Store(string where, string at, string arguments, string addition = "") - { - return "store " + where + " " + at + " " + arguments + " " + addition; - } - public static string StoreScore(string where, Score score, string selector = "", string addition = "") - { - if (selector == "") - { - return "store " + where + " score " + "#" + score.id + " " + score.id + " " + addition; - } - else - { - return "store " + where + " score " + selector + " " + score.id + " " + addition; - } - } + public static void Write(string execute, string[] commands = defaults) => FunctionBuilder.Add(Str.Execute.Write(execute, commands)); + public static void As(string selector, string addition = "") => FunctionBuilder.Add(Str.Execute.As(selector, addition)); + public static void At(string selector, string addition = "") => FunctionBuilder.Add(Str.Execute.At(selector, addition)); + public static void Asat(string selector, string addition = "") => FunctionBuilder.Add(Str.Execute.Asat(selector, addition)); + public static void Unless(string arguments, string addition = "") => FunctionBuilder.Add(Str.Execute.Unless(arguments, addition)); + public static void If(string arguments, string addition = "") => FunctionBuilder.Add(Str.Execute.If(arguments, addition)); + public static void Summon(string entity, string[] pos, string addition = "") => FunctionBuilder.Add(Str.Execute.Summon(entity, pos, addition)); + public static void Store(string where, string at, string arguments, string addition = "") => FunctionBuilder.Add(Str.Execute.Store(where, at, arguments, addition)); + public static void StoreScore(string where, Score score, string selector = "", string addition = "") => FunctionBuilder.Add(Str.Execute.StoreScore(where, score, selector, addition)); } } diff --git a/Core/For.cs b/Core/For.cs index 525958f..0d6a7dd 100644 --- a/Core/For.cs +++ b/Core/For.cs @@ -1,20 +1,10 @@ +using Str = SteveSharp.Core.Strings; + namespace SteveSharp.Core; public static class For { - public static string Loop(int to, Func> block, int from = 0) { - List> fullBlock = new(); - for(int i = from; i <= to; i++) { - fullBlock.Add(block(i)); - } - List ret = new(); - foreach(var codeBlock in fullBlock) { - foreach(var command in codeBlock) { - ret.Add(command); - } - } - return string.Join("\n", ret); - } + public static void Loop(int to, Func> block, int from = 0) => FunctionBuilder.Add(Str.For.Loop(to, block, from)); public static List Functions(int to, Func block, int from = 0) { List fullBlock = new(); for(int i = from; i <= to; i++) { diff --git a/Core/Recipe.cs b/Core/Recipe.cs index 30c5a9e..b6066c6 100644 --- a/Core/Recipe.cs +++ b/Core/Recipe.cs @@ -1,6 +1,8 @@ +using Str = SteveSharp.Core.Strings; + namespace SteveSharp.Core; public static class Recipe { - public static string Give(string targets, string recipe) => $"recipe give {targets} {recipe}"; - public static string Take(string targets, string recipe) => $"recipe take {targets} {recipe}"; + public static void Give(string targets, string recipe) => FunctionBuilder.Add(Str.Recipe.Give(targets, recipe)); + public static void Take(string targets, string recipe) => FunctionBuilder.Add(Str.Recipe.Take(targets, recipe)); } \ No newline at end of file diff --git a/Core/Score.cs b/Core/Score.cs index 4aec040..b91bbff 100644 --- a/Core/Score.cs +++ b/Core/Score.cs @@ -1,4 +1,6 @@ -namespace SteveSharp.Core +using Str = SteveSharp.Core.Strings; + +namespace SteveSharp.Core { public class Score { @@ -13,61 +15,47 @@ public Score(string id, string type = "dummy", string name = "", int count = 0) this.type = type; this.name = name; } - public string AddObjective() - { - return $"scoreboard objectives add {this.id} {this.type} {this.name}"; - } - public static string AddObjectives(Score[] scores) - { + public void AddObjective() => FunctionBuilder.Add($"scoreboard objectives add {this.id} {this.type} {this.name}"); + public static void AddObjective(string id, string type, string name) => FunctionBuilder.Add(Str.Score.AddObjective(id, type, name)); + public static void AddObjectives(Score[] scores) { string commands = ""; foreach(Score score in scores) { commands += $"scoreboard objectives add {score.id} {score.type} {score.name}\n"; } - return commands; + FunctionBuilder.Add(commands); } - public string Set(int count, string selector = "") + public void Set(int count, string selector = "") { - if(selector == "") - { - return $"scoreboard players set #{this.id} {this.id} {count}"; - } else - { - return $"scoreboard players set {selector} {this.id} {count}"; - } + Set(id, count, selector); } - public string Add(int count, string selector = "") + public static void Set(string id, int count, string selector = "") { - if (selector == "") - { - return $"scoreboard players add #{this.id} {this.id} {count}"; - } - else - { - return $"scoreboard players add {selector} {this.id} {count}"; - } + FunctionBuilder.Add(Str.Score.Set(id, count, selector)); } - public string Remove(string selector, int count) + public void Add(int count, string selector = "") { - if (selector == "") - { - return $"scoreboard players remove #{this.id} {this.id} {count}"; - } - else - { - return $"scoreboard players remove {selector} {this.id} {count}"; - } + Add(id, count, selector); } - public string Reset(string selector = "") + public static void Add(string id, int count, string selector = "") { - if (selector == "") - { - return $"scoreboard players reset #{this.id} {this.id}"; - } - else - { - return $"scoreboard players reset {selector} {this.id}"; - } + FunctionBuilder.Add(Str.Score.Add(id, count, selector)); + } + public void Remove(int count, string selector = "") + { + Remove(id, count, selector); + } + public static void Remove(string id, int count, string selector = "") + { + FunctionBuilder.Add(Str.Score.Remove(id, count, selector)); + } + public void Reset(string selector = "") + { + Reset(id, selector); + } + public static void Reset(string id, string selector = "") + { + FunctionBuilder.Add(Str.Score.Reset(id, selector)); } /// /// Only for use in scores={} cases diff --git a/Core/Strings/Bossbar.cs b/Core/Strings/Bossbar.cs new file mode 100644 index 0000000..00942d4 --- /dev/null +++ b/Core/Strings/Bossbar.cs @@ -0,0 +1,63 @@ +using SteveSharp.JsonShapes; +using SteveSharp.Generic; +using System.Text.Json; +using BB = SteveSharp.Core.Bossbar; + +namespace SteveSharp.Core.Strings; + +public class Bossbar +{ + public string? Id { get; set; } + public static string Add(string id, TextComponent text) => $"bossbar add {id} {JsonSerializer.Serialize(text)}"; + public static string Add(string id, TextComponent[] text) => $"bossbar add {id} {JsonSerializer.Serialize(text)}"; + public static string Get(string id, BB.GetField field) + { + Dictionary fieldStr = new() { + {BB.GetField.Max, "max"}, + {BB.GetField.Players, "players"}, + {BB.GetField.Value, "value"}, + {BB.GetField.Visible, "visible"} + }; + return $"bossbar get {id} {fieldStr[field]}"; + } + public static string Get(string id, string field) => $"bossbar get {id} {field}"; + public static string List() => "bossbar list"; + public static string Remove(string id) => $"bossbar remove {id}"; + public static string SetColor(string id, Color color) => $"bossbar set {id} color {ColorHandler.Get(color)}"; + public static string SetColor(string id, string color) => $"bossbar set {id} color {color}"; + public static string SetMax(string id, int max) => $"bossbar set {id} max {max}"; + public static string SetName(string id, TextComponent name) => $"bossbar set {id} name {JsonSerializer.Serialize(name)}"; + public static string SetName(string id, TextComponent[] name) => $"bossbar set {id} name {JsonSerializer.Serialize(name)}"; + public static string SetPlayers(string id, string targets) => $"bossbar set {id} players {targets}"; + public static string SetStyle(string id, BB.Style style) + { + Dictionary styleStr = new() { + {BB.Style.Notched6, "notched_6"}, + {BB.Style.Notched10, "notched_10"}, + {BB.Style.Notched12, "notched_12"}, + {BB.Style.Notched20, "notched_20"} + }; + return $"bossbar set {id} style {styleStr[style]}"; + } + public static string SetStyle(string id, string style) => $"bossbar set {id} style {style}"; + public static string SetValue(string id, int value) => $"bossbar set {id} value {value}"; + public static string SetVisible(string id, bool visible) => $"bossbar set {id} visible {visible.ToString().ToLower()}"; + public Bossbar(string id) + { + Id = id; + } + public string Add(TextComponent text) => Add(this.Id!, text); + public string Add(TextComponent[] text) => Add(this.Id!, text); + public string Get(BB.GetField field) => Get(this.Id!, field); + public string Get(string field) => Get(this.Id!, field); + public string SetColor(Color color) => SetColor(this.Id!, color); + public string SetColor(string color) => SetColor(this.Id!, color); + public string SetMax(int max) => SetMax(this.Id!, max); + public string SetName(TextComponent name) => SetName(this.Id!, name); + public string SetName(TextComponent[] name) => SetName(this.Id!, name); + public string SetPlayers(string targets) => SetPlayers(this.Id!, targets); + public string SetStyle(BB.Style style) => SetStyle(this.Id!, style); + public string SetStyle(string style) => SetStyle(this.Id!, style); + public string SetValue(int value) => SetValue(this.Id!, value); + public string SetVisible(bool visible) => SetVisible(this.Id!, visible); +} \ No newline at end of file diff --git a/Core/Strings/Chat.cs b/Core/Strings/Chat.cs new file mode 100644 index 0000000..fef240c --- /dev/null +++ b/Core/Strings/Chat.cs @@ -0,0 +1,23 @@ +using SteveSharp.JsonShapes; +using System.Text.Json; + +namespace SteveSharp.Core.Strings +{ + public static class Chat + { + public static string Say(string msg) + { + return $"say {msg}"; + } + public static string Out(string selector, TextComponent[] text) + { + string command = "tellraw " + selector + " " + JsonSerializer.Serialize(text); + return command; + } + public static string Out(string selector, TextComponent text) + { + string command = "tellraw " + selector + " " + JsonSerializer.Serialize(text); + return command; + } + } +} diff --git a/Core/Strings/Entity.cs b/Core/Strings/Entity.cs new file mode 100644 index 0000000..7897ed1 --- /dev/null +++ b/Core/Strings/Entity.cs @@ -0,0 +1,60 @@ +namespace SteveSharp.Core.Strings +{ + public static class Entity + { + /// + /// This method selects an entity with specific matches, recommended if you want to select an entity with specific matches. + /// + /// + public static string Custom(string selector, int? limit = null, string[]? tags = null, string[]? scores = null, string? team = null, string? type = null, string? distance = null, string? area = null, string? level = null, string? gamemode = null, string? horizontalRotation = null, string? verticalRotation = null, string? sort = null) { + string match = ""; + match += selector + "["; + if(limit != null) match += "limit=" + limit + ','; + if(tags?.Length >= 1){ + foreach(string tag in tags){ + match += "tag=" + tag + ","; + } + } + if(scores?.Length >= 1){ + match += "scores={"; + foreach(string score in scores){ + match += score + ','; + } + match += "},"; + } + if(team != null) match += "team=" + team + ','; + if(type != null && selector != "@a" || selector != "@r" || selector != "@p") + match += "type=" + type + ','; + if(distance != null) match += "distance=" + distance + ','; + if(area != null) match += area + ','; + if(level != null) match += "level=" + level + ','; + if(gamemode != null && selector != "@e") match += "gamemode=" + gamemode + ','; + if(horizontalRotation != null) match += "y_rotation=" + horizontalRotation + ','; + if(verticalRotation != null) match += "x_rotation=" + verticalRotation + ','; + if(sort != null) match += "sort=" + sort + ','; + if (match.EndsWith(',')) match.Remove(match.Length - 1); + match += ']'; + return match; + } + public static string Teleport(string selector, string to) + { + return $"tp {selector} {to}"; + } + public static string Summon(string entity, string[] pos, string nbt = "{}") + { + return $"summon {entity} {pos[0]} {pos[1]} {pos[2]} {nbt}"; + } + public static string AddTag(string selector, string tag) + { + return $"tag {selector} add {tag}"; + } + public static string RemoveTag(string selector, string tag) + { + return $"tag {selector} remove {tag}"; + } + public static string Kill(string selector) + { + return $"kill {selector}"; + } + } +} diff --git a/Core/Strings/Execute.cs b/Core/Strings/Execute.cs new file mode 100644 index 0000000..d4226db --- /dev/null +++ b/Core/Strings/Execute.cs @@ -0,0 +1,57 @@ +using Core = SteveSharp.Core; + +namespace SteveSharp.Core.Strings +{ + public static class Execute + { + const string[] defaults = null; + public static string Write(string execute, string[] commands = defaults) + { + string allCommands = ""; + foreach (string command in commands) + { + allCommands += "execute " + execute + "run " + command + "\n"; + } + return allCommands; + } + public static string As(string selector, string addition = "") + { + return "as " + selector + " " + addition; + } + public static string At(string selector, string addition = "") + { + return "at " + selector + " " + addition; + } + public static string Asat(string selector, string addition = "") + { + return "as " + selector + " at @s " + addition; + } + public static string Unless(string arguments, string addition = "") + { + return "unless " + arguments + " " + addition; + } + public static string If(string arguments, string addition = "") + { + return "if " + arguments + " " + addition; + } + public static string Summon(string entity, string[] pos, string addition = "") + { + return "summon " + entity + " " + pos[0] + " " + pos[1] + " " + pos[2] + " " + addition; + } + public static string Store(string where, string at, string arguments, string addition = "") + { + return "store " + where + " " + at + " " + arguments + " " + addition; + } + public static string StoreScore(string where, Core.Score score, string selector = "", string addition = "") + { + if (selector == "") + { + return "store " + where + " score " + "#" + score.id + " " + score.id + " " + addition; + } + else + { + return "store " + where + " score " + selector + " " + score.id + " " + addition; + } + } + } +} diff --git a/Core/Strings/For.cs b/Core/Strings/For.cs new file mode 100644 index 0000000..c993867 --- /dev/null +++ b/Core/Strings/For.cs @@ -0,0 +1,18 @@ +namespace SteveSharp.Core.Strings; + +public static class For +{ + public static string Loop(int to, Func> block, int from = 0) { + List> fullBlock = new(); + for(int i = from; i <= to; i++) { + fullBlock.Add(block(i)); + } + List ret = new(); + foreach(var codeBlock in fullBlock) { + foreach(var command in codeBlock) { + ret.Add(command); + } + } + return string.Join("\n", ret); + } +} \ No newline at end of file diff --git a/Core/Strings/Function.cs b/Core/Strings/Function.cs new file mode 100644 index 0000000..147807c --- /dev/null +++ b/Core/Strings/Function.cs @@ -0,0 +1,4 @@ +namespace SteveSharp.Core.Strings; + +public class Function { +} \ No newline at end of file diff --git a/Core/Strings/Recipe.cs b/Core/Strings/Recipe.cs new file mode 100644 index 0000000..32bd0e7 --- /dev/null +++ b/Core/Strings/Recipe.cs @@ -0,0 +1,6 @@ +namespace SteveSharp.Core.Strings; + +public static class Recipe { + public static string Give(string targets, string recipe) => $"recipe give {targets} {recipe}"; + public static string Take(string targets, string recipe) => $"recipe take {targets} {recipe}"; +} \ No newline at end of file diff --git a/Core/Strings/Score.cs b/Core/Strings/Score.cs new file mode 100644 index 0000000..dae538c --- /dev/null +++ b/Core/Strings/Score.cs @@ -0,0 +1,103 @@ +namespace SteveSharp.Core.Strings +{ + public class Score + { + public int count = 0; + public string id; + public string type; + public string name; + public Score(string id, string type = "dummy", string name = "", int count = 0) + { + this.id = id; + this.count = count; + this.type = type; + this.name = name; + } + public string AddObjective() + { + return AddObjective(id, type, name); + } + public static string AddObjective(string id, string type, string name) + { + return $"scoreboard objectives add {id} {type} {name}"; + } + public static string AddObjectives(Score[] scores) + { + string commands = ""; + foreach(Score score in scores) + { + commands += $"scoreboard objectives add {score.id} {score.type} {score.name}\n"; + } + return commands; + } + public string Set(int count, string selector = "") + { + return Set(id, count, selector); + } + public static string Set(string id, int count, string selector = "") + { + if(selector == "") + { + return $"scoreboard players set #{id} {id} {count}"; + } else + { + return $"scoreboard players set {selector} {id} {count}"; + } + } + public string Add(int count, string selector = "") + { + return Add(id, count, selector); + } + public static string Add(string id, int count, string selector = "") + { + if (selector == "") + { + return $"scoreboard players add #{id} {id} {count}"; + } + else + { + return $"scoreboard players add {selector} {id} {count}"; + } + } + public string Remove(int count, string selector = "") + { + return Remove(id, count, selector); + } + public static string Remove(string id, int count, string selector = "") + { + if (selector == "") + { + return $"scoreboard players remove #{id} {id} {count}"; + } + else + { + return $"scoreboard players remove {selector} {id} {count}"; + } + } + public string Reset(string selector = "") + { + return Reset(id, selector); + } + public static string Reset(string id, string selector = "") + { + if (selector == "") + { + return $"scoreboard players reset #{id} {id}"; + } + else + { + return $"scoreboard players reset {selector} {id}"; + } + } + /// + /// Only for use in scores={} cases + /// + /// + public string Matches(int value){ + return Matches(id, value); + } + public static string Matches(string id, int value){ + return id + '=' + value; + } + } +} diff --git a/Core/Text.cs b/Core/Text.cs deleted file mode 100644 index c892675..0000000 --- a/Core/Text.cs +++ /dev/null @@ -1,29 +0,0 @@ -using SteveSharp.JsonShapes; -using System.Text.Json; - -namespace SteveSharp.Core -{ - public static class Text - { - public static TextComponent New(string text, string? color = null, bool italic = false, bool bold = false, bool underlined = false, bool obfuscated = false, bool strikethrough = false, string? insertion = null, string? clickEventAction = null, string? clickEventValue = null) - { - TextComponent textComponent = new TextComponent - { - text = text, - color = color, - italic = italic, - bold = bold, - underlined = underlined, - obfuscated = obfuscated, - strikethrough = strikethrough, - insertion = insertion, - clickEvent = new clickEvent - { - action = clickEventAction, - value = clickEventValue - } - }; - return textComponent; - } - } -} diff --git a/Core/XYZ.cs b/Core/XYZ.cs index aa21c92..1cb1fb8 100644 --- a/Core/XYZ.cs +++ b/Core/XYZ.cs @@ -2,12 +2,16 @@ { public static class XYZ { - public static string[] Set(string X, string Y, string Z) - { - return new string[] { X, Y, Z }; + public static (int x, int y) Vec2(int x, int y) => (x, y); + public static (string x, string y) Vec2(string x, string y) => (x, y); + public static (int x, int y, int z) Vec3(int x, int y, int z) => (x, y, z); + public static (string x, string y, string z) Vec3(string x, string y, string z) => (x, y, z); + public static (string x, string y, string z) Rel(int x, int y, int z) => ('~'+x.ToString(), '~'+y.ToString(), '~'+z.ToString()); + public static string[] Pos(int a, int b, int c) { + return ["^"+b, "^"+b, "^"+c]; } - public static string[] Rel(string X, string Y, string Z) { - return Set("~"+X, "~"+Y, "~"+Z); + public static string[] Pos(string a, string b, string c) { + return ['^'+a, '^'+b, '^'+c]; } } } From 82fdff1192a913fd0c1ff0c786007f5584a62131 Mon Sep 17 00:00:00 2001 From: Hazel Rojas <84425557+hazelcode@users.noreply.github.com> Date: Mon, 17 Mar 2025 21:03:23 +0000 Subject: [PATCH 11/52] Rename Chat.Out to Chat.Tellraw --- Core/Chat.cs | 4 ++-- Core/Strings/Chat.cs | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Core/Chat.cs b/Core/Chat.cs index df8cfac..2aa53f0 100644 --- a/Core/Chat.cs +++ b/Core/Chat.cs @@ -7,7 +7,7 @@ namespace SteveSharp.Core public static class Chat { public static void Say(string msg) => FunctionBuilder.Add(Str.Chat.Say(msg)); - public static void Out(string selector, TextComponent[] text) => FunctionBuilder.Add(Str.Chat.Out(selector, text)); - public static void Out(string selector, TextComponent text) => FunctionBuilder.Add(Str.Chat.Out(selector, text)); + public static void Tellraw(string selector, TextComponent[] text) => FunctionBuilder.Add(Str.Chat.Tellraw(selector, text)); + public static void Tellraw(string selector, TextComponent text) => FunctionBuilder.Add(Str.Chat.Tellraw(selector, text)); } } diff --git a/Core/Strings/Chat.cs b/Core/Strings/Chat.cs index fef240c..cb27bfa 100644 --- a/Core/Strings/Chat.cs +++ b/Core/Strings/Chat.cs @@ -9,12 +9,12 @@ public static string Say(string msg) { return $"say {msg}"; } - public static string Out(string selector, TextComponent[] text) + public static string Tellraw(string selector, TextComponent[] text) { string command = "tellraw " + selector + " " + JsonSerializer.Serialize(text); return command; } - public static string Out(string selector, TextComponent text) + public static string Tellraw(string selector, TextComponent text) { string command = "tellraw " + selector + " " + JsonSerializer.Serialize(text); return command; From 75deac577889aa52c64af1192be3c5862d64f075 Mon Sep 17 00:00:00 2001 From: Hazel Rojas <84425557+hazelcode@users.noreply.github.com> Date: Mon, 17 Mar 2025 21:07:00 +0000 Subject: [PATCH 12/52] Add Tell command --- Core/Chat.cs | 1 + Core/Strings/Chat.cs | 3 +++ 2 files changed, 4 insertions(+) diff --git a/Core/Chat.cs b/Core/Chat.cs index 2aa53f0..30c6f9c 100644 --- a/Core/Chat.cs +++ b/Core/Chat.cs @@ -7,6 +7,7 @@ namespace SteveSharp.Core public static class Chat { public static void Say(string msg) => FunctionBuilder.Add(Str.Chat.Say(msg)); + public static void Tell(string targets, string message) => FunctionBuilder.Add(Str.Chat.Tell(targets, message)); public static void Tellraw(string selector, TextComponent[] text) => FunctionBuilder.Add(Str.Chat.Tellraw(selector, text)); public static void Tellraw(string selector, TextComponent text) => FunctionBuilder.Add(Str.Chat.Tellraw(selector, text)); } diff --git a/Core/Strings/Chat.cs b/Core/Strings/Chat.cs index cb27bfa..65f4536 100644 --- a/Core/Strings/Chat.cs +++ b/Core/Strings/Chat.cs @@ -9,6 +9,9 @@ public static string Say(string msg) { return $"say {msg}"; } + public static string Tell(string targets, string message) { + return $"tell {targets} {message}"; + } public static string Tellraw(string selector, TextComponent[] text) { string command = "tellraw " + selector + " " + JsonSerializer.Serialize(text); From 267280042e02807b434a7df3decdbe006d2f8274 Mon Sep 17 00:00:00 2001 From: Hazel Rojas <84425557+hazelcode@users.noreply.github.com> Date: Mon, 17 Mar 2025 21:16:23 +0000 Subject: [PATCH 13/52] Fix "scoreboard objectives add" whitespace error --- Core/Score.cs | 4 ++-- Core/Strings/Score.cs | 10 +++++++--- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/Core/Score.cs b/Core/Score.cs index b91bbff..fcaa747 100644 --- a/Core/Score.cs +++ b/Core/Score.cs @@ -15,13 +15,13 @@ public Score(string id, string type = "dummy", string name = "", int count = 0) this.type = type; this.name = name; } - public void AddObjective() => FunctionBuilder.Add($"scoreboard objectives add {this.id} {this.type} {this.name}"); + public void AddObjective() => FunctionBuilder.Add(Str.Score.AddObjective(id, type, name)); public static void AddObjective(string id, string type, string name) => FunctionBuilder.Add(Str.Score.AddObjective(id, type, name)); public static void AddObjectives(Score[] scores) { string commands = ""; foreach(Score score in scores) { - commands += $"scoreboard objectives add {score.id} {score.type} {score.name}\n"; + commands += Str.Score.AddObjective(score.id, score.type, score.name) + "\n"; } FunctionBuilder.Add(commands); } diff --git a/Core/Strings/Score.cs b/Core/Strings/Score.cs index dae538c..3c9ac45 100644 --- a/Core/Strings/Score.cs +++ b/Core/Strings/Score.cs @@ -17,16 +17,20 @@ public string AddObjective() { return AddObjective(id, type, name); } - public static string AddObjective(string id, string type, string name) + public static string AddObjective(string id, string type, string name = "") { - return $"scoreboard objectives add {id} {type} {name}"; + if(name == "") { + return $"scoreboard objectives add {id} {type}"; + } else { + return $"scoreboard objectives add {id} {type} {name}"; + } } public static string AddObjectives(Score[] scores) { string commands = ""; foreach(Score score in scores) { - commands += $"scoreboard objectives add {score.id} {score.type} {score.name}\n"; + commands += AddObjective(score.id, score.type, score.name) + "\n"; } return commands; } From 18b71b43a506ee5344feff2733330dae7fb209d4 Mon Sep 17 00:00:00 2001 From: Hazel Rojas <84425557+hazelcode@users.noreply.github.com> Date: Mon, 17 Mar 2025 21:21:39 +0000 Subject: [PATCH 14/52] Adjust TextComponent properties --- JsonShapes/TextComponent.cs | 39 ++++++++++++++++++++++++------------- 1 file changed, 26 insertions(+), 13 deletions(-) diff --git a/JsonShapes/TextComponent.cs b/JsonShapes/TextComponent.cs index 1d8c676..1403fc4 100644 --- a/JsonShapes/TextComponent.cs +++ b/JsonShapes/TextComponent.cs @@ -4,32 +4,45 @@ namespace SteveSharp.JsonShapes { public class TextComponent { - public string? text { get; set; } + [JsonPropertyName("text")] + public string? Text { get; set; } [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] - public string? color { get; set; } + [JsonPropertyName("color")] + public string? Color { get; set; } [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] - public bool italic { get; set; } + [JsonPropertyName("italic")] + public bool Italic { get; set; } [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] - public bool bold { get; set; } + [JsonPropertyName("bold")] + public bool Bold { get; set; } [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] - public bool underlined { get; set; } + [JsonPropertyName("underlined")] + public bool Underlined { get; set; } [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] - public bool obfuscated { get; set; } + [JsonPropertyName("obfuscated")] + public bool Obfuscated { get; set; } [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] - public bool strikethrough { get; set; } + [JsonPropertyName("strikethrough")] + public bool Strikethrough { get; set; } [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] - public string? insertion { get; set; } + [JsonPropertyName("insertion")] + public string? Insertion { get; set; } [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] - public clickEvent? clickEvent { get; set; } + [JsonPropertyName("clickEvent")] + public ClickEvent? ClickEvent { get; set; } [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] - public TextComponent[]? extra { get; set; } + [JsonPropertyName("extra")] + public TextComponent[]? Extra { get; set; } } - public class clickEvent + public class ClickEvent { + [JsonPropertyName("action")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] - public string? action { get; set; } + public string? Action { get; set; } + [JsonPropertyName("value")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] - public string? value { get; set; } + public string? Value { get; set; } } } From 9b1c99cb335e22f43b56606dad3d99da3fa65f91 Mon Sep 17 00:00:00 2001 From: Hazel Rojas <84425557+hazelcode@users.noreply.github.com> Date: Mon, 17 Mar 2025 21:48:28 +0000 Subject: [PATCH 15/52] Use PackFormat enumeration instead of Int --- PackFormat.cs | 76 +++++++++++++++++++++++++++++++++++++++++++++++++++ Project.cs | 5 ++-- 2 files changed, 79 insertions(+), 2 deletions(-) create mode 100644 PackFormat.cs diff --git a/PackFormat.cs b/PackFormat.cs new file mode 100644 index 0000000..09f29b0 --- /dev/null +++ b/PackFormat.cs @@ -0,0 +1,76 @@ +namespace SteveSharp; + +public enum PackFormat { + /// + /// Minecraft 1.14.4 + /// + [Obsolete("SteveSharp doesn't support pack format 4 officially")] + Format4 = 4, + /// + /// Minecraft 1.16.1 + /// + [Obsolete("SteveSharp doesn't support pack format 5 officially")] + Format5 = 5, + /// + /// Minecraft 1.16.5 + /// + [Obsolete("SteveSharp doesn't support pack format 6 officially")] + Format6 = 6, + /// + /// Minecraft 1.17.1 + /// + [Obsolete("SteveSharp doesn't support pack format 7 officially")] + Format7 = 7, + /// + /// Minecraft 1.18.1 + /// + [Obsolete("SteveSharp doesn't support pack format 8 officially")] + Format8 = 8, + /// + /// Minecraft 1.18.2 + /// + [Obsolete("SteveSharp doesn't support pack format 9 officially")] + Format9 = 9, + /// + /// Minecraft 1.19.3 + /// + [Obsolete("SteveSharp doesn't support pack format 10 officially")] + Format10 = 10, + /// + /// Minecraft 1.19.4 + /// + [Obsolete("SteveSharp doesn't support pack format 12 officially")] + Format12 = 12, + /// + /// Minecraft 1.20.1 + /// + Format15 = 15, + /// + /// Minecraft 1.20.2 + /// + Format18 = 18, + /// + /// Minecraft 1.20.4 + /// + Format26 = 26, + /// + /// Minecraft 1.20.6 + /// + Format41 = 41, + /// + /// Minecraft 1.21.1 + /// + Format48 = 48, + /// + /// Minecraft 1.21.3 + /// + Format57 = 57, + /// + /// Minecraft 1.21.4 + /// + Format61 = 61, + /// + /// Minecraft 1.21.5 + /// + Format71 = 71 +} \ No newline at end of file diff --git a/Project.cs b/Project.cs index 45632ef..d4237ba 100644 --- a/Project.cs +++ b/Project.cs @@ -21,13 +21,14 @@ private string[] GetFunctionCommands(string functionName) { return _functionContents[functionName]; } - public Project(string name, string description, string id, int pack_format, Function load, Function main, List functions, List> matrix = null!, List jsonFiles = null!) + public Project(string name, string description, string id, PackFormat packFormat, Function load, Function main, List functions, List> matrix = null!, List jsonFiles = null!) { // Display fresh SteveSharp Display Displays.SteveSharpDisplay(name); _name = name; _description = description; _namespace = id; + _packFormat = (int)packFormat; _load = load; _main = main; _functions = functions; @@ -43,7 +44,7 @@ public Project(string name, string description, string id, int pack_format, Func pack = new Pack { description = description, - pack_format = pack_format + pack_format = _packFormat } }; File.WriteAllText("pack.mcmeta", JsonSerializer.Serialize(metadata, new JsonSerializerOptions { WriteIndented = true })); From ed7b8e7e47e363b2ba2246405d1dea1493f1e370 Mon Sep 17 00:00:00 2001 From: Hazel Rojas <84425557+hazelcode@users.noreply.github.com> Date: Tue, 18 Mar 2025 00:04:18 +0000 Subject: [PATCH 16/52] Re-implement the capability of EXTENDING FUNCTIONS!!!! --- Function.cs | 12 ++++++++++++ FunctionBuilder.cs | 4 ++-- FunctionContext.cs | 6 +++--- Project.cs | 10 +++++----- 4 files changed, 22 insertions(+), 10 deletions(-) diff --git a/Function.cs b/Function.cs index b4162a2..d6fc9af 100644 --- a/Function.cs +++ b/Function.cs @@ -26,5 +26,17 @@ public static string Schedule(string function, string time, bool append = false, public string ScheduleSelf(string time, bool append = false, bool replace = false) => Schedule(Name, time, append, replace); public static string ClearSchedule(string function) => $"schedule clear {function}"; public string ClearSchedule() => ClearSchedule(Name); + + /// + /// Extend to another function from the current function + /// + /// The new function to assign + /// The actual function context + public static void Extend(Function function, FunctionContext ctx) { + FunctionBuilder.Add("function "+function.Name); + + // List the another function to build on project construction. + ctx.Project.FunctionIndex.Add(function.Name, function); + } } } diff --git a/FunctionBuilder.cs b/FunctionBuilder.cs index 76e5dd1..680b1db 100644 --- a/FunctionBuilder.cs +++ b/FunctionBuilder.cs @@ -22,7 +22,7 @@ public static void Clear() { Commands.Clear(); } - public static void BuildFunction(Function function, string id, int packFormat, Project project, ref Dictionary contentsRepository) { + public static void BuildFunction(Function function, string id, int packFormat, Project project) { // Create context for the function and then, register the contents var ctx = new FunctionContext( function.Name, @@ -31,7 +31,7 @@ public static void BuildFunction(Function function, string id, int packFormat, P packFormat, project ); - contentsRepository.Add(function.Name, function.Body(ctx)); + project.FunctionContents.Add(function.Name, function.Body(ctx)); // Clear stored commands for last function Clear(); } diff --git a/FunctionContext.cs b/FunctionContext.cs index 2e56e0d..9618a7b 100644 --- a/FunctionContext.cs +++ b/FunctionContext.cs @@ -6,16 +6,16 @@ public FunctionContext(string functionName, string id, string functionPath, int Namespace = id; FunctionPath = functionPath; PackFormat = packFormat; - _projectReference = projectReference; + Project = projectReference; } public string FunctionName { get; set; } public string Namespace { get; set; } public string FunctionPath { get; set; } public int PackFormat { get; set; } - private Project _projectReference { get; set; } + public Project Project { get; set; } public Dictionary Variables { get { - return _projectReference.Variables; + return Project.Variables; } set {} } diff --git a/Project.cs b/Project.cs index d4237ba..b102c78 100644 --- a/Project.cs +++ b/Project.cs @@ -14,11 +14,11 @@ public class Project private readonly Function _load; private readonly Function _main; private readonly List _functions; - private Dictionary _functionContents = new(); + public Dictionary FunctionContents = new(); public Dictionary Variables = new(); private string[] GetFunctionCommands(string functionName) { - return _functionContents[functionName]; + return FunctionContents[functionName]; } public Project(string name, string description, string id, PackFormat packFormat, Function load, Function main, List functions, List> matrix = null!, List jsonFiles = null!) @@ -61,10 +61,10 @@ public Project(string name, string description, string id, PackFormat packFormat }, new JsonSerializerOptions { WriteIndented = true }) ); Displays.ProjectCreated(); - FunctionBuilder.BuildFunction(_load, _namespace, _packFormat, this, ref _functionContents); + FunctionBuilder.BuildFunction(_load, _namespace, _packFormat, this); File.WriteAllLines(loadPath, GetFunctionCommands(_load.Name)); Displays.WrittenFunction(_load.Name); - FunctionBuilder.BuildFunction(_main, _namespace, _packFormat, this, ref _functionContents); + FunctionBuilder.BuildFunction(_main, _namespace, _packFormat, this); File.WriteAllLines(mainPath, GetFunctionCommands(_main.Name)); Displays.WrittenFunction(_main.Name); @@ -103,7 +103,7 @@ public Project(string name, string description, string id, PackFormat packFormat { Directory.CreateDirectory(directory); } - FunctionBuilder.BuildFunction(function.Value, _namespace, _packFormat, this, ref _functionContents); + FunctionBuilder.BuildFunction(function.Value, _namespace, _packFormat, this); File.WriteAllLines(FileOrganizer.GetFunctionPath(function.Value.Name), GetFunctionCommands(function.Value.Name)); } From 57276cd00b3728cd6ce158ffdd0bdb438b79facf Mon Sep 17 00:00:00 2001 From: Hazel Rojas <84425557+hazelcode@users.noreply.github.com> Date: Tue, 18 Mar 2025 02:14:55 +0000 Subject: [PATCH 17/52] Re-implement Hitbox!! --- Utils/Hitbox.cs | 130 ++++++++++++++++++++++++------------------------ 1 file changed, 64 insertions(+), 66 deletions(-) diff --git a/Utils/Hitbox.cs b/Utils/Hitbox.cs index fbef7b4..6e5133a 100644 --- a/Utils/Hitbox.cs +++ b/Utils/Hitbox.cs @@ -1,72 +1,70 @@ using SteveSharp; using SteveSharp.Core; using SteveSharp.JsonShapes; +using Str = SteveSharp.Core.Strings; -/* -NOT FOR NOW -namespace SteveSharp.Utils -{ - public class Hitbox - { - public float width = 1.0f; - public float height = 1.0f; - public string workspace; - public string id; - public string[] XYZ; - public string[] onAttack; - public string[] onRightClick; - public Hitbox(string workspace, string id) - { - this.workspace = workspace; - this.id = id; - XYZ = new string[3] { "~", "~", "~" }; - onAttack = new string[] { - Chat.Out( - Entity.Self(), - new TextComponent[] - { - new TextComponent - { - text = "" - } - } - ) - }; - onRightClick = new string[] { - Chat.Out( - Entity.Self(), - new TextComponent[] - { - new TextComponent - { - text = "" - } - } - ) - }; - } - public string Summon(string function) - { - Function f = new Function(FileOrganizer.GetFunctionPath(function)); - return f.Extend( - $"{workspace}:hitbox/" + this.id.ToLower() + "/summon", - new string[] - { - Entity.Summon("interaction",new[]{ "~", "~", "~" }, - "{Tags:[\"" + workspace + "." + this.id + "\"],width:" + this.width + ",height:" + this.height + "}"), - Execute.Write( - Execute.Asat(Entity.AllEntities("type=interaction,tag=" + workspace + "." + this.id)) + - "on attacker ", - onAttack - ), - Execute.Write( - Execute.Asat(Entity.AllEntities("type=interaction,tag=" + workspace + "." + this.id)) + - "on trigger ", - onRightClick - ), - Entity.Kill(Entity.AllEntities("type=interaction,tag=" + workspace + "." + this.id)) - }, true +namespace SteveSharp.Utils; + +public class Hitbox { + public float Width = 1.0f; + public float Height = 1.0f; + + public string Id { get; set; } + public string Workspace; + private FunctionContext _ctx; + public (string x, string y, string z) coords; + + public Hitbox(string id, string workspace, FunctionContext ctx) { + Id = id; + Workspace = workspace; + coords = XYZ.Vec3("~", "~", "~"); + _ctx = ctx; + } + + public void Setup(Action onAttack, Action onRightClick) { + _ctx.Project.FunctionIndex.Add($"{_ctx!.Namespace}:hitbox/{Workspace}/on_attack", OnAttack(onAttack)); + _ctx.Project.FunctionIndex.Add($"{_ctx!.Namespace}:hitbox/{Workspace}/on_right_click", OnRightClick(onRightClick)); + } + + public string Invoke() { + return Function.Call($"{_ctx!.Namespace}:hitbox/{Workspace}/summon"); + } + public Function OnAttack(Action body) { + return new Function( + name: $"{_ctx!.Namespace}:hitbox/{Workspace}/on_attack", + body: (ctx) => { + body(ctx); + return FunctionBuilder.Collect(); + } + ); + } + private Function OnRightClick(Action body) { + return new Function( + name: $"{_ctx!.Namespace}:hitbox/{Workspace}/on_right_click", + body: (ctx) => { + body(ctx); + return FunctionBuilder.Collect(); + } + ); + } + public Function SummonFunction() { + return new Function( + name: $"{_ctx!.Namespace}:hitbox/{Workspace}/summon", + body: (ctx) => { + Entity.Summon("interaction", [coords.x, coords.y, coords.y], "{Tags:[\"" + _ctx.Namespace + "." + Id + "\"],width:" + Width + ",height:" + Height + "}"); + Execute.Write( + Str.Execute.Asat(Entity.AllEntities("type=interaction,tag=" + _ctx.Namespace + "." + Id)) + + "on attacker ", + [Function.Call($"{_ctx.Namespace}:hitbox/{Workspace}/on_attack")] + ); + Execute.Write( + Str.Execute.Asat(Entity.AllEntities("type=interaction,tag=" + _ctx.Namespace + "." + Id)) + + "on target ", + [Function.Call($"{_ctx.Namespace}:hitbox/{Workspace}/on_right_click")] ); - } + Entity.Kill(Entity.AllEntities("type=interaction,tag=" + _ctx.Namespace + "." + Id)); + return FunctionBuilder.Collect(); + } + ); } -}*/ \ No newline at end of file +} \ No newline at end of file From 275baee365004dac30bb17f7a36d436d67bf46f9 Mon Sep 17 00:00:00 2001 From: Hazel Rojas <84425557+hazelcode@users.noreply.github.com> Date: Tue, 18 Mar 2025 02:15:30 +0000 Subject: [PATCH 18/52] Remove unused usings in Hitbox file --- Utils/Hitbox.cs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/Utils/Hitbox.cs b/Utils/Hitbox.cs index 6e5133a..fc61c6f 100644 --- a/Utils/Hitbox.cs +++ b/Utils/Hitbox.cs @@ -1,6 +1,4 @@ -using SteveSharp; -using SteveSharp.Core; -using SteveSharp.JsonShapes; +using SteveSharp.Core; using Str = SteveSharp.Core.Strings; namespace SteveSharp.Utils; From f5fd7b46393e8acdd68c6eee10cd46b0de1225bd Mon Sep 17 00:00:00 2001 From: Hazel Rojas <84425557+hazelcode@users.noreply.github.com> Date: Tue, 18 Mar 2025 02:16:37 +0000 Subject: [PATCH 19/52] Remove unused displays --- Displays.cs | 32 -------------------------------- 1 file changed, 32 deletions(-) diff --git a/Displays.cs b/Displays.cs index 39e372c..d5edba9 100644 --- a/Displays.cs +++ b/Displays.cs @@ -1,15 +1,5 @@ internal static class Displays { - internal static void ExtendedFrom(string path, string origin) - { - Console.ForegroundColor = ConsoleColor.DarkYellow; - Console.BackgroundColor = ConsoleColor.Yellow; - Console.Write(" EXT/F "); - Console.ResetColor(); - Console.ForegroundColor = ConsoleColor.Yellow; - Console.WriteLine($" Extended {path} from {origin}"); - Console.ResetColor(); - } internal static void NewFunction(string path) { Console.ForegroundColor = ConsoleColor.DarkGreen; @@ -50,16 +40,6 @@ internal static void WrittenJson(string path) Console.WriteLine($" Written {path} JSON file"); Console.ResetColor(); } - internal static void ExtendedFunction(string path) - { - Console.ForegroundColor = ConsoleColor.DarkYellow; - Console.BackgroundColor = ConsoleColor.Yellow; - Console.Write(" EXT "); - Console.ResetColor(); - Console.ForegroundColor = ConsoleColor.Yellow; - Console.WriteLine($" Extended {path}"); - Console.ResetColor(); - } internal static void SteveSharpDisplay(string name) { Console.Title = "SteveSharp Log"; @@ -77,16 +57,4 @@ internal static void ProjectCreated() Console.WriteLine(" Project created succesfully!"); Console.ResetColor(); } - internal static void ProjectNotCreated(IOException e) - { - Console.ForegroundColor = ConsoleColor.DarkRed; - Console.BackgroundColor = ConsoleColor.Red; - Console.Write(" P/E "); - Console.ResetColor(); - Console.ForegroundColor = ConsoleColor.Red; - Console.WriteLine(" Project wasn't created succesfully or completely. Check the errors:\n"); - Console.ForegroundColor = ConsoleColor.DarkRed; - Console.WriteLine(e.Message); - Console.ResetColor(); - } } \ No newline at end of file From b8b6bb9bd6fc0d5221dd72b1d41805b94865eba8 Mon Sep 17 00:00:00 2001 From: Hazel Rojas <84425557+hazelcode@users.noreply.github.com> Date: Tue, 18 Mar 2025 03:40:29 +0000 Subject: [PATCH 20/52] Make EntityEnum --- Core/Entity.cs | 4 +- Core/Strings/Entity.cs | 7 +- Generic/EntityEnum.cs | 130 +++++++++++++++++++++++++++++++++++++ Generic/EntityHandler.cs | 134 +++++++++++++++++++++++++++++++++++++++ Utils/Hitbox.cs | 3 +- 5 files changed, 275 insertions(+), 3 deletions(-) create mode 100644 Generic/EntityEnum.cs create mode 100644 Generic/EntityHandler.cs diff --git a/Core/Entity.cs b/Core/Entity.cs index 9f270fd..1e2d86b 100644 --- a/Core/Entity.cs +++ b/Core/Entity.cs @@ -1,4 +1,5 @@ -using Str = SteveSharp.Core.Strings; +using SteveSharp.Generic; +using Str = SteveSharp.Core.Strings; namespace SteveSharp.Core { @@ -17,6 +18,7 @@ public static void Custom(string selector, int? limit = null, string[]? tags = n => FunctionBuilder.Add(Str.Entity.Custom(selector, limit, tags, scores, team, type, distance, area, level, gamemode, horizontalRotation, verticalRotation, sort)); public static void Teleport(string selector, string to) => FunctionBuilder.Add(Str.Entity.Teleport(selector, to)); public static void Summon(string entity, string[] pos, string nbt = "{}") => FunctionBuilder.Add(Str.Entity.Summon(entity, pos, nbt)); + public static void Summon(EntityEnum entity, string[] pos, string nbt = "{}") => FunctionBuilder.Add(Str.Entity.Summon(entity, pos, nbt)); public static void AddTag(string selector, string tag) => FunctionBuilder.Add(Str.Entity.AddTag(selector, tag)); public static void RemoveTag(string selector, string tag) => FunctionBuilder.Add(Str.Entity.RemoveTag(selector, tag)); public static void Kill(string selector) => FunctionBuilder.Add(Str.Entity.Kill(selector)); diff --git a/Core/Strings/Entity.cs b/Core/Strings/Entity.cs index 7897ed1..bd383eb 100644 --- a/Core/Strings/Entity.cs +++ b/Core/Strings/Entity.cs @@ -1,4 +1,6 @@ -namespace SteveSharp.Core.Strings +using SteveSharp.Generic; + +namespace SteveSharp.Core.Strings { public static class Entity { @@ -44,6 +46,9 @@ public static string Summon(string entity, string[] pos, string nbt = "{}") { return $"summon {entity} {pos[0]} {pos[1]} {pos[2]} {nbt}"; } + public static string Summon(EntityEnum entity, string[] pos, string nbt = "{}") { + return Summon(EntityHandler.Get(entity), pos, nbt); + } public static string AddTag(string selector, string tag) { return $"tag {selector} add {tag}"; diff --git a/Generic/EntityEnum.cs b/Generic/EntityEnum.cs new file mode 100644 index 0000000..2ecc437 --- /dev/null +++ b/Generic/EntityEnum.cs @@ -0,0 +1,130 @@ +namespace SteveSharp.Generic; + +// https://www.digminecraft.com/lists/entity_list_pc.php +public enum EntityEnum { + Allay, + AreaEffectCloud, + Armadillo, + ArmorStand, + Arrow, + Axolotl, + Bat, + Bee, + Blaze, + BlockDisplay, + Boat, + Bogged, + Breeze, + Camel, + Cat, + CaveSpider, + BoatWithChest, + MinecartWithChest, + Chicken, + Cod, + MinecartWithCommandBlock, + Cow, + Creeper, + Dolphin, + Donkey, + DragonFireball, + Drowned, + Egg, + ElderGuardian, + EndCrystal, + EnderDragon, + EnderPearl, + Enderman, + Endermite, + Evoker, + EvokerFangs, + ExperienceBottle, + ExperienceOrb, + EyeOfEnder, + FallingBlock, + Fireball, + FireworkRocket, + Fox, + Frog, + MinecarftWithFurnace, + Ghast, + Giant, + GlowItemFrame, + GlowSquid, + Goat, + Guardian, + Hoglin, + MinecartWithHopper, + Horse, + Husk, + Illusioner, + Interaction, + IronGolem, + Item, + ItemDisplay, + ItemFrame, + LeashKnot, + LightningBolt, + Llama, + LlamaSpit, + MagmaCube, + Marker, + Minecart, + Mooshroom, + Mule, + Ocelot, + Painting, + Panda, + Parrot, + Phantom, + Pig, + Piglin, + PiglinBrute, + Pillager, + PolarBear, + Potion, + Pufferfish, + Rabbit, + Ravager, + Salmon, + Sheep, + Shulker, + ShulkerBullet, + Silverfish, + Skeleton, + SkeletonHorse, + Slime, + SmallFireball, + Sniffer, + SnowGolem, + Snowball, + MinecartWithSpawner, + SpectralArrow, + Spider, + Squid, + Stray, + Strider, + Tadpole, + TextDisplay, + TNT, + MinecartWithTNT, + TraderLlama, + Trident, + TropicalFish, + Turtle, + Vex, + Villager, + Vindicator, + WanderingTrader, + Warden, + Witch, + Wither, + WitherSkeleton, + WitherSkeletonSkull, + Wolf, + Zoglin, + Zombie, + ZombieHorse, + ZombieVillager, + ZombifiedPiglin +} \ No newline at end of file diff --git a/Generic/EntityHandler.cs b/Generic/EntityHandler.cs new file mode 100644 index 0000000..79bc3b4 --- /dev/null +++ b/Generic/EntityHandler.cs @@ -0,0 +1,134 @@ +namespace SteveSharp.Generic; + +internal static class EntityHandler { + public static string Get(EntityEnum entityEnum) { + // https://www.digminecraft.com/lists/entity_list_pc.php + Dictionary entityEnumStr = new() { + {EntityEnum.Allay, "minecraft:allay"}, + {EntityEnum.AreaEffectCloud, "minecraft:area_effect_cloud"}, + {EntityEnum.Armadillo, "minecraft:armadillo"}, + {EntityEnum.ArmorStand, "minecraft:armor_stand"}, + {EntityEnum.Arrow, "minecraft:arrow"}, + {EntityEnum.Axolotl, "minecraft:axolotl"}, + {EntityEnum.Bat, "minecraft:bat"}, + {EntityEnum.Bee, "minecraft:bee"}, + {EntityEnum.Blaze, "minecraft:blaze"}, + {EntityEnum.BlockDisplay, "minecraft:block_display"}, + {EntityEnum.Boat, "minecraft:boat"}, + {EntityEnum.Bogged, "minecraft:bogged"}, + {EntityEnum.Breeze, "minecraft:breeze"}, + {EntityEnum.Camel, "minecraft:camel"}, + {EntityEnum.Cat, "minecraft:cat"}, + {EntityEnum.CaveSpider, "minecraft:cave_spider"}, + {EntityEnum.BoatWithChest, "minecraft:chest_boat"}, + {EntityEnum.MinecartWithChest, "minecraft:chest_minecart"}, + {EntityEnum.Chicken, "minecraft:chicken"}, + {EntityEnum.Cod, "minecraft:cod"}, + {EntityEnum.MinecartWithCommandBlock, "minecraft:command_block_minecart"}, + {EntityEnum.Cow, "minecraft:cow"}, + {EntityEnum.Creeper, "minecraft:creeper"}, + {EntityEnum.Dolphin, "minecraft:dolphin"}, + {EntityEnum.Donkey, "minecraft:donkey"}, + {EntityEnum.DragonFireball, "minecraft:dragon_fireball"}, + {EntityEnum.Drowned, "minecraft:drowned"}, + {EntityEnum.Egg, "minecraft:egg"}, + {EntityEnum.ElderGuardian, "minecraft:elder_guardian"}, + {EntityEnum.EndCrystal, "minecraft:end_crystal"}, + {EntityEnum.EnderDragon, "minecraft:ender_dragon"}, + {EntityEnum.EnderPearl, "minecraft:ender_pearl"}, + {EntityEnum.Enderman, "minecraft:enderman"}, + {EntityEnum.Endermite, "minecraft:endermite"}, + {EntityEnum.Evoker, "minecraft:evoker"}, + {EntityEnum.EvokerFangs, "minecraft:evoker_fangs"}, + {EntityEnum.ExperienceBottle, "minecraft:experience_bottle"}, + {EntityEnum.ExperienceOrb, "minecraft:experience_orb"}, + {EntityEnum.FallingBlock, "minecraft:falling_block"}, + {EntityEnum.Fireball, "minecraft:fireball"}, + {EntityEnum.FireworkRocket, "minecraft:firework_rocket"}, + {EntityEnum.Fox, "minecraft:fox"}, + {EntityEnum.Frog, "minecraft:frog"}, + {EntityEnum.MinecarftWithFurnace, "minecraft:furnace_minecart"}, + {EntityEnum.Ghast, "minecraft:ghast"}, + {EntityEnum.Giant, "minecraft:giant"}, + {EntityEnum.GlowItemFrame, "minecraft:glow_item_frame"}, + {EntityEnum.GlowSquid, "minecraft:glow_squid"}, + {EntityEnum.Goat, "minecraft:goat"}, + {EntityEnum.Guardian, "minecraft:guardian"}, + {EntityEnum.Hoglin, "minecraft:hoglin"}, + {EntityEnum.MinecartWithHopper, "minecraft:hopper_minecart"}, + {EntityEnum.Horse, "minecraft:horse"}, + {EntityEnum.Husk, "minecraft:husk"}, + {EntityEnum.Illusioner, "minecraft:illusioner"}, + {EntityEnum.Interaction, "minecraft:interaction"}, + {EntityEnum.IronGolem, "minecraft:iron_golem"}, + {EntityEnum.Item, "minecraft:item"}, + {EntityEnum.ItemDisplay, "minecraft:item_display"}, + {EntityEnum.ItemFrame, "minecraft:item_frame"}, + {EntityEnum.LeashKnot, "minecraft:leash_knot"}, + {EntityEnum.LightningBolt, "minecraft:lightning_bolt"}, + {EntityEnum.Llama, "minecraft:llama"}, + {EntityEnum.LlamaSpit, "minecraft:llama_spit"}, + {EntityEnum.MagmaCube, "minecraft:magma_cube"}, + {EntityEnum.Marker, "minecraft:marker"}, + {EntityEnum.Minecart, "minecraft:minecart"}, + {EntityEnum.Mooshroom, "minecraft:mooshroom"}, + {EntityEnum.Mule, "minecraft:mule"}, + {EntityEnum.Ocelot, "minecraft:ocelot"}, + {EntityEnum.Painting, "minecraft:painting"}, + {EntityEnum.Panda, "minecraft:panda"}, + {EntityEnum.Parrot, "minecraft:parrot"}, + {EntityEnum.Phantom, "minecraft:phanton"}, + {EntityEnum.Pig, "minecraft:pig"}, + {EntityEnum.Piglin, "minecraft:piglin"}, + {EntityEnum.PiglinBrute, "minecraft:piglin_brute"}, + {EntityEnum.Pillager, "minecraft:pillager"}, + {EntityEnum.PolarBear, "minecraft:polar_bear"}, + {EntityEnum.Potion, "minecraft:potion"}, + {EntityEnum.Pufferfish, "minecraft:pufferfish"}, + {EntityEnum.Rabbit, "minecraft:rabbit"}, + {EntityEnum.Ravager, "minecraft:ravager"}, + {EntityEnum.Salmon, "minecraft:salmon"}, + {EntityEnum.Sheep, "minecraft:sheep"}, + {EntityEnum.Shulker, "minecraft:shulker"}, + {EntityEnum.ShulkerBullet, "minecraft:shulker_bullet"}, + {EntityEnum.Silverfish, "minecraft:silverfish"}, + {EntityEnum.Skeleton, "minecraft:skeleton"}, + {EntityEnum.SkeletonHorse, "minecraft:skeleton_horse"}, + {EntityEnum.Slime, "minecraft:slime"}, + {EntityEnum.SmallFireball, "minecraft:small_fireball"}, + {EntityEnum.Sniffer, "minecraft:sniffer"}, + {EntityEnum.SnowGolem, "minecraft:snow_golem"}, + {EntityEnum.Snowball, "minecraft:snowball"}, + {EntityEnum.MinecartWithSpawner, "minecraft:spawner_minecart"}, + {EntityEnum.SpectralArrow, "minecraft:spectral_arrow"}, + {EntityEnum.Spider, "minecraft:spider"}, + {EntityEnum.Squid, "minecraft:squid"}, + {EntityEnum.Stray, "minecraft:stray"}, + {EntityEnum.Strider, "minecraft:strider"}, + {EntityEnum.Tadpole, "minecraft:tadpole"}, + {EntityEnum.TextDisplay, "minecraft:text_display"}, + {EntityEnum.TNT, "minecraft:tnt"}, + {EntityEnum.MinecartWithTNT, "minecraft:tnt_minecart"}, + {EntityEnum.TraderLlama, "minecraft:trader_llama"}, + {EntityEnum.Trident, "minecraft:trident"}, + {EntityEnum.TropicalFish, "minecraft:tropical_fish"}, + {EntityEnum.Turtle, "minecraft:turtle"}, + {EntityEnum.Vex, "minecraft:vex"}, + {EntityEnum.Villager, "minecraft:villager"}, + {EntityEnum.Vindicator, "minecraft:vindicator"}, + {EntityEnum.WanderingTrader, "minecraft:wandering_trader"}, + {EntityEnum.Warden, "minecraft:warden"}, + {EntityEnum.Witch, "minecraft:witch"}, + {EntityEnum.Wither, "minecraft:wither"}, + {EntityEnum.WitherSkeleton, "minecraft:wither_skeleton"}, + {EntityEnum.WitherSkeletonSkull, "minecraft:wither_skeleton_skull"}, + {EntityEnum.Wolf, "minecraft:wolf"}, + {EntityEnum.Zoglin, "minecraft:zoglin"}, + {EntityEnum.Zombie, "minecraft:zombie"}, + {EntityEnum.ZombieHorse, "minecraft:zombie_horse"}, + {EntityEnum.ZombieVillager, "minecraft:zombie_villager"}, + {EntityEnum.ZombifiedPiglin, "minecraft:zombified_piglin"} + }; + return entityEnumStr[entityEnum]; + } +} \ No newline at end of file diff --git a/Utils/Hitbox.cs b/Utils/Hitbox.cs index fc61c6f..4d67add 100644 --- a/Utils/Hitbox.cs +++ b/Utils/Hitbox.cs @@ -1,4 +1,5 @@ using SteveSharp.Core; +using SteveSharp.Generic; using Str = SteveSharp.Core.Strings; namespace SteveSharp.Utils; @@ -49,7 +50,7 @@ public Function SummonFunction() { return new Function( name: $"{_ctx!.Namespace}:hitbox/{Workspace}/summon", body: (ctx) => { - Entity.Summon("interaction", [coords.x, coords.y, coords.y], "{Tags:[\"" + _ctx.Namespace + "." + Id + "\"],width:" + Width + ",height:" + Height + "}"); + Entity.Summon(EntityEnum.Interaction, [coords.x, coords.y, coords.y], "{Tags:[\"" + _ctx.Namespace + "." + Id + "\"],width:" + Width + ",height:" + Height + "}"); Execute.Write( Str.Execute.Asat(Entity.AllEntities("type=interaction,tag=" + _ctx.Namespace + "." + Id)) + "on attacker ", From 12e3aa56b8b81c3892bb78914db5a7e1a23657f4 Mon Sep 17 00:00:00 2001 From: Hazel Rojas <84425557+hazelcode@users.noreply.github.com> Date: Thu, 20 Mar 2025 17:59:24 +0000 Subject: [PATCH 21/52] Implement `DatapackFeatureException` exception and internal `Context` class --- Exceptions/DatapackFeatureException.cs | 11 +++++++++++ Internal/Context.cs | 5 +++++ 2 files changed, 16 insertions(+) create mode 100644 Exceptions/DatapackFeatureException.cs create mode 100644 Internal/Context.cs diff --git a/Exceptions/DatapackFeatureException.cs b/Exceptions/DatapackFeatureException.cs new file mode 100644 index 0000000..880ce8c --- /dev/null +++ b/Exceptions/DatapackFeatureException.cs @@ -0,0 +1,11 @@ +namespace SteveSharp.Exceptions; + +public class DatapackFeatureException : Exception { + public object Feature { get; } + public PackFormat PackFormat { get; } + public override string Message => $"The feature \"{Feature}\" isn't allowed to be used. You must update your project's pack format to {(int)PackFormat} to use this feature."; + public DatapackFeatureException(object feature, PackFormat packFormat) { + Feature = feature; + PackFormat = packFormat; + } +} \ No newline at end of file diff --git a/Internal/Context.cs b/Internal/Context.cs new file mode 100644 index 0000000..083b05f --- /dev/null +++ b/Internal/Context.cs @@ -0,0 +1,5 @@ +namespace SteveSharp.Internal; + +internal static class Context { + internal static PackFormat PackFormat; +} \ No newline at end of file From 2f4cb11c6af30b33b328b92da8e770999e89a6f4 Mon Sep 17 00:00:00 2001 From: Hazel Rojas <84425557+hazelcode@users.noreply.github.com> Date: Thu, 20 Mar 2025 18:01:45 +0000 Subject: [PATCH 22/52] Make use of Context --- Project.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Project.cs b/Project.cs index b102c78..70014ba 100644 --- a/Project.cs +++ b/Project.cs @@ -1,4 +1,5 @@ -using SteveSharp.JsonShapes; +using SteveSharp.Internal; +using SteveSharp.JsonShapes; using System.Text.Json; namespace SteveSharp @@ -32,6 +33,7 @@ public Project(string name, string description, string id, PackFormat packFormat _load = load; _main = main; _functions = functions; + Context.PackFormat = packFormat; FunctionIndex = new Dictionary(); string loadPath = FileOrganizer.GetFunctionPath(_load.Name); string mainPath = FileOrganizer.GetFunctionPath(_main.Name); From 12ffdf386294d8f56f2fce249bcb7f7abb787398 Mon Sep 17 00:00:00 2001 From: Hazel Rojas <84425557+hazelcode@users.noreply.github.com> Date: Thu, 20 Mar 2025 19:45:45 +0000 Subject: [PATCH 23/52] Implement Minecraft 1.20.2 changes for `pack.mcmeta` --- JsonShapes/PackMetadata.cs | 55 +++++++++++++++++++++++++++++++++++--- Project.cs | 42 +++++++++++++++++++---------- 2 files changed, 79 insertions(+), 18 deletions(-) diff --git a/JsonShapes/PackMetadata.cs b/JsonShapes/PackMetadata.cs index 3f0a6af..157a213 100644 --- a/JsonShapes/PackMetadata.cs +++ b/JsonShapes/PackMetadata.cs @@ -1,12 +1,59 @@ -namespace SteveSharp.JsonShapes +using System.Text.Json.Serialization; + +namespace SteveSharp.JsonShapes { public class PackMetadata { - public Pack? pack { get; set; } + [JsonPropertyName("pack")] + public Pack? Pack { get; set; } } public class Pack { - public string? description { get; set; } - public int pack_format { get; set; } + [JsonPropertyName("description")] + public string? Description { get; set; } + + [JsonPropertyName("pack_format")] + public PackFormat PackFormat { get; set; } + + /// + /// Pack Format 18+ Feature. + /// Values accepted by the pack metadata: + /// SupportedFormats = + /// SupportedFormats = new PackFormat[] {, } + /// SupportedFormats = new List {, } + /// SupportedFormats = new SupportedFormatsRange { + /// MinInclusive = , + /// MaxInclusive = + /// } + /// + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + [JsonPropertyName("supported_formats")] + public dynamic? SupportedFormats { get; set; } + + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] + [JsonPropertyName("overlays")] + public OverlaysField Overlays { get; set; } + } + + public struct SupportedFormatsRange { + [JsonPropertyName("min_inclusive")] + public PackFormat MinInclusive { get; set; } + + [JsonPropertyName("max_inclusive")] + public PackFormat MaxInclusive { get; set; } + } + + public struct OverlaysField { + [JsonPropertyName("entries")] + public OverlayEntry[] Entries { get; set; } + } + + public struct OverlayEntry { + // Same as supported_formats + [JsonPropertyName("formats")] + public dynamic Formats { get; set; } + + [JsonPropertyName("directory")] + public string Directory { get; set; } } } diff --git a/Project.cs b/Project.cs index 70014ba..fc07710 100644 --- a/Project.cs +++ b/Project.cs @@ -1,4 +1,5 @@ -using SteveSharp.Internal; +using SteveSharp.Exceptions; +using SteveSharp.Internal; using SteveSharp.JsonShapes; using System.Text.Json; @@ -9,7 +10,7 @@ public class Project private string _name { get; set; } private string _description { get; set; } - private int _packFormat { get; set; } + private PackFormat _packFormat { get; set; } private string _namespace { get; set; } public Dictionary FunctionIndex { get; set; } private readonly Function _load; @@ -22,14 +23,14 @@ private string[] GetFunctionCommands(string functionName) { return FunctionContents[functionName]; } - public Project(string name, string description, string id, PackFormat packFormat, Function load, Function main, List functions, List> matrix = null!, List jsonFiles = null!) + public Project(string name, string description, string id, PackFormat packFormat, Function load, Function main, List functions, List> matrix = null!, List jsonFiles = null!, PackMetadata customPackMetadata = null!) { // Display fresh SteveSharp Display Displays.SteveSharpDisplay(name); _name = name; _description = description; _namespace = id; - _packFormat = (int)packFormat; + _packFormat = packFormat; _load = load; _main = main; _functions = functions; @@ -41,14 +42,27 @@ public Project(string name, string description, string id, PackFormat packFormat Environment.CurrentDirectory = name; FileOrganizer.CreateFullDirectory($"data/{id}/functions"); FileOrganizer.CreateFullDirectory($"data/minecraft/tags/functions"); - var metadata = new PackMetadata - { - pack = new Pack - { - description = description, - pack_format = _packFormat + var metadata = new PackMetadata(); + if(customPackMetadata != null) { + metadata = customPackMetadata; + // Restriction for supported_formats field + // Beware: If you have specified a custom pack metadata and you have + // specified the supported formats field, + // and you specified a pack_format under 18, + // the code will throw an DatapackFeatureException. + if( + metadata.Pack!.SupportedFormats != null + && metadata.Pack!.PackFormat < PackFormat.Format18) { + throw new DatapackFeatureException("supported_formats", PackFormat.Format18); } - }; + } else { + metadata = new PackMetadata { + Pack = new Pack { + Description = description, + PackFormat = _packFormat + } + }; + } File.WriteAllText("pack.mcmeta", JsonSerializer.Serialize(metadata, new JsonSerializerOptions { WriteIndented = true })); File.WriteAllText($"data/minecraft/tags/functions/load.json", JsonSerializer.Serialize(new Tag @@ -63,10 +77,10 @@ public Project(string name, string description, string id, PackFormat packFormat }, new JsonSerializerOptions { WriteIndented = true }) ); Displays.ProjectCreated(); - FunctionBuilder.BuildFunction(_load, _namespace, _packFormat, this); + FunctionBuilder.BuildFunction(_load, _namespace, (int)_packFormat, this); File.WriteAllLines(loadPath, GetFunctionCommands(_load.Name)); Displays.WrittenFunction(_load.Name); - FunctionBuilder.BuildFunction(_main, _namespace, _packFormat, this); + FunctionBuilder.BuildFunction(_main, _namespace, (int)_packFormat, this); File.WriteAllLines(mainPath, GetFunctionCommands(_main.Name)); Displays.WrittenFunction(_main.Name); @@ -105,7 +119,7 @@ public Project(string name, string description, string id, PackFormat packFormat { Directory.CreateDirectory(directory); } - FunctionBuilder.BuildFunction(function.Value, _namespace, _packFormat, this); + FunctionBuilder.BuildFunction(function.Value, _namespace, (int)_packFormat, this); File.WriteAllLines(FileOrganizer.GetFunctionPath(function.Value.Name), GetFunctionCommands(function.Value.Name)); } From 9ad33c83b1fe387fe2d217ff00719fe69ac6d0c3 Mon Sep 17 00:00:00 2001 From: Hazel Rojas <84425557+hazelcode@users.noreply.github.com> Date: Sun, 30 Mar 2025 18:15:09 +0000 Subject: [PATCH 24/52] Add `/effect` command (`Effect`) and implement `StatusEffect` enumeration --- Core/Effect.cs | 22 ++++++++++++ Core/Strings/Effect.cs | 42 ++++++++++++++++++++++ Generic/StatusEffect.cs | 62 ++++++++++++++++++++++++++++++++ Generic/StatusEffectHandler.cs | 64 ++++++++++++++++++++++++++++++++++ 4 files changed, 190 insertions(+) create mode 100644 Core/Effect.cs create mode 100644 Core/Strings/Effect.cs create mode 100644 Generic/StatusEffect.cs create mode 100644 Generic/StatusEffectHandler.cs diff --git a/Core/Effect.cs b/Core/Effect.cs new file mode 100644 index 0000000..dcef01e --- /dev/null +++ b/Core/Effect.cs @@ -0,0 +1,22 @@ +using SteveSharp.Generic; +using Str = SteveSharp.Core.Strings; + +namespace SteveSharp.Core; + +public static class Effect { + public static void Give(string targets, StatusEffect effect, bool infinite = false, int amplifier = 0) => FunctionBuilder.Add(Str.Effect.Give(targets, effect, infinite, amplifier)); + + public static void Give(string targets, StatusEffect effect, int seconds, int amplifier = 0) => FunctionBuilder.Add(Str.Effect.Give(targets, effect, seconds, amplifier)); + + public static void Give(string targets, string effect, bool infinite = false, int amplifier = 0) => FunctionBuilder.Add(Str.Effect.Give(targets, effect, infinite, amplifier)); + + public static void Give(string targets, string effect, int seconds, int amplifier = 0) => FunctionBuilder.Add(Str.Effect.Give(targets, effect, seconds, amplifier)); + + public static void Clear() => FunctionBuilder.Add(Str.Effect.Clear()); + + public static void Clear(string targets) => FunctionBuilder.Add(Str.Effect.Clear(targets)); + + public static void Clear(string targets, StatusEffect effect) => FunctionBuilder.Add(Str.Effect.Clear(targets, effect)); + + public static void Clear(string targets, string effect) => FunctionBuilder.Add(Str.Effect.Clear(targets, effect)); +} \ No newline at end of file diff --git a/Core/Strings/Effect.cs b/Core/Strings/Effect.cs new file mode 100644 index 0000000..48bbeb8 --- /dev/null +++ b/Core/Strings/Effect.cs @@ -0,0 +1,42 @@ +using SteveSharp.Generic; + +namespace SteveSharp.Core.Strings; + +public static class Effect { + public static string Give(string targets, StatusEffect effect, bool infinite = false, int amplifier = 0) { + if(infinite) { + return $"effect give {targets} {StatusEffectHandler.Get(effect)} infinite {amplifier}"; + } else { + return $"effect give {targets} {StatusEffectHandler.Get(effect)}"; + } + } + public static string Give(string targets, StatusEffect effect, int seconds, int amplifier = 0) { + return $"effect give {targets} {StatusEffectHandler.Get(effect)} {seconds} {amplifier}"; + } + public static string Give(string targets, string effect, bool infinite = false, int amplifier = 0) { + if(infinite) { + return $"effect give {targets} {effect} infinite {amplifier}"; + } else { + return $"effect give {targets} {effect}"; + } + } + public static string Give(string targets, string effect, int seconds, int amplifier = 0) { + return $"effect give {targets} {effect} {seconds} {amplifier}"; + } + + public static string Clear() { + return "effect clear"; + } + + public static string Clear(string targets) { + return $"effect clear {targets}"; + } + + public static string Clear(string targets, StatusEffect effect) { + return $"effect clear {targets} {StatusEffectHandler.Get(effect)}"; + } + + public static string Clear(string targets, string effect) { + return $"effect clear {targets} {effect}"; + } +} \ No newline at end of file diff --git a/Generic/StatusEffect.cs b/Generic/StatusEffect.cs new file mode 100644 index 0000000..d227add --- /dev/null +++ b/Generic/StatusEffect.cs @@ -0,0 +1,62 @@ +namespace SteveSharp.Generic; + +// https://www.digminecraft.com/lists/effect_list_pc.php +public enum StatusEffect { + Absorption, + BadLuck, + BadOmen, + Blindness, + ConduitPower, + Darkness, + DolphinsGrace, + FireResistance, + Glowing, + Haste, + HealthBoost, + HeroOfTheVillage, + Hunger, + /// + /// Minecraft 1.21 + /// + Infested, + InstantDamage, + InstantHealth, + Invisibility, + JumpBoost, + Levitation, + Luck, + MiningFatigue, + Nausea, + NightVision, + /// + /// Minecraft 1.21 + /// + Oozing, + Poison, + /// + /// Minecraft 1.21 + /// + RaidOmen, + Regeneration, + Resistance, + Saturation, + SlowFalling, + Slowness, + Speed, + Strength, + /// + /// Minecraft 1.21 + /// + TrialOmen, + WaterBreathing, + Weakness, + /// + /// Minecraft 1.21 + /// + Weaving, + /// + /// Minecraft 1.21 + /// + WindCharged, + Wither +} \ No newline at end of file diff --git a/Generic/StatusEffectHandler.cs b/Generic/StatusEffectHandler.cs new file mode 100644 index 0000000..a34ded3 --- /dev/null +++ b/Generic/StatusEffectHandler.cs @@ -0,0 +1,64 @@ +using SteveSharp.Exceptions; +using SteveSharp.Internal; + +namespace SteveSharp.Generic; + +// https://www.digminecraft.com/lists/effect_list_pc.php +public static class StatusEffectHandler { + public static string Get(StatusEffect effect) { + Dictionary statusEffectStr = new() { + {StatusEffect.Absorption, "absorption"}, + {StatusEffect.BadLuck, "unluck"}, + {StatusEffect.BadOmen, "bad_omen"}, + {StatusEffect.Blindness, "blindness"}, + {StatusEffect.ConduitPower, "conduit_power"}, + {StatusEffect.Darkness, "darkness"}, + {StatusEffect.DolphinsGrace, "dolphins_grace"}, + {StatusEffect.FireResistance, "fire_resistance"}, + {StatusEffect.Glowing, "glowing"}, + {StatusEffect.Haste, "haste"}, + {StatusEffect.HealthBoost, "health_boost"}, + {StatusEffect.HeroOfTheVillage, "hero_of_the_village"}, + {StatusEffect.Hunger, "hunger"}, + {StatusEffect.Infested, "infested"}, + {StatusEffect.InstantDamage, "instant_damage"}, + {StatusEffect.InstantHealth, "instant_health"}, + {StatusEffect.Invisibility, "invisibility"}, + {StatusEffect.JumpBoost, "jump_boost"}, + {StatusEffect.Levitation, "levitation"}, + {StatusEffect.Luck, "luck"}, + {StatusEffect.MiningFatigue, "mining_fatigue"}, + {StatusEffect.Nausea, "nausea"}, + {StatusEffect.NightVision, "night_vision"}, + {StatusEffect.Oozing, "oozing"}, + {StatusEffect.Poison, "poison"}, + {StatusEffect.RaidOmen, "raid_omen"}, + {StatusEffect.Regeneration, "regeneration"}, + {StatusEffect.Resistance, "resistance"}, + {StatusEffect.Saturation, "saturation"}, + {StatusEffect.SlowFalling, "slow_falling"}, + {StatusEffect.Slowness, "slowness"}, + {StatusEffect.Speed, "speed"}, + {StatusEffect.Strength, "strength"}, + {StatusEffect.TrialOmen, "trial_omen"}, + {StatusEffect.WaterBreathing, "water_breathing"}, + {StatusEffect.Weakness, "weakness"}, + {StatusEffect.Weaving, "weaving"}, + {StatusEffect.WindCharged, "wind_charged"}, + {StatusEffect.Wither, "wither"} + }; + if( + Context.PackFormat < PackFormat.Format48 + && (effect == StatusEffect.Infested + || effect == StatusEffect.Oozing + || effect == StatusEffect.RaidOmen + || effect == StatusEffect.TrialOmen + || effect == StatusEffect.Weaving + || effect == StatusEffect.WindCharged) + ) { + // Only available for Minecraft 1.21 + throw new DatapackFeatureException(effect, PackFormat.Format48); + } + return statusEffectStr[effect]; + } +} \ No newline at end of file From 3b222c80037d2c93fa113b29e47992ef8020d676 Mon Sep 17 00:00:00 2001 From: Hazel Rojas <84425557+hazelcode@users.noreply.github.com> Date: Sun, 30 Mar 2025 20:02:00 +0000 Subject: [PATCH 25/52] Implement EntityTarget and other great changes --- Core/Chat.cs | 10 +++-- Core/Effect.cs | 7 +++ Core/Entity.cs | 32 +++++++++----- Core/Execute.cs | 15 ++++--- Core/Recipe.cs | 3 ++ Core/Score.cs | 70 ++++++++++++++++++++++-------- Core/Strings/Chat.cs | 24 ++++++++--- Core/Strings/Effect.cs | 33 ++++++++++++-- Core/Strings/Entity.cs | 66 ++++++++++++++++++++++------ Core/Strings/Execute.cs | 41 +++++++++++++----- Core/Strings/Recipe.cs | 4 ++ Core/Strings/Score.cs | 79 +++++++++++++++++++++++++--------- Generic/EntityTarget.cs | 9 ++++ Generic/EntityTargetHandler.cs | 15 +++++++ 14 files changed, 318 insertions(+), 90 deletions(-) create mode 100644 Generic/EntityTarget.cs create mode 100644 Generic/EntityTargetHandler.cs diff --git a/Core/Chat.cs b/Core/Chat.cs index 30c6f9c..34564ce 100644 --- a/Core/Chat.cs +++ b/Core/Chat.cs @@ -1,4 +1,5 @@ -using SteveSharp.JsonShapes; +using SteveSharp.Generic; +using SteveSharp.JsonShapes; using System.Text.Json; using Str = SteveSharp.Core.Strings; @@ -7,8 +8,11 @@ namespace SteveSharp.Core public static class Chat { public static void Say(string msg) => FunctionBuilder.Add(Str.Chat.Say(msg)); + public static void Tell(EntityTarget targets, string message) => FunctionBuilder.Add(Str.Chat.Tell(targets, message)); public static void Tell(string targets, string message) => FunctionBuilder.Add(Str.Chat.Tell(targets, message)); - public static void Tellraw(string selector, TextComponent[] text) => FunctionBuilder.Add(Str.Chat.Tellraw(selector, text)); - public static void Tellraw(string selector, TextComponent text) => FunctionBuilder.Add(Str.Chat.Tellraw(selector, text)); + public static void Tellraw(EntityTarget targets, TextComponent[] text) => FunctionBuilder.Add(Str.Chat.Tellraw(targets, text)); + public static void Tellraw(string targets, TextComponent[] text) => FunctionBuilder.Add(Str.Chat.Tellraw(targets, text)); + public static void Tellraw(EntityTarget targets, TextComponent text) => FunctionBuilder.Add(Str.Chat.Tellraw(targets, text)); + public static void Tellraw(string targets, TextComponent text) => FunctionBuilder.Add(Str.Chat.Tellraw(targets, text)); } } diff --git a/Core/Effect.cs b/Core/Effect.cs index dcef01e..07d2d5e 100644 --- a/Core/Effect.cs +++ b/Core/Effect.cs @@ -4,19 +4,26 @@ namespace SteveSharp.Core; public static class Effect { + public static void Give(EntityTarget targets, StatusEffect effect, bool infinite = false, int amplifier = 0) => FunctionBuilder.Add(Str.Effect.Give(targets, effect, infinite, amplifier)); public static void Give(string targets, StatusEffect effect, bool infinite = false, int amplifier = 0) => FunctionBuilder.Add(Str.Effect.Give(targets, effect, infinite, amplifier)); + public static void Give(EntityTarget targets, StatusEffect effect, int seconds, int amplifier = 0) => FunctionBuilder.Add(Str.Effect.Give(targets, effect, seconds, amplifier)); public static void Give(string targets, StatusEffect effect, int seconds, int amplifier = 0) => FunctionBuilder.Add(Str.Effect.Give(targets, effect, seconds, amplifier)); + public static void Give(EntityTarget targets, string effect, bool infinite = false, int amplifier = 0) => FunctionBuilder.Add(Str.Effect.Give(targets, effect, infinite, amplifier)); public static void Give(string targets, string effect, bool infinite = false, int amplifier = 0) => FunctionBuilder.Add(Str.Effect.Give(targets, effect, infinite, amplifier)); + public static void Give(EntityTarget targets, string effect, int seconds, int amplifier = 0) => FunctionBuilder.Add(Str.Effect.Give(targets, effect, seconds, amplifier)); public static void Give(string targets, string effect, int seconds, int amplifier = 0) => FunctionBuilder.Add(Str.Effect.Give(targets, effect, seconds, amplifier)); public static void Clear() => FunctionBuilder.Add(Str.Effect.Clear()); + public static void Clear(EntityTarget targets) => FunctionBuilder.Add(Str.Effect.Clear(targets)); public static void Clear(string targets) => FunctionBuilder.Add(Str.Effect.Clear(targets)); + public static void Clear(EntityTarget targets, StatusEffect effect) => FunctionBuilder.Add(Str.Effect.Clear(targets, effect)); public static void Clear(string targets, StatusEffect effect) => FunctionBuilder.Add(Str.Effect.Clear(targets, effect)); + public static void Clear(EntityTarget targets, string effect) => FunctionBuilder.Add(Str.Effect.Clear(targets, effect)); public static void Clear(string targets, string effect) => FunctionBuilder.Add(Str.Effect.Clear(targets, effect)); } \ No newline at end of file diff --git a/Core/Entity.cs b/Core/Entity.cs index 1e2d86b..5d09711 100644 --- a/Core/Entity.cs +++ b/Core/Entity.cs @@ -5,22 +5,32 @@ namespace SteveSharp.Core { public static class Entity { - public static string Self(string match = "") { if (match == "") return "@s"; else return "@s[" + match + "]"; } - public static string Everyone(string match = "") { if (match == "") return "@a"; else return "@a[" + match + "]"; } - public static string Random(string match = "") { if (match == "") return "@r"; else return "@r[" + match + "]"; } - public static string Closest(string match = "") { if (match == "") return "@p"; else return "@p[" + match + "]"; } + public static string Selected(string match = "") { if (match == "") return "@s"; else return "@s[" + match + "]"; } + public static string AllPlayers(string match = "") { if (match == "") return "@a"; else return "@a[" + match + "]"; } + public static string RandomPlayer(string match = "") { if (match == "") return "@r"; else return "@r[" + match + "]"; } + public static string NearestPlayer(string match = "") { if (match == "") return "@p"; else return "@p[" + match + "]"; } public static string AllEntities(string match = "") { if (match == "") return "@e"; else return "@e[" + match + "]"; } /// /// This method selects an entity with specific matches, recommended if you want to select an entity with specific matches. /// /// - public static void Custom(string selector, int? limit = null, string[]? tags = null, string[]? scores = null, string? team = null, string? type = null, string? distance = null, string? area = null, string? level = null, string? gamemode = null, string? horizontalRotation = null, string? verticalRotation = null, string? sort = null) - => FunctionBuilder.Add(Str.Entity.Custom(selector, limit, tags, scores, team, type, distance, area, level, gamemode, horizontalRotation, verticalRotation, sort)); - public static void Teleport(string selector, string to) => FunctionBuilder.Add(Str.Entity.Teleport(selector, to)); - public static void Summon(string entity, string[] pos, string nbt = "{}") => FunctionBuilder.Add(Str.Entity.Summon(entity, pos, nbt)); + public static void Custom(EntityTarget targets, int? limit = null, string[]? tags = null, string[]? scores = null, string? team = null, string? type = null, string? distance = null, string? area = null, string? level = null, string? gamemode = null, string? horizontalRotation = null, string? verticalRotation = null, string? sort = null) + => FunctionBuilder.Add(Str.Entity.Custom(targets, limit, tags, scores, team, type, distance, area, level, gamemode, horizontalRotation, verticalRotation, sort)); + public static void Custom(string targets, int? limit = null, string[]? tags = null, string[]? scores = null, string? team = null, string? type = null, string? distance = null, string? area = null, string? level = null, string? gamemode = null, string? horizontalRotation = null, string? verticalRotation = null, string? sort = null) + => FunctionBuilder.Add(Str.Entity.Custom(targets, limit, tags, scores, team, type, distance, area, level, gamemode, horizontalRotation, verticalRotation, sort)); + public static void Teleport(EntityTarget targets, string to) => FunctionBuilder.Add(Str.Entity.Teleport(targets, to)); + public static void Teleport(string targets, string to) => FunctionBuilder.Add(Str.Entity.Teleport(targets, to)); + public static void Summon(EntityEnum entity, (int X, int Y, int Z) pos, string nbt = "{}") => FunctionBuilder.Add(Str.Entity.Summon(entity, pos, nbt)); + public static void Summon(EntityEnum entity, (string X, string Y, string Z) rel, string nbt = "{}") => FunctionBuilder.Add(Str.Entity.Summon(entity, rel, nbt)); public static void Summon(EntityEnum entity, string[] pos, string nbt = "{}") => FunctionBuilder.Add(Str.Entity.Summon(entity, pos, nbt)); - public static void AddTag(string selector, string tag) => FunctionBuilder.Add(Str.Entity.AddTag(selector, tag)); - public static void RemoveTag(string selector, string tag) => FunctionBuilder.Add(Str.Entity.RemoveTag(selector, tag)); - public static void Kill(string selector) => FunctionBuilder.Add(Str.Entity.Kill(selector)); + public static void Summon(string entity, (int X, int Y, int Z) pos, string nbt = "{}") => FunctionBuilder.Add(Str.Entity.Summon(entity, pos, nbt)); + public static void Summon(string entity, (string X, string Y, string Z) rel, string nbt = "{}") => FunctionBuilder.Add(Str.Entity.Summon(entity, rel, nbt)); + public static void Summon(string entity, string[] pos, string nbt = "{}") => FunctionBuilder.Add(Str.Entity.Summon(entity, pos, nbt)); + public static void AddTag(EntityTarget targets, string tag) => FunctionBuilder.Add(Str.Entity.AddTag(targets, tag)); + public static void AddTag(string targets, string tag) => FunctionBuilder.Add(Str.Entity.AddTag(targets, tag)); + public static void RemoveTag(EntityTarget targets, string tag) => FunctionBuilder.Add(Str.Entity.RemoveTag(targets, tag)); + public static void RemoveTag(string targets, string tag) => FunctionBuilder.Add(Str.Entity.RemoveTag(targets, tag)); + public static void Kill(EntityTarget targets) => FunctionBuilder.Add(Str.Entity.Kill(targets)); + public static void Kill(string targets) => FunctionBuilder.Add(Str.Entity.Kill(targets)); } } \ No newline at end of file diff --git a/Core/Execute.cs b/Core/Execute.cs index d43480f..2ac0499 100644 --- a/Core/Execute.cs +++ b/Core/Execute.cs @@ -1,4 +1,5 @@ -using Str = SteveSharp.Core.Strings; +using SteveSharp.Generic; +using Str = SteveSharp.Core.Strings; namespace SteveSharp.Core { @@ -6,13 +7,17 @@ public static class Execute { const string[] defaults = null; public static void Write(string execute, string[] commands = defaults) => FunctionBuilder.Add(Str.Execute.Write(execute, commands)); - public static void As(string selector, string addition = "") => FunctionBuilder.Add(Str.Execute.As(selector, addition)); - public static void At(string selector, string addition = "") => FunctionBuilder.Add(Str.Execute.At(selector, addition)); - public static void Asat(string selector, string addition = "") => FunctionBuilder.Add(Str.Execute.Asat(selector, addition)); + public static void As(EntityTarget targets, string addition = "") => FunctionBuilder.Add(Str.Execute.As(targets, addition)); + public static void As(string targets, string addition = "") => FunctionBuilder.Add(Str.Execute.As(targets, addition)); + public static void At(EntityTarget targets, string addition = "") => FunctionBuilder.Add(Str.Execute.At(targets, addition)); + public static void At(string targets, string addition = "") => FunctionBuilder.Add(Str.Execute.At(targets, addition)); + public static void Asat(EntityTarget targets, string addition = "") => FunctionBuilder.Add(Str.Execute.Asat(targets, addition)); + public static void Asat(string targets, string addition = "") => FunctionBuilder.Add(Str.Execute.Asat(targets, addition)); public static void Unless(string arguments, string addition = "") => FunctionBuilder.Add(Str.Execute.Unless(arguments, addition)); public static void If(string arguments, string addition = "") => FunctionBuilder.Add(Str.Execute.If(arguments, addition)); public static void Summon(string entity, string[] pos, string addition = "") => FunctionBuilder.Add(Str.Execute.Summon(entity, pos, addition)); public static void Store(string where, string at, string arguments, string addition = "") => FunctionBuilder.Add(Str.Execute.Store(where, at, arguments, addition)); - public static void StoreScore(string where, Score score, string selector = "", string addition = "") => FunctionBuilder.Add(Str.Execute.StoreScore(where, score, selector, addition)); + public static void StoreScore(string where, Score score, EntityTarget targets, string addition = "") => FunctionBuilder.Add(Str.Execute.StoreScore(where, score, targets, addition)); + public static void StoreScore(string where, Score score, string targets = "", string addition = "") => FunctionBuilder.Add(Str.Execute.StoreScore(where, score, targets, addition)); } } diff --git a/Core/Recipe.cs b/Core/Recipe.cs index b6066c6..72de33b 100644 --- a/Core/Recipe.cs +++ b/Core/Recipe.cs @@ -1,8 +1,11 @@ +using SteveSharp.Generic; using Str = SteveSharp.Core.Strings; namespace SteveSharp.Core; public static class Recipe { + public static void Give(EntityTarget targets, string recipe) => FunctionBuilder.Add(Str.Recipe.Give(targets, recipe)); public static void Give(string targets, string recipe) => FunctionBuilder.Add(Str.Recipe.Give(targets, recipe)); + public static void Take(EntityTarget targets, string recipe) => FunctionBuilder.Add(Str.Recipe.Take(targets, recipe)); public static void Take(string targets, string recipe) => FunctionBuilder.Add(Str.Recipe.Take(targets, recipe)); } \ No newline at end of file diff --git a/Core/Score.cs b/Core/Score.cs index fcaa747..a69e212 100644 --- a/Core/Score.cs +++ b/Core/Score.cs @@ -1,4 +1,5 @@ -using Str = SteveSharp.Core.Strings; +using SteveSharp.Generic; +using Str = SteveSharp.Core.Strings; namespace SteveSharp.Core { @@ -25,37 +26,65 @@ public static void AddObjectives(Score[] scores) { } FunctionBuilder.Add(commands); } - public void Set(int count, string selector = "") + public void Set(int count, string targets = "") { - Set(id, count, selector); + FunctionBuilder.Add(Str.Score.Set(id, count, targets)); } - public static void Set(string id, int count, string selector = "") + public void Set(int count, EntityTarget targets) { - FunctionBuilder.Add(Str.Score.Set(id, count, selector)); + FunctionBuilder.Add(Str.Score.Set(id, count, targets)); } - public void Add(int count, string selector = "") + public static void Set(string id, int count, string targets = "") { - Add(id, count, selector); + FunctionBuilder.Add(Str.Score.Set(id, count, targets)); } - public static void Add(string id, int count, string selector = "") + public void Add(int count, string targets = "") { - FunctionBuilder.Add(Str.Score.Add(id, count, selector)); + FunctionBuilder.Add(Str.Score.Add(id, count, targets)); } - public void Remove(int count, string selector = "") + public void Add(int count, EntityTarget targets) { - Remove(id, count, selector); + FunctionBuilder.Add(Str.Score.Add(id, count, targets)); } - public static void Remove(string id, int count, string selector = "") + public static void Add(string id, int count, string targets = "") { - FunctionBuilder.Add(Str.Score.Remove(id, count, selector)); + FunctionBuilder.Add(Str.Score.Add(id, count, targets)); } - public void Reset(string selector = "") + public static void Add(string id, int count, EntityTarget targets) { - Reset(id, selector); + FunctionBuilder.Add(Str.Score.Add(id, count, targets)); } - public static void Reset(string id, string selector = "") + public void Remove(int count, string targets = "") { - FunctionBuilder.Add(Str.Score.Reset(id, selector)); + FunctionBuilder.Add(Str.Score.Remove(id, count, targets)); + } + public void Remove(int count, EntityTarget targets) + { + FunctionBuilder.Add(Str.Score.Remove(id, count, targets)); + } + public static void Remove(string id, int count, string targets = "") + { + FunctionBuilder.Add(Str.Score.Remove(id, count, targets)); + } + public static void Remove(string id, int count, EntityTarget targets) + { + FunctionBuilder.Add(Str.Score.Remove(id, count, targets)); + } + public void Reset(string targets = "") + { + FunctionBuilder.Add(Str.Score.Reset(id, targets)); + } + public void Reset(EntityTarget targets) + { + FunctionBuilder.Add(Str.Score.Reset(id, targets)); + } + public static void Reset(string id, string targets = "") + { + FunctionBuilder.Add(Str.Score.Reset(id, targets)); + } + public static void Reset(string id, EntityTarget targets) + { + FunctionBuilder.Add(Str.Score.Reset(id, targets)); } /// /// Only for use in scores={} cases @@ -64,5 +93,12 @@ public static void Reset(string id, string selector = "") public string Matches(int value){ return this.id + '=' + value; } + /// + /// Only for use in scores={} cases + /// + /// + public static string Matches(string id, int value){ + return id + '=' + value; + } } } diff --git a/Core/Strings/Chat.cs b/Core/Strings/Chat.cs index 65f4536..477a129 100644 --- a/Core/Strings/Chat.cs +++ b/Core/Strings/Chat.cs @@ -1,4 +1,5 @@ -using SteveSharp.JsonShapes; +using SteveSharp.Generic; +using SteveSharp.JsonShapes; using System.Text.Json; namespace SteveSharp.Core.Strings @@ -9,17 +10,30 @@ public static string Say(string msg) { return $"say {msg}"; } + public static string Tell(EntityTarget targets, string message) { + return $"tell {EntityTargetHandler.Get(targets)} {message}"; + } public static string Tell(string targets, string message) { return $"tell {targets} {message}"; } - public static string Tellraw(string selector, TextComponent[] text) + public static string Tellraw(EntityTarget targets, TextComponent[] text) + { + string command = "tellraw " + EntityTargetHandler.Get(targets) + " " + JsonSerializer.Serialize(text); + return command; + } + public static string Tellraw(string targets, TextComponent[] text) + { + string command = "tellraw " + targets + " " + JsonSerializer.Serialize(text); + return command; + } + public static string Tellraw(EntityTarget targets, TextComponent text) { - string command = "tellraw " + selector + " " + JsonSerializer.Serialize(text); + string command = "tellraw " + EntityTargetHandler.Get(targets) + " " + JsonSerializer.Serialize(text); return command; } - public static string Tellraw(string selector, TextComponent text) + public static string Tellraw(string targets, TextComponent text) { - string command = "tellraw " + selector + " " + JsonSerializer.Serialize(text); + string command = "tellraw " + targets + " " + JsonSerializer.Serialize(text); return command; } } diff --git a/Core/Strings/Effect.cs b/Core/Strings/Effect.cs index 48bbeb8..44893b6 100644 --- a/Core/Strings/Effect.cs +++ b/Core/Strings/Effect.cs @@ -3,6 +3,13 @@ namespace SteveSharp.Core.Strings; public static class Effect { + public static string Give(EntityTarget targets, StatusEffect effect, bool infinite = false, int amplifier = 0) { + if(infinite) { + return $"effect give {EntityTargetHandler.Get(targets)} {StatusEffectHandler.Get(effect)} infinite {amplifier}"; + } else { + return $"effect give {EntityTargetHandler.Get(targets)} {StatusEffectHandler.Get(effect)}"; + } + } public static string Give(string targets, StatusEffect effect, bool infinite = false, int amplifier = 0) { if(infinite) { return $"effect give {targets} {StatusEffectHandler.Get(effect)} infinite {amplifier}"; @@ -10,9 +17,19 @@ public static string Give(string targets, StatusEffect effect, bool infinite = f return $"effect give {targets} {StatusEffectHandler.Get(effect)}"; } } + public static string Give(EntityTarget targets, StatusEffect effect, int seconds, int amplifier = 0) { + return $"effect give {EntityTargetHandler.Get(targets)} {StatusEffectHandler.Get(effect)} {seconds} {amplifier}"; + } public static string Give(string targets, StatusEffect effect, int seconds, int amplifier = 0) { return $"effect give {targets} {StatusEffectHandler.Get(effect)} {seconds} {amplifier}"; } + public static string Give(EntityTarget targets, string effect, bool infinite = false, int amplifier = 0) { + if(infinite) { + return $"effect give {EntityTargetHandler.Get(targets)} {effect} infinite {amplifier}"; + } else { + return $"effect give {EntityTargetHandler.Get(targets)} {effect}"; + } + } public static string Give(string targets, string effect, bool infinite = false, int amplifier = 0) { if(infinite) { return $"effect give {targets} {effect} infinite {amplifier}"; @@ -20,22 +37,30 @@ public static string Give(string targets, string effect, bool infinite = false, return $"effect give {targets} {effect}"; } } + public static string Give(EntityTarget targets, string effect, int seconds, int amplifier = 0) { + return $"effect give {EntityTargetHandler.Get(targets)} {effect} {seconds} {amplifier}"; + } public static string Give(string targets, string effect, int seconds, int amplifier = 0) { return $"effect give {targets} {effect} {seconds} {amplifier}"; } - public static string Clear() { return "effect clear"; } - + public static string Clear(EntityTarget targets) { + return $"effect clear {EntityTargetHandler.Get(targets)}"; + } public static string Clear(string targets) { return $"effect clear {targets}"; } - + public static string Clear(EntityTarget targets, StatusEffect effect) { + return $"effect clear {EntityTargetHandler.Get(targets)} {StatusEffectHandler.Get(effect)}"; + } public static string Clear(string targets, StatusEffect effect) { return $"effect clear {targets} {StatusEffectHandler.Get(effect)}"; } - + public static string Clear(EntityTarget targets, string effect) { + return $"effect clear {EntityTargetHandler.Get(targets)} {effect}"; + } public static string Clear(string targets, string effect) { return $"effect clear {targets} {effect}"; } diff --git a/Core/Strings/Entity.cs b/Core/Strings/Entity.cs index bd383eb..d946432 100644 --- a/Core/Strings/Entity.cs +++ b/Core/Strings/Entity.cs @@ -8,9 +8,15 @@ public static class Entity /// This method selects an entity with specific matches, recommended if you want to select an entity with specific matches. /// /// - public static string Custom(string selector, int? limit = null, string[]? tags = null, string[]? scores = null, string? team = null, string? type = null, string? distance = null, string? area = null, string? level = null, string? gamemode = null, string? horizontalRotation = null, string? verticalRotation = null, string? sort = null) { + public static string Custom(EntityTarget targets, int? limit = null, string[]? tags = null, string[]? scores = null, string? team = null, string? type = null, string? distance = null, string? area = null, string? level = null, string? gamemode = null, string? horizontalRotation = null, string? verticalRotation = null, string? sort = null) + => Custom(EntityTargetHandler.Get(targets), limit, tags, scores, team, type, distance, area, level, gamemode, horizontalRotation, verticalRotation, sort); + /// + /// This method selects an entity with specific matches, recommended if you want to select an entity with specific matches. + /// + /// + public static string Custom(string targets, int? limit = null, string[]? tags = null, string[]? scores = null, string? team = null, string? type = null, string? distance = null, string? area = null, string? level = null, string? gamemode = null, string? horizontalRotation = null, string? verticalRotation = null, string? sort = null) { string match = ""; - match += selector + "["; + match += targets + "["; if(limit != null) match += "limit=" + limit + ','; if(tags?.Length >= 1){ foreach(string tag in tags){ @@ -25,12 +31,12 @@ public static string Custom(string selector, int? limit = null, string[]? tags = match += "},"; } if(team != null) match += "team=" + team + ','; - if(type != null && selector != "@a" || selector != "@r" || selector != "@p") + if(type != null && targets != "@a" || targets != "@r" || targets != "@p") match += "type=" + type + ','; if(distance != null) match += "distance=" + distance + ','; if(area != null) match += area + ','; if(level != null) match += "level=" + level + ','; - if(gamemode != null && selector != "@e") match += "gamemode=" + gamemode + ','; + if(gamemode != null && targets != "@e") match += "gamemode=" + gamemode + ','; if(horizontalRotation != null) match += "y_rotation=" + horizontalRotation + ','; if(verticalRotation != null) match += "x_rotation=" + verticalRotation + ','; if(sort != null) match += "sort=" + sort + ','; @@ -38,28 +44,60 @@ public static string Custom(string selector, int? limit = null, string[]? tags = match += ']'; return match; } - public static string Teleport(string selector, string to) + public static string Teleport(EntityTarget targets, string to) { - return $"tp {selector} {to}"; + return $"tp {EntityTargetHandler.Get(targets)} {to}"; } - public static string Summon(string entity, string[] pos, string nbt = "{}") + public static string Teleport(string targets, string to) { - return $"summon {entity} {pos[0]} {pos[1]} {pos[2]} {nbt}"; + return $"tp {targets} {to}"; + } + public static string Summon(EntityEnum entity, (int X, int Y, int Z) pos, string nbt = "{}") + { + return $"summon {EntityHandler.Get(entity)} {pos.X} {pos.Y} {pos.Z} {nbt}"; + } + public static string Summon(EntityEnum entity, (string X, string Y, string Z) rel, string nbt = "{}") + { + return $"summon {EntityHandler.Get(entity)} {rel.X} {rel.Y} {rel.Z} {nbt}"; } public static string Summon(EntityEnum entity, string[] pos, string nbt = "{}") { return Summon(EntityHandler.Get(entity), pos, nbt); } - public static string AddTag(string selector, string tag) + public static string Summon(string entity, (int X, int Y, int Z) pos, string nbt = "{}") + { + return $"summon {entity} {pos.X} {pos.Y} {pos.Z} {nbt}"; + } + public static string Summon(string entity, (string X, string Y, string Z) rel, string nbt = "{}") + { + return $"summon {entity} {rel.X} {rel.Y} {rel.Z} {nbt}"; + } + public static string Summon(string entity, string[] pos, string nbt = "{}") + { + return $"summon {entity} {pos[0]} {pos[1]} {pos[2]} {nbt}"; + } + public static string AddTag(EntityTarget targets, string tag) + { + return $"tag {EntityTargetHandler.Get(targets)} add {tag}"; + } + public static string AddTag(string targets, string tag) + { + return $"tag {targets} add {tag}"; + } + public static string RemoveTag(EntityTarget targets, string tag) + { + return $"tag {EntityTargetHandler.Get(targets)} remove {tag}"; + } + public static string RemoveTag(string targets, string tag) { - return $"tag {selector} add {tag}"; + return $"tag {targets} remove {tag}"; } - public static string RemoveTag(string selector, string tag) + public static string Kill(EntityTarget targets) { - return $"tag {selector} remove {tag}"; + return $"kill {EntityTargetHandler.Get(targets)}"; } - public static string Kill(string selector) + public static string Kill(string targets) { - return $"kill {selector}"; + return $"kill {targets}"; } } } diff --git a/Core/Strings/Execute.cs b/Core/Strings/Execute.cs index d4226db..fddd7b0 100644 --- a/Core/Strings/Execute.cs +++ b/Core/Strings/Execute.cs @@ -1,4 +1,5 @@ -using Core = SteveSharp.Core; +using SteveSharp.Generic; +using Core = SteveSharp.Core; namespace SteveSharp.Core.Strings { @@ -14,17 +15,29 @@ public static string Write(string execute, string[] commands = defaults) } return allCommands; } - public static string As(string selector, string addition = "") + public static string As(EntityTarget targets, string addition = "") { - return "as " + selector + " " + addition; + return "as " + EntityTargetHandler.Get(targets) + " " + addition; } - public static string At(string selector, string addition = "") + public static string As(string targets, string addition = "") { - return "at " + selector + " " + addition; + return "as " + targets + " " + addition; } - public static string Asat(string selector, string addition = "") + public static string At(EntityTarget targets, string addition = "") { - return "as " + selector + " at @s " + addition; + return "at " + EntityTargetHandler.Get(targets) + " " + addition; + } + public static string At(string targets, string addition = "") + { + return "at " + targets + " " + addition; + } + public static string Asat(EntityTarget targets, string addition = "") + { + return "as " + EntityTargetHandler.Get(targets) + " at @s " + addition; + } + public static string Asat(string targets, string addition = "") + { + return "as " + targets + " at @s " + addition; } public static string Unless(string arguments, string addition = "") { @@ -34,6 +47,10 @@ public static string If(string arguments, string addition = "") { return "if " + arguments + " " + addition; } + public static string Summon(EntityEnum entity, string[] pos, string addition = "") + { + return "summon " + EntityHandler.Get(entity) + " " + pos[0] + " " + pos[1] + " " + pos[2] + " " + addition; + } public static string Summon(string entity, string[] pos, string addition = "") { return "summon " + entity + " " + pos[0] + " " + pos[1] + " " + pos[2] + " " + addition; @@ -42,15 +59,19 @@ public static string Store(string where, string at, string arguments, string add { return "store " + where + " " + at + " " + arguments + " " + addition; } - public static string StoreScore(string where, Core.Score score, string selector = "", string addition = "") + public static string StoreScore(string where, Core.Score score, EntityTarget targets, string addition = "") + { + return "store " + where + " score " + EntityTargetHandler.Get(targets) + " " + score.id + " " + addition; + } + public static string StoreScore(string where, Core.Score score, string targets = "", string addition = "") { - if (selector == "") + if (targets == "") { return "store " + where + " score " + "#" + score.id + " " + score.id + " " + addition; } else { - return "store " + where + " score " + selector + " " + score.id + " " + addition; + return "store " + where + " score " + targets + " " + score.id + " " + addition; } } } diff --git a/Core/Strings/Recipe.cs b/Core/Strings/Recipe.cs index 32bd0e7..39a8d1e 100644 --- a/Core/Strings/Recipe.cs +++ b/Core/Strings/Recipe.cs @@ -1,6 +1,10 @@ +using SteveSharp.Generic; + namespace SteveSharp.Core.Strings; public static class Recipe { + public static string Give(EntityTarget targets, string recipe) => $"recipe give {EntityTargetHandler.Get(targets)} {recipe}"; public static string Give(string targets, string recipe) => $"recipe give {targets} {recipe}"; + public static string Take(EntityTarget targets, string recipe) => $"recipe take {EntityTargetHandler.Get(targets)} {recipe}"; public static string Take(string targets, string recipe) => $"recipe take {targets} {recipe}"; } \ No newline at end of file diff --git a/Core/Strings/Score.cs b/Core/Strings/Score.cs index 3c9ac45..c2c4c1a 100644 --- a/Core/Strings/Score.cs +++ b/Core/Strings/Score.cs @@ -1,4 +1,6 @@ -namespace SteveSharp.Core.Strings +using SteveSharp.Generic; + +namespace SteveSharp.Core.Strings { public class Score { @@ -34,65 +36,96 @@ public static string AddObjectives(Score[] scores) } return commands; } - public string Set(int count, string selector = "") + public string Set(int count, string targets = "") { - return Set(id, count, selector); + return Set(id, count, targets); } - public static string Set(string id, int count, string selector = "") + public string Set(int count, EntityTarget targets) { - if(selector == "") + return Set(id, count, EntityTargetHandler.Get(targets)); + } + public static string Set(string id, int count, string targets = "") + { + if(targets == "") { return $"scoreboard players set #{id} {id} {count}"; } else { - return $"scoreboard players set {selector} {id} {count}"; + return $"scoreboard players set {targets} {id} {count}"; } } - public string Add(int count, string selector = "") + public static string Set(string id, int count, EntityTarget targets) { - return Add(id, count, selector); + return $"scoreboard players set {EntityTargetHandler.Get(targets)} {id} {count}"; + } + public string Add(int count, string targets = "") + { + return Add(id, count, targets); + } + public string Add(int count, EntityTarget targets) { + return Add(id, count, EntityTargetHandler.Get(targets)); } - public static string Add(string id, int count, string selector = "") + public static string Add(string id, int count, string targets = "") { - if (selector == "") + if (targets == "") { return $"scoreboard players add #{id} {id} {count}"; } else { - return $"scoreboard players add {selector} {id} {count}"; + return $"scoreboard players add {targets} {id} {count}"; } } - public string Remove(int count, string selector = "") + public static string Add(string id, int count, EntityTarget targets) { - return Remove(id, count, selector); + return $"scoreboard players add {EntityTargetHandler.Get(targets)} {id} {count}"; } - public static string Remove(string id, int count, string selector = "") + public string Remove(int count, string targets = "") { - if (selector == "") + return Remove(id, count, targets); + } + public string Remove(int count, EntityTarget targets) + { + return Remove(id, count, targets); + } + public static string Remove(string id, int count, string targets = "") + { + if (targets == "") { return $"scoreboard players remove #{id} {id} {count}"; } else { - return $"scoreboard players remove {selector} {id} {count}"; + return $"scoreboard players remove {targets} {id} {count}"; } } - public string Reset(string selector = "") + public static string Remove(string id, int count, EntityTarget targets) { - return Reset(id, selector); + return $"scoreboard players remove {EntityTargetHandler.Get(targets)} {id} {count}"; } - public static string Reset(string id, string selector = "") + public string Reset(string targets = "") { - if (selector == "") + return Reset(id, targets); + } + public string Reset(EntityTarget targets) + { + return Reset(id, EntityTargetHandler.Get(targets)); + } + public static string Reset(string id, string targets = "") + { + if (targets == "") { return $"scoreboard players reset #{id} {id}"; } else { - return $"scoreboard players reset {selector} {id}"; + return $"scoreboard players reset {targets} {id}"; } } + public static string Reset(string id, EntityTarget targets) + { + return $"scoreboard players reset {EntityTargetHandler.Get(targets)} {id}"; + } /// /// Only for use in scores={} cases /// @@ -100,6 +133,10 @@ public static string Reset(string id, string selector = "") public string Matches(int value){ return Matches(id, value); } + /// + /// Only for use in scores={} cases + /// + /// public static string Matches(string id, int value){ return id + '=' + value; } diff --git a/Generic/EntityTarget.cs b/Generic/EntityTarget.cs new file mode 100644 index 0000000..e816ddb --- /dev/null +++ b/Generic/EntityTarget.cs @@ -0,0 +1,9 @@ +namespace SteveSharp.Generic; + +public enum EntityTarget { + NearestPlayer, + RandomPlayer, + AllPlayers, + AllEntities, + Selected +} \ No newline at end of file diff --git a/Generic/EntityTargetHandler.cs b/Generic/EntityTargetHandler.cs new file mode 100644 index 0000000..f29f4a7 --- /dev/null +++ b/Generic/EntityTargetHandler.cs @@ -0,0 +1,15 @@ +namespace SteveSharp.Generic; + +internal static class EntityTargetHandler { + internal static string Get(EntityTarget targets) { + Dictionary entityTargetStr = new() { + {EntityTarget.NearestPlayer, "@p"}, + {EntityTarget.RandomPlayer, "@r"}, + {EntityTarget.AllPlayers, "@a"}, + {EntityTarget.AllEntities, "@e"}, + {EntityTarget.Selected, "@s"} + }; + + return entityTargetStr[targets]; + } +} \ No newline at end of file From c1f274534b9c65c767a4770c6f9ec46a0f1a0139 Mon Sep 17 00:00:00 2001 From: Hazel Rojas <84425557+hazelcode@users.noreply.github.com> Date: Sun, 30 Mar 2025 21:07:33 +0000 Subject: [PATCH 26/52] Remove code in `StatusEffectHandler` that throws exceptions --- Generic/StatusEffectHandler.cs | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/Generic/StatusEffectHandler.cs b/Generic/StatusEffectHandler.cs index a34ded3..604bf9c 100644 --- a/Generic/StatusEffectHandler.cs +++ b/Generic/StatusEffectHandler.cs @@ -47,18 +47,6 @@ public static string Get(StatusEffect effect) { {StatusEffect.WindCharged, "wind_charged"}, {StatusEffect.Wither, "wither"} }; - if( - Context.PackFormat < PackFormat.Format48 - && (effect == StatusEffect.Infested - || effect == StatusEffect.Oozing - || effect == StatusEffect.RaidOmen - || effect == StatusEffect.TrialOmen - || effect == StatusEffect.Weaving - || effect == StatusEffect.WindCharged) - ) { - // Only available for Minecraft 1.21 - throw new DatapackFeatureException(effect, PackFormat.Format48); - } return statusEffectStr[effect]; } } \ No newline at end of file From 53e61121256f20f5de831704a7e084d2863afc91 Mon Sep 17 00:00:00 2001 From: Hazel Rojas <84425557+hazelcode@users.noreply.github.com> Date: Sun, 30 Mar 2025 21:09:49 +0000 Subject: [PATCH 27/52] Fix accessors in `SteveSharp.Generic` namespace --- Generic/ColorHandler.cs | 2 +- Generic/EntityHandler.cs | 2 +- Generic/StatusEffectHandler.cs | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Generic/ColorHandler.cs b/Generic/ColorHandler.cs index 47d783d..1efa281 100644 --- a/Generic/ColorHandler.cs +++ b/Generic/ColorHandler.cs @@ -1,7 +1,7 @@ namespace SteveSharp.Generic; internal static class ColorHandler { - public static string Get(Color color) { + internal static string Get(Color color) { Dictionary colorStr = new() { {Color.Blue, "blue"}, {Color.Green, "green"}, diff --git a/Generic/EntityHandler.cs b/Generic/EntityHandler.cs index 79bc3b4..3959ce5 100644 --- a/Generic/EntityHandler.cs +++ b/Generic/EntityHandler.cs @@ -1,7 +1,7 @@ namespace SteveSharp.Generic; internal static class EntityHandler { - public static string Get(EntityEnum entityEnum) { + internal static string Get(EntityEnum entityEnum) { // https://www.digminecraft.com/lists/entity_list_pc.php Dictionary entityEnumStr = new() { {EntityEnum.Allay, "minecraft:allay"}, diff --git a/Generic/StatusEffectHandler.cs b/Generic/StatusEffectHandler.cs index 604bf9c..2f0164f 100644 --- a/Generic/StatusEffectHandler.cs +++ b/Generic/StatusEffectHandler.cs @@ -4,8 +4,8 @@ namespace SteveSharp.Generic; // https://www.digminecraft.com/lists/effect_list_pc.php -public static class StatusEffectHandler { - public static string Get(StatusEffect effect) { +internal static class StatusEffectHandler { + internal static string Get(StatusEffect effect) { Dictionary statusEffectStr = new() { {StatusEffect.Absorption, "absorption"}, {StatusEffect.BadLuck, "unluck"}, From 3a23cfbe988078bf8069192ea6fcbd850c3c5cfb Mon Sep 17 00:00:00 2001 From: Hazel Rojas <84425557+hazelcode@users.noreply.github.com> Date: Sun, 30 Mar 2025 21:19:32 +0000 Subject: [PATCH 28/52] Fix `XYZ.Rel` returning ~0 if input equals to 0 --- Core/XYZ.cs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Core/XYZ.cs b/Core/XYZ.cs index 1cb1fb8..cf11ede 100644 --- a/Core/XYZ.cs +++ b/Core/XYZ.cs @@ -6,7 +6,10 @@ public static class XYZ public static (string x, string y) Vec2(string x, string y) => (x, y); public static (int x, int y, int z) Vec3(int x, int y, int z) => (x, y, z); public static (string x, string y, string z) Vec3(string x, string y, string z) => (x, y, z); - public static (string x, string y, string z) Rel(int x, int y, int z) => ('~'+x.ToString(), '~'+y.ToString(), '~'+z.ToString()); + public static (string x, string y, string z) Rel(int x, int y, int z) + => ('~' + (x == 0 ? "" : x.ToString()), + '~' + (y == 0 ? "" : y.ToString()), + '~' + (z == 0 ? "" : z.ToString())); public static string[] Pos(int a, int b, int c) { return ["^"+b, "^"+b, "^"+c]; } From 1873617e82846fe495642ca1750a43f650bec883 Mon Sep 17 00:00:00 2001 From: Hazel Rojas <84425557+hazelcode@users.noreply.github.com> Date: Sun, 30 Mar 2025 21:31:59 +0000 Subject: [PATCH 29/52] Remove Context and resume some code in `Project` and unused usings --- Generic/StatusEffectHandler.cs | 3 --- Internal/Context.cs | 5 ----- Project.cs | 6 ++---- 3 files changed, 2 insertions(+), 12 deletions(-) delete mode 100644 Internal/Context.cs diff --git a/Generic/StatusEffectHandler.cs b/Generic/StatusEffectHandler.cs index 2f0164f..52d7b61 100644 --- a/Generic/StatusEffectHandler.cs +++ b/Generic/StatusEffectHandler.cs @@ -1,6 +1,3 @@ -using SteveSharp.Exceptions; -using SteveSharp.Internal; - namespace SteveSharp.Generic; // https://www.digminecraft.com/lists/effect_list_pc.php diff --git a/Internal/Context.cs b/Internal/Context.cs deleted file mode 100644 index 083b05f..0000000 --- a/Internal/Context.cs +++ /dev/null @@ -1,5 +0,0 @@ -namespace SteveSharp.Internal; - -internal static class Context { - internal static PackFormat PackFormat; -} \ No newline at end of file diff --git a/Project.cs b/Project.cs index fc07710..b509f48 100644 --- a/Project.cs +++ b/Project.cs @@ -1,5 +1,4 @@ using SteveSharp.Exceptions; -using SteveSharp.Internal; using SteveSharp.JsonShapes; using System.Text.Json; @@ -34,7 +33,6 @@ public Project(string name, string description, string id, PackFormat packFormat _load = load; _main = main; _functions = functions; - Context.PackFormat = packFormat; FunctionIndex = new Dictionary(); string loadPath = FileOrganizer.GetFunctionPath(_load.Name); string mainPath = FileOrganizer.GetFunctionPath(_main.Name); @@ -67,13 +65,13 @@ public Project(string name, string description, string id, PackFormat packFormat File.WriteAllText($"data/minecraft/tags/functions/load.json", JsonSerializer.Serialize(new Tag { - values = new string[] { _load.Name } + values = [_load.Name] }, new JsonSerializerOptions { WriteIndented = true }) ); File.WriteAllText($"data/minecraft/tags/functions/tick.json", JsonSerializer.Serialize(new Tag { - values = new string[] { _main.Name } + values = [_main.Name] }, new JsonSerializerOptions { WriteIndented = true }) ); Displays.ProjectCreated(); From 24fb45f06312414c802dba111dd8395e69c2cdda Mon Sep 17 00:00:00 2001 From: Hazel Rojas <84425557+hazelcode@users.noreply.github.com> Date: Mon, 31 Mar 2025 06:51:31 +0000 Subject: [PATCH 30/52] Add `/title` command (`Title`) --- Core/Strings/Title.cs | 74 +++++++++++++++++++++++++++++++++++++++++++ Core/Title.cs | 38 ++++++++++++++++++++++ 2 files changed, 112 insertions(+) create mode 100644 Core/Strings/Title.cs create mode 100644 Core/Title.cs diff --git a/Core/Strings/Title.cs b/Core/Strings/Title.cs new file mode 100644 index 0000000..c914186 --- /dev/null +++ b/Core/Strings/Title.cs @@ -0,0 +1,74 @@ +using SteveSharp.Generic; +using SteveSharp.JsonShapes; +using System.Text.Json; + +namespace SteveSharp.Core.Strings; + +public static class Title { +#region /title actionbar + public static string Actionbar(EntityTarget targets, TextComponent text) { + return $"title {EntityTargetHandler.Get(targets)} actionbar {JsonSerializer.Serialize(text)}"; + } + public static string Actionbar(EntityTarget targets, TextComponent[] text) { + return $"title {EntityTargetHandler.Get(targets)} actionbar {JsonSerializer.Serialize(text)}"; + } + public static string Actionbar(string targets, TextComponent text) { + return $"title {targets} actionbar {JsonSerializer.Serialize(text)}"; + } + public static string Actionbar(string targets, TextComponent[] text) { + return $"title {targets} actionbar {JsonSerializer.Serialize(text)}"; + } +#endregion +#region /title title + public static string ShowTitle(EntityTarget targets, TextComponent text) { + return $"title {EntityTargetHandler.Get(targets)} title {JsonSerializer.Serialize(text)}"; + } + public static string ShowTitle(EntityTarget targets, TextComponent[] text) { + return $"title {EntityTargetHandler.Get(targets)} title {JsonSerializer.Serialize(text)}"; + } + public static string ShowTitle(string targets, TextComponent text) { + return $"title {targets} title {JsonSerializer.Serialize(text)}"; + } + public static string ShowTitle(string targets, TextComponent[] text) { + return $"title {targets} title {JsonSerializer.Serialize(text)}"; + } +#endregion +#region /title subtitle + public static string Subtitle(EntityTarget targets, TextComponent text) { + return $"title {EntityTargetHandler.Get(targets)} subtitle {JsonSerializer.Serialize(text)}"; + } + public static string Subtitle(EntityTarget targets, TextComponent[] text) { + return $"title {EntityTargetHandler.Get(targets)} subtitle {JsonSerializer.Serialize(text)}"; + } + public static string Subtitle(string targets, TextComponent text) { + return $"title {targets} subtitle {JsonSerializer.Serialize(text)}"; + } + public static string Subtitle(string targets, TextComponent[] text) { + return $"title {targets} subtitle {JsonSerializer.Serialize(text)}"; + } +#endregion +#region /title clear + public static string Clear(EntityTarget target) { + return $"title {EntityTargetHandler.Get(target)} clear"; + } + public static string Clear(string targets) { + return $"title {targets} clear"; + } +#endregion +#region /title reset + public static string Reset(EntityTarget targets) { + return $"title {EntityTargetHandler.Get(targets)} reset"; + } + public static string Reset(string targets) { + return $"title {targets} reset"; + } +#endregion +#region /title times + public static string Times(EntityTarget targets, string fadeIn, string stay, string fadeOut) { + return $"title {EntityTargetHandler.Get(targets)} times {fadeIn} {stay} {fadeOut}"; + } + public static string Times(string targets, string fadeIn, string stay, string fadeOut) { + return $"title {targets} times {fadeIn} {stay} {fadeOut}"; + } +#endregion +} \ No newline at end of file diff --git a/Core/Title.cs b/Core/Title.cs new file mode 100644 index 0000000..ddc9155 --- /dev/null +++ b/Core/Title.cs @@ -0,0 +1,38 @@ +using SteveSharp.Generic; +using SteveSharp.JsonShapes; +using Str = SteveSharp.Core.Strings; + +namespace SteveSharp.Core; + +public static class Title { +#region /title actionbar + public static void Actionbar(EntityTarget targets, TextComponent text) => FunctionBuilder.Add(Str.Title.Actionbar(targets, text)); + public static void Actionbar(EntityTarget targets, TextComponent[] text) => FunctionBuilder.Add(Str.Title.Actionbar(targets, text)); + public static void Actionbar(string targets, TextComponent text) => FunctionBuilder.Add(Str.Title.Actionbar(targets, text)); + public static void Actionbar(string targets, TextComponent[] text) => FunctionBuilder.Add(Str.Title.Actionbar(targets, text)); +#endregion +#region /title title + public static void ShowTitle(EntityTarget targets, TextComponent text) => FunctionBuilder.Add(Str.Title.ShowTitle(targets, text)); + public static void ShowTitle(EntityTarget targets, TextComponent[] text) => FunctionBuilder.Add(Str.Title.ShowTitle(targets, text)); + public static void ShowTitle(string targets, TextComponent text) => FunctionBuilder.Add(Str.Title.ShowTitle(targets, text)); + public static void ShowTitle(string targets, TextComponent[] text) => FunctionBuilder.Add(Str.Title.ShowTitle(targets, text)); +#endregion +#region /title subtitle + public static void Subtitle(EntityTarget targets, TextComponent text) => FunctionBuilder.Add(Str.Title.Subtitle(targets, text)); + public static void Subtitle(EntityTarget targets, TextComponent[] text) => FunctionBuilder.Add(Str.Title.Subtitle(targets, text)); + public static void Subtitle(string targets, TextComponent text) => FunctionBuilder.Add(Str.Title.Subtitle(targets, text)); + public static void Subtitle(string targets, TextComponent[] text) => FunctionBuilder.Add(Str.Title.Subtitle(targets, text)); +#endregion +#region /title clear + public static void Clear(EntityTarget target) => FunctionBuilder.Add(Str.Title.Clear(target)); + public static void Clear(string target) => FunctionBuilder.Add(Str.Title.Clear(target)); +#endregion +#region /title reset + public static void Reset(EntityTarget targets) => FunctionBuilder.Add(Str.Title.Reset(targets)); + public static void Reset(string targets) => FunctionBuilder.Add(Str.Title.Reset(targets)); +#endregion +#region /title times + public static void Times(EntityTarget targets, string fadeIn, string stay, string fadeOut) => FunctionBuilder.Add(Str.Title.Times(targets, fadeIn, stay, fadeOut)); + public static void Times(string targets, string fadeIn, string stay, string fadeOut) => FunctionBuilder.Add(Str.Title.Times(targets, fadeIn, stay, fadeOut)); +#endregion +} \ No newline at end of file From ca44bb1de095698bb9326460373ad0025b7dcf93 Mon Sep 17 00:00:00 2001 From: Hazel Rojas <84425557+hazelcode@users.noreply.github.com> Date: Mon, 31 Mar 2025 07:00:18 +0000 Subject: [PATCH 31/52] Add `Time` for representing game time --- Core/Time.cs | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 Core/Time.cs diff --git a/Core/Time.cs b/Core/Time.cs new file mode 100644 index 0000000..f3bfc91 --- /dev/null +++ b/Core/Time.cs @@ -0,0 +1,7 @@ +namespace SteveSharp.Core; + +public class Time { + public static string Ticks(int ticks) => ticks + "t"; + public static string Seconds(int seconds) => seconds + "s"; + public static string Days(int days) => days + "d"; +} \ No newline at end of file From b6477e96974731fd8db22836b7768983c06e0d5c Mon Sep 17 00:00:00 2001 From: Hazel Rojas <84425557+hazelcode@users.noreply.github.com> Date: Tue, 1 Apr 2025 03:34:06 +0000 Subject: [PATCH 32/52] Implement score operators!! --- Core/Score.cs | 155 +++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 152 insertions(+), 3 deletions(-) diff --git a/Core/Score.cs b/Core/Score.cs index a69e212..c439837 100644 --- a/Core/Score.cs +++ b/Core/Score.cs @@ -5,14 +5,12 @@ namespace SteveSharp.Core { public class Score { - public int count = 0; public string id; public string type; public string name; - public Score(string id, string type = "dummy", string name = "", int count = 0) + public Score(string id, string type = "dummy", string name = "") { this.id = id; - this.count = count; this.type = type; this.name = name; } @@ -100,5 +98,156 @@ public string Matches(int value){ public static string Matches(string id, int value){ return id + '=' + value; } +#region operators + public static Score operator + (Score a, int b) { + FunctionBuilder.Add($"scoreboard players add #{a.id} {a.id} {b}"); + return a; + } + public static Score operator - (Score a, int b) { + FunctionBuilder.Add($"scoreboard players remove #{a.id} {a.id} {b}"); + return a; + } + public static Score operator * (Score a, int b) { + FunctionBuilder.Add( + $"scoreboard players set #{a.id}_temp {a.id} {b}\n"+ + $"scoreboard players operation #{a.id} {a.id} *= #{a.id}_temp {a.id}\n"+ + $"scoreboard players reset #{a.id}_temp {a.id}" + ); + return a; + } + public static Score operator / (Score a, int b) { + FunctionBuilder.Add( + $"scoreboard players set #{a.id}_temp {a.id} {b}\n"+ + $"scoreboard players operation #{a.id} {a.id} /= #{a.id}_temp {a.id}\n"+ + $"scoreboard players reset #{a.id}_temp {a.id}" + ); + return a; + } + public static Score operator % (Score a, int b) { + FunctionBuilder.Add( + $"scoreboard players set #{a.id}_temp {a.id} {b}\n"+ + $"scoreboard players operation #{a.id} {a.id} %= #{a.id}_temp {a.id}\n"+ + $"scoreboard players reset #{a.id}_temp {a.id}" + ); + return a; + } + public static Score operator + (Score a, Score b) { + FunctionBuilder.Add($"scoreboard players operation #{a.id} {a.id} += #{b.id} {b.id}"); + return a; + } + public static Score operator - (Score a, Score b) { + FunctionBuilder.Add($"scoreboard players operation #{a.id} {a.id} -= #{b.id} {b.id}"); + return a; + } + public static Score operator * (Score a, Score b) { + FunctionBuilder.Add($"scoreboard players operation #{a.id} {a.id} *= #{b.id} {b.id}"); + return a; + } + public static Score operator / (Score a, Score b) { + FunctionBuilder.Add($"scoreboard players operation #{a.id} {a.id} /= #{b.id} {b.id}"); + return a; + } + public static Score operator % (Score a, Score b) { + FunctionBuilder.Add($"scoreboard players operation #{a.id} {a.id} %= #{b.id} {b.id}"); + return a; + } + public static Score operator + (Score a, EntityTarget b) { + FunctionBuilder.Add($"scoreboard players operation #{a.id} {a.id} += {EntityTargetHandler.Get(b)} {a.id}"); + return a; + } + public static Score operator - (Score a, EntityTarget b) { + FunctionBuilder.Add($"scoreboard players operation #{a.id} {a.id} -= {EntityTargetHandler.Get(b)} {a.id}"); + return a; + } + public static Score operator * (Score a, EntityTarget b) { + FunctionBuilder.Add($"scoreboard players operation #{a.id} {a.id} *= {EntityTargetHandler.Get(b)} {a.id}"); + return a; + } + public static Score operator / (Score a, EntityTarget b) { + FunctionBuilder.Add($"scoreboard players operation #{a.id} {a.id} /= {EntityTargetHandler.Get(b)} {a.id}"); + return a; + } + public static Score operator % (Score a, EntityTarget b) { + FunctionBuilder.Add($"scoreboard players operation #{a.id} {a.id} %= {EntityTargetHandler.Get(b)} {a.id}"); + return a; + } + public static Score operator + (Score a, string b) { + FunctionBuilder.Add($"scoreboard players operation #{a.id} {a.id} += {b} {a.id}"); + return a; + } + public static Score operator - (Score a, string b) { + FunctionBuilder.Add($"scoreboard players operation #{a.id} {a.id} -= {b} {a.id}"); + return a; + } + public static Score operator * (Score a, string b) { + FunctionBuilder.Add($"scoreboard players operation #{a.id} {a.id} *= {b} {a.id}"); + return a; + } + public static Score operator / (Score a, string b) { + FunctionBuilder.Add($"scoreboard players operation #{a.id} {a.id} /= {b} {a.id}"); + return a; + } + public static Score operator % (Score a, string b) { + FunctionBuilder.Add($"scoreboard players operation #{a.id} {a.id} %= {b} {a.id}"); + return a; + } + public static bool operator == (Score a, int b) { + FunctionBuilder.Add($"execute if score #{a.id} myVariable matches {b} run \\"); + return true; + } + public static bool operator != (Score a, int b) { + FunctionBuilder.Add($"execute unless score #{a.id} {a.id} matches {b} run \\"); + return true; + } + public static bool operator >= (Score a, int b) { + FunctionBuilder.Add($"execute if score #{a.id} {a.id} matches {b}.. run \\"); + return true; + } + public static bool operator <= (Score a, int b) { + FunctionBuilder.Add($"execute if score #{a.id} {a.id} matches ..{b} run \\"); + return true; + } + public static bool operator > (Score a, int b) { + FunctionBuilder.Add($"execute unless score #{a.id} {a.id} matches ..{b}"); + return true; + } + public static bool operator < (Score a, int b) { + FunctionBuilder.Add($"execute unless score #{a.id} {a.id} matches {b}.."); + return true; + } + public static bool operator == (Score a, Score b) { + FunctionBuilder.Add($"execute if score #{a.id} {a.id} = #{b.id} {b.id} run \\"); + return true; + } + public static bool operator != (Score a, Score b) { + FunctionBuilder.Add($"execute unless score #{a.id} {a.id} = #{b.id} {b.id} run \\"); + return true; + } + public static bool operator >= (Score a, Score b) { + FunctionBuilder.Add($"execute if score #{a.id} {a.id} >= #{b.id} {b.id} run \\"); + return true; + } + public static bool operator <= (Score a, Score b) { + FunctionBuilder.Add($"execute if score #{a.id} {a.id} <= #{b.id} {b.id} run \\"); + return true; + } + public static bool operator > (Score a, Score b) { + FunctionBuilder.Add($"execute if score #{a.id} {a.id} > #{b.id} {b.id} run \\"); + return true; + } + public static bool operator < (Score a, Score b) { + FunctionBuilder.Add($"execute if score #{a.id} {a.id} < #{b.id} {b.id} run \\"); + return true; + } +#endregion + public override bool Equals(object? obj) { + if(obj is Score s) { + return true; + } else { + return false; + } + } + + public override int GetHashCode() => GetHashCode(); } } From 8a066a97b58e6a7bd56238b63138b6bbe82d1100 Mon Sep 17 00:00:00 2001 From: Hazel Rojas <84425557+hazelcode@users.noreply.github.com> Date: Tue, 1 Apr 2025 04:42:44 +0000 Subject: [PATCH 33/52] Fix ortographic issues in EntityHandler and EntityEnum --- Generic/EntityEnum.cs | 2 +- Generic/EntityHandler.cs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Generic/EntityEnum.cs b/Generic/EntityEnum.cs index 2ecc437..120e00b 100644 --- a/Generic/EntityEnum.cs +++ b/Generic/EntityEnum.cs @@ -46,7 +46,7 @@ public enum EntityEnum { FireworkRocket, Fox, Frog, - MinecarftWithFurnace, + MinecartWithFurnace, Ghast, Giant, GlowItemFrame, diff --git a/Generic/EntityHandler.cs b/Generic/EntityHandler.cs index 3959ce5..653b9b5 100644 --- a/Generic/EntityHandler.cs +++ b/Generic/EntityHandler.cs @@ -47,7 +47,7 @@ internal static string Get(EntityEnum entityEnum) { {EntityEnum.FireworkRocket, "minecraft:firework_rocket"}, {EntityEnum.Fox, "minecraft:fox"}, {EntityEnum.Frog, "minecraft:frog"}, - {EntityEnum.MinecarftWithFurnace, "minecraft:furnace_minecart"}, + {EntityEnum.MinecartWithFurnace, "minecraft:furnace_minecart"}, {EntityEnum.Ghast, "minecraft:ghast"}, {EntityEnum.Giant, "minecraft:giant"}, {EntityEnum.GlowItemFrame, "minecraft:glow_item_frame"}, @@ -77,7 +77,7 @@ internal static string Get(EntityEnum entityEnum) { {EntityEnum.Painting, "minecraft:painting"}, {EntityEnum.Panda, "minecraft:panda"}, {EntityEnum.Parrot, "minecraft:parrot"}, - {EntityEnum.Phantom, "minecraft:phanton"}, + {EntityEnum.Phantom, "minecraft:phantom"}, {EntityEnum.Pig, "minecraft:pig"}, {EntityEnum.Piglin, "minecraft:piglin"}, {EntityEnum.PiglinBrute, "minecraft:piglin_brute"}, From 14872dc9616351eb9cdf9e04242ccc36f957b372 Mon Sep 17 00:00:00 2001 From: Hazel Rojas <84425557+hazelcode@users.noreply.github.com> Date: Tue, 1 Apr 2025 04:54:07 +0000 Subject: [PATCH 34/52] Fix Pos first element mistake --- Core/XYZ.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Core/XYZ.cs b/Core/XYZ.cs index cf11ede..278f1c0 100644 --- a/Core/XYZ.cs +++ b/Core/XYZ.cs @@ -11,7 +11,7 @@ public static (string x, string y, string z) Rel(int x, int y, int z) '~' + (y == 0 ? "" : y.ToString()), '~' + (z == 0 ? "" : z.ToString())); public static string[] Pos(int a, int b, int c) { - return ["^"+b, "^"+b, "^"+c]; + return ["^"+a, "^"+b, "^"+c]; } public static string[] Pos(string a, string b, string c) { return ['^'+a, '^'+b, '^'+c]; From 9696bdf6682574c0a409028e0be6bea59e05d7f6 Mon Sep 17 00:00:00 2001 From: Hazel Rojas <84425557+hazelcode@users.noreply.github.com> Date: Tue, 1 Apr 2025 13:41:36 +0000 Subject: [PATCH 35/52] Migrate Function strings --- Core/Strings/Function.cs | 11 ++++++++++- Function.cs | 26 ++++++++++---------------- Utils/Hitbox.cs | 6 +++--- 3 files changed, 23 insertions(+), 20 deletions(-) diff --git a/Core/Strings/Function.cs b/Core/Strings/Function.cs index 147807c..36c87fb 100644 --- a/Core/Strings/Function.cs +++ b/Core/Strings/Function.cs @@ -1,4 +1,13 @@ namespace SteveSharp.Core.Strings; -public class Function { +public static class Function +{ + public static string Return(int i) => "return " + i; + public static string Call(string function) => "function " + function; + public static string Schedule(string function, string time, bool append = false, bool replace = false) { + if (append && !replace) return $"schedule function {function} {time} append"; + else if (!append && replace) return $"schedule function {function} {time} replace"; + else return $"schedule function {function} {time}"; + } + public static string ClearSchedule(string function) => $"schedule clear {function}"; } \ No newline at end of file diff --git a/Function.cs b/Function.cs index d6fc9af..7bd3d94 100644 --- a/Function.cs +++ b/Function.cs @@ -1,4 +1,6 @@ -namespace SteveSharp +using Str = SteveSharp.Core.Strings; + +namespace SteveSharp { public class Function { @@ -10,22 +12,14 @@ public Function(string name, Func body) Body = body; Displays.NewFunction(name); } - public static string Return(int i) - { - return "return " + i; - } - public static string Call(string function) - { - return "function " + function; - } - public static string Schedule(string function, string time, bool append = false, bool replace = false) { - if(append && !replace) return $"schedule function {function} {time} append"; - else if(!append && replace) return $"schedule function {function} {time} replace"; - else return $"schedule function {function} {time}"; + public static void Return(int i) => FunctionBuilder.Add(Str.Function.Return(i)); + public static void Call(string function) => FunctionBuilder.Add(Str.Function.Call(function)); + public static void Schedule(string function, string time, bool append = false, bool replace = false) { + FunctionBuilder.Add(Str.Function.Schedule(function, time, append, replace)); } - public string ScheduleSelf(string time, bool append = false, bool replace = false) => Schedule(Name, time, append, replace); - public static string ClearSchedule(string function) => $"schedule clear {function}"; - public string ClearSchedule() => ClearSchedule(Name); + public void ScheduleSelf(string time, bool append = false, bool replace = false) => FunctionBuilder.Add(Str.Function.Schedule(Name, time, append, replace)); + public static void ClearSchedule(string function) => FunctionBuilder.Add(Str.Function.ClearSchedule(function)); + public void ClearSchedule() => ClearSchedule(Name); /// /// Extend to another function from the current function diff --git a/Utils/Hitbox.cs b/Utils/Hitbox.cs index 4d67add..7e2cba9 100644 --- a/Utils/Hitbox.cs +++ b/Utils/Hitbox.cs @@ -26,7 +26,7 @@ public void Setup(Action onAttack, Action onRi } public string Invoke() { - return Function.Call($"{_ctx!.Namespace}:hitbox/{Workspace}/summon"); + return Str.Function.Call($"{_ctx!.Namespace}:hitbox/{Workspace}/summon"); } public Function OnAttack(Action body) { return new Function( @@ -54,12 +54,12 @@ public Function SummonFunction() { Execute.Write( Str.Execute.Asat(Entity.AllEntities("type=interaction,tag=" + _ctx.Namespace + "." + Id)) + "on attacker ", - [Function.Call($"{_ctx.Namespace}:hitbox/{Workspace}/on_attack")] + [Str.Function.Call($"{_ctx.Namespace}:hitbox/{Workspace}/on_attack")] ); Execute.Write( Str.Execute.Asat(Entity.AllEntities("type=interaction,tag=" + _ctx.Namespace + "." + Id)) + "on target ", - [Function.Call($"{_ctx.Namespace}:hitbox/{Workspace}/on_right_click")] + [Str.Function.Call($"{_ctx.Namespace}:hitbox/{Workspace}/on_right_click")] ); Entity.Kill(Entity.AllEntities("type=interaction,tag=" + _ctx.Namespace + "." + Id)); return FunctionBuilder.Collect(); From 73dd5ac9d1770d8f8d491b2e069c1100536769ae Mon Sep 17 00:00:00 2001 From: Hazel Rojas <84425557+hazelcode@users.noreply.github.com> Date: Wed, 2 Apr 2025 07:52:52 +0000 Subject: [PATCH 36/52] Add `/enchant` command (`EnchantCommand`) --- Core/EnchantCommand.cs | 15 +++++++++ Core/Strings/EnchantCommand.cs | 14 +++++++++ Generic/Enchantment.cs | 56 ++++++++++++++++++++++++++++++++++ Generic/EnchantmentHandler.cs | 50 ++++++++++++++++++++++++++++++ 4 files changed, 135 insertions(+) create mode 100644 Core/EnchantCommand.cs create mode 100644 Core/Strings/EnchantCommand.cs create mode 100644 Generic/Enchantment.cs create mode 100644 Generic/EnchantmentHandler.cs diff --git a/Core/EnchantCommand.cs b/Core/EnchantCommand.cs new file mode 100644 index 0000000..a6b2405 --- /dev/null +++ b/Core/EnchantCommand.cs @@ -0,0 +1,15 @@ +using SteveSharp.Generic; +using Str = SteveSharp.Core.Strings; + +namespace SteveSharp.Core; + +public static class EnchantCommand { + public static void Enchant(EntityTarget targets, Enchantment enchantment) => FunctionBuilder.Add(Str.EnchantCommand.Enchant(targets, enchantment)); + public static void Enchant(EntityTarget targets, Enchantment enchantment, int level) => FunctionBuilder.Add(Str.EnchantCommand.Enchant(targets, enchantment, level)); + public static void Enchant(EntityTarget targets, string enchantment) => FunctionBuilder.Add(Str.EnchantCommand.Enchant(targets, enchantment)); + public static void Enchant(EntityTarget targets, string enchantment, int level) => FunctionBuilder.Add(Str.EnchantCommand.Enchant(targets, enchantment, level)); + public static void Enchant(string targets, string enchantment) => FunctionBuilder.Add(Str.EnchantCommand.Enchant(targets, enchantment)); + public static void Enchant(string targets, string enchantment, int level) => FunctionBuilder.Add(Str.EnchantCommand.Enchant(targets, enchantment, level)); + public static void Enchant(string targets, Enchantment enchantment) => FunctionBuilder.Add(Str.EnchantCommand.Enchant(targets, enchantment)); + public static void Enchant(string targets, Enchantment enchantment, int level) => FunctionBuilder.Add(Str.EnchantCommand.Enchant(targets, enchantment, level)); +} \ No newline at end of file diff --git a/Core/Strings/EnchantCommand.cs b/Core/Strings/EnchantCommand.cs new file mode 100644 index 0000000..48ad152 --- /dev/null +++ b/Core/Strings/EnchantCommand.cs @@ -0,0 +1,14 @@ +using SteveSharp.Generic; + +namespace SteveSharp.Core.Strings; + +public static class EnchantCommand { + public static string Enchant(EntityTarget targets, Enchantment enchantment) => $"enchant {EntityTargetHandler.Get(targets)} {EnchantmentHandler.Get(enchantment)}"; + public static string Enchant(EntityTarget targets, Enchantment enchantment, int level) => $"enchant {EntityTargetHandler.Get(targets)} {EnchantmentHandler.Get(enchantment)} {level}"; + public static string Enchant(EntityTarget targets, string enchantment) => $"enchant {EntityTargetHandler.Get(targets)} {enchantment}"; + public static string Enchant(EntityTarget targets, string enchantment, int level) => $"enchant {EntityTargetHandler.Get(targets)} {enchantment} {level}"; + public static string Enchant(string targets, string enchantment) => $"enchant {targets} {enchantment}"; + public static string Enchant(string targets, string enchantment, int level) => $"enchant {targets} {enchantment} {level}"; + public static string Enchant(string targets, Enchantment enchantment) => $"enchant {targets} {EnchantmentHandler.Get(enchantment)}"; + public static string Enchant(string targets, Enchantment enchantment, int level) => $"enchant {targets} {EnchantmentHandler.Get(enchantment)} {level}"; +} \ No newline at end of file diff --git a/Generic/Enchantment.cs b/Generic/Enchantment.cs new file mode 100644 index 0000000..79099e7 --- /dev/null +++ b/Generic/Enchantment.cs @@ -0,0 +1,56 @@ +namespace SteveSharp.Generic; + +// https://www.digminecraft.com/lists/enchantment_list_pc.php +public enum Enchantment { + AquaAffinity, + BaneOfArthropods, + BlastProtection, + /// + /// Minecraft 1.21 + /// + Breach, + Channeling, + CurseOfBinding, + CurseOfVanishing, + /// + /// Minecraft 1.21 + /// + Density, + DepthStrider, + Efficiency, + FeatherFalling, + FireAspect, + FireProtection, + Flame, + Fortune, + FrostWalker, + Impaling, + Infinity, + Knockback, + Looting, + Loyalty, + LuckOfTheSea, + Lure, + Mending, + Multishot, + Piercing, + Power, + ProjectileProtection, + Protection, + Punch, + QuickCharge, + Respiration, + Riptide, + Sharpness, + SilkTouck, + Smite, + SoulSpeed, + SweepingEdge, + SwiftSneak, + Thorns, + Unbreaking, + /// + /// 1.21 + /// + WindBurst +} \ No newline at end of file diff --git a/Generic/EnchantmentHandler.cs b/Generic/EnchantmentHandler.cs new file mode 100644 index 0000000..e308b8b --- /dev/null +++ b/Generic/EnchantmentHandler.cs @@ -0,0 +1,50 @@ +namespace SteveSharp.Generic; + +// https://www.digminecraft.com/lists/enchantment_list_pc.php +internal static class EnchantmentHandler { + internal static string Get(Enchantment enchantment) => enchantment switch { + Enchantment.AquaAffinity => "minecraft:aqua_affinity", + Enchantment.BaneOfArthropods => "minecraft:bane_of_arthropods", + Enchantment.BlastProtection => "minecraft:blast_protection", + Enchantment.Breach => "minecraft:breach", + Enchantment.Channeling => "minecraft:channeling", + Enchantment.CurseOfBinding => "minecraft:curse_of_binding", + Enchantment.CurseOfVanishing => "minecraft:curse_of_vanishing", + Enchantment.Density => "minecraft:density", + Enchantment.DepthStrider => "minecraft:depth_strider", + Enchantment.Efficiency => "minecraft:efficiency", + Enchantment.FeatherFalling => "minecraft:feather_falling", + Enchantment.FireAspect => "minecraft:fire_aspect", + Enchantment.FireProtection => "minecraft:fire_protection", + Enchantment.Flame => "minecraft:flame", + Enchantment.Fortune => "minecraft:fortune", + Enchantment.FrostWalker => "minecraft:frost_walker", + Enchantment.Impaling => "minecraft:impaling", + Enchantment.Infinity => "minecraft:infinity", + Enchantment.Knockback => "minecraft:knockback", + Enchantment.Looting => "minecraft:looting", + Enchantment.Loyalty => "minecraft:loyalty", + Enchantment.LuckOfTheSea => "minecraft:luck_of_the_sea", + Enchantment.Lure => "minecraft:lure", + Enchantment.Mending => "minecraft:mending", + Enchantment.Multishot => "minecraft:multishot", + Enchantment.Piercing => "minecraft:piercing", + Enchantment.Power => "minecraft:power", + Enchantment.ProjectileProtection => "minecraft:proyectile_protection", + Enchantment.Protection => "minecraft:protection", + Enchantment.Punch => "minecraft:punch", + Enchantment.QuickCharge => "minecraft:quick_charge", + Enchantment.Respiration => "minecraft:respiration", + Enchantment.Riptide => "minecraft:riptide", + Enchantment.Sharpness => "minecraft:sharpness", + Enchantment.SilkTouck => "minecraft:silk_touch", + Enchantment.Smite => "minecraft:smite", + Enchantment.SoulSpeed => "minecraft:soul_speed", + Enchantment.SweepingEdge => "minecraft:sweeping_edge", + Enchantment.SwiftSneak => "minecraft:swift_sneak", + Enchantment.Thorns => "minecraft:thorns", + Enchantment.Unbreaking => "minecraft:unbreaking", + Enchantment.WindBurst => "minecraft:wind_burst", + _ => "Invalid input (enchantment not found)" + }; +} \ No newline at end of file From 6022394181ac6a291084ecf1d7b2aedb69ff101c Mon Sep 17 00:00:00 2001 From: Hazel Rojas <84425557+hazelcode@users.noreply.github.com> Date: Wed, 2 Apr 2025 08:13:28 +0000 Subject: [PATCH 37/52] Rename `EntityTargets` to `Targets` and rename `Entity` selectors with `Match` suffix --- Core/Chat.cs | 6 ++--- Core/Effect.cs | 14 +++++----- Core/EnchantCommand.cs | 8 +++--- Core/Entity.cs | 20 +++++++------- Core/Execute.cs | 8 +++--- Core/Recipe.cs | 4 +-- Core/Score.cs | 34 +++++++++++------------ Core/Strings/Chat.cs | 12 ++++----- Core/Strings/Effect.cs | 32 +++++++++++----------- Core/Strings/EnchantCommand.cs | 8 +++--- Core/Strings/Entity.cs | 20 +++++++------- Core/Strings/Execute.cs | 16 +++++------ Core/Strings/Recipe.cs | 4 +-- Core/Strings/Score.cs | 30 ++++++++++----------- Core/Strings/Title.cs | 36 ++++++++++++------------- Core/Title.cs | 18 ++++++------- Generic/EntityTargetHandler.cs | 15 ----------- Generic/{EntityTarget.cs => Targets.cs} | 2 +- Generic/TargetsHandler.cs | 15 +++++++++++ 19 files changed, 151 insertions(+), 151 deletions(-) delete mode 100644 Generic/EntityTargetHandler.cs rename Generic/{EntityTarget.cs => Targets.cs} (80%) create mode 100644 Generic/TargetsHandler.cs diff --git a/Core/Chat.cs b/Core/Chat.cs index 34564ce..ee1c2f5 100644 --- a/Core/Chat.cs +++ b/Core/Chat.cs @@ -8,11 +8,11 @@ namespace SteveSharp.Core public static class Chat { public static void Say(string msg) => FunctionBuilder.Add(Str.Chat.Say(msg)); - public static void Tell(EntityTarget targets, string message) => FunctionBuilder.Add(Str.Chat.Tell(targets, message)); + public static void Tell(Targets targets, string message) => FunctionBuilder.Add(Str.Chat.Tell(targets, message)); public static void Tell(string targets, string message) => FunctionBuilder.Add(Str.Chat.Tell(targets, message)); - public static void Tellraw(EntityTarget targets, TextComponent[] text) => FunctionBuilder.Add(Str.Chat.Tellraw(targets, text)); + public static void Tellraw(Targets targets, TextComponent[] text) => FunctionBuilder.Add(Str.Chat.Tellraw(targets, text)); public static void Tellraw(string targets, TextComponent[] text) => FunctionBuilder.Add(Str.Chat.Tellraw(targets, text)); - public static void Tellraw(EntityTarget targets, TextComponent text) => FunctionBuilder.Add(Str.Chat.Tellraw(targets, text)); + public static void Tellraw(Targets targets, TextComponent text) => FunctionBuilder.Add(Str.Chat.Tellraw(targets, text)); public static void Tellraw(string targets, TextComponent text) => FunctionBuilder.Add(Str.Chat.Tellraw(targets, text)); } } diff --git a/Core/Effect.cs b/Core/Effect.cs index 07d2d5e..150a7b8 100644 --- a/Core/Effect.cs +++ b/Core/Effect.cs @@ -4,26 +4,26 @@ namespace SteveSharp.Core; public static class Effect { - public static void Give(EntityTarget targets, StatusEffect effect, bool infinite = false, int amplifier = 0) => FunctionBuilder.Add(Str.Effect.Give(targets, effect, infinite, amplifier)); + public static void Give(Targets targets, StatusEffect effect, bool infinite = false, int amplifier = 0) => FunctionBuilder.Add(Str.Effect.Give(targets, effect, infinite, amplifier)); public static void Give(string targets, StatusEffect effect, bool infinite = false, int amplifier = 0) => FunctionBuilder.Add(Str.Effect.Give(targets, effect, infinite, amplifier)); - public static void Give(EntityTarget targets, StatusEffect effect, int seconds, int amplifier = 0) => FunctionBuilder.Add(Str.Effect.Give(targets, effect, seconds, amplifier)); + public static void Give(Targets targets, StatusEffect effect, int seconds, int amplifier = 0) => FunctionBuilder.Add(Str.Effect.Give(targets, effect, seconds, amplifier)); public static void Give(string targets, StatusEffect effect, int seconds, int amplifier = 0) => FunctionBuilder.Add(Str.Effect.Give(targets, effect, seconds, amplifier)); - public static void Give(EntityTarget targets, string effect, bool infinite = false, int amplifier = 0) => FunctionBuilder.Add(Str.Effect.Give(targets, effect, infinite, amplifier)); + public static void Give(Targets targets, string effect, bool infinite = false, int amplifier = 0) => FunctionBuilder.Add(Str.Effect.Give(targets, effect, infinite, amplifier)); public static void Give(string targets, string effect, bool infinite = false, int amplifier = 0) => FunctionBuilder.Add(Str.Effect.Give(targets, effect, infinite, amplifier)); - public static void Give(EntityTarget targets, string effect, int seconds, int amplifier = 0) => FunctionBuilder.Add(Str.Effect.Give(targets, effect, seconds, amplifier)); + public static void Give(Targets targets, string effect, int seconds, int amplifier = 0) => FunctionBuilder.Add(Str.Effect.Give(targets, effect, seconds, amplifier)); public static void Give(string targets, string effect, int seconds, int amplifier = 0) => FunctionBuilder.Add(Str.Effect.Give(targets, effect, seconds, amplifier)); public static void Clear() => FunctionBuilder.Add(Str.Effect.Clear()); - public static void Clear(EntityTarget targets) => FunctionBuilder.Add(Str.Effect.Clear(targets)); + public static void Clear(Targets targets) => FunctionBuilder.Add(Str.Effect.Clear(targets)); public static void Clear(string targets) => FunctionBuilder.Add(Str.Effect.Clear(targets)); - public static void Clear(EntityTarget targets, StatusEffect effect) => FunctionBuilder.Add(Str.Effect.Clear(targets, effect)); + public static void Clear(Targets targets, StatusEffect effect) => FunctionBuilder.Add(Str.Effect.Clear(targets, effect)); public static void Clear(string targets, StatusEffect effect) => FunctionBuilder.Add(Str.Effect.Clear(targets, effect)); - public static void Clear(EntityTarget targets, string effect) => FunctionBuilder.Add(Str.Effect.Clear(targets, effect)); + public static void Clear(Targets targets, string effect) => FunctionBuilder.Add(Str.Effect.Clear(targets, effect)); public static void Clear(string targets, string effect) => FunctionBuilder.Add(Str.Effect.Clear(targets, effect)); } \ No newline at end of file diff --git a/Core/EnchantCommand.cs b/Core/EnchantCommand.cs index a6b2405..47f4177 100644 --- a/Core/EnchantCommand.cs +++ b/Core/EnchantCommand.cs @@ -4,10 +4,10 @@ namespace SteveSharp.Core; public static class EnchantCommand { - public static void Enchant(EntityTarget targets, Enchantment enchantment) => FunctionBuilder.Add(Str.EnchantCommand.Enchant(targets, enchantment)); - public static void Enchant(EntityTarget targets, Enchantment enchantment, int level) => FunctionBuilder.Add(Str.EnchantCommand.Enchant(targets, enchantment, level)); - public static void Enchant(EntityTarget targets, string enchantment) => FunctionBuilder.Add(Str.EnchantCommand.Enchant(targets, enchantment)); - public static void Enchant(EntityTarget targets, string enchantment, int level) => FunctionBuilder.Add(Str.EnchantCommand.Enchant(targets, enchantment, level)); + public static void Enchant(Targets targets, Enchantment enchantment) => FunctionBuilder.Add(Str.EnchantCommand.Enchant(targets, enchantment)); + public static void Enchant(Targets targets, Enchantment enchantment, int level) => FunctionBuilder.Add(Str.EnchantCommand.Enchant(targets, enchantment, level)); + public static void Enchant(Targets targets, string enchantment) => FunctionBuilder.Add(Str.EnchantCommand.Enchant(targets, enchantment)); + public static void Enchant(Targets targets, string enchantment, int level) => FunctionBuilder.Add(Str.EnchantCommand.Enchant(targets, enchantment, level)); public static void Enchant(string targets, string enchantment) => FunctionBuilder.Add(Str.EnchantCommand.Enchant(targets, enchantment)); public static void Enchant(string targets, string enchantment, int level) => FunctionBuilder.Add(Str.EnchantCommand.Enchant(targets, enchantment, level)); public static void Enchant(string targets, Enchantment enchantment) => FunctionBuilder.Add(Str.EnchantCommand.Enchant(targets, enchantment)); diff --git a/Core/Entity.cs b/Core/Entity.cs index 5d09711..58da9f2 100644 --- a/Core/Entity.cs +++ b/Core/Entity.cs @@ -5,20 +5,20 @@ namespace SteveSharp.Core { public static class Entity { - public static string Selected(string match = "") { if (match == "") return "@s"; else return "@s[" + match + "]"; } - public static string AllPlayers(string match = "") { if (match == "") return "@a"; else return "@a[" + match + "]"; } - public static string RandomPlayer(string match = "") { if (match == "") return "@r"; else return "@r[" + match + "]"; } - public static string NearestPlayer(string match = "") { if (match == "") return "@p"; else return "@p[" + match + "]"; } - public static string AllEntities(string match = "") { if (match == "") return "@e"; else return "@e[" + match + "]"; } + public static string SelectedMatch(string match) => "@s[" + match + "]"; + public static string AllPlayersMatch(string match) => "@a[" + match + "]"; + public static string RandomPlayerMatch(string match) => "@r[" + match + "]"; + public static string NearestPlayerMatch(string match) => "@p[" + match + "]"; + public static string AllEntitiesMatch(string match) => "@e[" + match + "]"; /// /// This method selects an entity with specific matches, recommended if you want to select an entity with specific matches. /// /// - public static void Custom(EntityTarget targets, int? limit = null, string[]? tags = null, string[]? scores = null, string? team = null, string? type = null, string? distance = null, string? area = null, string? level = null, string? gamemode = null, string? horizontalRotation = null, string? verticalRotation = null, string? sort = null) + public static void Custom(Targets targets, int? limit = null, string[]? tags = null, string[]? scores = null, string? team = null, string? type = null, string? distance = null, string? area = null, string? level = null, string? gamemode = null, string? horizontalRotation = null, string? verticalRotation = null, string? sort = null) => FunctionBuilder.Add(Str.Entity.Custom(targets, limit, tags, scores, team, type, distance, area, level, gamemode, horizontalRotation, verticalRotation, sort)); public static void Custom(string targets, int? limit = null, string[]? tags = null, string[]? scores = null, string? team = null, string? type = null, string? distance = null, string? area = null, string? level = null, string? gamemode = null, string? horizontalRotation = null, string? verticalRotation = null, string? sort = null) => FunctionBuilder.Add(Str.Entity.Custom(targets, limit, tags, scores, team, type, distance, area, level, gamemode, horizontalRotation, verticalRotation, sort)); - public static void Teleport(EntityTarget targets, string to) => FunctionBuilder.Add(Str.Entity.Teleport(targets, to)); + public static void Teleport(Targets targets, string to) => FunctionBuilder.Add(Str.Entity.Teleport(targets, to)); public static void Teleport(string targets, string to) => FunctionBuilder.Add(Str.Entity.Teleport(targets, to)); public static void Summon(EntityEnum entity, (int X, int Y, int Z) pos, string nbt = "{}") => FunctionBuilder.Add(Str.Entity.Summon(entity, pos, nbt)); public static void Summon(EntityEnum entity, (string X, string Y, string Z) rel, string nbt = "{}") => FunctionBuilder.Add(Str.Entity.Summon(entity, rel, nbt)); @@ -26,11 +26,11 @@ public static void Custom(string targets, int? limit = null, string[]? tags = nu public static void Summon(string entity, (int X, int Y, int Z) pos, string nbt = "{}") => FunctionBuilder.Add(Str.Entity.Summon(entity, pos, nbt)); public static void Summon(string entity, (string X, string Y, string Z) rel, string nbt = "{}") => FunctionBuilder.Add(Str.Entity.Summon(entity, rel, nbt)); public static void Summon(string entity, string[] pos, string nbt = "{}") => FunctionBuilder.Add(Str.Entity.Summon(entity, pos, nbt)); - public static void AddTag(EntityTarget targets, string tag) => FunctionBuilder.Add(Str.Entity.AddTag(targets, tag)); + public static void AddTag(Targets targets, string tag) => FunctionBuilder.Add(Str.Entity.AddTag(targets, tag)); public static void AddTag(string targets, string tag) => FunctionBuilder.Add(Str.Entity.AddTag(targets, tag)); - public static void RemoveTag(EntityTarget targets, string tag) => FunctionBuilder.Add(Str.Entity.RemoveTag(targets, tag)); + public static void RemoveTag(Targets targets, string tag) => FunctionBuilder.Add(Str.Entity.RemoveTag(targets, tag)); public static void RemoveTag(string targets, string tag) => FunctionBuilder.Add(Str.Entity.RemoveTag(targets, tag)); - public static void Kill(EntityTarget targets) => FunctionBuilder.Add(Str.Entity.Kill(targets)); + public static void Kill(Targets targets) => FunctionBuilder.Add(Str.Entity.Kill(targets)); public static void Kill(string targets) => FunctionBuilder.Add(Str.Entity.Kill(targets)); } } \ No newline at end of file diff --git a/Core/Execute.cs b/Core/Execute.cs index 2ac0499..fe49bed 100644 --- a/Core/Execute.cs +++ b/Core/Execute.cs @@ -7,17 +7,17 @@ public static class Execute { const string[] defaults = null; public static void Write(string execute, string[] commands = defaults) => FunctionBuilder.Add(Str.Execute.Write(execute, commands)); - public static void As(EntityTarget targets, string addition = "") => FunctionBuilder.Add(Str.Execute.As(targets, addition)); + public static void As(Targets targets, string addition = "") => FunctionBuilder.Add(Str.Execute.As(targets, addition)); public static void As(string targets, string addition = "") => FunctionBuilder.Add(Str.Execute.As(targets, addition)); - public static void At(EntityTarget targets, string addition = "") => FunctionBuilder.Add(Str.Execute.At(targets, addition)); + public static void At(Targets targets, string addition = "") => FunctionBuilder.Add(Str.Execute.At(targets, addition)); public static void At(string targets, string addition = "") => FunctionBuilder.Add(Str.Execute.At(targets, addition)); - public static void Asat(EntityTarget targets, string addition = "") => FunctionBuilder.Add(Str.Execute.Asat(targets, addition)); + public static void Asat(Targets targets, string addition = "") => FunctionBuilder.Add(Str.Execute.Asat(targets, addition)); public static void Asat(string targets, string addition = "") => FunctionBuilder.Add(Str.Execute.Asat(targets, addition)); public static void Unless(string arguments, string addition = "") => FunctionBuilder.Add(Str.Execute.Unless(arguments, addition)); public static void If(string arguments, string addition = "") => FunctionBuilder.Add(Str.Execute.If(arguments, addition)); public static void Summon(string entity, string[] pos, string addition = "") => FunctionBuilder.Add(Str.Execute.Summon(entity, pos, addition)); public static void Store(string where, string at, string arguments, string addition = "") => FunctionBuilder.Add(Str.Execute.Store(where, at, arguments, addition)); - public static void StoreScore(string where, Score score, EntityTarget targets, string addition = "") => FunctionBuilder.Add(Str.Execute.StoreScore(where, score, targets, addition)); + public static void StoreScore(string where, Score score, Targets targets, string addition = "") => FunctionBuilder.Add(Str.Execute.StoreScore(where, score, targets, addition)); public static void StoreScore(string where, Score score, string targets = "", string addition = "") => FunctionBuilder.Add(Str.Execute.StoreScore(where, score, targets, addition)); } } diff --git a/Core/Recipe.cs b/Core/Recipe.cs index 72de33b..b62d12a 100644 --- a/Core/Recipe.cs +++ b/Core/Recipe.cs @@ -4,8 +4,8 @@ namespace SteveSharp.Core; public static class Recipe { - public static void Give(EntityTarget targets, string recipe) => FunctionBuilder.Add(Str.Recipe.Give(targets, recipe)); + public static void Give(Targets targets, string recipe) => FunctionBuilder.Add(Str.Recipe.Give(targets, recipe)); public static void Give(string targets, string recipe) => FunctionBuilder.Add(Str.Recipe.Give(targets, recipe)); - public static void Take(EntityTarget targets, string recipe) => FunctionBuilder.Add(Str.Recipe.Take(targets, recipe)); + public static void Take(Targets targets, string recipe) => FunctionBuilder.Add(Str.Recipe.Take(targets, recipe)); public static void Take(string targets, string recipe) => FunctionBuilder.Add(Str.Recipe.Take(targets, recipe)); } \ No newline at end of file diff --git a/Core/Score.cs b/Core/Score.cs index c439837..1eaca74 100644 --- a/Core/Score.cs +++ b/Core/Score.cs @@ -28,7 +28,7 @@ public void Set(int count, string targets = "") { FunctionBuilder.Add(Str.Score.Set(id, count, targets)); } - public void Set(int count, EntityTarget targets) + public void Set(int count, Targets targets) { FunctionBuilder.Add(Str.Score.Set(id, count, targets)); } @@ -40,7 +40,7 @@ public void Add(int count, string targets = "") { FunctionBuilder.Add(Str.Score.Add(id, count, targets)); } - public void Add(int count, EntityTarget targets) + public void Add(int count, Targets targets) { FunctionBuilder.Add(Str.Score.Add(id, count, targets)); } @@ -48,7 +48,7 @@ public static void Add(string id, int count, string targets = "") { FunctionBuilder.Add(Str.Score.Add(id, count, targets)); } - public static void Add(string id, int count, EntityTarget targets) + public static void Add(string id, int count, Targets targets) { FunctionBuilder.Add(Str.Score.Add(id, count, targets)); } @@ -56,7 +56,7 @@ public void Remove(int count, string targets = "") { FunctionBuilder.Add(Str.Score.Remove(id, count, targets)); } - public void Remove(int count, EntityTarget targets) + public void Remove(int count, Targets targets) { FunctionBuilder.Add(Str.Score.Remove(id, count, targets)); } @@ -64,7 +64,7 @@ public static void Remove(string id, int count, string targets = "") { FunctionBuilder.Add(Str.Score.Remove(id, count, targets)); } - public static void Remove(string id, int count, EntityTarget targets) + public static void Remove(string id, int count, Targets targets) { FunctionBuilder.Add(Str.Score.Remove(id, count, targets)); } @@ -72,7 +72,7 @@ public void Reset(string targets = "") { FunctionBuilder.Add(Str.Score.Reset(id, targets)); } - public void Reset(EntityTarget targets) + public void Reset(Targets targets) { FunctionBuilder.Add(Str.Score.Reset(id, targets)); } @@ -80,7 +80,7 @@ public static void Reset(string id, string targets = "") { FunctionBuilder.Add(Str.Score.Reset(id, targets)); } - public static void Reset(string id, EntityTarget targets) + public static void Reset(string id, Targets targets) { FunctionBuilder.Add(Str.Score.Reset(id, targets)); } @@ -151,24 +151,24 @@ public static string Matches(string id, int value){ FunctionBuilder.Add($"scoreboard players operation #{a.id} {a.id} %= #{b.id} {b.id}"); return a; } - public static Score operator + (Score a, EntityTarget b) { - FunctionBuilder.Add($"scoreboard players operation #{a.id} {a.id} += {EntityTargetHandler.Get(b)} {a.id}"); + public static Score operator + (Score a, Targets b) { + FunctionBuilder.Add($"scoreboard players operation #{a.id} {a.id} += {TargetsHandler.Get(b)} {a.id}"); return a; } - public static Score operator - (Score a, EntityTarget b) { - FunctionBuilder.Add($"scoreboard players operation #{a.id} {a.id} -= {EntityTargetHandler.Get(b)} {a.id}"); + public static Score operator - (Score a, Targets b) { + FunctionBuilder.Add($"scoreboard players operation #{a.id} {a.id} -= {TargetsHandler.Get(b)} {a.id}"); return a; } - public static Score operator * (Score a, EntityTarget b) { - FunctionBuilder.Add($"scoreboard players operation #{a.id} {a.id} *= {EntityTargetHandler.Get(b)} {a.id}"); + public static Score operator * (Score a, Targets b) { + FunctionBuilder.Add($"scoreboard players operation #{a.id} {a.id} *= {TargetsHandler.Get(b)} {a.id}"); return a; } - public static Score operator / (Score a, EntityTarget b) { - FunctionBuilder.Add($"scoreboard players operation #{a.id} {a.id} /= {EntityTargetHandler.Get(b)} {a.id}"); + public static Score operator / (Score a, Targets b) { + FunctionBuilder.Add($"scoreboard players operation #{a.id} {a.id} /= {TargetsHandler.Get(b)} {a.id}"); return a; } - public static Score operator % (Score a, EntityTarget b) { - FunctionBuilder.Add($"scoreboard players operation #{a.id} {a.id} %= {EntityTargetHandler.Get(b)} {a.id}"); + public static Score operator % (Score a, Targets b) { + FunctionBuilder.Add($"scoreboard players operation #{a.id} {a.id} %= {TargetsHandler.Get(b)} {a.id}"); return a; } public static Score operator + (Score a, string b) { diff --git a/Core/Strings/Chat.cs b/Core/Strings/Chat.cs index 477a129..120dcd8 100644 --- a/Core/Strings/Chat.cs +++ b/Core/Strings/Chat.cs @@ -10,15 +10,15 @@ public static string Say(string msg) { return $"say {msg}"; } - public static string Tell(EntityTarget targets, string message) { - return $"tell {EntityTargetHandler.Get(targets)} {message}"; + public static string Tell(Targets targets, string message) { + return $"tell {TargetsHandler.Get(targets)} {message}"; } public static string Tell(string targets, string message) { return $"tell {targets} {message}"; } - public static string Tellraw(EntityTarget targets, TextComponent[] text) + public static string Tellraw(Targets targets, TextComponent[] text) { - string command = "tellraw " + EntityTargetHandler.Get(targets) + " " + JsonSerializer.Serialize(text); + string command = "tellraw " + TargetsHandler.Get(targets) + " " + JsonSerializer.Serialize(text); return command; } public static string Tellraw(string targets, TextComponent[] text) @@ -26,9 +26,9 @@ public static string Tellraw(string targets, TextComponent[] text) string command = "tellraw " + targets + " " + JsonSerializer.Serialize(text); return command; } - public static string Tellraw(EntityTarget targets, TextComponent text) + public static string Tellraw(Targets targets, TextComponent text) { - string command = "tellraw " + EntityTargetHandler.Get(targets) + " " + JsonSerializer.Serialize(text); + string command = "tellraw " + TargetsHandler.Get(targets) + " " + JsonSerializer.Serialize(text); return command; } public static string Tellraw(string targets, TextComponent text) diff --git a/Core/Strings/Effect.cs b/Core/Strings/Effect.cs index 44893b6..bbacc49 100644 --- a/Core/Strings/Effect.cs +++ b/Core/Strings/Effect.cs @@ -3,11 +3,11 @@ namespace SteveSharp.Core.Strings; public static class Effect { - public static string Give(EntityTarget targets, StatusEffect effect, bool infinite = false, int amplifier = 0) { + public static string Give(Targets targets, StatusEffect effect, bool infinite = false, int amplifier = 0) { if(infinite) { - return $"effect give {EntityTargetHandler.Get(targets)} {StatusEffectHandler.Get(effect)} infinite {amplifier}"; + return $"effect give {TargetsHandler.Get(targets)} {StatusEffectHandler.Get(effect)} infinite {amplifier}"; } else { - return $"effect give {EntityTargetHandler.Get(targets)} {StatusEffectHandler.Get(effect)}"; + return $"effect give {TargetsHandler.Get(targets)} {StatusEffectHandler.Get(effect)}"; } } public static string Give(string targets, StatusEffect effect, bool infinite = false, int amplifier = 0) { @@ -17,17 +17,17 @@ public static string Give(string targets, StatusEffect effect, bool infinite = f return $"effect give {targets} {StatusEffectHandler.Get(effect)}"; } } - public static string Give(EntityTarget targets, StatusEffect effect, int seconds, int amplifier = 0) { - return $"effect give {EntityTargetHandler.Get(targets)} {StatusEffectHandler.Get(effect)} {seconds} {amplifier}"; + public static string Give(Targets targets, StatusEffect effect, int seconds, int amplifier = 0) { + return $"effect give {TargetsHandler.Get(targets)} {StatusEffectHandler.Get(effect)} {seconds} {amplifier}"; } public static string Give(string targets, StatusEffect effect, int seconds, int amplifier = 0) { return $"effect give {targets} {StatusEffectHandler.Get(effect)} {seconds} {amplifier}"; } - public static string Give(EntityTarget targets, string effect, bool infinite = false, int amplifier = 0) { + public static string Give(Targets targets, string effect, bool infinite = false, int amplifier = 0) { if(infinite) { - return $"effect give {EntityTargetHandler.Get(targets)} {effect} infinite {amplifier}"; + return $"effect give {TargetsHandler.Get(targets)} {effect} infinite {amplifier}"; } else { - return $"effect give {EntityTargetHandler.Get(targets)} {effect}"; + return $"effect give {TargetsHandler.Get(targets)} {effect}"; } } public static string Give(string targets, string effect, bool infinite = false, int amplifier = 0) { @@ -37,8 +37,8 @@ public static string Give(string targets, string effect, bool infinite = false, return $"effect give {targets} {effect}"; } } - public static string Give(EntityTarget targets, string effect, int seconds, int amplifier = 0) { - return $"effect give {EntityTargetHandler.Get(targets)} {effect} {seconds} {amplifier}"; + public static string Give(Targets targets, string effect, int seconds, int amplifier = 0) { + return $"effect give {TargetsHandler.Get(targets)} {effect} {seconds} {amplifier}"; } public static string Give(string targets, string effect, int seconds, int amplifier = 0) { return $"effect give {targets} {effect} {seconds} {amplifier}"; @@ -46,20 +46,20 @@ public static string Give(string targets, string effect, int seconds, int amplif public static string Clear() { return "effect clear"; } - public static string Clear(EntityTarget targets) { - return $"effect clear {EntityTargetHandler.Get(targets)}"; + public static string Clear(Targets targets) { + return $"effect clear {TargetsHandler.Get(targets)}"; } public static string Clear(string targets) { return $"effect clear {targets}"; } - public static string Clear(EntityTarget targets, StatusEffect effect) { - return $"effect clear {EntityTargetHandler.Get(targets)} {StatusEffectHandler.Get(effect)}"; + public static string Clear(Targets targets, StatusEffect effect) { + return $"effect clear {TargetsHandler.Get(targets)} {StatusEffectHandler.Get(effect)}"; } public static string Clear(string targets, StatusEffect effect) { return $"effect clear {targets} {StatusEffectHandler.Get(effect)}"; } - public static string Clear(EntityTarget targets, string effect) { - return $"effect clear {EntityTargetHandler.Get(targets)} {effect}"; + public static string Clear(Targets targets, string effect) { + return $"effect clear {TargetsHandler.Get(targets)} {effect}"; } public static string Clear(string targets, string effect) { return $"effect clear {targets} {effect}"; diff --git a/Core/Strings/EnchantCommand.cs b/Core/Strings/EnchantCommand.cs index 48ad152..8819cac 100644 --- a/Core/Strings/EnchantCommand.cs +++ b/Core/Strings/EnchantCommand.cs @@ -3,10 +3,10 @@ namespace SteveSharp.Core.Strings; public static class EnchantCommand { - public static string Enchant(EntityTarget targets, Enchantment enchantment) => $"enchant {EntityTargetHandler.Get(targets)} {EnchantmentHandler.Get(enchantment)}"; - public static string Enchant(EntityTarget targets, Enchantment enchantment, int level) => $"enchant {EntityTargetHandler.Get(targets)} {EnchantmentHandler.Get(enchantment)} {level}"; - public static string Enchant(EntityTarget targets, string enchantment) => $"enchant {EntityTargetHandler.Get(targets)} {enchantment}"; - public static string Enchant(EntityTarget targets, string enchantment, int level) => $"enchant {EntityTargetHandler.Get(targets)} {enchantment} {level}"; + public static string Enchant(Targets targets, Enchantment enchantment) => $"enchant {TargetsHandler.Get(targets)} {EnchantmentHandler.Get(enchantment)}"; + public static string Enchant(Targets targets, Enchantment enchantment, int level) => $"enchant {TargetsHandler.Get(targets)} {EnchantmentHandler.Get(enchantment)} {level}"; + public static string Enchant(Targets targets, string enchantment) => $"enchant {TargetsHandler.Get(targets)} {enchantment}"; + public static string Enchant(Targets targets, string enchantment, int level) => $"enchant {TargetsHandler.Get(targets)} {enchantment} {level}"; public static string Enchant(string targets, string enchantment) => $"enchant {targets} {enchantment}"; public static string Enchant(string targets, string enchantment, int level) => $"enchant {targets} {enchantment} {level}"; public static string Enchant(string targets, Enchantment enchantment) => $"enchant {targets} {EnchantmentHandler.Get(enchantment)}"; diff --git a/Core/Strings/Entity.cs b/Core/Strings/Entity.cs index d946432..f1725a5 100644 --- a/Core/Strings/Entity.cs +++ b/Core/Strings/Entity.cs @@ -8,8 +8,8 @@ public static class Entity /// This method selects an entity with specific matches, recommended if you want to select an entity with specific matches. /// /// - public static string Custom(EntityTarget targets, int? limit = null, string[]? tags = null, string[]? scores = null, string? team = null, string? type = null, string? distance = null, string? area = null, string? level = null, string? gamemode = null, string? horizontalRotation = null, string? verticalRotation = null, string? sort = null) - => Custom(EntityTargetHandler.Get(targets), limit, tags, scores, team, type, distance, area, level, gamemode, horizontalRotation, verticalRotation, sort); + public static string Custom(Targets targets, int? limit = null, string[]? tags = null, string[]? scores = null, string? team = null, string? type = null, string? distance = null, string? area = null, string? level = null, string? gamemode = null, string? horizontalRotation = null, string? verticalRotation = null, string? sort = null) + => Custom(TargetsHandler.Get(targets), limit, tags, scores, team, type, distance, area, level, gamemode, horizontalRotation, verticalRotation, sort); /// /// This method selects an entity with specific matches, recommended if you want to select an entity with specific matches. /// @@ -44,9 +44,9 @@ public static string Custom(string targets, int? limit = null, string[]? tags = match += ']'; return match; } - public static string Teleport(EntityTarget targets, string to) + public static string Teleport(Targets targets, string to) { - return $"tp {EntityTargetHandler.Get(targets)} {to}"; + return $"tp {TargetsHandler.Get(targets)} {to}"; } public static string Teleport(string targets, string to) { @@ -75,25 +75,25 @@ public static string Summon(string entity, string[] pos, string nbt = "{}") { return $"summon {entity} {pos[0]} {pos[1]} {pos[2]} {nbt}"; } - public static string AddTag(EntityTarget targets, string tag) + public static string AddTag(Targets targets, string tag) { - return $"tag {EntityTargetHandler.Get(targets)} add {tag}"; + return $"tag {TargetsHandler.Get(targets)} add {tag}"; } public static string AddTag(string targets, string tag) { return $"tag {targets} add {tag}"; } - public static string RemoveTag(EntityTarget targets, string tag) + public static string RemoveTag(Targets targets, string tag) { - return $"tag {EntityTargetHandler.Get(targets)} remove {tag}"; + return $"tag {TargetsHandler.Get(targets)} remove {tag}"; } public static string RemoveTag(string targets, string tag) { return $"tag {targets} remove {tag}"; } - public static string Kill(EntityTarget targets) + public static string Kill(Targets targets) { - return $"kill {EntityTargetHandler.Get(targets)}"; + return $"kill {TargetsHandler.Get(targets)}"; } public static string Kill(string targets) { diff --git a/Core/Strings/Execute.cs b/Core/Strings/Execute.cs index fddd7b0..3590c9e 100644 --- a/Core/Strings/Execute.cs +++ b/Core/Strings/Execute.cs @@ -15,25 +15,25 @@ public static string Write(string execute, string[] commands = defaults) } return allCommands; } - public static string As(EntityTarget targets, string addition = "") + public static string As(Targets targets, string addition = "") { - return "as " + EntityTargetHandler.Get(targets) + " " + addition; + return "as " + TargetsHandler.Get(targets) + " " + addition; } public static string As(string targets, string addition = "") { return "as " + targets + " " + addition; } - public static string At(EntityTarget targets, string addition = "") + public static string At(Targets targets, string addition = "") { - return "at " + EntityTargetHandler.Get(targets) + " " + addition; + return "at " + TargetsHandler.Get(targets) + " " + addition; } public static string At(string targets, string addition = "") { return "at " + targets + " " + addition; } - public static string Asat(EntityTarget targets, string addition = "") + public static string Asat(Targets targets, string addition = "") { - return "as " + EntityTargetHandler.Get(targets) + " at @s " + addition; + return "as " + TargetsHandler.Get(targets) + " at @s " + addition; } public static string Asat(string targets, string addition = "") { @@ -59,9 +59,9 @@ public static string Store(string where, string at, string arguments, string add { return "store " + where + " " + at + " " + arguments + " " + addition; } - public static string StoreScore(string where, Core.Score score, EntityTarget targets, string addition = "") + public static string StoreScore(string where, Core.Score score, Targets targets, string addition = "") { - return "store " + where + " score " + EntityTargetHandler.Get(targets) + " " + score.id + " " + addition; + return "store " + where + " score " + TargetsHandler.Get(targets) + " " + score.id + " " + addition; } public static string StoreScore(string where, Core.Score score, string targets = "", string addition = "") { diff --git a/Core/Strings/Recipe.cs b/Core/Strings/Recipe.cs index 39a8d1e..ac273ba 100644 --- a/Core/Strings/Recipe.cs +++ b/Core/Strings/Recipe.cs @@ -3,8 +3,8 @@ namespace SteveSharp.Core.Strings; public static class Recipe { - public static string Give(EntityTarget targets, string recipe) => $"recipe give {EntityTargetHandler.Get(targets)} {recipe}"; + public static string Give(Targets targets, string recipe) => $"recipe give {TargetsHandler.Get(targets)} {recipe}"; public static string Give(string targets, string recipe) => $"recipe give {targets} {recipe}"; - public static string Take(EntityTarget targets, string recipe) => $"recipe take {EntityTargetHandler.Get(targets)} {recipe}"; + public static string Take(Targets targets, string recipe) => $"recipe take {TargetsHandler.Get(targets)} {recipe}"; public static string Take(string targets, string recipe) => $"recipe take {targets} {recipe}"; } \ No newline at end of file diff --git a/Core/Strings/Score.cs b/Core/Strings/Score.cs index c2c4c1a..59f5e17 100644 --- a/Core/Strings/Score.cs +++ b/Core/Strings/Score.cs @@ -40,9 +40,9 @@ public string Set(int count, string targets = "") { return Set(id, count, targets); } - public string Set(int count, EntityTarget targets) + public string Set(int count, Targets targets) { - return Set(id, count, EntityTargetHandler.Get(targets)); + return Set(id, count, TargetsHandler.Get(targets)); } public static string Set(string id, int count, string targets = "") { @@ -54,16 +54,16 @@ public static string Set(string id, int count, string targets = "") return $"scoreboard players set {targets} {id} {count}"; } } - public static string Set(string id, int count, EntityTarget targets) + public static string Set(string id, int count, Targets targets) { - return $"scoreboard players set {EntityTargetHandler.Get(targets)} {id} {count}"; + return $"scoreboard players set {TargetsHandler.Get(targets)} {id} {count}"; } public string Add(int count, string targets = "") { return Add(id, count, targets); } - public string Add(int count, EntityTarget targets) { - return Add(id, count, EntityTargetHandler.Get(targets)); + public string Add(int count, Targets targets) { + return Add(id, count, TargetsHandler.Get(targets)); } public static string Add(string id, int count, string targets = "") { @@ -76,15 +76,15 @@ public static string Add(string id, int count, string targets = "") return $"scoreboard players add {targets} {id} {count}"; } } - public static string Add(string id, int count, EntityTarget targets) + public static string Add(string id, int count, Targets targets) { - return $"scoreboard players add {EntityTargetHandler.Get(targets)} {id} {count}"; + return $"scoreboard players add {TargetsHandler.Get(targets)} {id} {count}"; } public string Remove(int count, string targets = "") { return Remove(id, count, targets); } - public string Remove(int count, EntityTarget targets) + public string Remove(int count, Targets targets) { return Remove(id, count, targets); } @@ -99,17 +99,17 @@ public static string Remove(string id, int count, string targets = "") return $"scoreboard players remove {targets} {id} {count}"; } } - public static string Remove(string id, int count, EntityTarget targets) + public static string Remove(string id, int count, Targets targets) { - return $"scoreboard players remove {EntityTargetHandler.Get(targets)} {id} {count}"; + return $"scoreboard players remove {TargetsHandler.Get(targets)} {id} {count}"; } public string Reset(string targets = "") { return Reset(id, targets); } - public string Reset(EntityTarget targets) + public string Reset(Targets targets) { - return Reset(id, EntityTargetHandler.Get(targets)); + return Reset(id, TargetsHandler.Get(targets)); } public static string Reset(string id, string targets = "") { @@ -122,9 +122,9 @@ public static string Reset(string id, string targets = "") return $"scoreboard players reset {targets} {id}"; } } - public static string Reset(string id, EntityTarget targets) + public static string Reset(string id, Targets targets) { - return $"scoreboard players reset {EntityTargetHandler.Get(targets)} {id}"; + return $"scoreboard players reset {TargetsHandler.Get(targets)} {id}"; } /// /// Only for use in scores={} cases diff --git a/Core/Strings/Title.cs b/Core/Strings/Title.cs index c914186..104cd38 100644 --- a/Core/Strings/Title.cs +++ b/Core/Strings/Title.cs @@ -6,11 +6,11 @@ namespace SteveSharp.Core.Strings; public static class Title { #region /title actionbar - public static string Actionbar(EntityTarget targets, TextComponent text) { - return $"title {EntityTargetHandler.Get(targets)} actionbar {JsonSerializer.Serialize(text)}"; + public static string Actionbar(Targets targets, TextComponent text) { + return $"title {TargetsHandler.Get(targets)} actionbar {JsonSerializer.Serialize(text)}"; } - public static string Actionbar(EntityTarget targets, TextComponent[] text) { - return $"title {EntityTargetHandler.Get(targets)} actionbar {JsonSerializer.Serialize(text)}"; + public static string Actionbar(Targets targets, TextComponent[] text) { + return $"title {TargetsHandler.Get(targets)} actionbar {JsonSerializer.Serialize(text)}"; } public static string Actionbar(string targets, TextComponent text) { return $"title {targets} actionbar {JsonSerializer.Serialize(text)}"; @@ -20,11 +20,11 @@ public static string Actionbar(string targets, TextComponent[] text) { } #endregion #region /title title - public static string ShowTitle(EntityTarget targets, TextComponent text) { - return $"title {EntityTargetHandler.Get(targets)} title {JsonSerializer.Serialize(text)}"; + public static string ShowTitle(Targets targets, TextComponent text) { + return $"title {TargetsHandler.Get(targets)} title {JsonSerializer.Serialize(text)}"; } - public static string ShowTitle(EntityTarget targets, TextComponent[] text) { - return $"title {EntityTargetHandler.Get(targets)} title {JsonSerializer.Serialize(text)}"; + public static string ShowTitle(Targets targets, TextComponent[] text) { + return $"title {TargetsHandler.Get(targets)} title {JsonSerializer.Serialize(text)}"; } public static string ShowTitle(string targets, TextComponent text) { return $"title {targets} title {JsonSerializer.Serialize(text)}"; @@ -34,11 +34,11 @@ public static string ShowTitle(string targets, TextComponent[] text) { } #endregion #region /title subtitle - public static string Subtitle(EntityTarget targets, TextComponent text) { - return $"title {EntityTargetHandler.Get(targets)} subtitle {JsonSerializer.Serialize(text)}"; + public static string Subtitle(Targets targets, TextComponent text) { + return $"title {TargetsHandler.Get(targets)} subtitle {JsonSerializer.Serialize(text)}"; } - public static string Subtitle(EntityTarget targets, TextComponent[] text) { - return $"title {EntityTargetHandler.Get(targets)} subtitle {JsonSerializer.Serialize(text)}"; + public static string Subtitle(Targets targets, TextComponent[] text) { + return $"title {TargetsHandler.Get(targets)} subtitle {JsonSerializer.Serialize(text)}"; } public static string Subtitle(string targets, TextComponent text) { return $"title {targets} subtitle {JsonSerializer.Serialize(text)}"; @@ -48,24 +48,24 @@ public static string Subtitle(string targets, TextComponent[] text) { } #endregion #region /title clear - public static string Clear(EntityTarget target) { - return $"title {EntityTargetHandler.Get(target)} clear"; + public static string Clear(Targets target) { + return $"title {TargetsHandler.Get(target)} clear"; } public static string Clear(string targets) { return $"title {targets} clear"; } #endregion #region /title reset - public static string Reset(EntityTarget targets) { - return $"title {EntityTargetHandler.Get(targets)} reset"; + public static string Reset(Targets targets) { + return $"title {TargetsHandler.Get(targets)} reset"; } public static string Reset(string targets) { return $"title {targets} reset"; } #endregion #region /title times - public static string Times(EntityTarget targets, string fadeIn, string stay, string fadeOut) { - return $"title {EntityTargetHandler.Get(targets)} times {fadeIn} {stay} {fadeOut}"; + public static string Times(Targets targets, string fadeIn, string stay, string fadeOut) { + return $"title {TargetsHandler.Get(targets)} times {fadeIn} {stay} {fadeOut}"; } public static string Times(string targets, string fadeIn, string stay, string fadeOut) { return $"title {targets} times {fadeIn} {stay} {fadeOut}"; diff --git a/Core/Title.cs b/Core/Title.cs index ddc9155..ea4e235 100644 --- a/Core/Title.cs +++ b/Core/Title.cs @@ -6,33 +6,33 @@ namespace SteveSharp.Core; public static class Title { #region /title actionbar - public static void Actionbar(EntityTarget targets, TextComponent text) => FunctionBuilder.Add(Str.Title.Actionbar(targets, text)); - public static void Actionbar(EntityTarget targets, TextComponent[] text) => FunctionBuilder.Add(Str.Title.Actionbar(targets, text)); + public static void Actionbar(Targets targets, TextComponent text) => FunctionBuilder.Add(Str.Title.Actionbar(targets, text)); + public static void Actionbar(Targets targets, TextComponent[] text) => FunctionBuilder.Add(Str.Title.Actionbar(targets, text)); public static void Actionbar(string targets, TextComponent text) => FunctionBuilder.Add(Str.Title.Actionbar(targets, text)); public static void Actionbar(string targets, TextComponent[] text) => FunctionBuilder.Add(Str.Title.Actionbar(targets, text)); #endregion #region /title title - public static void ShowTitle(EntityTarget targets, TextComponent text) => FunctionBuilder.Add(Str.Title.ShowTitle(targets, text)); - public static void ShowTitle(EntityTarget targets, TextComponent[] text) => FunctionBuilder.Add(Str.Title.ShowTitle(targets, text)); + public static void ShowTitle(Targets targets, TextComponent text) => FunctionBuilder.Add(Str.Title.ShowTitle(targets, text)); + public static void ShowTitle(Targets targets, TextComponent[] text) => FunctionBuilder.Add(Str.Title.ShowTitle(targets, text)); public static void ShowTitle(string targets, TextComponent text) => FunctionBuilder.Add(Str.Title.ShowTitle(targets, text)); public static void ShowTitle(string targets, TextComponent[] text) => FunctionBuilder.Add(Str.Title.ShowTitle(targets, text)); #endregion #region /title subtitle - public static void Subtitle(EntityTarget targets, TextComponent text) => FunctionBuilder.Add(Str.Title.Subtitle(targets, text)); - public static void Subtitle(EntityTarget targets, TextComponent[] text) => FunctionBuilder.Add(Str.Title.Subtitle(targets, text)); + public static void Subtitle(Targets targets, TextComponent text) => FunctionBuilder.Add(Str.Title.Subtitle(targets, text)); + public static void Subtitle(Targets targets, TextComponent[] text) => FunctionBuilder.Add(Str.Title.Subtitle(targets, text)); public static void Subtitle(string targets, TextComponent text) => FunctionBuilder.Add(Str.Title.Subtitle(targets, text)); public static void Subtitle(string targets, TextComponent[] text) => FunctionBuilder.Add(Str.Title.Subtitle(targets, text)); #endregion #region /title clear - public static void Clear(EntityTarget target) => FunctionBuilder.Add(Str.Title.Clear(target)); + public static void Clear(Targets target) => FunctionBuilder.Add(Str.Title.Clear(target)); public static void Clear(string target) => FunctionBuilder.Add(Str.Title.Clear(target)); #endregion #region /title reset - public static void Reset(EntityTarget targets) => FunctionBuilder.Add(Str.Title.Reset(targets)); + public static void Reset(Targets targets) => FunctionBuilder.Add(Str.Title.Reset(targets)); public static void Reset(string targets) => FunctionBuilder.Add(Str.Title.Reset(targets)); #endregion #region /title times - public static void Times(EntityTarget targets, string fadeIn, string stay, string fadeOut) => FunctionBuilder.Add(Str.Title.Times(targets, fadeIn, stay, fadeOut)); + public static void Times(Targets targets, string fadeIn, string stay, string fadeOut) => FunctionBuilder.Add(Str.Title.Times(targets, fadeIn, stay, fadeOut)); public static void Times(string targets, string fadeIn, string stay, string fadeOut) => FunctionBuilder.Add(Str.Title.Times(targets, fadeIn, stay, fadeOut)); #endregion } \ No newline at end of file diff --git a/Generic/EntityTargetHandler.cs b/Generic/EntityTargetHandler.cs deleted file mode 100644 index f29f4a7..0000000 --- a/Generic/EntityTargetHandler.cs +++ /dev/null @@ -1,15 +0,0 @@ -namespace SteveSharp.Generic; - -internal static class EntityTargetHandler { - internal static string Get(EntityTarget targets) { - Dictionary entityTargetStr = new() { - {EntityTarget.NearestPlayer, "@p"}, - {EntityTarget.RandomPlayer, "@r"}, - {EntityTarget.AllPlayers, "@a"}, - {EntityTarget.AllEntities, "@e"}, - {EntityTarget.Selected, "@s"} - }; - - return entityTargetStr[targets]; - } -} \ No newline at end of file diff --git a/Generic/EntityTarget.cs b/Generic/Targets.cs similarity index 80% rename from Generic/EntityTarget.cs rename to Generic/Targets.cs index e816ddb..64e7ab5 100644 --- a/Generic/EntityTarget.cs +++ b/Generic/Targets.cs @@ -1,6 +1,6 @@ namespace SteveSharp.Generic; -public enum EntityTarget { +public enum Targets { NearestPlayer, RandomPlayer, AllPlayers, diff --git a/Generic/TargetsHandler.cs b/Generic/TargetsHandler.cs new file mode 100644 index 0000000..a0e7466 --- /dev/null +++ b/Generic/TargetsHandler.cs @@ -0,0 +1,15 @@ +namespace SteveSharp.Generic; + +internal static class TargetsHandler { + internal static string Get(Targets targets) { + Dictionary TargetsStr = new() { + {Targets.NearestPlayer, "@p"}, + {Targets.RandomPlayer, "@r"}, + {Targets.AllPlayers, "@a"}, + {Targets.AllEntities, "@e"}, + {Targets.Selected, "@s"} + }; + + return TargetsStr[targets]; + } +} \ No newline at end of file From 2638538953cc97796440579a53fe14eceb3f3f44 Mon Sep 17 00:00:00 2001 From: Hazel Rojas <84425557+hazelcode@users.noreply.github.com> Date: Wed, 2 Apr 2025 08:16:44 +0000 Subject: [PATCH 38/52] Reflect Matches suffix change on Hitbox util --- Utils/Hitbox.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Utils/Hitbox.cs b/Utils/Hitbox.cs index 7e2cba9..010b288 100644 --- a/Utils/Hitbox.cs +++ b/Utils/Hitbox.cs @@ -52,16 +52,16 @@ public Function SummonFunction() { body: (ctx) => { Entity.Summon(EntityEnum.Interaction, [coords.x, coords.y, coords.y], "{Tags:[\"" + _ctx.Namespace + "." + Id + "\"],width:" + Width + ",height:" + Height + "}"); Execute.Write( - Str.Execute.Asat(Entity.AllEntities("type=interaction,tag=" + _ctx.Namespace + "." + Id)) + + Str.Execute.Asat(Entity.AllEntitiesMatch("type=interaction,tag=" + _ctx.Namespace + "." + Id)) + "on attacker ", [Str.Function.Call($"{_ctx.Namespace}:hitbox/{Workspace}/on_attack")] ); Execute.Write( - Str.Execute.Asat(Entity.AllEntities("type=interaction,tag=" + _ctx.Namespace + "." + Id)) + + Str.Execute.Asat(Entity.AllEntitiesMatch("type=interaction,tag=" + _ctx.Namespace + "." + Id)) + "on target ", [Str.Function.Call($"{_ctx.Namespace}:hitbox/{Workspace}/on_right_click")] ); - Entity.Kill(Entity.AllEntities("type=interaction,tag=" + _ctx.Namespace + "." + Id)); + Entity.Kill(Entity.AllEntitiesMatch("type=interaction,tag=" + _ctx.Namespace + "." + Id)); return FunctionBuilder.Collect(); } ); From de37ebcdabf448173be3fe18138aeb637fbc6128 Mon Sep 17 00:00:00 2001 From: Hazel Rojas <84425557+hazelcode@users.noreply.github.com> Date: Wed, 2 Apr 2025 08:39:37 +0000 Subject: [PATCH 39/52] Add support for tuples in Score operators, and string overloads behave as execute store --- Core/Score.cs | 50 +++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 45 insertions(+), 5 deletions(-) diff --git a/Core/Score.cs b/Core/Score.cs index 1eaca74..da0c54b 100644 --- a/Core/Score.cs +++ b/Core/Score.cs @@ -171,24 +171,64 @@ public static string Matches(string id, int value){ FunctionBuilder.Add($"scoreboard players operation #{a.id} {a.id} %= {TargetsHandler.Get(b)} {a.id}"); return a; } + public static Score operator + (Score a, (string targets, Score scoreboard) b) { + FunctionBuilder.Add($"scoreboard players operation #{a.id} {a.id} += {b.targets} {b.scoreboard.id}"); + return a; + } + public static Score operator - (Score a, (string targets, Score scoreboard) b) { + FunctionBuilder.Add($"scoreboard players operation #{a.id} {a.id} -= {b.targets} {b.scoreboard.id}"); + return a; + } + public static Score operator * (Score a, (string targets, Score scoreboard) b) { + FunctionBuilder.Add($"scoreboard players operation #{a.id} {a.id} *= {b.targets} {b.scoreboard.id}"); + return a; + } + public static Score operator / (Score a, (string targets, Score scoreboard) b) { + FunctionBuilder.Add($"scoreboard players operation #{a.id} {a.id} /= {b.targets} {b.scoreboard.id}"); + return a; + } + public static Score operator % (Score a, (string targets, Score scoreboard) b) { + FunctionBuilder.Add($"scoreboard players operation #{a.id} {a.id} %= {b.targets} {b.scoreboard.id}"); + return a; + } public static Score operator + (Score a, string b) { - FunctionBuilder.Add($"scoreboard players operation #{a.id} {a.id} += {b} {a.id}"); + FunctionBuilder.Add( + $"execute store result score #{a.id}_temp {a.id} run {b}\n"+ + $"scoreboard players operation #{a.id} {a.id} += #{a.id}_temp {a.id}\n"+ + $"scoreboard players reset #{a.id}_temp" + ); return a; } public static Score operator - (Score a, string b) { - FunctionBuilder.Add($"scoreboard players operation #{a.id} {a.id} -= {b} {a.id}"); + FunctionBuilder.Add( + $"execute store result score #{a.id}_temp {a.id} run {b}\n"+ + $"scoreboard players operation #{a.id} {a.id} -= #{a.id}_temp {a.id}\n"+ + $"scoreboard players reset #{a.id}_temp" + ); return a; } public static Score operator * (Score a, string b) { - FunctionBuilder.Add($"scoreboard players operation #{a.id} {a.id} *= {b} {a.id}"); + FunctionBuilder.Add( + $"execute store result score #{a.id}_temp {a.id} run {b}\n"+ + $"scoreboard players operation #{a.id} {a.id} *= #{a.id}_temp {a.id}\n"+ + $"scoreboard players reset #{a.id}_temp" + ); return a; } public static Score operator / (Score a, string b) { - FunctionBuilder.Add($"scoreboard players operation #{a.id} {a.id} /= {b} {a.id}"); + FunctionBuilder.Add( + $"execute store result score #{a.id}_temp {a.id} run {b}\n"+ + $"scoreboard players operation #{a.id} {a.id} /= #{a.id}_temp {a.id}\n"+ + $"scoreboard players reset #{a.id}_temp" + ); return a; } public static Score operator % (Score a, string b) { - FunctionBuilder.Add($"scoreboard players operation #{a.id} {a.id} %= {b} {a.id}"); + FunctionBuilder.Add( + $"execute store result score #{a.id}_temp {a.id} run {b}\n"+ + $"scoreboard players operation #{a.id} {a.id} %= #{a.id}_temp {a.id}\n"+ + $"scoreboard players reset #{a.id}_temp" + ); return a; } public static bool operator == (Score a, int b) { From 7d2b659c95c554ce37737291d93df44c3f353309 Mon Sep 17 00:00:00 2001 From: Hazel Rojas <84425557+hazelcode@users.noreply.github.com> Date: Wed, 2 Apr 2025 08:41:44 +0000 Subject: [PATCH 40/52] Add `GetTimestamp` function to `Time` class --- Core/Time.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/Core/Time.cs b/Core/Time.cs index f3bfc91..81ce2b1 100644 --- a/Core/Time.cs +++ b/Core/Time.cs @@ -4,4 +4,5 @@ public class Time { public static string Ticks(int ticks) => ticks + "t"; public static string Seconds(int seconds) => seconds + "s"; public static string Days(int days) => days + "d"; + public static string GetTimestamp() => "time query gametime"; } \ No newline at end of file From 726e954cf356049a255b162af910d353c8624cc9 Mon Sep 17 00:00:00 2001 From: Hazel Rojas <84425557+hazelcode@users.noreply.github.com> Date: Wed, 2 Apr 2025 08:54:07 +0000 Subject: [PATCH 41/52] Add NearestEntity target selector --- Generic/Targets.cs | 4 ++++ Generic/TargetsHandler.cs | 1 + 2 files changed, 5 insertions(+) diff --git a/Generic/Targets.cs b/Generic/Targets.cs index 64e7ab5..aadf26f 100644 --- a/Generic/Targets.cs +++ b/Generic/Targets.cs @@ -2,6 +2,10 @@ namespace SteveSharp.Generic; public enum Targets { NearestPlayer, + /// + /// Minecraft 1.21 + /// + NearestEntity, RandomPlayer, AllPlayers, AllEntities, diff --git a/Generic/TargetsHandler.cs b/Generic/TargetsHandler.cs index a0e7466..933c5cf 100644 --- a/Generic/TargetsHandler.cs +++ b/Generic/TargetsHandler.cs @@ -4,6 +4,7 @@ internal static class TargetsHandler { internal static string Get(Targets targets) { Dictionary TargetsStr = new() { {Targets.NearestPlayer, "@p"}, + {Targets.NearestEntity, "@n"}, {Targets.RandomPlayer, "@r"}, {Targets.AllPlayers, "@a"}, {Targets.AllEntities, "@e"}, From d05c86c6b159acdcd3c61d08dab77184a9e9cde6 Mon Sep 17 00:00:00 2001 From: Hazel Rojas <84425557+hazelcode@users.noreply.github.com> Date: Wed, 2 Apr 2025 09:02:50 +0000 Subject: [PATCH 42/52] Add objective by default on scoreboard creation --- Core/Score.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/Core/Score.cs b/Core/Score.cs index da0c54b..46387fa 100644 --- a/Core/Score.cs +++ b/Core/Score.cs @@ -13,6 +13,7 @@ public Score(string id, string type = "dummy", string name = "") this.id = id; this.type = type; this.name = name; + AddObjective(); } public void AddObjective() => FunctionBuilder.Add(Str.Score.AddObjective(id, type, name)); public static void AddObjective(string id, string type, string name) => FunctionBuilder.Add(Str.Score.AddObjective(id, type, name)); From 39548488786032f7dfac02882ff2761237149a21 Mon Sep 17 00:00:00 2001 From: Hazel Rojas <84425557+hazelcode@users.noreply.github.com> Date: Fri, 4 Apr 2025 08:34:18 +0000 Subject: [PATCH 43/52] Implement `ScoreEnum`s --- Core/Score.cs | 23 +++++++++++++++++++++-- Core/ScoreEnum.cs | 30 ++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+), 2 deletions(-) create mode 100644 Core/ScoreEnum.cs diff --git a/Core/Score.cs b/Core/Score.cs index 46387fa..e5762db 100644 --- a/Core/Score.cs +++ b/Core/Score.cs @@ -289,6 +289,25 @@ public override bool Equals(object? obj) { } } - public override int GetHashCode() => GetHashCode(); + public override int GetHashCode() => GetHashCode(); + + public static void Enum(string name, string[] keys, out ScoreEnum scoreEnum) { + Dictionary keyValuePairs = new(); + string commands = $"scoreboard objectives add {name} dummy\n"; + int i = 0; + foreach(var key in keys) { + commands += $"scoreboard players set #{key} {name} {i}\n"; + keyValuePairs[key] = i; + i++; + } + scoreEnum = (ScoreEnum) keyValuePairs; + i = 0; + foreach(var key in keys) { + scoreEnum.EnumMap.Add(i, key); + i++; + } + + FunctionBuilder.Add(commands); + } } -} +} \ No newline at end of file diff --git a/Core/ScoreEnum.cs b/Core/ScoreEnum.cs new file mode 100644 index 0000000..4e5809f --- /dev/null +++ b/Core/ScoreEnum.cs @@ -0,0 +1,30 @@ +using SteveSharp.Generic; + +namespace SteveSharp.Core; + +public class ScoreEnum() : Dictionary { + public string? Name { get; set; } + public Dictionary EnumMap { get; set; } = []; + public void Switch(Targets targets, Dictionary cases) { + List commands = []; + + foreach(var codeBlock in cases) { + foreach(var command in codeBlock.Value) { + commands.Add($"execute as {TargetsHandler.Get(targets)} if score @s {Name} = #{EnumMap[codeBlock.Key]} {Name} run {command}"); + } + } + + FunctionBuilder.Add(commands); + } + public void Switch(Targets asat, Dictionary> cases) { + List commands = []; + + foreach(var codeBlock in cases) { + foreach(var command in codeBlock.Value) { + commands.Add($"execute as {TargetsHandler.Get(asat)} at @s if score @s {Name} = #{EnumMap[codeBlock.Key]} {Name} run {command}"); + } + } + + FunctionBuilder.Add(commands); + } +} \ No newline at end of file From 8ae482de7cadd77c9f3722adebb8d60a720afa7e Mon Sep 17 00:00:00 2001 From: Hazel Rojas <84425557+hazelcode@users.noreply.github.com> Date: Fri, 4 Apr 2025 08:55:16 +0000 Subject: [PATCH 44/52] fix casting exception --- Core/Score.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Core/Score.cs b/Core/Score.cs index e5762db..5f62db7 100644 --- a/Core/Score.cs +++ b/Core/Score.cs @@ -295,12 +295,13 @@ public static void Enum(string name, string[] keys, out ScoreEnum scoreEnum) { Dictionary keyValuePairs = new(); string commands = $"scoreboard objectives add {name} dummy\n"; int i = 0; + scoreEnum = []; foreach(var key in keys) { commands += $"scoreboard players set #{key} {name} {i}\n"; keyValuePairs[key] = i; + scoreEnum.Add(key, keyValuePairs[key]); i++; } - scoreEnum = (ScoreEnum) keyValuePairs; i = 0; foreach(var key in keys) { scoreEnum.EnumMap.Add(i, key); From 3fea5141bfed07dc5386eb4d792cfe4cfdcc18ed Mon Sep 17 00:00:00 2001 From: Hazel Rojas <84425557+hazelcode@users.noreply.github.com> Date: Fri, 4 Apr 2025 09:26:41 +0000 Subject: [PATCH 45/52] Fixings and implementations in score enums --- Core/Score.cs | 5 +++-- Core/ScoreEnum.cs | 15 +++++++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/Core/Score.cs b/Core/Score.cs index 5f62db7..2f19c56 100644 --- a/Core/Score.cs +++ b/Core/Score.cs @@ -293,11 +293,12 @@ public override bool Equals(object? obj) { public static void Enum(string name, string[] keys, out ScoreEnum scoreEnum) { Dictionary keyValuePairs = new(); - string commands = $"scoreboard objectives add {name} dummy\n"; + List commands = [$"scoreboard objectives add {name} dummy"]; int i = 0; scoreEnum = []; + scoreEnum.Name = name; foreach(var key in keys) { - commands += $"scoreboard players set #{key} {name} {i}\n"; + commands.Add($"scoreboard players set #{key} {name} {i}"); keyValuePairs[key] = i; scoreEnum.Add(key, keyValuePairs[key]); i++; diff --git a/Core/ScoreEnum.cs b/Core/ScoreEnum.cs index 4e5809f..5baa558 100644 --- a/Core/ScoreEnum.cs +++ b/Core/ScoreEnum.cs @@ -27,4 +27,19 @@ public void Switch(Targets asat, Dictionary> cases) { FunctionBuilder.Add(commands); } + + public void Reset(Targets targets) => FunctionBuilder.Add($"scoreboard players reset {TargetsHandler.Get(targets)} {Name}"); + public void Reset(string targets) => FunctionBuilder.Add($"scoreboard players reset {targets} {Name}"); + public void Next(Targets targets) { + FunctionBuilder.Add([ + $"execute as {TargetsHandler.Get(targets)} if score @s {Name} >= #{EnumMap[EnumMap.Count-1]} {Name} run scoreboard players set @s {Name} -1", + $"execute as {TargetsHandler.Get(targets)} unless score @s {Name} > #{EnumMap[EnumMap.Count-1]} {Name} run scoreboard players add @s {Name} 1" + ]); + } + public void Next(string targets) { + FunctionBuilder.Add([ + $"execute as {targets} if score @s {Name} >= #{EnumMap[EnumMap.Count-1]} {Name} run scoreboard players set @s {Name} -1", + $"execute as {targets} unless score @s {Name} > #{EnumMap[EnumMap.Count-1]} {Name} run scoreboard players add @s {Name} 1" + ]); + } } \ No newline at end of file From 654d61a66957e67e92adb7ef6fcf0fa312644f82 Mon Sep 17 00:00:00 2001 From: Hazel Rojas <84425557+hazelcode@users.noreply.github.com> Date: Fri, 4 Apr 2025 14:56:35 +0000 Subject: [PATCH 46/52] Add `Past` method for ScoreEnum --- Core/ScoreEnum.cs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/Core/ScoreEnum.cs b/Core/ScoreEnum.cs index 5baa558..874d13a 100644 --- a/Core/ScoreEnum.cs +++ b/Core/ScoreEnum.cs @@ -42,4 +42,16 @@ public void Next(string targets) { $"execute as {targets} unless score @s {Name} > #{EnumMap[EnumMap.Count-1]} {Name} run scoreboard players add @s {Name} 1" ]); } + public void Past(Targets targets) { + FunctionBuilder.Add([ + $"execute as {TargetsHandler.Get(targets)} if score @s {Name} matches ..0 run scoreboard players set @s {Name} {Count-1}", + $"execute as {TargetsHandler.Get(targets)} unless score @s {Name} matches ..1 run scoreboard players remove @s {Name} 1" + ]); + } + public void Past(string targets) { + FunctionBuilder.Add([ + $"execute as {targets} if score @s {Name} matches ..0 run scoreboard players set @s {Name} {Count-1}", + $"execute as {targets} unless score @s {Name} matches ..1 run scoreboard players remove @s {Name} 1" + ]); + } } \ No newline at end of file From 106e0a901832a5c2887f5934ae9a7969c2154961 Mon Sep 17 00:00:00 2001 From: Hazel Rojas <84425557+hazelcode@users.noreply.github.com> Date: Tue, 8 Apr 2025 13:19:52 +0000 Subject: [PATCH 47/52] Implement `Trigger`s (`/scoreboard objectives add x trigger`) --- Core/Score.cs | 7 +++++++ Core/Trigger.cs | 31 +++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+) create mode 100644 Core/Trigger.cs diff --git a/Core/Score.cs b/Core/Score.cs index 2f19c56..7d45e72 100644 --- a/Core/Score.cs +++ b/Core/Score.cs @@ -311,5 +311,12 @@ public static void Enum(string name, string[] keys, out ScoreEnum scoreEnum) { FunctionBuilder.Add(commands); } + public static void Trigger(string name, Targets targets, Function onTrigger, ref Trigger trigger) { + trigger = new Trigger(name, targets, onTrigger); + } + + public static void Trigger(string name, string targets, Function onTrigger, out Trigger trigger) { + trigger = new Trigger(name, targets, onTrigger); + } } } \ No newline at end of file diff --git a/Core/Trigger.cs b/Core/Trigger.cs new file mode 100644 index 0000000..d3a09d2 --- /dev/null +++ b/Core/Trigger.cs @@ -0,0 +1,31 @@ +using SteveSharp.Generic; + +namespace SteveSharp.Core; + +public class Trigger : Score { + public string Name { get; set; } = "trigger_"+new Random().Next(1,64); + public string Targets { get; set; } = "@a"; + public Function OnTriggerFn { get; set; } + + public Trigger(string name, Targets targets, Function onTrigger) : base(name, "trigger") { + Name = name; + Targets = TargetsHandler.Get(targets); + OnTriggerFn = onTrigger; + } + public Trigger(string name, string targets, Function onTrigger) : base(name, "trigger") { + Name = name; + Targets = targets; + OnTriggerFn = onTrigger; + } + + public void Enable() { + FunctionBuilder.Add($"scoreboard players enable {Targets} {Name}"); + } + + public void IfTriggered(Targets targets, string matches) { + FunctionBuilder.Add($"execute as {TargetsHandler.Get(targets)} if score @s {Name} matches {matches} run function {OnTriggerFn.Name}"); + } + public void IfTriggered(string targets, string matches) { + FunctionBuilder.Add($"execute as {targets} if score @s {Name} matches {matches} run function {OnTriggerFn.Name}"); + } +} \ No newline at end of file From a90be3118097c731910442f429edf30b5792a644 Mon Sep 17 00:00:00 2001 From: Hazel Rojas <84425557+hazelcode@users.noreply.github.com> Date: Thu, 10 Apr 2025 18:38:45 +0000 Subject: [PATCH 48/52] Implement `StrictConventionException` exception --- Exceptions/StrictConventionException.cs | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 Exceptions/StrictConventionException.cs diff --git a/Exceptions/StrictConventionException.cs b/Exceptions/StrictConventionException.cs new file mode 100644 index 0000000..57e5d34 --- /dev/null +++ b/Exceptions/StrictConventionException.cs @@ -0,0 +1,10 @@ +namespace SteveSharp.Exceptions; +public class StrictConventionException : Exception { + public string Convention { get; set; } + public string Reason { get; } + public override string Message => $"MC Datapacks convention violation!\nConvention: {Convention}\nReason: \"{Reason}\".\nPlease check the convention and realize necessary changes."; + public StrictConventionException(string convention, string reason) { + Convention = convention; + Reason = reason; + } +} \ No newline at end of file From e767da3edb25d0bfbdfdf6399eb6de13a302ef2d Mon Sep 17 00:00:00 2001 From: Hazel Rojas <84425557+hazelcode@users.noreply.github.com> Date: Wed, 11 Jun 2025 16:48:38 +0000 Subject: [PATCH 49/52] Pre implementation of NBT (errors) --- NBT/NBT.cs | 14 ++++++++++++++ NBT/NBTParser.cs | 47 +++++++++++++++++++++++++++++++++++++++++++++++ NBT/NBTType.cs | 7 +++++++ 3 files changed, 68 insertions(+) create mode 100644 NBT/NBT.cs create mode 100644 NBT/NBTParser.cs create mode 100644 NBT/NBTType.cs diff --git a/NBT/NBT.cs b/NBT/NBT.cs new file mode 100644 index 0000000..e4914cb --- /dev/null +++ b/NBT/NBT.cs @@ -0,0 +1,14 @@ +namespace SteveSharp.NBT; + +public class NBTTag +{ + public NBTType Type { get; set; } = NBTType.SingleValue; + public string Name { get; set; } + public object Value { get; set; } + + public NBTTag(string name, object value) + { + Name = name; + Value = value; + } +} \ No newline at end of file diff --git a/NBT/NBTParser.cs b/NBT/NBTParser.cs new file mode 100644 index 0000000..329f0c2 --- /dev/null +++ b/NBT/NBTParser.cs @@ -0,0 +1,47 @@ +namespace SteveSharp.NBT; + +public class NBTParser +{ + public string ParseValueType(object value) + => value switch + { + string => "\"" + value.ToString() + "\"", + float => value.ToString() + "f", + bool => value.ToString()!.ToLower(), + byte => value.ToString() + "b", + short => value.ToString() + "s", + long => value.ToString() + "l", + _ => value.ToString()! + }; + public string Parse(NBTTag nbt) + { + string nbtString = ""; + switch (nbt.Type) + { + case NBTType.SingleValue: + return nbt.Name + ": " + ParseValueType(nbt.Value); + case NBTType.List: + nbtString = nbt.Name + ": ["; + List? list = nbt.Value as List; + for (int i = 0; i < list!.Count; i++) + { + nbtString += ParseValueType(list[i]); + if (i < list.Count - 1) + nbtString += ", "; + } + return s; + case NBTType.Compound: + nbtString = nbt.Name + "{"; + Dictionary? compound = nbt.Value as Dictionary; + foreach (var item in compound!) + { + nbtString += nbt.Name + ": "; + nbtString += nbt.Value switch + { + _ => nbtString.ToString() + }; + } + } + return null!; + } +} \ No newline at end of file diff --git a/NBT/NBTType.cs b/NBT/NBTType.cs new file mode 100644 index 0000000..a1c8fd0 --- /dev/null +++ b/NBT/NBTType.cs @@ -0,0 +1,7 @@ +namespace SteveSharp.NBT; + +public enum NBTType { + SingleValue, + List, + Compound +} \ No newline at end of file From 7375ea9df531bc44485aec3eac3175cca1fd0ce1 Mon Sep 17 00:00:00 2001 From: Hazel Rojas <84425557+hazelcode@users.noreply.github.com> Date: Sun, 22 Jun 2025 22:25:09 +0000 Subject: [PATCH 50/52] Implement NBT Parsing --- Exceptions/NBTParsingException.cs | 7 +++ NBT/NBT.cs | 5 +- NBT/NBTParser.cs | 100 +++++++++++++++++++++++++----- 3 files changed, 95 insertions(+), 17 deletions(-) create mode 100644 Exceptions/NBTParsingException.cs diff --git a/Exceptions/NBTParsingException.cs b/Exceptions/NBTParsingException.cs new file mode 100644 index 0000000..9366304 --- /dev/null +++ b/Exceptions/NBTParsingException.cs @@ -0,0 +1,7 @@ +using SteveSharp.NBT; + +namespace SteveSharp.Exceptions; +public class NBTParsingException(NBTTag nbt) : Exception { + public NBTTag NBT { get => nbt; } + public override string Message => $"Could not parse NBT Tag \"{NBT.Name}\". Please check the value type and tag type:\n\tValue Type: {NBT.Value.GetType()}\n\tTag Type: {NBT.Type}\nPlease check if it isn't supported by the NBT Tag parser."; +} \ No newline at end of file diff --git a/NBT/NBT.cs b/NBT/NBT.cs index e4914cb..524f2a5 100644 --- a/NBT/NBT.cs +++ b/NBT/NBT.cs @@ -2,12 +2,13 @@ namespace SteveSharp.NBT; public class NBTTag { - public NBTType Type { get; set; } = NBTType.SingleValue; + public NBTType Type { get; } public string Name { get; set; } public object Value { get; set; } - public NBTTag(string name, object value) + public NBTTag(string name, object value, NBTType type = NBTType.SingleValue) { + Type = type; Name = name; Value = value; } diff --git a/NBT/NBTParser.cs b/NBT/NBTParser.cs index 329f0c2..e0de9ea 100644 --- a/NBT/NBTParser.cs +++ b/NBT/NBTParser.cs @@ -1,7 +1,35 @@ +using SteveSharp.Exceptions; + namespace SteveSharp.NBT; public class NBTParser { + public string Encompass(string nbtText) => '{' + nbtText + '}'; + public string Encompass(List nbtTexts) + { + string s = "{"; + for (int i = 0; i < nbtTexts.Count; i++) + { + s += nbtTexts[i]; + if (i < nbtTexts.Count - 1) // if it's not the last item in the list + s += ", "; + } + s += "}"; + return s; + } + public string Enlist(string nbts) => '[' + nbts + ']'; + public string Enlist(List nbts) + { + string s = "["; + for (int i = 0; i < nbts.Count; i++) + { + s += nbts[i]; + if (i < nbts.Count - 1) // if it's not the last item in the list + s += ", "; + } + s += "]"; + return s; + } public string ParseValueType(object value) => value switch { @@ -13,35 +41,77 @@ public string ParseValueType(object value) long => value.ToString() + "l", _ => value.ToString()! }; + public string Parse(NBTTag nbt) { - string nbtString = ""; + string nbtString = nbt.Name + ": "; switch (nbt.Type) { case NBTType.SingleValue: - return nbt.Name + ": " + ParseValueType(nbt.Value); + nbtString += ParseValueType(nbt.Value); + return nbtString; case NBTType.List: - nbtString = nbt.Name + ": ["; - List? list = nbt.Value as List; + dynamic? list; + nbtString += "["; + if (nbt.Value is List) + { + list = nbt.Value as List; + } + else if (nbt.Value is List) + { + list = nbt.Value as List; + } + else if (nbt.Value is List) + { + list = nbt.Value as List; + } + else if (nbt.Value is List) + { + list = nbt.Value as List; + } + else if (nbt.Value is List) + { + list = nbt.Value as List; + } + else if (nbt.Value is List) + { + list = nbt.Value as List; + } + else if (nbt.Value is List) + { + list = nbt.Value as List; + } + else if (nbt.Value is List) + { + list = nbt.Value as List; + } + else + { + list = nbt.Value as List; + } + for (int i = 0; i < list!.Count; i++) { nbtString += ParseValueType(list[i]); - if (i < list.Count - 1) + if (i < list.Count - 1) // if it's not the last item in the list nbtString += ", "; } - return s; + nbtString += "]"; + return nbtString; case NBTType.Compound: - nbtString = nbt.Name + "{"; - Dictionary? compound = nbt.Value as Dictionary; - foreach (var item in compound!) + nbtString += "{"; + List? tags = nbt.Value as List; + int left = tags!.Count; + for (int i = 0; i < tags.Count; i++) { - nbtString += nbt.Name + ": "; - nbtString += nbt.Value switch - { - _ => nbtString.ToString() - }; + nbtString += Parse(tags[i]); + if (i < tags.Count - 1) // if it's not the last item in the list + nbtString += ", "; } + nbtString += "}"; + return nbtString; + default: + throw new NBTParsingException(nbt); } - return null!; } } \ No newline at end of file From d95a06bd3767ee192960316cf66af1ea67f9d0af Mon Sep 17 00:00:00 2001 From: Hazel Rojas <84425557+hazelcode@users.noreply.github.com> Date: Sun, 22 Jun 2025 23:13:19 +0000 Subject: [PATCH 51/52] Add `/xp` command (`XP`) --- Core/Strings/XP.cs | 86 +++++++++++++++++++++++++++++++++++++++++++ Core/XP.cs | 91 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 177 insertions(+) create mode 100644 Core/Strings/XP.cs create mode 100644 Core/XP.cs diff --git a/Core/Strings/XP.cs b/Core/Strings/XP.cs new file mode 100644 index 0000000..d0eadb7 --- /dev/null +++ b/Core/Strings/XP.cs @@ -0,0 +1,86 @@ +using SteveSharp.Generic; + +namespace SteveSharp.Core.Strings; + +public static class XP +{ + public static string AddXP(Targets targets, int amount) + { + return $"xp add {TargetsHandler.Get(targets)} {amount}"; + } + + public static string AddXP(string targets, int amount) + { + return $"xp add {targets} {amount}"; + } + + public static string AddXPLevels(Targets targets, int amount) + { + return $"xp add {TargetsHandler.Get(targets)} {amount} levels"; + } + + public static string AddXPLevels(string targets, int amount) + { + return $"xp add {targets} {amount} levels"; + } + + public static string AddXPPoints(Targets targets, int amount) + { + return $"xp add {TargetsHandler.Get(targets)} {amount} points"; + } + + public static string AddXPPoints(string targets, int amount) + { + return $"xp add {targets} {amount} points"; + } + + public static string XPLevelsQuery(Targets targets) + { + return $"xp query {TargetsHandler.Get(targets)} levels"; + } + + public static string XPLevelsQuery(string targets) + { + return $"xp query {targets} levels"; + } + + public static string XPQuery(Targets targets) + { + return $"xp query {TargetsHandler.Get(targets)} points"; + } + + public static string XPQuery(string targets) + { + return $"xp query {targets} points"; + } + + public static string SetXP(Targets targets, int amount) + { + return $"xp set {TargetsHandler.Get(targets)} {amount}"; + } + + public static string SetXP(string targets, int amount) + { + return $"xp set {targets} {amount}"; + } + + public static string SetXPLevels(Targets targets, int amount) + { + return $"xp set {TargetsHandler.Get(targets)} {amount} levels"; + } + + public static string SetXPLevels(string targets, int amount) + { + return $"xp set {targets} {amount} levels"; + } + + public static string SetXPPoints(Targets targets, int amount) + { + return $"xp set {TargetsHandler.Get(targets)} {amount} points"; + } + + public static string SetXPPoints(string targets, int amount) + { + return $"xp set {targets} {amount} points"; + } +} \ No newline at end of file diff --git a/Core/XP.cs b/Core/XP.cs new file mode 100644 index 0000000..9dad260 --- /dev/null +++ b/Core/XP.cs @@ -0,0 +1,91 @@ +using SteveSharp.Generic; +using Str = SteveSharp.Core.Strings; + +namespace SteveSharp.Core; + +public static class XP +{ + #region Add + public static void AddXP(Targets targets, int amount) + { + FunctionBuilder.Add(Str.XP.AddXP(targets, amount)); + } + + public static void AddXP(string targets, int amount) + { + FunctionBuilder.Add(Str.XP.AddXP(targets, amount)); + } + + public static void AddXPLevels(Targets targets, int amount) + { + FunctionBuilder.Add(Str.XP.AddXPLevels(targets, amount)); + } + + public static void AddXPLevels(string targets, int amount) + { + FunctionBuilder.Add(Str.XP.AddXPLevels(targets, amount)); + } + + public static void AddXPPoints(Targets targets, int amount) + { + FunctionBuilder.Add(Str.XP.AddXPPoints(targets, amount)); + } + + public static void AddXPPoints(string targets, int amount) + { + FunctionBuilder.Add(Str.XP.AddXPPoints(targets, amount)); + } + #endregion + #region Query + public static void XPLevelsQuery(Targets targets) + { + FunctionBuilder.Add(Str.XP.XPLevelsQuery(targets)); + } + + public static void XPLevelsQuery(string targets) + { + FunctionBuilder.Add(Str.XP.XPLevelsQuery(targets)); + } + + public static void XPQuery(Targets targets) + { + FunctionBuilder.Add(Str.XP.XPQuery(targets)); + } + + public static void XPQuery(string targets) + { + FunctionBuilder.Add(Str.XP.XPQuery(targets)); + } + #endregion + #region Set + public static void SetXP(Targets targets, int amount) + { + FunctionBuilder.Add(Str.XP.SetXP(targets, amount)); + } + + public static void SetXP(string targets, int amount) + { + FunctionBuilder.Add(Str.XP.SetXP(targets, amount)); + } + + public static void SetXPLevels(Targets targets, int amount) + { + FunctionBuilder.Add(Str.XP.SetXPLevels(targets, amount)); + } + + public static void SetXPLevels(string targets, int amount) + { + FunctionBuilder.Add(Str.XP.SetXPLevels(targets, amount)); + } + + public static void SetXPPoints(Targets targets, int amount) + { + FunctionBuilder.Add(Str.XP.SetXPPoints(targets, amount)); + } + + public static void SetXPPoints(string targets, int amount) + { + FunctionBuilder.Add(Str.XP.SetXPPoints(targets, amount)); + } + #endregion +} \ No newline at end of file From 0995a90b2986a6843485282419c4ae10d861faca Mon Sep 17 00:00:00 2001 From: Hazel Rojas <84425557+hazelcode@users.noreply.github.com> Date: Mon, 23 Jun 2025 02:08:33 +0000 Subject: [PATCH 52/52] Implement basic support for Common Trait Convention --- MCDatapacksConventions/OC.cs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 MCDatapacksConventions/OC.cs diff --git a/MCDatapacksConventions/OC.cs b/MCDatapacksConventions/OC.cs new file mode 100644 index 0000000..a147930 --- /dev/null +++ b/MCDatapacksConventions/OC.cs @@ -0,0 +1,22 @@ +using SteveSharp.NBT; + +namespace SteveSharp.MCDatapacksConventions; + +/// +/// 1. Official Conventions +/// +public static class OC +{ + public class CTCMember(string name, object value, NBTType type = NBTType.SingleValue) : NBTTag(name, value, type); + public class Trait(string traitName, bool enabled = true) : NBTTag(traitName, enabled); + + /// + /// Common Trait Convention + /// + public static NBTTag CTC(List members) => new NBTTag("ctc", members, NBTType.Compound); + + public static CTCMember Traits(List traits) => new CTCMember("traits", traits, NBTType.Compound); + public static CTCMember Id(string id) => new CTCMember("id", id); + public static CTCMember From(string namespacedId) => new CTCMember("from", namespacedId); + +} \ No newline at end of file