Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
plugins {
id "fabric-loom" version "1.13-SNAPSHOT"
id 'net.fabricmc.fabric-loom-remap' version "1.14-SNAPSHOT"
// id "org.ajoberstar.grgit" version "3.1.1"
}

Expand Down
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.14.3-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-9.2.0-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
5 changes: 1 addition & 4 deletions gradlew

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions gradlew.bat

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

144 changes: 52 additions & 92 deletions src/main/java/win/baruna/blockmeter/BlockMeterClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import net.minecraft.client.network.ClientPlayerEntity;
import net.minecraft.client.option.KeyBinding;
import net.minecraft.client.util.InputUtil;
import net.minecraft.client.util.Window;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.text.Text;
Expand All @@ -40,10 +39,35 @@
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.stream.Collectors;


@SuppressWarnings("UnstableApiUsage")
public class BlockMeterClient implements ClientModInitializer, InputUtils {
/// Currently running Instance of BlockMeterClient
private static BlockMeterClient instance;
private static ConfigManager<ModConfig> confMgr;
/// The List of Measuring-Boxes currently created by the current User
private final List<ClientMeasureBox> boxes = new ArrayList<>();
/// The QuickMenu for changing of Color etc.
private final OptionsGui quickMenu;
/// The QuickMenu for selecting on of multiple Boxes.
private final SelectBoxGui selectBoxGui;
private final EditBoxGui editBoxGui;
/// The current state of the BlockMeter (activated/deactivated)
private boolean active;
/// The Item selected as BlockMeter
private Item currentItem;
/// A Map of Lists of Boxes currently created by other Users, with Text being the
/// Username
private Map<String, List<ClientMeasureBox>> otherUsersBoxes;

public BlockMeterClient() {
active = false;
quickMenu = new OptionsGui();
selectBoxGui = new SelectBoxGui();
editBoxGui = new EditBoxGui();
otherUsersBoxes = null;
BlockMeterClient.instance = this;
}

/// Currently running Instance of BlockMeterClient
public static BlockMeterClient getInstance() {
Expand All @@ -54,12 +78,6 @@ private static ClientPlayerEntity getPlayer() {
return Objects.requireNonNull(MinecraftClient.getInstance().player);
}

private static Window getWindow() {
return MinecraftClient.getInstance().getWindow();
}

private static ConfigManager<ModConfig> confMgr;

/// Accessor for the ModConfigManager
public static ConfigManager<ModConfig> getConfigManager() {
return confMgr;
Expand All @@ -69,35 +87,6 @@ public static ModConfig getConfig() {
return confMgr.getConfig();
}

/// The current state of the BlockMeter (activated/deactivated)
private boolean active;

/// The Item selected as BlockMeter
private Item currentItem;

/// The List of Measuring-Boxes currently created by the current User
private final List<ClientMeasureBox> boxes = new ArrayList<>();

/// A Map of Lists of Boxes currently created by other Users, with Text being the
/// Username
private Map<String, List<ClientMeasureBox>> otherUsersBoxes;

/// The QuickMenu for changing of Color etc.
private final OptionsGui quickMenu;

/// The QuickMenu for selecting on of multiple Boxes.
private final SelectBoxGui selectBoxGui;
private final EditBoxGui editBoxGui;

public BlockMeterClient() {
active = false;
quickMenu = new OptionsGui();
selectBoxGui = new SelectBoxGui();
editBoxGui = new EditBoxGui();
otherUsersBoxes = null;
BlockMeterClient.instance = this;
}

/**
* Disables BlockMeter
*/
Expand Down Expand Up @@ -147,8 +136,7 @@ public boolean clear() {
* Removes the last box
*/
public boolean undo() {
if (this.boxes.isEmpty())
return false;
if (this.boxes.isEmpty()) return false;

this.boxes.remove(this.boxes.size() - 1);
sendBoxList();
Expand All @@ -167,29 +155,20 @@ public void renderOverlay(WorldRenderContext context) {

final ModConfig cfg = AutoConfig.getConfigHolder(ModConfig.class).getConfig();

// MEH! but this seems to be needed to get the first background
// rectangle
// client.textRenderer.draw("XXX", stack, -100, -100, 0);

if (this.active || cfg.showBoxesWhenDisabled)
if ((this.active || cfg.showBoxesWhenDisabled)) {
if (cfg.showOtherUsersBoxes) {
if (otherUsersBoxes != null && !otherUsersBoxes.isEmpty()) {
this.otherUsersBoxes.forEach((playerText, boxList) -> boxList.forEach(box -> box.render(
context, currentDimension, Text.literal(playerText))));
this.otherUsersBoxes.forEach((playerText, boxList) -> boxList.forEach(box -> box.render(context, currentDimension, playerText)));
this.boxes.forEach(box -> {
if (!box.isFinished())
box.render(context, currentDimension);
if (!box.isFinished()) box.render(context, currentDimension);
});
}
if (!cfg.sendBoxes)
this.boxes.forEach(box -> {
if (box.isFinished())
box.render(context, currentDimension, getPlayer().getDisplayName());
else
box.render(context, currentDimension);
});
} else
this.boxes.forEach(box -> box.render(context, currentDimension));
if (!cfg.sendBoxes) this.boxes.forEach(box -> {
if (box.isFinished()) box.render(context, currentDimension, getPlayer().getDisplayName().getLiteralString());
else box.render(context, currentDimension);
});
} else this.boxes.forEach(box -> box.render(context, currentDimension));
}

}

Expand All @@ -203,8 +182,7 @@ public void onDisconnected(ClientPlayNetworkHandler clientPlayNetworkHandler, Mi
/**
* Gets Triggered when the Player connects to the Server
*/
private void onConnected(ClientPlayNetworkHandler clientPlayNetworkHandler, PacketSender packetSender,
MinecraftClient minecraftClient) {
private void onConnected(ClientPlayNetworkHandler clientPlayNetworkHandler, PacketSender packetSender, MinecraftClient minecraftClient) {
sendBoxList(); // to make the server send other user's boxes
}

Expand All @@ -220,18 +198,13 @@ public ClientMeasureBox getCurrentBox() {
@Override
public void onInitializeClient() {
var category = KeyBinding.Category.create(Identifier.of("category.blockmeter.key"));
var window = MinecraftClient.getInstance().getWindow();
final KeyBinding keyBinding = KeyBindingHelper.registerKeyBinding(new KeyBinding("key.blockmeter.assign",
InputUtil.Type.KEYSYM, GLFW.GLFW_KEY_M, category));
final KeyBinding keyBindingMenu = new KeyBinding("key.blockmeter.menu", InputUtil.Type.KEYSYM,
GLFW.GLFW_KEY_LEFT_ALT, category);
final KeyBinding keyBinding = KeyBindingHelper.registerKeyBinding(new KeyBinding("key.blockmeter.assign", InputUtil.Type.KEYSYM, GLFW.GLFW_KEY_M, category));
final KeyBinding keyBindingMenu = new KeyBinding("key.blockmeter.menu", InputUtil.Type.KEYSYM, GLFW.GLFW_KEY_LEFT_ALT, category);
KeyBindingHelper.registerKeyBinding(keyBindingMenu);

final KeyBinding keyBindingMeasureWithItem = new KeyBinding("key.blockmeter.useItem", -1,
category);
final KeyBinding keyBindingMeasureWithItem = new KeyBinding("key.blockmeter.useItem", -1, category);
KeyBindingHelper.registerKeyBinding(keyBindingMeasureWithItem);
final KeyBinding keyBindingMeasure = new KeyBinding("key.blockmeter.measure", InputUtil.Type.MOUSE,
GLFW.GLFW_MOUSE_BUTTON_4, category);
final KeyBinding keyBindingMeasure = new KeyBinding("key.blockmeter.measure", InputUtil.Type.MOUSE, GLFW.GLFW_MOUSE_BUTTON_4, category);
KeyBindingHelper.registerKeyBinding(keyBindingMeasure);

WorldRenderEvents.BEFORE_DEBUG_RENDER.register(this::renderOverlay);
Expand All @@ -248,21 +221,17 @@ public void onInitializeClient() {
ClientTickEvents.START_CLIENT_TICK.register(e -> {
if (keyBinding.wasPressed()) {
if (isShift()) {
if (undo())
getPlayer().sendMessage(Text.translatable("blockmeter.clearLast"), true);
if (undo()) getPlayer().sendMessage(Text.translatable("blockmeter.clearLast"), true);
} else if (isCtrl()) {
if (clear())
getPlayer().sendMessage(Text.translatable("blockmeter.clearAll"), true);
if (clear()) getPlayer().sendMessage(Text.translatable("blockmeter.clearAll"), true);
} else if (this.active) {
disable();
getPlayer().sendMessage(Text.translatable("blockmeter.toggle.off"), true);
} else {
active = true;
ItemStack itemStack = getPlayer().getMainHandStack();
currentItem = itemStack.getItem();
getPlayer().sendMessage(
Text.translatable("blockmeter.toggle.on", itemStack.getItemName()),
true);
getPlayer().sendMessage(Text.translatable("blockmeter.toggle.on", itemStack.getItemName()), true);
}
}

Expand Down Expand Up @@ -290,10 +259,10 @@ public void onInitializeClient() {
pressed = GLFW.glfwGetMouseButton(MinecraftClient.getInstance().getWindow().getHandle(), 1) == 1;
} else {
switch (key.getCategory()) {
case KEYSYM, SCANCODE -> pressed = GLFW.glfwGetKey(MinecraftClient.getInstance().getWindow()
.getHandle(), key.getCode()) == 1;
case MOUSE -> pressed = GLFW.glfwGetMouseButton(MinecraftClient.getInstance().getWindow()
.getHandle(), key.getCode()) == 1;
case KEYSYM, SCANCODE ->
pressed = GLFW.glfwGetKey(MinecraftClient.getInstance().getWindow().getHandle(), key.getCode()) == 1;
case MOUSE ->
pressed = GLFW.glfwGetMouseButton(MinecraftClient.getInstance().getWindow().getHandle(), key.getCode()) == 1;
}
}
if (pressed) {
Expand Down Expand Up @@ -322,12 +291,8 @@ public void onInitializeClient() {
return ActionResult.PASS;
});
AttackBlockCallback.EVENT.register(((player, world, hand, pos, direction) -> {
var inside = this.boxes.stream()
.filter(box -> box.miningRestriction == ClientMeasureBox.MiningRestriction.Inside)
.anyMatch(box -> !box.contains(pos));
var outside = this.boxes.stream()
.filter(box -> box.miningRestriction == ClientMeasureBox.MiningRestriction.Outside)
.anyMatch(box -> box.contains(pos));
var inside = this.boxes.stream().filter(box -> box.miningRestriction == ClientMeasureBox.MiningRestriction.Inside).anyMatch(box -> !box.contains(pos));
var outside = this.boxes.stream().filter(box -> box.miningRestriction == ClientMeasureBox.MiningRestriction.Outside).anyMatch(box -> box.contains(pos));
if (!isShift() && (inside || outside)) {
return ActionResult.FAIL;
} else {
Expand Down Expand Up @@ -377,8 +342,7 @@ private void onBlockMeterClick(final BlockPos block) {
break;
}
} else {
final ClientMeasureBox box = ClientMeasureBox.getBox(block,
getPlayer().getEntityWorld().getRegistryKey().getValue());
final ClientMeasureBox box = ClientMeasureBox.getBox(block, getPlayer().getEntityWorld().getRegistryKey().getValue());
this.boxes.add(box);
}
} else {
Expand All @@ -402,19 +366,15 @@ private ClientMeasureBox[] findBoxes(BlockPos block) {
* Sends BoxList to Server if enabled in the config
*/
private void sendBoxList() {
if (!AutoConfig.getConfigHolder(ModConfig.class).getConfig().sendBoxes)
return;
if (!AutoConfig.getConfigHolder(ModConfig.class).getConfig().sendBoxes) return;
ClientPlayNetworking.send(new BoxPayload(Map.of("", new ArrayList<>(boxes))));
}

/**
* handles the BoxList of other Players
*/
private void handleServerBoxList(BoxPayload payload, ClientPlayNetworking.Context context) {
context.client().executeTask(() -> otherUsersBoxes = payload.receivedBoxes().entrySet().stream()
.map(entry -> Pair.of(entry.getKey(), entry.getValue().stream().map(ClientMeasureBox::new)
.toList()))
.collect(Collectors.toMap(Pair::getKey, Pair::getValue)));
context.client().executeTask(() -> otherUsersBoxes = payload.receivedBoxes().entrySet().stream().map(entry -> Pair.of(entry.getKey(), entry.getValue().stream().map(ClientMeasureBox::new).toList())).collect(Collectors.toMap(Pair::getKey, Pair::getValue)));
}

}
2 changes: 0 additions & 2 deletions src/main/java/win/baruna/blockmeter/ModConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ public class ModConfig implements ConfigData {
@ConfigEntry.Gui.Tooltip(count = 3)
public boolean sendBoxes = true;
public boolean showBoxesWhenDisabled = false;
@ConfigEntry.Gui.Excluded
public boolean backgroundForLabels = true;

@ConfigEntry.BoundedDiscrete(max=200, min = 7)
public int reach = 50;
Expand Down
25 changes: 3 additions & 22 deletions src/main/java/win/baruna/blockmeter/gui/OptionsGui.java
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ public void onPress(AbstractInput input) {

ColorButton(final int x, final int y, final int width, final int height, final MutableText label, final Color color,
final boolean selected, boolean texture, PressAction onPress) {
super(x, y, width, height, Text.literal(""), onPress, DEFAULT_NARRATION_SUPPLIER);
super(x, y, width, height, net.minecraft.text.Text.empty(), onPress, DEFAULT_NARRATION_SUPPLIER);
this.selected = false;
this.color = color;
this.x = x + 2;
Expand All @@ -136,35 +136,15 @@ public void onPress(AbstractInput input) {
this.selected = selected;
this.text = label;
this.texture = texture;
// this.color = Color.ofRGBA(0.5f, 1f, 1f, 1f);
}

@Override
public void renderWidget(DrawContext context, final int int_1, final int int_2, final float float_1) {

protected void drawIcon(DrawContext context, int mouseX, int mouseY, float deltaTicks) {
context.drawGuiTexture(
RenderPipelines.GUI_TEXTURED,
TEXTURES.get(this.active, this.isSelected()),
x, y, width, height, color.getColor()
);
// Tessellator tessellator = Tessellator.getInstance();
// var bufferBuilder = tessellator.begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION_COLOR);
// RenderSystem.setShader(ShaderProgramKeys.POSITION_COLOR);
//
// int r = this.color.getRed();
// int g = this.color.getGreen();
// int b = this.color.getBlue();
// int a = texture ? 102 : 255;
// bufferBuilder.vertex(this.x - (texture ? 1 : 0), this.y - (texture ? 1 : 0), 0f)
// .color(r, g, b, a);
// bufferBuilder.vertex(this.x - (texture ? 1 : 0), this.y + this.height + (texture ? 1 : 0), 0f)
// .color(r, g, b, a);
// bufferBuilder.vertex(this.x + this.width + (texture ? 1 : 0), this.y + this.height + (texture ? 1 : 0), 0f)
// .color(r, g, b, a);
// bufferBuilder.vertex(this.x + this.width + (texture ? 1 : 0), this.y - (texture ? 1 : 0), 0f)
// .color(r, g, b, a);
// BufferRenderer.drawWithGlobalProgram(bufferBuilder.end());

if (text != null) {
boolean dark = (0.299f * color.getRed() + 0.587f * color.getBlue() + 0.114f * color.getRed()) / 255f < 0.8f;

Expand All @@ -180,5 +160,6 @@ public void renderWidget(DrawContext context, final int int_1, final int int_2,
context.drawText(textRenderer, text, x + width / 2 - text_width / 2, y + height / 2 - 4, 0, false);
}
}
//drawButton(context);
}
}
2 changes: 1 addition & 1 deletion src/main/java/win/baruna/blockmeter/gui/SelectBoxGui.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ protected void init() {

this.addDrawableChild(new ColorButton(this.width / 2 - (BUTTONWIDTH) / 2,
this.height / 2 - uiHeight / 2 + i * (BUTTONHEIGHT + PADDING), BUTTONWIDTH, BUTTONHEIGHT, text,
Color.ofOpaque(box.getColor().getMapColor().color), false, true, button -> {
Color.ofOpaque(box.getColor()), false, true, button -> {
BlockMeterClient.getInstance().editBox(box, block);
MinecraftClient.getInstance().setScreen(null);
}));
Expand Down
Loading
Loading