Search in sources :

Example 1 with ClientMeasureBox

use of win.baruna.blockmeter.measurebox.ClientMeasureBox in project BlockMeter by ModProg.

the class ColorButton method init.

@Override
protected void init() {
    ModConfig config = BlockMeterClient.getConfigManager().getConfig();
    // Create Color Selector
    for (int i = 0; i < 4; ++i) {
        for (int j = 0; j < 4; ++j) {
            final int colorIndex = i * 4 + j;
            this.addDrawableChild(new ColorButton(this.width / 2 - 44 + j * 22, this.height / 2 - 88 + i * 22, 20, 20, null, DyeColor.byId(colorIndex).getColorComponents(), config.colorIndex == colorIndex, false, button -> {
                ClientMeasureBox.setColorIndex(colorIndex);
                final ClientMeasureBox currentBox = BlockMeterClient.getInstance().getCurrentBox();
                if (currentBox != null)
                    currentBox.setColor(DyeColor.byId(colorIndex));
                MinecraftClient.getInstance().setScreen((Screen) null);
            }));
        }
    }
    this.addDrawableChild(new ButtonWidget(this.width / 2 - BUTTONWIDTH / 2, this.height / 2 + 10, BUTTONWIDTH, 20, new TranslatableText("blockmeter.keepColor", new Object[] { new TranslatableText(config.incrementColor ? "options.off" : "options.on") }), button -> {
        config.incrementColor = !config.incrementColor;
        MinecraftClient.getInstance().setScreen((Screen) null);
        // Todo find a way to increment to a new Color if a box was created while
        // incrementColor was disabled
        BlockMeterClient.getConfigManager().save();
    }));
    this.addDrawableChild(new ButtonWidget(this.width / 2 - BUTTONWIDTH / 2, this.height / 2 + 32, BUTTONWIDTH, 20, new TranslatableText("blockmeter.diagonal", new Object[] { new TranslatableText(config.innerDiagonal ? "options.on" : "options.off") }), button -> {
        System.err.println("IDK WHAT YOU ARE DOING");
        config.innerDiagonal = !config.innerDiagonal;
        MinecraftClient.getInstance().setScreen((Screen) null);
        BlockMeterClient.getConfigManager().save();
    }));
    this.addDrawableChild(new ButtonWidget(this.width / 2 - BUTTONWIDTH / 2, this.height / 2 + 54, BUTTONWIDTH, 20, new TranslatableText("blockmeter.showOthers", new Object[] { new TranslatableText(config.showOtherUsersBoxes ? "options.on" : "options.off") }), button -> {
        System.err.println("IDK WHAT YOU ARE DOING");
        config.showOtherUsersBoxes = !config.showOtherUsersBoxes;
        MinecraftClient.getInstance().setScreen((Screen) null);
        BlockMeterClient.getConfigManager().save();
    }));
}
Also used : LiteralText(net.minecraft.text.LiteralText) Tessellator(net.minecraft.client.render.Tessellator) Color(me.shedaniel.math.Color) BlockMeterClient(win.baruna.blockmeter.BlockMeterClient) GameRenderer(net.minecraft.client.render.GameRenderer) MatrixStack(net.minecraft.client.util.math.MatrixStack) TranslatableText(net.minecraft.text.TranslatableText) ButtonWidget(net.minecraft.client.gui.widget.ButtonWidget) ModConfig(win.baruna.blockmeter.ModConfig) NarratorManager(net.minecraft.client.util.NarratorManager) Screen(net.minecraft.client.gui.screen.Screen) DrawMode(net.minecraft.client.render.VertexFormat.DrawMode) DyeColor(net.minecraft.util.DyeColor) RenderSystem(com.mojang.blaze3d.systems.RenderSystem) BufferBuilder(net.minecraft.client.render.BufferBuilder) MutableText(net.minecraft.text.MutableText) MinecraftClient(net.minecraft.client.MinecraftClient) ClientMeasureBox(win.baruna.blockmeter.measurebox.ClientMeasureBox) TextRenderer(net.minecraft.client.font.TextRenderer) VertexFormats(net.minecraft.client.render.VertexFormats) TranslatableText(net.minecraft.text.TranslatableText) Screen(net.minecraft.client.gui.screen.Screen) ClientMeasureBox(win.baruna.blockmeter.measurebox.ClientMeasureBox) ButtonWidget(net.minecraft.client.gui.widget.ButtonWidget) ModConfig(win.baruna.blockmeter.ModConfig)

