-
-
Notifications
You must be signed in to change notification settings - Fork 104
Keyboard #659
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Keyboard #659
Changes from 23 commits
Commits
Show all changes
30 commits
Select commit
Hold shift + click to select a range
8bc766d
[IntelligenceModding/Advanced-Peripherals-Features#59] Keyboard item …
SirEndii 6695fda
Remove custom indentation
SirEndii 027787b
Binding/Unbinding for the keyboard
SirEndii 19f4de9
Use translatable components and add name and description for the keyb…
SirEndii c507f0a
Removed owner tag from the memory card
SirEndii ab6a8cd
Key press/Char typed sync to the computer logic
SirEndii 5af40a8
The keyboard is now a working module, it currently uses the hotkey mo…
SirEndii b94b8be
Mouse events for the keyboard module
SirEndii 9ba1214
Fixed an issue where the keyboard does not bound to the glasses when …
SirEndii e8f70d7
Render a little info text when the player is using the keyboard
SirEndii 1b147a3
Preven JEI/REI/EMI from rendering in the keyboard screen
SirEndii 48ce6e5
Merge branch 'dev/0.8' into feat/keyboard
SirEndii b689497
checkstyle
SirEndii 36193be
Simplify KeyboardScreen
SirEndii 5e439b9
Sort ClientRegistry.java
SirEndii a7c5984
Merge branch 'dev/0.8' into feat/keyboard
SirEndii f5efd86
Add language entries
SirEndii 25cb800
Merge branch 'dev/0.8' of https://github.com/IntelligenceModding/Adva…
zyxkad 256cf0e
make keyboard based on computer ID instead of position
zyxkad 5251139
run runData
zyxkad 3549dd9
implement keyboard mouse capture mode
zyxkad d6dd79b
fix styles
zyxkad 21e7aeb
Merge pull request #719 from zyxkad/player-rotate-handle-feature
SirEndii 58a92cd
make lock final
zyxkad cf93b69
fix keyboard does not work in multiplayer
zyxkad 0e90294
fix keyboard_close fires with delay
zyxkad b471dd3
remove unused import
zyxkad 4978a6b
Merge pull request #751 from zyxkad/feat/keyboard
SirEndii 9b0f17a
add license to KeyboardScreen and some code cleanup
zyxkad 5be343f
Merge branch 'dev/0.8' of https://github.com/IntelligenceModding/Adva…
zyxkad File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
2 changes: 1 addition & 1 deletion
2
src/generated/resources/.cache/03e4de26f1265135874f8cdcaebc09d9c08eb42b
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,3 @@ | ||
| // 1.19.2 2025-01-20T07:59:27.474151 Tags for minecraft:item | ||
| // 1.19.2 2025-03-15T16:18:50.46663 Tags for minecraft:item | ||
| de4b4f45ec18b2b1f0db1c36882981042e20ee23 data/advancedperipherals/tags/items/p2p_attunements/cable_p2p_tunnel.json | ||
| 72eba3b11f69e16c87488f7c4ba7cfdad42c378e data/advancedperipherals/tags/items/smart_glasses.json |
2 changes: 1 addition & 1 deletion
2
src/generated/resources/.cache/2db41954e490230d51b10affff25ee2ee27b8d5b
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,2 @@ | ||
| // 1.19.2 2024-05-28T14:53:16.655175 AP POI Type Tags | ||
| // 1.19.2 2025-03-15T16:18:50.465796 AP POI Type Tags | ||
| d3d6b837660a4e213f287ad9d11e12368b90cd8e data/minecraft/tags/point_of_interest_type/acquirable_job_site.json |
2 changes: 1 addition & 1 deletion
2
src/generated/resources/.cache/5a761efb7472ef97566e41e81451930a004134bf
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/generated/resources/.cache/67cce32b1c3cbbcb1f646605f4914e3f196986c2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/generated/resources/.cache/9fb1092f32d4fcbf9e061ffd718d4ec689c6c95e
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/generated/resources/.cache/ae219fa7c7d3297c14e454863eac3998a4eab78c
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/generated/resources/.cache/b8526e444ae7356037f3a813274f6835d1f3dd16
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
src/generated/resources/.cache/c622617f6fabf890a00b9275cd5f643584a8a2c8
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,2 @@ | ||
| // 1.19.2 2025-01-25T19:46:21.234203 Languages: en_us | ||
| e858500d72e9279f0fe0e8b2d03f94469c8d1f65 assets/advancedperipherals/lang/en_us.json | ||
| // 1.19.2 2025-03-15T16:18:50.465918 Languages: en_us | ||
| fe52123263b91f49093d74278e8709484e4dfe59 assets/advancedperipherals/lang/en_us.json |
2 changes: 1 addition & 1 deletion
2
src/generated/resources/.cache/f95c7003282837dabaa33e3ffceec4e6865b5218
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| // 1.19.2 2025-01-16T15:46:41.859383 Block tags | ||
| // 1.19.2 2025-03-15T16:18:50.466493 Block tags | ||
| e1f71dcb4f9e7e36e29b0ad09d6520dc3adfa4a6 data/forge/tags/blocks/needs_wood_tool.json | ||
| 03322cd493601129eaad6ba7c2a6d808023dfac1 data/minecraft/tags/blocks/mineable/pickaxe.json | ||
| 277fe59db076a3eab3c97080531ad345f8ca5f3d data/minecraft/tags/blocks/needs_iron_tool.json |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 1 addition & 2 deletions
3
src/generated/resources/data/forge/tags/blocks/needs_wood_tool.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,5 @@ | ||
| { | ||
| "values": [ | ||
| "advancedperipherals:peripheral_casing", | ||
| "advancedperipherals:colony_integrator" | ||
| "advancedperipherals:peripheral_casing" | ||
| ] | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
src/main/java/de/srendi/advancedperipherals/client/ClientWorker.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| package de.srendi.advancedperipherals.client; | ||
|
|
||
| import de.srendi.advancedperipherals.AdvancedPeripherals; | ||
| import net.minecraftforge.api.distmarker.Dist; | ||
| import net.minecraftforge.event.TickEvent; | ||
| import net.minecraftforge.eventbus.api.SubscribeEvent; | ||
| import net.minecraftforge.fml.common.Mod; | ||
|
|
||
| import java.util.Map; | ||
| import java.util.concurrent.ConcurrentHashMap; | ||
|
|
||
| @Mod.EventBusSubscriber(value = Dist.CLIENT, modid = AdvancedPeripherals.MOD_ID) | ||
| public class ClientWorker { | ||
|
|
||
| private static final Map<String, Runnable> tasks = new ConcurrentHashMap<>(); | ||
|
|
||
| /** | ||
| * This method will put a task to current tick's end. | ||
| * If a task with given identifier is already exists, the task will be replaced. | ||
| */ | ||
| public static void put(final String id, final Runnable task) { | ||
| tasks.put(id, task); | ||
| } | ||
|
|
||
| @SubscribeEvent | ||
| public static void clientTick(TickEvent.ClientTickEvent event) { | ||
| if (event.phase == TickEvent.Phase.END) { | ||
| tasks.forEach((id, runnable) -> { | ||
| tasks.remove(id, runnable); | ||
| runnable.run(); | ||
| }); | ||
| } | ||
| } | ||
| } |
239 changes: 239 additions & 0 deletions
239
src/main/java/de/srendi/advancedperipherals/client/screens/KeyboardScreen.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,239 @@ | ||
| package de.srendi.advancedperipherals.client.screens; | ||
|
|
||
| import com.mojang.blaze3d.platform.InputConstants; | ||
| import com.mojang.blaze3d.platform.Window; | ||
| import com.mojang.blaze3d.vertex.PoseStack; | ||
| import dan200.computercraft.client.gui.ClientInputHandler; | ||
| import dan200.computercraft.client.gui.widgets.WidgetTerminal; | ||
| import dan200.computercraft.core.terminal.Terminal; | ||
| import dan200.computercraft.shared.computer.core.InputHandler; | ||
| import de.srendi.advancedperipherals.client.ClientWorker; | ||
| import de.srendi.advancedperipherals.common.container.KeyboardContainer; | ||
| import de.srendi.advancedperipherals.common.network.APNetworking; | ||
| import de.srendi.advancedperipherals.common.network.toserver.KeyboardMouseClickPacket; | ||
| import de.srendi.advancedperipherals.common.network.toserver.KeyboardMouseMovePacket; | ||
| import de.srendi.advancedperipherals.common.network.toserver.KeyboardMouseScrollPacket; | ||
| import net.minecraft.client.KeyMapping; | ||
| import net.minecraft.client.Minecraft; | ||
| import net.minecraft.client.gui.screens.Screen; | ||
| import net.minecraft.client.gui.screens.inventory.MenuAccess; | ||
| import net.minecraft.network.chat.Component; | ||
| import net.minecraft.world.entity.player.Inventory; | ||
| import org.jetbrains.annotations.NotNull; | ||
| import org.lwjgl.glfw.GLFW; | ||
|
|
||
| /** | ||
| * A simple screen but without any rendering calls. Used to unlock the mouse so we can freely write stuff | ||
| * <p> | ||
| * We just create a terminal which is used to forward all the key presses and mouse clicks but we don't render it. | ||
| */ | ||
| public class KeyboardScreen extends Screen implements MenuAccess<KeyboardContainer> { | ||
|
|
||
| protected final KeyboardContainer keyboardContainer; | ||
| protected final InputHandler input; | ||
| private final Terminal terminalData; | ||
| private WidgetTerminal terminal; | ||
| private MouseState mouseState = MouseState.RELEASED; | ||
| private boolean captureMouse; | ||
| private boolean regrabingMouse; | ||
| private byte[] lastPosLock = new byte[0]; | ||
| private double lastX = 0; | ||
| private double lastY = 0; | ||
| private double lastScroll = 0; | ||
|
|
||
| public KeyboardScreen(KeyboardContainer keyboardContainer, Inventory inv, Component titleIn) { | ||
| super(titleIn); | ||
| this.keyboardContainer = keyboardContainer; | ||
| this.input = new ClientInputHandler(keyboardContainer); | ||
| this.terminalData = new Terminal(0, 0, false); | ||
| } | ||
|
|
||
| @Override | ||
| public KeyboardContainer getMenu() { | ||
| return this.keyboardContainer; | ||
| } | ||
|
|
||
| @Override | ||
| public void render(@NotNull PoseStack poseStack, int x, int y, float partialTicks) { | ||
| super.render(poseStack, x, y, partialTicks); | ||
|
|
||
| Minecraft minecraft = Minecraft.getInstance(); | ||
| float scale = 2f; | ||
| int screenWidth = minecraft.getWindow().getGuiScaledWidth(); | ||
| // Make the text a bit smaller on small screens | ||
| if (screenWidth <= 1080) | ||
| scale = 1f; | ||
|
|
||
| poseStack.scale(scale, scale, 1); | ||
| Component text = Component.translatable("text.advancedperipherals.keyboard.close"); | ||
| float textX = (screenWidth / 2f - minecraft.font.width(text) * scale / 2f) / scale; | ||
| minecraft.font.drawShadow(poseStack, text, textX, 1, 0xFFFFFF); | ||
| } | ||
|
|
||
| @Override | ||
| protected void init() { | ||
| if (this.isCapturingMouse()) { | ||
| this.grabMouse(); | ||
| } else { | ||
| this.grabMouseWithControl(); | ||
| } | ||
| this.passEvents = true; | ||
| KeyMapping.releaseAll(); | ||
|
|
||
| super.init(); | ||
| this.minecraft.keyboardHandler.setSendRepeatsToGui(true); | ||
|
|
||
| this.terminal = addWidget(new WidgetTerminal(terminalData, new ClientInputHandler(this.keyboardContainer), 0, 0)); | ||
| this.terminal.visible = false; | ||
| this.terminal.active = false; | ||
| setFocused(this.terminal); | ||
| } | ||
|
|
||
| @Override | ||
| public final void removed() { | ||
| if (this.regrabingMouse) { | ||
| return; | ||
| } | ||
| super.removed(); | ||
| this.minecraft.keyboardHandler.setSendRepeatsToGui(false); | ||
| } | ||
|
|
||
| @Override | ||
| public void onClose() { | ||
| // Don't allow closing using standard keys like E. Closing using ESCAPE is still possible due to the keyPressed method | ||
| } | ||
|
|
||
| @Override | ||
| public boolean isPauseScreen() { | ||
| return false; | ||
| } | ||
|
|
||
| @Override | ||
| public void mouseMoved(double x, double y) { | ||
| if (this.mouseState != MouseState.CAPTURE) { | ||
| return; | ||
| } | ||
| ClientWorker.put("mouse_move", () -> { | ||
| synchronized (this.lastPosLock) { | ||
| double dx = x - this.lastX; | ||
| double dy = y - this.lastY; | ||
| APNetworking.sendToServer(new KeyboardMouseMovePacket(dx, dy)); | ||
| this.lastX = x; | ||
| this.lastY = y; | ||
| } | ||
| }); | ||
| } | ||
|
|
||
| @Override | ||
| public boolean mouseClicked(double x, double y, int button) { | ||
| if (this.mouseState != MouseState.CAPTURE) { | ||
| return false; | ||
| } | ||
| APNetworking.sendToServer(new KeyboardMouseClickPacket(button, false)); | ||
| return true; | ||
| } | ||
|
|
||
| @Override | ||
| public boolean mouseReleased(double x, double y, int button) { | ||
| if (this.mouseState != MouseState.CAPTURE) { | ||
| return false; | ||
| } | ||
| APNetworking.sendToServer(new KeyboardMouseClickPacket(button, true)); | ||
| return true; | ||
| } | ||
|
|
||
| @Override | ||
| public boolean mouseScrolled(double x, double y, double direction) { | ||
| this.lastScroll += direction; | ||
| int scrolled = (int) this.lastScroll; | ||
| if (scrolled == 0) { | ||
| return true; | ||
| } | ||
| if (this.mouseState == MouseState.CAPTURE) { | ||
| ClientWorker.put("mouse_scroll", () -> { | ||
| if (this.mouseState != MouseState.CAPTURE) { | ||
| return; | ||
| } | ||
| this.lastScroll -= scrolled; | ||
| APNetworking.sendToServer(new KeyboardMouseScrollPacket(scrolled)); | ||
| }); | ||
| } else { | ||
| this.lastScroll -= scrolled; | ||
| minecraft.player.getInventory().swapPaint(scrolled); | ||
| } | ||
| return true; | ||
| } | ||
|
|
||
| @Override | ||
| public final boolean keyPressed(int key, int scancode, int modifiers) { | ||
| if (key == GLFW.GLFW_KEY_ESCAPE) { | ||
| super.onClose(); | ||
| return true; | ||
| } | ||
| // Forward the tab key to the terminal, rather than moving between controls. | ||
| if (key == GLFW.GLFW_KEY_TAB && getFocused() != null && getFocused() == terminal) { | ||
| return getFocused().keyPressed(key, scancode, modifiers); | ||
| } | ||
|
|
||
| return super.keyPressed(key, scancode, modifiers); | ||
| } | ||
|
|
||
| public boolean isCapturingMouse() { | ||
| return this.captureMouse; | ||
| } | ||
|
|
||
| public void setCaptureMouse(boolean enable) { | ||
| this.captureMouse = enable; | ||
| if (enable) { | ||
| this.grabMouse(); | ||
| } else { | ||
| this.grabMouseWithControl(); | ||
| } | ||
| } | ||
|
|
||
| private void grabMouseWithControl() { | ||
| if (this.mouseState == MouseState.NORMAL) { | ||
| return; | ||
| } | ||
| this.releaseMouse(); | ||
| this.regrabingMouse = true; | ||
| this.minecraft.mouseHandler.grabMouse(); | ||
| this.regrabingMouse = false; | ||
| this.minecraft.screen = this; | ||
| this.mouseState = MouseState.NORMAL; | ||
| } | ||
|
|
||
| private void grabMouse() { | ||
| if (this.minecraft.mouseHandler.isMouseGrabbed()) { | ||
| this.minecraft.mouseHandler.releaseMouse(); | ||
| } | ||
| Window window = this.minecraft.getWindow(); | ||
| synchronized (this.lastPosLock) { | ||
| this.lastX = window.getScreenWidth() / 2; | ||
| this.lastY = window.getScreenHeight() / 2; | ||
| InputConstants.grabOrReleaseMouse(window.getWindow(), InputConstants.CURSOR_DISABLED, this.lastX, this.lastY); | ||
| } | ||
| this.mouseState = MouseState.CAPTURE; | ||
| } | ||
|
|
||
| private void releaseMouse() { | ||
| if (this.mouseState == MouseState.RELEASED) { | ||
| return; | ||
| } | ||
| if (this.minecraft.mouseHandler.isMouseGrabbed()) { | ||
| this.minecraft.mouseHandler.releaseMouse(); | ||
| return; | ||
| } | ||
| Window window = this.minecraft.getWindow(); | ||
| synchronized (this.lastPosLock) { | ||
| this.lastX = window.getScreenWidth() / 2; | ||
| this.lastY = window.getScreenHeight() / 2; | ||
| InputConstants.grabOrReleaseMouse(window.getWindow(), InputConstants.CURSOR_NORMAL, this.lastX, this.lastY); | ||
| } | ||
| this.mouseState = MouseState.RELEASED; | ||
| } | ||
|
|
||
| private enum MouseState { | ||
| RELEASED, NORMAL, CAPTURE | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.