Skip to content

Commit b009c32

Browse files
committed
Generate random int & double
1 parent 6a6d947 commit b009c32

File tree

1 file changed

+21
-3
lines changed

1 file changed

+21
-3
lines changed

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

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1611,8 +1611,26 @@ public enum ScriptActionType {
16111611
}
16121612
})),
16131613

1614-
RANDOM_NUMBER(builder -> builder.name("Random Number")
1615-
.description("Generates a random number between two other numbers.")
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 = ctx.value("Min").asNumber();
1623+
int max = ctx.value("Max").asNumber();
1624+
Random random = new Random();
1625+
int result = random.nextInt((int) max + 1 - (int) min) + (int) 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.")
16161634
.icon(Items.HOPPER)
16171635
.category(ScriptActionCategory.NUMBERS)
16181636
.arg("Result", ScriptActionArgumentType.VARIABLE)
@@ -1626,7 +1644,7 @@ public enum ScriptActionType {
16261644
ctx.variable("Result").name(),
16271645
new ScriptNumberValue(result)
16281646
);
1629-
})),
1647+
})),
16301648

16311649
REPEAT_FOREVER(builder -> builder.name("RepeatForever")
16321650
.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.")

0 commit comments

Comments
 (0)