Example 2 with ClientMeasureBox

use of win.baruna.blockmeter.measurebox.ClientMeasureBox in project BlockMeter by ModProg.

the class SelectBoxGui method init.

@Override
protected void init() {
    final int uiHeight = (boxes.length + 1) * (BUTTONHEIGHT + PADDING);
    for (int i = 0; i < boxes.length; i++) {
        final ClientMeasureBox box = boxes[i];
        final TranslatableText text = new TranslatableText("blockmeter.boxToString", new Object[] { box.getBlockStart().getX(), box.getBlockStart().getY(), box.getBlockStart().getZ(), box.getBlockEnd().getX(), box.getBlockEnd().getY(), box.getBlockEnd().getZ() });
        // text.setStyle(text.getStyle().withColor(TextColor.fromRgb(box.getColor().getSignColor())));
        this.addDrawableChild(new ColorButton(this.width / 2 - (BUTTONWIDTH) / 2, this.height / 2 - uiHeight / 2 + i * (BUTTONHEIGHT + PADDING), BUTTONWIDTH, BUTTONHEIGHT, text, box.getColor().getColorComponents(), false, true, button -> {
            box.loosenCorner(block);
            MinecraftClient.getInstance().setScreen((Screen) null);
        }));
    }
    this.addDrawableChild(new ButtonWidget(this.width / 2 - BUTTONWIDTH / 2, this.height / 2 - uiHeight / 2 + boxes.length * (BUTTONHEIGHT + PADDING) + PADDING, BUTTONWIDTH, BUTTONHEIGHT, new TranslatableText("gui.cancel"), button -> {
        MinecraftClient.getInstance().setScreen((Screen) null);
    }));
}
Also used : TranslatableText(net.minecraft.text.TranslatableText) NarratorManager(net.minecraft.client.util.NarratorManager) Screen(net.minecraft.client.gui.screen.Screen) MatrixStack(net.minecraft.client.util.math.MatrixStack) TranslatableText(net.minecraft.text.TranslatableText) MinecraftClient(net.minecraft.client.MinecraftClient) ButtonWidget(net.minecraft.client.gui.widget.ButtonWidget) BlockPos(net.minecraft.util.math.BlockPos) ClientMeasureBox(win.baruna.blockmeter.measurebox.ClientMeasureBox) Screen(net.minecraft.client.gui.screen.Screen) ClientMeasureBox(win.baruna.blockmeter.measurebox.ClientMeasureBox) ButtonWidget(net.minecraft.client.gui.widget.ButtonWidget)

Example 3 with ClientMeasureBox

use of win.baruna.blockmeter.measurebox.ClientMeasureBox 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 4 with ClientMeasureBox

use of win.baruna.blockmeter.measurebox.ClientMeasureBox in project BlockMeter by ModProg.

the class BlockMeterClient method onBlockMeterClick.

/**
 * Handles the right click Event for creating and confirming new Measuring-Boxes
 *
 * @param playerEntity the player object
 * @param hitResult
 * @return PASS if not active or wrong item, FAIL when successful, to not send
 *         the event to the server
 */
