Skip to content

Commit 1836f19

Browse files
Merge pull request #14 from RedCommand-dev/1.19
\n for newline instead of array
2 parents d784458 + 2343e43 commit 1836f19

File tree

2 files changed

+44
-11
lines changed

2 files changed

+44
-11
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# User-specific stuff
22
.idea/
3+
.vscode/
34

45
*.iml
56
*.ipr
@@ -116,3 +117,6 @@ run/
116117

117118
# Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored)
118119
!gradle-wrapper.jar
120+
121+
# Bin folder
122+
bin/

src/main/java/io/github/techstreet/dfscript/script/action/ScriptActionType.java

Lines changed: 40 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1611,10 +1611,46 @@ public enum ScriptActionType {
16111611
}
16121612
})),
16131613

1614+
RANDOM_INT(builder -> builder.name("Random Int")
1615+
.description("Generates a random whole number between two other numbers.")
1616+
.icon(Items.HOPPER)
1617+
.category(ScriptActionCategory.NUMBERS)
1618+
.arg("Result", ScriptActionArgumentType.VARIABLE)
1619+
.arg("Min", ScriptActionArgumentType.NUMBER)
1620+
.arg("Max", ScriptActionArgumentType.NUMBER)
1621+
.action(ctx -> {
1622+
int min = (int) ctx.value("Min").asNumber();
1623+
int max = (int) ctx.value("Max").asNumber();
1624+
Random random = new Random();
1625+
int result = random.nextInt(max + 1 - min) + min;
1626+
ctx.context().setVariable(
1627+
ctx.variable("Result").name(),
1628+
new ScriptNumberValue(result)
1629+
);
1630+
})),
1631+
1632+
RANDOM_DOUBLE(builder -> builder.name("Random Double")
1633+
.description("Generates a random floating point number between two other numbers.")
1634+
.icon(Items.HOPPER)
1635+
.category(ScriptActionCategory.NUMBERS)
1636+
.arg("Result", ScriptActionArgumentType.VARIABLE)
1637+
.arg("Min", ScriptActionArgumentType.NUMBER)
1638+
.arg("Max", ScriptActionArgumentType.NUMBER)
1639+
.action(ctx -> {
1640+
double min = ctx.value("Min").asNumber();
1641+
double max = ctx.value("Max").asNumber();
1642+
double result = Math.random() * (max - min) + min;
1643+
ctx.context().setVariable(
1644+
ctx.variable("Result").name(),
1645+
new ScriptNumberValue(result)
1646+
);
1647+
})),
1648+
16141649
RANDOM_NUMBER(builder -> builder.name("Random Number")
16151650
.description("Generates a random number between two other numbers.")
16161651
.icon(Items.HOPPER)
16171652
.category(ScriptActionCategory.NUMBERS)
1653+
.deprecate(RANDOM_DOUBLE)
16181654
.arg("Result", ScriptActionArgumentType.VARIABLE)
16191655
.arg("Min", ScriptActionArgumentType.NUMBER)
16201656
.arg("Max", ScriptActionArgumentType.NUMBER)
@@ -1629,7 +1665,7 @@ public enum ScriptActionType {
16291665
})),
16301666

16311667
REPEAT_FOREVER(builder -> builder.name("RepeatForever")
1632-
.description(new String[]{"Repeats for eternity.", "Make sure to have a Stop Repetition, Stop Codeline or Wait somewhere in the code!", "There's a lagslayer for the repetition actions.", "It activates after 100000 iterations with no Wait."})
1668+
.description("Repeats for eternity.\nMake sure to have a Stop Repetition, Stop Codeline or Wait somewhere in the code!\nThere's a lagslayer for the repetition actions.\nIt activates after 100000 iterations with no Wait.")
16331669
.icon(Items.GOLD_INGOT)
16341670
.category(ScriptActionCategory.MISC)
16351671
.hasChildren(true)
@@ -1638,7 +1674,7 @@ public enum ScriptActionType {
16381674
ctx.scheduleInner(null, context -> context.setLastIfResult(true));
16391675
})),
16401676
ELSE(builder -> builder.name("Else")
1641-
.description(new String[]{"Executes if the last IF condition failed.","And ELSE also works as a valid IF condition for ELSE."})
1677+
.description("Executes if the last IF condition failed.\nAnd ELSE also works as a valid IF condition for ELSE.")
16421678
.icon(Items.END_STONE)
16431679
.category(ScriptActionCategory.MISC)
16441680
.group(ScriptGroup.CONDITION)
@@ -1687,7 +1723,7 @@ public enum ScriptActionType {
16871723
})),
16881724

16891725
REGEX_REPLACE_TEXT(builder -> builder.name("Replace Text using Regex")
1690-
.description(new String[]{"Searches for part of a text", "using a regex and replaces it."})
1726+
.description("Searches for part of a text\nusing a regex and replaces it.")
16911727
.icon(Items.LEAD, true)
16921728
.arg("Result", ScriptActionArgumentType.VARIABLE)
16931729
.arg("Text to change", ScriptActionArgumentType.TEXT)
@@ -1874,17 +1910,10 @@ private ScriptActionType category(ScriptActionCategory category) {
18741910

18751911
private ScriptActionType description(String description) {
18761912
this.description.clear();
1877-
this.description.add(description);
1913+
this.description.addAll(Arrays.asList(description.split("\n", -1)));
18781914
return this;
18791915
}
18801916

1881-
private ScriptActionType description(String[] description) {
1882-
this.description.clear();
1883-
1884-
this.description.addAll(Arrays.asList(description));
1885-
1886-
return this;
1887-
}
18881917
private ScriptActionType group(ScriptGroup group) {
18891918
this.group = group;
18901919
return this;

0 commit comments

Comments
 (0)