Update to 1.21(.1)
This commit is contained in:
parent
4e6c135992
commit
0079cf3a59
7 changed files with 74 additions and 160 deletions
|
@ -1,87 +0,0 @@
|
||||||
package com.github.hhhzzzsss.songplayer.conversion;
|
|
||||||
|
|
||||||
import com.github.hhhzzzsss.songplayer.playing.SongHandler;
|
|
||||||
import com.github.hhhzzzsss.songplayer.song.Instrument;
|
|
||||||
import com.github.hhhzzzsss.songplayer.song.Note;
|
|
||||||
import com.github.hhhzzzsss.songplayer.song.Song;
|
|
||||||
|
|
||||||
public class TXTConverter {
|
|
||||||
public static Instrument[] instrumentIndex = new Instrument[] {
|
|
||||||
Instrument.HARP,
|
|
||||||
Instrument.BASS,
|
|
||||||
Instrument.BASEDRUM,
|
|
||||||
Instrument.SNARE,
|
|
||||||
Instrument.HAT,
|
|
||||||
Instrument.GUITAR,
|
|
||||||
Instrument.FLUTE,
|
|
||||||
Instrument.BELL,
|
|
||||||
Instrument.CHIME,
|
|
||||||
Instrument.XYLOPHONE,
|
|
||||||
Instrument.IRON_XYLOPHONE,
|
|
||||||
Instrument.COW_BELL,
|
|
||||||
Instrument.DIDGERIDOO,
|
|
||||||
Instrument.BIT,
|
|
||||||
Instrument.BANJO,
|
|
||||||
Instrument.PLING,
|
|
||||||
};
|
|
||||||
|
|
||||||
public static Song getSongFromBytes (byte[] bytes, String fileName) {
|
|
||||||
return getSong(new String(bytes), fileName);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Song getSong (String data, String fileName) {
|
|
||||||
if (!data.contains(":")) return null;
|
|
||||||
|
|
||||||
int length = 0;
|
|
||||||
|
|
||||||
final Song song = new Song(fileName);
|
|
||||||
|
|
||||||
for (String line : data.split("\r\n|\r|\n")) {
|
|
||||||
if (line.isBlank()) continue;
|
|
||||||
|
|
||||||
if (line.startsWith("title:")) {
|
|
||||||
song.name = line.substring("title:".length());
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
final String[] split = line.split(":");
|
|
||||||
|
|
||||||
final int tick = Integer.parseInt(split[0]);
|
|
||||||
int pitch = (int) Float.parseFloat(split[1]) + 33 + SongHandler.getInstance().pitch;
|
|
||||||
final String instrument = split[2];
|
|
||||||
|
|
||||||
int intInstrument = -1;
|
|
||||||
try {
|
|
||||||
intInstrument = Integer.parseInt(instrument);
|
|
||||||
} catch (NumberFormatException ignored) {}
|
|
||||||
|
|
||||||
if (intInstrument == -1) continue;
|
|
||||||
|
|
||||||
if (intInstrument > instrumentIndex.length - 1) continue;
|
|
||||||
|
|
||||||
final Instrument instrumentClass = instrumentIndex[intInstrument];
|
|
||||||
|
|
||||||
if (instrumentClass == null) continue;
|
|
||||||
|
|
||||||
final int time = tick * 50;
|
|
||||||
|
|
||||||
length = Math.max(length, time);
|
|
||||||
|
|
||||||
while (pitch < 33) pitch += 12;
|
|
||||||
while (pitch > 57) pitch -= 12;
|
|
||||||
|
|
||||||
pitch -= 33;
|
|
||||||
|
|
||||||
song.add(
|
|
||||||
new Note(
|
|
||||||
pitch + (instrumentClass.instrumentId * 25),
|
|
||||||
time
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
song.length = song.get(song.size() - 1).time + 50;
|
|
||||||
|
|
||||||
return song;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,39 +1,86 @@
|
||||||
package com.github.hhhzzzsss.songplayer.conversion;
|
package com.github.hhhzzzsss.songplayer.conversion;
|
||||||
|
|
||||||
|
import com.github.hhhzzzsss.songplayer.playing.SongHandler;
|
||||||
|
import com.github.hhhzzzsss.songplayer.song.Instrument;
|
||||||
import com.github.hhhzzzsss.songplayer.song.Note;
|
import com.github.hhhzzzsss.songplayer.song.Note;
|
||||||
import com.github.hhhzzzsss.songplayer.song.Song;
|
import com.github.hhhzzzsss.songplayer.song.Song;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.nio.charset.StandardCharsets;
|
|
||||||
|
|
||||||
public class TxtConverter {
|
public class TxtConverter {
|
||||||
public static Song getSongFromBytes(byte[] bytes, String fileName) throws IOException {
|
public static Instrument[] instrumentIndex = new Instrument[] {
|
||||||
Song song = new Song(fileName);
|
Instrument.HARP,
|
||||||
String strContent = new String(bytes, StandardCharsets.UTF_8);
|
Instrument.BASS,
|
||||||
|
Instrument.BASEDRUM,
|
||||||
|
Instrument.SNARE,
|
||||||
|
Instrument.HAT,
|
||||||
|
Instrument.GUITAR,
|
||||||
|
Instrument.FLUTE,
|
||||||
|
Instrument.BELL,
|
||||||
|
Instrument.CHIME,
|
||||||
|
Instrument.XYLOPHONE,
|
||||||
|
Instrument.IRON_XYLOPHONE,
|
||||||
|
Instrument.COW_BELL,
|
||||||
|
Instrument.DIDGERIDOO,
|
||||||
|
Instrument.BIT,
|
||||||
|
Instrument.BANJO,
|
||||||
|
Instrument.PLING,
|
||||||
|
};
|
||||||
|
|
||||||
String[] lines = strContent.split("\\r?\\n");
|
public static Song getSongFromBytes (byte[] bytes, String fileName) {
|
||||||
for (int lineNum = 1; lineNum <= lines.length; lineNum++) {
|
return getSong(new String(bytes), fileName);
|
||||||
String line = lines[lineNum-1].strip();
|
}
|
||||||
|
|
||||||
if (line.startsWith("#")) continue;
|
public static Song getSong (String data, String fileName) {
|
||||||
|
if (!data.contains(":")) return null;
|
||||||
|
|
||||||
String[] split = line.split(":");
|
int length = 0;
|
||||||
if (split.length != 3) throw new IOException("Invalid format at line " + lineNum);
|
|
||||||
int tick, pitch, instrument;
|
final Song song = new Song(fileName);
|
||||||
try {
|
|
||||||
tick = Integer.parseInt(split[0]);
|
for (String line : data.split("\r\n|\r|\n")) {
|
||||||
pitch = Integer.parseInt(split[1]);
|
if (line.isBlank()) continue;
|
||||||
instrument = Integer.parseInt(split[2]);
|
|
||||||
} catch (NumberFormatException e) {
|
if (line.startsWith("title:")) {
|
||||||
throw new IOException("Invalid format at line " + lineNum);
|
song.name = line.substring("title:".length());
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
int noteId = pitch + instrument*25;
|
final String[] split = line.split(":");
|
||||||
song.add(new Note(noteId, tick*50));
|
|
||||||
song.length = song.get(song.size()-1).time + 50;
|
final int tick = Integer.parseInt(split[0]);
|
||||||
|
int pitch = (int) Float.parseFloat(split[1]) + 33 + SongHandler.getInstance().pitch;
|
||||||
|
final String instrument = split[2];
|
||||||
|
|
||||||
|
int intInstrument = -1;
|
||||||
|
try {
|
||||||
|
intInstrument = Integer.parseInt(instrument);
|
||||||
|
} catch (NumberFormatException ignored) {}
|
||||||
|
|
||||||
|
if (intInstrument == -1) continue;
|
||||||
|
|
||||||
|
if (intInstrument > instrumentIndex.length - 1) continue;
|
||||||
|
|
||||||
|
final Instrument instrumentClass = instrumentIndex[intInstrument];
|
||||||
|
|
||||||
|
if (instrumentClass == null) continue;
|
||||||
|
|
||||||
|
final int time = tick * 50;
|
||||||
|
|
||||||
|
length = Math.max(length, time);
|
||||||
|
|
||||||
|
while (pitch < 33) pitch += 12;
|
||||||
|
while (pitch > 57) pitch -= 12;
|
||||||
|
|
||||||
|
pitch -= 33;
|
||||||
|
|
||||||
|
song.add(
|
||||||
|
new Note(
|
||||||
|
pitch + (instrumentClass.instrumentId * 25),
|
||||||
|
time
|
||||||
|
)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
song.sort();
|
song.length = song.get(song.size() - 1).time + 50;
|
||||||
|
|
||||||
return song;
|
return song;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,47 +0,0 @@
|
||||||
package com.github.hhhzzzsss.songplayer.mixin;
|
|
||||||
|
|
||||||
import com.github.hhhzzzsss.songplayer.Config;
|
|
||||||
import com.github.hhhzzzsss.songplayer.SongPlayer;
|
|
||||||
import com.github.hhhzzzsss.songplayer.playing.SongHandler;
|
|
||||||
import com.github.hhhzzzsss.songplayer.playing.Stage;
|
|
||||||
import net.minecraft.client.MinecraftClient;
|
|
||||||
import net.minecraft.entity.EntityPose;
|
|
||||||
import net.minecraft.network.ClientConnection;
|
|
||||||
import net.minecraft.network.packet.Packet;
|
|
||||||
import net.minecraft.network.packet.c2s.play.ClientCommandC2SPacket;
|
|
||||||
import net.minecraft.network.packet.c2s.play.PlayerMoveC2SPacket;
|
|
||||||
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.CallbackInfo;
|
|
||||||
|
|
||||||
@Mixin(ClientConnection.class)
|
|
||||||
public class ClientConnectionMixin {
|
|
||||||
@Inject(at = @At("HEAD"), method = "send(Lnet/minecraft/network/packet/Packet;)V", cancellable = true)
|
|
||||||
private void sendPacket(Packet<?> packet, CallbackInfo ci) {
|
|
||||||
Stage stage = SongHandler.getInstance().stage;
|
|
||||||
|
|
||||||
if (stage != null && packet instanceof PlayerMoveC2SPacket) {
|
|
||||||
if (!Config.getConfig().rotate) {
|
|
||||||
MinecraftClient.getInstance().getNetworkHandler().sendPacket(new PlayerMoveC2SPacket.Full(stage.position.getX() + 0.5, stage.position.getY(), stage.position.getZ() + 0.5, SongPlayer.MC.player.getYaw(), SongPlayer.MC.player.getPitch(), true));
|
|
||||||
if (SongPlayer.fakePlayer != null) {
|
|
||||||
SongPlayer.fakePlayer.copyStagePosAndPlayerLook();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
ci.cancel();
|
|
||||||
}
|
|
||||||
else if (packet instanceof ClientCommandC2SPacket) {
|
|
||||||
ClientCommandC2SPacket.Mode mode = ((ClientCommandC2SPacket) packet).getMode();
|
|
||||||
if (SongPlayer.fakePlayer != null) {
|
|
||||||
if (mode == ClientCommandC2SPacket.Mode.PRESS_SHIFT_KEY) {
|
|
||||||
SongPlayer.fakePlayer.setSneaking(true);
|
|
||||||
SongPlayer.fakePlayer.setPose(EntityPose.CROUCHING);
|
|
||||||
}
|
|
||||||
else if (mode == ClientCommandC2SPacket.Mode.RELEASE_SHIFT_KEY) {
|
|
||||||
SongPlayer.fakePlayer.setSneaking(false);
|
|
||||||
SongPlayer.fakePlayer.setPose(EntityPose.STANDING);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -713,7 +713,7 @@ public class SongHandler {
|
||||||
private void sendGamemodeCommand(String command) {
|
private void sendGamemodeCommand(String command) {
|
||||||
cachedCommand = command;
|
cachedCommand = command;
|
||||||
}
|
}
|
||||||
private void sendMessage(String message) {
|
public void sendMessage(String message) {
|
||||||
cachedMessage = message;
|
cachedMessage = message;
|
||||||
}
|
}
|
||||||
private void checkCommandCache() {
|
private void checkCommandCache() {
|
||||||
|
|
|
@ -46,6 +46,8 @@ public class Stage {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void sendMovementPacketToStagePosition() {
|
public void sendMovementPacketToStagePosition() {
|
||||||
|
if (SongPlayer.MC.getNetworkHandler() == null) return;
|
||||||
|
|
||||||
if (SongPlayer.fakePlayer != null) {
|
if (SongPlayer.fakePlayer != null) {
|
||||||
SongPlayer.MC.getNetworkHandler().sendPacket(new PlayerMoveC2SPacket.Full(
|
SongPlayer.MC.getNetworkHandler().sendPacket(new PlayerMoveC2SPacket.Full(
|
||||||
position.getX() + 0.5, position.getY(), position.getZ() + 0.5,
|
position.getX() + 0.5, position.getY(), position.getZ() + 0.5,
|
||||||
|
|
|
@ -56,7 +56,7 @@ public class SongLoaderThread extends Thread{
|
||||||
try {
|
try {
|
||||||
byte[] bytes;
|
byte[] bytes;
|
||||||
if (isUrl) {
|
if (isUrl) {
|
||||||
bytes = DownloadUtils.DownloadToByteArray(songUrl, 10*1024*1024);
|
bytes = DownloadUtils.DownloadToByteArray(songUrl);
|
||||||
filename = Paths.get(songUrl.toURI().getPath()).getFileName().toString();
|
filename = Paths.get(songUrl.toURI().getPath()).getFileName().toString();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
|
@ -12,7 +12,6 @@
|
||||||
"ClientPlayerInteractionManagerAccessor",
|
"ClientPlayerInteractionManagerAccessor",
|
||||||
"ClientPlayNetworkHandlerAccessor",
|
"ClientPlayNetworkHandlerAccessor",
|
||||||
"ClientPlayNetworkHandlerMixin",
|
"ClientPlayNetworkHandlerMixin",
|
||||||
"ClientConnectionMixin",
|
|
||||||
"InGameHudMixin",
|
"InGameHudMixin",
|
||||||
"MinecraftClientMixin"
|
"MinecraftClientMixin"
|
||||||
],
|
],
|
||||||
|
|
Loading…
Reference in a new issue