Skip to content

Commit

Permalink
Feat: Note taking
Browse files Browse the repository at this point in the history
This took 5 hours ;-;
closes #49
  • Loading branch information
showierdata9978 committed Aug 7, 2024
1 parent 62a6960 commit aa2bc47
Show file tree
Hide file tree
Showing 9 changed files with 239 additions and 24 deletions.
5 changes: 5 additions & 0 deletions DEVELOPMENT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Pickaxe mod needs a couple mods added to the runtime manually while in development. Those mods are as folows:

- https://modrinth.com/mod/auth-me (any version)
- https://modrinth.com/mod/replaymod/ (newest 1.20.4) (to check for regressions)
- https://modrinth.com/mod/imgui-mc/version/1.20.4-1.0.7
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,20 @@

A mod for the game ⛏️ on Minecraft Diamondfire.

I dont have any ideas for this mod.
I don't have any ideas for this mod.

## Features

- @Help command
- Relative plot coords from spawn
- Relative plot cords from spawn
- Coins covering the hunger bar
- XP Bar can be any supported Boss bar
- @up keybind (bound to R by default)
- Sage Icon
- Overclock icon
- itemlock Icon
- Chest Cooldown Timer (CCT)
- Forge Timer
- Note-taking (bound to N by default)
- Plot ad hider
- Chat Stacking

Expand All @@ -29,16 +29,16 @@ I dont have any ideas for this mod.
- Auto /c l (Disabled by default)
- Icon x, y (0, 0) by default
- Enable/disable icons (off by default)
- Keybinds
- Keybindings
- @up (default R)
- Various CCT Options
- Enable / desable plot ads
- Notes (Default N)
- Enable / disable plot ads

## Acknowledgements

- Sputt for creating Pickaxe
- Heptor / baltdev for creating the mod before this

- AlignedCookie88 for updating imgui-mc to 1.20.4 (and being a DF player!)

## Screenshots