private ActionResult onBlockMeterClick(final PlayerEntity playerEntity, final BlockHitResult hitResult) {
    if (!this.active) {
        return ActionResult.PASS;
    }
    if (playerEntity.getMainHandStack().getItem().equals(this.currentItem)) {
        final BlockPos block = hitResult.getBlockPos();
        ClientMeasureBox currentBox = getCurrentBox();
        if (currentBox == null) {
            if (Screen.hasShiftDown()) {
                ClientMeasureBox[] boxes = findBoxes(block);
                switch(boxes.length) {
                    case 0:
                        break;
                    case 1:
                        boxes[0].loosenCorner(block);
                        break;
                    default:
                        this.selectBoxGui.setBoxes(boxes);
                        this.selectBoxGui.setBlock(block);
                        MinecraftClient.getInstance().setScreen((Screen) this.selectBoxGui);
                        break;
                }
            } else {
                final ClientMeasureBox box = ClientMeasureBox.getBox(block, playerEntity.world.getRegistryKey().getValue());
                this.boxes.add(box);
            }
        } else {
            currentBox.setBlockEnd(block);
            currentBox.setFinished();
            sendBoxList();
        }
        return ActionResult.FAIL;
    }
    return ActionResult.PASS;
}
Also used : ClientMeasureBox(win.baruna.blockmeter.measurebox.ClientMeasureBox) BlockPos(net.minecraft.util.math.BlockPos)

Example 5 with ClientMeasureBox

use of win.baruna.blockmeter.measurebox.ClientMeasureBox in project BlockMeter by ModProg.

the class ClientMeasureBoxTest method testPacketByteBuf.

@ParameterizedTest
@JSONSource(classes = { ParseBlockPos.class, ParseBlockPos.class, ParseIdentifier.class, ParseDyeColor.class, Boolean.class }, jsons = { "(1|2|0), (0|0|0), overworld, red, true", "(-1020|30|10), (-1000|100|20), end, blue, false", "(1|2|0), (0|256|0), overworld, red, true", "(1400|2|-6000), (1200|32|-5000), nether, red, true" })
void testPacketByteBuf(final BlockPos bp0, final BlockPos bp1, final Identifier dimension, final DyeColor color, final boolean finished) {
    final PacketByteBuf expectedBuf = new PacketByteBuf(Unpooled.buffer());
    expectedBuf.writeBlockPos(bp0);
    expectedBuf.writeBlockPos(bp1);
    expectedBuf.writeIdentifier(dimension);
    expectedBuf.writeInt(color.getId());
    expectedBuf.writeBoolean(finished);
    expectedBuf.writeInt(0);
    expectedBuf.writeInt(0);
    final ClientMeasureBox mb = ClientMeasureBox.fromPacketByteBuf(expectedBuf);
    final PacketByteBuf actualBuf = new PacketByteBuf(Unpooled.buffer());
    mb.writePacketBuf(actualBuf);
    expectedBuf.resetReaderIndex();
    assertThat(expectedBuf).isEqualTo(actualBuf);
}
Also used : PacketByteBuf(net.minecraft.network.PacketByteBuf) ClientMeasureBox(win.baruna.blockmeter.measurebox.ClientMeasureBox) JSONSource(de.modprog.blockmeter.util.JSONSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

ClientMeasureBox (win.baruna.blockmeter.measurebox.ClientMeasureBox)13 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)8 BlockMeterClient (win.baruna.blockmeter.BlockMeterClient)8 JSONSource (de.modprog.blockmeter.util.JSONSource)7 BlockPos (net.minecraft.util.math.BlockPos)6 TranslatableText (net.minecraft.text.TranslatableText)4 ParseBlockPos (de.modprog.blockmeter.util.parser.ParseBlockPos)3 MinecraftClient (net.minecraft.client.MinecraftClient)2 Screen (net.minecraft.client.gui.screen.Screen)2 ButtonWidget (net.minecraft.client.gui.widget.ButtonWidget)2 NarratorManager (net.minecraft.client.util.NarratorManager)2 MatrixStack (net.minecraft.client.util.math.MatrixStack)2 ModConfig (win.baruna.blockmeter.ModConfig)2 RenderSystem (com.mojang.blaze3d.systems.RenderSystem)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Toml4jConfigSerializer (me.shedaniel.autoconfig.serializer.Toml4jConfigSerializer)1 Color (me.shedaniel.math.Color)1 TextRenderer (net.minecraft.client.font.TextRenderer)1