Skip to content

Commit

Permalink
backport to 1.14.4
Browse files Browse the repository at this point in the history
  • Loading branch information
Boxadactle committed Aug 19, 2024
1 parent ca73e06 commit 925ed8b
Show file tree
Hide file tree
Showing 41 changed files with 729 additions and 628 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## Changes
- Rewritten for 1.14.4
- Fixed config saving bug
33 changes: 29 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
plugins {
id 'dev.architectury.loom' version '1.6-SNAPSHOT' apply false
id 'dev.architectury.loom' version '1.7-SNAPSHOT' apply false
id 'architectury-plugin' version '3.4-SNAPSHOT'
id 'com.github.johnrengelman.shadow' version '8.1.1' apply false
id "me.shedaniel.unified-publishing" version "0.1.+"
id "com.github.breadmoirai.github-release" version "2.5.2"
}

architectury {
Expand Down Expand Up @@ -40,12 +41,12 @@ subprojects {
// If you remove this line, sources will not be generated.
withSourcesJar()

sourceCompatibility = JavaVersion.VERSION_21
targetCompatibility = JavaVersion.VERSION_21
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}

tasks.withType(JavaCompile).configureEach {
it.options.release = 21
it.options.release = 17
}

// Configure Maven publishing.
Expand All @@ -66,3 +67,27 @@ subprojects {
}
}
}

githubRelease {
owner = "Boxadactle"
repo = "BoxLib"
tagName = "$project.version"
targetCommitish = "latest"
releaseName = "BoxLib $project.version"
generateReleaseNotes = true
body = """BoxLib $project.version for Minecraft $project.minecraft_version
${new File(rootProject.rootDir, project.changelog_file).text}
"""
authorization = "Token ${System.getenv("GITHUB_TOKEN")}"

var files = []
for (String platform : project.enabled_platforms.split(',')) {
files += fileTree("$platform/build/libs") {
include "*$project.version*"
}
}
releaseAssets = files

// dryRun = true
}
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
package dev.boxadactle.debugkeybind;

import dev.boxadactle.boxlib.command.BCommandManager;
import dev.boxadactle.boxlib.config.BConfigClass;
import dev.boxadactle.boxlib.config.BConfigHandler;
import dev.boxadactle.boxlib.util.ModLogger;
import dev.boxadactle.debugkeybind.command.F3Command;
import dev.boxadactle.debugkeybind.keybind.KeybindConfig;
import net.minecraft.client.KeyMapping;
import net.minecraft.client.resources.language.I18n;

public class DebugKeybindMain {
public static final String MOD_NAME = "DebugKeybind";

public static final String MOD_ID = "debugkeybind";

public static final String VERSION = "9.0.0";
public static final String VERSION = "1.2.0";

public static final String VERSION_STRING = MOD_NAME + " v" + VERSION;

Expand All @@ -26,7 +24,7 @@ public static void init() {

CONFIG = BConfigHandler.registerConfig(KeybindConfig.class);

BCommandManager.register(F3Command.create());
// BCommandManager.register(F3Command.create());
}

}

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,15 +1,24 @@
package dev.boxadactle.debugkeybind.gui;

import dev.boxadactle.boxlib.gui.config.BOptionScreen;
import dev.boxadactle.boxlib.gui.config.widget.button.BCustomButton;
import dev.boxadactle.boxlib.gui.config.widget.label.BCenteredLabel;
import dev.boxadactle.boxlib.gui.config.widget.label.BLabel;
import dev.boxadactle.boxlib.util.ClientUtils;
import dev.boxadactle.debugkeybind.DebugKeybindMain;
import dev.boxadactle.debugkeybind.keybind.DebugKeybind;
import dev.boxadactle.debugkeybind.keybind.DebugKeybinds;
import dev.boxadactle.debugkeybind.keybind.GlobalKeybind;
import net.minecraft.client.KeyMapping;
import net.minecraft.client.gui.components.AbstractWidget;
import net.minecraft.client.gui.components.Button;
import net.minecraft.client.gui.screens.Screen;
import net.minecraft.client.resources.language.I18n;
import net.minecraft.network.chat.Component;

import java.util.List;
import java.util.function.Function;

