Skip to content

Commit e8f70d7

Browse files
committed
Render a little info text when the player is using the keyboard
1 parent 9ba1214 commit e8f70d7

File tree

2 files changed

+21
-8
lines changed

2 files changed

+21
-8
lines changed

src/main/java/de/srendi/advancedperipherals/client/screens/KeyboardScreen.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,17 @@ public KeyboardScreen(KeyboardContainer screenContainer, Inventory inv, Componen
4040

4141
@Override
4242
public void render(@NotNull PoseStack matrixStack, int x, int y, float partialTicks) {
43+
Minecraft minecraft = Minecraft.getInstance();
44+
float scale = 2f;
45+
int screenWidth = minecraft.getWindow().getGuiScaledWidth();
46+
// Make the text a bit smaller on small screens
47+
if (screenWidth <= 1080)
48+
scale = 1f;
49+
50+
matrixStack.scale(scale, scale, 1);
51+
String text = "Press ESC to close the Keyboard Screen.";
52+
float textX = (screenWidth / 2f - minecraft.font.width(text) * scale / 2f) / scale;
53+
minecraft.font.drawShadow(matrixStack, text, textX, 1, 0xFFFFFF);
4354
}
4455

4556
@Override
@@ -166,7 +177,6 @@ public boolean mouseReleased(double mouseX, double mouseY, int button) {
166177

167178
@Override
168179
public boolean mouseDragged(double mouseX, double mouseY, int button, double v2, double v3) {
169-
170180
if (button == lastMouseButton && (mouseX != lastMouseX || mouseY != lastMouseY)) {
171181
input.mouseDrag(button + 1, (int) mouseX, (int) mouseY);
172182
lastMouseX = (int) mouseX;
@@ -178,7 +188,6 @@ public boolean mouseDragged(double mouseX, double mouseY, int button, double v2,
178188

179189
@Override
180190
public boolean mouseScrolled(double mouseX, double mouseY, double delta) {
181-
182191
input.mouseScroll(delta < 0 ? 1 : -1, (int) mouseX, (int) mouseY);
183192

184193
lastMouseX = (int) mouseX;

src/main/java/de/srendi/advancedperipherals/common/items/KeyboardItem.java

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,14 @@ public boolean isEnabled() {
5454
@NotNull
5555
@Override
5656
public InteractionResult useOn(UseOnContext context) {
57-
if (context.getPlayer() == null) return InteractionResult.PASS;
57+
if (context.getPlayer() == null)
58+
return InteractionResult.PASS;
5859

59-
if (SideHelper.isClientPlayer(context.getPlayer())) return InteractionResult.PASS;
60+
if (SideHelper.isClientPlayer(context.getPlayer()))
61+
return InteractionResult.PASS;
6062

61-
if (!context.getPlayer().isShiftKeyDown()) return InteractionResult.PASS;
63+
if (!context.getPlayer().isShiftKeyDown())
64+
return InteractionResult.PASS;
6265

6366
BlockEntity entity = context.getLevel().getBlockEntity(context.getClickedPos());
6467
if (entity instanceof TileComputerBase) {
@@ -71,9 +74,11 @@ public InteractionResult useOn(UseOnContext context) {
7174

7275
@Override
7376
public void inventoryTick(ItemStack itemStack, Level level, Entity entity, int inventorySlot, boolean isCurrentItem, @Nullable SmartGlassesAccess access, @Nullable IModule module) {
74-
if (level.isClientSide()) return;
77+
if (level.isClientSide())
78+
return;
7579

76-
if (access == null) return;
80+
if (access == null)
81+
return;
7782

7883
CompoundTag data = itemStack.getOrCreateTag();
7984
int instanceId = access.getComputer().getInstanceID();
@@ -85,7 +90,6 @@ public void inventoryTick(ItemStack itemStack, Level level, Entity entity, int i
8590
data.putBoolean(BOUND_TYPE_TAG, true);
8691
data.putInt(GLASSES_BIND_TAG, access.getComputer().getInstanceID());
8792
data.remove(BIND_TAG);
88-
8993
}
9094

9195
if (KeybindUtil.isKeyPressed(KeyBindings.GLASSES_HOTKEY_KEYBINDING)) {

0 commit comments

Comments
 (0)