Search in sources :

Example 1 with KeyBinding

use of net.minecraft.client.option.KeyBinding in project BlockMeter by ModProg.

the class BlockMeterClient method onInitializeClient.

@Override
public void onInitializeClient() {
    final KeyBinding keyBinding = new KeyBinding("key.blockmeter.assign", InputUtil.Type.KEYSYM, GLFW.GLFW_KEY_M, "category.blockmeter.key");
    final KeyBinding keyBindingMenu = new KeyBinding("key.blockmeter.menu", InputUtil.Type.KEYSYM, GLFW.GLFW_KEY_LEFT_ALT, "category.blockmeter.key");
    KeyBindingHelper.registerKeyBinding(keyBinding);
    KeyBindingHelper.registerKeyBinding(keyBindingMenu);
    // This is ugly I know, but I did not find something better
    // (Issue in AutoConfig https://github.com/shedaniel/AutoConfig/issues/13)
    confMgr = (ConfigManager<ModConfig>) AutoConfig.register(ModConfig.class, Toml4jConfigSerializer::new);
    ClientTickEvents.START_CLIENT_TICK.register(e -> {
        if (keyBinding.wasPressed()) {
            if (Screen.hasShiftDown()) {
                if (undo())
                    e.player.sendMessage(new TranslatableText("blockmeter.clearLast"), true);
            } else if (Screen.hasControlDown()) {
                if (clear())
                    e.player.sendMessage(new TranslatableText("blockmeter.clearAll"), true);
            } else if (this.active) {
                disable();
                e.player.sendMessage(new TranslatableText("blockmeter.toggle.off", new Object[0]), true);
            } else {
                active = true;
                ItemStack itemStack = e.player.getMainHandStack();
                currentItem = itemStack.getItem();
                e.player.sendMessage(new TranslatableText("blockmeter.toggle.on", new Object[] { new TranslatableText(itemStack.getTranslationKey(), new Object[0]) }), true);
            }
        }
        if (keyBindingMenu.wasPressed() && active && MinecraftClient.getInstance().player.getMainHandStack().getItem() == this.currentItem) {
            MinecraftClient.getInstance().setScreen((Screen) this.quickMenu);
        }
        // Updates Selection preview
        if (this.active && this.boxes.size() > 0) {
            final ClientMeasureBox currentBox = getCurrentBox();
            if (currentBox != null) {
                final HitResult rayHit = e.player.raycast((double) e.interactionManager.getReachDistance(), 1.0f, false);
                if (rayHit.getType() == HitResult.Type.BLOCK) {
                    final BlockHitResult blockHitResult = (BlockHitResult) rayHit;
                    currentBox.setBlockEnd(new BlockPos(blockHitResult.getBlockPos()));
                }
            }
        }
    });
    UseBlockCallback.EVENT.register((playerEntity, world, hand, hitResult) -> this.onBlockMeterClick(playerEntity, hitResult));
}
Also used : Toml4jConfigSerializer(me.shedaniel.autoconfig.serializer.Toml4jConfigSerializer) TranslatableText(net.minecraft.text.TranslatableText) BlockHitResult(net.minecraft.util.hit.BlockHitResult) HitResult(net.minecraft.util.hit.HitResult) KeyBinding(net.minecraft.client.option.KeyBinding) ClientMeasureBox(win.baruna.blockmeter.measurebox.ClientMeasureBox) BlockPos(net.minecraft.util.math.BlockPos) ItemStack(net.minecraft.item.ItemStack) BlockHitResult(net.minecraft.util.hit.BlockHitResult)

Example 2 with KeyBinding

use of net.minecraft.client.option.KeyBinding in project logical_zoom by LogicalGeekBoy.

the class LogicalZoom method onInitializeClient.

@Override
public void onInitializeClient() {
    keyBinding = new KeyBinding("key.logical_zoom.zoom", InputUtil.Type.KEYSYM, GLFW.GLFW_KEY_C, "category.logical_zoom.zoom");
    currentlyZoomed = false;
    originalSmoothCameraEnabled = false;
    KeyBindingHelper.registerKeyBinding(keyBinding);
}
Also used : KeyBinding(net.minecraft.client.option.KeyBinding)

Example 3 with KeyBinding

use of net.minecraft.client.option.KeyBinding in project Moonfix by Kingdom-of-Moon.

the class KeyBindEntry method render.

@Override
public void render(MatrixStack matrices, int index, int y, int x, int entryWidth, int entryHeight, int mouseX, int mouseY, boolean hovered, float tickDelta) {
    // text
    TextRenderer textRenderer = client.textRenderer;
    int posY = y + entryHeight / 2;
    textRenderer.draw(matrices, this.title, (float) x, (float) (posY - 9 / 2), 0xFFFFFF);
    // reset button
    this.reset.x = x + 260;
    this.reset.y = y;
    this.reset.active = !this.binding.isDefault();
    this.reset.render(matrices, mouseX, mouseY, tickDelta);
    // toggle button
    this.toggle.x = x + 175;
    this.toggle.y = y;
    this.toggle.setMessage(this.binding.getBoundKeyLocalizedText());
    if (parent.focusedBinding == this.binding) {
        this.toggle.setMessage(new LiteralText("> ").styled(ConfigManager.ACCENT_COLOR).append(this.toggle.getMessage()).append(" <"));
    } else if (!this.binding.isUnbound()) {
        for (KeyBinding key : MinecraftClient.getInstance().options.allKeys) {
            if (key != this.binding && this.binding.equals(key)) {
                this.toggle.setMessage(this.toggle.getMessage().shallowCopy().formatted(Formatting.RED));
                break;
            }
        }
    }
    this.toggle.render(matrices, mouseX, mouseY, tickDelta);
}
Also used : KeyBinding(net.minecraft.client.option.KeyBinding) TextRenderer(net.minecraft.client.font.TextRenderer) LiteralText(net.minecraft.text.LiteralText)

Aggregations

KeyBinding (net.minecraft.client.option.KeyBinding)3 Toml4jConfigSerializer (me.shedaniel.autoconfig.serializer.Toml4jConfigSerializer)1 TextRenderer (net.minecraft.client.font.TextRenderer)1 ItemStack (net.minecraft.item.ItemStack)1 LiteralText (net.minecraft.text.LiteralText)1 TranslatableText (net.minecraft.text.TranslatableText)1 BlockHitResult (net.minecraft.util.hit.BlockHitResult)1 HitResult (net.minecraft.util.hit.HitResult)1 BlockPos (net.minecraft.util.math.BlockPos)1 ClientMeasureBox (win.baruna.blockmeter.measurebox.ClientMeasureBox)1