public class DebugKeybindsScreen extends BOptionScreen {

KeybindEntry selectedEntry;
Expand All @@ -19,8 +28,8 @@ public DebugKeybindsScreen(Screen parent) {
}

@Override
protected Component getName() {
return Component.translatable("controls.keybinds.debug.title");
protected String getName() {
return I18n.get("controls.keybinds.debug.title");
}

@Override
Expand Down Expand Up @@ -48,28 +57,28 @@ protected void initFooter(int startX, int startY) {

refreshEntries();
});
resetButton.setMessage(Component.translatable("controls.resetAll"));
resetButton.setMessage(I18n.get("controls.resetAll"));

Button doneButton = createHalfDoneButton(startX, startY, (b) -> {
ClientUtils.setScreen(parent);

DebugKeybindMain.CONFIG.save();
});
doneButton.setX(startX + getButtonWidth(ButtonType.SMALL) + getPadding());
doneButton.x = (startX + getButtonWidth(ButtonType.SMALL) + getPadding());

addRenderableWidget(resetButton);
addRenderableWidget(doneButton);
addButton(resetButton);
addButton(doneButton);
}

@Override
protected void initConfigButtons() {
addConfigLine(new BCenteredLabel(Component.translatable("key.categories.debug")));
addConfigLine(new BCenteredLabel(I18n.get("key.categories.debug")));

for (DebugKeybind keybind : DebugKeybinds.getGlobalKeybinds()) {
addConfigLine(new KeybindEntry(keybind, this::setSelectedEntry, this::refreshEntries));
}

addConfigLine(new BCenteredLabel(Component.translatable("key.categories.debug_actions")));
addConfigLine(new BCenteredLabel(I18n.get("key.categories.debug_actions")));

for (DebugKeybind keybind : DebugKeybinds.getActionKeybinds()) {
addConfigLine(new KeybindEntry(keybind, this::setSelectedEntry, this::refreshEntries));
Expand Down Expand Up @@ -104,4 +113,97 @@ public boolean mouseClicked(double d, double e, int i) {

return super.mouseClicked(d, e, i);
}

@Override
public void onClose() {
super.onClose();

DebugKeybindMain.CONFIG.save();
}

public class KeybindEntry extends ConfigEntry {
public DebugKeybind keybind;

public BLabel label;
public KeybindButton keybindButton;
public ResetButton resetButton;

Runnable globalRefresh;

public KeybindEntry(DebugKeybind keybind, Function<KeybindEntry, Boolean> onSelect, Runnable refresh) {
label = new BLabel(keybind.getTranslation());
keybindButton = new KeybindButton(keybind, () -> onSelect.apply(this), DebugKeybindsScreen.this::renderTooltip);
resetButton = new ResetButton(keybind, refresh);

this.keybind = keybind;

refresh();

this.globalRefresh = refresh;
}

@Override
public List<? extends AbstractWidget> getWidgets() {
return List.of(label, keybindButton, resetButton);
}

@Override
public boolean isInvalid() {
return false;
}

public void updateKey(int code) {
keybindButton.update(code);

refresh();
globalRefresh.run();
}

public void resetKey() {
keybindButton.resetKey();

globalRefresh.run();
}

public void refresh() {
resetButton.refresh();

if (keybind.isUnbound()) {
keybindButton.updateConflicts(List.of());
return;
}

List<String> collisions = keybind.checkConflicts(DebugKeybinds.toList());

if (keybind instanceof GlobalKeybind) {
KeyMapping[] mappings = ClientUtils.getOptions().keyMappings.clone();

collisions.addAll(((GlobalKeybind) keybind).checkMinecraftConflicts(List.of(mappings)));
}

keybindButton.updateConflicts(collisions);
}

@Override
public void render(int index, int y, int x, int entryWidth, int entryHeight, int mouseX, int mouseY, boolean hovered, float tickDelta) {
int keybindWidth = 75;
int resetWidth = 50;
int padding = 2;

label.x = (x - 25);
label.y = (y);
label.setWidth(entryWidth - keybindWidth - resetWidth - padding);
label.render(mouseX, mouseY, tickDelta);

keybindButton.x = (x + entryWidth - keybindWidth - resetWidth - padding);
keybindButton.y =(y);
keybindButton.setWidth(keybindWidth);
keybindButton.render(mouseX, mouseY, tickDelta);

resetButton.x = (x + entryWidth - resetWidth);
resetButton.y = (y);
resetButton.setWidth(resetWidth);
resetButton.render(mouseX, mouseY, tickDelta);
}
}
}
Loading

0 comments on commit 925ed8b

Please sign in to comment.