-
-
Notifications
You must be signed in to change notification settings - Fork 74
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
Keyboard #659
Open
SirEndii
wants to merge
17
commits into
dev/0.8
Choose a base branch
from
feat/keyboard
base: dev/0.8
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Keyboard #659
Changes from all commits
Commits
Show all changes
17 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 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
There are no files selected for viewing
2 changes: 1 addition & 1 deletion
2
src/generated/resources/.cache/67cce32b1c3cbbcb1f646605f4914e3f196986c2
This file contains 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 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-16T15:59:34.693839 Languages: en_us | ||
d0fe3ab5a88d6b925369860038c76f23d9910143 assets/advancedperipherals/lang/en_us.json | ||
// 1.19.2 2025-01-18T00:08:46.0946621 Languages: en_us | ||
d4cb5d2a7d78fc44e503663eb08d67a0fb981deb assets/advancedperipherals/lang/en_us.json |
This file contains 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
This file contains 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
126 changes: 126 additions & 0 deletions
126
src/main/java/de/srendi/advancedperipherals/client/screens/KeyboardScreen.java
This file contains 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,126 @@ | ||
package de.srendi.advancedperipherals.client.screens; | ||
|
||
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.screens.base.BaseScreen; | ||
import de.srendi.advancedperipherals.common.container.KeyboardContainer; | ||
import net.minecraft.client.KeyMapping; | ||
import net.minecraft.client.Minecraft; | ||
import net.minecraft.network.chat.Component; | ||
import net.minecraft.resources.ResourceLocation; | ||
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 BaseScreen<KeyboardContainer> { | ||
|
||
protected final InputHandler input; | ||
private final Terminal terminalData; | ||
|
||
private WidgetTerminal terminal; | ||
|
||
public KeyboardScreen(KeyboardContainer screenContainer, Inventory inv, Component titleIn) { | ||
super(screenContainer, inv, titleIn); | ||
input = new ClientInputHandler(menu); | ||
terminalData = new Terminal(0, 0, false); | ||
} | ||
|
||
@Override | ||
public void render(@NotNull PoseStack poseStack, int x, int y, float 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() { | ||
passEvents = true; | ||
KeyMapping.releaseAll(); | ||
|
||
super.init(); | ||
minecraft.keyboardHandler.setSendRepeatsToGui(true); | ||
|
||
terminal = addWidget(new WidgetTerminal(terminalData, new ClientInputHandler(menu), 0, 0)); | ||
terminal.visible = false; | ||
terminal.active = false; | ||
setFocused(terminal); | ||
} | ||
|
||
|
||
@Override | ||
protected void renderBg(@NotNull PoseStack matrixStack, float partialTicks, int x, int y) { | ||
} | ||
|
||
@Override | ||
public void renderBackground(@NotNull PoseStack pPoseStack) { | ||
} | ||
|
||
|
||
@Override | ||
public final void removed() { | ||
super.removed(); | ||
minecraft.keyboardHandler.setSendRepeatsToGui(false); | ||
} | ||
|
||
@Override | ||
public boolean mouseScrolled(double pMouseX, double pMouseY, double pDelta) { | ||
minecraft.player.getInventory().swapPaint(pDelta); | ||
return super.mouseScrolled(pMouseX, pMouseY, pDelta); | ||
} | ||
|
||
@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 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); | ||
} | ||
|
||
// We prevent jei by increasing the image size, even if we don't render it | ||
@Override | ||
public int getSizeX() { | ||
return 4096; | ||
} | ||
|
||
@Override | ||
public int getSizeY() { | ||
return 4096; | ||
} | ||
|
||
@Override | ||
public ResourceLocation getTexture() { | ||
return null; | ||
} | ||
} |
69 changes: 69 additions & 0 deletions
69
src/main/java/de/srendi/advancedperipherals/common/container/KeyboardContainer.java
This file contains 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,69 @@ | ||
package de.srendi.advancedperipherals.common.container; | ||
|
||
import dan200.computercraft.shared.computer.core.ServerComputer; | ||
import dan200.computercraft.shared.computer.core.ServerContext; | ||
import dan200.computercraft.shared.computer.menu.ComputerMenu; | ||
import dan200.computercraft.shared.computer.menu.ServerInputHandler; | ||
import dan200.computercraft.shared.computer.menu.ServerInputState; | ||
import dan200.computercraft.shared.computer.terminal.TerminalState; | ||
import de.srendi.advancedperipherals.common.container.base.BaseContainer; | ||
import de.srendi.advancedperipherals.common.items.KeyboardItem; | ||
import de.srendi.advancedperipherals.common.setup.APContainerTypes; | ||
import de.srendi.advancedperipherals.common.util.NBTUtil; | ||
import net.minecraft.core.BlockPos; | ||
import net.minecraft.nbt.CompoundTag; | ||
import net.minecraft.world.entity.player.Inventory; | ||
import net.minecraft.world.entity.player.Player; | ||
import net.minecraft.world.item.ItemStack; | ||
import net.minecraft.world.level.Level; | ||
import net.minecraftforge.server.ServerLifecycleHooks; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
public class KeyboardContainer extends BaseContainer implements ComputerMenu { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And so we don't need KeyboardContainer anymore |
||
|
||
private final ServerInputState<KeyboardContainer> input; | ||
@Nullable | ||
private ServerComputer computer = null; | ||
|
||
public KeyboardContainer(int id, Inventory inventory, BlockPos pos, Level level, ItemStack keyboardItem) { | ||
super(APContainerTypes.KEYBOARD_CONTAINER.get(), id, inventory, pos, level); | ||
this.input = new ServerInputState<>( this ); | ||
|
||
CompoundTag data = keyboardItem.getOrCreateTag(); | ||
|
||
if (!data.getBoolean(KeyboardItem.BOUND_TYPE_TAG)) { | ||
BlockPos computerPos = NBTUtil.blockPosFromNBT(keyboardItem.getOrCreateTag().getCompound(KeyboardItem.BIND_TAG)); | ||
|
||
for (ServerComputer computer : ServerContext.get(ServerLifecycleHooks.getCurrentServer()).registry().getComputers()) { | ||
if (computer.getPosition() != null && computer.getPosition().equals(computerPos)) { | ||
this.computer = computer; | ||
} | ||
} | ||
} else if (data.contains(KeyboardItem.GLASSES_BIND_TAG)) { | ||
computer = ServerContext.get(ServerLifecycleHooks.getCurrentServer()).registry().get(data.getInt(KeyboardItem.GLASSES_BIND_TAG)); | ||
} | ||
|
||
} | ||
|
||
@Override | ||
public boolean stillValid(@NotNull Player playerIn) { | ||
return true; | ||
} | ||
|
||
@Nullable | ||
@Override | ||
public ServerComputer getComputer() { | ||
return computer; | ||
} | ||
|
||
@Override | ||
public ServerInputHandler getInput() { | ||
return input; | ||
} | ||
|
||
@Override | ||
public void updateTerminal(TerminalState state) { | ||
|
||
} | ||
} |
This file contains 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
This file contains 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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you do not extend from
AbstractContainerScreen
, but inheritScreen
orGuiComponent
, then jade should not render on it