Skip to content
This repository has been archived by the owner on Sep 2, 2024. It is now read-only.

Adds the ability for custom instruments to have the names designated in the .nbs file imported. #66

Open
wants to merge 55 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
59e80ec
Nbs Decoder now handles Custom Instruments with names
mudkip989 Dec 15, 2023
bda6a4a
Cleaned up commit before pull request
mudkip989 Dec 15, 2023
2cd20ab
add <space> support
homchom Dec 16, 2023
86d0674
a very partial fix for the /recode icon
homchom Dec 16, 2023
a368197
partial formatting fix
homchom Dec 18, 2023
e948bf7
minimessage try/catch
homchom Dec 18, 2023
02ad88a
don't render scope for unnamed var, fix value highlighting bounds
homchom Dec 18, 2023
3bc1f0f
repeatable newline, df parity/crash fix, duck cleanup
homchom Dec 19, 2023
513f285
fix highlight setting
homchom Dec 19, 2023
cb811a1
sigh
homchom Dec 20, 2023
bc8eaa0
two highlighting fixes (counts and surrogates)
homchom Dec 21, 2023
509b9bc
update scope highlighting description, remove a bunch of periods
homchom Dec 21, 2023
471cd94
order of operations my beloved
homchom Dec 21, 2023
181a7a1
migrate /colors copy to minimessage
homchom Dec 21, 2023
1f37f2f
fix title screen Resource Packs crash
homchom Dec 22, 2023
9745a86
mixin cleanup, improve message stacking performance
homchom Dec 25, 2023
51fe947
lazy trials, detector logic change, improve chat performance
homchom Dec 27, 2023
0189199
remove TestResult
homchom Dec 27, 2023
8a0ba62
this is embarrassing
homchom Dec 28, 2023
d09ed80
regression fix, "regression" "fix"
homchom Dec 29, 2023
d7d7abb
event node detector
homchom Dec 29, 2023
2c9b940
more anti state tampering
homchom Dec 30, 2023
9ad1835
better state detection
homchom Jan 1, 2024
15ee48f
DelayedCommandSender, some unfinished coroutine stuff
homchom Jan 4, 2024
02d15fa
extract RecodeDispatcher
homchom Jan 4, 2024
393852e
gradle 8.3, fabric loader 0.15
homchom Jan 4, 2024
e204720
silly
homchom Jan 4, 2024
4b22211
recode messages, recode logo char, attribution
homchom Jan 5, 2024
83f58c2
mod usage message, lazy prettified version
homchom Jan 5, 2024
a1ee878
things and stuff at 2am
homchom Jan 5, 2024
83a88c8
update betterunicode
homchom Jan 5, 2024
b70b427
enforce on steroids, cleanup
homchom Jan 5, 2024
4148c2b
silly v2 (i swear i tested this...)
homchom Jan 6, 2024
699bb73
fix uncaught exception
homchom Jan 7, 2024
6c345a1
New Decoder that allows for notes outside 2 octave range. Bad Idea? S…
mudkip989 Jan 29, 2024
a788928
Fixed old decoder using new decoder code.
mudkip989 Jan 30, 2024
94291fc
PlotMode.Dev constructor, make features work more like power
homchom Jan 9, 2024
d27e72a
another npe fix
homchom Jan 10, 2024
f1cc4d6
listen refactor
homchom Jan 10, 2024
7b15181
senders
homchom Jan 26, 2024
902a987
trying something different with power
homchom Feb 2, 2024
ac7f87b
thanks, we get it
homchom Feb 14, 2024
ec48d21
Changed Card Call that recode didn't because official recode hasn't a…
mudkip989 Feb 15, 2024
8cd1fcc
Updated Support Chat Filter with new color value found on server.
mudkip989 Feb 15, 2024
8c566f4
StyledString, component love
homchom Feb 15, 2024
fe38c70
better colors
homchom Feb 17, 2024
5db228a
oh
homchom Feb 17, 2024
4d442e4
support custom tick rates, preparation for lagslayer hud fix
homchom Mar 8, 2024
ee20966
Nbs Decoder now handles Custom Instruments with names
mudkip989 Dec 15, 2023
03beb63
Cleaned up commit before pull request
mudkip989 Dec 15, 2023
e621d1b
New Decoder that allows for notes outside 2 octave range. Bad Idea? S…
mudkip989 Jan 29, 2024
7deacf2
Fixed old decoder using new decoder code.
mudkip989 Jan 30, 2024
3114718
Changed Card Call that recode didn't because official recode hasn't a…
mudkip989 Feb 15, 2024
9972c6c
Merge remote-tracking branch 'mine/main'
mudkip989 Jul 18, 2024
6981e5a
Merge remote-tracking branch 'origin/main' into recode
mudkip989 Aug 17, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import io.github.homchom.recode.mod.features.commands.nbs.NBSDecoder;
import io.github.homchom.recode.mod.features.commands.nbs.NBSToTemplate;
import io.github.homchom.recode.mod.features.commands.nbs.SongData;
import io.github.homchom.recode.mod.features.commands.nbs.alt.*;
import io.github.homchom.recode.mod.features.commands.nbs.exceptions.OutdatedNBSException;
import io.github.homchom.recode.sys.file.ExternalFile;
import io.github.homchom.recode.sys.hypercube.templates.TemplateUtil;
Expand Down Expand Up @@ -59,6 +60,36 @@ public static void loadNbs(File file, String fileName) {
});
}

