Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
2f80773
Resolve error for GitHub Codespace
hazelcode Mar 17, 2025
e679f0b
Create FunctionBuilder for building new functions
hazelcode Mar 17, 2025
af50188
Upgrade .NET Action to .NET 8.0
hazelcode Mar 17, 2025
365afbd
Implement Variables in Project
hazelcode Mar 17, 2025
6310fbc
Create Function context
hazelcode Mar 17, 2025
657cf15
Function modifications
hazelcode Mar 17, 2025
4ac564e
Project modifications
hazelcode Mar 17, 2025
8b53f87
Implement GetFunctionCommands function
hazelcode Mar 17, 2025
4af8cd0
Modifications for FunctionBuilder
hazelcode Mar 17, 2025
d717d7b
Rewrite Commands!
hazelcode Mar 17, 2025
82fdff1
Rename Chat.Out to Chat.Tellraw
hazelcode Mar 17, 2025
75deac5
Add Tell command
hazelcode Mar 17, 2025
2672800
Fix "scoreboard objectives add" whitespace error
hazelcode Mar 17, 2025
18b71b4
Adjust TextComponent properties
hazelcode Mar 17, 2025
9b1c99c
Use PackFormat enumeration instead of Int
hazelcode Mar 17, 2025
ed7b8e7
Re-implement the capability of EXTENDING FUNCTIONS!!!!
hazelcode Mar 18, 2025
57276cd
Re-implement Hitbox!!
hazelcode Mar 18, 2025
275baee
Remove unused usings in Hitbox file
hazelcode Mar 18, 2025
f5fd7b4
Remove unused displays
hazelcode Mar 18, 2025
b8b6bb9
Make EntityEnum
hazelcode Mar 18, 2025
12e3aa5
Implement `DatapackFeatureException` exception and internal `Context`…
hazelcode Mar 20, 2025
2f4cb11
Make use of Context
hazelcode Mar 20, 2025
12ffdf3
Implement Minecraft 1.20.2 changes for `pack.mcmeta`
hazelcode Mar 20, 2025
9ad33c8
Add `/effect` command (`Effect`) and implement `StatusEffect` enumer…
hazelcode Mar 30, 2025
3b222c8
Implement EntityTarget and other great changes
hazelcode Mar 30, 2025
c1f2745
Remove code in `StatusEffectHandler` that throws exceptions
hazelcode Mar 30, 2025
53e6112
Fix accessors in `SteveSharp.Generic` namespace
hazelcode Mar 30, 2025
3a23cfb
Fix `XYZ.Rel` returning ~0 if input equals to 0
hazelcode Mar 30, 2025
1873617
Remove Context and resume some code in `Project` and unused usings
hazelcode Mar 30, 2025
24fb45f
Add `/title` command (`Title`)
hazelcode Mar 31, 2025
ca44bb1
Add `Time` for representing game time
hazelcode Mar 31, 2025
b6477e9
Implement score operators!!
hazelcode Apr 1, 2025
8a066a9
Fix ortographic issues in EntityHandler and EntityEnum
hazelcode Apr 1, 2025
14872dc
Fix Pos first element mistake
hazelcode Apr 1, 2025
9696bdf
Migrate Function strings
hazelcode Apr 1, 2025
73dd5ac
Add `/enchant` command (`EnchantCommand`)
hazelcode Apr 2, 2025
6022394
Rename `EntityTargets` to `Targets` and rename `Entity` selectors wit…
hazelcode Apr 2, 2025
2638538
Reflect Matches suffix change on Hitbox util
hazelcode Apr 2, 2025
de37ebc
Add support for tuples in Score operators, and string overloads behav…
hazelcode Apr 2, 2025
7d2b659
Add `GetTimestamp` function to `Time` class
hazelcode Apr 2, 2025
726e954
Add NearestEntity target selector
hazelcode Apr 2, 2025
d05c86c
Add objective by default on scoreboard creation
hazelcode Apr 2, 2025
3954848
Implement `ScoreEnum`s
hazelcode Apr 4, 2025
8ae482d
fix casting exception
hazelcode Apr 4, 2025
3fea514
Fixings and implementations in score enums
hazelcode Apr 4, 2025
654d61a
Add `Past` method for ScoreEnum
hazelcode Apr 4, 2025
106e0a9
Implement `Trigger`s (`/scoreboard objectives add x trigger`)
hazelcode Apr 8, 2025
a90be31
Implement `StrictConventionException` exception
hazelcode Apr 10, 2025
e767da3
Pre implementation of NBT (errors)
hazelcode Jun 11, 2025
7375ea9
Implement NBT Parsing
hazelcode Jun 22, 2025
d95a06b
Add `/xp` command (`XP`)
hazelcode Jun 22, 2025
0995a90
Implement basic support for Common Trait Convention
hazelcode Jun 23, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/dotnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
81 changes: 32 additions & 49 deletions Core/Bossbar.cs
Original file line number Diff line number Diff line change
@@ -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
{
Expand All @@ -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<GetField, string> 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<Style, string> 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);
}
25 changes: 10 additions & 15 deletions Core/Chat.cs
Original file line number Diff line number Diff line change
@@ -1,23 +1,18 @@
using SteveSharp.JsonShapes;
using SteveSharp.Generic;
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 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(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(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));
}
}
29 changes: 29 additions & 0 deletions Core/Effect.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using SteveSharp.Generic;
using Str = SteveSharp.Core.Strings;

namespace SteveSharp.Core;

public static class Effect {
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(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(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(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(Targets targets) => FunctionBuilder.Add(Str.Effect.Clear(targets));
public static void Clear(string targets) => FunctionBuilder.Add(Str.Effect.Clear(targets));

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(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));
}
15 changes: 15 additions & 0 deletions Core/EnchantCommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using SteveSharp.Generic;
using Str = SteveSharp.Core.Strings;

namespace SteveSharp.Core;

public static class EnchantCommand {
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));
public static void Enchant(string targets, Enchantment enchantment, int level) => FunctionBuilder.Add(Str.EnchantCommand.Enchant(targets, enchantment, level));
}
85 changes: 28 additions & 57 deletions Core/Entity.cs
Original file line number Diff line number Diff line change
@@ -1,65 +1,36 @@
namespace SteveSharp.Core
using SteveSharp.Generic;
using Str = SteveSharp.Core.Strings;

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 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 + "]";
/// <summary>
/// This method selects an entity with specific matches, recommended if you want to select an entity with specific matches.
/// </summary>
/// <returns></returns>
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(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(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));
public static void Summon(EntityEnum entity, string[] pos, string nbt = "{}") => FunctionBuilder.Add(Str.Entity.Summon(entity, pos, nbt));
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(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(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(Targets targets) => FunctionBuilder.Add(Str.Entity.Kill(targets));
public static void Kill(string targets) => FunctionBuilder.Add(Str.Entity.Kill(targets));
}
}
}
Loading