Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
kr1viah authored Aug 27, 2024
1 parent aa8b102 commit e37d2cc
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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; }

}
3 changes: 0 additions & 3 deletions src/client/java/org/kr1v/noteblockrecorder/client/Header.java
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,29 +46,20 @@ public static int main(RegistryEntry<SoundEvent> instrument) {
}

HashSet<String> 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<CustomInstruments> getCustomInstruments() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,19 @@

import java.util.List;

// Class to represent the entire JSON structure
public class JsonStructure {
private Header header;
private List<Note> notes;
private List<Layer> layers;
private List<CustomInstruments> custom_instruments;

// Constructor
public JsonStructure(Header header, List<Note> notes, List<Layer> layers, List<CustomInstruments> custom_instruments) {
this.header = header;
this.notes = notes;
this.layers = layers;
this.custom_instruments = custom_instruments;
}

// Getters (if needed)
public Header getHeader() { return header; }
public List<Note> getNotes() { return notes; }
public List<Layer> getLayers() { return layers; }
Expand Down
30 changes: 13 additions & 17 deletions src/client/java/org/kr1v/noteblockrecorder/client/JsonWriter.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -12,23 +13,23 @@ public class JsonWriter {
static List<Note> notes = new ArrayList<>();
static List<Layer> layers = new ArrayList<>();
static List<CustomInstruments> 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
Expand All @@ -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");
Expand Down
13 changes: 8 additions & 5 deletions src/client/java/org/kr1v/noteblockrecorder/client/Layer.java
Original file line number Diff line number Diff line change
@@ -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;
}
}
5 changes: 1 addition & 4 deletions src/client/java/org/kr1v/noteblockrecorder/client/Pitch.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit e37d2cc

Please sign in to comment.