Expand Down
14 changes: 12 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,17 @@ repositories {
// Loom adds the essential maven repositories to download Minecraft and libraries from automatically.
// See https://docs.gradle.org/current/userguide/declaring_repositories.html
// for more information about repositories.
exclusiveContent {
forRepository {
maven {
name = "Modrinth"
url = "https://api.modrinth.com/maven"
}
}
filter {
includeGroup "maven.modrinth"
}
}

maven {
name 'Xander Maven'
Expand All @@ -28,7 +39,6 @@ repositories {
url 'https://maven.terraformersmc.com/releases/'
}


}

dependencies {
Expand All @@ -48,7 +58,7 @@ dependencies {
exclude(group: "com.twelvemonkeys.imageio")
}
modImplementation "com.terraformersmc:modmenu:${project.modmenu_version}"

modImplementation "maven.modrinth:imgui-mc:1.20.4-1.0.7"
// Uncomment the following line to enable the deprecated Fabric API modules.
// These are included in the Fabric API production distribution and allow you to update your mod to the latest modules at a later more convenient time.

Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ org.gradle.parallel=true

minecraft_version=1.20.4
yarn_mappings=1.20.4+build.3
loader_version=0.15.9
loader_version=0.15.11


# Mod Properties
Expand Down
19 changes: 15 additions & 4 deletions src/main/java/tech/showierdata/pickaxe/Pickaxe.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package tech.showierdata.pickaxe;

import imgui.ImGui;
import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
import net.fabricmc.fabric.api.client.keybinding.v1.KeyBindingHelper;
Expand Down Expand Up @@ -47,6 +48,8 @@
import tech.showierdata.pickaxe.server.CommandHelper;
import tech.showierdata.pickaxe.server.Plot;
import tech.showierdata.pickaxe.server.Regexps;
import tech.showierdata.pickaxe.ui.NoteEditor;
import xyz.breadloaf.imguimc.Imguimc;

import java.awt.*;
import java.util.ArrayList;
Expand All @@ -70,6 +73,7 @@ public class Pickaxe implements ModInitializer {


public static final Identifier COLORS = new Identifier("pickaxe", "textures/gui/colors.png");
public NoteEditor noteEditor;

public static Pickaxe getInstance() {
return instance;
Expand Down Expand Up @@ -245,6 +249,7 @@ public void onInitialize() {

LOGGER.info(String.format("Starting %s....", Constants.PICKAXE_STRING));

this.noteEditor = new NoteEditor(this);
register_callbacks();

// send a get request to https://api.modrinth.com/v2/project/{id|slug}/version
Expand Down Expand Up @@ -399,9 +404,13 @@ private void drawMDT(DrawContext context, TextRenderer renderer) {

private void register_callbacks() {
// @up keybind
KeyBinding keyBinding = KeyBindingHelper.registerKeyBinding(
KeyBinding upKeybind = KeyBindingHelper.registerKeyBinding(
new KeyBinding("key.pickaxe.up", InputUtil.Type.KEYSYM, GLFW.GLFW_KEY_R, "category.pickaxe.keybinds"));

KeyBinding notesKeybind = KeyBindingHelper.registerKeyBinding(
new KeyBinding("key.pickaxe.notes", InputUtil.Type.KEYSYM, GLFW.GLFW_KEY_N, "category.pickaxe.keybinds")
);

ClientTickEvents.END_CLIENT_TICK.register(client -> {
if (!isInPickaxe()) {
return;
Expand All @@ -424,11 +433,13 @@ private void register_callbacks() {
}


//disable keybind in all areas except main mine; mesa mine; and sputtrooms
while (keyBinding.wasPressed()) {
while (upKeybind.wasPressed()) {
client.player.networkHandler.sendChatMessage("@up");
}


if (notesKeybind.wasPressed()) {
notesKeybind.setPressed(false); // prevent spam
noteEditor.flip();
}
});

Expand Down
20 changes: 20 additions & 0 deletions src/main/java/tech/showierdata/pickaxe/mixin/TextFieldMixin.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package tech.showierdata.pickaxe.mixin;

import net.minecraft.client.gui.widget.TextFieldWidget;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import tech.showierdata.pickaxe.Pickaxe;

@Mixin(TextFieldWidget.class)
public class TextFieldMixin {
@Inject(method = "isActive", at = @At("HEAD"), cancellable = true)
protected void write(CallbackInfoReturnable<Boolean> cir) {
if (Pickaxe.getInstance().noteEditor.isFocused) {
cir.setReturnValue(false);
cir.cancel();
}
}

}
169 changes: 169 additions & 0 deletions src/main/java/tech/showierdata/pickaxe/ui/NoteEditor.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
package tech.showierdata.pickaxe.ui;

import imgui.ImGui;

import imgui.ImVec2;
import imgui.extension.texteditor.TextEditor;
import imgui.flag.ImGuiCond;
import imgui.flag.ImGuiWindowFlags;
import net.minecraft.client.MinecraftClient;
import org.lwjgl.glfw.GLFW;
import tech.showierdata.pickaxe.Pickaxe;
import xyz.breadloaf.imguimc.interfaces.Renderable;
import xyz.breadloaf.imguimc.interfaces.Theme;
import xyz.breadloaf.imguimc.theme.ImGuiDarkTheme;
import xyz.breadloaf.imguimc.Imguimc;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;

public class NoteEditor implements Renderable {
private final TextEditor textEditor;
private final Pickaxe pickaxe;
public String text;
public boolean isOpen;
public boolean isFocused = false;
private boolean helpScreenOpen = false;

public static Path SAVE_FILE_PATH = Path.of("./config/pickaxe.notes.txt");

public NoteEditor(Pickaxe pickaxe) {
if (Files.exists(SAVE_FILE_PATH)) {
try {
this.text = Files.readString(SAVE_FILE_PATH);
} catch (IOException e) {
this.text = "Failed to load saved notes!\n\n" + e;
Pickaxe.LOGGER.error("", e);
}
} else {
this.text = "";
}
this.textEditor = new TextEditor();
this.textEditor.setText(this.text);
this.pickaxe = pickaxe;
this.isOpen = false;
}

@Override
public String getName() {
return "Note Editor - Pickaxe Mod";
}

public void flip() {
if (this.isOpen) {
Imguimc.pullRenderable(this);
} else {
Imguimc.pushRenderable(this);
MinecraftClient client = MinecraftClient.getInstance();
ImGui.setNextWindowSize(client.getWindow().getHeight(), client.getWindow().getWidth() / 5f, ImGuiCond.Always);
ImGui.setNextWindowPos(0, 0, ImGuiCond.Always);
ImGui.setWindowFocus();
this.textEditor.setHandleKeyboardInputs(true);

}
this.isOpen = !this.isOpen;
}

public void save() {
try {
if (Files.notExists(SAVE_FILE_PATH)) {
Files.createFile(SAVE_FILE_PATH);
}
Files.writeString(SAVE_FILE_PATH, this.text);
ImGui.text("Saved!");
} catch (IOException e) {
Pickaxe.LOGGER.error("", e);
ImGui.text("Failed to save :( (check logs for details)");
}
}

public String getId() {
return "pickmod-notes";
}

@Override
public Theme getTheme() {
return new ImGuiDarkTheme();
}

private void renderHelpPage(int id) {
ImGui.begin("Help - Pickaxe Mod", ImGuiWindowFlags.AlwaysAutoResize);
String text = """
Hi, Welcome to pickaxe mod's note editor! Make sure to save your data!
Having the editor within the game screen is unsupported.
This UI was made with imgui-java (v1.86.12) with imgui-mc (v1.0.7)
""";
ImVec2 textSize = ImGui.calcTextSize(text);
ImGui.text(text);
ImGui.end();
}

private void renderTabBar() {
if (ImGui.button("Help")) {
helpScreenOpen = !helpScreenOpen;
}

if (ImGui.beginMenu("Edit")) {
if (ImGui.menuItem("Undo", "CTRL+Z"))
textEditor.undo(1);
if (ImGui.menuItem("Redo", "CTRL+Y"))
textEditor.redo(1);
ImGui.separator();
if (ImGui.menuItem("Cut", "CTRL+X"))
textEditor.cut();
if (ImGui.menuItem("Copy", "CTRL+C"))
textEditor.copy();
if (ImGui.menuItem("Paste", "CTRL+V"))
textEditor.paste();
ImGui.endMenu();
}
if (ImGui.button("Save")) {
ImGui.openPopup("saved");
}
if (ImGui.beginPopup("saved")) {
save();
ImGui.endPopup();
}
}

@Override
public void render() {

if (!this.pickaxe.isInPickaxe()) {
Imguimc.pullRenderableAfterRender(this);
this.isOpen = false;
}

MinecraftClient client = MinecraftClient.getInstance();


ImGui.begin(getName(), ImGuiWindowFlags.MenuBar);
this.isFocused = ImGui.isWindowFocused(ImGui.getID(getName()));

if (ImGui.beginMenuBar()) {
renderTabBar();
ImGui.endMenuBar();
};
this.textEditor.render(getName());

if (ImGui.isKeyPressed(GLFW.GLFW_KEY_BACKSPACE)) {
this.textEditor.delete();
}

if (this.textEditor.isTextChanged()) {
this.text = this.textEditor.getText();
}

int id = ImGui.getWindowDockID();
ImGui.end();


if (helpScreenOpen) renderHelpPage(id);


}

}
5 changes: 3 additions & 2 deletions src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,13 @@
"pickaxe.mixins.json"
],
"depends": {
"fabricloader": ">=0.15.9",
"fabricloader": ">=0.15.11",
"java": ">=17",
"minecraft": "~1.20.4",

"fabric-api": "*",
"yet_another_config_lib_v3": "*"
"yet_another_config_lib_v3": "*",
"imguimc": "1.20.4-1.0.7"
},
"suggests": {
"code-client": "*"
Expand Down
15 changes: 7 additions & 8 deletions src/main/resources/pickaxe.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,14 @@
"ClientPlayNetworkHandlerMixin",
"HandledScreenMixin",
"InGameHudMixin",
"PlayerHudListMixin"
],
"injectors": {
"defaultRequire": 1
},
"client": [
"PlayerHudListMixin",
"ChatHudMixin",
"TextFieldMixin",
"OtherClientPlayerEntityMixin",
"PlayerHudClassMixin",
"ChatHudMixin",
"SoundMixin"
]
],
"injectors": {
"defaultRequire": 1
}
}

0 comments on commit aa2bc47

Please sign in to comment.