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();
}));
}
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();
}
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;
}
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);
}
}
Aggregations