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