4242import net .fabricmc .fabric .api .client .command .v2 .FabricClientCommandSource ;
4343import net .minecraft .client .network .ClientPlayNetworkHandler ;
4444import net .minecraft .client .sound .PositionedSoundInstance ;
45+ import net .minecraft .enchantment .Enchantment ;
46+ import net .minecraft .enchantment .Enchantments ;
4547import net .minecraft .item .Item ;
4648import net .minecraft .item .ItemStack ;
4749import net .minecraft .item .Items ;
@@ -1667,6 +1669,22 @@ public enum ScriptActionType {
16671669 ctx .context ().setVariable (ctx .variable ("Result" ).name (), new ScriptTextValue (result ));
16681670 })),
16691671
1672+ REGEX_REPLACE_TEXT (builder -> builder .name ("Replace Text using Regex" )
1673+ .description (new String []{"Searches for part of a text" , "using a regex and replaces it." })
1674+ .icon (Items .LEAD , true )
1675+ .arg ("Result" , ScriptActionArgumentType .VARIABLE )
1676+ .arg ("Text to change" , ScriptActionArgumentType .TEXT )
1677+ .arg ("Regex" , ScriptActionArgumentType .TEXT )
1678+ .arg ("Replacement" , ScriptActionArgumentType .TEXT )
1679+ .category (ScriptActionCategory .TEXTS )
1680+ .action (ctx -> {
1681+ String result = ctx .value ("Text to change" ).asText ();
1682+
1683+ result = result .replaceAll (ctx .value ("Regex" ).asText (), ctx .value ("Replacement" ).asText ());
1684+
1685+ ctx .context ().setVariable (ctx .variable ("Result" ).name (), new ScriptTextValue (result ));
1686+ })),
1687+
16701688 REMOVE_TEXT (builder -> builder .name ("Remove Text" )
16711689 .description ("Searches for part of a text and replaces it." )
16721690 .icon (Items .WRITABLE_BOOK )
@@ -1729,6 +1747,8 @@ public enum ScriptActionType {
17291747
17301748 private Consumer <ScriptActionContext > action = (ctx ) -> {
17311749 };
1750+
1751+ private boolean glow = false ;
17321752 private Item icon = Items .STONE ;
17331753 private String name = "Unnamed Action" ;
17341754 private boolean hasChildren = false ;
@@ -1764,6 +1784,12 @@ public ItemStack getIcon() {
17641784 item .getSubNbt ("display" )
17651785 .put ("Lore" , lore );
17661786
1787+ if (glow )
1788+ {
1789+ item .addEnchantment (Enchantments .UNBREAKING , 1 );
1790+ item .addHideFlag (ItemStack .TooltipSection .ENCHANTMENTS );
1791+ }
1792+
17671793 return item ;
17681794 }
17691795 public String getName () {
@@ -1783,8 +1809,14 @@ private ScriptActionType action(Consumer<ScriptActionContext> action) {
17831809 return this ;
17841810 }
17851811
1786- private ScriptActionType icon (Item icon ) {
1812+ private ScriptActionType icon (Item icon , boolean glow ) {
17871813 this .icon = icon ;
1814+ this .glow = glow ;
1815+ return this ;
1816+ }
1817+
1818+ private ScriptActionType icon (Item icon ) {
1819+ icon (icon , false );
17881820 return this ;
17891821 }
17901822
0 commit comments