Skip to content

Commit

Permalink
fix(tsl): EXECUTE action acting up when PERCENT is present
Browse files Browse the repository at this point in the history
  • Loading branch information
iGoodie committed Jun 9, 2020
1 parent 3abcffa commit 8615e0d
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Expand Up @@ -5,7 +5,7 @@ org.gradle.daemon=false

mod_id=twitchspawn
mod_group=net.programmer.igoodie
mod_version=1.5.2
mod_version=1.5.3

minecraft_version=1.14.4
forge_version=28.0.83
Expand Down
Expand Up @@ -50,14 +50,16 @@ private void parseActions(List<String> words) throws TSLSyntaxError {
if (!containsPercentage(actionRaw))
throw new TSLSyntaxError("Expected chance information on rule#%d", (i + 1));

String percentage = null;

try {
TSLAction action = parseSingleAction(actionRaw.subList(3, actionRaw.size()));
String percentage = actionRaw.get(1);
percentage = actionRaw.get(1);
actions.addElement(action, percentage);

} catch (IllegalStateException e) {
throw new TSLSyntaxError("Expected total of a 100.00%% probability, found -> %.02f%%",
actions.getTotalPercentage() / 100f);
throw new TSLSyntaxError("Cannot add the action with %1$s%% probability, which goes above 100%%. " +
"(%1$.02f%% + %2$s%% > 100%%)", actions.getTotalPercentage() / 100f, percentage);
}

} else {
Expand All @@ -66,9 +68,10 @@ private void parseActions(List<String> words) throws TSLSyntaxError {
}
}

if (chanceMode && actions.getTotalPercentage() != 100_00)
if (chanceMode && actions.getTotalPercentage() != 100_00) {
throw new TSLSyntaxError("Expected total of a 100.00%% probability, found -> %.02f%%",
actions.getTotalPercentage() / 100f);
}
}

private TSLAction parseSingleAction(List<String> actionWords) throws TSLSyntaxError {
Expand Down
Expand Up @@ -36,7 +36,7 @@ public static int parsePercentage(String percentageString) {
String fractionGroup = matcher.group("fraction");

int decimal = Integer.parseInt(decimalGroup);
int fraction = fractionGroup == null ? 0 : Integer.parseInt(fractionGroup);
int fraction = fractionGroup == null ? 0 : Integer.parseInt(String.format("%-2s", fractionGroup).replace(' ', '0'));

return decimal * 100 + fraction;

Expand Down

0 comments on commit 8615e0d

Please sign in to comment.