From eb691f4612a95aeb61bd947df169cb34ec69f165 Mon Sep 17 00:00:00 2001 From: HacktheTime Date: Sun, 29 Oct 2023 02:35:33 +0200 Subject: improved numpad codes. --- .../de/hype/bbsentials/common/client/Config.java | 1 + .../hype/bbsentials/fabric/DoubleFieldWidget.java | 31 ++++ .../hype/bbsentials/fabric/IntegerFieldWidget.java | 41 +++++ .../hype/bbsentials/fabric/IntegerTextField.java | 34 ---- .../de/hype/bbsentials/fabric/ModInitialiser.java | 3 +- .../de/hype/bbsentials/fabric/numpad/NumCode.java | 44 ++++- .../fabric/numpad/NumCodeInputField.java | 68 -------- .../fabric/numpad/NumCodeInputFieldWidget.java | 73 ++++++++ .../fabric/numpad/NumPadCodeConfigScreen.java | 156 +++++++++++++++++ .../hype/bbsentials/fabric/numpad/NumPadCodes.java | 55 ++++-- .../fabric/numpad/NumPadCodesConfigScreen.java | 183 ++++++++++++++++++++ .../fabric/numpad/NumPadConfigScreen.java | 187 --------------------- run/saves/temp/DIM-1/data/raids.dat | Bin 90 -> 90 bytes run/saves/temp/DIM1/data/raids_end.dat | Bin 90 -> 90 bytes .../4fa1228c-8dd6-47c4-8fe3-b04b580311b8.json | 6 + run/saves/temp/level.dat_old | Bin 2580 -> 2635 bytes .../4fa1228c-8dd6-47c4-8fe3-b04b580311b8.dat | Bin 1206 -> 1255 bytes .../4fa1228c-8dd6-47c4-8fe3-b04b580311b8.dat_old | Bin 1206 -> 1260 bytes run/saves/temp/region/r.-1.0.mca | Bin 3571712 -> 3571712 bytes run/saves/temp/region/r.0.0.mca | Bin 3694592 -> 3698688 bytes 20 files changed, 571 insertions(+), 311 deletions(-) create mode 100644 fabric/src/main/java/de/hype/bbsentials/fabric/DoubleFieldWidget.java create mode 100644 fabric/src/main/java/de/hype/bbsentials/fabric/IntegerFieldWidget.java delete mode 100644 fabric/src/main/java/de/hype/bbsentials/fabric/IntegerTextField.java delete mode 100644 fabric/src/main/java/de/hype/bbsentials/fabric/numpad/NumCodeInputField.java create mode 100644 fabric/src/main/java/de/hype/bbsentials/fabric/numpad/NumCodeInputFieldWidget.java create mode 100644 fabric/src/main/java/de/hype/bbsentials/fabric/numpad/NumPadCodeConfigScreen.java create mode 100644 fabric/src/main/java/de/hype/bbsentials/fabric/numpad/NumPadCodesConfigScreen.java delete mode 100644 fabric/src/main/java/de/hype/bbsentials/fabric/numpad/NumPadConfigScreen.java diff --git a/common/src/main/java/de/hype/bbsentials/common/client/Config.java b/common/src/main/java/de/hype/bbsentials/common/client/Config.java index 62e5c16..d780c45 100644 --- a/common/src/main/java/de/hype/bbsentials/common/client/Config.java +++ b/common/src/main/java/de/hype/bbsentials/common/client/Config.java @@ -33,6 +33,7 @@ public class Config implements Serializable { private transient String username; // Set via load / default you may change these + public boolean useNumCodes = true; public boolean overrideBingoTime = false; public boolean connectToBeta = false; public boolean useMojangAuth = false; diff --git a/fabric/src/main/java/de/hype/bbsentials/fabric/DoubleFieldWidget.java b/fabric/src/main/java/de/hype/bbsentials/fabric/DoubleFieldWidget.java new file mode 100644 index 0000000..968cb92 --- /dev/null +++ b/fabric/src/main/java/de/hype/bbsentials/fabric/DoubleFieldWidget.java @@ -0,0 +1,31 @@ +package de.hype.bbsentials.fabric; + +import net.minecraft.client.font.TextRenderer; +import net.minecraft.client.gui.widget.TextFieldWidget; +import net.minecraft.text.Text; +import org.jetbrains.annotations.Nullable; + +public class DoubleFieldWidget extends IntegerFieldWidget { + public DoubleFieldWidget(TextRenderer textRenderer, int width, int height, Text text) { + super(textRenderer, width, height, text); + } + + public DoubleFieldWidget(TextRenderer textRenderer, int x, int y, int width, int height, Text text) { + super(textRenderer, x, y, width, height, text); + } + + public DoubleFieldWidget(TextRenderer textRenderer, int x, int y, int width, int height, @Nullable TextFieldWidget copyFrom, Text text) { + super(textRenderer, x, y, width, height, copyFrom, text); + } + + @Override + public boolean charTyped(char chr, int modifiers) { + if (chr == '.' || chr == ',') return super.typeChar('.', modifiers); + return super.charTyped(chr, modifiers); + } + + @Override + public String getText() { + return super.getText().replaceAll(",", "."); + } +} diff --git a/fabric/src/main/java/de/hype/bbsentials/fabric/IntegerFieldWidget.java b/fabric/src/main/java/de/hype/bbsentials/fabric/IntegerFieldWidget.java new file mode 100644 index 0000000..fbbd649 --- /dev/null +++ b/fabric/src/main/java/de/hype/bbsentials/fabric/IntegerFieldWidget.java @@ -0,0 +1,41 @@ +package de.hype.bbsentials.fabric; + +import net.minecraft.client.font.TextRenderer; +import net.minecraft.client.gui.widget.TextFieldWidget; +import net.minecraft.text.Text; +import org.jetbrains.annotations.Nullable; + +public class IntegerFieldWidget extends TextFieldWidget { + public IntegerFieldWidget(TextRenderer textRenderer, int width, int height, Text text) { + super(textRenderer, width, height, text); + } + + public IntegerFieldWidget(TextRenderer textRenderer, int x, int y, int width, int height, Text text) { + super(textRenderer, x, y, width, height, text); + } + + public IntegerFieldWidget(TextRenderer textRenderer, int x, int y, int width, int height, @Nullable TextFieldWidget copyFrom, Text text) { + super(textRenderer, x, y, width, height, copyFrom, text); + } + + @Override + public boolean charTyped(char chr, int modifiers) { + // Allow removal (backspace and delete) and specific key combinations (Ctrl+A) + if (chr == 8 || chr == 127 || (modifiers & 1) == 1) { + return super.charTyped(chr, modifiers); + } + // Allow digits (0-9) and the minus sign for negative numbers + else if ((chr >= '0' && chr <= '9') || chr == '-') { + return super.charTyped(chr, modifiers); + } + return false; // Block other characters + } + + /** + * Use this to bypass the check from the own charTyped. Passes this to the super Class of this. + */ + public boolean typeChar(char chr, int modifiers) { + return charTyped(chr, modifiers); + } + +} diff --git a/fabric/src/main/java/de/hype/bbsentials/fabric/IntegerTextField.java b/fabric/src/main/java/de/hype/bbsentials/fabric/IntegerTextField.java deleted file mode 100644 index 9204900..0000000 --- a/fabric/src/main/java/de/hype/bbsentials/fabric/IntegerTextField.java +++ /dev/null @@ -1,34 +0,0 @@ -package de.hype.bbsentials.fabric; - -import net.minecraft.client.font.TextRenderer; -import net.minecraft.client.gui.widget.TextFieldWidget; -import net.minecraft.text.Text; -import org.jetbrains.annotations.Nullable; - -public class IntegerTextField extends TextFieldWidget { - public IntegerTextField(TextRenderer textRenderer, int width, int height, Text text) { - super(textRenderer, width, height, text); - } - - public IntegerTextField(TextRenderer textRenderer, int x, int y, int width, int height, Text text) { - super(textRenderer, x, y, width, height, text); - } - - public IntegerTextField(TextRenderer textRenderer, int x, int y, int width, int height, @Nullable TextFieldWidget copyFrom, Text text) { - super(textRenderer, x, y, width, height, copyFrom, text); - } - - @Override - public boolean charTyped(char chr, int modifiers) { - // Allow removal (backspace and delete) and specific key combinations (Ctrl+A) - if (chr == 8 || chr == 127 || (modifiers & 1) == 1) { - return super.charTyped(chr, modifiers); - } - // Allow digits (0-9) and the minus sign for negative numbers - else if ((chr >= '0' && chr <= '9') || chr == '-') { - return super.charTyped(chr, modifiers); - } - return false; // Block other characters - } - -} diff --git a/fabric/src/main/java/de/hype/bbsentials/fabric/ModInitialiser.java b/fabric/src/main/java/de/hype/bbsentials/fabric/ModInitialiser.java index 8a81934..c94202b 100644 --- a/fabric/src/main/java/de/hype/bbsentials/fabric/ModInitialiser.java +++ b/fabric/src/main/java/de/hype/bbsentials/fabric/ModInitialiser.java @@ -192,7 +192,6 @@ public class ModInitialiser implements ClientModInitializer { }); KeyBinding promptKeyBind = new KeyBinding("Chat Prompt Yes / Open Menu", InputUtil.Type.KEYSYM, GLFW.GLFW_KEY_R, "BBsentials"); - KeyBindingHelper.registerKeyBinding(promptKeyBind); ClientTickEvents.END_CLIENT_TICK.register(client -> { if (promptKeyBind.wasPressed()) { if (config.getLastChatPromptAnswer() != null) { @@ -216,7 +215,7 @@ public class ModInitialiser implements ClientModInitializer { }); // for (int i = 1; i <= 9; i++) { // KeyBinding ecPageKeyBind = new KeyBinding("Ender Chest Page " + i, InputUtil.Type.KEYSYM, GLFW.GLFW_KEY_KP_1 + (i - 1), "BBsentials"); -// KeyBindingHelper.registerKeyBinding(ecPageKeyBind); +// ecPageKeyBind); // int pageNum = i; // Capture the page number for lambda // ClientTickEvents.END_CLIENT_TICK.register(client -> { // if (ecPageKeyBind.wasPressed()) { diff --git a/fabric/src/main/java/de/hype/bbsentials/fabric/numpad/NumCode.java b/fabric/src/main/java/de/hype/bbsentials/fabric/numpad/NumCode.java index 1e44654..e249304 100644 --- a/fabric/src/main/java/de/hype/bbsentials/fabric/numpad/NumCode.java +++ b/fabric/src/main/java/de/hype/bbsentials/fabric/numpad/NumCode.java @@ -4,8 +4,12 @@ import de.hype.bbsentials.common.api.Formatting; import de.hype.bbsentials.common.chat.Chat; import de.hype.bbsentials.common.client.BBsentials; +import java.util.ArrayList; +import java.util.List; + public class NumCode { - public String command; + public List commands; + public List commandDelay; public String code; public boolean codeIsTransient; public Formatting formatting; @@ -13,15 +17,30 @@ public class NumCode { public transient Runnable toPerform; public NumCode(String code, String command) { - this.command = command; + this.commands = new ArrayList<>(List.of(command)); + this.commandDelay = new ArrayList<>(List.of(1.1)); + this.code = code; + this.codeIsTransient = false; + this.formatting = Formatting.DARK_GREEN; + requiredPermission = ""; + } + + public NumCode(String code, List command, List commandDelay) { + this.commands = new ArrayList<>(command); + this.commandDelay = new ArrayList<>(commandDelay); this.code = code; this.codeIsTransient = false; this.formatting = Formatting.DARK_GREEN; requiredPermission = ""; } + public int pressCount() { + int count = commands.size() - (code.length()); + if (count < 0) count = 0; + return count; + } public NumCode(String code, Formatting format, String requiredRole, Runnable toPerform) { - this.command = ""; + this.commands = new ArrayList<>(); this.code = code; this.formatting = format; requiredPermission = requiredRole; @@ -31,11 +50,13 @@ public class NumCode { public void execute() { if (!BBsentials.config.hasBBRoles(requiredPermission)) { - Chat.sendPrivateMessageToSelfError("You don't have the required permissions to run '" + code + "' !"); + Chat.sendPrivateMessageToSelfError("You don't have the required permissions to run '" + code + "' ! (Required: '" + requiredPermission + "')"); return; } - if (!command.isEmpty()) { - BBsentials.config.sender.addImmediateSendTask(command); + if (!commands.isEmpty()) { + for (int i = 0; i < commands.size(); i++) { + BBsentials.config.sender.addHiddenSendTask(commands.get(i), commandDelay.get(i)); + } } else { if (toPerform == null) { @@ -52,6 +73,17 @@ public class NumCode { Chat.sendPrivateMessageToSelfInfo("'" + code + "' executed."); } + @Override + public String toString() { + String toReturn = code; + if (commands != null) { + if (commands.isEmpty()) { + toReturn += ": " + String.join(", ", commands); + } + } + return toReturn; + } + @Override public boolean equals(Object obj) { if (obj.getClass().equals(this.getClass())) { diff --git a/fabric/src/main/java/de/hype/bbsentials/fabric/numpad/NumCodeInputField.java b/fabric/src/main/java/de/hype/bbsentials/fabric/numpad/NumCodeInputField.java deleted file mode 100644 index 2baf9b4..0000000 --- a/fabric/src/main/java/de/hype/bbsentials/fabric/numpad/NumCodeInputField.java +++ /dev/null @@ -1,68 +0,0 @@ -package de.hype.bbsentials.fabric.numpad; - -import de.hype.bbsentials.common.api.Formatting; -import de.hype.bbsentials.common.client.BBsentials; -import de.hype.bbsentials.fabric.IntegerTextField; -import net.minecraft.client.font.TextRenderer; -import net.minecraft.client.gui.tooltip.Tooltip; -import net.minecraft.client.gui.widget.TextFieldWidget; -import net.minecraft.text.Text; -import org.jetbrains.annotations.Nullable; - -public class NumCodeInputField extends IntegerTextField { - public final NumPadConfigScreen codeConfigScreen; - - public NumCodeInputField(TextRenderer textRenderer, int width, int height, Text text, NumPadConfigScreen codeConfigScreen) { - super(textRenderer, width, height, text); - this.codeConfigScreen = codeConfigScreen; - setChangedListener(this::onChangeEvent); - } - - public NumCodeInputField(TextRenderer textRenderer, int x, int y, int width, int height, Text text, NumPadConfigScreen codeManager) { - super(textRenderer, x, y, width, height, text); - this.codeConfigScreen = codeManager; - setChangedListener(this::onChangeEvent); - } - - public NumCodeInputField(TextRenderer textRenderer, int x, int y, int width, int height, @Nullable TextFieldWidget copyFrom, Text text, NumPadConfigScreen codeManager) { - super(textRenderer, x, y, width, height, copyFrom, text); - this.codeConfigScreen = codeManager; - setChangedListener(this::onChangeEvent); - } - - @Override - public boolean charTyped(char chr, int modifiers) { - return super.charTyped(chr, modifiers); - } - - private boolean codeIsFree(String input) { - int usedAlready = 0; - for (int i1 = 0; i1 < codeConfigScreen.codes.numCodes.size(); i1++) { - if (codeConfigScreen.codes.numCodes.get(i1).code.equals(input)) { - usedAlready++; - if (usedAlready > 1) { - return false; - } - } - } - return true; - } - - public boolean forbiddenCode(String input) { - if (BBsentials.config.hasBBRoles("dev")) return false; - if (input.startsWith(String.valueOf(0))) { - return true; - } - return false; - } - - public void onChangeEvent(String newText) { - codeConfigScreen.updateCodes(); - if (!codeIsFree(newText) || forbiddenCode(newText)) { - setTooltip(Tooltip.of(Text.of(Formatting.RED + "You can not use this code.§r\nWarning: This is only updated once clicking into the field!"))); - } - else { - setTooltip(Tooltip.of(Text.of(""))); - } - } -} diff --git a/fabric/src/main/java/de/hype/bbsentials/fabric/numpad/NumCodeInputFieldWidget.java b/fabric/src/main/java/de/hype/bbsentials/fabric/numpad/NumCodeInputFieldWidget.java new file mode 100644 index 0000000..34e6d21 --- /dev/null +++ b/fabric/src/main/java/de/hype/bbsentials/fabric/numpad/NumCodeInputFieldWidget.java @@ -0,0 +1,73 @@ +package de.hype.bbsentials.fabric.numpad; + +import de.hype.bbsentials.common.api.Formatting; +import de.hype.bbsentials.common.client.BBsentials; +import de.hype.bbsentials.fabric.IntegerFieldWidget; +import net.minecraft.client.font.TextRenderer; +import net.minecraft.client.gui.tooltip.Tooltip; +import net.minecraft.client.gui.widget.TextFieldWidget; +import net.minecraft.text.Text; +import org.jetbrains.annotations.Nullable; + +public class NumCodeInputFieldWidget extends IntegerFieldWidget { + public final NumPadCodeConfigScreen codeConfigScreen; + int index; + + public NumCodeInputFieldWidget(TextRenderer textRenderer, int width, int height, Text text, NumPadCodeConfigScreen codeConfigScreen, int index) { + super(textRenderer, width, height, text); + this.index = index; + this.codeConfigScreen = codeConfigScreen; + setChangedListener(this::onChangeEvent); + } + + public NumCodeInputFieldWidget(TextRenderer textRenderer, int x, int y, int width, int height, Text text, NumPadCodeConfigScreen codeManager) { + super(textRenderer, x, y, width, height, text); + this.index = index; + this.codeConfigScreen = codeManager; + setChangedListener(this::onChangeEvent); + } + + public NumCodeInputFieldWidget(TextRenderer textRenderer, int x, int y, int width, int height, @Nullable TextFieldWidget copyFrom, Text text, NumPadCodeConfigScreen codeManager) { + super(textRenderer, x, y, width, height, copyFrom, text); + this.index = index; + this.codeConfigScreen = codeManager; + setChangedListener(this::onChangeEvent); + } + + @Override + public boolean charTyped(char chr, int modifiers) { + return super.charTyped(chr, modifiers); + } + + private boolean codeIsFree(String input) { + for (int i1 = 0; i1 < codeConfigScreen.codeManager.numCodes.size(); i1++) { + if (codeConfigScreen.codeManager.numCodes.get(i1).code.equals(input)) { + if (i1 != index) return false; + } + } + return true; + } + + public boolean forbiddenCode(String input) { + if (BBsentials.config.hasBBRoles("dev")) return false; + if (input.startsWith(String.valueOf(0))) { + return true; + } + return false; + } + + public void onChangeEvent(String newText) { + if (!codeIsFree(newText) || forbiddenCode(newText)) { + setTooltip(Tooltip.of(Text.of(Formatting.RED + "You can not use this code.§r\nWarning: This is only updated once clicking into the field!"))); + if (codeConfigScreen.okButton != null) { + codeConfigScreen.okButton.active = false; + } + } + else { + if (codeConfigScreen.okButton != null) { + codeConfigScreen.okButton.active = true; + } + setTooltip(Tooltip.of(Text.of(""))); + } + } +} diff --git a/fabric/src/main/java/de/hype/bbsentials/fabric/numpad/NumPadCodeConfigScreen.java b/fabric/src/main/java/de/hype/bbsentials/fabric/numpad/NumPadCodeConfigScreen.java new file mode 100644 index 0000000..bf9c25f --- /dev/null +++ b/fabric/src/main/java/de/hype/bbsentials/fabric/numpad/NumPadCodeConfigScreen.java @@ -0,0 +1,156 @@ +package de.hype.bbsentials.fabric.numpad; + +import de.hype.bbsentials.common.client.BBsentials; +import de.hype.bbsentials.fabric.DoubleFieldWidget; +import net.minecraft.client.MinecraftClient; +import net.minecraft.client.gui.screen.NoticeScreen; +import net.minecraft.client.gui.screen.Screen; +import net.minecraft.client.gui.tooltip.Tooltip; +import net.minecraft.client.gui.widget.ButtonWidget; +import net.minecraft.client.gui.widget.TextFieldWidget; +import net.minecraft.text.Text; + +import java.util.ArrayList; +import java.util.List; + + +public class NumPadCodeConfigScreen extends Screen { + NumCode code; + NumPadCodes codeManager; + int codeIndex; + private NumCodeInputFieldWidget codeTextField; + private ButtonWidget deleteButton; + ButtonWidget okButton; + private ButtonWidget addButton; + private List commandFields = new ArrayList<>(); + private List delayFields = new ArrayList<>(); + private NumPadCodesConfigScreen parent; + + + protected NumPadCodeConfigScreen(NumPadCodes codeManager, int codeIndex, NumPadCodesConfigScreen parent) { + super(Text.of("NumPadCodesConfigScreen")); + this.code = codeManager.numCodes.get(codeIndex); + this.codeIndex = codeIndex; + this.parent = parent; + this.codeManager = codeManager; + } + + @Override + protected void init() { + if (okButton == null) { + codeTextField = new NumCodeInputFieldWidget(textRenderer, width / 2, 20, Text.of(code.code), this, codeIndex); + codeTextField.setText(code.code); + addButton = new ButtonWidget.Builder(Text.of("+"), button -> { + addNewCommand(); + }).build(); + deleteButton = new ButtonWidget.Builder(Text.of("-"), button -> { + codeManager.numCodes.remove(codeIndex); + close(); + }).build(); + okButton = new ButtonWidget.Builder(Text.of("Done"), button -> saveAndExit()).build(); + for (int i = 0; i < code.commands.size(); i++) { + addCommand(code.commands.get(i), code.commandDelay.get(i)); + } + } + okButton.setY(height - okButton.getHeight()); + okButton.setX((width / 3) * 2 - okButton.getWidth() / 2); + addButton.setMessage(Text.of(("add command"))); + addButton.setWidth(width / 2); + addButton.setPosition((width / 2) - addButton.getWidth() / 2, 80); + deleteButton.setX((width / 3) - okButton.getWidth() / 2); + deleteButton.setY(height - deleteButton.getHeight()); + updateFields(); + } + + private void addCommand(String command, double delay) { + TextFieldWidget commandField = new TextFieldWidget(textRenderer, width / 3, 20, Text.of("")); + commandField.setText(command); + commandFields.add(commandField); + DoubleFieldWidget delayField = new DoubleFieldWidget(textRenderer, 40, 20, Text.of("")); + delayField.setTooltip(Tooltip.of(Text.of("Delay in seconds. Supports '.' (Double type)"))); + delayField.setText(String.valueOf(delay)); + delayFields.add(delayField); + } + + private void addNewCommand() { + addCommand("", 1); + code.commands.add(""); + code.commandDelay.add(1.0); + updateFields(); + } + + private void removeCommand(int index) { + code.commands.remove(index); + code.commandDelay.remove(index); + remove(commandFields.remove(index)); + remove(delayFields.remove(index)); + updateFields(); + } + + private void updateFields() { + clearChildren(); + int leftX = width / 9; // Start position for codeTextFields + int rightX = leftX * 2 + width / 2; // Start position for commandTextFields + if (addButton != null) { + if (code.commands.size() >= 10) addButton.active = false; + else addButton.active = true; + } + codeTextField.setX(width / 4); + codeTextField.setY(60); + codeTextField.setWidth(width / 2); + for (int i = 0; i < code.commands.size(); i++) { + int adaptedHeight = 120 + i * 30; + int finalI = i; + addDrawableChild(new ButtonWidget.Builder(Text.of("-"), (button) -> removeCommand(finalI)).position(rightX + width / 6, adaptedHeight).width(width / 12).build()); + commandFields.get(i).setHeight(20); + commandFields.get(i).setWidth(width / 2); + commandFields.get(i).setX(leftX); + commandFields.get(i).setY(adaptedHeight); + delayFields.get(i).setHeight(20); + delayFields.get(i).setWidth(40); + delayFields.get(i).setX(rightX); + delayFields.get(i).setY(adaptedHeight); + addDrawableChild(commandFields.get(i)); + addDrawableChild(delayFields.get(i)); + } + addDrawableChild(codeTextField); + addDrawableChild(addButton); + addDrawableChild(deleteButton); + addDrawableChild(okButton); + } + + public void saveAndExit() { + if (codeTextField.forbiddenCode(codeTextField.getText())) { + new NoticeScreen(() -> MinecraftClient.getInstance().setScreen(this), Text.of(""), Text.of("§cInvalid Code / already used!")); + return; + } + if (codeTextField.forbiddenCode(codeTextField.getText())) { + new NoticeScreen(() -> MinecraftClient.getInstance().setScreen(this), Text.of(""), Text.of("§cNo Command specified")); + return; + } + code.commands = new ArrayList<>(commandFields.stream().map(TextFieldWidget::getText).toList()); + code.commandDelay = new ArrayList<>(commandFields.stream().map((field) -> { + String text = field.getText(); + if (text.isEmpty()) return 1.0; + return Double.parseDouble(text); + } + ).toList()); + codeManager.saveNumCodesToFile(); + setScreen(parent); + } + + @Override + public boolean shouldCloseOnEsc() { + return BBsentials.config.devMode; + } + + @Override + public void close() { + super.close(); + } + + public void setScreen(Screen screen) { + MinecraftClient client = MinecraftClient.getInstance(); + client.execute(() -> client.setScreen(screen)); + } +} diff --git a/fabric/src/main/java/de/hype/bbsentials/fabric/numpad/NumPadCodes.java b/fabric/src/main/java/de/hype/bbsentials/fabric/numpad/NumPadCodes.java index 441c563..897285a 100644 --- a/fabric/src/main/java/de/hype/bbsentials/fabric/numpad/NumPadCodes.java +++ b/fabric/src/main/java/de/hype/bbsentials/fabric/numpad/NumPadCodes.java @@ -5,7 +5,6 @@ import de.hype.bbsentials.common.api.Formatting; import de.hype.bbsentials.common.chat.Message; import de.hype.bbsentials.common.client.BBsentials; import de.hype.bbsentials.common.mclibraries.EnvironmentCore; -import net.fabricmc.fabric.api.client.keybinding.v1.KeyBindingHelper; import net.minecraft.client.MinecraftClient; import net.minecraft.client.option.KeyBinding; import org.lwjgl.glfw.GLFW; @@ -20,6 +19,7 @@ import static de.hype.bbsentials.common.packets.PacketUtils.gson; public class NumPadCodes { private static final int NUMPAD_KEY_COUNT = 10; public List numCodes = new ArrayList<>(); + int enterPresses = 0; private KeyBinding[] numpadKeybindings = new KeyBinding[NUMPAD_KEY_COUNT]; private String enteredCode = ""; private boolean[] keyReleased = new boolean[NUMPAD_KEY_COUNT + 3]; @@ -39,15 +39,15 @@ public class NumPadCodes { } for (int i = 0; i < NUMPAD_KEY_COUNT; i++) { int keyCode = GLFW.GLFW_KEY_KP_0 + i; - numpadKeybindings[i] = KeyBindingHelper.registerKeyBinding(new KeyBinding( + numpadKeybindings[i] = new KeyBinding( String.valueOf(i), keyCode, "bbsentials.numpad" - )); + ); } - KeyBinding enterKey = KeyBindingHelper.registerKeyBinding(new KeyBinding("Enter", GLFW.GLFW_KEY_KP_ENTER, "bbsentials.numpad")); - KeyBinding clear = KeyBindingHelper.registerKeyBinding(new KeyBinding("Clear", GLFW.GLFW_KEY_KP_ADD, "bbsentials.numpad")); - KeyBinding remove = KeyBindingHelper.registerKeyBinding(new KeyBinding("Remove", GLFW.GLFW_KEY_KP_DECIMAL, "bbsentials.numpad")); + KeyBinding enterKey = new KeyBinding("Enter", GLFW.GLFW_KEY_KP_ENTER, "bbsentials.numpad"); + KeyBinding clear = new KeyBinding("Clear", GLFW.GLFW_KEY_KP_ADD, "bbsentials.numpad"); + KeyBinding remove = new KeyBinding("Remove", GLFW.GLFW_KEY_KP_DECIMAL, "bbsentials.numpad"); Thread t = new Thread(() -> { while (true) { for (int i = 0; i < numpadKeybindings.length; i++) { @@ -63,14 +63,13 @@ public class NumPadCodes { } if (enterKey.isPressed() && keyReleased[10]) { executeCode(); - enteredCode = ""; keyReleased[10] = false; } else if (!enterKey.isPressed()) { keyReleased[10] = true; } if (clear.isPressed() && keyReleased[11]) { - enteredCode = ""; + resetCode(); keyReleased[11] = false; } else if (!clear.isPressed()) { @@ -87,12 +86,19 @@ public class NumPadCodes { } // Reset key cooldowns after 5 seconds if (System.currentTimeMillis() - lastKeyPressTime >= 5000) { - enteredCode = ""; + resetCode(); } if (!enteredCode.isEmpty()) { - BBsentials.config.overwriteActionBar = getColorCode() + enteredCode; + String actionbarText = getColorCode() + enteredCode; + if (enterPresses > 0) { + int count = getMorePressesNeeded(); + if (count != 0) { + actionbarText = Formatting.GOLD + enteredCode + " (" + count + ")"; + } + } + BBsentials.config.overwriteActionBar = actionbarText; overidedActionBar = true; - EnvironmentCore.chat.showActionBar(Message.of(getColorCode() + enteredCode)); + EnvironmentCore.chat.showActionBar(Message.of(actionbarText)); } else if (overidedActionBar) { BBsentials.config.overwriteActionBar = ""; @@ -111,7 +117,7 @@ public class NumPadCodes { public void addDefaultCodes(boolean all) { List defaultCodes = new ArrayList(); - defaultCodes.add((new NumCode("042", Formatting.DARK_BLUE, "dev", () -> MinecraftClient.getInstance().execute(() -> MinecraftClient.getInstance().setScreen(new NumPadConfigScreen(this)))))); + defaultCodes.add((new NumCode("042", Formatting.DARK_BLUE, "", () -> MinecraftClient.getInstance().execute(() -> MinecraftClient.getInstance().setScreen(new NumPadCodesConfigScreen(this)))))); defaultCodes.add((new NumCode("11", "/l"))); if (all) { numCodes.addAll(defaultCodes); @@ -128,7 +134,6 @@ public class NumPadCodes { int index = getCodeIndex(); boolean exists = codeExists(); boolean devCode = enteredCode.startsWith("0"); - if (devCode) { if (index != -1 && !exists) { return Formatting.DARK_BLUE.toString(); @@ -157,8 +162,24 @@ public class NumPadCodes { public void executeCode() { int index = getCodeIndex(); if (index != -1) { - numCodes.get(index).execute(); + if (getMorePressesNeeded() <= 1) { + numCodes.get(index).execute(); + resetCode(); + } + else { + enterPresses++; + } + } + } + + public int getMorePressesNeeded() { + int index = getCodeIndex(); + if (index == -1) return 0; + int extraInputNeeded = numCodes.get(index).pressCount() - enterPresses; + if (extraInputNeeded < 0) { + return 0; } + return extraInputNeeded; } public int getCodeIndex() { @@ -168,6 +189,7 @@ public class NumPadCodes { return -1; } + /** * @return returns true if there is at least 1 code to go on. otherwise false */ @@ -216,4 +238,9 @@ public class NumPadCodes { } } } + + void resetCode() { + enteredCode = ""; + enterPresses = 0; + } } diff --git a/fabric/src/main/java/de/hype/bbsentials/fabric/numpad/NumPadCodesConfigScreen.java b/fabric/src/main/java/de/hype/bbsentials/fabric/numpad/NumPadCodesConfigScreen.java new file mode 100644 index 0000000..166958b --- /dev/null +++ b/fabric/src/main/java/de/hype/bbsentials/fabric/numpad/NumPadCodesConfigScreen.java @@ -0,0 +1,183 @@ +package de.hype.bbsentials.fabric.numpad; + +import de.hype.bbsentials.common.chat.Chat; +import de.hype.bbsentials.common.client.BBsentials; +import net.minecraft.client.MinecraftClient; +import net.minecraft.client.gui.screen.Screen; +import net.minecraft.client.gui.widget.ButtonWidget; +import net.minecraft.text.Text; + +import java.util.ArrayList; +import java.util.List; + +public class NumPadCodesConfigScreen extends Screen { + public List hiddenNumCodes = new ArrayList<>(); + + ButtonWidget addButton; + ButtonWidget okButton; + + ButtonWidget firstPage; + ButtonWidget lastPage; + ButtonWidget nextPage; + ButtonWidget previosPage; + NumPadCodes codes; + int page = 0; + + protected NumPadCodesConfigScreen(NumPadCodes codes) { + super(Text.of("NumPadCodesConfigScreen")); + this.codes = codes; + } + + @Override + protected void init() { + if (okButton == null) { + for (NumCode numCode : codes.numCodes) { + if (numCode.codeIsTransient) { + hiddenNumCodes.add(numCode); + } + } + okButton = new ButtonWidget.Builder(Text.of("Done"), button -> done()).build(); + addButton = new ButtonWidget.Builder(Text.of("+"), button -> { + addNewRow(); + }).build(); + firstPage = new ButtonWidget.Builder(Text.of("First"), button -> setPage(0)).build(); + lastPage = new ButtonWidget.Builder(Text.of("Last"), button -> setPage(-2)).build(); + nextPage = new ButtonWidget.Builder(Text.of("Next"), button -> setPage(page + 1)).build(); + previosPage = new ButtonWidget.Builder(Text.of("Previous"), button -> setPage(page - 1)).build(); + } + okButton.setY(height - okButton.getHeight()); + okButton.setX((width / 2) - okButton.getWidth() / 2); + addButton.setMessage(Text.of(("+"))); + addButton.setWidth(width / 2); + addButton.setPosition((width / 2) - addButton.getWidth() / 2, 20); + nextPage.setWidth(width / 12); + previosPage.setWidth(width / 12); + lastPage.setWidth(width / 12); + firstPage.setWidth(width / 12); + nextPage.setX(width / 12); + previosPage.setX(width / 12); + lastPage.setX(width / 12); + firstPage.setX(width / 12); + firstPage.setPosition(0, 20); + lastPage.setPosition(0, height - 10 - lastPage.getHeight()); + nextPage.setPosition(0, firstPage.getHeight() + firstPage.getY() + 10); + previosPage.setPosition(0, lastPage.getY() - lastPage.getHeight() - 10); + updateFields(); + + } + + public void setPage(int newPage) { + int max = codes.numCodes.size() / ((height - 100) / 30); + if (newPage < 0) newPage = 0; + if (newPage > max) newPage = max; + page = newPage; + updateFields(); + } + + private void addNewRow() { + NumCode newCode = new NumCode("", ""); + codes.numCodes.add(newCode); + updateFields(); + } + + void removeRow(int index) { + try { + codes.numCodes.remove(index); + } catch (Exception e) { + Chat.sendPrivateMessageToSelfError(e.getMessage()); + } + updateFields(); + } + + private void updateFields() { + int codeX = width / 2 - (width / 6); // Start position for commandTextFields + + clearChildren(); + int min = getMinimumEntry(); + int max = getHighestEntry(); + int skipped = 0; + for (int i = min; i <= max; i++) { + if (codes.numCodes.get(i).codeIsTransient) { + skipped++; + continue; + } + int hight = 60 + (i - getMinimumEntry() - skipped) * 30; + int finalI = i; + ButtonWidget removeButton = ButtonWidget.builder(Text.of("-"), button -> removeRow(finalI)).build(); + + // Set the positions for commandTextFields + int finalI1 = i; + Text buttonText = Text.of(codes.numCodes.get(i).toString()); + ButtonWidget codeButton = ButtonWidget.builder(buttonText, (buttonWidget) -> { + setScreen(new NumPadCodeConfigScreen(codes, finalI1, this)); + }).build(); + codeButton.setX(codeX); + codeButton.setY(hight); + codeButton.setWidth(width / 3); + + // Set positions for removeButtonFields + removeButton.setWidth(width / 12); + removeButton.setX(width - width / 6); // Place the remove button to the right + removeButton.setY(hight); + addDrawableChild(codeButton); + addDrawableChild(removeButton); + } + addDrawableChild(nextPage); + addDrawableChild(previosPage); + addDrawableChild(lastPage); + addDrawableChild(firstPage); + addDrawableChild(addButton); + addDrawableChild(okButton); + } + + public int getMinimumEntry() { + int toDisplay = 0; + int index = -1; + while ((toDisplay <= entriesPerPage() * page) && index + 1 < codes.numCodes.size()) { + index++; + if (!codes.numCodes.get(index).codeIsTransient) { + toDisplay++; + } + } + return index; + } + + public int entriesPerPage() { + return Math.min((height - 100) / 30, codes.numCodes.size()); + } + + public int getHighestEntry() { + int index = getMinimumEntry() - 1; + int toDisplay = 0; + while ((toDisplay <= entriesPerPage()) && index < codes.numCodes.size() - 1) { + index++; + if (!codes.numCodes.get(index).codeIsTransient) { + toDisplay++; + } + } + return index; + } + + public void done() { + codes.saveNumCodesToFile(); + close(); + } + + @Override + public boolean shouldCloseOnEsc() { + return BBsentials.config.devMode; + } + + @Override + public void close() { + codes.saveNumCodesToFile(); + super.close(); + } + + public void setScreen(Screen screen) { + MinecraftClient client = MinecraftClient.getInstance(); + client.execute(() -> client.setScreen(screen)); + } + +} + diff --git a/fabric/src/main/java/de/hype/bbsentials/fabric/numpad/NumPadConfigScreen.java b/fabric/src/main/java/de/hype/bbsentials/fabric/numpad/NumPadConfigScreen.java deleted file mode 100644 index eb70e5b..0000000 --- a/fabric/src/main/java/de/hype/bbsentials/fabric/numpad/NumPadConfigScreen.java +++ /dev/null @@ -1,187 +0,0 @@ -package de.hype.bbsentials.fabric.numpad; - -import net.minecraft.client.gui.screen.Screen; -import net.minecraft.client.gui.widget.ButtonWidget; -import net.minecraft.client.gui.widget.TextFieldWidget; -import net.minecraft.text.Text; - -import java.util.ArrayList; -import java.util.List; - -public class NumPadConfigScreen extends Screen { - public List hiddenNumCodes = new ArrayList<>(); - ButtonWidget addButton; - ButtonWidget okButton; - - ButtonWidget firstPage; - ButtonWidget lastPage; - ButtonWidget nextPage; - ButtonWidget previosPage; - NumPadCodes codes; - int page = 0; - private List codeTextFields; - private List commandTextFields; - private List removeButtonFields; - - protected NumPadConfigScreen(NumPadCodes codes) { - super(Text.of("NumPadConfigScreen")); - codeTextFields = new ArrayList<>(); - commandTextFields = new ArrayList<>(); - removeButtonFields = new ArrayList<>(); - this.codes = codes; - } - - @Override - protected void init() { - if (okButton == null) { - for (NumCode numCode : codes.numCodes) { - if (!numCode.codeIsTransient) { - addRow(numCode.code, numCode.command); - okButton = new ButtonWidget.Builder(Text.of("Done"), button -> done()).build(); - addButton = new ButtonWidget.Builder(Text.of("+"), button -> { - addNewRow(); - }).build(); - firstPage = new ButtonWidget.Builder(Text.of("First"), button -> setPage(0)).build(); - lastPage = new ButtonWidget.Builder(Text.of("Last"), button -> setPage(-2)).build(); - nextPage = new ButtonWidget.Builder(Text.of("Next"), button -> setPage(page + 1)).build(); - previosPage = new ButtonWidget.Builder(Text.of("Previous"), button -> setPage(page - 1)).build(); - } - else { - hiddenNumCodes.add(numCode); - } - } - } - okButton.setY(height - okButton.getHeight()); - okButton.setX((width / 2) - okButton.getWidth() / 2); - addButton.setMessage(Text.of(("+"))); - addButton.setWidth(width / 2); - addButton.setPosition((width / 2) - addButton.getWidth() / 2, 20); - codeTextFields.forEach((this::addDrawableChild)); - commandTextFields.forEach((this::addDrawableChild)); - removeButtonFields.forEach((this::addDrawableChild)); - updateFields(); - - } - - public void setPage(int newPage) { - int max = commandTextFields.size() / ((height - 100) / 30); - if (newPage < 0) newPage = 0; - if (newPage > max) newPage = max; - page = newPage; - updateFields(); - } - - private void addRow(String code, String command) { - NumCodeInputField textField2 = new NumCodeInputField(textRenderer, width / 3, 20, Text.of(("")), this); - textField2.setText(code); - codeTextFields.add(textField2); - TextFieldWidget textField = new TextFieldWidget(textRenderer, width / 3, 20, Text.of((""))); - textField.setText(command); - commandTextFields.add(textField); - int finalRemoveId = commandTextFields.size(); - ButtonWidget removeButton = ButtonWidget.builder(Text.of("-"), button -> removeRow(finalRemoveId)).build(); - removeButtonFields.add(removeButton); - } - - private void addNewRow() { - addRow("", ""); - updateFields(); - } - - private void removeRow(int i) { - if (!codeTextFields.isEmpty()) { - TextFieldWidget removedCodeField = codeTextFields.remove(i - 2); - TextFieldWidget removedCommandField = commandTextFields.remove(i - 2); - ButtonWidget removeButton = removeButtonFields.remove(i - 2); - remove(removeButton); - remove(removedCodeField); - remove(removedCommandField); - updateFields(); - } - } - - private void updateFields() { - int leftX = width / 9; // Start position for codeTextFields - int rightX = leftX * 2 + width / 3; // Start position for commandTextFields - - clearChildren(); - - for (int i = getMinimumEntry(); i < getHighestEntry(); i++) { - int hight = 60 + (i - getMinimumEntry()) * 30; - - // Set the positions for codeTextFields - codeTextFields.get(i).setX(leftX); - codeTextFields.get(i).setY(hight); - codeTextFields.get(i).setWidth(width / 3); - - // Set the positions for commandTextFields - commandTextFields.get(i).setX(rightX); - commandTextFields.get(i).setY(hight); - commandTextFields.get(i).setWidth(width / 3); - - // Set positions for removeButtonFields - removeButtonFields.get(i).setWidth(width / 12); - removeButtonFields.get(i).setX(rightX + width / 3 + width / 18 - removeButtonFields.get(i).getWidth() / 2); // Place the remove button to the right - removeButtonFields.get(i).setY(hight); - firstPage.setPosition(0, 20); - lastPage.setPosition(0, height - 10 - lastPage.getHeight()); - nextPage.setPosition(0, firstPage.getHeight() + firstPage.getY() + 10); - previosPage.setPosition(0, lastPage.getY() - lastPage.getHeight() - 10); - nextPage.setWidth(width / 12); - previosPage.setWidth(width / 12); - lastPage.setWidth(width / 12); - firstPage.setWidth(width / 12); - addDrawableChild(codeTextFields.get(i)); - addDrawableChild(commandTextFields.get(i)); - addDrawableChild(removeButtonFields.get(i)); - addDrawableChild(nextPage); - addDrawableChild(previosPage); - addDrawableChild(lastPage); - addDrawableChild(firstPage); - } - - addDrawableChild(addButton); - addDrawableChild(okButton); - } - - public int getMinimumEntry() { - return Math.min(entriesPerPage() * page, commandTextFields.size()); - } - - public int entriesPerPage() { - return Math.min((height - 100) / 30, commandTextFields.size()); - } - - public int getHighestEntry() { - int max = Math.min(entriesPerPage() * (page + 1) - 1, commandTextFields.size()); - return max; - } - - public void updateCodes() { - List newCodes = new ArrayList<>(hiddenNumCodes); - for (int i = 0; i < commandTextFields.size(); i++) { - newCodes.add(new NumCode(codeTextFields.get(i).getText(), commandTextFields.get(i).getText())); - } - codes.numCodes = newCodes; - } - - public void done() { - codes.saveNumCodesToFile(); - close(); - } - - @Override - public boolean shouldCloseOnEsc() { - return false; - } - - @Override - public void close() { - updateCodes(); - codes.saveNumCodesToFile(); - super.close(); - } - - -} - diff --git a/run/saves/temp/DIM-1/data/raids.dat b/run/saves/temp/DIM-1/data/raids.dat index e0e9849..5142c35 100644 Binary files a/run/saves/temp/DIM-1/data/raids.dat and b/run/saves/temp/DIM-1/data/raids.dat differ diff --git a/run/saves/temp/DIM1/data/raids_end.dat b/run/saves/temp/DIM1/data/raids_end.dat index e0e9849..5142c35 100644 Binary files a/run/saves/temp/DIM1/data/raids_end.dat and b/run/saves/temp/DIM1/data/raids_end.dat differ diff --git a/run/saves/temp/advancements/4fa1228c-8dd6-47c4-8fe3-b04b580311b8.json b/run/saves/temp/advancements/4fa1228c-8dd6-47c4-8fe3-b04b580311b8.json index 92d3076..ecb57f1 100644 --- a/run/saves/temp/advancements/4fa1228c-8dd6-47c4-8fe3-b04b580311b8.json +++ b/run/saves/temp/advancements/4fa1228c-8dd6-47c4-8fe3-b04b580311b8.json @@ -281,5 +281,11 @@ }, "done": true }, + "minecraft:recipes/redstone/repeater": { + "criteria": { + "has_redstone_torch": "2023-10-26 16:55:49 +0200" + }, + "done": true + }, "DataVersion": 3578 } \ No newline at end of file diff --git a/run/saves/temp/level.dat_old b/run/saves/temp/level.dat_old index edc4345..a3a217f 100644 Binary files a/run/saves/temp/level.dat_old and b/run/saves/temp/level.dat_old differ diff --git a/run/saves/temp/playerdata/4fa1228c-8dd6-47c4-8fe3-b04b580311b8.dat b/run/saves/temp/playerdata/4fa1228c-8dd6-47c4-8fe3-b04b580311b8.dat index 6162158..4a91554 100644 Binary files a/run/saves/temp/playerdata/4fa1228c-8dd6-47c4-8fe3-b04b580311b8.dat and b/run/saves/temp/playerdata/4fa1228c-8dd6-47c4-8fe3-b04b580311b8.dat differ diff --git a/run/saves/temp/playerdata/4fa1228c-8dd6-47c4-8fe3-b04b580311b8.dat_old b/run/saves/temp/playerdata/4fa1228c-8dd6-47c4-8fe3-b04b580311b8.dat_old index 6162158..838b728 100644 Binary files a/run/saves/temp/playerdata/4fa1228c-8dd6-47c4-8fe3-b04b580311b8.dat_old and b/run/saves/temp/playerdata/4fa1228c-8dd6-47c4-8fe3-b04b580311b8.dat_old differ diff --git a/run/saves/temp/region/r.-1.0.mca b/run/saves/temp/region/r.-1.0.mca index 38d6c97..b8668c6 100644 Binary files a/run/saves/temp/region/r.-1.0.mca and b/run/saves/temp/region/r.-1.0.mca differ diff --git a/run/saves/temp/region/r.0.0.mca b/run/saves/temp/region/r.0.0.mca index 99d7ae9..671ffcc 100644 Binary files a/run/saves/temp/region/r.0.0.mca and b/run/saves/temp/region/r.0.0.mca differ -- cgit