public static void loadNbsU(File file, String fileName) {
LegacyRecode.executor.submit(() -> {
try {
SongData d = NBSDecoderU.parse(file);
String code = new NBSToTemplate(d).convert();
ItemStack stack = new ItemStack(Items.NOTE_BLOCK);
TemplateUtil.compressTemplateNBT(stack, d.getName(), d.getAuthor(), code);

if (d.getName().length() == 0) {
String name;
if (d.getFileName().indexOf(".") > 0) {
name = d.getFileName().substring(0, d.getFileName().lastIndexOf("."));
} else {
name = d.getFileName();
}
stack.setHoverName(Component.literal("§5SONG§7 -§f " + name));
} else {
stack.setHoverName(Component.literal("§5SONG§7 -§f " + d.getName()));
}

ToasterUtil.sendToaster("NBS Loaded!", fileName, SystemToast.SystemToastId.NARRATOR_TOGGLE);
ItemUtil.giveCreativeItem(stack, true);
} catch (OutdatedNBSException e) {
ToasterUtil.sendToaster("§cLoading Error!", "Unsupported file version", SystemToast.SystemToastId.NARRATOR_TOGGLE);
} catch (IOException e) {
ToasterUtil.sendToaster("§cLoading Error!", "Invalid file", SystemToast.SystemToastId.NARRATOR_TOGGLE);
}
});
}

