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;
|
||||
|
||||
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;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
public class TxtConverter {
|
||||
public static Song getSongFromBytes(byte[] bytes, String fileName) throws IOException {
|
||||
Song song = new Song(fileName);
|
||||
String strContent = new String(bytes, StandardCharsets.UTF_8);
|
||||
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,
|
||||
};
|
||||
|
||||
String[] lines = strContent.split("\\r?\\n");
|
||||
for (int lineNum = 1; lineNum <= lines.length; lineNum++) {
|
||||
String line = lines[lineNum-1].strip();
|
||||
public static Song getSongFromBytes (byte[] bytes, String fileName) {
|
||||
return getSong(new String(bytes), fileName);
|
||||
}
|
||||
|
||||
if (line.startsWith("#")) continue;
|
||||
public static Song getSong (String data, String fileName) {
|
||||
if (!data.contains(":")) return null;
|
||||
|
||||
String[] split = line.split(":");
|
||||
if (split.length != 3) throw new IOException("Invalid format at line " + lineNum);
|
||||
int tick, pitch, instrument;
|
||||
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 {
|
||||
tick = Integer.parseInt(split[0]);
|
||||
pitch = Integer.parseInt(split[1]);
|
||||
instrument = Integer.parseInt(split[2]);
|
||||
} catch (NumberFormatException e) {
|
||||
throw new IOException("Invalid format at line " + lineNum);
|
||||
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
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
int noteId = pitch + instrument*25;
|
||||
song.add(new Note(noteId, tick*50));
|
||||
song.length = song.get(song.size()-1).time + 50;
|
||||
}
|
||||
|
||||
song.sort();
|
||||
song.length = song.get(song.size() - 1).time + 50;
|
||||
|
||||
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) {
|
||||
cachedCommand = command;
|
||||
}
|
||||
private void sendMessage(String message) {
|
||||
public void sendMessage(String message) {
|
||||
cachedMessage = message;
|
||||
}
|
||||
private void checkCommandCache() {
|
||||
|
|
|
@ -46,6 +46,8 @@ public class Stage {
|
|||
}
|
||||
|
||||
public void sendMovementPacketToStagePosition() {
|
||||
if (SongPlayer.MC.getNetworkHandler() == null) return;
|
||||
|
||||
if (SongPlayer.fakePlayer != null) {
|
||||
SongPlayer.MC.getNetworkHandler().sendPacket(new PlayerMoveC2SPacket.Full(
|
||||
position.getX() + 0.5, position.getY(), position.getZ() + 0.5,
|
||||
|
|
|
@ -56,7 +56,7 @@ public class SongLoaderThread extends Thread{
|
|||
try {
|
||||
byte[] bytes;
|
||||
if (isUrl) {
|
||||
bytes = DownloadUtils.DownloadToByteArray(songUrl, 10*1024*1024);
|
||||
bytes = DownloadUtils.DownloadToByteArray(songUrl);
|
||||
filename = Paths.get(songUrl.toURI().getPath()).getFileName().toString();
|
||||
}
|
||||
else {
|
||||
|
|
|
@ -12,7 +12,6 @@
|
|||
"ClientPlayerInteractionManagerAccessor",
|
||||
"ClientPlayNetworkHandlerAccessor",
|
||||
"ClientPlayNetworkHandlerMixin",
|
||||
"ClientConnectionMixin",
|
||||
"InGameHudMixin",
|
||||
"MinecraftClientMixin"
|
||||
],
|
||||
|
|
Loading…
Reference in a new issue