Search in sources :

Example 1 with ModConfig

use of win.baruna.blockmeter.ModConfig 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 ModConfig

use of win.baruna.blockmeter.ModConfig in project BlockMeter by ModProg.

the class ClientMeasureBox method drawText.

/**
 * Draws a text with orientation and position
 *
 * @param stack
 * @param x
 * @param y
 * @param z
 * @param yaw
 * @param pitch
 * @param text
 * @param playerPos
 */
private void drawText(final MatrixStack stack, final double x, final double y, final double z, final float yaw, final float pitch, final String text, final Vec3d playerPos) {
    @SuppressWarnings("resource") final TextRenderer textRenderer = MinecraftClient.getInstance().textRenderer;
    final LiteralText literalText = new LiteralText(text);
    float size = 0.03f;
    final int constDist = 10;
    if (AutoConfig.getConfigHolder(ModConfig.class).getConfig().minimalLabelSize) {
        final float dist = (float) Math.sqrt((x - playerPos.x) * (x - playerPos.x) + (y - playerPos.y) * (y - playerPos.y) + (z - playerPos.z) * (z - playerPos.z));
        if (dist > constDist)
            size = dist * size / constDist;
    }
    stack.push();
    stack.translate(x, y + 0.15, z);
    stack.multiply(Vec3f.POSITIVE_Y.getDegreesQuaternion(180.0F - yaw));
    stack.multiply(Vec3f.POSITIVE_X.getDegreesQuaternion(-pitch));
    stack.scale(size, -size, 0.001f);
    final int width = textRenderer.getWidth(literalText);
    stack.translate((-width / 2), 0.0, 0.0);
    final Matrix4f model = stack.peek().getPositionMatrix();
    final BufferBuilder buffer = Tessellator.getInstance().getBuffer();
    int textColor = color.getSignColor();
    final ModConfig conf = BlockMeterClient.getConfigManager().getConfig();
    if (conf.backgroundForLabels) {
        final float[] colors = this.color.getColorComponents();
        buffer.begin(DrawMode.QUADS, VertexFormats.POSITION_COLOR);
        buffer.vertex(model, -1, -1, 0).color(colors[0], colors[1], colors[2], 0.8f).next();
        buffer.vertex(model, -1, 8, 0).color(colors[0], colors[1], colors[2], 0.8f).next();
        buffer.vertex(model, width, 8, 0).color(colors[0], colors[1], colors[2], 0.8f).next();
        buffer.vertex(model, width, -1, 0).color(colors[0], colors[1], colors[2], 0.8f).next();
        Tessellator.getInstance().draw();
        float[] components = color.getColorComponents();
        float luminance = (0.299f * components[0] + 0.587f * components[1] + 0.114f * components[2]);
        textColor = luminance < 0.4f ? DyeColor.WHITE.getSignColor() : DyeColor.BLACK.getSignColor();
    }
    final VertexConsumerProvider.Immediate immediate = VertexConsumerProvider.immediate(buffer);
    textRenderer.draw(literalText, 0.0f, 0.0f, textColor, // shadow
    !conf.backgroundForLabels, // matrix
    model, // draw buffer
    immediate, // seeThrough
    true, // backgroundColor => underlineColor,
    0, // light
    15728880);
    immediate.draw();
    stack.pop();
}
Also used : Matrix4f(net.minecraft.util.math.Matrix4f) BufferBuilder(net.minecraft.client.render.BufferBuilder) TextRenderer(net.minecraft.client.font.TextRenderer) LiteralText(net.minecraft.text.LiteralText) ModConfig(win.baruna.blockmeter.ModConfig) VertexConsumerProvider(net.minecraft.client.render.VertexConsumerProvider)

Example 3 with ModConfig

use of win.baruna.blockmeter.ModConfig in project BlockMeter by ModProg.

the class ClientMeasureBoxTest method getBMC.

@SuppressWarnings("unchecked")
private MockedStatic<BlockMeterClient> getBMC() {
    final MockedStatic<BlockMeterClient> client = Mockito.mockStatic(BlockMeterClient.class);
    final ConfigManager<ModConfig> configHolder = Mockito.mock(ConfigManager.class);
    when(configHolder.getConfig()).thenReturn(new ModConfig());
    client.when(BlockMeterClient::getConfigManager).thenReturn(configHolder);
    return client;
}
Also used : BlockMeterClient(win.baruna.blockmeter.BlockMeterClient) ModConfig(win.baruna.blockmeter.ModConfig)

Example 4 with ModConfig

use of win.baruna.blockmeter.ModConfig in project BlockMeter by ModProg.

the class ClientMeasureBoxTest method testGetMeasureBox.

@ParameterizedTest
@JSONSource(classes = { ParseBlockPos.class, ParseIdentifier.class, ParseDyeColor.class, Boolean.class }, jsons = { "(1|2|3), overworld, blue, true", "(-10|200|3123), nether, black, false", "(-112312|100|33), end, red, true" })
void testGetMeasureBox(final BlockPos bp, final Identifier id, final DyeColor color, final boolean incrementColor) {
    try (MockedStatic<BlockMeterClient> client = getBMC()) {
        final ModConfig config = BlockMeterClient.getConfigManager().getConfig();
        config.colorIndex = color.getId();
        config.incrementColor = incrementColor;
        final ClientMeasureBox box = ClientMeasureBox.getBox(bp, id);
        assertThat(box.getBlockStart()).isEqualTo(bp);
        assertThat(box.getBlockEnd()).isEqualTo(bp);
        assertThat(box.getDimension()).isEqualTo(id);
        assertThat(box.isFinished()).isFalse();
        assertThat(box.getColor()).isEqualTo(color);
        if (!incrementColor)
            assertThat(DyeColor.byId(config.colorIndex)).isEqualTo(color);
        else
            assertThat(DyeColor.byId(config.colorIndex)).isNotEqualTo(color);
    }
}
Also used : ClientMeasureBox(win.baruna.blockmeter.measurebox.ClientMeasureBox) BlockMeterClient(win.baruna.blockmeter.BlockMeterClient) ModConfig(win.baruna.blockmeter.ModConfig) JSONSource(de.modprog.blockmeter.util.JSONSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

ModConfig (win.baruna.blockmeter.ModConfig)4 BlockMeterClient (win.baruna.blockmeter.BlockMeterClient)3 TextRenderer (net.minecraft.client.font.TextRenderer)2 BufferBuilder (net.minecraft.client.render.BufferBuilder)2 LiteralText (net.minecraft.text.LiteralText)2 ClientMeasureBox (win.baruna.blockmeter.measurebox.ClientMeasureBox)2 RenderSystem (com.mojang.blaze3d.systems.RenderSystem)1 JSONSource (de.modprog.blockmeter.util.JSONSource)1 Color (me.shedaniel.math.Color)1 MinecraftClient (net.minecraft.client.MinecraftClient)1 Screen (net.minecraft.client.gui.screen.Screen)1 ButtonWidget (net.minecraft.client.gui.widget.ButtonWidget)1 GameRenderer (net.minecraft.client.render.GameRenderer)1 Tessellator (net.minecraft.client.render.Tessellator)1 VertexConsumerProvider (net.minecraft.client.render.VertexConsumerProvider)1 DrawMode (net.minecraft.client.render.VertexFormat.DrawMode)1 VertexFormats (net.minecraft.client.render.VertexFormats)1 NarratorManager (net.minecraft.client.util.NarratorManager)1 MatrixStack (net.minecraft.client.util.math.MatrixStack)1 MutableText (net.minecraft.text.MutableText)1