diff --git a/src/main/java/appeng/client/gui/implementations/GuiQuartzKnife.java b/src/main/java/appeng/client/gui/implementations/GuiQuartzKnife.java index 0540b8b18..8f25226a4 100644 --- a/src/main/java/appeng/client/gui/implementations/GuiQuartzKnife.java +++ b/src/main/java/appeng/client/gui/implementations/GuiQuartzKnife.java @@ -18,16 +18,18 @@ package appeng.client.gui.implementations; -import java.io.IOException; +import org.lwjgl.glfw.GLFW; import net.minecraft.client.gui.widget.TextFieldWidget; +import net.minecraft.client.util.InputMappings; import net.minecraft.entity.player.PlayerInventory; import net.minecraft.util.text.ITextComponent; import net.minecraftforge.fml.client.gui.GuiUtils; +import appeng.client.ActionKey; import appeng.client.gui.AEBaseGui; import appeng.container.implementations.ContainerQuartzKnife; -import appeng.core.AELog; +import appeng.core.AppEng; import appeng.core.localization.GuiText; import appeng.core.sync.network.NetworkHandler; import appeng.core.sync.packets.PacketValueConfig; @@ -68,7 +70,7 @@ public class GuiQuartzKnife extends AEBaseGui { @Override public boolean charTyped(char character, int key) { - if (this.name.charTyped(character, key)) { + if (this.name.isFocused() && this.name.charTyped(character, key)) { final String Out = this.name.getText(); container.setName(Out); NetworkHandler.instance().sendToServer(new PacketValueConfig("QuartzKnife.Name", Out)); @@ -80,11 +82,33 @@ public class GuiQuartzKnife extends AEBaseGui { @Override public boolean keyPressed(int keyCode, int scanCode, int p_keyPressed_3_) { - if (this.name.keyPressed(keyCode, scanCode, p_keyPressed_3_)) { - final String Out = this.name.getText(); - container.setName(Out); - NetworkHandler.instance().sendToServer(new PacketValueConfig("QuartzKnife.Name", Out)); - return true; + + InputMappings.Input input = InputMappings.getInputByCode(keyCode, scanCode); + + if (keyCode != GLFW.GLFW_KEY_ESCAPE && !this.checkHotbarKeys(input)) { + if (AppEng.proxy.isActionKey(ActionKey.TOGGLE_FOCUS, input)) { + this.name.setFocused2(!this.name.isFocused()); + return true; + } + + if (this.name.isFocused()) { + if (keyCode == GLFW.GLFW_KEY_ENTER) { + this.name.setFocused2(false); + return true; + } + + if (this.name.keyPressed(keyCode, scanCode, p_keyPressed_3_)) { + final String Out = this.name.getText(); + container.setName(Out); + NetworkHandler.instance().sendToServer(new PacketValueConfig("QuartzKnife.Name", Out)); + return true; + } + + // We need to swallow key presses if the field is focused because typing 'e' + // would otherwise close + // the screen + return true; + } } return super.keyPressed(keyCode, scanCode, p_keyPressed_3_); diff --git a/src/main/java/appeng/container/implementations/ContainerQuartzKnife.java b/src/main/java/appeng/container/implementations/ContainerQuartzKnife.java index 7ea94f748..00712f9e7 100644 --- a/src/main/java/appeng/container/implementations/ContainerQuartzKnife.java +++ b/src/main/java/appeng/container/implementations/ContainerQuartzKnife.java @@ -36,6 +36,7 @@ import appeng.container.ContainerLocator; import appeng.container.slot.SlotOutput; import appeng.container.slot.SlotRestrictedInput; import appeng.items.contents.QuartzKnifeObj; +import appeng.items.materials.ItemMaterial; import appeng.tile.inventory.AppEngInternalInventory; import appeng.util.Platform; @@ -120,7 +121,7 @@ public class ContainerQuartzKnife extends AEBaseContainer { if (ContainerQuartzKnife.this.myName.length() > 0) { return AEApi.instance().definitions().materials().namePress().maybeStack(1).map(namePressStack -> { final CompoundNBT compound = namePressStack.getOrCreateTag(); - compound.putString("InscribeName", ContainerQuartzKnife.this.myName); + compound.putString(ItemMaterial.TAG_INSCRIBE_NAME, ContainerQuartzKnife.this.myName); return namePressStack; }).orElse(ItemStack.EMPTY);