-
-
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
base: dev/0.8
Are you sure you want to change the base?
Keyboard #659
Changes from 14 commits
8bc766d
6695fda
027787b
19f4de9
c507f0a
ab6a8cd
5af40a8
b94b8be
9ba1214
e8f70d7
1b147a3
48ce6e5
b689497
36193be
5e439b9
a7c5984
f5efd86
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,17 @@ | ||
// 1.19.2 2024-05-28T14:53:16.656615 LootTables | ||
d865e8ac35302c486faf5c7122569c554186186d data/advancedperipherals/loot_tables/blocks/block_reader.json | ||
a6f896cc3dbd8da12737825ec71e32970f54025c data/advancedperipherals/loot_tables/blocks/chat_box.json | ||
f50f506ae1987537f76be4c05a81689b25798f91 data/advancedperipherals/loot_tables/blocks/colony_integrator.json | ||
4dcad851450e4ddd8d28a0017a417bf6e5579bda data/advancedperipherals/loot_tables/blocks/distance_detector.json | ||
1d1b858d09538dc66bab2c33a2f9c58361a9c472 data/advancedperipherals/loot_tables/blocks/energy_detector.json | ||
317004b1358ef9bf83957d2d6796529a226161c7 data/advancedperipherals/loot_tables/blocks/environment_detector.json | ||
df6186990887f77b7db37ebb8ee50a7e7f096b0a data/advancedperipherals/loot_tables/blocks/fluid_detector.json | ||
cea5a036d4ccdcc6ef026d1a226b5e13f1060676 data/advancedperipherals/loot_tables/blocks/gas_detector.json | ||
d5a3964f518b138cbd7305c819a36af3d9340e4a data/advancedperipherals/loot_tables/blocks/geo_scanner.json | ||
8aa1deea908fd02f049e047c8ca16679bbef68a2 data/advancedperipherals/loot_tables/blocks/inventory_manager.json | ||
9a2898a63e2e0c087ce8eba211c63d1c8b9fd4aa data/advancedperipherals/loot_tables/blocks/me_bridge.json | ||
973770040bacb61482adb9739fd1d977f16c107f data/advancedperipherals/loot_tables/blocks/nbt_storage.json | ||
b4b80e8c9d62b53d9252cdfc5918c077d3a01f6e data/advancedperipherals/loot_tables/blocks/peripheral_casing.json | ||
58b6adbea5d4ae43ed9af0b627df2b8a4907acde data/advancedperipherals/loot_tables/blocks/player_detector.json | ||
a58aebcc52684302968e7af4f50a12aff93aaf2d data/advancedperipherals/loot_tables/blocks/redstone_integrator.json | ||
0ef1678f88b8fcb744bfd95261f66745340be8f4 data/advancedperipherals/loot_tables/blocks/rs_bridge.json | ||
// 1.19.2 2024-09-23T21:28:44.4809605 LootTables | ||
618b63c020ab64890c8a2d2506dd61cd30259a44 data/advancedperipherals/loot_tables/blocks/block_reader.json | ||
0923665563d05307a7fa7d711a2d7a994a31eb6e data/advancedperipherals/loot_tables/blocks/chat_box.json | ||
bf2a80256cfba0bd8c0283d493882e5816882f1f data/advancedperipherals/loot_tables/blocks/colony_integrator.json | ||
cff4b81aa381bc0d1172b0a4c8bb35c1b954a018 data/advancedperipherals/loot_tables/blocks/distance_detector.json | ||
1c5dbe1a8e07e040a3c2893a002cd535ee41dc20 data/advancedperipherals/loot_tables/blocks/energy_detector.json | ||
8cc03eca1d191f725bc558836f26a85a466cb127 data/advancedperipherals/loot_tables/blocks/environment_detector.json | ||
12589e7642b383029457d97a64637494ea8507a3 data/advancedperipherals/loot_tables/blocks/fluid_detector.json | ||
421a3ece56485bd46374844639bfd606ce4665ec data/advancedperipherals/loot_tables/blocks/gas_detector.json | ||
a2ae352dce564b878daecf47026f268dd432fbcf data/advancedperipherals/loot_tables/blocks/geo_scanner.json | ||
807d449d02c0af701f84d3e806ebac20d3a1f91c data/advancedperipherals/loot_tables/blocks/inventory_manager.json | ||
bb9b442dfad1d5f31397585c8394c85243fa169a data/advancedperipherals/loot_tables/blocks/me_bridge.json | ||
52b1fe2e265be456ebf48d7e0d9ebcc8c994176f data/advancedperipherals/loot_tables/blocks/nbt_storage.json | ||
2651e6053857a31f5bccc360969924848a197ad5 data/advancedperipherals/loot_tables/blocks/peripheral_casing.json | ||
6b5058b6bc49689bf2b858b89f3981a4bb681750 data/advancedperipherals/loot_tables/blocks/player_detector.json | ||
6af6542c7b64aa22dbfcdb01299daf4911827a49 data/advancedperipherals/loot_tables/blocks/redstone_integrator.json | ||
b221c6a82da0875264a112b54f847ac6a1f36797 data/advancedperipherals/loot_tables/blocks/rs_bridge.json |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
// 1.19.2 2024-05-28T14:53:16.658014 Languages: en_us | ||
2580077212426421e05822910bde2edff88e2346 assets/advancedperipherals/lang/en_us.json | ||
// 1.19.2 2024-09-25T15:15:12.3008086 Languages: en_us | ||
c5dde7701295d5ad506663dba947865df73d753c assets/advancedperipherals/lang/en_us.json |
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> { | ||
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. If you do not extend from |
||
|
||
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); | ||
String text = "Press ESC to close the Keyboard Screen."; | ||
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; | ||
} | ||
} |
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) { | ||
|
||
} | ||
} |
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.
I pretend I didn't see those
(although I think you should merge from dev/0.8)