From e37d2cc88298d46871554d7902307d8685905fb1 Mon Sep 17 00:00:00 2001 From: kr1viah_ <85935121+kr1viah@users.noreply.github.com> Date: Tue, 27 Aug 2024 14:04:01 +0200 Subject: [PATCH] Add files via upload --- .../client/CustomInstruments.java | 3 +- .../kr1v/noteblockrecorder/client/Header.java | 3 -- .../noteblockrecorder/client/Instruments.java | 9 ------ .../client/JsonStructure.java | 3 -- .../noteblockrecorder/client/JsonWriter.java | 30 ++++++++----------- .../kr1v/noteblockrecorder/client/Layer.java | 13 ++++---- .../kr1v/noteblockrecorder/client/Pitch.java | 5 +--- src/main/resources/fabric.mod.json | 2 +- 8 files changed, 24 insertions(+), 44 deletions(-) diff --git a/src/client/java/org/kr1v/noteblockrecorder/client/CustomInstruments.java b/src/client/java/org/kr1v/noteblockrecorder/client/CustomInstruments.java index cf18585..e66fc34 100644 --- a/src/client/java/org/kr1v/noteblockrecorder/client/CustomInstruments.java +++ b/src/client/java/org/kr1v/noteblockrecorder/client/CustomInstruments.java @@ -10,11 +10,10 @@ public class CustomInstruments { // Constructor public CustomInstruments(String name, int sound_id) { this.name = name; - this.filePath = name + ".ogg"; //e + this.filePath = name + ".ogg"; this.pitch = 45; this.pressKeys = false; this.sound_id = Integer.toString(sound_id); } public String getName() { return name; } - } diff --git a/src/client/java/org/kr1v/noteblockrecorder/client/Header.java b/src/client/java/org/kr1v/noteblockrecorder/client/Header.java index 174aab4..96971d4 100644 --- a/src/client/java/org/kr1v/noteblockrecorder/client/Header.java +++ b/src/client/java/org/kr1v/noteblockrecorder/client/Header.java @@ -1,6 +1,5 @@ package org.kr1v.noteblockrecorder.client; -// Class to represent the header part of the JSON public class Header { private final int length; private final int file_version; @@ -51,8 +50,6 @@ public Header(int length, int file_version, int vani_inst, int height, String na this.loop_max = loop_max; this.loop_start = loop_start; } - - // Getters (if needed) public int getLength() { return length; } public int getFileVersion() { return file_version; } public int getVaniInst() { return vani_inst; } diff --git a/src/client/java/org/kr1v/noteblockrecorder/client/Instruments.java b/src/client/java/org/kr1v/noteblockrecorder/client/Instruments.java index 8e0f60f..d6a4fd1 100644 --- a/src/client/java/org/kr1v/noteblockrecorder/client/Instruments.java +++ b/src/client/java/org/kr1v/noteblockrecorder/client/Instruments.java @@ -46,29 +46,20 @@ public static int main(RegistryEntry instrument) { } HashSet seenSounds = new HashSet<>(); - System.out.println(instrument.value().getId().getPath()); int soundId = instrument.value().getId().hashCode(); - System.out.println("translationKey: " + instrument.value().getId().toTranslationKey()); - System.out.println("translationKeyShort: " + instrument.value().getId().toShortTranslationKey()); - System.out.println("type: " + instrument.getType()); CustomInstruments thingToBeAdded = new CustomInstruments(instrument.value().getId().getPath(), soundId); customSounds.add(thingToBeAdded); for (int i = 0; i < customSounds.size(); i++) { if (Objects.equals(customSounds.get(i).getName(), thingToBeAdded.getName())) { soundId = i + 16; - System.out.println("this ones it: " + i); break; } - else { - System.out.println("this ones not it: " + i); - } } customSounds.removeLast(); thingToBeAdded.sound_id = Integer.toString(soundId); customSounds.add(thingToBeAdded); customSounds.removeIf(thingToBeAdded2 -> !seenSounds.add(String.valueOf(thingToBeAdded2.sound_id))); - System.out.println("soundId: " + soundId); return soundId; } public static List getCustomInstruments() { diff --git a/src/client/java/org/kr1v/noteblockrecorder/client/JsonStructure.java b/src/client/java/org/kr1v/noteblockrecorder/client/JsonStructure.java index 0ff3bb0..1d4ee6a 100644 --- a/src/client/java/org/kr1v/noteblockrecorder/client/JsonStructure.java +++ b/src/client/java/org/kr1v/noteblockrecorder/client/JsonStructure.java @@ -2,14 +2,12 @@ import java.util.List; -// Class to represent the entire JSON structure public class JsonStructure { private Header header; private List notes; private List layers; private List custom_instruments; - // Constructor public JsonStructure(Header header, List notes, List layers, List custom_instruments) { this.header = header; this.notes = notes; @@ -17,7 +15,6 @@ public JsonStructure(Header header, List notes, List layers, List getNotes() { return notes; } public List getLayers() { return layers; } diff --git a/src/client/java/org/kr1v/noteblockrecorder/client/JsonWriter.java b/src/client/java/org/kr1v/noteblockrecorder/client/JsonWriter.java index 1f91fb6..872efd8 100644 --- a/src/client/java/org/kr1v/noteblockrecorder/client/JsonWriter.java +++ b/src/client/java/org/kr1v/noteblockrecorder/client/JsonWriter.java @@ -2,6 +2,7 @@ import com.google.gson.Gson; import com.google.gson.GsonBuilder; +import net.minecraft.client.MinecraftClient; import java.io.FileWriter; import java.io.IOException; @@ -12,23 +13,23 @@ public class JsonWriter { static List notes = new ArrayList<>(); static List layers = new ArrayList<>(); static List custom_instruments = Instruments.getCustomInstruments(); + static String name = "name"; public static void main(int highestlayer) { - // Create some sample notes -// notes.add(new Note(0, 6, 1, 36, 100, 0, 1)); -// notes.add(new Note(0, 1, 0, 43, 20, -70, 1)); -// notes.add(new Note(0, 2, 0, 48, 20, -70, 1)); - + assert MinecraftClient.getInstance().player != null; + if (MinecraftClient.getInstance().player.getName() != null) { + name = MinecraftClient.getInstance().player.getName().getString(); + } // Create a header Header header = new Header( notes.getLast().getTick() + 1, // length 5, // file_version 16, // vani_inst highestlayer, // height - "kr1v", // name - "kr1v", // author - "kr1v", // orig_author - "Written with a mod by kr1v", // description + name, // name + name, // author + name, // orig_author + "Made with Note Block Recorder", // description 20.0, // tempo false, // auto_save 18, // auto_save_time @@ -46,18 +47,13 @@ public static void main(int highestlayer) { for (int i = 0; i < highestlayer; i++) { layers.add(new Layer()); } - // Create the JSON structure JsonStructure jsonStructure = new JsonStructure(header, notes, layers, custom_instruments); - // Create Gson instance - Gson gson = new GsonBuilder().setPrettyPrinting().create(); // Pretty print for better readability - - // Convert the JsonStructure object to a JSON string + Gson gson = new GsonBuilder().setPrettyPrinting().create(); String json = gson.toJson(jsonStructure); - System.out.println("hey do the thing i sasked you"); - // Write the JSON string to a file + try (FileWriter writer = new FileWriter("notes.json")) { - System.out.println("written to: "); + System.out.println("written"); writer.write(json); } catch (IOException e) { System.out.println("uck"); diff --git a/src/client/java/org/kr1v/noteblockrecorder/client/Layer.java b/src/client/java/org/kr1v/noteblockrecorder/client/Layer.java index 382a9b8..88caac2 100644 --- a/src/client/java/org/kr1v/noteblockrecorder/client/Layer.java +++ b/src/client/java/org/kr1v/noteblockrecorder/client/Layer.java @@ -1,11 +1,14 @@ package org.kr1v.noteblockrecorder.client; public class Layer { - + private String name; + private boolean lock; + private int volume; + private int pan; public Layer() { - String name = ""; - boolean lock = false; - int volume = 100; - int pan = 0; + this.name = ""; + this.lock = false; + this.volume = 100; + this.pan = 0; } } diff --git a/src/client/java/org/kr1v/noteblockrecorder/client/Pitch.java b/src/client/java/org/kr1v/noteblockrecorder/client/Pitch.java index 7887bb4..660f9ae 100644 --- a/src/client/java/org/kr1v/noteblockrecorder/client/Pitch.java +++ b/src/client/java/org/kr1v/noteblockrecorder/client/Pitch.java @@ -12,17 +12,14 @@ public Result(int closestInteger, int leftover) { } public static Result mapValueToIntegerWithLeftover(float x) { - // Calculate y using the derived formula: y = 12 * log2(x) + 44 + // y = 12 * log2(x) + 44 float y = (float) (12 * (Math.log(x) / Math.log(2)) + 44); int closestInteger = Math.round(y); - // Calculate the leftover as a float value float fractionalPart = y - closestInteger; - // Scale the fractional part to the range -50 to 49 int leftover = Math.round(fractionalPart * 100); - // Adjust leftover to fit within the range -50 to 49 if (leftover == 50) { leftover = -50; closestInteger += 1; diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index b16e1ee..780c284 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -4,7 +4,7 @@ "version": "${version}", "name": "Note block logger", "description": "Listens for packets and reconstructs a .json file from them", - "authors": [], + "authors": ["kr1v"], "contact": {}, "license": "mit", "icon": "assets/icon.png",