Horrible hack to avoid Forge stealing keyboard input in terminal screens.
This commit is contained in:
@@ -9,9 +9,11 @@ import li.cil.oc2.common.Constants;
|
||||
import li.cil.oc2.common.container.AbstractMachineTerminalContainer;
|
||||
import li.cil.oc2.common.util.TooltipUtils;
|
||||
import net.minecraft.ChatFormatting;
|
||||
import net.minecraft.client.gui.components.EditBox;
|
||||
import net.minecraft.client.renderer.GameRenderer;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.network.chat.FormattedText;
|
||||
import net.minecraft.network.chat.TextComponent;
|
||||
import net.minecraft.network.chat.TranslatableComponent;
|
||||
import net.minecraft.world.entity.player.Inventory;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
@@ -103,6 +105,10 @@ public abstract class AbstractMachineTerminalScreen<T extends AbstractMachineTer
|
||||
super.init();
|
||||
terminalWidget.init();
|
||||
|
||||
final EditBox focusIndicatorEditBox = new EditBox(font, 0, 0, 0, 0, TextComponent.EMPTY);
|
||||
focusIndicatorEditBox.setFocus(true);
|
||||
setFocusIndicatorEditBox(focusIndicatorEditBox);
|
||||
|
||||
addRenderableWidget(new ToggleImageButton(
|
||||
this, leftPos - Sprites.SIDEBAR_3.width + 4, topPos + CONTROLS_TOP + 4,
|
||||
12, 12,
|
||||
@@ -168,6 +174,11 @@ public abstract class AbstractMachineTerminalScreen<T extends AbstractMachineTer
|
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
|
||||
// We use this text box to indicate to Forge that we want all input, and event handlers should not be allowed
|
||||
// to steal input from us (e.g. via custom key bindings). Since Forge is lazy and just uses getDeclaredFields
|
||||
// to get private fields, which completely skips fields in base classes, we require subclasses to hold the field...
|
||||
protected abstract void setFocusIndicatorEditBox(final EditBox editBox);
|
||||
|
||||
@Override
|
||||
protected void renderBg(final PoseStack stack, final float partialTicks, final int mouseX, final int mouseY) {
|
||||
RenderSystem.setShader(GameRenderer::getPositionTexShader);
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package li.cil.oc2.client.gui;
|
||||
|
||||
import li.cil.oc2.common.container.ComputerTerminalContainer;
|
||||
import net.minecraft.client.gui.components.EditBox;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.world.entity.player.Inventory;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
@@ -8,7 +9,18 @@ import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
public final class ComputerTerminalScreen extends AbstractMachineTerminalScreen<ComputerTerminalContainer> {
|
||||
@SuppressWarnings("all") private EditBox focusIndicatorEditBox;
|
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
|
||||
public ComputerTerminalScreen(final ComputerTerminalContainer container, final Inventory playerInventory, final Component title) {
|
||||
super(container, playerInventory, title);
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
|
||||
@Override
|
||||
protected void setFocusIndicatorEditBox(final EditBox editBox) {
|
||||
focusIndicatorEditBox = editBox;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package li.cil.oc2.client.gui;
|
||||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import li.cil.oc2.common.container.RobotTerminalContainer;
|
||||
import net.minecraft.client.gui.components.EditBox;
|
||||
import net.minecraft.client.renderer.GameRenderer;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.world.entity.player.Inventory;
|
||||
@@ -16,6 +17,10 @@ public final class RobotTerminalScreen extends AbstractMachineTerminalScreen<Rob
|
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
|
||||
@SuppressWarnings("all") private EditBox focusIndicatorEditBox;
|
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
|
||||
public RobotTerminalScreen(final RobotTerminalContainer container, final Inventory playerInventory, final Component title) {
|
||||
super(container, playerInventory, title);
|
||||
}
|
||||
@@ -36,4 +41,11 @@ public final class RobotTerminalScreen extends AbstractMachineTerminalScreen<Rob
|
||||
RobotContainerScreen.renderSelection(stack, menu.getRobot().getSelectedSlot(), leftPos + SLOTS_X + 4, topPos + SLOTS_Y + 4, 12);
|
||||
renderTooltip(stack, mouseX, mouseY);
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
|
||||
@Override
|
||||
protected void setFocusIndicatorEditBox(final EditBox editBox) {
|
||||
focusIndicatorEditBox = editBox;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user