@Override
public void register(Minecraft mc, CommandDispatcher<FabricClientCommandSource> cd, CommandBuildContext context) {
cd.register(ArgBuilder.literal("nbs")
Expand All @@ -73,6 +104,17 @@ public void register(Minecraft mc, CommandDispatcher<FabricClientCommandSource>
return 1;
})
)
).then(ArgBuilder.literal("load2")
.then(ArgBuilder.argument("filename", PathArgumentType.folder(ExternalFile.NBS_FILES.getPath(), true))
.executes(ctx -> {
if (this.isCreative(mc)) {
File file = PathArgumentType.getPath(ctx, "filename").toFile();

loadNbsU(file, file.getName());
}
return 1;
})
)
)
.then(ArgBuilder.literal("player")
.executes(ctx -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ public void open(String... args) throws CommandSyntaxException {
int length = Integer
.parseInt(notearr[notearr.length - 1].split(":")[0]);
SongData d = new SongData("Song " + id, "Recode", 20f,
length, notes, "", "", 1, 0, 0);
length, notes, "", "", 1, 0, 0, new String[1]);

String code = new NBSToTemplate(d).convert();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,13 +165,14 @@ private static SongData parse(InputStream inputStream, File songFile) throws IOE
customInstruments = dataInputStream.readByte();

int[] customPitchList = new int[customInstruments];
String[] customNameList = new String[customInstruments];

if (customInstruments >= 1) {
for (int i = 0; i < customInstruments; i++) {
int instrumentOffset = vanillaInstruments + customInstruments;
int instrumentPitch = 0;

readString(dataInputStream); //Instrument name
customNameList[i] = readString(dataInputStream); //Instrument name
readString(dataInputStream); //Sound file

instrumentPitch = dataInputStream.readByte(); //Sound pitch
Expand Down Expand Up @@ -223,7 +224,7 @@ private static SongData parse(InputStream inputStream, File songFile) throws IOE
}


return new SongData(title, author, speed, (int) Math.ceil((length + 1.0) / (4 * timeSignature)) * (4 * timeSignature), stringBuilder.toString(), file, layerStringBuilder.toString(), (loopTick + 1), loopCount, customInstruments);
return new SongData(title, author, speed, (int) Math.ceil((length + 1.0) / (4 * timeSignature)) * (4 * timeSignature), stringBuilder.toString(), file, layerStringBuilder.toString(), (loopTick + 1), loopCount, customInstruments, customNameList);
}

private static short readShort(DataInputStream dataInputStream) throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public class NBSToTemplate {
final int loopTick;
final int loopCount;
final int customInstrumentCount;
final String[] customInstrumentNames;
String name;
String author;

Expand All @@ -33,6 +34,7 @@ public NBSToTemplate(SongData song) {
this.loopTick = song.getLoopTick();
this.loopCount = song.getLoopCount();
this.customInstrumentCount = song.getCustomInstrumentCount();
this.customInstrumentNames = song.getCustomInstrumentNames();
}

public String convert() {
Expand All @@ -43,7 +45,6 @@ public String convert() {
StringBuilder instList = new StringBuilder();

String songTempo = new BigDecimal(this.speed).stripTrailingZeros().toPlainString();

if (name.length() == 0) {
if (filename.indexOf(".") > 0) {
name = filename.substring(0, filename.lastIndexOf("."));
Expand All @@ -60,7 +61,6 @@ public String convert() {
boolean chestInited = false;
int noteCount = 0;
boolean finalNote = false;

for (int i = 0; i < songData.length; i++) {
boolean closeChest = false;
if (slot == 1) {
Expand All @@ -73,7 +73,6 @@ public String convert() {
if (slot >= 27) {
closeChest = true;
}

if (!closeChest) {
String currentNote = songData[i];
String revertString = currentNotes.toString();
Expand All @@ -84,7 +83,6 @@ public String convert() {
currentNotes.append("=").append(currentNote);
}
noteCount++;

if (currentNotes.length() > 1930) {
currentNotes = new StringBuilder(revertString);
currentBlock.append(String.format(",{\"item\":{\"id\":\"txt\",\"data\":{\"name\":\"%s\"}},\"slot\":%d}", currentNotes, slot));
Expand All @@ -111,7 +109,6 @@ public String convert() {
} else {
varActionType = "AppendValue";
}

currentBlock.append(String.format("]},\"action\":\"%s\"},", varActionType));
code.append(currentBlock);
currentBlock.setLength(0);
Expand All @@ -124,7 +121,6 @@ public String convert() {
slot = 1;
}
}

//CreateList: instrumentNames
if (customInstrumentCount == 0) {
code.append("{\"id\":\"block\",\"block\":\"set_var\",\"args\":{\"items\":[{\"item\":{\"id\":\"var\",\"data\":{\"name\":\"instrumentNames\",\"scope\":\"local\"}},\"slot\":0},{\"item\":{\"id\":\"txt\",\"data\":{\"name\":\"Harp\"}},\"slot\":1},{\"item\":{\"id\":\"txt\",\"data\":{\"name\":\"Bass\"}},\"slot\":2},{\"item\":{\"id\":\"txt\",\"data\":{\"name\":\"Bass Drum\"}},\"slot\":3},{\"item\":{\"id\":\"txt\",\"data\":{\"name\":\"Snare Drum\"}},\"slot\":4},{\"item\":{\"id\":\"txt\",\"data\":{\"name\":\"Click\"}},\"slot\":5},{\"item\":{\"id\":\"txt\",\"data\":{\"name\":\"Guitar\"}},\"slot\":6},{\"item\":{\"id\":\"txt\",\"data\":{\"name\":\"Flute\"}},\"slot\":7},{\"item\":{\"id\":\"txt\",\"data\":{\"name\":\"Bell\"}},\"slot\":8},{\"item\":{\"id\":\"txt\",\"data\":{\"name\":\"Chime\"}},\"slot\":9},{\"item\":{\"id\":\"txt\",\"data\":{\"name\":\"Xylophone\"}},\"slot\":10},{\"item\":{\"id\":\"txt\",\"data\":{\"name\":\"Iron Xylophone\"}},\"slot\":11},{\"item\":{\"id\":\"txt\",\"data\":{\"name\":\"Cow Bell\"}},\"slot\":12},{\"item\":{\"id\":\"txt\",\"data\":{\"name\":\"Didgeridoo\"}},\"slot\":13},{\"item\":{\"id\":\"txt\",\"data\":{\"name\":\"Bit\"}},\"slot\":14},{\"item\":{\"id\":\"txt\",\"data\":{\"name\":\"Banjo\"}},\"slot\":15},{\"item\":{\"id\":\"txt\",\"data\":{\"name\":\"Pling\"}},\"slot\":16}]},\"action\":\"CreateList\"},");
Expand All @@ -134,12 +130,22 @@ public String convert() {
int currentSlot;

currentSlot = 17;
int currentFails = 0;

for (int currentInstID = 1; currentInstID <= customInstrumentCount; currentInstID++) {
String currentName = "Custom Instrument";
currentName = customInstrumentNames[currentInstID - 1];
if(currentName == null || currentName.matches("^(\\s+)$") || currentName == ""){
currentFails++;
currentName = "<Custom Instrument " + currentFails + ">";
}
String formatted;
if (currentInstID == customInstrumentCount) {
instList.append(String.format("{\"item\":{\"id\":\"txt\",\"data\":{\"name\":\"<Custom Instrument #%d>\"}},\"slot\":%d}", currentInstID, currentSlot));
formatted = "{\"item\":{\"id\":\"txt\",\"data\":{\"name\":\"" + currentName + "\"}},\"slot\":" + currentSlot + "}";
} else {
instList.append(String.format("{\"item\":{\"id\":\"txt\",\"data\":{\"name\":\"<Custom Instrument #%d>\"}},\"slot\":%d},", currentInstID, currentSlot));
formatted = "{\"item\":{\"id\":\"txt\",\"data\":{\"name\":\"" + currentName + "\"}},\"slot\":" + currentSlot + "},";
}
instList.append(formatted);
currentSlot++;
}
instList.append("]},\"action\":\"CreateList\"},");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@ public class SongData {
final int loopTick;
final int loopCount;
final int customInstrumentCount;
final String[] customInstrumentNames;
String name;
String author;
float speed;
String fileName;
String notes;

public SongData(String name, String author, float speed, int length, String notes, String fileName, String layers, int loopTick, int loopCount, int customInstrumentCount) {
public SongData(String name, String author, float speed, int length, String notes, String fileName, String layers, int loopTick, int loopCount, int customInstrumentCount, String[] customInstrumentNames) {
this.name = name;
this.author = author;
this.speed = speed;
Expand All @@ -24,6 +25,7 @@ public SongData(String name, String author, float speed, int length, String note
this.loopTick = loopTick;
this.loopCount = loopCount;
this.customInstrumentCount = customInstrumentCount;
this.customInstrumentNames = customInstrumentNames;
}

public String getName() {
Expand Down Expand Up @@ -85,4 +87,8 @@ public int getLoopCount() {
public int getCustomInstrumentCount() {
return customInstrumentCount;
}

public String[] getCustomInstrumentNames() {
return customInstrumentNames;
}
}
Loading
Loading