Skip to content

Commit 84b0ffc

Browse files
authored
Merge branch 'TechStreetDev:1.19' into XTer-2
2 parents c2a03b3 + 1836f19 commit 84b0ffc

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
@@ -1631,10 +1631,46 @@ public enum ScriptActionType {
16311631
}
16321632
})),
16331633

1634+
RANDOM_INT(builder -> builder.name("Random Int")
1635+
.description("Generates a random whole number between two other numbers.")
1636+
.icon(Items.HOPPER)
1637+
.category(ScriptActionCategory.NUMBERS)
1638+
.arg("Result", ScriptActionArgumentType.VARIABLE)
1639+
.arg("Min", ScriptActionArgumentType.NUMBER)
1640+
.arg("Max", ScriptActionArgumentType.NUMBER)
1641+
.action(ctx -> {
1642+
int min = (int) ctx.value("Min").asNumber();
1643+
int max = (int) ctx.value("Max").asNumber();
1644+
Random random = new Random();
1645+
int result = random.nextInt(max + 1 - min) + min;
1646+
ctx.context().setVariable(
1647+
ctx.variable("Result").name(),
1648+
new ScriptNumberValue(result)
1649+
);
1650+
})),
1651+
1652+
RANDOM_DOUBLE(builder -> builder.name("Random Double")
1653+
.description("Generates a random floating point number between two other numbers.")
1654+
.icon(Items.HOPPER)
1655+
.category(ScriptActionCategory.NUMBERS)
1656+
.arg("Result", ScriptActionArgumentType.VARIABLE)
1657+
.arg("Min", ScriptActionArgumentType.NUMBER)
1658+
.arg("Max", ScriptActionArgumentType.NUMBER)
1659+
.action(ctx -> {
1660+
double min = ctx.value("Min").asNumber();
1661+
double max = ctx.value("Max").asNumber();
1662+
double result = Math.random() * (max - min) + min;
1663+
ctx.context().setVariable(
1664+
ctx.variable("Result").name(),
1665+
new ScriptNumberValue(result)
1666+
);
1667+
})),
1668+
16341669
RANDOM_NUMBER(builder -> builder.name("Random Number")
16351670
.description("Generates a random number between two other numbers.")
16361671
.icon(Items.HOPPER)
16371672
.category(ScriptActionCategory.NUMBERS)
1673+
.deprecate(RANDOM_DOUBLE)
16381674
.arg("Result", ScriptActionArgumentType.VARIABLE)
16391675
.arg("Min", ScriptActionArgumentType.NUMBER)
16401676
.arg("Max", ScriptActionArgumentType.NUMBER)
@@ -1649,7 +1685,7 @@ public enum ScriptActionType {
16491685
})),
16501686

16511687
REPEAT_FOREVER(builder -> builder.name("RepeatForever")
1652-
.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."})
1688+
.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.")
16531689
.icon(Items.GOLD_INGOT)
16541690
.category(ScriptActionCategory.MISC)
16551691
.hasChildren(true)
@@ -1658,7 +1694,7 @@ public enum ScriptActionType {
16581694
ctx.scheduleInner(null, context -> context.setLastIfResult(true));
16591695
})),
16601696
ELSE(builder -> builder.name("Else")
1661-
.description(new String[]{"Executes if the last IF condition failed.","And ELSE also works as a valid IF condition for ELSE."})
1697+
.description("Executes if the last IF condition failed.\nAnd ELSE also works as a valid IF condition for ELSE.")
16621698
.icon(Items.END_STONE)
16631699
.category(ScriptActionCategory.MISC)
16641700
.group(ScriptGroup.CONDITION)
@@ -1707,7 +1743,7 @@ public enum ScriptActionType {
17071743
})),
17081744

17091745
REGEX_REPLACE_TEXT(builder -> builder.name("Replace Text using Regex")
1710-
.description(new String[]{"Searches for part of a text", "using a regex and replaces it."})
1746+
.description("Searches for part of a text\nusing a regex and replaces it.")
17111747
.icon(Items.LEAD, true)
17121748
.arg("Result", ScriptActionArgumentType.VARIABLE)
17131749
.arg("Text to change", ScriptActionArgumentType.TEXT)
@@ -1894,17 +1930,10 @@ private ScriptActionType category(ScriptActionCategory category) {
18941930

18951931
private ScriptActionType description(String description) {
18961932
this.description.clear();
1897-
this.description.add(description);
1933+
this.description.addAll(Arrays.asList(description.split("\n", -1)));
18981934
return this;
18991935
}
19001936

1901-
private ScriptActionType description(String[] description) {
1902-
this.description.clear();
1903-
1904-
this.description.addAll(Arrays.asList(description));
1905-
1906-
return this;
1907-
}
19081937
private ScriptActionType group(ScriptGroup group) {
19091938
this.group = group;
19101939
return this;

0 commit comments

Comments
 (0)