diff options
author | nopo <noahogno@gmail.com> | 2022-07-07 02:23:53 +1000 |
---|---|---|
committer | nopo <noahogno@gmail.com> | 2022-07-07 02:23:53 +1000 |
commit | 1946d46648c46948839dd77f7a0e43efb99b3901 (patch) | |
tree | b6037ec30411e984dc4e0c71eb59db8fac8b90a8 | |
parent | de1c45f8d3b3e88eda79a5252fe81acc4bd30b7a (diff) | |
download | NotEnoughUpdates-1946d46648c46948839dd77f7a0e43efb99b3901.tar.gz NotEnoughUpdates-1946d46648c46948839dd77f7a0e43efb99b3901.tar.bz2 NotEnoughUpdates-1946d46648c46948839dd77f7a0e43efb99b3901.zip |
add x for multiplication, fixed - not working and quick math solverfeature/signcalc
3 files changed, 19 insertions, 4 deletions
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/commands/misc/CalculatorCommand.java b/src/main/java/io/github/moulberry/notenoughupdates/commands/misc/CalculatorCommand.java index 672183d7..e73e3b32 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/commands/misc/CalculatorCommand.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/commands/misc/CalculatorCommand.java @@ -43,8 +43,13 @@ public class CalculatorCommand extends ClientCommandBase { @Override public void processCommand(ICommandSender sender, String[] args) throws CommandException { - if (args.length == 1 && Objects.equals(args[0], "help")) { - sender.addChatMessage(new ChatComponentText("§e[NEU] §fUse like §b/neucalc 1+2§f. You can also use postfixes like §b/neucalc 14k * 3§f. Turn on Sign Calculator in /neu misc to also support this in sign popups." )); + if ((args.length == 1 && Objects.equals(args[0], "help")) || args.length == 0) { + sender.addChatMessage(new ChatComponentText( + "\n§e[NEU] §5Its a calculator.\n" + + "§eFor Example §b/neucalc 3m*7k§e.\n" + + "§eYou can also use suffixes (k, m, b, t, s)§e.\n" + + "§eThe \"s\" suffix acts as 64.\n" + + "§eTurn on Sign Calculator in /neu misc to also support this in sign popups.\n")); return; } String source = String.join(" ", args); diff --git a/src/main/java/io/github/moulberry/notenoughupdates/listener/ChatListener.java b/src/main/java/io/github/moulberry/notenoughupdates/listener/ChatListener.java index 0aade4b0..457042ee 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/listener/ChatListener.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/listener/ChatListener.java @@ -35,6 +35,7 @@ import net.minecraft.util.ChatComponentText; import net.minecraft.util.ChatComponentTranslation; import net.minecraft.util.EnumChatFormatting; import net.minecraft.util.IChatComponent; +import net.minecraftforge.client.ClientCommandHandler; import net.minecraftforge.client.event.ClientChatReceivedEvent; import net.minecraftforge.fml.common.eventhandler.EventPriority; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; @@ -213,6 +214,13 @@ public class ChatListener { SlayerOverlay.unloadOverlayTimer = System.currentTimeMillis(); } else if (unformatted.startsWith("You consumed a Booster Cookie!")) { CookieWarning.resetNotification(); + } else if (unformatted.startsWith("QUICK MATHS! Solve:")) { + if (Math.random() < 0.2) { + ClientCommandHandler.instance.executeCommand( + Minecraft.getMinecraft().thePlayer, + "/neucalc " + unformatted.substring("QUICK MATHS! Solve: ".length()) + ); + } } if (e.message.getFormattedText().contains( EnumChatFormatting.YELLOW + "Visit the Auction House to collect your item!")) { diff --git a/src/main/java/io/github/moulberry/notenoughupdates/util/Calculator.java b/src/main/java/io/github/moulberry/notenoughupdates/util/Calculator.java index 3b6a71f6..45d7c051 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/util/Calculator.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/util/Calculator.java @@ -46,7 +46,7 @@ public class Calculator { int tokenLength; } - static String binops = "+-*/"; + static String binops = "+-*/x"; static String postops = "mkbts"; static String digits = "0123456789"; @@ -146,6 +146,7 @@ public class Calculator { return 0; case "*": case "/": + case "x": return 1; } throw new CalculatorException("Unknown operator " + token.operatorValue, token.tokenStart, token.tokenLength); @@ -227,6 +228,7 @@ public class Calculator { BigDecimal right = values.pop().setScale(2, RoundingMode.HALF_UP); BigDecimal left = values.pop().setScale(2, RoundingMode.HALF_UP); switch (command.operatorValue.intern()) { + case "x": case "*": values.push(left.multiply(right).setScale(2, RoundingMode.HALF_UP)); break; @@ -241,7 +243,7 @@ public class Calculator { values.push(left.add(right).setScale(2, RoundingMode.HALF_UP)); break; case "-": - values.push(left.min(right).setScale(2, RoundingMode.HALF_UP)); + values.push(left.subtract(right).setScale(2, RoundingMode.HALF_UP)); break; default: throw new CalculatorException( |