Skip to content
Merged

2.10 #68

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
7 changes: 1 addition & 6 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
plugins {
id "fabric-loom" version "1.10-SNAPSHOT"
id "fabric-loom" version "1.13-SNAPSHOT"
// id "org.ajoberstar.grgit" version "3.1.1"
}

Expand All @@ -14,9 +14,6 @@ repositories {
maven { url = 'https://masa.dy.fi/maven' }
}

sourceCompatibility = 1.16
targetCompatibility = 1.16

ext.Version = new Properties()
Version.load(file("version.properties").newReader())

Expand All @@ -28,8 +25,6 @@ Versions.load(file("Versionfiles/${Version['minecraftVersion']}.properties").new

version = "${project.projectVersion}-${Version['minecraftVersion']}"

archivesBaseName = "blockmeter"

def getBranch() {
if (System.getenv().GIT_BRANCH) {
def branch = System.getenv().GIT_BRANCH
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.12-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.14.3-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
9 changes: 4 additions & 5 deletions gradlew

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

4 changes: 2 additions & 2 deletions gradlew.bat

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

1 change: 0 additions & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
pluginManagement {
repositories {
jcenter()
maven {
name = "Fabric"
url = "https://maven.fabricmc.net/"
Expand Down
80 changes: 30 additions & 50 deletions src/main/java/win/baruna/blockmeter/BlockMeterClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,18 @@
import net.fabricmc.fabric.api.client.keybinding.v1.KeyBindingHelper;
import net.fabricmc.fabric.api.client.networking.v1.ClientPlayConnectionEvents;
import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking;
import net.fabricmc.fabric.api.client.rendering.v1.WorldRenderContext;
import net.fabricmc.fabric.api.client.rendering.v1.WorldRenderEvents;
import net.fabricmc.fabric.api.client.rendering.v1.world.WorldRenderContext;
import net.fabricmc.fabric.api.client.rendering.v1.world.WorldRenderEvents;
import net.fabricmc.fabric.api.event.player.AttackBlockCallback;
import net.fabricmc.fabric.api.event.player.UseBlockCallback;
import net.fabricmc.fabric.api.event.player.UseItemCallback;
import net.fabricmc.fabric.api.networking.v1.PacketSender;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.network.ClientPlayNetworkHandler;
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 @@ -41,17 +41,11 @@
import java.util.stream.Collectors;

@SuppressWarnings("UnstableApiUsage")
public class BlockMeterClient implements ClientModInitializer {
/**
* Currently running Instance of BlockMeterClient
*/
public class BlockMeterClient implements ClientModInitializer, InputUtils {
/// Currently running Instance of BlockMeterClient
private static BlockMeterClient instance;

/**
* Accessor for the BlockMeterClient Instance
*
* @return running Instance of BlockMeterClient
*/
/// Currently running Instance of BlockMeterClient
public static BlockMeterClient getInstance() {
return instance;
}
Expand All @@ -60,54 +54,38 @@ private static ClientPlayerEntity getPlayer() {
return Objects.requireNonNull(MinecraftClient.getInstance().player);
}

/**
* ConfigManager of BlockMeter
*/
private static Window getWindow() {
return MinecraftClient.getInstance().getWindow();
}

private static ConfigManager<ModConfig> confMgr;

/**
* Accessor for the ModConfigManager
*
* @return ConfigManager for handling the Config
*/
/// Accessor for the ModConfigManager
public static ConfigManager<ModConfig> getConfigManager() {

return confMgr;
}

public static ModConfig getConfig() {
return confMgr.getConfig();
}

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

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

/**
* The List of Measuring-Boxes currently created by the current User
*/
/// 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
*/
/// 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.
*/
/// The QuickMenu for changing of Color etc.
private final OptionsGui quickMenu;

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

Expand Down Expand Up @@ -185,7 +163,7 @@ public boolean undo() {
}

public void renderOverlay(WorldRenderContext context) {
final Identifier currentDimension = getPlayer().clientWorld.getRegistryKey().getValue();
final Identifier currentDimension = getPlayer().getEntityWorld().getRegistryKey().getValue();

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

Expand Down Expand Up @@ -241,17 +219,19 @@ 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.blockmeter.key"));
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.blockmeter.key");
GLFW.GLFW_KEY_LEFT_ALT, category);
KeyBindingHelper.registerKeyBinding(keyBindingMenu);

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

WorldRenderEvents.BEFORE_DEBUG_RENDER.register(this::renderOverlay);
Expand All @@ -267,10 +247,10 @@ public void onInitializeClient() {
confMgr = (ConfigManager<ModConfig>) AutoConfig.register(ModConfig.class, Toml4jConfigSerializer::new);
ClientTickEvents.START_CLIENT_TICK.register(e -> {
if (keyBinding.wasPressed()) {
if (Screen.hasShiftDown()) {
if (isShift()) {
if (undo())
getPlayer().sendMessage(Text.translatable("blockmeter.clearLast"), true);
} else if (Screen.hasControlDown()) {
} else if (isCtrl()) {
if (clear())
getPlayer().sendMessage(Text.translatable("blockmeter.clearAll"), true);
} else if (this.active) {
Expand Down Expand Up @@ -348,7 +328,7 @@ public void onInitializeClient() {
var outside = this.boxes.stream()
.filter(box -> box.miningRestriction == ClientMeasureBox.MiningRestriction.Outside)
.anyMatch(box -> box.contains(pos));
if (!Screen.hasShiftDown() && (inside || outside)) {
if (!isShift() && (inside || outside)) {
return ActionResult.FAIL;
} else {
return ActionResult.PASS;
Expand Down Expand Up @@ -382,7 +362,7 @@ private void onBlockMeterClick(final BlockPos block) {
ClientMeasureBox currentBox = getCurrentBox();

if (currentBox == null) {
if (Screen.hasShiftDown()) {
if (isShift()) {
ClientMeasureBox[] boxes = findBoxes(block);
switch (boxes.length) {
case 0:
Expand All @@ -398,7 +378,7 @@ private void onBlockMeterClick(final BlockPos block) {
}
} else {
final ClientMeasureBox box = ClientMeasureBox.getBox(block,
getPlayer().getWorld().getRegistryKey().getValue());
getPlayer().getEntityWorld().getRegistryKey().getValue());
this.boxes.add(box);
}
} else {
Expand Down
26 changes: 26 additions & 0 deletions src/main/java/win/baruna/blockmeter/InputUtils.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package win.baruna.blockmeter;

import net.minecraft.client.MinecraftClient;
import net.minecraft.client.util.InputUtil;
import net.minecraft.client.util.Window;

import java.util.function.Function;
import java.util.function.Supplier;

public interface InputUtils {
default Window window() {
return MinecraftClient.getInstance().getWindow();
}

default boolean isKey(int key) {
return InputUtil.isKeyPressed(window(), key);
}

default boolean isShift() {
return isKey(InputUtil.GLFW_KEY_LEFT_SHIFT) || isKey(InputUtil.GLFW_KEY_RIGHT_SHIFT);
}

default boolean isCtrl() {
return isKey(InputUtil.GLFW_KEY_LEFT_CONTROL) || isKey(InputUtil.GLFW_KEY_RIGHT_CONTROL);
}
}
1 change: 0 additions & 1 deletion src/main/java/win/baruna/blockmeter/gui/EditBoxGui.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ protected void init() {

@Override
public void render(DrawContext context, int mouseX, int mouseY, float delta) {
super.renderBackground(context, mouseX, mouseY, delta);
super.render(context, mouseX, mouseY, delta);
}

Expand Down
6 changes: 3 additions & 3 deletions src/main/java/win/baruna/blockmeter/gui/OptionsGui.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import net.minecraft.client.gui.screen.ButtonTextures;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.widget.ButtonWidget;
import net.minecraft.client.input.AbstractInput;
import net.minecraft.client.render.*;
import net.minecraft.client.util.NarratorManager;
import net.minecraft.text.MutableText;
Expand Down Expand Up @@ -90,7 +91,6 @@ protected void init() {

@Override
public void render(DrawContext context, int mouseX, int mouseY, float delta) {
// super.renderBackground(context, mouseX, mouseY, delta);
super.render(context, mouseX, mouseY, delta);
}

Expand All @@ -115,12 +115,12 @@ class ColorButton extends ButtonWidget {
);

@Override
public void onPress() {
public void onPress(AbstractInput input) {
System.out.println(color.getRed());
System.out.println(color.getGreen());
System.out.println(color.getBlue());
System.err.println("IK WHAT YOU ARE DOING");
super.onPress();
super.onPress(input);
}

ColorButton(final int x, final int y, final int width, final int height, final MutableText label, final Color color,
Expand Down
1 change: 0 additions & 1 deletion src/main/java/win/baruna/blockmeter/gui/SelectBoxGui.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ protected void init() {

@Override
public void render(DrawContext context, int mouseX, int mouseY, float delta) {
super.renderBackground(context, mouseX, mouseY, delta);
super.render(context, mouseX, mouseY, delta);
}

Expand Down
Loading
Loading